textmode.js 0.1.6-beta.5 → 0.1.6-beta.7

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 (48) hide show
  1. package/dist/textmode.esm.js +1871 -0
  2. package/dist/textmode.esm.min.js +1870 -0
  3. package/dist/textmode.umd.js +64 -0
  4. package/dist/textmode.umd.min.js +63 -0
  5. package/dist/types/ColorPalette.d.ts +1 -5
  6. package/dist/types/Textmode.d.ts +0 -10
  7. package/dist/types/errors/Error.d.ts +3 -5
  8. package/dist/types/errors/ErrorHandler.d.ts +3 -3
  9. package/dist/types/export/base/DataExtractor.d.ts +3 -3
  10. package/dist/types/export/base/FileHandler.d.ts +6 -6
  11. package/dist/types/export/image/ImageContentGenerator.d.ts +3 -3
  12. package/dist/types/export/image/ImageDataExtractor.d.ts +2 -2
  13. package/dist/types/export/image/ImageExporter.d.ts +9 -9
  14. package/dist/types/export/image/ImageFileHandler.d.ts +3 -21
  15. package/dist/types/export/svg/SVGContentGenerator.d.ts +12 -12
  16. package/dist/types/export/svg/SVGDataExtractor.d.ts +4 -4
  17. package/dist/types/export/svg/SVGExporter.d.ts +6 -6
  18. package/dist/types/export/svg/SVGFileHandler.d.ts +3 -3
  19. package/dist/types/export/svg/SVGPathGenerator.d.ts +5 -11
  20. package/dist/types/export/txt/TXTContentGenerator.d.ts +1 -1
  21. package/dist/types/export/txt/TXTDataExtractor.d.ts +2 -2
  22. package/dist/types/export/txt/TXTExporter.d.ts +6 -6
  23. package/dist/types/export/txt/TXTFileHandler.d.ts +2 -2
  24. package/dist/types/index.d.ts +0 -1
  25. package/dist/types/rendering/webgl/Framebuffer.d.ts +8 -8
  26. package/dist/types/rendering/webgl/Renderer.d.ts +35 -35
  27. package/dist/types/rendering/webgl/Shader.d.ts +14 -14
  28. package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +10 -10
  29. package/dist/types/rendering/webgl/geometries/Line.d.ts +1 -1
  30. package/dist/types/rendering/webgl/geometries/Rectangle.d.ts +2 -2
  31. package/dist/types/textmode/Canvas.d.ts +9 -18
  32. package/dist/types/textmode/ConversionPipeline.d.ts +31 -20
  33. package/dist/types/textmode/Grid.d.ts +7 -12
  34. package/dist/types/textmode/Textmodifier.d.ts +18 -40
  35. package/dist/types/textmode/converters/BrightnessConverter.d.ts +8 -8
  36. package/dist/types/textmode/converters/Converter.d.ts +5 -5
  37. package/dist/types/textmode/converters/FeatureConverter.d.ts +27 -3
  38. package/dist/types/textmode/font/TextmodeFont.d.ts +8 -8
  39. package/dist/types/textmode/mixins/ConversionMixin.d.ts +63 -0
  40. package/dist/types/textmode/mixins/ExportMixin.d.ts +112 -1
  41. package/dist/types/textmode/mixins/FontMixin.d.ts +1 -1
  42. package/dist/types/textmode/mixins/RenderingMixin.d.ts +304 -1
  43. package/dist/types/textmode/mixins/{MixinBase.d.ts → TextmodifierMixin.d.ts} +4 -4
  44. package/dist/types/textmode/mixins/index.d.ts +2 -1
  45. package/package.json +16 -2
  46. package/dist/textmode.js +0 -26
  47. package/dist/textmode.min.js +0 -25
  48. package/dist/types/types/index.d.ts +0 -4
@@ -1,4 +1,4 @@
1
- import type { Mixin } from './MixinBase';
1
+ import type { Mixin } from './TextmodifierMixin';
2
2
  import type { Shader } from '../../rendering';
3
3
  /**
4
4
  * Interface for rendering capabilities that will be mixed into Textmodifier
@@ -10,6 +10,34 @@ export interface RenderingCapabilities {
10
10
  * @param g Green component (0-255, optional)
11
11
  * @param b Blue component (0-255, optional)
12
12
  * @param a Alpha component (0-255, optional)
13
+ *
14
+ * @example
15
+ * ```javascript
16
+ * const t = await textmode.create({
17
+ * width: 800,
18
+ * height: 600,
19
+ * })
20
+ *
21
+ * t.draw(() => {
22
+ * // Set the background color to black
23
+ * t.background(0);
24
+ *
25
+ * const centerX = t.width / 2;
26
+ * const centerY = t.height / 2;
27
+ * const radius = Math.min(t.width, t .height) / 3;
28
+ * const speed = 0.02; // Adjust speed of rotation
29
+ *
30
+ * const angle = t.frameCount * speed;
31
+ * const x = centerX + Math.cos(angle) * radius - 100;
32
+ * const y = centerY + Math.sin(angle) * radius - 50;
33
+ *
34
+ * // Set the fill color to white
35
+ * t.fill(255);
36
+ *
37
+ * // Draw a rectangle with the fill color
38
+ * t.rect(x, y, 200, 150);
39
+ * });
40
+ * ```
13
41
  */
14
42
  fill(r: number, g?: number, b?: number, a?: number): void;
15
43
  /**
@@ -18,34 +46,218 @@ export interface RenderingCapabilities {
18
46
  * @param g Green component (0-255, optional)
19
47
  * @param b Blue component (0-255, optional)
20
48
  * @param a Alpha component (0-255, optional)
49
+ *
50
+ * @example
51
+ * ```javascript
52
+ * const t = await textmode.create({
53
+ * width: 800,
54
+ * height: 600,
55
+ * })
56
+ *
57
+ * t.draw(() => {
58
+ * // Set the background color to black
59
+ * t.background(0);
60
+ *
61
+ * // Set stroke color to red and stroke weight to 4 pixels
62
+ * t.stroke(255, 0, 0);
63
+ * t.strokeWeight(4);
64
+ *
65
+ * // Draw a rectangle with red stroke
66
+ * t.rect(100, 100, 200, 150);
67
+ *
68
+ * // Rectangle with both fill and stroke
69
+ * t.fill(0, 255, 0);
70
+ * t.stroke(0, 0, 255);
71
+ * t.strokeWeight(2);
72
+ * t.rect(350, 100, 200, 150);
73
+ * });
74
+ * ```
21
75
  */
22
76
  stroke(r: number, g?: number, b?: number, a?: number): void;
23
77
  /**
24
78
  * Sets the stroke weight (thickness) for subsequent stroke operations
25
79
  * @param weight The stroke thickness in pixels
80
+ *
81
+ * @example
82
+ * ```javascript
83
+ * const t = await textmode.create({
84
+ * width: 800,
85
+ * height: 600,
86
+ * })
87
+ *
88
+ * t.draw(() => {
89
+ * t.background(0);
90
+ *
91
+ * // Thin stroke
92
+ * t.stroke(255);
93
+ * t.strokeWeight(1);
94
+ * t.rect(50, 50, 100, 100);
95
+ *
96
+ * // Thick stroke
97
+ * t.strokeWeight(8);
98
+ * t.rect(200, 50, 100, 100);
99
+ * });
100
+ * ```
26
101
  */
27
102
  strokeWeight(weight: number): void;
28
103
  /**
29
104
  * Disables stroke rendering for subsequent operations
105
+ *
106
+ * @example
107
+ * ```javascript
108
+ * const t = await textmode.create({
109
+ * width: 800,
110
+ * height: 600,
111
+ * })
112
+ *
113
+ * t.draw(() => {
114
+ * t.background(0);
115
+ *
116
+ * // Rectangle with stroke
117
+ * t.fill(255, 0, 0);
118
+ * t.stroke(0, 255, 0);
119
+ * t.strokeWeight(4);
120
+ * t.rect(100, 100, 150, 100);
121
+ *
122
+ * // Rectangle without stroke (fill only)
123
+ * t.noStroke();
124
+ * t.rect(300, 100, 150, 100);
125
+ * });
126
+ * ```
30
127
  */
31
128
  noStroke(): void;
32
129
  /**
33
130
  * Disables fill rendering for subsequent operations
131
+ *
132
+ * @example
133
+ * ```javascript
134
+ * const t = await textmode.create({
135
+ * width: 800,
136
+ * height: 600,
137
+ * })
138
+ *
139
+ * t.draw(() => {
140
+ * t.background(0);
141
+ *
142
+ * // Rectangle with fill
143
+ * t.fill(255, 0, 0);
144
+ * t.stroke(0, 255, 0);
145
+ * t.strokeWeight(4);
146
+ * t.rect(100, 100, 150, 100);
147
+ *
148
+ * // Rectangle without fill (stroke only)
149
+ * t.noFill();
150
+ * t.rect(300, 100, 150, 100);
151
+ * });
152
+ * ```
34
153
  */
35
154
  noFill(): void;
36
155
  /**
37
156
  * Sets the rotation angle for subsequent rendering operations
38
157
  * @param degrees The rotation angle in degrees
158
+ *
159
+ * @example
160
+ * ```javascript
161
+ * const t = await textmode.create({
162
+ * width: 800,
163
+ * height: 600,
164
+ * })
165
+ *
166
+ * t.draw(() => {
167
+ * t.background(0);
168
+ *
169
+ * // Normal rectangle
170
+ * t.fill(255, 0, 0);
171
+ * t.rect(100, 100, 150, 100);
172
+ *
173
+ * // Rotated rectangle
174
+ * t.push(); // Save current state
175
+ * t.rotate(45); // Rotate 45 degrees
176
+ * t.fill(0, 255, 0);
177
+ * t.rect(300, 100, 150, 100);
178
+ * t.pop(); // Restore state (no rotation)
179
+ *
180
+ * // Back to normal (no rotation)
181
+ * t.fill(0, 0, 255);
182
+ * t.rect(500, 100, 150, 100);
183
+ * });
184
+ * ```
39
185
  */
40
186
  rotate(degrees: number): void;
41
187
  /**
42
188
  * Save the current rendering state (fill, stroke, etc.) to the state stack.
43
189
  * Use with {@link pop} to isolate style changes within a block.
190
+ *
191
+ * @example
192
+ * ```javascript
193
+ * const t = await textmode.create({
194
+ * width: 800,
195
+ * height: 600,
196
+ * })
197
+ *
198
+ * t.draw(() => {
199
+ * t.background(0);
200
+ *
201
+ * // Set initial styles
202
+ * t.fill(255, 0, 0); // Red fill
203
+ * t.stroke(0, 255, 0); // Green stroke
204
+ * t.strokeWeight(4); // Thick stroke
205
+ *
206
+ * t.push(); // Save current state
207
+ *
208
+ * // Change styles temporarily
209
+ * t.fill(0, 0, 255); // Blue fill
210
+ * t.stroke(255, 255, 0); // Yellow stroke
211
+ * t.strokeWeight(2); // Thin stroke
212
+ * t.rect(100, 100, 150, 100);
213
+ *
214
+ * t.pop(); // Restore previous state
215
+ *
216
+ * // Back to red fill, green stroke, thick stroke
217
+ * t.rect(300, 100, 150, 100);
218
+ * });
219
+ * ```
44
220
  */
45
221
  push(): void;
46
222
  /**
47
223
  * Restore the most recently saved rendering state from the state stack.
48
224
  * Use with {@link push} to isolate style changes within a block.
225
+ *
226
+ * @example
227
+ * ```javascript
228
+ * const t = await textmode.create({
229
+ * width: 800,
230
+ * height: 600,
231
+ * })
232
+ *
233
+ * t.draw(() => {
234
+ * t.background(0);
235
+ *
236
+ * // Default styles
237
+ * t.fill(255); // White fill
238
+ * t.stroke(0); // Black stroke
239
+ * t.strokeWeight(1); // Thin stroke
240
+ *
241
+ * t.push(); // Save current state
242
+ *
243
+ * // Temporary style changes
244
+ * t.fill(255, 0, 0); // Red fill
245
+ * t.strokeWeight(8); // Thick stroke
246
+ * t.rect(50, 50, 100, 100);
247
+ *
248
+ * t.push(); // Save red style state
249
+ *
250
+ * t.fill(0, 255, 0); // Green fill
251
+ * t.noStroke(); // No stroke
252
+ * t.rect(200, 50, 100, 100);
253
+ *
254
+ * t.pop(); // Back to red fill, thick stroke
255
+ * t.rect(350, 50, 100, 100);
256
+ *
257
+ * t.pop(); // Back to white fill, black stroke, thin stroke
258
+ * t.rect(500, 50, 100, 100);
259
+ * });
260
+ * ```
49
261
  */
50
262
  pop(): void;
51
263
  /**
@@ -54,6 +266,34 @@ export interface RenderingCapabilities {
54
266
  * @param y Y-coordinate of the rectangle
55
267
  * @param width Width of the rectangle
56
268
  * @param height Height of the rectangle
269
+ *
270
+ * @example
271
+ * ```javascript
272
+ * const t = await textmode.create({
273
+ * width: 800,
274
+ * height: 600,
275
+ * })
276
+ *
277
+ * t.draw(() => {
278
+ * // Set the background color to black
279
+ * t.background(0);
280
+ *
281
+ * const centerX = t.width / 2;
282
+ * const centerY = t.height / 2;
283
+ * const radius = Math.min(t.width, t .height) / 3;
284
+ * const speed = 0.02; // Adjust speed of rotation
285
+ *
286
+ * const angle = t.frameCount * speed;
287
+ * const x = centerX + Math.cos(angle) * radius - 100;
288
+ * const y = centerY + Math.sin(angle) * radius - 50;
289
+ *
290
+ * // Set the fill color to white
291
+ * t.fill(255);
292
+ *
293
+ * // Draw a rectangle with the fill color
294
+ * t.rect(x, y, 200, 150);
295
+ * });
296
+ * ```
57
297
  */
58
298
  rect(x: number, y: number, width?: number, height?: number): void;
59
299
  /**
@@ -63,6 +303,41 @@ export interface RenderingCapabilities {
63
303
  * @param y1 Y-coordinate of the line start point
64
304
  * @param x2 X-coordinate of the line end point
65
305
  * @param y2 Y-coordinate of the line end point
306
+ *
307
+ * @example
308
+ * ```javascript
309
+ * const t = await textmode.create({
310
+ * width: 800,
311
+ * height: 600,
312
+ * })
313
+ *
314
+ * t.draw(() => {
315
+ * // Set the background color to black
316
+ * t.background(0);
317
+ *
318
+ * // Draw a simple line
319
+ * t.stroke(255, 0, 0); // Red stroke
320
+ * t.strokeWeight(2); // 2px thick
321
+ * t.line(100, 100, 300, 200);
322
+ *
323
+ * // Draw an animated rotating line
324
+ * t.push();
325
+ * t.stroke(0, 255, 0); // Green stroke
326
+ * t.strokeWeight(4); // 4px thick
327
+ * t.rotate(t.frameCount * 2); // Rotate based on frame count
328
+ * t.line(400, 300, 600, 300);
329
+ * t.pop();
330
+ *
331
+ * // Draw a thick yellow line
332
+ * t.stroke(255, 255, 0); // Yellow stroke
333
+ * t.strokeWeight(8); // 8px thick
334
+ * t.line(200, 400, 400, 500);
335
+ *
336
+ * // Line with no stroke won't be visible
337
+ * t.noStroke();
338
+ * t.line(500, 100, 700, 200); // This won't render
339
+ * });
340
+ * ```
66
341
  */
67
342
  line(x1: number, y1: number, x2: number, y2: number): void;
68
343
  /**
@@ -71,6 +346,34 @@ export interface RenderingCapabilities {
71
346
  * @param g Green component (0-255, optional)
72
347
  * @param b Blue component (0-255, optional)
73
348
  * @param a Alpha component (0-255, optional)
349
+ *
350
+ * @example
351
+ * ```javascript
352
+ * const t = await textmode.create({
353
+ * width: 800,
354
+ * height: 600,
355
+ * })
356
+ *
357
+ * t.draw(() => {
358
+ * // Set the background color to black
359
+ * t.background(0);
360
+ *
361
+ * const centerX = t.width / 2;
362
+ * const centerY = t.height / 2;
363
+ * const radius = Math.min(t.width, t .height) / 3;
364
+ * const speed = 0.02; // Adjust speed of rotation
365
+ *
366
+ * const angle = t.frameCount * speed;
367
+ * const x = centerX + Math.cos(angle) * radius - 100;
368
+ * const y = centerY + Math.sin(angle) * radius - 50;
369
+ *
370
+ * // Set the fill color to white
371
+ * t.fill(255);
372
+ *
373
+ * // Draw a rectangle with the fill color
374
+ * t.rect(x, y, 200, 150);
375
+ * });
376
+ * ```
74
377
  */
75
378
  background(r: number, g?: number, b?: number, a?: number): void;
76
379
  /**
@@ -13,12 +13,12 @@ export type Constructor<T = {}> = new (...args: any[]) => T;
13
13
  /**
14
14
  * Mixin function type that takes a base class and returns an extended class
15
15
  */
16
- export type Mixin<T> = <TBase extends Constructor<TextmodifierCore>>(Base: TBase) => TBase & Constructor<T>;
16
+ export type Mixin<T> = <TBase extends Constructor<TextmodifierContext>>(Base: TBase) => TBase & Constructor<T>;
17
17
  /**
18
- * Core interface that defines the essential properties all mixins can access.
19
- * This replaces both the old TextmodifierBase class and MixinCore interface.
18
+ * Essential properties that all mixins can access.
19
+ * This defines the contract for what mixins can expect to be available.
20
20
  */
21
- export interface TextmodifierCore {
21
+ export interface TextmodifierContext {
22
22
  /** Core WebGL renderer @ignore */
23
23
  readonly _renderer: GLRenderer;
24
24
  /** Font management @ignore */
@@ -1,4 +1,5 @@
1
- export { type Constructor, type Mixin, type TextmodifierCore, applyMixins } from './MixinBase';
1
+ export { type Constructor, type Mixin, type TextmodifierContext, applyMixins } from './TextmodifierMixin';
2
2
  export { RenderingMixin, type RenderingCapabilities } from './RenderingMixin';
3
3
  export { ExportMixin, type ExportCapabilities } from './ExportMixin';
4
4
  export { FontMixin, type FontCapabilities } from './FontMixin';
5
+ export { ConversionMixin, type ConversionCapabilities } from './ConversionMixin';
package/package.json CHANGED
@@ -1,9 +1,23 @@
1
1
  {
2
2
  "name": "textmode.js",
3
- "version": "0.1.6-beta.5",
3
+ "version": "0.1.6-beta.7",
4
4
  "description": "Apply real-time ASCII conversion to any HTML canvas.",
5
+ "type": "module",
5
6
  "types": "./dist/types/index.d.ts",
6
- "main": "./dist/textmode.js",
7
+ "main": "./dist/textmode.umd.js",
8
+ "module": "./dist/textmode.esm.js",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/types/index.d.ts",
12
+ "import": "./dist/textmode.esm.js",
13
+ "require": "./dist/textmode.umd.js"
14
+ },
15
+ "./min": {
16
+ "types": "./dist/types/index.d.ts",
17
+ "import": "./dist/textmode.esm.min.js",
18
+ "require": "./dist/textmode.umd.min.js"
19
+ }
20
+ },
7
21
  "scripts": {
8
22
  "dev": "vite --port 5177 --host",
9
23
  "build": "vite build && vite build --mode min && tsc",