Compare commits
38 Commits
4d09e6ee11
...
feature/ma
| Author | SHA1 | Date | |
|---|---|---|---|
| 55e729422b | |||
| 2660aef473 | |||
| 7eff09765b | |||
| 37149c83c4 | |||
| c7d76419f7 | |||
| 6ddb3bad29 | |||
| 16a6a05d89 | |||
| f1cbd9267c | |||
| 1929760e82 | |||
| 167e5c4f65 | |||
| 40c9ca38b9 | |||
| 6bb99f6e0e | |||
| 53fee00315 | |||
| c508caab7b | |||
| e90a1bb6ec | |||
| 27f023964f | |||
| b43c8db305 | |||
| e3fc28e440 | |||
| c9638403ab | |||
| 02ae9c6745 | |||
| c8cb378123 | |||
| 47060bcb2d | |||
| fb3acd5182 | |||
| cb1d7e24b7 | |||
| 0d6a56c9a3 | |||
| 7cc5cbaac3 | |||
| cf6128c248 | |||
| 1fd6dd632e | |||
| e291379602 | |||
| 1237ee4439 | |||
| 935d1f5dd9 | |||
| 2a31e85e50 | |||
| c4665737dc | |||
| e3dac5bc83 | |||
| 90582949d5 | |||
| a9436a5af7 | |||
| 8cd5dd1f8e | |||
| f9a7b812fe |
@@ -1,13 +1,9 @@
|
||||
{
|
||||
"root": true,
|
||||
"ignorePatterns": [
|
||||
"projects/**/*"
|
||||
],
|
||||
"ignorePatterns": ["**/*"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"*.ts"
|
||||
],
|
||||
"files": ["*.ts"],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
@@ -34,14 +30,31 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": [
|
||||
"*.html"
|
||||
],
|
||||
"files": ["*.html"],
|
||||
"extends": [
|
||||
"plugin:@angular-eslint/template/recommended",
|
||||
"plugin:@angular-eslint/template/accessibility"
|
||||
],
|
||||
"rules": {}
|
||||
},
|
||||
{
|
||||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
||||
"rules": {
|
||||
"@nx/enforce-module-boundaries": [
|
||||
"error",
|
||||
{
|
||||
"enforceBuildableLibDependency": true,
|
||||
"allow": [],
|
||||
"depConstraints": [
|
||||
{
|
||||
"sourceTag": "*",
|
||||
"onlyDependOnLibsWithTags": ["*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"plugins": ["@nx"]
|
||||
}
|
||||
|
||||
8
.gitignore
vendored
@@ -40,3 +40,11 @@ testem.log
|
||||
# System files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
|
||||
.nx/cache
|
||||
.nx/workspace-data
|
||||
|
||||
# env
|
||||
*.env*
|
||||
!*.env.example
|
||||
|
||||
5
.prettierignore
Normal file
@@ -0,0 +1,5 @@
|
||||
# Add files here to ignore them from prettier formatting
|
||||
/dist
|
||||
/coverage
|
||||
/.nx/cache
|
||||
/.nx/workspace-data
|
||||
8
.vscode/extensions.json
vendored
@@ -1,4 +1,8 @@
|
||||
{
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
|
||||
"recommendations": ["angular.ng-template"]
|
||||
"recommendations": [
|
||||
"angular.ng-template",
|
||||
"nrwl.angular-console",
|
||||
"dbaeumer.vscode-eslint",
|
||||
"esbenp.prettier-vscode"
|
||||
]
|
||||
}
|
||||
|
||||
7
.vscode/settings.json
vendored
@@ -6,7 +6,8 @@
|
||||
"**/CVS": true,
|
||||
"**/.DS_Store": true,
|
||||
"**/Thumbs.db": true,
|
||||
"**/node_modules": true,
|
||||
"**/.angular": true,
|
||||
}
|
||||
// "**/node_modules": true,
|
||||
"**/.angular": true
|
||||
},
|
||||
"editor.formatOnSave": true
|
||||
}
|
||||
24
README.md
@@ -2,26 +2,6 @@
|
||||
|
||||
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 17.2.2.
|
||||
|
||||
## Development server
|
||||
## Visitor counter
|
||||
|
||||
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files.
|
||||
|
||||
## Code scaffolding
|
||||
|
||||
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
|
||||
|
||||
## Build
|
||||
|
||||
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.
|
||||
|
||||
## Running unit tests
|
||||
|
||||
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
||||
|
||||
## Running end-to-end tests
|
||||
|
||||
Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.
|
||||
|
||||
## Further help
|
||||
|
||||
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|
||||

|
||||
|
||||
116
angular.json
@@ -1,116 +0,0 @@
|
||||
{
|
||||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||
"version": 1,
|
||||
"cli": {
|
||||
"packageManager": "pnpm",
|
||||
"schematicCollections": [
|
||||
"@angular-eslint/schematics"
|
||||
]
|
||||
},
|
||||
"newProjectRoot": "projects",
|
||||
"projects": {
|
||||
"NwaifuWeb": {
|
||||
"projectType": "application",
|
||||
"schematics": {
|
||||
"@schematics/angular:component": {
|
||||
"style": "less"
|
||||
}
|
||||
},
|
||||
"root": "",
|
||||
"sourceRoot": "src",
|
||||
"prefix": "app",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-angular:application",
|
||||
"options": {
|
||||
"outputPath": "dist/nwaifu-web",
|
||||
"index": "src/index.html",
|
||||
"browser": "src/main.ts",
|
||||
"polyfills": [
|
||||
"zone.js"
|
||||
],
|
||||
"tsConfig": "tsconfig.app.json",
|
||||
"inlineStyleLanguage": "less",
|
||||
"assets": [
|
||||
"src/favicon.ico",
|
||||
"src/assets"
|
||||
],
|
||||
"styles": [
|
||||
"src/styles.less"
|
||||
],
|
||||
"scripts": []
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "500kb",
|
||||
"maximumError": "1mb"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "2kb",
|
||||
"maximumError": "4kb"
|
||||
}
|
||||
],
|
||||
"outputHashing": "all"
|
||||
},
|
||||
"development": {
|
||||
"optimization": false,
|
||||
"extractLicenses": false,
|
||||
"sourceMap": true
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "production"
|
||||
},
|
||||
"serve": {
|
||||
"builder": "@angular-devkit/build-angular:dev-server",
|
||||
"configurations": {
|
||||
"production": {
|
||||
"buildTarget": "NwaifuWeb:build:production"
|
||||
},
|
||||
"development": {
|
||||
"buildTarget": "NwaifuWeb:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development"
|
||||
},
|
||||
"extract-i18n": {
|
||||
"builder": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"buildTarget": "NwaifuWeb:build"
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"builder": "@angular-devkit/build-angular:karma",
|
||||
"options": {
|
||||
"polyfills": [
|
||||
"zone.js",
|
||||
"zone.js/testing"
|
||||
],
|
||||
"tsConfig": "tsconfig.spec.json",
|
||||
"inlineStyleLanguage": "less",
|
||||
"assets": [
|
||||
"src/favicon.ico",
|
||||
"src/assets"
|
||||
],
|
||||
"styles": [
|
||||
"src/styles.less"
|
||||
],
|
||||
"scripts": []
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"builder": "@angular-eslint/builder:lint",
|
||||
"options": {
|
||||
"lintFilePatterns": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.html"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
apps/NwaifuAnime/.eslintrc.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"extends": ["../../.eslintrc.json"],
|
||||
"ignorePatterns": ["!**/*"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.ts"],
|
||||
"extends": ["plugin:@nx/angular", "plugin:@angular-eslint/template/process-inline-templates"],
|
||||
"rules": {
|
||||
"@angular-eslint/directive-selector": [
|
||||
"error",
|
||||
{
|
||||
"type": "attribute",
|
||||
"prefix": "app",
|
||||
"style": "camelCase"
|
||||
}
|
||||
],
|
||||
"@angular-eslint/component-selector": [
|
||||
"error",
|
||||
{
|
||||
"type": "element",
|
||||
"prefix": "app",
|
||||
"style": "kebab-case"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["*.html"],
|
||||
"extends": ["plugin:@nx/angular-template"],
|
||||
"rules": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
29
apps/NwaifuAnime/ngsw-config.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"$schema": "../../node_modules/@angular/service-worker/config/schema.json",
|
||||
"index": "/index.html",
|
||||
"assetGroups": [
|
||||
{
|
||||
"name": "app",
|
||||
"installMode": "prefetch",
|
||||
"resources": {
|
||||
"files": [
|
||||
"/favicon.ico",
|
||||
"/index.html",
|
||||
"/manifest.webmanifest",
|
||||
"/*.css",
|
||||
"/*.js"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "assets",
|
||||
"installMode": "lazy",
|
||||
"updateMode": "prefetch",
|
||||
"resources": {
|
||||
"files": [
|
||||
"/**/*.(svg|cur|jpg|jpeg|png|apng|webp|avif|gif|otf|ttf|woff|woff2)"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
75
apps/NwaifuAnime/project.json
Normal file
@@ -0,0 +1,75 @@
|
||||
{
|
||||
"name": "NwaifuAnime",
|
||||
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
||||
"projectType": "application",
|
||||
"prefix": "app",
|
||||
"sourceRoot": "apps/NwaifuAnime/src",
|
||||
"tags": [],
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@angular-devkit/build-angular:application",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"options": {
|
||||
"outputPath": "dist/apps/NwaifuAnime",
|
||||
"index": "apps/NwaifuAnime/src/index.html",
|
||||
"browser": "apps/NwaifuAnime/src/main.ts",
|
||||
"polyfills": ["zone.js"],
|
||||
"tsConfig": "apps/NwaifuAnime/tsconfig.app.json",
|
||||
"inlineStyleLanguage": "less",
|
||||
"assets": [
|
||||
{
|
||||
"glob": "**/*",
|
||||
"input": "apps/NwaifuAnime/public"
|
||||
}
|
||||
],
|
||||
"styles": ["apps/NwaifuAnime/src/styles.less"],
|
||||
"scripts": []
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "500kb",
|
||||
"maximumError": "1mb"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "2kb",
|
||||
"maximumError": "4kb"
|
||||
}
|
||||
],
|
||||
"outputHashing": "all",
|
||||
"serviceWorker": "apps/NwaifuAnime/ngsw-config.json"
|
||||
},
|
||||
"development": {
|
||||
"optimization": false,
|
||||
"extractLicenses": false,
|
||||
"sourceMap": true
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "production"
|
||||
},
|
||||
"serve": {
|
||||
"executor": "@angular-devkit/build-angular:dev-server",
|
||||
"configurations": {
|
||||
"production": {
|
||||
"buildTarget": "NwaifuAnime:build:production"
|
||||
},
|
||||
"development": {
|
||||
"buildTarget": "NwaifuAnime:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development"
|
||||
},
|
||||
"extract-i18n": {
|
||||
"executor": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"buildTarget": "NwaifuAnime:build"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nx/eslint:lint"
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
apps/NwaifuAnime/public/favicon.ico
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
apps/NwaifuAnime/public/icons/icon-128x128.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
apps/NwaifuAnime/public/icons/icon-144x144.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
apps/NwaifuAnime/public/icons/icon-152x152.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
apps/NwaifuAnime/public/icons/icon-192x192.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
apps/NwaifuAnime/public/icons/icon-384x384.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
apps/NwaifuAnime/public/icons/icon-512x512.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
apps/NwaifuAnime/public/icons/icon-72x72.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
apps/NwaifuAnime/public/icons/icon-96x96.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
59
apps/NwaifuAnime/public/manifest.webmanifest
Normal file
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"name": "NwaifuAnime",
|
||||
"short_name": "NwaifuAnime",
|
||||
"theme_color": "#1976d2",
|
||||
"background_color": "#fafafa",
|
||||
"display": "standalone",
|
||||
"scope": "./",
|
||||
"start_url": "./",
|
||||
"icons": [
|
||||
{
|
||||
"src": "icons/icon-72x72.png",
|
||||
"sizes": "72x72",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-96x96.png",
|
||||
"sizes": "96x96",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-128x128.png",
|
||||
"sizes": "128x128",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-144x144.png",
|
||||
"sizes": "144x144",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-152x152.png",
|
||||
"sizes": "152x152",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-384x384.png",
|
||||
"sizes": "384x384",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-512x512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
}
|
||||
]
|
||||
}
|
||||
11
apps/NwaifuAnime/src/app/app.component.html
Normal file
@@ -0,0 +1,11 @@
|
||||
@if (serviceWorkerEnabled) {
|
||||
@if (hasUpdate) {
|
||||
<h1>Update available</h1>
|
||||
<button (click)="update()">Update</button>
|
||||
} @else {
|
||||
<h1>Update not available</h1>
|
||||
}
|
||||
}
|
||||
<app-header></app-header>
|
||||
<div class="h-10"></div>
|
||||
<router-outlet></router-outlet>
|
||||
0
apps/NwaifuAnime/src/app/app.component.less
Normal file
31
apps/NwaifuAnime/src/app/app.component.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Component } from "@angular/core";
|
||||
import { RouterModule } from "@angular/router";
|
||||
import { AppService } from "./app.service";
|
||||
import { HeaderComponent } from "./components/header/header.component";
|
||||
import { Datum } from "./services/parsers/rulib/rulib.search.dto";
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [RouterModule, HeaderComponent],
|
||||
selector: "app-root",
|
||||
templateUrl: "./app.component.html",
|
||||
styleUrl: "./app.component.less",
|
||||
providers: [AppService],
|
||||
})
|
||||
export class AppComponent {
|
||||
title = "NwaifuAnime";
|
||||
items: Datum[] = [];
|
||||
constructor(private sw: AppService) {}
|
||||
|
||||
get hasUpdate() {
|
||||
return this.sw.isUpdateAvailable;
|
||||
}
|
||||
|
||||
update() {
|
||||
this.sw.update();
|
||||
}
|
||||
|
||||
get serviceWorkerEnabled() {
|
||||
return this.sw.serviceWorkerEnabled;
|
||||
}
|
||||
}
|
||||
17
apps/NwaifuAnime/src/app/app.config.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { provideHttpClient } from "@angular/common/http";
|
||||
import { ApplicationConfig, isDevMode, provideZoneChangeDetection } from "@angular/core";
|
||||
import { provideRouter } from "@angular/router";
|
||||
import { provideServiceWorker } from "@angular/service-worker";
|
||||
import { appRoutes } from "./app.routes";
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideZoneChangeDetection({ eventCoalescing: true }),
|
||||
provideRouter(appRoutes),
|
||||
provideServiceWorker("ngsw-worker.js", {
|
||||
enabled: !isDevMode(),
|
||||
registrationStrategy: "registerWhenStable:30000",
|
||||
}),
|
||||
provideHttpClient(),
|
||||
],
|
||||
};
|
||||
13
apps/NwaifuAnime/src/app/app.routes.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Route } from "@angular/router";
|
||||
import { DetailComponent } from "./components/detail/detail.component";
|
||||
import { HomeComponent } from "./components/home/home.component";
|
||||
import { ReaderComponent } from "./components/reader/reader.component";
|
||||
|
||||
export const appRoutes: Route[] = [
|
||||
{
|
||||
path: "",
|
||||
component: HomeComponent,
|
||||
},
|
||||
{ path: "detail", component: DetailComponent },
|
||||
{ path: "reader", component: ReaderComponent },
|
||||
];
|
||||
40
apps/NwaifuAnime/src/app/app.service.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { SwUpdate } from "@angular/service-worker";
|
||||
|
||||
@Injectable({ providedIn: "root" })
|
||||
export class AppService {
|
||||
private hasUpdate = false;
|
||||
constructor(private sw: SwUpdate) {
|
||||
if (this.sw.isEnabled) {
|
||||
console.log("service init");
|
||||
this.sw.checkForUpdate();
|
||||
|
||||
this.sw.versionUpdates.subscribe((ev) => {
|
||||
if (ev.type == "VERSION_DETECTED") {
|
||||
console.log("update detected");
|
||||
this.hasUpdate = true;
|
||||
} else {
|
||||
console.log("no update");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
get isUpdateAvailable() {
|
||||
return this.hasUpdate;
|
||||
}
|
||||
|
||||
get serviceWorkerEnabled() {
|
||||
return this.sw.isEnabled;
|
||||
}
|
||||
|
||||
update() {
|
||||
this.sw.activateUpdate().then((res) => {
|
||||
if (res) {
|
||||
console.log("updated");
|
||||
this.hasUpdate = false;
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<div class="flex flex-col items-center">
|
||||
@if (detail_item) {
|
||||
<h1>{{ detail_item.name }}</h1>
|
||||
<h2>{{ detail_item.rus_name }}</h2>
|
||||
<img [src]="detail_item.cover.default" [alt]="detail_item.slug" />
|
||||
@for (chapter of chapters.data; track $index) {
|
||||
<h3>
|
||||
<strong>{{ chapter.number }}.</strong> {{ chapter.name || "Нет названия" }}
|
||||
</h3>
|
||||
}
|
||||
<button class="p-3 text-white bg-slate-600 w-[400px] mt-5 rounded-lg" (click)="goToReader()">
|
||||
Читать
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,54 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { AfterViewInit, Component } from "@angular/core";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { IRulibChaptersResult } from "../../services/parsers/rulib/rulib.chapters.dto";
|
||||
import { Data } from "../../services/parsers/rulib/rulib.detail.dto";
|
||||
import { SearchService } from "../../services/search.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-detail",
|
||||
templateUrl: "./detail.component.html",
|
||||
styleUrls: ["./detail.component.less"],
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
})
|
||||
export class DetailComponent implements AfterViewInit {
|
||||
detail_item: Data | null = null;
|
||||
chapters: IRulibChaptersResult = { data: [] };
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private searchService: SearchService,
|
||||
private router: Router,
|
||||
) {}
|
||||
|
||||
private getDetails(url: string) {
|
||||
this.searchService.getDetails(url).subscribe((data) => {
|
||||
this.detail_item = data.data;
|
||||
});
|
||||
this.searchService.getChapters(url).subscribe((data) => {
|
||||
this.chapters = data;
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.route.queryParams.subscribe((params) => {
|
||||
const url = params["url"];
|
||||
if (url) {
|
||||
this.getDetails(url);
|
||||
} else {
|
||||
this.router.navigate(["/"]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
goToReader() {
|
||||
//TODO: Not only first chapter
|
||||
this.router.navigate(["/", "reader"], {
|
||||
queryParams: {
|
||||
url: this.detail_item?.slug_url,
|
||||
chapter: this.chapters.data[0].number,
|
||||
volume: this.chapters.data[0].volume,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<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"
|
||||
>
|
||||
<div class="flex justify-between flex-row w-full align-middle">
|
||||
<a href="/"><h1 class="text-white" title="Main page">NwaifuAnime</h1></a>
|
||||
<!-- Search bar on small screens -->
|
||||
<button type="button" class="md:hidden" (click)="changeMenu()">
|
||||
<i [class]="menuBtnClass"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Search bar on big screens -->
|
||||
<div [class]="searchBarClass">
|
||||
<input
|
||||
type="search"
|
||||
#searchInput
|
||||
class="outline-none ps-1 text-sm leading-6 w-full border-0 bg-transparent border-r border-gray-700"
|
||||
(keydown.enter)="search()"
|
||||
/>
|
||||
<button class="align-middle w-[100px] text-center" type="submit" (click)="search()">
|
||||
<span class="text-sm text-black h-full">Поиск</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
.header {
|
||||
transition: height 0.3s;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { AfterViewInit, Component, ElementRef, ViewChild } from "@angular/core";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
|
||||
@Component({
|
||||
selector: "app-header",
|
||||
templateUrl: "./header.component.html",
|
||||
styleUrls: ["./header.component.less"],
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
})
|
||||
export class HeaderComponent implements AfterViewInit {
|
||||
@ViewChild("searchInput") searchInput: ElementRef<HTMLInputElement> | null = null;
|
||||
menuOpened = false;
|
||||
constructor(
|
||||
private router: Router,
|
||||
private route: ActivatedRoute,
|
||||
) {}
|
||||
changeMenu() {
|
||||
this.menuOpened = !this.menuOpened;
|
||||
}
|
||||
|
||||
get menuBtnClass(): string {
|
||||
return `lni ${this.menuOpened ? "lni-close" : "lni-menu"} text-white`;
|
||||
}
|
||||
|
||||
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"}`;
|
||||
}
|
||||
|
||||
search() {
|
||||
if (this.searchInput) {
|
||||
const text = this.searchInput.nativeElement.value;
|
||||
this.router.navigateByUrl(`/?search=${text}`);
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.route.queryParams.subscribe((params) => {
|
||||
const search = params["search"];
|
||||
if (search && this.searchInput) {
|
||||
this.searchInput.nativeElement.value = search;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
11
apps/NwaifuAnime/src/app/components/home/home.component.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<h1>It's home component</h1>
|
||||
<div class="flex flex-col items-center">
|
||||
@for (item of items; track $index) {
|
||||
<button (click)="getDetails(item.slug_url)" title="{{ item.name }}" class="mb-6">
|
||||
<div class="card flex flex-col items-center border-black border-2 rounded-md p-4">
|
||||
<h1>{{ item.rus_name }}</h1>
|
||||
<img [src]="item.cover.thumbnail" [alt]="item.slug" class="w-[200px] h-auto aspect-auto" />
|
||||
</div>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
48
apps/NwaifuAnime/src/app/components/home/home.component.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { AfterViewInit, Component, Input, OnDestroy, OnInit } from "@angular/core";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { Subscription } from "rxjs";
|
||||
import { Datum } from "../../services/parsers/rulib/rulib.search.dto";
|
||||
import { SearchService } from "../../services/search.service";
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
selector: "app-home",
|
||||
templateUrl: "./home.component.html",
|
||||
styleUrls: ["./home.component.less"],
|
||||
imports: [CommonModule],
|
||||
})
|
||||
export class HomeComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
@Input() items: Datum[] = [];
|
||||
private subscription: Subscription = new Subscription();
|
||||
|
||||
constructor(
|
||||
private searchService: SearchService,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.subscription = this.searchService.currentItemsTerm.subscribe((data) => {
|
||||
this.items = data;
|
||||
});
|
||||
}
|
||||
|
||||
getDetails(slug_url: string) {
|
||||
this.router.navigate(["/", "detail"], { queryParams: { url: slug_url } });
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.subscription.unsubscribe();
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.route.queryParams.subscribe((params) => {
|
||||
const search = params["search"];
|
||||
console.log(params);
|
||||
if (search) {
|
||||
this.searchService.search(search);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<h1>It's reader page</h1>
|
||||
<div class="flex flex-col items-center">
|
||||
@for (page of pages; track $index) {
|
||||
<img [src]="page.url" [alt]="page.slug" />
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,38 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { AfterViewInit, Component } from "@angular/core";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { Page } from "../../services/parsers/rulib/rulib.chapter.dto";
|
||||
import { SearchService } from "../../services/search.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-reader",
|
||||
templateUrl: "./reader.component.html",
|
||||
styleUrls: ["./reader.component.less"],
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
})
|
||||
export class ReaderComponent implements AfterViewInit {
|
||||
pages: Page[] = [];
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private searchService: SearchService,
|
||||
) {}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.route.queryParams.subscribe((params) => {
|
||||
const url = params["url"];
|
||||
const chapter = params["chapter"];
|
||||
const volume = params["volume"];
|
||||
if (url && chapter && volume) {
|
||||
this.searchService.getChapter(url, chapter, volume).subscribe((data) => {
|
||||
this.pages = data.data.pages.map((page) => {
|
||||
return { ...page, url: this.searchService.getImageServer() + page.url };
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.router.navigate(["/"]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import { Injectable } from "@angular/core";
|
||||
import { Observable, catchError, map, throwError } from "rxjs";
|
||||
import { ESiteUrls } from "../urls";
|
||||
import { IRulibChapterResult } from "./rulib.chapter.dto";
|
||||
import { IRulibChaptersResult } from "./rulib.chapters.dto";
|
||||
import { IRulibDetailResult } from "./rulib.detail.dto";
|
||||
import { IRulibSearchResult } from "./rulib.search.dto";
|
||||
|
||||
//TODO: Make abstract classes
|
||||
@Injectable({
|
||||
providedIn: "root",
|
||||
})
|
||||
export class LibSocialParserService {
|
||||
private readonly url = ESiteUrls.LIB_SOCIAL;
|
||||
constructor(private readonly http: HttpClient) {}
|
||||
|
||||
get imageServer() {
|
||||
return "https://img33.imgslib.link";
|
||||
}
|
||||
|
||||
searchManga(query: string): Observable<IRulibSearchResult> {
|
||||
return this.http
|
||||
.get(`${this.url}/api/manga?fields[]=rate_avg&fields[]=rate&q=${query}&site_id[]=1`)
|
||||
.pipe(
|
||||
map((data: object) => {
|
||||
return data as IRulibSearchResult;
|
||||
}),
|
||||
catchError((error) => {
|
||||
return throwError(() => `Now found ${error}`);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
getDetails(slug_url: string): Observable<IRulibDetailResult> {
|
||||
return this.http
|
||||
.get(
|
||||
`${this.url}/api/manga/${slug_url}?fields[]=summary&fields[]=genres&fields[]=tags&fields[]=authors`,
|
||||
)
|
||||
.pipe(
|
||||
map((data: object) => {
|
||||
return data as IRulibDetailResult;
|
||||
}),
|
||||
catchError((error) => {
|
||||
return throwError(() => `Now found ${error}`);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
getChapters(url: string): Observable<IRulibChaptersResult> {
|
||||
return this.http.get(`${this.url}/api/manga/${url}/chapters`).pipe(
|
||||
map((data) => {
|
||||
return data as IRulibChaptersResult;
|
||||
}),
|
||||
catchError((error) => {
|
||||
return throwError(() => `Now found ${error}`);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
getChapter(url: string, chapter: string, volume: string): Observable<IRulibChapterResult> {
|
||||
return this.http
|
||||
.get(`${this.url}/api/manga/${url}/chapter?number=${chapter}&volume=${volume}`)
|
||||
.pipe(
|
||||
map((data) => data as IRulibChapterResult),
|
||||
catchError((error) => throwError(() => `Now found ${error}`)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
export interface IRulibChapterResult {
|
||||
data: Chapter;
|
||||
}
|
||||
|
||||
export interface Chapter {
|
||||
id: number;
|
||||
type: string;
|
||||
volume: string;
|
||||
number: string;
|
||||
number_secondary: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
branch_id: null;
|
||||
manga_id: number;
|
||||
created_at: Date;
|
||||
moderated: Moderated;
|
||||
likes_count: number;
|
||||
teams: Team[];
|
||||
pages: Page[];
|
||||
}
|
||||
|
||||
export interface Moderated {
|
||||
id: number;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export interface Page {
|
||||
id: number;
|
||||
image: string;
|
||||
slug: number;
|
||||
external: number;
|
||||
chunks: number;
|
||||
chapter_id: number;
|
||||
created_at: Date;
|
||||
updated_at: UpdatedAt;
|
||||
height: number;
|
||||
width: number;
|
||||
url: string;
|
||||
ratio: string;
|
||||
}
|
||||
|
||||
export enum UpdatedAt {
|
||||
The0000011130T000000000000Z = "-000001-11-30T00:00:00.000000Z",
|
||||
}
|
||||
|
||||
export interface Team {
|
||||
id: number;
|
||||
slug: string;
|
||||
slug_url: string;
|
||||
model: string;
|
||||
name: string;
|
||||
cover: Cover;
|
||||
vk: null;
|
||||
discord: null;
|
||||
}
|
||||
|
||||
export interface Cover {
|
||||
filename: null;
|
||||
thumbnail: string;
|
||||
default: string;
|
||||
md: string;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
export interface IRulibChaptersResult {
|
||||
data: IRulibChapter[];
|
||||
}
|
||||
|
||||
export interface IRulibChapter {
|
||||
id: number;
|
||||
index: number;
|
||||
item_number: number;
|
||||
volume: string;
|
||||
number: string;
|
||||
number_secondary: string;
|
||||
name: string;
|
||||
branches_count: number;
|
||||
branches: Branch[];
|
||||
}
|
||||
|
||||
export interface Branch {
|
||||
id: number;
|
||||
branch_id: null;
|
||||
created_at: Date;
|
||||
teams: Team[];
|
||||
user: User;
|
||||
}
|
||||
|
||||
export interface Team {
|
||||
id: number;
|
||||
slug: Slug;
|
||||
slug_url: SlugURL;
|
||||
model: Model;
|
||||
name: Name;
|
||||
cover: Cover;
|
||||
}
|
||||
|
||||
export interface Cover {
|
||||
filename: null | string;
|
||||
thumbnail: Thumbnail;
|
||||
default: Default;
|
||||
md: Default;
|
||||
}
|
||||
|
||||
export enum Default {
|
||||
StaticImagesPlaceholdersUserAvatarPNG = "/static/images/placeholders/user_avatar.png",
|
||||
UploadsTeamAnyasyavaCoverJSazXO7JdAKV250X350Jpg = "/uploads/team/anyasyava/cover/jSazXO7JdAKV_250x350.jpg",
|
||||
}
|
||||
|
||||
export enum Thumbnail {
|
||||
StaticImagesPlaceholdersUserAvatarPNG = "/static/images/placeholders/user_avatar.png",
|
||||
UploadsTeamAnyasyavaCoverJSazXO7JdAKVThumbJpg = "/uploads/team/anyasyava/cover/jSazXO7JdAKV_thumb.jpg",
|
||||
}
|
||||
|
||||
export enum Model {
|
||||
Team = "team",
|
||||
}
|
||||
|
||||
export enum Name {
|
||||
Abame = "abame",
|
||||
Anyasyava = "ANYASYAVA",
|
||||
Cabel = "Cabel",
|
||||
Deadvm = "deadvm",
|
||||
}
|
||||
|
||||
export enum Slug {
|
||||
Abame = "abame",
|
||||
Anyasyava = "anyasyava",
|
||||
Cabel = "cabel",
|
||||
Deadvm = "deadvm",
|
||||
}
|
||||
|
||||
export enum SlugURL {
|
||||
The13801Anyasyava = "13801--anyasyava",
|
||||
The33106Abame = "33106--abame",
|
||||
The42374Cabel = "42374--cabel",
|
||||
The45635Deadvm = "45635--deadvm",
|
||||
}
|
||||
|
||||
export interface User {
|
||||
username: Username;
|
||||
id: number;
|
||||
}
|
||||
|
||||
export enum Username {
|
||||
Deadvm = "deadvm",
|
||||
Gjunyaa = "gjunyaa ❤️\ud83e\ude79",
|
||||
Oksas = "oksas",
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
export interface IRulibDetailResult {
|
||||
data: Data;
|
||||
meta: Meta;
|
||||
}
|
||||
|
||||
export interface Data {
|
||||
id: number;
|
||||
name: string;
|
||||
rus_name: string;
|
||||
eng_name: string;
|
||||
slug: string;
|
||||
slug_url: string;
|
||||
cover: Cover;
|
||||
ageRestriction: AgeRestriction;
|
||||
site: number;
|
||||
type: AgeRestriction;
|
||||
summary: string;
|
||||
is_licensed: boolean;
|
||||
genres: Genre[];
|
||||
tags: Genre[];
|
||||
authors: Author[];
|
||||
model: string;
|
||||
status: AgeRestriction;
|
||||
releaseDateString: string;
|
||||
}
|
||||
|
||||
export interface AgeRestriction {
|
||||
id: number;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export interface Author {
|
||||
id: number;
|
||||
slug: string;
|
||||
slug_url: string;
|
||||
model: string;
|
||||
name: string;
|
||||
rus_name: null;
|
||||
alt_name: null;
|
||||
cover: Cover;
|
||||
subscription: Subscription;
|
||||
confirmed: null;
|
||||
user_id: number;
|
||||
}
|
||||
|
||||
export interface Cover {
|
||||
filename: null | string;
|
||||
thumbnail: string;
|
||||
default: string;
|
||||
md: string;
|
||||
}
|
||||
|
||||
export interface Subscription {
|
||||
is_subscribed: boolean;
|
||||
source_type: string;
|
||||
source_id: number;
|
||||
relation: null;
|
||||
}
|
||||
|
||||
export interface Genre {
|
||||
id: number;
|
||||
name: string;
|
||||
adult: boolean;
|
||||
alert: boolean;
|
||||
}
|
||||
|
||||
export interface Meta {
|
||||
country: string;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
export interface IRulibSearchResult {
|
||||
data: Datum[];
|
||||
links: Links;
|
||||
meta: Meta;
|
||||
}
|
||||
|
||||
//TODO: Make normal namings
|
||||
export interface Datum {
|
||||
id: number;
|
||||
name: string;
|
||||
rus_name: string;
|
||||
eng_name: string;
|
||||
slug: string;
|
||||
slug_url: string;
|
||||
cover: Cover;
|
||||
ageRestriction: AgeRestriction;
|
||||
site: number;
|
||||
type: AgeRestriction;
|
||||
rating: Rating;
|
||||
is_licensed: boolean;
|
||||
model: Model;
|
||||
status: AgeRestriction;
|
||||
releaseDateString: string;
|
||||
}
|
||||
|
||||
export interface AgeRestriction {
|
||||
id: number;
|
||||
label: Label;
|
||||
}
|
||||
|
||||
export enum Label {
|
||||
The12 = "12+",
|
||||
The6 = "6+",
|
||||
Завершён = "Завершён",
|
||||
КомиксЗападный = "Комикс западный",
|
||||
Манга = "Манга",
|
||||
Манхва = "Манхва",
|
||||
Маньхуа = "Маньхуа",
|
||||
Нет = "Нет",
|
||||
Онгоинг = "Онгоинг",
|
||||
Приостановлен = "Приостановлен",
|
||||
}
|
||||
|
||||
export interface Cover {
|
||||
filename: string;
|
||||
thumbnail: string;
|
||||
default: string;
|
||||
md: string;
|
||||
}
|
||||
|
||||
export enum Model {
|
||||
Manga = "manga",
|
||||
}
|
||||
|
||||
export interface Rating {
|
||||
average: string;
|
||||
averageFormated: string;
|
||||
votes: number;
|
||||
votesFormated: string;
|
||||
user: number;
|
||||
}
|
||||
|
||||
export interface Links {
|
||||
first: string;
|
||||
last: null;
|
||||
prev: null;
|
||||
next: string;
|
||||
}
|
||||
|
||||
export interface Meta {
|
||||
current_page: number;
|
||||
from: number;
|
||||
path: string;
|
||||
per_page: number;
|
||||
to: number;
|
||||
page: number;
|
||||
has_next_page: boolean;
|
||||
seed: string;
|
||||
}
|
||||
3
apps/NwaifuAnime/src/app/services/parsers/urls.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export enum ESiteUrls {
|
||||
LIB_SOCIAL = "https://api.lib.social",
|
||||
}
|
||||
48
apps/NwaifuAnime/src/app/services/search.service.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { BehaviorSubject, Observable, map } from "rxjs";
|
||||
import { LibSocialParserService } from "./parsers/rulib/lib.social.parser.service";
|
||||
import { IRulibChapterResult } from "./parsers/rulib/rulib.chapter.dto";
|
||||
import { IRulibChaptersResult } from "./parsers/rulib/rulib.chapters.dto";
|
||||
import { IRulibDetailResult } from "./parsers/rulib/rulib.detail.dto";
|
||||
import { Datum } from "./parsers/rulib/rulib.search.dto";
|
||||
|
||||
@Injectable({ providedIn: "root" })
|
||||
export class SearchService {
|
||||
private itemsTerm = new BehaviorSubject<Datum[]>([]);
|
||||
currentItemsTerm = this.itemsTerm.asObservable();
|
||||
constructor(private parser: LibSocialParserService) {}
|
||||
|
||||
search(query: string) {
|
||||
this.parser.searchManga(query).subscribe((data) => {
|
||||
this.itemsTerm.next(data.data);
|
||||
});
|
||||
}
|
||||
|
||||
getDetails(slug_url: string): Observable<IRulibDetailResult> {
|
||||
return this.parser.getDetails(slug_url).pipe(
|
||||
map((data) => {
|
||||
return data;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
getChapters(url: string): Observable<IRulibChaptersResult> {
|
||||
return this.parser.getChapters(url).pipe(
|
||||
map((data) => {
|
||||
return data;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
getChapter(url: string, chapter: string, volume: string): Observable<IRulibChapterResult> {
|
||||
return this.parser.getChapter(url, chapter, volume).pipe(
|
||||
map((data) => {
|
||||
return data;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
getImageServer() {
|
||||
return this.parser.imageServer;
|
||||
}
|
||||
}
|
||||
17
apps/NwaifuAnime/src/index.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>NwaifuAnime</title>
|
||||
<base href="/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
||||
<link href="https://cdn.lineicons.com/4.0/lineicons.css" rel="stylesheet" />
|
||||
<link rel="manifest" href="manifest.webmanifest" />
|
||||
<meta name="theme-color" content="#1976d2" />
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
<noscript>Please enable JavaScript to continue using this application.</noscript>
|
||||
</body>
|
||||
</html>
|
||||
5
apps/NwaifuAnime/src/main.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { bootstrapApplication } from "@angular/platform-browser";
|
||||
import { appConfig } from "./app/app.config";
|
||||
import { AppComponent } from "./app/app.component";
|
||||
|
||||
bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));
|
||||
3
apps/NwaifuAnime/src/styles.less
Normal file
@@ -0,0 +1,3 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
14
apps/NwaifuAnime/tailwind.config.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const { createGlobPatternsForDependencies } = require("@nx/angular/tailwind");
|
||||
const { join } = require("path");
|
||||
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: [
|
||||
join(__dirname, "src/**/!(*.stories|*.spec).{ts,html}"),
|
||||
...createGlobPatternsForDependencies(__dirname),
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
};
|
||||
10
apps/NwaifuAnime/tsconfig.app.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist/out-tsc",
|
||||
"types": []
|
||||
},
|
||||
"files": ["src/main.ts"],
|
||||
"include": ["src/**/*.d.ts"],
|
||||
"exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
|
||||
}
|
||||
6
apps/NwaifuAnime/tsconfig.editor.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["src/**/*.ts"],
|
||||
"compilerOptions": {},
|
||||
"exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
|
||||
}
|
||||
30
apps/NwaifuAnime/tsconfig.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2022",
|
||||
"useDefineForClassFields": false,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitOverride": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.editor.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.app.json"
|
||||
}
|
||||
],
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"angularCompilerOptions": {
|
||||
"enableI18nLegacyMessageIdFormat": false,
|
||||
"strictInjectionParameters": true,
|
||||
"strictInputAccessModifiers": true,
|
||||
"strictTemplates": true
|
||||
}
|
||||
}
|
||||
41
apps/NwaifuWeb/.eslintrc.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"ignorePatterns": ["!**/*"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.ts"],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:@angular-eslint/recommended",
|
||||
"plugin:@angular-eslint/template/process-inline-templates"
|
||||
],
|
||||
"rules": {
|
||||
"@angular-eslint/directive-selector": [
|
||||
"error",
|
||||
{
|
||||
"type": "attribute",
|
||||
"prefix": "app",
|
||||
"style": "camelCase"
|
||||
}
|
||||
],
|
||||
"@angular-eslint/component-selector": [
|
||||
"error",
|
||||
{
|
||||
"type": "element",
|
||||
"prefix": "app",
|
||||
"style": "kebab-case"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["*.html"],
|
||||
"extends": [
|
||||
"plugin:@angular-eslint/template/recommended",
|
||||
"plugin:@angular-eslint/template/accessibility"
|
||||
],
|
||||
"rules": {}
|
||||
}
|
||||
],
|
||||
"extends": "../../.eslintrc.json"
|
||||
}
|
||||
86
apps/NwaifuWeb/project.json
Normal file
@@ -0,0 +1,86 @@
|
||||
{
|
||||
"name": "NwaifuWeb",
|
||||
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
||||
"projectType": "application",
|
||||
"generators": {
|
||||
"@schematics/angular:component": {
|
||||
"style": "less"
|
||||
}
|
||||
},
|
||||
"sourceRoot": "apps/NwaifuWeb/src",
|
||||
"prefix": "app",
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@angular-devkit/build-angular:application",
|
||||
"options": {
|
||||
"outputPath": "dist/apps/NwaifuWeb",
|
||||
"index": "apps/NwaifuWeb/src/index.html",
|
||||
"browser": "apps/NwaifuWeb/src/main.ts",
|
||||
"polyfills": ["zone.js"],
|
||||
"tsConfig": "apps/NwaifuWeb/tsconfig.app.json",
|
||||
"inlineStyleLanguage": "less",
|
||||
"assets": ["apps/NwaifuWeb/src/favicon.ico", "apps/NwaifuWeb/src/assets"],
|
||||
"styles": ["apps/NwaifuWeb/src/styles.less"],
|
||||
"scripts": []
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "500kb",
|
||||
"maximumError": "1mb"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "2kb",
|
||||
"maximumError": "4kb"
|
||||
}
|
||||
],
|
||||
"outputHashing": "all"
|
||||
},
|
||||
"development": {
|
||||
"optimization": false,
|
||||
"extractLicenses": false,
|
||||
"sourceMap": true
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "production"
|
||||
},
|
||||
"serve": {
|
||||
"executor": "@angular-devkit/build-angular:dev-server",
|
||||
"configurations": {
|
||||
"production": {
|
||||
"buildTarget": "NwaifuWeb:build:production"
|
||||
},
|
||||
"development": {
|
||||
"buildTarget": "NwaifuWeb:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development"
|
||||
},
|
||||
"extract-i18n": {
|
||||
"executor": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"buildTarget": "NwaifuWeb:build"
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"executor": "@angular-devkit/build-angular:karma",
|
||||
"options": {
|
||||
"polyfills": ["zone.js", "zone.js/testing"],
|
||||
"tsConfig": "apps/NwaifuWeb/tsconfig.spec.json",
|
||||
"inlineStyleLanguage": "less",
|
||||
"assets": ["apps/NwaifuWeb/src/favicon.ico", "apps/NwaifuWeb/src/assets"],
|
||||
"styles": ["apps/NwaifuWeb/src/styles.less"],
|
||||
"scripts": []
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nx/eslint:lint",
|
||||
"options": {
|
||||
"lintFilePatterns": ["apps/NwaifuWeb/**/*.ts", "apps/NwaifuWeb/**/*.html"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<header>
|
||||
<app-panel></app-panel>
|
||||
</header>
|
||||
<main class="main">
|
||||
<app-dock></app-dock>
|
||||
<main>
|
||||
<router-outlet></router-outlet>
|
||||
</main>
|
||||
8
apps/NwaifuWeb/src/app/app.component.less
Normal file
@@ -0,0 +1,8 @@
|
||||
main {
|
||||
overflow-y: auto;
|
||||
width: 100%;
|
||||
height: calc(100% - 2rem);
|
||||
background-image: url("../assets/img/wallpaper.png");
|
||||
background-repeat: no-repeat;
|
||||
background-size: 100% 100%;
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { AppComponent } from './app.component';
|
||||
import { TestBed } from "@angular/core/testing";
|
||||
import { AppComponent } from "./app.component";
|
||||
|
||||
describe('AppComponent', () => {
|
||||
describe("AppComponent", () => {
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [AppComponent],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
it('should create the app', () => {
|
||||
it("should create the app", () => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.componentInstance;
|
||||
expect(app).toBeTruthy();
|
||||
@@ -17,13 +17,13 @@ describe('AppComponent', () => {
|
||||
it(`should have the 'NwaifuWeb' title`, () => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.componentInstance;
|
||||
expect(app.title).toEqual('NwaifuWeb');
|
||||
expect(app.title).toEqual("NwaifuWeb");
|
||||
});
|
||||
|
||||
it('should render title', () => {
|
||||
it("should render title", () => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
fixture.detectChanges();
|
||||
const compiled = fixture.nativeElement as HTMLElement;
|
||||
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, NwaifuWeb');
|
||||
expect(compiled.querySelector("h1")?.textContent).toContain("Hello, NwaifuWeb");
|
||||
});
|
||||
});
|
||||
@@ -1,12 +1,11 @@
|
||||
import { Component } from "@angular/core";
|
||||
import { RouterOutlet } from "@angular/router";
|
||||
import { DockComponent } from "./modules/dock/dock.component";
|
||||
import { RouterModule } from "@angular/router";
|
||||
import { PanelComponent } from "./modules/panel/panel.component";
|
||||
|
||||
@Component({
|
||||
selector: "app-root",
|
||||
standalone: true,
|
||||
imports: [RouterOutlet, PanelComponent, DockComponent],
|
||||
imports: [PanelComponent, RouterModule],
|
||||
templateUrl: "./app.component.html",
|
||||
styleUrl: "./app.component.less",
|
||||
})
|
||||
25
apps/NwaifuWeb/src/app/app.config.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { APP_INITIALIZER, ApplicationConfig } from "@angular/core";
|
||||
|
||||
import { provideHttpClient } from "@angular/common/http";
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { routes } from './app.routes';
|
||||
import { TranslateService } from "./services/translate.service";
|
||||
|
||||
export function setupTranslateServiceFactory(service: TranslateService) {
|
||||
const lang = localStorage.getItem("lang") ?? "en";
|
||||
return () => service.use(lang);
|
||||
}
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideRouter(routes),
|
||||
provideHttpClient(),
|
||||
TranslateService,
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: setupTranslateServiceFactory,
|
||||
deps: [TranslateService],
|
||||
multi: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
19
apps/NwaifuWeb/src/app/app.routes.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Routes } from "@angular/router";
|
||||
import { MainPageComponent } from './pages/main/main.component';
|
||||
import { NitroplusComponent } from './pages/nitroplus-translator/nitroplus-translator.component';
|
||||
|
||||
export const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
component: MainPageComponent
|
||||
},
|
||||
{
|
||||
path: 'translator',
|
||||
component: NitroplusComponent
|
||||
}
|
||||
]
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,4 @@
|
||||
<div class="desktop-icon">
|
||||
<img [src]="image" [alt]="alt" [title]="name" />
|
||||
<span>{{ name }}</span>
|
||||
</div>
|
||||
@@ -0,0 +1,17 @@
|
||||
.desktop-icon {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 5rem;
|
||||
height: 6rem;
|
||||
color: white;
|
||||
font-size: 0.7rem;
|
||||
user-select: none;
|
||||
padding: 1rem;
|
||||
border-radius: 10px;
|
||||
transition: 0.2s ease-in-out;
|
||||
&:hover {
|
||||
background-color: rgba(25, 17, 19, 0.7);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, Input } from '@angular/core';
|
||||
import { RouterModule } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'desktop-icon',
|
||||
templateUrl: './desktop-icon.component.html',
|
||||
styleUrls: ['./desktop-icon.component.less'],
|
||||
standalone: true,
|
||||
imports: [CommonModule, RouterModule]
|
||||
})
|
||||
export class DesktopIconComponent {
|
||||
@Input() image: string = '';
|
||||
@Input() alt: string = '';
|
||||
@Input() name: string = '';
|
||||
@Input({required: false}) click: ()=>void = ()=>{};
|
||||
}
|
||||
@@ -16,19 +16,19 @@ export class DockComponent {
|
||||
id: 0,
|
||||
svg: "../../../assets/svg/logo-telegram.svg",
|
||||
url: "https://t.me/neur0w0men",
|
||||
text: "Telegram channel",
|
||||
text: "TELEGRAM_LABEL",
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
svg: "../../../assets/svg/logo-github.svg",
|
||||
url: "https://github.com/MrSedan",
|
||||
text: "Admin's GitHub",
|
||||
text: "GITHUB_LABEL",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
svg: "../../../assets/svg/logo-gitea.svg",
|
||||
url: "https://git.nwaifu.su",
|
||||
text: "Gitea",
|
||||
text: "GITEA_LABEL",
|
||||
},
|
||||
];
|
||||
}
|
||||
4
apps/NwaifuWeb/src/app/modules/link/link.component.html
Normal file
@@ -0,0 +1,4 @@
|
||||
<a [href]="url">
|
||||
<img [src]="svg" [alt]="url" [title]="text | translate" />
|
||||
<span>{{ text | translate }}</span>
|
||||
</a>
|
||||
@@ -10,7 +10,7 @@ a {
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
gap: 0;
|
||||
transition: 0.3s ease-in-out;
|
||||
transition: 0.5s ease-in-out;
|
||||
span {
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
@@ -21,7 +21,7 @@ a {
|
||||
font-size: 0.8rem;
|
||||
height: 0;
|
||||
font-weight: 600;
|
||||
transition: opacity 0.3s ease-in-out;
|
||||
transition: all 0.6s ease-in-out;
|
||||
}
|
||||
&:hover {
|
||||
transform: translateY(-1rem);
|
||||
@@ -1,10 +1,11 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { Component, Input } from "@angular/core";
|
||||
import { TranslationPipe } from "../../pipes/translation.pipe";
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
selector: "app-link",
|
||||
imports: [CommonModule],
|
||||
imports: [CommonModule, TranslationPipe],
|
||||
templateUrl: "./link.component.html",
|
||||
styleUrls: ["./link.component.less"],
|
||||
})
|
||||
@@ -0,0 +1 @@
|
||||
<div class="modal-window" #modal></div>
|
||||
31
apps/NwaifuWeb/src/app/modules/modal/modal.component.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { AfterViewInit, Component, ElementRef, ViewChild } from "@angular/core";
|
||||
import { DialogRef, DialogService } from "@ngneat/dialog";
|
||||
import { WindowComponent } from "../window/window.component";
|
||||
|
||||
@Component({
|
||||
selector: "app-modal",
|
||||
templateUrl: "./modal.component.html",
|
||||
styleUrls: ["./modal.component.less"],
|
||||
imports: [CommonModule],
|
||||
standalone: true,
|
||||
})
|
||||
export class ModalComponent implements AfterViewInit {
|
||||
dialogRef: DialogRef | undefined = undefined;
|
||||
@ViewChild("modal") modal: ElementRef | undefined = undefined;
|
||||
constructor(private dialogService: DialogService, private ref: ElementRef) {}
|
||||
ngAfterViewInit(): void {
|
||||
this.dialogRef = this.dialogService.open(WindowComponent, {
|
||||
resizable: true,
|
||||
draggable: true,
|
||||
backdrop: false,
|
||||
closeButton: false,
|
||||
container: this.modal ?? this.ref,
|
||||
enableClose: false,
|
||||
dragConstraint: "constrain",
|
||||
id: "info-modal",
|
||||
minWidth: "300px",
|
||||
minHeight: "10rem",
|
||||
});
|
||||
}
|
||||
}
|
||||
29
apps/NwaifuWeb/src/app/modules/panel/panel.component.html
Normal file
@@ -0,0 +1,29 @@
|
||||
<div class="panel">
|
||||
<div class="desktops">
|
||||
<div class="ellipse"></div>
|
||||
<div class="circle"></div>
|
||||
</div>
|
||||
<div class="time">
|
||||
<span>{{ time }}</span>
|
||||
</div>
|
||||
<div class="right-menu">
|
||||
<span
|
||||
class="lang cursor-pointer"
|
||||
(click)="toggleModal()"
|
||||
(keydown)="toggleModal()"
|
||||
tabindex="0"
|
||||
#lang_btn
|
||||
>{{ getLang() }}</span
|
||||
>
|
||||
<a href="https://git.nwaifu.su/neuro_llc/NwaifuWeb" [title]="source_code_btn_title | translate">
|
||||
<fa-icon [icon]="faGithub" class="sourcecode-icon"></fa-icon>
|
||||
</a>
|
||||
<fa-icon [icon]="faVolume"></fa-icon>
|
||||
<fa-icon [icon]="faPower"></fa-icon>
|
||||
</div>
|
||||
</div>
|
||||
<div class="lang-choose" #lang_modal>
|
||||
<p (click)="useLang('en')" (keypress)="useLang('en')" tabindex="0"><b>en</b> - English</p>
|
||||
<p (click)="useLang('ru')" (keypress)="useLang('ru')" tabindex="0"><b>ru</b> - Русский</p>
|
||||
<p (click)="useLang('ja')" (keypress)="useLang('ja')" tabindex="0"><b>ja</b> - 日本語</p>
|
||||
</div>
|
||||
@@ -1,4 +1,5 @@
|
||||
.panel {
|
||||
z-index: 99999;
|
||||
position: relative;
|
||||
left: 0;
|
||||
top: 0;
|
||||
@@ -56,9 +57,51 @@
|
||||
align-items: center;
|
||||
span {
|
||||
font-weight: 600;
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
fa-icon {
|
||||
font-size: 1.2rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
.lang-choose {
|
||||
position: absolute;
|
||||
display: none;
|
||||
&.active {
|
||||
display: flex;
|
||||
}
|
||||
top: 0;
|
||||
flex-direction: column;
|
||||
justify-content: space-around;
|
||||
gap: 0;
|
||||
background-color: var(--black);
|
||||
margin-block-start: 3rem;
|
||||
z-index: 9999;
|
||||
margin-inline-end: 1rem;
|
||||
color: var(--white);
|
||||
padding: 1rem 0;
|
||||
border-radius: 15px;
|
||||
&::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translateX(-50%) rotate(45deg);
|
||||
vertical-align: middle;
|
||||
top: -0.5rem;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border: 10px solid var(--black);
|
||||
}
|
||||
p {
|
||||
line-height: 2rem;
|
||||
width: 100%;
|
||||
padding: 0.5rem 1rem;
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
cursor: pointer;
|
||||
&:hover {
|
||||
background-color: #000;
|
||||
}
|
||||
}
|
||||
}
|
||||
88
apps/NwaifuWeb/src/app/modules/panel/panel.component.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { Component, ElementRef, HostListener, ViewChild } from "@angular/core";
|
||||
import { FontAwesomeModule } from "@fortawesome/angular-fontawesome";
|
||||
import { faGithub } from "@fortawesome/free-brands-svg-icons";
|
||||
import { faPowerOff, faVolumeHigh } from "@fortawesome/free-solid-svg-icons";
|
||||
import { TranslationPipe } from "../../pipes/translation.pipe";
|
||||
import { PanelSevice } from "../../services/panel.service";
|
||||
import { TranslateService } from "../../services/translate.service";
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
selector: "app-panel",
|
||||
imports: [CommonModule, FontAwesomeModule, TranslationPipe],
|
||||
templateUrl: "./panel.component.html",
|
||||
styleUrls: ["./panel.component.less"],
|
||||
})
|
||||
export class PanelComponent {
|
||||
source_code_btn_title = "SOURCE_CODE_TITLE";
|
||||
|
||||
public time = "";
|
||||
faGithub = faGithub;
|
||||
faVolume = faVolumeHigh;
|
||||
faPower = faPowerOff;
|
||||
showLangModalBool = false;
|
||||
@ViewChild("lang_modal") langModal: ElementRef<HTMLDivElement> | null = null;
|
||||
@ViewChild("lang_btn") langBtn: ElementRef<HTMLSpanElement> | null = null;
|
||||
|
||||
constructor(private panelService: PanelSevice, private translateService: TranslateService) {
|
||||
this.time = this.getTime();
|
||||
setInterval(() => {
|
||||
this.time = this.getTime();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
private getTime() {
|
||||
const time = this.panelService.getTime();
|
||||
return time.toLocaleDateString(this.translateService.translate("TIME_SCHEMA"), {
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
});
|
||||
}
|
||||
|
||||
goToSource() {
|
||||
window.open("https://git.nwaifu.su/neuro_llc/NwaifuWeb", "_blank");
|
||||
}
|
||||
|
||||
@HostListener("window:resize")
|
||||
private moveLangModal() {
|
||||
if (!this.langModal || !this.langBtn) {
|
||||
return;
|
||||
}
|
||||
|
||||
const x = this.langBtn.nativeElement.getBoundingClientRect().x;
|
||||
this.langModal.nativeElement.style.left = `calc(${x}px - 3.5rem)`;
|
||||
}
|
||||
|
||||
@HostListener("window:click", ["$event"])
|
||||
private closeLangModal(event: MouseEvent) {
|
||||
if (
|
||||
this.langModal &&
|
||||
this.langBtn &&
|
||||
!this.langModal.nativeElement.contains(event.target as Node) &&
|
||||
!this.langBtn.nativeElement.contains(event.target as Node)
|
||||
) {
|
||||
this.langModal.nativeElement.classList.remove("active");
|
||||
}
|
||||
}
|
||||
|
||||
toggleModal() {
|
||||
if (this.langModal) {
|
||||
this.langModal.nativeElement.classList.toggle("active");
|
||||
if (this.langModal.nativeElement.classList.contains("active")) {
|
||||
this.moveLangModal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
useLang(lang: string) {
|
||||
this.langModal && this.langModal.nativeElement.classList.remove("active");
|
||||
this.translateService.use(lang);
|
||||
}
|
||||
|
||||
getLang() {
|
||||
return this.translateService.lang;
|
||||
}
|
||||
}
|
||||
10
apps/NwaifuWeb/src/app/modules/window/window.component.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<div class="panel">
|
||||
<span>{{ modal_title | translate }}</span>
|
||||
<div class="btns">
|
||||
<fa-icon [icon]="faMenu"></fa-icon>
|
||||
<fa-icon [icon]="faClose"></fa-icon>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
<h1>{{ modal_text | translate }}</h1>
|
||||
</div>
|
||||
24
apps/NwaifuWeb/src/app/modules/window/window.component.less
Normal file
@@ -0,0 +1,24 @@
|
||||
.panel {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
height: 3rem;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0 1rem;
|
||||
background-color: var(--black);
|
||||
color: var(--white);
|
||||
span {
|
||||
font-size: 600;
|
||||
}
|
||||
.btns {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
.content {
|
||||
margin: 1rem;
|
||||
}
|
||||
22
apps/NwaifuWeb/src/app/modules/window/window.component.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { Component } from "@angular/core";
|
||||
import { FontAwesomeModule } from "@fortawesome/angular-fontawesome";
|
||||
import { faBars, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||
import { DialogRef } from "@ngneat/dialog";
|
||||
import { TranslationPipe } from "../../pipes/translation.pipe";
|
||||
|
||||
@Component({
|
||||
selector: "app-window",
|
||||
standalone: true,
|
||||
imports: [CommonModule, FontAwesomeModule, TranslationPipe],
|
||||
templateUrl: "./window.component.html",
|
||||
styleUrls: ["./window.component.less"],
|
||||
// changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class WindowComponent {
|
||||
modal_text = "MODAL_TEXT";
|
||||
modal_title = "MODAL_TITLE";
|
||||
faClose = faXmark;
|
||||
faMenu = faBars;
|
||||
constructor(public ref: DialogRef) {}
|
||||
}
|
||||
5
apps/NwaifuWeb/src/app/pages/main/main.component.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<div class="icons">
|
||||
<a routerLink='/translator'><desktop-icon alt='translator' name='Translator' image='../../../assets/svg/logo-gitea.svg'></desktop-icon></a>
|
||||
</div>
|
||||
<app-modal></app-modal>
|
||||
<app-dock></app-dock>
|
||||
9
apps/NwaifuWeb/src/app/pages/main/main.component.less
Normal file
@@ -0,0 +1,9 @@
|
||||
.icons {
|
||||
margin: 2rem 3rem;
|
||||
position: absolute;
|
||||
}
|
||||
:host {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
15
apps/NwaifuWeb/src/app/pages/main/main.component.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component } from '@angular/core';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import { DesktopIconComponent } from '../../modules/desktop-icon/desktop-icon.component';
|
||||
import { DockComponent } from '../../modules/dock/dock.component';
|
||||
import { ModalComponent } from '../../modules/modal/modal.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-main-page',
|
||||
templateUrl: './main.component.html',
|
||||
styleUrls: ['./main.component.less'],
|
||||
imports: [DockComponent, ModalComponent, CommonModule, DesktopIconComponent, RouterLink],
|
||||
standalone: true
|
||||
})
|
||||
export class MainPageComponent {}
|
||||
@@ -0,0 +1,9 @@
|
||||
@if (elements_data.length) {
|
||||
<h1>{{ "ROW_COUNT_LABEL" | translate }}: {{ elements_data.length }}</h1>
|
||||
<h2>{{ "FILE_NAME_LABEL" | translate }}: {{ fileName }}</h2>
|
||||
}
|
||||
<div id="elements">
|
||||
@for (item of elements_data; track $index) {
|
||||
<app-translate-block #translateBlock [index]="$index" [item]="item"></app-translate-block>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,19 @@
|
||||
#elements {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3rem;
|
||||
align-items: center;
|
||||
margin-inline: 2rem;
|
||||
}
|
||||
|
||||
h1, h2 {
|
||||
color: #efdee0;
|
||||
text-align: center;
|
||||
margin: 1rem 2rem;
|
||||
}
|
||||
app-translate-block {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { AfterViewInit, Component, Input, QueryList, ViewChildren } from "@angular/core";
|
||||
import { TranslationPipe } from "../../../../pipes/translation.pipe";
|
||||
import { NpsFile, TranslateData } from "../../dto/translate_data.dto";
|
||||
import { TranslateBlockComponent } from "../translate_block/translate_block.component";
|
||||
|
||||
@Component({
|
||||
selector: "app-text-list",
|
||||
templateUrl: "./text_list.component.html",
|
||||
styleUrls: ["./text_list.component.scss"],
|
||||
standalone: true,
|
||||
imports: [CommonModule, TranslateBlockComponent, TranslationPipe],
|
||||
})
|
||||
export class TextListComponent implements AfterViewInit {
|
||||
@ViewChildren("translateBlock") translate_blocks: QueryList<TranslateBlockComponent> | null =
|
||||
null;
|
||||
fileName = "";
|
||||
elements_data: TranslateData[] = [];
|
||||
@Input() set elements(el: TranslateData[]) {
|
||||
this.elements_data = el;
|
||||
localStorage.setItem("translations", JSON.stringify(this.elements_data));
|
||||
this.ngAfterViewInit();
|
||||
}
|
||||
|
||||
get elements() {
|
||||
return this.elements_data;
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
const data = localStorage.getItem("original_file");
|
||||
if (data) {
|
||||
const file: NpsFile = JSON.parse(data);
|
||||
this.fileName = file.file_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<div class="element">
|
||||
<h2>{{ index + 1 }}</h2>
|
||||
<div class="fields">
|
||||
<h2>{{ item.name }}</h2>
|
||||
<nwui-textarea [contenteditable]="false">{{ item.english_text }}</nwui-textarea>
|
||||
<nwui-textarea
|
||||
#translatedText
|
||||
[contenteditable]="isEditing"
|
||||
(leave)="saveTranslate($event)"
|
||||
[disabled]="!isEditing"
|
||||
>{{ item.translated_text }}</nwui-textarea
|
||||
>
|
||||
</div>
|
||||
<div class="btns">
|
||||
<nwui-button (click)="sendToGoogleTranslate()" [disabled]="translateLoading">{{
|
||||
"TRANSLATE_BTN" | translate
|
||||
}}</nwui-button>
|
||||
<nwui-button (click)="isEditing = !isEditing" [disabled]="isEditing">{{
|
||||
"EDIT_BTN" | translate
|
||||
}}</nwui-button>
|
||||
<nwui-button (click)="clear()" [disabled]="!item.translated_text.length">{{
|
||||
"CLEAR_ROW_BTN" | translate
|
||||
}}</nwui-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,39 @@
|
||||
.element {
|
||||
display: flex;
|
||||
background-color: #413738;
|
||||
padding: 3rem 5rem;
|
||||
border-radius: 30px;
|
||||
flex-direction: row;
|
||||
width: 100%;
|
||||
max-width: 1200px;
|
||||
align-items: center;
|
||||
gap: 2rem;
|
||||
justify-content: space-between;
|
||||
h2 {
|
||||
color: #efdee0;
|
||||
}
|
||||
.fields {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
width: 100%;
|
||||
max-width: 1200px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.element {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
.btns {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
align-items: center;
|
||||
padding-inline: 1rem;
|
||||
nwui-button {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { Component, Input, OnInit, ViewChild } from "@angular/core";
|
||||
import { NWUIButtonComponent, NWUITextAreaComponent } from "@nwaifu-ui";
|
||||
import { TranslationPipe } from "../../../../pipes/translation.pipe";
|
||||
import { LocalStorageKeys } from "../../consts";
|
||||
import { TranslateData } from "../../dto/translate_data.dto";
|
||||
import { ETranslateService } from "../../services/translate.enums";
|
||||
import { TranslateService } from "../../services/translate.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-translate-block",
|
||||
templateUrl: "./translate_block.component.html",
|
||||
styleUrls: ["./translate_block.component.scss"],
|
||||
standalone: true,
|
||||
imports: [CommonModule, NWUIButtonComponent, NWUITextAreaComponent, TranslationPipe],
|
||||
providers: [TranslateService],
|
||||
})
|
||||
export class TranslateBlockComponent implements OnInit {
|
||||
@ViewChild("translatedText") translatedText: NWUITextAreaComponent | null = null;
|
||||
@Input({ required: true }) item: TranslateData = {
|
||||
english_text: "",
|
||||
translated_text: "",
|
||||
name: "",
|
||||
};
|
||||
@Input({ required: true }) index = 0;
|
||||
translateLoading = false;
|
||||
isEditing = false;
|
||||
|
||||
saveChanges() {
|
||||
const data: TranslateData[] = JSON.parse(
|
||||
localStorage.getItem(LocalStorageKeys.TRANSLATIONS) ?? "[]",
|
||||
);
|
||||
if (!data.length) {
|
||||
alert("No data");
|
||||
return;
|
||||
}
|
||||
data[this.index] = this.item;
|
||||
localStorage.setItem("translations", JSON.stringify(data));
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.isEditing = this.item.translated_text === "";
|
||||
}
|
||||
|
||||
constructor(private translateService: TranslateService) {}
|
||||
|
||||
private sendToTranslate(service: ETranslateService = ETranslateService.GOOGLE) {
|
||||
this.translateLoading = true;
|
||||
this.translateService.translate(this.item.english_text, service).subscribe((text) => {
|
||||
if (this.translatedText)
|
||||
if (this.translatedText.ref) this.translatedText.ref.nativeElement.textContent = text;
|
||||
this.item.translated_text = text;
|
||||
this.isEditing = false;
|
||||
this.translateLoading = false;
|
||||
this.saveChanges();
|
||||
});
|
||||
}
|
||||
|
||||
sendToGoogleTranslate() {
|
||||
this.sendToTranslate(ETranslateService.GOOGLE);
|
||||
}
|
||||
|
||||
sendToDeeplTranslate() {
|
||||
this.sendToTranslate(ETranslateService.DEEPL);
|
||||
}
|
||||
|
||||
sendToPromptTranslate() {
|
||||
this.sendToTranslate(ETranslateService.PROMPT);
|
||||
}
|
||||
|
||||
saveTranslate(text: string) {
|
||||
this.isEditing = false;
|
||||
if (this.translatedText)
|
||||
if (this.translatedText.ref) this.translatedText.ref.nativeElement.textContent = "";
|
||||
this.item.translated_text = text;
|
||||
this.saveChanges();
|
||||
}
|
||||
clear() {
|
||||
this.item.translated_text = "";
|
||||
this.isEditing = true;
|
||||
if (this.translatedText)
|
||||
if (this.translatedText.ref) this.translatedText.ref.nativeElement.textContent = "";
|
||||
this.saveChanges();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export enum LocalStorageKeys {
|
||||
TRANSLATIONS = 'translations',
|
||||
ORIGINAL_FILE = 'original_file',
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
export interface TranslateData {
|
||||
english_text: string;
|
||||
translated_text: string;
|
||||
name: string;
|
||||
}
|
||||
export interface NpsFile {
|
||||
file_name: string;
|
||||
original_text: string;
|
||||
translated_text?: string;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { LocalStorageKeys } from '../consts';
|
||||
import { NpsFile } from '../dto/translate_data.dto';
|
||||
|
||||
export function saveOriginalFile(file: NpsFile) {
|
||||
localStorage.setItem(LocalStorageKeys.ORIGINAL_FILE, JSON.stringify(file));
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { TranslateData } from "../dto/translate_data.dto";
|
||||
|
||||
export function parse(text: string): TranslateData[] {
|
||||
// Find all TEXT attr data
|
||||
const result: TranslateData[] = [];
|
||||
const re = /^(?!\/\/)<[^>]*TEXT="(?<textAttr>[^>"]+)"[^>]*>/gim;
|
||||
for (const match of text.matchAll(re)) {
|
||||
console.log(match);
|
||||
if (match.groups?.["textAttr"])
|
||||
result.push({
|
||||
english_text: match.groups?.["textAttr"],
|
||||
translated_text: "",
|
||||
name: "Choice (without name)",
|
||||
});
|
||||
}
|
||||
|
||||
const name_re = /<voice name="(?<name>[^"]+)"[^>]*>(?<text>[\s\S]*?)(?=<voice|$)/gi;
|
||||
|
||||
for (const match of text.matchAll(name_re)) {
|
||||
if (match.groups?.["name"] && match.groups?.["text"]) {
|
||||
const name_text = match.groups?.["text"];
|
||||
const name = match.groups?.["name"];
|
||||
const re = /<[^>]*>|\/\/.*|\s*\n\s*/gm;
|
||||
name_text
|
||||
.split(re)
|
||||
.filter((line) => line.length > 0)
|
||||
.map((line) => line.trim())
|
||||
.forEach((line) => {
|
||||
result.push({ english_text: line, translated_text: "", name: name });
|
||||
});
|
||||
}
|
||||
}
|
||||
console.log(result);
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<div class="btns">
|
||||
<div id="op_btns">
|
||||
<nwui-button (click)="fileInput.click()">
|
||||
<span><i class="lni lni-upload"></i> {{ "UPLOAD_BTN" | translate }}</span>
|
||||
<input
|
||||
type="file"
|
||||
(change)="submitFile($event)"
|
||||
accept=".nps"
|
||||
#fileInput
|
||||
style="display: none"
|
||||
/>
|
||||
</nwui-button>
|
||||
<nwui-button (click)="onSaveClicked()">
|
||||
<span><i class="lni lni-save"></i> {{ "SAVE_BTN" | translate }}</span>
|
||||
</nwui-button>
|
||||
@if (this.elements.length) {
|
||||
<nwui-button (click)="clearAllTranslations()" [disabled]="!has_translations">
|
||||
<span><i class="lni lni-trash-can"></i> {{ "CLEAR_TRANSLATIONS_BTN" | translate }}</span>
|
||||
</nwui-button>
|
||||
<nwui-button (click)="getAllTranslations()">
|
||||
<span><i class="lni lni-google"></i> {{ "TRANSLATE_ALL_BTN" | translate }}</span>
|
||||
</nwui-button>
|
||||
<nwui-button (click)="onClearClicked()">
|
||||
<span><i class="lni lni-trash-can"></i> {{ "CLEAR_BTN" | translate }}</span>
|
||||
</nwui-button>
|
||||
}
|
||||
</div>
|
||||
<button id="close_win" (click)="onCloseClicked()"><i class="lni lni-close"></i></button>
|
||||
</div>
|
||||
<app-text-list [elements]="elements"></app-text-list>
|
||||
<nwui-button class="to-top-btn" (click)="scrollToTop()"
|
||||
><i class="lni lni-arrow-up"></i
|
||||
></nwui-button>
|
||||
@@ -0,0 +1,58 @@
|
||||
.btns {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
overflow-x: auto;
|
||||
scrollbar-color: #413738;
|
||||
nwui-button {
|
||||
margin: 2rem;
|
||||
}
|
||||
#op_btns {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
}
|
||||
#close_win {
|
||||
color: var(--white);
|
||||
font-weight: 600;
|
||||
margin-inline: 2rem;
|
||||
background-color: #413738;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 0.5rem;
|
||||
border-radius: 50px;
|
||||
transition: 0.2s linear;
|
||||
i {
|
||||
transition: 0.3s linear;
|
||||
}
|
||||
&:hover {
|
||||
background-color: #5b3f45;
|
||||
transform: scale(1.1);
|
||||
i {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
:host {
|
||||
background-color: #191113;
|
||||
display: block;
|
||||
min-height: calc(100vh - 2rem);
|
||||
scrollbar-color: #413738;
|
||||
}
|
||||
.to-top-btn {
|
||||
position: fixed;
|
||||
width: 2rem;
|
||||
left: 2rem;
|
||||
bottom: -5rem;
|
||||
transition: bottom 0.3s ease-in-out;
|
||||
|
||||
&.active {
|
||||
bottom: 1rem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { AfterViewInit, Component, OnInit, ViewChild } from "@angular/core";
|
||||
import { Router } from "@angular/router";
|
||||
import { NWUIButtonComponent } from "@nwaifu-ui";
|
||||
import { fromEvent, map } from "rxjs";
|
||||
import { TranslationPipe } from "../../pipes/translation.pipe";
|
||||
import { TextListComponent } from "./components/text_list/text_list.component";
|
||||
import { LocalStorageKeys } from "./consts";
|
||||
import { NpsFile, TranslateData } from "./dto/translate_data.dto";
|
||||
import { saveOriginalFile } from "./lib/file_tools";
|
||||
import { parse } from "./lib/parser";
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [TextListComponent, CommonModule, NWUIButtonComponent, TranslationPipe],
|
||||
selector: "app-nitroplus",
|
||||
templateUrl: "./nitroplus-translator.component.html",
|
||||
styleUrl: "./nitroplus-translator.component.less",
|
||||
})
|
||||
export class NitroplusComponent implements OnInit, AfterViewInit {
|
||||
title = "NitroPlusTranslator";
|
||||
elements: TranslateData[] = [];
|
||||
@ViewChild("fileInput") fileInput: HTMLInputElement | null = null;
|
||||
@ViewChild(TextListComponent) text_list: TextListComponent | null = null;
|
||||
|
||||
constructor(private readonly router: Router) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
const data = localStorage.getItem(LocalStorageKeys.TRANSLATIONS);
|
||||
if (data) {
|
||||
try {
|
||||
this.elements = JSON.parse(data);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert("Error while loading");
|
||||
localStorage.removeItem(LocalStorageKeys.TRANSLATIONS);
|
||||
this.elements = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
const container = document.querySelector("main");
|
||||
if (container) {
|
||||
fromEvent(container, "scroll")
|
||||
.pipe(map(() => container.scrollTop > 100))
|
||||
.subscribe((val) => {
|
||||
if (val) document.querySelector(".to-top-btn")?.classList.add("active");
|
||||
else document.querySelector(".to-top-btn")?.classList.remove("active");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
scrollToTop() {
|
||||
const container = document.querySelector("main");
|
||||
if (container) {
|
||||
container.scrollTo({ top: 0, behavior: "smooth" });
|
||||
}
|
||||
}
|
||||
|
||||
submitFile($event: Event) {
|
||||
const target = $event.target as HTMLInputElement;
|
||||
if (target.files) {
|
||||
const file = target.files[0];
|
||||
if (file) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
if (reader.result) {
|
||||
this.onFileLoaded(reader.result.toString());
|
||||
const original_file: NpsFile = {
|
||||
file_name: file.name,
|
||||
original_text: reader.result.toString(),
|
||||
};
|
||||
saveOriginalFile(original_file);
|
||||
target.value = "";
|
||||
}
|
||||
};
|
||||
reader.readAsText(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onFileLoaded(text: string) {
|
||||
const parsed = parse(text);
|
||||
this.elements = parsed;
|
||||
}
|
||||
|
||||
onClearClicked() {
|
||||
this.elements = [];
|
||||
localStorage.removeItem(LocalStorageKeys.TRANSLATIONS);
|
||||
}
|
||||
|
||||
onSaveClicked() {
|
||||
const original_file: NpsFile = JSON.parse(
|
||||
localStorage.getItem(LocalStorageKeys.ORIGINAL_FILE) ??
|
||||
'{"file_name":"", "original_text":""}',
|
||||
);
|
||||
if (original_file.file_name && original_file.original_text) {
|
||||
const data: TranslateData[] = JSON.parse(
|
||||
localStorage.getItem(LocalStorageKeys.TRANSLATIONS) ?? "[]",
|
||||
);
|
||||
if (!data.length) {
|
||||
alert("No data");
|
||||
return;
|
||||
}
|
||||
original_file.translated_text = original_file.original_text;
|
||||
data.forEach((el) => {
|
||||
original_file.translated_text = original_file.translated_text?.replace(
|
||||
el.english_text,
|
||||
el.translated_text,
|
||||
);
|
||||
});
|
||||
|
||||
const element = document.createElement("a");
|
||||
const file = new Blob([original_file.translated_text], { type: "text/plain" });
|
||||
element.href = URL.createObjectURL(file);
|
||||
element.download = original_file.file_name;
|
||||
element.click();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Dialog windows for clear op
|
||||
clearAllTranslations() {
|
||||
if (this.text_list)
|
||||
if (this.text_list.translate_blocks) {
|
||||
this.text_list.translate_blocks
|
||||
.filter((item) => item.item.translated_text)
|
||||
.forEach((item) => item.clear());
|
||||
}
|
||||
}
|
||||
|
||||
getAllTranslations() {
|
||||
if (this.text_list)
|
||||
if (this.text_list.translate_blocks)
|
||||
this.text_list.translate_blocks.forEach((item) => item.sendToGoogleTranslate());
|
||||
}
|
||||
|
||||
get has_translations(): boolean {
|
||||
return this.elements.some((i) => i.translated_text);
|
||||
}
|
||||
|
||||
onCloseClicked() {
|
||||
this.router.navigate(["/"]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export type GoogleTranslateResponse = Array<Array<string>>;
|
||||
@@ -0,0 +1,5 @@
|
||||
export enum ETranslateService {
|
||||
GOOGLE = 'google',
|
||||
DEEPL = 'deepl',
|
||||
PROMPT = 'prompt',
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, map } from 'rxjs';
|
||||
import { GoogleTranslateResponse } from './translate.dto';
|
||||
import { ETranslateService } from './translate.enums';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class TranslateService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private googleTranslate(text: string): Observable<string> {
|
||||
return this.http
|
||||
.get<GoogleTranslateResponse>(
|
||||
'https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=ru&dt=t&q=' + encodeURIComponent(text),
|
||||
)
|
||||
.pipe(
|
||||
map((response) => {
|
||||
let result = '';
|
||||
response[0].forEach((el) => {
|
||||
result += el[0] + ' ';
|
||||
});
|
||||
return result;
|
||||
}),
|
||||
);
|
||||
}
|
||||
translate(text: string, service: ETranslateService = ETranslateService.GOOGLE): Observable<string> {
|
||||
switch (service) {
|
||||
case ETranslateService.GOOGLE:
|
||||
return this.googleTranslate(text);
|
||||
default:
|
||||
return this.googleTranslate(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
14
apps/NwaifuWeb/src/app/pipes/translation.pipe.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Pipe, PipeTransform } from "@angular/core";
|
||||
import { TranslateService } from "../services/translate.service";
|
||||
|
||||
@Pipe({
|
||||
name: "translate",
|
||||
standalone: true,
|
||||
pure: false,
|
||||
})
|
||||
export class TranslationPipe implements PipeTransform {
|
||||
constructor(private translateService: TranslateService) {}
|
||||
transform(key: string) {
|
||||
return this.translateService.data[key] ?? key;
|
||||
}
|
||||
}
|
||||