zx-kit 0.5.1 → 0.5.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/README.md +1 -1
- package/dist/renderer.d.ts +8 -7
- package/dist/renderer.d.ts.map +1 -1
- package/dist/renderer.js +2 -2
- package/dist/renderer.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -171,7 +171,7 @@ Centers a string within `cols` character columns. Bind `cols` once in a helper t
|
|
|
171
171
|
|
|
172
172
|
```ts
|
|
173
173
|
// Bind once:
|
|
174
|
-
const centered = (ctx: CanvasRenderingContext2D, text: string, y: number, ink:
|
|
174
|
+
const centered = (ctx: CanvasRenderingContext2D, text: string, y: number, ink: SpectrumColor) =>
|
|
175
175
|
drawTextCentered(ctx, text, y, 32, ink)
|
|
176
176
|
|
|
177
177
|
centered(ctx, 'GAME OVER', y, C.B_RED)
|
package/dist/renderer.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type SpectrumColor } from './palette.js';
|
|
1
2
|
/**
|
|
2
3
|
* Initialises a canvas element for pixel-perfect scaled rendering.
|
|
3
4
|
* Sets canvas dimensions, applies CSS size, disables image smoothing, applies `ctx.scale()`,
|
|
@@ -39,7 +40,7 @@ export declare function mirrorSprite(src: Uint8Array): Uint8Array;
|
|
|
39
40
|
* @example
|
|
40
41
|
* drawSprite(ctx, MINE_SPRITE, col * CELL, row * CELL, C.B_RED, C.BLACK)
|
|
41
42
|
*/
|
|
42
|
-
export declare function drawSprite(ctx: CanvasRenderingContext2D, sprite: Uint8Array, x: number, y: number, ink:
|
|
43
|
+
export declare function drawSprite(ctx: CanvasRenderingContext2D, sprite: Uint8Array, x: number, y: number, ink: SpectrumColor, paper: SpectrumColor): void;
|
|
43
44
|
/**
|
|
44
45
|
* Draws a single ASCII character at game coordinates using the ROM font.
|
|
45
46
|
* If `paper` is omitted the background is not cleared (transparent).
|
|
@@ -55,7 +56,7 @@ export declare function drawSprite(ctx: CanvasRenderingContext2D, sprite: Uint8A
|
|
|
55
56
|
* drawChar(ctx, 127, x, y, C.B_GREEN, C.BLACK) // solid block █
|
|
56
57
|
* drawChar(ctx, 'A'.charCodeAt(0), x, y, C.B_WHITE) // transparent bg
|
|
57
58
|
*/
|
|
58
|
-
export declare function drawChar(ctx: CanvasRenderingContext2D, code: number, x: number, y: number, ink:
|
|
59
|
+
export declare function drawChar(ctx: CanvasRenderingContext2D, code: number, x: number, y: number, ink: SpectrumColor, paper?: SpectrumColor): void;
|
|
59
60
|
/**
|
|
60
61
|
* Draws a string left-to-right starting at game coordinates `(x, y)`.
|
|
61
62
|
* Each character occupies one `CELL`-wide slot.
|
|
@@ -70,7 +71,7 @@ export declare function drawChar(ctx: CanvasRenderingContext2D, code: number, x:
|
|
|
70
71
|
* @example
|
|
71
72
|
* drawText(ctx, 'SCORE:00000', 0, statusY, C.B_WHITE, C.BLACK)
|
|
72
73
|
*/
|
|
73
|
-
export declare function drawText(ctx: CanvasRenderingContext2D, text: string, x: number, y: number, ink:
|
|
74
|
+
export declare function drawText(ctx: CanvasRenderingContext2D, text: string, x: number, y: number, ink: SpectrumColor, paper?: SpectrumColor): void;
|
|
74
75
|
/**
|
|
75
76
|
* Draws a string centered horizontally within a canvas of `cols` character columns.
|
|
76
77
|
*
|
|
@@ -83,18 +84,18 @@ export declare function drawText(ctx: CanvasRenderingContext2D, text: string, x:
|
|
|
83
84
|
*
|
|
84
85
|
* @example
|
|
85
86
|
* // Bind cols once to avoid passing it every time:
|
|
86
|
-
* const centered = (ctx: CanvasRenderingContext2D, text: string, y: number, ink:
|
|
87
|
+
* const centered = (ctx: CanvasRenderingContext2D, text: string, y: number, ink: SpectrumColor) =>
|
|
87
88
|
* drawTextCentered(ctx, text, y, COLS, ink)
|
|
88
89
|
* centered(ctx, 'GAME OVER', y, C.B_RED)
|
|
89
90
|
*/
|
|
90
|
-
export declare function drawTextCentered(ctx: CanvasRenderingContext2D, text: string, y: number, cols: number, ink:
|
|
91
|
+
export declare function drawTextCentered(ctx: CanvasRenderingContext2D, text: string, y: number, cols: number, ink: SpectrumColor, paper?: SpectrumColor): void;
|
|
91
92
|
/**
|
|
92
93
|
* Flashes `document.body.style.backgroundColor` between `color` and `resetColor`.
|
|
93
94
|
* Fire-and-forget — does not block. Uses `setInterval` internally.
|
|
94
95
|
* One "flash" = one `color → resetColor` cycle; total steps = `times * 2`.
|
|
95
96
|
* Always resets to `resetColor` on completion.
|
|
96
97
|
*
|
|
97
|
-
* @param color - Flash color (`C.*` palette value
|
|
98
|
+
* @param color - Flash color (`C.*` palette value)
|
|
98
99
|
* @param times - Number of flashes
|
|
99
100
|
* @param intervalMs - Duration of each half-cycle in milliseconds
|
|
100
101
|
* @param resetColor - Final color after flashing (default `C.BLACK`)
|
|
@@ -104,5 +105,5 @@ export declare function drawTextCentered(ctx: CanvasRenderingContext2D, text: st
|
|
|
104
105
|
* flashBorder(C.B_GREEN, 2, 200) // level complete
|
|
105
106
|
* flashBorder(C.B_CYAN, 2, 120, C.BLUE) // flash → reset to blue border
|
|
106
107
|
*/
|
|
107
|
-
export declare function flashBorder(color:
|
|
108
|
+
export declare function flashBorder(color: SpectrumColor, times: number, intervalMs: number, resetColor?: SpectrumColor): void;
|
|
108
109
|
//# sourceMappingURL=renderer.d.ts.map
|
package/dist/renderer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,aAAa,EAAE,MAAM,cAAc,CAAA;AAiB1D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,iBAAiB,EACzB,KAAK,EAAE,MAAM,EACb,KAAK,SAAM,EACX,MAAM,SAAM,GACX,wBAAwB,CAS1B;AAED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ind cols once to avoid passing it every time:
|
|
133
|
-
* const centered = (ctx: CanvasRenderingContext2D, text: string, y: number, ink:
|
|
133
|
+
* const centered = (ctx: CanvasRenderingContext2D, text: string, y: number, ink: SpectrumColor) =>
|
|
134
134
|
* drawTextCentered(ctx, text, y, COLS, ink)
|
|
135
135
|
* centered(ctx, 'GAME OVER', y, C.B_RED)
|
|
136
136
|
*/
|
|
@@ -144,7 +144,7 @@ export function drawTextCentered(ctx, text, y, cols, ink, paper) {
|
|
|
144
144
|
* One "flash" = one `color → resetColor` cycle; total steps = `times * 2`.
|
|
145
145
|
* Always resets to `resetColor` on completion.
|
|
146
146
|
*
|
|
147
|
-
* @param color - Flash color (`C.*` palette value
|
|
147
|
+
* @param color - Flash color (`C.*` palette value)
|
|
148
148
|
* @param times - Number of flashes
|
|
149
149
|
* @param intervalMs - Duration of each half-cycle in milliseconds
|
|
150
150
|
* @param resetColor - Final color after flashing (default `C.BLACK`)
|
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,
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,IAAI,EAAsB,MAAM,cAAc,CAAA;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,SAAS,UAAU,CACjB,GAA6B,EAC7B,OAAgC,EAChC,CAAS,EACT,CAAS;IAET,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;QACzB,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC;YACjC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AC,CAAA;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zx-kit",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Reusable ZX Spectrum primitives: font, palette, renderer, audio, input, ui, tilemap",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -33,4 +33,4 @@
|
|
|
33
33
|
"typescript": "^6.0.3",
|
|
34
34
|
"vitest": "^4.1.5"
|
|
35
35
|
}
|
|
36
|
-
}
|
|
36
|
+
}
|