@4bitlabs/sci0 5.0.1 → 6.1.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 +26 -26
- package/dist/index.js +12 -46
- package/dist/matchers/index.d.ts +11 -0
- package/dist/matchers/index.d.ts.map +1 -0
- package/dist/matchers/index.js +26 -0
- package/dist/matchers/index.js.map +1 -0
- package/dist/matchers/number-predicate.d.ts +6 -0
- package/dist/matchers/number-predicate.d.ts.map +1 -0
- package/dist/matchers/number-predicate.js +7 -0
- package/dist/matchers/number-predicate.js.map +1 -0
- package/dist/matchers/resource-map-predicate.d.ts +6 -0
- package/dist/matchers/resource-map-predicate.d.ts.map +1 -0
- package/dist/matchers/type-and-number-predicate.d.ts +10 -0
- package/dist/matchers/type-and-number-predicate.d.ts.map +1 -0
- package/dist/matchers/type-and-number-predicate.js +19 -0
- package/dist/matchers/type-and-number-predicate.js.map +1 -0
- package/dist/matchers/type-predicates.d.ts +17 -0
- package/dist/matchers/type-predicates.d.ts.map +1 -0
- package/dist/matchers/type-predicates.js +17 -0
- package/dist/matchers/type-predicates.js.map +1 -0
- package/dist/matchers/utils.d.ts +6 -0
- package/dist/matchers/utils.d.ts.map +1 -0
- package/dist/matchers/utils.js +6 -0
- package/dist/matchers/utils.js.map +1 -0
- 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 -28
- 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 +21 -14
- 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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-cel.js","
|
|
1
|
+
{"version":3,"file":"parse-cel.js","names":[],"sources":["../../src/parsers/parse-cel.ts"],"sourcesContent":["import { createIndexedPixelData } from '@4bitlabs/image';\nimport type { Cel } from '../models/cel.js';\n\nexport const parseCel = (frameView: DataView): Cel => {\n const [width, height] = [\n frameView.getUint16(0, true),\n frameView.getUint16(2, true),\n ];\n const [dx, dy] = [frameView.getInt8(4), frameView.getInt8(5)];\n const keyColor = frameView.getUint8(6);\n\n const total = width * height;\n const img = createIndexedPixelData(width, height);\n\n let idx = 0;\n for (let i = 0; i < total; ) {\n const data = frameView.getUint8(7 + idx);\n idx += 1;\n const [color, repeat] = [data & 0xf, data >>> 4];\n for (let r = 0; r < repeat; r++) {\n img.pixels[i] = color;\n i += 1;\n }\n }\n\n return {\n ...img,\n keyColor,\n dx,\n dy,\n };\n};\n"],"mappings":";;AAGA,MAAa,YAAY,cAA6B;CACpD,MAAM,CAAC,OAAO,UAAU,CACtB,UAAU,UAAU,GAAG,IAAI,GAC3B,UAAU,UAAU,GAAG,IAAI,CAC7B;CACA,MAAM,CAAC,IAAI,MAAM,CAAC,UAAU,QAAQ,CAAC,GAAG,UAAU,QAAQ,CAAC,CAAC;CAC5D,MAAM,WAAW,UAAU,SAAS,CAAC;CAErC,MAAM,QAAQ,QAAQ;CACtB,MAAM,MAAM,uBAAuB,OAAO,MAAM;CAEhD,IAAI,MAAM;CACV,KAAK,IAAI,IAAI,GAAG,IAAI,QAAS;EAC3B,MAAM,OAAO,UAAU,SAAS,IAAI,GAAG;EACvC,OAAO;EACP,MAAM,CAAC,OAAO,UAAU,CAAC,OAAO,IAAK,SAAS,CAAC;EAC/C,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK;GAC/B,IAAI,OAAO,KAAK;GAChB,KAAK;EACP;CACF;CAEA,OAAO;EACL,GAAG;EACH;EACA;EACA;CACF;AACF"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
//#region src/parsers/parse-cursor-options.d.ts
|
|
2
|
+
interface ParseCursorOptions {
|
|
3
|
+
mapping?: {
|
|
4
|
+
black: number;
|
|
5
|
+
gray: number;
|
|
6
|
+
white: number;
|
|
7
|
+
keyColor: number;
|
|
8
|
+
};
|
|
8
9
|
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { ParseCursorOptions };
|
|
9
12
|
//# sourceMappingURL=parse-cursor-options.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-cursor-options.d.ts","
|
|
1
|
+
{"version":3,"file":"parse-cursor-options.d.ts","names":[],"sources":["../../src/parsers/parse-cursor-options.ts"],"mappings":";UAAiB;EACf;IACE;IACA;IACA;IACA"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ParseCursorOptions } from "./parse-cursor-options.js";
|
|
2
|
+
import { Cursor } from "../models/cursor.js";
|
|
3
|
+
//#region src/parsers/parse-cursor.d.ts
|
|
4
|
+
declare const parseCursor: (source: Uint8Array, options?: ParseCursorOptions) => Cursor;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { parseCursor };
|
|
4
7
|
//# sourceMappingURL=parse-cursor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-cursor.d.ts","
|
|
1
|
+
{"version":3,"file":"parse-cursor.d.ts","names":[],"sources":["../../src/parsers/parse-cursor.ts"],"mappings":";;;cAWa,cACX,QAAQ,YACR,UAAS,uBACR"}
|
|
@@ -1,41 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.parseCursor = void 0;
|
|
4
|
-
const image_1 = require("@4bitlabs/image");
|
|
1
|
+
import { createIndexedPixelData } from "@4bitlabs/image";
|
|
2
|
+
//#region src/parsers/parse-cursor.ts
|
|
5
3
|
const DEFAULT_MAPPING = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
black: 0,
|
|
5
|
+
white: 15,
|
|
6
|
+
gray: 7,
|
|
7
|
+
keyColor: 13
|
|
10
8
|
};
|
|
11
9
|
const parseCursor = (source, options = {}) => {
|
|
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
|
-
hotspot,
|
|
38
|
-
};
|
|
10
|
+
const { mapping = DEFAULT_MAPPING } = options;
|
|
11
|
+
const { keyColor } = mapping;
|
|
12
|
+
const colorLut = [
|
|
13
|
+
mapping.black,
|
|
14
|
+
mapping.white,
|
|
15
|
+
mapping.keyColor,
|
|
16
|
+
mapping.gray
|
|
17
|
+
];
|
|
18
|
+
const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
|
|
19
|
+
const hotspot = [view.getUint16(0, true), view.getUint16(2, true)];
|
|
20
|
+
const img = createIndexedPixelData(16, 16, { keyColor });
|
|
21
|
+
const stride = 16;
|
|
22
|
+
for (let y = 0; y < 16; y++) for (let x = 0; x < 16; x++) {
|
|
23
|
+
const idx = 4 + y * 2;
|
|
24
|
+
const tx = view.getUint16(idx, true);
|
|
25
|
+
const clr = view.getUint16(idx + 32, true);
|
|
26
|
+
const a = tx >> 15 - x & 1;
|
|
27
|
+
const b = clr >> 15 - x & 1;
|
|
28
|
+
const value = a << 1 | b;
|
|
29
|
+
img.pixels[x + y * stride] = colorLut[value];
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
...img,
|
|
33
|
+
hotspot
|
|
34
|
+
};
|
|
39
35
|
};
|
|
40
|
-
|
|
36
|
+
//#endregion
|
|
37
|
+
export { parseCursor };
|
|
38
|
+
|
|
41
39
|
//# sourceMappingURL=parse-cursor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-cursor.js","
|
|
1
|
+
{"version":3,"file":"parse-cursor.js","names":[],"sources":["../../src/parsers/parse-cursor.ts"],"sourcesContent":["import { createIndexedPixelData } from '@4bitlabs/image';\nimport type { Cursor } from '../models/cursor.js';\nimport type { ParseCursorOptions } from './parse-cursor-options.js';\n\nconst DEFAULT_MAPPING = {\n black: 0x00,\n white: 0x0f,\n gray: 0x07,\n keyColor: 0x0d,\n};\n\nexport const parseCursor = (\n source: Uint8Array,\n options: ParseCursorOptions = {},\n): Cursor => {\n const { mapping = DEFAULT_MAPPING } = options;\n const { keyColor } = mapping;\n const colorLut = [\n mapping.black,\n mapping.white,\n mapping.keyColor,\n mapping.gray,\n ];\n\n const view = new DataView(\n source.buffer,\n source.byteOffset,\n source.byteLength,\n );\n\n const hotspot = [view.getUint16(0, true), view.getUint16(2, true)] as const;\n\n const img = createIndexedPixelData(16, 16, { keyColor });\n const stride = 16;\n for (let y = 0; y < 16; y++) {\n for (let x = 0; x < 16; x++) {\n const idx = 4 + y * 2;\n\n const tx = view.getUint16(idx, true);\n const clr = view.getUint16(idx + 32, true);\n\n const a = (tx >> (15 - x)) & 1;\n const b = (clr >> (15 - x)) & 1;\n const value = (a << 1) | b;\n img.pixels[x + y * stride] = colorLut[value];\n }\n }\n\n return {\n ...img,\n hotspot,\n };\n};\n"],"mappings":";;AAIA,MAAM,kBAAkB;CACtB,OAAO;CACP,OAAO;CACP,MAAM;CACN,UAAU;AACZ;AAEA,MAAa,eACX,QACA,UAA8B,CAAC,MACpB;CACX,MAAM,EAAE,UAAU,oBAAoB;CACtC,MAAM,EAAE,aAAa;CACrB,MAAM,WAAW;EACf,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,QAAQ;CACV;CAEA,MAAM,OAAO,IAAI,SACf,OAAO,QACP,OAAO,YACP,OAAO,UACT;CAEA,MAAM,UAAU,CAAC,KAAK,UAAU,GAAG,IAAI,GAAG,KAAK,UAAU,GAAG,IAAI,CAAC;CAEjE,MAAM,MAAM,uBAAuB,IAAI,IAAI,EAAE,SAAS,CAAC;CACvD,MAAM,SAAS;CACf,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,KACtB,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK;EAC3B,MAAM,MAAM,IAAI,IAAI;EAEpB,MAAM,KAAK,KAAK,UAAU,KAAK,IAAI;EACnC,MAAM,MAAM,KAAK,UAAU,MAAM,IAAI,IAAI;EAEzC,MAAM,IAAK,MAAO,KAAK,IAAM;EAC7B,MAAM,IAAK,OAAQ,KAAK,IAAM;EAC9B,MAAM,QAAS,KAAK,IAAK;EACzB,IAAI,OAAO,IAAI,IAAI,UAAU,SAAS;CACxC;CAGF,OAAO;EACL,GAAG;EACH;CACF;AACF"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region src/parsers/parse-font-options.d.ts
|
|
2
|
+
interface ParseFontOptions {
|
|
3
|
+
color?: number;
|
|
4
|
+
keyColor?: number;
|
|
4
5
|
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { ParseFontOptions };
|
|
5
8
|
//# sourceMappingURL=parse-font-options.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-font-options.d.ts","
|
|
1
|
+
{"version":3,"file":"parse-font-options.d.ts","names":[],"sources":["../../src/parsers/parse-font-options.ts"],"mappings":";UAAiB;EACf;EACA"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ParseFontOptions } from "./parse-font-options.js";
|
|
2
|
+
import { FontFace } from "../models/font-face.js";
|
|
3
|
+
//#region src/parsers/parse-font.d.ts
|
|
4
|
+
declare const parseFont: (source: Uint8Array, options?: ParseFontOptions) => FontFace;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { parseFont };
|
|
4
7
|
//# sourceMappingURL=parse-font.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-font.d.ts","
|
|
1
|
+
{"version":3,"file":"parse-font.d.ts","names":[],"sources":["../../src/parsers/parse-font.ts"],"mappings":";;;cAKa,YACX,QAAQ,YACR,UAAS,qBACR"}
|
|
@@ -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,33 +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
|
-
throw new Error(`Unhandled opcode: 0x${op.toString(16)}`);
|
|
20
|
-
yield* handler(r, state);
|
|
21
|
-
}
|
|
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
|
+
}
|
|
22
17
|
}
|
|
23
18
|
function parsePic(source, options = {}) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return picIterable(source);
|
|
29
|
-
},
|
|
30
|
-
}
|
|
31
|
-
: [...picIterable(source)];
|
|
19
|
+
const { defer } = options;
|
|
20
|
+
return defer ? { [Symbol.iterator]() {
|
|
21
|
+
return picIterable(source);
|
|
22
|
+
} } : [...picIterable(source)];
|
|
32
23
|
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { parsePic };
|
|
26
|
+
|
|
33
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"}
|