@syware/jlib 0.13.0 → 0.14.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.
- package/dist/atoms/jl-progress-ring.js +3 -2
- package/dist/atoms/jl-progress.js +3 -2
- package/dist/index.d.ts +1 -1
- package/dist/lib/hotkey.d.ts +13 -0
- package/dist/lib/hotkey.js +2 -1
- package/dist/lib/key-shortcut.js +11 -29
- package/dist/lib/progress.d.ts +0 -5
- package/dist/lib/progress.js +1 -9
- package/dist/lib/roving.d.ts +6 -0
- package/dist/lib/roving.js +14 -1
- package/dist/molecules/jl-chip-group.js +1 -1
- package/dist/molecules/jl-radio-group.js +1 -1
- package/dist/molecules/jl-toast.js +2 -2
- package/dist/organisms/jl-command-palette.js +1 -1
- package/dist/organisms/jl-table.d.ts +1 -1
- package/dist/organisms/jl-table.js +6 -2
- package/package.json +4 -2
- package/dist/lib/roving-index.d.ts +0 -10
- package/dist/lib/roving-index.js +0 -32
- /package/dist/types/{roving-index.types.d.ts → roving.types.d.ts} +0 -0
|
@@ -2,7 +2,8 @@ import { BASE_STYLES } from "../styles/shared.js";
|
|
|
2
2
|
import { JlElement } from "../base/jl-element.js";
|
|
3
3
|
import { oneOf } from "../lib/attributes.js";
|
|
4
4
|
import { svgElement } from "../lib/dom.js";
|
|
5
|
-
import {
|
|
5
|
+
import { parseNumber } from "../lib/numeric.js";
|
|
6
|
+
import { percentLabel, percentOf, progressRatio, ringGeometry } from "../lib/progress.js";
|
|
6
7
|
import { PROGRESS_TONES } from "./jl-progress.js";
|
|
7
8
|
import jl_progress_ring_default from "./jl-progress-ring.css.js";
|
|
8
9
|
import { css } from "@jadis/core";
|
|
@@ -22,7 +23,7 @@ var JlProgressRing = class extends JlElement {
|
|
|
22
23
|
/** How much is done, out of `max`; `null` (no attribute) for work of unknown length. */
|
|
23
24
|
value = this.useChange(null, () => this.renderValue(), {
|
|
24
25
|
attribute: "value",
|
|
25
|
-
parse:
|
|
26
|
+
parse: parseNumber
|
|
26
27
|
});
|
|
27
28
|
max = this.useChange(DEFAULT_MAX, () => this.renderValue(), { attribute: "max" });
|
|
28
29
|
/** The ring's width and height, in pixels. */
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { BASE_STYLES } from "../styles/shared.js";
|
|
2
2
|
import { JlElement } from "../base/jl-element.js";
|
|
3
3
|
import { oneOf } from "../lib/attributes.js";
|
|
4
|
-
import {
|
|
4
|
+
import { parseNumber } from "../lib/numeric.js";
|
|
5
|
+
import { percentLabel, percentOf, progressRatio } from "../lib/progress.js";
|
|
5
6
|
import jl_progress_default from "./jl-progress.css.js";
|
|
6
7
|
import { css } from "@jadis/core";
|
|
7
8
|
import { jsx, jsxs } from "@jadis/core/jsx-runtime";
|
|
@@ -24,7 +25,7 @@ var JlProgress = class extends JlElement {
|
|
|
24
25
|
/** How much is done, out of `max`; `null` (no attribute) for work of unknown length. */
|
|
25
26
|
value = this.useChange(null, () => this.render(), {
|
|
26
27
|
attribute: "value",
|
|
27
|
-
parse:
|
|
28
|
+
parse: parseNumber
|
|
28
29
|
});
|
|
29
30
|
max = this.useChange(DEFAULT_MAX, () => this.render(), { attribute: "max" });
|
|
30
31
|
tone = this.useChange("accent", (value) => this.reflect("tone", value), {
|
package/dist/index.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export type * from './types/keycaps.types';
|
|
|
66
66
|
export type * from './types/option-filter.types';
|
|
67
67
|
export type * from './types/options.types';
|
|
68
68
|
export type * from './types/pagination.types';
|
|
69
|
-
export type * from './types/roving
|
|
69
|
+
export type * from './types/roving.types';
|
|
70
70
|
export type * from './types/sparkline.types';
|
|
71
71
|
export type * from './types/texts.types';
|
|
72
72
|
export * from './atoms/jl-app-icon';
|
package/dist/lib/hotkey.d.ts
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import type { Hotkey, KeyPress } from '../types/hotkey.types';
|
|
2
|
+
export type Modifier = 'mod' | 'ctrl' | 'meta' | 'shift' | 'alt';
|
|
3
|
+
/** The words a key combination may use for each modifier: "mod+k", "cmd+shift+p", "ctrl+/". */
|
|
4
|
+
export declare const MODIFIER_NAMES: Record<string, Modifier>;
|
|
5
|
+
/** How each modifier reads on a keycap, on Apple keyboards and elsewhere. */
|
|
6
|
+
export declare const MODIFIER_LABELS: Record<Modifier, {
|
|
7
|
+
apple: string;
|
|
8
|
+
other: string;
|
|
9
|
+
}>;
|
|
10
|
+
/** The order keycaps are written in: ⌃⌥⇧⌘ on Apple, Ctrl+Alt+Shift elsewhere. */
|
|
11
|
+
export declare const MODIFIER_ORDER: {
|
|
12
|
+
apple: readonly Modifier[];
|
|
13
|
+
other: readonly Modifier[];
|
|
14
|
+
};
|
|
2
15
|
/** Reads a combination such as `mod+k` or `ctrl+shift+p`: `mod` is ⌘ on Apple and Ctrl elsewhere. */
|
|
3
16
|
export declare function parseHotkey(text: string): Hotkey;
|
|
4
17
|
/** Whether a key press is the combination; extra modifiers make it another one. */
|
package/dist/lib/hotkey.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/lib/hotkey.ts
|
|
2
2
|
var SEPARATOR = "+";
|
|
3
|
+
/** The words a key combination may use for each modifier: "mod+k", "cmd+shift+p", "ctrl+/". */
|
|
3
4
|
var MODIFIER_NAMES = {
|
|
4
5
|
alt: "alt",
|
|
5
6
|
cmd: "meta",
|
|
@@ -98,4 +99,4 @@ function hotkeyLabels(text, apple) {
|
|
|
98
99
|
function isApplePlatform(platform) {
|
|
99
100
|
return /mac|iphone|ipad|ipod/i.test(platform);
|
|
100
101
|
}
|
|
101
|
-
export { hotkeyLabels, isApplePlatform, matchesHotkey, parseHotkey };
|
|
102
|
+
export { MODIFIER_LABELS, MODIFIER_NAMES, MODIFIER_ORDER, hotkeyLabels, isApplePlatform, matchesHotkey, parseHotkey };
|
package/dist/lib/key-shortcut.js
CHANGED
|
@@ -1,25 +1,7 @@
|
|
|
1
|
+
import { MODIFIER_LABELS, MODIFIER_NAMES, MODIFIER_ORDER } from "./hotkey.js";
|
|
1
2
|
// src/lib/key-shortcut.ts
|
|
2
|
-
/** The words a shortcut may use for each modifier: "mod+k", "cmd+shift+p", "ctrl+/". */
|
|
3
|
-
var MODIFIER_WORDS = {
|
|
4
|
-
alt: "alt",
|
|
5
|
-
cmd: "meta",
|
|
6
|
-
command: "meta",
|
|
7
|
-
control: "ctrl",
|
|
8
|
-
ctrl: "ctrl",
|
|
9
|
-
meta: "meta",
|
|
10
|
-
mod: "mod",
|
|
11
|
-
option: "alt",
|
|
12
|
-
shift: "shift"
|
|
13
|
-
};
|
|
14
3
|
var SEPARATOR = "+";
|
|
15
|
-
var isModifierWord = (word) => Object.hasOwn(
|
|
16
|
-
var MAC_SYMBOLS = {
|
|
17
|
-
alt: "⌥",
|
|
18
|
-
ctrl: "⌃",
|
|
19
|
-
meta: "⌘",
|
|
20
|
-
mod: "⌘",
|
|
21
|
-
shift: "⇧"
|
|
22
|
-
};
|
|
4
|
+
var isModifierWord = (word) => Object.hasOwn(MODIFIER_NAMES, word);
|
|
23
5
|
var PC_NAMES = {
|
|
24
6
|
alt: "Alt",
|
|
25
7
|
ctrl: "Ctrl",
|
|
@@ -27,6 +9,13 @@ var PC_NAMES = {
|
|
|
27
9
|
mod: "Ctrl",
|
|
28
10
|
shift: "Shift"
|
|
29
11
|
};
|
|
12
|
+
var MAC_SYMBOLS = {
|
|
13
|
+
alt: MODIFIER_LABELS.alt.apple,
|
|
14
|
+
ctrl: MODIFIER_LABELS.ctrl.apple,
|
|
15
|
+
meta: MODIFIER_LABELS.meta.apple,
|
|
16
|
+
mod: MODIFIER_LABELS.mod.apple,
|
|
17
|
+
shift: MODIFIER_LABELS.shift.apple
|
|
18
|
+
};
|
|
30
19
|
var ARIA_NAMES = {
|
|
31
20
|
alt: "Alt",
|
|
32
21
|
ctrl: "Control",
|
|
@@ -34,13 +23,6 @@ var ARIA_NAMES = {
|
|
|
34
23
|
mod: "Control",
|
|
35
24
|
shift: "Shift"
|
|
36
25
|
};
|
|
37
|
-
var MODIFIER_ORDER = [
|
|
38
|
-
"ctrl",
|
|
39
|
-
"alt",
|
|
40
|
-
"shift",
|
|
41
|
-
"mod",
|
|
42
|
-
"meta"
|
|
43
|
-
];
|
|
44
26
|
/** Names of keys that read better than their `KeyboardEvent.key`. */
|
|
45
27
|
var KEY_LABELS = {
|
|
46
28
|
" ": "Space",
|
|
@@ -59,7 +41,7 @@ function parseShortcut(text) {
|
|
|
59
41
|
const parts = text.trim().toLowerCase().split(SEPARATOR).map((part) => part.trim());
|
|
60
42
|
const key = parts.at(-1) ?? "";
|
|
61
43
|
if (key === "" || isModifierWord(key)) return null;
|
|
62
|
-
const modifiers = new Set(parts.slice(0, -1).filter(isModifierWord).map((part) =>
|
|
44
|
+
const modifiers = new Set(parts.slice(0, -1).filter(isModifierWord).map((part) => MODIFIER_NAMES[part]));
|
|
63
45
|
return {
|
|
64
46
|
alt: modifiers.has("alt"),
|
|
65
47
|
ctrl: modifiers.has("ctrl"),
|
|
@@ -81,7 +63,7 @@ function matchesShortcut(event, shortcut, mac) {
|
|
|
81
63
|
const shiftMatters = shortcut.shift || hasCommandModifier(shortcut);
|
|
82
64
|
return event.key.toLowerCase() === shortcut.key && event.ctrlKey === wantsCtrl && event.metaKey === wantsMeta && event.altKey === shortcut.alt && (!shiftMatters || event.shiftKey === shortcut.shift);
|
|
83
65
|
}
|
|
84
|
-
var activeModifiers = (shortcut) => MODIFIER_ORDER.filter((modifier) => shortcut[modifier]);
|
|
66
|
+
var activeModifiers = (shortcut) => MODIFIER_ORDER.apple.filter((modifier) => shortcut[modifier]);
|
|
85
67
|
var keyLabel = (key) => KEY_LABELS[key] ?? (key.length === 1 ? key.toUpperCase() : key);
|
|
86
68
|
/** The keys to draw for a shortcut, one label per key: ["⌘", "K"] on a Mac, ["Ctrl", "K"] elsewhere. */
|
|
87
69
|
function shortcutLabels(shortcut, mac) {
|
package/dist/lib/progress.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A number attribute that may be absent: `null` when it is missing or unreadable. A progress without a value is
|
|
3
|
-
* indeterminate.
|
|
4
|
-
*/
|
|
5
|
-
export declare const optionalNumber: (value: string | null) => number | null;
|
|
6
1
|
/** How far along a value is, from 0 to 1; a maximum of 0 or less counts as no progress. */
|
|
7
2
|
export declare function progressRatio(value: number, max: number): number;
|
|
8
3
|
/** A ratio as the percentage people read: 0.456 gives "46%". */
|
package/dist/lib/progress.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
// src/lib/progress.ts
|
|
2
2
|
var PERCENT = 100;
|
|
3
|
-
/**
|
|
4
|
-
* A number attribute that may be absent: `null` when it is missing or unreadable. A progress without a value is
|
|
5
|
-
* indeterminate.
|
|
6
|
-
*/
|
|
7
|
-
var optionalNumber = (value) => {
|
|
8
|
-
const parsed = value === null || value.trim() === "" ? NaN : Number(value);
|
|
9
|
-
return Number.isFinite(parsed) ? parsed : null;
|
|
10
|
-
};
|
|
11
3
|
/** How far along a value is, from 0 to 1; a maximum of 0 or less counts as no progress. */
|
|
12
4
|
function progressRatio(value, max) {
|
|
13
5
|
if (!(max > 0) || !Number.isFinite(value)) return 0;
|
|
@@ -30,4 +22,4 @@ function ringGeometry(size, thickness) {
|
|
|
30
22
|
stroke
|
|
31
23
|
};
|
|
32
24
|
}
|
|
33
|
-
export {
|
|
25
|
+
export { percentLabel, percentOf, progressRatio, ringGeometry };
|
package/dist/lib/roving.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RovingMove } from '../types/roving.types';
|
|
1
2
|
/** The first entry that can be chosen. */
|
|
2
3
|
export declare const firstIndex: (enabled: readonly boolean[]) => number;
|
|
3
4
|
/** The last entry that can be chosen. */
|
|
@@ -9,3 +10,8 @@ export declare function stepIndex(enabled: readonly boolean[], from: number, ste
|
|
|
9
10
|
* ignores case and the spaces before the label.
|
|
10
11
|
*/
|
|
11
12
|
export declare function letterIndex(labels: readonly string[], enabled: readonly boolean[], from: number, letter: string): number;
|
|
13
|
+
/**
|
|
14
|
+
* Where the arrow keys of a list or a radio group move the focus, skipping the disabled items as native radios do.
|
|
15
|
+
* The list says which items are disabled; from nowhere (-1), next starts at the first item and previous at the last.
|
|
16
|
+
*/
|
|
17
|
+
export declare function rovingIndex(disabled: readonly boolean[], from: number, move: RovingMove): number;
|
package/dist/lib/roving.js
CHANGED
|
@@ -18,4 +18,17 @@ function letterIndex(labels, enabled, from, letter) {
|
|
|
18
18
|
const wanted = letter.toLocaleLowerCase();
|
|
19
19
|
return stepIndex(labels.map((label, index) => enabled[index] === true && label.trim().toLocaleLowerCase().startsWith(wanted)), from, 1);
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Where the arrow keys of a list or a radio group move the focus, skipping the disabled items as native radios do.
|
|
23
|
+
* The list says which items are disabled; from nowhere (-1), next starts at the first item and previous at the last.
|
|
24
|
+
*/
|
|
25
|
+
function rovingIndex(disabled, from, move) {
|
|
26
|
+
const enabled = disabled.map((isDisabled) => !isDisabled);
|
|
27
|
+
return {
|
|
28
|
+
first: () => firstIndex(enabled),
|
|
29
|
+
last: () => lastIndex(enabled),
|
|
30
|
+
next: () => stepIndex(enabled, from, 1),
|
|
31
|
+
previous: () => stepIndex(enabled, from === NONE ? disabled.length : from, -1)
|
|
32
|
+
}[move]();
|
|
33
|
+
}
|
|
34
|
+
export { firstIndex, lastIndex, letterIndex, rovingIndex, stepIndex };
|
|
@@ -6,7 +6,7 @@ import { registerIcons } from "../lib/icons.js";
|
|
|
6
6
|
import { CONTROL_SIZES } from "../lib/options.js";
|
|
7
7
|
import { JlIcon } from "../atoms/jl-icon.js";
|
|
8
8
|
import { setOrRemove } from "../lib/dom.js";
|
|
9
|
-
import { rovingIndex } from "../lib/roving
|
|
9
|
+
import { rovingIndex } from "../lib/roving.js";
|
|
10
10
|
import jl_chip_group_default from "./jl-chip-group.css.js";
|
|
11
11
|
import { css } from "@jadis/core";
|
|
12
12
|
import { Check } from "lucide";
|
|
@@ -2,7 +2,7 @@ import { jlText } from "../lib/texts.js";
|
|
|
2
2
|
import { BASE_STYLES } from "../styles/shared.js";
|
|
3
3
|
import { JlFormControl } from "../base/jl-form-control.js";
|
|
4
4
|
import { jsonOf, oneOf, textOf } from "../lib/attributes.js";
|
|
5
|
-
import { rovingIndex } from "../lib/roving
|
|
5
|
+
import { rovingIndex } from "../lib/roving.js";
|
|
6
6
|
import jl_radio_group_default from "./jl-radio-group.css.js";
|
|
7
7
|
import { css } from "@jadis/core";
|
|
8
8
|
import { jsx, jsxs } from "@jadis/core/jsx-runtime";
|
|
@@ -6,7 +6,7 @@ import { registerIcons } from "../lib/icons.js";
|
|
|
6
6
|
import { TONE_ICONS, TONE_ICON_FILLED } from "../lib/options.js";
|
|
7
7
|
import { JlIcon } from "../atoms/jl-icon.js";
|
|
8
8
|
import { JlButton } from "../atoms/jl-button.js";
|
|
9
|
-
import {
|
|
9
|
+
import { parseNumber } from "../lib/numeric.js";
|
|
10
10
|
import { JlProgress } from "../atoms/jl-progress.js";
|
|
11
11
|
import jl_toast_default from "./jl-toast.css.js";
|
|
12
12
|
import { css } from "@jadis/core";
|
|
@@ -89,7 +89,7 @@ var JlToast = class extends JlElement {
|
|
|
89
89
|
/** How far the work is, in percent; `null` (no attribute) for work of unknown length. */
|
|
90
90
|
progress = this.useChange(null, (value) => this._refs.work.value.set(value), {
|
|
91
91
|
attribute: "progress",
|
|
92
|
-
parse:
|
|
92
|
+
parse: parseNumber
|
|
93
93
|
});
|
|
94
94
|
_timer = {
|
|
95
95
|
animation: null,
|
|
@@ -6,8 +6,8 @@ import { registerIcons } from "../lib/icons.js";
|
|
|
6
6
|
import { JlIcon } from "../atoms/jl-icon.js";
|
|
7
7
|
import { setOrRemove } from "../lib/dom.js";
|
|
8
8
|
import { JlSpinner } from "../atoms/jl-spinner.js";
|
|
9
|
-
import { highlightSegments } from "../lib/fuzzy.js";
|
|
10
9
|
import { hotkeyLabels, isApplePlatform, matchesHotkey, parseHotkey } from "../lib/hotkey.js";
|
|
10
|
+
import { highlightSegments } from "../lib/fuzzy.js";
|
|
11
11
|
import { groupMatches, matchCommands } from "../lib/palette.js";
|
|
12
12
|
import jl_command_palette_default from "./jl-command-palette.css.js";
|
|
13
13
|
import { css } from "@jadis/core";
|
|
@@ -158,7 +158,7 @@ export declare class JlTable<Row extends object = TableRow, Extra extends string
|
|
|
158
158
|
* row changes that row alone, whatever the number of rows.
|
|
159
159
|
*/
|
|
160
160
|
private redraw;
|
|
161
|
-
/** The bar and the shade of marked rows, changed in place. */
|
|
161
|
+
/** The bar and the shade of marked rows, changed in place; `aria-selected` tells a screen reader the same. */
|
|
162
162
|
private renderMarks;
|
|
163
163
|
/** The details of the open rows, added under them and taken away in place: one that stays open keeps its content. */
|
|
164
164
|
private renderExpansion;
|
|
@@ -474,6 +474,7 @@ var JlTable = class extends JlElement {
|
|
|
474
474
|
const expand = this.isExpandable();
|
|
475
475
|
return Array.from({ length: SKELETON_ROWS }, () => /* @__PURE__ */ jsxs("tr", {
|
|
476
476
|
class: "skeleton",
|
|
477
|
+
attrs: { "aria-hidden": "true" },
|
|
477
478
|
children: [
|
|
478
479
|
select ? /* @__PURE__ */ jsx("td", {
|
|
479
480
|
class: "select-cell",
|
|
@@ -514,9 +515,12 @@ var JlTable = class extends JlElement {
|
|
|
514
515
|
this._view.shown[state] = keys;
|
|
515
516
|
for (const { key, open } of changes) for (const { element } of this._view.byKey.get(key) ?? []) draw(element, open);
|
|
516
517
|
}
|
|
517
|
-
/** The bar and the shade of marked rows, changed in place. */
|
|
518
|
+
/** The bar and the shade of marked rows, changed in place; `aria-selected` tells a screen reader the same. */
|
|
518
519
|
renderMarks() {
|
|
519
|
-
this.redraw("marked", this.marked.get(), (element, on) =>
|
|
520
|
+
this.redraw("marked", this.marked.get(), (element, on) => {
|
|
521
|
+
element.toggleAttribute(MARKED_ATTRIBUTE, on);
|
|
522
|
+
setOrRemove(element, "aria-selected", on ? "true" : "");
|
|
523
|
+
});
|
|
520
524
|
}
|
|
521
525
|
/** The details of the open rows, added under them and taken away in place: one that stays open keeps its content. */
|
|
522
526
|
renderExpansion() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syware/jlib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "A tree-shakeable component library on Jadis and native Web Components, organised in atomic design",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"size": "npm run build:lib && npm run size:report",
|
|
76
76
|
"size:report": "node scripts/size-report.mjs",
|
|
77
77
|
"test": "vitest run",
|
|
78
|
+
"postinstall": "npx skills update -p -y",
|
|
78
79
|
"test:watch": "vitest",
|
|
79
80
|
"test:e2e": "npm run build:site && vitest run --config vitest.e2e.config.ts",
|
|
80
81
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
@@ -86,7 +87,7 @@
|
|
|
86
87
|
"version": "node scripts/plugin-version.mjs"
|
|
87
88
|
},
|
|
88
89
|
"peerDependencies": {
|
|
89
|
-
"@jadis/core": "^1.
|
|
90
|
+
"@jadis/core": "^1.8.0"
|
|
90
91
|
},
|
|
91
92
|
"dependencies": {
|
|
92
93
|
"lucide": "^1.61.0"
|
|
@@ -97,6 +98,7 @@
|
|
|
97
98
|
"@fontsource-variable/manrope": "^5.3.0",
|
|
98
99
|
"@jadis/core": "^1.8.0",
|
|
99
100
|
"@types/node": "^24.13.3",
|
|
101
|
+
"happy-dom": "^21.0.4",
|
|
100
102
|
"playwright-core": "^1.64.1",
|
|
101
103
|
"typescript": "^7.0.2",
|
|
102
104
|
"vite": "^8.3.5",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { RovingMove } from '../types/roving-index.types';
|
|
2
|
-
/** The first item that is not disabled, or -1 when every item is. */
|
|
3
|
-
export declare function firstEnabledIndex(disabled: readonly boolean[]): number;
|
|
4
|
-
/** The last item that is not disabled, or -1 when every item is. */
|
|
5
|
-
export declare function lastEnabledIndex(disabled: readonly boolean[]): number;
|
|
6
|
-
/**
|
|
7
|
-
* Where a move goes from the item at `from`, skipping disabled items as native radios do. From nowhere (-1), next
|
|
8
|
-
* starts at the first item and previous at the last.
|
|
9
|
-
*/
|
|
10
|
-
export declare function rovingIndex(disabled: readonly boolean[], from: number, move: RovingMove): number;
|
package/dist/lib/roving-index.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// src/lib/roving-index.ts
|
|
2
|
-
var NONE = -1;
|
|
3
|
-
/** The first item that is not disabled, or -1 when every item is. */
|
|
4
|
-
function firstEnabledIndex(disabled) {
|
|
5
|
-
return disabled.indexOf(false);
|
|
6
|
-
}
|
|
7
|
-
/** The last item that is not disabled, or -1 when every item is. */
|
|
8
|
-
function lastEnabledIndex(disabled) {
|
|
9
|
-
return disabled.lastIndexOf(false);
|
|
10
|
-
}
|
|
11
|
-
/** The next enabled item after `from` in a direction, wrapping around the ends; -1 when none is enabled. */
|
|
12
|
-
function steppedIndex(disabled, from, step) {
|
|
13
|
-
const count = disabled.length;
|
|
14
|
-
for (let offset = 1; offset <= count; offset += 1) {
|
|
15
|
-
const index = ((from + step * offset) % count + count) % count;
|
|
16
|
-
if (disabled[index] === false) return index;
|
|
17
|
-
}
|
|
18
|
-
return NONE;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Where a move goes from the item at `from`, skipping disabled items as native radios do. From nowhere (-1), next
|
|
22
|
-
* starts at the first item and previous at the last.
|
|
23
|
-
*/
|
|
24
|
-
function rovingIndex(disabled, from, move) {
|
|
25
|
-
return {
|
|
26
|
-
first: () => firstEnabledIndex(disabled),
|
|
27
|
-
last: () => lastEnabledIndex(disabled),
|
|
28
|
-
next: () => steppedIndex(disabled, from, 1),
|
|
29
|
-
previous: () => steppedIndex(disabled, from === NONE ? disabled.length : from, -1)
|
|
30
|
-
}[move]();
|
|
31
|
-
}
|
|
32
|
-
export { firstEnabledIndex, lastEnabledIndex, rovingIndex };
|
|
File without changes
|