Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions docs-overrides/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@
<meta property="og:url" content="{{ page.canonical_url }}">
<meta property="og:image" content="{{ config.site_url }}images/social-preview.png">
<meta name="twitter:card" content="summary_large_image">
{#- The theme lets inline code break anywhere, which splits a name a reader copies (HsvColorPick|er,
colorpicker-|material3). In a table, code stays on one line and the table scrolls sideways instead;
in running text, code breaks at its spaces, and inside a name only when the name alone is wider
than the line. -#}
<style>
.md-typeset code { word-break: normal; }
.md-typeset table code { white-space: nowrap; }
</style>
{% endblock %}
10 changes: 5 additions & 5 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ edited. A slider edits in its own channel's space: the color is converted there
is set, and the result stays there. Reading another space converts forward, once, from that
value; nothing is re-derived from a conversion.

```
User drags the OkLCh chroma slider
-> the value is converted into OkLCh once and its chroma set (the value is now OkLCh)
-> the Okhsl sliders read it: one conversion, OkLCh -> Okhsl
-> the OkLCh sliders read it: no conversion at all
```mermaid
flowchart LR
drag["The user drags the OkLCh chroma slider"] -->|"set chroma"| value[("The value, converted into OkLCh once")]
value -->|"one conversion"| okhsl["The Okhsl sliders"]
value -->|"none"| oklch["The OkLCh sliders"]
```

This means:
Expand Down
26 changes: 26 additions & 0 deletions docs/color-spaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,31 @@ icon: material/palette-outline
- **sRGB**, **linear sRGB**, **Display P3** and **XYZ** are there for interchange, and
`ColorPicker(state, space = DisplayP3)` puts sliders on any of them.

## How the spaces connect

Every space is defined on another, down to XYZ D65. A conversion climbs to the nearest space both
ends share and comes back down: HSL to CMYK goes through sRGB alone, while HSL to LCH climbs all
the way to XYZ D65 and comes down through XYZ D50 and Lab.

```mermaid
flowchart TD
xyz65["XYZ D65"] --> xyz50["XYZ D50"]
xyz65 --> linear["linear sRGB"]
xyz65 --> p3["Display P3"]
xyz65 --> oklab["Oklab"]
xyz50 --> lab["Lab"] --> lch["LCH"]
linear --> srgb["sRGB"]
srgb --> hsl["HSL"]
srgb --> hwb["HWB"]
srgb --> hsv["HSV"]
srgb --> cmyk["CMYK"]
oklab --> oklch["OkLCh"]
oklab --> okhsl["Okhsl"]
oklab --> okhsv["Okhsv"]
```

Okhsl and Okhsv are built on Oklab but measure their saturation against sRGB's gamut, which is why
they stay inside it, bar a sliver just past pure blue.

Each space's channels and units are listed in [The color model](color-model.md), and the
[Gallery](gallery.md) shows a picker for each.
11 changes: 11 additions & 0 deletions docs/pickers.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ var color by remember { mutableStateOf(Color(0xFF3366CC)) }
OkhslColorPicker(color = color, onColorChange = { color = it })
```

```mermaid
sequenceDiagram
actor User
participant Picker
participant App as Your code
User->>Picker: drags a slider
Picker->>App: onValueChange(new value), in the same event
App->>Picker: value = it, or clamped, or rounded, or unchanged
Picker->>User: draws exactly the value it was given
```

- Every change reaches the callback in the same event, as the whole new value in the picker's
space, and the picker draws only what you pass back. Ignore the callback and the picker holds
still; clamp or round the value and it shows the clamp or the rounding at once.
Expand Down
9 changes: 9 additions & 0 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ A hue chosen in one space is carried into the others, so an Okhsl slider shows t
picked on an HSL one; that is this library's own rule, as CSS carries no hue across spaces
([csswg-drafts#8484](https://github.com/w3c/csswg-drafts/issues/8484)).

```mermaid
stateDiagram-v2
direction LR
colorful: Colorful, hue 200°
grey: Grey, 200° remembered
colorful --> grey: desaturate
grey --> colorful: saturate
```

Writing a channel that is out of its limit, or not a number, throws.

## Holding and saving the state
Expand Down
7 changes: 6 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ markdown_extensions:
- pymdownx.highlight:
anchor_linenums: true
- pymdownx.inlinehilite
- pymdownx.superfences
# ```mermaid blocks render as diagrams; the theme loads Mermaid only on a page that has one.
- pymdownx.superfences:
custom_fences:
- name: mermaid
class: mermaid
format: !!python/name:pymdownx.superfences.fence_code_format

plugins:
- search
9 changes: 8 additions & 1 deletion scripts/docs-llms-txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
ROOT = pathlib.Path(__file__).resolve().parent.parent


class ConfigLoader(yaml.SafeLoader):
"""Reads mkdocs.yml without running it: a `!!python/name:` reference (a Markdown extension's hook) stays a string."""


ConfigLoader.add_multi_constructor("tag:yaml.org,2002:python/name:", lambda loader, suffix, node: suffix)


def front_matter(page: pathlib.Path) -> dict:
text = page.read_text(encoding="utf-8")
if not text.startswith("---\n"):
Expand All @@ -23,7 +30,7 @@ def front_matter(page: pathlib.Path) -> dict:


def main() -> None:
config = yaml.safe_load((ROOT / "mkdocs.yml").read_text(encoding="utf-8"))
config = yaml.load((ROOT / "mkdocs.yml").read_text(encoding="utf-8"), Loader=ConfigLoader)
site = pathlib.Path(sys.argv[1]) if len(sys.argv) > 1 else ROOT / config.get("site_dir", "site")
docs = ROOT / config.get("docs_dir", "docs")
base = config["site_url"]
Expand Down
Loading