diff --git a/booklore-api/src/main/resources/db/migration/V91__Create_ebook_viewer_preference_table.sql b/booklore-api/src/main/resources/db/migration/V92__Create_ebook_viewer_preference_table.sql similarity index 100% rename from booklore-api/src/main/resources/db/migration/V91__Create_ebook_viewer_preference_table.sql rename to booklore-api/src/main/resources/db/migration/V92__Create_ebook_viewer_preference_table.sql diff --git a/booklore-ui/package-lock.json b/booklore-ui/package-lock.json index 00d66e841..2d300e15a 100644 --- a/booklore-ui/package-lock.json +++ b/booklore-ui/package-lock.json @@ -27,7 +27,6 @@ "chartjs-chart-matrix": "^3.0.0", "chartjs-plugin-datalabels": "^2.2.0", "date-fns": "^4.1.0", - "epubjs": "^0.3.93", "jwt-decode": "^4.0.0", "ng-lazyload-image": "^9.1.3", "ng2-charts": "^8.0.0", @@ -4573,16 +4572,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/localforage": { - "version": "0.0.34", - "resolved": "https://registry.npmjs.org/@types/localforage/-/localforage-0.0.34.tgz", - "integrity": "sha512-tJxahnjm9dEI1X+hQSC5f2BSd/coZaqbIl1m3TCl0q9SVuC52XcXfV0XmoCU1+PmjyucuVITwoTnN8OlTbEXXA==", - "deprecated": "This is a stub types definition for localforage (https://github.com/localForage/localForage). localforage provides its own type definitions, so you don't need @types/localforage installed!", - "license": "MIT", - "dependencies": { - "localforage": "*" - } - }, "node_modules/@types/node": { "version": "25.0.9", "resolved": "https://registry.npmjs.org/@types/node/-/node-25.0.9.tgz", @@ -4988,16 +4977,6 @@ "url": "https://opencollective.com/vitest" } }, - "node_modules/@xmldom/xmldom": { - "version": "0.7.13", - "resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.7.13.tgz", - "integrity": "sha512-lm2GW5PkosIzccsaZIz7tp8cPADSIlIHWDFTR1N0SzfinhhYgeIQjFMz4rYzanCScr3DqQLeomUDArp6MWKm+g==", - "deprecated": "this version is no longer supported, please update to at least 0.8.*", - "license": "MIT", - "engines": { - "node": ">=10.0.0" - } - }, "node_modules/@yarnpkg/lockfile": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz", @@ -5940,23 +5919,6 @@ "node": ">=6.6.0" } }, - "node_modules/core-js": { - "version": "3.47.0", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.47.0.tgz", - "integrity": "sha512-c3Q2VVkGAUyupsjRnaNX6u8Dq2vAdzm9iuPj5FW0fRxzlxgq9Q39MDq10IvmQSpLgHQNyQzQmOo6bgGHmH3NNg==", - "hasInstallScript": true, - "license": "MIT", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/core-js" - } - }, - "node_modules/core-util-is": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", - "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", - "license": "MIT" - }, "node_modules/cors": { "version": "2.8.5", "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", @@ -6068,19 +6030,6 @@ "node": "20 || >=22" } }, - "node_modules/d": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/d/-/d-1.0.2.tgz", - "integrity": "sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==", - "license": "ISC", - "dependencies": { - "es5-ext": "^0.10.64", - "type": "^2.7.2" - }, - "engines": { - "node": ">=0.12" - } - }, "node_modules/data-urls": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-6.0.0.tgz", @@ -6336,23 +6285,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/epubjs": { - "version": "0.3.93", - "resolved": "https://registry.npmjs.org/epubjs/-/epubjs-0.3.93.tgz", - "integrity": "sha512-c06pNSdBxcXv3dZSbXAVLE1/pmleRhOT6mXNZo6INKmvuKpYB65MwU/lO7830czCtjIiK9i+KR+3S+p0wtljrw==", - "license": "BSD-2-Clause", - "dependencies": { - "@types/localforage": "0.0.34", - "@xmldom/xmldom": "^0.7.5", - "core-js": "^3.18.3", - "event-emitter": "^0.3.5", - "jszip": "^3.7.1", - "localforage": "^1.10.0", - "lodash": "^4.17.21", - "marks-pane": "^1.0.9", - "path-webpack": "0.0.3" - } - }, "node_modules/err-code": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/err-code/-/err-code-2.0.3.tgz", @@ -6400,46 +6332,6 @@ "node": ">= 0.4" } }, - "node_modules/es5-ext": { - "version": "0.10.64", - "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.64.tgz", - "integrity": "sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==", - "hasInstallScript": true, - "license": "ISC", - "dependencies": { - "es6-iterator": "^2.0.3", - "es6-symbol": "^3.1.3", - "esniff": "^2.0.1", - "next-tick": "^1.1.0" - }, - "engines": { - "node": ">=0.10" - } - }, - "node_modules/es6-iterator": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", - "integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==", - "license": "MIT", - "dependencies": { - "d": "1", - "es5-ext": "^0.10.35", - "es6-symbol": "^3.1.1" - } - }, - "node_modules/es6-symbol": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.4.tgz", - "integrity": "sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==", - "license": "ISC", - "dependencies": { - "d": "^1.0.2", - "ext": "^1.7.0" - }, - "engines": { - "node": ">=0.12" - } - }, "node_modules/esbuild": { "version": "0.27.2", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.2.tgz", @@ -6690,21 +6582,6 @@ "node": "*" } }, - "node_modules/esniff": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz", - "integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==", - "license": "ISC", - "dependencies": { - "d": "^1.0.1", - "es5-ext": "^0.10.62", - "event-emitter": "^0.3.5", - "type": "^2.7.2" - }, - "engines": { - "node": ">=0.10" - } - }, "node_modules/espree": { "version": "10.4.0", "resolved": "https://registry.npmjs.org/espree/-/espree-10.4.0.tgz", @@ -6802,16 +6679,6 @@ "node": ">= 0.6" } }, - "node_modules/event-emitter": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", - "integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==", - "license": "MIT", - "dependencies": { - "d": "1", - "es5-ext": "~0.10.14" - } - }, "node_modules/eventemitter3": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", @@ -6918,15 +6785,6 @@ "express": ">= 4.11" } }, - "node_modules/ext": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz", - "integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==", - "license": "ISC", - "dependencies": { - "type": "^2.7.2" - } - }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -7538,12 +7396,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/immediate": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", - "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==", - "license": "MIT" - }, "node_modules/immutable": { "version": "5.1.4", "resolved": "https://registry.npmjs.org/immutable/-/immutable-5.1.4.tgz", @@ -7582,6 +7434,7 @@ "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true, "license": "ISC" }, "node_modules/ini": { @@ -7727,12 +7580,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", - "license": "MIT" - }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -7954,18 +7801,6 @@ ], "license": "MIT" }, - "node_modules/jszip": { - "version": "3.10.1", - "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz", - "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==", - "license": "(MIT OR GPL-3.0-or-later)", - "dependencies": { - "lie": "~3.3.0", - "pako": "~1.0.2", - "readable-stream": "~2.3.6", - "setimmediate": "^1.0.5" - } - }, "node_modules/jwt-decode": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz", @@ -7999,15 +7834,6 @@ "node": ">= 0.8.0" } }, - "node_modules/lie": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", - "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", - "license": "MIT", - "dependencies": { - "immediate": "~3.0.5" - } - }, "node_modules/lilconfig": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.3.tgz", @@ -8103,24 +7929,6 @@ "@lmdb/lmdb-win32-x64": "3.4.4" } }, - "node_modules/localforage": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/localforage/-/localforage-1.10.0.tgz", - "integrity": "sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==", - "license": "Apache-2.0", - "dependencies": { - "lie": "3.1.1" - } - }, - "node_modules/localforage/node_modules/lie": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz", - "integrity": "sha512-RiNhHysUjhrDQntfYSfY4MU24coXXdEOgw9WGcKHNeEwffDYbF//u87M1EWaMGzuFoSbqW0C9C6lEEhDOAswfw==", - "license": "MIT", - "dependencies": { - "immediate": "~3.0.5" - } - }, "node_modules/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", @@ -8137,12 +7945,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/lodash": { - "version": "4.17.21", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "license": "MIT" - }, "node_modules/lodash-es": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz", @@ -8308,12 +8110,6 @@ "node": "^20.17.0 || >=22.9.0" } }, - "node_modules/marks-pane": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/marks-pane/-/marks-pane-1.0.9.tgz", - "integrity": "sha512-Ahs4oeG90tbdPWwAJkAAoHg2lRR8lAs9mZXETNPO9hYg3AkjUJBKi1NQ4aaIQZVGrig7c/3NUV1jANl8rFTeMg==", - "license": "MIT" - }, "node_modules/math-intrinsics": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", @@ -8704,12 +8500,6 @@ "node": ">= 0.6" } }, - "node_modules/next-tick": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", - "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==", - "license": "ISC" - }, "node_modules/ng-lazyload-image": { "version": "9.1.3", "resolved": "https://registry.npmjs.org/ng-lazyload-image/-/ng-lazyload-image-9.1.3.tgz", @@ -9241,12 +9031,6 @@ "node": "^20.17.0 || >=22.9.0" } }, - "node_modules/pako": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", - "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==", - "license": "(MIT AND Zlib)" - }, "node_modules/parchment": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/parchment/-/parchment-3.0.0.tgz", @@ -9405,12 +9189,6 @@ "url": "https://opencollective.com/express" } }, - "node_modules/path-webpack": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/path-webpack/-/path-webpack-0.0.3.tgz", - "integrity": "sha512-AmeDxedoo5svf7aB3FYqSAKqMxys014lVKBzy1o/5vv9CtU7U4wgGWL1dA2o6MOzcD53ScN4Jmiq6VbtLz1vIQ==", - "license": "MIT" - }, "node_modules/pathe": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", @@ -9702,12 +9480,6 @@ "node": "^20.17.0 || >=22.9.0" } }, - "node_modules/process-nextick-args": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", - "license": "MIT" - }, "node_modules/promise-retry": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/promise-retry/-/promise-retry-2.0.1.tgz", @@ -9836,21 +9608,6 @@ "pify": "^2.3.0" } }, - "node_modules/readable-stream": { - "version": "2.3.8", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", - "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", - "license": "MIT", - "dependencies": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, "node_modules/readdirp": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-5.0.0.tgz", @@ -10079,12 +9836,6 @@ "tslib": "^2.1.0" } }, - "node_modules/safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "license": "MIT" - }, "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", @@ -10216,12 +9967,6 @@ "url": "https://opencollective.com/express" } }, - "node_modules/setimmediate": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", - "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==", - "license": "MIT" - }, "node_modules/setprototypeof": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", @@ -10579,15 +10324,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "license": "MIT", - "dependencies": { - "safe-buffer": "~5.1.0" - } - }, "node_modules/string-width": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", @@ -11035,12 +10771,6 @@ "node": "^20.17.0 || >=22.9.0" } }, - "node_modules/type": { - "version": "2.7.3", - "resolved": "https://registry.npmjs.org/type/-/type-2.7.3.tgz", - "integrity": "sha512-8j+1QmAbPvLZow5Qpi6NCaN8FB60p/6x8/vfNqOk/hC+HuvFZhL4+WfekuhQLiqFZXOgQdrs3B+XxEmCc6b3FQ==", - "license": "ISC" - }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", diff --git a/booklore-ui/package.json b/booklore-ui/package.json index ddac85d85..bee5ee868 100644 --- a/booklore-ui/package.json +++ b/booklore-ui/package.json @@ -31,7 +31,6 @@ "chartjs-chart-matrix": "^3.0.0", "chartjs-plugin-datalabels": "^2.2.0", "date-fns": "^4.1.0", - "epubjs": "^0.3.93", "jwt-decode": "^4.0.0", "ng-lazyload-image": "^9.1.3", "ng2-charts": "^8.0.0", diff --git a/booklore-ui/src/app/app.routes.ts b/booklore-ui/src/app/app.routes.ts index dc5fd62d6..0f2d8f7ae 100644 --- a/booklore-ui/src/app/app.routes.ts +++ b/booklore-ui/src/app/app.routes.ts @@ -16,7 +16,6 @@ import {MainDashboardComponent} from './features/dashboard/components/main-dashb import {SeriesPageComponent} from './features/book/components/series-page/series-page.component'; import {MetadataManagerComponent} from './features/metadata/component/metadata-manager/metadata-manager.component'; import {StatsComponent} from './features/stats/component/stats-component'; -import {EpubReaderComponent} from './features/readers/epub-reader/component/epub-reader.component'; import {PdfReaderComponent} from './features/readers/pdf-reader/pdf-reader.component'; import {BookdropFileReviewComponent} from './features/bookdrop/component/bookdrop-file-review/bookdrop-file-review.component'; import {LoginGuard} from './shared/components/setup/login.guard'; @@ -64,11 +63,6 @@ export const routes: Routes = [ component: PdfReaderComponent, canActivate: [AuthGuard] }, - { - path: 'epub-reader/book/:bookId', - component: EpubReaderComponent, - canActivate: [AuthGuard] - }, { path: 'ebook-reader/book/:bookId', component: EbookReaderComponent, diff --git a/booklore-ui/src/app/features/readers/ebook-reader/ebook-reader.component.ts b/booklore-ui/src/app/features/readers/ebook-reader/ebook-reader.component.ts index 10160942e..e4783cbc1 100644 --- a/booklore-ui/src/app/features/readers/ebook-reader/ebook-reader.component.ts +++ b/booklore-ui/src/app/features/readers/ebook-reader/ebook-reader.component.ts @@ -11,7 +11,6 @@ import {BookService} from '../../book/service/book.service'; import {ActivatedRoute} from '@angular/router'; import {BookMark, BookMarkService} from '../../../shared/service/book-mark.service'; import {BookPatchService} from '../../book/service/book-patch.service'; -import {EpubCustomFontService} from '../epub-reader/service/epub-custom-font.service'; import {Book, EbookViewerSetting} from '../../book/model/book.model'; import {ReaderHeaderComponent} from './reader-layout/header/reader-header.component'; import {ReaderSidebarComponent} from './reader-layout/sidebar/reader-sidebar.component'; @@ -22,6 +21,7 @@ import {ReadingSessionService} from '../../../shared/service/reading-session.ser import {TocItem} from 'epubjs'; import {PageInfo, ThemeInfo} from './utils/reader-header-footer.util'; import {ReaderHeaderFooterVisibilityManager} from './utils/reader-header-footer-visibility.util'; +import {EpubCustomFontService} from './services/epub-custom-font.service'; @Component({ selector: 'app-ebook-reader', diff --git a/booklore-ui/src/app/features/readers/ebook-reader/reader-layout/header/reader-settings-dialog.component.ts b/booklore-ui/src/app/features/readers/ebook-reader/reader-layout/header/reader-settings-dialog.component.ts index 659a94c25..7dfbca356 100644 --- a/booklore-ui/src/app/features/readers/ebook-reader/reader-layout/header/reader-settings-dialog.component.ts +++ b/booklore-ui/src/app/features/readers/ebook-reader/reader-layout/header/reader-settings-dialog.component.ts @@ -3,8 +3,8 @@ import {DecimalPipe, DOCUMENT} from '@angular/common'; import {ReaderStateService} from '../../services/reader-state.service'; import {ReaderViewManagerService} from '../../services/reader-view-manager.service'; import {BookService} from '../../../../book/service/book.service'; -import {EpubCustomFontService} from '../../../epub-reader/service/epub-custom-font.service'; import {EbookViewerSetting} from '../../../../book/model/book.model'; +import {EpubCustomFontService} from '../../services/epub-custom-font.service'; @Component({ selector: 'app-settings-dialog', diff --git a/booklore-ui/src/app/features/readers/epub-reader/service/epub-custom-font.service.ts b/booklore-ui/src/app/features/readers/ebook-reader/services/epub-custom-font.service.ts similarity index 100% rename from booklore-ui/src/app/features/readers/epub-reader/service/epub-custom-font.service.ts rename to booklore-ui/src/app/features/readers/ebook-reader/services/epub-custom-font.service.ts diff --git a/booklore-ui/src/app/features/readers/ebook-reader/services/reader-state.service.ts b/booklore-ui/src/app/features/readers/ebook-reader/services/reader-state.service.ts index 1c13cee33..ffa214140 100644 --- a/booklore-ui/src/app/features/readers/ebook-reader/services/reader-state.service.ts +++ b/booklore-ui/src/app/features/readers/ebook-reader/services/reader-state.service.ts @@ -4,7 +4,7 @@ import {map, tap} from 'rxjs/operators'; import {Theme, themes} from './reader-themes'; import {BookService} from '../../../book/service/book.service'; import {UserService} from '../../../settings/user-management/user.service'; -import {EpubCustomFontService} from '../../epub-reader/service/epub-custom-font.service'; +import {EpubCustomFontService} from './epub-custom-font.service'; export interface ReaderState { lineHeight: number; diff --git a/booklore-ui/src/app/features/readers/ebook-reader/services/reader-style.service.ts b/booklore-ui/src/app/features/readers/ebook-reader/services/reader-style.service.ts index 3be5e9309..246331f29 100644 --- a/booklore-ui/src/app/features/readers/ebook-reader/services/reader-style.service.ts +++ b/booklore-ui/src/app/features/readers/ebook-reader/services/reader-style.service.ts @@ -1,6 +1,6 @@ import {inject, Injectable} from '@angular/core'; import {ReaderState} from './reader-state.service'; -import {EpubCustomFontService} from '../../epub-reader/service/epub-custom-font.service'; +import {EpubCustomFontService} from './epub-custom-font.service'; @Injectable({ providedIn: 'root' diff --git a/booklore-ui/src/app/features/readers/epub-reader/component/bookmark-edit-dialog.component.ts b/booklore-ui/src/app/features/readers/epub-reader/component/bookmark-edit-dialog.component.ts deleted file mode 100644 index 4f88bef75..000000000 --- a/booklore-ui/src/app/features/readers/epub-reader/component/bookmark-edit-dialog.component.ts +++ /dev/null @@ -1,191 +0,0 @@ -import { Component, EventEmitter, Input, Output, OnChanges, SimpleChanges } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { FormsModule } from '@angular/forms'; -import { Dialog } from 'primeng/dialog'; -import { InputText } from 'primeng/inputtext'; -import { ColorPicker } from 'primeng/colorpicker'; -import { Textarea } from 'primeng/textarea'; -import { InputNumber } from 'primeng/inputnumber'; -import { Button } from 'primeng/button'; -import { BookMark, UpdateBookMarkRequest } from '../../../../shared/service/book-mark.service'; -import { PrimeTemplate } from 'primeng/api'; - -export interface BookmarkFormData { - title: string; - color: string; - notes: string; - priority: number | null; -} - -@Component({ - selector: 'app-bookmark-edit-dialog', - standalone: true, - imports: [ - CommonModule, - FormsModule, - Dialog, - InputText, - ColorPicker, - Textarea, - InputNumber, - Button, - PrimeTemplate - ], - template: ` - - - @if (formData) { -
-
- - - @if (titleError) { - Title is required - } -
- -
- -
- - - -
-
- -
- - - {{ formData.notes.length || 0 }}/2000 -
- -
- - - -
-
- } - - -
- - - - -
-
-
- ` -}) -export class BookmarkEditDialogComponent implements OnChanges { - @Input() visible = false; - @Input() bookmark: BookMark | null = null; - @Input() isSaving = false; - - @Output() visibleChange = new EventEmitter(); - @Output() save = new EventEmitter(); - @Output() cancelEdit = new EventEmitter(); - - formData: BookmarkFormData | null = null; - titleError = false; - - ngOnChanges(changes: SimpleChanges): void { - if (changes['bookmark'] && this.bookmark) { - this.titleError = false; - this.formData = { - title: this.bookmark.title || '', - color: this.bookmark.color || '#3B82F6', - notes: this.bookmark.notes || '', - priority: this.bookmark.priority ?? 3 - }; - } - } - - onSave(): void { - if (!this.formData) return; - - if (!this.formData.title || !this.formData.title.trim()) { - this.titleError = true; - return; - } - - const request: UpdateBookMarkRequest = { - title: this.formData.title.trim(), - color: this.formData.color || undefined, - notes: this.formData.notes || undefined, - priority: this.formData.priority ?? undefined - }; - - this.save.emit(request); - } - - onDialogHide(): void { - // When dialog is closed via X button, treat it as cancel - this.onCancel(); - } - - onCancel(): void { - this.formData = null; // Clear form data - this.visible = false; - this.visibleChange.emit(false); - this.cancelEdit.emit(); - } -} \ No newline at end of file diff --git a/booklore-ui/src/app/features/readers/epub-reader/component/bookmark-view-dialog.component.ts b/booklore-ui/src/app/features/readers/epub-reader/component/bookmark-view-dialog.component.ts deleted file mode 100644 index 82ebb2496..000000000 --- a/booklore-ui/src/app/features/readers/epub-reader/component/bookmark-view-dialog.component.ts +++ /dev/null @@ -1,198 +0,0 @@ -import { Component, EventEmitter, Input, Output } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { Dialog } from 'primeng/dialog'; -import { Button } from 'primeng/button'; -import { BookMark } from '../../../../shared/service/book-mark.service'; -import { PrimeTemplate } from 'primeng/api'; - -@Component({ - selector: 'app-bookmark-view-dialog', - standalone: true, - imports: [ - CommonModule, - Dialog, - Button, - PrimeTemplate - ], - template: ` - - - @if (bookmark) { -
-
- -

{{ bookmark.title }}

-
- -
-
- Created - {{ bookmark.createdAt | date:'MMM d, y, h:mm a' }} -
-
- Priority - - {{ getPriorityLabel(bookmark.priority) }} - -
-
- -
- Notes - @if (bookmark.notes) { -

{{ bookmark.notes }}

- } @else { -

No notes added

- } -
-
- } - - - - - -
- `, - styles: [` - .bookmark-view-content { - padding: 0.5rem 0; - } - - .bookmark-view-header { - display: flex; - align-items: center; - gap: 0.75rem; - margin-bottom: 1.25rem; - padding-bottom: 1rem; - border-bottom: 1px solid var(--surface-border); - } - - .bookmark-view-color { - width: 12px; - height: 12px; - border-radius: 50%; - flex-shrink: 0; - } - - .bookmark-view-title { - margin: 0; - font-size: 1.125rem; - font-weight: 600; - color: var(--text-color); - word-break: break-word; - } - - .bookmark-view-details { - display: flex; - flex-direction: column; - gap: 0.75rem; - margin-bottom: 1.25rem; - } - - .bookmark-view-row { - display: flex; - justify-content: space-between; - align-items: center; - } - - .bookmark-view-label { - font-size: 0.875rem; - color: var(--text-color-secondary); - } - - .bookmark-view-value { - font-size: 0.875rem; - color: var(--text-color); - } - - .bookmark-view-priority { - font-size: 0.8rem; - font-weight: 500; - padding: 0.25rem 0.625rem; - border-radius: 1rem; - background: color-mix(in srgb, var(--primary-color) 15%, transparent); - color: var(--primary-color); - } - - .bookmark-view-priority[data-priority="1"] { - background: color-mix(in srgb, #ef4444 15%, transparent); - color: #ef4444; - } - - .bookmark-view-priority[data-priority="2"] { - background: color-mix(in srgb, #f97316 15%, transparent); - color: #f97316; - } - - .bookmark-view-priority[data-priority="3"] { - background: color-mix(in srgb, var(--primary-color) 15%, transparent); - color: var(--primary-color); - } - - .bookmark-view-priority[data-priority="4"], - .bookmark-view-priority[data-priority="5"] { - background: color-mix(in srgb, #6b7280 15%, transparent); - color: #6b7280; - } - - .bookmark-view-notes { - display: flex; - flex-direction: column; - gap: 0.5rem; - } - - .bookmark-view-notes-content { - margin: 0; - padding: 0.875rem; - background: var(--surface-ground); - border-radius: 0.5rem; - font-size: 0.875rem; - color: var(--text-color); - white-space: pre-wrap; - word-break: break-word; - line-height: 1.5; - } - - .bookmark-view-notes-empty { - margin: 0; - font-size: 0.875rem; - color: var(--text-color-secondary); - font-style: italic; - } - `] -}) -export class BookmarkViewDialogComponent { - @Input() visible = false; - @Input() bookmark: BookMark | null = null; - @Output() visibleChange = new EventEmitter(); - - onClose(): void { - this.visible = false; - this.visibleChange.emit(false); - } - - getPriorityLabel(priority: number | undefined): string { - if (priority === undefined) return 'Normal'; - if (priority <= 1) return 'Highest'; - if (priority === 2) return 'High'; - if (priority === 3) return 'Normal'; - if (priority === 4) return 'Low'; - return 'Lowest'; - } -} diff --git a/booklore-ui/src/app/features/readers/epub-reader/component/epub-reader.component.html b/booklore-ui/src/app/features/readers/epub-reader/component/epub-reader.component.html deleted file mode 100644 index a3f6251f6..000000000 --- a/booklore-ui/src/app/features/readers/epub-reader/component/epub-reader.component.html +++ /dev/null @@ -1,315 +0,0 @@ -
- @if (isLoading) { -
- -
- } - @if (isDrawerVisible) { -
- } - @if (isSettingsDrawerVisible) { -
- } -
-
-
- -
- Progress: {{ progressPercentage }}% -
- - -
- Table of Contents -
-
- - - -
- - Chapters -
-
- -
- - Bookmarks -
-
-
- - -
-
    - @for (chapter of chapters; track chapter) { -
  • - - {{ chapter.label }} -
  • - } -
-
-
- -
-
- - - - -
- @if (filteredBookmarks.length === 0) { -
- -

No bookmarks found

- {{ filterText ? 'Try a different search term' : 'Tap the bookmark icon to save your place' }} -
- } @else { -
    - @for (bookmark of filteredBookmarks; track bookmark.id) { -
  • - - {{ bookmark.title }} -
    - - - -
    -
  • - } -
- } -
-
-
-
-
-
-
-

{{ currentChapter }}

-
-
-
- @if (!locationsReady) { -
- -
- } - - -
- - - -
- Reader Settings -
-
-
-
-
- - Typography -
-
-
- -
- - {{ fontSize }}% - -
-
-
- - - -
-
- -
- {{ lineHeight }} - - -
-
-
- -
- {{ letterSpacing ?? 0 }} em - - -
-
-
-
-
-
- - Appearance -
-
-
- -
- @for (theme of themes; track theme) { - - } -
-
-
-
-
-
- - Layout -
-
-
- -
- - -
-
- @if (selectedFlow === 'paginated' && !isMobileDevice()) { -
- -
- - -
-
- } -
-
-
-
-
- - -
-
-
-
- @if (selectedFlow !== 'scrolled') { - - } - @if (selectedFlow !== 'scrolled') { - - } -
- - - - diff --git a/booklore-ui/src/app/features/readers/epub-reader/component/epub-reader.component.scss b/booklore-ui/src/app/features/readers/epub-reader/component/epub-reader.component.scss deleted file mode 100644 index 4bb28c2dc..000000000 --- a/booklore-ui/src/app/features/readers/epub-reader/component/epub-reader.component.scss +++ /dev/null @@ -1,799 +0,0 @@ -.epub-header { - display: flex; - flex-direction: row; - align-items: center; - justify-content: space-between; - padding-left: 1rem; - padding-right: 1rem; - position: absolute; - top: 0; - left: 0; - right: 0; - z-index: 1001; - background: linear-gradient(180deg, - rgba(0, 0, 0, 0.85) 0%, - rgba(0, 0, 0, 0.75) 100%); - border-bottom: 1px solid rgba(255, 255, 255, 0.1); - transition: transform 0.3s ease; - min-height: 3rem; - box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3); - pointer-events: auto; - - &.hidden { - transform: translateY(-100%); - pointer-events: none; - } -} - -.header-left { - display: flex; - align-items: center; - gap: 1rem; - flex: 0 0 auto; -} - -.header-center { - position: absolute; - left: 50%; - top: 50%; - transform: translate(-50%, -50%); - pointer-events: none; - max-width: 40%; - - @media (max-width: 768px) { - max-width: 50%; - } - - @media (max-width: 480px) { - max-width: 40%; - } - - p { - color: rgba(255, 255, 255, 0.95); - text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4); - font-weight: 500; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - margin: 0; - } -} - -.header-right { - display: flex; - align-items: center; - flex: 0 0 auto; - margin-left: auto; -} - -.progress-info { - display: flex; - align-items: center; - justify-content: center; -} - -.progress-percentage { - font-size: 0.85rem; - color: rgba(255, 255, 255, 0.95); - font-weight: 600; - display: flex; - align-items: center; - text-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); - padding: 0.375rem 0.75rem; - background: rgba(255, 255, 255, 0.1); - border-radius: 0.5rem; - backdrop-filter: blur(8px); - border: 1px solid rgba(255, 255, 255, 0.15); -} - -.progress-label { - @media (max-width: 768px) { - display: none; - } -} - -.epub-viewer-container { - display: flex; - flex-direction: column; - height: 100dvh; - position: relative; - overflow: hidden; -} - -.spinner-wrapper { - position: absolute; - top: 0; - left: 0; - right: 0; - bottom: 0; - display: flex; - align-items: center; - justify-content: center; - background: var(--ground-background); - z-index: 1002; -} - -#epubContainer { - flex: 1; - width: 100%; - position: relative; - overflow: auto; - pointer-events: auto; - - &.paginated-mode { - overflow: hidden; - } -} - -.menu-toggle-button, -.settings-toggle-button { - top: 10px; - z-index: 1000; - margin: 0; - - &::ng-deep .p-button { - background: rgba(255, 255, 255, 0.1) !important; - border: 1px solid rgba(255, 255, 255, 0.2) !important; - color: rgba(255, 255, 255, 0.95) !important; - backdrop-filter: blur(8px); - transition: all 0.2s ease !important; - - &:hover { - background: rgba(255, 255, 255, 0.2) !important; - border-color: rgba(255, 255, 255, 0.3) !important; - transform: scale(1.05); - box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); - } - - &:active { - transform: scale(0.95); - } - - .p-button-icon { - color: rgba(255, 255, 255, 0.95) !important; - text-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); - } - } -} - -.menu-toggle-button { - left: 10px; -} - -.settings-toggle-button { - right: 10px; -} - -.epub-controls-left, -.epub-controls-right { - position: absolute; - top: 50%; - transform: translateY(-50%); - z-index: 10; - font-size: 30px; - color: rgba(0, 0, 0, 0.5); - cursor: pointer; - background: none; - border: none; - padding: 10px; - transition: color 0.3s ease, transform 0.2s ease, opacity 0.3s ease; - - &.dark-theme { - color: rgba(255, 255, 255, 0.7); - - &:hover { - color: rgba(255, 255, 255, 0.95); - } - } - - @media (max-width: 768px) { - opacity: 0; - pointer-events: none; - - &.visible { - opacity: 1; - pointer-events: auto; - } - } -} - -.epub-controls-left { - left: 10px; -} - -.epub-controls-right { - right: 10px; -} - -.epub-controls-left:hover, -.epub-controls-right:hover { - color: rgba(0, 0, 0, 0.8); - transform: scale(1.1) translateY(-50%); -} - -.epub-controls-left:focus, -.epub-controls-right:focus { - outline: none; -} - -.chapter-list { - list-style: none; - padding: 0; - margin: 0; - display: flex; - flex-direction: column; -} - -.chapter-item { - padding: 0.4rem 0.25rem; - font-size: 14px; - color: var(--text-color); - cursor: pointer; - transition: all 0.2s ease; - border-radius: 0.5rem; - background-color: transparent; - display: flex; - align-items: center; - gap: 0.5rem; - margin-bottom: 0.25rem; - - .chapter-icon { - font-size: 0.75rem; - color: var(--primary-color); - opacity: 0; - transition: opacity 0.2s ease; - } - - .chapter-label { - flex: 1; - } - - &:hover { - background-color: color-mix(in srgb, var(--primary-color) 8%, transparent); - transform: translateX(4px); - - .chapter-icon { - opacity: 1; - } - } -} - -.current-chapter { - color: var(--primary-color); - font-weight: 600; - background: linear-gradient(135deg, - color-mix(in srgb, var(--primary-color) 15%, transparent), - color-mix(in srgb, var(--primary-color) 8%, transparent)); - box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary-color) 25%, transparent); - - .chapter-icon { - opacity: 1; - } - - &:hover { - background: linear-gradient(135deg, - color-mix(in srgb, var(--primary-color) 20%, transparent), - color-mix(in srgb, var(--primary-color) 12%, transparent)); - } -} - -.bookmark-list { - list-style: none; - padding: 0; - margin: 0; - display: flex; - flex-direction: column; -} - -.bookmark-item { - padding: 0.4rem 0.75rem; - font-size: 14px; - color: var(--text-color); - cursor: pointer; - transition: all 0.2s ease; - border-radius: 0.5rem; - background-color: transparent; - display: flex; - align-items: center; - gap: 0.5rem; - margin-bottom: 0.25rem; - position: relative; - - .bookmark-icon { - font-size: 0.875rem; - color: var(--primary-color); - flex-shrink: 0; - } - - .bookmark-label { - flex: 1; - font-weight: 500; - } - - .bookmark-actions { - opacity: 0; - display: flex; - gap: 0.25rem; - margin-left: auto; - transition: opacity 0.2s ease; - } - - .bookmark-action-btn { - background: transparent; - border: none; - cursor: pointer; - padding: 0.375rem; - border-radius: 0.375rem; - color: color-mix(in srgb, var(--text-color) 60%, transparent); - transition: all 0.2s ease; - flex-shrink: 0; - display: flex; - align-items: center; - justify-content: center; - - &:hover { - background: color-mix(in srgb, var(--primary-color) 15%, transparent); - color: var(--primary-color); - } - - &.delete:hover { - background: color-mix(in srgb, #ef4444 15%, transparent); - color: #ef4444; - } - - i { - font-size: 0.875rem; - } - } - - &:hover { - background-color: color-mix(in srgb, var(--primary-color) 8%, transparent); - transform: translateX(4px); - - .bookmark-actions { - opacity: 1; - } - } -} - -.bookmark-content { - display: flex; - align-items: center; - gap: 0.75rem; - cursor: pointer; - flex: 1; - color: var(--text-color); - font-size: 14px; - - i { - color: var(--primary-color); - font-size: 1rem; - } - - .bookmark-title { - font-weight: 500; - } - - &:hover { - color: var(--primary-color); - } -} - -.empty-state { - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - padding: 2rem 1rem; - text-align: center; - color: color-mix(in srgb, var(--text-color) 50%, transparent); - - i { - font-size: 2.5rem; - margin-bottom: 1rem; - opacity: 0.3; - } - - p { - font-size: 0.875rem; - font-weight: 500; - margin: 0 0 0.25rem 0; - } - - span { - font-size: 0.75rem; - opacity: 0.7; - } -} - -.settings-container { - display: flex; - flex-direction: column; - gap: 1.25rem; -} - -.settings-card { - background: color-mix(in srgb, var(--surface-card) 50%, var(--surface-ground)); - border: 1px solid color-mix(in srgb, var(--text-color) 10%, transparent); - border-radius: 0.75rem; - overflow: hidden; - transition: all 0.2s ease; - - &:hover { - box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); - border-color: color-mix(in srgb, var(--primary-color) 20%, transparent); - } - - .card-header { - display: flex; - align-items: center; - gap: 0.625rem; - padding: 1rem 1.125rem; - background: linear-gradient(135deg, - color-mix(in srgb, var(--primary-color) 8%, transparent), - color-mix(in srgb, var(--primary-color) 4%, transparent)); - border-bottom: 1px solid color-mix(in srgb, var(--text-color) 8%, transparent); - - i { - color: var(--primary-color); - font-size: 1rem; - } - - span { - font-weight: 600; - font-size: 0.9375rem; - color: var(--text-color); - } - } - - .card-content { - padding: 1.5rem; - display: flex; - flex-direction: column; - gap: 1.25rem; - } -} - -.setting-row { - display: flex; - flex-direction: column; - gap: 0.625rem; - - > label { - font-size: 0.8125rem; - font-weight: 600; - color: var(--text-color); - text-transform: uppercase; - letter-spacing: 0.025em; - } -} - -.font-size-controls { - display: flex; - align-items: center; - gap: 1rem; - background: color-mix(in srgb, var(--text-color) 5%, transparent); - padding: 0.5rem; - border-radius: 0.5rem; - width: fit-content; - - .control-btn { - background: var(--primary-color); - color: white; - border: none; - width: 2rem; - height: 2rem; - border-radius: 0.375rem; - cursor: pointer; - transition: all 0.2s ease; - display: flex; - align-items: center; - justify-content: center; - - &:hover { - transform: scale(1.05); - box-shadow: 0 2px 8px color-mix(in srgb, var(--primary-color) 40%, transparent); - } - - &:active { - transform: scale(0.95); - } - } - - .font-size-value { - font-weight: 600; - color: var(--text-color); - min-width: 3rem; - text-align: center; - } -} - -.slider-container { - display: flex; - flex-direction: column; - gap: 0.5rem; - padding: 0 0.75rem; - - .slider-value { - font-size: 0.85rem; - font-weight: 600; - color: var(--primary-color); - align-self: flex-end; - } -} - -.theme-selector { - display: flex; - gap: 0.75rem; - flex-wrap: wrap; - - .theme-option { - width: 3rem; - height: 3rem; - border-radius: 0.5rem; - border: 2px solid transparent; - cursor: pointer; - transition: all 0.2s ease; - position: relative; - display: flex; - align-items: center; - justify-content: center; - - i { - color: white; - font-size: 1rem; - font-weight: bold; - text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); - } - - &:hover { - transform: scale(1.1); - box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); - } - - &.selected { - border-color: var(--primary-color); - box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-color) 25%, transparent); - } - } -} - -.toggle-group { - display: flex; - gap: 0.5rem; - background: color-mix(in srgb, var(--text-color) 5%, transparent); - padding: 0.375rem; - border-radius: 0.5rem; - - .toggle-option { - flex: 1; - display: flex; - align-items: center; - justify-content: center; - gap: 0.5rem; - padding: 0.5rem 0.8rem; - background: transparent; - border: none; - border-radius: 0.375rem; - cursor: pointer; - transition: all 0.2s ease; - color: color-mix(in srgb, var(--text-color) 70%, transparent); - font-weight: 500; - font-size: 0.95rem; - - i { - font-size: 0.95rem; - } - - &:hover { - background: color-mix(in srgb, var(--text-color) 8%, transparent); - color: var(--text-color); - } - - &.active { - background: var(--primary-color); - color: white; - box-shadow: 0 2px 6px color-mix(in srgb, var(--primary-color) 30%, transparent); - } - } -} - -::ng-deep .p-divider.p-divider-horizontal { - margin: 0.25rem 0 0.5rem 0 !important; -} - -.drawer-header { - display: flex; - align-items: center; - gap: 0.75rem; - - i { - color: var(--primary-color); - } - - .drawer-title { - font-size: 1.25rem; - font-weight: 600; - color: var(--text-color); - } -} - -.drawer-section { - margin-bottom: 1.5rem; - - .section-header { - display: flex; - align-items: center; - gap: 0.5rem; - margin-bottom: 1rem; - padding-bottom: 0.5rem; - border-bottom: 1px solid color-mix(in srgb, var(--text-color) 10%, transparent); - - i { - color: var(--primary-color); - font-size: 1rem; - } - - h3 { - font-size: 0.875rem; - font-weight: 600; - color: var(--text-color); - text-transform: uppercase; - letter-spacing: 0.05em; - margin: 0; - } - } - - .section-content { - padding: 0 0.25rem; - } -} - -.drawer-divider { - height: 1px; - background: linear-gradient(to right, transparent, color-mix(in srgb, var(--text-color) 20%, transparent), transparent); - margin: 1.5rem 0; -} - -::ng-deep .p-drawer .p-tabs { - .p-tablist { - background: transparent; - border: none; - border-bottom: 2px solid color-mix(in srgb, var(--text-color) 10%, transparent); - padding: 0 1rem; - margin: 0 -1rem; - display: flex; - gap: 0; - - .p-tab { - background: transparent; - border: none; - border-bottom: 2px solid transparent; - padding: 1rem 1.5rem; - margin-bottom: -2px; - transition: all 0.2s ease; - cursor: pointer; - - &:hover { - background: color-mix(in srgb, var(--primary-color) 5%, transparent); - } - - &[aria-selected="true"] { - border-bottom-color: var(--primary-color); - - .tab-header { - color: var(--primary-color); - } - } - } - - .p-tab:focus-visible { - box-shadow: none; - outline: 2px solid color-mix(in srgb, var(--primary-color) 30%, transparent); - outline-offset: -2px; - } - } - - .p-tabpanels { - background: transparent; - padding: 0; - - .p-tabpanel { - padding: 0; - } - } -} - -::ng-deep .p-drawer-left { - .p-drawer-content { - padding: 0 !important; - } -} - -.tab-header { - display: flex; - align-items: center; - gap: 0.5rem; - font-size: 0.9375rem; - font-weight: 500; - - i { - font-size: 1rem; - } -} - -.tab-content { - padding: 1.25rem 0.5rem; -} - -::ng-deep .header-right { - .p-button { - background: rgba(255, 255, 255, 0.1) !important; - border: 1px solid rgba(255, 255, 255, 0.2) !important; - color: rgba(255, 255, 255, 0.95) !important; - backdrop-filter: blur(8px); - transition: all 0.2s ease !important; - - &:hover:not(:disabled) { - background: rgba(255, 255, 255, 0.2) !important; - border-color: rgba(255, 255, 255, 0.3) !important; - transform: scale(1.05); - box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); - } - - &:active:not(:disabled) { - transform: scale(0.95); - } - - &:disabled { - opacity: 0.5; - cursor: not-allowed; - } - - .p-button-icon { - color: rgba(255, 255, 255, 0.95) !important; - text-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); - - &.pi-bookmark-fill { - color: #fbbf24 !important; - filter: drop-shadow(0 2px 6px rgba(251, 191, 36, 0.5)); - } - } - } -} - -.location-indicator { - display: flex; - align-items: center; - justify-content: center; - padding: 0.5rem; - - .dot { - width: 12px; - height: 12px; - border-radius: 50%; - background: #fbbf24; - box-shadow: 0 0 8px rgba(251, 191, 36, 0.6); - animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; - } -} - -@keyframes pulse { - 0%, 100% { - opacity: 1; - } - 50% { - opacity: 0.5; - } -} - -.drawer-backdrop { - position: fixed; - top: 0; - left: 0; - right: 0; - bottom: 0; - background-color: rgba(0, 0, 0, 0.4); - z-index: 999; - cursor: pointer; -} diff --git a/booklore-ui/src/app/features/readers/epub-reader/component/epub-reader.component.ts b/booklore-ui/src/app/features/readers/epub-reader/component/epub-reader.component.ts deleted file mode 100644 index ec5f4fe85..000000000 --- a/booklore-ui/src/app/features/readers/epub-reader/component/epub-reader.component.ts +++ /dev/null @@ -1,1142 +0,0 @@ -import {Component, ElementRef, inject, NgZone, OnDestroy, OnInit, ViewChild} from '@angular/core'; -import ePub from 'epubjs'; -import {Drawer} from 'primeng/drawer'; -import {firstValueFrom, forkJoin, Subscription} from 'rxjs'; -import {Button} from 'primeng/button'; -import {InputText} from 'primeng/inputtext'; -import {CommonModule, Location} from '@angular/common'; -import {FormsModule} from '@angular/forms'; -import {ActivatedRoute} from '@angular/router'; -import {Book, BookSetting} from '../../../book/model/book.model'; -import {BookService} from '../../../book/service/book.service'; -import {Select} from 'primeng/select'; -import {UserService} from '../../../settings/user-management/user.service'; -import {ProgressSpinner} from 'primeng/progressspinner'; -import {MessageService, PrimeTemplate} from 'primeng/api'; -import {BookMark, BookMarkService, UpdateBookMarkRequest} from '../../../../shared/service/book-mark.service'; -import {Tooltip} from 'primeng/tooltip'; -import {Slider} from 'primeng/slider'; -import {FALLBACK_EPUB_SETTINGS, getChapter} from '../epub-reader-helper'; -import {ReadingSessionService} from '../../../../shared/service/reading-session.service'; -import {EpubTheme, EpubThemeUtil} from '../epub-theme-util'; -import {PageTitleService} from "../../../../shared/service/page-title.service"; -import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs'; -import {IconField} from 'primeng/iconfield'; -import {InputIcon} from 'primeng/inputicon'; -import {BookmarkEditDialogComponent} from './bookmark-edit-dialog.component'; -import {BookmarkViewDialogComponent} from './bookmark-view-dialog.component'; -import {CustomFontService} from '../../../../shared/service/custom-font.service'; -import {CustomFont} from '../../../../shared/model/custom-font.model'; -import {addCustomFontsToDropdown} from '../../../../shared/util/custom-font.util'; - -@Component({ - selector: 'app-epub-reader', - templateUrl: './epub-reader.component.html', - styleUrls: ['./epub-reader.component.scss'], - imports: [CommonModule, FormsModule, Drawer, Button, Select, ProgressSpinner, Tooltip, Slider, PrimeTemplate, Tabs, TabList, Tab, TabPanels, TabPanel, IconField, InputIcon, BookmarkEditDialogComponent, BookmarkViewDialogComponent, InputText], - standalone: true -}) -export class EpubReaderComponent implements OnInit, OnDestroy { - @ViewChild('epubContainer', {static: false}) epubContainer!: ElementRef; - - isLoading = true; - chapters: { label: string; href: string; level: number }[] = []; - currentChapter = ''; - currentChapterHref: string | null = null; - isDrawerVisible = false; - isSettingsDrawerVisible = false; - bookmarks: BookMark[] = []; - currentCfi: string | null = null; - isBookmarked = false; - isAddingBookmark = false; - isDeletingBookmark = false; - isEditingBookmark = false; - private routeSubscription?: Subscription; - - filterText = ''; - viewDialogVisible = false; - selectedBookmark: BookMark | null = null; - - public locationsReady = false; - public approxProgress = 0; - public exactProgress = 0; - public progressPercentage = 0; - - showControls = !this.isMobileDevice(); - showHeader = true; - private hideControlsTimeout?: number; - private hideHeaderTimeout?: number; - private isMouseInTopRegion = false; - private headerShownByMobileTouch = false; - private currentIframe: HTMLIFrameElement | null = null; - private iframeTouchHandler: ((event: TouchEvent) => void) | null = null; - private iframeClickHandler: ((event: MouseEvent) => void) | null = null; - - editingBookmark: BookMark | null = null; - showEditBookmarkDialog = false; - - private book: any; - private epubArrayBuffer: ArrayBuffer | null = null; - private rendition: any; - private keyListener: (e: KeyboardEvent) => void = () => { - }; - - fontSize?: number = 100; - selectedFlow?: string = 'paginated'; - selectedTheme?: string = 'white'; - selectedFontType?: string | null = null; - selectedSpread?: string = 'double'; - lineHeight?: number; - letterSpacing?: number; - selectedCustomFontId?: number | null = null; - customFonts: CustomFont[] = []; - customFontsReady = false; - private customFontBlobUrls = new Map(); - - fontTypes: any[] = [ - {label: "Publisher's Default", value: null}, - {label: 'Serif', value: 'serif'}, - {label: 'Sans Serif', value: 'sans-serif'}, - {label: 'Roboto', value: 'roboto'}, - {label: 'Cursive', value: 'cursive'}, - {label: 'Monospace', value: 'monospace'}, - ]; - - themes: any[] = [ - {label: 'White', value: EpubTheme.WHITE}, - {label: 'Black', value: EpubTheme.BLACK}, - {label: 'Grey', value: EpubTheme.GREY}, - {label: 'Sepia', value: EpubTheme.SEPIA}, - {label: 'Green', value: EpubTheme.GREEN}, - {label: 'Lavender', value: EpubTheme.LAVENDER}, - {label: 'Cream', value: EpubTheme.CREAM}, - {label: 'Light Blue', value: EpubTheme.LIGHT_BLUE}, - {label: 'Peach', value: EpubTheme.PEACH}, - {label: 'Mint', value: EpubTheme.MINT}, - {label: 'Dark Slate', value: EpubTheme.DARK_SLATE}, - {label: 'Dark Olive', value: EpubTheme.DARK_OLIVE}, - {label: 'Dark Purple', value: EpubTheme.DARK_PURPLE}, - {label: 'Dark Teal', value: EpubTheme.DARK_TEAL}, - {label: 'Dark Brown', value: EpubTheme.DARK_BROWN}, - ]; - - private route = inject(ActivatedRoute); - private location = inject(Location); - private userService = inject(UserService); - private bookService = inject(BookService); - private messageService = inject(MessageService); - private ngZone = inject(NgZone); - private pageTitle = inject(PageTitleService); - private bookMarkService = inject(BookMarkService); - private readingSessionService = inject(ReadingSessionService); - private customFontService = inject(CustomFontService); - - epub!: Book; - - ngOnInit(): void { - this.routeSubscription = this.route.paramMap.subscribe(async (params) => { - this.isLoading = true; - const bookId = +params.get('bookId')!; - - try { - const fonts = await firstValueFrom(this.customFontService.getUserFonts()); - this.customFonts = fonts; - await this.customFontService.loadAllFonts(fonts); - await this.cacheCustomFontsAsBlobs(fonts); - addCustomFontsToDropdown(fonts, this.fontTypes, 'select'); - } catch (err) { - console.error('Failed to load custom fonts:', err); - } finally { - this.customFontsReady = true; - } - - const myself$ = this.userService.getMyself(); - const epub$ = this.bookService.getBookByIdFromAPI(bookId, false); - const epubData$ = this.bookService.getFileContent(bookId); - const bookSetting$ = this.bookService.getBookSetting(bookId); - const bookmarks$ = this.bookMarkService.getBookmarksForBook(bookId); - - forkJoin([myself$, epub$, epubData$, bookSetting$, bookmarks$]).subscribe({ - next: ([myself, epub, epubData, bookSetting, bookmarks]) => { - this.epub = epub; - this.bookmarks = bookmarks; - this.updateBookmarkStatus(); - const individualSetting = bookSetting?.epubSettings; - const fileReader = new FileReader(); - - this.pageTitle.setBookPageTitle(epub); - - fileReader.onload = () => { - this.epubArrayBuffer = fileReader.result as ArrayBuffer; - - const settingScope = myself.userSettings.perBookSetting.epub; - const globalSettings = myself.userSettings.epubReaderSetting; - - const resolvedFlow = settingScope === 'Global' ? globalSettings.flow : individualSetting?.flow; - const resolvedFontSize = settingScope === 'Global' ? globalSettings.fontSize : individualSetting?.fontSize; - const resolvedFontFamily = settingScope === 'Global' ? globalSettings.font : individualSetting?.font; - const resolvedTheme = settingScope === 'Global' ? globalSettings.theme : individualSetting?.theme; - const resolvedLineHeight = settingScope === 'Global' ? globalSettings.lineHeight : individualSetting?.lineHeight; - const resolvedLetterSpacing = settingScope === 'Global' ? globalSettings.letterSpacing : individualSetting?.letterSpacing; - const resolvedSpread = settingScope === 'Global' ? globalSettings.spread || 'double' : individualSetting?.spread || 'double'; - const resolvedCustomFontId = settingScope === 'Global' ? globalSettings.customFontId : individualSetting?.customFontId; - - if (resolvedTheme != null) this.selectedTheme = resolvedTheme; - if (resolvedFontFamily != null) this.selectedFontType = resolvedFontFamily; - if (resolvedFontSize != null) this.fontSize = resolvedFontSize; - if (resolvedLineHeight != null) this.lineHeight = resolvedLineHeight; - if (resolvedLetterSpacing != null) this.letterSpacing = resolvedLetterSpacing; - if (resolvedFlow != null) this.selectedFlow = resolvedFlow; - if (resolvedSpread != null) this.selectedSpread = resolvedSpread; - - if (resolvedCustomFontId != null) { - this.selectedFontType = `custom:${resolvedCustomFontId}`; - } - - this.initBook(); - this.initRendition(); - }; - - fileReader.readAsArrayBuffer(epubData); - }, - error: () => { - this.messageService.add({ - severity: 'error', - summary: 'Error', - detail: 'Failed to load the book', - }); - this.isLoading = false; - }, - }); - }); - } - - get filteredBookmarks(): BookMark[] { - let filtered = this.bookmarks; - - if (this.filterText && this.filterText.trim()) { - const lowerFilter = this.filterText.toLowerCase().trim(); - filtered = filtered.filter(b => - (b.title && b.title.toLowerCase().includes(lowerFilter)) || - (b.notes && b.notes.toLowerCase().includes(lowerFilter)) - ); - } - - return [...filtered].sort((a, b) => { - const priorityA = a.priority ?? 3; - const priorityB = b.priority ?? 3; - - if (priorityA !== priorityB) { - return priorityA - priorityB; - } - - const dateA = a.createdAt ? new Date(a.createdAt).getTime() : 0; - const dateB = b.createdAt ? new Date(b.createdAt).getTime() : 0; - - return dateB - dateA; - }); - } - - openViewDialog(bookmark: BookMark): void { - this.selectedBookmark = bookmark; - this.viewDialogVisible = true; - } - - updateThemeStyle(): void { - this.applyCombinedTheme(); - this.updateViewerSetting(); - } - - changeScrollMode(): void { - if (!this.rendition || !this.book) return; - - const cfi = this.rendition.currentLocation()?.start?.cfi; - const locations = this.book.locations.save(); - - this.initBook(locations); - this.initRendition(cfi); - this.updateViewerSetting(); - } - - changeSpreadMode(): void { - if (!this.rendition || !this.book || this.selectedFlow === 'scrolled' || this.isMobileDevice()) return; - - const cfi = this.rendition.currentLocation()?.start?.cfi; - const locations = this.book.locations.save(); - - this.initBook(locations); - this.initRendition(cfi); - this.updateViewerSetting(); - } - - changeThemes(): void { - this.applyCombinedTheme(); - this.updateViewerSetting(); - } - - private applyCombinedTheme(): void { - EpubThemeUtil.applyTheme( - this.rendition, - this.selectedTheme ?? 'white', - this.selectedFontType ?? undefined, - this.fontSize, - this.lineHeight, - this.letterSpacing - ); - } - - updateFontSize(): void { - if (this.rendition) { - this.rendition.themes.override('font-size', `${this.fontSize}%`); - this.updateViewerSetting(); - } - } - - async changeFontType(): Promise { - const result = await this.applyEpubTheme(); - - if (!result.success) { - this.selectedFontType = null; - this.selectedCustomFontId = null; - } else if (result.customFontId !== undefined) { - this.selectedCustomFontId = result.customFontId; - } - - this.updateViewerSetting(); - } - - private async cacheCustomFontsAsBlobs(fonts: CustomFont[]): Promise { - const promises = fonts.map(async (font) => { - try { - const fontUrl = this.customFontService.getFontUrl(font.id); - const fontUrlWithToken = this.customFontService.appendToken(fontUrl); - const response = await fetch(fontUrlWithToken); - const blob = await response.blob(); - const blobUrl = URL.createObjectURL(blob); - this.customFontBlobUrls.set(font.id, blobUrl); - } catch (error) { - console.error(`Failed to cache font ${font.fontName}:`, error); - } - }); - await Promise.all(promises); - } - - private async applyEpubTheme(): Promise<{ success: boolean, customFontId?: number | null }> { - if (!this.rendition) return {success: false}; - - let fontFamily = this.selectedFontType; - let customFontToInject: CustomFont | null = null; - let customFontId: number | null = null; - - if (this.selectedFontType?.startsWith('custom:')) { - const fontId = parseInt(this.selectedFontType.split(':')[1]); - const customFont = this.customFonts.find(f => f.id === fontId); - if (customFont) { - try { - await this.customFontService.loadFontFace(customFont); - if (this.customFontService.isFontLoaded(customFont.fontName)) { - fontFamily = customFont.fontName; - customFontId = fontId; - customFontToInject = customFont; - } else { - return {success: false}; - } - } catch (error) { - console.error('Failed to load custom font:', error); - this.messageService.add({ - severity: 'warn', - summary: 'Custom fonts not loaded', - detail: 'Your custom fonts could not be loaded. The reader will use default fonts instead.', - }); - return {success: false}; - } - } - } else { - customFontId = null; - } - - if (customFontToInject) { - const blobUrl = this.customFontBlobUrls.get(customFontToInject.id); - if (!blobUrl) { - console.error('Blob URL not found for custom font'); - return {success: false}; - } - this.rendition.themes.default({ - '@font-face': [{ - 'font-family': `"${customFontToInject.fontName}"`, - 'src': `url(${blobUrl})`, - 'font-weight': 'normal', - 'font-style': 'normal' - }] - }); - } else { - this.rendition.themes.default({}); - } - - if (fontFamily) { - this.rendition.themes.font(customFontToInject ? `"${fontFamily}"` : fontFamily); - } else { - this.rendition.themes.font(''); - } - - const baseTheme = EpubThemeUtil.themesMap.get(this.selectedTheme ?? 'black') || {}; - const combinedTheme = { - ...baseTheme, - body: { - ...baseTheme.body, - ...(this.lineHeight != null ? {'line-height': this.lineHeight} : {}), - ...(this.letterSpacing != null ? {'letter-spacing': `${this.letterSpacing}em`} : {}), - }, - '*': { - ...baseTheme['*'], - ...(this.lineHeight != null ? {'line-height': this.lineHeight} : {}), - ...(this.letterSpacing != null ? {'letter-spacing': `${this.letterSpacing}em`} : {}), - }, - }; - - this.rendition.themes.override('font-size', `${this.fontSize}%`); - this.rendition.themes.register('custom', combinedTheme); - this.rendition.themes.select('custom'); - - return {success: true, customFontId}; - } - - increaseFontSize(): void { - this.fontSize = Math.min(Number(this.fontSize) + 10, FALLBACK_EPUB_SETTINGS.maxFontSize); - this.updateFontSize(); - } - - decreaseFontSize(): void { - this.fontSize = Math.max(Number(this.fontSize) - 10, FALLBACK_EPUB_SETTINGS.minFontSize); - this.updateFontSize(); - } - - private updateViewerSetting(): void { - const epubSettings: any = {}; - - if (this.selectedTheme) epubSettings.theme = this.selectedTheme; - if (this.selectedFontType) epubSettings.font = this.selectedFontType; - if (this.fontSize) epubSettings.fontSize = this.fontSize; - if (this.selectedFlow) epubSettings.flow = this.selectedFlow; - if (this.selectedSpread === 'single' || this.selectedSpread === 'double') epubSettings.spread = this.selectedSpread; - if (this.lineHeight) epubSettings.lineHeight = this.lineHeight; - if (this.letterSpacing) epubSettings.letterSpacing = this.letterSpacing; - if (this.selectedCustomFontId != null) epubSettings.customFontId = this.selectedCustomFontId; - - const bookSetting: BookSetting = { - epubSettings: epubSettings - }; - - this.bookService.updateViewerSetting(bookSetting, this.epub.id).subscribe(); - } - - private setupKeyListener(): void { - this.keyListener = (e: KeyboardEvent) => { - switch (e.key) { - case 'ArrowLeft': - this.prevPage(); - break; - case 'ArrowRight': - this.nextPage(); - break; - default: - break; - } - }; - if (this.rendition) { - this.rendition.on('keyup', this.keyListener); - } - document.addEventListener('keyup', this.keyListener); - } - - private setupTouchListener(): void { - if (!this.isMobileDevice()) return; - - const container = this.epubContainer.nativeElement; - - container.addEventListener('touchend', (event: TouchEvent) => { - event.stopPropagation(); - this.ngZone.run(() => { - this.handleTouchEnd(event); - }); - }, {passive: false}); - - container.addEventListener('click', (event: MouseEvent) => { - event.stopPropagation(); - this.ngZone.run(() => { - this.handleClickAsTap(event); - }); - }, {capture: true}); - - this.rendition.on('rendered', () => { - const iframe = this.epubContainer.nativeElement.querySelector('iframe'); - - if (iframe && iframe !== this.currentIframe) { - if (this.currentIframe && this.currentIframe.contentDocument) { - if (this.iframeTouchHandler) { - this.currentIframe.contentDocument.removeEventListener('touchend', this.iframeTouchHandler, true); - } - if (this.iframeClickHandler) { - this.currentIframe.contentDocument.removeEventListener('click', this.iframeClickHandler, true); - } - } - - this.currentIframe = iframe; - - if (iframe.contentDocument) { - this.iframeTouchHandler = (event: TouchEvent) => { - event.stopPropagation(); - event.preventDefault(); - this.ngZone.run(() => { - this.handleTouchEnd(event); - }); - }; - - this.iframeClickHandler = (event: MouseEvent) => { - event.stopPropagation(); - event.preventDefault(); - this.ngZone.run(() => { - this.handleClickAsTap(event); - }); - }; - - iframe.contentDocument.addEventListener('touchend', this.iframeTouchHandler, {passive: false, capture: true}); - iframe.contentDocument.addEventListener('click', this.iframeClickHandler, {capture: true}); - } - } - }); - } - - public handleTouchEnd(event: TouchEvent): void { - if (!this.isMobileDevice()) return; - - const touch = event.changedTouches[0]; - let touchX = touch.clientX; - let touchY = touch.clientY; - - if (event.target && (event.target as HTMLElement).ownerDocument !== document) { - const iframe = this.currentIframe; - if (iframe) { - const iframeRect = iframe.getBoundingClientRect(); - touchX = touch.clientX + iframeRect.left; - touchY = touch.clientY + iframeRect.top; - } - } - - const screenWidth = window.innerWidth; - const screenHeight = window.innerHeight; - - const isTopTouch = touchY < screenHeight * 0.2; - const isInTapZoneVertically = touchY >= screenHeight * 0.2; - - if (isTopTouch) { - if (!this.showHeader) { - this.showHeader = true; - this.headerShownByMobileTouch = true; - this.clearHeaderTimeout(); - this.startHeaderAutoHide(); - } else if (this.headerShownByMobileTouch) { - this.showHeader = false; - this.headerShownByMobileTouch = false; - this.clearHeaderTimeout(); - } - return; - } - - if (isInTapZoneVertically) { - const leftZoneEnd = screenWidth / 3; - const rightZoneStart = screenWidth * (2 / 3); - - if (touchX < leftZoneEnd) { - this.prevPage(); - return; - } - - if (touchX > rightZoneStart) { - this.nextPage(); - return; - } - - this.showControlsTemporarily(); - } - } - - private handleClickAsTap(event: MouseEvent): void { - if (!this.isMobileDevice()) return; - - let clickX = event.clientX; - let clickY = event.clientY; - - if (event.target && (event.target as HTMLElement).ownerDocument !== document) { - const iframe = this.currentIframe; - if (iframe) { - const iframeRect = iframe.getBoundingClientRect(); - clickX = event.clientX + iframeRect.left; - clickY = event.clientY + iframeRect.top; - } - } - - const screenWidth = window.innerWidth; - const screenHeight = window.innerHeight; - - const isTopClick = clickY < screenHeight * 0.2; - const isInTapZoneVertically = clickY >= screenHeight * 0.2; - - if (isTopClick) { - if (!this.showHeader) { - this.showHeader = true; - this.headerShownByMobileTouch = true; - this.clearHeaderTimeout(); - this.startHeaderAutoHide(); - } else if (this.headerShownByMobileTouch) { - this.showHeader = false; - this.headerShownByMobileTouch = false; - this.clearHeaderTimeout(); - } - return; - } - - if (isInTapZoneVertically) { - const leftZoneEnd = screenWidth / 3; - const rightZoneStart = screenWidth * (2 / 3); - - if (clickX < leftZoneEnd) { - this.prevPage(); - return; - } - - if (clickX > rightZoneStart) { - this.nextPage(); - return; - } - - this.showControlsTemporarily(); - } - } - - closeReader(): void { - if (this.readingSessionService.isSessionActive()) { - this.readingSessionService.endSession( - this.currentCfi || undefined, - this.progressPercentage - ); - } - this.location.back(); - } - - toggleDrawer(): void { - this.isDrawerVisible = !this.isDrawerVisible; - if (this.isDrawerVisible) { - this.clearHeaderTimeout(); - } else { - this.startHeaderAutoHide(); - } - } - - toggleSettingsDrawer(): void { - this.isSettingsDrawerVisible = !this.isSettingsDrawerVisible; - if (this.isSettingsDrawerVisible) { - this.clearHeaderTimeout(); - } else { - this.startHeaderAutoHide(); - } - } - - navigateToChapter(chapter: { label: string; href: string; level: number }): void { - if (this.rendition) { - this.rendition.display(chapter.href).then(() => { - const location = this.rendition.currentLocation(); - this.readingSessionService.updateProgress( - location?.start?.cfi, - this.progressPercentage - ); - }); - } - } - - prevPage(): void { - if (this.rendition) { - this.rendition.prev(); - } - } - - nextPage(): void { - if (this.rendition) { - this.rendition.next(); - } - } - - isMobileDevice(): boolean { - return window.innerWidth <= 768; - } - - private trackProgress(): void { - if (!this.book || !this.rendition) return; - this.rendition.on('relocated', (location: any) => { - this.updateCurrentChapter(location); - const cfi = location.end.cfi; - this.currentCfi = location.start.cfi; - this.updateBookmarkStatus(); - const currentIndex = location.start.index; - const totalSpineItems = this.book.spine.items.length; - let percentage: number; - - if (this.locationsReady && this.book.locations.total > 0) { - percentage = this.book.locations.percentageFromCfi(cfi); - this.exactProgress = Math.round(percentage * 1000) / 10; - this.progressPercentage = Math.round(percentage * 1000) / 10; - } else { - if (totalSpineItems > 0) { - percentage = (currentIndex + 1) / totalSpineItems; - } else { - percentage = 0; - } - this.approxProgress = Math.round(percentage * 1000) / 10; - this.progressPercentage = Math.round(percentage * 1000) / 10; - } - - //this.bookService.saveEpubProgress(this.epub.id, cfi, '', Math.round(percentage * 1000) / 10).subscribe(); - - this.readingSessionService.updateProgress( - location.start.cfi, - this.progressPercentage - ); - }); - - this.book.ready.then(() => { - if (this.locationsReady && this.book.locations.total > 0) { - return Promise.resolve(); - } - return this.book.locations.generate(1600); - }).then(() => { - this.locationsReady = true; - if (this.rendition.currentLocation()) { - const location = this.rendition.currentLocation(); - const cfi = location.end.cfi; - const percentage = this.book.locations.percentageFromCfi(cfi); - this.progressPercentage = Math.round(percentage * 1000) / 10; - - this.readingSessionService.startSession(this.epub.id, "EPUB", location.start.cfi, this.progressPercentage); - } - }).catch(() => { - this.locationsReady = false; - const location = this.rendition.currentLocation(); - if (location) { - this.readingSessionService.startSession(this.epub.id, "EPUB", location.start.cfi, this.progressPercentage); - } - }); - } - - private initBook(restoreLocations?: string): void { - if (!this.epubArrayBuffer) return; - - if (this.book) { - this.book.destroy(); - } - - this.book = ePub(this.epubArrayBuffer); - - this.book.loaded.navigation.then((nav: any) => { - this.chapters = this.extractChapters(nav.toc, 0); - }); - - if (restoreLocations) { - this.book.ready.then(() => { - this.book.locations.load(restoreLocations); - this.locationsReady = true; - }); - } else { - this.locationsReady = false; - } - } - - private initRendition(targetCfi?: string): void { - if (!this.book) return; - - if (this.rendition) { - try { - this.rendition.destroy(); - } catch (e) { - console.warn('Error destroying rendition', e); - } - } - - this.rendition = this.book.renderTo(this.epubContainer.nativeElement, { - flow: this.selectedFlow ?? 'paginated', - manager: this.selectedFlow === 'scrolled' ? 'continuous' : 'default', - width: '100%', - height: '100%', - spread: this.selectedFlow === 'paginated' && !this.isMobileDevice() ? (this.selectedSpread === 'single' ? 'none' : this.selectedSpread) : 'none', - allowScriptedContent: true, - }); - - const baseTheme = EpubThemeUtil.themesMap.get(this.selectedTheme ?? 'black') || {}; - const combinedTheme = { - ...baseTheme, - body: { - ...(baseTheme.body || {}), - ...(this.lineHeight != null ? {'line-height': this.lineHeight} : {}), - ...(this.letterSpacing != null ? {'letter-spacing': `${this.letterSpacing}em`} : {}), - }, - '*': { - ...(baseTheme['*'] || {}), - ...(this.lineHeight != null ? {'line-height': this.lineHeight} : {}), - ...(this.letterSpacing != null ? {'letter-spacing': `${this.letterSpacing}em`} : {}), - }, - }; - - this.rendition.themes.override('font-size', `${this.fontSize}%`); - this.rendition.themes.register('custom', combinedTheme); - this.rendition.themes.select('custom'); - - const displayPromise = targetCfi - ? this.rendition.display(targetCfi) - : (this.epub?.epubProgress?.cfi ? this.rendition.display(this.epub.epubProgress.cfi) : this.rendition.display()); - - displayPromise.then(async () => { - const result = await this.applyEpubTheme(); - - if (!result.success) { - this.selectedFontType = null; - this.selectedCustomFontId = null; - } else if (result.customFontId !== undefined) { - this.selectedCustomFontId = result.customFontId; - } - - this.updateCurrentChapter(this.rendition.currentLocation()); - this.setupKeyListener(); - this.trackProgress(); - this.setupTouchListener(); - this.isLoading = false; - this.startHeaderAutoHide(); - }); - } - - ngOnDestroy(): void { - if (this.readingSessionService.isSessionActive()) { - this.readingSessionService.endSession( - this.currentCfi || undefined, - this.progressPercentage - ); - } - - this.customFontBlobUrls.forEach(url => URL.revokeObjectURL(url)); - this.customFontBlobUrls.clear(); - - this.routeSubscription?.unsubscribe(); - - if (this.currentIframe && this.currentIframe.contentDocument) { - if (this.iframeTouchHandler) { - this.currentIframe.contentDocument.removeEventListener('touchend', this.iframeTouchHandler, true); - } - if (this.iframeClickHandler) { - this.currentIframe.contentDocument.removeEventListener('click', this.iframeClickHandler, true); - } - } - - if (this.rendition) { - this.rendition.off('keyup', this.keyListener); - } - document.removeEventListener('keyup', this.keyListener); - - if (this.hideControlsTimeout) { - window.clearTimeout(this.hideControlsTimeout); - } - - this.clearHeaderTimeout(); - } - - selectTheme(themeKey: string): void { - this.selectedTheme = themeKey; - this.changeThemes(); - } - - getThemeColor(themeKey: string | undefined): string { - return EpubThemeUtil.getThemeColor(themeKey); - } - - onBookClick(event: MouseEvent): void { - - const clickX = event.clientX; - const clickY = event.clientY; - const screenWidth = window.innerWidth; - const screenHeight = window.innerHeight; - - if (this.isMobileDevice()) { - this.handleClickAsTap(event); - } else { - const isTopClick = clickY < screenHeight * 0.1; - if (isTopClick) { - this.showHeader = true; - this.startHeaderAutoHide(); - } - } - } - - onHeaderZoneEnter(): void { - if (this.isMobileDevice()) return; - this.isMouseInTopRegion = true; - this.showHeader = true; - this.clearHeaderTimeout(); - } - - onHeaderZoneLeave(): void { - if (this.isMobileDevice()) return; - this.isMouseInTopRegion = false; - this.startHeaderAutoHide(); - } - - onHeaderZoneClick(event: MouseEvent): void { - if (!this.showHeader) { - this.showHeader = true; - this.clearHeaderTimeout(); - } - } - - onBookMouseMove(event: MouseEvent): void { - if (this.isDrawerVisible || this.isSettingsDrawerVisible || this.isMobileDevice()) { - return; - } - - const mouseY = event.clientY; - const screenHeight = window.innerHeight; - const isInTopRegion = mouseY < screenHeight * 0.1; - - if (isInTopRegion && !this.isMouseInTopRegion) { - this.isMouseInTopRegion = true; - this.showHeader = true; - this.clearHeaderTimeout(); - } else if (!isInTopRegion && this.isMouseInTopRegion) { - this.isMouseInTopRegion = false; - this.startHeaderAutoHide(); - } - } - - onBookTouch(event?: TouchEvent): void { - if (this.isMobileDevice()) { - if (event) { - this.handleTouchEnd(event); - } else { - this.showControlsTemporarily(); - } - } - } - - private showControlsTemporarily(): void { - this.showControls = true; - this.showHeader = true; - this.headerShownByMobileTouch = false; - this.clearHeaderTimeout(); - - if (this.hideControlsTimeout) { - window.clearTimeout(this.hideControlsTimeout); - } - - this.hideControlsTimeout = window.setTimeout(() => { - this.ngZone.run(() => { - this.showControls = false; - if (!this.isDrawerVisible && !this.isSettingsDrawerVisible) { - this.showHeader = false; - } - }); - }, 2000); - } - - startHeaderAutoHide(): void { - this.clearHeaderTimeout(); - - if (this.isDrawerVisible || this.isSettingsDrawerVisible || this.isMouseInTopRegion) { - return; - } - - this.hideHeaderTimeout = window.setTimeout(() => { - this.ngZone.run(() => { - if (!this.isDrawerVisible && !this.isSettingsDrawerVisible && !this.isMouseInTopRegion) { - this.showHeader = false; - this.headerShownByMobileTouch = false; - } - }); - }, this.isMobileDevice() ? 2000 : 1000); - } - - private clearHeaderTimeout(): void { - if (this.hideHeaderTimeout) { - window.clearTimeout(this.hideHeaderTimeout); - this.hideHeaderTimeout = undefined; - } - } - - private updateCurrentChapter(location: any): void { - if (!location) return; - const chapter = getChapter(this.book, location); - if (chapter) { - if (chapter.label) { - this.currentChapter = chapter.label; - } - this.currentChapterHref = chapter.href; - } - } - - private extractChapters(toc: any[], level: number): { label: string; href: string; level: number }[] { - const chapters: { label: string; href: string; level: number }[] = []; - - for (const item of toc) { - chapters.push({ - label: item.label, - href: item.href, - level: level - }); - - if (item.subitems && item.subitems.length > 0) { - chapters.push(...this.extractChapters(item.subitems, level + 1)); - } - } - - return chapters; - } - - addBookmark(): void { - if (!this.currentCfi || this.isAddingBookmark) { - return; - } - - if (this.isCurrentLocationBookmarked()) { - this.messageService.add({ - severity: 'info', - summary: 'Info', - detail: 'Bookmark already exists at this location', - }); - return; - } - - this.isAddingBookmark = true; - const title = this.currentChapter || 'Untitled Bookmark'; - const request = { - bookId: this.epub.id, - cfi: this.currentCfi, - title: title - }; - - this.bookMarkService.createBookmark(request).subscribe({ - next: (bookmark) => { - this.bookmarks.push(bookmark); - this.bookmarks = [...this.bookmarks]; - this.updateBookmarkStatus(); - this.messageService.add({ - severity: 'success', - summary: 'Success', - detail: 'Bookmark created successfully', - }); - this.isAddingBookmark = false; - }, - error: () => { - this.messageService.add({ - severity: 'error', - summary: 'Error', - detail: 'Failed to create bookmark', - }); - this.isAddingBookmark = false; - }, - }); - } - - deleteBookmark(bookmarkId: number): void { - if (this.isDeletingBookmark) { - return; - } - if (!confirm('Are you sure you want to delete this bookmark?')) { - return; - } - - this.isDeletingBookmark = true; - this.bookMarkService.deleteBookmark(bookmarkId).subscribe({ - next: () => { - this.bookmarks = this.bookmarks.filter(b => b.id !== bookmarkId); - this.updateBookmarkStatus(); - this.messageService.add({ - severity: 'success', - summary: 'Success', - detail: 'Bookmark deleted successfully', - }); - this.isDeletingBookmark = false; - }, - error: () => { - this.messageService.add({ - severity: 'error', - summary: 'Error', - detail: 'Failed to delete bookmark', - }); - this.isDeletingBookmark = false; - }, - }); - } - - navigateToBookmark(bookmark: BookMark): void { - if (this.rendition && bookmark.cfi) { - this.rendition.display(bookmark.cfi).then(() => { - const location = this.rendition.currentLocation(); - this.readingSessionService.updateProgress( - location?.start?.cfi, - this.progressPercentage - ); - }); - } - } - - isCurrentLocationBookmarked(): boolean { - if (!this.currentCfi) return false; - return this.bookmarks.some(b => b.cfi === this.currentCfi); - } - - private updateBookmarkStatus(): void { - this.isBookmarked = this.currentCfi - ? this.bookmarks.some(b => b.cfi === this.currentCfi) - : false; - } - - openEditBookmarkDialog(bookmark: BookMark): void { - this.editingBookmark = {...bookmark}; - this.showEditBookmarkDialog = true; - } - - onBookmarkSave(updateRequest: UpdateBookMarkRequest): void { - if (!this.editingBookmark || this.isEditingBookmark) { - return; - } - - this.isEditingBookmark = true; - - this.bookMarkService.updateBookmark(this.editingBookmark.id, updateRequest).subscribe({ - next: (updatedBookmark) => { - const index = this.bookmarks.findIndex(b => b.id === this.editingBookmark!.id); - if (index !== -1) { - this.bookmarks[index] = updatedBookmark; - this.bookmarks = [...this.bookmarks]; - } - this.messageService.add({ - severity: 'success', - summary: 'Success', - detail: 'Bookmark updated successfully', - }); - this.showEditBookmarkDialog = false; - this.editingBookmark = null; - this.isEditingBookmark = false; - }, - error: () => { - this.messageService.add({ - severity: 'error', - summary: 'Error', - detail: 'Failed to update bookmark', - }); - this.showEditBookmarkDialog = false; - this.editingBookmark = null; - this.isEditingBookmark = false; - } - }); - } - - onBookmarkCancel(): void { - this.showEditBookmarkDialog = false; - this.editingBookmark = null; - } -} diff --git a/booklore-ui/src/app/features/readers/epub-reader/epub-reader-helper.ts b/booklore-ui/src/app/features/readers/epub-reader/epub-reader-helper.ts deleted file mode 100644 index bf1e36654..000000000 --- a/booklore-ui/src/app/features/readers/epub-reader/epub-reader-helper.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Book, EpubCFI, Location, TocItem } from 'epubjs'; - -export const FALLBACK_EPUB_SETTINGS = { - maxFontSize: 300, - minFontSize: 50 -}; - -export function flatten(chapters: TocItem[]): TocItem[] { - if (!chapters || !Array.isArray(chapters)) return []; - return chapters.flatMap((chapter: TocItem) => [chapter, ...flatten(chapter.subitems || [])]); -} - -export function getCfiFromHref(book: Book, href: string): string | null { - const [_, id] = href.split('#'); - const section = book.spine.get(href); - - if (!section || !section.document) { - console.debug('Section or section.document is undefined for href:', href); - return null; - } - - const el = id ? section.document.getElementById(id) : section.document.body; - if (!el) { - console.debug('Element not found in section.document for href:', href); - return null; - } - - return section.cfiFromElement(el); -} - -export function getChapter(book: Book, location: Location): TocItem | null { - const locationHref = location.start.href; - return flatten(book.navigation.toc || []) - .filter((chapter: TocItem) => { - return chapter.href && book.canonical && typeof book.canonical === 'function' && - book.canonical(chapter.href).includes(book.canonical(locationHref)); - }) - .reduce((result: TocItem | null, chapter: TocItem) => { - if (!chapter.href) return result; - const chapterCfi = getCfiFromHref(book, chapter.href); - if (!chapterCfi) { - return result; - } - const locationAfterChapter = (EpubCFI.prototype as any).compare(location.start.cfi, chapterCfi) > 0; - return locationAfterChapter ? chapter : result; - }, null); -} diff --git a/booklore-ui/src/app/features/readers/epub-reader/epub-theme-util.ts b/booklore-ui/src/app/features/readers/epub-reader/epub-theme-util.ts deleted file mode 100644 index b79101bc9..000000000 --- a/booklore-ui/src/app/features/readers/epub-reader/epub-theme-util.ts +++ /dev/null @@ -1,226 +0,0 @@ -interface EpubThemeObject { - body?: Record; - p?: Record; - 'h1, h2, h3, h4, h5, h6'?: Record; - a?: Record; - img?: Record; - code?: Record; - '*'?: Record; - [key: string]: Record | undefined; -} - -interface EpubRenditionThemes { - register(name: string, theme: EpubThemeObject): void; - select(name: string): void; -} - -interface EpubRenditionMinimal { - themes: { - register(name: string, theme: Record>): void; - select(name: string): void; - }; -} - -export enum EpubTheme { - WHITE = 'white', - BLACK = 'black', - GREY = 'grey', - SEPIA = 'sepia', - GREEN = 'green', - LAVENDER = 'lavender', - CREAM = 'cream', - LIGHT_BLUE = 'light-blue', - PEACH = 'peach', - MINT = 'mint', - DARK_SLATE = 'dark-slate', - DARK_OLIVE = 'dark-olive', - DARK_PURPLE = 'dark-purple', - DARK_TEAL = 'dark-teal', - DARK_BROWN = 'dark-brown' -} - -export class EpubThemeUtil { - static readonly themesMap = new Map([ - [EpubTheme.BLACK, { - "body": {"background-color": "#000000", "color": "#f9f9f9"}, - "p": {"color": "#f9f9f9"}, - "h1, h2, h3, h4, h5, h6": {"color": "#f9f9f9"}, - "a": {"color": "#f9f9f9"}, - "img": {"-webkit-filter": "none", "filter": "none"}, - "code": {"color": "#00ff00", "background-color": "black"} - }], - [EpubTheme.SEPIA, { - "body": {"background-color": "#f4ecd8", "color": "#6e4b3a"}, - "p": {"color": "#6e4b3a"}, - "h1, h2, h3, h4, h5, h6": {"color": "#6e4b3a"}, - "a": {"color": "#8b4513"}, - "img": {"-webkit-filter": "none", "filter": "none"}, - "code": {"color": "#8b0000", "background-color": "#f4ecd8"} - }], - [EpubTheme.WHITE, { - "body": {"background-color": "#ffffff", "color": "#000000"}, - "p": {"color": "#000000"}, - "h1, h2, h3, h4, h5, h6": {"color": "#000000"}, - "a": {"color": "#000000"}, - "img": {"-webkit-filter": "none", "filter": "none"}, - "code": {"color": "#d14", "background-color": "#f5f5f5"} - }], - [EpubTheme.GREY, { - "body": {"background-color": "#404040", "color": "#d3d3d3"}, - "p": {"color": "#d3d3d3"}, - "h1, h2, h3, h4, h5, h6": {"color": "#d3d3d3"}, - "a": {"color": "#1e90ff"}, - "img": {"filter": "none"}, - "code": {"color": "#d14", "background-color": "#585858"} - }], - [EpubTheme.GREEN, { - "body": {"background-color": "rgb(232, 245, 233)", "color": "#1b5e20"}, - "p": {"color": "#1b5e20"}, - "h1, h2, h3, h4, h5, h6": {"color": "#1b5e20"}, - "a": {"color": "#2e7d32"}, - "img": {"filter": "none"}, - "code": {"color": "#c62828", "background-color": "#e8f5e9"} - }], - [EpubTheme.LAVENDER, { - "body": {"background-color": "rgb(243, 237, 247)", "color": "#4a148c"}, - "p": {"color": "#4a148c"}, - "h1, h2, h3, h4, h5, h6": {"color": "#4a148c"}, - "a": {"color": "#6a1b9a"}, - "img": {"filter": "none"}, - "code": {"color": "#c62828", "background-color": "#f3e5f5"} - }], - [EpubTheme.CREAM, { - "body": {"background-color": "rgb(255, 253, 245)", "color": "#3e2723"}, - "p": {"color": "#3e2723"}, - "h1, h2, h3, h4, h5, h6": {"color": "#3e2723"}, - "a": {"color": "#5d4037"}, - "img": {"filter": "none"}, - "code": {"color": "#d84315", "background-color": "#fff8e1"} - }], - [EpubTheme.LIGHT_BLUE, { - "body": {"background-color": "rgb(232, 244, 253)", "color": "#01579b"}, - "p": {"color": "#01579b"}, - "h1, h2, h3, h4, h5, h6": {"color": "#01579b"}, - "a": {"color": "#0277bd"}, - "img": {"filter": "none"}, - "code": {"color": "#c62828", "background-color": "#e1f5fe"} - }], - [EpubTheme.PEACH, { - "body": {"background-color": "rgb(255, 243, 238)", "color": "#bf360c"}, - "p": {"color": "#bf360c"}, - "h1, h2, h3, h4, h5, h6": {"color": "#bf360c"}, - "a": {"color": "#d84315"}, - "img": {"filter": "none"}, - "code": {"color": "#c62828", "background-color": "#fbe9e7"} - }], - [EpubTheme.MINT, { - "body": {"background-color": "rgb(224, 247, 250)", "color": "#004d40"}, - "p": {"color": "#004d40"}, - "h1, h2, h3, h4, h5, h6": {"color": "#004d40"}, - "a": {"color": "#00695c"}, - "img": {"filter": "none"}, - "code": {"color": "#c62828", "background-color": "#e0f2f1"} - }], - [EpubTheme.DARK_SLATE, { - "body": {"background-color": "rgb(47, 55, 66)", "color": "#e4e7eb"}, - "p": {"color": "#e4e7eb"}, - "h1, h2, h3, h4, h5, h6": {"color": "#f0f3f7"}, - "a": {"color": "#7dd3fc"}, - "img": {"filter": "brightness(0.9)"}, - "code": {"color": "#fbbf24", "background-color": "#374151"} - }], - [EpubTheme.DARK_OLIVE, { - "body": {"background-color": "rgb(56, 61, 47)", "color": "#e8ecd7"}, - "p": {"color": "#e8ecd7"}, - "h1, h2, h3, h4, h5, h6": {"color": "#f4f7e3"}, - "a": {"color": "#bef264"}, - "img": {"filter": "brightness(0.9)"}, - "code": {"color": "#fde047", "background-color": "#3f4536"} - }], - [EpubTheme.DARK_PURPLE, { - "body": {"background-color": "rgb(49, 39, 67)", "color": "#e9d5ff"}, - "p": {"color": "#e9d5ff"}, - "h1, h2, h3, h4, h5, h6": {"color": "#f3e8ff"}, - "a": {"color": "#d8b4fe"}, - "img": {"filter": "brightness(0.9)"}, - "code": {"color": "#fde047", "background-color": "#3b2d4f"} - }], - [EpubTheme.DARK_TEAL, { - "body": {"background-color": "rgb(29, 53, 56)", "color": "#ccfbf1"}, - "p": {"color": "#ccfbf1"}, - "h1, h2, h3, h4, h5, h6": {"color": "#e0fdf8"}, - "a": {"color": "#5eead4"}, - "img": {"filter": "brightness(0.9)"}, - "code": {"color": "#fde047", "background-color": "#204145"} - }], - [EpubTheme.DARK_BROWN, { - "body": {"background-color": "rgb(54, 42, 36)", "color": "#f5e6d3"}, - "p": {"color": "#f5e6d3"}, - "h1, h2, h3, h4, h5, h6": {"color": "#fef3e2"}, - "a": {"color": "#fcd34d"}, - "img": {"filter": "brightness(0.9)"}, - "code": {"color": "#fde047", "background-color": "#42332d"} - }] - ]); - - static getThemeColor(themeKey: string | undefined): string { - switch (themeKey) { - case EpubTheme.WHITE: - return '#ffffff'; - case EpubTheme.BLACK: - return '#000000'; - case EpubTheme.GREY: - return '#808080'; - case EpubTheme.SEPIA: - return '#704214'; - case EpubTheme.GREEN: - return 'rgb(232, 245, 233)'; - case EpubTheme.LAVENDER: - return 'rgb(243, 237, 247)'; - case EpubTheme.CREAM: - return 'rgb(255, 253, 245)'; - case EpubTheme.LIGHT_BLUE: - return 'rgb(232, 244, 253)'; - case EpubTheme.PEACH: - return 'rgb(255, 243, 238)'; - case EpubTheme.MINT: - return 'rgb(224, 247, 250)'; - case EpubTheme.DARK_SLATE: - return 'rgb(47, 55, 66)'; - case EpubTheme.DARK_OLIVE: - return 'rgb(56, 61, 47)'; - case EpubTheme.DARK_PURPLE: - return 'rgb(49, 39, 67)'; - case EpubTheme.DARK_TEAL: - return 'rgb(29, 53, 56)'; - case EpubTheme.DARK_BROWN: - return 'rgb(54, 42, 36)'; - default: - return '#ffffff'; - } - } - - static applyTheme(rendition: EpubRenditionMinimal, themeKey: string, fontFamily?: string, fontSize?: number, lineHeight?: number, letterSpacing?: number): void { - if (!rendition) return; - - const baseTheme = this.themesMap.get(themeKey ?? 'black') as EpubThemeObject ?? {}; - const combined: EpubThemeObject = { - ...baseTheme, - body: { - ...(baseTheme.body || {}), - ...(fontFamily && { 'font-family': fontFamily }), - 'font-size': `${fontSize ?? 100}%`, - ...(lineHeight && { 'line-height': lineHeight.toString() }), - 'letter-spacing': `${letterSpacing ?? 0}em` - }, - '*': { - ...(baseTheme['*'] || {}), - ...(lineHeight && { 'line-height': lineHeight.toString() }), - 'letter-spacing': `${letterSpacing ?? 0}em` - } - }; - - rendition.themes.register('custom', combined as Record>); - rendition.themes.select('custom'); - } -}