textmode.js 0.7.1 → 0.8.0-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 (54) hide show
  1. package/dist/textmode.esm.js +2042 -2108
  2. package/dist/textmode.umd.js +16 -16
  3. package/dist/types/Textmode.d.ts +11 -11
  4. package/dist/types/errors/index.d.ts +1 -1
  5. package/dist/types/index.d.ts +11 -3
  6. package/dist/types/rendering/webgl/core/Framebuffer.d.ts +0 -6
  7. package/dist/types/rendering/webgl/core/Renderer.d.ts +7 -6
  8. package/dist/types/rendering/webgl/core/interfaces/IFramebuffer.d.ts +6 -6
  9. package/dist/types/rendering/webgl/core/interfaces/IRenderer.d.ts +3 -3
  10. package/dist/types/rendering/webgl/index.d.ts +2 -2
  11. package/dist/types/rendering/webgl/pipeline/MaterialBatchPipeline.d.ts +1 -1
  12. package/dist/types/textmode/Canvas.d.ts +2 -2
  13. package/dist/types/textmode/Grid.d.ts +32 -3
  14. package/dist/types/textmode/Textmodifier.d.ts +14 -72
  15. package/dist/types/textmode/conversion/ConversionManager.d.ts +73 -0
  16. package/dist/types/textmode/conversion/ConversionRegistry.d.ts +61 -18
  17. package/dist/types/textmode/conversion/index.d.ts +3 -1
  18. package/dist/types/textmode/filters/FilterManager.d.ts +0 -4
  19. package/dist/types/textmode/filters/index.d.ts +1 -1
  20. package/dist/types/textmode/interfaces/ITextmodifier.d.ts +165 -50
  21. package/dist/types/textmode/layers/Layer2DCompositor.d.ts +13 -20
  22. package/dist/types/textmode/layers/LayerManager.d.ts +31 -20
  23. package/dist/types/textmode/layers/TextmodeLayer.d.ts +58 -20
  24. package/dist/types/textmode/layers/interfaces/ILayerManager.d.ts +7 -0
  25. package/dist/types/textmode/layers/interfaces/ITextmodeLayer.d.ts +49 -28
  26. package/dist/types/textmode/layers/types.d.ts +16 -21
  27. package/dist/types/textmode/loadables/ITextmodeSource.d.ts +123 -0
  28. package/dist/types/textmode/loadables/TextmodeImage.d.ts +2 -2
  29. package/dist/types/textmode/loadables/TextmodeSource.d.ts +10 -118
  30. package/dist/types/textmode/loadables/font/CharacterExtractor.d.ts +1 -1
  31. package/dist/types/textmode/loadables/font/TextmodeFont.d.ts +3 -0
  32. package/dist/types/textmode/loadables/font/index.d.ts +2 -2
  33. package/dist/types/textmode/loadables/index.d.ts +0 -2
  34. package/dist/types/textmode/loadables/video/ITextmodeVideo.d.ts +75 -0
  35. package/dist/types/textmode/loadables/video/TextmodeVideo.d.ts +23 -126
  36. package/dist/types/textmode/loading/LoadingPhase.d.ts +26 -0
  37. package/dist/types/textmode/loading/LoadingScreenManager.d.ts +91 -93
  38. package/dist/types/textmode/loading/index.d.ts +3 -2
  39. package/dist/types/textmode/loading/types.d.ts +57 -57
  40. package/dist/types/textmode/managers/MouseManager.d.ts +24 -14
  41. package/dist/types/textmode/managers/TouchManager.d.ts +25 -13
  42. package/dist/types/textmode/mixins/index.d.ts +1 -2
  43. package/dist/types/textmode/mixins/interfaces/IAnimationMixin.d.ts +87 -87
  44. package/dist/types/textmode/mixins/interfaces/IKeyboardMixin.d.ts +128 -128
  45. package/dist/types/textmode/mixins/interfaces/IMouseMixin.d.ts +96 -105
  46. package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +271 -370
  47. package/dist/types/textmode/mixins/interfaces/ITouchMixin.d.ts +1 -1
  48. package/dist/types/textmode/types.d.ts +2 -6
  49. package/package.json +5 -2
  50. package/dist/types/textmode/layers/filters/index.d.ts +0 -6
  51. package/dist/types/textmode/loadables/video/TextmodeVideoPreloader.d.ts +0 -29
  52. package/dist/types/textmode/loadables/video/types.d.ts +0 -43
  53. package/dist/types/textmode/mixins/FontMixin.d.ts +0 -8
  54. package/dist/types/textmode/mixins/interfaces/IFontMixin.d.ts +0 -46
@@ -1,4 +1,4 @@
1
- import type { MouseEventHandler, MousePosition } from "../../managers/MouseManager";
1
+ import type { MouseEventHandler, MousePosition } from '../../managers/MouseManager';
2
2
  /**
3
3
  * Capabilities provided by the MouseMixin
4
4
  */
@@ -19,11 +19,11 @@ export interface IMouseMixin {
19
19
  *
20
20
  * // Create a ripple at the clicked grid cell
21
21
  * t.mouseClicked((data) => {
22
- * // Convert top-left grid coords to center-based coords (matching draw-time origin)
23
- * const centerX = Math.round(data.position.x - (t.grid.cols - 1) / 2);
24
- * const centerY = Math.round(data.position.y - (t.grid.rows - 1) / 2);
22
+ * // Skip if mouse is outside the grid
23
+ * if (data.position.x === Number.NEGATIVE_INFINITY) return;
25
24
  *
26
- * ripples.push({ x: centerX, y: centerY, age: 0, maxAge: 20 });
25
+ * // Coordinates are already center-based, matching the drawing coordinate system
26
+ * ripples.push({ x: data.position.x, y: data.position.y, age: 0, maxAge: 20 });
27
27
  * });
28
28
  *
29
29
  * t.draw(() => {
@@ -64,14 +64,12 @@ export interface IMouseMixin {
64
64
  * }
65
65
  * }
66
66
  *
67
- * // Show crosshair for the current mouse cell. Convert t.mouse (top-left origin)
68
- * // to the center-based coordinates used for drawing just like above.
69
- * if (t.mouse.x !== -1 && t.mouse.y !== -1) {
70
- * const cx = Math.round(t.mouse.x - (t.grid.cols - 1) / 2);
71
- * const cy = Math.round(t.mouse.y - (t.grid.rows - 1) / 2);
67
+ * // Show crosshair for the current mouse cell
68
+ * // Mouse coordinates are center-based, matching the drawing coordinate system
69
+ * if (t.mouse.x !== Number.NEGATIVE_INFINITY) {
72
70
  * t.push();
73
71
  * t.charColor(180);
74
- * t.translate(cx, cy);
72
+ * t.translate(t.mouse.x, t.mouse.y);
75
73
  * t.char('+');
76
74
  * t.point();
77
75
  * t.pop();
@@ -95,7 +93,7 @@ export interface IMouseMixin {
95
93
  * let pressing = false;
96
94
  *
97
95
  * t.mousePressed((data) => {
98
- * if (data.position.x === -1 || data.position.y === -1) return;
96
+ * if (data.position.x === Number.NEGATIVE_INFINITY) return;
99
97
  * pressing = true;
100
98
  * });
101
99
  *
@@ -106,10 +104,10 @@ export interface IMouseMixin {
106
104
  * t.draw(() => {
107
105
  * t.background(0);
108
106
  *
109
- * // Spawn particles while pressing
110
- * if (pressing && t.mouse.x !== -1) {
111
- * const cx = Math.round(t.mouse.x - (t.grid.cols - 1) / 2);
112
- * const cy = Math.round(t.mouse.y - (t.grid.rows - 1) / 2);
107
+ * // Spawn particles while pressing (mouse coords are center-based)
108
+ * if (pressing && t.mouse.x !== Number.NEGATIVE_INFINITY) {
109
+ * const cx = t.mouse.x;
110
+ * const cy = t.mouse.y;
113
111
  *
114
112
  * for (let i = 0; i < 3; i++) {
115
113
  * particles.push({
@@ -165,16 +163,15 @@ export interface IMouseMixin {
165
163
  * let dragStart = null;
166
164
  *
167
165
  * t.mousePressed((data) => {
168
- * if (data.position.x === -1 || data.position.y === -1) return;
169
- * const cx = Math.round(data.position.x - (t.grid.cols - 1) / 2);
170
- * const cy = Math.round(data.position.y - (t.grid.rows - 1) / 2);
171
- * dragStart = { x: cx, y: cy };
166
+ * if (data.position.x === Number.NEGATIVE_INFINITY) return;
167
+ * // Coordinates are already center-based
168
+ * dragStart = { x: data.position.x, y: data.position.y };
172
169
  * });
173
170
  *
174
171
  * t.mouseReleased((data) => {
175
- * if (!dragStart || data.position.x === -1) return;
176
- * const cx = Math.round(data.position.x - (t.grid.cols - 1) / 2);
177
- * const cy = Math.round(data.position.y - (t.grid.rows - 1) / 2);
172
+ * if (!dragStart || data.position.x === Number.NEGATIVE_INFINITY) return;
173
+ * const cx = data.position.x;
174
+ * const cy = data.position.y;
178
175
  *
179
176
  * // Calculate line center and local endpoints
180
177
  * const centerX = (dragStart.x + cx) / 2;
@@ -215,10 +212,10 @@ export interface IMouseMixin {
215
212
  * t.pop();
216
213
  * }
217
214
  *
218
- * // Draw current drag line
219
- * if (dragStart && t.mouse.x !== -1) {
220
- * const cx = Math.round(t.mouse.x - (t.grid.cols - 1) / 2);
221
- * const cy = Math.round(t.mouse.y - (t.grid.rows - 1) / 2);
215
+ * // Draw current drag line (mouse coords are center-based)
216
+ * if (dragStart && t.mouse.x !== Number.NEGATIVE_INFINITY) {
217
+ * const cx = t.mouse.x;
218
+ * const cy = t.mouse.y;
222
219
  * const centerX = (dragStart.x + cx) / 2;
223
220
  * const centerY = (dragStart.y + cy) / 2;
224
221
  * const dx = cx - dragStart.x;
@@ -252,11 +249,11 @@ export interface IMouseMixin {
252
249
  * let lastMouse = null;
253
250
  *
254
251
  * t.mouseMoved((data) => {
255
- * if (data.position.x === -1 || data.position.y === -1) return;
252
+ * if (data.position.x === Number.NEGATIVE_INFINITY) return;
256
253
  *
257
- * // Convert to center-based coords
258
- * const cx = Math.round(data.position.x - (t.grid.cols - 1) / 2);
259
- * const cy = Math.round(data.position.y - (t.grid.rows - 1) / 2);
254
+ * // Coordinates are already center-based, matching the drawing system
255
+ * const cx = data.position.x;
256
+ * const cy = data.position.y;
260
257
  *
261
258
  * // Spawn multiple particles based on movement speed
262
259
  * const dx = lastMouse ? cx - lastMouse.x : 0;
@@ -313,39 +310,40 @@ export interface IMouseMixin {
313
310
  *
314
311
  * @example
315
312
  * ```javascript
316
- * // Scroll to create expanding rings.
313
+ * // Scroll to create expanding rings.
317
314
  *
318
315
  * const t = textmode.create({ width: 800, height: 600 });
319
316
  *
320
317
  * const rings = [];
321
318
  *
322
- * t.mouseScrolled((data) => {
323
- * if (data.position.x === -1 || data.position.y === -1) return;
324
- *
325
- * const cx = Math.round(data.position.x - (t.grid.cols - 1) / 2);
326
- * const cy = Math.round(data.position.y - (t.grid.rows - 1) / 2);
327
- *
328
- * // Use scroll delta to determine ring intensity and direction
329
- * const scrollSpeed = 2;
330
- * const intensity = Math.min(scrollSpeed * 30, 255);
331
- * const scrollDown = (data.delta?.y || 0) > 0;
332
- *
333
- * rings.push({
334
- * x: cx,
335
- * y: cy,
336
- * radius: 1,
337
- * maxRadius: 5 + scrollSpeed * 0.5,
338
- * color: intensity,
339
- * scrollDown: scrollDown,
340
- * age: 0,
341
- * maxAge: 20
342
- * });
343
- * });
319
+ * t.mouseScrolled((data) => {
320
+ * if (data.position.x === Number.NEGATIVE_INFINITY) return;
321
+ *
322
+ * // Coordinates are already center-based
323
+ * const cx = data.position.x;
324
+ * const cy = data.position.y;
325
+ *
326
+ * // Use scroll delta to determine ring intensity and direction
327
+ * const scrollSpeed = 2;
328
+ * const intensity = Math.min(scrollSpeed * 30, 255);
329
+ * const scrollDown = (data.delta?.y || 0) > 0;
330
+ *
331
+ * rings.push({
332
+ * x: cx,
333
+ * y: cy,
334
+ * radius: 1,
335
+ * maxRadius: 5 + scrollSpeed * 0.5,
336
+ * color: intensity,
337
+ * scrollDown: scrollDown,
338
+ * age: 0,
339
+ * maxAge: 20
340
+ * });
341
+ * });
344
342
  *
345
343
  * t.draw(() => {
346
344
  * t.background(0);
347
345
  *
348
- * // Update and draw rings
346
+ * // Update and draw rings
349
347
  * for (let i = rings.length - 1; i >= 0; i--) {
350
348
  * const r = rings[i];
351
349
  * r.age++;
@@ -359,13 +357,13 @@ export interface IMouseMixin {
359
357
  * const life = 1 - (r.age / r.maxAge);
360
358
  * const brightness = Math.round(r.color * life);
361
359
  *
362
- * t.push();
363
- * // Blue for scroll down, orange for scroll up
364
- * if (r.scrollDown) {
365
- * t.charColor(brightness * 0.5, brightness * 0.8, 255);
366
- * } else {
367
- * t.charColor(255, brightness * 0.6, brightness * 0.3);
368
- * }
360
+ * t.push();
361
+ * // Blue for scroll down, orange for scroll up
362
+ * if (r.scrollDown) {
363
+ * t.charColor(brightness * 0.5, brightness * 0.8, 255);
364
+ * } else {
365
+ * t.charColor(255, brightness * 0.6, brightness * 0.3);
366
+ * }
369
367
  * t.translate(r.x, r.y);
370
368
  *
371
369
  * // Draw ring
@@ -385,12 +383,13 @@ export interface IMouseMixin {
385
383
  */
386
384
  mouseScrolled(callback: MouseEventHandler): void;
387
385
  /**
388
- * Get the current mouse position in grid coordinates.
386
+ * Get the current mouse position in center-based grid coordinates.
389
387
  *
390
- * Returns the mouse position as grid cell coordinates *(column, row)*.
388
+ * Returns the mouse position as grid cell coordinates where `(0, 0)` is the center cell.
389
+ * This matches the drawing coordinate system, so coordinates can be used directly with `translate()`.
391
390
  *
392
391
  * If the mouse is outside the grid or the instance is not ready,
393
- * it returns `{ x: -1, y: -1 }`.
392
+ * it returns `{ x: Number.NEGATIVE_INFINITY, y: Number.NEGATIVE_INFINITY }`.
394
393
  *
395
394
  * @example
396
395
  * ```javascript
@@ -399,15 +398,14 @@ export interface IMouseMixin {
399
398
  * t.draw(() => {
400
399
  * t.background(0);
401
400
  *
402
- * // Convert mouse position from top-left origin to center-based origin
403
- * const centerX = Math.round(t.mouse.x - (t.grid.cols - 1) / 2);
404
- * const centerY = Math.round(t.mouse.y - (t.grid.rows - 1) / 2);
405
- *
406
- * t.translate(centerX, centerY);
407
- * t.char('*');
408
- * t.charColor(255, 0, 0);
409
- * t.cellColor(100);
410
- * t.point();
401
+ * // Mouse coordinates are center-based, matching the drawing system
402
+ * if (t.mouse.x !== Number.NEGATIVE_INFINITY) {
403
+ * t.translate(t.mouse.x, t.mouse.y);
404
+ * t.char('*');
405
+ * t.charColor(255, 0, 0);
406
+ * t.cellColor(100);
407
+ * t.point();
408
+ * }
411
409
  * });
412
410
  * ```
413
411
  */
@@ -421,37 +419,30 @@ export interface IMouseMixin {
421
419
  *
422
420
  * See MDN for all options: https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
423
421
  *
424
- * @example
425
- * ```javascript
426
- * const t = textmode.create({ width: 800, height: 600 });
427
- * const target = { width: 30, height: 15 };
428
- *
429
- * t.draw(() => {
430
- * t.background(0);
431
- * t.charColor(255); // keep char visible
432
- * t.char('*');
433
- * t.rect(target.width, target.height);
434
- *
435
- * // Rectangle is centered at (0, 0) which is grid center
436
- * // Calculate bounds relative to grid center
437
- * const centerX = t.grid.cols / 2;
438
- * const centerY = t.grid.rows / 2;
439
- *
440
- * const halfRectWidth = target.width / 2;
441
- * const halfRectHeight = target.height / 2;
442
- *
443
- * const rectLeft = centerX - halfRectWidth;
444
- * const rectRight = centerX + halfRectWidth;
445
- * const rectTop = centerY - halfRectHeight;
446
- * const rectBottom = centerY + halfRectHeight;
447
- *
448
- * const hovering =
449
- * t.mouse.x >= rectLeft && t.mouse.x < rectRight &&
450
- * t.mouse.y >= rectTop && t.mouse.y < rectBottom;
451
- *
452
- * t.cursor(hovering ? 'pointer' : 'default');
453
- * });
454
- * ```
422
+ * @example
423
+ * ```javascript
424
+ * const t = textmode.create({ width: 800, height: 600 });
425
+ * const target = { width: 30, height: 15 };
426
+ *
427
+ * t.draw(() => {
428
+ * t.background(0);
429
+ * t.charColor(255); // keep char visible
430
+ * t.char('*');
431
+ * t.rect(target.width, target.height);
432
+ *
433
+ * // Rectangle is centered at (0, 0) which is grid center
434
+ * // Mouse coordinates are also center-based, so we can compare directly
435
+ * const halfRectWidth = target.width / 2;
436
+ * const halfRectHeight = target.height / 2;
437
+ *
438
+ * const hovering =
439
+ * t.mouse.x !== Number.NEGATIVE_INFINITY &&
440
+ * t.mouse.x >= -halfRectWidth && t.mouse.x < halfRectWidth &&
441
+ * t.mouse.y >= -halfRectHeight && t.mouse.y < halfRectHeight;
442
+ *
443
+ * t.cursor(hovering ? 'pointer' : 'default');
444
+ * });
445
+ * ```
455
446
  */
456
447
  cursor(cursor?: string): void;
457
448
  }