tiny-essentials 1.15.0 → 1.16.1

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 (47) hide show
  1. package/dist/v1/TinyAfterScrollWatcher.js +196 -0
  2. package/dist/v1/TinyAfterScrollWatcher.min.js +1 -0
  3. package/dist/v1/TinyBasicsEs.js +5058 -745
  4. package/dist/v1/TinyBasicsEs.min.js +1 -1
  5. package/dist/v1/TinyDragger.js +4874 -546
  6. package/dist/v1/TinyDragger.min.js +1 -1
  7. package/dist/v1/TinyEssentials.js +5299 -750
  8. package/dist/v1/TinyEssentials.min.js +1 -1
  9. package/dist/v1/TinyHtml.js +4815 -0
  10. package/dist/v1/TinyHtml.min.js +1 -0
  11. package/dist/v1/TinyUploadClicker.js +5093 -298
  12. package/dist/v1/TinyUploadClicker.min.js +1 -1
  13. package/dist/v1/basics/html.cjs +5 -187
  14. package/dist/v1/basics/html.d.mts +2 -53
  15. package/dist/v1/basics/html.mjs +5 -161
  16. package/dist/v1/basics/html_deprecated.cjs +124 -0
  17. package/dist/v1/basics/html_deprecated.d.mts +40 -0
  18. package/dist/v1/basics/html_deprecated.mjs +97 -0
  19. package/dist/v1/basics/index.cjs +8 -7
  20. package/dist/v1/basics/index.d.mts +7 -7
  21. package/dist/v1/basics/index.mjs +2 -1
  22. package/dist/v1/build/TinyAfterScrollWatcher.cjs +7 -0
  23. package/dist/v1/build/TinyAfterScrollWatcher.d.mts +3 -0
  24. package/dist/v1/build/TinyAfterScrollWatcher.mjs +2 -0
  25. package/dist/v1/build/TinyHtml.cjs +7 -0
  26. package/dist/v1/build/TinyHtml.d.mts +3 -0
  27. package/dist/v1/build/TinyHtml.mjs +2 -0
  28. package/dist/v1/index.cjs +12 -7
  29. package/dist/v1/index.d.mts +10 -8
  30. package/dist/v1/index.mjs +5 -2
  31. package/dist/v1/libs/TinyAfterScrollWatcher.cjs +157 -0
  32. package/dist/v1/libs/TinyAfterScrollWatcher.d.mts +86 -0
  33. package/dist/v1/libs/TinyAfterScrollWatcher.mjs +138 -0
  34. package/dist/v1/libs/TinyDragger.cjs +91 -16
  35. package/dist/v1/libs/TinyDragger.d.mts +78 -2
  36. package/dist/v1/libs/TinyDragger.mjs +93 -17
  37. package/dist/v1/libs/TinyHtml.cjs +4347 -0
  38. package/dist/v1/libs/TinyHtml.d.mts +2301 -0
  39. package/dist/v1/libs/TinyHtml.mjs +3926 -0
  40. package/dist/v1/libs/TinyUploadClicker.cjs +1 -0
  41. package/docs/v1/README.md +11 -10
  42. package/docs/v1/basics/html.md +0 -130
  43. package/docs/v1/basics/html_deprecated.md +127 -0
  44. package/docs/v1/libs/TinyAfterScrollWatcher.md +181 -0
  45. package/docs/v1/libs/TinyDragger.md +45 -15
  46. package/docs/v1/libs/TinyHtml.md +1658 -0
  47. package/package.json +4 -1
@@ -0,0 +1,196 @@
1
+ /******/ (() => { // webpackBootstrap
2
+ /******/ "use strict";
3
+ /******/ // The require scope
4
+ /******/ var __webpack_require__ = {};
5
+ /******/
6
+ /************************************************************************/
7
+ /******/ /* webpack/runtime/define property getters */
8
+ /******/ (() => {
9
+ /******/ // define getter functions for harmony exports
10
+ /******/ __webpack_require__.d = (exports, definition) => {
11
+ /******/ for(var key in definition) {
12
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
13
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
14
+ /******/ }
15
+ /******/ }
16
+ /******/ };
17
+ /******/ })();
18
+ /******/
19
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
20
+ /******/ (() => {
21
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
22
+ /******/ })();
23
+ /******/
24
+ /************************************************************************/
25
+ var __webpack_exports__ = {};
26
+
27
+ // EXPORTS
28
+ __webpack_require__.d(__webpack_exports__, {
29
+ TinyAfterScrollWatcher: () => (/* reexport */ libs_TinyAfterScrollWatcher)
30
+ });
31
+
32
+ ;// ./src/v1/libs/TinyAfterScrollWatcher.mjs
33
+ /**
34
+ * @typedef {(() => void)} FnData - Function with no arguments and no return value
35
+ */
36
+
37
+ /**
38
+ * A function that handles a scroll event.
39
+ * It receives a standard `Event` object when a scroll occurs.
40
+ *
41
+ * @typedef {(ev: Event) => void} OnScrollFunc
42
+ */
43
+
44
+ /**
45
+ * A scroll tracker that queues functions to be executed
46
+ * after the user stops scrolling a specific element or the window.
47
+ */
48
+ class TinyAfterScrollWatcher {
49
+ /** @type {Element|Window} */
50
+ #scrollTarget;
51
+
52
+ /** @type {number} */
53
+ lastScrollTime = 0;
54
+
55
+ /** @type {FnData[]} */
56
+ #afterScrollQueue = [];
57
+
58
+ /** @type {number} */
59
+ #inactivityTime = 100;
60
+
61
+ /** @type {Set<OnScrollFunc>} */
62
+ #externalScrollListeners = new Set();
63
+
64
+ /** @type {boolean} */
65
+ #destroyed = false;
66
+
67
+ /**
68
+ * @param {Element|Window} scrollTarget - The element or window to track scrolling on
69
+ * @param {number} [inactivityTime=100] - Time in milliseconds to wait after scroll ends before executing the queue
70
+ * @throws {TypeError} If scrollTarget is not a valid Element or Window
71
+ * @throws {TypeError} If inactivityTime is not a positive number
72
+ */
73
+ constructor(scrollTarget = window, inactivityTime = 100) {
74
+ if (!(scrollTarget instanceof Element) && !(scrollTarget instanceof Window))
75
+ throw new TypeError('scrollTarget must be an Element or the Window object.');
76
+ this.#scrollTarget = scrollTarget;
77
+
78
+ this._onScroll = this._onScroll.bind(this);
79
+ this._checkQueue = this._checkQueue.bind(this);
80
+
81
+ this.#scrollTarget.addEventListener('scroll', this._onScroll);
82
+ this.#inactivityTime = inactivityTime;
83
+
84
+ requestAnimationFrame(this._checkQueue);
85
+ }
86
+
87
+ /**
88
+ * Gets the current inactivity time in milliseconds.
89
+ * @returns {number}
90
+ */
91
+ get inactivityTime() {
92
+ return this.#inactivityTime;
93
+ }
94
+
95
+ /**
96
+ * Sets a new inactivity time.
97
+ * Must be a positive number (in milliseconds).
98
+ * @param {number} value
99
+ * @throws {Error} If value is not a positive number
100
+ */
101
+ set inactivityTime(value) {
102
+ if (typeof value !== 'number' || value <= 0 || !Number.isFinite(value))
103
+ throw new Error('inactivityTime must be a positive number in milliseconds.');
104
+ this.#inactivityTime = value;
105
+ }
106
+
107
+ /**
108
+ * Internal handler for scroll events.
109
+ * Updates the last scroll timestamp.
110
+ * @private
111
+ */
112
+ _onScroll() {
113
+ this.lastScrollTime = Date.now();
114
+ }
115
+
116
+ /**
117
+ * Continuously checks whether the user has stopped scrolling,
118
+ * and if so, runs all queued functions.
119
+ * @private
120
+ */
121
+ _checkQueue() {
122
+ if (this.#destroyed) return;
123
+ requestAnimationFrame(this._checkQueue);
124
+
125
+ if (Date.now() - this.lastScrollTime > this.#inactivityTime) {
126
+ while (this.#afterScrollQueue.length) {
127
+ const fn = this.#afterScrollQueue.pop();
128
+ if (typeof fn === 'function') fn();
129
+ }
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Adds a function to be executed after scroll has stopped.
135
+ * The scroll is considered "stopped" after the configured inactivity time.
136
+ *
137
+ * @param {() => void} fn - A function to execute once scrolling has stopped.
138
+ * @throws {TypeError} If the argument is not a function.
139
+ */
140
+ doAfterScroll(fn) {
141
+ if (typeof fn !== 'function') throw new TypeError('Argument must be a function.');
142
+ this.lastScrollTime = Date.now();
143
+ this.#afterScrollQueue.push(fn);
144
+ }
145
+
146
+ /**
147
+ * Registers an external scroll listener on the tracked element.
148
+ *
149
+ * @param {OnScrollFunc} fn - The scroll listener to add
150
+ * @throws {TypeError} If the argument is not a function.
151
+ */
152
+ onScroll(fn) {
153
+ if (typeof fn !== 'function') throw new TypeError('Argument must be a function.');
154
+ this.#scrollTarget.addEventListener('scroll', fn);
155
+ this.#externalScrollListeners.add(fn);
156
+ }
157
+
158
+ /**
159
+ * Removes a previously registered scroll listener from the tracked element.
160
+ *
161
+ * @param {OnScrollFunc} fn - The scroll listener to remove
162
+ * @throws {TypeError} If the argument is not a function.
163
+ */
164
+ offScroll(fn) {
165
+ if (typeof fn !== 'function') throw new TypeError('Argument must be a function.');
166
+ if (this.#externalScrollListeners.has(fn)) {
167
+ this.#scrollTarget.removeEventListener('scroll', fn);
168
+ this.#externalScrollListeners.delete(fn);
169
+ }
170
+ }
171
+
172
+ /**
173
+ * Destroys the watcher by removing internal listeners and clearing data.
174
+ */
175
+ destroy() {
176
+ if (this.#destroyed) return;
177
+ this.#destroyed = true;
178
+
179
+ this.#scrollTarget.removeEventListener('scroll', this._onScroll);
180
+ for (const fn of this.#externalScrollListeners)
181
+ this.#scrollTarget.removeEventListener('scroll', fn);
182
+
183
+ this.#externalScrollListeners.clear();
184
+ }
185
+ }
186
+
187
+ /* harmony default export */ const libs_TinyAfterScrollWatcher = (TinyAfterScrollWatcher);
188
+
189
+ ;// ./src/v1/build/TinyAfterScrollWatcher.mjs
190
+
191
+
192
+
193
+
194
+ window.TinyAfterScrollWatcher = __webpack_exports__.TinyAfterScrollWatcher;
195
+ /******/ })()
196
+ ;
@@ -0,0 +1 @@
1
+ (()=>{"use strict";var e={d:(t,r)=>{for(var i in r)e.o(r,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:r[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{TinyAfterScrollWatcher:()=>r});const r=class{#e;lastScrollTime=0;#t=[];#r=100;#i=new Set;#o=!1;constructor(e=window,t=100){if(!(e instanceof Element||e instanceof Window))throw new TypeError("scrollTarget must be an Element or the Window object.");this.#e=e,this._onScroll=this._onScroll.bind(this),this._checkQueue=this._checkQueue.bind(this),this.#e.addEventListener("scroll",this._onScroll),this.#r=t,requestAnimationFrame(this._checkQueue)}get inactivityTime(){return this.#r}set inactivityTime(e){if("number"!=typeof e||e<=0||!Number.isFinite(e))throw new Error("inactivityTime must be a positive number in milliseconds.");this.#r=e}_onScroll(){this.lastScrollTime=Date.now()}_checkQueue(){if(!this.#o&&(requestAnimationFrame(this._checkQueue),Date.now()-this.lastScrollTime>this.#r))for(;this.#t.length;){const e=this.#t.pop();"function"==typeof e&&e()}}doAfterScroll(e){if("function"!=typeof e)throw new TypeError("Argument must be a function.");this.lastScrollTime=Date.now(),this.#t.push(e)}onScroll(e){if("function"!=typeof e)throw new TypeError("Argument must be a function.");this.#e.addEventListener("scroll",e),this.#i.add(e)}offScroll(e){if("function"!=typeof e)throw new TypeError("Argument must be a function.");this.#i.has(e)&&(this.#e.removeEventListener("scroll",e),this.#i.delete(e))}destroy(){if(!this.#o){this.#o=!0,this.#e.removeEventListener("scroll",this._onScroll);for(const e of this.#i)this.#e.removeEventListener("scroll",e);this.#i.clear()}}};window.TinyAfterScrollWatcher=t.TinyAfterScrollWatcher})();