zx-kit 0.2.1 → 0.2.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 +10 -4
- package/dist/input.d.ts +3 -2
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js +7 -2
- package/dist/input.js.map +1 -1
- package/dist/renderer.d.ts +12 -9
- package/dist/renderer.d.ts.map +1 -1
- package/dist/renderer.js +17 -11
- package/dist/renderer.js.map +1 -1
- package/package.json +4 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 zrebec
|
|
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
|
@@ -29,7 +29,7 @@ import { setupCanvas, C, CELL, drawText, initAudio, playPattern, initInput, tick
|
|
|
29
29
|
|
|
30
30
|
// Canvas — one call replaces the manual boilerplate
|
|
31
31
|
const canvas = document.getElementById('game') as HTMLCanvasElement
|
|
32
|
-
const ctx = setupCanvas(canvas,
|
|
32
|
+
const ctx = setupCanvas(canvas, 4) // scale=4, 256×192 game px → 1024×768 CSS px
|
|
33
33
|
|
|
34
34
|
// Input
|
|
35
35
|
initInput()
|
|
@@ -113,14 +113,20 @@ All functions work in **game pixels**. At `SCALE=4` each game pixel maps to a 4
|
|
|
113
113
|
|
|
114
114
|
Every draw function follows the ZX Spectrum **ink / paper** model: each 8×8 cell has one foreground (ink) and one background (paper) color.
|
|
115
115
|
|
|
116
|
-
#### `setupCanvas(canvas,
|
|
116
|
+
#### `setupCanvas(canvas, scale, width?, height?): CanvasRenderingContext2D`
|
|
117
117
|
|
|
118
|
-
Initialises a canvas element for pixel-perfect rendering. Sets dimensions, disables image smoothing, and
|
|
118
|
+
Initialises a canvas element for pixel-perfect scaled rendering. Sets canvas dimensions, applies CSS size, disables image smoothing, and calls `ctx.scale(scale, scale)` so all subsequent draw calls use game-pixel coordinates. **Replaces the manual canvas setup boilerplate.**
|
|
119
|
+
|
|
120
|
+
- `scale` — CSS pixels per game pixel (`4` = standard ZX Spectrum display)
|
|
121
|
+
- `width` — game pixels wide (default `256`)
|
|
122
|
+
- `height` — game pixels tall (default `192`)
|
|
119
123
|
|
|
120
124
|
```ts
|
|
121
125
|
const canvas = document.getElementById('game') as HTMLCanvasElement
|
|
122
|
-
const ctx = setupCanvas(canvas, 256
|
|
126
|
+
const ctx = setupCanvas(canvas, 4) // 256×192 game px → 1024×768 CSS px
|
|
127
|
+
const ctx = setupCanvas(canvas, 4, 256, 208) // taller canvas for status rows
|
|
123
128
|
// ctx.imageSmoothingEnabled is already false — no need to set it manually
|
|
129
|
+
// all draw calls use game-pixel coordinates — ctx.scale() is already applied
|
|
124
130
|
```
|
|
125
131
|
|
|
126
132
|
#### `mirrorSprite(src): Uint8Array`
|
package/dist/input.d.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
export type Direction = 'up' | 'down' | 'left' | 'right';
|
|
3
3
|
/**
|
|
4
4
|
* Attaches global `keydown`/`keyup` listeners and configures key-repeat timing.
|
|
5
|
-
*
|
|
5
|
+
* Idempotent — safe to call multiple times. Timing params are always updated;
|
|
6
|
+
* listeners are only attached on the first call.
|
|
6
7
|
* Arrow keys drive movement; `F`/`f` = flag; `P`/`p` = pause; `Ctrl+Shift+B` = debug toggle.
|
|
7
8
|
*
|
|
8
9
|
* @param repeatDelay - Milliseconds before auto-repeat starts after initial press (default `150`)
|
|
@@ -10,7 +11,7 @@ export type Direction = 'up' | 'down' | 'left' | 'right';
|
|
|
10
11
|
*
|
|
11
12
|
* @example
|
|
12
13
|
* initInput() // defaults: 150ms delay, 80ms repeat
|
|
13
|
-
* initInput(200, 60) // custom timing
|
|
14
|
+
* initInput(200, 60) // custom timing; safe to call again to reconfigure
|
|
14
15
|
*/
|
|
15
16
|
export declare function initInput(repeatDelay?: number, repeatInterval?: number): void;
|
|
16
17
|
/**
|
package/dist/input.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAoBxD;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,WAAW,SAAM,EAAE,cAAc,SAAK,GAAG,IAAI,CAoCtE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAe3D;AAED,sGAAsG;AACtG,wBAAgB,WAAW,IAAI,OAAO,CAA+D;AAErG,gGAAgG;AAChG,wBAAgB,YAAY,IAAI,OAAO,CAA8D;AAErG,kFAAkF;AAClF,wBAAgB,YAAY,IAAI,OAAO,CAA8D;AAErG;;;GAGG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAA6D;AAErG;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAyB"}
|
package/dist/input.js
CHANGED
|
@@ -12,9 +12,11 @@ let repeatPhase = 'idle';
|
|
|
12
12
|
let pendingImmediate = null;
|
|
13
13
|
let _repeatDelay = 150;
|
|
14
14
|
let _repeatInterval = 80;
|
|
15
|
+
let inputInitialized = false;
|
|
15
16
|
/**
|
|
16
17
|
* Attaches global `keydown`/`keyup` listeners and configures key-repeat timing.
|
|
17
|
-
*
|
|
18
|
+
* Idempotent — safe to call multiple times. Timing params are always updated;
|
|
19
|
+
* listeners are only attached on the first call.
|
|
18
20
|
* Arrow keys drive movement; `F`/`f` = flag; `P`/`p` = pause; `Ctrl+Shift+B` = debug toggle.
|
|
19
21
|
*
|
|
20
22
|
* @param repeatDelay - Milliseconds before auto-repeat starts after initial press (default `150`)
|
|
@@ -22,11 +24,14 @@ let _repeatInterval = 80;
|
|
|
22
24
|
*
|
|
23
25
|
* @example
|
|
24
26
|
* initInput() // defaults: 150ms delay, 80ms repeat
|
|
25
|
-
* initInput(200, 60) // custom timing
|
|
27
|
+
* initInput(200, 60) // custom timing; safe to call again to reconfigure
|
|
26
28
|
*/
|
|
27
29
|
export function initInput(repeatDelay = 150, repeatInterval = 80) {
|
|
28
30
|
_repeatDelay = repeatDelay;
|
|
29
31
|
_repeatInterval = repeatInterval;
|
|
32
|
+
if (inputInitialized)
|
|
33
|
+
return;
|
|
34
|
+
inputInitialized = true;
|
|
30
35
|
window.addEventListener('keydown', (e) => {
|
|
31
36
|
if (e.repeat)
|
|
32
37
|
return;
|
package/dist/input.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.js","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":"AAGA,MAAM,QAAQ,GAA8B;IAC1C,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO;CACzE,CAAA;AAED,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;AAC9B,IAAI,WAAW,GAAG,KAAK,CAAA;AACvB,IAAI,YAAY,GAAG,KAAK,CAAA;AACxB,IAAI,YAAY,GAAG,KAAK,CAAA;AACxB,IAAI,aAAa,GAAG,KAAK,CAAA;AAEzB,IAAI,SAAS,GAAqB,IAAI,CAAA;AACtC,IAAI,WAAW,GAAG,CAAC,CAAA;AACnB,IAAI,WAAW,GAAgC,MAAM,CAAA;AACrD,IAAI,gBAAgB,GAAqB,IAAI,CAAA;AAC7C,IAAI,YAAY,GAAG,GAAG,CAAA;AACtB,IAAI,eAAe,GAAG,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":"AAGA,MAAM,QAAQ,GAA8B;IAC1C,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO;CACzE,CAAA;AAED,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;AAC9B,IAAI,WAAW,GAAG,KAAK,CAAA;AACvB,IAAI,YAAY,GAAG,KAAK,CAAA;AACxB,IAAI,YAAY,GAAG,KAAK,CAAA;AACxB,IAAI,aAAa,GAAG,KAAK,CAAA;AAEzB,IAAI,SAAS,GAAqB,IAAI,CAAA;AACtC,IAAI,WAAW,GAAG,CAAC,CAAA;AACnB,IAAI,W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AC,CAAC;AAErG,kFAAkF;AAClF,MAAM,UAAU,YAAY,KAAe,MAAM,CAAC,GAAG,YAAY,CAAC,CAAE,YAAY,GAAI,KAAK,CAAC,CAAC,OAAO,CAAC,CAAA,CAAC,CAAC;AAErG;;;GAGG;AACH,MAAM,UAAU,aAAa,KAAc,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,CAAA,CAAC,CAAC;AAErG;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM,CAAC,GAAW,IAAa,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA,CAAC,CAAC"}
|
package/dist/renderer.d.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Initialises a canvas element for pixel-perfect
|
|
3
|
-
* Sets canvas dimensions, disables image smoothing,
|
|
4
|
-
*
|
|
2
|
+
* Initialises a canvas element for pixel-perfect scaled rendering.
|
|
3
|
+
* Sets canvas dimensions, applies CSS size, disables image smoothing, applies `ctx.scale()`,
|
|
4
|
+
* and returns the 2D context. All subsequent draw calls use game-pixel coordinates.
|
|
5
|
+
* Call once at game startup.
|
|
5
6
|
*
|
|
6
|
-
* @param canvas
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @
|
|
7
|
+
* @param canvas - The `<canvas>` element to configure
|
|
8
|
+
* @param scale - CSS pixels per game pixel (e.g. `4` for standard ZX Spectrum display)
|
|
9
|
+
* @param width - Canvas width in game pixels (default `256`)
|
|
10
|
+
* @param height - Canvas height in game pixels (default `192`)
|
|
11
|
+
* @returns The configured `CanvasRenderingContext2D` (already scaled — draw in game pixels)
|
|
10
12
|
*
|
|
11
13
|
* @example
|
|
12
14
|
* const canvas = document.getElementById('game') as HTMLCanvasElement
|
|
13
|
-
* const ctx = setupCanvas(canvas, 256
|
|
15
|
+
* const ctx = setupCanvas(canvas, 4) // 256×192 game px → 1024×768 CSS px
|
|
16
|
+
* const ctx = setupCanvas(canvas, 4, 256, 208) // taller canvas for status rows
|
|
14
17
|
*/
|
|
15
|
-
export declare function setupCanvas(canvas: HTMLCanvasElement,
|
|
18
|
+
export declare function setupCanvas(canvas: HTMLCanvasElement, scale: number, width?: number, height?: number): CanvasRenderingContext2D;
|
|
16
19
|
/**
|
|
17
20
|
* Flips an 8×8 sprite horizontally. Returns a new `Uint8Array`.
|
|
18
21
|
* Use to derive left-facing sprites from right-facing definitions at module load time.
|
package/dist/renderer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,iBAAiB,EACzB,KAAK,EAAE,MAAM,EACb,KAAK,SAAM,EACX,MAAM,SAAM,GACX,wBAAwB,CAS1B;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,UAAU,GAAG,UAAU,CAUxD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,wBAAwB,EAC7B,MAAM,EAAE,UAAU,EAClB,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EACpB,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GACzB,IAAI,CAUN;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CACtB,GAAG,EAAE,wBAAwB,EAC7B,IAAI,EAAE,MAAM,EACZ,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EACpB,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAC1B,IAAI,CAYN;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CACtB,GAAG,EAAE,wBAAwB,EAC7B,IAAI,EAAE,MAAM,EACZ,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EACpB,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAC1B,IAAI,CAIN;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,wBAAwB,EAC7B,IAAI,EAAE,MAAM,EACZ,CAAC,EAAE,MAAM,EACT,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAC1B,IAAI,CAGN;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,UAAU,GAAE,MAAgB,GAC3B,IAAI,CAWN"}
|
package/dist/renderer.js
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
import { C, CELL } from './palette.js';
|
|
2
2
|
import { getCharRow } from './font.js';
|
|
3
3
|
/**
|
|
4
|
-
* Initialises a canvas element for pixel-perfect
|
|
5
|
-
* Sets canvas dimensions, disables image smoothing,
|
|
6
|
-
*
|
|
4
|
+
* Initialises a canvas element for pixel-perfect scaled rendering.
|
|
5
|
+
* Sets canvas dimensions, applies CSS size, disables image smoothing, applies `ctx.scale()`,
|
|
6
|
+
* and returns the 2D context. All subsequent draw calls use game-pixel coordinates.
|
|
7
|
+
* Call once at game startup.
|
|
7
8
|
*
|
|
8
|
-
* @param canvas
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
11
|
-
* @
|
|
9
|
+
* @param canvas - The `<canvas>` element to configure
|
|
10
|
+
* @param scale - CSS pixels per game pixel (e.g. `4` for standard ZX Spectrum display)
|
|
11
|
+
* @param width - Canvas width in game pixels (default `256`)
|
|
12
|
+
* @param height - Canvas height in game pixels (default `192`)
|
|
13
|
+
* @returns The configured `CanvasRenderingContext2D` (already scaled — draw in game pixels)
|
|
12
14
|
*
|
|
13
15
|
* @example
|
|
14
16
|
* const canvas = document.getElementById('game') as HTMLCanvasElement
|
|
15
|
-
* const ctx = setupCanvas(canvas, 256
|
|
17
|
+
* const ctx = setupCanvas(canvas, 4) // 256×192 game px → 1024×768 CSS px
|
|
18
|
+
* const ctx = setupCanvas(canvas, 4, 256, 208) // taller canvas for status rows
|
|
16
19
|
*/
|
|
17
|
-
export function setupCanvas(canvas, width, height) {
|
|
18
|
-
canvas.width = width;
|
|
19
|
-
canvas.height = height;
|
|
20
|
+
export function setupCanvas(canvas, scale, width = 256, height = 192) {
|
|
21
|
+
canvas.width = width * scale;
|
|
22
|
+
canvas.height = height * scale;
|
|
23
|
+
canvas.style.width = `${width * scale}px`;
|
|
24
|
+
canvas.style.height = `${height * scale}px`;
|
|
20
25
|
const ctx = canvas.getContext('2d');
|
|
21
26
|
ctx.imageSmoothingEnabled = false;
|
|
27
|
+
ctx.scale(scale, scale);
|
|
22
28
|
return ctx;
|
|
23
29
|
}
|
|
24
30
|
/**
|
package/dist/renderer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,WAAW,CACzB,MAAyB,EACzB,KAAa,EACb,KAAK,GAAG,GAAG,EACX,MAAM,GAAG,GAAG;IAEZ,MAAM,CAAC,KAAK,GAAG,KAAK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CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAA;QACzE,IAAI,EAAE,CAAA;QACN,IAAI,IAAI,IAAI,UAAU,EAAE,CAAC;YACvB,aAAa,CAAC,EAAE,CAAC,CAAA;YACjB,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,GAAG,UAAU,CAAA;QAClD,CAAC;IACH,CAAC,EAAE,UAAU,CAAC,CAAA;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zx-kit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Reusable ZX Spectrum primitives: font, palette, renderer, audio, input",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"main": "./dist/index.js",
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
14
|
"files": [
|
|
15
|
-
"dist"
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
16
18
|
],
|
|
17
19
|
"scripts": {
|
|
18
20
|
"build": "tsc",
|