@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.
Files changed (130) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +13 -0
  2. package/dist/index.d.ts +25 -26
  3. package/dist/index.js +11 -46
  4. package/dist/models/cel.d.ts +7 -4
  5. package/dist/models/cel.d.ts.map +1 -1
  6. package/dist/models/cursor.d.ts +6 -3
  7. package/dist/models/cursor.d.ts.map +1 -1
  8. package/dist/models/draw-codes.d.ts +4 -5
  9. package/dist/models/draw-codes.d.ts.map +1 -1
  10. package/dist/models/draw-command.d.ts +5 -2
  11. package/dist/models/draw-command.d.ts.map +1 -1
  12. package/dist/models/draw-commands.d.ts +16 -46
  13. package/dist/models/draw-commands.d.ts.map +1 -1
  14. package/dist/models/draw-mode.d.ts +21 -18
  15. package/dist/models/draw-mode.d.ts.map +1 -1
  16. package/dist/models/draw-mode.js +20 -25
  17. package/dist/models/draw-mode.js.map +1 -1
  18. package/dist/models/font-face.d.ts +7 -4
  19. package/dist/models/font-face.d.ts.map +1 -1
  20. package/dist/models/pattern-code.d.ts +4 -5
  21. package/dist/models/pattern-code.d.ts.map +1 -1
  22. package/dist/models/pic.d.ts +6 -3
  23. package/dist/models/pic.d.ts.map +1 -1
  24. package/dist/models/resource-header.d.ts +12 -9
  25. package/dist/models/resource-header.d.ts.map +1 -1
  26. package/dist/models/resource-id.d.ts +10 -5
  27. package/dist/models/resource-id.d.ts.map +1 -1
  28. package/dist/models/resource-id.js +28 -36
  29. package/dist/models/resource-id.js.map +1 -1
  30. package/dist/models/resource-map.d.ts +7 -4
  31. package/dist/models/resource-map.d.ts.map +1 -1
  32. package/dist/models/resource-type.d.ts +5 -2
  33. package/dist/models/resource-type.d.ts.map +1 -1
  34. package/dist/models/resource-types.d.ts +15 -10
  35. package/dist/models/resource-types.d.ts.map +1 -1
  36. package/dist/models/resource-types.js +17 -13
  37. package/dist/models/resource-types.js.map +1 -1
  38. package/dist/models/view.d.ts +16 -13
  39. package/dist/models/view.d.ts.map +1 -1
  40. package/dist/parsers/compression.d.ts +4 -1
  41. package/dist/parsers/compression.d.ts.map +1 -1
  42. package/dist/parsers/compression.js +36 -54
  43. package/dist/parsers/compression.js.map +1 -1
  44. package/dist/parsers/mapping.d.ts +5 -3
  45. package/dist/parsers/mapping.d.ts.map +1 -1
  46. package/dist/parsers/mapping.js +18 -23
  47. package/dist/parsers/mapping.js.map +1 -1
  48. package/dist/parsers/parse-cel.js +26 -29
  49. package/dist/parsers/parse-cel.js.map +1 -1
  50. package/dist/parsers/parse-cursor-options.d.ts +10 -7
  51. package/dist/parsers/parse-cursor-options.d.ts.map +1 -1
  52. package/dist/parsers/parse-cursor.d.ts +6 -3
  53. package/dist/parsers/parse-cursor.d.ts.map +1 -1
  54. package/dist/parsers/parse-cursor.js +34 -36
  55. package/dist/parsers/parse-cursor.js.map +1 -1
  56. package/dist/parsers/parse-font-options.d.ts +6 -3
  57. package/dist/parsers/parse-font-options.d.ts.map +1 -1
  58. package/dist/parsers/parse-font.d.ts +6 -3
  59. package/dist/parsers/parse-font.d.ts.map +1 -1
  60. package/dist/parsers/parse-font.js +27 -30
  61. package/dist/parsers/parse-font.js.map +1 -1
  62. package/dist/parsers/parse-pic.d.ts +8 -5
  63. package/dist/parsers/parse-pic.d.ts.map +1 -1
  64. package/dist/parsers/parse-pic.js +22 -29
  65. package/dist/parsers/parse-pic.js.map +1 -1
  66. package/dist/parsers/parse-view.d.ts +5 -2
  67. package/dist/parsers/parse-view.d.ts.map +1 -1
  68. package/dist/parsers/parse-view.js +45 -41
  69. package/dist/parsers/parse-view.js.map +1 -1
  70. package/dist/parsers/pic/handlers.js +272 -208
  71. package/dist/parsers/pic/handlers.js.map +1 -1
  72. package/dist/parsers/pic/op-codes.js +37 -45
  73. package/dist/parsers/pic/op-codes.js.map +1 -1
  74. package/dist/parsers/pic/pic-state.js +16 -8
  75. package/dist/parsers/pic/pic-state.js.map +1 -1
  76. package/dist/parsers/pic/points.js +19 -45
  77. package/dist/parsers/pic/points.js.map +1 -1
  78. package/dist/parsers/resource-header.d.ts +6 -3
  79. package/dist/parsers/resource-header.d.ts.map +1 -1
  80. package/dist/parsers/resource-header.js +15 -20
  81. package/dist/parsers/resource-header.js.map +1 -1
  82. package/dist/utils/exhaustive.js +5 -4
  83. package/dist/utils/exhaustive.js.map +1 -1
  84. package/dist/utils/repeat.js +5 -7
  85. package/dist/utils/repeat.js.map +1 -1
  86. package/package.json +17 -15
  87. package/dist/index.d.ts.map +0 -1
  88. package/dist/index.js.map +0 -1
  89. package/dist/models/cel.js +0 -3
  90. package/dist/models/cel.js.map +0 -1
  91. package/dist/models/cursor.js +0 -3
  92. package/dist/models/cursor.js.map +0 -1
  93. package/dist/models/draw-codes.js +0 -3
  94. package/dist/models/draw-codes.js.map +0 -1
  95. package/dist/models/draw-command.js +0 -3
  96. package/dist/models/draw-command.js.map +0 -1
  97. package/dist/models/draw-commands.js +0 -3
  98. package/dist/models/draw-commands.js.map +0 -1
  99. package/dist/models/font-face.js +0 -3
  100. package/dist/models/font-face.js.map +0 -1
  101. package/dist/models/pattern-code.js +0 -3
  102. package/dist/models/pattern-code.js.map +0 -1
  103. package/dist/models/pic.js +0 -3
  104. package/dist/models/pic.js.map +0 -1
  105. package/dist/models/resource-header.js +0 -3
  106. package/dist/models/resource-header.js.map +0 -1
  107. package/dist/models/resource-map.js +0 -3
  108. package/dist/models/resource-map.js.map +0 -1
  109. package/dist/models/resource-type.js +0 -3
  110. package/dist/models/resource-type.js.map +0 -1
  111. package/dist/models/view.js +0 -3
  112. package/dist/models/view.js.map +0 -1
  113. package/dist/parsers/parse-cel.d.ts +0 -3
  114. package/dist/parsers/parse-cel.d.ts.map +0 -1
  115. package/dist/parsers/parse-cursor-options.js +0 -3
  116. package/dist/parsers/parse-cursor-options.js.map +0 -1
  117. package/dist/parsers/parse-font-options.js +0 -3
  118. package/dist/parsers/parse-font-options.js.map +0 -1
  119. package/dist/parsers/pic/handlers.d.ts +0 -8
  120. package/dist/parsers/pic/handlers.d.ts.map +0 -1
  121. package/dist/parsers/pic/op-codes.d.ts +0 -32
  122. package/dist/parsers/pic/op-codes.d.ts.map +0 -1
  123. package/dist/parsers/pic/pic-state.d.ts +0 -10
  124. package/dist/parsers/pic/pic-state.d.ts.map +0 -1
  125. package/dist/parsers/pic/points.d.ts +0 -6
  126. package/dist/parsers/pic/points.d.ts.map +0 -1
  127. package/dist/utils/exhaustive.d.ts +0 -2
  128. package/dist/utils/exhaustive.d.ts.map +0 -1
  129. package/dist/utils/repeat.d.ts +0 -2
  130. package/dist/utils/repeat.d.ts.map +0 -1
@@ -1,33 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseFont = void 0;
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
- const { color = 0x0f, keyColor = 0x00 } = options;
8
- const headerView = new DataView(source.buffer, source.byteOffset, 6);
9
- const count = headerView.getUint16(2, true);
10
- const lineHeight = headerView.getUint16(4, true);
11
- const pointersView = new DataView(source.buffer, source.byteOffset + 6, count * 2);
12
- const pointers = (0, repeat_1.repeat)(count, (i) => pointersView.getUint16(i * 2, true));
13
- const characters = pointers.map((offset) => {
14
- const [width, height] = [source[offset], source[offset + 1]];
15
- const widthBytes = (width + 7) >>> 3;
16
- const image = (0, image_1.createIndexedPixelData)(width, height, { keyColor });
17
- for (let y = 0; y < height; y++) {
18
- const yOffset = offset + 2 + y * widthBytes;
19
- for (let x = 0; x < width; x++) {
20
- const idx = yOffset + (x >>> 3);
21
- const bit = (source[idx] >>> (7 - (x & 0b111))) & 1;
22
- image.pixels[x + y * width] = bit ? color : keyColor;
23
- }
24
- }
25
- return image;
26
- });
27
- return {
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
- exports.parseFont = parseFont;
27
+ //#endregion
28
+ export { parseFont };
29
+
33
30
  //# sourceMappingURL=parse-font.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-font.js","sourceRoot":"","sources":["../../src/parsers/parse-font.ts"],"names":[],"mappings":";;;AAAA,2CAAgF;AAEhF,4CAAyC;AAGlC,MAAM,SAAS,GAAG,CACvB,MAAkB,EAClB,UAA4B,EAAE,EACpB,EAAE;IACZ,MAAM,EAAE,KAAK,GAAG,IAAI,EAAE,QAAQ,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAElD,MAAM,UAAU,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IACrE,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAC5C,MAAM,UAAU,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAEjD,MAAM,YAAY,GAAG,IAA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,QAAQ,CAAC;YACvD,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,UAAU;QACV,UAAU;KACX,CAAC;AACJ,CAAC,CAAC;AAxCW,QAAA,SAAS,aAwCpB"}
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 type { DrawCommand } from '../models/draw-command';
2
- import type { Pic } from '../models/pic';
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
- export declare function parsePic(source: Uint8Array): DrawCommand[];
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
- export declare function parsePic(source: Uint8Array, options: {
18
- defer: true;
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","sourceRoot":"","sources":["../../src/parsers/parse-pic.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAqBzC;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,WAAW,EAAE,CAAC;AAC5D;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,GAAG,GAAG,CAAC"}
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parsePic = parsePic;
4
- const readers_1 = require("@4bitlabs/readers");
5
- const handlers_1 = require("./pic/handlers");
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
- process.stderr.write('parsing\n');
10
- const r = (0, readers_1.createBitReader)(source, { mode: 'msb' });
11
- const state = (0, pic_state_1.createPicState)();
12
- while (true) {
13
- const op = r.read32(8);
14
- if (!(0, op_codes_1.isOpCode)(op))
15
- throw new Error(`Unrecognized opcode: 0x${op.toString(16)}`);
16
- if (op === op_codes_1.OpCode.Done)
17
- break;
18
- const handler = handlers_1.CodeHandlers[op];
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
- const { defer } = options;
26
- return defer
27
- ? {
28
- [Symbol.iterator]() {
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","sourceRoot":"","sources":["../../src/parsers/parse-pic.ts"],"names":[],"mappings":";;AAyCA,4BAYC;AArDD,+CAAoD;AACpD,6CAA8C;AAC9C,6CAAkD;AAClD,+CAAiD;AAIjD,QAAQ,CAAC,CAAC,WAAW,CAAC,MAAkB;IACtC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAClC,MAAM,CAAC,GAAG,IAAA,yBAAe,EAAC,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,IAAA,0BAAc,GAAE,CAAC;IAC/B,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAEvB,IAAI,CAAC,IAAA,mBAAQ,EAAC,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,0BAA0B,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAE/D,IAAI,EAAE,KAAK,iBAAM,CAAC,IAAI;YAAE,MAAM;QAE9B,MAAM,OAAO,GAAG,uBAAY,CAAC,EAAE,CAAC,CAAC;QACjC,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAExE,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC;AAiBD,SAAgB,QAAQ,CACtB,MAAkB,EAClB,UAA+B,EAAE;IAEjC,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAC1B,OAAO,KAAK;QACV,CAAC,CAAC;YACE,CAAC,MAAM,CAAC,QAAQ,CAAC;gBACf,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;YAC7B,CAAC;SACF;QACH,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/B,CAAC"}
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 { type View } from '../models/view';
2
- export declare const parseView: (source: Uint8Array) => View;
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","sourceRoot":"","sources":["../../src/parsers/parse-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAa,MAAM,gBAAgB,CAAC;AAItD,eAAO,MAAM,SAAS,WAAY,UAAU,KAAG,IAyD9C,CAAC"}
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseView = void 0;
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
- const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
8
- const groupCount = view.getUint16(0, true);
9
- const mirrored = view.getUint16(2, true);
10
- return (0, repeat_1.repeat)(groupCount, (groupIdx) => {
11
- const groupOffset = view.getUint16(8 + groupIdx * 2, true);
12
- const groupView = new DataView(source.buffer, source.byteOffset + groupOffset);
13
- const frameCount = groupView.getUint16(0, true);
14
- const isMirrored = (mirrored & (1 << groupIdx)) !== 0;
15
- const frames = (0, repeat_1.repeat)(frameCount, (frameIdx) => {
16
- const frameOffset = groupView.getUint16(frameIdx * 2 + 4, true);
17
- const frameView = new DataView(source.buffer, source.byteOffset + frameOffset);
18
- return (0, parse_cel_1.parseCel)(frameView);
19
- });
20
- const [left, top, right, bottom] = frames.reduce(([x0, y0, x1, y1], { width, height, dx, dy }) => {
21
- const fLeft = -(width >>> 1);
22
- return [
23
- Math.min(x0, fLeft + dx),
24
- Math.min(y0, -height + dy),
25
- Math.max(x1, fLeft + width + dx),
26
- Math.max(y1, dy),
27
- ];
28
- }, [0, 0, 0, 0]);
29
- return {
30
- frames,
31
- isMirrored,
32
- bounds: {
33
- left,
34
- top,
35
- right,
36
- bottom,
37
- width: right - left,
38
- height: bottom - top,
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
- exports.parseView = parseView;
45
+ //#endregion
46
+ export { parseView };
47
+
44
48
  //# sourceMappingURL=parse-view.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-view.js","sourceRoot":"","sources":["../../src/parsers/parse-view.ts"],"names":[],"mappings":";;;AACA,2CAAuC;AACvC,4CAAyC;AAElC,MAAM,SAAS,GAAG,CAAC,MAAkB,EAAQ,EAAE;IACpD,MAAM,IAAI,GAAG,IAAI,QAAQ,CACvB,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,UAAU,CAClB,CAAC;IAEF,MAAM,UAAU,GA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C,KAAK,KAAK,CAAC,CAAC,CAAC;YAC7B,OAAO;gBACL,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,GAAG,EAAE,CAAC;gBACxB,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,EAAE,CAAC;gBAC1B,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,GAAG,KAAK,GAAG,EAAE,CAAC;gBAChC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC;aACjB,CAAC;QACJ,CAAC,EACD,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CACb,CAAC;QAEF,OAAO;YACL,MAAM;YACN,UAAU;YACV,MAAM,EAAE;gBACN,IAAI;gBACJ,GAAG;gBACH,KAAK;gBACL,MAAM;gBACN,KAAK,EAAE,KAAK,GAAG,IAAI;gBACnB,MAAM,EAAE,MAAM,GAAG,GAAG;aACrB;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAzDW,QAAA,SAAS,aAyDpB"}
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"}