Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/lib/components/Reader/MangaPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@
import TextBoxes from './TextBoxes.svelte';
import { zoomDefault } from '$lib/panzoom';
export let page: Page;
export let src: File;
type FileWithBlob = File & { blob?: string };
$: url = src ? `url(${URL.createObjectURL(src)})` : '';
export let page: Page;
export let src: FileWithBlob;
let url: string = '';
// $: url = src ? `url(${URL.createObjectURL(src)})` : '';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// $: url = src ? `url(${URL.createObjectURL(src)})` : '';

$: {
if (src) {
src.blob = src.blob || URL.createObjectURL(src);
url = `url(${src.blob})`;
} else {
url = '';
}
}
let legacy: HTMLElement | null;
onMount(() => {
Expand Down
49 changes: 46 additions & 3 deletions src/lib/components/Reader/Reader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import { getCharCount } from '$lib/util/count-chars';
import QuickActions from './QuickActions.svelte';
import { beforeNavigate } from '$app/navigation';
import { onMount } from 'svelte';
import { onMount, onDestroy } from 'svelte';

// TODO: Refactor this whole mess
export let volumeSettings: VolumeSettings;
Expand Down Expand Up @@ -221,11 +221,54 @@
}
}

onMount(() => {
// preload volumes
let preloadStyle: HTMLStyleElement | null = null;

$: {
if (volume && index != undefined) {
let preloadStartIndex = Math.max(0, index - (showSecondPage() ? 2 : 1));
let preloadEndIndex = index + (showSecondPage() ? 3 : 1);
let imagesToPreload: string[] = [];

for (let i = preloadEndIndex; i >= preloadStartIndex; i--) {
let src = Object.values(volume?.files)[i];
src.blob = src.blob || URL.createObjectURL(src);
imagesToPreload.push(src.blob);
}

preloadStyle = preloadStyle || document.createElement('style');

preloadStyle.innerHTML = `
body::after {
position: absolute;
width: 0;
height: 0;
overflow: hidden;
z-index: -1;
content: ${imagesToPreload.map(url => `url(${url})`).join(' ')};
}
`;
}
}

onMount(() => {
if ($settings.defaultFullscreen) {
document.documentElement.requestFullscreen();
}
});

preloadStyle = preloadStyle || document.createElement('style');
preloadStyle.type = 'text/css';
preloadStyle.id = "preloadCSS";

document.head.appendChild(preloadStyle);
});

onDestroy(() => {
if (preloadStyle) {
document.head.removeChild(preloadStyle);
}
preloadStyle = null;
});

beforeNavigate(() => {
if (document.exitFullscreen) {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ export type MokuroData = {
pages: Page[];
};

type FileWithBlob = File & { blob?: string };

export type Volume = {
mokuroData: MokuroData;
volumeName: string;
files: Record<string, File>;
files: Record<string, FileWithBlob>;
};