textmode.js 0.8.1 → 0.8.5

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 (29) hide show
  1. package/dist/textmode.esm.js +2150 -1860
  2. package/dist/textmode.umd.js +16 -16
  3. package/dist/types/Textmode.d.ts +1 -12
  4. package/dist/types/exports/conversion.d.ts +1 -0
  5. package/dist/types/exports/filters.d.ts +1 -0
  6. package/dist/types/exports/input.d.ts +1 -0
  7. package/dist/types/exports/layering.d.ts +1 -0
  8. package/dist/types/exports/loadables.d.ts +1 -0
  9. package/dist/types/exports/loading.d.ts +1 -0
  10. package/dist/types/exports/plugins.d.ts +1 -0
  11. package/dist/types/index.d.ts +35 -1
  12. package/dist/types/rendering/webgl/core/Framebuffer.d.ts +1 -1
  13. package/dist/types/rendering/webgl/core/Shader.d.ts +17 -3
  14. package/dist/types/rendering/webgl/core/interfaces/IFramebuffer.d.ts +1 -8
  15. package/dist/types/textmode/AnimationController.d.ts +39 -0
  16. package/dist/types/textmode/Grid.d.ts +2 -0
  17. package/dist/types/textmode/Textmodifier.d.ts +8 -15
  18. package/dist/types/textmode/interfaces/ITextmodifier.d.ts +9 -13
  19. package/dist/types/textmode/layers/LayerManager.d.ts +41 -25
  20. package/dist/types/textmode/layers/TextmodeLayer.d.ts +11 -52
  21. package/dist/types/textmode/layers/interfaces/ILayerManager.d.ts +5 -0
  22. package/dist/types/textmode/layers/interfaces/ITextmodeLayer.d.ts +45 -2
  23. package/dist/types/textmode/managers/PluginManager.d.ts +157 -9
  24. package/dist/types/textmode/mixins/interfaces/IAnimationMixin.d.ts +153 -1
  25. package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +8 -0
  26. package/dist/types/textmode/types.d.ts +4 -3
  27. package/dist/types/utils/TextmodeCollection.d.ts +262 -0
  28. package/dist/types/utils/math.d.ts +26 -0
  29. package/package.json +37 -2
@@ -0,0 +1,262 @@
1
+ /**
2
+ * A generic, managed collection for objects that require lifecycle management.
3
+ *
4
+ * This class provides CRUD operations (Create/Read/Update/Delete) with support for:
5
+ * - Adding and removing items
6
+ * - Reordering items (move, swap)
7
+ * - Deferred initialization via pending items
8
+ * - Automatic disposal of removed items
9
+ * - Event callbacks for lifecycle events
10
+ *
11
+ * @typeParam T - The type of items stored in the collection
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // Create a collection with a disposal callback
16
+ * const layers = new TextmodeCollection<TextmodeLayer>({
17
+ * onDispose: (layer) => layer.$dispose(),
18
+ * onAdd: (layer) => pluginManager.notifyLayerCreated(layer),
19
+ * onRemove: (layer) => pluginManager.notifyLayerDisposed(layer),
20
+ * });
21
+ *
22
+ * // Add items
23
+ * const layer = new TextmodeLayer();
24
+ * layers.add(layer);
25
+ *
26
+ * // Iterate
27
+ * for (const layer of layers) {
28
+ * layer.draw();
29
+ * }
30
+ *
31
+ * // Remove all
32
+ * layers.clear();
33
+ * ```
34
+ */
35
+ export declare class TextmodeCollection<T> implements Iterable<T> {
36
+ private _items;
37
+ private _pendingItems;
38
+ private _isReady;
39
+ private readonly _options;
40
+ /**
41
+ * Create a new TextmodeCollection.
42
+ *
43
+ * @param options Configuration options for the collection
44
+ */
45
+ constructor(options?: TextmodeCollectionOptions<T>);
46
+ /**
47
+ * Mark the collection as ready and move all pending items to the active list.
48
+ *
49
+ * Call this after async initialization is complete. Any items added before
50
+ * this call will be moved from the pending queue to the active collection.
51
+ *
52
+ * @param initializeItem Optional async function to initialize each pending item
53
+ * @returns Promise that resolves when all pending items are initialized
54
+ */
55
+ initialize(initializeItem?: (item: T) => Promise<void>): Promise<void>;
56
+ /**
57
+ * Check if the collection has been initialized.
58
+ */
59
+ get isReady(): boolean;
60
+ /**
61
+ * Add an item to the collection.
62
+ *
63
+ * If the collection is not yet ready, the item is added to a pending queue.
64
+ * Once `initialize()` is called, pending items are moved to the active collection.
65
+ *
66
+ * @param item The item to add
67
+ * @returns The added item (for chaining)
68
+ */
69
+ add(item: T): T;
70
+ /**
71
+ * Add multiple items to the collection.
72
+ *
73
+ * @param items The items to add
74
+ * @returns The added items
75
+ */
76
+ addMany(items: T[]): T[];
77
+ /**
78
+ * Remove an item from the collection and dispose it.
79
+ *
80
+ * @param item The item to remove
81
+ * @returns true if the item was found and removed, false otherwise
82
+ */
83
+ remove(item: T): boolean;
84
+ /**
85
+ * Remove an item at a specific index.
86
+ *
87
+ * @param index The index of the item to remove
88
+ * @returns The removed item, or undefined if index is out of bounds
89
+ */
90
+ removeAt(index: number): T | undefined;
91
+ /**
92
+ * Move an item to a new index in the collection.
93
+ *
94
+ * @param item The item to move
95
+ * @param newIndex The target index
96
+ * @returns true if the item was found and moved, false otherwise
97
+ */
98
+ move(item: T, newIndex: number): boolean;
99
+ /**
100
+ * Swap the positions of two items in the collection.
101
+ *
102
+ * @param itemA The first item
103
+ * @param itemB The second item
104
+ * @returns true if both items were found and swapped, false otherwise
105
+ */
106
+ swap(itemA: T, itemB: T): boolean;
107
+ /**
108
+ * Remove and dispose all items from the collection.
109
+ *
110
+ * This clears both active and pending items.
111
+ */
112
+ clear(): void;
113
+ /**
114
+ * Dispose the collection and all its items.
115
+ *
116
+ * After calling this, the collection should not be used.
117
+ */
118
+ dispose(): void;
119
+ /**
120
+ * Get all active items as a readonly array.
121
+ */
122
+ get all(): readonly T[];
123
+ /**
124
+ * Get all pending items as a readonly array.
125
+ */
126
+ get pending(): readonly T[];
127
+ /**
128
+ * Get the number of active items.
129
+ */
130
+ get length(): number;
131
+ /**
132
+ * Get the total number of items (active + pending).
133
+ */
134
+ get totalLength(): number;
135
+ /**
136
+ * Check if the collection is empty (no active items).
137
+ */
138
+ get isEmpty(): boolean;
139
+ /**
140
+ * Get an item at a specific index.
141
+ *
142
+ * @param index The index of the item
143
+ * @returns The item, or undefined if index is out of bounds
144
+ */
145
+ get(index: number): T | undefined;
146
+ /**
147
+ * Get the first item in the collection.
148
+ */
149
+ get first(): T | undefined;
150
+ /**
151
+ * Get the last item in the collection.
152
+ */
153
+ get last(): T | undefined;
154
+ /**
155
+ * Get the index of an item.
156
+ *
157
+ * @param item The item to find
158
+ * @returns The index, or -1 if not found
159
+ */
160
+ indexOf(item: T): number;
161
+ /**
162
+ * Check if an item exists in the collection.
163
+ *
164
+ * @param item The item to check
165
+ * @returns true if the item exists (in active or pending)
166
+ */
167
+ has(item: T): boolean;
168
+ /**
169
+ * Iterate over all active items.
170
+ */
171
+ [Symbol.iterator](): Iterator<T>;
172
+ /**
173
+ * Execute a callback for each active item.
174
+ *
175
+ * @param callback Function to execute for each item
176
+ */
177
+ forEach(callback: (item: T, index: number) => void): void;
178
+ /**
179
+ * Map active items to a new array.
180
+ *
181
+ * @param callback Function to transform each item
182
+ * @returns New array with transformed items
183
+ */
184
+ map<U>(callback: (item: T, index: number) => U): U[];
185
+ /**
186
+ * Filter active items.
187
+ *
188
+ * @param predicate Function to test each item
189
+ * @returns New array with items that pass the test
190
+ */
191
+ filter(predicate: (item: T, index: number) => boolean): T[];
192
+ /**
193
+ * Find an item matching a predicate.
194
+ *
195
+ * @param predicate Function to test each item
196
+ * @returns The first matching item, or undefined
197
+ */
198
+ find(predicate: (item: T, index: number) => boolean): T | undefined;
199
+ /**
200
+ * Find the index of an item matching a predicate.
201
+ *
202
+ * @param predicate Function to test each item
203
+ * @returns The index of the first matching item, or -1
204
+ */
205
+ findIndex(predicate: (item: T, index: number) => boolean): number;
206
+ /**
207
+ * Check if any item matches a predicate.
208
+ *
209
+ * @param predicate Function to test each item
210
+ * @returns true if any item matches
211
+ */
212
+ some(predicate: (item: T, index: number) => boolean): boolean;
213
+ /**
214
+ * Check if all items match a predicate.
215
+ *
216
+ * @param predicate Function to test each item
217
+ * @returns true if all items match
218
+ */
219
+ every(predicate: (item: T, index: number) => boolean): boolean;
220
+ /**
221
+ * Reduce active items to a single value.
222
+ *
223
+ * @param callback Reducer function
224
+ * @param initialValue Initial accumulator value
225
+ * @returns The final accumulated value
226
+ */
227
+ reduce<U>(callback: (accumulator: U, item: T, index: number) => U, initialValue: U): U;
228
+ /**
229
+ * Dispose a single item using the configured disposal callback.
230
+ */
231
+ private _disposeItem;
232
+ }
233
+ /**
234
+ * Configuration options for TextmodeCollection.
235
+ *
236
+ * @typeParam T - The type of items stored in the collection
237
+ */
238
+ export interface TextmodeCollectionOptions<T> {
239
+ /**
240
+ * Called when an item is added to the active collection.
241
+ * Not called for pending items until they become active.
242
+ */
243
+ onAdd?: (item: T) => void;
244
+ /**
245
+ * Called when an item is about to be removed from the collection.
246
+ * This is called before `onDispose`.
247
+ */
248
+ onRemove?: (item: T) => void;
249
+ /**
250
+ * Called to dispose an item when it's removed from the collection.
251
+ * This is where you should clean up resources.
252
+ */
253
+ onDispose?: (item: T) => void;
254
+ /**
255
+ * Called when an item is moved to a new index.
256
+ */
257
+ onMove?: (item: T, oldIndex: number, newIndex: number) => void;
258
+ /**
259
+ * Called when two items are swapped.
260
+ */
261
+ onSwap?: (itemA: T, itemB: T, indexA: number, indexB: number) => void;
262
+ }
@@ -1,3 +1,29 @@
1
+ /**
2
+ * Convert degrees to radians.
3
+ *
4
+ * @param degrees Angle in degrees
5
+ * @returns Angle in radians
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * degToRad(180); // Math.PI
10
+ * degToRad(90); // Math.PI / 2
11
+ * ```
12
+ */
13
+ export declare function degToRad(degrees: number): number;
14
+ /**
15
+ * Convert radians to degrees.
16
+ *
17
+ * @param radians Angle in radians
18
+ * @returns Angle in degrees
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * radToDeg(Math.PI); // 180
23
+ * radToDeg(Math.PI / 2); // 90
24
+ * ```
25
+ */
26
+ export declare function radToDeg(radians: number): number;
1
27
  /**
2
28
  * Calculate the angle in degrees between two points.
3
29
  * @param x1 - X coordinate of the first point
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "textmode.js",
3
- "version": "0.8.1",
3
+ "version": "0.8.5",
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",
@@ -11,6 +11,41 @@
11
11
  "types": "./dist/types/index.d.ts",
12
12
  "import": "./dist/textmode.esm.js",
13
13
  "require": "./dist/textmode.umd.js"
14
+ },
15
+ "./loadables": {
16
+ "types": "./dist/types/exports/loadables.d.ts",
17
+ "import": "./dist/textmode.esm.js",
18
+ "require": "./dist/textmode.umd.js"
19
+ },
20
+ "./conversion": {
21
+ "types": "./dist/types/exports/conversion.d.ts",
22
+ "import": "./dist/textmode.esm.js",
23
+ "require": "./dist/textmode.umd.js"
24
+ },
25
+ "./filters": {
26
+ "types": "./dist/types/exports/filters.d.ts",
27
+ "import": "./dist/textmode.esm.js",
28
+ "require": "./dist/textmode.umd.js"
29
+ },
30
+ "./loading": {
31
+ "types": "./dist/types/exports/loading.d.ts",
32
+ "import": "./dist/textmode.esm.js",
33
+ "require": "./dist/textmode.umd.js"
34
+ },
35
+ "./input": {
36
+ "types": "./dist/types/exports/input.d.ts",
37
+ "import": "./dist/textmode.esm.js",
38
+ "require": "./dist/textmode.umd.js"
39
+ },
40
+ "./layering": {
41
+ "types": "./dist/types/exports/layering.d.ts",
42
+ "import": "./dist/textmode.esm.js",
43
+ "require": "./dist/textmode.umd.js"
44
+ },
45
+ "./plugins": {
46
+ "types": "./dist/types/exports/plugins.d.ts",
47
+ "import": "./dist/textmode.esm.js",
48
+ "require": "./dist/textmode.umd.js"
14
49
  }
15
50
  },
16
51
  "scripts": {
@@ -60,7 +95,7 @@
60
95
  "design",
61
96
  "graphics"
62
97
  ],
63
- "author": "humanbydefinition",
98
+ "author": "humanbydefinition <hello@textmode.art> (https://code.textmode.art)",
64
99
  "license": "MIT",
65
100
  "bugs": {
66
101
  "url": "https://github.com/humanbydefinition/textmode.js/issues"