Compare commits
3 Commits
8f5f12ad30
...
9d2373a298
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d2373a298 | |||
| e6da8b17a7 | |||
| 29fb7fd04d |
@@ -8,4 +8,6 @@
|
|||||||
}
|
}
|
||||||
<app-header></app-header>
|
<app-header></app-header>
|
||||||
<div class="h-10"></div>
|
<div class="h-10"></div>
|
||||||
<router-outlet></router-outlet>
|
<main>
|
||||||
|
<router-outlet></router-outlet>
|
||||||
|
</main>
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
main {
|
||||||
|
overflow-y: auto;
|
||||||
|
height: calc(100vh - 3rem);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,12 +3,26 @@
|
|||||||
<h1>{{ detail_item.name }}</h1>
|
<h1>{{ detail_item.name }}</h1>
|
||||||
<h2>{{ detail_item.rus_name }}</h2>
|
<h2>{{ detail_item.rus_name }}</h2>
|
||||||
<img [src]="detail_item.cover.default" [alt]="detail_item.slug" />
|
<img [src]="detail_item.cover.default" [alt]="detail_item.slug" />
|
||||||
@for (chapter of chapters.data; track $index) {
|
|
||||||
<h3>
|
<details class="w-full">
|
||||||
<strong>{{ chapter.number }}.</strong> {{ chapter.name || "Нет названия" }}
|
<summary class="text-center sticky top-0 bg-white z-10 py-2">
|
||||||
</h3>
|
<h3>Главы</h3>
|
||||||
}
|
</summary>
|
||||||
<button class="p-3 text-white bg-slate-600 w-[400px] mt-5 rounded-lg" (click)="goToReader()">
|
<div class="flex flex-col items-center pb-16">
|
||||||
|
@for (chapter of chapters.data; track $index) {
|
||||||
|
<button
|
||||||
|
(click)="goToReader(chapter.number, chapter.volume)"
|
||||||
|
[title]="chapter.name"
|
||||||
|
class="p-3 text-white bg-slate-600 w-[300px] mt-3 rounded-lg"
|
||||||
|
>
|
||||||
|
<h3>
|
||||||
|
<strong>{{ chapter.number }}.</strong> {{ chapter.name || "Нет названия" }}
|
||||||
|
</h3>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
<button class="p-3 text-white bg-slate-600 w-[300px] mt-5 rounded-lg" (click)="goToReader()">
|
||||||
Читать
|
Читать
|
||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export class DetailComponent implements AfterViewInit {
|
|||||||
});
|
});
|
||||||
this.searchService.getChapters(url).subscribe((data) => {
|
this.searchService.getChapters(url).subscribe((data) => {
|
||||||
this.chapters = data;
|
this.chapters = data;
|
||||||
|
console.log(data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,13 +42,13 @@ export class DetailComponent implements AfterViewInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
goToReader() {
|
goToReader(chapter: string = "1", volume: string = "1") {
|
||||||
//TODO: Not only first chapter
|
console.log(chapter, volume);
|
||||||
this.router.navigate(["/", "reader"], {
|
this.router.navigate(["/", "reader"], {
|
||||||
queryParams: {
|
queryParams: {
|
||||||
url: this.detail_item?.slug_url,
|
url: this.detail_item?.slug_url,
|
||||||
chapter: this.chapters.data[0].number,
|
chapter: +chapter,
|
||||||
volume: this.chapters.data[0].volume,
|
volume: +volume,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div
|
<div
|
||||||
class="header fixed flex justify-between w-full p-2 bg-gray-700 md:h-8 h-auto items-center md:flex-row flex-col md:gap-0 gap-3"
|
class="header fixed flex justify-between w-full p-2 bg-gray-700 md:h-8 items-center md:flex-row flex-col md:gap-0 gap-3 text-xl md:text-base"
|
||||||
>
|
>
|
||||||
<div class="flex justify-between flex-row w-full align-middle">
|
<div class="flex justify-between flex-row w-full align-middle">
|
||||||
<a href="/"><h1 class="text-white" title="Main page">NwaifuAnime</h1></a>
|
<a href="/"><h1 class="text-white" title="Main page">NwaifuAnime</h1></a>
|
||||||
@@ -17,7 +17,11 @@
|
|||||||
class="outline-none ps-1 text-sm leading-6 w-full border-0 bg-transparent border-r border-gray-700"
|
class="outline-none ps-1 text-sm leading-6 w-full border-0 bg-transparent border-r border-gray-700"
|
||||||
(keydown.enter)="search()"
|
(keydown.enter)="search()"
|
||||||
/>
|
/>
|
||||||
<button class="align-middle w-[100px] text-center" type="submit" (click)="search()">
|
<button
|
||||||
|
class="align-middle w-[100px] text-center border-0 flex flex-col items-center justify-center"
|
||||||
|
type="submit"
|
||||||
|
(click)="search()"
|
||||||
|
>
|
||||||
<span class="text-sm text-black h-full">Поиск</span>
|
<span class="text-sm text-black h-full">Поиск</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule } from "@angular/common";
|
||||||
import { AfterViewInit, Component, ElementRef, ViewChild } from "@angular/core";
|
import { AfterViewInit, Component, ElementRef, ViewChild } from "@angular/core";
|
||||||
import { ActivatedRoute, Router } from "@angular/router";
|
import { ActivatedRoute, NavigationEnd, Router } from "@angular/router";
|
||||||
|
import { filter } from "rxjs";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-header",
|
selector: "app-header",
|
||||||
@@ -15,7 +16,16 @@ export class HeaderComponent implements AfterViewInit {
|
|||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
) {}
|
) {
|
||||||
|
this.router.events
|
||||||
|
.pipe(filter((event) => event instanceof NavigationEnd))
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
.subscribe((val: any) => {
|
||||||
|
if (val.url.startsWith("/detail") || val.url.startsWith("/reader")) {
|
||||||
|
this.menuOpened = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
changeMenu() {
|
changeMenu() {
|
||||||
this.menuOpened = !this.menuOpened;
|
this.menuOpened = !this.menuOpened;
|
||||||
}
|
}
|
||||||
@@ -25,7 +35,7 @@ export class HeaderComponent implements AfterViewInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get searchBarClass(): string {
|
get searchBarClass(): string {
|
||||||
return `search-bar bg-slate-300 md:w-[50%] w-full md:m-0 ms-2 me-2 max-h-6 md:flex justify-start flex-row items-center rounded-md ${this.menuOpened ? "flex" : "hidden"}`;
|
return `search-bar bg-slate-300 md:w-[50%] w-full md:m-0 ms-2 me-2 md:h-6 h-10 md:flex justify-start flex-row items-center rounded-md ${this.menuOpened ? "flex" : "hidden"}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
search() {
|
search() {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<h1>It's home component</h1>
|
<h1>It's home component</h1>
|
||||||
<div class="flex flex-col items-center">
|
<div class="flex flex-col items-center w-full px-3">
|
||||||
@for (item of items; track $index) {
|
@for (item of items; track $index) {
|
||||||
<button (click)="getDetails(item.slug_url)" title="{{ item.name }}" class="mb-6">
|
<button (click)="getDetails(item.slug_url)" title="{{ item.name }}" class="mb-6 w-full">
|
||||||
<div class="card flex flex-col items-center border-black border-2 rounded-md p-4">
|
<div class="card flex flex-col items-center border-black border-2 rounded-md p-4 w-full">
|
||||||
<h1>{{ item.rus_name }}</h1>
|
<h1>{{ item.rus_name }}</h1>
|
||||||
<img [src]="item.cover.thumbnail" [alt]="item.slug" class="w-[200px] h-auto aspect-auto" />
|
<img [src]="item.cover.thumbnail" [alt]="item.slug" class="w-[200px] h-auto aspect-auto" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ export class HomeComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||||||
ngAfterViewInit(): void {
|
ngAfterViewInit(): void {
|
||||||
this.route.queryParams.subscribe((params) => {
|
this.route.queryParams.subscribe((params) => {
|
||||||
const search = params["search"];
|
const search = params["search"];
|
||||||
console.log(params);
|
|
||||||
if (search) {
|
if (search) {
|
||||||
this.searchService.search(search);
|
this.searchService.search(search);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,22 @@
|
|||||||
<h1>It's reader page</h1>
|
<div class="flex flex-row items-center justify-between me-4">
|
||||||
|
<button class="bg-slate-600 text-white rounded-lg p-3 m-4" (click)="backToTitle()">
|
||||||
|
Назад к тайтлу
|
||||||
|
</button>
|
||||||
|
<h3>{{ currentChapterInfo?.number }}. {{ currentChapterInfo?.name }}</h3>
|
||||||
|
</div>
|
||||||
<div class="flex flex-col items-center">
|
<div class="flex flex-col items-center">
|
||||||
@if(pages.length > 0){
|
@if (pages.length > 0 && cachedPages[currentPageIndex]) {
|
||||||
<img #mangaImage [alt]="cachedPages[currentPageIndex]?.slug" />
|
<div [class]="imageContainerClass">
|
||||||
<div class="flex items-center justify-center space-x-4 mb-10">
|
<app-scale-image [imageSrc]="imageUrl"></app-scale-image>
|
||||||
<button (click)="prevPage()" [disabled]="currentPageIndex === 0" class="p-3 text-white bg-slate-600 w-[100px] mt-5 rounded-lg">←</button>
|
</div>
|
||||||
<p>{{pages[currentPageIndex]?.slug}} / {{pages.length}}</p>
|
<div class="flex items-center justify-center space-x-4 my-10">
|
||||||
<button (click)="nextPage()" [disabled]="currentPageIndex === pages.length - 1" class="p-3 text-white bg-slate-600 w-[100px] mt-5 rounded-lg">→</button>
|
<button (click)="prevPage()" class="p-3 text-white bg-slate-600 w-[100px] rounded-lg">
|
||||||
</div>
|
←
|
||||||
}
|
</button>
|
||||||
</div>
|
<p>{{ pages[currentPageIndex].slug }} / {{ pages.length }}</p>
|
||||||
|
<button (click)="nextPage()" class="p-3 text-white bg-slate-600 w-[100px] rounded-lg">
|
||||||
|
→
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
:host {
|
||||||
|
overflow-y: auto;
|
||||||
|
height: 100%;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,22 +1,32 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule } from "@angular/common";
|
||||||
import { AfterViewInit, Component, ElementRef, ViewChild } from "@angular/core";
|
import { AfterViewInit, Component } from "@angular/core";
|
||||||
import { ActivatedRoute, Router } from "@angular/router";
|
import { ActivatedRoute, Router } from "@angular/router";
|
||||||
import { Observable, map } from "rxjs";
|
import { Observable, map } from "rxjs";
|
||||||
import { Page } from "../../services/parsers/rulib/rulib.chapter.dto";
|
import { Chapter, Page } from "../../services/parsers/rulib/rulib.chapter.dto";
|
||||||
|
import { IRulibChapter } from "../../services/parsers/rulib/rulib.chapters.dto";
|
||||||
import { SearchService } from "../../services/search.service";
|
import { SearchService } from "../../services/search.service";
|
||||||
|
import { ScaleImageComponent } from "../scale-image/scale-image.component";
|
||||||
|
import { CachedPages } from "./reader.dto";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-reader",
|
selector: "app-reader",
|
||||||
templateUrl: "./reader.component.html",
|
templateUrl: "./reader.component.html",
|
||||||
styleUrls: ["./reader.component.less"],
|
styleUrls: ["./reader.component.less"],
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [CommonModule],
|
imports: [CommonModule, ScaleImageComponent],
|
||||||
})
|
})
|
||||||
export class ReaderComponent implements AfterViewInit {
|
export class ReaderComponent implements AfterViewInit {
|
||||||
pages: Page[] = [];
|
pages: Page[] = [];
|
||||||
currentPageIndex = 0;
|
currentPageIndex = 0;
|
||||||
cachedPages: { [key: number]: Page & { imageData?: Uint8Array } } = {};
|
cachedPages: CachedPages = {};
|
||||||
@ViewChild('mangaImage') mangaImage!: ElementRef<HTMLImageElement>;
|
imageUrl: string = "";
|
||||||
|
isManhwa = false;
|
||||||
|
currentChapterInfo: Chapter | null = null;
|
||||||
|
private chaptersInfo: IRulibChapter[] = [];
|
||||||
|
private chapterNum: number = 0;
|
||||||
|
private chapterVol: number = 0;
|
||||||
|
private url = "";
|
||||||
|
private fromTowards = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
@@ -29,18 +39,35 @@ export class ReaderComponent implements AfterViewInit {
|
|||||||
const url = params["url"];
|
const url = params["url"];
|
||||||
const chapter = params["chapter"];
|
const chapter = params["chapter"];
|
||||||
const volume = params["volume"];
|
const volume = params["volume"];
|
||||||
|
const fromTowards = params["from_towards"];
|
||||||
if (url && chapter && volume) {
|
if (url && chapter && volume) {
|
||||||
|
if (fromTowards) this.fromTowards = Boolean(+fromTowards);
|
||||||
|
else this.fromTowards = false;
|
||||||
|
this.chapterNum = +chapter;
|
||||||
|
this.chapterVol = +volume;
|
||||||
|
this.url = url;
|
||||||
this.loadChapter(url, chapter, volume);
|
this.loadChapter(url, chapter, volume);
|
||||||
|
this.searchService.getChapters(url).subscribe((data) => {
|
||||||
|
this.chaptersInfo = data.data;
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.router.navigate(["/"]);
|
this.router.navigate(["/"]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
backToTitle() {
|
||||||
|
this.router.navigate(["/", "detail"], { queryParams: { url: this.url } });
|
||||||
|
}
|
||||||
|
|
||||||
loadChapter(url: string, chapter: string, volume: string) {
|
loadChapter(url: string, chapter: string, volume: string) {
|
||||||
this.searchService.getChapter(url, chapter, volume).subscribe((data) => {
|
this.searchService.getChapter(url, chapter, volume).subscribe((data) => {
|
||||||
|
this.currentChapterInfo = data.data;
|
||||||
this.pages = data.data.pages;
|
this.pages = data.data.pages;
|
||||||
this.loadPage(0); // Загрузить первую страницу при открытии главы
|
if (this.fromTowards) {
|
||||||
|
this.currentPageIndex = this.pages.length - 1;
|
||||||
|
this.loadPage(this.pages.length - 1); // Загрузить последнюю страницу при открытии главы
|
||||||
|
} else this.loadPage(0); // Загрузить первую страницу при открытии главы
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,15 +76,55 @@ export class ReaderComponent implements AfterViewInit {
|
|||||||
this.currentPageIndex = index;
|
this.currentPageIndex = index;
|
||||||
this.cachePage(index); // Кэшируем текущую и соседние страницы
|
this.cachePage(index); // Кэшируем текущую и соседние страницы
|
||||||
this.unloadCachedPages(index); // Сгружаем ненужные страницы из кэша
|
this.unloadCachedPages(index); // Сгружаем ненужные страницы из кэша
|
||||||
|
const container = document.querySelector("app-reader");
|
||||||
|
if (container) {
|
||||||
|
container.scrollTo({
|
||||||
|
top: 0,
|
||||||
|
behavior: "smooth",
|
||||||
|
});
|
||||||
|
}
|
||||||
if (!this.cachedPages[index]?.imageData) {
|
if (!this.cachedPages[index]?.imageData) {
|
||||||
// Если страница не закэширована, загружаем её
|
// Если страница не закэширована, загружаем её
|
||||||
this.fetchAndCachePage(index).subscribe(() => {
|
this.fetchAndCachePage(index).subscribe(() => {
|
||||||
this.updateImage();
|
this.updateImage();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Если страница уже в кэше, просто обновляем изображение
|
// Если страница уже в кэше, просто обновляем изображение
|
||||||
this.updateImage();
|
this.updateImage();
|
||||||
}
|
}
|
||||||
|
} else if (index == this.pages.length) {
|
||||||
|
const thisChapterIndex = this.chaptersInfo.findIndex((chapter) => {
|
||||||
|
return +chapter.number === this.chapterNum && +chapter.volume === this.chapterVol;
|
||||||
|
});
|
||||||
|
const nextChapterIndex = Math.min(thisChapterIndex + 1, this.chaptersInfo.length - 1);
|
||||||
|
const nextChapter = this.chaptersInfo[nextChapterIndex];
|
||||||
|
if (nextChapter !== this.chaptersInfo[thisChapterIndex]) {
|
||||||
|
this.cachedPages = [];
|
||||||
|
this.router.navigate(["/", "reader"], {
|
||||||
|
queryParams: {
|
||||||
|
url: this.url,
|
||||||
|
chapter: nextChapter.number,
|
||||||
|
volume: nextChapter.volume,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (index == -1) {
|
||||||
|
const thisChapterIndex = this.chaptersInfo.findIndex((chapter) => {
|
||||||
|
return +chapter.number === this.chapterNum && +chapter.volume === this.chapterVol;
|
||||||
|
});
|
||||||
|
const prevChapterIndex = Math.max(thisChapterIndex - 1, 0);
|
||||||
|
const prevChapter = this.chaptersInfo[prevChapterIndex];
|
||||||
|
if (prevChapter !== this.chaptersInfo[thisChapterIndex]) {
|
||||||
|
this.cachedPages = [];
|
||||||
|
this.router.navigate(["/", "reader"], {
|
||||||
|
queryParams: {
|
||||||
|
url: this.url,
|
||||||
|
chapter: prevChapter.number,
|
||||||
|
volume: prevChapter.volume,
|
||||||
|
from_towards: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,14 +132,14 @@ export class ReaderComponent implements AfterViewInit {
|
|||||||
private cachePage(index: number) {
|
private cachePage(index: number) {
|
||||||
const startIndex = Math.max(0, index - 2);
|
const startIndex = Math.max(0, index - 2);
|
||||||
const endIndex = Math.min(this.pages.length - 1, index + 2);
|
const endIndex = Math.min(this.pages.length - 1, index + 2);
|
||||||
|
|
||||||
for (let i = startIndex; i <= endIndex; i++) {
|
for (let i = startIndex; i <= endIndex; i++) {
|
||||||
if (!this.isPageCached(i)) {
|
if (!this.isPageCached(i)) {
|
||||||
this.fetchAndCachePage(i).subscribe(() => {
|
this.fetchAndCachePage(i).subscribe(() => {
|
||||||
if (i === this.currentPageIndex) {
|
if (i === this.currentPageIndex) {
|
||||||
this.updateImage();
|
this.updateImage();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,19 +153,19 @@ export class ReaderComponent implements AfterViewInit {
|
|||||||
return this.searchService
|
return this.searchService
|
||||||
.getImageData(this.searchService.getImageServer() + this.pages[index].url)
|
.getImageData(this.searchService.getImageServer() + this.pages[index].url)
|
||||||
.pipe(
|
.pipe(
|
||||||
map((imageData) => {
|
map((imageData) => {
|
||||||
this.cachedPages[index] = {
|
this.cachedPages[index] = {
|
||||||
...this.pages[index],
|
...this.pages[index],
|
||||||
imageData,
|
imageData,
|
||||||
};
|
};
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Выгрузка из кэша старых страниц
|
// Выгрузка из кэша старых страниц
|
||||||
private unloadCachedPages(index: number) {
|
private unloadCachedPages(index: number) {
|
||||||
for (const key in this.cachedPages) {
|
for (const key in this.cachedPages) {
|
||||||
const pageIndex = parseInt(key, 10);
|
const pageIndex = +key;
|
||||||
if (index - pageIndex > 2) {
|
if (index - pageIndex > 2) {
|
||||||
delete this.cachedPages[pageIndex];
|
delete this.cachedPages[pageIndex];
|
||||||
}
|
}
|
||||||
@@ -108,13 +175,20 @@ export class ReaderComponent implements AfterViewInit {
|
|||||||
// Обновляем изображение на странице
|
// Обновляем изображение на странице
|
||||||
private updateImage() {
|
private updateImage() {
|
||||||
const currentPage = this.cachedPages[this.currentPageIndex];
|
const currentPage = this.cachedPages[this.currentPageIndex];
|
||||||
if (this.mangaImage?.nativeElement && currentPage?.imageData) {
|
if (currentPage && currentPage.imageData) {
|
||||||
const blob = new Blob([currentPage.imageData], { type: 'image/jpeg' });
|
const blob = new Blob([currentPage.imageData], { type: "image/jpeg" });
|
||||||
const urlCreator = window.URL || window.webkitURL;
|
const urlCreator = window.URL || window.webkitURL;
|
||||||
this.mangaImage.nativeElement.src = urlCreator.createObjectURL(blob);
|
this.imageUrl = urlCreator.createObjectURL(blob);
|
||||||
|
const imageUrl = this.imageUrl;
|
||||||
|
const image = new Image();
|
||||||
|
image.onload = () => {
|
||||||
|
this.isManhwa = image.naturalHeight / image.naturalWidth >= 5;
|
||||||
|
URL.revokeObjectURL(imageUrl);
|
||||||
|
};
|
||||||
|
image.src = imageUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nextPage() {
|
nextPage() {
|
||||||
this.loadPage(this.currentPageIndex + 1);
|
this.loadPage(this.currentPageIndex + 1);
|
||||||
}
|
}
|
||||||
@@ -122,4 +196,8 @@ export class ReaderComponent implements AfterViewInit {
|
|||||||
prevPage() {
|
prevPage() {
|
||||||
this.loadPage(this.currentPageIndex - 1);
|
this.loadPage(this.currentPageIndex - 1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
get imageContainerClass() {
|
||||||
|
return `${this.isManhwa ? "h-auto" : "h-[70vh]"} w-[95vw] md:w-[700px] md:h-auto`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
9
apps/NwaifuAnime/src/app/components/reader/reader.dto.ts
Normal file
9
apps/NwaifuAnime/src/app/components/reader/reader.dto.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Page } from "../../services/parsers/rulib/rulib.chapter.dto";
|
||||||
|
|
||||||
|
interface CachedPage extends Page {
|
||||||
|
imageData?: Uint8Array;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CachedPages {
|
||||||
|
[key: number]: CachedPage;
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<div class="image-container" #container>
|
||||||
|
<img #image [src]="imageSrc" (load)="onImageLoad()" alt="Manga page" />
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
.image-container {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
img {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import { AfterViewInit, Component, ElementRef, Input, OnDestroy, ViewChild } from "@angular/core";
|
||||||
|
import { Subscription, debounceTime, fromEvent } from "rxjs";
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: "app-scale-image",
|
||||||
|
templateUrl: "./scale-image.component.html",
|
||||||
|
styleUrls: ["./scale-image.component.less"],
|
||||||
|
standalone: true,
|
||||||
|
})
|
||||||
|
export class ScaleImageComponent implements AfterViewInit, OnDestroy {
|
||||||
|
@Input({ required: true }) imageSrc: string = "";
|
||||||
|
@ViewChild("container", { static: true }) containerRef: ElementRef | null = null;
|
||||||
|
@ViewChild("image", { static: true }) imageRef: ElementRef | null = null;
|
||||||
|
|
||||||
|
private resizeSubscription: Subscription = new Subscription();
|
||||||
|
|
||||||
|
ngAfterViewInit(): void {
|
||||||
|
this.setupResizeListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
if (this.resizeSubscription) this.resizeSubscription.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
onImageLoad() {
|
||||||
|
this.scaleImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private setupResizeListener() {
|
||||||
|
this.resizeSubscription = fromEvent(window, "resize")
|
||||||
|
.pipe(debounceTime(200))
|
||||||
|
.subscribe(() => this.scaleImage());
|
||||||
|
}
|
||||||
|
|
||||||
|
private scaleImage() {
|
||||||
|
if (this.containerRef && this.imageRef) {
|
||||||
|
const container = this.containerRef.nativeElement;
|
||||||
|
const img = this.imageRef.nativeElement;
|
||||||
|
|
||||||
|
const containerWidth = container.clientWidth;
|
||||||
|
const containerHeight = container.clientHeight;
|
||||||
|
const imgRatio = img.naturalWidth / img.naturalHeight;
|
||||||
|
const containerRatio = containerWidth / containerHeight;
|
||||||
|
|
||||||
|
let newWidth, newHeight;
|
||||||
|
|
||||||
|
if (imgRatio > containerRatio) {
|
||||||
|
newWidth = containerWidth;
|
||||||
|
newHeight = containerWidth / imgRatio;
|
||||||
|
} else {
|
||||||
|
newHeight = containerHeight;
|
||||||
|
newWidth = containerHeight * imgRatio;
|
||||||
|
}
|
||||||
|
|
||||||
|
newWidth = Math.min(newWidth, img.naturalWidth);
|
||||||
|
newHeight = Math.min(newHeight, img.naturalHeight);
|
||||||
|
|
||||||
|
if (img.naturalHeight / img.naturalWidth >= 5) {
|
||||||
|
img.style.width = "100%";
|
||||||
|
img.style.height = "auto";
|
||||||
|
} else {
|
||||||
|
img.style.width = `${newWidth}px`;
|
||||||
|
img.style.height = `${newHeight}px`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
@tailwind base;
|
@tailwind base;
|
||||||
@tailwind components;
|
@tailwind components;
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
body {
|
||||||
|
overflow-y: hidden;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user