@pitlane/theme 0.1.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/CHANGELOG.md +22 -0
- package/LICENSE +21 -0
- package/README.md +94 -0
- package/dist/index.d.mts +722 -0
- package/dist/index.mjs +629 -0
- package/package.json +53 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# @pitlane/theme
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
Initial release.
|
|
6
|
+
|
|
7
|
+
- `createTheme(document, options?)` — takes a W3C DTCG token document and
|
|
8
|
+
returns a typed `token` accessor, a `raw` base-value lookup, and a
|
|
9
|
+
`<Theme />` component. Token paths kebab-case into CSS custom properties, and
|
|
10
|
+
each accessor leaf is a `var()` string carrying a compile-time brand naming
|
|
11
|
+
its token type.
|
|
12
|
+
- `options.modes` — per-mode `$value` overrides. `<Theme />` emits `:root`
|
|
13
|
+
plus one `@media (prefers-color-scheme: <mode>)` block per mode, using
|
|
14
|
+
`var()` indirection so aliases cascade with no JavaScript.
|
|
15
|
+
- `css()`, `tva()`, `combine()`, and `cx()` — `remix/ui`'s `css()` mixin with
|
|
16
|
+
brand enforcement, a cva-style variant resolver, variant composition, and a
|
|
17
|
+
clsx-compatible class joiner. Token-mapped properties accept only the
|
|
18
|
+
matching brand, CSS-wide keywords, a small set of property keywords, and
|
|
19
|
+
literal `0`; every other property carries csstype's value union.
|
|
20
|
+
- Full type surface exported alongside `ThemeError`: the per-type token brands,
|
|
21
|
+
`ThemedCSSProps`, `TVAProps`, and the document and configuration types.
|
|
22
|
+
- `remix@^3.0.0-beta.5` is a peer dependency.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mark Malstrom
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @pitlane/theme
|
|
2
|
+
|
|
3
|
+
Type-safe styling with W3C design tokens for [Remix 3](https://remix.run). `createTheme` takes a [DTCG token document](https://www.designtokens.org/tr/drafts/format/) and returns a typed token accessor plus a `<Theme />` component that installs the tokens as CSS custom properties. The `css`, `tva`, `combine`, and `cx` helpers wrap `remix/ui`'s `css()` mixin and enforce your palette at the type level.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @pitlane/theme
|
|
9
|
+
# or
|
|
10
|
+
vp add @pitlane/theme
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires `remix@^3.0.0-beta.5` as a peer.
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
// app/theme.ts
|
|
19
|
+
import { createTheme } from "@pitlane/theme";
|
|
20
|
+
|
|
21
|
+
export let {
|
|
22
|
+
token: t,
|
|
23
|
+
raw,
|
|
24
|
+
Theme,
|
|
25
|
+
} = createTheme(
|
|
26
|
+
{
|
|
27
|
+
color: {
|
|
28
|
+
$type: "color",
|
|
29
|
+
white: { $value: "#fff" },
|
|
30
|
+
gray: { 50: { $value: "#fafafa" }, 900: { $value: "#171717" } },
|
|
31
|
+
bg: { $value: "{color.white}" },
|
|
32
|
+
},
|
|
33
|
+
space: { $type: "dimension", sm: { $value: "8px" }, md: { $value: "16px" } },
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
modes: {
|
|
37
|
+
dark: { color: { bg: { $value: "{color.gray.900}" } } },
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Render `<Theme />` once near the root. It emits a single `<style data-pitlane-theme>` element containing `:root` plus one `@media (prefers-color-scheme: dark)` block for the override:
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import { Theme } from "./theme.ts";
|
|
47
|
+
|
|
48
|
+
function App() {
|
|
49
|
+
return () => (
|
|
50
|
+
<html lang="en">
|
|
51
|
+
<head>
|
|
52
|
+
<Theme />
|
|
53
|
+
</head>
|
|
54
|
+
<body>…</body>
|
|
55
|
+
</html>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Pass tokens to `css()` inline at each element, through the `mix` prop. Token-mapped properties accept only the matching brand, so off-palette literals fail to compile:
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import { css } from "@pitlane/theme";
|
|
64
|
+
import { t } from "./theme.ts";
|
|
65
|
+
|
|
66
|
+
<article
|
|
67
|
+
mix={css({
|
|
68
|
+
color: t.color.bg, // ✓ ColorToken
|
|
69
|
+
padding: [t.space.sm, t.space.md], // ✓ 1–4 token tuple
|
|
70
|
+
margin: 0, // ✓ literal zero
|
|
71
|
+
// color: "#ff0000", // ✗ not in the palette
|
|
72
|
+
"&:hover": { color: t.color.gray[900] },
|
|
73
|
+
})}
|
|
74
|
+
/>;
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Exports
|
|
78
|
+
|
|
79
|
+
- `createTheme(document, options?)` — returns `{ token, raw, Theme }`. `token` (conventionally `t`) mirrors the document; each leaf is a branded `var()` string. `raw(ref)` resolves the base-mode value behind a ref. `<Theme />` installs the CSS custom properties and accepts an optional `nonce`.
|
|
80
|
+
- `css(props)` — `remix/ui`'s `css()` with brand enforcement; call it inline at each `mix` callsite.
|
|
81
|
+
- `tva(config)` — a cva-style variant resolver returning a `mix`-ready descriptor.
|
|
82
|
+
- `combine(...fns)` — composes `tva` components into one.
|
|
83
|
+
- `cx(...)` — a clsx-compatible `className` joiner.
|
|
84
|
+
- `ThemeError` — thrown for invalid documents, references, or overrides.
|
|
85
|
+
- Types: `ThemeOptions`, `ThemeProps`, `ThemeResult`, `ThemeComponent`, `ThemedCSSProps`, `ThemedCSSMixin`, `TVAConfig`, `TVAProps`, `TVAFn`, `CombinedTVAFn`, `ClassValue`, `DTCGDocument`, `TokenTree`, `DeepPartialTokens`, and the per-type token brands (`ColorToken`, `DimensionToken`, `DurationToken`, and the rest).
|
|
86
|
+
|
|
87
|
+
## Links
|
|
88
|
+
|
|
89
|
+
- [Styling guide](https://pitlane.tools/guides/styling)
|
|
90
|
+
- [API reference](https://pitlane.tools/package/theme/)
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
MIT
|