@nxtedition/lib 14.0.14 → 14.0.16
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 +30 -35
- package/package.json +1 -1
- package/util/template/index.js +19 -10
package/ass.js
CHANGED
|
@@ -2,35 +2,23 @@ const fp = require('lodash/fp')
|
|
|
2
2
|
|
|
3
3
|
module.exports = { encodeASS }
|
|
4
4
|
|
|
5
|
-
function encodeASS(events, { styles = {},
|
|
6
|
-
return [
|
|
7
|
-
encASSHeader(options),
|
|
8
|
-
encASSStyles(styles),
|
|
9
|
-
encASSEvents(
|
|
10
|
-
events.map((event) => {
|
|
11
|
-
// NOTE: :subtitle uses `end`, :event uses `duration`
|
|
12
|
-
if (event.end == null) {
|
|
13
|
-
return { ...event, end: event.duration != null ? event.start + event.duration : null }
|
|
14
|
-
}
|
|
15
|
-
return event
|
|
16
|
-
})
|
|
17
|
-
),
|
|
18
|
-
].join('\n')
|
|
5
|
+
function encodeASS(events, { styles = {}, width = 1920, height = 1080 } = {}) {
|
|
6
|
+
return [encASSHeader({ width, height }), encASSStyles(styles), encASSEvents(events)].join('\n')
|
|
19
7
|
}
|
|
20
8
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
s
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
9
|
+
function formatDialogues(events) {
|
|
10
|
+
let s = ''
|
|
11
|
+
for (const { start, duration, end = duration != null ? start + duration : null, text, style } of [
|
|
12
|
+
...events,
|
|
13
|
+
].sort((a, b) => a.start - b.start)) {
|
|
14
|
+
if (typeof text === 'string' && text.length > 0 && Number.isFinite(start)) {
|
|
15
|
+
s += `Dialogue: 0,${formatASSTime(start) || '0:00:00.00'},${
|
|
16
|
+
formatASSTime(end) || '9:59:59.00'
|
|
17
|
+
},${style || 'nxt-default'},,0000,0000,0000,,${(text || '').replace(/\\n|\n/, '\\N')}\n`
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return s
|
|
21
|
+
}
|
|
34
22
|
|
|
35
23
|
function encASSEvents(events) {
|
|
36
24
|
return `[Events]
|
|
@@ -100,7 +88,7 @@ Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour,
|
|
|
100
88
|
${formatStyles(styles)}`
|
|
101
89
|
}
|
|
102
90
|
|
|
103
|
-
function encASSHeader({ width, height }
|
|
91
|
+
function encASSHeader({ width, height }) {
|
|
104
92
|
// WrapStyle
|
|
105
93
|
// 0: smart wrapping, lines are evenly broken
|
|
106
94
|
// 1: end-of-line word wrapping, only \N breaks
|
|
@@ -114,19 +102,26 @@ WrapStyle: 1
|
|
|
114
102
|
`
|
|
115
103
|
}
|
|
116
104
|
|
|
117
|
-
function pad0(rep, x) {
|
|
118
|
-
return String(x || 0).padStart(rep, '0')
|
|
119
|
-
}
|
|
120
|
-
|
|
121
105
|
function formatASSTime(seconds) {
|
|
122
106
|
if (seconds == null) {
|
|
123
107
|
return ''
|
|
124
108
|
}
|
|
125
|
-
|
|
126
|
-
|
|
109
|
+
|
|
110
|
+
const h = Math.floor(seconds / 3600)
|
|
111
|
+
seconds -= h * 3600
|
|
127
112
|
const m = Math.floor(seconds / 60)
|
|
128
113
|
seconds -= m * 60
|
|
129
114
|
const s = Math.floor(seconds)
|
|
130
115
|
const cs = Math.floor((seconds - s) * 100)
|
|
131
|
-
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
h +
|
|
119
|
+
':' +
|
|
120
|
+
(m === 0 ? '00' : m < 10 ? '0' + m : m) +
|
|
121
|
+
':' +
|
|
122
|
+
(s === 0 ? '00' : s < 10 ? '0' + s : s) +
|
|
123
|
+
':' +
|
|
124
|
+
(cs === 0 ? '00' : cs < 10 ? '0' + cs : cs) +
|
|
125
|
+
':'
|
|
126
|
+
)
|
|
132
127
|
}
|
package/package.json
CHANGED
package/util/template/index.js
CHANGED
|
@@ -158,19 +158,28 @@ module.exports = ({ ds, proxify }) => {
|
|
|
158
158
|
|
|
159
159
|
const { pre, type, body, post } = match
|
|
160
160
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
throw new Error('unknown expression type: ' + type)
|
|
164
|
-
}
|
|
161
|
+
if (type === 'js') {
|
|
162
|
+
const expr = compilers.js(body)
|
|
165
163
|
|
|
166
|
-
|
|
164
|
+
if (!pre && !post) {
|
|
165
|
+
return (str, args$) => expr(args$)
|
|
166
|
+
}
|
|
167
167
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
return (str, args$) => expr(args$).pipe(rx.map((body) => `${pre}${stringify(body)}${post}`))
|
|
169
|
+
} else if (type === 'nxt') {
|
|
170
|
+
const expr = compilers.nxt(body)
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
if (!pre && !post) {
|
|
173
|
+
return (str, args$) => expr(args$)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return (str, args$) =>
|
|
177
|
+
expr(args$).pipe(
|
|
178
|
+
rx.switchMap((body) => onResolveTemplate(`${pre}${stringify(body, true)}${post}`, args$))
|
|
179
|
+
)
|
|
180
|
+
} else {
|
|
181
|
+
throw new Error('unknown expression type: ' + type)
|
|
182
|
+
}
|
|
174
183
|
}
|
|
175
184
|
|
|
176
185
|
function stringify(value, escape) {
|