textmode.js 0.2.0 → 0.2.1-beta.2

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 (33) hide show
  1. package/dist/textmode.esm.js +1566 -1294
  2. package/dist/textmode.esm.min.js +1662 -1390
  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 +8 -8
  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 +6 -7
  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 +8 -2
  25. package/dist/types/textmode/managers/KeyboardManager.d.ts +123 -0
  26. package/dist/types/textmode/managers/MouseManager.d.ts +130 -0
  27. package/dist/types/textmode/managers/index.d.ts +4 -0
  28. package/dist/types/textmode/mixins/KeyboardMixin.d.ts +39 -0
  29. package/dist/types/textmode/mixins/MouseMixin.d.ts +27 -0
  30. package/dist/types/textmode/mixins/RenderingMixin.d.ts +104 -0
  31. package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +6 -0
  32. package/dist/types/textmode/mixins/index.d.ts +4 -0
  33. package/package.json +3 -2
@@ -0,0 +1,27 @@
1
+ import type { Mixin } from './TextmodifierMixin';
2
+ import type { MousePosition, MouseEventHandler } from '../managers';
3
+ /**
4
+ * Capabilities provided by the MouseMixin
5
+ */
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 */
10
+ mouseClicked(callback: MouseEventHandler): void;
11
+ /** Set a callback for when the mouse is pressed down */
12
+ mousePressed(callback: MouseEventHandler): void;
13
+ /** Set a callback for when the mouse is released */
14
+ mouseReleased(callback: MouseEventHandler): void;
15
+ /** Set a callback for when the mouse moves */
16
+ mouseMoved(callback: MouseEventHandler): void;
17
+ /** Set a callback for when the mouse wheel is scrolled */
18
+ mouseScrolled(callback: MouseEventHandler): void;
19
+ }
20
+ /**
21
+ * Mixin that adds mouse tracking capabilities to Textmodifier.
22
+ *
23
+ * This is a thin wrapper around MouseManager that provides the public API
24
+ * for mouse interaction. All the actual implementation is handled by the
25
+ * MouseManager instance in the TextmodifierContext.
26
+ */
27
+ export declare const MouseMixin: Mixin<MouseCapabilities>;
@@ -1,5 +1,10 @@
1
1
  import type { Mixin } from './TextmodifierMixin';
2
2
  import type { GLShader } from '../../rendering/webgl/Shader';
3
+ import type { GLFramebuffer } from '../../rendering';
4
+ export interface UserFramebufferOptions {
5
+ width: number;
6
+ height: number;
7
+ }
3
8
  /**
4
9
  * Supported uniform value types for shader parameters
5
10
  */
@@ -39,6 +44,86 @@ export interface RenderingCapabilities {
39
44
  * ```
40
45
  */
41
46
  shader(shader: GLShader): void;
47
+ /**
48
+ * Create a new framebuffer for offscreen rendering.
49
+ *
50
+ * The framebuffer uses the same 5-attachment MRT structure as the main
51
+ * rendering pipeline, allowing all standard drawing operations to work
52
+ * seamlessly when rendering to the framebuffer.
53
+ *
54
+ * @param options Configuration options for the framebuffer
55
+ * @returns A new UserFramebuffer instance
56
+ *
57
+ * @example
58
+ * ```javascript
59
+ * const t = textmode.create({
60
+ * width: 800,
61
+ * height: 600,
62
+ * });
63
+ *
64
+ * // Create a framebuffer with 50x30 grid cells
65
+ * const fb = t.createFramebuffer({
66
+ * width: 50,
67
+ * height: 30
68
+ * });
69
+ *
70
+ * t.draw(() => {
71
+ * // Render to framebuffer
72
+ * fb.begin();
73
+ * t.background(255, 0, 0);
74
+ * t.charColor(255);
75
+ * t.rect(10, 10, 20, 10);
76
+ * fb.end();
77
+ *
78
+ * // Render framebuffer to main canvas
79
+ * t.background(0);
80
+ * t.image(fb, 0, 0);
81
+ * });
82
+ * ```
83
+ */
84
+ createFramebuffer(options: UserFramebufferOptions): GLFramebuffer;
85
+ /**
86
+ * Render a framebuffer to the current render target.
87
+ *
88
+ * This method takes the 5 MRT attachments from the source framebuffer
89
+ * and renders them as a textmode rectangle at the specified position.
90
+ * The framebuffer content will be processed through the same rendering
91
+ * pipeline as normal drawing operations.
92
+ *
93
+ * @param framebuffer The framebuffer to render
94
+ * @param x X position on the grid where to place the framebuffer content
95
+ * @param y Y position on the grid where to place the framebuffer content
96
+ * @param width Optional width to scale the framebuffer content (defaults to framebuffer width)
97
+ * @param height Optional height to scale the framebuffer content (defaults to framebuffer height)
98
+ *
99
+ * @example
100
+ * ```javascript
101
+ * const t = textmode.create({
102
+ * width: 800,
103
+ * height: 600,
104
+ * });
105
+ *
106
+ * const fb = t.createFramebuffer({width: 30, height: 20});
107
+ *
108
+ * t.draw(() => {
109
+ * // Draw something to the framebuffer
110
+ * fb.begin();
111
+ * t.charColor(255, 0, 0);
112
+ * t.rect(5, 5, 20, 10);
113
+ * fb.end();
114
+ *
115
+ * // Clear main canvas and render framebuffer content
116
+ * t.background(0);
117
+ *
118
+ * // Render at original size
119
+ * t.image(fb, 10, 10);
120
+ *
121
+ * // Render scaled version
122
+ * t.image(fb, 50, 10, 60, 40);
123
+ * });
124
+ * ```
125
+ */
126
+ image(framebuffer: GLFramebuffer, x: number, y: number, width?: number, height?: number): void;
42
127
  /**
43
128
  * Set a uniform value for the current custom shader.
44
129
  * @param name The name of the uniform variable
@@ -304,6 +389,25 @@ export interface RenderingCapabilities {
304
389
  * ```
305
390
  */
306
391
  rect(x: number, y: number, width?: number, height?: number): void;
392
+ /**
393
+ * Draw a single point at (x, y) with the current settings.
394
+ * @param x X-coordinate of the point
395
+ * @param y Y-coordinate of the point
396
+ *
397
+ * @example
398
+ * ```javascript
399
+ * const t = textmode.create({
400
+ * width: 800,
401
+ * height: 600,
402
+ * })
403
+ *
404
+ * t.draw(() => {
405
+ * t.background(0);
406
+ * t.point(10, 10);
407
+ * });
408
+ * ```
409
+ */
410
+ point(x: number, y: number): void;
307
411
  /**
308
412
  * Draw a line from point (x1, y1) to point (x2, y2) with the settings.
309
413
  * @param x1 X-coordinate of the line start point
@@ -7,6 +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 '../managers';
11
+ import type { KeyboardManager } from '../managers';
10
12
  /**
11
13
  * Constructor type for mixin pattern
12
14
  */
@@ -30,6 +32,10 @@ export interface TextmodifierContext {
30
32
  readonly _grid: TextmodeGrid;
31
33
  /** Animation controller for managing rendering loop @ignore */
32
34
  readonly _animationController: AnimationController;
35
+ /** Mouse interaction manager @ignore */
36
+ readonly _mouseManager: MouseManager;
37
+ /** Keyboard interaction manager @ignore */
38
+ readonly _keyboardManager: KeyboardManager;
33
39
  /** Draw shader that contains content drawn by the user @ignore */
34
40
  readonly _textmodeDrawShader: Shader;
35
41
  /** Framebuffer used for offscreen rendering @ignore */
@@ -3,3 +3,7 @@ export { RenderingMixin, type RenderingCapabilities } from './RenderingMixin';
3
3
  export { ExportMixin, type ExportCapabilities } from './ExportMixin';
4
4
  export { FontMixin, type FontCapabilities } from './FontMixin';
5
5
  export { AnimationMixin, type AnimationCapabilities } from './AnimationMixin';
6
+ export { MouseMixin, type MouseCapabilities } from './MouseMixin';
7
+ export { KeyboardMixin, type KeyboardCapabilities } from './KeyboardMixin';
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.0",
3
+ "version": "0.2.1-beta.2",
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",
@@ -41,7 +42,7 @@
41
42
  "tslib": "^2.8.1",
42
43
  "typedoc": "^0.28.7",
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"