tiny-essentials 1.25.0 โ†’ 1.25.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.
@@ -0,0 +1,295 @@
1
+ # ๐Ÿ•ฐ๏ธ TinyAnalogClock
2
+
3
+ **TinyAnalogClock** is a dependency-free JavaScript class for rendering fully customizable analog clocks. It supports dynamic resizing, custom skins (background images), flexible coloring, advanced geometry tuning, and rigorous input validation.
4
+
5
+ ## โœจ Features
6
+
7
+ * **Zero Dependencies:** Pure JavaScript (ESM).
8
+ * **Fully Customizable:** Control colors, sizes, layout, and internal geometry.
9
+ * **Scalable:** All internal elements (hands, numbers, ticks) scale mathematically based on the `size`.
10
+ * **Dynamic API:** Update **any** property (colors, padding, tick thickness, etc.) in real-time using setters.
11
+ * **Type Safe:** Built-in validation throws errors if invalid data types are passed.
12
+
13
+ ---
14
+
15
+ ## ๐Ÿš€ Getting Started
16
+
17
+ ### 1. Import the Class
18
+
19
+ Import the class into your JavaScript module.
20
+
21
+ ```javascript
22
+ import TinyAnalogClock from './TinyAnalogClock.js';
23
+ ```
24
+
25
+ ### 2. Basic Usage
26
+
27
+ Create an instance and append its element to your DOM.
28
+
29
+ ```javascript
30
+ // 1. Create the clock instance
31
+ const myClock = new TinyAnalogClock({
32
+ size: 400,
33
+ showSeconds: true
34
+ });
35
+
36
+ // 2. Append the generated HTML to your page
37
+ document.body.appendChild(myClock.element);
38
+
39
+ ```
40
+
41
+ ---
42
+
43
+ ## โš™๏ธ Configuration
44
+
45
+ You can pass an options object to the **constructor**. All properties are optional; defaults will be used if omitted.
46
+
47
+ | Property | Type | Default | Description |
48
+ | --- | --- | --- | --- |
49
+ | `size` | `number` | `800` | Total width/height of the clock in pixels. |
50
+ | `bgColor` | `string` | `'#f0f0f0'` | Background color of the clock face. |
51
+ | `borderColor` | `string` | `'#333'` | Color of the outer border. |
52
+ | `borderWidth` | `number` | `8` | Thickness of the outer border in pixels. |
53
+ | `markColor` | `string` | `'#333'` | Color of the minute/hour tick marks. |
54
+ | `textColor` | `string` | `'#000'` | Color of the numbers (1-12). |
55
+ | `hourHandColor` | `string` | `'#000'` | Color of the hour hand. |
56
+ | `minuteHandColor` | `string` | `'#444'` | Color of the minute hand. |
57
+ | `secondHandColor` | `string` | `'#d81c1c'` | Color of the second hand. |
58
+ | `skinUrl` | `string|null` | `null` | URL of an image to use as background. |
59
+ | `showNumbers` | `boolean` | `true` | Show/Hide numbers on the face. |
60
+ | `showSeconds` | `boolean` | `true` | Show/Hide the second hand. |
61
+ | `padding` | `number` | `45` | Padding in pixels between the clock edge and the tick marks. |
62
+ | `sizeAdjust` | `number` | `0.04` | Scale factor for the numbers font size relative to clock size. |
63
+ | `angleDistance` | `number` | `0.95` | Distance multiplier (0-1) for placing numbers relative to the radius. |
64
+ | `pwH` | `number` | `0.008` | Hour tick **width** as a percentage of clock size (0.0 - 1.0). |
65
+ | `phH` | `number` | `0.08` | Hour tick **height** as a percentage of clock size (0.0 - 1.0). |
66
+ | `pwM` | `number` | `0.005` | Minute tick **width** as a percentage of clock size (0.0 - 1.0). |
67
+ | `phM` | `number` | `0.03` | Minute tick **height** as a percentage of clock size (0.0 - 1.0). |
68
+
69
+ ---
70
+
71
+ ## ๐Ÿ› ๏ธ API Reference
72
+
73
+ ### Properties & Setters
74
+
75
+ The class provides strict setters to update **every aspect** of the clock dynamically.
76
+ **Note:** Invalid inputs (wrong types or negative numbers where forbidden) will throw an `Error`.
77
+
78
+ #### Core Properties
79
+
80
+ ##### `element`
81
+
82
+ * **Returns:** `HTMLElement`
83
+ * **Description:** The main container of the clock. Use this to append the clock to your DOM.
84
+
85
+ ##### `size`
86
+
87
+ * **Type:** `number` (positive)
88
+ * **Description:** Updates the dimensions of the clock. Triggers a full re-render.
89
+
90
+ ```javascript
91
+ clock.size = 500;
92
+ ```
93
+
94
+ ##### `skinUrl`
95
+
96
+ * **Type:** `string | null`
97
+ * **Description:** Sets a background image. Set to `null` to use `bgColor`.
98
+
99
+ ```javascript
100
+ clock.skinUrl = './assets/wood-texture.jpg';
101
+ ```
102
+
103
+ ##### `bgColor`
104
+
105
+ * **Type:** `string`
106
+ * **Description:** Updates the background color (visible if no skin is set).
107
+
108
+ ```javascript
109
+ clock.bgColor = '#fafafa';
110
+ ```
111
+
112
+ #### Border & Colors
113
+
114
+ ##### `borderColor` / `borderWidth`
115
+
116
+ * **Description:** Control the outer border style.
117
+
118
+ ```javascript
119
+ clock.borderColor = '#ff0055';
120
+ clock.borderWidth = 12;
121
+ ```
122
+
123
+ ##### `markColor` / `textColor`
124
+
125
+ * **Description:** Colors for the tick marks and the numbers.
126
+
127
+ ```javascript
128
+ clock.markColor = '#444';
129
+ clock.textColor = '#222';
130
+ ```
131
+
132
+ ##### `hourHandColor` / `minuteHandColor` / `secondHandColor`
133
+
134
+ * **Description:** Individual colors for each hand.
135
+
136
+ ```javascript
137
+ clock.secondHandColor = 'red';
138
+ ```
139
+
140
+ #### Visibility & Layout
141
+
142
+ ##### `showNumbers`
143
+
144
+ * **Type:** `boolean`
145
+ * **Description:** Toggles the numbers 1-12.
146
+
147
+ ```javascript
148
+ clock.showNumbers = false;
149
+ ```
150
+
151
+ ##### `showSeconds`
152
+
153
+ * **Type:** `boolean`
154
+ * **Description:** Toggles the second hand visibility.
155
+
156
+ ```javascript
157
+ clock.showSeconds = false;
158
+ ```
159
+
160
+ ##### `padding`
161
+
162
+ * **Type:** `number` (non-negative)
163
+ * **Description:** Adjusts space between the outer edge and the ticks.
164
+
165
+ ```javascript
166
+ clock.padding = 20; // Move ticks closer to edge
167
+ ```
168
+
169
+ #### Advanced Geometry (Fine Tuning)
170
+
171
+ ##### `sizeAdjust`
172
+
173
+ * **Type:** `number` (positive)
174
+ * **Description:** Scales the font size of the numbers.
175
+
176
+ ```javascript
177
+ clock.sizeAdjust = 0.15; // Make numbers huge
178
+ ```
179
+
180
+ ##### `angleDistance`
181
+
182
+ * **Type:** `number` (positive)
183
+ * **Description:** Controls how far from the center the numbers are placed (percentage of radius).
184
+
185
+ ```javascript
186
+ clock.angleDistance = 0.80; // Move numbers closer to center
187
+ ```
188
+
189
+ ##### `pwH`, `phH` (Hour Ticks)
190
+
191
+ * **Type:** `number` (positive)
192
+ * **Description:** Width and Height of **Hour** ticks (percentage of clock size).
193
+
194
+ ```javascript
195
+ clock.pwH = 0.02; // Thicker hour lines
196
+ clock.phH = 0.15; // Longer hour lines
197
+ ```
198
+
199
+ ##### `pwM`, `phM` (Minute Ticks)
200
+
201
+ * **Type:** `number` (positive)
202
+ * **Description:** Width and Height of **Minute** ticks (percentage of clock size).
203
+
204
+ ```javascript
205
+ clock.pwM = 0.01; // Thicker minute lines
206
+ ```
207
+
208
+ ### Methods
209
+
210
+ #### `destroy()`
211
+
212
+ Stops the internal animation loop (`requestAnimationFrame`) and removes the element from the DOM. **Always call this when removing the clock to prevent memory leaks.**
213
+
214
+ ```javascript
215
+ // When you are done with the clock
216
+ myClock.destroy();
217
+ ```
218
+
219
+ ---
220
+
221
+ ## ๐ŸŽจ Advanced Examples
222
+
223
+ ### Example 1: Dark Mode Clock
224
+
225
+ ```javascript
226
+ const darkClock = new TinyAnalogClock({
227
+ size: 300,
228
+ bgColor: '#222',
229
+ borderColor: '#444',
230
+ markColor: '#888',
231
+ textColor: '#fff',
232
+ hourHandColor: '#fff',
233
+ minuteHandColor: '#ccc',
234
+ secondHandColor: '#ffcc00'
235
+ });
236
+
237
+ document.getElementById('app').appendChild(darkClock.element);
238
+ ```
239
+
240
+ ### Example 2: Minimalist Modern
241
+
242
+ A clock with no numbers, thin lines, and a sleek look.
243
+
244
+ ```javascript
245
+ const modernClock = new TinyAnalogClock({
246
+ size: 400,
247
+ showNumbers: false,
248
+ borderWidth: 2,
249
+ borderColor: '#000',
250
+ markColor: '#999',
251
+ hourHandColor: '#000',
252
+ minuteHandColor: '#555',
253
+ secondHandColor: '#d81c1c',
254
+ padding: 10,
255
+ pwH: 0.005, // Very thin hour ticks
256
+ pwM: 0.002 // Ultra thin minute ticks
257
+ });
258
+
259
+ document.body.appendChild(modernClock.element);
260
+ ```
261
+
262
+ ### Example 3: Chunky & Colorful
263
+
264
+ A clock with thick borders, large numbers, and custom colors.
265
+
266
+ ```javascript
267
+ const chunkyClock = new TinyAnalogClock({
268
+ size: 500,
269
+ bgColor: '#2a2a2a',
270
+ borderColor: '#ffeb3b', // Yellow border
271
+ borderWidth: 20,
272
+ textColor: '#ffeb3b',
273
+ sizeAdjust: 0.12, // Large numbers
274
+ padding: 60,
275
+ hourHandColor: '#fff',
276
+ minuteHandColor: '#ccc',
277
+ secondHandColor: '#ffeb3b'
278
+ });
279
+
280
+ document.body.appendChild(chunkyClock.element);
281
+ ```
282
+
283
+ ---
284
+
285
+ ### โš ๏ธ Error Handling
286
+
287
+ The class ensures data integrity. If you try to set an invalid value, it will fail loudly to help you debug:
288
+
289
+ ```javascript
290
+ try {
291
+ clock.size = -100; // โŒ Throws Error: 'size' must be a positive number.
292
+ } catch (e) {
293
+ console.error(e.message);
294
+ }
295
+ ```
@@ -0,0 +1,114 @@
1
+ # ๐Ÿ“ TinyTextDiffer โ€” Text Comparison Tool
2
+
3
+ Welcome to **TinyTextDiffer**! This is a lightweight, history-based utility designed to compute granular differences between text versions, mimicking the logic used by modern version control systems like GitHub.
4
+
5
+ It uses the **Longest Common Subsequence (LCS)** algorithm to ensure that changes are detected accurately at the character level, providing a clean "Added/Deleted/Normal" parse for your UI.
6
+
7
+ ---
8
+
9
+ ## โœจ Features
10
+
11
+ * ๐Ÿ“œ **Version History**: Store and manage multiple versions of a string.
12
+ * ๐Ÿ” **Granular Diff**: Detects specific changes (additions, removals, or unchanged text).
13
+ * ๐Ÿ›ก๏ธ **Type Safety**: Robust internal validations for indices and data types.
14
+ * ๐Ÿงน **Memory Management**: Includes `clear()` and `destroy()` methods to prevent memory leaks.
15
+ * ๐Ÿ“ฆ **ESM Ready**: Built with modern JavaScript using `import/export`.
16
+
17
+ ---
18
+
19
+ ## ๐Ÿš€ Installation & Setup
20
+
21
+ Since this is an ES Module, you can simply import it into your project:
22
+
23
+ ```javascript
24
+ import TinyTextDiffer from './TinyTextDiffer.js';
25
+
26
+ const differ = new TinyTextDiffer(["Initial text", "Updated text!"]);
27
+
28
+ ```
29
+
30
+ ---
31
+
32
+ ## ๐Ÿ“š API Reference
33
+
34
+ ### ๐Ÿ—๏ธ Constructor
35
+
36
+ `new TinyTextDiffer(history)`
37
+
38
+ * **history** (`string[]`): Optional. Initial array of text versions.
39
+
40
+ ---
41
+
42
+ ### ๐Ÿ› ๏ธ Methods
43
+
44
+ | Method | Parameters | Returns | Description |
45
+ | --- | --- | --- | --- |
46
+ | `add` | `text: string` | `void` | Appends a new version to the end of the history. |
47
+ | `addAt` | `index: number, text: string` | `void` | Inserts a version at a specific position. |
48
+ | `compare` | `...indexes: number` | `DiffResult[][]` | Compares pairs of indices and returns the differences. |
49
+ | `get` | `index: number` | `string` | Retrieves the text at the specified index. |
50
+ | `has` | `index: number` | `boolean` | Checks if a version exists at the specified index. |
51
+ | `remove` | `none` | `string` | Removes and returns the last version in history. |
52
+ | `removeAt` | `index: number` | `boolean` | Removes a specific version and returns `true` if successful. |
53
+ | `clear` | `none` | `void` | Wipes the entire history. |
54
+ | `destroy` | `none` | `void` | Marks the instance as destroyed and frees memory. |
55
+
56
+ ---
57
+
58
+ ### ๐Ÿ“Š Data Types
59
+
60
+ #### `DiffResult`
61
+
62
+ The `compare` method returns an array of these objects:
63
+
64
+ ```javascript
65
+ /**
66
+ * @typedef {Object} DiffResult
67
+ * @property {string} value - The actual string content.
68
+ * @property {"normal"|"added"|"deleted"} type - The status of the segment.
69
+ */
70
+ ```
71
+
72
+ ---
73
+
74
+ ## ๐Ÿ’ก Usage Example
75
+
76
+ Comparing two versions to see what changed:
77
+
78
+ ```javascript
79
+ const differ = new TinyTextDiffer(["Hello World", "Hello World!"]);
80
+
81
+ // Comparing index 0 with index 1
82
+ const [result] = differ.compare(0, 1);
83
+
84
+ console.log(result);
85
+ /*
86
+ Output:
87
+ [
88
+ { value: "Hello World", type: "normal" },
89
+ { value: "!", type: "added" }
90
+ ]
91
+ */
92
+ ```
93
+
94
+ ---
95
+
96
+ ## โš™๏ธ Technical Details
97
+
98
+ ### The Algorithm
99
+
100
+ The core of this tool is the `_computeDiff` private method. It implements a dynamic programming approach to find the **Longest Common Subsequence**.
101
+
102
+ 1. It builds a comparison matrix between two strings.
103
+ 2. It traces back the path to identify where characters were added or removed.
104
+ 3. It optimizes the output by grouping consecutive characters of the same type (e.g., merging "H", "e", "l", "l", "o" into "Hello").
105
+
106
+ ---
107
+
108
+ ## ๐Ÿ›ก๏ธ Error Handling
109
+
110
+ This class is designed to be "loud" about misuse to help you debug faster:
111
+
112
+ * Throws `TypeError` if you try to add non-string values.
113
+ * Throws `Error` if you try to access indices out of bounds.
114
+ * Throws `Error` if you attempt to use the instance after calling `destroy()`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-essentials",
3
- "version": "1.25.0",
3
+ "version": "1.25.2",
4
4
  "description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
5
5
  "scripts": {
6
6
  "test": "npm run test:mjs && npm run test:cjs && npm run test:js",
@@ -216,6 +216,10 @@
216
216
  "require": "./dist/v1/libs/TinyDragger.cjs",
217
217
  "import": "./dist/v1/libs/TinyDragger.mjs"
218
218
  },
219
+ "./libs/TinyTextDiffer": {
220
+ "require": "./dist/v1/libs/TinyTextDiffer.cjs",
221
+ "import": "./dist/v1/libs/TinyTextDiffer.mjs"
222
+ },
219
223
  "./libs/TinyDragDropDetector": {
220
224
  "require": "./dist/v1/libs/TinyDragDropDetector.cjs",
221
225
  "import": "./dist/v1/libs/TinyDragDropDetector.mjs"
@@ -248,6 +252,10 @@
248
252
  "require": "./dist/v1/libs/TinyAfterScrollWatcher.cjs",
249
253
  "import": "./dist/v1/libs/TinyAfterScrollWatcher.mjs"
250
254
  },
255
+ "./libs/TinyAnalogClock": {
256
+ "require": "./dist/v1/libs/TinyAnalogClock.cjs",
257
+ "import": "./dist/v1/libs/TinyAnalogClock.mjs"
258
+ },
251
259
  "./libs/TinyAdvancedRaffle": {
252
260
  "require": "./dist/v1/libs/TinyAdvancedRaffle.cjs",
253
261
  "import": "./dist/v1/libs/TinyAdvancedRaffle.mjs"