@csszyx/dynamic 0.10.11 → 0.10.12

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 (2) hide show
  1. package/README.md +93 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # @csszyx/dynamic
2
+
3
+ Runtime CSS injection for [CSSzyx](https://github.com/nguyennhutien/csszyx) —
4
+ turn sz objects into class strings **at runtime**, injecting CSS only for
5
+ classes not already in your pre-built stylesheet.
6
+
7
+ Static styles belong in the build (`sz` prop / `szv` — zero runtime cost).
8
+ `dynamic()` is the escape hatch for values that genuinely cannot be known at
9
+ build time: styling driven by a CMS, an API response, or user configuration.
10
+
11
+ ```tsx
12
+ import { dynamic } from "@csszyx/dynamic";
13
+
14
+ const cls = dynamic(apiResponse.field.style); // e.g. { p: 4, bg: 'blue-500' }
15
+ <div className={cls} />;
16
+ ```
17
+
18
+ ## How it works
19
+
20
+ 1. **Manifest delta check** — a build-generated manifest lists every class in
21
+ the built CSS. Classes already covered are returned as-is (mangled in
22
+ production), with no injection.
23
+ 2. **CSS generation** — classes NOT in the manifest get a CSS rule generated in
24
+ the browser using Tailwind v4 variable patterns.
25
+ 3. **21-tier injection** — rules insert into per-breakpoint
26
+ `CSSStyleSheet`s whose order matches the Tailwind cascade, so
27
+ `sm:`/`md:`/`max-*`/container-query variants win in the right order
28
+ regardless of injection timing.
29
+
30
+ SSR-safe: on the server, `dynamic()` returns class names without touching the
31
+ CSSOM (and applies the build's mangle map during SSG so classes match the
32
+ mangled CSS).
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ pnpm add @csszyx/dynamic
38
+ ```
39
+
40
+ ## API
41
+
42
+ ```ts
43
+ import { dynamic, preloadManifest, cleanup, purifySz } from "@csszyx/dynamic";
44
+
45
+ // Optional: eagerly fetch the manifest at startup for zero-latency first inject
46
+ await preloadManifest("/csszyx-manifest.json");
47
+
48
+ // Untrusted input (JSON from a CMS)? Sanitize before injecting:
49
+ const cls = dynamic(purifySz(untrustedSzObject));
50
+
51
+ // Release injected sheets + manifest cache (e.g. on route teardown)
52
+ cleanup();
53
+ ```
54
+
55
+ ## React
56
+
57
+ ```tsx
58
+ import { useSz, CsszyxProvider } from "@csszyx/dynamic/react";
59
+
60
+ function FormField({ schema }) {
61
+ const { sz } = useSz(); // stable reference; manages manifest + cleanup
62
+ return <div className={sz(schema.style)}>{schema.label}</div>;
63
+ }
64
+
65
+ // Custom manifest URL (non-root deployments):
66
+ <CsszyxProvider manifest="/assets/csszyx-manifest.json">
67
+ <App />
68
+ </CsszyxProvider>;
69
+ ```
70
+
71
+ `useSz` handles manifest preloading on mount and releases the shared
72
+ stylesheets when the **last** consumer unmounts (StrictMode-safe).
73
+
74
+ ## When NOT to use this
75
+
76
+ - A finite set of styles selected by a prop → use `szv` (build-time, typed).
77
+ - Literal styles → use the `sz` prop.
78
+ - A runtime **value** inside an otherwise static rule (`bg-(--user-color)`) →
79
+ consider [`@csszyx/vars`](https://www.npmjs.com/package/@csszyx/vars) + a CSS
80
+ variable instead of generating rules per value.
81
+
82
+ Injected rules live for the session and are not individually removed — apps
83
+ that feed continuously varying values (a new arbitrary width per animation
84
+ frame) will grow the CSSOM. In development, a one-time warning fires if a
85
+ session crosses a large number of unique injected classes.
86
+
87
+ ## Documentation
88
+
89
+ <https://csszyx.com/docs/dynamic/>
90
+
91
+ ## License
92
+
93
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@csszyx/dynamic",
3
- "version": "0.10.11",
3
+ "version": "0.10.12",
4
4
  "description": "Runtime CSS injection engine for @csszyx — injects only CSS not already in the pre-built stylesheet",
5
5
  "type": "module",
6
6
  "repository": {
@@ -38,7 +38,7 @@
38
38
  "node": ">=22.12.0"
39
39
  },
40
40
  "dependencies": {
41
- "@csszyx/compiler": "0.10.11"
41
+ "@csszyx/compiler": "0.10.12"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "react": ">=17.0.0"