dasha 3.0.5 → 3.1.0
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/LICENSE +21 -661
- package/README.md +2 -1
- package/dist/dasha.js +6 -0
- package/dist/dasha.mjs +6 -0
- package/package.json +44 -28
- package/types/dasha.d.ts +62 -12
- package/dasha.js +0 -26
- package/lib/audio.js +0 -128
- package/lib/dash.js +0 -430
- package/lib/hls.js +0 -206
- package/lib/subtitle.js +0 -120
- package/lib/track.js +0 -107
- package/lib/util.js +0 -97
- package/lib/video.js +0 -158
- package/lib/xml.js +0 -296
package/lib/xml.js
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
function parse(text, options = {}) {
|
|
2
|
-
var pos = options.pos || 0;
|
|
3
|
-
var keepComments = !!options.keepComments;
|
|
4
|
-
var keepWhitespace = !!options.keepWhitespace;
|
|
5
|
-
|
|
6
|
-
var openBracket = '<';
|
|
7
|
-
var openBracketCC = '<'.charCodeAt(0);
|
|
8
|
-
var closeBracket = '>';
|
|
9
|
-
var closeBracketCC = '>'.charCodeAt(0);
|
|
10
|
-
var minusCC = '-'.charCodeAt(0);
|
|
11
|
-
var slashCC = '/'.charCodeAt(0);
|
|
12
|
-
var exclamationCC = '!'.charCodeAt(0);
|
|
13
|
-
var singleQuoteCC = "'".charCodeAt(0);
|
|
14
|
-
var doubleQuoteCC = '"'.charCodeAt(0);
|
|
15
|
-
var openCornerBracketCC = '['.charCodeAt(0);
|
|
16
|
-
var closeCornerBracketCC = ']'.charCodeAt(0);
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* parsing a list of entries
|
|
20
|
-
*/
|
|
21
|
-
function parseChildren(tagName) {
|
|
22
|
-
var children = [];
|
|
23
|
-
while (text[pos]) {
|
|
24
|
-
if (text.charCodeAt(pos) == openBracketCC) {
|
|
25
|
-
if (text.charCodeAt(pos + 1) === slashCC) {
|
|
26
|
-
var closeStart = pos + 2;
|
|
27
|
-
pos = text.indexOf(closeBracket, pos);
|
|
28
|
-
|
|
29
|
-
var closeTag = text.substring(closeStart, pos);
|
|
30
|
-
if (closeTag.indexOf(tagName) == -1) {
|
|
31
|
-
const parsedText = text.substring(0, pos).split('\n');
|
|
32
|
-
throw new Error(
|
|
33
|
-
'Unexpected close tag\nLine: ' +
|
|
34
|
-
(parsedText.length - 1) +
|
|
35
|
-
'\nColumn: ' +
|
|
36
|
-
(parsedText[parsedText.length - 1].length + 1) +
|
|
37
|
-
'\nChar: ' +
|
|
38
|
-
text[pos]
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (pos + 1) pos += 1;
|
|
43
|
-
|
|
44
|
-
return children;
|
|
45
|
-
} else if (text.charCodeAt(pos + 1) === exclamationCC) {
|
|
46
|
-
if (text.charCodeAt(pos + 2) == minusCC) {
|
|
47
|
-
//comment support
|
|
48
|
-
const startCommentPos = pos;
|
|
49
|
-
while (
|
|
50
|
-
pos !== -1 &&
|
|
51
|
-
!(
|
|
52
|
-
text.charCodeAt(pos) === closeBracketCC &&
|
|
53
|
-
text.charCodeAt(pos - 1) == minusCC &&
|
|
54
|
-
text.charCodeAt(pos - 2) == minusCC &&
|
|
55
|
-
pos != -1
|
|
56
|
-
)
|
|
57
|
-
) {
|
|
58
|
-
pos = text.indexOf(closeBracket, pos + 1);
|
|
59
|
-
}
|
|
60
|
-
if (pos === -1) {
|
|
61
|
-
pos = text.length;
|
|
62
|
-
}
|
|
63
|
-
if (keepComments) {
|
|
64
|
-
children.push(text.substring(startCommentPos, pos + 1));
|
|
65
|
-
}
|
|
66
|
-
} else if (
|
|
67
|
-
text.charCodeAt(pos + 2) === openCornerBracketCC &&
|
|
68
|
-
text.charCodeAt(pos + 8) === openCornerBracketCC &&
|
|
69
|
-
text.substr(pos + 3, 5).toLowerCase() === 'cdata'
|
|
70
|
-
) {
|
|
71
|
-
// cdata
|
|
72
|
-
var cdataEndIndex = text.indexOf(']]>', pos);
|
|
73
|
-
if (cdataEndIndex == -1) {
|
|
74
|
-
children.push(text.substr(pos + 9));
|
|
75
|
-
pos = text.length;
|
|
76
|
-
} else {
|
|
77
|
-
children.push(text.substring(pos + 9, cdataEndIndex));
|
|
78
|
-
pos = cdataEndIndex + 3;
|
|
79
|
-
}
|
|
80
|
-
continue;
|
|
81
|
-
} else {
|
|
82
|
-
// doctypesupport
|
|
83
|
-
const startDoctype = pos + 1;
|
|
84
|
-
pos += 2;
|
|
85
|
-
var encapsuled = false;
|
|
86
|
-
while ((text.charCodeAt(pos) !== closeBracketCC || encapsuled === true) && text[pos]) {
|
|
87
|
-
if (text.charCodeAt(pos) === openCornerBracketCC) {
|
|
88
|
-
encapsuled = true;
|
|
89
|
-
} else if (encapsuled === true && text.charCodeAt(pos) === closeCornerBracketCC) {
|
|
90
|
-
encapsuled = false;
|
|
91
|
-
}
|
|
92
|
-
pos++;
|
|
93
|
-
}
|
|
94
|
-
children.push(text.substring(startDoctype, pos));
|
|
95
|
-
}
|
|
96
|
-
pos++;
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
var node = parseNode();
|
|
100
|
-
children.push(node);
|
|
101
|
-
if (node.tagName[0] === '?') {
|
|
102
|
-
children.push(...node.children);
|
|
103
|
-
node.children = [];
|
|
104
|
-
}
|
|
105
|
-
} else {
|
|
106
|
-
const parsedText = parseText();
|
|
107
|
-
if (keepWhitespace) {
|
|
108
|
-
if (parsedText.length > 0) {
|
|
109
|
-
children.push(parsedText);
|
|
110
|
-
}
|
|
111
|
-
} else {
|
|
112
|
-
var trimmed = parsedText.trim();
|
|
113
|
-
if (trimmed.length > 0) {
|
|
114
|
-
children.push(trimmed);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
pos++;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return children;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* returns the text outside of texts until the first '<'
|
|
125
|
-
*/
|
|
126
|
-
function parseText() {
|
|
127
|
-
var start = pos;
|
|
128
|
-
pos = text.indexOf(openBracket, pos) - 1;
|
|
129
|
-
if (pos === -2) pos = text.length;
|
|
130
|
-
return text.slice(start, pos + 1);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* returns text until the first nonAlphabetic letter
|
|
134
|
-
*/
|
|
135
|
-
var nameSpacer = '\r\n\t>/= ';
|
|
136
|
-
|
|
137
|
-
function parseName() {
|
|
138
|
-
var start = pos;
|
|
139
|
-
while (nameSpacer.indexOf(text[pos]) === -1 && text[pos]) {
|
|
140
|
-
pos++;
|
|
141
|
-
}
|
|
142
|
-
return text.slice(start, pos);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* is parsing a node, including tagName, Attributes and its children,
|
|
146
|
-
* to parse children it uses the parseChildren again, that makes the parsing recursive
|
|
147
|
-
*/
|
|
148
|
-
var NoChildNodes = options.noChildNodes || ['img', 'br', 'input', 'meta', 'link', 'hr'];
|
|
149
|
-
|
|
150
|
-
function parseNode() {
|
|
151
|
-
pos++;
|
|
152
|
-
const tagName = parseName();
|
|
153
|
-
const attributes = {};
|
|
154
|
-
let children = [];
|
|
155
|
-
|
|
156
|
-
// parsing attributes
|
|
157
|
-
while (text.charCodeAt(pos) !== closeBracketCC && text[pos]) {
|
|
158
|
-
var c = text.charCodeAt(pos);
|
|
159
|
-
if ((c > 64 && c < 91) || (c > 96 && c < 123)) {
|
|
160
|
-
//if('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.indexOf(S[pos])!==-1 ){
|
|
161
|
-
var name = parseName();
|
|
162
|
-
// search beginning of the string
|
|
163
|
-
var code = text.charCodeAt(pos);
|
|
164
|
-
while (
|
|
165
|
-
code &&
|
|
166
|
-
code !== singleQuoteCC &&
|
|
167
|
-
code !== doubleQuoteCC &&
|
|
168
|
-
!((code > 64 && code < 91) || (code > 96 && code < 123)) &&
|
|
169
|
-
code !== closeBracketCC
|
|
170
|
-
) {
|
|
171
|
-
pos++;
|
|
172
|
-
code = text.charCodeAt(pos);
|
|
173
|
-
}
|
|
174
|
-
if (code === singleQuoteCC || code === doubleQuoteCC) {
|
|
175
|
-
var value = parseString();
|
|
176
|
-
if (pos === -1) {
|
|
177
|
-
return {
|
|
178
|
-
tagName,
|
|
179
|
-
attributes,
|
|
180
|
-
children,
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
} else {
|
|
184
|
-
value = null;
|
|
185
|
-
pos--;
|
|
186
|
-
}
|
|
187
|
-
attributes[name] = value;
|
|
188
|
-
}
|
|
189
|
-
pos++;
|
|
190
|
-
}
|
|
191
|
-
// optional parsing of children
|
|
192
|
-
if (text.charCodeAt(pos - 1) !== slashCC) {
|
|
193
|
-
if (tagName == 'script') {
|
|
194
|
-
const start = pos + 1;
|
|
195
|
-
pos = text.indexOf('</script>', pos);
|
|
196
|
-
children = [text.slice(start, pos)];
|
|
197
|
-
pos += 9;
|
|
198
|
-
} else if (tagName == 'style') {
|
|
199
|
-
const start = pos + 1;
|
|
200
|
-
pos = text.indexOf('</style>', pos);
|
|
201
|
-
children = [text.slice(start, pos)];
|
|
202
|
-
pos += 8;
|
|
203
|
-
} else if (NoChildNodes.indexOf(tagName) === -1) {
|
|
204
|
-
pos++;
|
|
205
|
-
children = parseChildren(tagName);
|
|
206
|
-
} else {
|
|
207
|
-
pos++;
|
|
208
|
-
}
|
|
209
|
-
} else {
|
|
210
|
-
pos++;
|
|
211
|
-
}
|
|
212
|
-
return {
|
|
213
|
-
tagName,
|
|
214
|
-
attributes,
|
|
215
|
-
children,
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* is parsing a string, that starts with a char and with the same usually ' or "
|
|
221
|
-
*/
|
|
222
|
-
|
|
223
|
-
function parseString() {
|
|
224
|
-
var startChar = text[pos];
|
|
225
|
-
var startpos = pos + 1;
|
|
226
|
-
pos = text.indexOf(startChar, startpos);
|
|
227
|
-
return text.slice(startpos, pos);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
*
|
|
232
|
-
*/
|
|
233
|
-
function findElements() {
|
|
234
|
-
var r = new RegExp('\\s' + options.attrName + '\\s*=[\'"]' + options.attrValue + '[\'"]').exec(
|
|
235
|
-
text
|
|
236
|
-
);
|
|
237
|
-
if (r) {
|
|
238
|
-
return r.index;
|
|
239
|
-
} else {
|
|
240
|
-
return -1;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
let out = null;
|
|
245
|
-
if (options.attrValue !== undefined) {
|
|
246
|
-
options.attrName = options.attrName || 'id';
|
|
247
|
-
out = [];
|
|
248
|
-
|
|
249
|
-
while ((pos = findElements()) !== -1) {
|
|
250
|
-
pos = text.lastIndexOf('<', pos);
|
|
251
|
-
if (pos !== -1) {
|
|
252
|
-
out.push(parseNode());
|
|
253
|
-
}
|
|
254
|
-
text = text.substr(pos);
|
|
255
|
-
pos = 0;
|
|
256
|
-
}
|
|
257
|
-
} else if (options.parseNode) {
|
|
258
|
-
out = parseNode();
|
|
259
|
-
} else {
|
|
260
|
-
out = parseChildren('');
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (options.filter) {
|
|
264
|
-
out = filter(out, options.filter);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (options.setPos) {
|
|
268
|
-
out.pos = pos;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return out;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* behaves the same way as Array.filter, if the filter method return true, the element is in the resultList
|
|
276
|
-
* @params children{Array} the children of a node
|
|
277
|
-
* @param f{function} the filter method
|
|
278
|
-
*/
|
|
279
|
-
function filter(children, f, dept = 0, path = '') {
|
|
280
|
-
var out = [];
|
|
281
|
-
children.forEach(function (child, i) {
|
|
282
|
-
if (typeof child === 'object' && f(child, i, dept, path)) out.push(child);
|
|
283
|
-
if (child.children) {
|
|
284
|
-
var kids = filter(
|
|
285
|
-
child.children,
|
|
286
|
-
f,
|
|
287
|
-
dept + 1,
|
|
288
|
-
(path ? path + '.' : '') + i + '.' + child.tagName
|
|
289
|
-
);
|
|
290
|
-
out = out.concat(kids);
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
return out;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
module.exports = { parse, filter };
|