textmode.js 0.2.1-beta.1 → 0.2.1-beta.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.
Files changed (36) hide show
  1. package/dist/textmode.esm.js +1470 -1442
  2. package/dist/textmode.esm.min.js +1356 -1328
  3. package/dist/textmode.umd.js +10 -26
  4. package/dist/textmode.umd.min.js +9 -25
  5. package/dist/types/assets/shaders-minified/frag/ascii.d.ts +14 -0
  6. package/dist/types/assets/shaders-minified/frag/copy-mrt.d.ts +14 -0
  7. package/dist/types/assets/shaders-minified/frag/instanced-ascii-mrt.d.ts +14 -0
  8. package/dist/types/assets/shaders-minified/index.d.ts +5 -0
  9. package/dist/types/assets/shaders-minified/vert/instanced-ascii-mrt.d.ts +14 -0
  10. package/dist/types/assets/shaders-minified/vert/shader.d.ts +14 -0
  11. package/dist/types/export/svg/SVGContentGenerator.d.ts +0 -6
  12. package/dist/types/index.d.ts +2 -0
  13. package/dist/types/rendering/index.d.ts +2 -0
  14. package/dist/types/rendering/webgl/Framebuffer.d.ts +31 -20
  15. package/dist/types/rendering/webgl/InstanceData.d.ts +1 -1
  16. package/dist/types/rendering/webgl/RenderPipeline.d.ts +10 -3
  17. package/dist/types/rendering/webgl/RenderState.d.ts +11 -11
  18. package/dist/types/rendering/webgl/Renderer.d.ts +26 -2
  19. package/dist/types/rendering/webgl/Shader.d.ts +7 -8
  20. package/dist/types/rendering/webgl/ShaderManager.d.ts +65 -1
  21. package/dist/types/rendering/webgl/index.d.ts +1 -0
  22. package/dist/types/rendering/webgl/types/GeometryTypes.d.ts +7 -7
  23. package/dist/types/rendering/webgl/types/ShaderTypes.d.ts +35 -0
  24. package/dist/types/textmode/Textmodifier.d.ts +2 -2
  25. package/dist/types/textmode/managers/index.d.ts +4 -0
  26. package/dist/types/textmode/mixins/AnimationMixin.d.ts +0 -4
  27. package/dist/types/textmode/mixins/KeyboardMixin.d.ts +75 -19
  28. package/dist/types/textmode/mixins/MouseMixin.d.ts +101 -8
  29. package/dist/types/textmode/mixins/RenderingMixin.d.ts +92 -0
  30. package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +2 -2
  31. package/dist/types/textmode/mixins/index.d.ts +2 -2
  32. package/package.json +4 -3
  33. package/dist/types/textmode/keyboard/index.d.ts +0 -2
  34. package/dist/types/textmode/mouse/index.d.ts +0 -2
  35. /package/dist/types/textmode/{keyboard → managers}/KeyboardManager.d.ts +0 -0
  36. /package/dist/types/textmode/{mouse → managers}/MouseManager.d.ts +0 -0
@@ -1,21 +1,114 @@
1
1
  import type { Mixin } from './TextmodifierMixin';
2
- import type { MousePosition, MouseEventHandler } from '../mouse';
2
+ import type { MousePosition, MouseEventHandler } from '../managers';
3
3
  /**
4
4
  * Capabilities provided by the MouseMixin
5
5
  */
6
6
  export interface MouseCapabilities {
7
- /** Get the current mouse position in grid coordinates */
8
- readonly mouse: MousePosition;
9
- /** Set a callback for when the mouse is clicked */
7
+ /**
8
+ * Set a callback function that will be called when the mouse is clicked.
9
+ *
10
+ * @param callback The function to call when the mouse is clicked
11
+ *
12
+ * @example
13
+ * ```javascript
14
+ * const t = textmode.create({ width: 800, height: 600 });
15
+ *
16
+ * t.mouseClicked((data) => {
17
+ * console.log(`Clicked at grid position: ${data.position.x}, ${data.position.y}`);
18
+ * console.log(`Button: ${data.button}`); // 0=left, 1=middle, 2=right
19
+ * });
20
+ * ```
21
+ */
10
22
  mouseClicked(callback: MouseEventHandler): void;
11
- /** Set a callback for when the mouse is pressed down */
23
+ /**
24
+ * Set a callback function that will be called when the mouse is pressed down.
25
+ *
26
+ * @param callback The function to call when the mouse is pressed
27
+ *
28
+ * @example
29
+ * ```javascript
30
+ * const t = textmode.create({ width: 800, height: 600 });
31
+ *
32
+ * t.mousePressed((data) => {
33
+ * console.log(`Mouse pressed at: ${data.position.x}, ${data.position.y}`);
34
+ * });
35
+ * ```
36
+ */
12
37
  mousePressed(callback: MouseEventHandler): void;
13
- /** Set a callback for when the mouse is released */
38
+ /**
39
+ * Set a callback function that will be called when the mouse is released.
40
+ *
41
+ * @param callback The function to call when the mouse is released
42
+ *
43
+ * @example
44
+ * ```javascript
45
+ * const t = textmode.create({ width: 800, height: 600 });
46
+ *
47
+ * t.mouseReleased((data) => {
48
+ * console.log(`Mouse released at: ${data.position.x}, ${data.position.y}`);
49
+ * });
50
+ * ```
51
+ */
14
52
  mouseReleased(callback: MouseEventHandler): void;
15
- /** Set a callback for when the mouse moves */
53
+ /**
54
+ * Set a callback function that will be called when the mouse moves.
55
+ *
56
+ * @param callback The function to call when the mouse moves
57
+ *
58
+ * @example
59
+ * ```javascript
60
+ * const t = textmode.create({ width: 800, height: 600 });
61
+ *
62
+ * t.mouseMoved((data) => {
63
+ * if (data.position.x !== -1 && data.position.y !== -1) {
64
+ * console.log(`Mouse moved to: ${data.position.x}, ${data.position.y}`);
65
+ * console.log(`Previous position: ${data.previousPosition.x}, ${data.previousPosition.y}`);
66
+ * }
67
+ * });
68
+ * ```
69
+ */
16
70
  mouseMoved(callback: MouseEventHandler): void;
17
- /** Set a callback for when the mouse wheel is scrolled */
71
+ /**
72
+ * Set a callback function that will be called when the mouse wheel is scrolled.
73
+ *
74
+ * @param callback The function to call when the mouse wheel is scrolled
75
+ *
76
+ * @example
77
+ * ```javascript
78
+ * const t = textmode.create({ width: 800, height: 600 });
79
+ *
80
+ * t.mouseScrolled((data) => {
81
+ * console.log(`Mouse scrolled at: ${data.position.x}, ${data.position.y}`);
82
+ * console.log(`Scroll delta: ${data.delta?.x}, ${data.delta?.y}`);
83
+ * });
84
+ * ```
85
+ */
18
86
  mouseScrolled(callback: MouseEventHandler): void;
87
+ /**
88
+ * Get the current mouse position in grid coordinates.
89
+ *
90
+ * Returns the mouse position as grid cell coordinates *(column, row)*.
91
+ *
92
+ * If the mouse is outside the grid or the instance is not ready,
93
+ * it returns `{ x: -1, y: -1 }`.
94
+ *
95
+ * @example
96
+ * ```javascript
97
+ * const t = textmode.create({ width: 800, height: 600 });
98
+ *
99
+ * t.draw(() => {
100
+ * const mousePos = t.mouse;
101
+ *
102
+ * if (mousePos.x !== -1 && mousePos.y !== -1) {
103
+ * // Mouse is over the grid
104
+ * t.char('*');
105
+ * t.charColor(255, 0, 0);
106
+ * t.point(mousePos.x, mousePos.y);
107
+ * }
108
+ * });
109
+ * ```
110
+ */
111
+ get mouse(): MousePosition;
19
112
  }
20
113
  /**
21
114
  * Mixin that adds mouse tracking capabilities to Textmodifier.
@@ -1,5 +1,15 @@
1
1
  import type { Mixin } from './TextmodifierMixin';
2
2
  import type { GLShader } from '../../rendering/webgl/Shader';
3
+ import type { GLFramebuffer } from '../../rendering';
4
+ /**
5
+ * Options for creating a framebuffer.
6
+ */
7
+ export type TextmodeFramebufferOptions = {
8
+ /** Width of the framebuffer in grid cells */
9
+ width: number;
10
+ /** Height of the framebuffer in grid cells */
11
+ height: number;
12
+ };
3
13
  /**
4
14
  * Supported uniform value types for shader parameters
5
15
  */
@@ -39,6 +49,86 @@ export interface RenderingCapabilities {
39
49
  * ```
40
50
  */
41
51
  shader(shader: GLShader): void;
52
+ /**
53
+ * Create a new framebuffer for offscreen rendering.
54
+ *
55
+ * The framebuffer uses the same 5-attachment MRT structure as the main
56
+ * rendering pipeline, allowing all standard drawing operations to work
57
+ * seamlessly when rendering to the framebuffer.
58
+ *
59
+ * @param options Configuration options for the framebuffer.
60
+ * @returns A new Framebuffer instance.
61
+ *
62
+ * @example
63
+ * ```javascript
64
+ * const t = textmode.create({
65
+ * width: 800,
66
+ * height: 600,
67
+ * });
68
+ *
69
+ * // Create a framebuffer with 50x30 grid cells
70
+ * const fb = t.createFramebuffer({
71
+ * width: 50,
72
+ * height: 30
73
+ * });
74
+ *
75
+ * t.draw(() => {
76
+ * // Render to framebuffer
77
+ * fb.begin();
78
+ * t.background(255, 0, 0);
79
+ * t.charColor(255);
80
+ * t.rect(10, 10, 20, 10);
81
+ * fb.end();
82
+ *
83
+ * // Render framebuffer to main canvas
84
+ * t.background(0);
85
+ * t.image(fb, 0, 0);
86
+ * });
87
+ * ```
88
+ */
89
+ createFramebuffer(options: TextmodeFramebufferOptions): GLFramebuffer;
90
+ /**
91
+ * Render a framebuffer to the current render target.
92
+ *
93
+ * This method takes the 5 MRT attachments from the source framebuffer
94
+ * and renders them at the specified position.
95
+ * The framebuffer content will be processed through the same rendering
96
+ * pipeline as normal drawing operations.
97
+ *
98
+ * @param framebuffer The framebuffer to render
99
+ * @param x X position on the grid where to place the framebuffer content *(top-left corner)*
100
+ * @param y Y position on the grid where to place the framebuffer content *(top-left corner)*
101
+ * @param width Optional width to scale the framebuffer content *(defaults to framebuffer width)*
102
+ * @param height Optional height to scale the framebuffer content *(defaults to framebuffer height)*
103
+ *
104
+ * @example
105
+ * ```javascript
106
+ * const t = textmode.create({
107
+ * width: 800,
108
+ * height: 600,
109
+ * });
110
+ *
111
+ * const fb = t.createFramebuffer({width: 30, height: 20});
112
+ *
113
+ * t.draw(() => {
114
+ * // Draw something to the framebuffer
115
+ * fb.begin();
116
+ * t.charColor(255, 0, 0);
117
+ * t.rect(5, 5, 20, 10);
118
+ * fb.end();
119
+ *
120
+ * // Clear main canvas and render framebuffer content
121
+ * t.background(0);
122
+ *
123
+ * // Render at original size
124
+ * t.image(fb, 10, 10);
125
+ *
126
+ * // Render scaled version
127
+ * t.image(fb, 50, 10, 60, 40);
128
+ * });
129
+ * ```
130
+ */
131
+ image(framebuffer: GLFramebuffer, x: number, y: number, width?: number, height?: number): void;
42
132
  /**
43
133
  * Set a uniform value for the current custom shader.
44
134
  * @param name The name of the uniform variable
@@ -318,6 +408,8 @@ export interface RenderingCapabilities {
318
408
  *
319
409
  * t.draw(() => {
320
410
  * t.background(0);
411
+ *
412
+ * t.char('*');
321
413
  * t.point(10, 10);
322
414
  * });
323
415
  * ```
@@ -7,8 +7,8 @@ import type { TextmodeCanvas } from '../Canvas';
7
7
  import type { TextmodeGrid } from '../Grid';
8
8
  import type { AnimationController } from '../AnimationController';
9
9
  import type { GLFramebuffer, Shader } from '../../rendering';
10
- import type { MouseManager } from '../mouse';
11
- import type { KeyboardManager } from '../keyboard';
10
+ import type { MouseManager } from '../managers';
11
+ import type { KeyboardManager } from '../managers';
12
12
  /**
13
13
  * Constructor type for mixin pattern
14
14
  */
@@ -5,5 +5,5 @@ export { FontMixin, type FontCapabilities } from './FontMixin';
5
5
  export { AnimationMixin, type AnimationCapabilities } from './AnimationMixin';
6
6
  export { MouseMixin, type MouseCapabilities } from './MouseMixin';
7
7
  export { KeyboardMixin, type KeyboardCapabilities } from './KeyboardMixin';
8
- export type { MousePosition, MouseEventData, MouseEventHandler } from '../mouse';
9
- export type { KeyboardEventData, KeyboardEventHandler, KeyState } from '../keyboard';
8
+ export type { MousePosition, MouseEventData, MouseEventHandler } from '../managers';
9
+ export type { KeyboardEventData, KeyboardEventHandler, KeyState } from '../managers';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "textmode.js",
3
- "version": "0.2.1-beta.1",
3
+ "version": "0.2.1-beta.3",
4
4
  "description": "textmode.js is a lightweight creative coding library for creating real-time ASCII art on the web.",
5
5
  "type": "module",
6
6
  "types": "./dist/types/index.d.ts",
@@ -32,6 +32,7 @@
32
32
  "test:coverage": "vitest --coverage"
33
33
  },
34
34
  "devDependencies": {
35
+ "@mapwhit/glsl-minify": "^1.0.0",
35
36
  "@rollup/plugin-terser": "^0.4.4",
36
37
  "@types/jsdom": "^21.1.7",
37
38
  "@types/node": "^24.0.13",
@@ -39,9 +40,9 @@
39
40
  "jsdom": "^26.1.0",
40
41
  "terser": "^5.43.1",
41
42
  "tslib": "^2.8.1",
42
- "typedoc": "^0.28.7",
43
+ "typedoc": "^0.28.13",
43
44
  "typedoc-plugin-markdown": "^4.7.0",
44
- "typescript": "^5.8.3",
45
+ "typescript": "^5.9.2",
45
46
  "vite": "^6.3.4",
46
47
  "vite-plugin-glsl": "^1.5.1",
47
48
  "vitest": "^3.1.2"
@@ -1,2 +0,0 @@
1
- export { KeyboardManager } from './KeyboardManager';
2
- export type { KeyboardEventData, KeyboardEventHandler, KeyState } from './KeyboardManager';
@@ -1,2 +0,0 @@
1
- export { MouseManager } from './MouseManager';
2
- export type { MousePosition, MouseEventData, MouseEventHandler } from './MouseManager';