tidepool 1.0.0 → 1.0.1

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.
@@ -1,5 +1,5 @@
1
- import { Box } from "./objects/box";
2
- import { Text } from "./objects/text";
3
- import { TideScreen } from "./screen";
4
-
5
- export { Box, Text, TideScreen };
1
+ import { Box } from "./objects/box";
2
+ import { Text } from "./objects/text";
3
+ import { TideScreen } from "./screen";
4
+ export { Box, Text, TideScreen };
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC"}
@@ -1,4 +1,5 @@
1
- export interface TideObject {
2
- zIndex: number;
3
- draw: Function;
4
- }
1
+ export interface TideObject {
2
+ zIndex: number;
3
+ draw: Function;
4
+ }
5
+ //# sourceMappingURL=interfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,CAAC;CAClB"}
@@ -0,0 +1,17 @@
1
+ import { TideObject } from "../interfaces";
2
+ export declare class Box implements TideObject {
3
+ x: number;
4
+ y: number;
5
+ width: number;
6
+ height: number;
7
+ color: string;
8
+ title: string;
9
+ contents: TideObject[];
10
+ zIndex: number;
11
+ constructor(x: number, y: number, width: number, height: number, color?: string, title?: string, zIndex?: number);
12
+ addContent(content: TideObject): void;
13
+ clear(screen: string[][]): void;
14
+ draw(screen: string[][]): void;
15
+ move(dx: number, dy: number): void;
16
+ }
17
+ //# sourceMappingURL=box.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../../src/objects/box.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,qBAAa,GAAI,YAAW,UAAU;IAClC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;gBAEH,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,SAAU,EAAE,KAAK,SAAK,EAAE,MAAM,SAAI;IAWxG,UAAU,CAAC,OAAO,EAAE,UAAU;IAI9B,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;IAQxB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;IAoCvB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;CAI5B"}
@@ -0,0 +1,11 @@
1
+ import { TideObject } from "../interfaces";
2
+ export declare class Text implements TideObject {
3
+ relativeX: number;
4
+ relativeY: number;
5
+ text: string;
6
+ color: string;
7
+ zIndex: number;
8
+ constructor(x: number, y: number, text: string, color?: string, zIndex?: number);
9
+ draw(screen: string[][], boxX: number, boxY: number, boxWidth: number): void;
10
+ }
11
+ //# sourceMappingURL=text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/objects/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,qBAAa,IAAK,YAAW,UAAU;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;gBAEH,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,SAAU,EAAE,MAAM,SAAI;IAQ3E,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAetE"}
@@ -0,0 +1,20 @@
1
+ import { TideObject } from "./interfaces";
2
+ export declare class TideScreen {
3
+ width: number;
4
+ height: number;
5
+ screen: string[][];
6
+ buffer: string[][];
7
+ components: TideObject[];
8
+ fps: number | null;
9
+ updateFunction: (() => void) | null;
10
+ constructor(width: number, height: number);
11
+ clearScreen(): void;
12
+ clearBuffer(): void;
13
+ addComponent(component: TideObject): void;
14
+ renderBuffer(): void;
15
+ render(): void;
16
+ setUpdateFunction(fn: () => void): void;
17
+ setFPS(fps: number): void;
18
+ renderCycle(): void;
19
+ }
20
+ //# sourceMappingURL=screen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screen.d.ts","sourceRoot":"","sources":["../src/screen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,UAAU;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;IACnB,UAAU,EAAE,UAAU,EAAE,CAAC;IACzB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC1B,cAAc,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAQ;gBAE/B,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAQzC,WAAW;IAIX,WAAW;IAIX,YAAY,CAAC,SAAS,EAAE,UAAU;IAIlC,YAAY;IAMZ,MAAM;IAMN,iBAAiB,CAAC,EAAE,EAAE,MAAM,IAAI;IAIhC,MAAM,CAAC,GAAG,EAAE,MAAM;IAIlB,WAAW;CAkBd"}
package/dist/util.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare function getColorCode(color: string): string;
2
+ export declare function wrapText(text: string, maxWidth: number): string[];
3
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,UAczC;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,YAetD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tidepool",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "author": "stuncs69",
5
5
  "main": "dist/index.js",
6
6
  "devDependencies": {
package/bun.lockb DELETED
Binary file
@@ -1,78 +0,0 @@
1
- import { TideObject } from "../interfaces";
2
- import { getColorCode } from "../util";
3
-
4
- export class Box implements TideObject {
5
- x: number;
6
- y: number;
7
- width: number;
8
- height: number;
9
- color: string;
10
- title: string;
11
- contents: TideObject[];
12
- zIndex: number;
13
-
14
- constructor(x: number, y: number, width: number, height: number, color = 'reset', title = '', zIndex = 0) {
15
- this.x = x;
16
- this.y = y;
17
- this.width = width;
18
- this.height = height;
19
- this.color = color;
20
- this.title = title;
21
- this.contents = [];
22
- this.zIndex = zIndex;
23
- }
24
-
25
- addContent(content: TideObject) {
26
- this.contents.push(content);
27
- }
28
-
29
- clear(screen: string[][]) {
30
- for (let i = this.y; i < this.y + this.height; i++) {
31
- for (let j = this.x; j < this.x + this.width; j++) {
32
- screen[i][j] = ' ';
33
- }
34
- }
35
- }
36
-
37
- draw(screen: string[][]) {
38
- this.clear(screen);
39
-
40
- const colorCode = getColorCode(this.color);
41
- const titleColorCode = getColorCode('magenta');
42
-
43
- for (let i = this.x + 1; i < this.x + this.width - 1; i++) {
44
- screen[this.y][i] = `${colorCode}─\x1b[0m`;
45
- }
46
- for (let i = this.x + 1; i < this.x + this.width - 1; i++) {
47
- screen[this.y + this.height - 1][i] = `${colorCode}─\x1b[0m`;
48
- }
49
- for (let i = this.y + 1; i < this.y + this.height - 1; i++) {
50
- screen[i][this.x] = `${colorCode}│\x1b[0m`;
51
- screen[i][this.x + this.width - 1] = `${colorCode}│\x1b[0m`;
52
- }
53
-
54
- screen[this.y][this.x] = `${colorCode}┌\x1b[0m`;
55
- screen[this.y][this.x + this.width - 1] = `${colorCode}┐\x1b[0m`;
56
- screen[this.y + this.height - 1][this.x] = `${colorCode}└\x1b[0m`;
57
- screen[this.y + this.height - 1][this.x + this.width - 1] = `${colorCode}┘\x1b[0m`;
58
-
59
- if (this.title) {
60
- const titlePosition = Math.max(this.x + 2, Math.min(this.x + this.width - 2 - this.title.length, this.x + 2));
61
- for (let i = 0; i < this.title.length; i++) {
62
- if (titlePosition + i < screen[0].length && this.y < screen.length) {
63
- screen[this.y][titlePosition + i] = `${titleColorCode}${this.title[i]}\x1b[0m`;
64
- }
65
- }
66
- }
67
-
68
- for (let content of this.contents) {
69
- content.draw(screen, this.x + 1, this.y + 1, this.width - 2);
70
- }
71
- }
72
-
73
- move(dx: number, dy: number) {
74
- this.x += dx;
75
- this.y += dy;
76
- }
77
- }
78
-
@@ -1,34 +0,0 @@
1
- import { TideObject } from "../interfaces";
2
- import { getColorCode, wrapText } from "../util";
3
-
4
- export class Text implements TideObject {
5
- relativeX: number;
6
- relativeY: number;
7
- text: string;
8
- color: string;
9
- zIndex: number;
10
-
11
- constructor(x: number, y: number, text: string, color = 'reset', zIndex = 0) {
12
- this.relativeX = x;
13
- this.relativeY = y;
14
- this.text = text;
15
- this.color = color;
16
- this.zIndex = zIndex;
17
- }
18
-
19
- draw(screen: string[][], boxX: number, boxY: number, boxWidth: number) {
20
- const colorCode = getColorCode(this.color);
21
- const lines = wrapText(this.text, boxWidth);
22
-
23
- for (let i = 0; i < lines.length; i++) {
24
- const line = lines[i];
25
- for (let j = 0; j < line.length; j++) {
26
- const screenX = boxX + this.relativeX + j;
27
- const screenY = boxY + this.relativeY + i;
28
- if (screenX < screen[0].length && screenY < screen.length) {
29
- screen[screenY][screenX] = `${colorCode}${line[j]}\x1b[0m`;
30
- }
31
- }
32
- }
33
- }
34
- }
package/src/screen.ts DELETED
@@ -1,70 +0,0 @@
1
- import { TideObject } from "./interfaces";
2
-
3
- export class TideScreen {
4
- width: number;
5
- height: number;
6
- screen: string[][];
7
- buffer: string[][];
8
- components: TideObject[];
9
- fps: number | null = null;
10
- updateFunction: (() => void) | null = null;
11
-
12
- constructor(width: number, height: number) {
13
- this.width = width;
14
- this.height = height;
15
- this.screen = Array.from({ length: height }, () => Array(width).fill(' '));
16
- this.buffer = Array.from({ length: height }, () => Array(width).fill(' '));
17
- this.components = [];
18
- }
19
-
20
- clearScreen() {
21
- this.screen = Array.from({ length: this.height }, () => Array(this.width).fill(' '));
22
- }
23
-
24
- clearBuffer() {
25
- this.buffer = Array.from({ length: this.height }, () => Array(this.width).fill(' '));
26
- }
27
-
28
- addComponent(component: TideObject) {
29
- this.components.push(component);
30
- }
31
-
32
- renderBuffer() {
33
- this.clearBuffer();
34
- this.components.sort((a, b) => b.zIndex - a.zIndex);
35
- this.components.forEach(component => component.draw(this.buffer));
36
- }
37
-
38
- render() {
39
- console.clear();
40
- const output = this.buffer.map(row => row.join('')).join('\n');
41
- console.log(output);
42
- }
43
-
44
- setUpdateFunction(fn: () => void) {
45
- this.updateFunction = fn;
46
- }
47
-
48
- setFPS(fps: number) {
49
- this.fps = fps;
50
- }
51
-
52
- renderCycle() {
53
- if (this.fps === null) {
54
- throw new Error("FPS must be set before starting the render cycle.");
55
- }
56
-
57
- const interval = 1000 / this.fps;
58
-
59
- const loop = () => {
60
- if (this.updateFunction) {
61
- this.updateFunction();
62
- }
63
- this.renderBuffer(); // Prepare the buffer with updated content
64
- this.render(); // Output the buffer to the screen
65
- setTimeout(loop, interval);
66
- };
67
-
68
- loop();
69
- }
70
- }
package/src/util.ts DELETED
@@ -1,32 +0,0 @@
1
- export function getColorCode(color: string) {
2
- const colors: { [key: string]: string } = {
3
- reset: '\x1b[0m',
4
- black: '\x1b[30m',
5
- red: '\x1b[31m',
6
- green: '\x1b[32m',
7
- yellow: '\x1b[33m',
8
- blue: '\x1b[34m',
9
- magenta: '\x1b[35m',
10
- cyan: '\x1b[36m',
11
- white: '\x1b[37m',
12
- };
13
-
14
- return colors[color.toLowerCase()] || colors['reset'];
15
- }
16
-
17
- export function wrapText(text: string, maxWidth: number) {
18
- const lines = [];
19
- let currentLine = '';
20
-
21
- for (const word of text.split(' ')) {
22
- if ((currentLine + word).length > maxWidth) {
23
- lines.push(currentLine.trim());
24
- currentLine = word + ' ';
25
- } else {
26
- currentLine += word + ' ';
27
- }
28
- }
29
- lines.push(currentLine.trim());
30
-
31
- return lines;
32
- }