@t007/utils 0.0.33 → 0.0.34
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/{arrowNavigation-VenvPI4H.d.ts → arrowNavigation-DF7ul3A3.d.ts} +1 -1
- package/dist/{arrowNavigation-DK8mqVOk.d.cts → arrowNavigation-IaWiNTa6.d.cts} +1 -1
- package/dist/{chunk-4O76EZJ4.js → chunk-HGUYOV3P.js} +127 -21
- package/dist/{chunk-QJ72EQCJ.js → chunk-ZRCBB5P4.js} +9 -6
- package/dist/components/react.d.cts +1 -1
- package/dist/components/react.d.ts +1 -1
- package/dist/hooks/react.cjs +26 -22
- package/dist/hooks/react.d.cts +4 -4
- package/dist/hooks/react.d.ts +4 -4
- package/dist/hooks/react.js +2 -2
- package/dist/hooks/vanilla.cjs +22 -18
- package/dist/hooks/vanilla.d.cts +10 -10
- package/dist/hooks/vanilla.d.ts +10 -10
- package/dist/hooks/vanilla.js +2 -2
- package/dist/index.cjs +136 -20
- package/dist/index.d.cts +131 -12
- package/dist/index.d.ts +131 -12
- package/dist/index.js +23 -3
- package/dist/{ripple-C5MfEErC.d.cts → ripple-87VO-U7A.d.cts} +25 -24
- package/dist/{ripple-C5MfEErC.d.ts → ripple-87VO-U7A.d.ts} +25 -24
- package/dist/{scrollAssist-y9wFmYgt.d.cts → scrollAssist-l0V2H-jx.d.cts} +20 -20
- package/dist/{scrollAssist-y9wFmYgt.d.ts → scrollAssist-l0V2H-jx.d.ts} +20 -20
- package/dist/{useHighlight-DMpDCILK.d.cts → useHighlight-DYc_GF0R.d.cts} +2 -2
- package/dist/{useHighlight-DMpDCILK.d.ts → useHighlight-DYc_GF0R.d.ts} +2 -2
- package/package.json +4 -3
package/dist/hooks/vanilla.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
export { a as ScrollAssistConfig, S as ScrollAssistHandle, b as ScrollDir, i as initScrollAssist, r as removeScrollAssist } from '../scrollAssist-
|
|
2
|
-
export { F as FocusTrapConfig, O as OutsideClickConfig, R as RippleConfig, i as initFocusTrap, a as initOutsideClick, r as removeFocusTrap, b as removeOutsideClick, c as rippleHandler } from '../ripple-
|
|
3
|
-
export { A as ArrowNavigationHandle, i as initArrowNavigation, r as removeArrowNavigation } from '../arrowNavigation-
|
|
1
|
+
export { a as ScrollAssistConfig, S as ScrollAssistHandle, b as ScrollDir, i as initScrollAssist, r as removeScrollAssist } from '../scrollAssist-l0V2H-jx.js';
|
|
2
|
+
export { F as FocusTrapConfig, O as OutsideClickConfig, R as RippleConfig, i as initFocusTrap, a as initOutsideClick, r as removeFocusTrap, b as removeOutsideClick, c as rippleHandler } from '../ripple-87VO-U7A.js';
|
|
3
|
+
export { A as ArrowNavigationHandle, i as initArrowNavigation, r as removeArrowNavigation } from '../arrowNavigation-DF7ul3A3.js';
|
|
4
4
|
|
|
5
5
|
/** Configuration for the vertical edge-scrolling helper. */
|
|
6
6
|
interface ScrolleratorOptions {
|
|
7
|
-
/** Starting lines-per-second speed.
|
|
7
|
+
/** Starting lines-per-second speed. @default `3`. */
|
|
8
8
|
baseSpeed?: number;
|
|
9
|
-
/** Maximum accelerated speed.
|
|
9
|
+
/** Maximum accelerated speed. @default `10`. */
|
|
10
10
|
maxSpeed?: number;
|
|
11
|
-
/** Delay before acceleration kicks in.
|
|
11
|
+
/** Delay before acceleration kicks in. @default `2000`. */
|
|
12
12
|
stepDelay?: number;
|
|
13
|
-
/** Base frame rate used to estimate movement.
|
|
13
|
+
/** Base frame rate used to estimate movement. @default `16`. */
|
|
14
14
|
baseRate?: number;
|
|
15
|
-
/** Approximate line height in pixels.
|
|
15
|
+
/** Approximate line height in pixels. @default `80`. */
|
|
16
16
|
lineHeight?: number;
|
|
17
|
-
/** Edge margin that triggers scrolling.
|
|
17
|
+
/** Edge margin that triggers scrolling. @default `80`. */
|
|
18
18
|
margin?: number;
|
|
19
|
-
/** Scroll container or window target.
|
|
19
|
+
/** Scroll container or window target. @default `window`. */
|
|
20
20
|
car?: Window | HTMLElement;
|
|
21
21
|
}
|
|
22
22
|
/** Scrolling controls returned by initVScrollerator. */
|
package/dist/hooks/vanilla.js
CHANGED
|
@@ -10,12 +10,12 @@ import {
|
|
|
10
10
|
removeFocusTrap,
|
|
11
11
|
removeOutsideClick,
|
|
12
12
|
rippleHandler
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-ZRCBB5P4.js";
|
|
14
14
|
import {
|
|
15
15
|
INTERACTIVE_SELECTOR,
|
|
16
16
|
createEl,
|
|
17
17
|
getActiveEl
|
|
18
|
-
} from "../chunk-
|
|
18
|
+
} from "../chunk-HGUYOV3P.js";
|
|
19
19
|
|
|
20
20
|
// src/ts/hooks/vanilla/scrollAssist.ts
|
|
21
21
|
import { NIL } from "sia-reactor";
|
package/dist/index.cjs
CHANGED
|
@@ -21,17 +21,24 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
INTERACTIVE_SELECTOR: () => INTERACTIVE_SELECTOR,
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
KEYS_BLOCKS: () => import_utils6.KEYS_BLOCKS,
|
|
25
|
+
NIL: () => import_sia_reactor2.NIL,
|
|
26
|
+
NOOP: () => import_sia_reactor2.NOOP,
|
|
27
|
+
RAFLoop: () => RAFLoop,
|
|
26
28
|
VIRTUAL_RESOURCE: () => VIRTUAL_RESOURCE,
|
|
27
29
|
assignEl: () => import_utils.assignEl,
|
|
28
30
|
bindAllMethods: () => import_utils7.bindAllMethods,
|
|
29
31
|
bindCleanupToSignal: () => bindCleanupToSignal,
|
|
30
32
|
breath: () => breath,
|
|
33
|
+
camelize: () => camelize,
|
|
34
|
+
cancelRAFLoop: () => cancelRAFLoop,
|
|
35
|
+
capitalize: () => capitalize,
|
|
31
36
|
clamp: () => import_utils4.clamp,
|
|
32
37
|
cleanKeyCombo: () => import_utils6.cleanKeyCombo,
|
|
33
38
|
cleanURL: () => cleanURL,
|
|
34
39
|
createEl: () => import_utils.createEl,
|
|
40
|
+
createListRenderer: () => createListRenderer,
|
|
41
|
+
debounce: () => debounce,
|
|
35
42
|
deepBreath: () => deepBreath,
|
|
36
43
|
formatKeyForDisplay: () => import_utils6.formatKeyForDisplay,
|
|
37
44
|
formatKeyShortcutsForDisplay: () => import_utils6.formatKeyShortcutsForDisplay,
|
|
@@ -57,6 +64,7 @@ __export(index_exports, {
|
|
|
57
64
|
keyEventAllowed: () => import_utils6.keyEventAllowed,
|
|
58
65
|
limited: () => limited,
|
|
59
66
|
loadResource: () => loadResource,
|
|
67
|
+
longestIncreasingSubsequence: () => longestIncreasingSubsequence,
|
|
60
68
|
matchKeys: () => import_utils6.matchKeys,
|
|
61
69
|
mockAsync: () => mockAsync,
|
|
62
70
|
onAllMethods: () => import_utils7.onAllMethods,
|
|
@@ -70,49 +78,86 @@ __export(index_exports, {
|
|
|
70
78
|
setInterval: () => import_utils5.setInterval,
|
|
71
79
|
setTimeout: () => import_utils5.setTimeout,
|
|
72
80
|
stringifyKeyEvent: () => import_utils6.stringifyKeyEvent,
|
|
73
|
-
|
|
81
|
+
throttle: () => throttle,
|
|
82
|
+
uid: () => uid,
|
|
83
|
+
uncamelize: () => uncamelize
|
|
74
84
|
});
|
|
75
85
|
module.exports = __toCommonJS(index_exports);
|
|
76
86
|
|
|
77
87
|
// src/ts/core/dom.ts
|
|
78
88
|
var import_utils = require("sia-reactor/utils");
|
|
79
89
|
var import_utils2 = require("sia-reactor/utils");
|
|
80
|
-
var
|
|
90
|
+
var import_sia_reactor = require("sia-reactor");
|
|
91
|
+
var INTERACTIVE_SELECTOR = ":is(button,[href],input:not([type='hidden']),select,textarea,details>summary,[contenteditable],iframe,audio[controls],video[controls],[tabindex]):not([disabled],[tabindex='-1'],[data-focus-guard],[inert],[inert] *)";
|
|
81
92
|
var isInteractive = (target) => target instanceof HTMLElement && target.matches(INTERACTIVE_SELECTOR);
|
|
82
93
|
var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
|
|
83
|
-
function loadResource(req, type = "style", { module: module2, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {},
|
|
84
|
-
|
|
94
|
+
function loadResource(req, type = "style", { module: module2, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, win = window) {
|
|
95
|
+
win.t007 ??= {}, win.t007._resourceCache ??= {};
|
|
85
96
|
if (req === VIRTUAL_RESOURCE || isSym(req)) return Promise.resolve();
|
|
86
97
|
const src = req;
|
|
87
|
-
if (
|
|
88
|
-
const existing = type === "script" ? Array.prototype.find.call(
|
|
89
|
-
if (existing) return
|
|
90
|
-
|
|
98
|
+
if (win.t007._resourceCache[src]) return win.t007._resourceCache[src];
|
|
99
|
+
const existing = type === "script" ? Array.prototype.find.call(win.document.scripts, (s) => isSameURL(s.src, src)) : type === "style" ? Array.prototype.find.call(win.document.styleSheets, (s) => isSameURL(s.href, src)) : null;
|
|
100
|
+
if (existing) return win.t007._resourceCache[src] = Promise.resolve(existing);
|
|
101
|
+
win.t007._resourceCache[src] = new Promise((resolve, reject) => {
|
|
91
102
|
(function tryLoad(remaining, el) {
|
|
92
103
|
const onerror = () => {
|
|
93
104
|
el?.remove?.();
|
|
94
105
|
if (remaining > 1) {
|
|
95
106
|
setTimeout(tryLoad, 1e3, remaining - 1);
|
|
96
|
-
console.warn(`Retrying ${type} load (${attempts - remaining + 1})
|
|
107
|
+
console.warn(`Retrying ${type} load for "${src}" (${attempts - remaining + 1})...`);
|
|
97
108
|
} else {
|
|
98
|
-
delete
|
|
99
|
-
reject(new Error(`${type} load failed
|
|
109
|
+
delete win.t007._resourceCache[src];
|
|
110
|
+
reject(new Error(`${capitalize(type)} load failed for "${src}" after ${attempts - 1} attempts`));
|
|
100
111
|
}
|
|
101
112
|
};
|
|
102
113
|
const url = retryKey && remaining < attempts ? `${src}${src.includes("?") ? "&" : "?"}_${retryKey}=${Date.now()}` : src;
|
|
103
|
-
if (type === "script")
|
|
104
|
-
else if (type === "style")
|
|
114
|
+
if (type === "script") win.document.body.append(el = (0, import_utils.createEl)("script", { src: url, type: module2 ? "module" : "text/javascript", crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
|
|
115
|
+
else if (type === "style") win.document.head.append(el = (0, import_utils.createEl)("link", { rel: "stylesheet", href: url, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
|
|
105
116
|
else reject(new Error(`Unsupported resource type: ${type}`));
|
|
106
117
|
})(attempts);
|
|
107
118
|
});
|
|
108
|
-
return
|
|
119
|
+
return win.t007._resourceCache[src];
|
|
109
120
|
}
|
|
110
121
|
function getWindow(el = window) {
|
|
111
|
-
return
|
|
122
|
+
return el?.ownerDocument?.defaultView ?? el?.defaultView ?? window;
|
|
123
|
+
}
|
|
124
|
+
function createListRenderer({ container, getKey, createNode, updateNode = import_sia_reactor.NOOP, destroyNode = import_sia_reactor.NOOP }) {
|
|
125
|
+
let nodeRegistry = /* @__PURE__ */ new Map();
|
|
126
|
+
return function syncDOM(array, strict = true) {
|
|
127
|
+
const newRegistry = /* @__PURE__ */ new Map(), seenKeys = /* @__PURE__ */ new Set(), oldPositions = /* @__PURE__ */ new WeakMap(), children = Array.from(container.children);
|
|
128
|
+
for (let i = 0, len = children.length; i < len; i++) oldPositions.set(children[i], i);
|
|
129
|
+
const futureNodes = [], oldIndices = [];
|
|
130
|
+
for (let i = 0, len = array.length; i < len; i++) {
|
|
131
|
+
const item = array[i], key = getKey(item);
|
|
132
|
+
if (seenKeys.has(key)) throw new Error(`[List Renderer] Duplicate key "${key}" detected`);
|
|
133
|
+
let node = nodeRegistry.get(key);
|
|
134
|
+
if (!node) {
|
|
135
|
+
node = createNode(item);
|
|
136
|
+
if (!node) {
|
|
137
|
+
if (strict) throw new Error(`[List Renderer] No HTMLElement for key "${key}"`);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
oldIndices.push(-1);
|
|
141
|
+
} else updateNode(node, item), oldIndices.push(oldPositions.get(node) ?? -1);
|
|
142
|
+
seenKeys.add(key), futureNodes.push(node), newRegistry.set(key, node);
|
|
143
|
+
}
|
|
144
|
+
for (const [key, node] of nodeRegistry.entries()) !seenKeys.has(key) && node.parentElement === container && (destroyNode(node, key), node.remove());
|
|
145
|
+
const sequence = longestIncreasingSubsequence(oldIndices), stable = new Set(sequence);
|
|
146
|
+
let anchor = null;
|
|
147
|
+
for (let i = futureNodes.length - 1; i >= 0; i--) {
|
|
148
|
+
const node = futureNodes[i];
|
|
149
|
+
if (oldIndices[i] !== -1 && stable.has(i)) {
|
|
150
|
+
anchor = node;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
container.insertBefore(node, anchor), anchor = node;
|
|
154
|
+
}
|
|
155
|
+
nodeRegistry = newRegistry;
|
|
156
|
+
};
|
|
112
157
|
}
|
|
113
158
|
|
|
114
159
|
// src/ts/index.ts
|
|
115
|
-
var
|
|
160
|
+
var import_sia_reactor2 = require("sia-reactor");
|
|
116
161
|
|
|
117
162
|
// src/ts/core/obj.ts
|
|
118
163
|
var import_utils3 = require("sia-reactor/utils");
|
|
@@ -149,11 +194,42 @@ function inBoolArrOpt(opt, str) {
|
|
|
149
194
|
|
|
150
195
|
// src/ts/core/num.ts
|
|
151
196
|
var import_utils4 = require("sia-reactor/utils");
|
|
197
|
+
function longestIncreasingSubsequence(array) {
|
|
198
|
+
const n = array.length, parent = new Array(n), tails = [];
|
|
199
|
+
for (let i = 0; i < n; i++) {
|
|
200
|
+
const value = array[i];
|
|
201
|
+
if (value === -1) continue;
|
|
202
|
+
let left = 0;
|
|
203
|
+
let right = tails.length;
|
|
204
|
+
while (left < right) {
|
|
205
|
+
const mid = left + right >> 1;
|
|
206
|
+
if (array[tails[mid]] < value) left = mid + 1;
|
|
207
|
+
else right = mid;
|
|
208
|
+
}
|
|
209
|
+
if (left > 0) parent[i] = tails[left - 1];
|
|
210
|
+
else parent[i] = -1;
|
|
211
|
+
tails[left] = i;
|
|
212
|
+
}
|
|
213
|
+
if (!tails.length) return [];
|
|
214
|
+
const result = [];
|
|
215
|
+
let k = tails[tails.length - 1];
|
|
216
|
+
while (k >= 0) result.push(k), k = parent[k];
|
|
217
|
+
return result.reverse(), result;
|
|
218
|
+
}
|
|
152
219
|
|
|
153
220
|
// src/ts/core/str.ts
|
|
154
221
|
function uid(prefix = "") {
|
|
155
222
|
return prefix + Date.now().toString(36) + "_" + performance.now().toString(36).replace(".", "") + "_" + Math.random().toString(36).slice(2);
|
|
156
223
|
}
|
|
224
|
+
function capitalize(word = "") {
|
|
225
|
+
return word.replace(/^(\s*)([a-z])/i, (_, s, l) => s + l.toUpperCase());
|
|
226
|
+
}
|
|
227
|
+
function camelize(str = "", { source } = /[\s_-]+/, { preserveInnerCase: pIC = true, upperFirst: uF = false } = {}) {
|
|
228
|
+
return (pIC ? str : str.toLowerCase()).replace(new RegExp(source + "(\\w)", "g"), (_, c) => c.toUpperCase()).replace(/^\w/, (c) => c[uF ? "toUpperCase" : "toLowerCase"]());
|
|
229
|
+
}
|
|
230
|
+
function uncamelize(str, separator = " ") {
|
|
231
|
+
return str.replace(/([a-z])([A-Z])/g, `$1${separator}$2`).toLowerCase();
|
|
232
|
+
}
|
|
157
233
|
function remToPx(rem, el = document.documentElement) {
|
|
158
234
|
return rem * parseFloat(getComputedStyle(el).fontSize);
|
|
159
235
|
}
|
|
@@ -175,12 +251,42 @@ function cleanURL(url) {
|
|
|
175
251
|
}
|
|
176
252
|
}
|
|
177
253
|
function isSameURL(url1, url2) {
|
|
254
|
+
if (url1 === url2) return true;
|
|
178
255
|
if (!isStr(url1) || !isStr(url2) || !url1 || !url2) return false;
|
|
179
256
|
return cleanURL(url1) === cleanURL(url2);
|
|
180
257
|
}
|
|
181
258
|
|
|
182
259
|
// src/ts/core/fn.ts
|
|
183
260
|
var import_utils5 = require("sia-reactor/utils");
|
|
261
|
+
function throttle(key, fn, delay = 30, strict = true, signal, win) {
|
|
262
|
+
const throttleMap = t007._throttlers ??= /* @__PURE__ */ new Map();
|
|
263
|
+
if (strict === true) {
|
|
264
|
+
const now = performance.now();
|
|
265
|
+
return now - (throttleMap.get(key) ?? 0) < delay ? void 0 : (throttleMap.set(key, now), fn());
|
|
266
|
+
}
|
|
267
|
+
if (throttleMap.has(key)) return;
|
|
268
|
+
const id = strict === false ? (0, import_utils5.setTimeout)(() => throttleMap.delete(key), delay, signal, win) : strict(() => throttleMap.delete(key));
|
|
269
|
+
return throttleMap.set(key, id), fn();
|
|
270
|
+
}
|
|
271
|
+
function debounce(key, fn, delay = 30, strict = true, signal, win) {
|
|
272
|
+
const debounceMap = t007._debouncers ??= /* @__PURE__ */ new Map();
|
|
273
|
+
if (strict) {
|
|
274
|
+
const now = performance.now(), prev = debounceMap.get(key) ?? 0;
|
|
275
|
+
return debounceMap.set(key, now), now - prev < delay ? void 0 : fn();
|
|
276
|
+
}
|
|
277
|
+
const prevId = debounceMap.get(key);
|
|
278
|
+
prevId !== void 0 && (win ?? window).clearTimeout(prevId);
|
|
279
|
+
const id = (0, import_utils5.setTimeout)(() => (debounceMap.delete(key), fn()), delay, signal, win);
|
|
280
|
+
return void debounceMap.set(key, id);
|
|
281
|
+
}
|
|
282
|
+
function RAFLoop(key, fn, signal, win) {
|
|
283
|
+
const rafLoopMap = t007._RAFLoopers ??= /* @__PURE__ */ new Map();
|
|
284
|
+
if (rafLoopMap.has(key)) return void rafLoopMap.set(key, fn);
|
|
285
|
+
rafLoopMap.set(key, fn);
|
|
286
|
+
const loop = (_ = 0, fn2 = rafLoopMap.get(key)) => fn2 && (fn2(), (0, import_utils5.requestAnimationFrame)(loop, signal, win));
|
|
287
|
+
loop();
|
|
288
|
+
}
|
|
289
|
+
var cancelRAFLoop = (key) => t007._RAFLoopers ? t007._RAFLoopers.delete(key) : false;
|
|
184
290
|
function limited(FN_KEY, fn, opts = {}) {
|
|
185
291
|
let count = 0, { key, maxTimes: max = 1 } = isStr(opts) ? { key: opts } : opts;
|
|
186
292
|
const getReg = () => JSON.parse(localStorage.getItem(FN_KEY) || "{}"), setReg = (r) => localStorage.setItem(FN_KEY, JSON.stringify(r));
|
|
@@ -194,7 +300,7 @@ function limited(FN_KEY, fn, opts = {}) {
|
|
|
194
300
|
handle.block = () => (count = max, key && ((r) => (r[key] = max, setReg(r)))(getReg()));
|
|
195
301
|
return handle;
|
|
196
302
|
}
|
|
197
|
-
var mockAsync = (timeout = 250) => new Promise((resolve) => setTimeout(resolve, timeout));
|
|
303
|
+
var mockAsync = (timeout = 250) => new Promise((resolve) => (0, import_utils5.setTimeout)(resolve, timeout));
|
|
198
304
|
var breath = (w = window) => new Promise((res) => w.requestAnimationFrame(res));
|
|
199
305
|
var deepBreath = (w = window) => new Promise((res) => w.requestAnimationFrame(() => w.requestAnimationFrame(res)));
|
|
200
306
|
function bindCleanupToSignal(cleanup, signal) {
|
|
@@ -229,17 +335,24 @@ if ("undefined" !== typeof window) {
|
|
|
229
335
|
// Annotate the CommonJS export names for ESM import in node:
|
|
230
336
|
0 && (module.exports = {
|
|
231
337
|
INTERACTIVE_SELECTOR,
|
|
338
|
+
KEYS_BLOCKS,
|
|
232
339
|
NIL,
|
|
233
340
|
NOOP,
|
|
341
|
+
RAFLoop,
|
|
234
342
|
VIRTUAL_RESOURCE,
|
|
235
343
|
assignEl,
|
|
236
344
|
bindAllMethods,
|
|
237
345
|
bindCleanupToSignal,
|
|
238
346
|
breath,
|
|
347
|
+
camelize,
|
|
348
|
+
cancelRAFLoop,
|
|
349
|
+
capitalize,
|
|
239
350
|
clamp,
|
|
240
351
|
cleanKeyCombo,
|
|
241
352
|
cleanURL,
|
|
242
353
|
createEl,
|
|
354
|
+
createListRenderer,
|
|
355
|
+
debounce,
|
|
243
356
|
deepBreath,
|
|
244
357
|
formatKeyForDisplay,
|
|
245
358
|
formatKeyShortcutsForDisplay,
|
|
@@ -265,6 +378,7 @@ if ("undefined" !== typeof window) {
|
|
|
265
378
|
keyEventAllowed,
|
|
266
379
|
limited,
|
|
267
380
|
loadResource,
|
|
381
|
+
longestIncreasingSubsequence,
|
|
268
382
|
matchKeys,
|
|
269
383
|
mockAsync,
|
|
270
384
|
onAllMethods,
|
|
@@ -278,5 +392,7 @@ if ("undefined" !== typeof window) {
|
|
|
278
392
|
setInterval,
|
|
279
393
|
setTimeout,
|
|
280
394
|
stringifyKeyEvent,
|
|
281
|
-
|
|
395
|
+
throttle,
|
|
396
|
+
uid,
|
|
397
|
+
uncamelize
|
|
282
398
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { A as ArrowNavigationHandle } from './arrowNavigation-
|
|
2
|
-
import { S as ScrollAssistHandle } from './scrollAssist-
|
|
1
|
+
import { A as ArrowNavigationHandle } from './arrowNavigation-IaWiNTa6.cjs';
|
|
2
|
+
import { S as ScrollAssistHandle } from './scrollAssist-l0V2H-jx.cjs';
|
|
3
3
|
export { NIL, NOOP } from 'sia-reactor';
|
|
4
|
-
export { KeyStruct, assignEl, bindAllMethods, clamp, cleanKeyCombo, createEl, formatKeyForDisplay, formatKeyShortcutsForDisplay, getActiveEl, getTermsForKey, guardAllMethods, guardMethod, isObj, keyEventAllowed,
|
|
4
|
+
export { KEYS_BLOCKS, KeyStruct, KeysSettings, assignEl, bindAllMethods, clamp, cleanKeyCombo, createEl, formatKeyForDisplay, formatKeyShortcutsForDisplay, getActiveEl, getTermsForKey, guardAllMethods, guardMethod, isObj, keyEventAllowed, matchKeys, onAllMethods, parseForARIAKS, parseKeyCombo, requestAnimationFrame, setInterval, setTimeout, stringifyKeyEvent } from 'sia-reactor/utils';
|
|
5
5
|
|
|
6
6
|
declare global {
|
|
7
7
|
interface T007Namespace {
|
|
8
8
|
/** Symbol used to mark virtual resources that should not load a real asset. */
|
|
9
9
|
VIRTUAL_RESOURCE: symbol;
|
|
10
10
|
_resourceCache: Partial<Record<string, Promise<HTMLElement | void>>>;
|
|
11
|
+
_throttlers?: Map<string, number>;
|
|
12
|
+
_debouncers?: Map<string, number>;
|
|
13
|
+
_RAFLoopers?: Map<string, Function>;
|
|
11
14
|
_ftrappers?: WeakMap<HTMLElement, () => void>;
|
|
12
15
|
_outsiders?: WeakMap<HTMLElement, () => void>;
|
|
13
16
|
_arrownavs?: WeakMap<HTMLElement, ArrowNavigationHandle>;
|
|
@@ -37,6 +40,27 @@ declare global {
|
|
|
37
40
|
var t007: T007Namespace;
|
|
38
41
|
}
|
|
39
42
|
|
|
43
|
+
type TitleCase<S extends string> = S extends `${infer First}${infer Rest}`
|
|
44
|
+
? `${Uppercase<First>}${Rest}`
|
|
45
|
+
: S;
|
|
46
|
+
|
|
47
|
+
type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}`
|
|
48
|
+
? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}`
|
|
49
|
+
: S extends `${infer P1}-${infer P2}${infer P3}`
|
|
50
|
+
? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}`
|
|
51
|
+
: S extends `${infer P1} ${infer P2}${infer P3}`
|
|
52
|
+
? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}`
|
|
53
|
+
: Lowercase<S>;
|
|
54
|
+
|
|
55
|
+
type NoCamelCase<
|
|
56
|
+
S extends string,
|
|
57
|
+
Sep extends string = " "
|
|
58
|
+
> = S extends `${infer First}${infer Rest}`
|
|
59
|
+
? First extends Uppercase<First>
|
|
60
|
+
? `${Sep}${Lowercase<First>}${NoCamelCase<Rest, Sep>}`
|
|
61
|
+
: `${First}${NoCamelCase<Rest, Sep>}`
|
|
62
|
+
: S;
|
|
63
|
+
|
|
40
64
|
declare function isDef(val: any): boolean;
|
|
41
65
|
declare function isSym<T extends symbol = symbol>(val: any): val is T;
|
|
42
66
|
declare function isBool<T extends boolean = boolean>(val: any): val is T;
|
|
@@ -49,20 +73,52 @@ declare function isIter<T = unknown>(obj: any): obj is Iterable<T>;
|
|
|
49
73
|
declare function isFunc<T extends Function = Function>(val: any): val is T;
|
|
50
74
|
declare function inBoolArrOpt(opt: any, str: string): boolean;
|
|
51
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Finds the longest increasing subsequence in an array of numbers.
|
|
78
|
+
* @param array The input array of numbers
|
|
79
|
+
* @returns An array of indices representing the longest increasing subsequence
|
|
80
|
+
*/
|
|
81
|
+
declare function longestIncreasingSubsequence(array: number[]): number[];
|
|
82
|
+
|
|
52
83
|
/** Create a short unique string with an optional prefix.
|
|
53
84
|
* @param prefix Prefix added to the generated id.
|
|
54
85
|
* @returns A browser-safe unique id string.
|
|
55
86
|
*/
|
|
56
87
|
declare function uid(prefix?: string): string;
|
|
88
|
+
/** Capitalize the first letter of a string, leaving the rest unchanged.
|
|
89
|
+
* @param word The string to capitalize.
|
|
90
|
+
* @returns The input string with the first letter capitalized.
|
|
91
|
+
*/
|
|
92
|
+
declare function capitalize<T extends string>(word?: T): TitleCase<T>;
|
|
93
|
+
/** Convert a string to camelCase by removing separators and capitalizing subsequent words.
|
|
94
|
+
* @param str The input string to convert.
|
|
95
|
+
* @param options.source A regex or string defining word separators. @default whitespace, underscores, and hyphens (`[\s_-]+`).
|
|
96
|
+
* @param options.preserveInnerCase If true, preserves the original casing of letters; if false, converts the entire string to lowercase before processing. @default `true`.
|
|
97
|
+
* @param options.upperFirst If true, capitalizes the first letter of the resulting string (PascalCase); if false, lowercases the first letter (camelCase). @default `false`.
|
|
98
|
+
* @returns The camelCase version of the input string.
|
|
99
|
+
*/
|
|
100
|
+
declare function camelize<T extends string>(str?: T, { source }?: RegExp, { preserveInnerCase: pIC, upperFirst: uF }?: {
|
|
101
|
+
preserveInnerCase?: boolean | undefined;
|
|
102
|
+
upperFirst?: boolean | undefined;
|
|
103
|
+
}): CamelCase<T>;
|
|
104
|
+
/** Convert a camelCase or PascalCase string to a separator-based format (e.g. "helloWorld" to "hello-world").
|
|
105
|
+
* @param str The camelCase or PascalCase string to convert.
|
|
106
|
+
* @param separator The string to insert between words. @default a hyphen ("-").
|
|
107
|
+
* @returns The uncamelized version of the input string with separators.
|
|
108
|
+
* @example
|
|
109
|
+
* uncamelize("helloWorld") // "hello-world"
|
|
110
|
+
* uncamelize("HelloWorld", "_") // "hello_world"
|
|
111
|
+
*/
|
|
112
|
+
declare function uncamelize<T extends string, S extends string = " ">(str: T, separator?: S): NoCamelCase<T, S>;
|
|
57
113
|
/** Convert a rem value to pixels based on the font size of a given element.
|
|
58
114
|
* @param rem The rem value to convert.
|
|
59
|
-
* @param el The element to use for font size reference.
|
|
115
|
+
* @param el The element to use for font size reference. @default the root element.
|
|
60
116
|
* @returns The equivalent pixel value.
|
|
61
117
|
*/
|
|
62
118
|
declare function remToPx(rem: number, el?: HTMLElement): number;
|
|
63
119
|
/** Convert a pixel value to rem based on the font size of a given element.
|
|
64
120
|
* @param px The pixel value to convert.
|
|
65
|
-
* @param el The element to use for font size reference.
|
|
121
|
+
* @param el The element to use for font size reference. @default the root element.
|
|
66
122
|
* @returns The equivalent rem value.
|
|
67
123
|
*/
|
|
68
124
|
declare function pxToRem(px: number, el?: HTMLElement): number;
|
|
@@ -73,7 +129,7 @@ declare function pxToRem(px: number, el?: HTMLElement): number;
|
|
|
73
129
|
declare function parseCSSTime(time: any): number;
|
|
74
130
|
/** Parse a CSS size value (i.e. "16px" or "1.5rem") into pixels.
|
|
75
131
|
* @param size The CSS size string to parse.
|
|
76
|
-
* @param el The element to use for rem reference if needed.
|
|
132
|
+
* @param el The element to use for rem reference if needed. @default the root element.
|
|
77
133
|
* @returns The equivalent value in pixels.
|
|
78
134
|
*/
|
|
79
135
|
declare function parseCSSSize(size: any, el?: HTMLElement): number;
|
|
@@ -89,6 +145,38 @@ declare function cleanURL(url: string): string;
|
|
|
89
145
|
*/
|
|
90
146
|
declare function isSameURL(url1: unknown, url2: unknown): boolean;
|
|
91
147
|
|
|
148
|
+
/** Throttles a function, ensuring it's only called once within a specified delay period.
|
|
149
|
+
* @param key Unique identifier for the throttled function, used to track its last execution time.
|
|
150
|
+
* @param fn Function to be throttled.
|
|
151
|
+
* @param delay Time in milliseconds to wait before allowing the function to be called again. @default `30ms`.
|
|
152
|
+
* @param strict If `true`, exact timestamp difference between calls will be used else a `setTimeout()` will clear the throttle, allowing for more thread leniency. @default `true`.
|
|
153
|
+
* @param signal Optional `AbortSignal` to automatically clear the throttle when aborted.
|
|
154
|
+
* @param win Optional `Window` object for scheduling the throttle timeout, useful for testing or if running in a non-browser environment.
|
|
155
|
+
*/
|
|
156
|
+
declare function throttle(key: string, fn: Function, delay?: number, strict?: ((fn: Function) => number) | boolean, signal?: AbortSignal, win?: Window): void;
|
|
157
|
+
/** Debounces a function, ensuring it's only called after a quiet period of no further calls.
|
|
158
|
+
* @param key Unique identifier for the debounced function, used to track pending calls.
|
|
159
|
+
* @param fn Function to be debounced.
|
|
160
|
+
* @param delay Time in milliseconds to wait after the latest call before invoking the function. @default `30ms`.
|
|
161
|
+
* @param strict If `true`, exact timestamp difference between calls will be used else pending timeout is reset each call for practical thread leniency. @default `true`.
|
|
162
|
+
* @param signal Optional `AbortSignal` to automatically clear scheduled debounce execution when aborted.
|
|
163
|
+
* @param win Optional `Window` object for scheduling/clearing the debounce timeout, useful for testing or if running in a non-browser environment.
|
|
164
|
+
*/
|
|
165
|
+
declare function debounce(key: string, fn: Function, delay?: number, strict?: boolean, signal?: AbortSignal, win?: Window): void;
|
|
166
|
+
/** Creates a loop using `requestAnimationFrame`, allowing for efficient execution of a function on every frame.
|
|
167
|
+
* @param key Unique identifier for the loop, used to manage its execution and allow for updates or cancellation.
|
|
168
|
+
* @param fn Function to be executed on every frame.
|
|
169
|
+
* @param signal Optional `AbortSignal` to automatically cancel the loop when aborted.
|
|
170
|
+
* @param win Optional `Window` object for scheduling the animation frame, useful for testing or if running in a non-browser environment.
|
|
171
|
+
*
|
|
172
|
+
* Game-like loops will be our lil secret... ~ "The Smoooth Criminal" :)
|
|
173
|
+
*/
|
|
174
|
+
declare function RAFLoop(key: string, fn: Function, signal?: AbortSignal, win?: Window & typeof globalThis): void;
|
|
175
|
+
/** Cancels a loop created by `RAFLoop`.
|
|
176
|
+
* @param key Unique identifier for the loop to be cancelled.
|
|
177
|
+
* @returns True if the loop was successfully cancelled, false if no loop with the given key exists.
|
|
178
|
+
*/
|
|
179
|
+
declare const cancelRAFLoop: (key: string) => boolean;
|
|
92
180
|
interface LimitedOptions {
|
|
93
181
|
/** Storage key used to persist call counts. */
|
|
94
182
|
key?: string;
|
|
@@ -137,7 +225,7 @@ declare const deepBreath: (w?: Window & typeof globalThis) => Promise<unknown>;
|
|
|
137
225
|
declare function bindCleanupToSignal<Cb extends () => any>(cleanup: Cb, signal?: AbortSignal): Cb;
|
|
138
226
|
|
|
139
227
|
/** Exhaustive Selector used for interactive, tabbable UI controls. */
|
|
140
|
-
declare const INTERACTIVE_SELECTOR = ":is(button,[href],input:not([type='hidden']),select,textarea,details>summary,[contenteditable
|
|
228
|
+
declare const INTERACTIVE_SELECTOR = ":is(button,[href],input:not([type='hidden']),select,textarea,details>summary,[contenteditable],iframe,audio[controls],video[controls],[tabindex]):not([disabled],[tabindex='-1'],[data-focus-guard],[inert],[inert] *)";
|
|
141
229
|
/** Check whether an event target points to an interactive element. */
|
|
142
230
|
declare const isInteractive: (target: EventTarget | null) => boolean;
|
|
143
231
|
/** Resource type accepted by loadResource. */
|
|
@@ -169,16 +257,47 @@ declare const VIRTUAL_RESOURCE: symbol;
|
|
|
169
257
|
* @param req Resource URL or virtual resource symbol.
|
|
170
258
|
* @param type Resource type to load.
|
|
171
259
|
* @param options Resource loading options.
|
|
172
|
-
* @param
|
|
260
|
+
* @param win Window-like target used for DOM insertion.
|
|
173
261
|
* @returns Promise resolving to the created element or void.
|
|
174
262
|
*/
|
|
175
|
-
declare function loadResource(req: string | symbol, type?: ResourceType, { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts, retryKey }?: LoadResourceOptions,
|
|
263
|
+
declare function loadResource(req: string | symbol, type?: ResourceType, { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts, retryKey }?: LoadResourceOptions, win?: Window & typeof globalThis): Promise<HTMLElement | void>;
|
|
176
264
|
|
|
177
265
|
/** Get the window object associated with a given element.
|
|
178
266
|
* @param el The element to get the window for, defaults to the main window.
|
|
179
|
-
* @returns The
|
|
267
|
+
* @returns The `Window` object or undefined if none found.
|
|
268
|
+
*/
|
|
269
|
+
declare function getWindow(el?: any): Window & typeof globalThis;
|
|
270
|
+
/** Options for configuring a list renderer */
|
|
271
|
+
type ListRendererOptions<T> = {
|
|
272
|
+
/** The container element to render the list into */
|
|
273
|
+
container: HTMLElement;
|
|
274
|
+
/** Function to extract a unique key from each item.
|
|
275
|
+
* @param item The item to extract the key from
|
|
276
|
+
* @returns A unique string key for the item
|
|
277
|
+
*/
|
|
278
|
+
getKey: (item: T) => string;
|
|
279
|
+
/** Function to create a DOM node for an item.
|
|
280
|
+
* @param item The item to create a node for
|
|
281
|
+
* @returns An HTMLElement representing the item, or null/undefined to skip rendering
|
|
282
|
+
*/
|
|
283
|
+
createNode: (item: T) => HTMLElement | null | undefined;
|
|
284
|
+
/** Optional function to update an existing node with new item data, called when an item is reused.
|
|
285
|
+
* @param node The existing DOM node for the item
|
|
286
|
+
* @param item The new item data to update the node with
|
|
287
|
+
*/
|
|
288
|
+
updateNode?: (node: HTMLElement, item: T) => void;
|
|
289
|
+
/** Optional function to clean up a DOM node when an item is removed, called before the node is removed from the DOM.
|
|
290
|
+
* @param node The DOM node to be removed
|
|
291
|
+
* @param key The unique key of the item associated with the node
|
|
292
|
+
*/
|
|
293
|
+
destroyNode?: (node: HTMLElement, key: string) => void;
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
296
|
+
* Creates a list renderer function for efficiently updating a DOM list based on a new array of items using the L.I.S(Longest Increasing Subsequence) algorithm.
|
|
297
|
+
* @param param0 The options for configuring the list renderer
|
|
298
|
+
* @returns A function that synchronizes the DOM with the new array of items
|
|
180
299
|
*/
|
|
181
|
-
declare function
|
|
300
|
+
declare function createListRenderer<T>({ container, getKey, createNode, updateNode, destroyNode }: ListRendererOptions<T>): (array: T[], strict?: boolean) => void;
|
|
182
301
|
|
|
183
302
|
/** Format a file size for display.
|
|
184
303
|
* @param size Size in bytes.
|
|
@@ -188,4 +307,4 @@ declare function getWindow(el?: any): (Window & typeof globalThis) | undefined;
|
|
|
188
307
|
*/
|
|
189
308
|
declare function formatSize(bytes: number, decimals?: number, base?: number): string;
|
|
190
309
|
|
|
191
|
-
export { INTERACTIVE_SELECTOR, type LimitedHandle, type LimitedOptions, type LoadResourceOptions, type ResourceType, VIRTUAL_RESOURCE, bindCleanupToSignal, breath, cleanURL, deepBreath, formatSize, getWindow, inBoolArrOpt, isArr, isBool, isDef, isFunc, isInteractive, isIter, isNum, isPOJO, isSameURL, isStr, isSym, limited, loadResource, mockAsync, parseCSSSize, parseCSSTime, pxToRem, remToPx, uid };
|
|
310
|
+
export { type CamelCase, INTERACTIVE_SELECTOR, type LimitedHandle, type LimitedOptions, type ListRendererOptions, type LoadResourceOptions, type NoCamelCase, RAFLoop, type ResourceType, type TitleCase, VIRTUAL_RESOURCE, bindCleanupToSignal, breath, camelize, cancelRAFLoop, capitalize, cleanURL, createListRenderer, debounce, deepBreath, formatSize, getWindow, inBoolArrOpt, isArr, isBool, isDef, isFunc, isInteractive, isIter, isNum, isPOJO, isSameURL, isStr, isSym, limited, loadResource, longestIncreasingSubsequence, mockAsync, parseCSSSize, parseCSSTime, pxToRem, remToPx, throttle, uid, uncamelize };
|