Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS update prebuilts 2024-12-16 #2324

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8d9a44b
CSS builder script and ignore node_modules
ascholerChemeketa Dec 4, 2024
86d0af2
Legacy web colors and themes move to new home
ascholerChemeketa Dec 4, 2024
4e34ffd
Ebook/Reveal targets moved
ascholerChemeketa Dec 4, 2024
10225c0
Catalog moved
ascholerChemeketa Dec 4, 2024
b638468
Delete unused css files
ascholerChemeketa Dec 4, 2024
4258a73
ptx-search in legacy
ascholerChemeketa Dec 4, 2024
6c42c43
JS updates for new themes
ascholerChemeketa Dec 4, 2024
e710dc6
SCSS building blocks
ascholerChemeketa Dec 4, 2024
1452a0e
New modern, tacoma and salem themes
ascholerChemeketa Dec 4, 2024
86a4484
Denver and Greeley themes
oscarlevin Dec 4, 2024
7b30c1d
Pubfile deprecations
ascholerChemeketa Dec 4, 2024
ad73d30
Remove old pub variable xsl
ascholerChemeketa Dec 4, 2024
135c179
Add new pub variables
ascholerChemeketa Dec 4, 2024
37020db
Report new pub variables
ascholerChemeketa Dec 4, 2024
1aedb6e
HTML and Epub generation for new theme file
ascholerChemeketa Dec 4, 2024
3014d66
Python updates for building / moving themes
ascholerChemeketa Dec 4, 2024
752ee8b
Add component "theme" to pretext script
ascholerChemeketa Dec 4, 2024
269421e
Guide documentation
ascholerChemeketa Dec 4, 2024
a0996e0
Set examples/guide to use new themes
ascholerChemeketa Dec 4, 2024
fa775bd
Initial prebuilt files
ascholerChemeketa Dec 4, 2024
6ed8caa
Add block tests to sample article
ascholerChemeketa Dec 8, 2024
91bb425
CSS bugfix - underline sometimes makes it into inline heading
ascholerChemeketa Dec 9, 2024
54e01ee
Summary link variable name fix
ascholerChemeketa Dec 9, 2024
89ba2db
Salem theme widening edge case fix
ascholerChemeketa Dec 9, 2024
2694cc9
Salem exercise and footer button tweaks
ascholerChemeketa Dec 9, 2024
4f38f70
Update prebuilt themes with recent CSS changes
ascholerChemeketa Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ examples/webwork/minimal/generated/*
**/cli.log
**/rsbuild
**/build
**/node_modules/
69 changes: 69 additions & 0 deletions css/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Notes on CSS structure and development

PreTeXt books expect to use a `theme.css` file for its styling. SCSS is used to build that CSS file.

A few themes (the default-modern one and legacy ones that predate SCSS overhaul) are provided "prerolled" in `css/dist`. These can be used without rebuilding from SCSS and even gently modified via the appending of CSS `variables` to customize things like `primary-color`.

Other themes, or using `options` to more substantially change a "prerolled" theme, require that the theme is rebuilt.

## Building

If a book's theme requires building, the pretext script or CLI should handle all of the build details. If you are using the CLI, it should handle installing the build tools as well. If you are using the pretext script, you will need to [install Node and the build script dependencies manually](../script/cssbuilder/README.md#installing-node-and-dependencies)

For more advanced use, including rebuilding themes by hand, see the [CSS Builder script README](../script/cssbuilder/README.md)

### Installing NPM

You will need to [install node](https://nodejs.org/en/download/package-manager).

Install the needed dependencies by switching to the `pretext/script/cssbuilder` and doing `npm install`.

Run `npm run build` to build all the default targets to the output directory (default is `pretext/css/dist`). You can change the directory the build product is produced into with `-o PATH`. If using a relative path, make sure to specify it from the `cssbuilder` folder.

## Folders

### colors

Color palettes that ideally can be used across multiple themes, though it is not expected every palette will be available in every theme. These are all designed to produce a variable `$colors` containing a map of variable definitions. The theme is responsible for turning that map into CSS variables via the `scss-to-css` function.

If a shared palette needs slight modifications by a given theme, the theme can simply override the individual variables (or add new ones). See the comment in `theme-default-modern` for an example.

### components

Shared files that are (or are expected to be) used across many **targets**.

Some of these files are in need of refactoring and modularization.

See README.md in subfolders of `components/` for tips on organization of subcomponents.

### dist

Built CSS ready for inclusion by pretext.

Files in the directory **should not be modified by hand**. The CSS build script in `script/cssbuilder` will produce these files from the items in the `targets` directory.

### fonts

Mechanisms for selection of fonts by a theme

### legacy

Files only used by legacy (pre scss) styles

### targets

Root targets that produce a CSS file. Anything that represents a self-contained final product belongs here.

Any files that are designed only to be used in one target also belong here, grouped with the target they belong to. For example, if `foo.scss` is only intended to be used by the `reveal` target, that file should be placed in the `revealjs` folder.

### other

CSS that is not a part of producing PreTeXt volumes and is not bundled into any target in `dist/` e.g. CSS related to the PreTeXt catalog.

## File "ownership", @use, and copy/paste

Files in the `target` folder are considered "owned" by the folder they are in. When making changes to those files you are encouraged to think about other targets in the same "family" that may @use the files, but are not expected to go out of your way to fix issues in those other targets that result from the changes.

Files in `components` are "shared". Changes to them should consider (and test) all targets that @use the component.

There is a balancing act between the complexity of the include tree for targets and avoiding duplication of effort. Avoid coping/pasting large numbers of rules from one target to another. If you want to reuse some of the rules from another target, consider factoring out those rules into a `component` that the old file and your new one can both @use. But doing so to reuse a small number of CSS rules likely creates more complexity than simply duplicating those rules in your target.
77 changes: 77 additions & 0 deletions css/colors/_color-helpers.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// This file contains functions and mixins for working with colors in SCSS

@use "sass:map";

@mixin set-root-colors($colors, $dark-colors: null) {
:root {
color-scheme: light;
// prevent variable leak through to dark
&:not(.dark-mode) {
@include scss-to-css($colors);
}
}

@if $dark-colors {
:root.dark-mode {
color-scheme: dark;
@include scss-to-css($dark-colors);
}
}
}

// Renders a map of SCSS variables as CSS variables
@mixin scss-to-css($colors) {
@each $name, $value in $colors {
--#{$name}: #{$value};
}
}

// Create a map of colors that blend $color with $other at $mix-amounts
// The resulting map will have keys of the form 'color-other-10'
// Indicating 10% of other mixed into color
@function mixes($color, $other, $mix-amounts) {
$result: ();

@each $i in $mix-amounts {
$result: map.set($result, '#{$color}-#{$other}-#{$i}', 'color-mix(in oklab, var(--#{$color}), #{$other} #{$i}%)');
}

@return $result;
}

$std-mixes: (1, 2, 3, 4, 5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 65, 70, 75, 80, 85, 90, 95, 96, 97, 98, 99);

// Creates a map of color blends for a given color
// By default it creates blends with black, white, and gray at $std-mixes amounts
// Mixing is done using css color-mix function so that if a theme file has the base
// css variable overridden, the blends will be updated accordingly
@function get-blends($color, $shades: $std-mixes, $tints: $std-mixes, $tones: $std-mixes, ) {
$shades: mixes($color, black, $std-mixes);
$tints: mixes($color, white, $std-mixes);
$tones: mixes($color, gray, $std-mixes);

$blends: map.merge(
$tints,
$shades
);

$blends: map.merge(
$blends,
$tones
);
@return $blends;
}

//--------------------------------------------------------------------------
// https://jonnykates.medium.com/automating-colour-contrast-ratios-with-sass-e201f3b52797

@function text-contrast($color, $light: #ffffff, $dark: #000000) {
$color-brightness: round((red($color) * 299) + (green($color) * 587) + (blue($color) * 114) / 1000);
$light-color: round((red(#ffffff) * 299) + (green(#ffffff) * 587) + (blue(#ffffff) * 114) / 1000);
@if abs($color-brightness) < calc($light-color / 2){
@return $light;
} @else {
@return $dark;
}
}
//--------------------------------------------------------------------------
156 changes: 156 additions & 0 deletions css/colors/_color-vars.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
Master list of color variables and default values.
Variables are defined in SCSS to allow for calculation of values. They are
then converted to CSS variables for use in the HTML so authors can, if
need be, override them with custom CSS.

Any new variable should be added to this file and either defined to another
variable or given a reasonable default value for the red-blue default theme.

Variables should be semantic, not descriptive
i.e. --link-color, not --pretty-blue
*/

@use "sass:map";

// ==============================================================================
// Light theme

// ==============================================================================
// Page structures

$colors: (
// Background of page (gutters if any)
"page-color": white,
// Background of content area
"content-background": white,
// Border around content area - also possibly used for internal borders
"page-border-color": #ccc,

// ------------------------------------------------------------------------------
// Banner/nav related

"doc-title-color": #932919,
"byline-color": #333,
"banner-background": #fafafa,
"navbar-background": #ededed,
"footer-background": var(--banner-background),

// ------------------------------------------------------------------------------
// TOC related

"toc-border-color": #666,
"toc-background": var(--content-background),

"tocitem-background": var(--toc-background),
"toc-text-color": var(--body-text-color),

// highlight styles are used for hover
"tocitem-highlight-background": #671d12,
"tocitem-highlight-text-color": white,
"tocitem-highlight-border-color": var(--toc-border-color),

// active styles are used for the current toc item
"tocitem-active-background": #671d12,
"tocitem-active-text-color": white,
"tocitem-active-border-color": var(--toc-border-color),

// level based colors for TOC
// levels are not necessarily all used
// see the toc-basics.scss for how these are determined
"toclevel1-background": var(--content-background),
"toclevel1-text-color": var(--toc-text-color),
"toclevel2-background": var(--content-background),
"toclevel2-text-color": var(--toc-text-color),
"toclevel3-background": var(--content-background),
"toclevel3-text-color": var(--toc-text-color),


// ==============================================================================
// Content
// ==============================================================================

// ------------------------------------------------------------------------------
// Text & titles

"body-text-color": #000,
"body-title-color": #000,

"ptx-image-bg": transparent,
"activated-content-bg": rgba(241, 185, 255, 30%),

"summary-link-background": var(--button-background),
"summary-link-text-color": var(--button-text-color),
"summary-link-hover-background": var(--button-hover-background),
"summary-link-hover-text-color": var(--button-hover-text-color),

// ------------------------------------------------------------------------------
// Links & knowls

"link-text-color": #2B5F82,
"link-background": transparent,
"link-active-text-color": var(--link-text-color),
"link-active-background": #cad2e1,

"link-alt-text-color": #A62E1C,
"link-alt-background": transparent,
"link-alt-active-text-color": var(--link-alt-text-color),
"link-alt-active-background": #e3d1ce,

"knowl-link-color": var(--link-text-color),
"knowl-background": #f5f8ff,
"knowl-border-color": #e0e9ff,
"knowl-nested-1-background": #f5f5ff,
"knowl-nested-2-background": #fffff5,
"knowl-nested-3-background": #f5ffff,
"knowl-nested-4-background": #fff5f5,

// ------------------------------------------------------------------------------
// Blocks

// Fall back generic block colors:
"block-body-background": var(--content-background),
"block-border-color": var(--knowl-border-color),
"block-head-color": var(--body-text-color),

// See below for specific block types

// ------------------------------------------------------------------------------
// Buttons & Widgets

"button-background": #ededed,
"button-text-color": #333333,
"button-border-color": #ccc,
"button-hover-background": #c7c7c7,
"button-hover-text-color": var(--button-text-color),
"code-inline": #ededed,

"dropdown-background": var(--content-background),
"dropdown-border-color": var(--toc-border-color),
"dropdown-text-color": var(--toc-text-color),
"dropdown-hover-background": var(--tocitem-active-background),
"dropdown-hover-text-color": var(--tocitem-active-text-color),
);

// ==============================================================================
// Block types

// Variables for specific block types should look like those below. In this file
// only "top level" blocks from the -like families are defined.
// Other themes/color palettes may define
// more specific ones - see palette_quad_chunks.scss for an example.

// block-types based on those in entities.ent
$block-types: "assemblage-like", "definition-like", "theorem-like", "theorem-like", "axiom-like", "remark-like", "computation-like", "openproblem-like", "aside-like", "proof-like", "example-like", "project-like", "goal-like", "solution-like";
// TODO - "proof" should probably be updated to "proof-like" in HTML css

@each $block in $block-types {
$colors: map.merge(
$colors,
(
// define background and border, but default to generic block colors
"#{$block}-body-background": var(--block-body-background),
"#{$block}-border-color": var(--block-border-color),
)
);
}
Loading