@fusion.dev/helix-core 0.235.1 → 0.237.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/custom-elements.json +1 -1
- package/dist/controllers/floating-controller/floating-controller.d.ts +10 -0
- package/dist/controllers/floating-controller/floating-controller.js +7 -1
- package/dist/controllers/popover-controller/popover-controller.d.ts +2 -0
- package/dist/controllers/popover-controller/popover-controller.js +1 -0
- package/dist/helix-element/helix-element.js +2 -0
- package/dist/helix-element/react-audit.d.ts +2 -1
- package/dist/helix-element/react-bridge.js +2 -1
- package/dist/helix-form-element/helix-form-element-base.d.ts +7 -0
- package/dist/helix-form-element/helix-form-element-base.js +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.js +5 -4
- package/dist/mixins/mixin-chart-status/mixin-chart-status.d.ts +19 -5
- package/dist/mixins/mixin-chart-status/mixin-chart-status.js +8 -0
- package/dist/mixins/mixin-picker-field/mixin-picker-field.js +3 -2
- package/dist/mixins/mixin-viewport/mixin-viewport.d.ts +5 -1
- package/dist/mixins/mixin-viewport/mixin-viewport.js +23 -4
- package/dist/utils/audit-seed/audit-seed-off.d.ts +10 -0
- package/dist/utils/audit-seed/audit-seed-off.js +1 -0
- package/dist/utils/audit-seed/audit-seed.d.ts +58 -0
- package/dist/utils/audit-seed/audit-seed.js +171 -0
- package/dist/utils/box-labels/box-labels.js +64 -12
- package/dist/utils/filter-marks/filter-marks.d.ts +7 -0
- package/dist/utils/filter-marks/filter-marks.js +9 -1
- package/dist/utils/find-text/find-text.js +1 -0
- package/dist/utils/focusable-elements/focusable-elements.d.ts +36 -0
- package/dist/utils/focusable-elements/focusable-elements.js +22 -0
- package/dist/utils/format-numbers/format-numbers.js +6 -1
- package/dist/utils/number-format/number-format.d.ts +6 -0
- package/dist/utils/number-format/number-format.js +1 -0
- package/dist/utils/report-runtime/report-runtime.d.ts +4 -0
- package/dist/utils/scale/ticks.d.ts +30 -0
- package/dist/utils/scale/ticks.js +34 -7
- package/dist/utils/scroll-lock/scroll-lock.d.ts +30 -0
- package/dist/utils/scroll-lock/scroll-lock.js +26 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/words/registry.d.ts +1 -1
- package/dist/words/words.d.ts +2 -2
- package/package.json +15 -4
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { reportRuntime } from '../report-runtime/report-runtime.js';
|
|
2
|
+
let audited;
|
|
3
|
+
let changed = false;
|
|
4
|
+
let measured;
|
|
5
|
+
const reported = new Set();
|
|
6
|
+
let watching = false;
|
|
7
|
+
const TEXT = 4.5;
|
|
8
|
+
const FILL = 3;
|
|
9
|
+
const STATUS_DISTANCE = 0.08;
|
|
10
|
+
const STATUSES = ['danger', 'info', 'success', 'warning'];
|
|
11
|
+
export const oklabOf = (bytes) => {
|
|
12
|
+
const [red = 0, green = 0, blue = 0] = bytes.map((byte) => {
|
|
13
|
+
const channel = byte / 255;
|
|
14
|
+
return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
|
|
15
|
+
});
|
|
16
|
+
const long = Math.cbrt(0.4122214708 * red + 0.5363325363 * green + 0.0514459929 * blue);
|
|
17
|
+
const medium = Math.cbrt(0.2119034982 * red + 0.6806995451 * green + 0.1073969566 * blue);
|
|
18
|
+
const short = Math.cbrt(0.0883024619 * red + 0.2817188376 * green + 0.6299787005 * blue);
|
|
19
|
+
return [
|
|
20
|
+
0.2104542553 * long + 0.793617785 * medium - 0.0040720468 * short,
|
|
21
|
+
1.9779984951 * long - 2.428592205 * medium + 0.4505937099 * short,
|
|
22
|
+
0.0259040371 * long + 0.7827717662 * medium - 0.808675766 * short,
|
|
23
|
+
];
|
|
24
|
+
};
|
|
25
|
+
export const distanceOf = (one, other) => {
|
|
26
|
+
const [l1, a1, b1] = oklabOf(one);
|
|
27
|
+
const [l2, a2, b2] = oklabOf(other);
|
|
28
|
+
return Math.hypot(l1 - l2, a1 - a2, b1 - b2);
|
|
29
|
+
};
|
|
30
|
+
export const statusMessage = (scheme, status, distance) => `In ${scheme}, the primary color is ${distance.toFixed(3)} from the ${status} color in OKLab, ` +
|
|
31
|
+
`under the ${STATUS_DISTANCE} that tells two colors apart, so a ${status} reads as the brand. ` +
|
|
32
|
+
'Choose a seed further from it, or build the theme with the theme engine, which turns the ' +
|
|
33
|
+
'status colors clear of the brand.';
|
|
34
|
+
const luminance = (bytes) => {
|
|
35
|
+
const [red = 0, green = 0, blue = 0] = bytes.map((byte) => {
|
|
36
|
+
const channel = byte / 255;
|
|
37
|
+
return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
|
|
38
|
+
});
|
|
39
|
+
return 0.2126 * red + 0.7152 * green + 0.0722 * blue;
|
|
40
|
+
};
|
|
41
|
+
export const contrastOf = (one, other) => {
|
|
42
|
+
const [low, high] = [luminance(one), luminance(other)].sort((a, b) => a - b);
|
|
43
|
+
return (high + 0.05) / (low + 0.05);
|
|
44
|
+
};
|
|
45
|
+
export const schemeOf = (page) => contrastOf(page, [0, 0, 0]) > contrastOf(page, [255, 255, 255]) ? 'light' : 'dark';
|
|
46
|
+
let context;
|
|
47
|
+
export const contrastMessage = (scheme, text, fill) => [
|
|
48
|
+
text < TEXT
|
|
49
|
+
? `In ${scheme}, primary text measures ${text.toFixed(2)}:1 against the page, under the ${TEXT}:1 it needs.`
|
|
50
|
+
: '',
|
|
51
|
+
fill < FILL
|
|
52
|
+
? `In ${scheme}, a filled control measures ${fill.toFixed(2)}:1 against the page, under the ${FILL}:1 it needs.`
|
|
53
|
+
: '',
|
|
54
|
+
'A seed alone cannot cause this, so look for an override of `--helix-color-primary`, ' +
|
|
55
|
+
'`--helix-color-primary-surface`, or the page color.',
|
|
56
|
+
]
|
|
57
|
+
.filter(Boolean)
|
|
58
|
+
.join(' ');
|
|
59
|
+
export const auditSeed = () => {
|
|
60
|
+
if (typeof document === 'undefined') {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const root = document.documentElement;
|
|
64
|
+
if (!watching && typeof MutationObserver !== 'undefined') {
|
|
65
|
+
watching = true;
|
|
66
|
+
let queued = false;
|
|
67
|
+
const queue = () => {
|
|
68
|
+
changed = true;
|
|
69
|
+
if (queued) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
queued = true;
|
|
73
|
+
requestAnimationFrame(() => {
|
|
74
|
+
queued = false;
|
|
75
|
+
auditSeed();
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
const observer = new MutationObserver((records) => {
|
|
79
|
+
for (const record of records) {
|
|
80
|
+
for (const node of record.addedNodes) {
|
|
81
|
+
if (node instanceof HTMLLinkElement) {
|
|
82
|
+
node.addEventListener('load', queue, { once: true });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
queue();
|
|
87
|
+
});
|
|
88
|
+
globalThis.matchMedia?.('(prefers-color-scheme: dark)').addEventListener?.('change', queue);
|
|
89
|
+
const where = { attributeFilter: ['style', 'class', 'data-theme'], attributes: true };
|
|
90
|
+
observer.observe(root, where);
|
|
91
|
+
if (document.body) {
|
|
92
|
+
observer.observe(document.body, where);
|
|
93
|
+
}
|
|
94
|
+
if (document.head) {
|
|
95
|
+
observer.observe(document.head, { characterData: true, childList: true, subtree: true });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const seed = getComputedStyle(root).getPropertyValue('--helix-seed-brand').trim();
|
|
99
|
+
if (seed === audited && !changed) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
audited = seed;
|
|
103
|
+
changed = false;
|
|
104
|
+
context ??= document.createElement('canvas').getContext?.('2d', { willReadFrequently: true });
|
|
105
|
+
if (!context) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const pen = context;
|
|
109
|
+
const bytes = (value) => {
|
|
110
|
+
pen.fillStyle = '#000';
|
|
111
|
+
pen.fillStyle = value;
|
|
112
|
+
pen.fillRect(0, 0, 1, 1);
|
|
113
|
+
return [...pen.getImageData(0, 0, 1, 1).data].slice(0, 3);
|
|
114
|
+
};
|
|
115
|
+
const [light, dark] = ['light', 'dark'].map((scheme) => {
|
|
116
|
+
const probe = document.createElement('span');
|
|
117
|
+
probe.style.cssText =
|
|
118
|
+
`color-scheme:${scheme};color:var(--helix-color-primary);` +
|
|
119
|
+
'background-color:var(--helix-color-background);' +
|
|
120
|
+
'border-color:var(--helix-color-primary-surface);display:none';
|
|
121
|
+
root.append(probe);
|
|
122
|
+
const { backgroundColor, borderTopColor, color } = getComputedStyle(probe);
|
|
123
|
+
const statuses = STATUSES.map((status) => {
|
|
124
|
+
probe.style.color = `var(--helix-color-${status})`;
|
|
125
|
+
return bytes(getComputedStyle(probe).color);
|
|
126
|
+
});
|
|
127
|
+
probe.remove();
|
|
128
|
+
return {
|
|
129
|
+
fill: bytes(borderTopColor),
|
|
130
|
+
page: bytes(backgroundColor),
|
|
131
|
+
scheme,
|
|
132
|
+
statuses,
|
|
133
|
+
text: bytes(color),
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
const key = JSON.stringify([light, dark]);
|
|
137
|
+
if (key === measured) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
measured = key;
|
|
141
|
+
const probes = JSON.stringify([light.fill, light.page, light.text]) ===
|
|
142
|
+
JSON.stringify([dark.fill, dark.page, dark.text])
|
|
143
|
+
? [{ ...light, scheme: schemeOf(light.page) }]
|
|
144
|
+
: [light, dark];
|
|
145
|
+
for (const { scheme, statuses, text } of probes) {
|
|
146
|
+
STATUSES.forEach((status, index) => {
|
|
147
|
+
const distance = distanceOf(text, statuses[index] ?? text);
|
|
148
|
+
if (distance >= STATUS_DISTANCE) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const message = statusMessage(scheme, status, distance);
|
|
152
|
+
if (!reported.has(message)) {
|
|
153
|
+
reported.add(message);
|
|
154
|
+
reportRuntime({ kind: 'primary-status', message, tag: 'html' });
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
for (const { fill, page, scheme, text } of probes) {
|
|
159
|
+
const textContrast = contrastOf(text, page);
|
|
160
|
+
const fillContrast = contrastOf(fill, page);
|
|
161
|
+
if (textContrast >= TEXT && fillContrast >= FILL) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const message = contrastMessage(scheme, textContrast, fillContrast);
|
|
165
|
+
if (reported.has(message)) {
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
reported.add(message);
|
|
169
|
+
reportRuntime({ kind: 'primary-contrast', message, tag: 'html' });
|
|
170
|
+
}
|
|
171
|
+
};
|
|
@@ -1,6 +1,48 @@
|
|
|
1
|
-
const
|
|
1
|
+
const inkOf = (text) => ({
|
|
2
|
+
down: /[gjpqyçÇ]/.test(text) ? 0.44 : /[()[\]{},;|/]/.test(text) ? 0.38 : 0.29,
|
|
3
|
+
up: /^[acemnorsuvwxz\s.,:;-]*$/.test(text) ? 0.27 : 0.48,
|
|
4
|
+
});
|
|
2
5
|
const overlaps = (one, other, pad) => Math.abs(one.x - other.x) < one.half.width + other.half.width + pad &&
|
|
3
|
-
|
|
6
|
+
one.y - one.ink.up < other.y + other.ink.down &&
|
|
7
|
+
other.y - other.ink.up < one.y + one.ink.down;
|
|
8
|
+
const LINE = 1.3;
|
|
9
|
+
const crowds = (one, other, pad) => Math.abs(one.x - other.x) < one.half.width + other.half.width + pad &&
|
|
10
|
+
Math.abs(one.y - other.y) < (one.half.height + other.half.height) * LINE;
|
|
11
|
+
const NUDGE = { away: 1.6, toward: 0.4 };
|
|
12
|
+
const spread = (names, down) => {
|
|
13
|
+
const placed = names.map((name) => ({ from: name.y, name }));
|
|
14
|
+
const order = [...placed].sort((one, other) => one.from - other.from);
|
|
15
|
+
const held = (one) => {
|
|
16
|
+
const size = one.name.half.height * 2;
|
|
17
|
+
const lower = one.from + size * (down === 1 ? NUDGE.away : NUDGE.toward);
|
|
18
|
+
const upper = one.from - size * (down === -1 ? NUDGE.away : NUDGE.toward);
|
|
19
|
+
one.name.y = Math.min(lower, Math.max(upper, one.name.y));
|
|
20
|
+
};
|
|
21
|
+
for (let round = 0; round < 64; round += 1) {
|
|
22
|
+
let moved = false;
|
|
23
|
+
for (const [step, below] of order.entries()) {
|
|
24
|
+
const above = order[step - 1];
|
|
25
|
+
if (above === undefined) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const line = Math.max(above.name.half.height, below.name.half.height) * 2 * LINE;
|
|
29
|
+
const short = line - (below.name.y - above.name.y);
|
|
30
|
+
if (short <= line * 1e-3 ||
|
|
31
|
+
Math.abs(above.name.x - below.name.x) >= above.name.half.width + below.name.half.width) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const [was, wasBelow] = [above.name.y, below.name.y];
|
|
35
|
+
above.name.y -= short / 2;
|
|
36
|
+
below.name.y += short / 2;
|
|
37
|
+
held(above);
|
|
38
|
+
held(below);
|
|
39
|
+
moved ||= above.name.y !== was || below.name.y !== wasBelow;
|
|
40
|
+
}
|
|
41
|
+
if (!moved) {
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
4
46
|
export const boxLabels = (seen, axes, sizes) => {
|
|
5
47
|
const corners = [];
|
|
6
48
|
for (const x of [-1, 1]) {
|
|
@@ -38,11 +80,16 @@ export const boxLabels = (seen, axes, sizes) => {
|
|
|
38
80
|
const height = name ? sizes.name : sizes.tick;
|
|
39
81
|
return { height, width: text.length * height * sizes.wide };
|
|
40
82
|
};
|
|
41
|
-
const off = (at, out, box, by) =>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
83
|
+
const off = (at, out, box, by, text) => {
|
|
84
|
+
const reach = by + (Math.abs(out.x) * box.width) / 2 + (Math.abs(out.y) * box.height) / 2;
|
|
85
|
+
const ink = inkOf(text);
|
|
86
|
+
return {
|
|
87
|
+
half: { height: box.height / 2, width: box.width / 2 },
|
|
88
|
+
ink: { down: ink.down * box.height, up: ink.up * box.height },
|
|
89
|
+
x: at.x + out.x * reach,
|
|
90
|
+
y: at.y + out.y * reach,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
46
93
|
const names = [];
|
|
47
94
|
const ticks = [];
|
|
48
95
|
for (const { along, key } of edges) {
|
|
@@ -58,16 +105,18 @@ export const boxLabels = (seen, axes, sizes) => {
|
|
|
58
105
|
out = { x: -out.x, y: -out.y };
|
|
59
106
|
}
|
|
60
107
|
let deepest = 0;
|
|
108
|
+
const first = ticks.length;
|
|
61
109
|
for (const tick of axis.ticks) {
|
|
62
110
|
const box = size(tick.text, false);
|
|
63
111
|
ticks.push({
|
|
64
|
-
...off(seen(along(tick.at)), out, box, sizes.gap),
|
|
112
|
+
...off(seen(along(tick.at)), out, box, sizes.gap, tick.text),
|
|
65
113
|
category: tick.category === true,
|
|
66
114
|
of: axis.ticks.length,
|
|
67
115
|
text: tick.text,
|
|
68
116
|
});
|
|
69
117
|
deepest = Math.max(deepest, Math.abs(out.x) * box.width + Math.abs(out.y) * box.height);
|
|
70
118
|
}
|
|
119
|
+
spread(ticks.slice(first).filter((tick) => tick.category), out.y > 0.1 ? 1 : out.y < -0.1 ? -1 : 0);
|
|
71
120
|
if (axis.name === '') {
|
|
72
121
|
continue;
|
|
73
122
|
}
|
|
@@ -76,8 +125,8 @@ export const boxLabels = (seen, axes, sizes) => {
|
|
|
76
125
|
names.push({
|
|
77
126
|
...(key === 'y'
|
|
78
127
|
?
|
|
79
|
-
off(to, { x: 0, y: -1 }, box, sizes.gap + (topped ? sizes.tick / 2 : 0))
|
|
80
|
-
: off(seen(along(0)), out, box, sizes.gap * 2 + deepest)),
|
|
128
|
+
off(to, { x: 0, y: -1 }, box, sizes.gap + (topped ? sizes.tick / 2 : 0), axis.name)
|
|
129
|
+
: off(seen(along(0)), out, box, sizes.gap * 2 + deepest, axis.name)),
|
|
81
130
|
text: axis.name,
|
|
82
131
|
});
|
|
83
132
|
}
|
|
@@ -89,10 +138,13 @@ export const boxLabels = (seen, axes, sizes) => {
|
|
|
89
138
|
y: one.y,
|
|
90
139
|
}));
|
|
91
140
|
for (const tick of [...ticks].sort((one, other) => one.of - other.of)) {
|
|
92
|
-
|
|
141
|
+
const number = !tick.category;
|
|
142
|
+
if (kept.some((other) => number && other.number === true
|
|
143
|
+
? crowds(tick, other, sizes.gap / 2)
|
|
144
|
+
: overlaps(tick, other, number ? sizes.gap / 2 : 0))) {
|
|
93
145
|
continue;
|
|
94
146
|
}
|
|
95
|
-
kept.push(tick);
|
|
147
|
+
kept.push({ ...tick, number });
|
|
96
148
|
labels.push({ name: false, text: tick.text, x: tick.x, y: tick.y });
|
|
97
149
|
}
|
|
98
150
|
return labels;
|
|
@@ -32,6 +32,13 @@ export declare const rangeOf: (root: Element, needle: string) => Range[];
|
|
|
32
32
|
* Nothing at all where the API is missing, as on a server, in a test
|
|
33
33
|
* environment or in an older browser: the text nodes are not walked for an
|
|
34
34
|
* answer nothing can paint.
|
|
35
|
+
*
|
|
36
|
+
* **Nothing for a single letter or digit of a cased script.** One letter
|
|
37
|
+
* matches somewhere in nearly every option, so each row carried one
|
|
38
|
+
* underlined letter at a different place, which read as stray underscores in
|
|
39
|
+
* Combobox and Listbox and marked nothing a reader was looking for. The
|
|
40
|
+
* marks start at the second character. A single character of a script with
|
|
41
|
+
* no case, such as a Chinese one, is often a whole word, and is marked.
|
|
35
42
|
*/
|
|
36
43
|
export declare const markMatches: (owner: Element, elements: Iterable<Element>, needle: string) => void;
|
|
37
44
|
/**
|
|
@@ -20,12 +20,20 @@ export const rangeOf = (root, needle) => {
|
|
|
20
20
|
range.setEnd(last, end - under);
|
|
21
21
|
return [range];
|
|
22
22
|
};
|
|
23
|
+
const tooShortToMark = (needle) => {
|
|
24
|
+
const characters = [...needle];
|
|
25
|
+
if (characters.length !== 1) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const [character] = characters;
|
|
29
|
+
return /\p{Nd}/u.test(character) || character.toLowerCase() !== character.toUpperCase();
|
|
30
|
+
};
|
|
23
31
|
export const markMatches = (owner, elements, needle) => {
|
|
24
32
|
const registry = globalThis.CSS?.highlights;
|
|
25
33
|
if (registry === undefined) {
|
|
26
34
|
return;
|
|
27
35
|
}
|
|
28
|
-
if (needle === '') {
|
|
36
|
+
if (needle === '' || tooShortToMark(needle)) {
|
|
29
37
|
matched.delete(owner);
|
|
30
38
|
}
|
|
31
39
|
else {
|
|
@@ -86,6 +86,7 @@ const textsOf = (root, skip) => {
|
|
|
86
86
|
return { joined, nodes };
|
|
87
87
|
}
|
|
88
88
|
const never = skip === '' ? NEVER : `${NEVER}, ${skip}`;
|
|
89
|
+
root.getClientRects();
|
|
89
90
|
const shown = new Map();
|
|
90
91
|
const inline = new Map();
|
|
91
92
|
const walker = root.ownerDocument.createTreeWalker(root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, {
|
|
@@ -53,3 +53,39 @@ export declare const deepActiveElement: () => Element | null;
|
|
|
53
53
|
* the first time something calls it early.
|
|
54
54
|
*/
|
|
55
55
|
export declare const deepContains: (root: Node, node: Node | null) => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* The element inside `root` marked `autofocus`, once it can take focus, or
|
|
58
|
+
* `null` where nothing is marked.
|
|
59
|
+
*
|
|
60
|
+
* For a modal whose contents are components. A `<dialog>`'s focusing steps
|
|
61
|
+
* look for `autofocus`, and Chromium's skip a component host that delegates
|
|
62
|
+
* focus, so a dialog with a close control opened with focus on the close
|
|
63
|
+
* control rather than the action marked. It waits on two things first: the
|
|
64
|
+
* end of parsing, because a dialog opened from markup while the page is still
|
|
65
|
+
* loading opens before the parser has added its contents, and the marked
|
|
66
|
+
* element's first render, because a host has nothing to delegate to before it.
|
|
67
|
+
*/
|
|
68
|
+
export declare const autofocusTarget: (root: HTMLElement) => Promise<HTMLElement | null>;
|
|
69
|
+
/**
|
|
70
|
+
* How a modal moves focus as it opens: with a ring where the reader came by
|
|
71
|
+
* keyboard, and without one where they came by pointer or by nothing at all.
|
|
72
|
+
*
|
|
73
|
+
* Read before the modal opens, while the control that opened it still holds
|
|
74
|
+
* focus, and passed to every focus the modal then moves. **WebKit counts a
|
|
75
|
+
* focus a script moves as one the keyboard made**: a Drawer opened by a tap
|
|
76
|
+
* drew a ring on its close control in WebKit and on iOS, where Chromium drew
|
|
77
|
+
* none, and its own dialog focusing does the same.
|
|
78
|
+
*/
|
|
79
|
+
export declare const openingFocus: () => FocusOptions;
|
|
80
|
+
/**
|
|
81
|
+
* Focuses `element` with `options`, letting go first where it has focus
|
|
82
|
+
* already: WebKit takes a focus on the element that has it as nothing to do,
|
|
83
|
+
* and kept the ring its own dialog focusing step drew.
|
|
84
|
+
*/
|
|
85
|
+
export declare const focusAs: (element: HTMLElement, options: FocusOptions) => void;
|
|
86
|
+
/**
|
|
87
|
+
* Focuses the element that has focus again, with `options`, so a ring the
|
|
88
|
+
* browser drew for its own focusing step follows how the reader came. Only
|
|
89
|
+
* where that element is inside `root`.
|
|
90
|
+
*/
|
|
91
|
+
export declare const refocusWithin: (root: HTMLElement, options: FocusOptions) => void;
|
|
@@ -34,3 +34,25 @@ export const deepContains = (root, node) => {
|
|
|
34
34
|
}
|
|
35
35
|
return false;
|
|
36
36
|
};
|
|
37
|
+
export const autofocusTarget = async (root) => {
|
|
38
|
+
const document = root.ownerDocument;
|
|
39
|
+
if (document.readyState === 'loading') {
|
|
40
|
+
await new Promise((resolve) => document.addEventListener('DOMContentLoaded', resolve, { once: true }));
|
|
41
|
+
}
|
|
42
|
+
const marked = root.querySelector('[autofocus]');
|
|
43
|
+
await marked?.updateComplete;
|
|
44
|
+
return marked;
|
|
45
|
+
};
|
|
46
|
+
export const openingFocus = () => ({ focusVisible: deepActiveElement()?.matches(':focus-visible') ?? false });
|
|
47
|
+
export const focusAs = (element, options) => {
|
|
48
|
+
if (deepActiveElement() === element) {
|
|
49
|
+
element.blur();
|
|
50
|
+
}
|
|
51
|
+
element.focus(options);
|
|
52
|
+
};
|
|
53
|
+
export const refocusWithin = (root, options) => {
|
|
54
|
+
const active = deepActiveElement();
|
|
55
|
+
if (active instanceof HTMLElement && deepContains(root, active)) {
|
|
56
|
+
focusAs(active, options);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -6,5 +6,10 @@ export const formatNumbers = (locale) => {
|
|
|
6
6
|
held.set(locale, format);
|
|
7
7
|
}
|
|
8
8
|
const found = format;
|
|
9
|
-
return (value) =>
|
|
9
|
+
return (value) => value < 0 || Object.is(value, -0)
|
|
10
|
+
? found
|
|
11
|
+
.formatToParts(value)
|
|
12
|
+
.map((part) => (part.type === 'minusSign' && part.value === '-' ? '\u2212' : part.value))
|
|
13
|
+
.join('')
|
|
14
|
+
: found.format(value);
|
|
10
15
|
};
|
|
@@ -9,6 +9,12 @@
|
|
|
9
9
|
*/
|
|
10
10
|
/** Writes a number in a locale with `Intl.NumberFormat` options. */
|
|
11
11
|
export declare const formatNumber: (value: number, locale?: string, options?: Intl.NumberFormatOptions | null) => string;
|
|
12
|
+
/**
|
|
13
|
+
* A number written in a locale with `Intl.NumberFormat` options, in its pieces:
|
|
14
|
+
* the digits, the group and decimal separators, the sign, the currency. Joined,
|
|
15
|
+
* they are what `formatNumber` writes.
|
|
16
|
+
*/
|
|
17
|
+
export declare const formatNumberParts: (value: number, locale?: string, options?: Intl.NumberFormatOptions | null) => Intl.NumberFormatPart[];
|
|
12
18
|
/**
|
|
13
19
|
* A share, from 0 to 1, as a locale writes a whole percentage: `40%`, or
|
|
14
20
|
* `40 %` in French. For `aria-valuetext`, since a bare `aria-valuenow` is read
|
|
@@ -9,6 +9,7 @@ const formatter = (locale, options) => {
|
|
|
9
9
|
return found;
|
|
10
10
|
};
|
|
11
11
|
export const formatNumber = (value, locale = '', options) => formatter(locale, options).format(value);
|
|
12
|
+
export const formatNumberParts = (value, locale = '', options) => formatter(locale, options).formatToParts(value);
|
|
12
13
|
const WHOLE_PERCENT = { maximumFractionDigits: 0, style: 'percent' };
|
|
13
14
|
export const formatPercent = (share, locale = '') => formatNumber(share, locale, WHOLE_PERCENT);
|
|
14
15
|
export const readingText = (value, share, locale = '', options) => options && options.style !== 'percent'
|
|
@@ -30,6 +30,10 @@ export type RuntimeKind =
|
|
|
30
30
|
| 'fullscreen-refused'
|
|
31
31
|
/** A rating's `min` is no score between 0 and its `max`. */
|
|
32
32
|
| 'min-out-of-range'
|
|
33
|
+
/** Primary text under 4.5:1 or a filled control under 3:1 against the page, in light or dark. Development builds only. */
|
|
34
|
+
| 'primary-contrast'
|
|
35
|
+
/** The primary color sits so close to a status color that the two read as one, in light or dark. Development builds only. */
|
|
36
|
+
| 'primary-status'
|
|
33
37
|
/** A chart's `data` is not `{ columns, rows }`, so it draws its empty state. Development builds only. */
|
|
34
38
|
| 'malformed-data'
|
|
35
39
|
/** A Stat was given one of Trend's directions, `up`, `down` or `neutral`, which lay nothing out. */
|
|
@@ -25,3 +25,33 @@
|
|
|
25
25
|
* subscribes to nothing, and can be called from `render`.
|
|
26
26
|
*/
|
|
27
27
|
export declare const ticks: (domain: readonly [number, number], count?: number) => number[];
|
|
28
|
+
/**
|
|
29
|
+
* A domain whose top is raised to a level `ticks` rules, with room above the
|
|
30
|
+
* highest reading, and whose floor is lowered to one, with room below the
|
|
31
|
+
* lowest, unless the floor is zero.
|
|
32
|
+
*
|
|
33
|
+
* **A peak drawn on the plot's top edge reads as cut off**, and its top rule is
|
|
34
|
+
* the box's edge rather than a number. Measured on Line Chart's sessions
|
|
35
|
+
* example before this: 1,410 at the top edge, 0px above it, and the highest
|
|
36
|
+
* numbered level, 1,400, under the peak. The top is raised to the first level
|
|
37
|
+
* at least a thirtieth of the span above the highest reading, so the peak
|
|
38
|
+
* stands clear of the edge and the top edge is a numbered level. A peak exactly
|
|
39
|
+
* on a level takes the next one. The room is a thirtieth of the span, which
|
|
40
|
+
* clears the peak without taking the next level over a peak just under one.
|
|
41
|
+
*
|
|
42
|
+
* **The floor is the same edge turned over.** Left where the data put it, the
|
|
43
|
+
* same example's lowest reading, 1,180, lay on the bottom edge under the lowest
|
|
44
|
+
* rule, 1,200, and a diverging bar of -14,000 ran past the last numbered level,
|
|
45
|
+
* -10,000. The floor is lowered to the first level at least a thirtieth of the
|
|
46
|
+
* span below the lowest reading. **A floor of zero stays**, since zero is the
|
|
47
|
+
* baseline the drawing stands on, and a floor above zero is lowered no further
|
|
48
|
+
* than zero.
|
|
49
|
+
*
|
|
50
|
+
* The step is worked out again from the widened domain until it holds, since
|
|
51
|
+
* widening it can widen the step: 0 to 140 rules every 20, and 0 to 160 every
|
|
52
|
+
* 50, which would leave 160 off the scale. The result is 0 to 150.
|
|
53
|
+
*
|
|
54
|
+
* A top at zero stays, for the reason the floor does, and a flat domain comes
|
|
55
|
+
* back as it went in: it has no levels.
|
|
56
|
+
*/
|
|
57
|
+
export declare const headroom: (domain: readonly [number, number], count?: number) => [number, number];
|
|
@@ -1,16 +1,43 @@
|
|
|
1
|
+
const stepOf = (low, high, count) => {
|
|
2
|
+
const rough = (high - low) / count;
|
|
3
|
+
const magnitude = 10 ** Math.floor(Math.log10(rough));
|
|
4
|
+
const eased = rough / magnitude;
|
|
5
|
+
return magnitude * (eased >= 7.5 ? 10 : eased >= 3 ? 5 : eased >= 1.5 ? 2 : 1);
|
|
6
|
+
};
|
|
7
|
+
const toStep = (value, step) => Number(value.toFixed(Math.max(0, -Math.floor(Math.log10(step)))));
|
|
1
8
|
export const ticks = (domain, count = 5) => {
|
|
2
9
|
const [low, high] = domain;
|
|
3
10
|
if (!Number.isFinite(low) || !Number.isFinite(high) || low === high || count < 1) {
|
|
4
11
|
return [];
|
|
5
12
|
}
|
|
6
|
-
const
|
|
7
|
-
const magnitude = 10 ** Math.floor(Math.log10(rough));
|
|
8
|
-
const eased = rough / magnitude;
|
|
9
|
-
const step = magnitude * (eased >= 7.5 ? 10 : eased >= 3 ? 5 : eased >= 1.5 ? 2 : 1);
|
|
13
|
+
const step = stepOf(low, high, count);
|
|
10
14
|
const found = [];
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
found.push(
|
|
15
|
+
const first = Math.ceil(low / step - 1e-9);
|
|
16
|
+
for (let index = first; index * step <= high + step * 1e-6; index += 1) {
|
|
17
|
+
found.push(toStep(index * step, step));
|
|
14
18
|
}
|
|
15
19
|
return found;
|
|
16
20
|
};
|
|
21
|
+
export const headroom = (domain, count = 5) => {
|
|
22
|
+
const [low, high] = domain;
|
|
23
|
+
if (!Number.isFinite(low) || !Number.isFinite(high) || low >= high || count < 1) {
|
|
24
|
+
return [low, high];
|
|
25
|
+
}
|
|
26
|
+
const room = (high - low) / 30;
|
|
27
|
+
const [above, below] = [high === 0 ? 0 : high + room, low === 0 ? 0 : low - room];
|
|
28
|
+
let [floor, top] = [low, high];
|
|
29
|
+
let held = 0;
|
|
30
|
+
for (let round = 0; round < 8; round += 1) {
|
|
31
|
+
const step = stepOf(floor, top, count);
|
|
32
|
+
if (step === held) {
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
held = step;
|
|
36
|
+
top = high === 0 ? 0 : toStep(Math.ceil(above / step) * step, step);
|
|
37
|
+
floor = low === 0 ? 0 : toStep(Math.floor(below / step) * step, step);
|
|
38
|
+
if (low > 0 && floor < 0) {
|
|
39
|
+
floor = 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return [floor, top];
|
|
43
|
+
};
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A box that stays above every modal surface: Toast's stack. `raise` puts it
|
|
3
|
+
* back on top of the top layer, `covers` says whether a point lands on it, and
|
|
4
|
+
* `release` tells it a modal surface has let go of the page.
|
|
5
|
+
*/
|
|
6
|
+
export interface Raised {
|
|
7
|
+
covers(x: number, y: number): boolean;
|
|
8
|
+
raise(): void;
|
|
9
|
+
release?(): void;
|
|
10
|
+
}
|
|
1
11
|
/**
|
|
2
12
|
* Stops the page behind a modal surface from scrolling.
|
|
3
13
|
*
|
|
@@ -14,3 +24,23 @@ export declare const lockScroll: (holder: Element) => void;
|
|
|
14
24
|
export declare const unlockScroll: (holder: Element) => void;
|
|
15
25
|
/** The surfaces holding the page still, in the order they took it. */
|
|
16
26
|
export declare const scrollHolders: () => Element[];
|
|
27
|
+
/**
|
|
28
|
+
* Keeps a box above every modal surface opened after it, until the returned
|
|
29
|
+
* function lets go.
|
|
30
|
+
*
|
|
31
|
+
* The top layer is ordered by when each element entered it, so a modal opened
|
|
32
|
+
* while a toast showed covered the toast with its backdrop: measured, the
|
|
33
|
+
* whole stack sat under the scrim until another message arrived.
|
|
34
|
+
*/
|
|
35
|
+
export declare const keepAbove: (one: Raised) => (() => void);
|
|
36
|
+
/** Puts every kept box back on top. A modal surface calls it once it has opened. */
|
|
37
|
+
export declare const raiseAbove: () => void;
|
|
38
|
+
/**
|
|
39
|
+
* Whether a press lands on a kept box, which a modal surface reads before it
|
|
40
|
+
* takes the press for one on its backdrop.
|
|
41
|
+
*
|
|
42
|
+
* **The box is inert under the modal**, as everything outside it is, so the
|
|
43
|
+
* press passes through it to the backdrop, and a reader pressing a toast's
|
|
44
|
+
* Dismiss closed the Dialog under it instead.
|
|
45
|
+
*/
|
|
46
|
+
export declare const coversPress: (event: MouseEvent) => boolean;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
const SCROLL_LOCK = Symbol.for('fusion.helix.scroll-lock');
|
|
2
2
|
const record = () => globalThis[SCROLL_LOCK];
|
|
3
|
-
|
|
3
|
+
const made = () => {
|
|
4
4
|
const globals = globalThis;
|
|
5
|
+
globals[SCROLL_LOCK] ??= { gutter: '', holders: new Set(), overflow: '', raised: new Set() };
|
|
6
|
+
globals[SCROLL_LOCK].raised ??= new Set();
|
|
7
|
+
return globals[SCROLL_LOCK];
|
|
8
|
+
};
|
|
9
|
+
export const lockScroll = (holder) => {
|
|
5
10
|
const root = document.documentElement;
|
|
6
|
-
|
|
7
|
-
const lock = globals[SCROLL_LOCK];
|
|
11
|
+
const lock = made();
|
|
8
12
|
if (lock.holders.has(holder)) {
|
|
9
13
|
return;
|
|
10
14
|
}
|
|
@@ -20,7 +24,13 @@ export const lockScroll = (holder) => {
|
|
|
20
24
|
};
|
|
21
25
|
export const unlockScroll = (holder) => {
|
|
22
26
|
const lock = record();
|
|
23
|
-
if (!lock?.holders.delete(holder)
|
|
27
|
+
if (!lock?.holders.delete(holder)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
for (const one of lock.raised) {
|
|
31
|
+
one.release?.();
|
|
32
|
+
}
|
|
33
|
+
if (lock.holders.size > 0) {
|
|
24
34
|
return;
|
|
25
35
|
}
|
|
26
36
|
const root = document.documentElement;
|
|
@@ -28,3 +38,15 @@ export const unlockScroll = (holder) => {
|
|
|
28
38
|
root.style.scrollbarGutter = lock.gutter;
|
|
29
39
|
};
|
|
30
40
|
export const scrollHolders = () => [...(record()?.holders ?? [])];
|
|
41
|
+
export const keepAbove = (one) => {
|
|
42
|
+
made().raised.add(one);
|
|
43
|
+
return () => {
|
|
44
|
+
record()?.raised.delete(one);
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export const raiseAbove = () => {
|
|
48
|
+
for (const one of record()?.raised ?? []) {
|
|
49
|
+
one.raise();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
export const coversPress = (event) => [...(record()?.raised ?? [])].some((one) => one.covers(event.clientX, event.clientY));
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.237.0';
|
package/dist/words/registry.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export type Words = {
|
|
|
35
35
|
* as Color Picker's `colorWords`, merges entry by entry.
|
|
36
36
|
*
|
|
37
37
|
* ```js
|
|
38
|
-
* registerWords('de', { 'helix-combobox': {
|
|
38
|
+
* registerWords('de', { 'helix-combobox': { noResultsText: 'Keine Treffer' } })
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
41
|
export declare const registerWords: (locale: string, ...words: Words[]) => void;
|
package/dist/words/words.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ type Host = ReactiveElement & {
|
|
|
13
13
|
* static words = 'helix-combobox'
|
|
14
14
|
*
|
|
15
15
|
* @words
|
|
16
|
-
* @property({ attribute: '
|
|
17
|
-
*
|
|
16
|
+
* @property({ attribute: 'no-results-text' })
|
|
17
|
+
* noResultsText = 'No matches'
|
|
18
18
|
* ```
|
|
19
19
|
*
|
|
20
20
|
* **Reading the property gives the word in the element's locale**: a value
|