@nixia/2d 0.0.0-stage → 0.0.3
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/LICENSE +21 -0
- package/README.md +91 -2
- package/cli.js +124 -0
- package/index.html +11 -0
- package/package.json +34 -5
- package/publish.js +0 -0
- package/src/core/Actor.ts +20 -0
- package/src/core/Application.ts +105 -0
- package/src/core/Base.ts +25 -0
- package/src/core/ITickable.ts +5 -0
- package/src/core/Level.ts +27 -0
- package/src/core/RenderBuffer.ts +13 -0
- package/src/core/Renderer.ts +40 -0
- package/src/index.ts +9 -0
- package/src/main.ts +8 -0
- package/tsconfig.json +19 -0
- package/vite.config.ts +17 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 nixia.org
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,92 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 🎮 NIXIA 2D Game Engine
|
|
2
|
+
> A lightning-fast, lightweight 2D game engine written entirely in TypeScript, engineered from the ground up to run seamlessly on low-power machines and resource-constrained devices.
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## 🚀 Getting Started
|
|
7
|
+
|
|
8
|
+
Getting your first Nixia project up and running takes less than a minute. Follow these simple steps:
|
|
9
|
+
|
|
10
|
+
### 1. Initialize your workspace
|
|
11
|
+
Create a new directory for your game and step into it:
|
|
12
|
+
```bash
|
|
13
|
+
mkdir my-game
|
|
14
|
+
cd my-game
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### 2. Install the core package
|
|
18
|
+
Install the NIXIA package as a development dependency (this automatically pulls in Vite and all other required toolchain dependencies):
|
|
19
|
+
```bash
|
|
20
|
+
npm install -D @nixia/2d
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### 3. Initialize your project structure
|
|
24
|
+
Run the built-in CLI tool to scaffold your configuration files and entry point:
|
|
25
|
+
```bash
|
|
26
|
+
nixia init
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Once initialization is complete, you are ready to write code! Your application's main entry point is located at `src/main.ts`
|
|
30
|
+
|
|
31
|
+
## 🏗️ Creating Your First Level
|
|
32
|
+
Levels represent the scenes or stages of your game. To create a new level, generate a new TypeScript file inside `src/levels/MyLevel.ts`, extend the core `Nixia.Level` class, and configure it:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
// src/levels/MyLevel.ts
|
|
36
|
+
import * as Nixia from '@nixia/2d';
|
|
37
|
+
|
|
38
|
+
export class MyLevel extends Nixia.Level {
|
|
39
|
+
constructor() {
|
|
40
|
+
super("MyLevel");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Then in your `src/main.ts`, you can make this your default level by using the following code:
|
|
46
|
+
```ts
|
|
47
|
+
// src/main.ts
|
|
48
|
+
import * as Nixia from '@nixia/2d';
|
|
49
|
+
import { MyLevel } from './levels/MyLevel';
|
|
50
|
+
|
|
51
|
+
// Preload your level
|
|
52
|
+
const myLevel = new MyLevel();
|
|
53
|
+
|
|
54
|
+
// Create a new Application
|
|
55
|
+
const app = new Nixia.Application();
|
|
56
|
+
|
|
57
|
+
// Set the default level to our custom level
|
|
58
|
+
app.setDefaultLevel(myLevel);
|
|
59
|
+
|
|
60
|
+
// Start the application
|
|
61
|
+
app.start();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 👾 Creating Your First Actor
|
|
65
|
+
Actors represent game objects—or more specifically, active entities living inside a level. They handle components, custom game logic, rendering, physics, and more. You can create one like this:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
// src/actors/MyActor.ts
|
|
69
|
+
import * as Nixia from '@nixia/2d';
|
|
70
|
+
|
|
71
|
+
export class MyActor extends Nixai.Actor {
|
|
72
|
+
constructor() {
|
|
73
|
+
super("MyActor");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
You can add your Actor to your Level like this:
|
|
79
|
+
```ts
|
|
80
|
+
// src/levels/MyLevel.ts
|
|
81
|
+
import * as Nixia from '@nixia/2d';
|
|
82
|
+
import { MyActor } from './actors/MyActor';
|
|
83
|
+
|
|
84
|
+
export class MyLevel extends Nixia.Level {
|
|
85
|
+
constructor() {
|
|
86
|
+
super("MyLevel");
|
|
87
|
+
|
|
88
|
+
// This both adds the actor to the scene and registers it with
|
|
89
|
+
// the game lifecycle.
|
|
90
|
+
this.root.add(new MyActor(this, this.app));
|
|
91
|
+
}
|
|
92
|
+
}
|
package/cli.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
|
|
5
|
+
async function runCli() {
|
|
6
|
+
console.log('🔍 Running pre-flight environment checks...');
|
|
7
|
+
|
|
8
|
+
// Centralized pre-flight checks to prevent accidental overwrites
|
|
9
|
+
const existenceChecks = [
|
|
10
|
+
{ target: "src", message: "Error: The 'src/' directory already exists. Aborting to protect your files." },
|
|
11
|
+
{ target: "tsconfig.json", message: "Error: 'tsconfig.json' already exists in this directory." },
|
|
12
|
+
{ target: "vite.config.ts", message: "Error: 'vite.config.ts' already exists in this directory." }
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
for (const check of existenceChecks) {
|
|
16
|
+
if (fs.existsSync(check.target)) {
|
|
17
|
+
throw new Error(check.message);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
console.log('✅ Pre-flight checks passed successfully!');
|
|
21
|
+
|
|
22
|
+
console.log('💾 Creating project structure and writing files locally...');
|
|
23
|
+
|
|
24
|
+
// Ensure the src directory exists before writing nested files
|
|
25
|
+
fs.mkdirSync("src", { recursive: true });
|
|
26
|
+
|
|
27
|
+
// 1. Write index.html
|
|
28
|
+
const indexHtmlContent = `<!DOCTYPE html>
|
|
29
|
+
<html lang="en">
|
|
30
|
+
<head>
|
|
31
|
+
<meta charset="utf-8">
|
|
32
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
33
|
+
<title>Nixia Engine Default Game</title>
|
|
34
|
+
</head>
|
|
35
|
+
<body>
|
|
36
|
+
<script type="module" src="./src/main.ts"></script>
|
|
37
|
+
</body>
|
|
38
|
+
</html>`;
|
|
39
|
+
fs.writeFileSync("index.html", indexHtmlContent);
|
|
40
|
+
console.log('📄 Created index.html successfully!');
|
|
41
|
+
|
|
42
|
+
// 2. Write tsconfig.json (Fixed the missing filename bug!)
|
|
43
|
+
const tsConfigData = {
|
|
44
|
+
"compilerOptions": {
|
|
45
|
+
"target": "ESNext",
|
|
46
|
+
"useDefineForClassFields": true,
|
|
47
|
+
"module": "ESNext",
|
|
48
|
+
"moduleResolution": "bundler",
|
|
49
|
+
"isolatedModules": true,
|
|
50
|
+
"strict": true,
|
|
51
|
+
"noUnusedLocals": true,
|
|
52
|
+
"noUnusedParameters": true,
|
|
53
|
+
"noImplicitReturns": true,
|
|
54
|
+
"skipLibCheck": true,
|
|
55
|
+
"resolveJsonModule": true,
|
|
56
|
+
"esModuleInterop": true,
|
|
57
|
+
"allowSyntheticDefaultImports": true,
|
|
58
|
+
"types": ["vite/client"]
|
|
59
|
+
},
|
|
60
|
+
"include": ["src/**/*", "vite.config.ts"]
|
|
61
|
+
};
|
|
62
|
+
fs.writeFileSync("tsconfig.json", JSON.stringify(tsConfigData, null, 2));
|
|
63
|
+
console.log('📄 Created tsconfig.json successfully!');
|
|
64
|
+
|
|
65
|
+
// 3. Write vite.config.ts
|
|
66
|
+
const viteConfigContent = `import { defineConfig } from 'vite';
|
|
67
|
+
import { viteSingleFile } from 'vite-plugin-singlefile';
|
|
68
|
+
|
|
69
|
+
export default defineConfig({
|
|
70
|
+
plugins: [viteSingleFile()],
|
|
71
|
+
build: {
|
|
72
|
+
target: 'esnext',
|
|
73
|
+
assetsInlineLimit: 100000000,
|
|
74
|
+
chunkSizeWarningLimit: 100000000,
|
|
75
|
+
cssCodeSplit: false,
|
|
76
|
+
rollupOptions: {
|
|
77
|
+
output: {
|
|
78
|
+
inlineDynamicImports: true,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
});`;
|
|
83
|
+
fs.writeFileSync("vite.config.ts", viteConfigContent);
|
|
84
|
+
console.log('📄 Created vite.config.ts successfully!');
|
|
85
|
+
|
|
86
|
+
// 4. Write src/main.ts
|
|
87
|
+
const mainTsContent = `// This is the entry point for your game.
|
|
88
|
+
import * as Nixia from '@nixia/2d';
|
|
89
|
+
|
|
90
|
+
// Hello, world!`;
|
|
91
|
+
fs.writeFileSync(path.join("src", "main.ts"), mainTsContent);
|
|
92
|
+
console.log('📄 Created src/main.ts successfully!');
|
|
93
|
+
|
|
94
|
+
console.log('✅ All project components written to disk successfully!');
|
|
95
|
+
|
|
96
|
+
console.log('📦 Updating package.json configuration...');
|
|
97
|
+
const packageJsonPath = path.join("package.json");
|
|
98
|
+
|
|
99
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
100
|
+
const packageData = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
101
|
+
|
|
102
|
+
// Safely inject scripts and type module setting
|
|
103
|
+
packageData.scripts = {
|
|
104
|
+
...(packageData.scripts || {}),
|
|
105
|
+
"dev": "vite",
|
|
106
|
+
"build": "vite build",
|
|
107
|
+
"preview": "vite preview"
|
|
108
|
+
};
|
|
109
|
+
packageData.type = "module";
|
|
110
|
+
|
|
111
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageData, null, 2));
|
|
112
|
+
console.log('✨ package.json updated successfully with Vite scripts and ESM type!');
|
|
113
|
+
} else {
|
|
114
|
+
console.warn('⚠️ Warning: package.json not found in the current directory. Skipping script injection.');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
console.log('🎉 Project scaffolding completed successfully! Happy coding! 🚀✨');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Global execution wrapper with robust error catching
|
|
121
|
+
runCli().catch((error) => {
|
|
122
|
+
console.error(`\n💥 Fatal CLI Error: ${error.message}`);
|
|
123
|
+
process.exit(1);
|
|
124
|
+
});
|
package/index.html
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Nixia Engine Default Game</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<script type="module" src="./src/main.ts"></script>
|
|
10
|
+
</body>
|
|
11
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@nixia/2d",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "Aedan Maki",
|
|
6
|
+
"email": "aedanmaki@gmail.com"
|
|
7
|
+
},
|
|
8
|
+
"bin": "./cli.js",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./src/index.ts",
|
|
12
|
+
"module": "./src/index.ts",
|
|
13
|
+
"keywords": ["game-engine", "2d"],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./src/index.ts",
|
|
17
|
+
"types": "./src/index.ts"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"dev": "vite",
|
|
22
|
+
"build": "vite build",
|
|
23
|
+
"preview": "vite preview",
|
|
24
|
+
"publish": "nixia publish"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"fs": "^0.0.1-security",
|
|
28
|
+
"path": "^0.12.7"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"typescript": "^7.0.2",
|
|
32
|
+
"vite": "^8.3.5",
|
|
33
|
+
"vite-plugin-singlefile": "^2.3.4"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/publish.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/core/Actor.ts
|
|
2
|
+
import { Base } from "./Base";
|
|
3
|
+
import { ITickable } from "./ITickable";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents an Actor.
|
|
7
|
+
*/
|
|
8
|
+
export class Actor extends Base implements ITickable {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new Actor.
|
|
11
|
+
*/
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Called on tick.
|
|
18
|
+
*/
|
|
19
|
+
tick(dt: number): void {}
|
|
20
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// src/core/Application.ts
|
|
2
|
+
import { Base } from "./Base";
|
|
3
|
+
import { ITickable } from "./ITickable";
|
|
4
|
+
import { Renderer } from "./Renderer";
|
|
5
|
+
import { Level } from "./Level";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Represents an Application.
|
|
9
|
+
*/
|
|
10
|
+
export class Application extends Base {
|
|
11
|
+
/**
|
|
12
|
+
* If the game has already been initialized.
|
|
13
|
+
*/
|
|
14
|
+
private wasInitialized: boolean = false;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* If the game is ready.
|
|
18
|
+
*/
|
|
19
|
+
private isReady: boolean = false;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Previous tick time.
|
|
23
|
+
*/
|
|
24
|
+
private previousTickTime: number = Date.now();
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* An array of every tickable instance.
|
|
28
|
+
*/
|
|
29
|
+
private tickableInstances: ITickable[] = [];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The renderer instance.
|
|
33
|
+
*/
|
|
34
|
+
private renderer: Renderer;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The default level.
|
|
38
|
+
*/
|
|
39
|
+
private defaultLevel!: Level;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new Application.
|
|
43
|
+
*/
|
|
44
|
+
constructor() {
|
|
45
|
+
super();
|
|
46
|
+
|
|
47
|
+
this.renderer = new Renderer();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Starts the Application.
|
|
52
|
+
*/
|
|
53
|
+
start() {
|
|
54
|
+
if (this.wasInitialized) throw new Error('Application is already initialized.');
|
|
55
|
+
this.wasInitialized = true;
|
|
56
|
+
|
|
57
|
+
if (document.readyState === 'complete') {
|
|
58
|
+
this._ready();
|
|
59
|
+
} else {
|
|
60
|
+
window.addEventListener('load', () => {
|
|
61
|
+
this._ready();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Called when the game is ready.
|
|
68
|
+
*/
|
|
69
|
+
private _ready() {
|
|
70
|
+
this.isReady = true;
|
|
71
|
+
if (!this.defaultLevel) throw new Error("No default level was assigned, cannot create game.");
|
|
72
|
+
this.fire('ready');
|
|
73
|
+
|
|
74
|
+
requestAnimationFrame(this._tick);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Called on tick.
|
|
79
|
+
*/
|
|
80
|
+
private _tick = () => {
|
|
81
|
+
const now = Date.now();
|
|
82
|
+
const delta = now - this.previousTickTime;
|
|
83
|
+
|
|
84
|
+
const len = this.tickableInstances.length;
|
|
85
|
+
for (let i = 0; i < len; i++) {
|
|
86
|
+
const inst = this.tickableInstances[i];
|
|
87
|
+
inst.tick(delta);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.renderer.clear();
|
|
91
|
+
this.renderer.draw();
|
|
92
|
+
|
|
93
|
+
this.previousTickTime = now;
|
|
94
|
+
|
|
95
|
+
requestAnimationFrame(this._tick);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Sets the default level.
|
|
100
|
+
*/
|
|
101
|
+
setDefaultLevel(defaultLevel: Level) {
|
|
102
|
+
if (this.isReady) throw new Error("Cannot assign a default level when the game is already running.");
|
|
103
|
+
this.defaultLevel = defaultLevel;
|
|
104
|
+
}
|
|
105
|
+
}
|
package/src/core/Base.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/core/Base.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base class containing code for replication and events.
|
|
5
|
+
*/
|
|
6
|
+
export abstract class Base {
|
|
7
|
+
private events: Map<string, Function[]> = new Map();
|
|
8
|
+
|
|
9
|
+
on(event: string, callback: Function) {
|
|
10
|
+
const callbacks = this.events.get(event);
|
|
11
|
+
if (!callbacks) this.events.set(event, [callback]); else {
|
|
12
|
+
callbacks.push(callback);
|
|
13
|
+
this.events.set(event, callbacks);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
fire(event: string) {
|
|
18
|
+
const callbacks = this.events.get(event);
|
|
19
|
+
if (!callbacks) return;
|
|
20
|
+
const len = callbacks.length;
|
|
21
|
+
for (let i = 0; i < len; i++) {
|
|
22
|
+
callbacks[i]();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/core/Level.ts
|
|
2
|
+
import { Base } from "./Base";
|
|
3
|
+
import { ITickable } from "./ITickable";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents a Level.
|
|
7
|
+
*/
|
|
8
|
+
export class Level extends Base implements ITickable {
|
|
9
|
+
/**
|
|
10
|
+
* The level name.
|
|
11
|
+
*/
|
|
12
|
+
private name: string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new Level.
|
|
16
|
+
*/
|
|
17
|
+
constructor(name: string) {
|
|
18
|
+
super();
|
|
19
|
+
|
|
20
|
+
this.name = name;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Called on tick.
|
|
25
|
+
*/
|
|
26
|
+
tick(dt: number): void {}
|
|
27
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// src/core/Renderer.ts
|
|
2
|
+
import { Base } from "./Base";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Represents a Renderer.
|
|
6
|
+
*/
|
|
7
|
+
export class Renderer extends Base {
|
|
8
|
+
/**
|
|
9
|
+
* The canvas element.
|
|
10
|
+
*/
|
|
11
|
+
private canvas: HTMLCanvasElement;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new Renderer.
|
|
15
|
+
*/
|
|
16
|
+
constructor() {
|
|
17
|
+
super();
|
|
18
|
+
|
|
19
|
+
const canvas = document.createElement("canvas") as HTMLCanvasElement;
|
|
20
|
+
this.canvas = canvas;
|
|
21
|
+
this.canvas.width = 600;
|
|
22
|
+
this.canvas.height = 400;
|
|
23
|
+
this.canvas.style.border = "1px solid black";
|
|
24
|
+
document.body.appendChild(this.canvas);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Completely clears the canvas.
|
|
29
|
+
*/
|
|
30
|
+
clear() {
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Draws the buffers onto the canvas.
|
|
36
|
+
*/
|
|
37
|
+
draw() {
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/index.ts
ADDED
package/src/main.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"isolatedModules": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noUnusedLocals": true,
|
|
10
|
+
"noUnusedParameters": true,
|
|
11
|
+
"noImplicitReturns": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"allowSyntheticDefaultImports": true,
|
|
16
|
+
"types": ["vite/client"]
|
|
17
|
+
},
|
|
18
|
+
"include": ["src/**/*", "vite.config.ts"]
|
|
19
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import { viteSingleFile } from 'vite-plugin-singlefile';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
plugins: [viteSingleFile()],
|
|
6
|
+
build: {
|
|
7
|
+
target: 'esnext',
|
|
8
|
+
assetsInlineLimit: 100000000,
|
|
9
|
+
chunkSizeWarningLimit: 100000000,
|
|
10
|
+
cssCodeSplit: false,
|
|
11
|
+
rollupOptions: {
|
|
12
|
+
output: {
|
|
13
|
+
inlineDynamicImports: true,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|