feat(dictionary): add Hachidori backend support (#266)

This commit is contained in:
sudacode authored and GitHub committed 2026-10-24 21:08:18 -07:00
1 parent e690ffba07
commit cbaa4626e1
143 files changed
+5564 -305

No files matched your search

+26 -10
View File
@@ -1,11 +1,12 @@
import type { ModalStateReader, RendererContext } from '../context';
import { syncOverlayMouseIgnoreState } from '../overlay-mouse-ignore.js';
import {
YOMITAN_POPUP_HIDDEN_EVENT,
YOMITAN_POPUP_MOUSE_ENTER_EVENT,
YOMITAN_POPUP_MOUSE_LEAVE_EVENT,
YOMITAN_POPUP_SHOWN_EVENT,
registerDictionaryPopupVisibilityListener,
registerYomitanLookupListener,
PRIMARY_SUB_VISIBLE_ON_YOMITAN_POPUP_CLASS,
isHachidoriPopupOpen,
isYomitanPopupVisible,
isYomitanPopupIframe,
} from '../yomitan-popup.js';
@@ -257,8 +258,20 @@ export function createMouseHandlers(
options.sendMpvCommand(['set_property', 'pause', 'no']);
}
// Hachidori also claims attention for a left press anywhere on the overlay
// that may become a selection, so once its events identify the reader only
// an open popup pane should pause playback.
function canPauseForYomitanPopup(): boolean {
return (
yomitanPopupVisible &&
options.getYomitanPopupAutoPauseEnabled() &&
(!ctx.state.hachidoriReaderSeen ||
(typeof document !== 'undefined' && isHachidoriPopupOpen(document)))
);
}
async function maybePauseForYomitanPopup(): Promise<void> {
if (!yomitanPopupVisible || !options.getYomitanPopupAutoPauseEnabled()) {
if (!canPauseForYomitanPopup()) {
return;
}
@@ -278,11 +291,7 @@ export function createMouseHandlers(
return;
}
if (
requestId !== popupPauseRequestId ||
!yomitanPopupVisible ||
!options.getYomitanPopupAutoPauseEnabled()
) {
if (requestId !== popupPauseRequestId || !canPauseForYomitanPopup()) {
return;
}
if (paused !== false) return;
@@ -470,7 +479,8 @@ export function createMouseHandlers(
function setupYomitanObserver(): void {
reconcilePopupInteraction({ allowPause: true });
window.addEventListener(YOMITAN_POPUP_SHOWN_EVENT, () => {
registerDictionaryPopupVisibilityListener('shown', (reader) => {
if (reader === 'hachidori') ctx.state.hachidoriReaderSeen = true;
reconcilePopupInteraction({
assumeVisible: true,
allowPause: true,
@@ -478,10 +488,16 @@ export function createMouseHandlers(
});
});
window.addEventListener(YOMITAN_POPUP_HIDDEN_EVENT, () => {
registerDictionaryPopupVisibilityListener('hidden', () => {
disablePopupInteractionIfIdle();
});
// A Hachidori selection opens its popup while the drag's attention claim is
// still held, so no second shown event arrives; its lookup marks the open.
registerYomitanLookupListener(window, () => {
reconcilePopupInteraction({ allowPause: true });
});
window.addEventListener(YOMITAN_POPUP_MOUSE_ENTER_EVENT, () => {
ctx.state.isOverYomitanPopup = true;
reconcilePopupInteraction({ assumeVisible: true, reclaimFocus: true });