public void CanMergeWHenFalseyValues()
        {
            var result = StyleEngine
                         .MergeStyleSets(null,
                                         new StyleSetFake
            {
                Root = new Style {
                    Background = "red"
                },
                A = new Style {
                    Background = "green"
                }
            },
                                         null,
                                         new StyleSetFake
            {
                A = new Style {
                    Background = "white"
                },
                B = new Style {
                    Background = "blue"
                }
            });

            Assert.AreEqual("root-0", result.Root);
            Assert.AreEqual("a-1", result.A);
            Assert.AreEqual("b-2", result.B);
            Assert.AreEqual(".root-0{background:red;}" + ".a-1{background:white;}" + ".b-2{background:blue;}", _stylesheet.GetRules());
        }
        public void CanMergeWhenAllInputsAraFalsy()
        {
            var result = StyleEngine.MergeStyleSets <StyleSetFake>(null, false, null);

            Assert.AreEqual(new StyleSetFake(), result);
            Assert.AreEqual("", _stylesheet.GetRules());
        }
コード例 #3
0
        public async Task SupportOverridingTheDefaultPrefix()
        {
            var className = await StyleEngine.StyleToClassName(new Style { Background = "red" });

            Assert.AreEqual(className, "myCss-0");
            Assert.AreEqual(".myCss-0{background:red;}", _stylessheet.GetRules());
        }
コード例 #4
0
        public static void ExportDefaultStyle(string baseDir, StyleEngine styleEngine)
        {
            var textAssetType = Il2CppType.Of <TextAsset>();
            var spriteType    = Il2CppType.Of <Sprite>();
            var audioClipType = Il2CppType.Of <AudioClip>();

            MelonLogger.Msg($"Exporting default VRC skin to {baseDir}");
            foreach (var keyValuePair in styleEngine.field_Private_Dictionary_2_Tuple_2_String_Type_Object_0)
            {
                var basePath = Path.Combine(baseDir, keyValuePair.Key.Item1);

                if (keyValuePair.Key.Item2 == textAssetType)
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(basePath) !);
                    var textAsset = keyValuePair.Value.Cast <TextAsset>();
                    File.WriteAllBytes(basePath + ".txt", textAsset.bytes);
                }
                else if (keyValuePair.Key.Item2 == spriteType)
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(basePath) !);
                    var sprite = keyValuePair.Value.Cast <Sprite>();
                    SpriteSnipperUtil.SaveSpriteAsPngWithMetadata(sprite, basePath + ".png");
                }
                else if (keyValuePair.Key.Item2 == audioClipType)
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(basePath) !);
                    var audioClip = keyValuePair.Value.Cast <AudioClip>();
                    WriteWaveFile(basePath + ".wav", audioClip);
                }
            }
            MelonLogger.Msg($"Export finished");
        }
        public void CanExpandChildSelectorsWithStaticClassNames()
        {
            var result = StyleEngine.MergeStyleSets(new StyleSetFake
            {
                Root = new Style[] {
                    "a",
                    new Style
                    {
                        Selectors =
                        {
                            ["&:hover $child"] = new Style {
                                Background = "red"
                            }
                        }
                    }
                },
                Child = new Style[] {
                    "d",
                    new Style
                    {
                        Background = "green"
                    }
                }
            });

            Assert.AreEqual(new StyleSetFake
            {
                Root  = "a root-0",
                Child = "d child-1"
            }, result);
            Assert.AreEqual(".root-0:hover .child-1{background:red;}" + ".child-1{background:green;}", _stylesheet.GetRules());
        }
        public void CarMergeTwoSetsWithClassNames()
        {
            var styleSet1 = StyleEngine.MergeStyleSets(new StyleSetFake
            {
                Root = new Style[] {
                    "ms-Foo", new Style {
                        Background = "red"
                    }
                },
            });

            var styleSet2 = StyleEngine.MergeStyleSets(styleSet1, new StyleSetFake
            {
                Root = new Style[] {
                    "ms-Bar", new Style {
                        Background = "green"
                    }
                },
            });
            var test = $"{styleSet2}";

            Assert.AreEqual(new StyleSetFake {
                Root = "ms-Foo ms-Bar root-1"
            }, styleSet2);
            Assert.AreEqual(".root-0{background:red;}" + ".root-1{background:green;}", _stylesheet.GetRules());
        }
コード例 #7
0
        public async Task CanApplyMediaQueries()
        {
            await StyleEngine.StyleToClassName(new Style
            {
                Background = "blue",
                Selectors  =
                {
                    ["@media(min-width: 300px)"] = new Style
                            {
                            Background = "red",
                            Selectors  =
                            {
                            [":hover"] = new Style
                            {
                            Background = "green"
                            }
                            }
                            }
                }
            });

            var expect = ".css-0{background:blue;}" +
                         "@media(min-width: 300px){" +
                         ".css-0{background:red;}" +
                         "}" +
                         "@media(min-width: 300px){" +
                         ".css-0:hover{background:green;}" +
                         "}";

            Assert.AreEqual(expect, _stylesheet.GetRules());
        }
コード例 #8
0
        /// <summary>
        /// Package typed document asynchronously
        /// </summary>
        /// <typeparam name="T">Type of document body</typeparam>
        /// <param name="request">Request to be packaged</param>
        /// <param name="responseTask">Reponse task to be packaged</param>
        /// <returns>Packaged document</returns>
        protected async Task <IDocument <T> > PackageAndAddDocumentAsync <T>(IRestRequest request, Task <IRestResponse <T> > responseTask)
        {
            Uri requestUri                 = _restClient.BaseUrl;
            IRestResponse <T> response     = await responseTask;
            HtmlParser        parser       = new HtmlParser();
            IHtmlDocument     htmlDocument = parser.ParseDocument(response.Content);
            IDocument <T>     document     = new Document <T>(request, response, htmlDocument);

            Task <int> result      = null;
            Task <int> styleResult = null;

            if (JavascriptScrapingEnabled)
            {
                result = JavascriptEngine.AddAsync(document);
            }
            if (StyleScrapingEnabled)
            {
                styleResult = StyleEngine.AddAsync(document);
            }

            if (JavascriptScrapingEnabled && result != null)
            {
                await result;
            }
            if (StyleScrapingEnabled && styleResult != null)
            {
                await styleResult;
            }
            document.RequestUri = requestUri;
            Documents.Add(document);
            return(document);
        }
コード例 #9
0
 /// <summary>
 /// Secondary initializer
 /// </summary>
 /// <param name="javascriptEngine"></param>
 /// <param name="styleEngine"></param>
 /// <param name="restClient"></param>
 /// <param name="cookieContainer"></param>
 /// <param name="historyManager"></param>
 /// <param name="styleScrapingEnabled"></param>
 /// <param name="javascriptScrapingEnabled"></param>
 /// <param name="defaultUriProtocol"></param>
 public StandardCore(JavascriptEngine javascriptEngine, StyleEngine styleEngine,
                     RestClient restClient, CookieContainer cookieContainer,
                     HistoryManager historyManager, bool styleScrapingEnabled,
                     bool javascriptScrapingEnabled, string defaultUriProtocol) :
     base(javascriptEngine, styleEngine, restClient,
          cookieContainer, historyManager, styleScrapingEnabled,
          javascriptScrapingEnabled, defaultUriProtocol)
 {
 }
コード例 #10
0
        public async Task DoesNotEmitRuleWhichHasAnUndefinedValue()
        {
            var className = await StyleEngine.StyleToClassName(new Style()
            {
                FontFamily = null
            });

            Assert.AreEqual(string.Empty, className);
            Assert.AreEqual("", _stylesheet.GetRules());
        }
コード例 #11
0
        public async Task CanExpandAnArrayOfRules()
        {
            await StyleEngine.StyleToClassName(new Style[] { new Style {
                                                                 Background = "red"
                                                             }, new Style {
                                                                 Background = "white"
                                                             } });

            Assert.AreEqual(".css-0{background:white;}", _stylesheet.GetRules());
        }
コード例 #12
0
 /// <summary>
 /// Default Constructor
 /// </summary>
 public BrowserCore()
 {
     _javascriptEngine           = new JavascriptEngine();
     _styleEngine                = new StyleEngine();
     _restClient                 = new RestClient();
     _restClient.CookieContainer = new CookieContainer();
     _history = new HistoryManager();
     _styleScrapingEnabled      = true;
     _javascriptScrapingEnabled = true;
     DefaultUriProtocol         = "http";
 }
コード例 #13
0
        void registerFontFace(string fontFamily, string url, FontWeight fontWeight = default, string localFontName = null)
        {
            fontFamily = $"'{fontFamily}'";
            var localFontSrc = localFontName != null ? $"local('{localFontName}')," : "";

            StyleEngine.InsertFontFace(new FontFace
            {
                FontFamily = fontFamily,
                Src        = $"{localFontSrc}url('{url}.woff2') format('woff2'),url('{url}.woff') format('woff')",
                FontWeight = fontWeight,
                FontStyle  = FontStyle.Normal
            });
        }
コード例 #14
0
        public async Task CanExpandPreviouslyRegisteredRules()
        {
            var className = await StyleEngine.MergeStyle(new Style { Left = 1 });

            (List <string> classes, List <Style> objects) = await StyleEngine.ExtractStyleParts(className, new Style { Left = 2 });

            CollectionAssert.AreEqual(new List <string>(), classes);
            CollectionAssert.AreEqual(new Style[] { new Style {
                                                        Left = 1
                                                    }, new Style {
                                                        Left = 2
                                                    } }, objects);
        }
コード例 #15
0
        public void CanMergeClassNames()
        {
            var result = StyleEngine.MergeStyleSets(new StyleSetFake
            {
                Root = new Style[] { "a", "b", new Style {
                                         Background = "red"
                                     } }
            });

            Assert.AreEqual(new StyleSetFake {
                Root = "a b root-0"
            }, result);
        }
コード例 #16
0
        public async Task CanFlipRTLAndAddUnits()
        {
            await TransformationsRules.SetRTL(true);

            var style = new Style()
            {
                Left = 40
            };
            var className = await StyleEngine.StyleToClassName(style);

            Assert.AreEqual(".css-0{right:40px;}", _stylesheet.GetRules());
            await TransformationsRules.SetRTL(false);
        }
コード例 #17
0
        public async Task CanHaveSameElementClassSelector()
        {
            var className = await StyleEngine.StyleToClassName(new Style
            {
                Selectors =
                {
                    ["&.foo"] = new Style[] { new Style {
                                                  Background = "red"
                                              } }
                }
            });

            Assert.AreEqual(".css-0.foo{background:red;}", _stylesheet.GetRules());
        }
コード例 #18
0
        public async Task CanExpandIncreasedSpecificityRules()
        {
            await StyleEngine.StyleToClassName(new Style
            {
                Selectors =
                {
                    ["&&&"] = new Style {
                        Background = "red"
                    }
                }
            });

            Assert.AreEqual(".css-0.css-0.css-0{background:red;}", _stylesheet.GetRules());
        }
コード例 #19
0
        public async Task CanExpandPreviusDfinedRules()
        {
            var style = new Style()
            {
                Background = "red"
            };
            var className = await StyleEngine.StyleToClassName(style);

            var newClassName = await StyleEngine.StyleToClassName(className, new Style { Color = "white" });

            Assert.AreEqual("css-1", newClassName);

            Assert.AreEqual(".css-0{background:red;}.css-1{background:red;color:white;}", _stylesheet.GetRules());
        }
コード例 #20
0
        public async Task CanPrefixWebkitSpecificThings()
        {
            VendorSettings.SetCurrent(new VendorSettings {
                IsWebKit = true
            });
            var style = new Style()
            {
                WebkitFontSmoothing = FontSmoothing.None
            };
            var className = await StyleEngine.StyleToClassName(style);

            Assert.AreEqual(".css-0{-webkit-font-smoothing:none;}", _stylesheet.GetRules());
            VendorSettings.SetCurrent(null);
        }
コード例 #21
0
 /// <summary>
 /// Browser core secondary constructor
 /// </summary>
 /// <param name="javascriptEngine"></param>
 /// <param name="styleEngine"></param>
 /// <param name="restClient"></param>
 /// <param name="cookieContainer"></param>
 /// <param name="historyManager"></param>
 /// <param name="styleScrapingEnabled"></param>
 /// <param name="javascriptScrapingEnabled"></param>
 /// <param name="defaultUriProtocol"></param>
 public BrowserCore(JavascriptEngine javascriptEngine, StyleEngine styleEngine,
                    RestClient restClient, CookieContainer cookieContainer,
                    HistoryManager historyManager, bool styleScrapingEnabled,
                    bool javascriptScrapingEnabled, string defaultUriProtocol)
 {
     _javascriptEngine           = javascriptEngine;
     _styleEngine                = styleEngine;
     _restClient                 = restClient;
     _restClient.CookieContainer = cookieContainer;
     _history = historyManager;
     _styleScrapingEnabled      = styleScrapingEnabled;
     _javascriptScrapingEnabled = javascriptScrapingEnabled;
     DefaultUriProtocol         = defaultUriProtocol;
 }
コード例 #22
0
        public async Task CanRegisterGlobalSelectors()
        {
            var className = await StyleEngine.StyleToClassName(new Style()
            {
                Selectors =
                {
                    [":global(button)"] = new Style {
                        Background = "red"
                    }
                }
            });

            Assert.AreEqual("css-0", className);
            Assert.AreEqual("button{background:red;}", _stylesheet.GetRules());
        }
コード例 #23
0
        public void CanNormalizeDuplicateStaticClassName()
        {
            var styles = StyleEngine
                         .MergeStyleSets(new StyleSetFake {
                Root = new Style[] { "a", new Style {
                                         Background = "red"
                                     } }
            });

            var styles1 = StyleEngine.MergeStyleSets(styles, styles);

            Assert.AreEqual(new StyleSetFake {
                Root = "a root-0"
            }, styles1);
        }
コード例 #24
0
 public void CanRegisterFromToKeyframesInRTL()
 {
     TransformationsRules.SetRTL(true).GetAwaiter().GetResult();
     StyleEngine.Keyframes(new Keyframes {
         From = new Style
         {
             Opacity = 0
         },
         To = new Style
         {
             Opacity = 1
         }
     });
     Assert.AreEqual("@keyframes css-0{from{opacity:0;}to{opacity:1;}}", stylesheet.GetRules());
 }
コード例 #25
0
 public void CanRegisterFromToKeyFrames()
 {
     StyleEngine.Keyframes(new Keyframes
     {
         From = new Style
         {
             Opacity = 0,
         },
         To = new Style
         {
             Opacity = 1
         }
     });
     Assert.AreEqual("@keyframes css-0{from{opacity:0;}to{opacity:1;}}", stylesheet.GetRules());
 }
コード例 #26
0
        public async Task CanRegisterPseduoSelectors()
        {
            var className = await StyleEngine.StyleToClassName(new Style
            {
                Selectors = new Dictionary <string, Style>
                {
                    [":hover"] = new Style {
                        Background = "red"
                    }
                }
            });

            Assert.AreEqual("css-0", className, $"Bad generated class name, expected css-0 and get {className}");

            Assert.AreEqual(".css-0:hover{background:red;}", _stylesheet.GetRules());
        }
コード例 #27
0
        public async Task CanPreserveDisplayNameInNames()
        {
            var className = await StyleEngine.StyleToClassName(new Style()
            {
                DisplayName = "foo"
            });

            Assert.AreEqual("foo-0", className);
            className = await StyleEngine.StyleToClassName(new Style()
            {
                DisplayName = "foo"
            });

            Assert.AreEqual("foo-0", className);
            Assert.AreEqual("", _stylesheet.GetRules());
        }
コード例 #28
0
        public async Task CanMergeTools()
        {
            var className = await StyleEngine.StyleToClassName(
                null,
                false,
                null,
                new Style { BackgroundColor = "red", Color = "white" },
                new Style { BackgroundColor = "green" });

            Assert.AreEqual("css-0", className, $"Bad generated class name, expected css-0 and get {className}");
            Assert.AreEqual(".css-0{background-color:green;color:white;}", _stylesheet.GetRules());

            className = await StyleEngine.StyleToClassName(new Style { BackgroundColor = "green", Color = "white" });

            Assert.AreEqual("css-0", className, $"Bad generated class name, expected css-0 and get {className}");
        }
コード例 #29
0
        public async Task SameClassNameForOnlyDysplayNameRule()
        {
            var className = await StyleEngine.StyleToClassName(new Style()
            {
                DisplayName = "foo"
            });

            Assert.AreEqual("foo-0", className);
            className = await StyleEngine.StyleToClassName(new Style()
            {
                DisplayName = "foo"
            });

            Assert.AreEqual("foo-0", className);
            Assert.AreEqual("", _stylesheet.GetRules());
        }
コード例 #30
0
        public async Task CanRegisterClassesAndAvoidReRegistering()
        {
            var className = await StyleEngine.StyleToClassName(new Style { Background = "red" });

            Assert.AreEqual("css-0", className, $"Bad generated class name, expected css-0 and get {className}");
            Assert.AreEqual(".css-0{background:red;}", _stylesheet.GetRules());

            className = await StyleEngine.StyleToClassName(new Style { Background = "red" });

            Assert.AreEqual("css-0", className, $"Bad generated class name, expected css-0 and get {className}");
            Assert.AreEqual(".css-0{background:red;}", _stylesheet.GetRules());

            className = await StyleEngine.StyleToClassName(new Style { Background = "green" });

            Assert.AreEqual("css-1", className, $"Bad generated class name, expected css-0 and get {className}");
            Assert.AreEqual(".css-0{background:red;}.css-1{background:green;}", _stylesheet.GetRules());
        }