Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into svg-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuuuube committed Dec 28, 2024
2 parents 6bec9e7 + 4b97a01 commit a6d96ef
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 21 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@
"ext/js/core/extension-error.js",
"ext/js/core/json.js",
"ext/js/data/anki-note-data-creator.js",
"ext/js/data/array-buffer-util.js",
"ext/js/dictionary/dictionary-data-util.js",
"ext/js/display/display-content-manager.js",
"ext/js/display/pronunciation-generator.js",
Expand Down
8 changes: 8 additions & 0 deletions docs/development/npm-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
This file documents the scripts available in the [package.json](../../package.json) file.
Scripts can be executed by running `npm run <name>`.

- `anki:css-json:write`

Writes Anki structured content styling json for use when sending stuctured content dictionaries to Anki.

CSS rules are taken from `ext/css/structured-content.css` and converted into json.

CSS rule overrides and exclusions can be set in `dev/data/structured-content-overrides.css`.

- `bench`
Runs performance benchmarks.

Expand Down
1 change: 0 additions & 1 deletion ext/css/display.css
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,6 @@ button.action-button:active {
.entry {
padding: var(--entry-vertical-padding) var(--entry-horizontal-padding);
position: relative;
content-visibility: auto;
contain-intrinsic-height: auto 500px;
}
.entry+.entry {
Expand Down
2 changes: 0 additions & 2 deletions ext/css/structured-content.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
}
.gloss-image-link:hover {
color: var(--accent-color-dark);
}
.gloss-image-link[href]:hover {
cursor: pointer;
}
.gloss-image-container-overlay {
Expand Down
6 changes: 0 additions & 6 deletions ext/data/structured-content-style.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
["color", "inherit"]
]
},
{
"selectors": [".gloss-image-link[href]:hover"],
"styles": [
["cursor", "pointer"]
]
},
{
"selectors": [".gloss-image-container-overlay"],
"styles": [
Expand Down
14 changes: 14 additions & 0 deletions ext/js/display/display-content-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import {EventListenerCollection} from '../core/event-listener-collection.js';
import {base64ToArrayBuffer} from '../data/array-buffer-util.js';

/**
* The content manager which is used when generating HTML display content.
Expand Down Expand Up @@ -86,6 +87,19 @@ export class DisplayContentManager {
this._loadMediaRequests = [];
}

/**
* @param {string} path
* @param {string} dictionary
* @param {Window} window
*/
async openMediaInTab(path, dictionary, window) {
const data = await this._display.application.api.getMedia([{path, dictionary}]);
const buffer = base64ToArrayBuffer(data[0].content);
const blob = new Blob([buffer], {type: data[0].mediaType});
const blobUrl = URL.createObjectURL(blob);
window.open(blobUrl, '_blank')?.focus();
}

/**
* @param {MouseEvent} e
*/
Expand Down
12 changes: 12 additions & 0 deletions ext/js/display/structured-content-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ export class StructuredContentGenerator {
const overlay = this._createElement('span', 'gloss-image-container-overlay');
imageContainer.appendChild(overlay);

const linkText = this._createElement('span', 'gloss-image-link-text');
linkText.textContent = 'Image';
node.appendChild(linkText);

if (this._contentManager instanceof DisplayContentManager) {
node.addEventListener('click', () => {
if (this._contentManager instanceof DisplayContentManager) {
void this._contentManager.openMediaInTab(path, dictionary, window);
}
});
}

node.dataset.path = path;
node.dataset.dictionary = dictionary;
node.dataset.imageLoadState = 'not-loaded';
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"type": "module",
"scripts": {
"anki:css-json:write": "node ./dev/bin/generate-css-json.js --dryRun --all",
"bench": "vitest bench",
"build": "node ./dev/bin/build.js",
"build:libs": "node ./dev/bin/build-libs.js",
Expand Down
24 changes: 12 additions & 12 deletions test/data/anki-note-builder-test-results.json

Large diffs are not rendered by default.

0 comments on commit a6d96ef

Please sign in to comment.