Skip to content

Commit 61cfee9

Browse files
committed
Various updates to the docs website.
1 parent 3986a03 commit 61cfee9

File tree

12 files changed

+3721
-47
lines changed

12 files changed

+3721
-47
lines changed

build.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ build({
4242
outfile: 'bundled/culori.min.mjs'
4343
});
4444

45+
// Bundled ESM, minified, for the website
46+
build({
47+
entryPoints: ['./src/index.js'],
48+
logLevel: 'info',
49+
bundle: true,
50+
minify: true,
51+
format: 'esm',
52+
outfile: 'docs/static/culori.min.mjs'
53+
});
54+
4555
// Bundled IIFE
4656
build({
4757
entryPoints: ['./src/index.js'],

docs/_includes/layouts/default.html

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,23 @@ <h1>{{ title }}</h1>
2121
</div>
2222
{% include 'partials/footer.html' %}
2323

24-
<script
25-
type="text/javascript"
26-
src="https://unpkg.com/culori@{{ pkg.version }}"
27-
></script>
28-
<script type="text/javascript">
29-
const r = () => culori.random('lch', { l: [30, 80], c: [60, 90] });
24+
<script type="module">
25+
import * as culori from '/culori.min.mjs';
26+
27+
/* Expose as global variable */
28+
window.culori = culori;
29+
30+
const { p3, random, formatCss, formatHex } = culori;
31+
32+
const r = () => random('lch', { l: [30, 80], c: [60, 90] });
3033
let r1 = r();
3134
let r2 = r();
32-
if (CSS.supports('color: color(display-p3)')) {
33-
r1 = culori.formatCss(culori.p3(r1));
34-
r2 = culori.formatCss(culori.p3(r2));
35+
if (CSS.supports('color: color(display-p3 0 0 0)')) {
36+
r1 = formatCss(p3(r1));
37+
r2 = formatCss(p3(r2));
3538
} else {
36-
r1 = culori.formatHex(r1);
37-
r2 = culori.formatHex(r2);
39+
r1 = formatHex(r1);
40+
r2 = formatHex(r2);
3841
}
3942
document.body.style.setProperty('--random-1', r1);
4043
document.body.style.setProperty('--random-2', r2);

docs/_includes/partials/footer.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<footer>
22
<div class="container">
33
<p>
4-
A <a href="https://labs.moqups.com">Moqups Labs</a> thing. Can this
5-
page be improved?
4+
Culori is a <a href="https://moqups.com">Moqups</a> production. Can
5+
this page be improved?
66
<a
77
href="https://github.com/Evercoder/culori/blob/main/{{ page.inputPath }}"
88
>Edit it on GitHub</a

docs/colophon.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ title: Colophon
44
menu-order: 6
55
---
66

7-
Developed by [Dan Burzo](http://danburzo.ro) with the help of many collaborators, and released under the MIT license. The library is indebted to Mike Bostock's [D3.js](https://github.com/d3) and Gregor Aisch's [chroma.js](https://github.com/gka/chroma.js). D3, in particular, has been a treasure-trove of ideas and academic references.
7+
Culori is developed by [Dan Burzo](http://danburzo.ro) with the help of many collaborators, and released under the MIT license.
88

9-
Culori is the Romanian word for ‘colors’. The logo is typeset in [Hatch](https://pstypelab.com/hatchfont) by Mark Caneso.
9+
The library has been inspired by Mike Bostock's [D3.js](https://github.com/d3) and Gregor Aisch's [chroma.js](https://github.com/gka/chroma.js): they have popularized color science in the browser and provided a blueprint for a color manipulation API. I have learned a tremendous amount by reading through the documentation the source code while developing Culori. D3, in particular, has been a treasure trove of ideas and pointers to academic references.
10+
11+
I pronounce the name of the library as [[kuːlori]](http://ipa-reader.xyz/?text=ku%CB%90lori). Culori is the Romanian word for ‘colors’. The logo is typeset in [Hatch](https://pstypelab.com/hatchfont) by Mark Caneso.
1012

11-
The code is formatted with [Prettier](https://prettier.io), upkeeped with [ESLint](https://eslint.org/), tested with [tape](https://github.com/substack/tape), and bundled with [esbuild](https://esbuild.github.io/).
12-
13-
This website is statically generated using [Eleventy](https://11ty.dev) and published to GitHub Pages.
13+
The code is formatted with [Prettier](https://prettier.io), upkept with [ESLint](https://eslint.org/), tested with [tape](https://github.com/ljharb/tape), and bundled with [esbuild](https://esbuild.github.io/). This website is statically generated using [Eleventy](https://11ty.dev) and published to GitHub Pages.

docs/css/main.css

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
body {
2-
font-family: var(--ff-main);
3-
line-height: 1.5;
4-
margin: 0;
5-
1+
html {
62
--red: #d84f4c;
73
--indigo: #57467d;
84
--offwhite: #f8f5f4;
@@ -14,12 +10,25 @@ body {
1410
sans-serif, Apple Color Emoji, Segoe UI Emoji;
1511
--ff-code: 'Consolas', monospace;
1612

13+
font-size: 115%;
14+
}
15+
16+
@media (max-width: 30em) {
17+
html {
18+
font-size: 90%;
19+
}
20+
}
21+
22+
body {
23+
font-family: var(--ff-main);
24+
line-height: 1.5;
25+
margin: 0;
1726
text-size-adjust: none;
1827
-webkit-text-size-adjust: none;
1928
}
2029

2130
.container {
22-
max-width: 60rem;
31+
max-width: 50rem;
2332
margin: 0 auto;
2433
padding: 0 1rem;
2534
}
@@ -121,6 +130,15 @@ nav a {
121130
border-bottom: 0.2em solid transparent;
122131
}
123132

133+
h1,
134+
h2,
135+
h3,
136+
h4,
137+
h5,
138+
h6 {
139+
line-height: 1.1;
140+
}
141+
124142
h1 {
125143
font-size: 2.4em;
126144
margin: 0 0 0.5em;

docs/getting-started.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ menu-order: 1
66

77
## Install Culori from npm
88

9-
Add Culori as a dependency to your project:
9+
Culori is distributed [on npm](https://npmjs.com/package/culori) in a variety of formats. Install it with:
1010

1111
```bash
1212
npm install culori
1313
```
1414

15-
Then start using it:
15+
Then start importing functions from [the API](/api/):
1616

1717
```js
1818
import { rgb } from 'culori';
@@ -21,6 +21,8 @@ rgb('tomato');
2121
// ⇒ Object { mode: "rgb", r: 1, g: 0.38823529411764707, b: 0.2784313725490196 }
2222
```
2323

24+
For code that runs in browsers, you may want to streamline the bundle to only include the parts of Culori you're using. See [Optimize bundle size with tree-shaking](/guides/tree-shaking/) for guidance on switching your imports to use `'culori/fn'` instead of `'culori'` once you're done prototyping.
25+
2426
## Fetch Culori from a CDN
2527

2628
You can use Culori from your favorite Content Delivery Network to create quick prototypes in HTML. Here are a few popular choices:
@@ -53,11 +55,7 @@ Use it as an ES module:
5355

5456
### In your browser's console
5557

56-
The library is added to every page of this website, so you can try the API in your browser's console as you read through the examples.
57-
58-
### Runkit
59-
60-
You can also use Culori in the Runkit npm playground ([npm.runkit.com/culori](https://npm.runkit.com/culori)) to test the API without installing anything.
58+
The library is available on this website as the global variable `culori`, so can try the API in your browser's console as you read through the examples.
6159

6260
### Observable
6361

docs/guides/index.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ title: 'Guides'
33
menu-order: 4
44
---
55

6-
## [Migration guide](./migration)
6+
## Working with Culori
77

8-
This guide documents the breaking changes in each new major release of the library and how to address them in your code.
8+
### [Optimize bundle size with tree-shaking](./tree-shaking/)
9+
10+
Once you're done prototyping and you're ready to ship an optimized bundle, switch your imports over to the fully tree-shakeable version.
911

10-
## [Optimize bundle size with tree-shaking](./tree-shaking)
12+
### [Migration guide](./migration/)
13+
14+
This guide documents the breaking changes in each new major release of the library and how to address them in your code.
1115

1216
## Elsewhere
1317

docs/guides/migration.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: 'Migration guide'
33
---
44

5-
## Migrating from version 2.x to 3.0
5+
## From v2 to v3
66

77
### Custom identifiers removed from the `color()` syntax
88

@@ -35,7 +35,7 @@ The parsing of the [modern syntax](https://w3c.github.io/csswg-drafts/css-color-
3535
* `parseRgbLegacy()` has been added to the API to parse the legacy `rgb()` / `rgba()` syntax
3636
* `parseHslLegacy()` has been added to the API to parse the legacy `hsl()` / `hsla()` syntax
3737

38-
## Migrating from version 1.x to 2.0
38+
## From v1 to v2
3939

4040
* all color components in all CSS color syntaxes now accept the `none` keyword. ([w3c/csswg-drafts#6107](https://github.com/w3c/csswg-drafts/issues/6107))
4141

@@ -124,7 +124,7 @@ lch(75 50 15deg)
124124
In version 2.0, we drop this quirk and bring Culori in line with the specification.
125125

126126

127-
## Migrating from version 0.x to 1.0
127+
## From v0.x to v1
128128

129129
### Using the library
130130

docs/guides/tree-shaking.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
title: 'Optimize bundle size with tree-shaking'
33
---
44

5-
The default `culori` import comes with the full set of color spaces and functions to let you prototype quickly and with fewer errors.
5+
The default `culori` import comes with the full set of color spaces and functions to let you prototype quickly and with fewer errors. However, the way color spaces are initialized prevents the library from being tree-shaken, so when you use a bundler (such as [esbuild](https://esbuild.github.io/), [Vite](https://vitejs.dev/), or [Parcel](https://parceljs.org/)), the entire Culori library is bundled regardless of what you're actually using.
66

7-
However, the way color spaces are initialized prevents the library from being tree-shaken, so when you use a bundler such as Webpack or Parcel, the entire Culori library is bundled regardless of what you're actually using.
7+
This guides walks you through switching your imports to the tree-shakeable version once you're done prototyping and you're ready to ship an optimized bundle.
88

99
## Using `culori/fn`
1010

@@ -46,6 +46,8 @@ import {
4646
modeHwb,
4747
modeLab,
4848
modeLch,
49+
modeOklab,
50+
modeOklch,
4951
modeP3,
5052
modeProphoto,
5153
modeRec2020,
@@ -59,6 +61,8 @@ const hsl = useMode(modeHsl);
5961
const hwb = useMode(modeHwb);
6062
const lab = useMode(modeLab);
6163
const lch = useMode(modeLch);
64+
const oklab = useMode(modeOklab);
65+
const oklch = useMode(modeOklch);
6266
const p3 = useMode(modeP3);
6367
const prophoto = useMode(modeProphoto);
6468
const rec2020 = useMode(modeRec2020);
@@ -67,6 +71,8 @@ const xyz50 = useMode(modeXyz50);
6771
const xyz65 = useMode(modeXyz65);
6872
```
6973

74+
You don't need to do all of this manually. You can import the [CSS bundle](#culori-css) instead.
75+
7076
### Using Culori without registering color spaces
7177

7278
You can import and use the [low-level parsing and conversion functions](/api#low-level-api) without registering any color space beforehand:
@@ -102,11 +108,11 @@ esbuild --bundle --minify hex-to-hsl-string.js
102108

103109
For convenience, a couple of bootstrap packages are available.
104110

105-
### `culori/css`
111+
<h3 id='culori-css'><code>culori/css</code></h3>
106112

107113
Bootstrap all the color spaces available in CSS, plus a handful of related ones we get for free, since they are used under the hood.
108114

109-
It provides the following named exports: `a98`, `hsl`, `hsv`, `hwb`, `lab`, `lab65`, `lch`, `lch65`, `lrgb`, `p3`, `prophoto`, `rec2020`, `rgb`, `xyz50`, and `xyz65`.
115+
It provides the following named exports: `a98`, `hsl`, `hsv`, `hwb`, `lab`, `lab65`, `lch`, `lch65`, `lrgb`, `oklab`, `oklch`, `p3`, `prophoto`, `rec2020`, `rgb`, `xyz50`, and `xyz65`.
110116

111117
```js
112118
import 'culori/css';
@@ -125,5 +131,5 @@ It provides the following named exports: `a98`, `cubehelix`, `dlab`, `dlch`, `hs
125131
import 'culori/all';
126132
import { interpolate } from 'culori/fn';
127133

128-
interpolate(['red', 'green'], 'oklab');
134+
interpolate(['red', 'green'], 'xyb');
129135
```

docs/index.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
2-
title: Home
2+
title: Color functions for JavaScript
3+
homepage: true
34
layout: layouts/default
45
menu-order: 0
56
---
@@ -13,9 +14,7 @@ menu-order: 0
1314
[hwb-colors]: https://drafts.csswg.org/css-color/#the-hwb-notation
1415
[lab-colors]: https://drafts.csswg.org/css-color/#lab-colors
1516

16-
Culori is a color library for JavaScript that supports most color spaces and formats defined in the [CSS Colors Level 4][css4-colors] specification ([named colors][css4-named-colors], [hex colors][hex-colors] with 3 to 8 digits, [RGB][rgb-colors], [HSL][hsl-colors], [HWB][hwb-colors], [Lab and LCh][lab-colors]), plus [additional color spaces](./color-spaces).
17-
18-
It handles [color differences](https://en.wikipedia.org/wiki/Color_difference), interpolation, gradients, blend modes [and more](./api).
17+
Culori is a JavaScript color library that supports the conversion and manipulation of all formats defined in the [CSS Colors Level 4][css4-colors] specification, plus [additional color spaces](./color-spaces). It handles [color differences](https://en.wikipedia.org/wiki/Color_difference), interpolation, gradients, blend modes [and much more](/api/).
1918

2019
```bash
2120
npm install culori

0 commit comments

Comments
 (0)