Skip to content

Commit

Permalink
Merge pull request #184 from ator-dev/type-definition-files
Browse files Browse the repository at this point in the history
Give type-only modules .d.mts, improve hierarchy
  • Loading branch information
ator-dev authored Sep 9, 2024
2 parents 27f5dff + df12bbf commit cb11d4c
Show file tree
Hide file tree
Showing 51 changed files with 1,111 additions and 1,100 deletions.
2 changes: 1 addition & 1 deletion src/background.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "/dist/modules/namespace/normalize.mjs";
import type { ConfigURLFilters, ResearchInstance, SearchSites, URLFilter } from "/dist/modules/storage.mjs";
import { Bank, Config, configInitialize } from "/dist/modules/storage.mjs";
import { parseCommand } from "/dist/modules/commands.mjs";
import type * as Message from "/dist/modules/messaging.mjs";
import type * as Message from "/dist/modules/messaging.d.mjs";
import { sendTabMessage } from "/dist/modules/messaging/tab.mjs";
import { MatchTerm } from "/dist/modules/match-term.mjs";
import { SearchSite } from "/dist/modules/search-site.mjs";
Expand Down
9 changes: 5 additions & 4 deletions src/content.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
/* eslint-disable indent */ // TODO remove
import type { ConfigValues } from "/dist/modules/storage.mjs";
import type { CommandInfo } from "/dist/modules/commands.mjs";
import type * as Message from "/dist/modules/messaging.mjs";
import type * as Message from "/dist/modules/messaging.d.mjs";
import { sendBackgroundMessage } from "/dist/modules/messaging/background.mjs";
import { type MatchMode, MatchTerm, termEquals, TermTokens, TermPatterns } from "/dist/modules/match-term.mjs";
import { EleID } from "/dist/modules/common.mjs";
import { type AbstractEngineManager, EngineManager } from "/dist/modules/highlight/engine-manager.mjs";
import { type AbstractToolbar, type ControlButtonName } from "/dist/modules/interface/toolbar.mjs";
import { Toolbar } from "/dist/modules/interface/toolbars/toolbar.mjs";
import type { AbstractEngineManager } from "/dist/modules/highlight/engine-manager.d.mjs";
import { EngineManager } from "/dist/modules/highlight/engine-manager.mjs";
import type { AbstractToolbar, ControlButtonName } from "/dist/modules/interface/toolbar.d.mjs";
import { Toolbar } from "/dist/modules/interface/toolbar.mjs";
import { assert, itemsMatch } from "/dist/modules/common.mjs";

type GetToolbar<CreateIfNull extends boolean> = (CreateIfNull extends true
Expand Down
27 changes: 27 additions & 0 deletions src/modules/highlight/engine-manager.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This file is part of Mark My Search.
* Copyright © 2021-present ‘ator-dev’, Mark My Search contributors.
* Licensed under the EUPL-1.2-or-later.
*/

import type { HighlighterCounterInterface, HighlighterWalkerInterface } from "/dist/modules/highlight/model.d.mjs";
import type { Highlighter } from "/dist/modules/highlight/engine.d.mjs";
import type { Engine, PaintEngineMethod } from "/dist/modules/common.mjs";

interface AbstractEngineManager extends Highlighter, HighlighterCounterInterface, HighlighterWalkerInterface {
readonly setEngine: (preference: Engine) => Promise<void>

readonly applyEngine: () => void

readonly removeEngine: () => void

readonly signalPaintEngineMethod: (preference: PaintEngineMethod) => void

readonly applyPaintEngineMethod: (preference: PaintEngineMethod) => Promise<void>

readonly setSpecialEngine: () => Promise<void>

readonly removeSpecialEngine: () => void
}

export type { AbstractEngineManager };
29 changes: 6 additions & 23 deletions src/modules/highlight/engine-manager.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,19 @@
* Licensed under the EUPL-1.2-or-later.
*/

import type { HighlighterCounterInterface, HighlighterWalkerInterface } from "/dist/modules/highlight/model.mjs";
import type { Highlighter } from "/dist/modules/highlight/engine.mjs";
import type { AbstractSpecialEngine } from "/dist/modules/highlight/special-engine.mjs";
import type { AbstractTermCounter } from "/dist/modules/highlight/tools/term-counter.mjs";
import type { AbstractTermWalker } from "/dist/modules/highlight/tools/term-walker.mjs";
import type { AbstractTermMarker } from "/dist/modules/highlight/tools/term-marker.mjs";
import type { AbstractEngineManager } from "/dist/modules/highlight/engine-manager.d.mjs";
import type { AbstractSpecialEngine } from "/dist/modules/highlight/special-engine.d.mjs";
import type { AbstractTermCounter } from "/dist/modules/highlight/tools/term-counter.d.mjs";
import type { AbstractTermWalker } from "/dist/modules/highlight/tools/term-walker.d.mjs";
import type { AbstractTermMarker } from "/dist/modules/highlight/tools/term-marker.d.mjs";
import type { AbstractTreeEditEngine } from "/dist/modules/highlight/models/tree-edit.mjs";
import type { AbstractTreeCacheEngine } from "/dist/modules/highlight/models/tree-cache.mjs";
import type { AbstractTreeCacheEngine } from "/dist/modules/highlight/models/tree-cache.d.mjs";
import { getContainerBlock } from "/dist/modules/highlight/container-blocks.mjs";
import type { Engine, PaintEngineMethod } from "/dist/modules/common.mjs";
import type { MatchTerm, TermTokens, TermPatterns } from "/dist/modules/match-term.mjs";
import { requestCallFn } from "/dist/modules/call-requester.mjs";
import { compatibility } from "/dist/modules/common.mjs";

interface AbstractEngineManager extends Highlighter, HighlighterCounterInterface, HighlighterWalkerInterface {
readonly setEngine: (preference: Engine) => Promise<void>

readonly applyEngine: () => void

readonly removeEngine: () => void

readonly signalPaintEngineMethod: (preference: PaintEngineMethod) => void

readonly applyPaintEngineMethod: (preference: PaintEngineMethod) => Promise<void>

readonly setSpecialEngine: () => Promise<void>

readonly removeSpecialEngine: () => void
}

type EngineData = Readonly<{
engine: AbstractTreeEditEngine | AbstractTreeCacheEngine
termCounter?: AbstractTermCounter
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/modules/highlight/engines/element.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import type { AbstractTreeEditEngine } from "/dist/modules/highlight/models/tree-edit.mjs";
import { HIGHLIGHT_TAG, HIGHLIGHT_TAG_UPPER } from "/dist/modules/highlight/models/tree-edit/tags.mjs";
import type { FlowMutationObserver } from "/dist/modules/highlight/flow-mutation-observer.mjs";
import type { FlowMutationObserver } from "/dist/modules/highlight/flow-mutation-observer.d.mjs";
import { highlightTags } from "/dist/modules/highlight/highlight-tags.mjs";
import * as TermCSS from "/dist/modules/highlight/term-css.mjs";
import type { MatchTerm, TermTokens, TermPatterns } from "/dist/modules/match-term.mjs";
Expand Down
6 changes: 3 additions & 3 deletions src/modules/highlight/engines/highlight.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* Licensed under the EUPL-1.2-or-later.
*/

import type { AbstractTreeCacheEngine } from "/dist/modules/highlight/models/tree-cache.mjs";
import type { AbstractFlowTracker, Flow, Span } from "/dist/modules/highlight/models/tree-cache/flow-tracker.mjs";
import { FlowTracker } from "/dist/modules/highlight/models/tree-cache/flow-trackers/flow-tracker.mjs";
import type { AbstractTreeCacheEngine } from "/dist/modules/highlight/models/tree-cache.d.mjs";
import type { AbstractFlowTracker, Flow, Span } from "/dist/modules/highlight/models/tree-cache/flow-tracker.d.mjs";
import { FlowTracker } from "/dist/modules/highlight/models/tree-cache/flow-tracker.mjs";
import * as TermCSS from "/dist/modules/highlight/term-css.mjs";
import type { MatchTerm, TermTokens, TermPatterns } from "/dist/modules/match-term.mjs";
import { StyleManager } from "/dist/modules/style-manager.mjs";
Expand Down
8 changes: 4 additions & 4 deletions src/modules/highlight/engines/paint.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* Licensed under the EUPL-1.2-or-later.
*/

import type { AbstractMethod } from "/dist/modules/highlight/engines/paint/method.mjs";
import type { AbstractMethod } from "/dist/modules/highlight/engines/paint/method.d.mjs";
import { getBoxesOwned } from "/dist/modules/highlight/engines/paint/boxes.mjs";
import type { AbstractTreeCacheEngine } from "/dist/modules/highlight/models/tree-cache.mjs";
import type { AbstractFlowTracker, Flow, Span } from "/dist/modules/highlight/models/tree-cache/flow-tracker.mjs";
import { FlowTracker } from "/dist/modules/highlight/models/tree-cache/flow-trackers/flow-tracker.mjs";
import type { AbstractTreeCacheEngine } from "/dist/modules/highlight/models/tree-cache.d.mjs";
import type { AbstractFlowTracker, Flow, Span } from "/dist/modules/highlight/models/tree-cache/flow-tracker.d.mjs";
import { FlowTracker } from "/dist/modules/highlight/models/tree-cache/flow-tracker.mjs";
import { highlightTags } from "/dist/modules/highlight/highlight-tags.mjs";
import * as TermCSS from "/dist/modules/highlight/term-css.mjs";
import type { MatchTerm, TermTokens, TermPatterns } from "/dist/modules/match-term.mjs";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/highlight/engines/paint/boxes.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import type { Flow, Span, Box } from "/dist/modules/highlight/engines/paint.mjs";
import type { Highlightables } from "/dist/modules/highlight/engines/paint/highlightables.mjs";
import type { Highlightables } from "/dist/modules/highlight/engines/paint/highlightables.d.mjs";
import { highlightTags } from "/dist/modules/highlight/highlight-tags.mjs";
import type { TermTokens } from "/dist/modules/match-term.mjs";
import type { AllReadonly } from "/dist/modules/common.mjs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import type { Box } from "/dist/modules/highlight/engines/paint.mjs";
import type { Highlightables } from "/dist/modules/highlight/engines/paint/highlightables.mjs";
import type { Highlightables } from "/dist/modules/highlight/engines/paint/highlightables.d.mjs";
import type { MatchTerm } from "/dist/modules/match-term.mjs";

interface AbstractMethod {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/highlight/engines/paint/methods/element.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the EUPL-1.2-or-later.
*/

import type { AbstractMethod } from "/dist/modules/highlight/engines/paint/method.mjs";
import type { AbstractMethod } from "/dist/modules/highlight/engines/paint/method.d.mjs";
import { getBoxesOwned } from "/dist/modules/highlight/engines/paint/boxes.mjs";
import type { HighlightingStyleObserver, Flow, Span, Box } from "/dist/modules/highlight/engines/paint.mjs";
import * as TermCSS from "/dist/modules/highlight/term-css.mjs";
Expand Down
4 changes: 2 additions & 2 deletions src/modules/highlight/engines/paint/methods/paint.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* Licensed under the EUPL-1.2-or-later.
*/

import type { AbstractMethod } from "/dist/modules/highlight/engines/paint/method.mjs";
import type { AbstractMethod } from "/dist/modules/highlight/engines/paint/method.d.mjs";
import type { Box } from "/dist/modules/highlight/engines/paint.mjs";
import type { Highlightables } from "/dist/modules/highlight/engines/paint/highlightables.mjs";
import type { Highlightables } from "/dist/modules/highlight/engines/paint/highlightables.d.mjs";
import type { MatchTerm, TermTokens } from "/dist/modules/match-term.mjs";
import { StyleManager } from "/dist/modules/style-manager.mjs";
import { HTMLStylesheet } from "/dist/modules/stylesheets/html.mjs";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/highlight/engines/paint/methods/url.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the EUPL-1.2-or-later.
*/

import type { AbstractMethod } from "/dist/modules/highlight/engines/paint/method.mjs";
import type { AbstractMethod } from "/dist/modules/highlight/engines/paint/method.d.mjs";
import type { Box } from "/dist/modules/highlight/engines/paint.mjs";
import type { MatchTerm, TermTokens } from "/dist/modules/match-term.mjs";
import { EleID, EleClass } from "/dist/modules/common.mjs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the EUPL-1.2-or-later.
*/

import type { AbstractTermCounter } from "/dist/modules/highlight/tools/term-counter.mjs";
import type { AbstractTermCounter } from "/dist/modules/highlight/tools/term-counter.d.mjs";
import type { MatchTerm } from "/dist/modules/match-term.mjs";

interface HighlighterCounterInterface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Licensed under the EUPL-1.2-or-later.
*/

import type { Flow } from "/dist/modules/highlight/models/tree-cache/flow-tracker.mjs";
import type { AbstractEngine } from "/dist/modules/highlight/engine.mjs";
import type { Flow } from "/dist/modules/highlight/models/tree-cache/flow-tracker.d.mjs";
import type { AbstractEngine } from "/dist/modules/highlight/engine.d.mjs";
import type { AllReadonly } from "/dist/modules/common.mjs";

type Model = "tree-cache"
Expand Down
92 changes: 92 additions & 0 deletions src/modules/highlight/models/tree-cache/flow-tracker.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* This file is part of Mark My Search.
* Copyright © 2021-present ‘ator-dev’, Mark My Search contributors.
* Licensed under the EUPL-1.2-or-later.
*/

import type { FlowMutationObserver } from "/dist/modules/highlight/flow-mutation-observer.d.mjs";
import type { BaseFlow, BaseSpan } from "/dist/modules/highlight/matcher.mjs";
import type { MatchTerm } from "/dist/modules/match-term.mjs";
import type { AllReadonly } from "/dist/modules/common.mjs";

type Flow = BaseFlow<true>

type Span = BaseSpan<true>

/**
* Interface for the core utility of the tree-cache highlighting engines.
*
* Implementers are responsible for:
*
* - determining "flows" of text and matching within them, producing highlighting "boxes" information;
* - maintaining a cache of [TODO]
*/
interface AbstractFlowTracker extends FlowMutationObserver {
readonly getElementFlowsMap: () => AllReadonly<Map<HTMLElement, Array<Flow>>>

/** Sets the listener for gain of highlight spans in an unhighlighted element. */
readonly setNewSpanOwnerListener: (
listener: (
/** The new owner of text flows which together contain 1+ highlight spans. */
flowOwner: HTMLElement,
) => void,
) => void

/** Sets the listener for gain of 1+ highlight spans in an element. */
readonly setSpansCreatedListener: (
listener: (
/** The owner of text flows which together contain 1+ new highlight spans (and any already present). */
flowOwner: HTMLElement,
/** Spans created in text flows of the element. */
spansCreated: AllReadonly<Array<Span>>,
) => void,
) => void

/** Sets the listener for loss of 1+ highlight spans in an element. */
readonly setSpansRemovedListener: (
listener: (
/** The owner of text flows which together contain some number of highlight spans. */
flowOwner: HTMLElement,
/** Spans removed from text flows of the element. */
spansRemoved: AllReadonly<Array<Span>>,
) => void,
) => void

/** Sets the listener for loss of all highlight spans in an element. */
readonly setNonSpanOwnerListener: (
listener: (
/** The owner of text flows which together used to contain highlight spans. */
flowOwner: HTMLElement,
) => void,
) => void

/** Adds a listener for changes in highlighting. */
readonly addHighlightingUpdatedListener: (listener: () => void) => void

/**
* Generates highlighting information for all text flows below the given element.
* @param terms The terms to highlight. Highlighting is removed for all terms not included.
* @param root The highest element below which to generate highlight spans for flows.
* This is assumed to be a flow-breaking element; an element at whose boundaries text flows start and end.
* Otherwise the function would need to look above the element, since the boundary flows would extend outside.
*/
readonly generateHighlightSpansFor: (
terms: ReadonlyArray<MatchTerm>,
root: HTMLElement,
) => void

/**
* Removes highlighting information for all text flows below the given element.
* @param terms The terms for which to remove highlighting. If undefined, all highlighting information is removed.
* @param root The element below which to remove flow highlighting.
*/
readonly removeHighlightSpansFor: (
terms?: ReadonlyArray<MatchTerm>,
root?: HTMLElement,
) => void
}

export type {
Flow, Span,
AbstractFlowTracker,
};
Loading

0 comments on commit cb11d4c

Please sign in to comment.