Merge pull request #1122 from hgiesel/webviewcss2

Prefer SASS over including files
This commit is contained in:
Damien Elmes 2021-04-14 11:55:19 +10:00 committed by GitHub
commit ff944c88fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 160 additions and 116 deletions

View File

@ -1,6 +1,6 @@
load("@bazel_skylib//rules:copy_file.bzl", "copy_file") load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("//ts:copy.bzl", "copy_files_into_group") load("//ts:copy.bzl", "copy_files_into_group")
load("compile_sass.bzl", "compile_sass") load("//ts:compile_sass.bzl", "compile_sass")
compile_sass( compile_sass(
srcs = glob( srcs = glob(
@ -8,15 +8,15 @@ compile_sass(
exclude = ["_*.scss"], exclude = ["_*.scss"],
), ),
group = "css_local", group = "css_local",
deps = [
"//ts/sass:core_lib",
"//ts/sass:buttons_lib",
"//ts/sass:scrollbar_lib",
"//ts/sass:card_counts_lib",
],
visibility = ["//visibility:private"], visibility = ["//visibility:private"],
) )
copy_file(
name = "core_css",
src = "//ts/sass:core.css",
out = "core.css",
)
copy_files_into_group( copy_files_into_group(
name = "editor", name = "editor",
srcs = [ srcs = [
@ -29,10 +29,8 @@ copy_files_into_group(
filegroup( filegroup(
name = "css", name = "css",
srcs = [ srcs = [
"core.css",
"css_local", "css_local",
"editor", "editor",
"//qt/aqt/data/web/css/vendor",
], ],
visibility = ["//qt:__subpackages__"], visibility = ["//qt:__subpackages__"],
) )

View File

@ -1,34 +0,0 @@
.review-count {
color: var(--review-count);
}
.new-count {
color: var(--new-count);
}
.learn-count {
color: var(--learn-count);
}
.zero-count {
color: var(--zero-count);
}
.nightMode {
.review-count {
color: var(--review-count);
}
.new-count {
color: var(--new-count);
}
.learn-count {
color: var(--learn-count);
}
.zero-count {
color: var(--zero-count);
}
}

View File

@ -1,7 +1,7 @@
/* Copyright: Ankitects Pty Ltd and contributors /* Copyright: Ankitects Pty Ltd and contributors
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */ * License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
@use 'card_counts'; @use 'ts/sass/card_counts';
a.deck { a.deck {
color: var(--text-fg); color: var(--text-fg);
@ -84,4 +84,4 @@ body {
div { div {
margin: 1em; margin: 1em;
} }
} }

View File

@ -1,7 +1,7 @@
/* Copyright: Ankitects Pty Ltd and contributors /* Copyright: Ankitects Pty Ltd and contributors
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */ * License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
@use 'card_counts'; @use 'ts/sass/card_counts';
.smallLink { .smallLink {
font-size: 10px; font-size: 10px;

View File

@ -1,7 +1,7 @@
/* Copyright: Ankitects Pty Ltd and contributors /* Copyright: Ankitects Pty Ltd and contributors
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */ * License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
@use 'card_counts'; @use 'ts/sass/card_counts';
body { body {
margin: 0; margin: 0;

View File

@ -1,17 +0,0 @@
load("//ts:vendor.bzl", "copy_bootstrap_css")
copy_bootstrap_css(name = "bootstrap")
files = [
"bootstrap",
]
directories = []
filegroup(
name = "vendor",
srcs = glob(["*.css"]) +
["//qt/aqt/data/web/css/vendor:{}".format(file) for file in files] +
["//qt/aqt/data/web/css/vendor/{}".format(dir) for dir in directories],
visibility = ["//qt:__subpackages__"],
)

View File

@ -3,6 +3,7 @@ load("//ts:copy.bzl", "copy_files_into_group")
copy_files_into_group( copy_files_into_group(
name = "graphs_page", name = "graphs_page",
srcs = [ srcs = [
"graphs-base.css",
"graphs.css", "graphs.css",
"graphs.html", "graphs.html",
"graphs.js", "graphs.js",
@ -13,6 +14,7 @@ copy_files_into_group(
copy_files_into_group( copy_files_into_group(
name = "congrats_page", name = "congrats_page",
srcs = [ srcs = [
"congrats-base.css",
"congrats.css", "congrats.css",
"congrats.html", "congrats.html",
"congrats.js", "congrats.js",

View File

@ -232,15 +232,14 @@ class Editor:
self.web.stdHtml( self.web.stdHtml(
_html % (bgcol, topbuts, tr.editing_show_duplicates()), _html % (bgcol, topbuts, tr.editing_show_duplicates()),
css=[ css=[
"css/vendor/bootstrap.min.css",
"css/editor.css", "css/editor.css",
], ],
js=[ js=[
"js/vendor/jquery.min.js", "js/vendor/jquery.min.js",
"js/vendor/bootstrap.bundle.min.js",
"js/editor.js", "js/editor.js",
], ],
context=self, context=self,
default_css=False,
) )
self.web.eval("preventButtonFocus();") self.web.eval("preventButtonFocus();")

View File

@ -456,13 +456,15 @@ body {{ zoom: {zoom}; background: {background}; direction: {lang_dir}; {font} }}
js: Optional[List[str]] = None, js: Optional[List[str]] = None,
head: str = "", head: str = "",
context: Optional[Any] = None, context: Optional[Any] = None,
default_css: bool = True,
) -> None: ) -> None:
web_content = WebContent( web_content = WebContent(
body=body, body=body,
head=head, head=head,
js=["js/webview.js"] + (["js/vendor/jquery.min.js"] if js is None else js), js=["js/webview.js"] + (["js/vendor/jquery.min.js"] if js is None else js),
css=["css/webview.css"] + ([] if css is None else css), css=(["css/webview.css"] if default_css else [])
+ ([] if css is None else css),
) )
gui_hooks.webview_will_set_content(web_content, context) gui_hooks.webview_will_set_content(web_content, context)

View File

@ -1,6 +1,6 @@
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary") load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
def compile_sass(group, srcs, visibility): def compile_sass(group, srcs, visibility, deps):
css_files = [] css_files = []
for scss_file in srcs: for scss_file in srcs:
base = scss_file.replace(".scss", "") base = scss_file.replace(".scss", "")
@ -12,7 +12,8 @@ def compile_sass(group, srcs, visibility):
name = name, name = name,
src = scss_file, src = scss_file,
sourcemap = False, sourcemap = False,
deps = ["//ts/sass:core_lib"], deps = deps,
visibility = visibility,
) )
native.filegroup( native.filegroup(

View File

@ -3,12 +3,24 @@ load("//ts:prettier.bzl", "prettier_test")
load("//ts:eslint.bzl", "eslint_test") load("//ts:eslint.bzl", "eslint_test")
load("//ts/svelte:svelte.bzl", "svelte", "svelte_check") load("//ts/svelte:svelte.bzl", "svelte", "svelte_check")
load("//ts:esbuild.bzl", "esbuild") load("//ts:esbuild.bzl", "esbuild")
load("//ts:compile_sass.bzl", "compile_sass")
compile_sass(
group = "base_css",
srcs = ["congrats-base.scss"],
deps = [
"//ts/sass:base_lib",
"//ts/sass:scrollbar_lib",
],
visibility = ["//visibility:public"],
)
svelte( svelte(
name = "CongratsPage", name = "CongratsPage",
entry_point = "CongratsPage.svelte", entry_point = "CongratsPage.svelte",
) )
ts_library( ts_library(
name = "index", name = "index",
srcs = ["index.ts"], srcs = ["index.ts"],
@ -16,6 +28,7 @@ ts_library(
"CongratsPage", "CongratsPage",
"lib", "lib",
"//ts/lib", "//ts/lib",
"@npm//svelte",
"@npm//svelte2tsx", "@npm//svelte2tsx",
], ],
) )
@ -47,11 +60,11 @@ esbuild(
output_css = True, output_css = True,
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [ deps = [
"CongratsPage",
"index",
"//ts/lib", "//ts/lib",
"//ts/lib:backend_proto", "//ts/lib:backend_proto",
"//ts/sass:core_css", "CongratsPage",
":index",
":base_css",
], ],
) )

View File

@ -3,8 +3,6 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import "../sass/core.css";
import type pb from "anki/backend_proto"; import type pb from "anki/backend_proto";
import { buildNextLearnMsg } from "./lib"; import { buildNextLearnMsg } from "./lib";
import { bridgeLink } from "anki/bridgecommand"; import { bridgeLink } from "anki/bridgecommand";

View File

@ -0,0 +1,6 @@
@use 'ts/sass/core';
@use 'ts/sass/scrollbar';
.night-mode {
@include scrollbar.night-mode;
}

View File

@ -3,6 +3,7 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" id="viewport" content="width=device-width" /> <meta name="viewport" id="viewport" content="width=device-width" />
<link href="congrats-base.css" rel="stylesheet" />
<link href="congrats.css" rel="stylesheet" /> <link href="congrats.css" rel="stylesheet" />
<script src="../js/vendor/protobuf.min.js"></script> <script src="../js/vendor/protobuf.min.js"></script>
<script src="congrats.js"></script> <script src="congrats.js"></script>

View File

@ -3,17 +3,16 @@ load("//ts:prettier.bzl", "prettier_test")
load("//ts:eslint.bzl", "eslint_test") load("//ts:eslint.bzl", "eslint_test")
load("//ts:esbuild.bzl", "esbuild") load("//ts:esbuild.bzl", "esbuild")
load("//ts:vendor.bzl", "copy_bootstrap_icons") load("//ts:vendor.bzl", "copy_bootstrap_icons")
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary") load("//ts:compile_sass.bzl", "compile_sass")
sass_binary( compile_sass(
name = "editor_css", group = "base_css",
src = "editor.scss", srcs = ["editor.scss", "editable.scss"],
visibility = ["//visibility:public"], deps = [
) "//ts/sass:base_lib",
"//ts/sass:buttons_lib",
sass_binary( "//ts/sass:scrollbar_lib",
name = "editable_css", ],
src = "editable.scss",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
@ -42,8 +41,9 @@ esbuild(
entry_point = "index_wrapper.ts", entry_point = "index_wrapper.ts",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [ deps = [
"bootstrap-icons", ":bootstrap-icons",
"editor_ts", ":editor_ts",
"base_css",
], ],
) )

View File

@ -1,4 +1,4 @@
@use '../sass/scrollbar'; @use 'ts/sass/scrollbar';
anki-editable { anki-editable {
display: block; display: block;

View File

@ -1,9 +1,12 @@
/* Copyright: Ankitects Pty Ltd and contributors /* Copyright: Ankitects Pty Ltd and contributors
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */ * License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
body { @use 'ts/sass/base';
color: var(--text-fg); @use 'ts/sass/buttons';
background-color: var(--bg-color); @use 'ts/sass/scrollbar';
.nightMode {
@include scrollbar.night-mode;
} }
#fields { #fields {

View File

@ -3,6 +3,17 @@ load("//ts/svelte:svelte.bzl", "compile_svelte", "svelte_check")
load("//ts:prettier.bzl", "prettier_test") load("//ts:prettier.bzl", "prettier_test")
load("//ts:eslint.bzl", "eslint_test") load("//ts:eslint.bzl", "eslint_test")
load("//ts:esbuild.bzl", "esbuild") load("//ts:esbuild.bzl", "esbuild")
load("//ts:compile_sass.bzl", "compile_sass")
compile_sass(
group = "base_css",
srcs = ["graphs-base.scss"],
deps = [
"//ts/sass:base_lib",
"//ts/sass:scrollbar_lib",
],
visibility = ["//visibility:public"],
)
svelte_files = glob(["*.svelte"]) svelte_files = glob(["*.svelte"])
@ -67,7 +78,7 @@ esbuild(
"//ts/lib", "//ts/lib",
"//ts/lib:backend_proto", "//ts/lib:backend_proto",
":index", ":index",
"//ts/sass:core_css", ":base_css",
] + svelte_names, ] + svelte_names,
) )

View File

@ -57,6 +57,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
text-align: center; text-align: center;
margin-bottom: 0.25em; margin-bottom: 0.25em;
margin-top: 1.5em; margin-top: 1.5em;
font-weight: bold;
} }
.subtitle { .subtitle {

View File

@ -3,8 +3,6 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="typescript"> <script lang="typescript">
import "../sass/core.css";
import type { SvelteComponent } from "svelte/internal"; import type { SvelteComponent } from "svelte/internal";
import { writable } from "svelte/store"; import { writable } from "svelte/store";

View File

@ -0,0 +1,6 @@
@use 'ts/sass/base';
@use 'ts/sass/scrollbar';
.night-mode {
@include scrollbar.night-mode;
}

View File

@ -3,6 +3,7 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" id="viewport" content="width=device-width" /> <meta name="viewport" id="viewport" content="width=device-width" />
<link href="graphs-base.css" rel="stylesheet" />
<link href="graphs.css" rel="stylesheet" /> <link href="graphs.css" rel="stylesheet" />
<script src="../js/vendor/protobuf.min.js"></script> <script src="../js/vendor/protobuf.min.js"></script>
<script src="graphs.js"></script> <script src="graphs.js"></script>

View File

@ -1,12 +1,29 @@
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library") load("@io_bazel_rules_sass//:defs.bzl", "sass_library")
sass_binary( sass_library(
name = "core_css", name = "base_lib",
src = "core.scss", srcs = [
visibility = ["//visibility:public"], "_vars.scss",
deps = [ "base.scss",
":core_lib",
], ],
visibility = ["//visibility:public"],
)
sass_library(
name = "buttons_lib",
srcs = [
"_fusion_vars.scss",
"buttons.scss",
],
visibility = ["//visibility:public"],
)
sass_library(
name = "card_counts_lib",
srcs = [
"card_counts.scss",
],
visibility = ["//visibility:public"],
) )
sass_library( sass_library(
@ -18,8 +35,16 @@ sass_library(
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
sass_library(
name = "scrollbar_lib",
srcs = [
"scrollbar.scss",
],
visibility = ["//visibility:public"],
)
# qt package extracts colours from source file # qt package extracts colours from source file
exports_files( exports_files(
["_vars.scss"], ["_vars.scss"] + glob(["*.scss"], exclude = ["_*.scss"]),
visibility = ["//qt:__subpackages__"], visibility = ["//qt:__subpackages__", "//ts:__subpackages__"],
) )

View File

@ -0,0 +1,7 @@
/* night-mode-specific colours */
$button-gradient-start: #555555;
$button-gradient-end: #656565;
$button-outline: #222222;
$button-hover-bg: #656565;
$button-border: #646464;
$button-base-bg: #454545;

14
ts/sass/base.scss Normal file
View File

@ -0,0 +1,14 @@
@use 'vars';
$body-color: var(--text-fg);
$body-bg: var(--window-bg);
$link-hover-color: var(--link);
$link-hover-decoration: none;
@import "ts/node_modules/bootstrap/scss/bootstrap-reboot";
@import "ts/node_modules/bootstrap/scss/bootstrap-utilities";
body {
overscroll-behavior: none;
}

View File

@ -1,10 +1,4 @@
/* night-mode-specific colours */ @use 'fusion_vars';
$fusion-button-gradient-start: #555555;
$fusion-button-gradient-end: #656565;
$fusion-button-outline: #222222;
$fusion-button-hover-bg: #656565;
$fusion-button-border: #646464;
$fusion-button-base-bg: #454545;
.isWin { .isWin {
button { button {
@ -37,11 +31,11 @@ $fusion-button-base-bg: #454545;
/* match the fusion button gradient */ /* match the fusion button gradient */
background: linear-gradient( background: linear-gradient(
0deg, 0deg,
$fusion-button-gradient-start 0%, fusion_vars.$button-gradient-start 0%,
$fusion-button-gradient-end 100% fusion_vars.$button-gradient-end 100%
); );
box-shadow: 0 0 3px $fusion-button-outline; box-shadow: 0 0 3px fusion_vars.$button-outline;
border: 1px solid $fusion-button-border; border: 1px solid fusion_vars.$button-border;
border-radius: 2px; border-radius: 2px;
padding: 10px; padding: 10px;
@ -50,7 +44,7 @@ $fusion-button-base-bg: #454545;
} }
button:hover { button:hover {
background: $fusion-button-hover-bg; background: fusion_vars.$button-hover-bg;
} }
} }

15
ts/sass/card_counts.scss Normal file
View File

@ -0,0 +1,15 @@
.review-count {
color: var(--review-count);
}
.new-count {
color: var(--new-count);
}
.learn-count {
color: var(--learn-count);
}
.zero-count {
color: var(--zero-count);
}

View File

@ -2,7 +2,7 @@
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */ * License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
@use 'vars'; @use 'vars';
@use 'buttons'; @use 'fusion_vars';
@mixin night-mode { @mixin night-mode {
&::-webkit-scrollbar { &::-webkit-scrollbar {
@ -18,7 +18,7 @@
} }
&::-webkit-scrollbar-thumb { &::-webkit-scrollbar-thumb {
background: buttons.$fusion-button-hover-bg; background: fusion_vars.$button-hover-bg;
border-radius: 8px; border-radius: 8px;
&:horizontal { &:horizontal {