@swf2es/native 0.0.0-stage → 0.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 (105) hide show
  1. package/LICENSE +202 -0
  2. package/LICENSE.third-party +313 -0
  3. package/README.md +489 -2
  4. package/dist/atf/binary.d.ts +2 -0
  5. package/dist/atf/binary.d.ts.map +1 -0
  6. package/dist/atf/binary.js +4 -0
  7. package/dist/atf/binary.js.map +1 -0
  8. package/dist/atf/index.d.ts +27 -0
  9. package/dist/atf/index.d.ts.map +1 -0
  10. package/dist/atf/index.js +158 -0
  11. package/dist/atf/index.js.map +1 -0
  12. package/dist/atf/jxr.d.ts +22 -0
  13. package/dist/atf/jxr.d.ts.map +1 -0
  14. package/dist/atf/jxr.js +60 -0
  15. package/dist/atf/jxr.js.map +1 -0
  16. package/dist/atf/parse.d.ts +65 -0
  17. package/dist/atf/parse.d.ts.map +1 -0
  18. package/dist/atf/parse.js +204 -0
  19. package/dist/atf/parse.js.map +1 -0
  20. package/dist/audio/binary.d.ts +2 -0
  21. package/dist/audio/binary.d.ts.map +1 -0
  22. package/dist/audio/binary.js +4 -0
  23. package/dist/audio/binary.js.map +1 -0
  24. package/dist/audio/index.d.ts +21 -0
  25. package/dist/audio/index.d.ts.map +1 -0
  26. package/dist/audio/index.js +73 -0
  27. package/dist/audio/index.js.map +1 -0
  28. package/dist/base64.d.ts +3 -0
  29. package/dist/base64.d.ts.map +1 -0
  30. package/dist/base64.js +10 -0
  31. package/dist/base64.js.map +1 -0
  32. package/dist/compress/binary.d.ts +2 -0
  33. package/dist/compress/binary.d.ts.map +1 -0
  34. package/dist/compress/binary.js +4 -0
  35. package/dist/compress/binary.js.map +1 -0
  36. package/dist/compress/index.d.ts +59 -0
  37. package/dist/compress/index.d.ts.map +1 -0
  38. package/dist/compress/index.js +146 -0
  39. package/dist/compress/index.js.map +1 -0
  40. package/dist/instance.d.ts +25 -0
  41. package/dist/instance.d.ts.map +1 -0
  42. package/dist/instance.js +50 -0
  43. package/dist/instance.js.map +1 -0
  44. package/dist/mp3/binary.d.ts +2 -0
  45. package/dist/mp3/binary.d.ts.map +1 -0
  46. package/dist/mp3/binary.js +4 -0
  47. package/dist/mp3/binary.js.map +1 -0
  48. package/dist/mp3/index.d.ts +20 -0
  49. package/dist/mp3/index.d.ts.map +1 -0
  50. package/dist/mp3/index.js +49 -0
  51. package/dist/mp3/index.js.map +1 -0
  52. package/dist/render/binary.d.ts +2 -0
  53. package/dist/render/binary.d.ts.map +1 -0
  54. package/dist/render/binary.js +4 -0
  55. package/dist/render/binary.js.map +1 -0
  56. package/dist/render/bitmap-kernel.d.ts +118 -0
  57. package/dist/render/bitmap-kernel.d.ts.map +1 -0
  58. package/dist/render/bitmap-kernel.js +592 -0
  59. package/dist/render/bitmap-kernel.js.map +1 -0
  60. package/dist/render/draw-kernel.d.ts +79 -0
  61. package/dist/render/draw-kernel.d.ts.map +1 -0
  62. package/dist/render/draw-kernel.js +205 -0
  63. package/dist/render/draw-kernel.js.map +1 -0
  64. package/dist/render/dxt-encoder.d.ts +19 -0
  65. package/dist/render/dxt-encoder.d.ts.map +1 -0
  66. package/dist/render/dxt-encoder.js +95 -0
  67. package/dist/render/dxt-encoder.js.map +1 -0
  68. package/dist/render/index.d.ts +6 -0
  69. package/dist/render/index.d.ts.map +1 -0
  70. package/dist/render/index.js +11 -0
  71. package/dist/render/index.js.map +1 -0
  72. package/dist/render/lines.d.ts +55 -0
  73. package/dist/render/lines.d.ts.map +1 -0
  74. package/dist/render/lines.js +123 -0
  75. package/dist/render/lines.js.map +1 -0
  76. package/dist/render/module.d.ts +11 -0
  77. package/dist/render/module.d.ts.map +1 -0
  78. package/dist/render/module.js +27 -0
  79. package/dist/render/module.js.map +1 -0
  80. package/dist/render/pixel-ops.d.ts +77 -0
  81. package/dist/render/pixel-ops.d.ts.map +1 -0
  82. package/dist/render/pixel-ops.js +236 -0
  83. package/dist/render/pixel-ops.js.map +1 -0
  84. package/dist/render/tessellator.d.ts +90 -0
  85. package/dist/render/tessellator.d.ts.map +1 -0
  86. package/dist/render/tessellator.js +251 -0
  87. package/dist/render/tessellator.js.map +1 -0
  88. package/package.json +53 -3
  89. package/src/atf/index.ts +212 -0
  90. package/src/atf/jxr.ts +83 -0
  91. package/src/atf/parse.ts +263 -0
  92. package/src/audio/index.ts +93 -0
  93. package/src/base64.ts +10 -0
  94. package/src/compress/index.ts +225 -0
  95. package/src/instance.ts +53 -0
  96. package/src/mp3/index.ts +71 -0
  97. package/src/render/bitmap-kernel.ts +856 -0
  98. package/src/render/draw-kernel.ts +268 -0
  99. package/src/render/dxt-encoder.ts +121 -0
  100. package/src/render/index.ts +37 -0
  101. package/src/render/lines.ts +161 -0
  102. package/src/render/module.ts +30 -0
  103. package/src/render/pixel-ops.ts +356 -0
  104. package/src/render/tessellator.ts +367 -0
  105. package/src/webassembly.d.ts +22 -0
@@ -0,0 +1,79 @@
1
+ /**
2
+ * A draw, which its caller keeps and fills for each: the source's pixels
3
+ * and size and the rows it reads, the destination's pixels (read only) and
4
+ * width and the area drawn, and the numbers draw.zig takes.
5
+ */
6
+ export interface DrawJob {
7
+ source: Uint32Array;
8
+ sourceWidth: number;
9
+ sourceHeight: number;
10
+ /** The first row the draw reads, and how many. */
11
+ sourceTop: number;
12
+ sourceRows: number;
13
+ into: Uint32Array;
14
+ intoWidth: number;
15
+ x: number;
16
+ y: number;
17
+ width: number;
18
+ height: number;
19
+ /** composite's, unscaled at whole pixels (tx, ty), rather than drawBitmap's through the matrix. */
20
+ moved: boolean;
21
+ /** The matrix's inverse: a, b, c, d, tx, ty. */
22
+ inverse: Float64Array;
23
+ /** The prepared colour transform, multipliers in 256ths then offsets, red, green, blue, alpha. */
24
+ transform: Float64Array;
25
+ tx: number;
26
+ ty: number;
27
+ flags: number;
28
+ }
29
+ /** draw.zig's flags. */
30
+ export declare const DRAW_SMOOTH = 1;
31
+ export declare const DRAW_TRANSFORM = 2;
32
+ export declare const DRAW_OPAQUE = 4;
33
+ export declare const DRAW_SKIP_ZERO_ALPHA = 8;
34
+ /**
35
+ * What a draw did: refused, where the module could not take it and the
36
+ * caller draws it itself; drew nothing; or wrote the area, which `writeBack`
37
+ * then copies into the store.
38
+ */
39
+ export type DrawResult = "refused" | "untouched" | "written";
40
+ export declare class DrawKernel {
41
+ private wasm;
42
+ /** Whether making an instance failed once, after which the module is never tried again. */
43
+ private broken;
44
+ /** The input resetArena gave, and its bytes. */
45
+ private input;
46
+ private inputBytes;
47
+ private buffer;
48
+ private words;
49
+ private doubles;
50
+ private ints;
51
+ /** Where the last draw's area lies in the input. */
52
+ private area;
53
+ /** Whether the module drew since `idle` last asked. */
54
+ private busy;
55
+ /** How many draws the module took. */
56
+ drawn: number;
57
+ /** A job to fill for each draw. */
58
+ static job(): DrawJob;
59
+ /** Whether an instance is held, with its memory. */
60
+ get held(): boolean;
61
+ /** The job drawn in the module; never a write to the destination, which `writeBack` makes. */
62
+ draw(job: DrawJob): DrawResult;
63
+ /** The area the last draw wrote, copied into `into`. */
64
+ writeBack(job: DrawJob, into: Uint32Array): void;
65
+ /** Whether the module drew nothing since this was last asked. */
66
+ idle(): boolean;
67
+ /** The instance let go of, and its memory with it; the next draw makes another. */
68
+ release(): void;
69
+ private run;
70
+ /**
71
+ * Whether the input holds `bytes`: an instance made where there is none,
72
+ * one grown past KEEP_BYTES made anew, and the input taken anew where it
73
+ * is smaller.
74
+ */
75
+ private room;
76
+ /** The views of the memory made again where it grew, which detached them. */
77
+ private refresh;
78
+ }
79
+ //# sourceMappingURL=draw-kernel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draw-kernel.d.ts","sourceRoot":"","sources":["../../src/render/draw-kernel.ts"],"names":[],"mappings":"AAiBA;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,kDAAkD;IAClD,SAAS,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IAC9F,IAAI,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,CAQ7B;IAED,wDAAwD;IACxD,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAS/C;IAED,iEAAiE;IACjE,IAAI,IAAI,OAAO,CAId;IAED,mFAAmF;IACnF,OAAO,IAAI,IAAI,CAQd;IAED,OAAO,CAAC,GAAG;IAwDX;;;;OAIG;IACH,OAAO,CAAC,IAAI;IAsCZ,6EAA6E;IAC7E,OAAO,CAAC,OAAO;CAShB"}
@@ -0,0 +1,205 @@
1
+ // BitmapData.draw of a bitmap in the normal blend mode, in the render
2
+ // module (draw.zig), one call a draw. Each draw copies into the module's
3
+ // input the rows of the source it reads and the destination's area, and
4
+ // the area back out after: no source is kept between draws, which costs no
5
+ // more than keeping them did for a game drawing hundreds of small bitmaps
6
+ // a frame, and holds nothing for them. Its own instance, so that the
7
+ // filters' calls (BitmapKernel) do not reset its input, let go of when its
8
+ // owner says it went idle, and after a draw that grew it past KEEP_BYTES.
9
+ import { renderInstance } from "./module.js";
10
+ /** draw.zig's flags. */
11
+ export const DRAW_SMOOTH = 1;
12
+ export const DRAW_TRANSFORM = 2;
13
+ export const DRAW_OPAQUE = 4;
14
+ export const DRAW_SKIP_ZERO_ALPHA = 8;
15
+ // draw.zig's results.
16
+ const INVALID = 0;
17
+ const WRITTEN = 2;
18
+ /** draw.zig's DrawParams: 14 doubles, then 14 words. */
19
+ const PARAMS = 168;
20
+ /** The most a draw copies in, its source's rows and its area; a larger one is drawn by the caller. */
21
+ const DRAWN_BYTES = 32 << 20;
22
+ /** The input a new instance takes first. */
23
+ const FIRST_BYTES = 1 << 20;
24
+ /** The memory an instance keeps after a draw; past it, the instance is let go of. */
25
+ const KEEP_BYTES = 16 << 20;
26
+ export class DrawKernel {
27
+ wasm = null;
28
+ /** Whether making an instance failed once, after which the module is never tried again. */
29
+ broken = false;
30
+ /** The input resetArena gave, and its bytes. */
31
+ input = 0;
32
+ inputBytes = 0;
33
+ buffer = null;
34
+ words = new Uint32Array(0);
35
+ doubles = new Float64Array(0);
36
+ ints = new Int32Array(0);
37
+ /** Where the last draw's area lies in the input. */
38
+ area = 0;
39
+ /** Whether the module drew since `idle` last asked. */
40
+ busy = false;
41
+ /** How many draws the module took. */
42
+ drawn = 0;
43
+ /** A job to fill for each draw. */
44
+ static job() {
45
+ return {
46
+ source: new Uint32Array(0),
47
+ sourceWidth: 0,
48
+ sourceHeight: 0,
49
+ sourceTop: 0,
50
+ sourceRows: 0,
51
+ into: new Uint32Array(0),
52
+ intoWidth: 0,
53
+ x: 0,
54
+ y: 0,
55
+ width: 0,
56
+ height: 0,
57
+ moved: false,
58
+ inverse: new Float64Array(6),
59
+ transform: new Float64Array(8),
60
+ tx: 0,
61
+ ty: 0,
62
+ flags: 0,
63
+ };
64
+ }
65
+ /** Whether an instance is held, with its memory. */
66
+ get held() {
67
+ return this.wasm !== null;
68
+ }
69
+ /** The job drawn in the module; never a write to the destination, which `writeBack` makes. */
70
+ draw(job) {
71
+ try {
72
+ return this.run(job);
73
+ }
74
+ catch {
75
+ // A trap: never resume that instance.
76
+ this.release();
77
+ return "refused";
78
+ }
79
+ }
80
+ /** The area the last draw wrote, copied into `into`. */
81
+ writeBack(job, into) {
82
+ const { x, y, width: w, height: h, intoWidth } = job;
83
+ const base = this.area >> 2;
84
+ this.refresh();
85
+ const words = this.words;
86
+ for (let row = 0; row < h; row++) {
87
+ const at = base + row * w;
88
+ into.set(words.subarray(at, at + w), (y + row) * intoWidth + x);
89
+ }
90
+ }
91
+ /** Whether the module drew nothing since this was last asked. */
92
+ idle() {
93
+ const idle = !this.busy;
94
+ this.busy = false;
95
+ return idle;
96
+ }
97
+ /** The instance let go of, and its memory with it; the next draw makes another. */
98
+ release() {
99
+ this.wasm = null;
100
+ this.buffer = null;
101
+ this.words = new Uint32Array(0);
102
+ this.doubles = new Float64Array(0);
103
+ this.ints = new Int32Array(0);
104
+ this.input = 0;
105
+ this.inputBytes = 0;
106
+ }
107
+ run(job) {
108
+ const { sourceWidth: sw, sourceRows: rows, width: w, height: h } = job;
109
+ const sourceBytes = sw * rows * 4;
110
+ const areaBytes = w * h * 4;
111
+ if (job.source.length !== sw * job.sourceHeight ||
112
+ sourceBytes + areaBytes > DRAWN_BYTES ||
113
+ !this.room(PARAMS + sourceBytes + areaBytes)) {
114
+ return "refused";
115
+ }
116
+ const wasm = this.wasm;
117
+ this.refresh();
118
+ const { words, doubles, ints } = this;
119
+ const p = this.input;
120
+ const src = p + PARAMS;
121
+ this.area = src + sourceBytes;
122
+ const top = job.sourceTop * sw;
123
+ words.set(job.source.subarray(top, top + rows * sw), src >> 2);
124
+ const base = this.area >> 2;
125
+ const { into, intoWidth, x, y } = job;
126
+ for (let row = 0; row < h; row++) {
127
+ const at = (y + row) * intoWidth + x;
128
+ words.set(into.subarray(at, at + w), base + row * w);
129
+ }
130
+ const d = p >> 3;
131
+ doubles.set(job.inverse, d);
132
+ doubles.set(job.transform, d + 6);
133
+ const i = (p + 112) >> 2;
134
+ words[i] = src;
135
+ words[i + 1] = sw;
136
+ words[i + 2] = job.sourceHeight;
137
+ words[i + 3] = this.area;
138
+ ints[i + 4] = x;
139
+ ints[i + 5] = y;
140
+ words[i + 6] = w;
141
+ words[i + 7] = h;
142
+ words[i + 8] = job.flags;
143
+ ints[i + 9] = job.tx;
144
+ ints[i + 10] = job.ty;
145
+ words[i + 11] = job.sourceTop;
146
+ words[i + 12] = rows;
147
+ words[i + 13] = 0;
148
+ const result = job.moved ? wasm.compositePixels(p) : wasm.drawPixels(p);
149
+ if (result === INVALID) {
150
+ return "refused";
151
+ }
152
+ this.drawn++;
153
+ this.busy = true;
154
+ return result === WRITTEN ? "written" : "untouched";
155
+ }
156
+ /**
157
+ * Whether the input holds `bytes`: an instance made where there is none,
158
+ * one grown past KEEP_BYTES made anew, and the input taken anew where it
159
+ * is smaller.
160
+ */
161
+ room(bytes) {
162
+ if (this.broken) {
163
+ return false;
164
+ }
165
+ // Grown past what it keeps by a large draw before, it goes, and its memory with it.
166
+ if (this.wasm && this.wasm.memory.buffer.byteLength > KEEP_BYTES) {
167
+ this.release();
168
+ }
169
+ if (this.wasm && this.inputBytes >= bytes) {
170
+ return true;
171
+ }
172
+ if (!this.wasm) {
173
+ try {
174
+ this.wasm = renderInstance(() => {
175
+ throw new Error("the draw kernel takes no tessellator");
176
+ });
177
+ }
178
+ catch {
179
+ this.broken = true;
180
+ return false;
181
+ }
182
+ }
183
+ // Half again what is asked, so that a few larger draws do not each take it anew.
184
+ const want = Math.max(FIRST_BYTES, bytes + (bytes >> 1));
185
+ this.input = this.wasm.resetArena(want);
186
+ if (!this.input) {
187
+ // Out of memory: the instance goes, and the next draw that fits makes another.
188
+ this.release();
189
+ return false;
190
+ }
191
+ this.inputBytes = want;
192
+ return true;
193
+ }
194
+ /** The views of the memory made again where it grew, which detached them. */
195
+ refresh() {
196
+ const buffer = this.wasm.memory.buffer;
197
+ if (buffer !== this.buffer) {
198
+ this.buffer = buffer;
199
+ this.words = new Uint32Array(buffer);
200
+ this.doubles = new Float64Array(buffer);
201
+ this.ints = new Int32Array(buffer);
202
+ }
203
+ }
204
+ }
205
+ //# sourceMappingURL=draw-kernel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draw-kernel.js","sourceRoot":"","sources":["../../src/render/draw-kernel.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,yEAAyE;AACzE,wEAAwE;AACxE,2EAA2E;AAC3E,0EAA0E;AAC1E,qEAAqE;AACrE,2EAA2E;AAC3E,0EAA0E;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAsC7C,wBAAwB;AACxB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAChC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,oBAAoB,GAAG,C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,CAAC,KAAK,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;YACrC,IAAI,CAAC,OAAO,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;YACxC,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,19 @@
1
+ export declare class DxtEncoder {
2
+ private wasm;
3
+ private broken;
4
+ private input;
5
+ private inputBytes;
6
+ /** Successful native encodes, so a reference comparison can rule out falling back. */
7
+ encoded: number;
8
+ /** The memory kept now: a larger level's instance goes before the next call. */
9
+ get capacity(): number;
10
+ /** Release the instance and its memory; the next level makes another. */
11
+ release(): void;
12
+ /**
13
+ * Top-down RGBA to DXT1 or DXT5, matching the TS encoder's blocks. The
14
+ * result stays valid until the next call; null leaves the level to TS.
15
+ */
16
+ encode: (rgba: Uint8Array, dxt5: boolean, width: number, height: number) => Uint8Array | null;
17
+ private room;
18
+ }
19
+ //# sourceMappingURL=dxt-encoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dxt-encoder.d.ts","sourceRoot":"","sources":["../../src/render/dxt-encoder.ts"],"names":[],"mappings":"AAqBA,qBAAa,UAAU;IACrB,OAAO,CAAC,IAAI,CAA2B;IACvC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,UAAU,CAAK;IACvB,sFAAsF;IACtF,OAAO,SAAK;IAEZ,gFAAgF;IAChF,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,yEAAyE;IACzE,OAAO,IAAI,IAAI,CAId;IAED;;;OAGG;IACH,MAAM,SAAU,UAAU,QAAQ,OAAO,SAAS,MAAM,UAAU,MAAM,KAAG,UAAU,GAAG,IAAI,CAuC1F;IAEF,OAAO,CAAC,IAAI;CAkCb"}
@@ -0,0 +1,95 @@
1
+ // Compressed texture uploads, one whole level at a time in dxt.zig. The
2
+ // input is kept between levels and grown only as needed; the result is a
3
+ // view to consume before the next call, as context3d's TS encoder gives.
4
+ import { renderInstance } from "./module.js";
5
+ /** Enough to keep a 2048² DXT5 upload's input and output, including growth slack. */
6
+ const KEEP_BYTES = 32 << 20;
7
+ const FIRST_BYTES = 64 << 10;
8
+ export class DxtEncoder {
9
+ wasm = null;
10
+ broken = false;
11
+ input = 0;
12
+ inputBytes = 0;
13
+ /** Successful native encodes, so a reference comparison can rule out falling back. */
14
+ encoded = 0;
15
+ /** The memory kept now: a larger level's instance goes before the next call. */
16
+ get capacity() {
17
+ return this.wasm?.memory.buffer.byteLength ?? 0;
18
+ }
19
+ /** Release the instance and its memory; the next level makes another. */
20
+ release() {
21
+ this.wasm = null;
22
+ this.input = 0;
23
+ this.inputBytes = 0;
24
+ }
25
+ /**
26
+ * Top-down RGBA to DXT1 or DXT5, matching the TS encoder's blocks. The
27
+ * result stays valid until the next call; null leaves the level to TS.
28
+ */
29
+ encode = (rgba, dxt5, width, height) => {
30
+ if (!Number.isInteger(width) ||
31
+ !Number.isInteger(height) ||
32
+ width <= 0 ||
33
+ height <= 0 ||
34
+ width > 4096 ||
35
+ height > 4096 ||
36
+ rgba.length !== width * height * 4) {
37
+ return null;
38
+ }
39
+ try {
40
+ // A caller may use an earlier result as a smaller level's input. Preserve it if growth
41
+ // detaches that view, or a large earlier level causes its instance to be replaced.
42
+ if (this.wasm && rgba.buffer === this.wasm.memory.buffer) {
43
+ rgba = rgba.slice();
44
+ }
45
+ const length = Math.ceil(width / 4) * Math.ceil(height / 4) * (dxt5 ? 16 : 8);
46
+ if (!this.room(rgba.length + length)) {
47
+ return null;
48
+ }
49
+ const wasm = this.wasm;
50
+ const destination = this.input + rgba.length;
51
+ new Uint8Array(wasm.memory.buffer, this.input, rgba.length).set(rgba);
52
+ if (!wasm.encodeDxt(this.input, destination, width, height, dxt5 ? 1 : 0)) {
53
+ return null;
54
+ }
55
+ this.encoded++;
56
+ return new Uint8Array(wasm.memory.buffer, destination, length);
57
+ }
58
+ catch {
59
+ // A trapped instance is never resumed, and a refused module leaves the TS path available.
60
+ this.release();
61
+ return null;
62
+ }
63
+ };
64
+ room(bytes) {
65
+ if (this.broken) {
66
+ return false;
67
+ }
68
+ if (this.wasm && this.wasm.memory.buffer.byteLength > KEEP_BYTES) {
69
+ this.release();
70
+ }
71
+ if (this.wasm && this.inputBytes >= bytes) {
72
+ return true;
73
+ }
74
+ if (!this.wasm) {
75
+ try {
76
+ this.wasm = renderInstance(() => {
77
+ throw new Error("the DXT encoder takes no tessellator");
78
+ });
79
+ }
80
+ catch {
81
+ this.broken = true;
82
+ return false;
83
+ }
84
+ }
85
+ const want = Math.max(FIRST_BYTES, bytes + Math.floor(bytes / 2));
86
+ this.input = this.wasm.resetArena(want);
87
+ if (!this.input) {
88
+ this.release();
89
+ return false;
90
+ }
91
+ this.inputBytes = want;
92
+ return true;
93
+ }
94
+ }
95
+ //# sourceMappingURL=dxt-encoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dxt-encoder.js","sourceRoot":"","sources":["../../src/render/dxt-encoder.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,yEAAyE;AACzE,yEAAyE;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAc7C,qFAAqF;AACrF,MAAM,UAAU,GAAG,EAAE,IAAI,EAAE,CAAC;AAC5B,MAAM,WAAW,GAAG,EAAE,IAAI,EAAE,CAAC;AAE7B,MAAM,OAAO,UAAU;IACb,IAAI,GAAsB,IAAI,CAAC;IAC/B,MAAM,GAAG,KAAK,CAAC;IACf,KAAK,GAAG,CAAC,CAAC;IACV,UAAU,GAAG,CAAC,CAAC;IACvB,sFAAsF;IACtF,OAAO,GAAG,CAAC,CAAC;IAEZ,gFAAgF;IAChF,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,CAAC;IAClD,CAAC;IAED,yEAAyE;IACzE,OAAO;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C;gBACnB,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;QAClE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export { BitmapKernel, type BitmapKernelOptions, type BitmapRect, type BitmapSource, type ConvolutionFilter, type CopyOp, type LayerFilter, type PerlinSetup, type PixelRegion, } from "./bitmap-kernel.js";
2
+ export { DRAW_OPAQUE, DRAW_SKIP_ZERO_ALPHA, DRAW_SMOOTH, DRAW_TRANSFORM, type DrawJob, DrawKernel, type DrawResult, } from "./draw-kernel.js";
3
+ export { DxtEncoder } from "./dxt-encoder.js";
4
+ export { LineBuilder, type LineBuilderOptions, type LineGeometry } from "./lines.js";
5
+ export { type FillGeometry, type FillTessellate, PATH_CUBIC, PATH_CURVE, PATH_LINE, PATH_MOVE, Tessellator, type TessellatorOptions, } from "./tessellator.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,WAAW,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,WAAW,EACX,cAAc,EACd,KAAK,OAAO,EACZ,UAAU,EACV,KAAK,UAAU,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AACrF,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,UAAU,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,WAAW,EACX,KAAK,kBAAkB,GACxB,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,11 @@
1
+ // The render module's wrappers, each over an instance of its own: fills
2
+ // (Tessellator), a layer's lines (LineBuilder, also a Tessellator's
3
+ // `tessellate.lines`) and BitmapData's CPU filters and pixel operations
4
+ // (BitmapKernel), BitmapData.draw of a bitmap (DrawKernel), and DXT1/DXT5
5
+ // texture encoding (DxtEncoder).
6
+ export { BitmapKernel, } from "./bitmap-kernel.js";
7
+ export { DRAW_OPAQUE, DRAW_SKIP_ZERO_ALPHA, DRAW_SMOOTH, DRAW_TRANSFORM, DrawKernel, } from "./draw-kernel.js";
8
+ export { DxtEncoder } from "./dxt-encoder.js";
9
+ export { LineBuilder } from "./lines.js";
10
+ export { PATH_CUBIC, PATH_CURVE, PATH_LINE, PATH_MOVE, Tessellator, } from "./tessellator.js";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,oEAAoE;AACpE,wEAAwE;AACxE,0EAA0E;AAC1E,iCAAiC;AACjC,OAAO,EACL,YAAY,GASb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,WAAW,EACX,cAAc,EAEd,UAAU,GAEX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAA8C,MAAM,YAAY,CAAC;AACrF,OAAO,EAGL,UAAU,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,WAAW,GAEZ,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,55 @@
1
+ /** A layer's lines as triangles: two floats a vertex, its colour, and three indices a triangle. */
2
+ export interface LineGeometry {
3
+ positions: Float32Array;
4
+ colors: Uint32Array;
5
+ indices: Uint32Array;
6
+ }
7
+ export interface LineBuilderOptions {
8
+ /** Maximum arena address, including the C stack; at most 128 MiB. */
9
+ memoryLimit?: number;
10
+ /** Drop instances larger than this after each call. Defaults to 8 MiB. */
11
+ retainMemory?: number;
12
+ /** Fill outlines by the module's bands alone, never by libtess2: for tests of the bands. */
13
+ bands?: boolean;
14
+ }
15
+ /**
16
+ * A shape layer's lines built in one call by the render module's
17
+ * strokes.zig, its outlines filled by the module's libtess2, or its bands
18
+ * where libtess2 fails: the caller writes the layer into input() as
19
+ * strokes.zig reads it (the player's scene/strokes.ts) and calls build()
20
+ * with its length. Its instance is its own, apart from any Tessellator's,
21
+ * and held to the same limits as a Tessellator's (TessellatorOptions),
22
+ * which pass them on: where a fill would have run out of memory, so do the
23
+ * lines, and none are drawn.
24
+ */
25
+ export declare class LineBuilder {
26
+ private instance;
27
+ private view;
28
+ private layout;
29
+ /** libtess2 trapped the last instance: the next fills its outlines by the bands alone. */
30
+ private trapped;
31
+ private lastUnwound;
32
+ private readonly limit;
33
+ private readonly keep;
34
+ private readonly bands;
35
+ constructor(options?: LineBuilderOptions);
36
+ /** Whether the last build() unwound, which the next, in a new instance by the bands, may not. */
37
+ get unwound(): boolean;
38
+ /** Current retained Wasm capacity. */
39
+ get capacity(): number;
40
+ /** A view of at least `n` f64s of input, valid until build(); null where no instance could be made. */
41
+ input(n: number): Float64Array | null;
42
+ /**
43
+ * The layer in the input's first `length` f64s, copied out in one
44
+ * block: null for none, undefined where the module refused it (a
45
+ * position not a number) or failed. Where libtess2 trapped, the next
46
+ * instance fills the layer's outlines by the bands alone, for the
47
+ * caller's next input() and build().
48
+ */
49
+ build(length: number): LineGeometry | null | undefined;
50
+ /** strokes.zig's layout, read again where memory grew. */
51
+ private header;
52
+ /** The instance let go, its memory with it; the next input() makes another. */
53
+ dispose(): void;
54
+ }
55
+ //# sourceMappingURL=lines.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lines.d.ts","sourceRoot":"","sources":["../../src/render/lines.ts"],"names":[],"mappings":"AAEA,mGAAmG;AACnG,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,YAAY,CAAC;IACxB,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,WAAW,CAAC;CACtB;AAWD,MAAM,WAAW,kBAAkB;IACjC,qEAAqE;IACrE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0EAA0E;IAC1E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4FAA4F;IAC5F,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;GASG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,IAAI,CAAuB;IACnC,OAAO,CAAC,MAAM,CAAsB;IACpC,0FAA0F;IAC1F,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAU;IAEhC,YAAY,OAAO,GAAE,kBAAuB,EAK3C;IAED,iGAAiG;IACjG,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,sCAAsC;IACtC,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,uGAAuG;IACvG,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CA2BpC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,GAAG,SAAS,CAyCrD;IAED,0DAA0D;IAC1D,OAAO,CAAC,MAAM;IAQd,+EAA+E;IAC/E,OAAO,IAAI,IAAI,CAId;CACF"}
@@ -0,0 +1,123 @@
1
+ import { renderInstance, renderModule } from "./module.js";
2
+ /**
3
+ * A shape layer's lines built in one call by the render module's
4
+ * strokes.zig, its outlines filled by the module's libtess2, or its bands
5
+ * where libtess2 fails: the caller writes the layer into input() as
6
+ * strokes.zig reads it (the player's scene/strokes.ts) and calls build()
7
+ * with its length. Its instance is its own, apart from any Tessellator's,
8
+ * and held to the same limits as a Tessellator's (TessellatorOptions),
9
+ * which pass them on: where a fill would have run out of memory, so do the
10
+ * lines, and none are drawn.
11
+ */
12
+ export class LineBuilder {
13
+ instance = null;
14
+ view = new Float64Array(0);
15
+ layout = new Uint32Array(0);
16
+ /** libtess2 trapped the last instance: the next fills its outlines by the bands alone. */
17
+ trapped = false;
18
+ lastUnwound = false;
19
+ limit;
20
+ keep;
21
+ bands;
22
+ constructor(options = {}) {
23
+ this.limit = options.memoryLimit ?? 128 << 20;
24
+ this.keep = options.retainMemory ?? 8 << 20;
25
+ this.bands = options.bands ?? false;
26
+ renderModule();
27
+ }
28
+ /** Whether the last build() unwound, which the next, in a new instance by the bands, may not. */
29
+ get unwound() {
30
+ return this.lastUnwound;
31
+ }
32
+ /** Current retained Wasm capacity. */
33
+ get capacity() {
34
+ return this.instance?.memory.buffer.byteLength ?? 0;
35
+ }
36
+ /** A view of at least `n` f64s of input, valid until build(); null where no instance could be made. */
37
+ input(n) {
38
+ if (!this.instance) {
39
+ try {
40
+ this.instance = renderInstance(() => {
41
+ throw new Error("line tessellation allocation failed");
42
+ });
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ this.instance.setLimit(this.limit);
48
+ this.instance.bandsOnly(Number(this.bands || this.trapped));
49
+ }
50
+ const x = this.instance;
51
+ if (n > this.view.length || this.view.buffer !== x.memory.buffer) {
52
+ const size = Math.max(n, this.view.length * 2, 1024);
53
+ const at = x.lineInput(size);
54
+ if (!at) {
55
+ this.dispose();
56
+ return null;
57
+ }
58
+ this.view = new Float64Array(x.memory.buffer, at, size);
59
+ }
60
+ return this.view;
61
+ }
62
+ /**
63
+ * The layer in the input's first `length` f64s, copied out in one
64
+ * block: null for none, undefined where the module refused it (a
65
+ * position not a number) or failed. Where libtess2 trapped, the next
66
+ * instance fills the layer's outlines by the bands alone, for the
67
+ * caller's next input() and build().
68
+ */
69
+ build(length) {
70
+ this.lastUnwound = false;
71
+ const x = this.instance;
72
+ if (!x) {
73
+ return undefined;
74
+ }
75
+ try {
76
+ const status = x.lineBuild(length);
77
+ // Built without unwinding: libtess2 again for the next.
78
+ if (this.trapped) {
79
+ this.trapped = false;
80
+ x.bandsOnly(Number(this.bands));
81
+ }
82
+ if (status !== 0) {
83
+ return undefined;
84
+ }
85
+ const [at, vertices, count] = this.header(x);
86
+ if (count === 0) {
87
+ return null;
88
+ }
89
+ const copy = x.memory.buffer.slice(at, at + (vertices * 3 + count) * 4);
90
+ return {
91
+ positions: new Float32Array(copy, 0, vertices * 2),
92
+ colors: new Uint32Array(copy, vertices * 8, vertices),
93
+ indices: new Uint32Array(copy, vertices * 12, count),
94
+ };
95
+ }
96
+ catch {
97
+ // libtess2 unwound through the failure import: never resume that instance.
98
+ this.dispose();
99
+ this.trapped = true;
100
+ this.lastUnwound = true;
101
+ return undefined;
102
+ }
103
+ finally {
104
+ if (this.capacity > this.keep) {
105
+ this.dispose();
106
+ }
107
+ }
108
+ }
109
+ /** strokes.zig's layout, read again where memory grew. */
110
+ header(x) {
111
+ if (this.layout.buffer !== x.memory.buffer) {
112
+ this.layout = new Uint32Array(x.memory.buffer, x.lineHeader(), 3);
113
+ }
114
+ return this.layout;
115
+ }
116
+ /** The instance let go, its memory with it; the next input() makes another. */
117
+ dispose() {
118
+ this.instance = null;
119
+ this.view = new Float64Array(0);
120
+ this.layout = new Uint32Array(0);
121
+ }
122
+ }
123
+ //# sourceMappingURL=lines.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lines.js","sourceRoot":"","sources":["../../src/render/lines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA2B3D;;;;;;;;;GASG;AACH,MAAM,OAAO,WAAW;IACd,QAAQ,GAAyB,IAAI,CAAC;IACtC,IAAI,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;IAC3B,MAAM,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;IACpC,0FAA0F;IAClF,OAAO,GAAG,KAAK,CAAC;IAChB,WAAW,GAAG,KAAK,CAAC;IACX,KAAK,CAAS;IACd,IAAI,CAAS;IACb,KAAK,CAAU;IAEhC,YAAY,OAAO,GAAuB,EAAE;QAC1C,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,WAAW,IAAI,GAAG,IAAI,EAAE,CAAC;QAC9C,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,YAAY,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5C,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC;QACpC,YAAY,EAAE,CAAC;IACjB,CAAC;IAED,iGAAiG;IACjG,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,sCAAsC;IACtC,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,uGAAuG;IACvG,KAAK,CAAC,CAAS;QACb,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,IAAI,CAAC;gBACH,IAAI,CAAC,QAAQ,GAAG,cAAc,CAAC,GAAG,EAAE;oBAClC,MAAM,IAAI,KAAK,CAAC,qCAAqC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