public void WriteKeyframes(KeyFramesBlock keyframes) { _wrapped.Write("@"); _wrapped.Write(keyframes.Prefix); _wrapped.Write("keyframes "); _wrapped.Write(keyframes.Name); StartClass(); foreach (var frame in keyframes.Frames) { var percents = string.Join( ",", frame.Percentages.Select( p => { // to is shorter than 100% if (p == 100m) { return("to"); } return(p + "%"); } ) ); _wrapped.Write(percents); StartClass(); var properties = frame.Properties.Cast <NameValueProperty>(); var firstN = properties.Take(properties.Count() - 1); var last = properties.LastOrDefault(); foreach (var rule in firstN) { WriteRule(rule, lastRule: false); } if (last != null) { WriteRule(last, lastRule: true); } EndClass(); } EndClass(); }
public void WriteKeyframes(KeyFramesBlock keyframes) { _wrapped.Write("@"); _wrapped.Write(keyframes.Prefix); _wrapped.Write("keyframes "); _wrapped.Write(keyframes.Name); StartClass(); foreach (var frame in keyframes.Frames) { var percents = string.Join( ",", frame.Percentages.Select( p => { if (p == 100m) { return("to"); } if (p == 0m) { return("from"); } return(p + "%"); } ) ); _wrapped.WriteLine(percents); StartClass(); foreach (var rule in frame.Properties.Cast <NameValueProperty>()) { WriteRule(rule); } EndClass(); } EndClass(); }
public static List <Block> Task(List <Block> blocks) { var ret = new List <Block>(); // Gotta maintain order at this point foreach (var block in blocks) { var selBlock = block as SelectorAndBlock; if (selBlock != null) { ret.Add(PrefixBlock(selBlock)); continue; } var mediaBlock = block as MediaBlock; if (mediaBlock != null) { var mediaRet = new List <Block>(); foreach (var subBlock in mediaBlock.Blocks.Cast <SelectorAndBlock>()) { mediaRet.Add(PrefixBlock(subBlock)); } ret.Add(new MediaBlock(mediaBlock.MediaQuery, mediaRet, mediaBlock.Start, mediaBlock.Stop, mediaBlock.FilePath)); continue; } var keyframesBlock = block as KeyFramesBlock; if (keyframesBlock != null) { var keyframeRet = new List <KeyFrame>(); foreach (var frame in keyframesBlock.Frames) { var frameProp = new List <Property>(); foreach (var prop in frame.Properties.Cast <NameValueProperty>()) { frameProp.AddRange(PrefixProperty(prop)); } keyframeRet.Add(new KeyFrame(frame.Percentages.ToList(), frameProp, frame.Start, frame.Stop, frame.FilePath)); } var prefixedKeyframe = new KeyFramesBlock(keyframesBlock.Prefix, keyframesBlock.Name, keyframeRet, keyframesBlock.Variables.ToList(), keyframesBlock.Start, keyframesBlock.Stop, keyframesBlock.FilePath); ret.Add(prefixedKeyframe); // there are @-wekbit-, @-moz-, and @-o- versions of @keyframes (of course...) if (prefixedKeyframe.Prefix.IsNullOrEmpty()) { if (!blocks.OfType <KeyFramesBlock>().Any(a => a.Prefix.Equals("-webkit-", StringComparison.InvariantCultureIgnoreCase) && a.Name == prefixedKeyframe.Name)) { ret.Add(new KeyFramesBlock("-webkit-", prefixedKeyframe.Name, prefixedKeyframe.Frames.ToList(), prefixedKeyframe.Variables.ToList(), prefixedKeyframe.Start, prefixedKeyframe.Stop, prefixedKeyframe.FilePath)); } if (!blocks.OfType <KeyFramesBlock>().Any(a => a.Prefix.Equals("-moz-", StringComparison.InvariantCultureIgnoreCase) && a.Name == prefixedKeyframe.Name)) { ret.Add(new KeyFramesBlock("-moz-", prefixedKeyframe.Name, prefixedKeyframe.Frames.ToList(), prefixedKeyframe.Variables.ToList(), prefixedKeyframe.Start, prefixedKeyframe.Stop, prefixedKeyframe.FilePath)); } if (!blocks.OfType <KeyFramesBlock>().Any(a => a.Prefix.Equals("-o-", StringComparison.InvariantCultureIgnoreCase) && a.Name == prefixedKeyframe.Name)) { ret.Add(new KeyFramesBlock("-o-", prefixedKeyframe.Name, prefixedKeyframe.Frames.ToList(), prefixedKeyframe.Variables.ToList(), prefixedKeyframe.Start, prefixedKeyframe.Stop, prefixedKeyframe.FilePath)); } } continue; } var fontBlock = block as FontFaceBlock; if (fontBlock != null) { var fontRet = new List <Property>(); foreach (var rule in fontBlock.Properties.Cast <NameValueProperty>()) { fontRet.AddRange(PrefixProperty(rule)); } ret.Add(new FontFaceBlock(fontRet, fontBlock.Start, fontBlock.Stop, fontBlock.FilePath)); continue; } ret.Add(block); } return(ret); }