public BootWindow(params Union <string, Control, HTMLElement>[] typos) : base("")
        {
            if (assignedBootWindow == string.Empty)
            {
                assignedBootWindow = CreateWindowHandle().ToString();
            }

            responsiveClass = GetResponsiveClass();

            privateSyle = new HTMLStyleElement();
            this.Body.AppendChild(privateSyle);

            var container = (new BootStyleWidget("container"));                      // fluid

            this.BackColor = Color.White;
            this.Body.AppendChild(container.Content);
            this.BodyStyle.OverflowY = Overflow.Auto;
            this.BodyStyle.OverflowX = Overflow.Hidden;

            prevBody = this.Body;

            this.Body = (HTMLDivElement)container.Content;
            this.BodyStyle.Padding = "0";

            SetCalcSize();

            if (typos != null)
            {
                int length = typos.Length;
                for (int i = 0; i < length; i++)
                {
                    if (typos[i].Is <string>())
                    {
                        this.Body.AppendChild(Document.CreateTextNode((string)typos[i]));
                    }
                    else if (typos[i].Is <Control>())
                    {
                        if (typos[i].Is <Navbar>())
                        {
                            makeChangesForNav((Navbar)typos[i]);
                        }
                        else
                        {
                            this.Body.AppendChild((Control)typos[i]);
                        }
                    }
                    else if (typos[i].Is <HTMLElement>())
                    {
                        if (((HTMLElement)typos[i]).TagName.ToUpper() == "NAV")
                        {
                            makeChangesForNav(BootWidget.CastElement <Navbar>((HTMLElement)typos[i]));
                        }
                        else
                        {
                            this.Body.AppendChild((HTMLElement)typos[i]);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static StyleSheet Style(HTMLStyleElement style)
        {
            var sheet = CssParser.ParseStyleSheet(style.TextContent);

            sheet.Media.MediaText = style.Media;
            sheet.OwnerNode       = style;
            return(sheet);
        }
Exemplo n.º 3
0
 private static void Main()
 {
     HTMLStyleElement styleElement = (HTMLStyleElement)document.createElement("style");
 }
Exemplo n.º 4
0
            public static void SetPrimary(Color primaryLightColor, Color primaryDarkColor)
            {
                if (_primaryStyleElement is object)
                {
                    _primaryStyleElement.remove();
                    _primaryStyleElement = null;
                }

                var borderColorLight      = (HSLColor)primaryLightColor;
                var borderColorDark       = (HSLColor)primaryDarkColor;
                var backgroundActiveLight = (HSLColor)primaryLightColor;
                var backgroundActiveDark  = (HSLColor)primaryDarkColor;

                // rgb(0, 120, 212)  = hsl(206, 100, 41.6)
                // rgb(16, 110, 190) = hsl(208, 85.5, 40.4)
                // rgb(0, 90, 158)   = hsl(206, 100, 31)

                borderColorLight.Luminosity -= (100 - 85.5);       //Uses the same delta as in the current template
                borderColorLight.Saturation -= (41.6 - 40.4);      //TODO: get real values instead using Color.EvalVar
                borderColorLight.Hue        -= (206 - 208);        // Main problem is just how to handle the .tss-dark-mode eval, as it will change the return value

                borderColorDark.Luminosity -= (100 - 85.5);
                borderColorDark.Saturation -= (41.6 - 40.4);
                borderColorDark.Hue        -= (206 - 208);

                backgroundActiveLight.Luminosity -= (100 - 100);
                backgroundActiveLight.Saturation -= (41.6 - 31);
                backgroundActiveLight.Hue        -= (206 - 206);

                backgroundActiveDark.Luminosity -= (100 - 100);
                backgroundActiveDark.Saturation -= (41.6 - 31);
                backgroundActiveDark.Hue        -= (206 - 206);

                var sb = new StringBuilder();

                sb.AppendLine(":root {");
                sb.Append("  --tss-primary-background-color: ").Append(primaryLightColor.ToRGB()).AppendLine(";");
                sb.Append("  --tss-sidebar-background-color: ").Append(primaryLightColor.ToRGB()).AppendLine(";");
                sb.Append("  --tss-link-color: ").Append(primaryLightColor.ToRGB()).AppendLine(";");
                sb.Append("  --tss-primary-border-color: ").Append(borderColorLight.ToRGB()).AppendLine(";");
                sb.Append("  --tss-primary-background-hover-color: ").Append(borderColorLight.ToRGB()).AppendLine(";");
                sb.Append("  --tss-primary-background-active-color: ").Append(backgroundActiveLight.ToRGB()).AppendLine(";");
                sb.Append("  --tss-primary-shadow: ").Append($"0 1.6px 3.6px 0 {primaryLightColor.ToRGBA(0.132f)}, 0 0.3px 0.9px 0 {primaryLightColor.ToRGBA(0.108f)}").AppendLine(";");
                sb.AppendLine("}");

                sb.AppendLine(".tss-dark-mode {");
                sb.Append("  --tss-primary-background-color: ").Append(primaryDarkColor.ToRGB()).AppendLine(";");
                sb.Append("  --tss-sidebar-background-color: ").Append(primaryDarkColor.ToRGB()).AppendLine(";");
                sb.Append("  --tss-link-color: ").Append(primaryDarkColor.ToRGB()).AppendLine(";");
                sb.Append("  --tss-primary-border-color: ").Append(borderColorDark.ToRGB()).AppendLine(";");
                sb.Append("  --tss-primary-background-hover-color: ").Append(borderColorDark.ToRGB()).AppendLine(";");
                sb.Append("  --tss-primary-background-active-color: ").Append(backgroundActiveDark.ToRGB()).AppendLine(";");
                sb.Append("  --tss-primary-shadow: ").Append($"0 1.6px 3.6px 0 {primaryDarkColor.ToRGBA(0.132f)}, 0 0.3px 0.9px 0 {primaryDarkColor.ToRGBA(0.108f)}").AppendLine(";");
                sb.AppendLine("}");

                _primaryStyleElement      = (HTMLStyleElement)document.createElement("style");
                _primaryStyleElement.type = "text/css";
                _primaryStyleElement.appendChild(document.createTextNode(sb.ToString()));

                var head = document.getElementsByTagName("head")[0];

                head.appendChild(_primaryStyleElement);
            }
Exemplo n.º 5
0
        public void Merge(string[] htmlFiles, string outPath)
        {
            _htmlOutputPath = Path.GetDirectoryName(outPath);
            var temp = Path.Combine(_htmlOutputPath, "Output2");

            Directory.CreateDirectory(temp);

            for (var i = 0; i < htmlFiles.Length; i++)
            {
                var htmlFile           = htmlFiles[i];
                var fileName           = Path.GetFileName(htmlFile);
                var tempOutputFilePath = Path.Combine(temp, fileName);
                File.Copy(htmlFile, tempOutputFilePath);
                htmlFiles[i] = tempOutputFilePath;

                using (var htmlDocument = new HTMLDocument(htmlFiles[i]))
                {
                    HTMLDivElement   anchorDivContainer = (HTMLDivElement)htmlDocument.CreateElement("div");
                    HTMLBodyElement  htmlDocumentBody   = (HTMLBodyElement)htmlDocument.Body;
                    HTMLHeadElement  head             = (HTMLHeadElement)htmlDocument.GetElementsByTagName("head")[0];
                    HTMLStyleElement htmlStyleElement = (HTMLStyleElement)htmlDocument.CreateElement("style");

                    var resetEvent = new AutoResetEvent(false);
                    htmlStyleElement.OnLoad  += (sender, e) => { resetEvent.Set(); };
                    htmlStyleElement.OnError += (sender, e) => { resetEvent.Set(); };

                    var cssContent = htmlDocument.CreateTextNode(_content);
                    htmlStyleElement.AppendChild(cssContent);
                    head.AppendChild(htmlStyleElement);
                    resetEvent.WaitOne();

                    anchorDivContainer.SetAttribute("class", "container");
                    anchorDivContainer.SetAttribute("align", "center");

                    var paragraphElement = GetParagraphElement(htmlDocument, "Navigation");
                    anchorDivContainer.AppendChild(paragraphElement);

                    if (i != 0)
                    {
                        var anchorBackward = GetAnchorElement(htmlDocument, "Backward");
                        anchorBackward.Href = Path.GetFileName(htmlFiles[i - 1]);
                        anchorDivContainer.AppendChild(anchorBackward);
                    }
                    else
                    {
                        HTMLAnchorElement anchorBackward = GetAnchorElement(htmlDocument, "Backward");
                        anchorBackward.Href = Path.GetFileName(htmlFiles[htmlFiles.Length - 1]);
                        anchorDivContainer.AppendChild(anchorBackward);
                    }

                    if (i != htmlFiles.Length - 1)
                    {
                        HTMLAnchorElement anchorForward = GetAnchorElement(htmlDocument, "Forward");
                        anchorForward.Href = Path.GetFileName(htmlFiles[i + 1]);
                        anchorDivContainer.AppendChild(anchorForward);
                    }
                    else
                    {
                        HTMLAnchorElement anchorForward = GetAnchorElement(htmlDocument, "Forward");
                        anchorForward.Href = Path.GetFileName(htmlFiles[0]);
                        anchorDivContainer.AppendChild(anchorForward);
                    }

                    Node firstChild = htmlDocumentBody.FirstChild;
                    htmlDocumentBody.InsertBefore(anchorDivContainer, firstChild);
                    var outputPath = Path.Combine(_htmlOutputPath, fileName);
                    htmlDocument.Save(outputPath);
                    htmlDocument.Dispose();
                    htmlFiles[i] = outputPath;
                    ClearDirectory(temp);
                }
            }
            var name = Path.GetFileNameWithoutExtension(outPath);

            SaveDocument($"{name}.mhtml", htmlFiles[0], htmlFiles.Length);
        }