@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.
Files changed (152) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +13 -0
  2. package/dist/index.d.ts +26 -26
  3. package/dist/index.js +12 -46
  4. package/dist/matchers/index.d.ts +11 -0
  5. package/dist/matchers/index.d.ts.map +1 -0
  6. package/dist/matchers/index.js +26 -0
  7. package/dist/matchers/index.js.map +1 -0
  8. package/dist/matchers/number-predicate.d.ts +6 -0
  9. package/dist/matchers/number-predicate.d.ts.map +1 -0
  10. package/dist/matchers/number-predicate.js +7 -0
  11. package/dist/matchers/number-predicate.js.map +1 -0
  12. package/dist/matchers/resource-map-predicate.d.ts +6 -0
  13. package/dist/matchers/resource-map-predicate.d.ts.map +1 -0
  14. package/dist/matchers/type-and-number-predicate.d.ts +10 -0
  15. package/dist/matchers/type-and-number-predicate.d.ts.map +1 -0
  16. package/dist/matchers/type-and-number-predicate.js +19 -0
  17. package/dist/matchers/type-and-number-predicate.js.map +1 -0
  18. package/dist/matchers/type-predicates.d.ts +17 -0
  19. package/dist/matchers/type-predicates.d.ts.map +1 -0
  20. package/dist/matchers/type-predicates.js +17 -0
  21. package/dist/matchers/type-predicates.js.map +1 -0
  22. package/dist/matchers/utils.d.ts +6 -0
  23. package/dist/matchers/utils.d.ts.map +1 -0
  24. package/dist/matchers/utils.js +6 -0
  25. package/dist/matchers/utils.js.map +1 -0
  26. package/dist/models/cel.d.ts +7 -4
  27. package/dist/models/cel.d.ts.map +1 -1
  28. package/dist/models/cursor.d.ts +6 -3
  29. package/dist/models/cursor.d.ts.map +1 -1
  30. package/dist/models/draw-codes.d.ts +4 -5
  31. package/dist/models/draw-codes.d.ts.map +1 -1
  32. package/dist/models/draw-command.d.ts +5 -2
  33. package/dist/models/draw-command.d.ts.map +1 -1
  34. package/dist/models/draw-commands.d.ts +16 -46
  35. package/dist/models/draw-commands.d.ts.map +1 -1
  36. package/dist/models/draw-mode.d.ts +21 -18
  37. package/dist/models/draw-mode.d.ts.map +1 -1
  38. package/dist/models/draw-mode.js +20 -25
  39. package/dist/models/draw-mode.js.map +1 -1
  40. package/dist/models/font-face.d.ts +7 -4
  41. package/dist/models/font-face.d.ts.map +1 -1
  42. package/dist/models/pattern-code.d.ts +4 -5
  43. package/dist/models/pattern-code.d.ts.map +1 -1
  44. package/dist/models/pic.d.ts +6 -3
  45. package/dist/models/pic.d.ts.map +1 -1
  46. package/dist/models/resource-header.d.ts +12 -9
  47. package/dist/models/resource-header.d.ts.map +1 -1
  48. package/dist/models/resource-id.d.ts +10 -5
  49. package/dist/models/resource-id.d.ts.map +1 -1
  50. package/dist/models/resource-id.js +28 -36
  51. package/dist/models/resource-id.js.map +1 -1
  52. package/dist/models/resource-map.d.ts +7 -4
  53. package/dist/models/resource-map.d.ts.map +1 -1
  54. package/dist/models/resource-type.d.ts +5 -2
  55. package/dist/models/resource-type.d.ts.map +1 -1
  56. package/dist/models/resource-types.d.ts +15 -10
  57. package/dist/models/resource-types.d.ts.map +1 -1
  58. package/dist/models/resource-types.js +17 -13
  59. package/dist/models/resource-types.js.map +1 -1
  60. package/dist/models/view.d.ts +16 -13
  61. package/dist/models/view.d.ts.map +1 -1
  62. package/dist/parsers/compression.d.ts +4 -1
  63. package/dist/parsers/compression.d.ts.map +1 -1
  64. package/dist/parsers/compression.js +36 -54
  65. package/dist/parsers/compression.js.map +1 -1
  66. package/dist/parsers/mapping.d.ts +5 -3
  67. package/dist/parsers/mapping.d.ts.map +1 -1
  68. package/dist/parsers/mapping.js +18 -23
  69. package/dist/parsers/mapping.js.map +1 -1
  70. package/dist/parsers/parse-cel.js +26 -29
  71. package/dist/parsers/parse-cel.js.map +1 -1
  72. package/dist/parsers/parse-cursor-options.d.ts +10 -7
  73. package/dist/parsers/parse-cursor-options.d.ts.map +1 -1
  74. package/dist/parsers/parse-cursor.d.ts +6 -3
  75. package/dist/parsers/parse-cursor.d.ts.map +1 -1
  76. package/dist/parsers/parse-cursor.js +34 -36
  77. package/dist/parsers/parse-cursor.js.map +1 -1
  78. package/dist/parsers/parse-font-options.d.ts +6 -3
  79. package/dist/parsers/parse-font-options.d.ts.map +1 -1
  80. package/dist/parsers/parse-font.d.ts +6 -3
  81. package/dist/parsers/parse-font.d.ts.map +1 -1
  82. package/dist/parsers/parse-font.js +27 -30
  83. package/dist/parsers/parse-font.js.map +1 -1
  84. package/dist/parsers/parse-pic.d.ts +8 -5
  85. package/dist/parsers/parse-pic.d.ts.map +1 -1
  86. package/dist/parsers/parse-pic.js +22 -28
  87. package/dist/parsers/parse-pic.js.map +1 -1
  88. package/dist/parsers/parse-view.d.ts +5 -2
  89. package/dist/parsers/parse-view.d.ts.map +1 -1
  90. package/dist/parsers/parse-view.js +45 -41
  91. package/dist/parsers/parse-view.js.map +1 -1
  92. package/dist/parsers/pic/handlers.js +272 -208
  93. package/dist/parsers/pic/handlers.js.map +1 -1
  94. package/dist/parsers/pic/op-codes.js +37 -45
  95. package/dist/parsers/pic/op-codes.js.map +1 -1
  96. package/dist/parsers/pic/pic-state.js +16 -8
  97. package/dist/parsers/pic/pic-state.js.map +1 -1
  98. package/dist/parsers/pic/points.js +19 -45
  99. package/dist/parsers/pic/points.js.map +1 -1
  100. package/dist/parsers/resource-header.d.ts +6 -3
  101. package/dist/parsers/resource-header.d.ts.map +1 -1
  102. package/dist/parsers/resource-header.js +15 -20
  103. package/dist/parsers/resource-header.js.map +1 -1
  104. package/dist/utils/exhaustive.js +5 -4
  105. package/dist/utils/exhaustive.js.map +1 -1
  106. package/dist/utils/repeat.js +5 -7
  107. package/dist/utils/repeat.js.map +1 -1
  108. package/package.json +21 -14
  109. package/dist/index.d.ts.map +0 -1
  110. package/dist/index.js.map +0 -1
  111. package/dist/models/cel.js +0 -3
  112. package/dist/models/cel.js.map +0 -1
  113. package/dist/models/cursor.js +0 -3
  114. package/dist/models/cursor.js.map +0 -1
  115. package/dist/models/draw-codes.js +0 -3
  116. package/dist/models/draw-codes.js.map +0 -1
  117. package/dist/models/draw-command.js +0 -3
  118. package/dist/models/draw-command.js.map +0 -1
  119. package/dist/models/draw-commands.js +0 -3
  120. package/dist/models/draw-commands.js.map +0 -1
  121. package/dist/models/font-face.js +0 -3
  122. package/dist/models/font-face.js.map +0 -1
  123. package/dist/models/pattern-code.js +0 -3
  124. package/dist/models/pattern-code.js.map +0 -1
  125. package/dist/models/pic.js +0 -3
  126. package/dist/models/pic.js.map +0 -1
  127. package/dist/models/resource-header.js +0 -3
  128. package/dist/models/resource-header.js.map +0 -1
  129. package/dist/models/resource-map.js +0 -3
  130. package/dist/models/resource-map.js.map +0 -1
  131. package/dist/models/resource-type.js +0 -3
  132. package/dist/models/resource-type.js.map +0 -1
  133. package/dist/models/view.js +0 -3
  134. package/dist/models/view.js.map +0 -1
  135. package/dist/parsers/parse-cel.d.ts +0 -3
  136. package/dist/parsers/parse-cel.d.ts.map +0 -1
  137. package/dist/parsers/parse-cursor-options.js +0 -3
  138. package/dist/parsers/parse-cursor-options.js.map +0 -1
  139. package/dist/parsers/parse-font-options.js +0 -3
  140. package/dist/parsers/parse-font-options.js.map +0 -1
  141. package/dist/parsers/pic/handlers.d.ts +0 -8
  142. package/dist/parsers/pic/handlers.d.ts.map +0 -1
  143. package/dist/parsers/pic/op-codes.d.ts +0 -32
  144. package/dist/parsers/pic/op-codes.d.ts.map +0 -1
  145. package/dist/parsers/pic/pic-state.d.ts +0 -10
  146. package/dist/parsers/pic/pic-state.d.ts.map +0 -1
  147. package/dist/parsers/pic/points.d.ts +0 -6
  148. package/dist/parsers/pic/points.d.ts.map +0 -1
  149. package/dist/utils/exhaustive.d.ts +0 -2
  150. package/dist/utils/exhaustive.d.ts.map +0 -1
  151. package/dist/utils/repeat.d.ts +0 -2
  152. package/dist/utils/repeat.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"parse-cel.js","sourceRoot":"","sources":["../../src/parsers/parse-cel.ts"],"names":[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"}
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
- export interface ParseCursorOptions {
2
- mapping?: {
3
- black: number;
4
- gray: number;
5
- white: number;
6
- keyColor: number;
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","sourceRoot":"","sources":["../../src/parsers/parse-cursor-options.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE;QACR,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH"}
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 { type Cursor } from '../models/cursor';
2
- import { ParseCursorOptions } from './parse-cursor-options';
3
- export declare const parseCursor: (source: Uint8Array, options?: ParseCursorOptions) => Cursor;
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","sourceRoot":"","sources":["../../src/parsers/parse-cursor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAS5D,eAAO,MAAM,WAAW,WACd,UAAU,YACT,kBAAkB,KAC1B,MAsCF,CAAC"}
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
- black: 0x00,
7
- white: 0x0f,
8
- gray: 0x07,
9
- keyColor: 0x0d,
4
+ black: 0,
5
+ white: 15,
6
+ gray: 7,
7
+ keyColor: 13
10
8
  };
11
9
  const parseCursor = (source, options = {}) => {
12
- const { mapping = DEFAULT_MAPPING } = options;
13
- const { keyColor } = mapping;
14
- const colorLut = [
15
- mapping.black,
16
- mapping.white,
17
- mapping.keyColor,
18
- mapping.gray,
19
- ];
20
- const view = new DataView(source.buffer, source.byteOffset, source.byteLength);
21
- const hotspot = [view.getUint16(0, true), view.getUint16(2, true)];
22
- const img = (0, image_1.createIndexedPixelData)(16, 16, { keyColor });
23
- const stride = 16;
24
- for (let y = 0; y < 16; y++) {
25
- for (let x = 0; x < 16; x++) {
26
- const idx = 4 + y * 2;
27
- const tx = view.getUint16(idx, true);
28
- const clr = view.getUint16(idx + 32, true);
29
- const a = (tx >> (15 - x)) & 1;
30
- const b = (clr >> (15 - x)) & 1;
31
- const value = (a << 1) | b;
32
- img.pixels[x + y * stride] = colorLut[value];
33
- }
34
- }
35
- return {
36
- ...img,
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
- exports.parseCursor = parseCursor;
36
+ //#endregion
37
+ export { parseCursor };
38
+
41
39
  //# sourceMappingURL=parse-cursor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-cursor.js","sourceRoot":"","sources":["../../src/parsers/parse-cursor.ts"],"names":[],"mappings":";;;AAAA,2CAAyD;AAIzD,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,IAAI;IACV,QAAQ,EAAE,IAAI;CACf,CAAC;AAEK,MAAM,WAAW,GAAG,CACzB,MAAkB,EAClB,UAA8B,EAAE,EACxB,EAAE;IACV,MAAM,EAAE,OAAO,GAAG,eAAe,EAAE,GAAG,OAAO,CAAC;IAC9C,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,QAAQ,GAAG;QACf,OAAO,CAAC,KAAK;QACb,OAAO,CAAC,KAAK;QACb,OAAO,CAAC,QAAQ;QAChB,OAAO,CAAC,IAAI;KACb,CAAC;IAEF,MAAM,IAAI,GAAG,IAAI,QAAQ,CACvB,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,UAAU,CAClB,CAAC;IAEF,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAU,CAAC;IAE5E,MAAM,GAAG,GAAG,IAAA,8BAAsB,EAAC,EAAE,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5B,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAEtB,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACrC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;YAE3C,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YAC/B,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YAChC,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;YAC3B,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,OAAO;QACL,GAAG,GAAG;QACN,OAAO;KACR,CAAC;AACJ,CAAC,CAAC;AAzCW,QAAA,WAAW,eAyCtB"}
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
- export interface ParseFontOptions {
2
- color?: number;
3
- keyColor?: number;
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","sourceRoot":"","sources":["../../src/parsers/parse-font-options.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
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 { FontFace } from '../models/font-face';
2
- import { ParseFontOptions } from './parse-font-options';
3
- export declare const parseFont: (source: Uint8Array, options?: ParseFontOptions) => FontFace;
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","sourceRoot":"","sources":["../../src/parsers/parse-font.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,eAAO,MAAM,SAAS,WACZ,UAAU,YACT,gBAAgB,KACxB,QAqCF,CAAC"}
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
- "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,IAAI,QAAQ,CAC/B,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,UAAU,GAAG,CAAC,EACrB,KAAK,GAAG,CAAC,CACV,CAAC;IACF,MAAM,QAAQ,GAAG,IAAA,eAAM,EAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,GAAG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-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;AAoBzC;;;;;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,33 +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
- const r = (0, readers_1.createBitReader)(source, { mode: 'msb' });
10
- const state = (0, pic_state_1.createPicState)();
11
- while (true) {
12
- const op = r.read32(8);
13
- if (!(0, op_codes_1.isOpCode)(op))
14
- throw new Error(`Unrecognized opcode: 0x${op.toString(16)}`);
15
- if (op === op_codes_1.OpCode.Done)
16
- break;
17
- const handler = handlers_1.CodeHandlers[op];
18
- if (!handler)
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
- const { defer } = options;
25
- return defer
26
- ? {
27
- [Symbol.iterator]() {
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","sourceRoot":"","sources":["../../src/parsers/parse-pic.ts"],"names":[],"mappings":";;AAwCA,4BAYC;AApDD,+CAAoD;AACpD,6CAA8C;AAC9C,6CAAkD;AAClD,+CAAiD;AAIjD,QAAQ,CAAC,CAAC,WAAW,CAAC,MAAkB;IACtC,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,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAEzC,OAAO,IAAA,eAAM,EAAO,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE;QAC3C,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,QAAQ,GAAG,CAAC,EAAE,IAAI,CAAC,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AE,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"}