1
0
mirror of https://github.com/koloml/furbooru-tagging-assistant.git synced 2025-12-24 07:12:57 +00:00

Updated viewer to receive all the image URLs and apply selected size

This commit is contained in:
2024-12-30 22:40:58 +04:00
parent 98d3b1c696
commit 3d1e0d6f06
4 changed files with 50 additions and 11 deletions

View File

@@ -16,6 +16,7 @@ export class FullscreenViewer extends BaseComponent {
#startY = null;
/** @type {boolean|null} */
#isClosingSwipeStarted = null;
#isSizeFetched = false;
/**
* @protected
@@ -187,6 +188,9 @@ export class FullscreenViewer extends BaseComponent {
*/
#onSizeResolved(size) {
this.#sizeSelectorElement.value = size;
this.#isSizeFetched = true;
this.emit('size-loaded');
}
#watchForSizeSelectionChanges() {
@@ -227,9 +231,42 @@ export class FullscreenViewer extends BaseComponent {
}
/**
* @param {string} url
* @param {App.ImageURIs} imageUris
* @return {Promise<string|null>}
*/
show(url) {
async #resolveCurrentSelectedSizeUrl(imageUris) {
if (!this.#isSizeFetched) {
await new Promise(resolve => this.on('size-loaded', resolve))
}
let targetSize = this.#sizeSelectorElement.value;
if (!imageUris.hasOwnProperty(targetSize)) {
targetSize = FullscreenViewer.#fallbackSize;
}
if (!imageUris.hasOwnProperty(targetSize)) {
targetSize = Object.keys(imageUris)[0];
}
if (!targetSize) {
return null;
}
return imageUris[targetSize];
}
/**
* @param {App.ImageURIs} imageUris
*/
async show(imageUris) {
const url = await this.#resolveCurrentSelectedSizeUrl(imageUris);
if (!url) {
console.warn('Failed to resolve media for the viewer!');
return;
}
this.container.classList.add('loading');
requestAnimationFrame(() => {
@@ -283,4 +320,6 @@ export class FullscreenViewer extends BaseComponent {
medium: 'Medium',
small: 'Small'
}
static #fallbackSize = 'large';
}

View File

@@ -47,7 +47,7 @@ export class ImageShowFullscreenButton extends BaseComponent {
#onButtonClicked() {
ImageShowFullscreenButton
.#resolveViewer()
.show(this.#mediaBoxTools.mediaBox.imageLinks.large);
.show(this.#mediaBoxTools.mediaBox.imageLinks);
}
/**

View File

@@ -56,7 +56,7 @@ export class MediaBoxWrapper extends BaseComponent {
}
/**
* @return {ImageURIs}
* @return {App.ImageURIs}
*/
get imageLinks() {
return JSON.parse(this.#thumbnailContainer.dataset.uris);
@@ -100,10 +100,3 @@ export function calculateMediaBoxesPositions(mediaBoxesList) {
}
})
}
/**
* @typedef {Object} ImageURIs
* @property {string} full
* @property {string} large
* @property {string} small
*/