feat: support asian languages

This commit is contained in:
ThaUnknown 2025-05-30 19:30:32 +02:00
parent fd01257bdf
commit 869f012734
No known key found for this signature in database
7 changed files with 31 additions and 17 deletions

View file

@ -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",

View file

@ -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

View file

@ -52,6 +52,15 @@ const OVERRIDE_FONTS: Partial<Record<typeof defaults.subtitleStyle, string>> = {
notosans: '/NotoSans-Bold.woff2'
}
const LANGUAGE_OVERRIDES: Record<string, {url: string, name: string}> = {
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()
}

View file

@ -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()

BIN
static/NotoSansHK.woff2 Normal file

Binary file not shown.

BIN
static/NotoSansJP.woff2 Normal file

Binary file not shown.

BIN
static/NotoSansKR.woff2 Normal file

Binary file not shown.