diff --git a/package.json b/package.json index 7f0c646..9262ab9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ui", - "version": "6.3.35", + "version": "6.3.36", "license": "BUSL-1.1", "private": true, "packageManager": "pnpm@9.14.4", @@ -30,7 +30,7 @@ "eslint-config-standard-universal": "^1.0.6", "gql.tada": "^1.8.10", "hayase-extensions": "github:hayase-app/extensions", - "jassub": "^1.8.4", + "jassub": "^1.8.5", "svelte": "^4.2.19", "svelte-check": "^4.2.1", "svelte-radix": "^1.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d6e2f36..64b4ed9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -157,8 +157,8 @@ importers: specifier: github:hayase-app/extensions version: https://codeload.github.com/hayase-app/extensions/tar.gz/a9415c297a899459be34a135a9adbcd72115e019 jassub: - specifier: ^1.8.4 - version: 1.8.4 + specifier: ^1.8.5 + version: 1.8.5 svelte: specifier: ^4.2.19 version: 4.2.19 @@ -1659,8 +1659,8 @@ packages: jackspeak@3.4.3: resolution: {integrity: sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==} - jassub@1.8.4: - resolution: {integrity: sha512-j4GiLAfqZCYFPCZz4YVM20AJUCNcIqTdykbFNxJvBfbU7Xz6y0vnEDvxcYPtsNyrTDuyGlUhuLILgp8Ad18vxg==} + jassub@1.8.5: + resolution: {integrity: sha512-BKf3qureEQcJ0WKi7rSJ86UsQF8hTcQqJaIWcwqezxIVTCOatT+tnShM6fauS0pdjeG4bLLFS2+51xMasl/WCw==} jiti@1.21.6: resolution: {integrity: sha512-2yTgeWTWzMWkHu6Jp9NKgePDaYHbntiwvYuuJLbbN9vl7DC9DvXKOB2BC3ZZ92D3cvV/aflH0osDfwpHepQ53w==} @@ -4224,7 +4224,7 @@ snapshots: optionalDependencies: '@pkgjs/parseargs': 0.11.0 - jassub@1.8.4: + jassub@1.8.5: dependencies: rvfc-polyfill: 1.0.7 diff --git a/src/lib/components/ui/player/subtitles.ts b/src/lib/components/ui/player/subtitles.ts index 5fc68db..fc742ce 100644 --- a/src/lib/components/ui/player/subtitles.ts +++ b/src/lib/components/ui/player/subtitles.ts @@ -52,6 +52,15 @@ const OVERRIDE_FONTS: Partial> = { notosans: '/NotoSans-Bold.woff2' } +const LANGUAGE_OVERRIDES: Record = { + jpn: { url: '/NotoSansJP.woff2', name: 'Noto Sans JP' }, + kor: { url: '/NotoSansKR.woff2', name: 'Noto Sans KR' }, + chi: { url: '/NotoSansHK.woff2', name: 'Noto Sans HK' }, + ja: { url: '/NotoSansJP.woff2', name: 'Noto Sans JP' }, + ko: { url: '/NotoSansKR.woff2', name: 'Noto Sans KR' }, + zh: { url: '/NotoSansHK.woff2', name: 'Noto Sans HK' } +} + const stylesRx = /^Style:[^,]*/gm export default class Subtitles { video: HTMLVideoElement @@ -158,10 +167,7 @@ export default class Subtitles { native.attachments(this.selected.hash, this.selected.id).then(attachments => { for (const attachment of attachments) { if (fontRx.test(attachment.filename) || attachment.mimetype.toLowerCase().includes('font')) { - if (!this.fonts.includes(attachment.url)) { - this.fonts.push(attachment.url) - this.renderer?.addFont(attachment.url) - } + this.addFont(attachment.url) } } }) @@ -183,6 +189,13 @@ export default class Subtitles { } } + addFont (url: string) { + if (!this.fonts.includes(url)) { + this.fonts.push(url) + this.renderer?.addFont(url) + } + } + pickFile () { const input = document.createElement('input') input.type = 'file' @@ -230,7 +243,6 @@ export default class Subtitles { initSubtitleRenderer () { if (this.renderer) return - // @ts-expect-error yeah, patching the library if (SUPPORTS.isAndroid) JASSUB._hasBitmapBug = true this.renderer = new JASSUB({ video: this.video, @@ -255,10 +267,7 @@ export default class Subtitles { if (this.renderer) this.lastSubtitleStyle = subtitleStyle if (subtitleStyle !== 'none') { const font = OVERRIDE_FONTS[subtitleStyle] - if (font && !this.fonts.includes(font)) { - this.fonts.push(font) - this.renderer?.addFont(font) - } + if (font) this.addFont(font) const overrideStyle: ASSStyle = { Name: 'DialogueStyleOverride', FontSize: 72, @@ -354,6 +363,11 @@ export default class Subtitles { this.renderer.setTrack(track.meta.header.slice(0, -1)) for (const subtitle of track.events) this.renderer.createEvent(subtitle) + if (LANGUAGE_OVERRIDES[track.meta.language ?? '']) { + const { name, url } = LANGUAGE_OVERRIDES[track.meta.language ?? '']! + this.addFont(url) + this.renderer.setDefaultFont(name) + } this.renderer.resize() } diff --git a/src/service-worker/index.ts b/src/service-worker/index.ts index 1509a33..373a194 100644 --- a/src/service-worker/index.ts +++ b/src/service-worker/index.ts @@ -3,7 +3,7 @@ import { cleanupOutdatedCaches, precacheAndRoute } from 'workbox-precaching' import { build, files, prerendered, version } from '$service-worker' -precacheAndRoute([...build, ...files.filter(e => !['/Ameku.webm', '/video.mkv'].includes(e)), ...prerendered, '/'].map(url => ({ url, revision: version }))) +precacheAndRoute([...build, ...files.filter(e => !['/Ameku.webm', '/video.mkv', '/NotoSansHK.woff2', '/NotoSansJP.woff2', '/NotoSansKR.woff2'].includes(e)), ...prerendered, '/'].map(url => ({ url, revision: version }))) cleanupOutdatedCaches() clientsClaim() skipWaiting() diff --git a/static/NotoSansHK.woff2 b/static/NotoSansHK.woff2 new file mode 100644 index 0000000..6ed7020 Binary files /dev/null and b/static/NotoSansHK.woff2 differ diff --git a/static/NotoSansJP.woff2 b/static/NotoSansJP.woff2 new file mode 100644 index 0000000..d98103a Binary files /dev/null and b/static/NotoSansJP.woff2 differ diff --git a/static/NotoSansKR.woff2 b/static/NotoSansKR.woff2 new file mode 100644 index 0000000..3623d0f Binary files /dev/null and b/static/NotoSansKR.woff2 differ