@al8b/screen 0.1.13 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/base-screen.js +38 -16
- package/dist/core/base-screen.js.map +1 -1
- package/dist/core/base-screen.mjs +38 -18
- package/dist/core/base-screen.mjs.map +1 -1
- package/dist/core/index.js +61 -31
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +61 -31
- package/dist/core/index.mjs.map +1 -1
- package/dist/core/screen.js +61 -31
- package/dist/core/screen.js.map +1 -1
- package/dist/core/screen.mjs +61 -31
- package/dist/core/screen.mjs.map +1 -1
- package/dist/drawing/primitives-screen.js +49 -22
- package/dist/drawing/primitives-screen.js.map +1 -1
- package/dist/drawing/primitives-screen.mjs +49 -24
- package/dist/drawing/primitives-screen.mjs.map +1 -1
- package/dist/drawing/sprite-screen.js +61 -29
- package/dist/drawing/sprite-screen.js.map +1 -1
- package/dist/drawing/sprite-screen.mjs +61 -31
- package/dist/drawing/sprite-screen.mjs.map +1 -1
- package/dist/drawing/text-screen.js +61 -31
- package/dist/drawing/text-screen.js.map +1 -1
- package/dist/drawing/text-screen.mjs +61 -31
- package/dist/drawing/text-screen.mjs.map +1 -1
- package/dist/index.js +61 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -31
- package/dist/index.mjs.map +1 -1
- package/dist/tri/triangle-screen.js +61 -31
- package/dist/tri/triangle-screen.js.map +1 -1
- package/dist/tri/triangle-screen.mjs +61 -31
- package/dist/tri/triangle-screen.mjs.map +1 -1
- package/package.json +4 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/drawing/primitives-screen.ts","../../src/core/base-screen.ts","../../src/tri/ttri.ts"],"sourcesContent":["import { APIErrorCode, reportRuntimeError } from \"@al8b/diagnostics\";\nimport { BaseScreen } from \"../core/base-screen\";\n\n/**\n * Adds primitive shape drawing APIs on top of BaseScreen.\n */\nexport class PrimitiveScreen extends BaseScreen {\n\tfillRect(x: number, y: number, w: number, h: number, color?: string | number): void {\n\t\t// Validate drawing context\n\t\tif (!this.context) {\n\t\t\treportRuntimeError(this.runtime?.listener, APIErrorCode.E7092, {});\n\t\t\treturn;\n\t\t}\n\n\t\t// Validate drawing parameters\n\t\tif (!isFinite(x) || !isFinite(y) || !isFinite(w) || !isFinite(h) || w <= 0 || h <= 0) {\n\t\t\treportRuntimeError(this.runtime?.listener, APIErrorCode.E7093, { error: `Invalid parameters: x=${x}, y=${y}, w=${w}, h=${h}` });\n\t\t\treturn;\n\t\t}\n\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tif (this.initDrawOp(x, -y)) {\n\t\t\tthis.context.fillRect(-w / 2 - (this.anchor_x * w) / 2, -h / 2 + (this.anchor_y * h) / 2, w, h);\n\t\t\tthis.closeDrawOp();\n\t\t} else {\n\t\t\tthis.context.fillRect(x - w / 2 - (this.anchor_x * w) / 2, -y - h / 2 + (this.anchor_y * h) / 2, w, h);\n\t\t}\n\t}\n\n\tfillRoundRect(x: number, y: number, w: number, h: number, round: number = 10, color?: string | number): void {\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tconst transform = this.initDrawOp(x, -y);\n\t\tconst rx = (transform ? -w / 2 : x - w / 2) - (this.anchor_x * w) / 2;\n\t\tconst ry = (transform ? -h / 2 : -y - h / 2) + (this.anchor_y * h) / 2;\n\n\t\tthis.context.beginPath();\n\t\tif (this.context.roundRect) {\n\t\t\tthis.context.roundRect(rx, ry, w, h, round);\n\t\t} else {\n\t\t\tconst r = Math.min(round, w / 2, h / 2);\n\t\t\tthis.context.moveTo(rx + r, ry);\n\t\t\tthis.context.lineTo(rx + w - r, ry);\n\t\t\tthis.context.quadraticCurveTo(rx + w, ry, rx + w, ry + r);\n\t\t\tthis.context.lineTo(rx + w, ry + h - r);\n\t\t\tthis.context.quadraticCurveTo(rx + w, ry + h, rx + w - r, ry + h);\n\t\t\tthis.context.lineTo(rx + r, ry + h);\n\t\t\tthis.context.quadraticCurveTo(rx, ry + h, rx, ry + h - r);\n\t\t\tthis.context.lineTo(rx, ry + r);\n\t\t\tthis.context.quadraticCurveTo(rx, ry, rx + r, ry);\n\t\t\tthis.context.closePath();\n\t\t}\n\t\tthis.context.fill();\n\t\tif (transform) this.closeDrawOp();\n\t}\n\n\tfillRound(x: number, y: number, w: number, h: number, color?: string | number): void {\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tw = Math.abs(w);\n\t\th = Math.abs(h);\n\t\tif (this.initDrawOp(x, -y)) {\n\t\t\tthis.context.beginPath();\n\t\t\tthis.context.ellipse((-this.anchor_x * w) / 2, (this.anchor_y * h) / 2, w / 2, h / 2, 0, 0, Math.PI * 2, false);\n\t\t\tthis.context.fill();\n\t\t\tthis.closeDrawOp();\n\t\t} else {\n\t\t\tthis.context.beginPath();\n\t\t\tthis.context.ellipse(\n\t\t\t\tx - (this.anchor_x * w) / 2,\n\t\t\t\t-y + (this.anchor_y * h) / 2,\n\t\t\t\tw / 2,\n\t\t\t\th / 2,\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t\tMath.PI * 2,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t\tthis.context.fill();\n\t\t}\n\t}\n\n\tdrawRect(x: number, y: number, w: number, h: number, color?: string | number): void {\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\t\tif (this.initDrawOp(x, -y)) {\n\t\t\tthis.context.strokeRect(-w / 2 - (this.anchor_x * w) / 2, -h / 2 + (this.anchor_y * h) / 2, w, h);\n\t\t\tthis.closeDrawOp();\n\t\t} else {\n\t\t\tthis.context.strokeRect(x - w / 2 - (this.anchor_x * w) / 2, -y - h / 2 + (this.anchor_y * h) / 2, w, h);\n\t\t}\n\t}\n\n\tdrawRoundRect(x: number, y: number, w: number, h: number, round: number = 10, color?: string | number): void {\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\t\tconst transform = this.initDrawOp(x, -y);\n\t\tconst rx = (transform ? -w / 2 : x - w / 2) - (this.anchor_x * w) / 2;\n\t\tconst ry = (transform ? -h / 2 : -y - h / 2) + (this.anchor_y * h) / 2;\n\n\t\tthis.context.beginPath();\n\t\tif (this.context.roundRect) {\n\t\t\tthis.context.roundRect(rx, ry, w, h, round);\n\t\t} else {\n\t\t\tconst r = Math.min(round, w / 2, h / 2);\n\t\t\tthis.context.moveTo(rx + r, ry);\n\t\t\tthis.context.lineTo(rx + w - r, ry);\n\t\t\tthis.context.quadraticCurveTo(rx + w, ry, rx + w, ry + r);\n\t\t\tthis.context.lineTo(rx + w, ry + h - r);\n\t\t\tthis.context.quadraticCurveTo(rx + w, ry + h, rx + w - r, ry + h);\n\t\t\tthis.context.lineTo(rx + r, ry + h);\n\t\t\tthis.context.quadraticCurveTo(rx, ry + h, rx, ry + h - r);\n\t\t\tthis.context.lineTo(rx, ry + r);\n\t\t\tthis.context.quadraticCurveTo(rx, ry, rx + r, ry);\n\t\t\tthis.context.closePath();\n\t\t}\n\t\tthis.context.stroke();\n\t\tif (transform) this.closeDrawOp();\n\t}\n\n\tdrawRound(x: number, y: number, w: number, h: number, color?: string | number): void {\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\t\tw = Math.abs(w);\n\t\th = Math.abs(h);\n\t\tif (this.initDrawOp(x, -y)) {\n\t\t\tthis.context.beginPath();\n\t\t\tthis.context.ellipse((-this.anchor_x * w) / 2, (this.anchor_y * h) / 2, w / 2, h / 2, 0, 0, Math.PI * 2, false);\n\t\t\tthis.context.stroke();\n\t\t\tthis.closeDrawOp();\n\t\t} else {\n\t\t\tthis.context.beginPath();\n\t\t\tthis.context.ellipse(\n\t\t\t\tx - (this.anchor_x * w) / 2,\n\t\t\t\t-y + (this.anchor_y * h) / 2,\n\t\t\t\tw / 2,\n\t\t\t\th / 2,\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t\tMath.PI * 2,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t\tthis.context.stroke();\n\t\t}\n\t}\n\n\tdrawLine(x1: number, y1: number, x2: number, y2: number, color?: string | number): void {\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\t\tconst transform = this.initDrawOp(0, 0, false);\n\t\tthis.context.beginPath();\n\t\tthis.context.moveTo(x1, -y1);\n\t\tthis.context.lineTo(x2, -y2);\n\t\tthis.context.stroke();\n\t\tif (transform) this.closeDrawOp();\n\t}\n\n\tdrawPolygon(args: any[]): void {\n\t\tconst { color, points } = this.extractPoints(args);\n\t\tif (!points || points.length < 4) return;\n\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\n\t\tconst len = Math.floor(points.length / 2);\n\t\tconst transform = this.initDrawOp(0, 0, false);\n\t\tthis.context.beginPath();\n\t\tthis.context.moveTo(points[0], -points[1]);\n\t\tfor (let i = 1; i < len; i++) {\n\t\t\tthis.context.lineTo(points[i * 2], -points[i * 2 + 1]);\n\t\t}\n\t\tthis.context.closePath();\n\t\tthis.context.stroke();\n\t\tif (transform) this.closeDrawOp();\n\t}\n\n\tdrawPolyline(args: any[]): void {\n\t\tconst { color, points } = this.extractPoints(args);\n\t\tif (!points || points.length < 4) return;\n\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\n\t\tconst len = Math.floor(points.length / 2);\n\t\tconst transform = this.initDrawOp(0, 0, false);\n\t\tthis.context.beginPath();\n\t\tthis.context.moveTo(points[0], -points[1]);\n\t\tfor (let i = 1; i < len; i++) {\n\t\t\tthis.context.lineTo(points[i * 2], -points[i * 2 + 1]);\n\t\t}\n\t\tthis.context.stroke();\n\t\tif (transform) this.closeDrawOp();\n\t}\n\n\tfillPolygon(args: any[]): void {\n\t\tconst { color, points } = this.extractPoints(args);\n\t\tif (!points || points.length < 4) return;\n\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\n\t\tconst len = Math.floor(points.length / 2);\n\t\tconst transform = this.initDrawOp(0, 0, false);\n\t\tthis.context.beginPath();\n\t\tthis.context.moveTo(points[0], -points[1]);\n\t\tfor (let i = 1; i < len; i++) {\n\t\t\tthis.context.lineTo(points[i * 2], -points[i * 2 + 1]);\n\t\t}\n\t\tthis.context.fill();\n\t\tif (transform) this.closeDrawOp();\n\t}\n\n\tdrawQuadCurve(args: any[]): void {\n\t\tconst { color, points } = this.extractPoints(args);\n\t\tif (!points || points.length < 4) return;\n\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\n\t\tconst transform = this.initDrawOp(0, 0, false);\n\t\tthis.context.beginPath();\n\t\tthis.context.moveTo(points[0], -points[1]);\n\t\tlet index = 2;\n\t\twhile (index <= points.length - 4) {\n\t\t\tthis.context.quadraticCurveTo(points[index], -points[index + 1], points[index + 2], -points[index + 3]);\n\t\t\tindex += 4;\n\t\t}\n\t\tthis.context.stroke();\n\t\tif (transform) this.closeDrawOp();\n\t}\n\n\tdrawBezierCurve(args: any[]): void {\n\t\tconst { color, points } = this.extractPoints(args);\n\t\tif (!points || points.length < 4) return;\n\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\n\t\tconst transform = this.initDrawOp(0, 0, false);\n\t\tthis.context.beginPath();\n\t\tthis.context.moveTo(points[0], -points[1]);\n\t\tlet index = 2;\n\t\twhile (index <= points.length - 6) {\n\t\t\tthis.context.bezierCurveTo(\n\t\t\t\tpoints[index],\n\t\t\t\t-points[index + 1],\n\t\t\t\tpoints[index + 2],\n\t\t\t\t-points[index + 3],\n\t\t\t\tpoints[index + 4],\n\t\t\t\t-points[index + 5],\n\t\t\t);\n\t\t\tindex += 6;\n\t\t}\n\t\tthis.context.stroke();\n\t\tif (transform) this.closeDrawOp();\n\t}\n\n\tdrawArc(\n\t\tx: number,\n\t\ty: number,\n\t\tradius: number,\n\t\tangle1: number,\n\t\tangle2: number,\n\t\tccw: boolean,\n\t\tcolor?: string | number,\n\t): void {\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\n\t\tif (this.initDrawOp(x, -y)) {\n\t\t\tthis.context.beginPath();\n\t\t\tthis.context.arc(0, 0, radius, (-angle1 / 180) * Math.PI, (-angle2 / 180) * Math.PI, ccw);\n\t\t\tthis.context.stroke();\n\t\t\tthis.closeDrawOp();\n\t\t} else {\n\t\t\tthis.context.beginPath();\n\t\t\tthis.context.arc(x, -y, radius, (-angle1 / 180) * Math.PI, (-angle2 / 180) * Math.PI, ccw);\n\t\t\tthis.context.stroke();\n\t\t}\n\t}\n\n\tfillArc(\n\t\tx: number,\n\t\ty: number,\n\t\tradius: number,\n\t\tangle1: number,\n\t\tangle2: number,\n\t\tccw: boolean,\n\t\tcolor?: string | number,\n\t): void {\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\n\t\tif (this.initDrawOp(x, -y)) {\n\t\t\tthis.context.beginPath();\n\t\t\tthis.context.arc(0, 0, radius, (-angle1 / 180) * Math.PI, (-angle2 / 180) * Math.PI, ccw);\n\t\t\tthis.context.fill();\n\t\t\tthis.closeDrawOp();\n\t\t} else {\n\t\t\tthis.context.beginPath();\n\t\t\tthis.context.arc(x, -y, radius, (-angle1 / 180) * Math.PI, (-angle2 / 180) * Math.PI, ccw);\n\t\t\tthis.context.fill();\n\t\t}\n\t}\n\n\tprivate extractPoints(args: any[]): {\n\t\tcolor?: string | number;\n\t\tpoints?: number[];\n\t} {\n\t\tlet color: string | number | undefined;\n\t\tlet points: number[] | undefined;\n\n\t\tif (args.length > 0 && args.length % 2 === 1 && typeof args[args.length - 1] === \"string\") {\n\t\t\tcolor = args[args.length - 1];\n\t\t\tpoints = args.slice(0, -1);\n\t\t} else if (Array.isArray(args[0])) {\n\t\t\tif (args[1] && typeof args[1] === \"string\") {\n\t\t\t\tcolor = args[1];\n\t\t\t}\n\t\t\tpoints = args[0];\n\t\t} else {\n\t\t\tpoints = args as number[];\n\t\t}\n\n\t\treturn {\n\t\t\tcolor,\n\t\t\tpoints,\n\t\t};\n\t}\n}\n","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,IAAAA,sBAAiD;;;ACAjD,yBAAqF;;;ACoD9E,IAAMC,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;;EAGGC,QAAQ;EACRC,YAAY;EACZC,aAAa;EACbC,OAAO;;EAGPC,gBAAgB;EAChBC,gBAAgB;EAChBC,WAAW;EACXC,UAAU;EACVC,UAAU;EACVC,mBAAmB;;EAGnBC,kBAAkB;EAClBC,iB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OAAM;IACpB;EACD;EAEA2B,QACCxE,GACAC,GACAkE,QACAC,QACAC,QACAC,KACAlE,OACO;AACP,QAAIA,MAAO,MAAKU,SAASV,KAAAA;AACzB,SAAKC,QAAQU,cAAc,KAAKC;AAEhC,QAAI,KAAKC,WAAWjB,GAAG,CAACC,CAAAA,GAAI;AAC3B,WAAKI,QAAQqB,UAAS;AACtB,WAAKrB,QAAQkE,IAAI,GAAG,GAAGJ,QAAS,CAACC,SAAS,MAAOvC,KAAKU,IAAK,CAAC8B,SAAS,MAAOxC,KAAKU,IAAI+B,GAAAA;AACrF,WAAKjE,QAAQ8B,KAAI;AACjB,WAAKf,YAAW;IACjB,OAAO;AACN,WAAKf,QAAQqB,UAAS;AACtB,WAAKrB,QAAQkE,IAAIvE,GAAG,CAACC,GAAGkE,QAAS,CAACC,SAAS,MAAOvC,KAAKU,IAAK,CAAC8B,SAAS,MAAOxC,KAAKU,IAAI+B,GAAAA;AACtF,WAAKjE,QAAQ8B,KAAI;IAClB;EACD;EAEQoB,cAAcF,MAGpB;AACD,QAAIjD;AACJ,QAAIkD;AAEJ,QAAID,KAAKG,SAAS,KAAKH,KAAKG,SAAS,MAAM,KAAK,OAAOH,KAAKA,KAAKG,SAAS,CAAA,MAAO,UAAU;AAC1FpD,cAAQiD,KAAKA,KAAKG,SAAS,CAAA;AAC3BF,eAASD,KAAKoB,MAAM,GAAG,EAAC;IACzB,WAAWC,MAAMC,QAAQtB,KAAK,CAAA,CAAE,GAAG;AAClC,UAAIA,KAAK,CAAA,KAAM,OAAOA,KAAK,CAAA,MAAO,UAAU;AAC3CjD,gBAAQiD,KAAK,CAAA;MACd;AACAC,eAASD,KAAK,CAAA;IACf,OAAO;AACNC,eAASD;IACV;AAEA,WAAO;MACNjD;MACAkD;IACD;EACD;AACD;","names":["import_diagnostics","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","PrimitiveScreen","BaseScreen","fillRect","x","y","w","h","color","context","reportRuntimeError","runtime","listener","APIErrorCode","E7092","isFinite","E7093","error","setColor","globalAlpha","alpha","initDrawOp","anchor_x","anchor_y","closeDrawOp","fillRoundRect","round","transform","rx","ry","beginPath","roundRect","r","Math","min","moveTo","lineTo","quadraticCurveTo","closePath","fill","fillRound","abs","ellipse","PI","drawRect","lineWidth","line_width","strokeRect","drawRoundRect","stroke","drawRound","drawLine","x1","y1","x2","y2","drawPolygon","args","points","extractPoints","length","len","floor","i","drawPolyline","fillPolygon","drawQuadCurve","index","drawBezierCurve","bezierCurveTo","drawArc","radius","angle1","angle2","ccw","arc","fillArc","slice","Array","isArray"]}
|
|
1
|
+
{"version":3,"sources":["../../src/drawing/primitives-screen.ts","../../src/tri/ttri.ts","../../src/core/base-screen.ts"],"sourcesContent":["import { BaseScreen } from \"../core/base-screen\";\n\n/**\n * Adds primitive shape drawing APIs on top of BaseScreen.\n */\nexport class PrimitiveScreen extends BaseScreen {\n\tfillRect(x: number, y: number, w: number, h: number, color?: string | number): void {\n\t\t// Validate drawing context\n\t\tif (!this.context) {\n\t\t\tthis.runtime?.listener?.reportError?.({ code: \"E7092\", message: \"Drawing context not available\", data: {} });\n\t\t\treturn;\n\t\t}\n\n\t\t// Validate drawing parameters\n\t\tif (!isFinite(x) || !isFinite(y) || !isFinite(w) || !isFinite(h) || w <= 0 || h <= 0) {\n\t\t\tthis.runtime?.listener?.reportError?.({ code: \"E7093\", message: \"Invalid draw parameters\", data: { error: `Invalid parameters: x=${x}, y=${y}, w=${w}, h=${h}` } });\n\t\t\treturn;\n\t\t}\n\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tif (this.initDrawOp(x, -y)) {\n\t\t\tthis.context.fillRect(-w / 2 - (this.anchor_x * w) / 2, -h / 2 + (this.anchor_y * h) / 2, w, h);\n\t\t\tthis.closeDrawOp();\n\t\t} else {\n\t\t\tthis.context.fillRect(x - w / 2 - (this.anchor_x * w) / 2, -y - h / 2 + (this.anchor_y * h) / 2, w, h);\n\t\t}\n\t}\n\n\tfillRoundRect(x: number, y: number, w: number, h: number, round: number = 10, color?: string | number): void {\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tconst transform = this.initDrawOp(x, -y);\n\t\tconst rx = (transform ? -w / 2 : x - w / 2) - (this.anchor_x * w) / 2;\n\t\tconst ry = (transform ? -h / 2 : -y - h / 2) + (this.anchor_y * h) / 2;\n\n\t\tthis.context.beginPath();\n\t\tif (this.context.roundRect) {\n\t\t\tthis.context.roundRect(rx, ry, w, h, round);\n\t\t} else {\n\t\t\tconst r = Math.min(round, w / 2, h / 2);\n\t\t\tthis.context.moveTo(rx + r, ry);\n\t\t\tthis.context.lineTo(rx + w - r, ry);\n\t\t\tthis.context.quadraticCurveTo(rx + w, ry, rx + w, ry + r);\n\t\t\tthis.context.lineTo(rx + w, ry + h - r);\n\t\t\tthis.context.quadraticCurveTo(rx + w, ry + h, rx + w - r, ry + h);\n\t\t\tthis.context.lineTo(rx + r, ry + h);\n\t\t\tthis.context.quadraticCurveTo(rx, ry + h, rx, ry + h - r);\n\t\t\tthis.context.lineTo(rx, ry + r);\n\t\t\tthis.context.quadraticCurveTo(rx, ry, rx + r, ry);\n\t\t\tthis.context.closePath();\n\t\t}\n\t\tthis.context.fill();\n\t\tif (transform) this.closeDrawOp();\n\t}\n\n\tfillRound(x: number, y: number, w: number, h: number, color?: string | number): void {\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tw = Math.abs(w);\n\t\th = Math.abs(h);\n\t\tif (this.initDrawOp(x, -y)) {\n\t\t\tthis.context.beginPath();\n\t\t\tthis.context.ellipse((-this.anchor_x * w) / 2, (this.anchor_y * h) / 2, w / 2, h / 2, 0, 0, Math.PI * 2, false);\n\t\t\tthis.context.fill();\n\t\t\tthis.closeDrawOp();\n\t\t} else {\n\t\t\tthis.context.beginPath();\n\t\t\tthis.context.ellipse(\n\t\t\t\tx - (this.anchor_x * w) / 2,\n\t\t\t\t-y + (this.anchor_y * h) / 2,\n\t\t\t\tw / 2,\n\t\t\t\th / 2,\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t\tMath.PI * 2,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t\tthis.context.fill();\n\t\t}\n\t}\n\n\tdrawRect(x: number, y: number, w: number, h: number, color?: string | number): void {\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\t\tif (this.initDrawOp(x, -y)) {\n\t\t\tthis.context.strokeRect(-w / 2 - (this.anchor_x * w) / 2, -h / 2 + (this.anchor_y * h) / 2, w, h);\n\t\t\tthis.closeDrawOp();\n\t\t} else {\n\t\t\tthis.context.strokeRect(x - w / 2 - (this.anchor_x * w) / 2, -y - h / 2 + (this.anchor_y * h) / 2, w, h);\n\t\t}\n\t}\n\n\tdrawRoundRect(x: number, y: number, w: number, h: number, round: number = 10, color?: string | number): void {\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\t\tconst transform = this.initDrawOp(x, -y);\n\t\tconst rx = (transform ? -w / 2 : x - w / 2) - (this.anchor_x * w) / 2;\n\t\tconst ry = (transform ? -h / 2 : -y - h / 2) + (this.anchor_y * h) / 2;\n\n\t\tthis.context.beginPath();\n\t\tif (this.context.roundRect) {\n\t\t\tthis.context.roundRect(rx, ry, w, h, round);\n\t\t} else {\n\t\t\tconst r = Math.min(round, w / 2, h / 2);\n\t\t\tthis.context.moveTo(rx + r, ry);\n\t\t\tthis.context.lineTo(rx + w - r, ry);\n\t\t\tthis.context.quadraticCurveTo(rx + w, ry, rx + w, ry + r);\n\t\t\tthis.context.lineTo(rx + w, ry + h - r);\n\t\t\tthis.context.quadraticCurveTo(rx + w, ry + h, rx + w - r, ry + h);\n\t\t\tthis.context.lineTo(rx + r, ry + h);\n\t\t\tthis.context.quadraticCurveTo(rx, ry + h, rx, ry + h - r);\n\t\t\tthis.context.lineTo(rx, ry + r);\n\t\t\tthis.context.quadraticCurveTo(rx, ry, rx + r, ry);\n\t\t\tthis.context.closePath();\n\t\t}\n\t\tthis.context.stroke();\n\t\tif (transform) this.closeDrawOp();\n\t}\n\n\tdrawRound(x: number, y: number, w: number, h: number, color?: string | number): void {\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\t\tw = Math.abs(w);\n\t\th = Math.abs(h);\n\t\tif (this.initDrawOp(x, -y)) {\n\t\t\tthis.context.beginPath();\n\t\t\tthis.context.ellipse((-this.anchor_x * w) / 2, (this.anchor_y * h) / 2, w / 2, h / 2, 0, 0, Math.PI * 2, false);\n\t\t\tthis.context.stroke();\n\t\t\tthis.closeDrawOp();\n\t\t} else {\n\t\t\tthis.context.beginPath();\n\t\t\tthis.context.ellipse(\n\t\t\t\tx - (this.anchor_x * w) / 2,\n\t\t\t\t-y + (this.anchor_y * h) / 2,\n\t\t\t\tw / 2,\n\t\t\t\th / 2,\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t\tMath.PI * 2,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t\tthis.context.stroke();\n\t\t}\n\t}\n\n\tdrawLine(x1: number, y1: number, x2: number, y2: number, color?: string | number): void {\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\t\tconst transform = this.initDrawOp(0, 0, false);\n\t\tthis.context.beginPath();\n\t\tthis.context.moveTo(x1, -y1);\n\t\tthis.context.lineTo(x2, -y2);\n\t\tthis.context.stroke();\n\t\tif (transform) this.closeDrawOp();\n\t}\n\n\tdrawPolygon(args: any[]): void {\n\t\tconst { color, points } = this.extractPoints(args);\n\t\tif (!points || points.length < 4) return;\n\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\n\t\tconst len = Math.floor(points.length / 2);\n\t\tconst transform = this.initDrawOp(0, 0, false);\n\t\tthis.context.beginPath();\n\t\tthis.context.moveTo(points[0], -points[1]);\n\t\tfor (let i = 1; i < len; i++) {\n\t\t\tthis.context.lineTo(points[i * 2], -points[i * 2 + 1]);\n\t\t}\n\t\tthis.context.closePath();\n\t\tthis.context.stroke();\n\t\tif (transform) this.closeDrawOp();\n\t}\n\n\tdrawPolyline(args: any[]): void {\n\t\tconst { color, points } = this.extractPoints(args);\n\t\tif (!points || points.length < 4) return;\n\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\n\t\tconst len = Math.floor(points.length / 2);\n\t\tconst transform = this.initDrawOp(0, 0, false);\n\t\tthis.context.beginPath();\n\t\tthis.context.moveTo(points[0], -points[1]);\n\t\tfor (let i = 1; i < len; i++) {\n\t\t\tthis.context.lineTo(points[i * 2], -points[i * 2 + 1]);\n\t\t}\n\t\tthis.context.stroke();\n\t\tif (transform) this.closeDrawOp();\n\t}\n\n\tfillPolygon(args: any[]): void {\n\t\tconst { color, points } = this.extractPoints(args);\n\t\tif (!points || points.length < 4) return;\n\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\n\t\tconst len = Math.floor(points.length / 2);\n\t\tconst transform = this.initDrawOp(0, 0, false);\n\t\tthis.context.beginPath();\n\t\tthis.context.moveTo(points[0], -points[1]);\n\t\tfor (let i = 1; i < len; i++) {\n\t\t\tthis.context.lineTo(points[i * 2], -points[i * 2 + 1]);\n\t\t}\n\t\tthis.context.fill();\n\t\tif (transform) this.closeDrawOp();\n\t}\n\n\tdrawQuadCurve(args: any[]): void {\n\t\tconst { color, points } = this.extractPoints(args);\n\t\tif (!points || points.length < 4) return;\n\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\n\t\tconst transform = this.initDrawOp(0, 0, false);\n\t\tthis.context.beginPath();\n\t\tthis.context.moveTo(points[0], -points[1]);\n\t\tlet index = 2;\n\t\twhile (index <= points.length - 4) {\n\t\t\tthis.context.quadraticCurveTo(points[index], -points[index + 1], points[index + 2], -points[index + 3]);\n\t\t\tindex += 4;\n\t\t}\n\t\tthis.context.stroke();\n\t\tif (transform) this.closeDrawOp();\n\t}\n\n\tdrawBezierCurve(args: any[]): void {\n\t\tconst { color, points } = this.extractPoints(args);\n\t\tif (!points || points.length < 4) return;\n\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\n\t\tconst transform = this.initDrawOp(0, 0, false);\n\t\tthis.context.beginPath();\n\t\tthis.context.moveTo(points[0], -points[1]);\n\t\tlet index = 2;\n\t\twhile (index <= points.length - 6) {\n\t\t\tthis.context.bezierCurveTo(\n\t\t\t\tpoints[index],\n\t\t\t\t-points[index + 1],\n\t\t\t\tpoints[index + 2],\n\t\t\t\t-points[index + 3],\n\t\t\t\tpoints[index + 4],\n\t\t\t\t-points[index + 5],\n\t\t\t);\n\t\t\tindex += 6;\n\t\t}\n\t\tthis.context.stroke();\n\t\tif (transform) this.closeDrawOp();\n\t}\n\n\tdrawArc(\n\t\tx: number,\n\t\ty: number,\n\t\tradius: number,\n\t\tangle1: number,\n\t\tangle2: number,\n\t\tccw: boolean,\n\t\tcolor?: string | number,\n\t): void {\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\t\tthis.context.lineWidth = this.line_width;\n\n\t\tif (this.initDrawOp(x, -y)) {\n\t\t\tthis.context.beginPath();\n\t\t\tthis.context.arc(0, 0, radius, (-angle1 / 180) * Math.PI, (-angle2 / 180) * Math.PI, ccw);\n\t\t\tthis.context.stroke();\n\t\t\tthis.closeDrawOp();\n\t\t} else {\n\t\t\tthis.context.beginPath();\n\t\t\tthis.context.arc(x, -y, radius, (-angle1 / 180) * Math.PI, (-angle2 / 180) * Math.PI, ccw);\n\t\t\tthis.context.stroke();\n\t\t}\n\t}\n\n\tfillArc(\n\t\tx: number,\n\t\ty: number,\n\t\tradius: number,\n\t\tangle1: number,\n\t\tangle2: number,\n\t\tccw: boolean,\n\t\tcolor?: string | number,\n\t): void {\n\t\tif (color) this.setColor(color);\n\t\tthis.context.globalAlpha = this.alpha;\n\n\t\tif (this.initDrawOp(x, -y)) {\n\t\t\tthis.context.beginPath();\n\t\t\tthis.context.arc(0, 0, radius, (-angle1 / 180) * Math.PI, (-angle2 / 180) * Math.PI, ccw);\n\t\t\tthis.context.fill();\n\t\t\tthis.closeDrawOp();\n\t\t} else {\n\t\t\tthis.context.beginPath();\n\t\t\tthis.context.arc(x, -y, radius, (-angle1 / 180) * Math.PI, (-angle2 / 180) * Math.PI, ccw);\n\t\t\tthis.context.fill();\n\t\t}\n\t}\n\n\tprivate extractPoints(args: any[]): {\n\t\tcolor?: string | number;\n\t\tpoints?: number[];\n\t} {\n\t\tlet color: string | number | undefined;\n\t\tlet points: number[] | undefined;\n\n\t\tif (args.length > 0 && args.length % 2 === 1 && typeof args[args.length - 1] === \"string\") {\n\t\t\tcolor = args[args.length - 1];\n\t\t\tpoints = args.slice(0, -1);\n\t\t} else if (Array.isArray(args[0])) {\n\t\t\tif (args[1] && typeof args[1] === \"string\") {\n\t\t\t\tcolor = args[1];\n\t\t\t}\n\t\t\tpoints = args[0];\n\t\t} else {\n\t\t\tpoints = args as number[];\n\t\t}\n\n\t\treturn {\n\t\t\tcolor,\n\t\t\tpoints,\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","import { 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 message = \"Failed to get 2D rendering context\";\n\t\t\tthis.runtime?.listener?.reportError?.({ code: \"E7001\", message, data: {} });\n\n\t\t\tthrow new Error(message);\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\tthis.runtime?.listener?.reportError?.({ code: \"E7003\", message: \"Invalid color\", data: { 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\tthis.runtime?.listener?.reportError?.({ code: \"E7007\", message: \"Invalid blend mode\", data: { 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\tthis.runtime?.listener?.reportError?.({ code: \"E7006\", message: \"Font loading failed\", data: { font } });\n\t\t\t});\n\t\t} catch {\n\t\t\tthis.runtime?.listener?.reportError?.({ code: \"E7006\", message: \"Font loading failed\", data: { 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\tthis.runtime?.listener?.reportError?.({ code: \"E7002\", message: \"Invalid resize dimensions\", data: { 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACoDO,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;;;AC3EO,IAAMU,aAAN,MAAMA;EAPb,OAOaA;;;EACFC;EACAC;EACAC;EAEHC;EACAC;;EAGGC,QAAQ;EACRC,YAAY;EACZC,aAAa;EACbC,OAAO;;EAGPC,gBA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D,KAAK,CAAA;MACd;AACAC,eAASD,KAAK,CAAA;IACf,OAAO;AACNC,eAASD;IACV;AAEA,WAAO;MACNjD;MACAkD;IACD;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","message","listener","reportError","code","data","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","setAlpha","setPixelated","setBlending","blend","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","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","PrimitiveScreen","BaseScreen","fillRect","x","y","w","h","color","context","runtime","listener","reportError","code","message","data","isFinite","error","setColor","globalAlpha","alpha","initDrawOp","anchor_x","anchor_y","closeDrawOp","fillRoundRect","round","transform","rx","ry","beginPath","roundRect","r","Math","min","moveTo","lineTo","quadraticCurveTo","closePath","fill","fillRound","abs","ellipse","PI","drawRect","lineWidth","line_width","strokeRect","drawRoundRect","stroke","drawRound","drawLine","x1","y1","x2","y2","drawPolygon","args","points","extractPoints","length","len","floor","i","drawPolyline","fillPolygon","drawQuadCurve","index","drawBezierCurve","bezierCurveTo","drawArc","radius","angle1","angle2","ccw","arc","fillArc","slice","Array","isArray"]}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
|
-
// src/drawing/primitives-screen.ts
|
|
5
|
-
import { APIErrorCode as APIErrorCode2, reportRuntimeError as reportRuntimeError2 } from "@al8b/diagnostics";
|
|
6
|
-
|
|
7
|
-
// src/core/base-screen.ts
|
|
8
|
-
import { APIErrorCode, createDiagnostic, formatForBrowser, reportRuntimeError } from "@al8b/diagnostics";
|
|
9
|
-
|
|
10
4
|
// src/tri/ttri.ts
|
|
11
5
|
var ZBuffer = class {
|
|
12
6
|
static {
|
|
@@ -148,10 +142,13 @@ var BaseScreen = class {
|
|
|
148
142
|
alpha: false
|
|
149
143
|
});
|
|
150
144
|
if (!ctx) {
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
145
|
+
const message = "Failed to get 2D rendering context";
|
|
146
|
+
this.runtime?.listener?.reportError?.({
|
|
147
|
+
code: "E7001",
|
|
148
|
+
message,
|
|
149
|
+
data: {}
|
|
150
|
+
});
|
|
151
|
+
throw new Error(message);
|
|
155
152
|
}
|
|
156
153
|
if (ctx !== this.context) {
|
|
157
154
|
this.context = ctx;
|
|
@@ -204,8 +201,12 @@ var BaseScreen = class {
|
|
|
204
201
|
} else if (typeof color === "string") {
|
|
205
202
|
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);
|
|
206
203
|
if (!isValidColor) {
|
|
207
|
-
|
|
208
|
-
|
|
204
|
+
this.runtime?.listener?.reportError?.({
|
|
205
|
+
code: "E7003",
|
|
206
|
+
message: "Invalid color",
|
|
207
|
+
data: {
|
|
208
|
+
color
|
|
209
|
+
}
|
|
209
210
|
});
|
|
210
211
|
return;
|
|
211
212
|
}
|
|
@@ -222,8 +223,12 @@ var BaseScreen = class {
|
|
|
222
223
|
setBlending(blending) {
|
|
223
224
|
const blend = this.blending[blending || "normal"];
|
|
224
225
|
if (!blend) {
|
|
225
|
-
|
|
226
|
-
|
|
226
|
+
this.runtime?.listener?.reportError?.({
|
|
227
|
+
code: "E7007",
|
|
228
|
+
message: "Invalid blend mode",
|
|
229
|
+
data: {
|
|
230
|
+
blendMode: blending
|
|
231
|
+
}
|
|
227
232
|
});
|
|
228
233
|
this.context.globalCompositeOperation = "source-over";
|
|
229
234
|
return;
|
|
@@ -265,13 +270,21 @@ var BaseScreen = class {
|
|
|
265
270
|
this.font_load_requested[font] = true;
|
|
266
271
|
try {
|
|
267
272
|
document.fonts?.load?.(`16pt ${font}`).catch(() => {
|
|
268
|
-
|
|
269
|
-
|
|
273
|
+
this.runtime?.listener?.reportError?.({
|
|
274
|
+
code: "E7006",
|
|
275
|
+
message: "Font loading failed",
|
|
276
|
+
data: {
|
|
277
|
+
font
|
|
278
|
+
}
|
|
270
279
|
});
|
|
271
280
|
});
|
|
272
281
|
} catch {
|
|
273
|
-
|
|
274
|
-
|
|
282
|
+
this.runtime?.listener?.reportError?.({
|
|
283
|
+
code: "E7006",
|
|
284
|
+
message: "Font loading failed",
|
|
285
|
+
data: {
|
|
286
|
+
font
|
|
287
|
+
}
|
|
275
288
|
});
|
|
276
289
|
}
|
|
277
290
|
}
|
|
@@ -379,9 +392,13 @@ var BaseScreen = class {
|
|
|
379
392
|
resize(width, height) {
|
|
380
393
|
if (width && height) {
|
|
381
394
|
if (width <= 0 || height <= 0 || !isFinite(width) || !isFinite(height)) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
395
|
+
this.runtime?.listener?.reportError?.({
|
|
396
|
+
code: "E7002",
|
|
397
|
+
message: "Invalid resize dimensions",
|
|
398
|
+
data: {
|
|
399
|
+
width,
|
|
400
|
+
height
|
|
401
|
+
}
|
|
385
402
|
});
|
|
386
403
|
return;
|
|
387
404
|
}
|
|
@@ -401,12 +418,20 @@ var PrimitiveScreen = class extends BaseScreen {
|
|
|
401
418
|
}
|
|
402
419
|
fillRect(x, y, w, h, color) {
|
|
403
420
|
if (!this.context) {
|
|
404
|
-
|
|
421
|
+
this.runtime?.listener?.reportError?.({
|
|
422
|
+
code: "E7092",
|
|
423
|
+
message: "Drawing context not available",
|
|
424
|
+
data: {}
|
|
425
|
+
});
|
|
405
426
|
return;
|
|
406
427
|
}
|
|
407
428
|
if (!isFinite(x) || !isFinite(y) || !isFinite(w) || !isFinite(h) || w <= 0 || h <= 0) {
|
|
408
|
-
|
|
409
|
-
|
|
429
|
+
this.runtime?.listener?.reportError?.({
|
|
430
|
+
code: "E7093",
|
|
431
|
+
message: "Invalid draw parameters",
|
|
432
|
+
data: {
|
|
433
|
+
error: `Invalid parameters: x=${x}, y=${y}, w=${w}, h=${h}`
|
|
434
|
+
}
|
|
410
435
|
});
|
|
411
436
|
return;
|
|
412
437
|
}
|