answerstyle 0.1.2__py3-none-any.whl

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.
@@ -0,0 +1,8 @@
1
+ """Shared styles and browser behavior for semantic HTML."""
2
+ __version__ = "0.1.2"
3
+
4
+
5
+
6
+ from importlib.resources import files
7
+
8
+ assets = files(__package__) / 'assets'
answerstyle/_build.py ADDED
@@ -0,0 +1,35 @@
1
+ """Assemble browser stylesheets from the notebooks without running their lessons."""
2
+
3
+ from ast import literal_eval, parse
4
+ from collections import defaultdict
5
+
6
+
7
+ class _Assets:
8
+ def __init__(self, nb): self.parts = defaultdict(list)
9
+
10
+ def _asset_(self, cell, name):
11
+ stmt, = parse(cell.source).body
12
+ self.parts[name].append(literal_eval(stmt.value).strip())
13
+
14
+ def _asset_include_(self, cell, name, filename):
15
+ from nbdev.config import get_config
16
+ self.parts[name].append((get_config().nbs_path / filename).read_text(encoding='utf-8').strip())
17
+
18
+
19
+ def build_assets_(cell):
20
+ "Export the notebook stylesheet sections in notebook and cell order."
21
+ from nbdev.config import get_config
22
+ from nbdev.process import NBProcessor
23
+
24
+ cfg = get_config()
25
+ parts = defaultdict(list)
26
+ for nb in sorted(cfg.nbs_path.glob('[0-9]*.ipynb')):
27
+ proc = NBProcessor(nb, _Assets)
28
+ proc.process()
29
+ for name, sections in proc.procs[0].parts.items(): parts[name].extend(sections)
30
+ dest = cfg.lib_path / 'assets'
31
+ dest.mkdir(exist_ok=True)
32
+ for name, sections in parts.items():
33
+ out = dest / name
34
+ css = '/* Generated by nbdev-export. Edit the source notebooks. */\n\n' + '\n\n'.join(sections) + '\n'
35
+ if not out.exists() or out.read_text(encoding='utf-8') != css: out.write_text(css, encoding='utf-8')
answerstyle/_modidx.py ADDED
@@ -0,0 +1,8 @@
1
+ # Autogenerated by nbdev
2
+
3
+ d = { 'settings': { 'branch': 'main',
4
+ 'doc_baseurl': '/',
5
+ 'doc_host': '',
6
+ 'git_url': 'https://github.com/AnswerDotAI/answerstyle',
7
+ 'lib_path': 'answerstyle'},
8
+ 'syms': {}}
@@ -0,0 +1,7 @@
1
+ export async function copyText(textOrPromise) {
2
+ if (typeof textOrPromise === 'string') return navigator.clipboard.writeText(textOrPromise);
3
+ const type = 'text/plain';
4
+ // Safari checks for user activation when write() is called, not when the data is ready.
5
+ const data = Promise.resolve(textOrPromise).then(text => new Blob([text], {type}));
6
+ return navigator.clipboard.write([new ClipboardItem({[type]: data})]);
7
+ }
@@ -0,0 +1,92 @@
1
+ function inlineSize(style, box) {
2
+ const edges = ['Start', 'End'].reduce((n, end) => n + parseFloat(style[`paddingInline${end}`]) +
3
+ parseFloat(style[`borderInline${end}Width`]), 0);
4
+ const size = parseFloat(style.writingMode.startsWith('horizontal') ? style.width : style.height);
5
+ if (box === 'content') return style.boxSizing === 'border-box' ? size - edges : size;
6
+ return style.boxSizing === 'border-box' ? size : size + edges;
7
+ }
8
+
9
+ export function watchInlineFit(host, row, onCompact) {
10
+ const doc = host.ownerDocument, win = doc.defaultView;
11
+ const events = new win.AbortController(), {signal} = events;
12
+ let frame, compact;
13
+ function measure() {
14
+ frame = undefined;
15
+ if (!host.getClientRects().length) return;
16
+ const available = inlineSize(win.getComputedStyle(host), 'content');
17
+ host.setAttribute('data-fitting', '');
18
+ const needed = inlineSize(win.getComputedStyle(row), 'border');
19
+ host.removeAttribute('data-fitting');
20
+ if (!Number.isFinite(needed) || !Number.isFinite(available)) return;
21
+ const next = needed > available;
22
+ if (compact !== next) onCompact(compact = next);
23
+ }
24
+ function schedule() { frame ??= win.requestAnimationFrame(measure); }
25
+ const resize = new win.ResizeObserver(schedule);
26
+ resize.observe(host);
27
+ if (row !== host) resize.observe(row);
28
+ const children = new Set();
29
+ function observeChildren() {
30
+ const next = new Set(row.children);
31
+ for (const child of children) if (!next.has(child)) { resize.unobserve(child); children.delete(child); }
32
+ for (const child of next) if (!children.has(child)) { resize.observe(child); children.add(child); }
33
+ }
34
+ const mutations = new win.MutationObserver(records => {
35
+ if (records.some(r => r.type === 'childList' && r.target === row)) observeChildren();
36
+ if (records.some(r => r.target !== host || r.attributeName !== 'data-fitting')) schedule();
37
+ });
38
+ mutations.observe(row, {subtree: true, attributes: true, childList: true, characterData: true});
39
+ row.addEventListener('load', schedule, {capture: true, signal});
40
+ doc.fonts?.addEventListener('loadingdone', schedule, {signal});
41
+ observeChildren();
42
+ measure();
43
+ return () => {
44
+ events.abort();
45
+ win.cancelAnimationFrame(frame);
46
+ resize.disconnect();
47
+ mutations.disconnect();
48
+ };
49
+ }
50
+
51
+ export function mountNavbar(host, {open = false, onOpenChange} = {}) {
52
+ const row = host.querySelector(':scope > [navbar-row]'), nav = row?.querySelector(':scope > nav');
53
+ const toggle = row?.querySelector(':scope > [navbar-toggle]');
54
+ if (!nav || !toggle) return {setOpen() {}, dispose() {}};
55
+ const doc = host.ownerDocument, events = new doc.defaultView.AbortController();
56
+ let compact, expanded = Boolean(open);
57
+ function setOpen(next) {
58
+ const changed = expanded !== Boolean(next);
59
+ expanded = Boolean(next);
60
+ host.toggleAttribute('data-open', compact && expanded);
61
+ toggle.setAttribute('aria-expanded', String(Boolean(compact && expanded)));
62
+ if (changed) onOpenChange?.(expanded);
63
+ }
64
+ const stop = watchInlineFit(host, row, next => {
65
+ const wasCompact = compact, focus = doc.activeElement;
66
+ compact = next;
67
+ if (compact && nav.contains(focus)) setOpen(true);
68
+ else if (wasCompact && !compact) setOpen(false);
69
+ else setOpen(expanded);
70
+ host.toggleAttribute('data-compact', compact);
71
+ if (wasCompact && !compact && toggle.contains(focus))
72
+ (nav.querySelector('a[href]') ?? row.querySelector('[navbar-brand]'))?.focus({preventScroll: true});
73
+ });
74
+ const {signal} = events;
75
+ toggle.addEventListener('click', () => setOpen(!expanded), {signal});
76
+ doc.addEventListener('click', event => {
77
+ if (compact && expanded && (!host.contains(event.target) || nav.contains(event.target.closest?.('a[href]') ?? null))) setOpen(false);
78
+ }, {signal});
79
+ host.addEventListener('keydown', event => {
80
+ if (!compact || !expanded || event.key !== 'Escape' || event.defaultPrevented) return;
81
+ event.preventDefault();
82
+ setOpen(false);
83
+ toggle.focus({preventScroll: true});
84
+ }, {signal});
85
+ return {setOpen, dispose() {
86
+ events.abort();
87
+ stop();
88
+ host.removeAttribute('data-compact');
89
+ host.removeAttribute('data-open');
90
+ toggle.setAttribute('aria-expanded', 'false');
91
+ }};
92
+ }
@@ -0,0 +1,78 @@
1
+ let anchorId = 0;
2
+
3
+ export function positionFloating(trigger, panel, {side = 'bottom', align = 'start', sideOffset = 6, onReferenceHidden} = {}) {
4
+ const doc = trigger.ownerDocument, win = doc.defaultView, events = new win.AbortController();
5
+ const anchored = win.CSS.supports('position-area', 'center'), name = `--answerstyle-anchor-${++anchorId}`;
6
+ const previousAnchor = trigger.style.anchorName;
7
+ const horizontal = side === 'left' || side === 'right';
8
+ const start = horizontal ? 'top' : (win.getComputedStyle(trigger).direction === 'rtl' ? 'right' : 'left');
9
+ const end = horizontal ? 'bottom' : (start === 'left' ? 'right' : 'left');
10
+ const extent = align === 'center' ? '' : ` span-${align === 'start' ? end : start}`;
11
+ function place() {
12
+ const r = trigger.getBoundingClientRect(), vw = doc.documentElement.clientWidth, vh = doc.documentElement.clientHeight, edge = 8;
13
+ if (!trigger.getClientRects().length || r.bottom < 0 || r.top > vh || r.right < 0 || r.left > vw) return onReferenceHidden?.();
14
+ if (anchored) return;
15
+ const below = vh - r.bottom - sideOffset - edge, above = r.top - sideOffset - edge;
16
+ const right = vw - r.right - sideOffset - edge, left = r.left - sideOffset - edge;
17
+ const extent = horizontal ? panel.scrollWidth : panel.scrollHeight;
18
+ let placed = side;
19
+ if (side === 'bottom' && extent > below && above > below) placed = 'top';
20
+ if (side === 'top' && extent > above && below > above) placed = 'bottom';
21
+ if (side === 'right' && extent > right && left > right) placed = 'left';
22
+ if (side === 'left' && extent > left && right > left) placed = 'right';
23
+ panel.style.setProperty('--floating-available-height', `${Math.max(0, placed === 'top' ? above : placed === 'bottom' ? below : vh - edge * 2)}px`);
24
+ const cross = align === 'center' ? (horizontal ? (r.top + r.bottom - panel.offsetHeight) / 2 : (r.left + r.right - panel.offsetWidth) / 2) :
25
+ (align === 'start' ? start : end) === (horizontal ? 'top' : 'left') ? (horizontal ? r.top : r.left) :
26
+ (horizontal ? r.bottom - panel.offsetHeight : r.right - panel.offsetWidth);
27
+ const x = horizontal ? (placed === 'left' ? r.left - panel.offsetWidth - sideOffset : r.right + sideOffset) : cross;
28
+ const y = horizontal ? cross : (placed === 'top' ? r.top - panel.offsetHeight - sideOffset : r.bottom + sideOffset);
29
+ panel.style.left = `${Math.max(edge, Math.min(x, vw - panel.offsetWidth - edge))}px`;
30
+ panel.style.top = `${Math.max(edge, Math.min(y, vh - panel.offsetHeight - edge))}px`;
31
+ }
32
+ if (anchored) {
33
+ trigger.style.anchorName = previousAnchor ? `${previousAnchor}, ${name}` : name;
34
+ panel.style.positionAnchor = name;
35
+ panel.style.positionArea = `${side}${extent}`;
36
+ panel.style.setProperty(`margin-${{top: 'bottom', bottom: 'top', left: 'right', right: 'left'}[side]}`, `${sideOffset}px`);
37
+ } else {
38
+ win.addEventListener('resize', place, {signal: events.signal});
39
+ doc.addEventListener('scroll', place, {capture: true, signal: events.signal});
40
+ }
41
+ const resize = new win.ResizeObserver(place);
42
+ resize.observe(trigger);
43
+ if (!anchored) resize.observe(panel);
44
+ place();
45
+ return () => {
46
+ events.abort();
47
+ resize.disconnect();
48
+ if (anchored) trigger.style.anchorName = previousAnchor;
49
+ for (const prop of ['position-anchor', 'position-area', 'left', 'top', 'margin-top', 'margin-bottom', 'margin-left', 'margin-right', '--floating-available-height'])
50
+ panel.style.removeProperty(prop);
51
+ };
52
+ }
53
+
54
+ export function mountPopover(trigger, panel, {onOpenChange, ...position} = {}) {
55
+ const win = panel.ownerDocument.defaultView, events = new win.AbortController();
56
+ let stop;
57
+ function update(open) {
58
+ stop?.();
59
+ trigger.setAttribute('aria-expanded', String(open));
60
+ stop = open ? positionFloating(trigger, panel, {...position, onReferenceHidden: () => panel.hidePopover()}) : undefined;
61
+ }
62
+ panel.addEventListener('beforetoggle', event => {
63
+ if (event.target !== panel) return;
64
+ update(event.newState === 'open');
65
+ }, {signal: events.signal});
66
+ panel.addEventListener('click', event => {
67
+ if (event.target.closest('a[href]') && panel.hasAttribute('dropdown')) panel.hidePopover();
68
+ }, {signal: events.signal});
69
+ panel.addEventListener('toggle', event => {
70
+ if (event.target !== panel) return;
71
+ onOpenChange?.(event.newState === 'open');
72
+ if (event.newState === 'open' && panel.hasAttribute('dropdown'))
73
+ [...panel.querySelectorAll('button:not(:disabled), a[href]:not([aria-disabled=true]), select:not(:disabled), input:not(:disabled), summary')]
74
+ .find(node => !node.closest('[inert]') && node.getClientRects().length)?.focus();
75
+ }, {signal: events.signal});
76
+ update(panel.matches(':popover-open'));
77
+ return () => { events.abort(); stop?.(); trigger.setAttribute('aria-expanded', 'false'); };
78
+ }
@@ -0,0 +1,93 @@
1
+ Copyright 2019 IBM Corp. All rights reserved. IBMPlexSans-Italic[wdth,wght].ttf: Copyright 2019 IBM Corp. All rights reserved.
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,7 @@
1
+ /* Generated by nbdev-export. Edit the source notebooks. */
2
+
3
+ @font-face { font-family: 'IBM Plex Sans'; font-weight: 400; font-style: normal; font-display: swap; src: url('./fonts/ibm-plex-sans-latin-400-normal.woff2') format('woff2'); }
4
+ @font-face { font-family: 'IBM Plex Sans'; font-weight: 400; font-style: italic; font-display: swap; src: url('./fonts/ibm-plex-sans-latin-400-italic.woff2') format('woff2'); }
5
+ @font-face { font-family: 'IBM Plex Sans'; font-weight: 600; font-style: normal; font-display: swap; src: url('./fonts/ibm-plex-sans-latin-600-normal.woff2') format('woff2'); }
6
+ @font-face { font-family: 'IBM Plex Serif'; font-weight: 600; font-style: normal; font-display: swap; src: url('./fonts/ibm-plex-serif-latin-600-normal.woff2') format('woff2'); }
7
+ @font-face { font-family: 'IBM Plex Mono'; font-weight: 400; font-style: normal; font-display: swap; src: url('./fonts/ibm-plex-mono-latin-400-normal.woff2') format('woff2'); }
@@ -0,0 +1,92 @@
1
+ export function mountToolbar(root) {
2
+ const events = new root.ownerDocument.defaultView.AbortController();
3
+ const controls = () => [...root.querySelectorAll('button:not(:disabled), a[href]:not([aria-disabled=true])')]
4
+ .filter(node => !node.closest('[popover]'));
5
+ function focusable(target = controls().find(node => node.tabIndex === 0) ?? controls()[0]) {
6
+ for (const node of controls()) node.tabIndex = node === target ? 0 : -1;
7
+ }
8
+ root.addEventListener('focusin', event => { if (controls().includes(event.target)) focusable(event.target); }, {signal: events.signal});
9
+ root.addEventListener('keydown', event => {
10
+ const items = controls(), current = items.indexOf(event.target);
11
+ if (current < 0 || !['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
12
+ event.preventDefault();
13
+ const rtl = root.ownerDocument.defaultView.getComputedStyle(root).direction === 'rtl';
14
+ const step = (event.key === 'ArrowRight') !== rtl ? 1 : -1;
15
+ const next = event.key === 'Home' ? items[0] : event.key === 'End' ? items.at(-1) : items[(current + step + items.length) % items.length];
16
+ focusable(next);
17
+ next.focus();
18
+ }, {signal: events.signal});
19
+ const changes = new root.ownerDocument.defaultView.MutationObserver(() => focusable());
20
+ changes.observe(root, {subtree: true, childList: true, attributes: true, attributeFilter: ['disabled', 'aria-disabled']});
21
+ focusable();
22
+ return () => { events.abort(); changes.disconnect(); for (const node of controls()) node.removeAttribute('tabindex'); };
23
+ }
24
+
25
+ export function mountTabs(root, {activationMode = 'automatic', onValueChange} = {}) {
26
+ const win = root.ownerDocument.defaultView, events = new win.AbortController();
27
+ const list = root.querySelector('[role=tablist]'), tabs = () => [...list.querySelectorAll('[role=tab]')];
28
+ function setValue(value, notify = false) {
29
+ const items = tabs(), selected = items.find(tab => tab.dataset.value === value && !tab.disabled) ?? items.find(tab => !tab.disabled);
30
+ for (const tab of items) {
31
+ const active = tab === selected;
32
+ tab.setAttribute('aria-selected', String(active));
33
+ tab.tabIndex = active ? 0 : -1;
34
+ const panel = root.ownerDocument.getElementById(tab.getAttribute('aria-controls'));
35
+ if (panel) panel.hidden = !active;
36
+ }
37
+ if (notify && selected) onValueChange?.(selected.dataset.value);
38
+ return selected?.dataset.value;
39
+ }
40
+ list.addEventListener('click', event => {
41
+ const tab = event.target.closest('[role=tab]');
42
+ if (tab && !tab.disabled) setValue(tab.dataset.value, true);
43
+ }, {signal: events.signal});
44
+ list.addEventListener('keydown', event => {
45
+ const items = tabs().filter(tab => !tab.disabled), current = items.indexOf(event.target);
46
+ const vertical = list.getAttribute('aria-orientation') === 'vertical', rtl = win.getComputedStyle(list).direction === 'rtl';
47
+ const previous = vertical ? 'ArrowUp' : rtl ? 'ArrowRight' : 'ArrowLeft', next = vertical ? 'ArrowDown' : rtl ? 'ArrowLeft' : 'ArrowRight';
48
+ if (current < 0 || ![previous, next, 'Home', 'End'].includes(event.key)) return;
49
+ event.preventDefault();
50
+ const target = event.key === 'Home' ? items[0] : event.key === 'End' ? items.at(-1) :
51
+ items[(current + (event.key === next ? 1 : -1) + items.length) % items.length];
52
+ for (const tab of tabs()) tab.tabIndex = tab === target ? 0 : -1;
53
+ target.focus();
54
+ if (activationMode === 'automatic') setValue(target.dataset.value, true);
55
+ }, {signal: events.signal});
56
+ setValue(tabs().find(tab => tab.getAttribute('aria-selected') === 'true')?.dataset.value);
57
+ const changes = new win.MutationObserver(() => {
58
+ const current = tabs().find(tab => tab.getAttribute('aria-selected') === 'true');
59
+ if (!current || current.disabled) setValue(undefined, true);
60
+ });
61
+ changes.observe(list, {subtree: true, childList: true, attributes: true, attributeFilter: ['disabled']});
62
+ return {setValue, dispose() { events.abort(); changes.disconnect(); }};
63
+ }
64
+
65
+ export function mountHoverPopover(trigger, panel, {openDelay = 0, closeDelay = 300} = {}) {
66
+ const win = trigger.ownerDocument.defaultView, events = new win.AbortController();
67
+ let timer;
68
+ function show() { win.clearTimeout(timer); if (!trigger.disabled && !panel.matches(':popover-open')) panel.showPopover({source: trigger}); }
69
+ function leave() {
70
+ win.clearTimeout(timer);
71
+ timer = win.setTimeout(() => {
72
+ if (!panel.contains(panel.ownerDocument.activeElement)) panel.hidePopover();
73
+ }, closeDelay);
74
+ }
75
+ for (const node of [trigger, panel]) {
76
+ node.addEventListener('pointerenter', event => {
77
+ if (event.pointerType !== 'mouse') return;
78
+ win.clearTimeout(timer);
79
+ timer = win.setTimeout(show, openDelay);
80
+ }, {signal: events.signal});
81
+ node.addEventListener('pointerleave', event => { if (event.pointerType === 'mouse') leave(); }, {signal: events.signal});
82
+ }
83
+ trigger.addEventListener('keydown', event => {
84
+ if (event.key !== 'ArrowDown') return;
85
+ event.preventDefault();
86
+ show();
87
+ win.requestAnimationFrame(() => panel.querySelector('select:not(:disabled), button:not(:disabled), input:not(:disabled), a[href]')?.focus());
88
+ }, {signal: events.signal});
89
+ trigger.addEventListener('click', event => { if (event.pointerType === 'touch') show(); }, {signal: events.signal});
90
+ panel.addEventListener('focusout', event => { if (!panel.contains(event.relatedTarget)) leave(); }, {signal: events.signal});
91
+ return () => { events.abort(); win.clearTimeout(timer); };
92
+ }