Skip to content

Commit 809ffff

Browse files
slorberclaude
andauthored
refactor(infima): convert the Infima sources to plain CSS, build them without dependencies (#13086)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent fff5a6b commit 809ffff

66 files changed

Lines changed: 2725 additions & 2905 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.oxfmtrc.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"!packages/docusaurus-*/lib/theme/",
2626

2727
"packages/create-docusaurus/templates/*/docusaurus.config.js",
28-
"packages/docusaurus-infima/styles",
2928
"packages/eslint-plugin/lib/",
3029
"packages/stylelint-copyright/lib/",
3130
"__fixtures__",

‎.stylelintrc.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,20 @@ module.exports = {
3333
'comment-empty-line-before': null,
3434
'value-keyword-case': ['lower', {camelCaseSvgKeywords: true}],
3535
},
36+
overrides: [
37+
{
38+
files: ['packages/docusaurus-infima/styles/**/*.css'],
39+
// Fixing these would change the Infima output, or its cascade order
40+
rules: {
41+
'comment-whitespace-inside': null, // Breaks the /*rtl:raw: directive
42+
'declaration-block-no-redundant-longhand-properties': null,
43+
'declaration-property-value-keyword-no-deprecated': null,
44+
'media-feature-range-notation': null,
45+
'no-descending-specificity': null,
46+
'property-no-deprecated': null,
47+
'selector-not-notation': null,
48+
'value-keyword-case': null, // Font family names
49+
},
50+
},
51+
],
3652
};

‎packages/docusaurus-infima/README.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ The Infima CSS framework, an internal package of `@docusaurus/theme-classic`.
44

55
Don't depend on it directly: it has no stability guarantee, except for the `--ifm-*` CSS variables and the documented class names. The Infima documentation moves to [docusaurus.io/infima](https://docusaurus.io/infima).
66

7+
## Sources
8+
9+
The `styles` folder contains plain CSS. `scripts/build.mjs` only inlines the `@import` rules of `styles/infima.css` into `dist/infima.css`, and flips it with rtlcss into `dist/infima-rtl.css`. The site bundler does the rest: vendor prefixes and fallbacks for the site's target browsers, and minification.
10+
11+
The rule order is the cascade order: moving a rule can change which one wins.
12+
713
## Origin
814

9-
The `styles` sources come from the former upstream repository at commit [`87bc1dbf`](https://github.com/facebookincubator/infima/tree/87bc1dbfde5dfb2a70b5ff105b5f2f5ee130c2ab): they are the same as the published `infima@0.2.0-alpha.45` package. `scripts/build.mjs` inlines its [PostCSS preset](https://github.com/facebookincubator/infima/blob/87bc1dbfde5dfb2a70b5ff105b5f2f5ee130c2ab/packages/postcss-preset-infima/index.js).
15+
The `styles` sources come from the former upstream repository at commit [`87bc1dbf`](https://github.com/facebookincubator/infima/tree/87bc1dbfde5dfb2a70b5ff105b5f2f5ee130c2ab), the same as the published `infima@0.2.0-alpha.45` package. They were converted from PostCSS to plain CSS: loops, mixins and nesting expanded, and `color-mod()` colors precomputed.

‎packages/docusaurus-infima/package.json‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,6 @@
2626
},
2727
"license": "MIT",
2828
"devDependencies": {
29-
"postcss": "catalog:",
30-
"postcss-color-mod-function": "catalog:dev",
31-
"postcss-combine-duplicated-selectors": "catalog:dev",
32-
"postcss-each": "catalog:dev",
33-
"postcss-for": "catalog:dev",
34-
"postcss-import": "catalog:dev",
35-
"postcss-mixins": "catalog:dev",
36-
"postcss-nested": "catalog:dev",
37-
"postcss-nested-ancestors": "catalog:dev",
38-
"postcss-preset-env-v7": "catalog:dev",
39-
"postcss-sort-media-queries": "catalog:dev",
4029
"rtlcss": "catalog:"
4130
},
4231
"engines": {

‎packages/docusaurus-infima/scripts/build.mjs‎

Lines changed: 24 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,83 +5,47 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
// Inlines the upstream postcss-preset-infima and the gulp styles and rtl tasks
9-
// See https://github.com/facebookincubator/infima/blob/87bc1dbfde5dfb2a70b5ff105b5f2f5ee130c2ab/packages/postcss-preset-infima/index.js
10-
118
import fs from 'node:fs/promises';
129
import path from 'node:path';
13-
import postcss from 'postcss';
14-
import postcssColorModFunction from 'postcss-color-mod-function';
15-
import postcssCombineDuplicatedSelectors from 'postcss-combine-duplicated-selectors';
16-
import postcssEach from 'postcss-each';
17-
import postcssFor from 'postcss-for';
18-
import postcssImport from 'postcss-import';
19-
import postcssMixins from 'postcss-mixins';
20-
import postcssNested from 'postcss-nested';
21-
import postcssNestedAncestors from 'postcss-nested-ancestors';
22-
import postcssPresetEnv from 'postcss-preset-env-v7';
23-
import postcssSortMediaQueries from 'postcss-sort-media-queries';
2410
import rtlcss from 'rtlcss';
2511

2612
const packageDir = path.dirname(import.meta.dirname);
27-
const entryFile = path.join(packageDir, 'styles/themes/default/default.pcss');
13+
const entryFile = path.join(packageDir, 'styles/infima.css');
2814
const outputFile = path.join(packageDir, 'dist/infima.css');
2915
const rtlOutputFile = path.join(packageDir, 'dist/infima-rtl.css');
3016

17+
// Matches the imports of the entry file, like @import url('common/base.css');
18+
const ImportRegExp = /^@import url\('(?<importPath>.+)'\);$/gm;
19+
20+
// Only bundles the sources: the site bundler adds the vendor prefixes and the
21+
// fallbacks for its target browsers, and minifies
3122
async function main() {
32-
const source = await fs.readFile(entryFile, 'utf8');
33-
const css = await compileInfima(source, entryFile);
23+
const css = await inlineImports(entryFile);
3424
await fs.mkdir(path.dirname(outputFile), {recursive: true});
3525
await fs.writeFile(outputFile, css);
3626
await fs.writeFile(rtlOutputFile, rtlcss.process(css));
3727
}
3828

39-
async function compileInfima(source, from) {
40-
const result = await postcss(getPlugins()).process(source, {from});
41-
return result.css;
29+
async function inlineImports(file) {
30+
const css = await fs.readFile(file, 'utf8');
31+
const importedFiles = await readImportedFiles(file, css);
32+
return css.replace(ImportRegExp, (_match, importPath) =>
33+
importedFiles.get(importPath),
34+
);
4235
}
4336

44-
// The plugin order matters
45-
function getPlugins() {
46-
return [
47-
postcssImport,
48-
// TODO postcss-each v1 doesn't seem to be compatible due to color-mod.
49-
// Need to upgrade later
50-
postcssEach,
51-
postcssFor,
52-
postcssMixins({mixins: {transition: transitionMixin}}),
53-
postcssNestedAncestors,
54-
postcssNested,
55-
// color-mod has been removed from the spec, so it's not included in
56-
// preset-env. Using a separate plugin instead. We probably would eventually
57-
// get rid of color-mod
58-
postcssColorModFunction({unresolved: 'ignore'}),
59-
postcssPresetEnv({
60-
stage: 1,
61-
features: {
62-
'custom-properties': false,
63-
},
37+
async function readImportedFiles(file, css) {
38+
const importPaths = Array.from(
39+
css.matchAll(ImportRegExp),
40+
(match) => match.groups.importPath,
41+
);
42+
const entries = await Promise.all(
43+
importPaths.map(async (importPath) => {
44+
const importedFile = path.resolve(path.dirname(file), importPath);
45+
return [importPath, await fs.readFile(importedFile, 'utf8')];
6446
}),
65-
postcssSortMediaQueries,
66-
postcssCombineDuplicatedSelectors,
67-
];
68-
}
69-
70-
// @mixin transition opacity visibility, var(--ifm-transition-fast), linear;
71-
function transitionMixin(
72-
_mixin,
73-
properties,
74-
duration = 'var(--ifm-transition-fast)',
75-
timing = 'var(--ifm-transition-timing-default)',
76-
) {
77-
if (properties.includes(' ')) {
78-
return {
79-
'transition-property': properties.replace(/\s/g, ', '),
80-
'transition-duration': duration,
81-
'transition-timing-function': timing,
82-
};
83-
}
84-
return {transition: [properties, duration, timing].join(' ')};
47+
);
48+
return new Map(entries);
8549
}
8650

8751
await main();
File renamed without changes.

packages/docusaurus-infima/styles/common/dark-mode.pcss renamed to packages/docusaurus-infima/styles/common/dark-mode.css

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,35 @@ html[data-theme='dark'] {
2323
--ifm-background-color: #1b1b1d;
2424
--ifm-background-surface-color: #242526;
2525

26-
--ifm-hover-overlay: rgba(255, 255, 255, 0.05);
26+
--ifm-hover-overlay: rgb(255 255 255 / 5%);
2727

2828
--ifm-color-content: #e3e3e3;
29-
--ifm-color-content-secondary: rgba(255, 255, 255, 1);
29+
--ifm-color-content-secondary: rgb(255 255 255 / 100%);
3030

3131
--ifm-breadcrumb-separator-filter: invert(64%) sepia(11%) saturate(0%)
3232
hue-rotate(149deg) brightness(99%) contrast(95%);
3333

34-
--ifm-code-background: rgba(255, 255, 255, 0.1);
34+
--ifm-code-background: rgb(255 255 255 / 10%);
3535

36-
--ifm-scrollbar-track-background-color: #444444;
36+
--ifm-scrollbar-track-background-color: #444;
3737
--ifm-scrollbar-thumb-background-color: #686868;
3838
--ifm-scrollbar-thumb-hover-background-color: #7a7a7a;
3939

40-
--ifm-table-stripe-background: rgba(255, 255, 255, 0.07);
40+
--ifm-table-stripe-background: rgb(255 255 255 / 7%);
4141

4242
--ifm-toc-border-color: var(--ifm-color-emphasis-200);
4343

44-
@each $color in (primary, secondary, success, info, warning, danger) {
45-
--ifm-color-$(color)-contrast-background: color-mod(
46-
var(--ifm-color-$(color)),
47-
shade(var(--ifm-contrast-background-dark-value))
48-
);
49-
--ifm-color-$(color)-contrast-foreground: color-mod(
50-
var(--ifm-color-$(color)),
51-
tint(var(--ifm-contrast-foreground-dark-value))
52-
);
53-
}
44+
/* Precomputed with the dark mode values of common/variables.css */
45+
--ifm-color-primary-contrast-background: rgb(16 36 69);
46+
--ifm-color-primary-contrast-foreground: rgb(235 242 252);
47+
--ifm-color-secondary-contrast-background: rgb(71 71 72);
48+
--ifm-color-secondary-contrast-foreground: rgb(253 253 254);
49+
--ifm-color-success-contrast-background: rgb(0 49 0);
50+
--ifm-color-success-contrast-foreground: rgb(230 246 230);
51+
--ifm-color-info-contrast-background: rgb(25 60 71);
52+
--ifm-color-info-contrast-foreground: rgb(238 249 253);
53+
--ifm-color-warning-contrast-background: rgb(77 56 0);
54+
--ifm-color-warning-contrast-foreground: rgb(255 248 230);
55+
--ifm-color-danger-contrast-background: rgb(75 17 19);
56+
--ifm-color-danger-contrast-foreground: rgb(255 235 236);
5457
}

packages/docusaurus-infima/styles/common/variables.pcss renamed to packages/docusaurus-infima/styles/common/variables.css

Lines changed: 74 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,66 @@
3535
--ifm-color-warning: #ffba00;
3636
--ifm-color-danger: #fa383e;
3737

38-
@each $color in (primary, secondary, success, info, warning, danger) {
39-
--ifm-color-$(color)-dark: color-mod(
40-
var(--ifm-color-$(color)) shade(var(--ifm-dark-value))
41-
);
42-
--ifm-color-$(color)-darker: color-mod(
43-
var(--ifm-color-$(color)),
44-
shade(var(--ifm-darker-value))
45-
);
46-
--ifm-color-$(color)-darkest: color-mod(
47-
var(--ifm-color-$(color)),
48-
shade(var(--ifm-darkest-value))
49-
);
50-
--ifm-color-$(color)-light: color-mod(
51-
var(--ifm-color-$(color)),
52-
tint(var(--ifm-light-value))
53-
);
54-
--ifm-color-$(color)-lighter: color-mod(
55-
var(--ifm-color-$(color)),
56-
tint(var(--ifm-lighter-value))
57-
);
58-
--ifm-color-$(color)-lightest: color-mod(
59-
var(--ifm-color-$(color)),
60-
tint(var(--ifm-lightest-value))
61-
);
62-
--ifm-color-$(color)-contrast-background: color-mod(
63-
var(--ifm-color-$(color)),
64-
tint(var(--ifm-contrast-background-value))
65-
);
66-
--ifm-color-$(color)-contrast-foreground: color-mod(
67-
var(--ifm-color-$(color)),
68-
shade(var(--ifm-contrast-foreground-value))
69-
);
70-
}
38+
/*
39+
Shades and tints of the colors above, precomputed with the values above
40+
For example, --ifm-color-primary-dark is
41+
color-mix(in srgb, var(--ifm-color-primary), black var(--ifm-dark-value))
42+
and --ifm-color-primary-light is
43+
color-mix(in srgb, var(--ifm-color-primary), white var(--ifm-light-value))
44+
*/
45+
--ifm-color-primary-dark: rgb(48 108 206);
46+
--ifm-color-primary-darker: rgb(45 102 195);
47+
--ifm-color-primary-darkest: rgb(37 84 160);
48+
--ifm-color-primary-light: rgb(83 140 233);
49+
--ifm-color-primary-lighter: rgb(114 161 237);
50+
--ifm-color-primary-lightest: rgb(154 188 242);
51+
--ifm-color-primary-contrast-background: rgb(235 242 252);
52+
--ifm-color-primary-contrast-foreground: rgb(16 36 69);
53+
54+
--ifm-color-secondary-dark: rgb(212 213 216);
55+
--ifm-color-secondary-darker: rgb(200 201 204);
56+
--ifm-color-secondary-darkest: rgb(164 166 168);
57+
--ifm-color-secondary-light: rgb(238 240 242);
58+
--ifm-color-secondary-lighter: rgb(241 242 245);
59+
--ifm-color-secondary-lightest: rgb(245 246 248);
60+
--ifm-color-secondary-contrast-background: rgb(253 253 254);
61+
--ifm-color-secondary-contrast-foreground: rgb(71 71 72);
62+
63+
--ifm-color-success-dark: rgb(0 148 0);
64+
--ifm-color-success-darker: rgb(0 139 0);
65+
--ifm-color-success-darkest: rgb(0 115 0);
66+
--ifm-color-success-light: rgb(38 178 38);
67+
--ifm-color-success-lighter: rgb(77 191 77);
68+
--ifm-color-success-lightest: rgb(128 210 128);
69+
--ifm-color-success-contrast-background: rgb(230 246 230);
70+
--ifm-color-success-contrast-foreground: rgb(0 49 0);
71+
72+
--ifm-color-info-dark: rgb(76 179 212);
73+
--ifm-color-info-darker: rgb(71 169 201);
74+
--ifm-color-info-darkest: rgb(59 139 165);
75+
--ifm-color-info-light: rgb(110 207 239);
76+
--ifm-color-info-lighter: rgb(135 216 242);
77+
--ifm-color-info-lightest: rgb(170 227 246);
78+
--ifm-color-info-contrast-background: rgb(238 249 253);
79+
--ifm-color-info-contrast-foreground: rgb(25 60 71);
80+
81+
--ifm-color-warning-dark: rgb(230 167 0);
82+
--ifm-color-warning-darker: rgb(217 158 0);
83+
--ifm-color-warning-darkest: rgb(179 130 0);
84+
--ifm-color-warning-light: rgb(255 196 38);
85+
--ifm-color-warning-lighter: rgb(255 207 77);
86+
--ifm-color-warning-lightest: rgb(255 221 128);
87+
--ifm-color-warning-contrast-background: rgb(255 248 230);
88+
--ifm-color-warning-contrast-foreground: rgb(77 56 0);
89+
90+
--ifm-color-danger-dark: rgb(225 50 56);
91+
--ifm-color-danger-darker: rgb(213 48 53);
92+
--ifm-color-danger-darkest: rgb(175 39 43);
93+
--ifm-color-danger-light: rgb(251 86 91);
94+
--ifm-color-danger-lighter: rgb(251 116 120);
95+
--ifm-color-danger-lightest: rgb(253 156 159);
96+
--ifm-color-danger-contrast-background: rgb(255 235 236);
97+
--ifm-color-danger-contrast-foreground: rgb(75 17 19);
7198

7299
--ifm-color-white: #fff;
73100
--ifm-color-black: #000;
@@ -106,17 +133,21 @@
106133
--ifm-global-border-width: 1px;
107134
--ifm-global-radius: 0.4rem;
108135

109-
--ifm-hover-overlay: rgba(0, 0, 0, 0.05);
136+
--ifm-hover-overlay: rgb(0 0 0 / 5%);
110137

111138
/* Typography. */
112139
--ifm-font-color-base: var(--ifm-color-content);
113140
--ifm-font-color-base-inverse: var(--ifm-color-content-inverse);
114141
--ifm-font-color-secondary: var(--ifm-color-content-secondary);
115-
--ifm-font-family-base: system-ui, -apple-system, BlinkMacSystemFont,
116-
'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji',
117-
'Segoe UI Emoji', 'Segoe UI Symbol';
118-
--ifm-font-family-monospace: SFMono-Regular, Menlo, Monaco, Consolas,
119-
'Liberation Mono', 'Courier New', monospace;
142+
/* The fonts after system-ui were added by postcss-preset-env v7 */
143+
/* Removing them could change the per-glyph font fallback */
144+
--ifm-font-family-base:
145+
system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell,
146+
'Noto Sans', sans-serif, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial,
147+
sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
148+
--ifm-font-family-monospace:
149+
SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New',
150+
monospace;
120151
--ifm-font-size-base: 100%;
121152

122153
--ifm-font-weight-light: 300;
@@ -138,10 +169,10 @@
138169
--ifm-transition-timing-default: cubic-bezier(0.08, 0.52, 0.52, 1);
139170

140171
/* Shadows. */
141-
--ifm-global-shadow-lw: 0 1px 2px 0 rgba(0, 0, 0, 0.1);
142-
--ifm-global-shadow-md: 0 5px 40px rgba(0, 0, 0, 0.2);
143-
--ifm-global-shadow-tl: 0 12px 28px 0 rgba(0, 0, 0, 0.2),
144-
0 2px 4px 0 rgba(0, 0, 0, 0.1);
172+
--ifm-global-shadow-lw: 0 1px 2px 0 rgb(0 0 0 / 10%);
173+
--ifm-global-shadow-md: 0 5px 40px rgb(0 0 0 / 20%);
174+
--ifm-global-shadow-tl:
175+
0 12px 28px 0 rgb(0 0 0 / 20%), 0 2px 4px 0 rgb(0 0 0 / 10%);
145176

146177
/* Z-index. */
147178
--ifm-z-index-dropdown: 100;
@@ -155,5 +186,3 @@
155186
--ifm-transition-slow: 0ms;
156187
}
157188
}
158-
159-
@custom-media --ifm-narrow-window (max-width: 996px);

0 commit comments

Comments
 (0)