refactor(theme)!: rebuild the base styles on tailwind's preflight

base.css is now Tailwind's preflight (pinned to their e48c5e80) wrapped
in the vitepress cascade layer, with the font stacks pointing at the
vitepress variables and the bold weight at 600, followed by a section
with the vitepress-specific overrides. Compared to the old base this
picks up the universal margin/padding/border reset, tab-size: 4, iOS
tap-highlight removal, and the modern form and date-input
normalizations, and drops fossils like the touch-action click-delay
hack and main { display: block }.

BREAKING CHANGE: normalize-level defaults differ from the old reset -
native select and number-input chrome is restored, headings inherit
font size and weight, the hidden attribute is enforced with !important,
and every element starts with zero margin/padding and border-style:
solid. Sites layering custom CSS on the default theme may notice.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
pull/5335/head
Divyansh Singh 2 months ago
parent 829288ddec
commit f1ee91335e

@ -1,54 +1,40 @@
@layer __vitepress_base { @layer __vitepress_base {
@media (prefers-reduced-motion: reduce) { /* #region Tailwind Preflight */
*,
::before, /* Based on https://github.com/tailwindlabs/tailwindcss/blob/e48c5e80473c25fe5a27fe267fbaf4f6512424a3/packages/tailwindcss/preflight.css,
::after { with the `--theme()` references replaced by vitepress variables, and `bolder` replaced by `600` */
animation-delay: -1ms !important;
animation-duration: 1ms !important;
animation-iteration-count: 1 !important;
background-attachment: initial !important;
scroll-behavior: auto !important;
transition-duration: 0s !important;
transition-delay: 0s !important;
}
}
*, *,
::after,
::before, ::before,
::after { ::backdrop,
::file-selector-button {
box-sizing: border-box; box-sizing: border-box;
margin: 0;
padding: 0;
border: 0 solid;
} }
html { html,
line-height: 1.4; :host {
font-size: 16px; line-height: 1.5;
-webkit-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;
tab-size: 4;
font-family: var(--vp-font-family-base);
font-feature-settings: normal;
font-variation-settings: normal;
-webkit-tap-highlight-color: transparent;
} }
html.dark { hr {
color-scheme: dark; height: 0;
} color: inherit;
border-top-width: 1px;
body {
margin: 0;
width: 100%;
min-width: 320px;
min-height: 100vh;
line-height: 24px;
font-family: var(--vp-font-family-base);
font-size: 16px;
font-weight: 400;
color: var(--vp-c-text-1);
background-color: var(--vp-c-bg);
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-autospace: normal;
text-spacing-trim: normal;
} }
main { abbr:where([title]) {
display: block; -webkit-text-decoration: underline dotted;
text-decoration: underline dotted;
} }
h1, h1,
@ -57,70 +43,73 @@
h4, h4,
h5, h5,
h6 { h6 {
margin: 0; font-size: inherit;
line-height: 24px; font-weight: inherit;
font-size: 16px;
font-weight: 400;
} }
p { a {
margin: 0; color: inherit;
-webkit-text-decoration: inherit;
text-decoration: inherit;
} }
strong, b,
b { strong {
font-weight: 600; font-weight: 600;
} }
/** code,
* Avoid 300ms click delay on touch devices that support the `touch-action` kbd,
* CSS property. samp,
* pre {
* In particular, unlike most other browsers, IE11+Edge on Windows 10 on font-family: var(--vp-font-family-mono);
* touch devices and IE Mobile 10-11 DON'T remove the click delay when font-feature-settings: normal;
* `<meta name="viewport" content="width=device-width">` is present. font-variation-settings: normal;
* However, they DO support removing the click delay via font-size: 1em;
* `touch-action: manipulation`.
*
* See:
* - http://v4-alpha.getbootstrap.com/content/reboot/#click-delay-optimization-for-touch
* - http://caniuse.com/#feat=css-touch-action
* - http://patrickhlauke.github.io/touch/tests/results/#suppressing-300ms-delay
*/
a,
area,
button,
[role='button'],
input,
label,
select,
summary,
textarea {
touch-action: manipulation;
} }
a { small {
color: inherit; font-size: 80%;
text-decoration: inherit;
} }
ol, sub,
ul { sup {
list-style: none; font-size: 75%;
margin: 0; line-height: 0;
padding: 0; position: relative;
vertical-align: baseline;
} }
blockquote { sub {
margin: 0; bottom: -0.25em;
} }
pre, sup {
code, top: -0.5em;
kbd, }
samp {
font-family: var(--vp-font-family-mono); table {
text-autospace: no-autospace; text-indent: 0;
border-color: inherit;
border-collapse: collapse;
}
:-moz-focusring:where(:not(iframe)) {
outline: auto;
}
progress {
vertical-align: baseline;
}
summary {
display: list-item;
}
ol,
ul,
menu {
list-style: none;
} }
img, img,
@ -134,10 +123,6 @@
display: block; display: block;
} }
figure {
margin: 0;
}
img, img,
video { video {
max-width: 100%; max-width: 100%;
@ -146,87 +131,171 @@
button, button,
input, input,
optgroup,
select, select,
textarea { optgroup,
border: 0; textarea,
padding: 0; ::file-selector-button {
line-height: inherit; font: inherit;
font-feature-settings: inherit;
font-variation-settings: inherit;
letter-spacing: inherit;
color: inherit; color: inherit;
border-radius: 0;
background-color: transparent;
opacity: 1;
} }
button { :where(select:is([multiple], [size])) optgroup {
font-weight: 600;
}
:where(select:is([multiple], [size])) optgroup option {
padding-inline-start: 20px;
}
::file-selector-button {
margin-inline-end: 4px;
}
::placeholder {
opacity: 1;
}
@supports (not (-webkit-appearance: -apple-pay-button)) or
(contain-intrinsic-size: 1px) {
::placeholder {
color: color-mix(in oklab, currentcolor 50%, transparent);
}
}
textarea {
resize: vertical;
}
::-webkit-search-decoration {
-webkit-appearance: none;
}
::-webkit-date-and-time-value {
min-height: 1lh;
text-align: inherit;
}
::-webkit-datetime-edit {
display: inline-flex;
}
::-webkit-datetime-edit-fields-wrapper {
padding: 0; padding: 0;
font-family: inherit;
background-color: transparent;
background-image: none;
} }
button:enabled, ::-webkit-datetime-edit,
[role='button']:enabled { ::-webkit-datetime-edit-year-field,
cursor: pointer; ::-webkit-datetime-edit-month-field,
::-webkit-datetime-edit-day-field,
::-webkit-datetime-edit-hour-field,
::-webkit-datetime-edit-minute-field,
::-webkit-datetime-edit-second-field,
::-webkit-datetime-edit-millisecond-field,
::-webkit-datetime-edit-meridiem-field {
padding-block: 0;
} }
button:focus, ::-webkit-calendar-picker-indicator {
button:focus-visible { line-height: 1;
outline: 1px dotted;
outline: 4px auto -webkit-focus-ring-color;
} }
button:focus:not(:focus-visible) { :-moz-ui-invalid {
outline: none !important; box-shadow: none;
} }
input:focus, button,
textarea:focus, input:where([type='button'], [type='reset'], [type='submit']),
select:focus { ::file-selector-button {
outline: none; appearance: button;
} }
table { ::-webkit-inner-spin-button,
border-collapse: collapse; ::-webkit-outer-spin-button {
height: auto;
} }
input { [hidden]:where(:not([hidden='until-found'])) {
background-color: transparent; display: none !important;
} }
input:-ms-input-placeholder, /* #endregion */
textarea:-ms-input-placeholder {
color: var(--vp-c-text-3); /* #region VitePress Overrides */
/* https://web.dev/articles/prefers-reduced-motion#bonus_forcing_reduced_motion_on_all_websites */
@media (prefers-reduced-motion: reduce) {
*,
::before,
::after {
animation-delay: -1ms !important;
animation-duration: 1ms !important;
animation-iteration-count: 1 !important;
background-attachment: initial !important;
scroll-behavior: auto !important;
transition-duration: 0s !important;
transition-delay: 0s !important;
}
} }
input::-ms-input-placeholder, :root {
textarea::-ms-input-placeholder { /* FIXME: pins rem-sized bits while the theme is px-based - remove when
color: var(--vp-c-text-3); moving to relative units (#570) */
font-size: 16px;
&:is(.dark) {
color-scheme: dark;
}
&:not(.dark) {
color-scheme: light;
}
} }
input::placeholder, body {
textarea::placeholder { /* FIXME: unlike html's unitless 1.5, this is inherited as-is by elements
color: var(--vp-c-text-3); with other font sizes - make unitless with #570 */
line-height: 24px;
color: var(--vp-c-text-1);
background-color: var(--vp-c-bg);
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-autospace: normal;
text-spacing-trim: normal;
} }
input::-webkit-outer-spin-button, pre,
input::-webkit-inner-spin-button { code,
-webkit-appearance: none; kbd,
margin: 0; samp {
text-autospace: no-autospace;
} }
input[type='number'] { button:enabled,
-moz-appearance: textfield; [role='button']:enabled {
cursor: pointer;
} }
textarea { button:focus,
resize: vertical; input:focus,
textarea:focus,
select:focus {
outline: none;
} }
select { button:focus-visible {
-webkit-appearance: none; outline: 1px dotted;
outline: 4px auto -webkit-focus-ring-color;
} }
fieldset { input::placeholder,
margin: 0; textarea::placeholder {
padding: 0; color: var(--vp-c-text-3);
} }
h1, h1,
@ -240,22 +309,6 @@
overflow-wrap: break-word; overflow-wrap: break-word;
} }
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sub {
bottom: -0.25em;
}
sup {
top: -0.5em;
}
vite-error-overlay { vite-error-overlay {
z-index: 9999; z-index: 9999;
} }
@ -268,4 +321,6 @@
display: inline-block; display: inline-block;
margin: auto; margin: auto;
} }
/* #endregion */
} }

Loading…
Cancel
Save