@barocss/browser 0.0.3 → 0.5.0
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.
- package/README.md +92 -7
- package/dist/cdn/barocss.js +1873 -1261
- package/dist/cdn/barocss.js.map +1 -1
- package/dist/cdn/barocss.umd.cjs +1 -1
- package/dist/cdn/barocss.umd.cjs.map +1 -1
- package/dist/index.d.ts +330 -5
- package/dist/index.es.js +290 -98
- package/dist/index.umd.js +9 -6
- package/package.json +10 -6
- package/dist/baro-boot.d.ts +0 -8
- package/dist/browser-runtime.d.ts +0 -119
- package/dist/change-detector.d.ts +0 -80
- package/dist/style-partition-manager.d.ts +0 -51
- package/dist/utils.d.ts +0 -2
package/README.md
CHANGED
|
@@ -8,6 +8,41 @@
|
|
|
8
8
|
|
|
9
9
|
@barocss/browser provides a browser-specific runtime that automatically detects DOM changes and generates CSS in real-time. It includes DOM change detection, style injection, and performance optimizations for browser environments.
|
|
10
10
|
|
|
11
|
+
## Recipe: BaroCSS next to a Tailwind/shadcn build (json-render)
|
|
12
|
+
|
|
13
|
+
Use this when the page already links a Tailwind 4 / shadcn build and a model sends json-render specs whose `className` values the build never saw. Copy it as is:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { getRuntime, shadcnTheme, preloadJsonRenderClasses } from '@barocss/browser';
|
|
17
|
+
// CDN/UMD build: const { getRuntime, shadcnTheme, preloadJsonRenderClasses } = window.BaroCSS;
|
|
18
|
+
|
|
19
|
+
const runtime = getRuntime({
|
|
20
|
+
skipExisting: true, // only generate classes the build does not already define
|
|
21
|
+
config: {
|
|
22
|
+
cssVarPrefix: 'tw', // share --tw-* composite variables with the Tailwind build
|
|
23
|
+
theme: { extend: shadcnTheme }, // use the shadcn :root tokens (primary, muted-foreground, ...)
|
|
24
|
+
// preflight: leave unset. The layered preflight (@layer base) is the default and should stay on.
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
runtime.observe(document.body, { scan: true }); // also covers classes added later
|
|
28
|
+
|
|
29
|
+
const spec = validateResponse(response); // your catalog / class allowlist checks
|
|
30
|
+
preloadJsonRenderClasses(spec, runtime); // BEFORE mounting, so there is no unstyled flash
|
|
31
|
+
renderJsonUi(spec); // mount your json-render Renderer
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The five settings: `skipExisting: true`, `cssVarPrefix: 'tw'`, `theme: { extend: shadcnTheme }`, `preloadJsonRenderClasses(spec, runtime)` before mount, and the default layered preflight (don't set `preflight: false`).
|
|
35
|
+
|
|
36
|
+
**Verify it rendered** (DevTools console, after mount):
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
runtime.getCss('bg-primary'); // a CSS string once generated (undefined if the build already had it)
|
|
40
|
+
getComputedStyle(document.querySelector('[class~="bg-primary"]')).backgroundColor; // not 'rgba(0, 0, 0, 0)'
|
|
41
|
+
document.querySelectorAll('style[id^="barocss-runtime"]').length; // > 0
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Browser support:** Chrome/Edge 85+, Safari/iOS 16.4+, Firefox 128+. The runtime needs CSS `@property`; composite utilities (shadows, rings, transforms, filters) may not render on older engines.
|
|
45
|
+
|
|
11
46
|
## ✨ Key Features
|
|
12
47
|
|
|
13
48
|
- **🚀 Real-time DOM Detection** - Automatically detects and processes class changes
|
|
@@ -36,7 +71,7 @@ yarn add @barocss/browser
|
|
|
36
71
|
```typescript
|
|
37
72
|
import { BrowserRuntime } from '@barocss/browser';
|
|
38
73
|
|
|
39
|
-
//
|
|
74
|
+
// Standalone page with no Tailwind build: defaults are fine. Next to a build, use the recipe above.
|
|
40
75
|
const runtime = new BrowserRuntime();
|
|
41
76
|
|
|
42
77
|
// Watch DOM changes and auto-style
|
|
@@ -51,6 +86,25 @@ document.body.innerHTML = `
|
|
|
51
86
|
`;
|
|
52
87
|
```
|
|
53
88
|
|
|
89
|
+
### Preload classes from json-render
|
|
90
|
+
|
|
91
|
+
Call the preloader after validating the response and before mounting the renderer:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { BrowserRuntime, preloadJsonRenderClasses, shadcnTheme } from '@barocss/browser';
|
|
95
|
+
|
|
96
|
+
// Same options as the recipe above; drop them only when there is no Tailwind/shadcn build on the page.
|
|
97
|
+
const runtime = new BrowserRuntime({
|
|
98
|
+
skipExisting: true,
|
|
99
|
+
config: { cssVarPrefix: 'tw', theme: { extend: shadcnTheme } },
|
|
100
|
+
});
|
|
101
|
+
const spec = validateResponse(response); // Your catalog and class allowlist checks
|
|
102
|
+
preloadJsonRenderClasses(spec, runtime);
|
|
103
|
+
renderJsonUi(spec); // Mount your json-render Renderer here
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The helper reads literal `props.className` strings in the flat `spec.elements` map. It splits class lists, removes duplicates, and calls `runtime.addClass` synchronously. It does not return a CSS readiness result. The application must validate the spec, response size, class allowlist, class support, and runtime state before this call. The helper reads every entry, including nodes that the renderer may not mount. State-derived classes and classes added inside registered components need a separate source of classes.
|
|
107
|
+
|
|
54
108
|
### CDN Usage
|
|
55
109
|
|
|
56
110
|
```html
|
|
@@ -68,9 +122,9 @@ document.body.innerHTML = `
|
|
|
68
122
|
</div>
|
|
69
123
|
|
|
70
124
|
<script type="module">
|
|
71
|
-
import { BrowserRuntime } from 'https://unpkg.com/@barocss/browser/dist/
|
|
125
|
+
import { BrowserRuntime } from 'https://unpkg.com/@barocss/browser@latest/dist/cdn/barocss.js';
|
|
72
126
|
|
|
73
|
-
const runtime = new BrowserRuntime();
|
|
127
|
+
const runtime = new BrowserRuntime(); // no Tailwind build here; next to one, use the recipe's options
|
|
74
128
|
runtime.observe(document.body, { scan: true });
|
|
75
129
|
</script>
|
|
76
130
|
</body>
|
|
@@ -90,7 +144,7 @@ The browser runtime provides real-time CSS generation:
|
|
|
90
144
|
```typescript
|
|
91
145
|
import { BrowserRuntime } from '@barocss/browser';
|
|
92
146
|
|
|
93
|
-
const runtime = new BrowserRuntime();
|
|
147
|
+
const runtime = new BrowserRuntime(); // no Tailwind build here; next to one, use the recipe's options
|
|
94
148
|
|
|
95
149
|
// Automatically detects and processes these changes:
|
|
96
150
|
document.body.innerHTML = `
|
|
@@ -114,7 +168,7 @@ document.body.innerHTML = `
|
|
|
114
168
|
```typescript
|
|
115
169
|
import { BrowserRuntime } from '@barocss/browser';
|
|
116
170
|
|
|
117
|
-
const runtime = new BrowserRuntime();
|
|
171
|
+
const runtime = new BrowserRuntime(); // no Tailwind build here; next to one, use the recipe's options
|
|
118
172
|
|
|
119
173
|
// Watch entire document
|
|
120
174
|
runtime.observe(document.body, { scan: true });
|
|
@@ -129,6 +183,7 @@ runtime.observe(container, { scan: true });
|
|
|
129
183
|
```typescript
|
|
130
184
|
import { BrowserRuntime } from '@barocss/browser';
|
|
131
185
|
|
|
186
|
+
// Custom theme, no Tailwind build; next to one, add the recipe's options too
|
|
132
187
|
const runtime = new BrowserRuntime({
|
|
133
188
|
config: {
|
|
134
189
|
theme: {
|
|
@@ -154,7 +209,7 @@ const runtime = new BrowserRuntime({
|
|
|
154
209
|
```typescript
|
|
155
210
|
import { BrowserRuntime } from '@barocss/browser';
|
|
156
211
|
|
|
157
|
-
const runtime = new BrowserRuntime();
|
|
212
|
+
const runtime = new BrowserRuntime(); // no Tailwind build here; next to one, use the recipe's options
|
|
158
213
|
|
|
159
214
|
// Get runtime statistics
|
|
160
215
|
const stats = runtime.getStats();
|
|
@@ -167,6 +222,10 @@ runtime.clearCaches();
|
|
|
167
222
|
|
|
168
223
|
## 🔧 Configuration
|
|
169
224
|
|
|
225
|
+
`getRuntime()` / `baroStart()` share one runtime. Passing a `config` when that runtime
|
|
226
|
+
already exists applies it with `updateConfig` (replacing the whole config), so calling
|
|
227
|
+
`getRuntime()` before `baroStart({ config })` does not lose the config.
|
|
228
|
+
|
|
170
229
|
### Runtime Options
|
|
171
230
|
|
|
172
231
|
```typescript
|
|
@@ -270,4 +329,30 @@ This project is licensed under the MIT License - see the [LICENSE](../../LICENSE
|
|
|
270
329
|
|
|
271
330
|
---
|
|
272
331
|
|
|
273
|
-
**@barocss/browser** - Real-time CSS generation for browsers.
|
|
332
|
+
**@barocss/browser** - Real-time CSS generation for browsers.
|
|
333
|
+
|
|
334
|
+
## BaroCSS next to a shadcn build
|
|
335
|
+
|
|
336
|
+
A shadcn app built with Tailwind 4 can make the runtime use its theme without a duplicate JS config:
|
|
337
|
+
|
|
338
|
+
```js
|
|
339
|
+
import { baroStart, shadcnTheme } from '@barocss/browser';
|
|
340
|
+
|
|
341
|
+
baroStart({ config: { theme: { extend: shadcnTheme } } }); // theme only; with a Tailwind build + json-render use the full recipe at the top
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
`shadcnTheme` maps the shadcn colours (`background`, `primary`, `muted-foreground`, `border`, `ring`, `chart-1..5`, `sidebar-*`, ...) and `rounded-sm/md/lg/xl` to the raw `:root` variables (`var(--primary)`, `calc(var(--radius) - 2px)`). It does not use `--color-*`, because `@theme inline` doesn't emit those to the page. Opacity modifiers such as `bg-primary/90` work. It expects full colour values in `:root`, as shadcn v4 ships them (e.g. `--primary: oklch(0.205 0 0)`). Older shadcn v3 themes that store bare HSL channels (`--primary: 222 47% 11%`) won't resolve through `var(--primary)`; map those tokens to `hsl(var(--primary))` in your own `theme.extend` instead.
|
|
345
|
+
|
|
346
|
+
Custom tokens (for example `--brand`) are not included. Add them yourself: `theme: { extend: { ...shadcnTheme, colors: { ...shadcnTheme.colors, brand: 'var(--brand)' } } }`.
|
|
347
|
+
|
|
348
|
+
## BaroCSS next to a Tailwind build (companion mode)
|
|
349
|
+
|
|
350
|
+
When the page already links a Tailwind 4 build and the runtime only fills in classes the build did not see, set `cssVarPrefix: 'tw'` so the runtime writes its composite variables with the build's names (`--tw-shadow`, `--tw-ring-shadow`, `--tw-translate-x`, `--tw-skew-x`, `--tw-blur`, `--tw-border-style`, ...):
|
|
351
|
+
|
|
352
|
+
```js
|
|
353
|
+
baroStart({ skipExisting: true, config: { cssVarPrefix: 'tw' } }); // add theme: { extend: shadcnTheme } for shadcn (recipe at the top)
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
The rename applies to every `--baro-` name in the generated CSS, including `--baro-*` names you write in your own arbitrary or custom-property values.
|
|
357
|
+
|
|
358
|
+
A build class and a runtime class on one element then compose: build `ring-2` + runtime `shadow-md` gives both layers, build `translate-x-2` + runtime `translate-y-4` gives `8px 16px`, build `border-dashed` + runtime `border-2` stays dashed. Without it the runtime uses `--baro-*` names, and the two halves overwrite each other. Leave it unset when there is no Tailwind build. Gradient stops (`from-*`/`via-*`/`to-*` with `bg-linear-*`) do not yet follow Tailwind's variable protocol, so mixing them between build and runtime is not supported.
|