Skip to content

Commit

Permalink
Merge pull request #186 from ator-dev/hierarchy-improve
Browse files Browse the repository at this point in the history
Improve organisation of the src/ hierarchy
  • Loading branch information
ator-dev authored Sep 12, 2024
2 parents 5518cc4 + 2e22b5f commit 8abbeb8
Show file tree
Hide file tree
Showing 33 changed files with 126 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: |
git clone https://user:[email protected]/$GITHUB_REPOSITORY
cd ${{ env.REPO_NAME }}
version=$( cat manifest/firefox.json | jq --raw-output '.version' )
version=$( cat platform/firefox/manifest.json | jq --raw-output '.version' )
tag_name=v$version
git config user.name "searchmarkers"
git config user.email "[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"scripts": {
"icons-convert": "bash -c 'mkdir -p icons/dist; SIZES=(16 32 48 64 96 128 240 300); for SIZE in ${SIZES[@]}; do inkscape icons/mms.svg -w $SIZE -h $SIZE -o icons/dist/mms-${SIZE}.png; done; SIZES=(32); for SIZE in ${SIZES[@]}; do inkscape icons/mms-off.svg -w $SIZE -h $SIZE -o icons/dist/mms-off-${SIZE}.png; done'",
"scripts-build": "rm --recursive dist; tsc --project tsconfig.json",
"prepare-firefox": "ln --force --symbolic manifest/firefox.json manifest.json",
"prepare-chromium": "ln --force --symbolic manifest/chromium.json manifest.json",
"prepare-firefox": "ln --force --symbolic platform/firefox/manifest.json manifest.json",
"prepare-chromium": "ln --force --symbolic platform/chromium/manifest.json manifest.json",
"pack-firefox": "rm --force pack/mark_my_search-firefox.zip; npm run scripts-build; npm run prepare-firefox; mkdir --parents pack; zip pack/mark_my_search-firefox.zip * -ri dist/**\\* icons/**\\* pages/**\\* lib/**\\* manifest.json",
"pack-chromium": "rm --force pack/mark_my_search-chromium.zip; npm run scripts-build; npm run prepare-chromium; mkdir --parents pack; zip pack/mark_my_search-chromium.zip * -ri dist/**\\* icons/**\\* pages/**\\* lib/**\\* manifest.json"
},
Expand Down
1 change: 0 additions & 1 deletion manifest/chromium.json → platform/chromium/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
{
"resources": [
"/icons/*.svg",
"/dist/paint.js",
"/dist/content.mjs",
"/dist/modules/*.mjs"
],
Expand Down
1 change: 0 additions & 1 deletion manifest/firefox.json → platform/firefox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
{
"resources": [
"/icons/*.svg",
"/dist/paint.js",
"/dist/content.mjs",
"/dist/modules/*.mjs"
],
Expand Down
File renamed without changes.
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 { highlightTags } from "/dist/modules/highlight/highlight-tags.mjs";
import { highlightTags } from "/dist/modules/highlight/common/highlight-tags.mjs";

/**
* A selector string for the container block of an element.
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions src/modules/highlight/common/matching.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 { MatchTerm } from "/dist/modules/match-term.mjs";

type BaseFlow<WithNode extends boolean> = {
text: string
spans: Array<BaseSpan<WithNode>>
}

type BaseSpan<WithNode extends boolean> = {
term: MatchTerm
start: number
end: number
} & (WithNode extends true
? { node: Text }
: Record<never, never>
)

export type { BaseFlow, BaseSpan };
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,9 @@
* Licensed under the EUPL-1.2-or-later.
*/

import type { BaseSpan } from "/dist/modules/highlight/common/matching.d.mjs";
import type { MatchTerm, TermPatterns } from "/dist/modules/match-term.mjs";

type BaseFlow<WithNode extends boolean> = {
text: string
spans: Array<BaseSpan<WithNode>>
}

type BaseSpan<WithNode extends boolean> = {
term: MatchTerm
start: number
end: number
} & (WithNode extends true
? { node: Text }
: Record<never, never>
)

const matchInText = (
terms: ReadonlyArray<MatchTerm>,
termPatterns: TermPatterns,
Expand Down Expand Up @@ -79,7 +66,4 @@ const matchInTextFlow = (
return spans;
};

export {
type BaseFlow, type BaseSpan,
matchInText, matchInTextFlow,
};
export { matchInText, matchInTextFlow };
36 changes: 36 additions & 0 deletions src/modules/highlight/common/term-css.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.
*/

abstract class TermCSS {
static getFlatStyle (this: void, color: string) {
return color;
}

static getDiagonalStyle (this: void, colorA: string, colorB: string, cycle: number) {
const isAboveStyleLevel = (level: number) => cycle >= level;
return isAboveStyleLevel(1)
? `repeating-linear-gradient(${
isAboveStyleLevel(3) ? isAboveStyleLevel(4) ? 0 : 90 : isAboveStyleLevel(2) ? 45 : -45
}deg, ${colorA}, ${colorA} 2px, ${colorB} 2px, ${colorB} 8px)`
: colorA;
}

static getHorizontalStyle (this: void, colorA: string, colorB: string, cycle: number) {
const isAboveStyleLevel = (level: number) => cycle >= level;
return isAboveStyleLevel(1)
? `linear-gradient(${Array(Math.floor(cycle/2 + 1.5) * 2)
.fill("")
.map((v, i) => (
(Math.floor(i / 2) % 2 == cycle % 2 ? colorB : colorA)
+ (Math.floor((i + 1) / 2)/(Math.floor((cycle + 1) / 2) + 1) * 100) + "%"
))
.join(", ")
})`
: colorA;
}
}

export default TermCSS;
30 changes: 28 additions & 2 deletions src/modules/highlight/engine-manager.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
* 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 { AbstractTermCounter } from "/dist/modules/highlight/tools/term-counter.mjs";
import type { MatchTerm } from "/dist/modules/match-term.mjs";
import type { Engine, PaintEngineMethod } from "/dist/modules/common.mjs";

interface AbstractEngineManager extends Highlighter, HighlighterCounterInterface, HighlighterWalkerInterface {
Expand All @@ -24,4 +25,29 @@ interface AbstractEngineManager extends Highlighter, HighlighterCounterInterface
readonly removeSpecialEngine: () => void
}

export type { AbstractEngineManager };
interface HighlighterCounterInterface {
readonly termCounter: AbstractTermCounter;
}

interface HighlighterWalkerInterface {
/**
* Moves to the next (downwards) occurrence of a term in the document, beginning from the current selection position.
* If an occurrence is successfully focused, the corresponding term marker in the scrollbar will be raised.
* *Refer to the TermWalker and TermMarker interfaces for more details.*
* @param reverse Indicates whether elements should be tried in reverse, selecting the previous term as opposed to the next.
* @param stepNotJump
* @param term A term to jump to. If unspecified, the next closest occurrence of any term is jumpted to.
* @returns The element landed on by the function, if any.
*/
readonly stepToNextOccurrence: (
reverse: boolean,
stepNotJump: boolean,
term: MatchTerm | null,
) => HTMLElement | null
}

export type {
AbstractEngineManager,
HighlighterCounterInterface,
HighlighterWalkerInterface,
};
2 changes: 1 addition & 1 deletion src/modules/highlight/engine-manager.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { AbstractTermWalker } from "/dist/modules/highlight/tools/term-walk
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.d.mjs";
import { getContainerBlock } from "/dist/modules/highlight/container-blocks.mjs";
import { getContainerBlock } from "/dist/modules/highlight/common/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";
Expand Down
6 changes: 3 additions & 3 deletions src/modules/highlight/engines/element.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

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.d.mjs";
import { highlightTags } from "/dist/modules/highlight/highlight-tags.mjs";
import * as TermCSS from "/dist/modules/highlight/term-css.mjs";
import type { FlowMutationObserver } from "/dist/modules/highlight/common/flow-mutations.d.mjs";
import { highlightTags } from "/dist/modules/highlight/common/highlight-tags.mjs";
import TermCSS from "/dist/modules/highlight/common/term-css.mjs";
import type { MatchTerm, TermTokens, TermPatterns } 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/highlight.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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 TermCSS from "/dist/modules/highlight/common/term-css.mjs";
import type { MatchTerm, TermTokens, TermPatterns } from "/dist/modules/match-term.mjs";
import { StyleManager } from "/dist/modules/style-manager.mjs";
import { HTMLStylesheet } from "/dist/modules/stylesheets/html.mjs";
Expand Down
4 changes: 2 additions & 2 deletions src/modules/highlight/engines/paint.mts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { getBoxesOwned } from "/dist/modules/highlight/engines/paint/boxes.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 { highlightTags } from "/dist/modules/highlight/common/highlight-tags.mjs";
import TermCSS from "/dist/modules/highlight/common/term-css.mjs";
import type { MatchTerm, TermTokens, TermPatterns } 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/boxes.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import type { Flow, Span, Box } from "/dist/modules/highlight/engines/paint.mjs";
import type { Highlightables } from "/dist/modules/highlight/engines/paint/highlightables.d.mjs";
import { highlightTags } from "/dist/modules/highlight/highlight-tags.mjs";
import { highlightTags } from "/dist/modules/highlight/common/highlight-tags.mjs";
import type { TermTokens } from "/dist/modules/match-term.mjs";
import type { AllReadonly } from "/dist/modules/common.mjs";

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 @@ -7,7 +7,7 @@
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";
import TermCSS from "/dist/modules/highlight/common/term-css.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
4 changes: 3 additions & 1 deletion src/modules/highlight/engines/paint/methods/paint.mts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class PaintMethod implements AbstractMethod {
constructor (termTokens: TermTokens) {
this.#termTokens = termTokens;
if (!PaintMethod.#paintModuleAdded) {
CSS.paintWorklet?.addModule(chrome.runtime.getURL("/dist/paint.js"));
CSS.paintWorklet?.addModule(chrome.runtime.getURL(
"/dist/modules/highlight/engines/paint/methods/paint/paint-worklet.mjs",
));
PaintMethod.#paintModuleAdded = true;
}
}
Expand Down
File renamed without changes.
34 changes: 0 additions & 34 deletions src/modules/highlight/model.d.mts

This file was deleted.

4 changes: 2 additions & 2 deletions src/modules/highlight/models/tree-cache/flow-tracker.d.mts
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 { FlowMutationObserver } from "/dist/modules/highlight/flow-mutation-observer.d.mjs";
import type { BaseFlow, BaseSpan } from "/dist/modules/highlight/matcher.mjs";
import type { FlowMutationObserver } from "/dist/modules/highlight/common/flow-mutations.d.mjs";
import type { BaseFlow, BaseSpan } from "/dist/modules/highlight/common/matching.d.mjs";
import type { MatchTerm } from "/dist/modules/match-term.mjs";
import type { AllReadonly } from "/dist/modules/common.mjs";

Expand Down
4 changes: 2 additions & 2 deletions src/modules/highlight/models/tree-cache/flow-tracker.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import type { Flow, Span, AbstractFlowTracker } from "/dist/modules/highlight/models/tree-cache/flow-tracker.d.mjs";
import { highlightTags } from "/dist/modules/highlight/highlight-tags.mjs";
import { matchInTextFlow } from "/dist/modules/highlight/matcher.mjs";
import { highlightTags } from "/dist/modules/highlight/common/highlight-tags.mjs";
import { matchInTextFlow } from "/dist/modules/highlight/common/matching.mjs";
import type { MatchTerm, TermPatterns } from "/dist/modules/match-term.mjs";
import type { RContainer, AllReadonly } from "/dist/modules/common.mjs";

Expand Down
3 changes: 2 additions & 1 deletion src/modules/highlight/special-engines/paint.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import type { AbstractSpecialEngine } from "/dist/modules/highlight/special-engine.d.mjs";
import type { Box } from "/dist/modules/highlight/engines/paint.mjs";
import { UrlMethod } from "/dist/modules/highlight/engines/paint/methods/url.mjs";
import { type BaseFlow, type BaseSpan, matchInText } from "/dist/modules/highlight/matcher.mjs";
import { type BaseFlow, type BaseSpan } from "/dist/modules/highlight/common/matching.d.mjs";
import { matchInText } from "/dist/modules/highlight/common/matching.mjs";
import type { MatchTerm, TermTokens, TermPatterns } from "/dist/modules/match-term.mjs";
import { StyleManager } from "/dist/modules/style-manager.mjs";
import { HTMLStylesheet } from "/dist/modules/stylesheets/html.mjs";
Expand Down
32 changes: 0 additions & 32 deletions src/modules/highlight/term-css.mts

This file was deleted.

4 changes: 2 additions & 2 deletions src/modules/highlight/tools/term-counters/tree-cache.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import type { AbstractTermCounter } from "/dist/modules/highlight/tools/term-counter.d.mjs";
import type { BaseFlow } from "/dist/modules/highlight/matcher.mjs";
import { highlightTags } from "/dist/modules/highlight/highlight-tags.mjs";
import type { BaseFlow } from "/dist/modules/highlight/common/matching.d.mjs";
import { highlightTags } from "/dist/modules/highlight/common/highlight-tags.mjs";
import type { MatchTerm } from "/dist/modules/match-term.mjs";
import type { AllReadonly } from "/dist/modules/common.mjs";

Expand Down
2 changes: 1 addition & 1 deletion src/modules/highlight/tools/term-markers/tree-cache.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import type { AbstractTermMarker } from "/dist/modules/highlight/tools/term-marker.d.mjs";
import { Styles } from "/dist/modules/highlight/tools/term-marker/common.mjs";
import type { BaseFlow } from "/dist/modules/highlight/matcher.mjs";
import type { BaseFlow } from "/dist/modules/highlight/common/matching.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/tools/term-markers/tree-edit.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import type { AbstractTermMarker } from "/dist/modules/highlight/tools/term-marker.d.mjs";
import { Styles } from "/dist/modules/highlight/tools/term-marker/common.mjs";
import { getContainerBlock } from "/dist/modules/highlight/container-blocks.mjs";
import { getContainerBlock } from "/dist/modules/highlight/common/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";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/highlight/tools/term-walkers/tree-cache.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import type { AbstractTermWalker } from "/dist/modules/highlight/tools/term-walker.d.mjs";
import { Styles } from "/dist/modules/highlight/tools/term-walker/common.mjs";
import type { BaseFlow } from "/dist/modules/highlight/matcher.mjs";
import type { BaseFlow } from "/dist/modules/highlight/common/matching.d.mjs";
import type { MatchTerm } 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/tools/term-walkers/tree-edit.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import type { AbstractTermWalker } from "/dist/modules/highlight/tools/term-walker.d.mjs";
import { Styles } from "/dist/modules/highlight/tools/term-walker/common.mjs";
import { getContainerBlock } from "/dist/modules/highlight/container-blocks.mjs";
import { getContainerBlock } from "/dist/modules/highlight/common/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 { StyleManager } from "/dist/modules/style-manager.mjs";
Expand Down
Loading

0 comments on commit 8abbeb8

Please sign in to comment.