@nice2dev/ui-graphics 1.3.15 → 1.3.16
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 +9 -0
- package/dist/cjs/animation/AnimatedPerson.js +470 -143
- package/dist/cjs/animation/AnimationEditor.js +289 -101
- package/dist/cjs/animation/Audience.js +83 -61
- package/dist/cjs/animation/BodyRenderer.js +69 -28
- package/dist/cjs/animation/animationHelper.js +281 -288
- package/dist/cjs/animation/characterTypes.js +200 -203
- package/dist/cjs/animation/choreoDSL.js +205 -219
- package/dist/cjs/animation/choreography.js +4 -32
- package/dist/cjs/animation/karaokeIntegration.js +68 -77
- package/dist/cjs/animation/lottieExport.js +108 -114
- package/dist/cjs/animation/motionPath.js +225 -248
- package/dist/cjs/animation/physics.js +227 -254
- package/dist/cjs/animation/rig/RigPlayer.js +53 -56
- package/dist/cjs/animation/rig/RiggedBody.js +71 -26
- package/dist/cjs/animation/rig/choreoRigBridge.js +72 -77
- package/dist/cjs/animation/rig/ik.js +13 -18
- package/dist/cjs/animation/rig/poseOps.js +34 -41
- package/dist/cjs/animation/rig/presets.js +64 -72
- package/dist/cjs/animation/rig/rigMath.js +25 -32
- package/dist/cjs/animation/rig/rigTypes.js +59 -63
- package/dist/cjs/animation/shapes/arms.js +31 -13
- package/dist/cjs/animation/shapes/eyes.js +129 -47
- package/dist/cjs/animation/shapes/hair.js +72 -45
- package/dist/cjs/animation/shapes/heads.js +131 -57
- package/dist/cjs/animation/shapes/headwear.js +47 -38
- package/dist/cjs/animation/shapes/legs.js +31 -13
- package/dist/cjs/animation/shapes/mouths.js +120 -44
- package/dist/cjs/animation/shapes/noses.js +80 -25
- package/dist/cjs/animation/shapes/outfits.js +101 -39
- package/dist/cjs/animation/shapes/torsos.js +15 -11
- package/dist/cjs/animation/spineExport.js +103 -121
- package/dist/cjs/core/LocalUI.js +108 -43
- package/dist/cjs/core/NiceBrushEngine.js +758 -552
- package/dist/cjs/core/collaboration.js +249 -251
- package/dist/cjs/core/colorBlindness.js +100 -115
- package/dist/cjs/core/dragDrop.js +155 -158
- package/dist/cjs/core/editorAsk.js +51 -41
- package/dist/cjs/core/fixes.js +140 -171
- package/dist/cjs/core/gridGuides.js +166 -201
- package/dist/cjs/core/historyVisual.js +156 -135
- package/dist/cjs/core/i18n.js +13 -14
- package/dist/cjs/core/integrations.js +238 -249
- package/dist/cjs/core/minimap.js +149 -151
- package/dist/cjs/core/plugins.js +98 -113
- package/dist/cjs/core/rtl.js +71 -83
- package/dist/cjs/core/shortcuts.js +196 -225
- package/dist/cjs/core/theme.js +142 -149
- package/dist/cjs/core/yjsCollaboration.js +232 -293
- package/dist/cjs/design/design-tools.js +12 -22
- package/dist/cjs/font/NiceFontEditor.js +877 -316
- package/dist/cjs/font/fontFormatUtils.js +388 -448
- package/dist/cjs/game/GameAsset2dEditor.js +1201 -392
- package/dist/cjs/game/GameAsset2dEditor.module.css.js +146 -5
- package/dist/cjs/game/gameAssetTypes.js +7 -16
- package/dist/cjs/game/gameAssetUtils.js +390 -413
- package/dist/cjs/game/useGameAssetEditor.js +820 -763
- package/dist/cjs/index.js +81 -84
- package/dist/cjs/nice2dev-ui-graphics.css +1 -1
- package/dist/cjs/node_modules/lib0/array.js +8 -70
- package/dist/cjs/node_modules/lib0/binary.js +3 -20
- package/dist/cjs/node_modules/lib0/broadcastchannel.js +24 -86
- package/dist/cjs/node_modules/lib0/buffer.js +15 -82
- package/dist/cjs/node_modules/lib0/conditions.js +3 -16
- package/dist/cjs/node_modules/lib0/decoding.js +108 -287
- package/dist/cjs/node_modules/lib0/dom.js +14 -44
- package/dist/cjs/node_modules/lib0/encoding.js +68 -418
- package/dist/cjs/node_modules/lib0/environment.js +26 -92
- package/dist/cjs/node_modules/lib0/error.js +5 -29
- package/dist/cjs/node_modules/lib0/function.js +27 -66
- package/dist/cjs/node_modules/lib0/iterator.js +8 -33
- package/dist/cjs/node_modules/lib0/logging.common.js +12 -22
- package/dist/cjs/node_modules/lib0/logging.js +32 -71
- package/dist/cjs/node_modules/lib0/map.js +16 -86
- package/dist/cjs/node_modules/lib0/math.js +3 -32
- package/dist/cjs/node_modules/lib0/number.js +4 -15
- package/dist/cjs/node_modules/lib0/object.js +14 -88
- package/dist/cjs/node_modules/lib0/observable.js +38 -78
- package/dist/cjs/node_modules/lib0/pair.js +3 -20
- package/dist/cjs/node_modules/lib0/prng.js +8 -77
- package/dist/cjs/node_modules/lib0/promise.js +6 -30
- package/dist/cjs/node_modules/lib0/random.js +8 -23
- package/dist/cjs/node_modules/lib0/schema.js +313 -687
- package/dist/cjs/node_modules/lib0/set.js +3 -10
- package/dist/cjs/node_modules/lib0/storage.js +20 -55
- package/dist/cjs/node_modules/lib0/string.js +17 -72
- package/dist/cjs/node_modules/lib0/symbol.js +2 -12
- package/dist/cjs/node_modules/lib0/time.js +2 -15
- package/dist/cjs/node_modules/lib0/trait/equality.js +3 -28
- package/dist/cjs/node_modules/lib0/url.js +4 -18
- package/dist/cjs/node_modules/lib0/webcrypto.js +2 -5
- package/dist/cjs/node_modules/y-protocols/auth.js +5 -19
- package/dist/cjs/node_modules/y-protocols/awareness.js +53 -116
- package/dist/cjs/node_modules/y-protocols/sync.js +16 -103
- package/dist/cjs/node_modules/y-websocket/src/y-websocket.js +77 -219
- package/dist/cjs/node_modules/yjs/dist/yjs.js +2128 -4868
- package/dist/cjs/photo/FilterThumb.js +37 -25
- package/dist/cjs/photo/NiceAITools.js +679 -467
- package/dist/cjs/photo/PhotoEditor.js +34 -20
- package/dist/cjs/photo/PhotoEditor.module.css.js +296 -5
- package/dist/cjs/photo/PhotoEditorCanvas.js +250 -91
- package/dist/cjs/photo/PhotoEditorLeftPanel.js +1086 -224
- package/dist/cjs/photo/PhotoEditorToolbar.js +135 -19
- package/dist/cjs/photo/photoEditorActions.js +89 -72
- package/dist/cjs/photo/photoEditorTypes.js +29 -32
- package/dist/cjs/photo/photoFilters.js +959 -985
- package/dist/cjs/photo/photoOverlays.js +899 -945
- package/dist/cjs/photo/photoSelection.js +427 -499
- package/dist/cjs/photo/usePhotoEditor.js +739 -741
- package/dist/cjs/pixel/HSVPicker.js +191 -175
- package/dist/cjs/pixel/PixelEditor.js +159 -48
- package/dist/cjs/pixel/PixelEditor.module.css.js +209 -5
- package/dist/cjs/pixel/PixelEditorCanvas.js +29 -16
- package/dist/cjs/pixel/PixelEditorMenuBar.js +160 -162
- package/dist/cjs/pixel/PixelEditorRightPanel.js +377 -45
- package/dist/cjs/pixel/PixelEditorStatusBar.js +47 -20
- package/dist/cjs/pixel/PixelEditorTimeline.js +106 -23
- package/dist/cjs/pixel/PixelEditorToolbar.js +99 -21
- package/dist/cjs/pixel/SpriteGeneratorPanel.js +483 -303
- package/dist/cjs/pixel/animalGeneratorPresets.js +776 -601
- package/dist/cjs/pixel/asepriteFormat.js +511 -560
- package/dist/cjs/pixel/buildingGeneratorPresets.js +693 -520
- package/dist/cjs/pixel/characterGeneratorPresets.js +644 -544
- package/dist/cjs/pixel/pixel-pro.js +52 -63
- package/dist/cjs/pixel/pixelEditorExports.js +388 -428
- package/dist/cjs/pixel/pixelEditorTypes.js +91 -108
- package/dist/cjs/pixel/pixelEditorUtils.js +519 -561
- package/dist/cjs/pixel/spriteGeneratorCore.js +206 -257
- package/dist/cjs/pixel/usePixelEditor.js +1321 -1343
- package/dist/cjs/texture/Nice3DTexturePainter.js +707 -440
- package/dist/cjs/ui/NiceUIDesigner.js +954 -527
- package/dist/cjs/vector/NiceSvgToCode.js +586 -446
- package/dist/cjs/vector/VectorEditor.js +290 -117
- package/dist/cjs/vector/VectorEditor.module.css.js +86 -5
- package/dist/cjs/vector/VectorEditorMenuBar.js +333 -275
- package/dist/cjs/vector/VectorEditorRightPanel.js +1094 -371
- package/dist/cjs/vector/VectorEditorShapeRenderer.js +198 -60
- package/dist/cjs/vector/VectorEditorStatusBar.js +39 -13
- package/dist/cjs/vector/useVectorEditor.js +848 -889
- package/dist/cjs/vector/vectorAnimation.js +110 -137
- package/dist/cjs/vector/vectorBooleanOps.js +398 -485
- package/dist/cjs/vector/vectorEditorExport.js +201 -203
- package/dist/cjs/vector/vectorEditorImport.js +173 -189
- package/dist/cjs/vector/vectorEditorTypes.js +42 -49
- package/dist/cjs/vector/vectorGradients.js +151 -174
- package/dist/cjs/vector/vectorIconExport.js +52 -59
- package/dist/cjs/vector/vectorIconImport.js +169 -219
- package/dist/esm/animation/AnimatedPerson.js +470 -141
- package/dist/esm/animation/AnimationEditor.js +290 -100
- package/dist/esm/animation/Audience.js +83 -59
- package/dist/esm/animation/BodyRenderer.js +71 -25
- package/dist/esm/animation/animationHelper.js +284 -287
- package/dist/esm/animation/characterTypes.js +204 -202
- package/dist/esm/animation/choreoDSL.js +212 -218
- package/dist/esm/animation/choreography.js +8 -31
- package/dist/esm/animation/karaokeIntegration.js +74 -76
- package/dist/esm/animation/lottieExport.js +112 -113
- package/dist/esm/animation/motionPath.js +235 -247
- package/dist/esm/animation/physics.js +235 -253
- package/dist/esm/animation/rig/RigPlayer.js +53 -54
- package/dist/esm/animation/rig/RiggedBody.js +71 -24
- package/dist/esm/animation/rig/choreoRigBridge.js +74 -76
- package/dist/esm/animation/rig/ik.js +14 -17
- package/dist/esm/animation/rig/poseOps.js +37 -40
- package/dist/esm/animation/rig/presets.js +70 -71
- package/dist/esm/animation/rig/rigMath.js +28 -31
- package/dist/esm/animation/rig/rigTypes.js +62 -62
- package/dist/esm/animation/shapes/arms.js +32 -12
- package/dist/esm/animation/shapes/eyes.js +135 -46
- package/dist/esm/animation/shapes/hair.js +80 -44
- package/dist/esm/animation/shapes/heads.js +140 -56
- package/dist/esm/animation/shapes/headwear.js +54 -37
- package/dist/esm/animation/shapes/legs.js +32 -12
- package/dist/esm/animation/shapes/mouths.js +127 -43
- package/dist/esm/animation/shapes/noses.js +87 -24
- package/dist/esm/animation/shapes/outfits.js +106 -38
- package/dist/esm/animation/shapes/torsos.js +16 -10
- package/dist/esm/animation/spineExport.js +106 -120
- package/dist/esm/core/LocalUI.js +111 -42
- package/dist/esm/core/NiceBrushEngine.js +761 -551
- package/dist/esm/core/collaboration.js +255 -250
- package/dist/esm/core/colorBlindness.js +106 -114
- package/dist/esm/core/dragDrop.js +157 -157
- package/dist/esm/core/editorAsk.js +53 -40
- package/dist/esm/core/fixes.js +145 -170
- package/dist/esm/core/gridGuides.js +178 -200
- package/dist/esm/core/historyVisual.js +158 -134
- package/dist/esm/core/i18n.js +15 -13
- package/dist/esm/core/integrations.js +244 -248
- package/dist/esm/core/minimap.js +151 -150
- package/dist/esm/core/plugins.js +102 -112
- package/dist/esm/core/rtl.js +77 -82
- package/dist/esm/core/shortcuts.js +200 -224
- package/dist/esm/core/theme.js +150 -148
- package/dist/esm/core/yjsCollaboration.js +240 -292
- package/dist/esm/design/design-tools.js +13 -21
- package/dist/esm/font/NiceFontEditor.js +880 -315
- package/dist/esm/font/fontFormatUtils.js +394 -447
- package/dist/esm/game/GameAsset2dEditor.js +1202 -391
- package/dist/esm/game/GameAsset2dEditor.module.css.js +146 -3
- package/dist/esm/game/gameAssetTypes.js +8 -15
- package/dist/esm/game/gameAssetUtils.js +408 -412
- package/dist/esm/game/useGameAssetEditor.js +821 -762
- package/dist/esm/index.js +332 -69
- package/dist/esm/nice2dev-ui-graphics.css +1 -1
- package/dist/esm/node_modules/lib0/array.js +15 -69
- package/dist/esm/node_modules/lib0/binary.js +14 -19
- package/dist/esm/node_modules/lib0/broadcastchannel.js +27 -85
- package/dist/esm/node_modules/lib0/buffer.js +20 -80
- package/dist/esm/node_modules/lib0/conditions.js +4 -15
- package/dist/esm/node_modules/lib0/decoding.js +128 -286
- package/dist/esm/node_modules/lib0/dom.js +20 -43
- package/dist/esm/node_modules/lib0/encoding.js +90 -415
- package/dist/esm/node_modules/lib0/environment.js +33 -91
- package/dist/esm/node_modules/lib0/error.js +8 -28
- package/dist/esm/node_modules/lib0/function.js +31 -65
- package/dist/esm/node_modules/lib0/iterator.js +11 -32
- package/dist/esm/node_modules/lib0/logging.common.js +22 -21
- package/dist/esm/node_modules/lib0/logging.js +44 -70
- package/dist/esm/node_modules/lib0/map.js +21 -85
- package/dist/esm/node_modules/lib0/math.js +9 -31
- package/dist/esm/node_modules/lib0/number.js +7 -14
- package/dist/esm/node_modules/lib0/object.js +26 -87
- package/dist/esm/node_modules/lib0/observable.js +40 -77
- package/dist/esm/node_modules/lib0/pair.js +5 -19
- package/dist/esm/node_modules/lib0/prng.js +15 -76
- package/dist/esm/node_modules/lib0/promise.js +7 -29
- package/dist/esm/node_modules/lib0/random.js +10 -22
- package/dist/esm/node_modules/lib0/schema.js +367 -686
- package/dist/esm/node_modules/lib0/set.js +4 -9
- package/dist/esm/node_modules/lib0/storage.js +23 -54
- package/dist/esm/node_modules/lib0/string.js +26 -71
- package/dist/esm/node_modules/lib0/symbol.js +3 -11
- package/dist/esm/node_modules/lib0/time.js +3 -14
- package/dist/esm/node_modules/lib0/trait/equality.js +5 -27
- package/dist/esm/node_modules/lib0/url.js +5 -17
- package/dist/esm/node_modules/lib0/webcrypto.js +3 -4
- package/dist/esm/node_modules/y-protocols/auth.js +7 -18
- package/dist/esm/node_modules/y-protocols/awareness.js +58 -115
- package/dist/esm/node_modules/y-protocols/sync.js +26 -102
- package/dist/esm/node_modules/y-websocket/src/y-websocket.js +82 -218
- package/dist/esm/node_modules/yjs/dist/yjs.js +2263 -4899
- package/dist/esm/photo/FilterThumb.js +37 -23
- package/dist/esm/photo/NiceAITools.js +685 -466
- package/dist/esm/photo/PhotoEditor.js +34 -18
- package/dist/esm/photo/PhotoEditor.module.css.js +296 -3
- package/dist/esm/photo/PhotoEditorCanvas.js +250 -89
- package/dist/esm/photo/PhotoEditorLeftPanel.js +1086 -222
- package/dist/esm/photo/PhotoEditorToolbar.js +135 -17
- package/dist/esm/photo/photoEditorActions.js +93 -71
- package/dist/esm/photo/photoEditorTypes.js +32 -31
- package/dist/esm/photo/photoFilters.js +967 -984
- package/dist/esm/photo/photoOverlays.js +913 -944
- package/dist/esm/photo/photoSelection.js +438 -498
- package/dist/esm/photo/usePhotoEditor.js +740 -740
- package/dist/esm/pixel/HSVPicker.js +192 -174
- package/dist/esm/pixel/PixelEditor.js +160 -47
- package/dist/esm/pixel/PixelEditor.module.css.js +209 -3
- package/dist/esm/pixel/PixelEditorCanvas.js +29 -14
- package/dist/esm/pixel/PixelEditorMenuBar.js +160 -160
- package/dist/esm/pixel/PixelEditorRightPanel.js +377 -43
- package/dist/esm/pixel/PixelEditorStatusBar.js +47 -18
- package/dist/esm/pixel/PixelEditorTimeline.js +106 -21
- package/dist/esm/pixel/PixelEditorToolbar.js +99 -19
- package/dist/esm/pixel/SpriteGeneratorPanel.js +483 -301
- package/dist/esm/pixel/animalGeneratorPresets.js +782 -600
- package/dist/esm/pixel/asepriteFormat.js +517 -559
- package/dist/esm/pixel/buildingGeneratorPresets.js +699 -519
- package/dist/esm/pixel/characterGeneratorPresets.js +650 -543
- package/dist/esm/pixel/pixel-pro.js +53 -62
- package/dist/esm/pixel/pixelEditorExports.js +397 -427
- package/dist/esm/pixel/pixelEditorTypes.js +103 -107
- package/dist/esm/pixel/pixelEditorUtils.js +551 -560
- package/dist/esm/pixel/spriteGeneratorCore.js +223 -256
- package/dist/esm/pixel/usePixelEditor.js +1322 -1342
- package/dist/esm/texture/Nice3DTexturePainter.js +709 -439
- package/dist/esm/ui/NiceUIDesigner.js +957 -526
- package/dist/esm/vector/NiceSvgToCode.js +589 -445
- package/dist/esm/vector/VectorEditor.js +291 -116
- package/dist/esm/vector/VectorEditor.module.css.js +86 -3
- package/dist/esm/vector/VectorEditorMenuBar.js +333 -273
- package/dist/esm/vector/VectorEditorRightPanel.js +1094 -369
- package/dist/esm/vector/VectorEditorShapeRenderer.js +199 -59
- package/dist/esm/vector/VectorEditorStatusBar.js +39 -11
- package/dist/esm/vector/useVectorEditor.js +849 -888
- package/dist/esm/vector/vectorAnimation.js +115 -136
- package/dist/esm/vector/vectorBooleanOps.js +401 -484
- package/dist/esm/vector/vectorEditorExport.js +207 -202
- package/dist/esm/vector/vectorEditorImport.js +174 -188
- package/dist/esm/vector/vectorEditorTypes.js +50 -48
- package/dist/esm/vector/vectorGradients.js +158 -173
- package/dist/esm/vector/vectorIconExport.js +53 -58
- package/dist/esm/vector/vectorIconImport.js +171 -218
- package/package.json +9 -15
|
@@ -1,588 +1,546 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* asepriteFormat.ts — Aseprite .ase/.aseprite binary format parser & writer.
|
|
3
|
-
* Spec: https://github.com/aseprite/aseprite/blob/main/docs/ase-file-specs.md
|
|
4
|
-
*
|
|
5
|
-
* Supports:
|
|
6
|
-
* - RGBA color depth (32-bit)
|
|
7
|
-
* - Layers (normal, groups)
|
|
8
|
-
* - Cels (raw + zlib-compressed read, raw write)
|
|
9
|
-
* - Palette chunks
|
|
10
|
-
* - Frame tags
|
|
11
|
-
* - Round-trip: parseAse → writeAse produces valid .ase files
|
|
12
|
-
*/
|
|
13
|
-
// ── Binary helpers ───────────────────────────────────────────
|
|
14
1
|
class BinaryReader {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
2
|
+
constructor(buffer) {
|
|
3
|
+
this.pos = 0;
|
|
4
|
+
this.view = new DataView(buffer);
|
|
5
|
+
}
|
|
6
|
+
get offset() {
|
|
7
|
+
return this.pos;
|
|
8
|
+
}
|
|
9
|
+
set offset(v) {
|
|
10
|
+
this.pos = v;
|
|
11
|
+
}
|
|
12
|
+
get length() {
|
|
13
|
+
return this.view.byteLength;
|
|
14
|
+
}
|
|
15
|
+
byte() {
|
|
16
|
+
return this.view.getUint8(this.pos++);
|
|
17
|
+
}
|
|
18
|
+
word() {
|
|
19
|
+
const v = this.view.getUint16(this.pos, true);
|
|
20
|
+
this.pos += 2;
|
|
21
|
+
return v;
|
|
22
|
+
}
|
|
23
|
+
short() {
|
|
24
|
+
const v = this.view.getInt16(this.pos, true);
|
|
25
|
+
this.pos += 2;
|
|
26
|
+
return v;
|
|
27
|
+
}
|
|
28
|
+
dword() {
|
|
29
|
+
const v = this.view.getUint32(this.pos, true);
|
|
30
|
+
this.pos += 4;
|
|
31
|
+
return v;
|
|
32
|
+
}
|
|
33
|
+
long() {
|
|
34
|
+
const v = this.view.getInt32(this.pos, true);
|
|
35
|
+
this.pos += 4;
|
|
36
|
+
return v;
|
|
37
|
+
}
|
|
38
|
+
bytes(n) {
|
|
39
|
+
const data = new Uint8Array(this.view.buffer, this.pos, n);
|
|
40
|
+
this.pos += n;
|
|
41
|
+
return data;
|
|
42
|
+
}
|
|
43
|
+
skip(n) {
|
|
44
|
+
this.pos += n;
|
|
45
|
+
}
|
|
46
|
+
string() {
|
|
47
|
+
const len = this.word();
|
|
48
|
+
const bytes = this.bytes(len);
|
|
49
|
+
return new TextDecoder("utf-8").decode(bytes);
|
|
50
|
+
}
|
|
64
51
|
}
|
|
65
52
|
class BinaryWriter {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
53
|
+
constructor() {
|
|
54
|
+
this.chunks = [];
|
|
55
|
+
this.tempBuf = new ArrayBuffer(8);
|
|
56
|
+
this.tempView = new DataView(this.tempBuf);
|
|
57
|
+
}
|
|
58
|
+
get byteLength() {
|
|
59
|
+
return this.chunks.reduce((s, c) => s + c.length, 0);
|
|
60
|
+
}
|
|
61
|
+
byte(v) {
|
|
62
|
+
this.chunks.push(new Uint8Array([v & 255]));
|
|
63
|
+
}
|
|
64
|
+
word(v) {
|
|
65
|
+
this.tempView.setUint16(0, v, true);
|
|
66
|
+
this.chunks.push(new Uint8Array(this.tempBuf.slice(0, 2)));
|
|
67
|
+
}
|
|
68
|
+
short(v) {
|
|
69
|
+
this.tempView.setInt16(0, v, true);
|
|
70
|
+
this.chunks.push(new Uint8Array(this.tempBuf.slice(0, 2)));
|
|
71
|
+
}
|
|
72
|
+
dword(v) {
|
|
73
|
+
this.tempView.setUint32(0, v, true);
|
|
74
|
+
this.chunks.push(new Uint8Array(this.tempBuf.slice(0, 4)));
|
|
75
|
+
}
|
|
76
|
+
bytes(data) {
|
|
77
|
+
this.chunks.push(new Uint8Array(data));
|
|
78
|
+
}
|
|
79
|
+
string(s) {
|
|
80
|
+
const encoded = new TextEncoder().encode(s);
|
|
81
|
+
this.word(encoded.length);
|
|
82
|
+
this.bytes(encoded);
|
|
83
|
+
}
|
|
84
|
+
zeros(n) {
|
|
85
|
+
this.chunks.push(new Uint8Array(n));
|
|
86
|
+
}
|
|
87
|
+
toArrayBuffer() {
|
|
88
|
+
const total = this.byteLength;
|
|
89
|
+
const result = new Uint8Array(total);
|
|
90
|
+
let off = 0;
|
|
91
|
+
for (const chunk of this.chunks) {
|
|
92
|
+
result.set(chunk, off);
|
|
93
|
+
off += chunk.length;
|
|
94
|
+
}
|
|
95
|
+
return result.buffer;
|
|
96
|
+
}
|
|
110
97
|
}
|
|
111
|
-
// ── Zlib helpers (browser native) ────────────────────────────
|
|
112
98
|
async function zlibInflate(data) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
99
|
+
try {
|
|
100
|
+
const ds = new DecompressionStream("deflate");
|
|
101
|
+
const writer = ds.writable.getWriter();
|
|
102
|
+
const buffer = data.buffer.slice(
|
|
103
|
+
data.byteOffset,
|
|
104
|
+
data.byteOffset + data.byteLength
|
|
105
|
+
);
|
|
106
|
+
writer.write(new Uint8Array(buffer));
|
|
107
|
+
writer.close();
|
|
108
|
+
const reader = ds.readable.getReader();
|
|
109
|
+
const chunks = [];
|
|
110
|
+
for (; ; ) {
|
|
111
|
+
const { done, value } = await reader.read();
|
|
112
|
+
if (done) {
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
chunks.push(value);
|
|
116
|
+
}
|
|
117
|
+
const total = chunks.reduce((s, c) => s + c.length, 0);
|
|
118
|
+
const result = new Uint8Array(total);
|
|
119
|
+
let off = 0;
|
|
120
|
+
for (const c of chunks) {
|
|
121
|
+
result.set(c, off);
|
|
122
|
+
off += c.length;
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
} catch {
|
|
126
|
+
return data;
|
|
127
|
+
}
|
|
142
128
|
}
|
|
143
129
|
async function zlibDeflate(data) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
130
|
+
try {
|
|
131
|
+
const cs = new CompressionStream("deflate");
|
|
132
|
+
const writer = cs.writable.getWriter();
|
|
133
|
+
const buffer = data.buffer.slice(
|
|
134
|
+
data.byteOffset,
|
|
135
|
+
data.byteOffset + data.byteLength
|
|
136
|
+
);
|
|
137
|
+
writer.write(new Uint8Array(buffer));
|
|
138
|
+
writer.close();
|
|
139
|
+
const reader = cs.readable.getReader();
|
|
140
|
+
const chunks = [];
|
|
141
|
+
for (; ; ) {
|
|
142
|
+
const { done, value } = await reader.read();
|
|
143
|
+
if (done) {
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
chunks.push(value);
|
|
147
|
+
}
|
|
148
|
+
const total = chunks.reduce((s, c) => s + c.length, 0);
|
|
149
|
+
const result = new Uint8Array(total);
|
|
150
|
+
let off = 0;
|
|
151
|
+
for (const c of chunks) {
|
|
152
|
+
result.set(c, off);
|
|
153
|
+
off += c.length;
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
} catch {
|
|
157
|
+
return data;
|
|
158
|
+
}
|
|
172
159
|
}
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
// CEL_EXTRA=0x2006, OLD_PALETTE_1=0x0004, OLD_PALETTE_2=0x0011,
|
|
180
|
-
// USER_DATA=0x2020, SLICE=0x2022, TILESET=0x2023
|
|
181
|
-
const CHUNK_PALETTE = 0x2019;
|
|
182
|
-
const CHUNK_FRAME_TAGS = 0x2018;
|
|
183
|
-
// ── Parse .ase ───────────────────────────────────────────────
|
|
160
|
+
const ASE_MAGIC = 42464;
|
|
161
|
+
const FRAME_MAGIC = 61946;
|
|
162
|
+
const CHUNK_LAYER = 8196;
|
|
163
|
+
const CHUNK_CEL = 8197;
|
|
164
|
+
const CHUNK_PALETTE = 8217;
|
|
165
|
+
const CHUNK_FRAME_TAGS = 8216;
|
|
184
166
|
async function parseAseFile(buffer) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
167
|
+
const r = new BinaryReader(buffer);
|
|
168
|
+
r.dword();
|
|
169
|
+
const magic = r.word();
|
|
170
|
+
if (magic !== ASE_MAGIC) {
|
|
171
|
+
throw new Error(`Not an Aseprite file (magic: 0x${magic.toString(16)})`);
|
|
172
|
+
}
|
|
173
|
+
const numFrames = r.word();
|
|
174
|
+
const width = r.word();
|
|
175
|
+
const height = r.word();
|
|
176
|
+
const colorDepth = r.word();
|
|
177
|
+
r.dword();
|
|
178
|
+
r.word();
|
|
179
|
+
r.skip(8);
|
|
180
|
+
const transparentIndex = r.byte();
|
|
181
|
+
r.skip(3);
|
|
182
|
+
r.word();
|
|
183
|
+
r.byte();
|
|
184
|
+
r.byte();
|
|
185
|
+
r.short();
|
|
186
|
+
r.short();
|
|
187
|
+
r.word();
|
|
188
|
+
r.word();
|
|
189
|
+
r.skip(84);
|
|
190
|
+
const layers = [];
|
|
191
|
+
const palette = [];
|
|
192
|
+
const tags = [];
|
|
193
|
+
const frames = [];
|
|
194
|
+
for (let fr = 0; fr < numFrames; fr++) {
|
|
195
|
+
r.dword();
|
|
196
|
+
const frameMagic = r.word();
|
|
197
|
+
if (frameMagic !== FRAME_MAGIC) {
|
|
198
|
+
throw new Error(`Bad frame magic at frame ${fr}`);
|
|
199
|
+
}
|
|
200
|
+
const oldChunks = r.word();
|
|
201
|
+
const duration = r.word();
|
|
202
|
+
r.skip(2);
|
|
203
|
+
let numChunks = r.dword();
|
|
204
|
+
if (numChunks === 0) {
|
|
205
|
+
numChunks = oldChunks;
|
|
206
|
+
}
|
|
207
|
+
const frame = { duration, cels: [] };
|
|
208
|
+
for (let ch = 0; ch < numChunks; ch++) {
|
|
209
|
+
const chunkStart = r.offset;
|
|
210
|
+
const chunkSize = r.dword();
|
|
211
|
+
const chunkType = r.word();
|
|
212
|
+
const chunkDataEnd = chunkStart + chunkSize;
|
|
213
|
+
switch (chunkType) {
|
|
214
|
+
case CHUNK_LAYER: {
|
|
215
|
+
const flags = r.word();
|
|
216
|
+
const layerType = r.word();
|
|
217
|
+
const childLevel = r.word();
|
|
218
|
+
r.skip(2);
|
|
219
|
+
r.skip(2);
|
|
220
|
+
const blendMode = r.word();
|
|
221
|
+
const opacity = r.byte();
|
|
222
|
+
r.skip(3);
|
|
223
|
+
const name = r.string();
|
|
224
|
+
layers.push({
|
|
225
|
+
name,
|
|
226
|
+
visible: !!(flags & 1),
|
|
227
|
+
opacity,
|
|
228
|
+
blendMode,
|
|
229
|
+
childLevel,
|
|
230
|
+
layerType
|
|
231
|
+
});
|
|
232
|
+
break;
|
|
219
233
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
234
|
+
case CHUNK_CEL: {
|
|
235
|
+
const layerIndex = r.word();
|
|
236
|
+
const x = r.short();
|
|
237
|
+
const y = r.short();
|
|
238
|
+
const opacity = r.byte();
|
|
239
|
+
const celType = r.word();
|
|
240
|
+
r.short();
|
|
241
|
+
r.skip(5);
|
|
242
|
+
if (celType === 0) {
|
|
243
|
+
const cw = r.word();
|
|
244
|
+
const ch2 = r.word();
|
|
245
|
+
const pixelBytes = cw * ch2 * (colorDepth / 8);
|
|
246
|
+
const rawPixels = r.bytes(pixelBytes);
|
|
247
|
+
const rgba = colorDepth === 32 ? new Uint8Array(rawPixels) : convertToRGBA(rawPixels, colorDepth, palette, transparentIndex, cw, ch2);
|
|
248
|
+
frame.cels.push({ layerIndex, x, y, opacity, width: cw, height: ch2, pixels: rgba });
|
|
249
|
+
} else if (celType === 2) {
|
|
250
|
+
const cw = r.word();
|
|
251
|
+
const ch2 = r.word();
|
|
252
|
+
const compressedLen = chunkDataEnd - r.offset;
|
|
253
|
+
const compressed = r.bytes(compressedLen);
|
|
254
|
+
const raw = await zlibInflate(compressed);
|
|
255
|
+
const rgba = colorDepth === 32 ? new Uint8Array(raw) : convertToRGBA(raw, colorDepth, palette, transparentIndex, cw, ch2);
|
|
256
|
+
frame.cels.push({ layerIndex, x, y, opacity, width: cw, height: ch2, pixels: rgba });
|
|
257
|
+
} else if (celType === 1) {
|
|
258
|
+
const linkedFrame = r.word();
|
|
259
|
+
if (linkedFrame < frames.length) {
|
|
260
|
+
const linked = frames[linkedFrame].cels.find((c) => c.layerIndex === layerIndex);
|
|
261
|
+
if (linked) {
|
|
262
|
+
frame.cels.push({ ...linked, x, y, opacity });
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
break;
|
|
226
267
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const opacity = r.byte();
|
|
242
|
-
r.skip(3);
|
|
243
|
-
const name = r.string();
|
|
244
|
-
layers.push({
|
|
245
|
-
name,
|
|
246
|
-
visible: !!(flags & 1),
|
|
247
|
-
opacity,
|
|
248
|
-
blendMode,
|
|
249
|
-
childLevel,
|
|
250
|
-
layerType,
|
|
251
|
-
});
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
case CHUNK_CEL: {
|
|
255
|
-
const layerIndex = r.word();
|
|
256
|
-
const x = r.short();
|
|
257
|
-
const y = r.short();
|
|
258
|
-
const opacity = r.byte();
|
|
259
|
-
const celType = r.word();
|
|
260
|
-
r.short(); // zIndex
|
|
261
|
-
r.skip(5);
|
|
262
|
-
if (celType === 0) {
|
|
263
|
-
// Raw cel
|
|
264
|
-
const cw = r.word();
|
|
265
|
-
const ch2 = r.word();
|
|
266
|
-
const pixelBytes = cw * ch2 * (colorDepth / 8);
|
|
267
|
-
const rawPixels = r.bytes(pixelBytes);
|
|
268
|
-
const rgba = colorDepth === 32
|
|
269
|
-
? new Uint8Array(rawPixels)
|
|
270
|
-
: convertToRGBA(rawPixels, colorDepth, palette, transparentIndex, cw, ch2);
|
|
271
|
-
frame.cels.push({ layerIndex, x, y, opacity, width: cw, height: ch2, pixels: rgba });
|
|
272
|
-
}
|
|
273
|
-
else if (celType === 2) {
|
|
274
|
-
// Compressed cel
|
|
275
|
-
const cw = r.word();
|
|
276
|
-
const ch2 = r.word();
|
|
277
|
-
const compressedLen = chunkDataEnd - r.offset;
|
|
278
|
-
const compressed = r.bytes(compressedLen);
|
|
279
|
-
const raw = await zlibInflate(compressed);
|
|
280
|
-
const rgba = colorDepth === 32
|
|
281
|
-
? new Uint8Array(raw)
|
|
282
|
-
: convertToRGBA(raw, colorDepth, palette, transparentIndex, cw, ch2);
|
|
283
|
-
frame.cels.push({ layerIndex, x, y, opacity, width: cw, height: ch2, pixels: rgba });
|
|
284
|
-
}
|
|
285
|
-
else if (celType === 1) {
|
|
286
|
-
// Linked cel — points to another frame
|
|
287
|
-
const linkedFrame = r.word();
|
|
288
|
-
if (linkedFrame < frames.length) {
|
|
289
|
-
const linked = frames[linkedFrame].cels.find((c) => c.layerIndex === layerIndex);
|
|
290
|
-
if (linked) {
|
|
291
|
-
frame.cels.push({ ...linked, x, y, opacity });
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
// Skip tilemap cels (type 3)
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
case CHUNK_PALETTE: {
|
|
299
|
-
const palSize = r.dword();
|
|
300
|
-
const firstIdx = r.dword();
|
|
301
|
-
const lastIdx = r.dword();
|
|
302
|
-
r.skip(8);
|
|
303
|
-
// Ensure palette array is large enough
|
|
304
|
-
while (palette.length < palSize) {
|
|
305
|
-
palette.push({ r: 0, g: 0, b: 0, a: 255 });
|
|
306
|
-
}
|
|
307
|
-
for (let i = firstIdx; i <= lastIdx; i++) {
|
|
308
|
-
const hasName = r.word();
|
|
309
|
-
const pr = r.byte(), pg = r.byte(), pb = r.byte(), pa = r.byte();
|
|
310
|
-
palette[i] = { r: pr, g: pg, b: pb, a: pa };
|
|
311
|
-
if (hasName & 1) {
|
|
312
|
-
r.string();
|
|
313
|
-
} // skip name
|
|
314
|
-
}
|
|
315
|
-
break;
|
|
316
|
-
}
|
|
317
|
-
case CHUNK_FRAME_TAGS: {
|
|
318
|
-
const numTags = r.word();
|
|
319
|
-
r.skip(8);
|
|
320
|
-
for (let t = 0; t < numTags; t++) {
|
|
321
|
-
const from = r.word();
|
|
322
|
-
const to = r.word();
|
|
323
|
-
const dir = r.byte();
|
|
324
|
-
r.word();
|
|
325
|
-
r.skip(6);
|
|
326
|
-
r.skip(1); // padding
|
|
327
|
-
const tr = r.byte(), tg = r.byte(), tb = r.byte();
|
|
328
|
-
const name = r.string();
|
|
329
|
-
tags.push({ name, from, to, direction: dir, color: { r: tr, g: tg, b: tb, a: 255 } });
|
|
330
|
-
}
|
|
331
|
-
break;
|
|
332
|
-
}
|
|
268
|
+
case CHUNK_PALETTE: {
|
|
269
|
+
const palSize = r.dword();
|
|
270
|
+
const firstIdx = r.dword();
|
|
271
|
+
const lastIdx = r.dword();
|
|
272
|
+
r.skip(8);
|
|
273
|
+
while (palette.length < palSize) {
|
|
274
|
+
palette.push({ r: 0, g: 0, b: 0, a: 255 });
|
|
275
|
+
}
|
|
276
|
+
for (let i = firstIdx; i <= lastIdx; i++) {
|
|
277
|
+
const hasName = r.word();
|
|
278
|
+
const pr = r.byte(), pg = r.byte(), pb = r.byte(), pa = r.byte();
|
|
279
|
+
palette[i] = { r: pr, g: pg, b: pb, a: pa };
|
|
280
|
+
if (hasName & 1) {
|
|
281
|
+
r.string();
|
|
333
282
|
}
|
|
334
|
-
|
|
283
|
+
}
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
case CHUNK_FRAME_TAGS: {
|
|
287
|
+
const numTags = r.word();
|
|
288
|
+
r.skip(8);
|
|
289
|
+
for (let t = 0; t < numTags; t++) {
|
|
290
|
+
const from = r.word();
|
|
291
|
+
const to = r.word();
|
|
292
|
+
const dir = r.byte();
|
|
293
|
+
r.word();
|
|
294
|
+
r.skip(6);
|
|
295
|
+
r.skip(1);
|
|
296
|
+
const tr = r.byte(), tg = r.byte(), tb = r.byte();
|
|
297
|
+
const name = r.string();
|
|
298
|
+
tags.push({ name, from, to, direction: dir, color: { r: tr, g: tg, b: tb, a: 255 } });
|
|
299
|
+
}
|
|
300
|
+
break;
|
|
335
301
|
}
|
|
336
|
-
|
|
302
|
+
}
|
|
303
|
+
r.offset = chunkDataEnd;
|
|
337
304
|
}
|
|
338
|
-
|
|
305
|
+
frames.push(frame);
|
|
306
|
+
}
|
|
307
|
+
return { width, height, colorDepth, frames, layers, palette, tags, transparentIndex };
|
|
339
308
|
}
|
|
340
309
|
function convertToRGBA(raw, depth, palette, transIdx, w, h) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
return rgba;
|
|
310
|
+
const rgba = new Uint8Array(w * h * 4);
|
|
311
|
+
if (depth === 16) {
|
|
312
|
+
for (let i = 0; i < w * h; i++) {
|
|
313
|
+
const v = raw[i * 2], a = raw[i * 2 + 1];
|
|
314
|
+
rgba[i * 4] = v;
|
|
315
|
+
rgba[i * 4 + 1] = v;
|
|
316
|
+
rgba[i * 4 + 2] = v;
|
|
317
|
+
rgba[i * 4 + 3] = a;
|
|
318
|
+
}
|
|
319
|
+
} else if (depth === 8) {
|
|
320
|
+
for (let i = 0; i < w * h; i++) {
|
|
321
|
+
const idx = raw[i];
|
|
322
|
+
if (idx === transIdx) {
|
|
323
|
+
rgba[i * 4 + 3] = 0;
|
|
324
|
+
} else if (idx < palette.length) {
|
|
325
|
+
const c = palette[idx];
|
|
326
|
+
rgba[i * 4] = c.r;
|
|
327
|
+
rgba[i * 4 + 1] = c.g;
|
|
328
|
+
rgba[i * 4 + 2] = c.b;
|
|
329
|
+
rgba[i * 4 + 3] = c.a;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return rgba;
|
|
369
334
|
}
|
|
370
|
-
// ── Write .ase ───────────────────────────────────────────────
|
|
371
335
|
async function writeAseFile(doc) {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
chunk.byte(c.r);
|
|
409
|
-
chunk.byte(c.g);
|
|
410
|
-
chunk.byte(c.b);
|
|
411
|
-
chunk.byte(c.a);
|
|
412
|
-
}
|
|
413
|
-
const chunkData = chunk.toArrayBuffer();
|
|
414
|
-
fw.dword(chunkData.byteLength + 6);
|
|
415
|
-
fw.word(CHUNK_PALETTE);
|
|
416
|
-
fw.bytes(new Uint8Array(chunkData));
|
|
417
|
-
numChunks++;
|
|
418
|
-
}
|
|
419
|
-
// Frame tags
|
|
420
|
-
if (doc.tags.length > 0) {
|
|
421
|
-
const chunk = new BinaryWriter();
|
|
422
|
-
chunk.word(doc.tags.length);
|
|
423
|
-
chunk.zeros(8);
|
|
424
|
-
for (const tag of doc.tags) {
|
|
425
|
-
chunk.word(tag.from);
|
|
426
|
-
chunk.word(tag.to);
|
|
427
|
-
chunk.byte(tag.direction);
|
|
428
|
-
chunk.word(0); // repeat
|
|
429
|
-
chunk.zeros(6);
|
|
430
|
-
chunk.byte(0); // padding
|
|
431
|
-
chunk.byte(tag.color.r);
|
|
432
|
-
chunk.byte(tag.color.g);
|
|
433
|
-
chunk.byte(tag.color.b);
|
|
434
|
-
chunk.string(tag.name);
|
|
435
|
-
}
|
|
436
|
-
const chunkData = chunk.toArrayBuffer();
|
|
437
|
-
fw.dword(chunkData.byteLength + 6);
|
|
438
|
-
fw.word(CHUNK_FRAME_TAGS);
|
|
439
|
-
fw.bytes(new Uint8Array(chunkData));
|
|
440
|
-
numChunks++;
|
|
441
|
-
}
|
|
336
|
+
const frameBuffers = [];
|
|
337
|
+
for (let fr = 0; fr < doc.frames.length; fr++) {
|
|
338
|
+
const frame = doc.frames[fr];
|
|
339
|
+
const fw = new BinaryWriter();
|
|
340
|
+
let numChunks = 0;
|
|
341
|
+
if (fr === 0) {
|
|
342
|
+
for (const layer of doc.layers) {
|
|
343
|
+
const chunk = new BinaryWriter();
|
|
344
|
+
const flags = layer.visible ? 1 : 0;
|
|
345
|
+
chunk.word(flags);
|
|
346
|
+
chunk.word(layer.layerType);
|
|
347
|
+
chunk.word(layer.childLevel);
|
|
348
|
+
chunk.word(0);
|
|
349
|
+
chunk.word(0);
|
|
350
|
+
chunk.word(layer.blendMode);
|
|
351
|
+
chunk.byte(layer.opacity);
|
|
352
|
+
chunk.zeros(3);
|
|
353
|
+
chunk.string(layer.name);
|
|
354
|
+
const chunkData = chunk.toArrayBuffer();
|
|
355
|
+
fw.dword(chunkData.byteLength + 6);
|
|
356
|
+
fw.word(CHUNK_LAYER);
|
|
357
|
+
fw.bytes(new Uint8Array(chunkData));
|
|
358
|
+
numChunks++;
|
|
359
|
+
}
|
|
360
|
+
if (doc.palette.length > 0) {
|
|
361
|
+
const chunk = new BinaryWriter();
|
|
362
|
+
chunk.dword(doc.palette.length);
|
|
363
|
+
chunk.dword(0);
|
|
364
|
+
chunk.dword(doc.palette.length - 1);
|
|
365
|
+
chunk.zeros(8);
|
|
366
|
+
for (const c of doc.palette) {
|
|
367
|
+
chunk.word(0);
|
|
368
|
+
chunk.byte(c.r);
|
|
369
|
+
chunk.byte(c.g);
|
|
370
|
+
chunk.byte(c.b);
|
|
371
|
+
chunk.byte(c.a);
|
|
442
372
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
373
|
+
const chunkData = chunk.toArrayBuffer();
|
|
374
|
+
fw.dword(chunkData.byteLength + 6);
|
|
375
|
+
fw.word(CHUNK_PALETTE);
|
|
376
|
+
fw.bytes(new Uint8Array(chunkData));
|
|
377
|
+
numChunks++;
|
|
378
|
+
}
|
|
379
|
+
if (doc.tags.length > 0) {
|
|
380
|
+
const chunk = new BinaryWriter();
|
|
381
|
+
chunk.word(doc.tags.length);
|
|
382
|
+
chunk.zeros(8);
|
|
383
|
+
for (const tag of doc.tags) {
|
|
384
|
+
chunk.word(tag.from);
|
|
385
|
+
chunk.word(tag.to);
|
|
386
|
+
chunk.byte(tag.direction);
|
|
387
|
+
chunk.word(0);
|
|
388
|
+
chunk.zeros(6);
|
|
389
|
+
chunk.byte(0);
|
|
390
|
+
chunk.byte(tag.color.r);
|
|
391
|
+
chunk.byte(tag.color.g);
|
|
392
|
+
chunk.byte(tag.color.b);
|
|
393
|
+
chunk.string(tag.name);
|
|
463
394
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
395
|
+
const chunkData = chunk.toArrayBuffer();
|
|
396
|
+
fw.dword(chunkData.byteLength + 6);
|
|
397
|
+
fw.word(CHUNK_FRAME_TAGS);
|
|
398
|
+
fw.bytes(new Uint8Array(chunkData));
|
|
399
|
+
numChunks++;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
for (const cel of frame.cels) {
|
|
403
|
+
const chunk = new BinaryWriter();
|
|
404
|
+
chunk.word(cel.layerIndex);
|
|
405
|
+
chunk.short(cel.x);
|
|
406
|
+
chunk.short(cel.y);
|
|
407
|
+
chunk.byte(cel.opacity);
|
|
408
|
+
const compressed = await zlibDeflate(cel.pixels);
|
|
409
|
+
chunk.word(2);
|
|
410
|
+
chunk.short(0);
|
|
411
|
+
chunk.zeros(5);
|
|
412
|
+
chunk.word(cel.width);
|
|
413
|
+
chunk.word(cel.height);
|
|
414
|
+
chunk.bytes(compressed);
|
|
415
|
+
const chunkData = chunk.toArrayBuffer();
|
|
416
|
+
fw.dword(chunkData.byteLength + 6);
|
|
417
|
+
fw.word(CHUNK_CEL);
|
|
418
|
+
fw.bytes(new Uint8Array(chunkData));
|
|
419
|
+
numChunks++;
|
|
420
|
+
}
|
|
421
|
+
const frameData = fw.toArrayBuffer();
|
|
422
|
+
const fh = new BinaryWriter();
|
|
423
|
+
fh.dword(frameData.byteLength + 16);
|
|
424
|
+
fh.word(FRAME_MAGIC);
|
|
425
|
+
fh.word(numChunks > 65535 ? 65535 : numChunks);
|
|
426
|
+
fh.word(frame.duration);
|
|
427
|
+
fh.zeros(2);
|
|
428
|
+
fh.dword(numChunks);
|
|
429
|
+
const headerBuf2 = fh.toArrayBuffer();
|
|
430
|
+
const combined = new Uint8Array(headerBuf2.byteLength + frameData.byteLength);
|
|
431
|
+
combined.set(new Uint8Array(headerBuf2), 0);
|
|
432
|
+
combined.set(new Uint8Array(frameData), headerBuf2.byteLength);
|
|
433
|
+
frameBuffers.push(combined.buffer);
|
|
434
|
+
}
|
|
435
|
+
const framesTotal = frameBuffers.reduce((s, b) => s + b.byteLength, 0);
|
|
436
|
+
const fileSize = 128 + framesTotal;
|
|
437
|
+
const header = new BinaryWriter();
|
|
438
|
+
header.dword(fileSize);
|
|
439
|
+
header.word(ASE_MAGIC);
|
|
440
|
+
header.word(doc.frames.length);
|
|
441
|
+
header.word(doc.width);
|
|
442
|
+
header.word(doc.height);
|
|
443
|
+
header.word(doc.colorDepth);
|
|
444
|
+
header.dword(1);
|
|
445
|
+
header.word(100);
|
|
446
|
+
header.dword(0);
|
|
447
|
+
header.dword(0);
|
|
448
|
+
header.byte(doc.transparentIndex);
|
|
449
|
+
header.zeros(3);
|
|
450
|
+
header.word(doc.palette.length || 0);
|
|
451
|
+
header.byte(1);
|
|
452
|
+
header.byte(1);
|
|
453
|
+
header.short(0);
|
|
454
|
+
header.short(0);
|
|
455
|
+
header.word(16);
|
|
456
|
+
header.word(16);
|
|
457
|
+
header.zeros(84);
|
|
458
|
+
const headerBuf = header.toArrayBuffer();
|
|
459
|
+
const file = new Uint8Array(fileSize);
|
|
460
|
+
file.set(new Uint8Array(headerBuf), 0);
|
|
461
|
+
let off = 128;
|
|
462
|
+
for (const fb of frameBuffers) {
|
|
463
|
+
file.set(new Uint8Array(fb), off);
|
|
464
|
+
off += fb.byteLength;
|
|
465
|
+
}
|
|
466
|
+
return file.buffer;
|
|
514
467
|
}
|
|
515
|
-
// ── Convenience: create empty AseDocument ────────────────────
|
|
516
468
|
function createEmptyAseDocument(width = 64, height = 64) {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
469
|
+
const pixels = new Uint8Array(width * height * 4);
|
|
470
|
+
return {
|
|
471
|
+
width,
|
|
472
|
+
height,
|
|
473
|
+
colorDepth: 32,
|
|
474
|
+
frames: [
|
|
475
|
+
{ duration: 100, cels: [{ layerIndex: 0, x: 0, y: 0, opacity: 255, width, height, pixels }] }
|
|
476
|
+
],
|
|
477
|
+
layers: [
|
|
478
|
+
{ name: "Layer 1", visible: true, opacity: 255, blendMode: 0, childLevel: 0, layerType: 0 }
|
|
479
|
+
],
|
|
480
|
+
palette: defaultPalette(),
|
|
481
|
+
tags: [],
|
|
482
|
+
transparentIndex: 0
|
|
483
|
+
};
|
|
532
484
|
}
|
|
533
485
|
function defaultPalette() {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
486
|
+
const hex = [
|
|
487
|
+
"var(--nice-text, #000000)",
|
|
488
|
+
"#1d2b53",
|
|
489
|
+
"#7e2553",
|
|
490
|
+
"#008751",
|
|
491
|
+
"#ab5236",
|
|
492
|
+
"#5f574f",
|
|
493
|
+
"#c2c3c7",
|
|
494
|
+
"#fff1e8",
|
|
495
|
+
"#ff004d",
|
|
496
|
+
"#ffa300",
|
|
497
|
+
"#ffec27",
|
|
498
|
+
"#00e436",
|
|
499
|
+
"#29adff",
|
|
500
|
+
"#83769c",
|
|
501
|
+
"#ff77a8",
|
|
502
|
+
"#ffccaa",
|
|
503
|
+
"#291814",
|
|
504
|
+
"#111d35",
|
|
505
|
+
"#422136",
|
|
506
|
+
"#125359",
|
|
507
|
+
"#742f29",
|
|
508
|
+
"#49333b",
|
|
509
|
+
"#a28879",
|
|
510
|
+
"#f2e8cf",
|
|
511
|
+
"#be1250",
|
|
512
|
+
"#ff6c24",
|
|
513
|
+
"#ffd726",
|
|
514
|
+
"#44891a",
|
|
515
|
+
"#1d6aff",
|
|
516
|
+
"#6b3a89",
|
|
517
|
+
"#ff5577",
|
|
518
|
+
"#eebb77"
|
|
519
|
+
];
|
|
520
|
+
return hex.map((h) => {
|
|
521
|
+
const r = parseInt(h.slice(1, 3), 16);
|
|
522
|
+
const g = parseInt(h.slice(3, 5), 16);
|
|
523
|
+
const b = parseInt(h.slice(5, 7), 16);
|
|
524
|
+
return { r, g, b, a: 255 };
|
|
525
|
+
});
|
|
574
526
|
}
|
|
575
527
|
function aseColorToHex(c) {
|
|
576
|
-
|
|
528
|
+
return "#" + [c.r, c.g, c.b].map((v) => v.toString(16).padStart(2, "0")).join("");
|
|
577
529
|
}
|
|
578
530
|
function hexToAseColor(hex) {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
531
|
+
const h = hex.startsWith("#") ? hex.slice(1) : hex;
|
|
532
|
+
return {
|
|
533
|
+
r: parseInt(h.slice(0, 2), 16),
|
|
534
|
+
g: parseInt(h.slice(2, 4), 16),
|
|
535
|
+
b: parseInt(h.slice(4, 6), 16),
|
|
536
|
+
a: 255
|
|
537
|
+
};
|
|
586
538
|
}
|
|
587
|
-
|
|
588
|
-
|
|
539
|
+
export {
|
|
540
|
+
aseColorToHex,
|
|
541
|
+
createEmptyAseDocument,
|
|
542
|
+
defaultPalette,
|
|
543
|
+
hexToAseColor,
|
|
544
|
+
parseAseFile,
|
|
545
|
+
writeAseFile
|
|
546
|
+
};
|