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
1 change: 0 additions & 1 deletion .oxfmtrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"!packages/docusaurus-*/lib/theme/",

"packages/create-docusaurus/templates/*/docusaurus.config.js",
"packages/docusaurus-infima/styles",
"packages/eslint-plugin/lib/",
"packages/stylelint-copyright/lib/",
"__fixtures__",
Expand Down
16 changes: 16 additions & 0 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,20 @@ module.exports = {
'comment-empty-line-before': null,
'value-keyword-case': ['lower', {camelCaseSvgKeywords: true}],
},
overrides: [
{
files: ['packages/docusaurus-infima/styles/**/*.css'],
// Fixing these would change the Infima output, or its cascade order
rules: {
'comment-whitespace-inside': null, // Breaks the /*rtl:raw: directive
'declaration-block-no-redundant-longhand-properties': null,
'declaration-property-value-keyword-no-deprecated': null,
'media-feature-range-notation': null,
'no-descending-specificity': null,
'property-no-deprecated': null,
'selector-not-notation': null,
'value-keyword-case': null, // Font family names
},
},
],
};
8 changes: 7 additions & 1 deletion packages/docusaurus-infima/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ The Infima CSS framework, an internal package of `@docusaurus/theme-classic`.

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).

## Sources

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.

The rule order is the cascade order: moving a rule can change which one wins.

## Origin

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).
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.
11 changes: 0 additions & 11 deletions packages/docusaurus-infima/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@
},
"license": "MIT",
"devDependencies": {
"postcss": "catalog:",
"postcss-color-mod-function": "catalog:dev",
"postcss-combine-duplicated-selectors": "catalog:dev",
"postcss-each": "catalog:dev",
"postcss-for": "catalog:dev",
"postcss-import": "catalog:dev",
"postcss-mixins": "catalog:dev",
"postcss-nested": "catalog:dev",
"postcss-nested-ancestors": "catalog:dev",
"postcss-preset-env-v7": "catalog:dev",
"postcss-sort-media-queries": "catalog:dev",
"rtlcss": "catalog:"
},
"engines": {
Expand Down
84 changes: 24 additions & 60 deletions packages/docusaurus-infima/scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,83 +5,47 @@
* LICENSE file in the root directory of this source tree.
*/

// Inlines the upstream postcss-preset-infima and the gulp styles and rtl tasks
// See https://github.com/facebookincubator/infima/blob/87bc1dbfde5dfb2a70b5ff105b5f2f5ee130c2ab/packages/postcss-preset-infima/index.js

import fs from 'node:fs/promises';
import path from 'node:path';
import postcss from 'postcss';
import postcssColorModFunction from 'postcss-color-mod-function';
import postcssCombineDuplicatedSelectors from 'postcss-combine-duplicated-selectors';
import postcssEach from 'postcss-each';
import postcssFor from 'postcss-for';
import postcssImport from 'postcss-import';
import postcssMixins from 'postcss-mixins';
import postcssNested from 'postcss-nested';
import postcssNestedAncestors from 'postcss-nested-ancestors';
import postcssPresetEnv from 'postcss-preset-env-v7';
import postcssSortMediaQueries from 'postcss-sort-media-queries';
import rtlcss from 'rtlcss';

const packageDir = path.dirname(import.meta.dirname);
const entryFile = path.join(packageDir, 'styles/themes/default/default.pcss');
const entryFile = path.join(packageDir, 'styles/infima.css');
const outputFile = path.join(packageDir, 'dist/infima.css');
const rtlOutputFile = path.join(packageDir, 'dist/infima-rtl.css');

// Matches the imports of the entry file, like @import url('common/base.css');
const ImportRegExp = /^@import url\('(?<importPath>.+)'\);$/gm;

// Only bundles the sources: the site bundler adds the vendor prefixes and the
// fallbacks for its target browsers, and minifies
async function main() {
const source = await fs.readFile(entryFile, 'utf8');
const css = await compileInfima(source, entryFile);
const css = await inlineImports(entryFile);
await fs.mkdir(path.dirname(outputFile), {recursive: true});
await fs.writeFile(outputFile, css);
await fs.writeFile(rtlOutputFile, rtlcss.process(css));
}

async function compileInfima(source, from) {
const result = await postcss(getPlugins()).process(source, {from});
return result.css;
async function inlineImports(file) {
const css = await fs.readFile(file, 'utf8');
const importedFiles = await readImportedFiles(file, css);
return css.replace(ImportRegExp, (_match, importPath) =>
importedFiles.get(importPath),
);
}

// The plugin order matters
function getPlugins() {
return [
postcssImport,
// TODO postcss-each v1 doesn't seem to be compatible due to color-mod.
// Need to upgrade later
postcssEach,
postcssFor,
postcssMixins({mixins: {transition: transitionMixin}}),
postcssNestedAncestors,
postcssNested,
// color-mod has been removed from the spec, so it's not included in
// preset-env. Using a separate plugin instead. We probably would eventually
// get rid of color-mod
postcssColorModFunction({unresolved: 'ignore'}),
postcssPresetEnv({
stage: 1,
features: {
'custom-properties': false,
},
async function readImportedFiles(file, css) {
const importPaths = Array.from(
css.matchAll(ImportRegExp),
(match) => match.groups.importPath,
);
const entries = await Promise.all(
importPaths.map(async (importPath) => {
const importedFile = path.resolve(path.dirname(file), importPath);
return [importPath, await fs.readFile(importedFile, 'utf8')];
}),
postcssSortMediaQueries,
postcssCombineDuplicatedSelectors,
];
}

// @mixin transition opacity visibility, var(--ifm-transition-fast), linear;
function transitionMixin(
_mixin,
properties,
duration = 'var(--ifm-transition-fast)',
timing = 'var(--ifm-transition-timing-default)',
) {
if (properties.includes(' ')) {
return {
'transition-property': properties.replace(/\s/g, ', '),
'transition-duration': duration,
'transition-timing-function': timing,
};
}
return {transition: [properties, duration, timing].join(' ')};
);
return new Map(entries);
}

await main();
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,35 @@ html[data-theme='dark'] {
--ifm-background-color: #1b1b1d;
--ifm-background-surface-color: #242526;

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

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

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

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

--ifm-scrollbar-track-background-color: #444444;
--ifm-scrollbar-track-background-color: #444;
--ifm-scrollbar-thumb-background-color: #686868;
--ifm-scrollbar-thumb-hover-background-color: #7a7a7a;

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

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

@each $color in (primary, secondary, success, info, warning, danger) {
--ifm-color-$(color)-contrast-background: color-mod(
var(--ifm-color-$(color)),
shade(var(--ifm-contrast-background-dark-value))
);
--ifm-color-$(color)-contrast-foreground: color-mod(
var(--ifm-color-$(color)),
tint(var(--ifm-contrast-foreground-dark-value))
);
}
/* Precomputed with the dark mode values of common/variables.css */
--ifm-color-primary-contrast-background: rgb(16 36 69);
--ifm-color-primary-contrast-foreground: rgb(235 242 252);
--ifm-color-secondary-contrast-background: rgb(71 71 72);
--ifm-color-secondary-contrast-foreground: rgb(253 253 254);
--ifm-color-success-contrast-background: rgb(0 49 0);
--ifm-color-success-contrast-foreground: rgb(230 246 230);
--ifm-color-info-contrast-background: rgb(25 60 71);
--ifm-color-info-contrast-foreground: rgb(238 249 253);
--ifm-color-warning-contrast-background: rgb(77 56 0);
--ifm-color-warning-contrast-foreground: rgb(255 248 230);
--ifm-color-danger-contrast-background: rgb(75 17 19);
--ifm-color-danger-contrast-foreground: rgb(255 235 236);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,66 @@
--ifm-color-warning: #ffba00;
--ifm-color-danger: #fa383e;

@each $color in (primary, secondary, success, info, warning, danger) {
--ifm-color-$(color)-dark: color-mod(
var(--ifm-color-$(color)) shade(var(--ifm-dark-value))
);
--ifm-color-$(color)-darker: color-mod(
var(--ifm-color-$(color)),
shade(var(--ifm-darker-value))
);
--ifm-color-$(color)-darkest: color-mod(
var(--ifm-color-$(color)),
shade(var(--ifm-darkest-value))
);
--ifm-color-$(color)-light: color-mod(
var(--ifm-color-$(color)),
tint(var(--ifm-light-value))
);
--ifm-color-$(color)-lighter: color-mod(
var(--ifm-color-$(color)),
tint(var(--ifm-lighter-value))
);
--ifm-color-$(color)-lightest: color-mod(
var(--ifm-color-$(color)),
tint(var(--ifm-lightest-value))
);
--ifm-color-$(color)-contrast-background: color-mod(
var(--ifm-color-$(color)),
tint(var(--ifm-contrast-background-value))
);
--ifm-color-$(color)-contrast-foreground: color-mod(
var(--ifm-color-$(color)),
shade(var(--ifm-contrast-foreground-value))
);
}
/*
Shades and tints of the colors above, precomputed with the values above
For example, --ifm-color-primary-dark is
color-mix(in srgb, var(--ifm-color-primary), black var(--ifm-dark-value))
and --ifm-color-primary-light is
color-mix(in srgb, var(--ifm-color-primary), white var(--ifm-light-value))
*/
--ifm-color-primary-dark: rgb(48 108 206);
--ifm-color-primary-darker: rgb(45 102 195);
--ifm-color-primary-darkest: rgb(37 84 160);
--ifm-color-primary-light: rgb(83 140 233);
--ifm-color-primary-lighter: rgb(114 161 237);
--ifm-color-primary-lightest: rgb(154 188 242);
--ifm-color-primary-contrast-background: rgb(235 242 252);
--ifm-color-primary-contrast-foreground: rgb(16 36 69);

--ifm-color-secondary-dark: rgb(212 213 216);
--ifm-color-secondary-darker: rgb(200 201 204);
--ifm-color-secondary-darkest: rgb(164 166 168);
--ifm-color-secondary-light: rgb(238 240 242);
--ifm-color-secondary-lighter: rgb(241 242 245);
--ifm-color-secondary-lightest: rgb(245 246 248);
--ifm-color-secondary-contrast-background: rgb(253 253 254);
--ifm-color-secondary-contrast-foreground: rgb(71 71 72);

--ifm-color-success-dark: rgb(0 148 0);
--ifm-color-success-darker: rgb(0 139 0);
--ifm-color-success-darkest: rgb(0 115 0);
--ifm-color-success-light: rgb(38 178 38);
--ifm-color-success-lighter: rgb(77 191 77);
--ifm-color-success-lightest: rgb(128 210 128);
--ifm-color-success-contrast-background: rgb(230 246 230);
--ifm-color-success-contrast-foreground: rgb(0 49 0);

--ifm-color-info-dark: rgb(76 179 212);
--ifm-color-info-darker: rgb(71 169 201);
--ifm-color-info-darkest: rgb(59 139 165);
--ifm-color-info-light: rgb(110 207 239);
--ifm-color-info-lighter: rgb(135 216 242);
--ifm-color-info-lightest: rgb(170 227 246);
--ifm-color-info-contrast-background: rgb(238 249 253);
--ifm-color-info-contrast-foreground: rgb(25 60 71);

--ifm-color-warning-dark: rgb(230 167 0);
--ifm-color-warning-darker: rgb(217 158 0);
--ifm-color-warning-darkest: rgb(179 130 0);
--ifm-color-warning-light: rgb(255 196 38);
--ifm-color-warning-lighter: rgb(255 207 77);
--ifm-color-warning-lightest: rgb(255 221 128);
--ifm-color-warning-contrast-background: rgb(255 248 230);
--ifm-color-warning-contrast-foreground: rgb(77 56 0);

--ifm-color-danger-dark: rgb(225 50 56);
--ifm-color-danger-darker: rgb(213 48 53);
--ifm-color-danger-darkest: rgb(175 39 43);
--ifm-color-danger-light: rgb(251 86 91);
--ifm-color-danger-lighter: rgb(251 116 120);
--ifm-color-danger-lightest: rgb(253 156 159);
--ifm-color-danger-contrast-background: rgb(255 235 236);
--ifm-color-danger-contrast-foreground: rgb(75 17 19);

--ifm-color-white: #fff;
--ifm-color-black: #000;
Expand Down Expand Up @@ -106,17 +133,21 @@
--ifm-global-border-width: 1px;
--ifm-global-radius: 0.4rem;

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

/* Typography. */
--ifm-font-color-base: var(--ifm-color-content);
--ifm-font-color-base-inverse: var(--ifm-color-content-inverse);
--ifm-font-color-secondary: var(--ifm-color-content-secondary);
--ifm-font-family-base: system-ui, -apple-system, BlinkMacSystemFont,
'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji',
'Segoe UI Emoji', 'Segoe UI Symbol';
--ifm-font-family-monospace: SFMono-Regular, Menlo, Monaco, Consolas,
'Liberation Mono', 'Courier New', monospace;
/* The fonts after system-ui were added by postcss-preset-env v7 */
/* Removing them could change the per-glyph font fallback */
--ifm-font-family-base:
system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell,
'Noto Sans', sans-serif, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial,
sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
--ifm-font-family-monospace:
SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New',
monospace;
--ifm-font-size-base: 100%;

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

/* Shadows. */
--ifm-global-shadow-lw: 0 1px 2px 0 rgba(0, 0, 0, 0.1);
--ifm-global-shadow-md: 0 5px 40px rgba(0, 0, 0, 0.2);
--ifm-global-shadow-tl: 0 12px 28px 0 rgba(0, 0, 0, 0.2),
0 2px 4px 0 rgba(0, 0, 0, 0.1);
--ifm-global-shadow-lw: 0 1px 2px 0 rgb(0 0 0 / 10%);
--ifm-global-shadow-md: 0 5px 40px rgb(0 0 0 / 20%);
--ifm-global-shadow-tl:
0 12px 28px 0 rgb(0 0 0 / 20%), 0 2px 4px 0 rgb(0 0 0 / 10%);

/* Z-index. */
--ifm-z-index-dropdown: 100;
Expand All @@ -155,5 +186,3 @@
--ifm-transition-slow: 0ms;
}
}

@custom-media --ifm-narrow-window (max-width: 996px);
Loading
Loading