diff --git a/src/background.mts b/src/background.mts index 1931aca..562f8a3 100644 --- a/src/background.mts +++ b/src/background.mts @@ -5,8 +5,8 @@ */ import "/dist/modules/namespace/normalize.mjs"; -import type { ConfigURLFilters, ResearchInstance, SearchSites, URLFilter } from "./modules/storage.mjs"; -import { Bank, Config, configInitialize } from "./modules/storage.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 { sendTabMessage } from "/dist/modules/messaging/tab.mjs"; diff --git a/src/content.mts b/src/content.mts index a74038a..3f996df 100644 --- a/src/content.mts +++ b/src/content.mts @@ -5,14 +5,13 @@ */ /* eslint-disable indent */ // TODO remove -import type { ConfigValues } from "./modules/storage.mjs"; +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 { 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 { Style } from "/dist/modules/style.mjs"; import { type AbstractToolbar, type ControlButtonName } from "/dist/modules/interface/toolbar.mjs"; import { Toolbar } from "/dist/modules/interface/toolbars/toolbar.mjs"; import { assert, itemsMatch } from "/dist/modules/common.mjs"; @@ -235,7 +234,6 @@ interface TermAppender { }; const updateTermStatus = (term: MatchTerm) => getToolbarOrNull()?.updateTermStatus(term); const highlighter: AbstractEngineManager = new EngineManager(updateTermStatus, termTokens, termPatterns); - const styleManager = new Style(); const termSetterInternal: TermSetter = { setTerms: termsNew => { if (itemsMatch(terms, termsNew, termEquals)) { @@ -243,7 +241,6 @@ interface TermAppender { } const termsOld: ReadonlyArray = [ ...terms ]; terms = termsNew; - styleManager.updateStyle(terms, termTokens, hues); updateToolbar(termsOld, terms, null, getToolbar(), commands); // Give the interface a chance to redraw before performing highlighting. setTimeout(() => { @@ -259,7 +256,6 @@ interface TermAppender { } else { terms = terms.slice(0, termIndex).concat(terms.slice(termIndex + 1)); } - styleManager.updateStyle(terms, termTokens, hues); updateToolbar(termsOld, terms, { term, termIndex }, getToolbar(), commands); // Give the interface a chance to redraw before performing highlighting. setTimeout(() => { @@ -269,7 +265,6 @@ interface TermAppender { appendTerm: term => { const termsOld: ReadonlyArray = [ ...terms ]; terms = terms.concat(term); - styleManager.updateStyle(terms, termTokens, hues); updateToolbar(termsOld, terms, { term, termIndex: termsOld.length }, getToolbar(), commands); // Give the interface a chance to redraw before performing highlighting. setTimeout(() => { diff --git a/src/modules/common.mts b/src/modules/common.mts index 91c5b80..f4b106b 100644 --- a/src/modules/common.mts +++ b/src/modules/common.mts @@ -125,6 +125,7 @@ enum EleID { } enum EleClass { + STYLESHEET = "markmysearch--stylesheet", HIGHLIGHTS_SHOWN = "mms--highlights-shown", TERM = "mms--term", FOCUS = "mms--focus", diff --git a/src/modules/highlight/engine-manager.mts b/src/modules/highlight/engine-manager.mts index fb68127..f016f98 100644 --- a/src/modules/highlight/engine-manager.mts +++ b/src/modules/highlight/engine-manager.mts @@ -7,9 +7,9 @@ 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/term-counter.mjs"; -import type { AbstractTermWalker } from "/dist/modules/highlight/term-walker.mjs"; -import type { AbstractTermMarker } from "/dist/modules/highlight/term-marker.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 { AbstractTreeEditEngine } from "/dist/modules/highlight/models/tree-edit.mjs"; import type { AbstractTreeCacheEngine } from "/dist/modules/highlight/models/tree-cache.mjs"; import { getContainerBlock } from "/dist/modules/highlight/container-blocks.mjs"; @@ -113,10 +113,7 @@ class EngineManager implements AbstractEngineManager { } async setEngine (preference: Engine) { - const highlighting = this.#highlighting; - if (highlighting && this.#engineData) { - this.#engineData.engine.deactivate(); - } + this.deactivateEngine(); this.#engineData = await this.constructAndLinkEngineData(compatibility.highlighting.engineToUse(preference)); } @@ -173,9 +170,9 @@ class EngineManager implements AbstractEngineManager { case "ELEMENT": { const [ { ElementEngine }, { TermCounter }, { TermWalker }, { TermMarker } ] = await Promise.all([ import("/dist/modules/highlight/engines/element.mjs"), - import("/dist/modules/highlight/models/tree-edit/term-counters/term-counter.mjs"), - import("/dist/modules/highlight/models/tree-edit/term-walkers/term-walker.mjs"), - import("/dist/modules/highlight/models/tree-edit/term-markers/term-marker.mjs"), + import("/dist/modules/highlight/tools/term-counters/tree-edit.mjs"), + import("/dist/modules/highlight/tools/term-walkers/tree-edit.mjs"), + import("/dist/modules/highlight/tools/term-markers/tree-edit.mjs"), ]); const engine = new ElementEngine(this.#termTokens, this.#termPatterns); return { @@ -187,9 +184,9 @@ class EngineManager implements AbstractEngineManager { } case "PAINT": { const [ { PaintEngine }, { TermCounter }, { TermWalker }, { TermMarker } ] = await Promise.all([ import("/dist/modules/highlight/engines/paint.mjs"), - import("/dist/modules/highlight/models/tree-cache/term-counters/term-counter.mjs"), - import("/dist/modules/highlight/models/tree-cache/term-walkers/term-walker.mjs"), - import("/dist/modules/highlight/models/tree-cache/term-markers/term-marker.mjs"), + import("/dist/modules/highlight/tools/term-counters/tree-cache.mjs"), + import("/dist/modules/highlight/tools/term-walkers/tree-cache.mjs"), + import("/dist/modules/highlight/tools/term-markers/tree-cache.mjs"), ]); const engine = new PaintEngine( await PaintEngine.getMethodModule(this.#paintEngineMethodClass), @@ -204,9 +201,9 @@ class EngineManager implements AbstractEngineManager { } case "HIGHLIGHT": { const [ { HighlightEngine }, { TermCounter }, { TermWalker }, { TermMarker } ] = await Promise.all([ import("/dist/modules/highlight/engines/highlight.mjs"), - import("/dist/modules/highlight/models/tree-cache/term-counters/term-counter.mjs"), - import("/dist/modules/highlight/models/tree-cache/term-walkers/term-walker.mjs"), - import("/dist/modules/highlight/models/tree-cache/term-markers/term-marker.mjs"), + import("/dist/modules/highlight/tools/term-counters/tree-cache.mjs"), + import("/dist/modules/highlight/tools/term-walkers/tree-cache.mjs"), + import("/dist/modules/highlight/tools/term-markers/tree-cache.mjs"), ]); const engine = new HighlightEngine(this.#termTokens, this.#termPatterns); return { @@ -219,12 +216,20 @@ class EngineManager implements AbstractEngineManager { } removeEngine () { - if (this.#highlighting && this.#engineData) { - this.#engineData.engine.deactivate(); - } + this.deactivateEngine(); this.#engineData = null; } + deactivateEngine () { + const engineData = this.#engineData; + if (!engineData) { + return; + } + engineData.termWalker?.deactivate(); + engineData.termMarker?.deactivate(); + engineData.engine.deactivate(); + } + signalPaintEngineMethod (preference: PaintEngineMethod) { this.#paintEngineMethodClass = compatibility.highlighting.paintEngineMethodToUse(preference); } diff --git a/src/modules/highlight/model.mts b/src/modules/highlight/model.mts index a1381ad..8a42bb5 100644 --- a/src/modules/highlight/model.mts +++ b/src/modules/highlight/model.mts @@ -4,7 +4,7 @@ * Licensed under the EUPL-1.2-or-later. */ -import type { AbstractTermCounter } from "/dist/modules/highlight/term-counter.mjs"; +import type { AbstractTermCounter } from "/dist/modules/highlight/tools/term-counter.mjs"; import type { MatchTerm } from "/dist/modules/match-term.mjs"; interface HighlighterCounterInterface { diff --git a/src/modules/highlight/term-counter.mts b/src/modules/highlight/tools/term-counter.mts similarity index 100% rename from src/modules/highlight/term-counter.mts rename to src/modules/highlight/tools/term-counter.mts diff --git a/src/modules/highlight/models/tree-cache/term-counters/term-counter.mts b/src/modules/highlight/tools/term-counters/tree-cache.mts similarity index 98% rename from src/modules/highlight/models/tree-cache/term-counters/term-counter.mts rename to src/modules/highlight/tools/term-counters/tree-cache.mts index e6ba566..a8c659b 100644 --- a/src/modules/highlight/models/tree-cache/term-counters/term-counter.mts +++ b/src/modules/highlight/tools/term-counters/tree-cache.mts @@ -4,7 +4,7 @@ * Licensed under the EUPL-1.2-or-later. */ -import type { AbstractTermCounter } from "/dist/modules/highlight/term-counter.mjs"; +import type { AbstractTermCounter } from "/dist/modules/highlight/tools/term-counter.mjs"; import type { BaseFlow } from "/dist/modules/highlight/matcher.mjs"; import { highlightTags } from "/dist/modules/highlight/highlight-tags.mjs"; import type { MatchTerm } from "/dist/modules/match-term.mjs"; diff --git a/src/modules/highlight/models/tree-edit/term-counters/term-counter.mts b/src/modules/highlight/tools/term-counters/tree-edit.mts similarity index 97% rename from src/modules/highlight/models/tree-edit/term-counters/term-counter.mts rename to src/modules/highlight/tools/term-counters/tree-edit.mts index f8cbfc6..7c6eea0 100644 --- a/src/modules/highlight/models/tree-edit/term-counters/term-counter.mts +++ b/src/modules/highlight/tools/term-counters/tree-edit.mts @@ -4,7 +4,7 @@ * Licensed under the EUPL-1.2-or-later. */ -import type { AbstractTermCounter } from "/dist/modules/highlight/term-counter.mjs"; +import type { AbstractTermCounter } from "/dist/modules/highlight/tools/term-counter.mjs"; import type { MatchTerm, TermTokens } from "/dist/modules/match-term.mjs"; import { getTermClass } from "/dist/modules/common.mjs"; diff --git a/src/modules/highlight/term-marker.mts b/src/modules/highlight/tools/term-marker.mts similarity index 95% rename from src/modules/highlight/term-marker.mts rename to src/modules/highlight/tools/term-marker.mts index a3212d6..baf7d4f 100644 --- a/src/modules/highlight/term-marker.mts +++ b/src/modules/highlight/tools/term-marker.mts @@ -7,6 +7,8 @@ import type { MatchTerm } from "/dist/modules/match-term.mjs"; interface AbstractTermMarker { + readonly deactivate: () => void + /** * Inserts markers in the scrollbar to indicate the scroll positions of term highlights. * @param terms Terms highlighted in the page to mark the scroll position of. diff --git a/src/modules/style.mts b/src/modules/highlight/tools/term-marker/common.mts similarity index 53% rename from src/modules/style.mts rename to src/modules/highlight/tools/term-marker/common.mts index 8a22f6e..a2150ed 100644 --- a/src/modules/style.mts +++ b/src/modules/highlight/tools/term-marker/common.mts @@ -4,26 +4,11 @@ * Licensed under the EUPL-1.2-or-later. */ -import { StyleManager } from "/dist/modules/style-manager.mjs"; -import { HTMLStylesheet } from "/dist/modules/stylesheets/html.mjs"; import type { MatchTerm, TermTokens } from "/dist/modules/match-term.mjs"; import { Z_INDEX_MAX, EleID, EleClass, AtRuleID, getTermClass } from "/dist/modules/common.mjs"; -class Style { - #styleManager = new StyleManager(new HTMLStylesheet(document.head)); - - updateStyle ( - terms: ReadonlyArray, - termTokens: TermTokens, - hues: ReadonlyArray, - ) { - /** Prevents websites from taking precedence by applying !important to every rule. */ - const makeImportant = (styleText: string) => ( - styleText.replace(/;/g, " !important;") - ); - let style = makeImportant(` -/* || Scroll Markers */ - +abstract class Styles { + static readonly mainCSS = (` #${EleID.MARKER_GUTTER} { & { display: block; @@ -46,39 +31,29 @@ class Style { } } -/* || Term Highlights */ - -.${EleClass.FOCUS_CONTAINER} { - animation: ${AtRuleID.FLASH} 1s; -} -`) + (` -/* || Transitions */ - @keyframes ${AtRuleID.MARKER_ON} { from {} to { padding-right: 16px; }; } @keyframes ${AtRuleID.MARKER_OFF} { from { padding-right: 16px; } to { padding-right: 0; }; } -@keyframes ${AtRuleID.FLASH} { - from { background-color: hsl(0 0% 65% / 0.8); } to {}; -} ` - ); - for (let i = 0; i < terms.length; i++) { - const term = terms[i]; - const hue = hues[i % hues.length]; - style += makeImportant(` -/* || Term Scroll Markers */ + ); + static getTermCSS ( + term: MatchTerm, + termIndex: number, + hues: ReadonlyArray, + termTokens: TermTokens, + ): string { + const hue = hues[termIndex % hues.length]; + return ` #${EleID.MARKER_GUTTER} .${getTermClass(term, termTokens)} { background: hsl(${hue} 100% 44%); } ` - ); - } - this.#styleManager.setStyle(style); + ; } } -export { Style }; +export { Styles }; diff --git a/src/modules/highlight/models/tree-cache/term-markers/term-marker.mts b/src/modules/highlight/tools/term-markers/tree-cache.mts similarity index 75% rename from src/modules/highlight/models/tree-cache/term-markers/term-marker.mts rename to src/modules/highlight/tools/term-markers/tree-cache.mts index d462104..b0ade08 100644 --- a/src/modules/highlight/models/tree-cache/term-markers/term-marker.mts +++ b/src/modules/highlight/tools/term-markers/tree-cache.mts @@ -4,9 +4,12 @@ * Licensed under the EUPL-1.2-or-later. */ -import type { AbstractTermMarker } from "/dist/modules/highlight/term-marker.mjs"; +import type { AbstractTermMarker } from "/dist/modules/highlight/tools/term-marker.mjs"; +import { Styles } from "/dist/modules/highlight/tools/term-marker/common.mjs"; import type { BaseFlow } from "/dist/modules/highlight/matcher.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"; import { EleID, getElementYRelative, getTermClass, type AllReadonly } from "/dist/modules/common.mjs"; type Flow = BaseFlow @@ -16,6 +19,8 @@ class TermMarker implements AbstractTermMarker { readonly #elementFlowsMap: AllReadonly>>; + readonly #styleManager = new StyleManager(new HTMLStylesheet(document.head)); + readonly #termsStyleManager = new StyleManager(new HTMLStylesheet(document.head)); readonly #scrollGutter: HTMLElement; constructor ( @@ -24,6 +29,7 @@ class TermMarker implements AbstractTermMarker { ) { this.#termTokens = termTokens; this.#elementFlowsMap = elementFlowsMap; + this.#styleManager.setStyle(Styles.mainCSS); this.#scrollGutter = document.createElement("div"); this.#scrollGutter.id = EleID.MARKER_GUTTER; document.body.insertAdjacentElement("afterend", this.#scrollGutter); @@ -31,6 +37,8 @@ class TermMarker implements AbstractTermMarker { deactivate () { this.#scrollGutter.remove(); + this.#termsStyleManager.deactivate(); + this.#styleManager.deactivate(); } insert ( @@ -56,6 +64,11 @@ class TermMarker implements AbstractTermMarker { this.#scrollGutter.innerHTML = markersHtml; } + setTermsStyle (terms: ReadonlyArray, hues: ReadonlyArray) { + const styles = terms.map((term, i) => Styles.getTermCSS(term, i, hues, this.#termTokens)); + this.#termsStyleManager.setStyle(styles.join("")); + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars raise (term: MatchTerm | null, container: HTMLElement) { // Depends on scroll markers refreshed Paint implementation (TODO) diff --git a/src/modules/highlight/models/tree-edit/term-markers/term-marker.mts b/src/modules/highlight/tools/term-markers/tree-edit.mts similarity index 80% rename from src/modules/highlight/models/tree-edit/term-markers/term-marker.mts rename to src/modules/highlight/tools/term-markers/tree-edit.mts index d3d8c53..da7eb65 100644 --- a/src/modules/highlight/models/tree-edit/term-markers/term-marker.mts +++ b/src/modules/highlight/tools/term-markers/tree-edit.mts @@ -4,9 +4,12 @@ * Licensed under the EUPL-1.2-or-later. */ -import type { AbstractTermMarker } from "/dist/modules/highlight/term-marker.mjs"; +import type { AbstractTermMarker } from "/dist/modules/highlight/tools/term-marker.mjs"; +import { Styles } from "/dist/modules/highlight/tools/term-marker/common.mjs"; import { getContainerBlock } from "/dist/modules/highlight/container-blocks.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"; import { EleID, EleClass, getElementYRelative, elementsPurgeClass, getTermClass, getTermClassToken, @@ -15,10 +18,13 @@ import { class TermMarker implements AbstractTermMarker { readonly #termTokens: TermTokens; + readonly #styleManager = new StyleManager(new HTMLStylesheet(document.head)); + readonly #termsStyleManager = new StyleManager(new HTMLStylesheet(document.head)); readonly #scrollGutter: HTMLElement; - + constructor (termTokens: TermTokens) { this.#termTokens = termTokens; + this.#styleManager.setStyle(Styles.mainCSS); this.#scrollGutter = document.createElement("div"); this.#scrollGutter.id = EleID.MARKER_GUTTER; document.body.insertAdjacentElement("afterend", this.#scrollGutter); @@ -26,6 +32,8 @@ class TermMarker implements AbstractTermMarker { deactivate () { this.#scrollGutter.remove(); + this.#termsStyleManager.deactivate(); + this.#styleManager.deactivate(); } insert ( @@ -33,6 +41,7 @@ class TermMarker implements AbstractTermMarker { hues: ReadonlyArray, highlightedElements: Iterable, ) { + this.setTermsStyle(terms, hues); const regexMatchTermSelector = new RegExp(`\\b${EleClass.TERM}(?:-\\w+)+\\b`); const containersInfo: Array<{ container: HTMLElement @@ -67,6 +76,11 @@ class TermMarker implements AbstractTermMarker { this.#scrollGutter.innerHTML = markersHtml; } + setTermsStyle (terms: ReadonlyArray, hues: ReadonlyArray) { + const styles = terms.map((term, i) => Styles.getTermCSS(term, i, hues, this.#termTokens)); + this.#termsStyleManager.setStyle(styles.join("")); + } + raise (term: MatchTerm | null, container: HTMLElement) { elementsPurgeClass(EleClass.FOCUS, this.#scrollGutter); [6, 5, 4, 3, 2].some(precisionFactor => { diff --git a/src/modules/highlight/term-walker.mts b/src/modules/highlight/tools/term-walker.mts similarity index 96% rename from src/modules/highlight/term-walker.mts rename to src/modules/highlight/tools/term-walker.mts index c882212..4a07bb3 100644 --- a/src/modules/highlight/term-walker.mts +++ b/src/modules/highlight/tools/term-walker.mts @@ -7,6 +7,8 @@ import type { MatchTerm } from "/dist/modules/match-term.mjs"; interface AbstractTermWalker { + readonly deactivate: () => void + /** * Scrolls to the next (downwards) occurrence of a term in the document. Testing begins from the current selection position. * @param reverse Indicates whether elements should be tried in reverse, selecting the previous term as opposed to the next. diff --git a/src/modules/highlight/tools/term-walker/common.mts b/src/modules/highlight/tools/term-walker/common.mts new file mode 100644 index 0000000..b22b581 --- /dev/null +++ b/src/modules/highlight/tools/term-walker/common.mts @@ -0,0 +1,22 @@ +/* + * 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 { EleClass, AtRuleID } from "/dist/modules/common.mjs"; + +abstract class Styles { + static readonly mainCSS = (` +.${EleClass.FOCUS_CONTAINER} { + animation: ${AtRuleID.FLASH} 1s; +} + +@keyframes ${AtRuleID.FLASH} { + from { background-color: hsl(0 0% 65% / 0.8); } to {}; +} +` + ); +} + +export { Styles }; diff --git a/src/modules/highlight/models/tree-cache/term-walkers/term-walker.mts b/src/modules/highlight/tools/term-walkers/tree-cache.mts similarity index 87% rename from src/modules/highlight/models/tree-cache/term-walkers/term-walker.mts rename to src/modules/highlight/tools/term-walkers/tree-cache.mts index 41a835e..4e99a04 100644 --- a/src/modules/highlight/models/tree-cache/term-walkers/term-walker.mts +++ b/src/modules/highlight/tools/term-walkers/tree-cache.mts @@ -4,19 +4,29 @@ * Licensed under the EUPL-1.2-or-later. */ -import type { AbstractTermWalker } from "/dist/modules/highlight/term-walker.mjs"; +import type { AbstractTermWalker } from "/dist/modules/highlight/tools/term-walker.mjs"; +import { Styles } from "/dist/modules/highlight/tools/term-walker/common.mjs"; import type { BaseFlow } from "/dist/modules/highlight/matcher.mjs"; import type { MatchTerm } from "/dist/modules/match-term.mjs"; -import { EleID, EleClass, getNodeFinal, isVisible, elementsPurgeClass, focusClosest } from "/dist/modules/common.mjs"; +import { StyleManager } from "/dist/modules/style-manager.mjs"; +import { HTMLStylesheet } from "/dist/modules/stylesheets/html.mjs"; import type { AllReadonly } from "/dist/modules/common.mjs"; +import { EleID, EleClass, getNodeFinal, isVisible, elementsPurgeClass, focusClosest } from "/dist/modules/common.mjs"; type Flow = BaseFlow class TermWalker implements AbstractTermWalker { readonly #elementFlowsMap: AllReadonly>>; + readonly #styleManager = new StyleManager(new HTMLStylesheet(document.head)); + constructor (elementFlowsMap: AllReadonly>>) { this.#elementFlowsMap = elementFlowsMap; + this.#styleManager.setStyle(Styles.mainCSS); + } + + deactivate () { + this.#styleManager.deactivate(); } step ( diff --git a/src/modules/highlight/models/tree-edit/term-walkers/term-walker.mts b/src/modules/highlight/tools/term-walkers/tree-edit.mts similarity index 93% rename from src/modules/highlight/models/tree-edit/term-walkers/term-walker.mts rename to src/modules/highlight/tools/term-walkers/tree-edit.mts index b59eb51..2b8c1b4 100644 --- a/src/modules/highlight/models/tree-edit/term-walkers/term-walker.mts +++ b/src/modules/highlight/tools/term-walkers/tree-edit.mts @@ -4,18 +4,28 @@ * Licensed under the EUPL-1.2-or-later. */ -import type { AbstractTermWalker } from "/dist/modules/highlight/term-walker.mjs"; +import type { AbstractTermWalker } from "/dist/modules/highlight/tools/term-walker.mjs"; +import { Styles } from "/dist/modules/highlight/tools/term-walker/common.mjs"; import { getContainerBlock } from "/dist/modules/highlight/container-blocks.mjs"; import { HIGHLIGHT_TAG, HIGHLIGHT_TAG_UPPER } from "/dist/modules/highlight/models/tree-edit/tags.mjs"; import type { MatchTerm, TermTokens } from "/dist/modules/match-term.mjs"; -import { getTermClass } from "/dist/modules/common.mjs"; -import { EleID, EleClass, getNodeFinal, isVisible, elementsPurgeClass } from "/dist/modules/common.mjs"; +import { StyleManager } from "/dist/modules/style-manager.mjs"; +import { HTMLStylesheet } from "/dist/modules/stylesheets/html.mjs"; +import { EleID, EleClass, getNodeFinal, isVisible, elementsPurgeClass, getTermClass } from "/dist/modules/common.mjs"; class TermWalker implements AbstractTermWalker { readonly #termTokens: TermTokens; + + readonly #styleManager = new StyleManager(new HTMLStylesheet(document.head)); constructor (termTokens: TermTokens) { this.#termTokens = termTokens; + this.#styleManager.setStyle(Styles.mainCSS); + } + + deactivate () { + this.cleanup(); + this.#styleManager.deactivate(); } step ( @@ -36,9 +46,11 @@ class TermWalker implements AbstractTermWalker { } /** - * Scrolls to and focuses the next block containing an occurrence of a term in the document, from the current selection position. - * @param reverse Indicates whether elements should be tried in reverse, selecting the previous term as opposed to the next. - * @param term A term to jump to. If unspecified, the next closest occurrence of any term is jumpted to. + * Scrolls to and focuses the next block containing an occurrence of a term in the document, + * from the current selection position. + * @param reverse Indicates whether elements should be tried in reverse, + * selecting the previous term as opposed to the next. + * @param term A term to jump to. If unspecified, the next closest occurrence of any term is jumped to. */ focusNextTermJump (reverse: boolean, term: MatchTerm | null): HTMLElement | null { const termSelector = term ? getTermClass(term, this.#termTokens) : undefined; diff --git a/src/modules/interface/toolbar.mts b/src/modules/interface/toolbar.mts index c5d058a..38ea020 100644 --- a/src/modules/interface/toolbar.mts +++ b/src/modules/interface/toolbar.mts @@ -6,7 +6,7 @@ import type { BrowserCommands } from "/dist/modules/interface/toolbar/common.mjs"; import type { TermControlInputInterface } from "/dist/modules/interface/toolbar/term-control.mjs"; -import type { ConfigBarControlsShown } from "../storage.mjs"; +import type { ConfigBarControlsShown } from "/dist/modules/storage.mjs"; import type { MatchTerm } from "/dist/modules/match-term.mjs"; type SelectionReturnTarget = Readonly<{ diff --git a/src/modules/messaging.mts b/src/modules/messaging.mts index 28c7102..5ad2661 100644 --- a/src/modules/messaging.mts +++ b/src/modules/messaging.mts @@ -5,7 +5,7 @@ */ import type { CommandInfo } from "/dist/modules/commands.mjs"; -import type { ConfigValues } from "./storage.mjs"; +import type { ConfigValues } from "/dist/modules/storage.mjs"; import type { MatchTerm } from "/dist/modules/match-term.mjs"; type Tab = Readonly<{ diff --git a/src/modules/page/build.mts b/src/modules/page/build.mts index 38971ab..f8be89f 100644 --- a/src/modules/page/build.mts +++ b/src/modules/page/build.mts @@ -5,7 +5,7 @@ */ import * as Manifest from "/dist/modules/manifest.mjs"; -import { Bank, Config } from "../storage.mjs"; +import { Bank, Config } from "/dist/modules/storage.mjs"; import type { MatchTerm } from "/dist/modules/match-term.mjs"; import { getIdSequential } from "/dist/modules/common.mjs"; import * as EmailJS from "/lib/email.min.js"; diff --git a/src/modules/privileged/tabs.mts b/src/modules/privileged/tabs.mts index eb41dc6..117de02 100644 --- a/src/modules/privileged/tabs.mts +++ b/src/modules/privileged/tabs.mts @@ -4,7 +4,7 @@ * Licensed under the EUPL-1.2-or-later. */ -import { Bank } from "../storage.mjs"; +import { Bank } from "/dist/modules/storage.mjs"; /** * Gets whether or not a tab has active highlighting information stored, so is considered highlighted. diff --git a/src/modules/stylesheets/html.mts b/src/modules/stylesheets/html.mts index 844f873..4beb340 100644 --- a/src/modules/stylesheets/html.mts +++ b/src/modules/stylesheets/html.mts @@ -5,11 +5,14 @@ */ import type { AbstractStylesheet } from "/dist/modules/stylesheet.mjs"; +import { EleClass } from "/dist/modules/common.mjs"; class HTMLStylesheet implements AbstractStylesheet { - readonly #stylesheet = document.createElement("style"); + readonly #stylesheet: HTMLStyleElement; constructor (parent: Node) { + this.#stylesheet = document.createElement("style"); + this.#stylesheet.classList.add(EleClass.STYLESHEET); parent.appendChild(this.#stylesheet); } diff --git a/src/pages/options-new.mts b/src/pages/options-new.mts index eef33af..9f4939b 100644 --- a/src/pages/options-new.mts +++ b/src/pages/options-new.mts @@ -11,8 +11,8 @@ import { } from "/dist/modules/page/build.mjs"; import type { StoreImmediate, StoreList, StoreListInterface, ConfigValues, ConfigKey, -} from "../modules/storage.mjs"; -import { StoreType, Config } from "../modules/storage.mjs"; +} from "/dist/modules/storage.mjs"; +import { StoreType, Config } from "/dist/modules/storage.mjs"; import { compatibility } from "/dist/modules/common.mjs"; const getControlOptionTemp = ( diff --git a/src/pages/options.mts b/src/pages/options.mts index 9fc4f45..c19db8c 100644 --- a/src/pages/options.mts +++ b/src/pages/options.mts @@ -8,8 +8,8 @@ //import { isWindowInFrame } from "/dist/modules/page/build.mjs"; import type { StoreImmediate, StoreList, StoreListInterface, ConfigValues, ConfigKey, -} from "../modules/storage.mjs"; -import { StoreType, Config } from "../modules/storage.mjs"; +} from "/dist/modules/storage.mjs"; +import { StoreType, Config } from "/dist/modules/storage.mjs"; import { compatibility, getIdSequential } from "/dist/modules/common.mjs"; const isWindowInFrame = () => ( diff --git a/src/pages/popup.mts b/src/pages/popup.mts index 7a557a8..8fd55c6 100644 --- a/src/pages/popup.mts +++ b/src/pages/popup.mts @@ -5,7 +5,7 @@ */ import { type Page, loadPage, pageInsertWarning, sendProblemReport } from "/dist/modules/page/build.mjs"; -import { Bank, Config } from "../modules/storage.mjs"; +import { Bank, Config } from "/dist/modules/storage.mjs"; import { sendBackgroundMessage } from "/dist/modules/messaging/background.mjs"; import { isTabResearchPage } from "/dist/modules/privileged/tabs.mjs"; import { type MatchMode, MatchTerm } from "/dist/modules/match-term.mjs"; diff --git a/src/pages/startpage.mts b/src/pages/startpage.mts index 4994e7a..2b04af0 100644 --- a/src/pages/startpage.mts +++ b/src/pages/startpage.mts @@ -6,7 +6,7 @@ import * as Manifest from "/dist/modules/manifest.mjs"; import { type Page, loadPage } from "/dist/modules/page/build.mjs"; -import { Config } from "../modules/storage.mjs"; +import { Config } from "/dist/modules/storage.mjs"; /** * Loads the startpage content into the page.