@nxtedition/lib 26.0.12 → 26.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ass.js +7 -4
- package/cache.js +34 -18
- package/package.json +1 -1
package/ass.js
CHANGED
|
@@ -31,8 +31,9 @@ const BASE_HEIGHT = 1080
|
|
|
31
31
|
*
|
|
32
32
|
* @typedef {object} EmbeddableSubtitleFontFace
|
|
33
33
|
* @property {string} family
|
|
34
|
-
* @property {
|
|
35
|
-
* @property {'normal'|'
|
|
34
|
+
* @property {string} name
|
|
35
|
+
* @property {'normal'|'bold'} [weight]
|
|
36
|
+
* @property {'normal'|'italic'} [style]
|
|
36
37
|
* @property {Uint8Array} data
|
|
37
38
|
*
|
|
38
39
|
* @typedef {object} Styles
|
|
@@ -351,8 +352,10 @@ function encFontFaces(fontFaces) {
|
|
|
351
352
|
* @param {EmbeddableSubtitleFontFace} fontFace
|
|
352
353
|
*/
|
|
353
354
|
function getFontName(fontFace) {
|
|
354
|
-
const { family, weight, style } = fontFace
|
|
355
|
-
|
|
355
|
+
const { name, family, weight, style } = fontFace
|
|
356
|
+
// NOTE: Seems like libass doesn't care about the font name as specified in the original spec.
|
|
357
|
+
// That is good, because then we can register more faces than the original spec allowed.
|
|
358
|
+
return name ?? `${family}_${weight === 'bold' ? 'B' : ''}${style === 'italic' ? 'I' : ''}0`
|
|
356
359
|
}
|
|
357
360
|
|
|
358
361
|
/**
|
package/cache.js
CHANGED
|
@@ -103,6 +103,7 @@ export class AsyncCache {
|
|
|
103
103
|
`INSERT OR REPLACE INTO cache (key, val, ttl, stale) VALUES (?, ?, ?, ?)`,
|
|
104
104
|
)
|
|
105
105
|
this.#delQuery = this.#db.prepare(`DELETE FROM cache WHERE key = ?`)
|
|
106
|
+
break
|
|
106
107
|
} catch (err) {
|
|
107
108
|
if (n >= 8) {
|
|
108
109
|
this.#db?.close()
|
|
@@ -139,6 +140,14 @@ export class AsyncCache {
|
|
|
139
140
|
return this.#load(args, false)
|
|
140
141
|
}
|
|
141
142
|
|
|
143
|
+
/**
|
|
144
|
+
* @param {...any} args
|
|
145
|
+
* @returns {Promise<V>}
|
|
146
|
+
*/
|
|
147
|
+
refresh(...args) {
|
|
148
|
+
return this.#refresh(args)
|
|
149
|
+
}
|
|
150
|
+
|
|
142
151
|
/**
|
|
143
152
|
* @param {any[]} args
|
|
144
153
|
* @param {boolean} refresh
|
|
@@ -189,30 +198,37 @@ export class AsyncCache {
|
|
|
189
198
|
}
|
|
190
199
|
}
|
|
191
200
|
|
|
192
|
-
|
|
193
|
-
if (this.#valueSelector && refresh) {
|
|
194
|
-
promise = this.#dedupe.get(key)
|
|
195
|
-
if (promise === undefined) {
|
|
196
|
-
promise = this.#valueSelector(...args).then(
|
|
197
|
-
(value) => {
|
|
198
|
-
this.set(key, value)
|
|
199
|
-
return value
|
|
200
|
-
},
|
|
201
|
-
(err) => {
|
|
202
|
-
this.delete(key)
|
|
203
|
-
throw err
|
|
204
|
-
},
|
|
205
|
-
)
|
|
206
|
-
promise.catch(noop)
|
|
207
|
-
this.#dedupe.set(key, promise)
|
|
208
|
-
}
|
|
209
|
-
}
|
|
201
|
+
const promise = refresh ? this.#refresh(args, key) : null
|
|
210
202
|
|
|
211
203
|
return cached !== undefined
|
|
212
204
|
? { value: cached.value, async: false }
|
|
213
205
|
: { value: promise, async: true }
|
|
214
206
|
}
|
|
215
207
|
|
|
208
|
+
#refresh(args, key = this.#keySelector(...args)) {
|
|
209
|
+
if (typeof key !== 'string' || key.length === 0) {
|
|
210
|
+
throw new TypeError('keySelector must return a non-empty string')
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
let promise = this.#dedupe.get(key)
|
|
214
|
+
if (promise === undefined && this.#valueSelector) {
|
|
215
|
+
promise = this.#valueSelector(...args).then(
|
|
216
|
+
(value) => {
|
|
217
|
+
this.set(key, value)
|
|
218
|
+
return value
|
|
219
|
+
},
|
|
220
|
+
(err) => {
|
|
221
|
+
this.delete(key)
|
|
222
|
+
throw err
|
|
223
|
+
},
|
|
224
|
+
)
|
|
225
|
+
promise.catch(noop)
|
|
226
|
+
this.#dedupe.set(key, promise)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return promise
|
|
230
|
+
}
|
|
231
|
+
|
|
216
232
|
/**
|
|
217
233
|
* @param {string} key
|
|
218
234
|
* @param {V} value
|