bun-types 1.3.2-canary.20251105T140650 → 1.3.2-canary.20251106T140813

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/docs/README.md +28 -0
  2. package/package.json +1 -1
  3. package/docs/api/binary-data.md +0 -1038
  4. package/docs/api/cc.md +0 -197
  5. package/docs/api/color.md +0 -262
  6. package/docs/api/console.md +0 -57
  7. package/docs/api/cookie.md +0 -449
  8. package/docs/api/dns.md +0 -110
  9. package/docs/api/fetch.md +0 -463
  10. package/docs/api/ffi.md +0 -557
  11. package/docs/api/file-io.md +0 -366
  12. package/docs/api/file-system-router.md +0 -112
  13. package/docs/api/file.md +0 -19
  14. package/docs/api/glob.md +0 -178
  15. package/docs/api/globals.md +0 -387
  16. package/docs/api/hashing.md +0 -319
  17. package/docs/api/html-rewriter.md +0 -334
  18. package/docs/api/http.md +0 -1408
  19. package/docs/api/import-meta.md +0 -69
  20. package/docs/api/node-api.md +0 -14
  21. package/docs/api/redis.md +0 -597
  22. package/docs/api/s3.md +0 -850
  23. package/docs/api/secrets.md +0 -319
  24. package/docs/api/semver.md +0 -52
  25. package/docs/api/spawn.md +0 -582
  26. package/docs/api/sql.md +0 -1374
  27. package/docs/api/sqlite.md +0 -694
  28. package/docs/api/streams.md +0 -230
  29. package/docs/api/tcp.md +0 -221
  30. package/docs/api/transpiler.md +0 -276
  31. package/docs/api/udp.md +0 -123
  32. package/docs/api/utils.md +0 -891
  33. package/docs/api/websockets.md +0 -573
  34. package/docs/api/workers.md +0 -322
  35. package/docs/api/yaml.md +0 -668
  36. package/docs/benchmarks.md +0 -120
  37. package/docs/bun-flavored-toml.md +0 -42
  38. package/docs/bundler/css.md +0 -1028
  39. package/docs/bundler/css_modules.md +0 -145
  40. package/docs/bundler/executables.md +0 -626
  41. package/docs/bundler/fullstack.md +0 -418
  42. package/docs/bundler/hmr.md +0 -234
  43. package/docs/bundler/html.md +0 -349
  44. package/docs/bundler/index.md +0 -1735
  45. package/docs/bundler/intro.md +0 -75
  46. package/docs/bundler/loaders.md +0 -410
  47. package/docs/bundler/macros.md +0 -329
  48. package/docs/bundler/plugins.md +0 -449
  49. package/docs/bundler/vs-esbuild.md +0 -1127
  50. package/docs/cli/add.md +0 -173
  51. package/docs/cli/bun-completions.md +0 -3
  52. package/docs/cli/bun-create.md +0 -338
  53. package/docs/cli/bun-install.md +0 -349
  54. package/docs/cli/bun-upgrade.md +0 -39
  55. package/docs/cli/bunx.md +0 -89
  56. package/docs/cli/filter.md +0 -90
  57. package/docs/cli/info.md +0 -65
  58. package/docs/cli/init.md +0 -85
  59. package/docs/cli/install.md +0 -344
  60. package/docs/cli/link.md +0 -40
  61. package/docs/cli/outdated.md +0 -90
  62. package/docs/cli/patch-commit.md +0 -11
  63. package/docs/cli/pm.md +0 -285
  64. package/docs/cli/publish.md +0 -120
  65. package/docs/cli/remove.md +0 -7
  66. package/docs/cli/run.md +0 -261
  67. package/docs/cli/test.md +0 -397
  68. package/docs/cli/unlink.md +0 -9
  69. package/docs/cli/update.md +0 -129
  70. package/docs/cli/why.md +0 -67
  71. package/docs/contributing/upgrading-webkit.md +0 -57
  72. package/docs/ecosystem/elysia.md +0 -24
  73. package/docs/ecosystem/express.md +0 -37
  74. package/docs/ecosystem/hono.md +0 -18
  75. package/docs/ecosystem/react.md +0 -65
  76. package/docs/ecosystem/stric.md +0 -38
  77. package/docs/guides/binary/arraybuffer-to-array.md +0 -27
  78. package/docs/guides/binary/arraybuffer-to-blob.md +0 -24
  79. package/docs/guides/binary/arraybuffer-to-buffer.md +0 -25
  80. package/docs/guides/binary/arraybuffer-to-string.md +0 -15
  81. package/docs/guides/binary/arraybuffer-to-typedarray.md +0 -39
  82. package/docs/guides/binary/blob-to-arraybuffer.md +0 -14
  83. package/docs/guides/binary/blob-to-dataview.md +0 -14
  84. package/docs/guides/binary/blob-to-stream.md +0 -14
  85. package/docs/guides/binary/blob-to-string.md +0 -15
  86. package/docs/guides/binary/blob-to-typedarray.md +0 -14
  87. package/docs/guides/binary/buffer-to-arraybuffer.md +0 -14
  88. package/docs/guides/binary/buffer-to-blob.md +0 -14
  89. package/docs/guides/binary/buffer-to-readablestream.md +0 -41
  90. package/docs/guides/binary/buffer-to-string.md +0 -25
  91. package/docs/guides/binary/buffer-to-typedarray.md +0 -14
  92. package/docs/guides/binary/dataview-to-string.md +0 -15
  93. package/docs/guides/binary/typedarray-to-arraybuffer.md +0 -25
  94. package/docs/guides/binary/typedarray-to-blob.md +0 -16
  95. package/docs/guides/binary/typedarray-to-buffer.md +0 -14
  96. package/docs/guides/binary/typedarray-to-dataview.md +0 -14
  97. package/docs/guides/binary/typedarray-to-readablestream.md +0 -41
  98. package/docs/guides/binary/typedarray-to-string.md +0 -16
  99. package/docs/guides/deployment/railway.md +0 -157
  100. package/docs/guides/ecosystem/astro.md +0 -72
  101. package/docs/guides/ecosystem/discordjs.md +0 -77
  102. package/docs/guides/ecosystem/docker.md +0 -140
  103. package/docs/guides/ecosystem/drizzle.md +0 -185
  104. package/docs/guides/ecosystem/edgedb.md +0 -228
  105. package/docs/guides/ecosystem/elysia.md +0 -31
  106. package/docs/guides/ecosystem/express.md +0 -40
  107. package/docs/guides/ecosystem/hono.md +0 -39
  108. package/docs/guides/ecosystem/mongoose.md +0 -87
  109. package/docs/guides/ecosystem/neon-drizzle.md +0 -220
  110. package/docs/guides/ecosystem/neon-serverless-postgres.md +0 -55
  111. package/docs/guides/ecosystem/nextjs.md +0 -49
  112. package/docs/guides/ecosystem/nuxt.md +0 -56
  113. package/docs/guides/ecosystem/pm2.md +0 -57
  114. package/docs/guides/ecosystem/prisma.md +0 -141
  115. package/docs/guides/ecosystem/qwik.md +0 -107
  116. package/docs/guides/ecosystem/react.md +0 -50
  117. package/docs/guides/ecosystem/remix.md +0 -78
  118. package/docs/guides/ecosystem/render.md +0 -79
  119. package/docs/guides/ecosystem/sentry.md +0 -52
  120. package/docs/guides/ecosystem/solidstart.md +0 -58
  121. package/docs/guides/ecosystem/ssr-react.md +0 -51
  122. package/docs/guides/ecosystem/stric.md +0 -55
  123. package/docs/guides/ecosystem/sveltekit.md +0 -125
  124. package/docs/guides/ecosystem/systemd.md +0 -113
  125. package/docs/guides/ecosystem/vite.md +0 -71
  126. package/docs/guides/html-rewriter/extract-links.md +0 -68
  127. package/docs/guides/html-rewriter/extract-social-meta.md +0 -93
  128. package/docs/guides/http/cluster.md +0 -66
  129. package/docs/guides/http/fetch-unix.md +0 -33
  130. package/docs/guides/http/fetch.md +0 -24
  131. package/docs/guides/http/file-uploads.md +0 -94
  132. package/docs/guides/http/hot.md +0 -26
  133. package/docs/guides/http/proxy.md +0 -24
  134. package/docs/guides/http/server.md +0 -46
  135. package/docs/guides/http/simple.md +0 -18
  136. package/docs/guides/http/stream-file.md +0 -48
  137. package/docs/guides/http/stream-iterator.md +0 -47
  138. package/docs/guides/http/stream-node-streams-in-bun.md +0 -20
  139. package/docs/guides/http/tls.md +0 -30
  140. package/docs/guides/install/add-dev.md +0 -26
  141. package/docs/guides/install/add-git.md +0 -36
  142. package/docs/guides/install/add-optional.md +0 -25
  143. package/docs/guides/install/add-peer.md +0 -43
  144. package/docs/guides/install/add-tarball.md +0 -33
  145. package/docs/guides/install/add.md +0 -42
  146. package/docs/guides/install/azure-artifacts.md +0 -73
  147. package/docs/guides/install/cicd.md +0 -41
  148. package/docs/guides/install/custom-registry.md +0 -30
  149. package/docs/guides/install/from-npm-install-to-bun-install.md +0 -214
  150. package/docs/guides/install/git-diff-bun-lockfile.md +0 -44
  151. package/docs/guides/install/jfrog-artifactory.md +0 -28
  152. package/docs/guides/install/npm-alias.md +0 -23
  153. package/docs/guides/install/registry-scope.md +0 -38
  154. package/docs/guides/install/trusted.md +0 -46
  155. package/docs/guides/install/workspaces.md +0 -70
  156. package/docs/guides/install/yarnlock.md +0 -44
  157. package/docs/guides/process/argv.md +0 -58
  158. package/docs/guides/process/ctrl-c.md +0 -16
  159. package/docs/guides/process/ipc.md +0 -66
  160. package/docs/guides/process/nanoseconds.md +0 -13
  161. package/docs/guides/process/os-signals.md +0 -39
  162. package/docs/guides/process/spawn-stderr.md +0 -31
  163. package/docs/guides/process/spawn-stdout.md +0 -26
  164. package/docs/guides/process/spawn.md +0 -41
  165. package/docs/guides/process/stdin.md +0 -54
  166. package/docs/guides/read-file/arraybuffer.md +0 -28
  167. package/docs/guides/read-file/buffer.md +0 -19
  168. package/docs/guides/read-file/exists.md +0 -16
  169. package/docs/guides/read-file/json.md +0 -17
  170. package/docs/guides/read-file/mime.md +0 -20
  171. package/docs/guides/read-file/stream.md +0 -26
  172. package/docs/guides/read-file/string.md +0 -22
  173. package/docs/guides/read-file/uint8array.md +0 -21
  174. package/docs/guides/read-file/watch.md +0 -68
  175. package/docs/guides/runtime/build-time-constants.md +0 -293
  176. package/docs/guides/runtime/cicd.md +0 -43
  177. package/docs/guides/runtime/codesign-macos-executable.md +0 -56
  178. package/docs/guides/runtime/define-constant.md +0 -145
  179. package/docs/guides/runtime/delete-directory.md +0 -37
  180. package/docs/guides/runtime/delete-file.md +0 -19
  181. package/docs/guides/runtime/heap-snapshot.md +0 -26
  182. package/docs/guides/runtime/import-html.md +0 -15
  183. package/docs/guides/runtime/import-json.md +0 -44
  184. package/docs/guides/runtime/import-toml.md +0 -30
  185. package/docs/guides/runtime/import-yaml.md +0 -102
  186. package/docs/guides/runtime/read-env.md +0 -32
  187. package/docs/guides/runtime/set-env.md +0 -47
  188. package/docs/guides/runtime/shell.md +0 -40
  189. package/docs/guides/runtime/timezone.md +0 -35
  190. package/docs/guides/runtime/tsconfig-paths.md +0 -29
  191. package/docs/guides/runtime/typescript.md +0 -49
  192. package/docs/guides/runtime/vscode-debugger.md +0 -47
  193. package/docs/guides/runtime/web-debugger.md +0 -82
  194. package/docs/guides/streams/node-readable-to-arraybuffer.md +0 -11
  195. package/docs/guides/streams/node-readable-to-blob.md +0 -11
  196. package/docs/guides/streams/node-readable-to-json.md +0 -12
  197. package/docs/guides/streams/node-readable-to-string.md +0 -12
  198. package/docs/guides/streams/node-readable-to-uint8array.md +0 -11
  199. package/docs/guides/streams/to-array.md +0 -14
  200. package/docs/guides/streams/to-arraybuffer.md +0 -14
  201. package/docs/guides/streams/to-blob.md +0 -14
  202. package/docs/guides/streams/to-buffer.md +0 -15
  203. package/docs/guides/streams/to-json.md +0 -14
  204. package/docs/guides/streams/to-string.md +0 -14
  205. package/docs/guides/streams/to-typedarray.md +0 -22
  206. package/docs/guides/test/bail.md +0 -22
  207. package/docs/guides/test/coverage-threshold.md +0 -60
  208. package/docs/guides/test/coverage.md +0 -44
  209. package/docs/guides/test/happy-dom.md +0 -68
  210. package/docs/guides/test/migrate-from-jest.md +0 -143
  211. package/docs/guides/test/mock-clock.md +0 -48
  212. package/docs/guides/test/mock-functions.md +0 -68
  213. package/docs/guides/test/rerun-each.md +0 -14
  214. package/docs/guides/test/run-tests.md +0 -111
  215. package/docs/guides/test/skip-tests.md +0 -39
  216. package/docs/guides/test/snapshot.md +0 -95
  217. package/docs/guides/test/spy-on.md +0 -46
  218. package/docs/guides/test/svelte-test.md +0 -120
  219. package/docs/guides/test/testing-library.md +0 -92
  220. package/docs/guides/test/timeout.md +0 -15
  221. package/docs/guides/test/todo-tests.md +0 -67
  222. package/docs/guides/test/update-snapshots.md +0 -46
  223. package/docs/guides/test/watch-mode.md +0 -19
  224. package/docs/guides/util/base64.md +0 -15
  225. package/docs/guides/util/deep-equals.md +0 -39
  226. package/docs/guides/util/deflate.md +0 -18
  227. package/docs/guides/util/detect-bun.md +0 -23
  228. package/docs/guides/util/entrypoint.md +0 -17
  229. package/docs/guides/util/escape-html.md +0 -22
  230. package/docs/guides/util/file-url-to-path.md +0 -14
  231. package/docs/guides/util/gzip.md +0 -18
  232. package/docs/guides/util/hash-a-password.md +0 -54
  233. package/docs/guides/util/import-meta-dir.md +0 -13
  234. package/docs/guides/util/import-meta-file.md +0 -13
  235. package/docs/guides/util/import-meta-path.md +0 -13
  236. package/docs/guides/util/javascript-uuid.md +0 -23
  237. package/docs/guides/util/main.md +0 -32
  238. package/docs/guides/util/path-to-file-url.md +0 -14
  239. package/docs/guides/util/sleep.md +0 -22
  240. package/docs/guides/util/version.md +0 -21
  241. package/docs/guides/util/which-path-to-executable-bin.md +0 -15
  242. package/docs/guides/websocket/compression.md +0 -31
  243. package/docs/guides/websocket/context.md +0 -77
  244. package/docs/guides/websocket/pubsub.md +0 -41
  245. package/docs/guides/websocket/simple.md +0 -33
  246. package/docs/guides/write-file/append.md +0 -52
  247. package/docs/guides/write-file/basic.md +0 -44
  248. package/docs/guides/write-file/blob.md +0 -28
  249. package/docs/guides/write-file/cat.md +0 -17
  250. package/docs/guides/write-file/file-cp.md +0 -16
  251. package/docs/guides/write-file/filesink.md +0 -52
  252. package/docs/guides/write-file/response.md +0 -17
  253. package/docs/guides/write-file/stdout.md +0 -21
  254. package/docs/guides/write-file/stream.md +0 -17
  255. package/docs/guides/write-file/unlink.md +0 -16
  256. package/docs/index.md +0 -77
  257. package/docs/install/audit.md +0 -57
  258. package/docs/install/cache.md +0 -59
  259. package/docs/install/catalogs.md +0 -298
  260. package/docs/install/index.md +0 -248
  261. package/docs/install/isolated.md +0 -197
  262. package/docs/install/lifecycle.md +0 -46
  263. package/docs/install/lockfile.md +0 -58
  264. package/docs/install/npmrc.md +0 -105
  265. package/docs/install/overrides.md +0 -73
  266. package/docs/install/patch.md +0 -59
  267. package/docs/install/registries.md +0 -30
  268. package/docs/install/security-scanner-api.md +0 -81
  269. package/docs/install/workspaces.md +0 -114
  270. package/docs/installation.md +0 -327
  271. package/docs/project/asan.md +0 -124
  272. package/docs/project/benchmarking.md +0 -203
  273. package/docs/project/bindgen.md +0 -225
  274. package/docs/project/building-windows.md +0 -162
  275. package/docs/project/contributing.md +0 -347
  276. package/docs/project/internals/build-process-for-ci.md +0 -75
  277. package/docs/project/licensing.md +0 -73
  278. package/docs/project/roadmap.md +0 -87
  279. package/docs/quickstart.md +0 -157
  280. package/docs/runtime/autoimport.md +0 -94
  281. package/docs/runtime/bun-apis.md +0 -207
  282. package/docs/runtime/bunfig.md +0 -772
  283. package/docs/runtime/debugger.md +0 -325
  284. package/docs/runtime/env.md +0 -253
  285. package/docs/runtime/hot.md +0 -145
  286. package/docs/runtime/index.md +0 -312
  287. package/docs/runtime/jsx.md +0 -385
  288. package/docs/runtime/loaders.md +0 -130
  289. package/docs/runtime/modules.md +0 -320
  290. package/docs/runtime/nodejs-apis.md +0 -463
  291. package/docs/runtime/plugins.md +0 -561
  292. package/docs/runtime/shell.md +0 -605
  293. package/docs/runtime/typescript.md +0 -139
  294. package/docs/runtime/web-apis.md +0 -128
  295. package/docs/test/configuration.md +0 -154
  296. package/docs/test/coverage.md +0 -142
  297. package/docs/test/discovery.md +0 -85
  298. package/docs/test/dom.md +0 -75
  299. package/docs/test/examples/concurrent-test-glob.md +0 -132
  300. package/docs/test/hot.md +0 -15
  301. package/docs/test/lifecycle.md +0 -81
  302. package/docs/test/mocks.md +0 -313
  303. package/docs/test/reporters.md +0 -117
  304. package/docs/test/runtime-behavior.md +0 -95
  305. package/docs/test/snapshots.md +0 -68
  306. package/docs/test/time.md +0 -126
  307. package/docs/test/writing.md +0 -825
  308. package/docs/typescript.md +0 -53
@@ -1,1028 +0,0 @@
1
- Bun's bundler has built-in support for CSS with the following features:
2
-
3
- - Transpiling modern/future features to work on all browsers (including vendor prefixing)
4
- - Minification
5
- - CSS Modules
6
- - Tailwind (via a native bundler plugin)
7
-
8
- ## Transpiling
9
-
10
- Bun's CSS bundler lets you use modern/future CSS features without having to worry about browser compatibility — all thanks to its transpiling and vendor prefixing features which are enabled by default.
11
-
12
- Bun's CSS parser and bundler is a direct Rust → Zig port of [LightningCSS](https://lightningcss.dev/), with a bundling approach inspired by esbuild. The transpiler converts modern CSS syntax into backwards-compatible equivalents that work across browsers.
13
-
14
- A huge thanks goes to the amazing work from the authors of [LightningCSS](https://lightningcss.dev/) and [esbuild](https://esbuild.github.io/).
15
-
16
- ### Browser Compatibility
17
-
18
- By default, Bun's CSS bundler targets the following browsers:
19
-
20
- - ES2020
21
- - Edge 88+
22
- - Firefox 78+
23
- - Chrome 87+
24
- - Safari 14+
25
-
26
- ### Syntax Lowering
27
-
28
- #### Nesting
29
-
30
- The CSS Nesting specification allows you to write more concise and intuitive stylesheets by nesting selectors inside one another. Instead of repeating parent selectors across your CSS file, you can write child styles directly within their parent blocks.
31
-
32
- ```css
33
- /* With nesting */
34
- .card {
35
- background: white;
36
- border-radius: 4px;
37
-
38
- .title {
39
- font-size: 1.2rem;
40
- font-weight: bold;
41
- }
42
-
43
- .content {
44
- padding: 1rem;
45
- }
46
- }
47
- ```
48
-
49
- Bun's CSS bundler automatically converts this nested syntax into traditional flat CSS that works in all browsers:
50
-
51
- ```css
52
- /* Compiled output */
53
- .card {
54
- background: white;
55
- border-radius: 4px;
56
- }
57
-
58
- .card .title {
59
- font-size: 1.2rem;
60
- font-weight: bold;
61
- }
62
-
63
- .card .content {
64
- padding: 1rem;
65
- }
66
- ```
67
-
68
- You can also nest media queries and other at-rules inside selectors, eliminating the need to repeat selector patterns:
69
-
70
- ```css
71
- .responsive-element {
72
- display: block;
73
-
74
- @media (min-width: 768px) {
75
- display: flex;
76
- }
77
- }
78
- ```
79
-
80
- This compiles to:
81
-
82
- ```css
83
- .responsive-element {
84
- display: block;
85
- }
86
-
87
- @media (min-width: 768px) {
88
- .responsive-element {
89
- display: flex;
90
- }
91
- }
92
- ```
93
-
94
- #### Color mix
95
-
96
- The `color-mix()` function gives you an easy way to blend two colors together according to a specified ratio in a chosen color space. This powerful feature lets you create color variations without manually calculating the resulting values.
97
-
98
- ```css
99
- .button {
100
- /* Mix blue and red in the RGB color space with a 30/70 proportion */
101
- background-color: color-mix(in srgb, blue 30%, red);
102
-
103
- /* Create a lighter variant for hover state */
104
- &:hover {
105
- background-color: color-mix(in srgb, blue 30%, red, white 20%);
106
- }
107
- }
108
- ```
109
-
110
- Bun's CSS bundler evaluates these color mixes at build time when all color values are known (not CSS variables), generating static color values that work in all browsers:
111
-
112
- ```css
113
- .button {
114
- /* Computed to the exact resulting color */
115
- background-color: #b31a1a;
116
- }
117
-
118
- .button:hover {
119
- background-color: #c54747;
120
- }
121
- ```
122
-
123
- This feature is particularly useful for creating color systems with programmatically derived shades, tints, and accents without needing preprocessors or custom tooling.
124
-
125
- #### Relative colors
126
-
127
- CSS now allows you to modify individual components of a color using relative color syntax. This powerful feature lets you create color variations by adjusting specific attributes like lightness, saturation, or individual channels without having to recalculate the entire color.
128
-
129
- ```css
130
- .theme-color {
131
- /* Start with a base color and increase lightness by 15% */
132
- --accent: lch(from purple calc(l + 15%) c h);
133
-
134
- /* Take our brand blue and make a desaturated version */
135
- --subtle-blue: oklch(from var(--brand-blue) l calc(c * 0.8) h);
136
- }
137
- ```
138
-
139
- Bun's CSS bundler computes these relative color modifications at build time (when not using CSS variables) and generates static color values for browser compatibility:
140
-
141
- ```css
142
- .theme-color {
143
- --accent: lch(69.32% 58.34 328.37);
144
- --subtle-blue: oklch(60.92% 0.112 240.01);
145
- }
146
- ```
147
-
148
- This approach is extremely useful for theme generation, creating accessible color variants, or building color scales based on mathematical relationships instead of hard-coding each value.
149
-
150
- #### LAB colors
151
-
152
- Modern CSS supports perceptually uniform color spaces like LAB, LCH, OKLAB, and OKLCH that offer significant advantages over traditional RGB. These color spaces can represent colors outside the standard RGB gamut, resulting in more vibrant and visually consistent designs.
153
-
154
- ```css
155
- .vibrant-element {
156
- /* A vibrant red that exceeds sRGB gamut boundaries */
157
- color: lab(55% 78 35);
158
-
159
- /* A smooth gradient using perceptual color space */
160
- background: linear-gradient(
161
- to right,
162
- oklch(65% 0.25 10deg),
163
- oklch(65% 0.25 250deg)
164
- );
165
- }
166
- ```
167
-
168
- Bun's CSS bundler automatically converts these advanced color formats to backwards-compatible alternatives for browsers that don't yet support them:
169
-
170
- ```css
171
- .vibrant-element {
172
- /* Fallback to closest RGB approximation */
173
- color: #ff0f52;
174
- /* P3 fallback for browsers with wider gamut support */
175
- color: color(display-p3 1 0.12 0.37);
176
- /* Original value preserved for browsers that support it */
177
- color: lab(55% 78 35);
178
-
179
- background: linear-gradient(to right, #cd4e15, #3887ab);
180
- background: linear-gradient(
181
- to right,
182
- oklch(65% 0.25 10deg),
183
- oklch(65% 0.25 250deg)
184
- );
185
- }
186
- ```
187
-
188
- This layered approach ensures optimal color rendering across all browsers while allowing you to use the latest color technologies in your designs.
189
-
190
- #### Color function
191
-
192
- The `color()` function provides a standardized way to specify colors in various predefined color spaces, expanding your design options beyond the traditional RGB space. This allows you to access wider color gamuts and create more vibrant designs.
193
-
194
- ```css
195
- .vivid-element {
196
- /* Using the Display P3 color space for wider gamut colors */
197
- color: color(display-p3 1 0.1 0.3);
198
-
199
- /* Using A98 RGB color space */
200
- background-color: color(a98-rgb 0.44 0.5 0.37);
201
- }
202
- ```
203
-
204
- For browsers that don't support these advanced color functions yet, Bun's CSS bundler provides appropriate RGB fallbacks:
205
-
206
- ```css
207
- .vivid-element {
208
- /* RGB fallback first for maximum compatibility */
209
- color: #fa1a4c;
210
- /* Keep original for browsers that support it */
211
- color: color(display-p3 1 0.1 0.3);
212
-
213
- background-color: #6a805d;
214
- background-color: color(a98-rgb 0.44 0.5 0.37);
215
- }
216
- ```
217
-
218
- This functionality lets you use modern color spaces immediately while ensuring your designs remain functional across all browsers, with optimal colors displayed in supporting browsers and reasonable approximations elsewhere.
219
-
220
- #### HWB colors
221
-
222
- The HWB (Hue, Whiteness, Blackness) color model provides an intuitive way to express colors based on how much white or black is mixed with a pure hue. Many designers find this approach more natural for creating color variations compared to manipulating RGB or HSL values.
223
-
224
- ```css
225
- .easy-theming {
226
- /* Pure cyan with no white or black added */
227
- --primary: hwb(180 0% 0%);
228
-
229
- /* Same hue, but with 20% white added (tint) */
230
- --primary-light: hwb(180 20% 0%);
231
-
232
- /* Same hue, but with 30% black added (shade) */
233
- --primary-dark: hwb(180 0% 30%);
234
-
235
- /* Muted version with both white and black added */
236
- --primary-muted: hwb(180 30% 20%);
237
- }
238
- ```
239
-
240
- Bun's CSS bundler automatically converts HWB colors to RGB for compatibility with all browsers:
241
-
242
- ```css
243
- .easy-theming {
244
- --primary: #00ffff;
245
- --primary-light: #33ffff;
246
- --primary-dark: #00b3b3;
247
- --primary-muted: #339999;
248
- }
249
- ```
250
-
251
- The HWB model makes it particularly easy to create systematic color variations for design systems, providing a more intuitive approach to creating consistent tints and shades than working directly with RGB or HSL values.
252
-
253
- #### Color notation
254
-
255
- Modern CSS has introduced more intuitive and concise ways to express colors. Space-separated color syntax eliminates the need for commas in RGB and HSL values, while hex colors with alpha channels provide a compact way to specify transparency.
256
-
257
- ```css
258
- .modern-styling {
259
- /* Space-separated RGB notation (no commas) */
260
- color: rgb(50 100 200);
261
-
262
- /* Space-separated RGB with alpha */
263
- border-color: rgba(100 50 200 / 75%);
264
-
265
- /* Hex with alpha channel (8 digits) */
266
- background-color: #00aaff80;
267
-
268
- /* HSL with simplified notation */
269
- box-shadow: 0 5px 10px hsl(200 50% 30% / 40%);
270
- }
271
- ```
272
-
273
- Bun's CSS bundler automatically converts these modern color formats to ensure compatibility with older browsers:
274
-
275
- ```css
276
- .modern-styling {
277
- /* Converted to comma format for older browsers */
278
- color: rgb(50, 100, 200);
279
-
280
- /* Alpha channels handled appropriately */
281
- border-color: rgba(100, 50, 200, 0.75);
282
-
283
- /* Hex+alpha converted to rgba when needed */
284
- background-color: rgba(0, 170, 255, 0.5);
285
-
286
- box-shadow: 0 5px 10px rgba(38, 115, 153, 0.4);
287
- }
288
- ```
289
-
290
- This conversion process lets you write cleaner, more modern CSS while ensuring your styles work correctly across all browsers.
291
-
292
- #### light-dark() color function
293
-
294
- The `light-dark()` function provides an elegant solution for implementing color schemes that respect the user's system preference without requiring complex media queries. This function accepts two color values and automatically selects the appropriate one based on the current color scheme context.
295
-
296
- ```css
297
- :root {
298
- /* Define color scheme support */
299
- color-scheme: light dark;
300
- }
301
-
302
- .themed-component {
303
- /* Automatically picks the right color based on system preference */
304
- background-color: light-dark(#ffffff, #121212);
305
- color: light-dark(#333333, #eeeeee);
306
- border-color: light-dark(#dddddd, #555555);
307
- }
308
-
309
- /* Override system preference when needed */
310
- .light-theme {
311
- color-scheme: light;
312
- }
313
-
314
- .dark-theme {
315
- color-scheme: dark;
316
- }
317
- ```
318
-
319
- For browsers that don't support this feature yet, Bun's CSS bundler converts it to use CSS variables with proper fallbacks:
320
-
321
- ```css
322
- :root {
323
- --lightningcss-light: initial;
324
- --lightningcss-dark: ;
325
- color-scheme: light dark;
326
- }
327
-
328
- @media (prefers-color-scheme: dark) {
329
- :root {
330
- --lightningcss-light: ;
331
- --lightningcss-dark: initial;
332
- }
333
- }
334
-
335
- .light-theme {
336
- --lightningcss-light: initial;
337
- --lightningcss-dark: ;
338
- color-scheme: light;
339
- }
340
-
341
- .dark-theme {
342
- --lightningcss-light: ;
343
- --lightningcss-dark: initial;
344
- color-scheme: dark;
345
- }
346
-
347
- .themed-component {
348
- background-color: var(--lightningcss-light, #ffffff)
349
- var(--lightningcss-dark, #121212);
350
- color: var(--lightningcss-light, #333333) var(--lightningcss-dark, #eeeeee);
351
- border-color: var(--lightningcss-light, #dddddd)
352
- var(--lightningcss-dark, #555555);
353
- }
354
- ```
355
-
356
- This approach gives you a clean way to handle light and dark themes without duplicating styles or writing complex media queries, while maintaining compatibility with browsers that don't yet support the feature natively.
357
-
358
- #### Logical properties
359
-
360
- CSS logical properties let you define layout, spacing, and sizing relative to the document's writing mode and text direction rather than physical screen directions. This is crucial for creating truly international layouts that automatically adapt to different writing systems.
361
-
362
- ```css
363
- .multilingual-component {
364
- /* Margin that adapts to writing direction */
365
- margin-inline-start: 1rem;
366
-
367
- /* Padding that makes sense regardless of text direction */
368
- padding-block: 1rem 2rem;
369
-
370
- /* Border radius for the starting corner at the top */
371
- border-start-start-radius: 4px;
372
-
373
- /* Size that respects the writing mode */
374
- inline-size: 80%;
375
- block-size: auto;
376
- }
377
- ```
378
-
379
- For browsers that don't fully support logical properties, Bun's CSS bundler compiles them to physical properties with appropriate directional adjustments:
380
-
381
- ```css
382
- /* For left-to-right languages */
383
- .multilingual-component:dir(ltr) {
384
- margin-left: 1rem;
385
- padding-top: 1rem;
386
- padding-bottom: 2rem;
387
- border-top-left-radius: 4px;
388
- width: 80%;
389
- height: auto;
390
- }
391
-
392
- /* For right-to-left languages */
393
- .multilingual-component:dir(rtl) {
394
- margin-right: 1rem;
395
- padding-top: 1rem;
396
- padding-bottom: 2rem;
397
- border-top-right-radius: 4px;
398
- width: 80%;
399
- height: auto;
400
- }
401
- ```
402
-
403
- If the `:dir()` selector isn't supported, additional fallbacks are automatically generated to ensure your layouts work properly across all browsers and writing systems. This makes creating internationalized designs much simpler while maintaining compatibility with older browsers.
404
-
405
- #### :dir() selector
406
-
407
- The `:dir()` pseudo-class selector allows you to style elements based on their text direction (RTL or LTR), providing a powerful way to create direction-aware designs without JavaScript. This selector matches elements based on their directionality as determined by the document or explicit direction attributes.
408
-
409
- ```css
410
- /* Apply different styles based on text direction */
411
- .nav-arrow:dir(ltr) {
412
- transform: rotate(0deg);
413
- }
414
-
415
- .nav-arrow:dir(rtl) {
416
- transform: rotate(180deg);
417
- }
418
-
419
- /* Position elements based on text flow */
420
- .sidebar:dir(ltr) {
421
- border-right: 1px solid #ddd;
422
- }
423
-
424
- .sidebar:dir(rtl) {
425
- border-left: 1px solid #ddd;
426
- }
427
- ```
428
-
429
- For browsers that don't support the `:dir()` selector yet, Bun's CSS bundler converts it to the more widely supported `:lang()` selector with appropriate language mappings:
430
-
431
- ```css
432
- /* Converted to use language-based selectors as fallback */
433
- .nav-arrow:lang(en, fr, de, es, it, pt, nl) {
434
- transform: rotate(0deg);
435
- }
436
-
437
- .nav-arrow:lang(ar, he, fa, ur) {
438
- transform: rotate(180deg);
439
- }
440
-
441
- .sidebar:lang(en, fr, de, es, it, pt, nl) {
442
- border-right: 1px solid #ddd;
443
- }
444
-
445
- .sidebar:lang(ar, he, fa, ur) {
446
- border-left: 1px solid #ddd;
447
- }
448
- ```
449
-
450
- This conversion lets you write direction-aware CSS that works reliably across browsers, even those that don't yet support the `:dir()` selector natively. If multiple arguments to `:lang()` aren't supported, further fallbacks are automatically provided.
451
-
452
- #### :lang() selector
453
-
454
- The `:lang()` pseudo-class selector allows you to target elements based on the language they're in, making it easy to apply language-specific styling. Modern CSS allows the `:lang()` selector to accept multiple language codes, letting you group language-specific rules more efficiently.
455
-
456
- ```css
457
- /* Typography adjustments for CJK languages */
458
- :lang(zh, ja, ko) {
459
- line-height: 1.8;
460
- font-size: 1.05em;
461
- }
462
-
463
- /* Different quote styles by language group */
464
- blockquote:lang(fr, it, es, pt) {
465
- font-style: italic;
466
- }
467
-
468
- blockquote:lang(de, nl, da, sv) {
469
- font-weight: 500;
470
- }
471
- ```
472
-
473
- For browsers that don't support multiple arguments in the `:lang()` selector, Bun's CSS bundler converts this syntax to use the `:is()` selector to maintain the same behavior:
474
-
475
- ```css
476
- /* Multiple languages grouped with :is() for better browser support */
477
- :is(:lang(zh), :lang(ja), :lang(ko)) {
478
- line-height: 1.8;
479
- font-size: 1.05em;
480
- }
481
-
482
- blockquote:is(:lang(fr), :lang(it), :lang(es), :lang(pt)) {
483
- font-style: italic;
484
- }
485
-
486
- blockquote:is(:lang(de), :lang(nl), :lang(da), :lang(sv)) {
487
- font-weight: 500;
488
- }
489
- ```
490
-
491
- If needed, Bun can provide additional fallbacks for `:is()` as well, ensuring your language-specific styles work across all browsers. This approach simplifies creating internationalized designs with distinct typographic and styling rules for different language groups.
492
-
493
- #### :is() selector
494
-
495
- The `:is()` pseudo-class function (formerly `:matches()`) allows you to create more concise and readable selectors by grouping multiple selectors together. It accepts a selector list as its argument and matches if any of the selectors in that list match, significantly reducing repetition in your CSS.
496
-
497
- ```css
498
- /* Instead of writing these separately */
499
- /*
500
- .article h1,
501
- .article h2,
502
- .article h3 {
503
- margin-top: 1.5em;
504
- }
505
- */
506
-
507
- /* You can write this */
508
- .article :is(h1, h2, h3) {
509
- margin-top: 1.5em;
510
- }
511
-
512
- /* Complex example with multiple groups */
513
- :is(header, main, footer) :is(h1, h2, .title) {
514
- font-family: "Heading Font", sans-serif;
515
- }
516
- ```
517
-
518
- For browsers that don't support `:is()`, Bun's CSS bundler provides fallbacks using vendor-prefixed alternatives:
519
-
520
- ```css
521
- /* Fallback using -webkit-any */
522
- .article :-webkit-any(h1, h2, h3) {
523
- margin-top: 1.5em;
524
- }
525
-
526
- /* Fallback using -moz-any */
527
- .article :-moz-any(h1, h2, h3) {
528
- margin-top: 1.5em;
529
- }
530
-
531
- /* Original preserved for modern browsers */
532
- .article :is(h1, h2, h3) {
533
- margin-top: 1.5em;
534
- }
535
-
536
- /* Complex example with fallbacks */
537
- :-webkit-any(header, main, footer) :-webkit-any(h1, h2, .title) {
538
- font-family: "Heading Font", sans-serif;
539
- }
540
-
541
- :-moz-any(header, main, footer) :-moz-any(h1, h2, .title) {
542
- font-family: "Heading Font", sans-serif;
543
- }
544
-
545
- :is(header, main, footer) :is(h1, h2, .title) {
546
- font-family: "Heading Font", sans-serif;
547
- }
548
- ```
549
-
550
- It's worth noting that the vendor-prefixed versions have some limitations compared to the standardized `:is()` selector, particularly with complex selectors. Bun handles these limitations intelligently, only using prefixed versions when they'll work correctly.
551
-
552
- #### :not() selector
553
-
554
- The `:not()` pseudo-class allows you to exclude elements that match a specific selector. The modern version of this selector accepts multiple arguments, letting you exclude multiple patterns with a single, concise selector.
555
-
556
- ```css
557
- /* Select all buttons except primary and secondary variants */
558
- button:not(.primary, .secondary) {
559
- background-color: #f5f5f5;
560
- border: 1px solid #ddd;
561
- }
562
-
563
- /* Apply styles to all headings except those inside sidebars or footers */
564
- h2:not(.sidebar *, footer *) {
565
- margin-top: 2em;
566
- }
567
- ```
568
-
569
- For browsers that don't support multiple arguments in `:not()`, Bun's CSS bundler converts this syntax to a more compatible form while preserving the same behavior:
570
-
571
- ```css
572
- /* Converted to use :not with :is() for compatibility */
573
- button:not(:is(.primary, .secondary)) {
574
- background-color: #f5f5f5;
575
- border: 1px solid #ddd;
576
- }
577
-
578
- h2:not(:is(.sidebar *, footer *)) {
579
- margin-top: 2em;
580
- }
581
- ```
582
-
583
- And if `:is()` isn't supported, Bun can generate further fallbacks:
584
-
585
- ```css
586
- /* Even more fallbacks for maximum compatibility */
587
- button:not(:-webkit-any(.primary, .secondary)) {
588
- background-color: #f5f5f5;
589
- border: 1px solid #ddd;
590
- }
591
-
592
- button:not(:-moz-any(.primary, .secondary)) {
593
- background-color: #f5f5f5;
594
- border: 1px solid #ddd;
595
- }
596
-
597
- button:not(:is(.primary, .secondary)) {
598
- background-color: #f5f5f5;
599
- border: 1px solid #ddd;
600
- }
601
- ```
602
-
603
- This conversion ensures your negative selectors work correctly across all browsers while maintaining the correct specificity and behavior of the original selector.
604
-
605
- #### Math functions
606
-
607
- CSS now includes a rich set of mathematical functions that let you perform complex calculations directly in your stylesheets. These include standard math functions (`round()`, `mod()`, `rem()`, `abs()`, `sign()`), trigonometric functions (`sin()`, `cos()`, `tan()`, `asin()`, `acos()`, `atan()`, `atan2()`), and exponential functions (`pow()`, `sqrt()`, `exp()`, `log()`, `hypot()`).
608
-
609
- ```css
610
- .dynamic-sizing {
611
- /* Clamp a value between minimum and maximum */
612
- width: clamp(200px, 50%, 800px);
613
-
614
- /* Round to the nearest multiple */
615
- padding: round(14.8px, 5px);
616
-
617
- /* Trigonometry for animations or layouts */
618
- transform: rotate(calc(sin(45deg) * 50deg));
619
-
620
- /* Complex math with multiple functions */
621
- --scale-factor: pow(1.25, 3);
622
- font-size: calc(16px * var(--scale-factor));
623
- }
624
- ```
625
-
626
- Bun's CSS bundler evaluates these mathematical expressions at build time when all values are known constants (not variables), resulting in optimized output:
627
-
628
- ```css
629
- .dynamic-sizing {
630
- width: clamp(200px, 50%, 800px);
631
- padding: 15px;
632
- transform: rotate(35.36deg);
633
- --scale-factor: 1.953125;
634
- font-size: calc(16px * var(--scale-factor));
635
- }
636
- ```
637
-
638
- This approach lets you write more expressive and maintainable CSS with meaningful mathematical relationships, which then gets compiled to optimized values for maximum browser compatibility and performance.
639
-
640
- #### Media query ranges
641
-
642
- Modern CSS supports intuitive range syntax for media queries, allowing you to specify breakpoints using comparison operators like `<`, `>`, `<=`, and `>=` instead of the more verbose `min-` and `max-` prefixes. This syntax is more readable and matches how we normally think about values and ranges.
643
-
644
- ```css
645
- /* Modern syntax with comparison operators */
646
- @media (width >= 768px) {
647
- .container {
648
- max-width: 720px;
649
- }
650
- }
651
-
652
- /* Inclusive range using <= and >= */
653
- @media (768px <= width <= 1199px) {
654
- .sidebar {
655
- display: flex;
656
- }
657
- }
658
-
659
- /* Exclusive range using < and > */
660
- @media (width > 320px) and (width < 768px) {
661
- .mobile-only {
662
- display: block;
663
- }
664
- }
665
- ```
666
-
667
- Bun's CSS bundler converts these modern range queries to traditional media query syntax for compatibility with all browsers:
668
-
669
- ```css
670
- /* Converted to traditional min/max syntax */
671
- @media (min-width: 768px) {
672
- .container {
673
- max-width: 720px;
674
- }
675
- }
676
-
677
- @media (min-width: 768px) and (max-width: 1199px) {
678
- .sidebar {
679
- display: flex;
680
- }
681
- }
682
-
683
- @media (min-width: 321px) and (max-width: 767px) {
684
- .mobile-only {
685
- display: block;
686
- }
687
- }
688
- ```
689
-
690
- This lets you write more intuitive and mathematical media queries while ensuring your stylesheets work correctly across all browsers, including those that don't support the modern range syntax.
691
-
692
- #### Shorthands
693
-
694
- CSS has introduced several modern shorthand properties that improve code readability and maintainability. Bun's CSS bundler ensures these convenient shorthands work on all browsers by converting them to their longhand equivalents when needed.
695
-
696
- ```css
697
- /* Alignment shorthands */
698
- .flex-container {
699
- /* Shorthand for align-items and justify-items */
700
- place-items: center start;
701
-
702
- /* Shorthand for align-content and justify-content */
703
- place-content: space-between center;
704
- }
705
-
706
- .grid-item {
707
- /* Shorthand for align-self and justify-self */
708
- place-self: end center;
709
- }
710
-
711
- /* Two-value overflow */
712
- .content-box {
713
- /* First value for horizontal, second for vertical */
714
- overflow: hidden auto;
715
- }
716
-
717
- /* Enhanced text-decoration */
718
- .fancy-link {
719
- /* Combines multiple text decoration properties */
720
- text-decoration: underline dotted blue 2px;
721
- }
722
-
723
- /* Two-value display syntax */
724
- .component {
725
- /* Outer display type + inner display type */
726
- display: inline flex;
727
- }
728
- ```
729
-
730
- For browsers that don't support these modern shorthands, Bun converts them to their component longhand properties:
731
-
732
- ```css
733
- .flex-container {
734
- /* Expanded alignment properties */
735
- align-items: center;
736
- justify-items: start;
737
-
738
- align-content: space-between;
739
- justify-content: center;
740
- }
741
-
742
- .grid-item {
743
- align-self: end;
744
- justify-self: center;
745
- }
746
-
747
- .content-box {
748
- /* Separate overflow properties */
749
- overflow-x: hidden;
750
- overflow-y: auto;
751
- }
752
-
753
- .fancy-link {
754
- /* Individual text decoration properties */
755
- text-decoration-line: underline;
756
- text-decoration-style: dotted;
757
- text-decoration-color: blue;
758
- text-decoration-thickness: 2px;
759
- }
760
-
761
- .component {
762
- /* Single value display */
763
- display: inline-flex;
764
- }
765
- ```
766
-
767
- This conversion ensures your stylesheets remain clean and maintainable while providing the broadest possible browser compatibility.
768
-
769
- #### Double position gradients
770
-
771
- The double position gradient syntax is a modern CSS feature that allows you to create hard color stops in gradients by specifying the same color at two adjacent positions. This creates a sharp transition rather than a smooth fade, which is useful for creating stripes, color bands, and other multi-color designs.
772
-
773
- ```css
774
- .striped-background {
775
- /* Creates a sharp transition from green to red at 30%-40% */
776
- background: linear-gradient(
777
- to right,
778
- yellow 0%,
779
- green 20%,
780
- green 30%,
781
- red 30%,
782
- /* Double position creates hard stop */ red 70%,
783
- blue 70%,
784
- blue 100%
785
- );
786
- }
787
-
788
- .progress-bar {
789
- /* Creates distinct color sections */
790
- background: linear-gradient(
791
- to right,
792
- #4caf50 0% 25%,
793
- /* Green from 0% to 25% */ #ffc107 25% 50%,
794
- /* Yellow from 25% to 50% */ #2196f3 50% 75%,
795
- /* Blue from 50% to 75% */ #9c27b0 75% 100% /* Purple from 75% to 100% */
796
- );
797
- }
798
- ```
799
-
800
- For browsers that don't support this syntax, Bun's CSS bundler automatically converts it to the traditional format by duplicating color stops:
801
-
802
- ```css
803
- .striped-background {
804
- background: linear-gradient(
805
- to right,
806
- yellow 0%,
807
- green 20%,
808
- green 30%,
809
- red 30%,
810
- /* Split into two color stops */ red 70%,
811
- blue 70%,
812
- blue 100%
813
- );
814
- }
815
-
816
- .progress-bar {
817
- background: linear-gradient(
818
- to right,
819
- #4caf50 0%,
820
- #4caf50 25%,
821
- /* Two stops for green section */ #ffc107 25%,
822
- #ffc107 50%,
823
- /* Two stops for yellow section */ #2196f3 50%,
824
- #2196f3 75%,
825
- /* Two stops for blue section */ #9c27b0 75%,
826
- #9c27b0 100% /* Two stops for purple section */
827
- );
828
- }
829
- ```
830
-
831
- This conversion lets you use the cleaner double position syntax in your source code while ensuring gradients display correctly in all browsers.
832
-
833
- #### system-ui font
834
-
835
- The `system-ui` generic font family lets you use the device's native UI font, creating interfaces that feel more integrated with the operating system. This provides a more native look and feel without having to specify different font stacks for each platform.
836
-
837
- ```css
838
- .native-interface {
839
- /* Use the system's default UI font */
840
- font-family: system-ui;
841
- }
842
-
843
- .fallback-aware {
844
- /* System UI font with explicit fallbacks */
845
- font-family: system-ui, sans-serif;
846
- }
847
- ```
848
-
849
- For browsers that don't support `system-ui`, Bun's CSS bundler automatically expands it to a comprehensive cross-platform font stack:
850
-
851
- ```css
852
- .native-interface {
853
- /* Expanded to support all major platforms */
854
- font-family:
855
- system-ui,
856
- -apple-system,
857
- BlinkMacSystemFont,
858
- "Segoe UI",
859
- Roboto,
860
- "Noto Sans",
861
- Ubuntu,
862
- Cantarell,
863
- "Helvetica Neue";
864
- }
865
-
866
- .fallback-aware {
867
- /* Preserves the original fallback after the expanded stack */
868
- font-family:
869
- system-ui,
870
- -apple-system,
871
- BlinkMacSystemFont,
872
- "Segoe UI",
873
- Roboto,
874
- "Noto Sans",
875
- Ubuntu,
876
- Cantarell,
877
- "Helvetica Neue",
878
- sans-serif;
879
- }
880
- ```
881
-
882
- This approach gives you the simplicity of writing just `system-ui` in your source code while ensuring your interface adapts correctly to all operating systems and browsers. The expanded font stack includes appropriate system fonts for macOS/iOS, Windows, Android, Linux, and fallbacks for older browsers.
883
-
884
- ## CSS Modules
885
-
886
- Bun's bundler also supports bundling [CSS modules](https://css-tricks.com/css-modules-part-1-need/) in addition to [regular CSS](/docs/bundler/css) with support for the following features:
887
-
888
- - Automatically detecting CSS module files (`.module.css`) with zero configuration
889
- - Composition (`composes` property)
890
- - Importing CSS modules into JSX/TSX
891
- - Warnings/errors for invalid usages of CSS modules
892
-
893
- A CSS module is a CSS file (with the `.module.css` extension) where are all class names and animations are scoped to the file. This helps you avoid class name collisions as CSS declarations are globally scoped by default.
894
-
895
- Under the hood, Bun's bundler transforms locally scoped class names into unique identifiers.
896
-
897
- ## Getting started
898
-
899
- Create a CSS file with the `.module.css` extension:
900
-
901
- ```css
902
- /* styles.module.css */
903
- .button {
904
- color: red;
905
- }
906
-
907
- /* other-styles.module.css */
908
- .button {
909
- color: blue;
910
- }
911
- ```
912
-
913
- You can then import this file, for example into a TSX file:
914
-
915
- ```tsx
916
- import styles from "./styles.module.css";
917
- import otherStyles from "./other-styles.module.css";
918
-
919
- export default function App() {
920
- return (
921
- <>
922
- <button className={styles.button}>Red button!</button>
923
- <button className={otherStyles.button}>Blue button!</button>
924
- </>
925
- );
926
- }
927
- ```
928
-
929
- The `styles` object from importing the CSS module file will be an object with all class names as keys and
930
- their unique identifiers as values:
931
-
932
- ```tsx
933
- import styles from "./styles.module.css";
934
- import otherStyles from "./other-styles.module.css";
935
-
936
- console.log(styles);
937
- console.log(otherStyles);
938
- ```
939
-
940
- This will output:
941
-
942
- ```ts
943
- {
944
- button: "button_123";
945
- }
946
-
947
- {
948
- button: "button_456";
949
- }
950
- ```
951
-
952
- As you can see, the class names are unique to each file, avoiding any collisions!
953
-
954
- ### Composition
955
-
956
- CSS modules allow you to _compose_ class selectors together. This lets you reuse style rules across multiple classes.
957
-
958
- For example:
959
-
960
- ```css
961
- /* styles.module.css */
962
- .button {
963
- composes: background;
964
- color: red;
965
- }
966
-
967
- .background {
968
- background-color: blue;
969
- }
970
- ```
971
-
972
- Would be the same as writing:
973
-
974
- ```css
975
- .button {
976
- background-color: blue;
977
- color: red;
978
- }
979
-
980
- .background {
981
- background-color: blue;
982
- }
983
- ```
984
-
985
- {% callout %}
986
- There are a couple rules to keep in mind when using `composes`:
987
-
988
- - A `composes` property must come before any regular CSS properties or declarations
989
- - You can only use `composes` on a **simple selector with a single class name**:
990
-
991
- ```css
992
- #button {
993
- /* Invalid! `#button` is not a class selector */
994
- composes: background;
995
- }
996
-
997
- .button,
998
- .button-secondary {
999
- /* Invalid! `.button, .button-secondary` is not a simple selector */
1000
- composes: background;
1001
- }
1002
- ```
1003
-
1004
- {% /callout %}
1005
-
1006
- ### Composing from a separate CSS module file
1007
-
1008
- You can also compose from a separate CSS module file:
1009
-
1010
- ```css
1011
- /* background.module.css */
1012
- .background {
1013
- background-color: blue;
1014
- }
1015
-
1016
- /* styles.module.css */
1017
- .button {
1018
- composes: background from "./background.module.css";
1019
- color: red;
1020
- }
1021
- ```
1022
-
1023
- {% callout %}
1024
- When composing classes from separate files, be sure that they do not contain the same properties.
1025
-
1026
- The CSS module spec says that composing classes from separate files with conflicting properties is
1027
- undefined behavior, meaning that the output may differ and be unreliable.
1028
- {% /callout %}