tiny-essentials 1.20.1 → 1.20.3
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/README.md +5 -0
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyTextarea.min.js +1 -0
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/basics/html.cjs +33 -2
- package/dist/v1/basics/html.d.mts +14 -4
- package/dist/v1/basics/html.mjs +27 -2
- package/dist/v1/basics/index.cjs +2 -0
- package/dist/v1/basics/index.d.mts +3 -1
- package/dist/v1/basics/index.mjs +3 -3
- package/dist/v1/basics/simpleMath.cjs +23 -4
- package/dist/v1/basics/simpleMath.d.mts +18 -4
- package/dist/v1/basics/simpleMath.mjs +22 -4
- package/dist/v1/build/TinyTextarea.cjs +7 -0
- package/dist/v1/build/TinyTextarea.d.mts +3 -0
- package/dist/v1/build/TinyTextarea.mjs +2 -0
- package/dist/v1/index.cjs +4 -0
- package/dist/v1/index.d.mts +4 -1
- package/dist/v1/index.mjs +4 -3
- package/dist/v1/libs/TinyHtml.cjs +210 -4
- package/dist/v1/libs/TinyHtml.d.mts +109 -3
- package/dist/v1/libs/TinyHtml.mjs +184 -4
- package/dist/v1/libs/TinySmartScroller.cjs +87 -0
- package/dist/v1/libs/TinySmartScroller.d.mts +52 -0
- package/dist/v1/libs/TinySmartScroller.mjs +76 -0
- package/dist/v1/libs/TinyTextarea.cjs +230 -0
- package/dist/v1/libs/TinyTextarea.d.mts +128 -0
- package/dist/v1/libs/TinyTextarea.mjs +198 -0
- package/docs/v1/README.md +1 -0
- package/docs/v1/basics/html.md +78 -22
- package/docs/v1/basics/simpleMath.md +22 -4
- package/docs/v1/libs/TinyHtml.md +140 -0
- package/docs/v1/libs/TinySmartScroller.md +4 -4
- package/docs/v1/libs/TinyTextarea.md +156 -0
- package/package.json +1 -1
|
@@ -153,6 +153,12 @@ export type SetValueList = SetValueBase | SetValueBase[];
|
|
|
153
153
|
* Includes common input types used in forms.
|
|
154
154
|
*/
|
|
155
155
|
export type InputElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | HTMLOptionElement;
|
|
156
|
+
/**
|
|
157
|
+
* Represents a parsed HTML element in JSON-like array form.
|
|
158
|
+
*/
|
|
159
|
+
export type HtmlParsed = [tagName: string, // The tag name of the element (e.g., 'div', 'img')
|
|
160
|
+
attributes: Record<string, string>, // All element attributes as key-value pairs
|
|
161
|
+
...children: (string | HtmlParsed)[]];
|
|
156
162
|
/**
|
|
157
163
|
* Possible directions from which a collision was detected and locked.
|
|
158
164
|
*
|
|
@@ -183,6 +189,15 @@ export type InputElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaEl
|
|
|
183
189
|
*
|
|
184
190
|
* @typedef {HTMLInputElement|HTMLSelectElement|HTMLTextAreaElement|HTMLOptionElement} InputElement
|
|
185
191
|
*/
|
|
192
|
+
/**
|
|
193
|
+
* Represents a parsed HTML element in JSON-like array form.
|
|
194
|
+
*
|
|
195
|
+
* @typedef {[
|
|
196
|
+
* tagName: string, // The tag name of the element (e.g., 'div', 'img')
|
|
197
|
+
* attributes: Record<string, string>, // All element attributes as key-value pairs
|
|
198
|
+
* ...children: (string | HtmlParsed)[] // Text or nested elements
|
|
199
|
+
* ]} HtmlParsed
|
|
200
|
+
*/
|
|
186
201
|
/**
|
|
187
202
|
* TinyHtml is a utility class that provides static and instance-level methods
|
|
188
203
|
* for precise dimension and position computations on HTML elements.
|
|
@@ -236,6 +251,15 @@ declare class TinyHtml {
|
|
|
236
251
|
*
|
|
237
252
|
* @typedef {HTMLInputElement|HTMLSelectElement|HTMLTextAreaElement|HTMLOptionElement} InputElement
|
|
238
253
|
*/
|
|
254
|
+
/**
|
|
255
|
+
* Represents a parsed HTML element in JSON-like array form.
|
|
256
|
+
*
|
|
257
|
+
* @typedef {[
|
|
258
|
+
* tagName: string, // The tag name of the element (e.g., 'div', 'img')
|
|
259
|
+
* attributes: Record<string, string>, // All element attributes as key-value pairs
|
|
260
|
+
* ...children: (string | HtmlParsed)[] // Text or nested elements
|
|
261
|
+
* ]} HtmlParsed
|
|
262
|
+
*/
|
|
239
263
|
/**
|
|
240
264
|
* TinyHtml is a utility class that provides static and instance-level methods
|
|
241
265
|
* for precise dimension and position computations on HTML elements.
|
|
@@ -248,6 +272,15 @@ declare class TinyHtml {
|
|
|
248
272
|
*/
|
|
249
273
|
rect1: TinyCollision.ObjRect, rect2: TinyCollision.ObjRect) => string | null;
|
|
250
274
|
getElsPerfColliding: (rect1: TinyCollision.ObjRect /**
|
|
275
|
+
* Represents a parsed HTML element in JSON-like array form.
|
|
276
|
+
*
|
|
277
|
+
* @typedef {[
|
|
278
|
+
* tagName: string, // The tag name of the element (e.g., 'div', 'img')
|
|
279
|
+
* attributes: Record<string, string>, // All element attributes as key-value pairs
|
|
280
|
+
* ...children: (string | HtmlParsed)[] // Text or nested elements
|
|
281
|
+
* ]} HtmlParsed
|
|
282
|
+
*/
|
|
283
|
+
/**
|
|
251
284
|
* TinyHtml is a utility class that provides static and instance-level methods
|
|
252
285
|
* for precise dimension and position computations on HTML elements.
|
|
253
286
|
* It mimics some jQuery functionalities while using native browser APIs.
|
|
@@ -256,7 +289,8 @@ declare class TinyHtml {
|
|
|
256
289
|
* and offset utilities. This class serves as a lightweight alternative using modern DOM APIs.
|
|
257
290
|
*
|
|
258
291
|
* @class
|
|
259
|
-
|
|
292
|
+
*/
|
|
293
|
+
, rect2: TinyCollision.ObjRect) => "top" | "bottom" | "left" | "right" | null;
|
|
260
294
|
getElsCollOverlap: (rect1: TinyCollision.ObjRect, rect2: TinyCollision.ObjRect) => {
|
|
261
295
|
overlapLeft: number;
|
|
262
296
|
overlapRight: number;
|
|
@@ -277,6 +311,72 @@ declare class TinyHtml {
|
|
|
277
311
|
y: number;
|
|
278
312
|
};
|
|
279
313
|
};
|
|
314
|
+
/**
|
|
315
|
+
* Fetches an HTML file from the given URL, parses it to JSON.
|
|
316
|
+
*
|
|
317
|
+
* @param {string | URL | globalThis.Request} url - The URL of the HTML file.
|
|
318
|
+
* @param {RequestInit} [ops] - Optional fetch configuration (e.g., method, headers, cache, etc).
|
|
319
|
+
* @returns {Promise<HtmlParsed[]>} A promise that resolves with the parsed JSON representation of the HTML structure.
|
|
320
|
+
*/
|
|
321
|
+
static fetchHtmlFile(url: string | URL | globalThis.Request, ops?: RequestInit): Promise<HtmlParsed[]>;
|
|
322
|
+
/**
|
|
323
|
+
* Fetches an HTML file from the given URL, parses it to JSON, then converts it to DOM nodes.
|
|
324
|
+
*
|
|
325
|
+
* @param {string} url - The URL of the HTML file.
|
|
326
|
+
* @param {RequestInit} [ops] - Optional fetch configuration (e.g., method, headers, cache, etc).
|
|
327
|
+
* @returns {Promise<(HTMLElement|Text)[]>} A promise that resolves with the DOM nodes.
|
|
328
|
+
*/
|
|
329
|
+
static fetchHtmlNodes(url: string, ops?: RequestInit): Promise<(HTMLElement | Text)[]>;
|
|
330
|
+
/**
|
|
331
|
+
* Fetches an HTML file from the given URL, parses it to JSON, then converts it to TinyHtml instances.
|
|
332
|
+
*
|
|
333
|
+
* @param {string} url - The URL of the HTML file.
|
|
334
|
+
* @param {RequestInit} [ops] - Optional fetch configuration (e.g., method, headers, cache, etc).
|
|
335
|
+
* @returns {Promise<TinyHtml[]>} A promise that resolves with the TinyHtml instances.
|
|
336
|
+
*/
|
|
337
|
+
static fetchHtmlTinyElems(url: string, ops?: RequestInit): Promise<TinyHtml[]>;
|
|
338
|
+
/**
|
|
339
|
+
* Converts the content of a <template> to an array of HtmlParsed.
|
|
340
|
+
*
|
|
341
|
+
* @param {HTMLTemplateElement} nodes
|
|
342
|
+
* @returns {HtmlParsed[]}
|
|
343
|
+
*/
|
|
344
|
+
static templateToJson(nodes: HTMLTemplateElement): HtmlParsed[];
|
|
345
|
+
/**
|
|
346
|
+
* Converts the content of a <template> to real DOM nodes.
|
|
347
|
+
*
|
|
348
|
+
* @param {HTMLTemplateElement} nodes
|
|
349
|
+
* @returns {(Element|Text)[]}
|
|
350
|
+
*/
|
|
351
|
+
static templateToNodes(nodes: HTMLTemplateElement): (Element | Text)[];
|
|
352
|
+
/**
|
|
353
|
+
* Converts the content of a <template> to an array of TinyHtml elements.
|
|
354
|
+
*
|
|
355
|
+
* @param {HTMLTemplateElement} nodes
|
|
356
|
+
* @returns {TinyHtml[]}
|
|
357
|
+
*/
|
|
358
|
+
static templateToTinyElems(nodes: HTMLTemplateElement): TinyHtml[];
|
|
359
|
+
/**
|
|
360
|
+
* Parses a full HTML string into a JSON-like structure.
|
|
361
|
+
*
|
|
362
|
+
* @param {string} htmlString - Full HTML markup as a string.
|
|
363
|
+
* @returns {HtmlParsed[]} An array of parsed HTML elements in structured format.
|
|
364
|
+
*/
|
|
365
|
+
static htmlToJson(htmlString: string): HtmlParsed[];
|
|
366
|
+
/**
|
|
367
|
+
* Converts a JSON-like HTML structure back to DOM Elements.
|
|
368
|
+
*
|
|
369
|
+
* @param {HtmlParsed[]} jsonArray - Parsed JSON format of HTML.
|
|
370
|
+
* @returns {(HTMLElement|Text)[]} List of DOM nodes.
|
|
371
|
+
*/
|
|
372
|
+
static jsonToNodes(jsonArray: HtmlParsed[]): (HTMLElement | Text)[];
|
|
373
|
+
/**
|
|
374
|
+
* Converts a JSON-like HTML structure back to TinyHtml instances.
|
|
375
|
+
*
|
|
376
|
+
* @param {HtmlParsed[]} jsonArray - Parsed JSON format of HTML.
|
|
377
|
+
* @returns {TinyHtml[]} List of TinyHtml instances.
|
|
378
|
+
*/
|
|
379
|
+
static jsonToTinyElems(jsonArray: HtmlParsed[]): TinyHtml[];
|
|
280
380
|
/**
|
|
281
381
|
* Creates a new TinyHtml element from a tag name and optional attributes.
|
|
282
382
|
*
|
|
@@ -576,10 +676,10 @@ declare class TinyHtml {
|
|
|
576
676
|
* This ensures consistent access to methods of the `TinyHtml` class regardless
|
|
577
677
|
* of the input form.
|
|
578
678
|
*
|
|
579
|
-
* @param {TinyElement|TinyElement[]} elems - A single element or an array of elements (DOM or TinyHtml).
|
|
679
|
+
* @param {TinyElement|Text|(TinyElement|Text)[]} elems - A single element or an array of elements (DOM or TinyHtml).
|
|
580
680
|
* @returns {TinyHtml[]} An array of TinyHtml instances corresponding to the input elements.
|
|
581
681
|
*/
|
|
582
|
-
static toTinyElm(elems: TinyElement | TinyElement[]): TinyHtml[];
|
|
682
|
+
static toTinyElm(elems: TinyElement | Text | (TinyElement | Text)[]): TinyHtml[];
|
|
583
683
|
/**
|
|
584
684
|
* Extracts native `Element` instances from one or more elements,
|
|
585
685
|
* which can be either raw DOM elements or wrapped in `TinyHtml`.
|
|
@@ -2197,6 +2297,12 @@ declare class TinyHtml {
|
|
|
2197
2297
|
* @returns {TinyNode|TinyNode[]}
|
|
2198
2298
|
*/
|
|
2199
2299
|
replaceAll(targets: TinyNode | TinyNode[]): TinyNode | TinyNode[];
|
|
2300
|
+
/**
|
|
2301
|
+
* Returns the number of elements currently stored in the internal element list.
|
|
2302
|
+
*
|
|
2303
|
+
* @returns {number} The total count of elements.
|
|
2304
|
+
*/
|
|
2305
|
+
get size(): number;
|
|
2200
2306
|
/**
|
|
2201
2307
|
* Returns the full computed CSS styles for the given element.
|
|
2202
2308
|
*
|
|
@@ -186,6 +186,15 @@ const __elemCollision = {
|
|
|
186
186
|
*
|
|
187
187
|
* @typedef {HTMLInputElement|HTMLSelectElement|HTMLTextAreaElement|HTMLOptionElement} InputElement
|
|
188
188
|
*/
|
|
189
|
+
/**
|
|
190
|
+
* Represents a parsed HTML element in JSON-like array form.
|
|
191
|
+
*
|
|
192
|
+
* @typedef {[
|
|
193
|
+
* tagName: string, // The tag name of the element (e.g., 'div', 'img')
|
|
194
|
+
* attributes: Record<string, string>, // All element attributes as key-value pairs
|
|
195
|
+
* ...children: (string | HtmlParsed)[] // Text or nested elements
|
|
196
|
+
* ]} HtmlParsed
|
|
197
|
+
*/
|
|
189
198
|
/**
|
|
190
199
|
* TinyHtml is a utility class that provides static and instance-level methods
|
|
191
200
|
* for precise dimension and position computations on HTML elements.
|
|
@@ -199,6 +208,165 @@ const __elemCollision = {
|
|
|
199
208
|
class TinyHtml {
|
|
200
209
|
/** @typedef {import('../basics/collision.mjs').ObjRect} ObjRect */
|
|
201
210
|
static Utils = { ...TinyCollision };
|
|
211
|
+
/**
|
|
212
|
+
* Fetches an HTML file from the given URL, parses it to JSON.
|
|
213
|
+
*
|
|
214
|
+
* @param {string | URL | globalThis.Request} url - The URL of the HTML file.
|
|
215
|
+
* @param {RequestInit} [ops] - Optional fetch configuration (e.g., method, headers, cache, etc).
|
|
216
|
+
* @returns {Promise<HtmlParsed[]>} A promise that resolves with the parsed JSON representation of the HTML structure.
|
|
217
|
+
*/
|
|
218
|
+
static async fetchHtmlFile(url, ops = { method: 'GET' }) {
|
|
219
|
+
const res = await fetch(url, ops);
|
|
220
|
+
const contentType = res.headers.get('Content-Type') || '';
|
|
221
|
+
if (!res.ok)
|
|
222
|
+
throw new Error(`Failed to fetch: ${res.status} ${res.statusText}`);
|
|
223
|
+
// Only accept HTML responses
|
|
224
|
+
if (!contentType.includes('text/html')) {
|
|
225
|
+
throw new Error(`Invalid content type: ${contentType} (expected text/html)`);
|
|
226
|
+
}
|
|
227
|
+
const html = await res.text();
|
|
228
|
+
return TinyHtml.htmlToJson(html);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Fetches an HTML file from the given URL, parses it to JSON, then converts it to DOM nodes.
|
|
232
|
+
*
|
|
233
|
+
* @param {string} url - The URL of the HTML file.
|
|
234
|
+
* @param {RequestInit} [ops] - Optional fetch configuration (e.g., method, headers, cache, etc).
|
|
235
|
+
* @returns {Promise<(HTMLElement|Text)[]>} A promise that resolves with the DOM nodes.
|
|
236
|
+
*/
|
|
237
|
+
static async fetchHtmlNodes(url, ops) {
|
|
238
|
+
const json = await TinyHtml.fetchHtmlFile(url, ops);
|
|
239
|
+
return TinyHtml.jsonToNodes(json);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Fetches an HTML file from the given URL, parses it to JSON, then converts it to TinyHtml instances.
|
|
243
|
+
*
|
|
244
|
+
* @param {string} url - The URL of the HTML file.
|
|
245
|
+
* @param {RequestInit} [ops] - Optional fetch configuration (e.g., method, headers, cache, etc).
|
|
246
|
+
* @returns {Promise<TinyHtml[]>} A promise that resolves with the TinyHtml instances.
|
|
247
|
+
*/
|
|
248
|
+
static async fetchHtmlTinyElems(url, ops) {
|
|
249
|
+
const nodes = await TinyHtml.fetchHtmlNodes(url, ops);
|
|
250
|
+
return TinyHtml.toTinyElm(nodes);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Converts the content of a <template> to an array of HtmlParsed.
|
|
254
|
+
*
|
|
255
|
+
* @param {HTMLTemplateElement} nodes
|
|
256
|
+
* @returns {HtmlParsed[]}
|
|
257
|
+
*/
|
|
258
|
+
static templateToJson(nodes) {
|
|
259
|
+
return TinyHtml.htmlToJson([...nodes.content.childNodes]
|
|
260
|
+
.map((node) => node instanceof Element ? node.getHTML() : node instanceof Text ? node.textContent : '')
|
|
261
|
+
.join(''));
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Converts the content of a <template> to real DOM nodes.
|
|
265
|
+
*
|
|
266
|
+
* @param {HTMLTemplateElement} nodes
|
|
267
|
+
* @returns {(Element|Text)[]}
|
|
268
|
+
*/
|
|
269
|
+
static templateToNodes(nodes) {
|
|
270
|
+
/** @type {(Element|Text)[]} */
|
|
271
|
+
const result = [];
|
|
272
|
+
[...nodes.content.cloneNode(true).childNodes].map((node) => {
|
|
273
|
+
if (!(node instanceof Element) && !(node instanceof Text) && !(node instanceof Comment))
|
|
274
|
+
throw new Error(`Expected only Element nodes in <template>, but found: ${node.constructor.name}`);
|
|
275
|
+
if (!(node instanceof Comment))
|
|
276
|
+
result.push(node);
|
|
277
|
+
});
|
|
278
|
+
return result;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Converts the content of a <template> to an array of TinyHtml elements.
|
|
282
|
+
*
|
|
283
|
+
* @param {HTMLTemplateElement} nodes
|
|
284
|
+
* @returns {TinyHtml[]}
|
|
285
|
+
*/
|
|
286
|
+
static templateToTinyElems(nodes) {
|
|
287
|
+
return TinyHtml.toTinyElm(TinyHtml.templateToNodes(nodes));
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Parses a full HTML string into a JSON-like structure.
|
|
291
|
+
*
|
|
292
|
+
* @param {string} htmlString - Full HTML markup as a string.
|
|
293
|
+
* @returns {HtmlParsed[]} An array of parsed HTML elements in structured format.
|
|
294
|
+
*/
|
|
295
|
+
static htmlToJson(htmlString) {
|
|
296
|
+
const container = document.createElement('div');
|
|
297
|
+
container.innerHTML = htmlString.trim();
|
|
298
|
+
const result = [];
|
|
299
|
+
/**
|
|
300
|
+
* @param {Node} el
|
|
301
|
+
* @returns {*}
|
|
302
|
+
*/
|
|
303
|
+
const parseElement = (el) => {
|
|
304
|
+
if (el instanceof Comment)
|
|
305
|
+
return null;
|
|
306
|
+
if (el instanceof Text) {
|
|
307
|
+
const text = el.textContent?.trim();
|
|
308
|
+
return text ? text : null;
|
|
309
|
+
}
|
|
310
|
+
if (!(el instanceof Element))
|
|
311
|
+
return null;
|
|
312
|
+
const tag = el.tagName.toLowerCase();
|
|
313
|
+
/** @type {Record<string, string>} */
|
|
314
|
+
const props = {};
|
|
315
|
+
for (const attr of el.attributes) {
|
|
316
|
+
props[TinyHtml.getPropName(attr.name)] = attr.value;
|
|
317
|
+
}
|
|
318
|
+
const children = Array.from(el.childNodes).map(parseElement).filter(Boolean);
|
|
319
|
+
return children.length > 0 ? [tag, props, ...children] : [tag, props];
|
|
320
|
+
};
|
|
321
|
+
for (const child of container.childNodes) {
|
|
322
|
+
const parsed = parseElement(child);
|
|
323
|
+
if (parsed)
|
|
324
|
+
result.push(parsed);
|
|
325
|
+
}
|
|
326
|
+
container.innerHTML = '';
|
|
327
|
+
return result;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Converts a JSON-like HTML structure back to DOM Elements.
|
|
331
|
+
*
|
|
332
|
+
* @param {HtmlParsed[]} jsonArray - Parsed JSON format of HTML.
|
|
333
|
+
* @returns {(HTMLElement|Text)[]} List of DOM nodes.
|
|
334
|
+
*/
|
|
335
|
+
static jsonToNodes(jsonArray) {
|
|
336
|
+
/**
|
|
337
|
+
* @param {HtmlParsed|string} nodeData
|
|
338
|
+
* @returns {HTMLElement|Text}
|
|
339
|
+
*/
|
|
340
|
+
const createElement = (nodeData) => {
|
|
341
|
+
if (typeof nodeData === 'string') {
|
|
342
|
+
return document.createTextNode(nodeData);
|
|
343
|
+
}
|
|
344
|
+
if (!Array.isArray(nodeData))
|
|
345
|
+
return document.createTextNode('');
|
|
346
|
+
const [tag, props, ...children] = nodeData;
|
|
347
|
+
const el = document.createElement(tag);
|
|
348
|
+
for (const [key, value] of Object.entries(props)) {
|
|
349
|
+
el.setAttribute(TinyHtml.getAttrName(key), value);
|
|
350
|
+
}
|
|
351
|
+
for (const child of children) {
|
|
352
|
+
const childEl = createElement(child);
|
|
353
|
+
if (childEl instanceof Comment)
|
|
354
|
+
continue;
|
|
355
|
+
el.appendChild(childEl);
|
|
356
|
+
}
|
|
357
|
+
return el;
|
|
358
|
+
};
|
|
359
|
+
return jsonArray.map(createElement).filter((node) => !(node instanceof Comment));
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Converts a JSON-like HTML structure back to TinyHtml instances.
|
|
363
|
+
*
|
|
364
|
+
* @param {HtmlParsed[]} jsonArray - Parsed JSON format of HTML.
|
|
365
|
+
* @returns {TinyHtml[]} List of TinyHtml instances.
|
|
366
|
+
*/
|
|
367
|
+
static jsonToTinyElems(jsonArray) {
|
|
368
|
+
return TinyHtml.toTinyElm(TinyHtml.jsonToNodes(jsonArray));
|
|
369
|
+
}
|
|
202
370
|
/**
|
|
203
371
|
* Creates a new TinyHtml element from a tag name and optional attributes.
|
|
204
372
|
*
|
|
@@ -440,7 +608,8 @@ class TinyHtml {
|
|
|
440
608
|
_getElement(where, index) {
|
|
441
609
|
if (!(this.#el[index] instanceof Element) &&
|
|
442
610
|
!(this.#el[index] instanceof Window) &&
|
|
443
|
-
!(this.#el[index] instanceof Document)
|
|
611
|
+
!(this.#el[index] instanceof Document) &&
|
|
612
|
+
!(this.#el[index] instanceof Text))
|
|
444
613
|
throw new Error(`[TinyHtml] Invalid Element in ${where}().`);
|
|
445
614
|
return this.#el[index];
|
|
446
615
|
}
|
|
@@ -452,7 +621,10 @@ class TinyHtml {
|
|
|
452
621
|
* @readonly
|
|
453
622
|
*/
|
|
454
623
|
_getElements(where) {
|
|
455
|
-
if (!this.#el.every((el) => el instanceof Element ||
|
|
624
|
+
if (!this.#el.every((el) => el instanceof Element ||
|
|
625
|
+
el instanceof Window ||
|
|
626
|
+
el instanceof Document ||
|
|
627
|
+
el instanceof Text))
|
|
456
628
|
throw new Error(`[TinyHtml] Invalid Element in ${where}().`);
|
|
457
629
|
return [...this.#el];
|
|
458
630
|
}
|
|
@@ -751,11 +923,11 @@ class TinyHtml {
|
|
|
751
923
|
* This ensures consistent access to methods of the `TinyHtml` class regardless
|
|
752
924
|
* of the input form.
|
|
753
925
|
*
|
|
754
|
-
* @param {TinyElement|TinyElement[]} elems - A single element or an array of elements (DOM or TinyHtml).
|
|
926
|
+
* @param {TinyElement|Text|(TinyElement|Text)[]} elems - A single element or an array of elements (DOM or TinyHtml).
|
|
755
927
|
* @returns {TinyHtml[]} An array of TinyHtml instances corresponding to the input elements.
|
|
756
928
|
*/
|
|
757
929
|
static toTinyElm(elems) {
|
|
758
|
-
/** @param {TinyElement[]} item */
|
|
930
|
+
/** @param {(TinyElement|Text)[]} item */
|
|
759
931
|
const checkElement = (item) => item.map((elem) => (!(elem instanceof TinyHtml) ? new TinyHtml(elem) : elem));
|
|
760
932
|
if (!Array.isArray(elems))
|
|
761
933
|
return checkElement([elems]);
|
|
@@ -1623,6 +1795,14 @@ class TinyHtml {
|
|
|
1623
1795
|
* @type {ConstructorElValues[]}
|
|
1624
1796
|
*/
|
|
1625
1797
|
#el;
|
|
1798
|
+
/**
|
|
1799
|
+
* Returns the number of elements currently stored in the internal element list.
|
|
1800
|
+
*
|
|
1801
|
+
* @returns {number} The total count of elements.
|
|
1802
|
+
*/
|
|
1803
|
+
get size() {
|
|
1804
|
+
return this.#el.length;
|
|
1805
|
+
}
|
|
1626
1806
|
/**
|
|
1627
1807
|
* Creates an instance of TinyHtml for a specific Element.
|
|
1628
1808
|
* Useful when you want to operate repeatedly on the same element using instance methods.
|
|
@@ -275,6 +275,11 @@ class TinySmartScroller {
|
|
|
275
275
|
/** @type {null|EventListenerOrEventListenerObject} */
|
|
276
276
|
#handler = null;
|
|
277
277
|
|
|
278
|
+
#isPastAtBottom = false;
|
|
279
|
+
#isPastAtTop = false;
|
|
280
|
+
#isPastAtCustomTop = false;
|
|
281
|
+
#isPastAtCustomBottom = false;
|
|
282
|
+
|
|
278
283
|
#isAtBottom = false;
|
|
279
284
|
#isAtTop = false;
|
|
280
285
|
#isAtCustomTop = false;
|
|
@@ -639,6 +644,12 @@ class TinySmartScroller {
|
|
|
639
644
|
else if (atCustomTop) atCustomResult = 'top';
|
|
640
645
|
else if (atCustomBottom) atCustomResult = 'bottom';
|
|
641
646
|
|
|
647
|
+
this.#isPastAtTop = this.#isAtTop ?? false;
|
|
648
|
+
this.#isPastAtBottom = this.#isAtBottom ?? false;
|
|
649
|
+
|
|
650
|
+
this.#isPastAtCustomTop = this.#isAtCustomTop ?? false;
|
|
651
|
+
this.#isPastAtCustomBottom = this.#isAtCustomBottom ?? false;
|
|
652
|
+
|
|
642
653
|
this.#isAtTop = atTop;
|
|
643
654
|
this.#isAtBottom = atBottom;
|
|
644
655
|
|
|
@@ -968,6 +979,79 @@ class TinySmartScroller {
|
|
|
968
979
|
*
|
|
969
980
|
* @returns {boolean}
|
|
970
981
|
*/
|
|
982
|
+
isAtCustomBottom() {
|
|
983
|
+
return this.#isAtCustomBottom;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
/**
|
|
987
|
+
* Checks if the user is within the defined extra scroll boundary from the top.
|
|
988
|
+
*
|
|
989
|
+
* @returns {boolean}
|
|
990
|
+
*/
|
|
991
|
+
isAtCustomTop() {
|
|
992
|
+
return this.#isAtCustomTop;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
/**
|
|
996
|
+
* Returns true if the user is currently scrolled to the bottom of the element.
|
|
997
|
+
*
|
|
998
|
+
* @returns {boolean}
|
|
999
|
+
*/
|
|
1000
|
+
isAtBottom() {
|
|
1001
|
+
return this.#isAtBottom;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* Returns true if the user is currently scrolled to the top of the element.
|
|
1006
|
+
*
|
|
1007
|
+
* @returns {boolean}
|
|
1008
|
+
*/
|
|
1009
|
+
isAtTop() {
|
|
1010
|
+
return this.#isAtTop;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* Returns true if the user has already passed beyond the bottom boundary at some point.
|
|
1015
|
+
*
|
|
1016
|
+
* @returns {boolean}
|
|
1017
|
+
*/
|
|
1018
|
+
isPastAtBottom() {
|
|
1019
|
+
return this.#isPastAtBottom;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
* Returns true if the user has already passed beyond the top boundary at some point.
|
|
1024
|
+
*
|
|
1025
|
+
* @returns {boolean}
|
|
1026
|
+
*/
|
|
1027
|
+
isPastAtTop() {
|
|
1028
|
+
return this.#isPastAtTop;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* Returns true if the user has passed beyond the defined extra scroll boundary from the top at some point.
|
|
1033
|
+
*
|
|
1034
|
+
* @returns {boolean}
|
|
1035
|
+
*/
|
|
1036
|
+
isPastAtCustomTop() {
|
|
1037
|
+
return this.#isPastAtCustomTop;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
/**
|
|
1041
|
+
* Returns true if the user has passed beyond the defined extra scroll boundary from the bottom at some point.
|
|
1042
|
+
*
|
|
1043
|
+
* @returns {boolean}
|
|
1044
|
+
*/
|
|
1045
|
+
isPastAtCustomBottom() {
|
|
1046
|
+
return this.#isPastAtCustomBottom;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
/**
|
|
1050
|
+
* Checks if the user is within the defined extra scroll boundary from the bottom.
|
|
1051
|
+
*
|
|
1052
|
+
* @returns {boolean}
|
|
1053
|
+
* @deprecated - Use isAtCustomBottom instead.
|
|
1054
|
+
*/
|
|
971
1055
|
isUserAtCustomBottom() {
|
|
972
1056
|
return this.#isAtCustomBottom;
|
|
973
1057
|
}
|
|
@@ -976,6 +1060,7 @@ class TinySmartScroller {
|
|
|
976
1060
|
* Checks if the user is within the defined extra scroll boundary from the top.
|
|
977
1061
|
*
|
|
978
1062
|
* @returns {boolean}
|
|
1063
|
+
* @deprecated - Use isAtCustomTop instead.
|
|
979
1064
|
*/
|
|
980
1065
|
isUserAtCustomTop() {
|
|
981
1066
|
return this.#isAtCustomTop;
|
|
@@ -985,6 +1070,7 @@ class TinySmartScroller {
|
|
|
985
1070
|
* Returns true if the user is currently scrolled to the bottom of the element.
|
|
986
1071
|
*
|
|
987
1072
|
* @returns {boolean}
|
|
1073
|
+
* @deprecated - Use isAtBottom instead.
|
|
988
1074
|
*/
|
|
989
1075
|
isUserAtBottom() {
|
|
990
1076
|
return this.#isAtBottom;
|
|
@@ -994,6 +1080,7 @@ class TinySmartScroller {
|
|
|
994
1080
|
* Returns true if the user is currently scrolled to the top of the element.
|
|
995
1081
|
*
|
|
996
1082
|
* @returns {boolean}
|
|
1083
|
+
* @deprecated - Use isAtTop instead.
|
|
997
1084
|
*/
|
|
998
1085
|
isUserAtTop() {
|
|
999
1086
|
return this.#isAtTop;
|
|
@@ -515,23 +515,75 @@ declare class TinySmartScroller {
|
|
|
515
515
|
*
|
|
516
516
|
* @returns {boolean}
|
|
517
517
|
*/
|
|
518
|
+
isAtCustomBottom(): boolean;
|
|
519
|
+
/**
|
|
520
|
+
* Checks if the user is within the defined extra scroll boundary from the top.
|
|
521
|
+
*
|
|
522
|
+
* @returns {boolean}
|
|
523
|
+
*/
|
|
524
|
+
isAtCustomTop(): boolean;
|
|
525
|
+
/**
|
|
526
|
+
* Returns true if the user is currently scrolled to the bottom of the element.
|
|
527
|
+
*
|
|
528
|
+
* @returns {boolean}
|
|
529
|
+
*/
|
|
530
|
+
isAtBottom(): boolean;
|
|
531
|
+
/**
|
|
532
|
+
* Returns true if the user is currently scrolled to the top of the element.
|
|
533
|
+
*
|
|
534
|
+
* @returns {boolean}
|
|
535
|
+
*/
|
|
536
|
+
isAtTop(): boolean;
|
|
537
|
+
/**
|
|
538
|
+
* Returns true if the user has already passed beyond the bottom boundary at some point.
|
|
539
|
+
*
|
|
540
|
+
* @returns {boolean}
|
|
541
|
+
*/
|
|
542
|
+
isPastAtBottom(): boolean;
|
|
543
|
+
/**
|
|
544
|
+
* Returns true if the user has already passed beyond the top boundary at some point.
|
|
545
|
+
*
|
|
546
|
+
* @returns {boolean}
|
|
547
|
+
*/
|
|
548
|
+
isPastAtTop(): boolean;
|
|
549
|
+
/**
|
|
550
|
+
* Returns true if the user has passed beyond the defined extra scroll boundary from the top at some point.
|
|
551
|
+
*
|
|
552
|
+
* @returns {boolean}
|
|
553
|
+
*/
|
|
554
|
+
isPastAtCustomTop(): boolean;
|
|
555
|
+
/**
|
|
556
|
+
* Returns true if the user has passed beyond the defined extra scroll boundary from the bottom at some point.
|
|
557
|
+
*
|
|
558
|
+
* @returns {boolean}
|
|
559
|
+
*/
|
|
560
|
+
isPastAtCustomBottom(): boolean;
|
|
561
|
+
/**
|
|
562
|
+
* Checks if the user is within the defined extra scroll boundary from the bottom.
|
|
563
|
+
*
|
|
564
|
+
* @returns {boolean}
|
|
565
|
+
* @deprecated - Use isAtCustomBottom instead.
|
|
566
|
+
*/
|
|
518
567
|
isUserAtCustomBottom(): boolean;
|
|
519
568
|
/**
|
|
520
569
|
* Checks if the user is within the defined extra scroll boundary from the top.
|
|
521
570
|
*
|
|
522
571
|
* @returns {boolean}
|
|
572
|
+
* @deprecated - Use isAtCustomTop instead.
|
|
523
573
|
*/
|
|
524
574
|
isUserAtCustomTop(): boolean;
|
|
525
575
|
/**
|
|
526
576
|
* Returns true if the user is currently scrolled to the bottom of the element.
|
|
527
577
|
*
|
|
528
578
|
* @returns {boolean}
|
|
579
|
+
* @deprecated - Use isAtBottom instead.
|
|
529
580
|
*/
|
|
530
581
|
isUserAtBottom(): boolean;
|
|
531
582
|
/**
|
|
532
583
|
* Returns true if the user is currently scrolled to the top of the element.
|
|
533
584
|
*
|
|
534
585
|
* @returns {boolean}
|
|
586
|
+
* @deprecated - Use isAtTop instead.
|
|
535
587
|
*/
|
|
536
588
|
isUserAtTop(): boolean;
|
|
537
589
|
/**
|