Current section
Files
Jump to
Current section
Files
src/keyboard_shortcuts.ffi.mjs
// See https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform ;
// "navigator.platform should almost always be avoided in favor of feature
// detection. But there is one case where, among the options you could use,
// navigator.platform may be the least-bad option: When you need to show
// users advice about whether the modifier key for keyboard shortcuts is the
// ⌘ command key (found on Apple systems) rather than the ⌃ control key
// (on non-Apple systems)
//
const isMac =
typeof navigator !== "undefined" &&
((navigator.platform && navigator.platform.toLowerCase().startsWith("mac")) ||
(navigator.platform &&
navigator.platform.toLowerCase().startsWith("iphone")) ||
(navigator.userAgent && /mac/i.test(navigator.userAgent.toLowerCase())) ||
navigator.userAgent?.platform?.startsWith("mac"));
export const window_add_event_listener = (name, handler) => {
window.addEventListener(name, handler);
};
export const prevent_default = (event) => {
event.preventDefault();
};
export const is_mac = () => {
return isMac;
};
// Use composedPath() to pierce shadow DOM boundaries and get the real
// originating element, not the retargeted shadow host.
const resolveTarget = (event) => {
const path = event.composedPath();
return path.length > 0 ? path[0] : event.target;
};
export const composed_target_tag_name = (event) => {
return resolveTarget(event).tagName || "";
};
export const composed_target_is_content_editable = (event) => {
return !!resolveTarget(event).isContentEditable;
};