@fluentic/style 0.1.0-beta.5 → 0.1.0-beta.6
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/CHANGELOG.md +14 -0
- package/README.md +105 -31
- package/atomic/className.ts +19 -2
- package/atomic/utils/hash.ts +1 -65
- package/compiler/compiler/compiler.ts +85 -8
- package/compiler/cssProp.ts +0 -14
- package/compiler/transform/cssProp/plugin.ts +33 -1
- package/compiler/transform/evaluator/evaluator.ts +1 -0
- package/compiler/transform/extract/chain/chain.ts +120 -11
- package/compiler/utils/import_source.ts +17 -7
- package/dist/{combine-Ca6LfFxv.js → combine-D0AXSTn-.js} +2 -2
- package/dist/{combine-Ca6LfFxv.js.map → combine-D0AXSTn-.js.map} +1 -1
- package/dist/compiler/index.mjs +1 -1
- package/dist/{compiler-OgDBuqfs.mjs → compiler-CCvRlaq0.mjs} +141 -89
- package/dist/compiler-CCvRlaq0.mjs.map +1 -0
- package/dist/{config-Barf8f4B.js → config-B-w6rOe0.js} +2 -2
- package/dist/{config-Barf8f4B.js.map → config-B-w6rOe0.js.map} +1 -1
- package/dist/{config-CsB4MuFI.js → config-B1WtpYar.js} +2 -2
- package/dist/{config-CsB4MuFI.js.map → config-B1WtpYar.js.map} +1 -1
- package/dist/{config-t76UljYv.js → config-CCMwA9Gm.js} +2 -2
- package/dist/{config-t76UljYv.js.map → config-CCMwA9Gm.js.map} +1 -1
- package/dist/{createTransformElement-DDqld3RF.js → createTransformElement-PCilcudP.js} +2 -2
- package/dist/{createTransformElement-DDqld3RF.js.map → createTransformElement-PCilcudP.js.map} +1 -1
- package/dist/{css-a9O5so0b.js → css-DirG7Jwu.js} +41 -7
- package/dist/css-DirG7Jwu.js.map +1 -0
- package/dist/{css-YfHN_8Nk.js → css-nmclCl2P.js} +8 -8
- package/dist/{css-YfHN_8Nk.js.map → css-nmclCl2P.js.map} +1 -1
- package/dist/{css-CZwrac6F.js → css-shX7_73D.js} +12 -41
- package/dist/css-shX7_73D.js.map +1 -0
- package/dist/css.js +1 -1
- package/dist/{data-CzHJg147.js → data-DUvixly5.js} +14 -6
- package/dist/data-DUvixly5.js.map +1 -0
- package/dist/{debug-DkrxyknP.js → debug-DJRCBKhM.js} +2 -2
- package/dist/{debug-DkrxyknP.js.map → debug-DJRCBKhM.js.map} +1 -1
- package/dist/dev/rsc.js +5 -5
- package/dist/{dev-z4laBwlS.js → dev-Cwha8aAp.js} +4 -4
- package/dist/{dev-z4laBwlS.js.map → dev-Cwha8aAp.js.map} +1 -1
- package/dist/dev.js +1 -1
- package/dist/dialect/extracted/index.js +1 -1
- package/dist/dialect/index.js +1 -1
- package/dist/{elementMarker-CqhU_l_m.js → elementMarker-Cb46vtLU.js} +3 -3
- package/dist/{elementMarker-CqhU_l_m.js.map → elementMarker-Cb46vtLU.js.map} +1 -1
- package/dist/entry/dev/adapter/preact.js +2 -2
- package/dist/entry/dev/adapter/react.js +2 -2
- package/dist/entry/dev/adapter/solid.js +2 -2
- package/dist/entry/dev/css.js +2 -2
- package/dist/entry/dev/jsx-dev-runtime.js +2 -2
- package/dist/entry/dev/jsx-runtime.js +2 -2
- package/dist/entry/dev.js +8 -8
- package/dist/entry/prod/adapter/preact.js +1 -1
- package/dist/entry/prod/adapter/react.js +1 -1
- package/dist/entry/prod/adapter/solid.js +1 -1
- package/dist/entry/prod/css.js +2 -2
- package/dist/entry/prod.js +2 -2
- package/dist/entry/rsc-dev/adapter/preact.js +5 -4
- package/dist/entry/rsc-dev/adapter/preact.js.map +1 -1
- package/dist/entry/rsc-dev/adapter/react.js +5 -4
- package/dist/entry/rsc-dev/adapter/react.js.map +1 -1
- package/dist/entry/rsc-dev/adapter/solid.js +5 -4
- package/dist/entry/rsc-dev/adapter/solid.js.map +1 -1
- package/dist/entry/rsc-dev/css.js +2 -2
- package/dist/entry/rsc-dev/dev.js +5 -6
- package/dist/entry/rsc-dev/dev.js.map +1 -1
- package/dist/entry/rsc-dev/jsx-dev-runtime.js +2 -2
- package/dist/entry/rsc-dev/jsx-runtime.js +2 -2
- package/dist/entry/rsc-dev.js +5 -5
- package/dist/entry/rsc-prod/css.js +2 -2
- package/dist/entry/rsc-prod.js +2 -2
- package/dist/{env-Db2cRt-h.js → env-0Gu2Jh47.js} +2 -39
- package/dist/env-0Gu2Jh47.js.map +1 -0
- package/dist/{utils-CLnpwhJd.js → getClassName-CHZKhmde.js} +5 -43
- package/dist/getClassName-CHZKhmde.js.map +1 -0
- package/dist/{getClassName-DaZF5nfJ.js → getClassName-CHd0iCXp.js} +3 -3
- package/dist/{getClassName-DaZF5nfJ.js.map → getClassName-CHd0iCXp.js.map} +1 -1
- package/dist/global-Dg37z0lV.js +14 -0
- package/dist/global-Dg37z0lV.js.map +1 -0
- package/dist/{hash-BOlQThNz.js → hash-Cr-LCWDt.js} +2 -40
- package/dist/hash-Cr-LCWDt.js.map +1 -0
- package/dist/index.js +6 -6
- package/dist/jsx/jsx-dev-runtime.js +1 -1
- package/dist/jsx/jsx-dev-runtime.server.js +1 -1
- package/dist/jsx/jsx-runtime.js +1 -1
- package/dist/jsx/jsx-runtime.server.js +1 -1
- package/dist/{jsx-C2pnWLcb.js → jsx-BMFC8_tA.js} +4 -4
- package/dist/{jsx-C2pnWLcb.js.map → jsx-BMFC8_tA.js.map} +1 -1
- package/dist/{jsx_runtime-XJSHujgI.js → jsx_runtime-Ch1pZ6-n.js} +2 -2
- package/dist/{jsx_runtime-XJSHujgI.js.map → jsx_runtime-Ch1pZ6-n.js.map} +1 -1
- package/dist/{loader-DHvgp0fK.mjs → loader-hNaefW-U.mjs} +13 -14
- package/dist/loader-hNaefW-U.mjs.map +1 -0
- package/dist/{misc-BuSLnvx0.mjs → misc-1OS0aeY1.mjs} +2 -2
- package/dist/{misc-BuSLnvx0.mjs.map → misc-1OS0aeY1.mjs.map} +1 -1
- package/dist/{namedTokens-D3tt-joz.js → namedTokens-mgRfd9hs.js} +3 -3
- package/dist/{namedTokens-D3tt-joz.js.map → namedTokens-mgRfd9hs.js.map} +1 -1
- package/dist/plugin/farm/index.mjs +3 -3
- package/dist/plugin/nextjs/index.mjs +120 -16
- package/dist/plugin/nextjs/index.mjs.map +1 -1
- package/dist/plugin/nextjs/loader.mjs +4 -4
- package/dist/plugin/parcel/index.cjs +1 -1
- package/dist/plugin/parcel/index.mjs +2 -2
- package/dist/plugin/parcel/optimizer.cjs +1 -1
- package/dist/plugin/parcel/optimizer.mjs +2 -2
- package/dist/plugin/parcel/resolver.cjs +1 -1
- package/dist/plugin/parcel/resolver.mjs +2 -2
- package/dist/plugin/parcel/runtime.cjs +1 -1
- package/dist/plugin/parcel/runtime.mjs +1 -1
- package/dist/plugin/parcel/transformer.cjs +1 -1
- package/dist/plugin/parcel/transformer.mjs +2 -2
- package/dist/plugin/rspack/index.mjs +2 -2
- package/dist/plugin/vite/index.mjs +3 -3
- package/dist/plugin/webpack/index.mjs +2 -2
- package/dist/plugin/webpack/loader.mjs +2 -2
- package/dist/presets/tailwind/index.js +25 -3
- package/dist/presets/tailwind/index.js.map +1 -1
- package/dist/{registry-r3BKWqpI.mjs → registry-OA0niXJL.mjs} +2 -2
- package/dist/{registry-r3BKWqpI.mjs.map → registry-OA0niXJL.mjs.map} +1 -1
- package/dist/{resolveClassNameRuntime-D5a37GNr.js → resolveClassNameRuntime-BKXT1bmR.js} +2 -2
- package/dist/{resolveClassNameRuntime-D5a37GNr.js.map → resolveClassNameRuntime-BKXT1bmR.js.map} +1 -1
- package/dist/{rules-B0_rKPfB.js → rules-DgcCENkw.js} +5 -5
- package/dist/{rules-B0_rKPfB.js.map → rules-DgcCENkw.js.map} +1 -1
- package/dist/server.js +10 -10
- package/dist/{shared-8_Msr7Q5.cjs → shared-Bc9RwNNj.cjs} +140 -88
- package/dist/shared-Bc9RwNNj.cjs.map +1 -0
- package/dist/{shared-BGO_05rW.mjs → shared-COiLPdZ1.mjs} +4 -4
- package/dist/{shared-BGO_05rW.mjs.map → shared-COiLPdZ1.mjs.map} +1 -1
- package/dist/sheet-B87QCFWF.js +7 -0
- package/dist/{sheet-BpLZIIuO.js.map → sheet-B87QCFWF.js.map} +1 -1
- package/dist/{sidecar-Bu2x35JE.mjs → sidecar-ViZUL9B8.mjs} +3 -3
- package/dist/{sidecar-Bu2x35JE.mjs.map → sidecar-ViZUL9B8.mjs.map} +1 -1
- package/dist/{styleStore-BDy5TH6N.js → styleStore-BlC8Ax9f.js} +3 -3
- package/dist/{styleStore-BDy5TH6N.js.map → styleStore-BlC8Ax9f.js.map} +1 -1
- package/dist/{styleStore-DX3z_UVK.js → styleStore-DHzH25A7.js} +2 -2
- package/dist/{styleStore-DX3z_UVK.js.map → styleStore-DHzH25A7.js.map} +1 -1
- package/dist/{token-BsW_S8fN.js → token-CAQWMtan.js} +2 -2
- package/dist/{token-BsW_S8fN.js.map → token-CAQWMtan.js.map} +1 -1
- package/dist/{trace-BdKEpgME.js → trace-D3yBmJad.js} +2 -2
- package/dist/{trace-BdKEpgME.js.map → trace-D3yBmJad.js.map} +1 -1
- package/dist/{trace-DcuMxR45.js → trace-DdXWjgAD.js} +3 -3
- package/dist/{trace-DcuMxR45.js.map → trace-DdXWjgAD.js.map} +1 -1
- package/dist/{types-BEUgXuu2.js → types-BhdAXX7z.js} +7 -7
- package/dist/{types-BEUgXuu2.js.map → types-BhdAXX7z.js.map} +1 -1
- package/dist/utils-B6HVRX10.js +42 -0
- package/dist/utils-B6HVRX10.js.map +1 -0
- package/dist/{utils-BPDxr-oc.mjs → utils-C7UalRKf.mjs} +41 -7
- package/dist/utils-C7UalRKf.mjs.map +1 -0
- package/dist/{utils-sBVZEq4u.js → utils-Cd4wqN56.js} +2 -39
- package/dist/utils-Cd4wqN56.js.map +1 -0
- package/dist/{utils-DZjLTV4D.mjs → utils-DjxH0zc7.mjs} +3 -3
- package/dist/{utils-DZjLTV4D.mjs.map → utils-DjxH0zc7.mjs.map} +1 -1
- package/dist/utils-DxCpyV2E.js +62 -0
- package/dist/utils-DxCpyV2E.js.map +1 -0
- package/dist/utils.js +2 -2
- package/dist/{webpack-DTKgR-HY.mjs → webpack-6et2ZVI6.mjs} +5 -5
- package/dist/{webpack-DTKgR-HY.mjs.map → webpack-6et2ZVI6.mjs.map} +1 -1
- package/entry/rsc_dev/adapter/preact.ts +9 -1
- package/entry/rsc_dev/adapter/react.ts +9 -1
- package/entry/rsc_dev/adapter/solid.ts +9 -1
- package/package.json +21 -11
- package/plugin/bundler/webpack/shared/loader.ts +9 -7
- package/plugin/nextjs/plugin.ts +205 -15
- package/plugin/nextjs/types.ts +1 -2
- package/plugin/nextjs/utils.ts +50 -0
- package/presets/tailwind/classname/transform.ts +32 -1
- package/runtime/adapter/utils.ts +40 -14
- package/dist/compiler-OgDBuqfs.mjs.map +0 -1
- package/dist/css-CZwrac6F.js.map +0 -1
- package/dist/css-a9O5so0b.js.map +0 -1
- package/dist/css_extra-CXXZAylc.js +0 -8
- package/dist/css_extra-CXXZAylc.js.map +0 -1
- package/dist/data-CzHJg147.js.map +0 -1
- package/dist/env-Db2cRt-h.js.map +0 -1
- package/dist/getClassName-DKtQl5ZX.js +0 -32
- package/dist/getClassName-DKtQl5ZX.js.map +0 -1
- package/dist/global-zYTvWskP.js +0 -10
- package/dist/global-zYTvWskP.js.map +0 -1
- package/dist/hash-BOlQThNz.js.map +0 -1
- package/dist/loader-DHvgp0fK.mjs.map +0 -1
- package/dist/shared-8_Msr7Q5.cjs.map +0 -1
- package/dist/sheet-BpLZIIuO.js +0 -7
- package/dist/utils-BPDxr-oc.mjs.map +0 -1
- package/dist/utils-CLnpwhJd.js.map +0 -1
- package/dist/utils-okFWrQsg.js +0 -41
- package/dist/utils-okFWrQsg.js.map +0 -1
- package/dist/utils-sBVZEq4u.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @fluentic/style
|
|
2
2
|
|
|
3
|
+
## 0.1.0-beta.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2bff82f: Improve css-prop adapters, class-name extraction, and Next.js build stability.
|
|
8
|
+
|
|
9
|
+
- Preserve normal JSX prop precedence when compiling intrinsic `css` props through React, Preact, and Solid adapters.
|
|
10
|
+
- Keep React `key` props outside generated css-prop spreads so list identity is preserved.
|
|
11
|
+
- Improve React Server Component development handling for css-prop adapter imports, including client components.
|
|
12
|
+
- Make class-name extraction produce stable debug hashes and better source locations for class-name utilities.
|
|
13
|
+
- Add Tailwind class-name support for arbitrary text values such as `text-[13px]`, `text-[length:13px]`, and `text-[color:purple]`.
|
|
14
|
+
- Improve Next.js integration for dev CSS delivery, Turbopack loader options, and production CSS precollection.
|
|
15
|
+
- Add default export conditions for common package entry points.
|
|
16
|
+
|
|
3
17
|
## 0.1.0-beta.5
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
# Fluentic Style
|
|
2
2
|
|
|
3
|
-
Build your own styling language on top of a stable
|
|
3
|
+
Build your own styling language on top of a stable component styling model.
|
|
4
4
|
|
|
5
|
-
Styling
|
|
5
|
+
Styling UI apps has a lot of good answers already: CSS files, utility classes,
|
|
6
6
|
CSS-in-JS, compiled CSS, design tokens, and component libraries. Fluentic
|
|
7
7
|
explores a specific question inside that space: what if styles composed around
|
|
8
|
-
components the same way props and
|
|
9
|
-
|
|
10
|
-
With Fluentic, you start simple with type-safe `style(...)` and
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
components the same way props, state, and themes do?
|
|
9
|
+
|
|
10
|
+
With Fluentic, you start simple with type-safe `style(...)` values and attach
|
|
11
|
+
them through a JSX `css` prop or a framework adapter. React, Preact, and SolidJS
|
|
12
|
+
are supported today, with the core style data model designed to keep expanding
|
|
13
|
+
across JSX runtimes, compiler-backed frameworks, and server-rendered UI stacks.
|
|
14
|
+
If your team prefers utility class names, you can also create class-name style
|
|
15
|
+
chains, including a Tailwind-like preset.
|
|
16
|
+
|
|
17
|
+
When a component needs variants, themes, nested parts, or consumer overrides,
|
|
18
|
+
add slots, scopes, tokens, values, and `combineStyle(...)` so those styles stay
|
|
19
|
+
organized around the component instead of leaking through class names or private
|
|
20
|
+
DOM structure. For production builds, Fluentic extracts static styles into
|
|
21
|
+
atomic CSS output while dynamic values from props, state, signals, or request
|
|
22
|
+
data still work at runtime.
|
|
19
23
|
|
|
20
24
|
[Docs](https://fluenticstack.com/style) |
|
|
21
|
-
[
|
|
25
|
+
[Start here](https://fluenticstack.com/style/docs/learn/start-here/) |
|
|
22
26
|
[Playground](https://fluenticstack.com/style/playground/) |
|
|
23
27
|
[npm](https://www.npmjs.com/package/@fluentic/style)
|
|
24
28
|
|
|
@@ -36,13 +40,35 @@ Or with pnpm:
|
|
|
36
40
|
pnpm add @fluentic/style@beta
|
|
37
41
|
```
|
|
38
42
|
|
|
39
|
-
Use Fluentic in a JSX app. Add a bundler plugin
|
|
40
|
-
extraction.
|
|
43
|
+
Use Fluentic in a JSX app. Add a bundler or framework plugin when you want
|
|
44
|
+
production extraction.
|
|
45
|
+
|
|
46
|
+
## What Fluentic Supports
|
|
47
|
+
|
|
48
|
+
Fluentic is not tied to one styling vocabulary or one framework runtime. The
|
|
49
|
+
same style model powers CSS-like objects, custom design-system fields,
|
|
50
|
+
Tailwind-like object fields, class-name chains, slots, scopes, themes, tokens,
|
|
51
|
+
runtime values, static extraction, and development traces.
|
|
52
|
+
|
|
53
|
+
| Area | Support |
|
|
54
|
+
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
55
|
+
| Core styling model | [`style(...)`](https://fluenticstack.com/style/docs/reference/style/), [`style.slot(...)`](https://fluenticstack.com/style/docs/reference/style-slot/), [`style.scope(...)`](https://fluenticstack.com/style/docs/reference/style-scope/), [`combineStyle(...)`](https://fluenticstack.com/style/docs/reference/combine-style/), themes, tokens, values, selectors, at-rules, keyframes, and font faces. |
|
|
56
|
+
| Authoring vocabularies | CSS-like object styles, custom style functions, custom selectors, custom properties, Tailwind-like object fields, and Tailwind-like class-name chains. |
|
|
57
|
+
| Runtime paths | Runtime-only JSX setup for quick adoption, compiler-backed extracted runtime for production, and framework css-prop adapters that keep the framework's normal JSX transform. |
|
|
58
|
+
| Frameworks today | React, Next.js App Router, Preact, and SolidJS. |
|
|
59
|
+
| Bundlers today | Vite, Webpack, Rspack, Farm, Parcel 2, Babel/custom compiler use, and the Next.js integration for App Router projects. |
|
|
60
|
+
| Development tools | Readable debug class names, source traces, JSX element markers, sourcemaps, priority inspection, and React Server Component development support for Next.js. |
|
|
61
|
+
|
|
62
|
+
See the [integration overview](https://fluenticstack.com/style/docs/integrations/overview/)
|
|
63
|
+
for setup guides and the
|
|
64
|
+
[reference overview](https://fluenticstack.com/style/docs/reference/overview/)
|
|
65
|
+
for the API surface.
|
|
41
66
|
|
|
42
67
|
## Configure Runtime JSX
|
|
43
68
|
|
|
44
69
|
Enable the runtime JSX import source so DOM and SVG elements accept the `css`
|
|
45
|
-
prop. This path works without a Fluentic bundler plugin
|
|
70
|
+
prop. This path works without a Fluentic bundler plugin and is the quickest
|
|
71
|
+
React setup path.
|
|
46
72
|
|
|
47
73
|
```jsonc
|
|
48
74
|
/* tsconfig.json */
|
|
@@ -54,10 +80,14 @@ prop. This path works without a Fluentic bundler plugin.
|
|
|
54
80
|
}
|
|
55
81
|
```
|
|
56
82
|
|
|
83
|
+
For SolidJS and Preact, keep the framework's normal JSX configuration and use
|
|
84
|
+
the Vite css-prop adapter instead:
|
|
85
|
+
[SolidJS](https://fluenticstack.com/style/docs/integrations/solidjs/) and
|
|
86
|
+
[PreactJS](https://fluenticstack.com/style/docs/integrations/preact/).
|
|
87
|
+
|
|
57
88
|
## Why Another Style Library?
|
|
58
89
|
|
|
59
|
-
Component
|
|
60
|
-
need:
|
|
90
|
+
Component systems need more than a way to attach styles to elements. They need:
|
|
61
91
|
|
|
62
92
|
- base styles owned by the component;
|
|
63
93
|
- state styles for hover, focus, active, disabled, media, and container queries;
|
|
@@ -99,8 +129,9 @@ export function Card() {
|
|
|
99
129
|
}
|
|
100
130
|
```
|
|
101
131
|
|
|
102
|
-
That is the smallest version of Fluentic Style: type-safe styles, selectors,
|
|
103
|
-
a
|
|
132
|
+
That is the smallest version of Fluentic Style: type-safe styles, selectors,
|
|
133
|
+
and a component-owned style value attached to JSX. The example uses React-style
|
|
134
|
+
syntax, but the same style data can be lowered through framework adapters.
|
|
104
135
|
|
|
105
136
|
## Class Name Chains
|
|
106
137
|
|
|
@@ -147,7 +178,11 @@ for the built-in Tailwind-like class-name vocabulary.
|
|
|
147
178
|
|
|
148
179
|
## Scale Into Components
|
|
149
180
|
|
|
150
|
-
When a component becomes reusable, give its styles component structure.
|
|
181
|
+
When a component becomes reusable, give its styles component structure. This
|
|
182
|
+
section uses React component types for the example, but the important part is
|
|
183
|
+
the framework-independent style model: slots name public styling targets, scopes
|
|
184
|
+
describe changes to those targets, and the component decides where resolved
|
|
185
|
+
styles attach.
|
|
151
186
|
|
|
152
187
|
```tsx
|
|
153
188
|
/* tokens.ts */
|
|
@@ -330,15 +365,24 @@ priority with layers or sorted output.
|
|
|
330
365
|
|
|
331
366
|
## Add Production Extraction
|
|
332
367
|
|
|
333
|
-
Fluentic Style works without a compiler. In runtime mode, the JSX `css`
|
|
334
|
-
resolves class names and inserts atomic CSS rules as needed.
|
|
368
|
+
Fluentic Style works without a compiler. In runtime-only mode, the JSX `css`
|
|
369
|
+
prop resolves class names and inserts atomic CSS rules as needed. That is useful
|
|
370
|
+
for trying the API, custom environments, and incremental adoption.
|
|
371
|
+
|
|
372
|
+
For production builds, add a bundler or framework plugin. Static styles are
|
|
373
|
+
extracted into ordered atomic CSS output. Runtime composition stays available
|
|
374
|
+
for values that still depend on props, state, signals, request data, user input,
|
|
375
|
+
or incoming themes.
|
|
376
|
+
|
|
377
|
+
There are two integration shapes:
|
|
335
378
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
379
|
+
- React apps can use Fluentic's JSX runtime import source, switching from
|
|
380
|
+
`@fluentic/style/jsx` to `@fluentic/style/plugin/jsx` after adding a plugin.
|
|
381
|
+
- React, Preact, and SolidJS can also use a compiler css-prop adapter, letting
|
|
382
|
+
the framework keep its normal JSX runtime while Fluentic compiles
|
|
383
|
+
`css={...}` before the framework JSX transform runs.
|
|
339
384
|
|
|
340
|
-
|
|
341
|
-
`@fluentic/style/jsx` to `@fluentic/style/plugin/jsx`.
|
|
385
|
+
The React JSX-runtime setup looks like this:
|
|
342
386
|
|
|
343
387
|
```jsonc
|
|
344
388
|
/* tsconfig.json */
|
|
@@ -370,8 +414,38 @@ export default defineConfig({
|
|
|
370
414
|
development sourcemaps, and extracted CSS output. See
|
|
371
415
|
[Plugin Options](https://fluenticstack.com/style/docs/reference/plugin-options/).
|
|
372
416
|
|
|
373
|
-
|
|
374
|
-
|
|
417
|
+
The framework-adapter setup passes a css-prop preset to the plugin. This is the
|
|
418
|
+
normal path for SolidJS and Preact, and an optional path for React:
|
|
419
|
+
|
|
420
|
+
```ts
|
|
421
|
+
/* vite.config.ts */
|
|
422
|
+
import { CssPropPresets, plugin as stylePlugin } from '@fluentic/style/plugin/vite';
|
|
423
|
+
import { defineConfig } from 'vite';
|
|
424
|
+
|
|
425
|
+
export default defineConfig({
|
|
426
|
+
plugins: [
|
|
427
|
+
stylePlugin({
|
|
428
|
+
cssProp: CssPropPresets.Solid,
|
|
429
|
+
}),
|
|
430
|
+
// then the framework JSX plugin, such as vite-plugin-solid
|
|
431
|
+
],
|
|
432
|
+
});
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
For framework and bundler-specific setup, see:
|
|
436
|
+
|
|
437
|
+
| Environment | Guide |
|
|
438
|
+
| -------------------------- | ----------------------------------------------------------------------------------------- |
|
|
439
|
+
| Next.js App Router | [Next.js](https://fluenticstack.com/style/docs/integrations/nextjs/) |
|
|
440
|
+
| Vite + React | [Vite](https://fluenticstack.com/style/docs/integrations/vite/) |
|
|
441
|
+
| Vite + SolidJS | [SolidJS](https://fluenticstack.com/style/docs/integrations/solidjs/) |
|
|
442
|
+
| Vite + Preact | [PreactJS](https://fluenticstack.com/style/docs/integrations/preact/) |
|
|
443
|
+
| Webpack | [Webpack](https://fluenticstack.com/style/docs/integrations/webpack/) |
|
|
444
|
+
| Rspack | [Rspack](https://fluenticstack.com/style/docs/integrations/rspack/) |
|
|
445
|
+
| Farm | [Farm](https://fluenticstack.com/style/docs/integrations/farm/) |
|
|
446
|
+
| Parcel 2 | [Parcel](https://fluenticstack.com/style/docs/integrations/parcel/) |
|
|
447
|
+
| Runtime-only | [Runtime-Only Mode](https://fluenticstack.com/style/docs/integrations/runtime-only-mode/) |
|
|
448
|
+
| Custom compiler or bundler | [Custom Compiler](https://fluenticstack.com/style/docs/integrations/custom-compiler/) |
|
|
375
449
|
|
|
376
450
|
## Benchmarks
|
|
377
451
|
|
package/atomic/className.ts
CHANGED
|
@@ -81,8 +81,25 @@ export function getAtomicClassName(
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
function getRuntimeClassNameHashLength(debugClassName: boolean) {
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
return getClassNameHashLength({
|
|
85
|
+
debugClassName,
|
|
86
|
+
isDev: DEV_CONFIG.isDev,
|
|
87
|
+
devHashLength: DEV_CONFIG.hashLength,
|
|
88
|
+
cssHashLength: CSS_CONFIG.hashLength,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function getClassNameHashLength(options: {
|
|
93
|
+
debugClassName: boolean;
|
|
94
|
+
isDev: boolean;
|
|
95
|
+
devHashLength?: number | null;
|
|
96
|
+
cssHashLength?: number | null;
|
|
97
|
+
}) {
|
|
98
|
+
if (options.debugClassName && options.isDev) {
|
|
99
|
+
return options.devHashLength ?? options.cssHashLength ?? 3;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return options.cssHashLength ?? 7;
|
|
86
103
|
}
|
|
87
104
|
|
|
88
105
|
export function getClassNameDedupe(
|
package/atomic/utils/hash.ts
CHANGED
|
@@ -1,72 +1,8 @@
|
|
|
1
|
-
import { globalData } from '../../utils/global';
|
|
2
1
|
import { hashString, normalizeHashLength } from '../../utils/hash';
|
|
3
2
|
|
|
4
|
-
type PooledHashState = {
|
|
5
|
-
byValue: Map<string, string>;
|
|
6
|
-
byHash: Map<string, string>;
|
|
7
|
-
usedByLength: number[];
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const POOLED_HASH_STATE = globalData<PooledHashState>(
|
|
11
|
-
'atomic.hashPool',
|
|
12
|
-
() => ({
|
|
13
|
-
byValue: new Map(),
|
|
14
|
-
byHash: new Map(),
|
|
15
|
-
usedByLength: [],
|
|
16
|
-
}),
|
|
17
|
-
);
|
|
18
|
-
|
|
19
3
|
export function getIdentifierSafeHash(value: string, startLength = 7) {
|
|
20
|
-
return getPooledHash(value, startLength);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function getPooledHash(value: string, startLength: number) {
|
|
24
4
|
const normalizedStartLength = normalizeHashLength(startLength);
|
|
25
|
-
|
|
26
|
-
const existing = POOLED_HASH_STATE.byValue.get(valueKey);
|
|
27
|
-
if (existing) return existing;
|
|
28
|
-
|
|
29
|
-
let length = normalizedStartLength;
|
|
30
|
-
|
|
31
|
-
while (true) {
|
|
32
|
-
if (getPooledHashUsedCount(length) >= getIdentifierSafeHashPoolSize(length)) {
|
|
33
|
-
length++;
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
for (let index = 0; index < getIdentifierSafeHashPoolSize(length); index++) {
|
|
38
|
-
const hash = getPooledHashCandidate(value, length, index);
|
|
39
|
-
const owner = POOLED_HASH_STATE.byHash.get(hash);
|
|
40
|
-
|
|
41
|
-
if (owner !== undefined && owner !== valueKey) continue;
|
|
42
|
-
|
|
43
|
-
POOLED_HASH_STATE.byValue.set(valueKey, hash);
|
|
44
|
-
POOLED_HASH_STATE.byHash.set(hash, valueKey);
|
|
45
|
-
POOLED_HASH_STATE.usedByLength[length] = getPooledHashUsedCount(length) + 1;
|
|
46
|
-
return hash;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
length++;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function getPooledHashCandidate(
|
|
54
|
-
value: string,
|
|
55
|
-
length: number,
|
|
56
|
-
index: number,
|
|
57
|
-
) {
|
|
58
|
-
const hashValue = index === 0 ? value : value + '::' + index;
|
|
59
|
-
return getIdentifierSafeHashValue(hashString(hashValue)).slice(0, length);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function getPooledHashUsedCount(length: number) {
|
|
63
|
-
return POOLED_HASH_STATE.usedByLength[length] ?? 0;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function getIdentifierSafeHashPoolSize(length: number) {
|
|
67
|
-
if (length <= 0) return 0;
|
|
68
|
-
|
|
69
|
-
return 26 * 36 ** (length - 1);
|
|
5
|
+
return getIdentifierSafeHashValue(hashString(value)).slice(0, normalizedStartLength);
|
|
70
6
|
}
|
|
71
7
|
|
|
72
8
|
function getIdentifierSafeHashValue(hash: string) {
|
|
@@ -48,6 +48,7 @@ export function createCompiler(args: CompilerArgs, options: CompilerOptions) {
|
|
|
48
48
|
return rewriteTransformResult(
|
|
49
49
|
transformDebug(internal, args, { tracer }),
|
|
50
50
|
internal.runtimeMode,
|
|
51
|
+
args.code,
|
|
51
52
|
);
|
|
52
53
|
};
|
|
53
54
|
|
|
@@ -55,6 +56,7 @@ export function createCompiler(args: CompilerArgs, options: CompilerOptions) {
|
|
|
55
56
|
const debugResult = rewriteTransformResult(
|
|
56
57
|
transformDebug(internal, args, { tracer }),
|
|
57
58
|
internal.runtimeMode,
|
|
59
|
+
args.code,
|
|
58
60
|
);
|
|
59
61
|
if (!debugResult) return null;
|
|
60
62
|
|
|
@@ -99,7 +101,7 @@ export function createCompiler(args: CompilerArgs, options: CompilerOptions) {
|
|
|
99
101
|
return rewriteTransformResult({
|
|
100
102
|
...result,
|
|
101
103
|
rules: collector.getItems().slice(startIndex),
|
|
102
|
-
}, internal.runtimeMode);
|
|
104
|
+
}, internal.runtimeMode, args.code);
|
|
103
105
|
};
|
|
104
106
|
|
|
105
107
|
const getExtractedCss = () => {
|
|
@@ -140,27 +142,46 @@ function createCompilerInternal(args: CompilerArgs, options: CompilerOptions) {
|
|
|
140
142
|
function rewriteTransformResult<Result extends { code: string; }>(
|
|
141
143
|
result: Result | null,
|
|
142
144
|
runtimeMode: CompilerRuntimeMode | null,
|
|
145
|
+
sourceCode: string,
|
|
143
146
|
) {
|
|
144
147
|
if (!result || !runtimeMode) return result;
|
|
145
148
|
|
|
146
149
|
return {
|
|
147
150
|
...result,
|
|
148
|
-
code: rewriteCompilerRuntimeImports(result.code, runtimeMode),
|
|
151
|
+
code: rewriteCompilerRuntimeImports(result.code, runtimeMode, sourceCode),
|
|
149
152
|
};
|
|
150
153
|
}
|
|
151
154
|
|
|
152
|
-
function rewriteCompilerRuntimeImports(
|
|
155
|
+
function rewriteCompilerRuntimeImports(
|
|
156
|
+
code: string,
|
|
157
|
+
runtimeMode: CompilerRuntimeMode,
|
|
158
|
+
sourceCode: string,
|
|
159
|
+
) {
|
|
160
|
+
const importRuntimeMode = getImportRuntimeMode(runtimeMode, sourceCode);
|
|
161
|
+
|
|
153
162
|
return rewriteImportSources(
|
|
154
163
|
code,
|
|
155
|
-
(source) => getCompilerRuntimeImportSource(source, runtimeMode),
|
|
164
|
+
(source) => getCompilerRuntimeImportSource(source, runtimeMode, importRuntimeMode),
|
|
156
165
|
);
|
|
157
166
|
}
|
|
158
167
|
|
|
159
|
-
function
|
|
160
|
-
if (
|
|
161
|
-
|
|
168
|
+
function getImportRuntimeMode(runtimeMode: CompilerRuntimeMode, sourceCode: string) {
|
|
169
|
+
if (runtimeMode === CompilerRuntimeMode.RscDev && hasUseClientDirective(sourceCode)) {
|
|
170
|
+
return CompilerRuntimeMode.Dev;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return runtimeMode;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function getCompilerRuntimeImportSource(
|
|
177
|
+
source: string,
|
|
178
|
+
runtimeMode: CompilerRuntimeMode,
|
|
179
|
+
importRuntimeMode: CompilerRuntimeMode,
|
|
180
|
+
) {
|
|
181
|
+
if (source === STYLE_IMPORT_PATH) return getStyleRuntimeImportPath(importRuntimeMode);
|
|
182
|
+
const adapterImportPath = getStyleRuntimeAdapterImportPath(source, importRuntimeMode);
|
|
162
183
|
if (adapterImportPath) return adapterImportPath;
|
|
163
|
-
if (source === STYLE_CSS_IMPORT_PATH) return getStyleRuntimeCssImportPath(
|
|
184
|
+
if (source === STYLE_CSS_IMPORT_PATH) return getStyleRuntimeCssImportPath(importRuntimeMode);
|
|
164
185
|
if (source === STYLE_EXTRACT_RUNTIME_IMPORT_PATH) return getStyleExtractRuntimeImportPath(runtimeMode);
|
|
165
186
|
if (runtimeMode === CompilerRuntimeMode.RscDev && source === STYLE_DEV_RSC_IMPORT_PATH) {
|
|
166
187
|
return getStyleRuntimeDevRscImportPath(runtimeMode);
|
|
@@ -168,3 +189,59 @@ function getCompilerRuntimeImportSource(source: string, runtimeMode: CompilerRun
|
|
|
168
189
|
|
|
169
190
|
return null;
|
|
170
191
|
}
|
|
192
|
+
|
|
193
|
+
function hasUseClientDirective(code: string) {
|
|
194
|
+
let index = 0;
|
|
195
|
+
|
|
196
|
+
while (index < code.length) {
|
|
197
|
+
index = skipWhitespaceAndComments(code, index);
|
|
198
|
+
|
|
199
|
+
const quote = code[index];
|
|
200
|
+
if (quote !== '"' && quote !== "'") return false;
|
|
201
|
+
|
|
202
|
+
const end = code.indexOf(quote, index + 1);
|
|
203
|
+
if (end < 0) return false;
|
|
204
|
+
|
|
205
|
+
const directive = code.slice(index + 1, end);
|
|
206
|
+
index = skipWhitespaceAndComments(code, end + 1);
|
|
207
|
+
|
|
208
|
+
if (code[index] === ';') {
|
|
209
|
+
index += 1;
|
|
210
|
+
} else if (code[index] && code[index] !== '\n' && code[index] !== '\r') {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (directive === 'use client') return true;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function skipWhitespaceAndComments(code: string, index: number) {
|
|
221
|
+
let next = index;
|
|
222
|
+
|
|
223
|
+
while (next < code.length) {
|
|
224
|
+
const char = code[next];
|
|
225
|
+
|
|
226
|
+
if (char === ' ' || char === '\t' || char === '\n' || char === '\r') {
|
|
227
|
+
next += 1;
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (char === '/' && code[next + 1] === '/') {
|
|
232
|
+
const lineEnd = code.indexOf('\n', next + 2);
|
|
233
|
+
next = lineEnd < 0 ? code.length : lineEnd + 1;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (char === '/' && code[next + 1] === '*') {
|
|
238
|
+
const commentEnd = code.indexOf('*/', next + 2);
|
|
239
|
+
next = commentEnd < 0 ? code.length : commentEnd + 2;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return next;
|
|
247
|
+
}
|
package/compiler/cssProp.ts
CHANGED
|
@@ -1,30 +1,16 @@
|
|
|
1
|
-
export type CompilerCssPropStyleMode = 'react' | 'solid';
|
|
2
|
-
|
|
3
1
|
export type CompilerCssPropOptions = {
|
|
4
|
-
classProp: 'class' | 'className';
|
|
5
|
-
styleProp: 'style';
|
|
6
|
-
styleMode: CompilerCssPropStyleMode;
|
|
7
2
|
adapter: string;
|
|
8
3
|
};
|
|
9
4
|
|
|
10
5
|
const CssPropSolid: CompilerCssPropOptions = {
|
|
11
|
-
classProp: 'class',
|
|
12
|
-
styleProp: 'style',
|
|
13
|
-
styleMode: 'solid',
|
|
14
6
|
adapter: '@fluentic/style/adapter/solid',
|
|
15
7
|
};
|
|
16
8
|
|
|
17
9
|
const CssPropPreact: CompilerCssPropOptions = {
|
|
18
|
-
classProp: 'class',
|
|
19
|
-
styleProp: 'style',
|
|
20
|
-
styleMode: 'react',
|
|
21
10
|
adapter: '@fluentic/style/adapter/preact',
|
|
22
11
|
};
|
|
23
12
|
|
|
24
13
|
const CssPropReact: CompilerCssPropOptions = {
|
|
25
|
-
classProp: 'className',
|
|
26
|
-
styleProp: 'style',
|
|
27
|
-
styleMode: 'react',
|
|
28
14
|
adapter: '@fluentic/style/adapter/react',
|
|
29
15
|
};
|
|
30
16
|
|
|
@@ -45,14 +45,21 @@ export function createCssPropPlugin(args: PluginArgs) {
|
|
|
45
45
|
},
|
|
46
46
|
|
|
47
47
|
JSXOpeningElement(path: NodePath<BabelTypes.JSXOpeningElement>, state: PluginState) {
|
|
48
|
+
const keyHoistedAttributes = hoistKeyAttributes(path.node.attributes);
|
|
49
|
+
if (keyHoistedAttributes) path.node.attributes = keyHoistedAttributes;
|
|
50
|
+
|
|
48
51
|
const options = getCssPropOptions(state.options);
|
|
49
52
|
if (!options || !state.mergeId) return;
|
|
50
53
|
if (!isIntrinsicElement(path.node.name)) return;
|
|
51
54
|
if (!hasCssAttribute(path.node.attributes)) return;
|
|
52
55
|
|
|
53
|
-
const
|
|
56
|
+
const keyAttributes = path.node.attributes.filter(isKeyAttribute);
|
|
57
|
+
const parts = path.node.attributes
|
|
58
|
+
.filter((attr) => !isKeyAttribute(attr))
|
|
59
|
+
.map((attr) => buildPart(t, attr));
|
|
54
60
|
|
|
55
61
|
path.node.attributes = [
|
|
62
|
+
...keyAttributes,
|
|
56
63
|
t.jsxSpreadAttribute(t.callExpression(state.mergeId, [
|
|
57
64
|
t.arrayExpression(parts),
|
|
58
65
|
])),
|
|
@@ -81,6 +88,31 @@ function hasCssAttribute(attrs: readonly (BabelTypes.JSXAttribute | BabelTypes.J
|
|
|
81
88
|
});
|
|
82
89
|
}
|
|
83
90
|
|
|
91
|
+
function hoistKeyAttributes(
|
|
92
|
+
attrs: readonly (BabelTypes.JSXAttribute | BabelTypes.JSXSpreadAttribute)[],
|
|
93
|
+
) {
|
|
94
|
+
const keyAttributes = attrs.filter(isKeyAttribute);
|
|
95
|
+
if (!keyAttributes.length) return null;
|
|
96
|
+
|
|
97
|
+
const firstKeyIndex = attrs.findIndex(isKeyAttribute);
|
|
98
|
+
const firstSpreadIndex = attrs.findIndex((attr) => attr.type === 'JSXSpreadAttribute');
|
|
99
|
+
|
|
100
|
+
if (firstSpreadIndex < 0 || firstKeyIndex < firstSpreadIndex) return null;
|
|
101
|
+
|
|
102
|
+
return [
|
|
103
|
+
...keyAttributes,
|
|
104
|
+
...attrs.filter((attr) => !isKeyAttribute(attr)),
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function isKeyAttribute(
|
|
109
|
+
attr: BabelTypes.JSXAttribute | BabelTypes.JSXSpreadAttribute,
|
|
110
|
+
) {
|
|
111
|
+
return attr.type === 'JSXAttribute' &&
|
|
112
|
+
attr.name.type === 'JSXIdentifier' &&
|
|
113
|
+
attr.name.name === 'key';
|
|
114
|
+
}
|
|
115
|
+
|
|
84
116
|
function buildPart(
|
|
85
117
|
t: typeof BabelTypes,
|
|
86
118
|
attr: BabelTypes.JSXAttribute | BabelTypes.JSXSpreadAttribute,
|