@al8b/screen 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 (68) hide show
  1. package/README.md +23 -0
  2. package/dist/core/base-screen.d.mts +84 -0
  3. package/dist/core/base-screen.d.ts +84 -0
  4. package/dist/core/base-screen.js +419 -0
  5. package/dist/core/base-screen.js.map +1 -0
  6. package/dist/core/base-screen.mjs +396 -0
  7. package/dist/core/base-screen.mjs.map +1 -0
  8. package/dist/core/index.d.mts +10 -0
  9. package/dist/core/index.d.ts +10 -0
  10. package/dist/core/index.js +1208 -0
  11. package/dist/core/index.js.map +1 -0
  12. package/dist/core/index.mjs +1183 -0
  13. package/dist/core/index.mjs.map +1 -0
  14. package/dist/core/screen.d.mts +15 -0
  15. package/dist/core/screen.d.ts +15 -0
  16. package/dist/core/screen.js +1209 -0
  17. package/dist/core/screen.js.map +1 -0
  18. package/dist/core/screen.mjs +1184 -0
  19. package/dist/core/screen.mjs.map +1 -0
  20. package/dist/drawing/primitives-screen.d.mts +28 -0
  21. package/dist/drawing/primitives-screen.d.ts +28 -0
  22. package/dist/drawing/primitives-screen.js +685 -0
  23. package/dist/drawing/primitives-screen.js.map +1 -0
  24. package/dist/drawing/primitives-screen.mjs +662 -0
  25. package/dist/drawing/primitives-screen.mjs.map +1 -0
  26. package/dist/drawing/sprite-screen.d.mts +41 -0
  27. package/dist/drawing/sprite-screen.d.ts +41 -0
  28. package/dist/drawing/sprite-screen.js +853 -0
  29. package/dist/drawing/sprite-screen.js.map +1 -0
  30. package/dist/drawing/sprite-screen.mjs +830 -0
  31. package/dist/drawing/sprite-screen.mjs.map +1 -0
  32. package/dist/drawing/text-screen.d.mts +19 -0
  33. package/dist/drawing/text-screen.d.ts +19 -0
  34. package/dist/drawing/text-screen.js +909 -0
  35. package/dist/drawing/text-screen.js.map +1 -0
  36. package/dist/drawing/text-screen.mjs +884 -0
  37. package/dist/drawing/text-screen.mjs.map +1 -0
  38. package/dist/index.d.mts +10 -0
  39. package/dist/index.d.ts +10 -0
  40. package/dist/index.js +1210 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/index.mjs +1184 -0
  43. package/dist/index.mjs.map +1 -0
  44. package/dist/tri/index.d.mts +3 -0
  45. package/dist/tri/index.d.ts +3 -0
  46. package/dist/tri/index.js +231 -0
  47. package/dist/tri/index.js.map +1 -0
  48. package/dist/tri/index.mjs +203 -0
  49. package/dist/tri/index.mjs.map +1 -0
  50. package/dist/tri/triangle-screen.d.mts +16 -0
  51. package/dist/tri/triangle-screen.d.ts +16 -0
  52. package/dist/tri/triangle-screen.js +1147 -0
  53. package/dist/tri/triangle-screen.js.map +1 -0
  54. package/dist/tri/triangle-screen.mjs +1122 -0
  55. package/dist/tri/triangle-screen.mjs.map +1 -0
  56. package/dist/tri/ttri.d.mts +71 -0
  57. package/dist/tri/ttri.d.ts +71 -0
  58. package/dist/tri/ttri.js +229 -0
  59. package/dist/tri/ttri.js.map +1 -0
  60. package/dist/tri/ttri.mjs +203 -0
  61. package/dist/tri/ttri.mjs.map +1 -0
  62. package/dist/types/index.d.mts +64 -0
  63. package/dist/types/index.d.ts +64 -0
  64. package/dist/types/index.js +19 -0
  65. package/dist/types/index.js.map +1 -0
  66. package/dist/types/index.mjs +1 -0
  67. package/dist/types/index.mjs.map +1 -0
  68. package/package.json +37 -0
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # @al8b/screen
2
+
3
+ Main rendering surface for L8B. It owns the high-level screen abstraction, text and sprite drawing layers, and the triangle rasterization helpers used for lower-level rendering.
4
+
5
+ ## Public API
6
+
7
+ - `Screen` (`default`)
8
+ - `ZBuffer`
9
+ - Types: `TextureSource`, `TexVert`, `Vec2`, `Vec3`
10
+ - Shared screen types from `./types`
11
+
12
+ ## Notes
13
+
14
+ - Depends on `@al8b/image`, `@al8b/map`, and `@al8b/sprites`.
15
+ - This is the primary render surface exposed through the runtime's script API.
16
+
17
+ ## Scripts
18
+
19
+ ```bash
20
+ bun run build
21
+ bun run test
22
+ bun run clean
23
+ ```
@@ -0,0 +1,84 @@
1
+ import { ZBuffer } from '../tri/ttri.mjs';
2
+ import { ScreenInterface, ScreenOptions } from '../types/index.mjs';
3
+ import '@al8b/map';
4
+ import '@al8b/sprites';
5
+
6
+ /**
7
+ * BaseScreen encapsulates canvas/context management plus shared drawing state.
8
+ * Feature-specific behaviors (primitives, sprites, text, triangles) extend this class.
9
+ */
10
+ declare class BaseScreen {
11
+ protected canvas: HTMLCanvasElement;
12
+ protected context: CanvasRenderingContext2D;
13
+ protected runtime: any;
14
+ width: number;
15
+ height: number;
16
+ protected alpha: number;
17
+ protected pixelated: number;
18
+ protected line_width: number;
19
+ protected font: string;
20
+ protected translation_x: number;
21
+ protected translation_y: number;
22
+ protected rotation: number;
23
+ protected scale_x: number;
24
+ protected scale_y: number;
25
+ protected screen_transform: boolean;
26
+ protected object_rotation: number;
27
+ protected object_scale_x: number;
28
+ protected object_scale_y: number;
29
+ protected anchor_x: number;
30
+ protected anchor_y: number;
31
+ protected blending: Record<string, string>;
32
+ protected font_load_requested: Record<string, boolean>;
33
+ protected font_loaded: Record<string, boolean>;
34
+ protected interfaceCache: ScreenInterface | null;
35
+ protected cursor: string;
36
+ protected cursor_visibility: string;
37
+ protected last_mouse_move: number;
38
+ protected zBuffer: ZBuffer;
39
+ constructor(options?: ScreenOptions);
40
+ protected initContext(): void;
41
+ /**
42
+ * Initialize draw state (called before each draw frame)
43
+ */
44
+ initDraw(): void;
45
+ /**
46
+ * Update interface dimensions (called before each draw frame)
47
+ */
48
+ updateInterface(): void;
49
+ clear(color?: string): void;
50
+ setColor(color: string | number): void;
51
+ setAlpha(alpha: number): void;
52
+ setPixelated(pixelated: number): void;
53
+ setBlending(blending: string): void;
54
+ setLineWidth(width: number): void;
55
+ setLineDash(dash: number[] | null): void;
56
+ setLinearGradient(x1: number, y1: number, x2: number, y2: number, c1: string, c2: string): void;
57
+ setRadialGradient(x: number, y: number, radius: number, c1: string, c2: string): void;
58
+ setFont(font: string): void;
59
+ loadFont(font?: string): void;
60
+ isFontReady(font?: string): number;
61
+ setTranslation(tx: number, ty: number): void;
62
+ setScale(x: number, y: number): void;
63
+ setRotation(rotation: number): void;
64
+ protected updateScreenTransform(): void;
65
+ setDrawAnchor(ax: number, ay: number): void;
66
+ setDrawRotation(rotation: number): void;
67
+ setDrawScale(x: number, y?: number): void;
68
+ protected initDrawOp(x: number, y: number, object_transform?: boolean): boolean;
69
+ protected closeDrawOp(): void;
70
+ /**
71
+ * Check mouse cursor visibility
72
+ * Auto-hides cursor after 4 seconds of inactivity
73
+ */
74
+ protected checkMouseCursor(): void;
75
+ /**
76
+ * Set cursor visibility
77
+ */
78
+ setCursorVisible(visible: boolean): void;
79
+ getCanvas(): HTMLCanvasElement;
80
+ getContext(): CanvasRenderingContext2D;
81
+ resize(width?: number, height?: number): void;
82
+ }
83
+
84
+ export { BaseScreen };
@@ -0,0 +1,84 @@
1
+ import { ZBuffer } from '../tri/ttri.js';
2
+ import { ScreenInterface, ScreenOptions } from '../types/index.js';
3
+ import '@al8b/map';
4
+ import '@al8b/sprites';
5
+
6
+ /**
7
+ * BaseScreen encapsulates canvas/context management plus shared drawing state.
8
+ * Feature-specific behaviors (primitives, sprites, text, triangles) extend this class.
9
+ */
10
+ declare class BaseScreen {
11
+ protected canvas: HTMLCanvasElement;
12
+ protected context: CanvasRenderingContext2D;
13
+ protected runtime: any;
14
+ width: number;
15
+ height: number;
16
+ protected alpha: number;
17
+ protected pixelated: number;
18
+ protected line_width: number;
19
+ protected font: string;
20
+ protected translation_x: number;
21
+ protected translation_y: number;
22
+ protected rotation: number;
23
+ protected scale_x: number;
24
+ protected scale_y: number;
25
+ protected screen_transform: boolean;
26
+ protected object_rotation: number;
27
+ protected object_scale_x: number;
28
+ protected object_scale_y: number;
29
+ protected anchor_x: number;
30
+ protected anchor_y: number;
31
+ protected blending: Record<string, string>;
32
+ protected font_load_requested: Record<string, boolean>;
33
+ protected font_loaded: Record<string, boolean>;
34
+ protected interfaceCache: ScreenInterface | null;
35
+ protected cursor: string;
36
+ protected cursor_visibility: string;
37
+ protected last_mouse_move: number;
38
+ protected zBuffer: ZBuffer;
39
+ constructor(options?: ScreenOptions);
40
+ protected initContext(): void;
41
+ /**
42
+ * Initialize draw state (called before each draw frame)
43
+ */
44
+ initDraw(): void;
45
+ /**
46
+ * Update interface dimensions (called before each draw frame)
47
+ */
48
+ updateInterface(): void;
49
+ clear(color?: string): void;
50
+ setColor(color: string | number): void;
51
+ setAlpha(alpha: number): void;
52
+ setPixelated(pixelated: number): void;
53
+ setBlending(blending: string): void;
54
+ setLineWidth(width: number): void;
55
+ setLineDash(dash: number[] | null): void;
56
+ setLinearGradient(x1: number, y1: number, x2: number, y2: number, c1: string, c2: string): void;
57
+ setRadialGradient(x: number, y: number, radius: number, c1: string, c2: string): void;
58
+ setFont(font: string): void;
59
+ loadFont(font?: string): void;
60
+ isFontReady(font?: string): number;
61
+ setTranslation(tx: number, ty: number): void;
62
+ setScale(x: number, y: number): void;
63
+ setRotation(rotation: number): void;
64
+ protected updateScreenTransform(): void;
65
+ setDrawAnchor(ax: number, ay: number): void;
66
+ setDrawRotation(rotation: number): void;
67
+ setDrawScale(x: number, y?: number): void;
68
+ protected initDrawOp(x: number, y: number, object_transform?: boolean): boolean;
69
+ protected closeDrawOp(): void;
70
+ /**
71
+ * Check mouse cursor visibility
72
+ * Auto-hides cursor after 4 seconds of inactivity
73
+ */
74
+ protected checkMouseCursor(): void;
75
+ /**
76
+ * Set cursor visibility
77
+ */
78
+ setCursorVisible(visible: boolean): void;
79
+ getCanvas(): HTMLCanvasElement;
80
+ getContext(): CanvasRenderingContext2D;
81
+ resize(width?: number, height?: number): void;
82
+ }
83
+
84
+ export { BaseScreen };
@@ -0,0 +1,419 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/core/base-screen.ts
22
+ var base_screen_exports = {};
23
+ __export(base_screen_exports, {
24
+ BaseScreen: () => BaseScreen
25
+ });
26
+ module.exports = __toCommonJS(base_screen_exports);
27
+ var import_diagnostics = require("@al8b/diagnostics");
28
+
29
+ // src/tri/ttri.ts
30
+ var ZBuffer = class {
31
+ static {
32
+ __name(this, "ZBuffer");
33
+ }
34
+ buffer;
35
+ width;
36
+ height;
37
+ constructor(width, height) {
38
+ this.width = width;
39
+ this.height = height;
40
+ this.buffer = new Float32Array(width * height);
41
+ }
42
+ clear() {
43
+ this.buffer.fill(0);
44
+ }
45
+ get(x, y) {
46
+ return this.buffer[y * this.width + x] || 0;
47
+ }
48
+ set(x, y, z) {
49
+ this.buffer[y * this.width + x] = z;
50
+ }
51
+ resize(width, height) {
52
+ if (this.width !== width || this.height !== height) {
53
+ this.width = width;
54
+ this.height = height;
55
+ this.buffer = new Float32Array(width * height);
56
+ }
57
+ }
58
+ };
59
+
60
+ // src/core/base-screen.ts
61
+ var BaseScreen = class {
62
+ static {
63
+ __name(this, "BaseScreen");
64
+ }
65
+ canvas;
66
+ context;
67
+ runtime;
68
+ width;
69
+ height;
70
+ // Drawing state
71
+ alpha = 1;
72
+ pixelated = 1;
73
+ line_width = 1;
74
+ font = "BitCell";
75
+ // Transformations
76
+ translation_x = 0;
77
+ translation_y = 0;
78
+ rotation = 0;
79
+ scale_x = 1;
80
+ scale_y = 1;
81
+ screen_transform = false;
82
+ // Object transformations
83
+ object_rotation = 0;
84
+ object_scale_x = 1;
85
+ object_scale_y = 1;
86
+ anchor_x = 0;
87
+ anchor_y = 0;
88
+ // Blending + font caches
89
+ blending = {};
90
+ font_load_requested = {};
91
+ font_loaded = {};
92
+ // Interface cache
93
+ interfaceCache = null;
94
+ // Cursor management
95
+ cursor = "default";
96
+ cursor_visibility = "auto";
97
+ last_mouse_move = Date.now();
98
+ // 3D helper
99
+ zBuffer;
100
+ constructor(options = {}) {
101
+ this.runtime = options.runtime;
102
+ if (options.canvas) {
103
+ this.canvas = options.canvas;
104
+ if (this.canvas.width === 0 || this.canvas.height === 0) {
105
+ this.canvas.width = options.width || 1080;
106
+ this.canvas.height = options.height || 1920;
107
+ }
108
+ } else {
109
+ this.canvas = document.createElement("canvas");
110
+ this.canvas.width = options.width || 1080;
111
+ this.canvas.height = options.height || 1920;
112
+ }
113
+ this.initContext();
114
+ this.blending = {
115
+ normal: "source-over",
116
+ additive: "lighter"
117
+ };
118
+ const blendModes = [
119
+ "source-over",
120
+ "source-in",
121
+ "source-out",
122
+ "source-atop",
123
+ "destination-over",
124
+ "destination-in",
125
+ "destination-out",
126
+ "destination-atop",
127
+ "lighter",
128
+ "copy",
129
+ "xor",
130
+ "multiply",
131
+ "screen",
132
+ "overlay",
133
+ "darken",
134
+ "lighten",
135
+ "color-dodge",
136
+ "color-burn",
137
+ "hard-light",
138
+ "soft-light",
139
+ "difference",
140
+ "exclusion",
141
+ "hue",
142
+ "saturation",
143
+ "color",
144
+ "luminosity"
145
+ ];
146
+ for (const mode of blendModes) {
147
+ this.blending[mode] = mode;
148
+ }
149
+ this.loadFont(this.font);
150
+ this.zBuffer = new ZBuffer(this.canvas.width, this.canvas.height);
151
+ this.cursor = "default";
152
+ this.canvas.addEventListener("mousemove", () => {
153
+ this.last_mouse_move = Date.now();
154
+ if (this.cursor !== "default" && this.cursor_visibility === "auto") {
155
+ this.cursor = "default";
156
+ this.canvas.style.cursor = "default";
157
+ }
158
+ });
159
+ this.canvas.addEventListener("contextrestored", () => {
160
+ this.initContext();
161
+ });
162
+ setInterval(() => this.checkMouseCursor(), 1e3);
163
+ this.cursor_visibility = "auto";
164
+ }
165
+ initContext() {
166
+ const ctx = this.canvas.getContext("2d", {
167
+ alpha: false
168
+ });
169
+ if (!ctx) {
170
+ const diagnostic = (0, import_diagnostics.createDiagnostic)(import_diagnostics.APIErrorCode.E7001);
171
+ const formatted = (0, import_diagnostics.formatForBrowser)(diagnostic);
172
+ (0, import_diagnostics.reportRuntimeError)(this.runtime?.listener, import_diagnostics.APIErrorCode.E7001, {});
173
+ throw new Error(formatted);
174
+ }
175
+ if (ctx !== this.context) {
176
+ this.context = ctx;
177
+ } else {
178
+ this.context.restore();
179
+ }
180
+ this.context.save();
181
+ this.context.translate(this.canvas.width / 2, this.canvas.height / 2);
182
+ const ratio = Math.min(this.canvas.width / 200, this.canvas.height / 200);
183
+ this.context.scale(ratio, ratio);
184
+ this.width = this.canvas.width / ratio;
185
+ this.height = this.canvas.height / ratio;
186
+ this.context.lineCap = "round";
187
+ }
188
+ /**
189
+ * Initialize draw state (called before each draw frame)
190
+ */
191
+ initDraw() {
192
+ this.alpha = 1;
193
+ this.line_width = 1;
194
+ }
195
+ /**
196
+ * Update interface dimensions (called before each draw frame)
197
+ */
198
+ updateInterface() {
199
+ if (this.interfaceCache) {
200
+ this.interfaceCache.width = this.width;
201
+ this.interfaceCache.height = this.height;
202
+ }
203
+ }
204
+ clear(color) {
205
+ this.context.globalAlpha = 1;
206
+ this.context.globalCompositeOperation = "source-over";
207
+ this.context.fillStyle = color || "#000";
208
+ this.context.strokeStyle = color || "#000";
209
+ this.context.fillRect(-this.width / 2, -this.height / 2, this.width, this.height);
210
+ this.zBuffer.clear();
211
+ }
212
+ setColor(color) {
213
+ if (!color) return;
214
+ if (!Number.isNaN(Number.parseInt(String(color)))) {
215
+ const num = Number.parseInt(String(color));
216
+ const r = Math.floor(num / 100) % 10 / 9 * 255;
217
+ const g = Math.floor(num / 10) % 10 / 9 * 255;
218
+ const b = num % 10 / 9 * 255;
219
+ const c = 4278190080 + (r << 16) + (g << 8) + b;
220
+ const hex = "#" + c.toString(16).substring(2, 8);
221
+ this.context.fillStyle = hex;
222
+ this.context.strokeStyle = hex;
223
+ } else if (typeof color === "string") {
224
+ const isValidColor = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(color) || /^rgb\(|^rgba\(|^hsl\(|^hsla\(/.test(color) || /^(red|green|blue|yellow|cyan|magenta|black|white|gray|grey|orange|pink|purple|brown|transparent)$/i.test(color);
225
+ if (!isValidColor) {
226
+ (0, import_diagnostics.reportRuntimeError)(this.runtime?.listener, import_diagnostics.APIErrorCode.E7003, {
227
+ color
228
+ });
229
+ return;
230
+ }
231
+ this.context.fillStyle = color;
232
+ this.context.strokeStyle = color;
233
+ }
234
+ }
235
+ setAlpha(alpha) {
236
+ this.alpha = alpha;
237
+ }
238
+ setPixelated(pixelated) {
239
+ this.pixelated = pixelated;
240
+ }
241
+ setBlending(blending) {
242
+ const blend = this.blending[blending || "normal"];
243
+ if (!blend) {
244
+ (0, import_diagnostics.reportRuntimeError)(this.runtime?.listener, import_diagnostics.APIErrorCode.E7007, {
245
+ blendMode: blending
246
+ });
247
+ this.context.globalCompositeOperation = "source-over";
248
+ return;
249
+ }
250
+ this.context.globalCompositeOperation = blend;
251
+ }
252
+ setLineWidth(width) {
253
+ this.line_width = width;
254
+ }
255
+ setLineDash(dash) {
256
+ if (!Array.isArray(dash)) {
257
+ this.context.setLineDash([]);
258
+ } else {
259
+ this.context.setLineDash(dash);
260
+ }
261
+ }
262
+ setLinearGradient(x1, y1, x2, y2, c1, c2) {
263
+ const grd = this.context.createLinearGradient(x1, -y1, x2, -y2);
264
+ grd.addColorStop(0, c1);
265
+ grd.addColorStop(1, c2);
266
+ this.context.fillStyle = grd;
267
+ this.context.strokeStyle = grd;
268
+ }
269
+ setRadialGradient(x, y, radius, c1, c2) {
270
+ const grd = this.context.createRadialGradient(x, -y, 0, x, -y, radius);
271
+ grd.addColorStop(0, c1);
272
+ grd.addColorStop(1, c2);
273
+ this.context.fillStyle = grd;
274
+ this.context.strokeStyle = grd;
275
+ }
276
+ setFont(font) {
277
+ this.font = font || "Verdana";
278
+ this.loadFont(this.font);
279
+ }
280
+ loadFont(font = "BitCell") {
281
+ if (this.font_load_requested[font]) {
282
+ return;
283
+ }
284
+ this.font_load_requested[font] = true;
285
+ try {
286
+ document.fonts?.load?.(`16pt ${font}`).catch(() => {
287
+ (0, import_diagnostics.reportRuntimeError)(this.runtime?.listener, import_diagnostics.APIErrorCode.E7006, {
288
+ font
289
+ });
290
+ });
291
+ } catch {
292
+ (0, import_diagnostics.reportRuntimeError)(this.runtime?.listener, import_diagnostics.APIErrorCode.E7006, {
293
+ font
294
+ });
295
+ }
296
+ }
297
+ isFontReady(font = this.font) {
298
+ if (this.font_loaded[font]) {
299
+ return 1;
300
+ }
301
+ try {
302
+ const ready = document.fonts?.check?.(`16pt ${font}`) ?? true;
303
+ if (ready) {
304
+ this.font_loaded[font] = true;
305
+ }
306
+ return ready ? 1 : 0;
307
+ } catch {
308
+ return 1;
309
+ }
310
+ }
311
+ setTranslation(tx, ty) {
312
+ this.translation_x = isFinite(tx) ? tx : 0;
313
+ this.translation_y = isFinite(ty) ? ty : 0;
314
+ this.updateScreenTransform();
315
+ }
316
+ setScale(x, y) {
317
+ this.scale_x = isFinite(x) && x !== 0 ? x : 1;
318
+ this.scale_y = isFinite(y) && y !== 0 ? y : 1;
319
+ this.updateScreenTransform();
320
+ }
321
+ setRotation(rotation) {
322
+ this.rotation = isFinite(rotation) ? rotation : 0;
323
+ this.updateScreenTransform();
324
+ }
325
+ updateScreenTransform() {
326
+ this.screen_transform = this.translation_x !== 0 || this.translation_y !== 0 || this.scale_x !== 1 || this.scale_y !== 1 || this.rotation !== 0;
327
+ }
328
+ setDrawAnchor(ax, ay) {
329
+ this.anchor_x = typeof ax === "number" ? ax : 0;
330
+ this.anchor_y = typeof ay === "number" ? ay : 0;
331
+ }
332
+ setDrawRotation(rotation) {
333
+ this.object_rotation = rotation;
334
+ }
335
+ setDrawScale(x, y = x) {
336
+ this.object_scale_x = x;
337
+ this.object_scale_y = y;
338
+ }
339
+ initDrawOp(x, y, object_transform = true) {
340
+ let res = false;
341
+ if (this.screen_transform) {
342
+ this.context.save();
343
+ res = true;
344
+ this.context.translate(this.translation_x, -this.translation_y);
345
+ this.context.scale(this.scale_x, this.scale_y);
346
+ this.context.rotate(-this.rotation / 180 * Math.PI);
347
+ this.context.translate(x, y);
348
+ }
349
+ if (object_transform && (this.object_rotation !== 0 || this.object_scale_x !== 1 || this.object_scale_y !== 1)) {
350
+ if (!res) {
351
+ this.context.save();
352
+ res = true;
353
+ this.context.translate(x, y);
354
+ }
355
+ if (this.object_rotation !== 0) {
356
+ this.context.rotate(-this.object_rotation / 180 * Math.PI);
357
+ }
358
+ if (this.object_scale_x !== 1 || this.object_scale_y !== 1) {
359
+ this.context.scale(this.object_scale_x, this.object_scale_y);
360
+ }
361
+ }
362
+ return res;
363
+ }
364
+ closeDrawOp() {
365
+ this.context.restore();
366
+ }
367
+ /**
368
+ * Check mouse cursor visibility
369
+ * Auto-hides cursor after 4 seconds of inactivity
370
+ */
371
+ checkMouseCursor() {
372
+ if (Date.now() > this.last_mouse_move + 4e3 && this.cursor_visibility === "auto") {
373
+ if (this.cursor !== "none") {
374
+ this.cursor = "none";
375
+ this.canvas.style.cursor = "none";
376
+ }
377
+ }
378
+ }
379
+ /**
380
+ * Set cursor visibility
381
+ */
382
+ setCursorVisible(visible) {
383
+ this.cursor_visibility = visible ? "default" : "none";
384
+ if (visible) {
385
+ this.cursor = "default";
386
+ this.canvas.style.cursor = "default";
387
+ } else {
388
+ this.cursor = "none";
389
+ this.canvas.style.cursor = "none";
390
+ }
391
+ }
392
+ getCanvas() {
393
+ return this.canvas;
394
+ }
395
+ getContext() {
396
+ return this.context;
397
+ }
398
+ resize(width, height) {
399
+ if (width && height) {
400
+ if (width <= 0 || height <= 0 || !isFinite(width) || !isFinite(height)) {
401
+ (0, import_diagnostics.reportRuntimeError)(this.runtime?.listener, import_diagnostics.APIErrorCode.E7002, {
402
+ width,
403
+ height
404
+ });
405
+ return;
406
+ }
407
+ this.canvas.width = width;
408
+ this.canvas.height = height;
409
+ this.initContext();
410
+ this.zBuffer.resize(width, height);
411
+ this.updateInterface();
412
+ }
413
+ }
414
+ };
415
+ // Annotate the CommonJS export names for ESM import in node:
416
+ 0 && (module.exports = {
417
+ BaseScreen
418
+ });
419
+ //# sourceMappingURL=base-screen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/base-screen.ts","../../src/tri/ttri.ts"],"sourcesContent":["import { APIErrorCode, createDiagnostic, formatForBrowser, reportRuntimeError } from \"@al8b/diagnostics\";\nimport { ZBuffer } from \"../tri\";\nimport type { ScreenInterface, ScreenOptions } from \"../types\";\n\n/**\n * BaseScreen encapsulates canvas/context management plus shared drawing state.\n * Feature-specific behaviors (primitives, sprites, text, triangles) extend this class.\n */\nexport class BaseScreen {\n\tprotected canvas: HTMLCanvasElement;\n\tprotected context!: CanvasRenderingContext2D;\n\tprotected runtime: any;\n\n\tpublic width!: number;\n\tpublic height!: number;\n\n\t// Drawing state\n\tprotected alpha = 1;\n\tprotected pixelated = 1;\n\tprotected line_width = 1;\n\tprotected font = \"BitCell\";\n\n\t// Transformations\n\tprotected translation_x = 0;\n\tprotected translation_y = 0;\n\tprotected rotation = 0;\n\tprotected scale_x = 1;\n\tprotected scale_y = 1;\n\tprotected screen_transform = false;\n\n\t// Object transformations\n\tprotected object_rotation = 0;\n\tprotected object_scale_x = 1;\n\tprotected object_scale_y = 1;\n\tprotected anchor_x = 0;\n\tprotected anchor_y = 0;\n\n\t// Blending + font caches\n\tprotected blending: Record<string, string> = {};\n\tprotected font_load_requested: Record<string, boolean> = {};\n\tprotected font_loaded: Record<string, boolean> = {};\n\n\t// Interface cache\n\tprotected interfaceCache: ScreenInterface | null = null;\n\n\t// Cursor management\n\tprotected cursor: string = \"default\";\n\tprotected cursor_visibility: string = \"auto\";\n\tprotected last_mouse_move: number = Date.now();\n\n\t// 3D helper\n\tprotected zBuffer: ZBuffer;\n\n\tconstructor(options: ScreenOptions = {}) {\n\t\tthis.runtime = options.runtime;\n\n\t\tif (options.canvas) {\n\t\t\tthis.canvas = options.canvas;\n\t\t\tif (this.canvas.width === 0 || this.canvas.height === 0) {\n\t\t\t\tthis.canvas.width = options.width || 1080;\n\t\t\t\tthis.canvas.height = options.height || 1920;\n\t\t\t}\n\t\t} else {\n\t\t\tthis.canvas = document.createElement(\"canvas\");\n\t\t\tthis.canvas.width = options.width || 1080;\n\t\t\tthis.canvas.height = options.height || 1920;\n\t\t}\n\n\t\tthis.initContext();\n\n\t\tthis.blending = {\n\t\t\tnormal: \"source-over\",\n\t\t\tadditive: \"lighter\",\n\t\t};\n\n\t\tconst blendModes = [\n\t\t\t\"source-over\",\n\t\t\t\"source-in\",\n\t\t\t\"source-out\",\n\t\t\t\"source-atop\",\n\t\t\t\"destination-over\",\n\t\t\t\"destination-in\",\n\t\t\t\"destination-out\",\n\t\t\t\"destination-atop\",\n\t\t\t\"lighter\",\n\t\t\t\"copy\",\n\t\t\t\"xor\",\n\t\t\t\"multiply\",\n\t\t\t\"screen\",\n\t\t\t\"overlay\",\n\t\t\t\"darken\",\n\t\t\t\"lighten\",\n\t\t\t\"color-dodge\",\n\t\t\t\"color-burn\",\n\t\t\t\"hard-light\",\n\t\t\t\"soft-light\",\n\t\t\t\"difference\",\n\t\t\t\"exclusion\",\n\t\t\t\"hue\",\n\t\t\t\"saturation\",\n\t\t\t\"color\",\n\t\t\t\"luminosity\",\n\t\t];\n\n\t\tfor (const mode of blendModes) {\n\t\t\tthis.blending[mode] = mode;\n\t\t}\n\n\t\tthis.loadFont(this.font);\n\t\tthis.zBuffer = new ZBuffer(this.canvas.width, this.canvas.height);\n\n\t\tthis.cursor = \"default\";\n\n\t\tthis.canvas.addEventListener(\"mousemove\", () => {\n\t\t\tthis.last_mouse_move = Date.now();\n\t\t\tif (this.cursor !== \"default\" && this.cursor_visibility === \"auto\") {\n\t\t\t\tthis.cursor = \"default\";\n\t\t\t\tthis.canvas.style.cursor = \"default\";\n\t\t\t}\n\t\t});\n\n\t\t// When the context is lost and then restored, base transform needs to be reinstated\n\t\tthis.canvas.addEventListener(\"contextrestored\", () => {\n\t\t\tthis.initContext();\n\t\t});\n\n\t\tsetInterval(() => this.checkMouseCursor(), 1000);\n\t\tthis.cursor_visibility = \"auto\";\n\t}\n\n\tprotected initContext(): void {\n\t\tconst ctx = this.canvas.getContext(\"2d\", {\n\t\t\talpha: false,\n\t\t});\n\t\tif (!ctx) {\n\t\t\tconst diagnostic = createDiagnostic(APIErrorCode.E7001);\n\t\t\tconst formatted = formatForBrowser(diagnostic);\n\t\t\treportRuntimeError(this.runtime?.listener, APIErrorCode.E7001, {});\n\n\t\t\tthrow new Error(formatted);\n\t\t}\n\n\t\tif (ctx !== this.context) {\n\t\t\tthis.context = ctx;\n\t\t} else {\n\t\t\tthis.context.restore();\n\t\t}\n\n\t\tthis.context.save();\n\t\tthis.context.translate(this.canvas.width / 2, this.canvas.height / 2);\n\n\t\t// Calculate ratio: Math.min(canvas.width/200, canvas.height/200)\n\t\tconst ratio = Math.min(this.canvas.width / 200, this.canvas.height / 200);\n\t\tthis.context.scale(ratio, ratio);\n\n\t\t// Set logical width/height\n\t\tthis.width = this.canvas.width / ratio;\n\t\tthis.height = this.canvas.height / ratio;\n\t\tthis.context.lineCap = \"round\";\n\t}\n\n\t/**\n\t * Initialize draw state (called before each draw frame)\n\t */\n\tinitDraw(): void {\n\t\tthis.alpha = 1;\n\t\tthis.line_width = 1;\n\t\t// Note: Supersampling not implemented in l8b\n\t\t// If needed, add: if (this.supersampling != this.previous_supersampling) { this.resize(); this.previous_supersampling = this.supersampling; }\n\t}\n\n\t/**\n\t * Update interface dimensions (called before each draw frame)\n\t */\n\tupdateInterface(): void {\n\t\t// Update interface cache if it exists\n\t\tif (this.interfaceCache) {\n\t\t\tthis.interfaceCache.width = this.width;\n\t\t\tthis.interfaceCache.height = this.height;\n\t\t}\n\t}\n\n\tclear(color?: string): void {\n\t\tthis.context.globalAlpha = 1;\n\t\tthis.context.globalCompositeOperation = \"source-over\";\n\t\tthis.context.fillStyle = color || \"#000\";\n\t\tthis.context.strokeStyle = color || \"#000\";\n\t\tthis.context.fillRect(-this.width / 2, -this.height / 2, this.width, this.height);\n\t\tthis.zBuffer.clear();\n\t}\n\n\tsetColor(color: string | number): void {\n\t\tif (!color) return;\n\n\t\tif (!Number.isNaN(Number.parseInt(String(color)))) {\n\t\t\tconst num = Number.parseInt(String(color));\n\t\t\tconst r = ((Math.floor(num / 100) % 10) / 9) * 255;\n\t\t\tconst g = ((Math.floor(num / 10) % 10) / 9) * 255;\n\t\t\tconst b = ((num % 10) / 9) * 255;\n\t\t\tconst c = 0xff000000 + (r << 16) + (g << 8) + b;\n\t\t\tconst hex = \"#\" + c.toString(16).substring(2, 8);\n\t\t\tthis.context.fillStyle = hex;\n\t\t\tthis.context.strokeStyle = hex;\n\t\t} else if (typeof color === \"string\") {\n\t\t\t// Validate color format\n\t\t\tconst isValidColor =\n\t\t\t\t/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/.test(color) ||\n\t\t\t\t/^rgb\\(|^rgba\\(|^hsl\\(|^hsla\\(/.test(color) ||\n\t\t\t\t/^(red|green|blue|yellow|cyan|magenta|black|white|gray|grey|orange|pink|purple|brown|transparent)$/i.test(color);\n\n\t\t\tif (!isValidColor) {\n\t\t\t\treportRuntimeError(this.runtime?.listener, APIErrorCode.E7003, { color });\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.context.fillStyle = color;\n\t\t\tthis.context.strokeStyle = color;\n\t\t}\n\t}\n\n\tsetAlpha(alpha: number): void {\n\t\tthis.alpha = alpha;\n\t}\n\n\tsetPixelated(pixelated: number): void {\n\t\tthis.pixelated = pixelated;\n\t}\n\n\tsetBlending(blending: string): void {\n\t\tconst blend = this.blending[blending || \"normal\"];\n\n\t\tif (!blend) {\n\t\t\treportRuntimeError(this.runtime?.listener, APIErrorCode.E7007, { blendMode: blending });\n\t\t\t// Fallback to normal blend mode\n\t\t\tthis.context.globalCompositeOperation = \"source-over\";\n\t\t\treturn;\n\t\t}\n\n\t\tthis.context.globalCompositeOperation = blend as GlobalCompositeOperation;\n\t}\n\n\tsetLineWidth(width: number): void {\n\t\tthis.line_width = width;\n\t}\n\n\tsetLineDash(dash: number[] | null): void {\n\t\tif (!Array.isArray(dash)) {\n\t\t\tthis.context.setLineDash([]);\n\t\t} else {\n\t\t\tthis.context.setLineDash(dash);\n\t\t}\n\t}\n\n\tsetLinearGradient(x1: number, y1: number, x2: number, y2: number, c1: string, c2: string): void {\n\t\tconst grd = this.context.createLinearGradient(x1, -y1, x2, -y2);\n\t\tgrd.addColorStop(0, c1);\n\t\tgrd.addColorStop(1, c2);\n\t\tthis.context.fillStyle = grd;\n\t\tthis.context.strokeStyle = grd;\n\t}\n\n\tsetRadialGradient(x: number, y: number, radius: number, c1: string, c2: string): void {\n\t\tconst grd = this.context.createRadialGradient(x, -y, 0, x, -y, radius);\n\t\tgrd.addColorStop(0, c1);\n\t\tgrd.addColorStop(1, c2);\n\t\tthis.context.fillStyle = grd;\n\t\tthis.context.strokeStyle = grd;\n\t}\n\n\tsetFont(font: string): void {\n\t\tthis.font = font || \"Verdana\";\n\t\tthis.loadFont(this.font);\n\t}\n\n\tloadFont(font: string = \"BitCell\"): void {\n\t\tif (this.font_load_requested[font]) {\n\t\t\treturn;\n\t\t}\n\t\tthis.font_load_requested[font] = true;\n\t\ttry {\n\t\t\tdocument.fonts?.load?.(`16pt ${font}`).catch(() => {\n\t\t\t\treportRuntimeError(this.runtime?.listener, APIErrorCode.E7006, { font });\n\t\t\t});\n\t\t} catch {\n\t\t\treportRuntimeError(this.runtime?.listener, APIErrorCode.E7006, { font });\n\t\t}\n\t}\n\n\tisFontReady(font: string = this.font): number {\n\t\tif (this.font_loaded[font]) {\n\t\t\treturn 1;\n\t\t}\n\n\t\ttry {\n\t\t\tconst ready = document.fonts?.check?.(`16pt ${font}`) ?? true;\n\t\t\tif (ready) {\n\t\t\t\tthis.font_loaded[font] = true;\n\t\t\t}\n\t\t\treturn ready ? 1 : 0;\n\t\t} catch {\n\t\t\treturn 1;\n\t\t}\n\t}\n\n\tsetTranslation(tx: number, ty: number): void {\n\t\tthis.translation_x = isFinite(tx) ? tx : 0;\n\t\tthis.translation_y = isFinite(ty) ? ty : 0;\n\t\tthis.updateScreenTransform();\n\t}\n\n\tsetScale(x: number, y: number): void {\n\t\tthis.scale_x = isFinite(x) && x !== 0 ? x : 1;\n\t\tthis.scale_y = isFinite(y) && y !== 0 ? y : 1;\n\t\tthis.updateScreenTransform();\n\t}\n\n\tsetRotation(rotation: number): void {\n\t\tthis.rotation = isFinite(rotation) ? rotation : 0;\n\t\tthis.updateScreenTransform();\n\t}\n\n\tprotected updateScreenTransform(): void {\n\t\tthis.screen_transform =\n\t\t\tthis.translation_x !== 0 ||\n\t\t\tthis.translation_y !== 0 ||\n\t\t\tthis.scale_x !== 1 ||\n\t\t\tthis.scale_y !== 1 ||\n\t\t\tthis.rotation !== 0;\n\t}\n\n\tsetDrawAnchor(ax: number, ay: number): void {\n\t\tthis.anchor_x = typeof ax === \"number\" ? ax : 0;\n\t\tthis.anchor_y = typeof ay === \"number\" ? ay : 0;\n\t}\n\n\tsetDrawRotation(rotation: number): void {\n\t\tthis.object_rotation = rotation;\n\t}\n\n\tsetDrawScale(x: number, y: number = x): void {\n\t\tthis.object_scale_x = x;\n\t\tthis.object_scale_y = y;\n\t}\n\n\tprotected initDrawOp(x: number, y: number, object_transform: boolean = true): boolean {\n\t\tlet res = false;\n\n\t\tif (this.screen_transform) {\n\t\t\tthis.context.save();\n\t\t\tres = true;\n\t\t\tthis.context.translate(this.translation_x, -this.translation_y);\n\t\t\tthis.context.scale(this.scale_x, this.scale_y);\n\t\t\tthis.context.rotate((-this.rotation / 180) * Math.PI);\n\t\t\tthis.context.translate(x, y);\n\t\t}\n\n\t\tif (object_transform && (this.object_rotation !== 0 || this.object_scale_x !== 1 || this.object_scale_y !== 1)) {\n\t\t\tif (!res) {\n\t\t\t\tthis.context.save();\n\t\t\t\tres = true;\n\t\t\t\tthis.context.translate(x, y);\n\t\t\t}\n\n\t\t\tif (this.object_rotation !== 0) {\n\t\t\t\tthis.context.rotate((-this.object_rotation / 180) * Math.PI);\n\t\t\t}\n\n\t\t\tif (this.object_scale_x !== 1 || this.object_scale_y !== 1) {\n\t\t\t\tthis.context.scale(this.object_scale_x, this.object_scale_y);\n\t\t\t}\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tprotected closeDrawOp(): void {\n\t\tthis.context.restore();\n\t}\n\n\t/**\n\t * Check mouse cursor visibility\n\t * Auto-hides cursor after 4 seconds of inactivity\n\t */\n\tprotected checkMouseCursor(): void {\n\t\tif (Date.now() > this.last_mouse_move + 4000 && this.cursor_visibility === \"auto\") {\n\t\t\tif (this.cursor !== \"none\") {\n\t\t\t\tthis.cursor = \"none\";\n\t\t\t\tthis.canvas.style.cursor = \"none\";\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Set cursor visibility\n\t */\n\tsetCursorVisible(visible: boolean): void {\n\t\tthis.cursor_visibility = visible ? \"default\" : \"none\";\n\t\tif (visible) {\n\t\t\tthis.cursor = \"default\";\n\t\t\tthis.canvas.style.cursor = \"default\";\n\t\t} else {\n\t\t\tthis.cursor = \"none\";\n\t\t\tthis.canvas.style.cursor = \"none\";\n\t\t}\n\t}\n\n\tgetCanvas(): HTMLCanvasElement {\n\t\treturn this.canvas;\n\t}\n\n\tgetContext(): CanvasRenderingContext2D {\n\t\treturn this.context;\n\t}\n\n\tresize(width?: number, height?: number): void {\n\t\tif (width && height) {\n\t\t\t// Validate dimensions\n\t\t\tif (width <= 0 || height <= 0 || !isFinite(width) || !isFinite(height)) {\n\t\t\t\treportRuntimeError(this.runtime?.listener, APIErrorCode.E7002, { width, height });\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.canvas.width = width;\n\t\t\tthis.canvas.height = height;\n\t\t\tthis.initContext();\n\t\t\tthis.zBuffer.resize(width, height);\n\t\t\t// Update interface cache immediately after resize\n\t\t\tthis.updateInterface();\n\t\t}\n\t}\n}\n","/**\n * TTRI - Textured Triangle Rendering (Software Rasterization)\n *\n * Based on TIC-80's ttri implementation for 3D-style graphics.\n * This is NOT a 3D engine - it's pure 2D pixel manipulation using Canvas 2D API.\n *\n * How it works:\n * 1. Use getImageData() to get pixel buffer\n * 2. Rasterize triangle pixel-by-pixel (barycentric coordinates)\n * 3. Interpolate UV texture coordinates (perspective-correct with 1/z)\n * 4. Sample texture and write to pixel buffer\n * 5. Use putImageData() to update canvas\n *\n * This is software rendering like Doom, Quake software mode, and PlayStation 1.\n * No WebGL, no GPU - just CPU pixel manipulation.\n */\n\nimport type { TileMap as Map } from \"@al8b/map\";\nimport type { Sprite } from \"@al8b/sprites\";\n\nexport interface Vec2 {\n\tx: number;\n\ty: number;\n}\n\nexport interface Vec3 {\n\tx: number;\n\ty: number;\n\tz: number;\n}\n\nexport interface TexVert {\n\tx: number;\n\ty: number;\n\tu: number;\n\tv: number;\n\tz: number;\n}\n\nexport type TextureSource = \"tiles\" | \"map\" | \"screen\";\n\nexport interface TriangleData {\n\tcontext: CanvasRenderingContext2D;\n\twidth: number;\n\theight: number;\n\truntime?: any;\n\tpixelated: boolean;\n}\n\n/**\n * Z-Buffer for depth testing\n */\nexport class ZBuffer {\n\tprivate buffer: Float32Array;\n\tprivate width: number;\n\tprivate height: number;\n\n\tconstructor(width: number, height: number) {\n\t\tthis.width = width;\n\t\tthis.height = height;\n\t\tthis.buffer = new Float32Array(width * height);\n\t}\n\n\tclear(): void {\n\t\tthis.buffer.fill(0);\n\t}\n\n\tget(x: number, y: number): number {\n\t\treturn this.buffer[y * this.width + x] || 0;\n\t}\n\n\tset(x: number, y: number, z: number): void {\n\t\tthis.buffer[y * this.width + x] = z;\n\t}\n\n\tresize(width: number, height: number): void {\n\t\tif (this.width !== width || this.height !== height) {\n\t\t\tthis.width = width;\n\t\t\tthis.height = height;\n\t\t\tthis.buffer = new Float32Array(width * height);\n\t\t}\n\t}\n}\n\n/**\n * Edge function for triangle rasterization\n */\nfunction edgeFn(a: Vec2, b: Vec2, c: Vec2): number {\n\treturn (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);\n}\n\n/**\n * Get pixel from sprite/image\n */\nfunction getSpritePixel(\n\tsprite: Sprite | any,\n\tu: number,\n\tv: number,\n\truntime?: any,\n): {\n\tr: number;\n\tg: number;\n\tb: number;\n\ta: number;\n} | null {\n\t// Resolve sprite canvas from object or runtime registry\n\tlet canvas: HTMLCanvasElement | null = null;\n\n\tif (sprite && typeof sprite === \"object\" && sprite.canvas) {\n\t\tcanvas = sprite.canvas;\n\t} else if (typeof sprite === \"string\" && runtime?.sprites) {\n\t\tconst spriteObj = runtime.sprites[sprite];\n\t\tif (spriteObj?.frames?.[0]?.canvas) {\n\t\t\tcanvas = spriteObj.frames[0].canvas;\n\t\t}\n\t}\n\n\tif (!canvas) return null;\n\n\t// Apply texture coordinate wrapping (repeat mode)\n\tconst width = canvas.width;\n\tconst height = canvas.height;\n\tconst x = Math.floor(u) % width;\n\tconst y = Math.floor(v) % height;\n\tconst px = x < 0 ? x + width : x;\n\tconst py = y < 0 ? y + height : y;\n\n\t// Sample pixel color from sprite canvas\n\tconst ctx = canvas.getContext(\"2d\");\n\tif (!ctx) return null;\n\n\ttry {\n\t\tconst imageData = ctx.getImageData(px, py, 1, 1);\n\t\treturn {\n\t\t\tr: imageData.data[0],\n\t\t\tg: imageData.data[1],\n\t\t\tb: imageData.data[2],\n\t\t\ta: imageData.data[3],\n\t\t};\n\t} catch (e) {\n\t\treturn null;\n\t}\n}\n\n/**\n * Get pixel from map\n */\nfunction getMapPixel(\n\tmap: Map | any,\n\tu: number,\n\tv: number,\n\truntime?: any,\n): {\n\tr: number;\n\tg: number;\n\tb: number;\n\ta: number;\n} | null {\n\t// Get map object\n\tlet mapObj: any = null;\n\n\tif (map && typeof map === \"object\" && map.getCanvas) {\n\t\tmapObj = map;\n\t} else if (typeof map === \"string\" && runtime?.maps) {\n\t\tmapObj = runtime.maps[map];\n\t}\n\n\tif (!mapObj) return null;\n\n\t// Get canvas from map\n\tconst canvas = mapObj.getCanvas ? mapObj.getCanvas() : mapObj.canvas;\n\tif (!canvas) return null;\n\n\t// Wrap texture coordinates\n\tconst width = canvas.width;\n\tconst height = canvas.height;\n\tconst x = Math.floor(u) % width;\n\tconst y = Math.floor(v) % height;\n\tconst px = x < 0 ? x + width : x;\n\tconst py = y < 0 ? y + height : y;\n\n\t// Get pixel data\n\tconst ctx = canvas.getContext(\"2d\");\n\tif (!ctx) return null;\n\n\ttry {\n\t\tconst imageData = ctx.getImageData(px, py, 1, 1);\n\t\treturn {\n\t\t\tr: imageData.data[0],\n\t\t\tg: imageData.data[1],\n\t\t\tb: imageData.data[2],\n\t\t\ta: imageData.data[3],\n\t\t};\n\t} catch (e) {\n\t\treturn null;\n\t}\n}\n\n/**\n * Draw textured triangle with perspective correction\n */\nexport function drawTexturedTriangle(\n\tdata: TriangleData,\n\tv0: TexVert,\n\tv1: TexVert,\n\tv2: TexVert,\n\ttexture: Sprite | Map | string | any,\n\ttextureSource: TextureSource = \"tiles\",\n\tzBuffer?: ZBuffer,\n\tuseDepth: boolean = false,\n): void {\n\tconst { context, width, height, runtime, pixelated } = data;\n\n\t// Get bounding box\n\tconst minX = Math.max(0, Math.floor(Math.min(v0.x, v1.x, v2.x)));\n\tconst minY = Math.max(0, Math.floor(Math.min(v0.y, v1.y, v2.y)));\n\tconst maxX = Math.min(width, Math.ceil(Math.max(v0.x, v1.x, v2.x)));\n\tconst maxY = Math.min(height, Math.ceil(Math.max(v0.y, v1.y, v2.y)));\n\n\tif (minX >= maxX || minY >= maxY) return;\n\n\t// Calculate triangle area\n\tconst area = edgeFn(v0, v1, v2);\n\tif (Math.abs(area) < 0.001) return;\n\n\t// Backface culling\n\tif (area < 0) return;\n\n\t// Prepare perspective-correct interpolation\n\tconst useZ = useDepth && v0.z > 0 && v1.z > 0 && v2.z > 0;\n\n\tlet w0 = 1,\n\t\tw1 = 1,\n\t\tw2 = 1;\n\tlet u0 = v0.u,\n\t\tu1 = v1.u,\n\t\tu2 = v2.u;\n\tlet v0v = v0.v,\n\t\tv1v = v1.v,\n\t\tv2v = v2.v;\n\n\tif (useZ) {\n\t\tw0 = 1 / v0.z;\n\t\tw1 = 1 / v1.z;\n\t\tw2 = 1 / v2.z;\n\t\tu0 *= w0;\n\t\tu1 *= w1;\n\t\tu2 *= w2;\n\t\tv0v *= w0;\n\t\tv1v *= w1;\n\t\tv2v *= w2;\n\t}\n\n\t// Get image data for fast pixel manipulation\n\tconst imageData = context.getImageData(minX, minY, maxX - minX, maxY - minY);\n\tconst pixels = imageData.data;\n\n\t// Rasterize\n\tfor (let y = minY; y < maxY; y++) {\n\t\tfor (let x = minX; x < maxX; x++) {\n\t\t\tconst p = {\n\t\t\t\tx: x + 0.5,\n\t\t\t\ty: y + 0.5,\n\t\t\t};\n\n\t\t\t// Calculate barycentric coordinates\n\t\t\tconst w0b = edgeFn(v1, v2, p);\n\t\t\tconst w1b = edgeFn(v2, v0, p);\n\t\t\tconst w2b = edgeFn(v0, v1, p);\n\n\t\t\t// Check if point is inside triangle\n\t\t\tif (w0b >= 0 && w1b >= 0 && w2b >= 0) {\n\t\t\t\t// Normalize barycentric coordinates\n\t\t\t\tconst bary0 = w0b / area;\n\t\t\t\tconst bary1 = w1b / area;\n\t\t\t\tconst bary2 = w2b / area;\n\n\t\t\t\t// Depth test\n\t\t\t\tif (useZ && zBuffer) {\n\t\t\t\t\tconst z = bary0 * v0.z + bary1 * v1.z + bary2 * v2.z;\n\t\t\t\t\tconst currentZ = zBuffer.get(x, y);\n\t\t\t\t\tif (currentZ > 0 && currentZ >= z) continue;\n\t\t\t\t\tzBuffer.set(x, y, z);\n\t\t\t\t}\n\n\t\t\t\t// Interpolate texture coordinates\n\t\t\t\tlet u: number, v: number;\n\n\t\t\t\tif (useZ) {\n\t\t\t\t\tconst w = bary0 * w0 + bary1 * w1 + bary2 * w2;\n\t\t\t\t\tu = (bary0 * u0 + bary1 * u1 + bary2 * u2) / w;\n\t\t\t\t\tv = (bary0 * v0v + bary1 * v1v + bary2 * v2v) / w;\n\t\t\t\t} else {\n\t\t\t\t\tu = bary0 * v0.u + bary1 * v1.u + bary2 * v2.u;\n\t\t\t\t\tv = bary0 * v0.v + bary1 * v1.v + bary2 * v2.v;\n\t\t\t\t}\n\n\t\t\t\t// Sample texture\n\t\t\t\tlet pixel: {\n\t\t\t\t\tr: number;\n\t\t\t\t\tg: number;\n\t\t\t\t\tb: number;\n\t\t\t\t\ta: number;\n\t\t\t\t} | null = null;\n\n\t\t\t\tif (textureSource === \"map\") {\n\t\t\t\t\tpixel = getMapPixel(texture, u, v, runtime);\n\t\t\t\t} else {\n\t\t\t\t\tpixel = getSpritePixel(texture, u, v, runtime);\n\t\t\t\t}\n\n\t\t\t\t// Draw pixel\n\t\t\t\tif (pixel && pixel.a > 0) {\n\t\t\t\t\tconst idx = ((y - minY) * (maxX - minX) + (x - minX)) * 4;\n\t\t\t\t\tpixels[idx] = pixel.r;\n\t\t\t\t\tpixels[idx + 1] = pixel.g;\n\t\t\t\t\tpixels[idx + 2] = pixel.b;\n\t\t\t\t\tpixels[idx + 3] = pixel.a;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Put image data back\n\tcontext.imageSmoothingEnabled = !pixelated;\n\tcontext.putImageData(imageData, minX, minY);\n}\n\n/**\n * Draw solid color triangle\n */\nexport function drawTriangle(context: CanvasRenderingContext2D, v0: Vec2, v1: Vec2, v2: Vec2, color: string): void {\n\tcontext.fillStyle = color;\n\tcontext.beginPath();\n\tcontext.moveTo(v0.x, v0.y);\n\tcontext.lineTo(v1.x, v1.y);\n\tcontext.lineTo(v2.x, v2.y);\n\tcontext.closePath();\n\tcontext.fill();\n}\n\n/**\n * Draw triangle outline\n */\nexport function drawTriangleOutline(\n\tcontext: CanvasRenderingContext2D,\n\tv0: Vec2,\n\tv1: Vec2,\n\tv2: Vec2,\n\tcolor: string,\n\tlineWidth: number = 1,\n): void {\n\tcontext.strokeStyle = color;\n\tcontext.lineWidth = lineWidth;\n\tcontext.beginPath();\n\tcontext.moveTo(v0.x, v0.y);\n\tcontext.lineTo(v1.x, v1.y);\n\tcontext.lineTo(v2.x, v2.y);\n\tcontext.closePath();\n\tcontext.stroke();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,yBAAqF;;;ACoD9E,IAAMA,UAAN,MAAMA;EApDb,OAoDaA;;;EACJC;EACAC;EACAC;EAER,YAAYD,OAAeC,QAAgB;AAC1C,SAAKD,QAAQA;AACb,SAAKC,SAASA;AACd,SAAKF,SAAS,IAAIG,aAAaF,QAAQC,MAAAA;EACxC;EAEAE,QAAc;AACb,SAAKJ,OAAOK,KAAK,CAAA;EAClB;EAEAC,IAAIC,GAAWC,GAAmB;AACjC,WAAO,KAAKR,OAAOQ,IAAI,KAAKP,QAAQM,CAAAA,KAAM;EAC3C;EAEAE,IAAIF,GAAWC,GAAWE,GAAiB;AAC1C,SAAKV,OAAOQ,IAAI,KAAKP,QAAQM,CAAAA,IAAKG;EACnC;EAEAC,OAAOV,OAAeC,QAAsB;AAC3C,QAAI,KAAKD,UAAUA,SAAS,KAAKC,WAAWA,QAAQ;AACnD,WAAKD,QAAQA;AACb,WAAKC,SAASA;AACd,WAAKF,SAAS,IAAIG,aAAaF,QAAQC,MAAAA;IACxC;EACD;AACD;;;AD1EO,IAAMU,aAAN,MAAMA;EARb,OAQaA;;;EACFC;EACAC;EACAC;EAEHC;EACAC;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cAAc;MAC5D;IACD;AAEA,WAAOwH;EACR;EAEUG,cAAoB;AAC7B,SAAK3I,QAAQsD,QAAO;EACrB;;;;;EAMUZ,mBAAyB;AAClC,QAAIhB,KAAKC,IAAG,IAAK,KAAKF,kBAAkB,OAAQ,KAAKD,sBAAsB,QAAQ;AAClF,UAAI,KAAKD,WAAW,QAAQ;AAC3B,aAAKA,SAAS;AACd,aAAKxB,OAAOyC,MAAMjB,SAAS;MAC5B;IACD;EACD;;;;EAKAqH,iBAAiBC,SAAwB;AACxC,SAAKrH,oBAAoBqH,UAAU,YAAY;AAC/C,QAAIA,SAAS;AACZ,WAAKtH,SAAS;AACd,WAAKxB,OAAOyC,MAAMjB,SAAS;IAC5B,OAAO;AACN,WAAKA,SAAS;AACd,WAAKxB,OAAOyC,MAAMjB,SAAS;IAC5B;EACD;EAEAuH,YAA+B;AAC9B,WAAO,KAAK/I;EACb;EAEA6C,aAAuC;AACtC,WAAO,KAAK5C;EACb;EAEA+I,OAAO7I,OAAgBC,QAAuB;AAC7C,QAAID,SAASC,QAAQ;AAEpB,UAAID,SAAS,KAAKC,UAAU,KAAK,CAAC0H,SAAS3H,KAAAA,KAAU,CAAC2H,SAAS1H,MAAAA,GAAS;AACvEgD,mDAAmB,KAAKlD,SAASmD,UAAUL,gCAAaiG,OAAO;UAAE9I;UAAOC;QAAO,CAAA;AAC/E;MACD;AAEA,WAAKJ,OAAOG,QAAQA;AACpB,WAAKH,OAAOI,SAASA;AACrB,WAAK6B,YAAW;AAChB,WAAKJ,QAAQmH,OAAO7I,OAAOC,MAAAA;AAE3B,WAAK4D,gBAAe;IACrB;EACD;AACD;","names":["ZBuffer","buffer","width","height","Float32Array","clear","fill","get","x","y","set","z","resize","BaseScreen","canvas","context","runtime","width","height","alpha","pixelated","line_width","font","translation_x","translation_y","rotation","scale_x","scale_y","screen_transform","object_rotation","object_scale_x","object_scale_y","anchor_x","anchor_y","blending","font_load_requested","font_loaded","interfaceCache","cursor","cursor_visibility","last_mouse_move","Date","now","zBuffer","options","document","createElement","initContext","normal","additive","blendModes","mode","loadFont","ZBuffer","addEventListener","style","setInterval","checkMouseCursor","ctx","getContext","diagnostic","createDiagnostic","APIErrorCode","E7001","formatted","formatForBrowser","reportRuntimeError","listener","Error","restore","save","translate","ratio","Math","min","scale","lineCap","initDraw","updateInterface","clear","color","globalAlpha","globalCompositeOperation","fillStyle","strokeStyle","fillRect","setColor","Number","isNaN","parseInt","String","num","r","floor","g","b","c","hex","toString","substring","isValidColor","test","E7003","setAlpha","setPixelated","setBlending","blend","E7007","blendMode","setLineWidth","setLineDash","dash","Array","isArray","setLinearGradient","x1","y1","x2","y2","c1","c2","grd","createLinearGradient","addColorStop","setRadialGradient","x","y","radius","createRadialGradient","setFont","fonts","load","catch","E7006","isFontReady","ready","check","setTranslation","tx","ty","isFinite","updateScreenTransform","setScale","setRotation","setDrawAnchor","ax","ay","setDrawRotation","setDrawScale","initDrawOp","object_transform","res","rotate","PI","closeDrawOp","setCursorVisible","visible","getCanvas","resize","E7002"]}