@4bitlabs/sci0 5.0.0 → 6.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/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/index.d.ts +25 -26
- package/dist/index.js +11 -46
- package/dist/models/cel.d.ts +7 -4
- package/dist/models/cel.d.ts.map +1 -1
- package/dist/models/cursor.d.ts +6 -3
- package/dist/models/cursor.d.ts.map +1 -1
- package/dist/models/draw-codes.d.ts +4 -5
- package/dist/models/draw-codes.d.ts.map +1 -1
- package/dist/models/draw-command.d.ts +5 -2
- package/dist/models/draw-command.d.ts.map +1 -1
- package/dist/models/draw-commands.d.ts +16 -46
- package/dist/models/draw-commands.d.ts.map +1 -1
- package/dist/models/draw-mode.d.ts +21 -18
- package/dist/models/draw-mode.d.ts.map +1 -1
- package/dist/models/draw-mode.js +20 -25
- package/dist/models/draw-mode.js.map +1 -1
- package/dist/models/font-face.d.ts +7 -4
- package/dist/models/font-face.d.ts.map +1 -1
- package/dist/models/pattern-code.d.ts +4 -5
- package/dist/models/pattern-code.d.ts.map +1 -1
- package/dist/models/pic.d.ts +6 -3
- package/dist/models/pic.d.ts.map +1 -1
- package/dist/models/resource-header.d.ts +12 -9
- package/dist/models/resource-header.d.ts.map +1 -1
- package/dist/models/resource-id.d.ts +10 -5
- package/dist/models/resource-id.d.ts.map +1 -1
- package/dist/models/resource-id.js +28 -36
- package/dist/models/resource-id.js.map +1 -1
- package/dist/models/resource-map.d.ts +7 -4
- package/dist/models/resource-map.d.ts.map +1 -1
- package/dist/models/resource-type.d.ts +5 -2
- package/dist/models/resource-type.d.ts.map +1 -1
- package/dist/models/resource-types.d.ts +15 -10
- package/dist/models/resource-types.d.ts.map +1 -1
- package/dist/models/resource-types.js +17 -13
- package/dist/models/resource-types.js.map +1 -1
- package/dist/models/view.d.ts +16 -13
- package/dist/models/view.d.ts.map +1 -1
- package/dist/parsers/compression.d.ts +4 -1
- package/dist/parsers/compression.d.ts.map +1 -1
- package/dist/parsers/compression.js +36 -54
- package/dist/parsers/compression.js.map +1 -1
- package/dist/parsers/mapping.d.ts +5 -3
- package/dist/parsers/mapping.d.ts.map +1 -1
- package/dist/parsers/mapping.js +18 -23
- package/dist/parsers/mapping.js.map +1 -1
- package/dist/parsers/parse-cel.js +26 -29
- package/dist/parsers/parse-cel.js.map +1 -1
- package/dist/parsers/parse-cursor-options.d.ts +10 -7
- package/dist/parsers/parse-cursor-options.d.ts.map +1 -1
- package/dist/parsers/parse-cursor.d.ts +6 -3
- package/dist/parsers/parse-cursor.d.ts.map +1 -1
- package/dist/parsers/parse-cursor.js +34 -36
- package/dist/parsers/parse-cursor.js.map +1 -1
- package/dist/parsers/parse-font-options.d.ts +6 -3
- package/dist/parsers/parse-font-options.d.ts.map +1 -1
- package/dist/parsers/parse-font.d.ts +6 -3
- package/dist/parsers/parse-font.d.ts.map +1 -1
- package/dist/parsers/parse-font.js +27 -30
- package/dist/parsers/parse-font.js.map +1 -1
- package/dist/parsers/parse-pic.d.ts +8 -5
- package/dist/parsers/parse-pic.d.ts.map +1 -1
- package/dist/parsers/parse-pic.js +22 -29
- package/dist/parsers/parse-pic.js.map +1 -1
- package/dist/parsers/parse-view.d.ts +5 -2
- package/dist/parsers/parse-view.d.ts.map +1 -1
- package/dist/parsers/parse-view.js +45 -41
- package/dist/parsers/parse-view.js.map +1 -1
- package/dist/parsers/pic/handlers.js +272 -208
- package/dist/parsers/pic/handlers.js.map +1 -1
- package/dist/parsers/pic/op-codes.js +37 -45
- package/dist/parsers/pic/op-codes.js.map +1 -1
- package/dist/parsers/pic/pic-state.js +16 -8
- package/dist/parsers/pic/pic-state.js.map +1 -1
- package/dist/parsers/pic/points.js +19 -45
- package/dist/parsers/pic/points.js.map +1 -1
- package/dist/parsers/resource-header.d.ts +6 -3
- package/dist/parsers/resource-header.d.ts.map +1 -1
- package/dist/parsers/resource-header.js +15 -20
- package/dist/parsers/resource-header.js.map +1 -1
- package/dist/utils/exhaustive.js +5 -4
- package/dist/utils/exhaustive.js.map +1 -1
- package/dist/utils/repeat.js +5 -7
- package/dist/utils/repeat.js.map +1 -1
- package/package.json +17 -15
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/models/cel.js +0 -3
- package/dist/models/cel.js.map +0 -1
- package/dist/models/cursor.js +0 -3
- package/dist/models/cursor.js.map +0 -1
- package/dist/models/draw-codes.js +0 -3
- package/dist/models/draw-codes.js.map +0 -1
- package/dist/models/draw-command.js +0 -3
- package/dist/models/draw-command.js.map +0 -1
- package/dist/models/draw-commands.js +0 -3
- package/dist/models/draw-commands.js.map +0 -1
- package/dist/models/font-face.js +0 -3
- package/dist/models/font-face.js.map +0 -1
- package/dist/models/pattern-code.js +0 -3
- package/dist/models/pattern-code.js.map +0 -1
- package/dist/models/pic.js +0 -3
- package/dist/models/pic.js.map +0 -1
- package/dist/models/resource-header.js +0 -3
- package/dist/models/resource-header.js.map +0 -1
- package/dist/models/resource-map.js +0 -3
- package/dist/models/resource-map.js.map +0 -1
- package/dist/models/resource-type.js +0 -3
- package/dist/models/resource-type.js.map +0 -1
- package/dist/models/view.js +0 -3
- package/dist/models/view.js.map +0 -1
- package/dist/parsers/parse-cel.d.ts +0 -3
- package/dist/parsers/parse-cel.d.ts.map +0 -1
- package/dist/parsers/parse-cursor-options.js +0 -3
- package/dist/parsers/parse-cursor-options.js.map +0 -1
- package/dist/parsers/parse-font-options.js +0 -3
- package/dist/parsers/parse-font-options.js.map +0 -1
- package/dist/parsers/pic/handlers.d.ts +0 -8
- package/dist/parsers/pic/handlers.d.ts.map +0 -1
- package/dist/parsers/pic/op-codes.d.ts +0 -32
- package/dist/parsers/pic/op-codes.d.ts.map +0 -1
- package/dist/parsers/pic/pic-state.d.ts +0 -10
- package/dist/parsers/pic/pic-state.d.ts.map +0 -1
- package/dist/parsers/pic/points.d.ts +0 -6
- package/dist/parsers/pic/points.d.ts.map +0 -1
- package/dist/utils/exhaustive.d.ts +0 -2
- package/dist/utils/exhaustive.d.ts.map +0 -1
- package/dist/utils/repeat.d.ts +0 -2
- package/dist/utils/repeat.d.ts.map +0 -1
|
@@ -1,33 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const image_1 = require("@4bitlabs/image");
|
|
5
|
-
const repeat_1 = require("../utils/repeat");
|
|
1
|
+
import { repeat } from "../utils/repeat.js";
|
|
2
|
+
import { createIndexedPixelData } from "@4bitlabs/image";
|
|
3
|
+
//#region src/parsers/parse-font.ts
|
|
6
4
|
const parseFont = (source, options = {}) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
characters,
|
|
29
|
-
lineHeight,
|
|
30
|
-
};
|
|
5
|
+
const { color = 15, keyColor = 0 } = options;
|
|
6
|
+
const headerView = new DataView(source.buffer, source.byteOffset, 6);
|
|
7
|
+
const count = headerView.getUint16(2, true);
|
|
8
|
+
const lineHeight = headerView.getUint16(4, true);
|
|
9
|
+
const pointersView = new DataView(source.buffer, source.byteOffset + 6, count * 2);
|
|
10
|
+
return {
|
|
11
|
+
characters: repeat(count, (i) => pointersView.getUint16(i * 2, true)).map((offset) => {
|
|
12
|
+
const [width, height] = [source[offset], source[offset + 1]];
|
|
13
|
+
const widthBytes = width + 7 >>> 3;
|
|
14
|
+
const image = createIndexedPixelData(width, height, { keyColor });
|
|
15
|
+
for (let y = 0; y < height; y++) {
|
|
16
|
+
const yOffset = offset + 2 + y * widthBytes;
|
|
17
|
+
for (let x = 0; x < width; x++) {
|
|
18
|
+
const bit = source[yOffset + (x >>> 3)] >>> 7 - (x & 7) & 1;
|
|
19
|
+
image.pixels[x + y * width] = bit ? color : keyColor;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return image;
|
|
23
|
+
}),
|
|
24
|
+
lineHeight
|
|
25
|
+
};
|
|
31
26
|
};
|
|
32
|
-
|
|
27
|
+
//#endregion
|
|
28
|
+
export { parseFont };
|
|
29
|
+
|
|
33
30
|
//# sourceMappingURL=parse-font.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-font.js","
|
|
1
|
+
{"version":3,"file":"parse-font.js","names":[],"sources":["../../src/parsers/parse-font.ts"],"sourcesContent":["import { createIndexedPixelData, type IndexedPixelData } from '@4bitlabs/image';\nimport type { FontFace } from '../models/font-face.js';\nimport { repeat } from '../utils/repeat.js';\nimport type { ParseFontOptions } from './parse-font-options.js';\n\nexport const parseFont = (\n source: Uint8Array,\n options: ParseFontOptions = {},\n): FontFace => {\n const { color = 0x0f, keyColor = 0x00 } = options;\n\n const headerView = new DataView(source.buffer, source.byteOffset, 6);\n const count = headerView.getUint16(2, true);\n const lineHeight = headerView.getUint16(4, true);\n\n const pointersView = new DataView(\n source.buffer,\n source.byteOffset + 6,\n count * 2,\n );\n const pointers = repeat(count, (i) => pointersView.getUint16(i * 2, true));\n\n const characters = pointers.map<IndexedPixelData>((offset) => {\n const [width, height] = [source[offset], source[offset + 1]];\n\n const widthBytes = (width + 7) >>> 3;\n\n const image = createIndexedPixelData(width, height, { keyColor });\n\n for (let y = 0; y < height; y++) {\n const yOffset = offset + 2 + y * widthBytes;\n\n for (let x = 0; x < width; x++) {\n const idx = yOffset + (x >>> 3);\n const bit = (source[idx] >>> (7 - (x & 0b111))) & 1;\n image.pixels[x + y * width] = bit ? color : keyColor;\n }\n }\n return image;\n });\n\n return {\n characters,\n lineHeight,\n };\n};\n"],"mappings":";;;AAKA,MAAa,aACX,QACA,UAA4B,CAAC,MAChB;CACb,MAAM,EAAE,QAAQ,IAAM,WAAW,MAAS;CAE1C,MAAM,aAAa,IAAI,SAAS,OAAO,QAAQ,OAAO,YAAY,CAAC;CACnE,MAAM,QAAQ,WAAW,UAAU,GAAG,IAAI;CAC1C,MAAM,aAAa,WAAW,UAAU,GAAG,IAAI;CAE/C,MAAM,eAAe,IAAI,SACvB,OAAO,QACP,OAAO,aAAa,GACpB,QAAQ,CACV;CAsBA,OAAO;EACL,YAtBe,OAAO,QAAQ,MAAM,aAAa,UAAU,IAAI,GAAG,IAAI,CAE9C,CAAC,CAAC,KAAuB,WAAW;GAC5D,MAAM,CAAC,OAAO,UAAU,CAAC,OAAO,SAAS,OAAO,SAAS,EAAE;GAE3D,MAAM,aAAc,QAAQ,MAAO;GAEnC,MAAM,QAAQ,uBAAuB,OAAO,QAAQ,EAAE,SAAS,CAAC;GAEhE,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK;IAC/B,MAAM,UAAU,SAAS,IAAI,IAAI;IAEjC,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;KAE9B,MAAM,MAAO,OADD,WAAW,MAAM,QACC,KAAK,IAAI,KAAW;KAClD,MAAM,OAAO,IAAI,IAAI,SAAS,MAAM,QAAQ;IAC9C;GACF;GACA,OAAO;EACT,CAGW;EACT;CACF;AACF"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { DrawCommand } from "../models/draw-command.js";
|
|
2
|
+
import { Pic } from "../models/pic.js";
|
|
3
|
+
//#region src/parsers/parse-pic.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* Parse a {@link Pic} resource from bytes.
|
|
5
6
|
*
|
|
6
7
|
* @param source
|
|
7
8
|
* @returns Parsed draw commands as an array.
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
+
declare function parsePic(source: Uint8Array): DrawCommand[];
|
|
10
11
|
/**
|
|
11
12
|
* Parse a {@link Pic} resource from bytes.
|
|
12
13
|
*
|
|
@@ -14,7 +15,9 @@ export declare function parsePic(source: Uint8Array): DrawCommand[];
|
|
|
14
15
|
* @param options
|
|
15
16
|
* @param options.defer Return an {@link !Iterable} of {@link DrawCommand} that will parse source on demand.
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
declare function parsePic(source: Uint8Array, options: {
|
|
19
|
+
defer: true;
|
|
19
20
|
}): Pic;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { parsePic };
|
|
20
23
|
//# sourceMappingURL=parse-pic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-pic.d.ts","
|
|
1
|
+
{"version":3,"file":"parse-pic.d.ts","names":[],"sources":["../../src/parsers/parse-pic.ts"],"mappings":";;;;;;;;;iBA+BgB,SAAS,QAAQ,aAAa;;;;;;;;iBAQ9B,SAAS,QAAQ,YAAY;EAAW;IAAgB"}
|
|
@@ -1,34 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const op_codes_1 = require("./pic/op-codes");
|
|
7
|
-
const pic_state_1 = require("./pic/pic-state");
|
|
1
|
+
import { isOpCode } from "./pic/op-codes.js";
|
|
2
|
+
import { CodeHandlers } from "./pic/handlers.js";
|
|
3
|
+
import { createPicState } from "./pic/pic-state.js";
|
|
4
|
+
import { createBitReader } from "@4bitlabs/readers";
|
|
5
|
+
//#region src/parsers/parse-pic.ts
|
|
8
6
|
function* picIterable(source) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (!handler)
|
|
20
|
-
throw new Error(`Unhandled opcode: 0x${op.toString(16)}`);
|
|
21
|
-
yield* handler(r, state);
|
|
22
|
-
}
|
|
7
|
+
const r = createBitReader(source, { mode: "msb" });
|
|
8
|
+
const state = createPicState();
|
|
9
|
+
while (true) {
|
|
10
|
+
const op = r.read32(8);
|
|
11
|
+
if (!isOpCode(op)) throw new Error(`Unrecognized opcode: 0x${op.toString(16)}`);
|
|
12
|
+
if (op === 255) break;
|
|
13
|
+
const handler = CodeHandlers[op];
|
|
14
|
+
if (!handler) throw new Error(`Unhandled opcode: 0x${op.toString(16)}`);
|
|
15
|
+
yield* handler(r, state);
|
|
16
|
+
}
|
|
23
17
|
}
|
|
24
18
|
function parsePic(source, options = {}) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return picIterable(source);
|
|
30
|
-
},
|
|
31
|
-
}
|
|
32
|
-
: [...picIterable(source)];
|
|
19
|
+
const { defer } = options;
|
|
20
|
+
return defer ? { [Symbol.iterator]() {
|
|
21
|
+
return picIterable(source);
|
|
22
|
+
} } : [...picIterable(source)];
|
|
33
23
|
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { parsePic };
|
|
26
|
+
|
|
34
27
|
//# sourceMappingURL=parse-pic.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-pic.js","
|
|
1
|
+
{"version":3,"file":"parse-pic.js","names":[],"sources":["../../src/parsers/parse-pic.ts"],"sourcesContent":["import { createBitReader } from '@4bitlabs/readers';\nimport { CodeHandlers } from './pic/handlers.js';\nimport { OpCode, isOpCode } from './pic/op-codes.js';\nimport { createPicState } from './pic/pic-state.js';\nimport type { DrawCommand } from '../models/draw-command.js';\nimport type { Pic } from '../models/pic.js';\n\nfunction* picIterable(source: Uint8Array): IterableIterator<DrawCommand> {\n const r = createBitReader(source, { mode: 'msb' });\n const state = createPicState();\n while (true) {\n const op = r.read32(8);\n\n if (!isOpCode(op))\n throw new Error(`Unrecognized opcode: 0x${op.toString(16)}`);\n\n if (op === OpCode.Done) break;\n\n const handler = CodeHandlers[op];\n if (!handler) throw new Error(`Unhandled opcode: 0x${op.toString(16)}`);\n\n yield* handler(r, state);\n }\n}\n\n/**\n * Parse a {@link Pic} resource from bytes.\n *\n * @param source\n * @returns Parsed draw commands as an array.\n */\nexport function parsePic(source: Uint8Array): DrawCommand[];\n/**\n * Parse a {@link Pic} resource from bytes.\n *\n * @param source\n * @param options\n * @param options.defer Return an {@link !Iterable} of {@link DrawCommand} that will parse source on demand.\n */\nexport function parsePic(source: Uint8Array, options: { defer: true }): Pic;\nexport function parsePic(\n source: Uint8Array,\n options: { defer?: boolean } = {},\n): Pic {\n const { defer } = options;\n return defer\n ? {\n [Symbol.iterator](): Iterator<DrawCommand, void, undefined> {\n return picIterable(source);\n },\n }\n : [...picIterable(source)];\n}\n"],"mappings":";;;;;AAOA,UAAU,YAAY,QAAmD;CACvE,MAAM,IAAI,gBAAgB,QAAQ,EAAE,MAAM,MAAM,CAAC;CACjD,MAAM,QAAQ,eAAe;CAC7B,OAAO,MAAM;EACX,MAAM,KAAK,EAAE,OAAO,CAAC;EAErB,IAAI,CAAC,SAAS,EAAE,GACd,MAAM,IAAI,MAAM,0BAA0B,GAAG,SAAS,EAAE,GAAG;EAE7D,IAAI,OAAA,KAAoB;EAExB,MAAM,UAAU,aAAa;EAC7B,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,uBAAuB,GAAG,SAAS,EAAE,GAAG;EAEtE,OAAO,QAAQ,GAAG,KAAK;CACzB;AACF;AAiBA,SAAgB,SACd,QACA,UAA+B,CAAC,GAC3B;CACL,MAAM,EAAE,UAAU;CAClB,OAAO,QACH,EACE,CAAC,OAAO,YAAoD;EAC1D,OAAO,YAAY,MAAM;CAC3B,EACF,IACA,CAAC,GAAG,YAAY,MAAM,CAAC;AAC7B"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { View } from "../models/view.js";
|
|
2
|
+
//#region src/parsers/parse-view.d.ts
|
|
3
|
+
declare const parseView: (source: Uint8Array) => View;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { parseView };
|
|
3
6
|
//# sourceMappingURL=parse-view.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-view.d.ts","
|
|
1
|
+
{"version":3,"file":"parse-view.d.ts","names":[],"sources":["../../src/parsers/parse-view.ts"],"mappings":";;cAIa,YAAa,QAAQ,eAAa"}
|
|
@@ -1,44 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const parse_cel_1 = require("./parse-cel");
|
|
5
|
-
const repeat_1 = require("../utils/repeat");
|
|
1
|
+
import { repeat } from "../utils/repeat.js";
|
|
2
|
+
import { parseCel } from "./parse-cel.js";
|
|
3
|
+
//#region src/parsers/parse-view.ts
|
|
6
4
|
const parseView = (source) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
5
|
+
const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
|
|
6
|
+
const groupCount = view.getUint16(0, true);
|
|
7
|
+
const mirrored = view.getUint16(2, true);
|
|
8
|
+
return repeat(groupCount, (groupIdx) => {
|
|
9
|
+
const groupOffset = view.getUint16(8 + groupIdx * 2, true);
|
|
10
|
+
const groupView = new DataView(source.buffer, source.byteOffset + groupOffset);
|
|
11
|
+
const frameCount = groupView.getUint16(0, true);
|
|
12
|
+
const isMirrored = (mirrored & 1 << groupIdx) !== 0;
|
|
13
|
+
const frames = repeat(frameCount, (frameIdx) => {
|
|
14
|
+
const frameOffset = groupView.getUint16(frameIdx * 2 + 4, true);
|
|
15
|
+
return parseCel(new DataView(source.buffer, source.byteOffset + frameOffset));
|
|
16
|
+
});
|
|
17
|
+
const [left, top, right, bottom] = frames.reduce(([x0, y0, x1, y1], { width, height, dx, dy }) => {
|
|
18
|
+
const fLeft = -(width >>> 1);
|
|
19
|
+
return [
|
|
20
|
+
Math.min(x0, fLeft + dx),
|
|
21
|
+
Math.min(y0, -height + dy),
|
|
22
|
+
Math.max(x1, fLeft + width + dx),
|
|
23
|
+
Math.max(y1, dy)
|
|
24
|
+
];
|
|
25
|
+
}, [
|
|
26
|
+
0,
|
|
27
|
+
0,
|
|
28
|
+
0,
|
|
29
|
+
0
|
|
30
|
+
]);
|
|
31
|
+
return {
|
|
32
|
+
frames,
|
|
33
|
+
isMirrored,
|
|
34
|
+
bounds: {
|
|
35
|
+
left,
|
|
36
|
+
top,
|
|
37
|
+
right,
|
|
38
|
+
bottom,
|
|
39
|
+
width: right - left,
|
|
40
|
+
height: bottom - top
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
});
|
|
42
44
|
};
|
|
43
|
-
|
|
45
|
+
//#endregion
|
|
46
|
+
export { parseView };
|
|
47
|
+
|
|
44
48
|
//# sourceMappingURL=parse-view.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-view.js","
|
|
1
|
+
{"version":3,"file":"parse-view.js","names":[],"sources":["../../src/parsers/parse-view.ts"],"sourcesContent":["import type { View, Loop } from '../models/view.js';\nimport { parseCel } from './parse-cel.js';\nimport { repeat } from '../utils/repeat.js';\n\nexport const parseView = (source: Uint8Array): View => {\n const view = new DataView(\n source.buffer,\n source.byteOffset,\n source.byteLength,\n );\n\n const groupCount = view.getUint16(0, true);\n const mirrored = view.getUint16(2, true);\n\n return repeat<Loop>(groupCount, (groupIdx) => {\n const groupOffset = view.getUint16(8 + groupIdx * 2, true);\n\n const groupView = new DataView(\n source.buffer,\n source.byteOffset + groupOffset,\n );\n const frameCount = groupView.getUint16(0, true);\n const isMirrored = (mirrored & (1 << groupIdx)) !== 0;\n\n const frames = repeat(frameCount, (frameIdx) => {\n const frameOffset = groupView.getUint16(frameIdx * 2 + 4, true);\n const frameView = new DataView(\n source.buffer,\n source.byteOffset + frameOffset,\n );\n return parseCel(frameView);\n });\n\n const [left, top, right, bottom] = frames.reduce<\n [number, number, number, number]\n >(\n ([x0, y0, x1, y1], { width, height, dx, dy }) => {\n const fLeft = -(width >>> 1);\n return [\n Math.min(x0, fLeft + dx),\n Math.min(y0, -height + dy),\n Math.max(x1, fLeft + width + dx),\n Math.max(y1, dy),\n ];\n },\n [0, 0, 0, 0],\n );\n\n return {\n frames,\n isMirrored,\n bounds: {\n left,\n top,\n right,\n bottom,\n width: right - left,\n height: bottom - top,\n },\n };\n });\n};\n"],"mappings":";;;AAIA,MAAa,aAAa,WAA6B;CACrD,MAAM,OAAO,IAAI,SACf,OAAO,QACP,OAAO,YACP,OAAO,UACT;CAEA,MAAM,aAAa,KAAK,UAAU,GAAG,IAAI;CACzC,MAAM,WAAW,KAAK,UAAU,GAAG,IAAI;CAEvC,OAAO,OAAa,aAAa,aAAa;EAC5C,MAAM,cAAc,KAAK,UAAU,IAAI,WAAW,GAAG,IAAI;EAEzD,MAAM,YAAY,IAAI,SACpB,OAAO,QACP,OAAO,aAAa,WACtB;EACA,MAAM,aAAa,UAAU,UAAU,GAAG,IAAI;EAC9C,MAAM,cAAc,WAAY,KAAK,cAAe;EAEpD,MAAM,SAAS,OAAO,aAAa,aAAa;GAC9C,MAAM,cAAc,UAAU,UAAU,WAAW,IAAI,GAAG,IAAI;GAK9D,OAAO,SAAS,IAJM,SACpB,OAAO,QACP,OAAO,aAAa,WAEE,CAAC;EAC3B,CAAC;EAED,MAAM,CAAC,MAAM,KAAK,OAAO,UAAU,OAAO,QAGvC,CAAC,IAAI,IAAI,IAAI,KAAK,EAAE,OAAO,QAAQ,IAAI,SAAS;GAC/C,MAAM,QAAQ,EAAE,UAAU;GAC1B,OAAO;IACL,KAAK,IAAI,IAAI,QAAQ,EAAE;IACvB,KAAK,IAAI,IAAI,CAAC,SAAS,EAAE;IACzB,KAAK,IAAI,IAAI,QAAQ,QAAQ,EAAE;IAC/B,KAAK,IAAI,IAAI,EAAE;GACjB;EACF,GACA;GAAC;GAAG;GAAG;GAAG;EAAC,CACb;EAEA,OAAO;GACL;GACA;GACA,QAAQ;IACN;IACA;IACA;IACA;IACA,OAAO,QAAQ;IACf,QAAQ,SAAS;GACnB;EACF;CACF,CAAC;AACH"}
|