|
1 | 1 | const { parseSingle, serialize } = require("@hookun/parse-animation-shorthand");
|
2 | 2 |
|
3 | 3 | /**
|
4 |
| - * @param {@} options |
| 4 | + * @param {@} options |
5 | 5 | * @returns {import('postcss').Plugin}
|
6 | 6 | */
|
7 | 7 | module.exports = (options = { debug: false }) => {
|
8 | 8 | return {
|
9 | 9 | postcssPlugin: "postcss-nativescript-animations",
|
10 | 10 | Declaration(decl) {
|
11 |
| - // replace animation: * |
12 |
| - // with animation-*: |
13 |
| - if (decl.prop === "animation") { |
14 |
| - const styles = parseSingle(decl.value); |
15 |
| - if (styles.duration && Number.isInteger(styles.duration)) { |
16 |
| - styles.duration = `${styles.duration / 1000}s`; |
17 |
| - } |
18 |
| - Object.entries(styles) |
19 |
| - .filter(([, value]) => typeof value === "object") |
20 |
| - .map(([key, value]) => [ |
21 |
| - key, |
22 |
| - serialize({ [key]: value }).split(" ")[0], |
23 |
| - ]) |
24 |
| - .map(([key, value]) => (styles[key] = value)); |
| 11 | + try { |
| 12 | + // replace animation: * |
| 13 | + // with animation-*: |
| 14 | + if (decl.prop === "animation") { |
| 15 | + const styles = parseSingle(decl.value); |
| 16 | + if (styles.duration && Number.isInteger(styles.duration)) { |
| 17 | + styles.duration = `${styles.duration / 1000}s`; |
| 18 | + } |
| 19 | + Object.entries(styles) |
| 20 | + .filter(([, value]) => typeof value === "object") |
| 21 | + .map(([key, value]) => [ |
| 22 | + key, |
| 23 | + serialize({ [key]: value }).split(" ")[0], |
| 24 | + ]) |
| 25 | + .map(([key, value]) => (styles[key] = value)); |
25 | 26 |
|
26 |
| - Object.entries(styles) |
27 |
| - .filter(([, value]) => value !== "unset") |
28 |
| - .map(([key, value]) => |
29 |
| - decl.parent.insertAfter( |
30 |
| - decl, |
31 |
| - decl.clone({ |
32 |
| - prop: `animation-${camelToKebab(key)}`, |
33 |
| - value: `${value}`, |
34 |
| - }) |
35 |
| - ) |
36 |
| - ); |
| 27 | + Object.entries(styles) |
| 28 | + .filter(([, value]) => value !== "unset") |
| 29 | + .map(([key, value]) => |
| 30 | + decl.parent.insertAfter( |
| 31 | + decl, |
| 32 | + decl.clone({ |
| 33 | + prop: `animation-${camelToKebab(key)}`, |
| 34 | + value: `${value}`, |
| 35 | + }) |
| 36 | + ) |
| 37 | + ); |
37 | 38 |
|
38 |
| - decl.remove(); |
| 39 | + decl.remove(); |
| 40 | + } |
| 41 | + } catch (err) { |
| 42 | + // ignore errors, and just keep the animation as-is |
39 | 43 | }
|
40 | 44 | },
|
41 | 45 | };
|
|
0 commit comments