@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.
- package/README.md +23 -0
- package/dist/core/base-screen.d.mts +84 -0
- package/dist/core/base-screen.d.ts +84 -0
- package/dist/core/base-screen.js +419 -0
- package/dist/core/base-screen.js.map +1 -0
- package/dist/core/base-screen.mjs +396 -0
- package/dist/core/base-screen.mjs.map +1 -0
- package/dist/core/index.d.mts +10 -0
- package/dist/core/index.d.ts +10 -0
- package/dist/core/index.js +1208 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/index.mjs +1183 -0
- package/dist/core/index.mjs.map +1 -0
- package/dist/core/screen.d.mts +15 -0
- package/dist/core/screen.d.ts +15 -0
- package/dist/core/screen.js +1209 -0
- package/dist/core/screen.js.map +1 -0
- package/dist/core/screen.mjs +1184 -0
- package/dist/core/screen.mjs.map +1 -0
- package/dist/drawing/primitives-screen.d.mts +28 -0
- package/dist/drawing/primitives-screen.d.ts +28 -0
- package/dist/drawing/primitives-screen.js +685 -0
- package/dist/drawing/primitives-screen.js.map +1 -0
- package/dist/drawing/primitives-screen.mjs +662 -0
- package/dist/drawing/primitives-screen.mjs.map +1 -0
- package/dist/drawing/sprite-screen.d.mts +41 -0
- package/dist/drawing/sprite-screen.d.ts +41 -0
- package/dist/drawing/sprite-screen.js +853 -0
- package/dist/drawing/sprite-screen.js.map +1 -0
- package/dist/drawing/sprite-screen.mjs +830 -0
- package/dist/drawing/sprite-screen.mjs.map +1 -0
- package/dist/drawing/text-screen.d.mts +19 -0
- package/dist/drawing/text-screen.d.ts +19 -0
- package/dist/drawing/text-screen.js +909 -0
- package/dist/drawing/text-screen.js.map +1 -0
- package/dist/drawing/text-screen.mjs +884 -0
- package/dist/drawing/text-screen.mjs.map +1 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1210 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1184 -0
- package/dist/index.mjs.map +1 -0
- package/dist/tri/index.d.mts +3 -0
- package/dist/tri/index.d.ts +3 -0
- package/dist/tri/index.js +231 -0
- package/dist/tri/index.js.map +1 -0
- package/dist/tri/index.mjs +203 -0
- package/dist/tri/index.mjs.map +1 -0
- package/dist/tri/triangle-screen.d.mts +16 -0
- package/dist/tri/triangle-screen.d.ts +16 -0
- package/dist/tri/triangle-screen.js +1147 -0
- package/dist/tri/triangle-screen.js.map +1 -0
- package/dist/tri/triangle-screen.mjs +1122 -0
- package/dist/tri/triangle-screen.mjs.map +1 -0
- package/dist/tri/ttri.d.mts +71 -0
- package/dist/tri/ttri.d.ts +71 -0
- package/dist/tri/ttri.js +229 -0
- package/dist/tri/ttri.js.map +1 -0
- package/dist/tri/ttri.mjs +203 -0
- package/dist/tri/ttri.mjs.map +1 -0
- package/dist/types/index.d.mts +64 -0
- package/dist/types/index.d.ts +64 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/index.mjs.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/tri/ttri.ts
|
|
5
|
+
var ZBuffer = class {
|
|
6
|
+
static {
|
|
7
|
+
__name(this, "ZBuffer");
|
|
8
|
+
}
|
|
9
|
+
buffer;
|
|
10
|
+
width;
|
|
11
|
+
height;
|
|
12
|
+
constructor(width, height) {
|
|
13
|
+
this.width = width;
|
|
14
|
+
this.height = height;
|
|
15
|
+
this.buffer = new Float32Array(width * height);
|
|
16
|
+
}
|
|
17
|
+
clear() {
|
|
18
|
+
this.buffer.fill(0);
|
|
19
|
+
}
|
|
20
|
+
get(x, y) {
|
|
21
|
+
return this.buffer[y * this.width + x] || 0;
|
|
22
|
+
}
|
|
23
|
+
set(x, y, z) {
|
|
24
|
+
this.buffer[y * this.width + x] = z;
|
|
25
|
+
}
|
|
26
|
+
resize(width, height) {
|
|
27
|
+
if (this.width !== width || this.height !== height) {
|
|
28
|
+
this.width = width;
|
|
29
|
+
this.height = height;
|
|
30
|
+
this.buffer = new Float32Array(width * height);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
function edgeFn(a, b, c) {
|
|
35
|
+
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
|
|
36
|
+
}
|
|
37
|
+
__name(edgeFn, "edgeFn");
|
|
38
|
+
function getSpritePixel(sprite, u, v, runtime) {
|
|
39
|
+
let canvas = null;
|
|
40
|
+
if (sprite && typeof sprite === "object" && sprite.canvas) {
|
|
41
|
+
canvas = sprite.canvas;
|
|
42
|
+
} else if (typeof sprite === "string" && runtime?.sprites) {
|
|
43
|
+
const spriteObj = runtime.sprites[sprite];
|
|
44
|
+
if (spriteObj?.frames?.[0]?.canvas) {
|
|
45
|
+
canvas = spriteObj.frames[0].canvas;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!canvas) return null;
|
|
49
|
+
const width = canvas.width;
|
|
50
|
+
const height = canvas.height;
|
|
51
|
+
const x = Math.floor(u) % width;
|
|
52
|
+
const y = Math.floor(v) % height;
|
|
53
|
+
const px = x < 0 ? x + width : x;
|
|
54
|
+
const py = y < 0 ? y + height : y;
|
|
55
|
+
const ctx = canvas.getContext("2d");
|
|
56
|
+
if (!ctx) return null;
|
|
57
|
+
try {
|
|
58
|
+
const imageData = ctx.getImageData(px, py, 1, 1);
|
|
59
|
+
return {
|
|
60
|
+
r: imageData.data[0],
|
|
61
|
+
g: imageData.data[1],
|
|
62
|
+
b: imageData.data[2],
|
|
63
|
+
a: imageData.data[3]
|
|
64
|
+
};
|
|
65
|
+
} catch (e) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
__name(getSpritePixel, "getSpritePixel");
|
|
70
|
+
function getMapPixel(map, u, v, runtime) {
|
|
71
|
+
let mapObj = null;
|
|
72
|
+
if (map && typeof map === "object" && map.getCanvas) {
|
|
73
|
+
mapObj = map;
|
|
74
|
+
} else if (typeof map === "string" && runtime?.maps) {
|
|
75
|
+
mapObj = runtime.maps[map];
|
|
76
|
+
}
|
|
77
|
+
if (!mapObj) return null;
|
|
78
|
+
const canvas = mapObj.getCanvas ? mapObj.getCanvas() : mapObj.canvas;
|
|
79
|
+
if (!canvas) return null;
|
|
80
|
+
const width = canvas.width;
|
|
81
|
+
const height = canvas.height;
|
|
82
|
+
const x = Math.floor(u) % width;
|
|
83
|
+
const y = Math.floor(v) % height;
|
|
84
|
+
const px = x < 0 ? x + width : x;
|
|
85
|
+
const py = y < 0 ? y + height : y;
|
|
86
|
+
const ctx = canvas.getContext("2d");
|
|
87
|
+
if (!ctx) return null;
|
|
88
|
+
try {
|
|
89
|
+
const imageData = ctx.getImageData(px, py, 1, 1);
|
|
90
|
+
return {
|
|
91
|
+
r: imageData.data[0],
|
|
92
|
+
g: imageData.data[1],
|
|
93
|
+
b: imageData.data[2],
|
|
94
|
+
a: imageData.data[3]
|
|
95
|
+
};
|
|
96
|
+
} catch (e) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
__name(getMapPixel, "getMapPixel");
|
|
101
|
+
function drawTexturedTriangle(data, v0, v1, v2, texture, textureSource = "tiles", zBuffer, useDepth = false) {
|
|
102
|
+
const { context, width, height, runtime, pixelated } = data;
|
|
103
|
+
const minX = Math.max(0, Math.floor(Math.min(v0.x, v1.x, v2.x)));
|
|
104
|
+
const minY = Math.max(0, Math.floor(Math.min(v0.y, v1.y, v2.y)));
|
|
105
|
+
const maxX = Math.min(width, Math.ceil(Math.max(v0.x, v1.x, v2.x)));
|
|
106
|
+
const maxY = Math.min(height, Math.ceil(Math.max(v0.y, v1.y, v2.y)));
|
|
107
|
+
if (minX >= maxX || minY >= maxY) return;
|
|
108
|
+
const area = edgeFn(v0, v1, v2);
|
|
109
|
+
if (Math.abs(area) < 1e-3) return;
|
|
110
|
+
if (area < 0) return;
|
|
111
|
+
const useZ = useDepth && v0.z > 0 && v1.z > 0 && v2.z > 0;
|
|
112
|
+
let w0 = 1, w1 = 1, w2 = 1;
|
|
113
|
+
let u0 = v0.u, u1 = v1.u, u2 = v2.u;
|
|
114
|
+
let v0v = v0.v, v1v = v1.v, v2v = v2.v;
|
|
115
|
+
if (useZ) {
|
|
116
|
+
w0 = 1 / v0.z;
|
|
117
|
+
w1 = 1 / v1.z;
|
|
118
|
+
w2 = 1 / v2.z;
|
|
119
|
+
u0 *= w0;
|
|
120
|
+
u1 *= w1;
|
|
121
|
+
u2 *= w2;
|
|
122
|
+
v0v *= w0;
|
|
123
|
+
v1v *= w1;
|
|
124
|
+
v2v *= w2;
|
|
125
|
+
}
|
|
126
|
+
const imageData = context.getImageData(minX, minY, maxX - minX, maxY - minY);
|
|
127
|
+
const pixels = imageData.data;
|
|
128
|
+
for (let y = minY; y < maxY; y++) {
|
|
129
|
+
for (let x = minX; x < maxX; x++) {
|
|
130
|
+
const p = {
|
|
131
|
+
x: x + 0.5,
|
|
132
|
+
y: y + 0.5
|
|
133
|
+
};
|
|
134
|
+
const w0b = edgeFn(v1, v2, p);
|
|
135
|
+
const w1b = edgeFn(v2, v0, p);
|
|
136
|
+
const w2b = edgeFn(v0, v1, p);
|
|
137
|
+
if (w0b >= 0 && w1b >= 0 && w2b >= 0) {
|
|
138
|
+
const bary0 = w0b / area;
|
|
139
|
+
const bary1 = w1b / area;
|
|
140
|
+
const bary2 = w2b / area;
|
|
141
|
+
if (useZ && zBuffer) {
|
|
142
|
+
const z = bary0 * v0.z + bary1 * v1.z + bary2 * v2.z;
|
|
143
|
+
const currentZ = zBuffer.get(x, y);
|
|
144
|
+
if (currentZ > 0 && currentZ >= z) continue;
|
|
145
|
+
zBuffer.set(x, y, z);
|
|
146
|
+
}
|
|
147
|
+
let u, v;
|
|
148
|
+
if (useZ) {
|
|
149
|
+
const w = bary0 * w0 + bary1 * w1 + bary2 * w2;
|
|
150
|
+
u = (bary0 * u0 + bary1 * u1 + bary2 * u2) / w;
|
|
151
|
+
v = (bary0 * v0v + bary1 * v1v + bary2 * v2v) / w;
|
|
152
|
+
} else {
|
|
153
|
+
u = bary0 * v0.u + bary1 * v1.u + bary2 * v2.u;
|
|
154
|
+
v = bary0 * v0.v + bary1 * v1.v + bary2 * v2.v;
|
|
155
|
+
}
|
|
156
|
+
let pixel = null;
|
|
157
|
+
if (textureSource === "map") {
|
|
158
|
+
pixel = getMapPixel(texture, u, v, runtime);
|
|
159
|
+
} else {
|
|
160
|
+
pixel = getSpritePixel(texture, u, v, runtime);
|
|
161
|
+
}
|
|
162
|
+
if (pixel && pixel.a > 0) {
|
|
163
|
+
const idx = ((y - minY) * (maxX - minX) + (x - minX)) * 4;
|
|
164
|
+
pixels[idx] = pixel.r;
|
|
165
|
+
pixels[idx + 1] = pixel.g;
|
|
166
|
+
pixels[idx + 2] = pixel.b;
|
|
167
|
+
pixels[idx + 3] = pixel.a;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
context.imageSmoothingEnabled = !pixelated;
|
|
173
|
+
context.putImageData(imageData, minX, minY);
|
|
174
|
+
}
|
|
175
|
+
__name(drawTexturedTriangle, "drawTexturedTriangle");
|
|
176
|
+
function drawTriangle(context, v0, v1, v2, color) {
|
|
177
|
+
context.fillStyle = color;
|
|
178
|
+
context.beginPath();
|
|
179
|
+
context.moveTo(v0.x, v0.y);
|
|
180
|
+
context.lineTo(v1.x, v1.y);
|
|
181
|
+
context.lineTo(v2.x, v2.y);
|
|
182
|
+
context.closePath();
|
|
183
|
+
context.fill();
|
|
184
|
+
}
|
|
185
|
+
__name(drawTriangle, "drawTriangle");
|
|
186
|
+
function drawTriangleOutline(context, v0, v1, v2, color, lineWidth = 1) {
|
|
187
|
+
context.strokeStyle = color;
|
|
188
|
+
context.lineWidth = lineWidth;
|
|
189
|
+
context.beginPath();
|
|
190
|
+
context.moveTo(v0.x, v0.y);
|
|
191
|
+
context.lineTo(v1.x, v1.y);
|
|
192
|
+
context.lineTo(v2.x, v2.y);
|
|
193
|
+
context.closePath();
|
|
194
|
+
context.stroke();
|
|
195
|
+
}
|
|
196
|
+
__name(drawTriangleOutline, "drawTriangleOutline");
|
|
197
|
+
export {
|
|
198
|
+
ZBuffer,
|
|
199
|
+
drawTexturedTriangle,
|
|
200
|
+
drawTriangle,
|
|
201
|
+
drawTriangleOutline
|
|
202
|
+
};
|
|
203
|
+
//# sourceMappingURL=ttri.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/tri/ttri.ts"],"sourcesContent":["/**\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":";;;;AAoDO,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,MAAA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OAAAA;QACvC;AAGA,YAAI6D,SAASA,MAAMpE,IAAI,GAAG;AACzB,gBAAMqE,QAAQ1E,IAAI+C,SAASC,OAAOJ,SAAS7C,IAAI6C,SAAS;AACxDmB,iBAAOW,GAAAA,IAAOD,MAAMhD;AACpBsC,iBAAOW,MAAM,CAAA,IAAKD,MAAM9C;AACxBoC,iBAAOW,MAAM,CAAA,IAAKD,MAAMnE;AACxByD,iBAAOW,MAAM,CAAA,IAAKD,MAAMpE;QACzB;MACD;IACD;EACD;AAGAqC,UAAQiC,wBAAwB,CAAChC;AACjCD,UAAQkC,aAAarD,WAAWqB,MAAMG,IAAAA;AACvC;AA7HgBb;AAkIT,SAAS2C,aAAanC,SAAmCP,IAAUC,IAAUC,IAAUyC,OAAa;AAC1GpC,UAAQqC,YAAYD;AACpBpC,UAAQsC,UAAS;AACjBtC,UAAQuC,OAAO9C,GAAGpC,GAAGoC,GAAGnC,CAAC;AACzB0C,UAAQwC,OAAO9C,GAAGrC,GAAGqC,GAAGpC,CAAC;AACzB0C,UAAQwC,OAAO7C,GAAGtC,GAAGsC,GAAGrC,CAAC;AACzB0C,UAAQyC,UAAS;AACjBzC,UAAQ7C,KAAI;AACb;AARgBgF;AAaT,SAASO,oBACf1C,SACAP,IACAC,IACAC,IACAyC,OACAO,YAAoB,GAAC;AAErB3C,UAAQ4C,cAAcR;AACtBpC,UAAQ2C,YAAYA;AACpB3C,UAAQsC,UAAS;AACjBtC,UAAQuC,OAAO9C,GAAGpC,GAAGoC,GAAGnC,CAAC;AACzB0C,UAAQwC,OAAO9C,GAAGrC,GAAGqC,GAAGpC,CAAC;AACzB0C,UAAQwC,OAAO7C,GAAGtC,GAAGsC,GAAGrC,CAAC;AACzB0C,UAAQyC,UAAS;AACjBzC,UAAQ6C,OAAM;AACf;AAhBgBH;","names":["ZBuffer","buffer","width","height","Float32Array","clear","fill","get","x","y","set","z","resize","edgeFn","a","b","c","getSpritePixel","sprite","u","v","runtime","canvas","sprites","spriteObj","frames","Math","floor","px","py","ctx","getContext","imageData","getImageData","r","data","g","e","getMapPixel","map","mapObj","getCanvas","maps","drawTexturedTriangle","v0","v1","v2","texture","textureSource","zBuffer","useDepth","context","pixelated","minX","max","min","minY","maxX","ceil","maxY","area","abs","useZ","w0","w1","w2","u0","u1","u2","v0v","v1v","v2v","pixels","p","w0b","w1b","w2b","bary0","bary1","bary2","currentZ","w","pixel","idx","imageSmoothingEnabled","putImageData","drawTriangle","color","fillStyle","beginPath","moveTo","lineTo","closePath","drawTriangleOutline","lineWidth","strokeStyle","stroke"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { TileMap } from '@al8b/map';
|
|
2
|
+
import { Sprite } from '@al8b/sprites';
|
|
3
|
+
import { TextureSource } from '../tri/ttri.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Screen initialization options
|
|
7
|
+
*/
|
|
8
|
+
interface ScreenOptions {
|
|
9
|
+
runtime?: any;
|
|
10
|
+
canvas?: HTMLCanvasElement;
|
|
11
|
+
width?: number;
|
|
12
|
+
height?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Public API exposed to the runtime/VM layer
|
|
16
|
+
*/
|
|
17
|
+
interface ScreenInterface {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
clear: (color?: string) => void;
|
|
21
|
+
setColor: (color: string | number) => void;
|
|
22
|
+
setAlpha: (alpha: number) => void;
|
|
23
|
+
setPixelated: (pixelated: number) => void;
|
|
24
|
+
setBlending: (blending: string) => void;
|
|
25
|
+
setLinearGradient: (x1: number, y1: number, x2: number, y2: number, c1: string, c2: string) => void;
|
|
26
|
+
setRadialGradient: (x: number, y: number, radius: number, c1: string, c2: string) => void;
|
|
27
|
+
setFont: (font: string) => void;
|
|
28
|
+
setTranslation: (tx: number, ty: number) => void;
|
|
29
|
+
setScale: (x: number, y: number) => void;
|
|
30
|
+
setRotation: (rotation: number) => void;
|
|
31
|
+
setDrawAnchor: (ax: number, ay: number) => void;
|
|
32
|
+
setDrawRotation: (rotation: number) => void;
|
|
33
|
+
setDrawScale: (x: number, y?: number) => void;
|
|
34
|
+
fillRect: (x: number, y: number, w: number, h: number, c?: string | number) => void;
|
|
35
|
+
fillRoundRect: (x: number, y: number, w: number, h: number, r?: number, c?: string | number) => void;
|
|
36
|
+
fillRound: (x: number, y: number, w: number, h: number, c?: string | number) => void;
|
|
37
|
+
drawRect: (x: number, y: number, w: number, h: number, c?: string | number) => void;
|
|
38
|
+
drawRoundRect: (x: number, y: number, w: number, h: number, r?: number, c?: string | number) => void;
|
|
39
|
+
drawRound: (x: number, y: number, w: number, h: number, c?: string | number) => void;
|
|
40
|
+
drawSprite: (sprite: Sprite | string, x: number, y: number, w?: number, h?: number) => void;
|
|
41
|
+
drawSpritePart: (sprite: Sprite | string | any, sx: number, sy: number, sw: number, sh: number, x: number, y: number, w?: number, h?: number) => void;
|
|
42
|
+
drawMap: (map: TileMap | string, x: number, y: number, w: number, h: number) => void;
|
|
43
|
+
drawText: (text: string, x: number, y: number, size: number, color?: string | number) => void;
|
|
44
|
+
drawTextOutline: (text: string, x: number, y: number, size: number, color?: string | number) => void;
|
|
45
|
+
textWidth: (text: string, size: number) => number;
|
|
46
|
+
setLineWidth: (width: number) => void;
|
|
47
|
+
setLineDash: (dash: number[] | null) => void;
|
|
48
|
+
drawLine: (x1: number, y1: number, x2: number, y2: number, color?: string | number) => void;
|
|
49
|
+
drawPolygon: (...args: any[]) => void;
|
|
50
|
+
drawPolyline: (...args: any[]) => void;
|
|
51
|
+
fillPolygon: (...args: any[]) => void;
|
|
52
|
+
drawQuadCurve: (...args: any[]) => void;
|
|
53
|
+
drawBezierCurve: (...args: any[]) => void;
|
|
54
|
+
drawArc: (x: number, y: number, radius: number, angle1: number, angle2: number, ccw: boolean, color?: string | number) => void;
|
|
55
|
+
fillArc: (x: number, y: number, radius: number, angle1: number, angle2: number, ccw: boolean, color?: string | number) => void;
|
|
56
|
+
setCursorVisible: (visible: boolean) => void;
|
|
57
|
+
loadFont: (font: string) => void;
|
|
58
|
+
isFontReady: (font?: string) => number;
|
|
59
|
+
tri: (x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, color?: string | number) => void;
|
|
60
|
+
trib: (x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, color?: string | number) => void;
|
|
61
|
+
ttri: (x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, u1: number, v1: number, u2: number, v2: number, u3: number, v3: number, texture: Sprite | TileMap | string, textureSource?: TextureSource, z1?: number, z2?: number, z3?: number, useDepth?: boolean) => void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type { ScreenInterface, ScreenOptions };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { TileMap } from '@al8b/map';
|
|
2
|
+
import { Sprite } from '@al8b/sprites';
|
|
3
|
+
import { TextureSource } from '../tri/ttri.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Screen initialization options
|
|
7
|
+
*/
|
|
8
|
+
interface ScreenOptions {
|
|
9
|
+
runtime?: any;
|
|
10
|
+
canvas?: HTMLCanvasElement;
|
|
11
|
+
width?: number;
|
|
12
|
+
height?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Public API exposed to the runtime/VM layer
|
|
16
|
+
*/
|
|
17
|
+
interface ScreenInterface {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
clear: (color?: string) => void;
|
|
21
|
+
setColor: (color: string | number) => void;
|
|
22
|
+
setAlpha: (alpha: number) => void;
|
|
23
|
+
setPixelated: (pixelated: number) => void;
|
|
24
|
+
setBlending: (blending: string) => void;
|
|
25
|
+
setLinearGradient: (x1: number, y1: number, x2: number, y2: number, c1: string, c2: string) => void;
|
|
26
|
+
setRadialGradient: (x: number, y: number, radius: number, c1: string, c2: string) => void;
|
|
27
|
+
setFont: (font: string) => void;
|
|
28
|
+
setTranslation: (tx: number, ty: number) => void;
|
|
29
|
+
setScale: (x: number, y: number) => void;
|
|
30
|
+
setRotation: (rotation: number) => void;
|
|
31
|
+
setDrawAnchor: (ax: number, ay: number) => void;
|
|
32
|
+
setDrawRotation: (rotation: number) => void;
|
|
33
|
+
setDrawScale: (x: number, y?: number) => void;
|
|
34
|
+
fillRect: (x: number, y: number, w: number, h: number, c?: string | number) => void;
|
|
35
|
+
fillRoundRect: (x: number, y: number, w: number, h: number, r?: number, c?: string | number) => void;
|
|
36
|
+
fillRound: (x: number, y: number, w: number, h: number, c?: string | number) => void;
|
|
37
|
+
drawRect: (x: number, y: number, w: number, h: number, c?: string | number) => void;
|
|
38
|
+
drawRoundRect: (x: number, y: number, w: number, h: number, r?: number, c?: string | number) => void;
|
|
39
|
+
drawRound: (x: number, y: number, w: number, h: number, c?: string | number) => void;
|
|
40
|
+
drawSprite: (sprite: Sprite | string, x: number, y: number, w?: number, h?: number) => void;
|
|
41
|
+
drawSpritePart: (sprite: Sprite | string | any, sx: number, sy: number, sw: number, sh: number, x: number, y: number, w?: number, h?: number) => void;
|
|
42
|
+
drawMap: (map: TileMap | string, x: number, y: number, w: number, h: number) => void;
|
|
43
|
+
drawText: (text: string, x: number, y: number, size: number, color?: string | number) => void;
|
|
44
|
+
drawTextOutline: (text: string, x: number, y: number, size: number, color?: string | number) => void;
|
|
45
|
+
textWidth: (text: string, size: number) => number;
|
|
46
|
+
setLineWidth: (width: number) => void;
|
|
47
|
+
setLineDash: (dash: number[] | null) => void;
|
|
48
|
+
drawLine: (x1: number, y1: number, x2: number, y2: number, color?: string | number) => void;
|
|
49
|
+
drawPolygon: (...args: any[]) => void;
|
|
50
|
+
drawPolyline: (...args: any[]) => void;
|
|
51
|
+
fillPolygon: (...args: any[]) => void;
|
|
52
|
+
drawQuadCurve: (...args: any[]) => void;
|
|
53
|
+
drawBezierCurve: (...args: any[]) => void;
|
|
54
|
+
drawArc: (x: number, y: number, radius: number, angle1: number, angle2: number, ccw: boolean, color?: string | number) => void;
|
|
55
|
+
fillArc: (x: number, y: number, radius: number, angle1: number, angle2: number, ccw: boolean, color?: string | number) => void;
|
|
56
|
+
setCursorVisible: (visible: boolean) => void;
|
|
57
|
+
loadFont: (font: string) => void;
|
|
58
|
+
isFontReady: (font?: string) => number;
|
|
59
|
+
tri: (x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, color?: string | number) => void;
|
|
60
|
+
trib: (x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, color?: string | number) => void;
|
|
61
|
+
ttri: (x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, u1: number, v1: number, u2: number, v2: number, u3: number, v3: number, texture: Sprite | TileMap | string, textureSource?: TextureSource, z1?: number, z2?: number, z3?: number, useDepth?: boolean) => void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type { ScreenInterface, ScreenOptions };
|
|
@@ -0,0 +1,19 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types/index.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["import type { TileMap as Map } from \"@al8b/map\";\nimport type { Sprite } from \"@al8b/sprites\";\nimport type { TextureSource } from \"../tri\";\n\n/**\n * Screen initialization options\n */\nexport interface ScreenOptions {\n\truntime?: any; // Reference to runtime for accessing sprites and maps\n\tcanvas?: HTMLCanvasElement;\n\twidth?: number;\n\theight?: number;\n}\n\n/**\n * Public API exposed to the runtime/VM layer\n */\nexport interface ScreenInterface {\n\twidth: number;\n\theight: number;\n\tclear: (color?: string) => void;\n\tsetColor: (color: string | number) => void;\n\tsetAlpha: (alpha: number) => void;\n\tsetPixelated: (pixelated: number) => void;\n\tsetBlending: (blending: string) => void;\n\tsetLinearGradient: (x1: number, y1: number, x2: number, y2: number, c1: string, c2: string) => void;\n\tsetRadialGradient: (x: number, y: number, radius: number, c1: string, c2: string) => void;\n\tsetFont: (font: string) => void;\n\tsetTranslation: (tx: number, ty: number) => void;\n\tsetScale: (x: number, y: number) => void;\n\tsetRotation: (rotation: number) => void;\n\tsetDrawAnchor: (ax: number, ay: number) => void;\n\tsetDrawRotation: (rotation: number) => void;\n\tsetDrawScale: (x: number, y?: number) => void;\n\tfillRect: (x: number, y: number, w: number, h: number, c?: string | number) => void;\n\tfillRoundRect: (x: number, y: number, w: number, h: number, r?: number, c?: string | number) => void;\n\tfillRound: (x: number, y: number, w: number, h: number, c?: string | number) => void;\n\tdrawRect: (x: number, y: number, w: number, h: number, c?: string | number) => void;\n\tdrawRoundRect: (x: number, y: number, w: number, h: number, r?: number, c?: string | number) => void;\n\tdrawRound: (x: number, y: number, w: number, h: number, c?: string | number) => void;\n\tdrawSprite: (sprite: Sprite | string, x: number, y: number, w?: number, h?: number) => void;\n\tdrawSpritePart: (\n\t\tsprite: Sprite | string | any,\n\t\tsx: number,\n\t\tsy: number,\n\t\tsw: number,\n\t\tsh: number,\n\t\tx: number,\n\t\ty: number,\n\t\tw?: number,\n\t\th?: number,\n\t) => void;\n\tdrawMap: (map: Map | string, x: number, y: number, w: number, h: number) => void;\n\tdrawText: (text: string, x: number, y: number, size: number, color?: string | number) => void;\n\tdrawTextOutline: (text: string, x: number, y: number, size: number, color?: string | number) => void;\n\ttextWidth: (text: string, size: number) => number;\n\tsetLineWidth: (width: number) => void;\n\tsetLineDash: (dash: number[] | null) => void;\n\tdrawLine: (x1: number, y1: number, x2: number, y2: number, color?: string | number) => void;\n\tdrawPolygon: (...args: any[]) => void;\n\tdrawPolyline: (...args: any[]) => void;\n\tfillPolygon: (...args: any[]) => void;\n\tdrawQuadCurve: (...args: any[]) => void;\n\tdrawBezierCurve: (...args: any[]) => void;\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\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\tsetCursorVisible: (visible: boolean) => void;\n\tloadFont: (font: string) => void;\n\tisFontReady: (font?: string) => number;\n\ttri: (x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, color?: string | number) => void;\n\ttrib: (x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, color?: string | number) => void;\n\tttri: (\n\t\tx1: number,\n\t\ty1: number,\n\t\tx2: number,\n\t\ty2: number,\n\t\tx3: number,\n\t\ty3: number,\n\t\tu1: number,\n\t\tv1: number,\n\t\tu2: number,\n\t\tv2: number,\n\t\tu3: number,\n\t\tv3: number,\n\t\ttexture: Sprite | Map | string,\n\t\ttextureSource?: TextureSource,\n\t\tz1?: number,\n\t\tz2?: number,\n\t\tz3?: number,\n\t\tuseDepth?: boolean,\n\t) => void;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAcA;;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@al8b/screen",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"files": [
|
|
6
|
+
"dist/**/*",
|
|
7
|
+
"README.md",
|
|
8
|
+
"package.json"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsup",
|
|
12
|
+
"clean": "bun --bun ../../../scripts/clean-package.mjs dist",
|
|
13
|
+
"test": "vitest run --passWithNoTests"
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"module": "./dist/index.mjs",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.mjs",
|
|
22
|
+
"require": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@al8b/diagnostics": "workspace:*",
|
|
27
|
+
"@al8b/image": "workspace:*",
|
|
28
|
+
"@al8b/map": "workspace:*",
|
|
29
|
+
"@al8b/sprites": "workspace:*"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"screen"
|
|
33
|
+
],
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
}
|
|
37
|
+
}
|