tiny-essentials 1.16.0 → 1.16.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.
- package/dist/v1/TinyAfterScrollWatcher.js +219 -0
- package/dist/v1/TinyAfterScrollWatcher.min.js +1 -0
- package/dist/v1/TinyBasicsEs.js +488 -0
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragger.js +488 -0
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.js +670 -0
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.js +488 -0
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinyUploadClicker.js +489 -0
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/build/TinyAfterScrollWatcher.cjs +7 -0
- package/dist/v1/build/TinyAfterScrollWatcher.d.mts +3 -0
- package/dist/v1/build/TinyAfterScrollWatcher.mjs +2 -0
- package/dist/v1/index.cjs +2 -0
- package/dist/v1/index.d.mts +2 -1
- package/dist/v1/index.mjs +2 -1
- package/dist/v1/libs/TinyAfterScrollWatcher.cjs +180 -0
- package/dist/v1/libs/TinyAfterScrollWatcher.d.mts +89 -0
- package/dist/v1/libs/TinyAfterScrollWatcher.mjs +164 -0
- package/dist/v1/libs/TinyHtml.cjs +488 -0
- package/dist/v1/libs/TinyHtml.d.mts +150 -0
- package/dist/v1/libs/TinyHtml.mjs +469 -0
- package/dist/v1/libs/TinyUploadClicker.cjs +1 -0
- package/docs/v1/README.md +10 -10
- package/docs/v1/libs/TinyAfterScrollWatcher.md +231 -0
- package/docs/v1/libs/TinyHtml.md +325 -0
- package/package.json +1 -1
|
@@ -0,0 +1,219 @@
|
|
|
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 {null|NodeJS.Timeout} */
|
|
53
|
+
#lastScrollTime = null;
|
|
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 {Set<FnData>} */
|
|
65
|
+
#onStopListeners = new Set();
|
|
66
|
+
|
|
67
|
+
/** @type {boolean} */
|
|
68
|
+
#destroyed = false;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {Element|Window} scrollTarget - The element or window to track scrolling on
|
|
72
|
+
* @param {number} [inactivityTime=100] - Time in milliseconds to wait after scroll ends before executing the queue
|
|
73
|
+
* @throws {TypeError} If scrollTarget is not a valid Element or Window
|
|
74
|
+
* @throws {TypeError} If inactivityTime is not a positive number
|
|
75
|
+
*/
|
|
76
|
+
constructor(scrollTarget = window, inactivityTime = 100) {
|
|
77
|
+
if (!(scrollTarget instanceof Element) && !(scrollTarget instanceof Window))
|
|
78
|
+
throw new TypeError('scrollTarget must be an Element or the Window object.');
|
|
79
|
+
this.#scrollTarget = scrollTarget;
|
|
80
|
+
this._checkTimer = this._checkTimer.bind(this);
|
|
81
|
+
|
|
82
|
+
this.#scrollTarget.addEventListener('scroll', this._checkTimer);
|
|
83
|
+
this.#inactivityTime = inactivityTime;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
_checkTimer = () => {
|
|
87
|
+
if (this.#lastScrollTime) clearTimeout(this.#lastScrollTime);
|
|
88
|
+
this.#lastScrollTime = setTimeout(() => {
|
|
89
|
+
this.#lastScrollTime = null;
|
|
90
|
+
this.#checkQueue();
|
|
91
|
+
}, this.#inactivityTime);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Gets the current inactivity time in milliseconds.
|
|
96
|
+
* @returns {number}
|
|
97
|
+
*/
|
|
98
|
+
get inactivityTime() {
|
|
99
|
+
return this.#inactivityTime;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Sets a new inactivity time.
|
|
104
|
+
* Must be a positive number (in milliseconds).
|
|
105
|
+
* @param {number} value
|
|
106
|
+
* @throws {Error} If value is not a positive number
|
|
107
|
+
*/
|
|
108
|
+
set inactivityTime(value) {
|
|
109
|
+
if (typeof value !== 'number' || value <= 0 || !Number.isFinite(value))
|
|
110
|
+
throw new Error('inactivityTime must be a positive number in milliseconds.');
|
|
111
|
+
this.#inactivityTime = value;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Continuously checks whether the user has stopped scrolling,
|
|
116
|
+
* and if so, runs all queued functions.
|
|
117
|
+
*/
|
|
118
|
+
#checkQueue() {
|
|
119
|
+
if (this.#destroyed) return;
|
|
120
|
+
// Runs all onStop first listeners
|
|
121
|
+
for (const fn of this.#onStopListeners) {
|
|
122
|
+
if (typeof fn === 'function') fn();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Then execute the queue afterScrollQueue
|
|
126
|
+
while (this.#afterScrollQueue.length) {
|
|
127
|
+
const fn = this.#afterScrollQueue.pop();
|
|
128
|
+
if (typeof fn === 'function') fn();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Adds a function to be executed after scroll has stopped.
|
|
134
|
+
* The scroll is considered "stopped" after the configured inactivity time.
|
|
135
|
+
*
|
|
136
|
+
* @param {() => void} fn - A function to execute once scrolling has stopped.
|
|
137
|
+
* @throws {TypeError} If the argument is not a function.
|
|
138
|
+
*/
|
|
139
|
+
doAfterScroll(fn) {
|
|
140
|
+
if (typeof fn !== 'function') throw new TypeError('Argument must be a function.');
|
|
141
|
+
this.lastScrollTime = Date.now();
|
|
142
|
+
this.#afterScrollQueue.push(fn);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Registers a function to run once after scrolling has stopped,
|
|
147
|
+
* before any afterScrollQueue functions.
|
|
148
|
+
*
|
|
149
|
+
* @param {FnData} fn - A function to execute after scroll stop.
|
|
150
|
+
* @throws {TypeError} If the argument is not a function.
|
|
151
|
+
*/
|
|
152
|
+
onStop(fn) {
|
|
153
|
+
if (typeof fn !== 'function') throw new TypeError('Argument must be a function.');
|
|
154
|
+
this.#onStopListeners.add(fn);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Removes a previously registered onStop function.
|
|
159
|
+
*
|
|
160
|
+
* @param {FnData} fn - The function to remove.
|
|
161
|
+
* @throws {TypeError} If the argument is not a function.
|
|
162
|
+
*/
|
|
163
|
+
offStop(fn) {
|
|
164
|
+
if (typeof fn !== 'function') throw new TypeError('Argument must be a function.');
|
|
165
|
+
this.#onStopListeners.delete(fn);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Registers an external scroll listener on the tracked element.
|
|
170
|
+
*
|
|
171
|
+
* @param {OnScrollFunc} fn - The scroll listener to add
|
|
172
|
+
* @throws {TypeError} If the argument is not a function.
|
|
173
|
+
*/
|
|
174
|
+
onScroll(fn) {
|
|
175
|
+
if (typeof fn !== 'function') throw new TypeError('Argument must be a function.');
|
|
176
|
+
this.#scrollTarget.addEventListener('scroll', fn);
|
|
177
|
+
this.#externalScrollListeners.add(fn);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Removes a previously registered scroll listener from the tracked element.
|
|
182
|
+
*
|
|
183
|
+
* @param {OnScrollFunc} fn - The scroll listener to remove
|
|
184
|
+
* @throws {TypeError} If the argument is not a function.
|
|
185
|
+
*/
|
|
186
|
+
offScroll(fn) {
|
|
187
|
+
if (typeof fn !== 'function') throw new TypeError('Argument must be a function.');
|
|
188
|
+
if (this.#externalScrollListeners.has(fn)) {
|
|
189
|
+
this.#scrollTarget.removeEventListener('scroll', fn);
|
|
190
|
+
this.#externalScrollListeners.delete(fn);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Destroys the watcher by removing internal listeners and clearing data.
|
|
196
|
+
*/
|
|
197
|
+
destroy() {
|
|
198
|
+
if (this.#destroyed) return;
|
|
199
|
+
this.#destroyed = true;
|
|
200
|
+
|
|
201
|
+
this.#scrollTarget.removeEventListener('scroll', this._checkTimer);
|
|
202
|
+
for (const fn of this.#externalScrollListeners)
|
|
203
|
+
this.#scrollTarget.removeEventListener('scroll', fn);
|
|
204
|
+
|
|
205
|
+
this.#externalScrollListeners.clear();
|
|
206
|
+
this.#onStopListeners.clear();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/* harmony default export */ const libs_TinyAfterScrollWatcher = (TinyAfterScrollWatcher);
|
|
211
|
+
|
|
212
|
+
;// ./src/v1/build/TinyAfterScrollWatcher.mjs
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
window.TinyAfterScrollWatcher = __webpack_exports__.TinyAfterScrollWatcher;
|
|
218
|
+
/******/ })()
|
|
219
|
+
;
|
|
@@ -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;#t=null;#r=[];#i=100;#o=new Set;#n=new Set;#s=!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._checkTimer=this._checkTimer.bind(this),this.#e.addEventListener("scroll",this._checkTimer),this.#i=t}_checkTimer=()=>{this.#t&&clearTimeout(this.#t),this.#t=setTimeout((()=>{this.#t=null,this.#l()}),this.#i)};get inactivityTime(){return this.#i}set inactivityTime(e){if("number"!=typeof e||e<=0||!Number.isFinite(e))throw new Error("inactivityTime must be a positive number in milliseconds.");this.#i=e}#l(){if(!this.#s){for(const e of this.#n)"function"==typeof e&&e();for(;this.#r.length;){const e=this.#r.pop();"function"==typeof e&&e()}}}doAfterScroll(e){if("function"!=typeof e)throw new TypeError("Argument must be a function.");this.lastScrollTime=Date.now(),this.#r.push(e)}onStop(e){if("function"!=typeof e)throw new TypeError("Argument must be a function.");this.#n.add(e)}offStop(e){if("function"!=typeof e)throw new TypeError("Argument must be a function.");this.#n.delete(e)}onScroll(e){if("function"!=typeof e)throw new TypeError("Argument must be a function.");this.#e.addEventListener("scroll",e),this.#o.add(e)}offScroll(e){if("function"!=typeof e)throw new TypeError("Argument must be a function.");this.#o.has(e)&&(this.#e.removeEventListener("scroll",e),this.#o.delete(e))}destroy(){if(!this.#s){this.#s=!0,this.#e.removeEventListener("scroll",this._checkTimer);for(const e of this.#o)this.#e.removeEventListener("scroll",e);this.#o.clear(),this.#n.clear()}}};window.TinyAfterScrollWatcher=t.TinyAfterScrollWatcher})();
|