|
74 | 74 | tag.r = text.slice(1);
|
75 | 75 | } else if (/^fs[\d+-]/.test(text)) {
|
76 | 76 | tag.fs = text.slice(2);
|
77 |
| - } else if (/^\d?c&?H?[0-9a-f]+|^\d?c$/i.test(text)) { |
| 77 | + } else if (/^\d?c&?H?[0-9a-fA-F]+|^\d?c$/.test(text)) { |
78 | 78 | var ref$1 = text.match(/^(\d?)c&?H?(\w*)/);
|
79 | 79 | var num = ref$1[1];
|
80 | 80 | var color = ref$1[2];
|
81 | 81 | tag[("c" + (num || 1))] = color && ("000000" + color).slice(-6);
|
82 |
| - } else if (/^\da&?H?[0-9a-f]+/i.test(text)) { |
| 82 | + } else if (/^\da&?H?[0-9a-fA-F]+/.test(text)) { |
83 | 83 | var ref$2 = text.match(/^(\d)a&?H?([0-9a-f]+)/i);
|
84 | 84 | var num$1 = ref$2[1];
|
85 | 85 | var alpha = ref$2[2];
|
86 | 86 | tag[("a" + num$1)] = ("00" + alpha).slice(-2);
|
87 |
| - } else if (/^alpha&?H?[0-9a-f]+/i.test(text)) { |
| 87 | + } else if (/^alpha&?H?[0-9a-fA-F]+/.test(text)) { |
88 | 88 | (assign = text.match(/^alpha&?H?([0-9a-f]+)/i), tag.alpha = assign[1]);
|
89 | 89 | tag.alpha = ("00" + (tag.alpha)).slice(-2);
|
90 | 90 | } else if (/^(?:pos|org|move|fad|fade)\([^)]+/.test(text)) {
|
|
259 | 259 | var stylesFormat = ['Name', 'Fontname', 'Fontsize', 'PrimaryColour', 'SecondaryColour', 'OutlineColour', 'BackColour', 'Bold', 'Italic', 'Underline', 'StrikeOut', 'ScaleX', 'ScaleY', 'Spacing', 'Angle', 'BorderStyle', 'Outline', 'Shadow', 'Alignment', 'MarginL', 'MarginR', 'MarginV', 'Encoding'];
|
260 | 260 | var eventsFormat = ['Layer', 'Start', 'End', 'Style', 'Name', 'MarginL', 'MarginR', 'MarginV', 'Effect', 'Text'];
|
261 | 261 |
|
| 262 | + function parseFormat(text) { |
| 263 | + var fields = stylesFormat.concat(eventsFormat); |
| 264 | + return text.match(/Format\s*:\s*(.*)/i)[1] |
| 265 | + .split(/\s*,\s*/) |
| 266 | + .map(function (field) { |
| 267 | + var caseField = fields.find(function (f) { return f.toLowerCase() === field.toLowerCase(); }); |
| 268 | + return caseField || field; |
| 269 | + }); |
| 270 | + } |
| 271 | + |
262 | 272 | function parseStyle(text, format) {
|
263 | 273 | var values = text.match(/Style\s*:\s*(.*)/i)[1].split(/\s*,\s*/);
|
264 | 274 | return assign.apply(void 0, [ {} ].concat( format.map(function (fmt, idx) {
|
|
296 | 306 | }
|
297 | 307 | if (state === 2) {
|
298 | 308 | if (/^Format\s*:/i.test(line)) {
|
299 |
| - tree.styles.format = stylesFormat.concat(); |
| 309 | + tree.styles.format = parseFormat(line); |
300 | 310 | }
|
301 | 311 | if (/^Style\s*:/i.test(line)) {
|
302 | 312 | tree.styles.style.push(parseStyle(line, tree.styles.format));
|
303 | 313 | }
|
304 | 314 | }
|
305 | 315 | if (state === 3) {
|
306 | 316 | if (/^Format\s*:/i.test(line)) {
|
307 |
| - tree.events.format = eventsFormat.concat(); |
| 317 | + tree.events.format = parseFormat(line); |
308 | 318 | }
|
309 | 319 | if (/^(?:Comment|Dialogue)\s*:/i.test(line)) {
|
310 | 320 | var ref$1 = line.match(/^(\w+?)\s*:\s*(.*)/i);
|
|
1064 | 1074 |
|
1065 | 1075 | function decompileText(dia, style) {
|
1066 | 1076 | return dia.slices
|
| 1077 | + .filter(function (slice) { return slice.fragments.length; }) |
1067 | 1078 | .map(function (slice, idx) {
|
1068 | 1079 | var sliceCopy = JSON.parse(JSON.stringify(slice));
|
1069 | 1080 | var ref = sliceCopy.fragments[0];
|
|
0 commit comments