All files / packages/css/src base.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 2/2
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281                            2x                                                                                                             2x                                                                                                                                                                                                                                                                                                                                                                                                                   3x             2x    
// SPDX-License-Identifier: MIT
/**
 * Base semantic styles for Turbo Themes.
 *
 * Provides optional CSS that applies theme variables to common HTML elements.
 * This is a lightweight alternative to a full CSS framework.
 *
 * @packageDocumentation
 */
 
/**
 * Minimal CSS reset that works well with Turbo theme variables.
 * Approximately 500 bytes minified.
 */
export const CSS_RESET = `/* Turbo Themes - Minimal Reset */
*,
*::before,
*::after {
  box-sizing: border-box;
}
 
body,
h1,
h2,
h3,
h4,
h5,
h6,
p,
figure,
blockquote,
dl,
dd {
  margin: 0;
}
 
html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
 
body {
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
 
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}
 
input,
button,
textarea,
select {
  font: inherit;
}
`;
 
/**
 * Base semantic styles that use Turbo theme variables.
 * Approximately 2KB minified.
 */
export const CSS_BASE = `/* Turbo Themes - Base Semantic Styles */
 
/* Root & Body */
:root {
  color-scheme: light dark;
}
 
body {
  font-family: var(--turbo-font-sans, system-ui, -apple-system, sans-serif);
  color: var(--turbo-text-primary, #000);
  background-color: var(--turbo-bg-base, #fff);
}
 
/* Typography */
h1, h2, h3, h4, h5, h6 {
  line-height: 1.2;
  font-weight: 600;
}
 
h1 { color: var(--turbo-heading-h1, var(--turbo-text-primary)); font-size: 2.5rem; }
h2 { color: var(--turbo-heading-h2, var(--turbo-text-primary)); font-size: 2rem; }
h3 { color: var(--turbo-heading-h3, var(--turbo-text-primary)); font-size: 1.75rem; }
h4 { color: var(--turbo-heading-h4, var(--turbo-text-primary)); font-size: 1.5rem; }
h5 { color: var(--turbo-heading-h5, var(--turbo-text-primary)); font-size: 1.25rem; }
h6 { color: var(--turbo-heading-h6, var(--turbo-text-primary)); font-size: 1rem; }
 
p {
  color: var(--turbo-body-primary, var(--turbo-text-primary));
}
 
/* Links */
a {
  color: var(--turbo-accent-link, var(--turbo-brand-primary));
  text-decoration: none;
}
 
a:hover {
  text-decoration: underline;
}
 
/* Selection */
::selection {
  color: var(--turbo-selection-fg, #fff);
  background-color: var(--turbo-selection-bg, #3273dc);
}
 
/* Code */
code,
kbd,
samp,
pre {
  font-family: var(--turbo-font-mono, ui-monospace, monospace);
}
 
code {
  padding: 0.125rem 0.25rem;
  color: var(--turbo-code-inline-fg, #e83e8c);
  background-color: var(--turbo-code-inline-bg, #f8f9fa);
  border-radius: 0.25rem;
  font-size: 0.875em;
}
 
pre {
  padding: 1rem;
  color: var(--turbo-code-block-fg, #f8f9fa);
  background-color: var(--turbo-code-block-bg, #2b2b2b);
  border-radius: 0.5rem;
  overflow-x: auto;
}
 
pre code {
  padding: 0;
  background-color: transparent;
  font-size: inherit;
}
 
/* Blockquote */
blockquote {
  margin: 1rem 0;
  padding: 0.5rem 1rem;
  color: var(--turbo-blockquote-fg);
  background-color: var(--turbo-blockquote-bg);
  border-left: 4px solid var(--turbo-blockquote-border);
  border-radius: 0 0.25rem 0.25rem 0;
}
 
/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
}
 
th,
td {
  padding: 0.75rem;
  text-align: left;
  border: 1px solid var(--turbo-table-border);
}
 
th {
  color: var(--turbo-table-header-fg, var(--turbo-text-primary));
  background-color: var(--turbo-table-thead-bg);
  font-weight: 600;
}
 
tr:nth-child(even) td {
  background-color: var(--turbo-table-stripe);
}
 
/* Form Elements */
button,
input,
select,
textarea {
  border: 1px solid var(--turbo-border-default);
  border-radius: 0.25rem;
  background-color: var(--turbo-bg-surface);
  color: var(--turbo-text-primary);
}
 
button {
  padding: 0.5rem 1rem;
  cursor: pointer;
  background-color: var(--turbo-brand-primary);
  color: var(--turbo-text-inverse);
  border: none;
  font-weight: 500;
}
 
button:hover {
  opacity: 0.9;
}
 
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
 
input,
select,
textarea {
  padding: 0.5rem 0.75rem;
}
 
button:focus-visible,
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--turbo-brand-primary);
  outline-offset: 2px;
}
 
/* Utility classes */
.surface {
  background-color: var(--turbo-bg-surface);
}
 
.surface-alt {
  background-color: var(--turbo-bg-overlay);
}
 
.text-primary {
  color: var(--turbo-text-primary);
}
 
.text-secondary {
  color: var(--turbo-text-secondary);
}
 
.text-success {
  color: var(--turbo-state-success);
}
 
.text-warning {
  color: var(--turbo-state-warning);
}
 
.text-danger {
  color: var(--turbo-state-danger);
}
 
.text-info {
  color: var(--turbo-state-info);
}
 
.border {
  border: 1px solid var(--turbo-border-default);
}
 
.rounded {
  border-radius: 0.25rem;
}
 
.rounded-lg {
  border-radius: 0.5rem;
}
`;
 
/**
 * Generates the complete base CSS including reset and semantic styles.
 */
export function generateBaseCss(): string {
  return `${CSS_RESET}\n${CSS_BASE}`;
}
 
/**
 * Generates only the reset CSS.
 */
export function generateResetCss(): string {
  return CSS_RESET;
}