tiny-essentials 1.20.2 → 1.21.0

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 (123) hide show
  1. package/README.md +13 -11
  2. package/dist/_/numbers.cjs +136 -0
  3. package/dist/_/numbers.d.mts +24 -0
  4. package/dist/_/numbers.mjs +102 -0
  5. package/dist/v1/TinyAdvancedRaffle.min.js +1 -0
  6. package/dist/v1/TinyArrayPaginator.min.js +1 -0
  7. package/dist/v1/TinyBasicsEs.min.js +1 -1
  8. package/dist/v1/TinyCookieConsent.min.js +1 -0
  9. package/dist/v1/TinyDayNightCycle.min.js +1 -0
  10. package/dist/v1/TinyEssentials.min.js +1 -1
  11. package/dist/v1/TinyGamepad.min.js +1 -0
  12. package/dist/v1/TinyI18.min.js +1 -0
  13. package/dist/v1/TinyInventory.min.js +1 -0
  14. package/dist/v1/TinyInventoryTrader.min.js +1 -0
  15. package/dist/v1/TinyLocalStorage.min.js +1 -1
  16. package/dist/v1/TinyRateLimiter.min.js +1 -1
  17. package/dist/v1/TinySmartScroller.min.js +1 -1
  18. package/dist/v1/TinyTextarea.min.js +1 -0
  19. package/dist/v1/TinyToastNotify.min.js +1 -1
  20. package/dist/v1/TinyUploadClicker.min.js +1 -1
  21. package/dist/v1/basics/array.cjs +21 -0
  22. package/dist/v1/basics/array.d.mts +8 -0
  23. package/dist/v1/basics/array.mjs +18 -0
  24. package/dist/v1/basics/index.cjs +2 -8
  25. package/dist/v1/basics/index.d.mts +3 -8
  26. package/dist/v1/basics/index.mjs +2 -3
  27. package/dist/v1/basics/simpleMath.cjs +46 -0
  28. package/dist/v1/basics/simpleMath.d.mts +27 -0
  29. package/dist/v1/basics/simpleMath.mjs +42 -0
  30. package/dist/v1/build/TinyAdvancedRaffle.cjs +7 -0
  31. package/dist/v1/build/TinyAdvancedRaffle.d.mts +3 -0
  32. package/dist/v1/build/TinyAdvancedRaffle.mjs +2 -0
  33. package/dist/v1/build/TinyArrayPaginator.cjs +7 -0
  34. package/dist/v1/build/TinyArrayPaginator.d.mts +3 -0
  35. package/dist/v1/build/TinyArrayPaginator.mjs +2 -0
  36. package/dist/v1/build/TinyCookieConsent.cjs +7 -0
  37. package/dist/v1/build/TinyCookieConsent.d.mts +3 -0
  38. package/dist/v1/build/TinyCookieConsent.mjs +2 -0
  39. package/dist/v1/build/TinyDayNightCycle.cjs +7 -0
  40. package/dist/v1/build/TinyDayNightCycle.d.mts +3 -0
  41. package/dist/v1/build/TinyDayNightCycle.mjs +2 -0
  42. package/dist/v1/build/TinyGamepad.cjs +7 -0
  43. package/dist/v1/build/TinyGamepad.d.mts +3 -0
  44. package/dist/v1/build/TinyGamepad.mjs +2 -0
  45. package/dist/v1/build/TinyI18.cjs +7 -0
  46. package/dist/v1/build/TinyI18.d.mts +3 -0
  47. package/dist/v1/build/TinyI18.mjs +2 -0
  48. package/dist/v1/build/TinyInventory.cjs +7 -0
  49. package/dist/v1/build/TinyInventory.d.mts +3 -0
  50. package/dist/v1/build/TinyInventory.mjs +2 -0
  51. package/dist/v1/build/TinyInventoryTrader.cjs +7 -0
  52. package/dist/v1/build/TinyInventoryTrader.d.mts +3 -0
  53. package/dist/v1/build/TinyInventoryTrader.mjs +2 -0
  54. package/dist/v1/build/TinyTextarea.cjs +7 -0
  55. package/dist/v1/build/TinyTextarea.d.mts +3 -0
  56. package/dist/v1/build/TinyTextarea.mjs +2 -0
  57. package/dist/v1/css/TinyCookieConsent.min.css +1 -0
  58. package/dist/v1/index.cjs +20 -8
  59. package/dist/v1/index.d.mts +12 -8
  60. package/dist/v1/index.mjs +11 -3
  61. package/dist/v1/libs/TinyAdvancedRaffle.cjs +1654 -0
  62. package/dist/v1/libs/TinyAdvancedRaffle.d.mts +851 -0
  63. package/dist/v1/libs/TinyAdvancedRaffle.mjs +1477 -0
  64. package/dist/v1/libs/TinyArrayPaginator.cjs +132 -0
  65. package/dist/v1/libs/TinyArrayPaginator.d.mts +78 -0
  66. package/dist/v1/libs/TinyArrayPaginator.mjs +119 -0
  67. package/dist/v1/libs/TinyCookieConsent.cjs +278 -0
  68. package/dist/v1/libs/TinyCookieConsent.d.mts +142 -0
  69. package/dist/v1/libs/TinyCookieConsent.mjs +248 -0
  70. package/dist/v1/libs/TinyDayNightCycle.cjs +1389 -0
  71. package/dist/v1/libs/TinyDayNightCycle.d.mts +673 -0
  72. package/dist/v1/libs/TinyDayNightCycle.mjs +1232 -0
  73. package/dist/v1/libs/TinyGamepad.cjs +2690 -0
  74. package/dist/v1/libs/TinyGamepad.d.mts +1286 -0
  75. package/dist/v1/libs/TinyGamepad.mjs +2386 -0
  76. package/dist/v1/libs/TinyHtml.d.mts +2 -2
  77. package/dist/v1/libs/TinyI18.cjs +946 -0
  78. package/dist/v1/libs/TinyI18.d.mts +418 -0
  79. package/dist/v1/libs/TinyI18.mjs +873 -0
  80. package/dist/v1/libs/TinyInventory.cjs +1788 -0
  81. package/dist/v1/libs/TinyInventory.d.mts +871 -0
  82. package/dist/v1/libs/TinyInventory.mjs +1650 -0
  83. package/dist/v1/libs/TinyInventoryTrader.cjs +242 -0
  84. package/dist/v1/libs/TinyInventoryTrader.d.mts +95 -0
  85. package/dist/v1/libs/TinyInventoryTrader.mjs +212 -0
  86. package/dist/v1/libs/TinyLocalStorage.cjs +14 -1
  87. package/dist/v1/libs/TinyLocalStorage.mjs +8 -1
  88. package/dist/v1/libs/TinyRateLimiter.cjs +0 -13
  89. package/dist/v1/libs/TinyRateLimiter.d.mts +0 -8
  90. package/dist/v1/libs/TinyRateLimiter.mjs +0 -12
  91. package/dist/v1/libs/TinySmartScroller.cjs +51 -15
  92. package/dist/v1/libs/TinySmartScroller.d.mts +28 -12
  93. package/dist/v1/libs/TinySmartScroller.mjs +44 -14
  94. package/dist/v1/libs/TinyTextarea.cjs +230 -0
  95. package/dist/v1/libs/TinyTextarea.d.mts +128 -0
  96. package/dist/v1/libs/TinyTextarea.mjs +198 -0
  97. package/dist/v1/libs/TinyToastNotify.cjs +2 -2
  98. package/dist/v1/libs/TinyToastNotify.mjs +2 -2
  99. package/dist/v1/libs/TinyUploadClicker.cjs +1 -1
  100. package/docs/v1/Ai-Tips.md +51 -0
  101. package/docs/v1/Personal-Ai-Prompts(portuguese).md +134 -0
  102. package/docs/v1/Personal-Ai-Prompts.md +113 -0
  103. package/docs/v1/README.md +24 -0
  104. package/docs/v1/basics/array.md +17 -0
  105. package/docs/v1/basics/simpleMath.md +73 -0
  106. package/docs/v1/libs/TinyAdvancedRaffle.md +674 -0
  107. package/docs/v1/libs/TinyArrayPaginator.md +150 -0
  108. package/docs/v1/libs/TinyCookieConsent.md +152 -0
  109. package/docs/v1/libs/TinyDayNightCycle.md +711 -0
  110. package/docs/v1/libs/TinyGamepad.md +980 -0
  111. package/docs/v1/libs/TinyI18.md +515 -0
  112. package/docs/v1/libs/TinyInventory.md +777 -0
  113. package/docs/v1/libs/TinyInventoryTrader.md +114 -0
  114. package/docs/v1/libs/TinySmartScroller.md +4 -4
  115. package/docs/v1/libs/TinyTextarea.md +156 -0
  116. package/package.json +7 -5
  117. package/dist/v1/basics/html_deprecated.cjs +0 -124
  118. package/dist/v1/basics/html_deprecated.d.mts +0 -40
  119. package/dist/v1/basics/html_deprecated.mjs +0 -97
  120. package/dist/v1/css/TinyDraggerExample.css +0 -21
  121. package/dist/v1/css/TinyNotify.css +0 -350
  122. package/dist/v1/css/aiMarker.css +0 -4
  123. package/docs/v1/basics/html_deprecated.md +0 -127
@@ -0,0 +1,142 @@
1
+ export default TinyCookieConsent;
2
+ export type Category = {
3
+ /**
4
+ * - Category label displayed to the user
5
+ */
6
+ label: string;
7
+ /**
8
+ * - If true, cannot be disabled
9
+ */
10
+ required: boolean;
11
+ /**
12
+ * - Default state (true = enabled, false = disabled)
13
+ */
14
+ default: boolean;
15
+ };
16
+ export type Config = {
17
+ /**
18
+ * - Consent message
19
+ */
20
+ message: string;
21
+ /**
22
+ * - Text for "Accept All" button
23
+ */
24
+ acceptText: string;
25
+ /**
26
+ * - Text for "Reject All" button
27
+ */
28
+ rejectText: string;
29
+ /**
30
+ * - Text for "Manage Settings" button
31
+ */
32
+ settingsText: string;
33
+ /**
34
+ * - List of cookie categories
35
+ */
36
+ categories: Category[];
37
+ /**
38
+ * - Key used to store preferences
39
+ */
40
+ storageKey: string;
41
+ /**
42
+ * - Callback when preferences are saved
43
+ */
44
+ onSave: (preferences: Object) => void;
45
+ /**
46
+ * - Animation duration in ms
47
+ */
48
+ animationDuration?: number | undefined;
49
+ /**
50
+ * - Optional custom HTML renderer for consent bar
51
+ */
52
+ renderBar?: ((config: Config) => string) | null | undefined;
53
+ /**
54
+ * - Optional custom HTML renderer for modal
55
+ */
56
+ renderModal?: ((config: Config) => string) | null | undefined;
57
+ };
58
+ /**
59
+ * @typedef {Object} Category
60
+ * @property {string} label - Category label displayed to the user
61
+ * @property {boolean} required - If true, cannot be disabled
62
+ * @property {boolean} default - Default state (true = enabled, false = disabled)
63
+ */
64
+ /**
65
+ * @typedef {Object} Config
66
+ * @property {string} message - Consent message
67
+ * @property {string} acceptText - Text for "Accept All" button
68
+ * @property {string} rejectText - Text for "Reject All" button
69
+ * @property {string} settingsText - Text for "Manage Settings" button
70
+ * @property {Category[]} categories - List of cookie categories
71
+ * @property {string} storageKey - Key used to store preferences
72
+ * @property {(preferences: Object) => void} onSave - Callback when preferences are saved
73
+ * @property {number} [animationDuration=400] - Animation duration in ms
74
+ * @property {((config: Config) => string)|null} [renderBar] - Optional custom HTML renderer for consent bar
75
+ * @property {((config: Config) => string)|null} [renderModal] - Optional custom HTML renderer for modal
76
+ */
77
+ /**
78
+ * CookieConsent
79
+ *
80
+ * A flexible and customizable cookie consent manager.
81
+ * Features:
82
+ * - Displays a consent bar with customizable text and buttons.
83
+ * - Allows defining multiple cookie categories (required, analytics, ads, etc.).
84
+ * - Stores user preferences in localStorage.
85
+ * - Provides callbacks for when user accepts or denies categories.
86
+ * - Fully customizable via configuration.
87
+ */
88
+ declare class TinyCookieConsent {
89
+ /**
90
+ * @param {Config} config
91
+ */
92
+ constructor(config: Config);
93
+ /** @type {Record<string, boolean>} */
94
+ get preferences(): Record<string, boolean>;
95
+ /** @param {Config} value */
96
+ set config(value: Config);
97
+ /** @type {Config} */
98
+ get config(): Config;
99
+ /**
100
+ * Validates config object against jsDoc typedefs
101
+ * @param {Partial<Config>} config
102
+ */
103
+ validateConfig(config: Partial<Config>): void;
104
+ /**
105
+ * Validates a single category object
106
+ * @param {Category} cat
107
+ * @param {number} index
108
+ */
109
+ validateCategory(cat: Category, index: number): void;
110
+ /**
111
+ * Loads saved preferences from localStorage
112
+ * @returns {Record<string, boolean>|null}
113
+ */
114
+ loadPreferences(): Record<string, boolean> | null;
115
+ /**
116
+ * Smoothly removes an element with fade-out/slide-out animation
117
+ * @param {HTMLElement} el
118
+ */
119
+ removeWithAnimation(el: HTMLElement): void;
120
+ /**
121
+ * Saves preferences to localStorage
122
+ *
123
+ * @param {Record<string, boolean>} prefs
124
+ */
125
+ savePreferences(prefs: Record<string, boolean>): void;
126
+ /** Shows the initial consent bar */
127
+ showConsentBar(): void;
128
+ /**
129
+ * Shows settings modal for fine-grained control
130
+ *
131
+ * @param {HTMLElement} bar
132
+ */
133
+ showSettingsModal(bar: HTMLElement): void;
134
+ /**
135
+ * Checks if a category is allowed
136
+ * @param {string} category
137
+ * @returns {boolean}
138
+ */
139
+ isAllowed(category: string): boolean;
140
+ #private;
141
+ }
142
+ //# sourceMappingURL=TinyCookieConsent.d.mts.map
@@ -0,0 +1,248 @@
1
+ /**
2
+ * @typedef {Object} Category
3
+ * @property {string} label - Category label displayed to the user
4
+ * @property {boolean} required - If true, cannot be disabled
5
+ * @property {boolean} default - Default state (true = enabled, false = disabled)
6
+ */
7
+ /**
8
+ * @typedef {Object} Config
9
+ * @property {string} message - Consent message
10
+ * @property {string} acceptText - Text for "Accept All" button
11
+ * @property {string} rejectText - Text for "Reject All" button
12
+ * @property {string} settingsText - Text for "Manage Settings" button
13
+ * @property {Category[]} categories - List of cookie categories
14
+ * @property {string} storageKey - Key used to store preferences
15
+ * @property {(preferences: Object) => void} onSave - Callback when preferences are saved
16
+ * @property {number} [animationDuration=400] - Animation duration in ms
17
+ * @property {((config: Config) => string)|null} [renderBar] - Optional custom HTML renderer for consent bar
18
+ * @property {((config: Config) => string)|null} [renderModal] - Optional custom HTML renderer for modal
19
+ */
20
+ /**
21
+ * CookieConsent
22
+ *
23
+ * A flexible and customizable cookie consent manager.
24
+ * Features:
25
+ * - Displays a consent bar with customizable text and buttons.
26
+ * - Allows defining multiple cookie categories (required, analytics, ads, etc.).
27
+ * - Stores user preferences in localStorage.
28
+ * - Provides callbacks for when user accepts or denies categories.
29
+ * - Fully customizable via configuration.
30
+ */
31
+ class TinyCookieConsent {
32
+ /** @type {Record<string, boolean>} */
33
+ #preferences;
34
+ /** @type {Config} */
35
+ #config = {
36
+ message: 'We use cookies to improve your experience.',
37
+ acceptText: 'Accept All',
38
+ rejectText: 'Reject All',
39
+ settingsText: 'Manage Settings',
40
+ categories: [],
41
+ storageKey: 'cookie-consent-preferences',
42
+ onSave: (prefs) => console.log('Preferences saved:', prefs),
43
+ animationDuration: 400,
44
+ renderBar: null,
45
+ renderModal: null,
46
+ };
47
+ /** @type {Record<string, boolean>} */
48
+ get preferences() {
49
+ const saved = localStorage.getItem(this.#config.storageKey);
50
+ return saved ? JSON.parse(saved) : {};
51
+ }
52
+ /** @type {Config} */
53
+ get config() {
54
+ return { ...this.#config, categories: [...this.#config.categories] };
55
+ }
56
+ /** @param {Config} value */
57
+ set config(value) {
58
+ this.validateConfig(value);
59
+ this.#config = Object.assign(this.#config, value);
60
+ }
61
+ /**
62
+ * @param {Config} config
63
+ */
64
+ constructor(config) {
65
+ if (!config || typeof config !== 'object')
66
+ throw new TypeError('Config must be an object.');
67
+ this.config = config;
68
+ const prefs = this.loadPreferences();
69
+ this.#preferences = prefs ?? {};
70
+ if (!prefs)
71
+ this.showConsentBar();
72
+ }
73
+ /**
74
+ * Validates config object against jsDoc typedefs
75
+ * @param {Partial<Config>} config
76
+ */
77
+ validateConfig(config) {
78
+ if (typeof config.message !== 'undefined' && typeof config.message !== 'string')
79
+ throw new TypeError('Config.message must be a string.');
80
+ ['acceptText', 'rejectText', 'settingsText', 'storageKey'].forEach((key) => {
81
+ // @ts-ignore
82
+ if (typeof config[key] !== 'undefined' && typeof config[key] !== 'string') {
83
+ throw new TypeError(`Config.${key} must be a string.`);
84
+ }
85
+ });
86
+ if (typeof config.categories !== 'undefined') {
87
+ if (!Array.isArray(config.categories)) {
88
+ throw new TypeError('Config.categories must be an array of Category objects.');
89
+ }
90
+ config.categories.forEach((cat, i) => this.validateCategory(cat, i));
91
+ }
92
+ if (typeof config.onSave !== 'undefined' && typeof config.onSave !== 'function')
93
+ throw new TypeError('Config.onSave must be a function.');
94
+ if (typeof config.animationDuration !== 'undefined') {
95
+ if (typeof config.animationDuration !== 'number' || config.animationDuration < 0) {
96
+ throw new TypeError('Config.animationDuration must be a positive number.');
97
+ }
98
+ }
99
+ if (typeof config.renderBar !== 'undefined' &&
100
+ config.renderBar !== null &&
101
+ typeof config.renderBar !== 'function')
102
+ throw new TypeError('Config.renderBar must be a function or null.');
103
+ if (typeof config.renderModal !== 'undefined' &&
104
+ config.renderModal !== null &&
105
+ typeof config.renderModal !== 'function')
106
+ throw new TypeError('Config.renderModal must be a function or null.');
107
+ }
108
+ /**
109
+ * Validates a single category object
110
+ * @param {Category} cat
111
+ * @param {number} index
112
+ */
113
+ validateCategory(cat, index) {
114
+ if (!cat || typeof cat !== 'object')
115
+ throw new TypeError(`Category at index ${index} must be an object.`);
116
+ if (typeof cat.label !== 'string')
117
+ throw new TypeError(`Category.label at index ${index} must be a string.`);
118
+ if (typeof cat.required !== 'boolean')
119
+ throw new TypeError(`Category.required at index ${index} must be a boolean.`);
120
+ if (typeof cat.default !== 'boolean')
121
+ throw new TypeError(`Category.default at index ${index} must be a boolean.`);
122
+ }
123
+ /**
124
+ * Loads saved preferences from localStorage
125
+ * @returns {Record<string, boolean>|null}
126
+ */
127
+ loadPreferences() {
128
+ const saved = localStorage.getItem(this.#config.storageKey);
129
+ return saved ? JSON.parse(saved) : null;
130
+ }
131
+ /**
132
+ * Smoothly removes an element with fade-out/slide-out animation
133
+ * @param {HTMLElement} el
134
+ */
135
+ removeWithAnimation(el) {
136
+ if (!(el instanceof HTMLElement))
137
+ throw new TypeError('removeWithAnimation expects an HTMLElement.');
138
+ el.classList.add('closing');
139
+ setTimeout(() => el.remove(), this.#config.animationDuration);
140
+ }
141
+ /**
142
+ * Saves preferences to localStorage
143
+ *
144
+ * @param {Record<string, boolean>} prefs
145
+ */
146
+ savePreferences(prefs) {
147
+ if (!prefs || typeof prefs !== 'object')
148
+ throw new TypeError('Preferences must be an object.');
149
+ localStorage.setItem(this.#config.storageKey, JSON.stringify(prefs));
150
+ this.#config.onSave(prefs);
151
+ }
152
+ /** Shows the initial consent bar */
153
+ showConsentBar() {
154
+ const bar = document.createElement('div');
155
+ bar.className = 'cookie-consent-bar';
156
+ bar.innerHTML = this.#config.renderBar
157
+ ? this.#config.renderBar(this.#config)
158
+ : `
159
+ <div><p>${this.#config.message}</p></div>
160
+ <div><button class="accept">${this.#config.acceptText}</button></div>
161
+ <div><button class="reject">${this.#config.rejectText}</button></div>
162
+ <div><button class="settings">${this.#config.settingsText}</button></div>
163
+ `;
164
+ document.body.appendChild(bar);
165
+ const accept = bar.querySelector('.accept');
166
+ if (accept instanceof HTMLElement) {
167
+ accept.onclick = () => {
168
+ /** @type {Record<string, boolean>} */
169
+ const prefs = {};
170
+ this.#config.categories.forEach((cat) => (prefs[cat.label] = true));
171
+ this.savePreferences(prefs);
172
+ this.removeWithAnimation(bar);
173
+ };
174
+ }
175
+ const reject = bar.querySelector('.reject');
176
+ if (reject instanceof HTMLElement) {
177
+ reject.onclick = () => {
178
+ /** @type {Record<string, boolean>} */
179
+ const prefs = {};
180
+ this.#config.categories.forEach((cat) => (prefs[cat.label] = cat.required));
181
+ this.savePreferences(prefs);
182
+ this.removeWithAnimation(bar);
183
+ };
184
+ }
185
+ const settings = bar.querySelector('.settings');
186
+ if (settings instanceof HTMLElement) {
187
+ settings.onclick = () => this.showSettingsModal(bar);
188
+ }
189
+ }
190
+ /**
191
+ * Shows settings modal for fine-grained control
192
+ *
193
+ * @param {HTMLElement} bar
194
+ */
195
+ showSettingsModal(bar) {
196
+ const modal = document.createElement('div');
197
+ modal.className = 'cookie-consent-modal';
198
+ modal.innerHTML = this.#config.renderModal
199
+ ? this.#config.renderModal(this.#config)
200
+ : `
201
+ <div class="modal-content">
202
+ <h2>Cookie Settings</h2>
203
+ <form class="settings-form">
204
+ ${this.#config.categories
205
+ .map((cat) => `
206
+ <label>
207
+ <input type="checkbox" name="${cat.label}"
208
+ ${cat.default ? 'checked' : ''}
209
+ ${cat.required ? 'disabled' : ''}>
210
+ ${cat.label}
211
+ </label>
212
+ `)
213
+ .join('')}
214
+ </form>
215
+ <button class="save">Save Preferences</button>
216
+ </div>
217
+ `;
218
+ document.body.appendChild(modal);
219
+ const save = modal.querySelector('.save');
220
+ if (save instanceof HTMLElement) {
221
+ save.onclick = () => {
222
+ /** @type {Record<string, boolean>} */
223
+ const prefs = {};
224
+ modal.querySelectorAll('input[type=checkbox]').forEach((input) => {
225
+ if (input instanceof HTMLInputElement)
226
+ prefs[input.name] = input.checked;
227
+ });
228
+ this.savePreferences(prefs);
229
+ this.removeWithAnimation(modal);
230
+ if (bar)
231
+ this.removeWithAnimation(bar);
232
+ };
233
+ }
234
+ }
235
+ /**
236
+ * Checks if a category is allowed
237
+ * @param {string} category
238
+ * @returns {boolean}
239
+ */
240
+ isAllowed(category) {
241
+ if (typeof category !== 'string')
242
+ throw new TypeError('isAllowed expects a string as category.');
243
+ if (!this.#preferences)
244
+ return false;
245
+ return !!this.#preferences[category];
246
+ }
247
+ }
248
+ export default TinyCookieConsent;