@zappie/tokens 0.1.0 → 0.1.1
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 +18 -0
- package/README.md +36 -94
- package/package.json +3 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @zappie/tokens
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1e6f420: Each package now has a README written for people installing it from npm: what it does, how to install and use it, its entry points, and links to docs.zappie.ai. `@zappie/kit` gains its first README.
|
|
8
|
+
|
|
9
|
+
## 0.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- - `@zappie/tokens`: Publish the semantic storefront token contract, CSS aliases, validation and compilation tools.
|
|
14
|
+
- `@zappie/sdk`: Publish the framework-agnostic storefront client and its React, server, checkout, customer, places, visits and URL entries.
|
|
15
|
+
- `@zappie/foundations`: Publish accessible, unstyled React primitives for storefront catalogue, item, fulfilment and cart experiences.
|
|
16
|
+
- `@zappie/theme-base`: Publish the reusable base storefront theme and its catalogue, item and cart surfaces.
|
|
17
|
+
- `@zappie/kit`: Publish the built component registry consumed by the Zappie CLI.
|
|
18
|
+
- `zappie`: Publish the component CLI with `add`, `list` and `diff`.
|
package/README.md
CHANGED
|
@@ -1,93 +1,54 @@
|
|
|
1
1
|
# @zappie/tokens
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The design tokens Zappie storefronts are styled with. A theme sets a closed list of `--z-*` CSS custom properties for colour, type, spacing, radius and motion. Every Zappie component reads only these, so one theme restyles all of them. The package has no runtime dependencies and doesn't touch the DOM.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { DEFAULT_THEME, TOKEN_NAMES, type ThemeJson } from '@zappie/tokens';
|
|
9
|
-
import { validateTheme, contrastRatio } from '@zappie/tokens/validate';
|
|
10
|
-
import { compileTheme, resolveTokens } from '@zappie/tokens/compile';
|
|
11
|
-
import { toCheckoutTheme } from '@zappie/tokens/checkout';
|
|
5
|
+
```sh
|
|
6
|
+
npm install @zappie/tokens
|
|
12
7
|
```
|
|
13
8
|
|
|
14
|
-
|
|
9
|
+
## Use it
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
@import '@zappie/tokens/tokens.css';
|
|
18
|
-
/* In a Tailwind v4 stylesheet, after importing Tailwind: */
|
|
19
|
-
@import '@zappie/tokens/tailwind.css';
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
The default CSS is below **3,000 bytes uncompressed**. Tailwind aliases include `bg-z-surface`, `text-z-muted`, `rounded-z-md`, `p-z-4`, `font-z-display`, `text-z-lg`, `ease-z-out` and `duration-z-base`. Importing aliases alone does not assign runtime token values; also import the default CSS or supply compiled theme CSS.
|
|
11
|
+
Load the default tokens once, then style your own components with them:
|
|
23
12
|
|
|
24
|
-
|
|
13
|
+
```css
|
|
14
|
+
@import "@zappie/tokens/tokens.css";
|
|
25
15
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
tokens: {
|
|
31
|
-
'--z-bg': '#fff',
|
|
32
|
-
'--z-text': '#101828',
|
|
33
|
-
'--z-accent': '#9FE870',
|
|
34
|
-
'--z-accent-contrast': '#163300',
|
|
35
|
-
},
|
|
36
|
-
logo: { light: '/logo.svg', alt: 'My store' },
|
|
37
|
-
fonts: [{ family: 'Inter', source: 'google', role: 'body', weights: [400, 700] }],
|
|
38
|
-
};
|
|
39
|
-
const result = validateTheme(theme);
|
|
40
|
-
if (!result.ok) console.error(result.issues);
|
|
41
|
-
else {
|
|
42
|
-
console.warn(result.warnings);
|
|
43
|
-
const css = compileTheme(result.theme, { scope: '[data-zappie-theme="store"]' });
|
|
44
|
-
// Install css using your framework's stylesheet pipeline.
|
|
16
|
+
.button {
|
|
17
|
+
background: var(--z-accent);
|
|
18
|
+
color: var(--z-accent-contrast);
|
|
19
|
+
border-radius: var(--z-radius-md);
|
|
45
20
|
}
|
|
46
21
|
```
|
|
47
22
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
Colors support hex (3/4/6/8 digits), named colors, `rgb()/rgba()`, `hsl()/hsla()` and `oklch()` converted to sRGB. Context-dependent colors (`var()`, `currentColor`) and injection syntax are rejected. Lengths support nonnegative px/rem/em/%/dvh/vh/vw, unitless zero, nested min/max/clamp, and calc with whitespace-separated addition/subtraction. Multiplication, division and variable references are outside this contract. Font families are unquoted comma-separated names, excluding CSS-wide keywords such as `inherit`; font declarations take one family each. Font roles must be unique, with at most three declarations. Self-hosted fonts require an HTTPS `.woff2` URL. Logo assets accept HTTPS or relative paths, with required alternative text.
|
|
51
|
-
|
|
52
|
-
`darkMode` defaults to `light`. `dark` inherits the theme's light values. An explicit dark choice on the root, `data-theme="dark"` or the `.dark` class the host and Tailwind use, applies the overrides in `light` and `auto`. Only `auto` also follows `prefers-color-scheme`, unless the root has `data-theme="light"`; `light` ignores the OS so a merchant's colours aren't decided by the visitor's system. `dark` is always dark. Scope accepts `:root`, one class/id, or one double-quoted data attribute selector. Google imports precede rules; self-hosted fonts emit `@font-face`. Font declarations apply globally even with scoped tokens. A declared font leads its role's token stack, keeping the theme's own stack as the fallback. Compilation validates its input and throws on errors.
|
|
53
|
-
|
|
54
|
-
`motion.reduce: true` zeros all duration tokens. Compiled themes always also honor `prefers-reduced-motion`. Components must consume those durations for the preference to affect their animations.
|
|
55
|
-
|
|
56
|
-
## Checkout projection
|
|
23
|
+
A theme is JSON. Check an untrusted theme before you use it, then compile it to CSS:
|
|
57
24
|
|
|
58
25
|
```ts
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
origin: 'https://shop.example', // Makes a relative logo absolute.
|
|
62
|
-
copy: { payButton: 'Pay now', successTitle: 'Thank you' },
|
|
63
|
-
onWarning: issue => console.warn(issue.message),
|
|
64
|
-
});
|
|
65
|
-
```
|
|
26
|
+
import { validateTheme } from "@zappie/tokens/validate";
|
|
27
|
+
import { compileTheme } from "@zappie/tokens/compile";
|
|
66
28
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
```ts
|
|
74
|
-
import Ajv2020 from 'ajv/dist/2020.js';
|
|
75
|
-
import schema from '@zappie/tokens/schema/theme.v1.json';
|
|
76
|
-
import { themeFormats, themeSemanticsKeyword } from '@zappie/tokens/schema-runtime';
|
|
77
|
-
|
|
78
|
-
const ajv = new Ajv2020({ allErrors: true });
|
|
79
|
-
for (const [name, validate] of Object.entries(themeFormats)) ajv.addFormat(name, validate);
|
|
80
|
-
ajv.addKeyword(themeSemanticsKeyword);
|
|
81
|
-
const valid = ajv.compile(schema)(theme);
|
|
29
|
+
const result = validateTheme(themeJson);
|
|
30
|
+
if (!result.ok) {
|
|
31
|
+
throw new Error(result.issues.map((issue) => issue.message).join("\n"));
|
|
32
|
+
}
|
|
33
|
+
const css = compileTheme(result.theme, { scope: ":root" });
|
|
82
34
|
```
|
|
83
35
|
|
|
84
|
-
|
|
36
|
+
`validateTheme` rejects unknown token names, invalid values and CSS injection, and it checks text contrast in light and dark mode. It returns warnings with a valid theme and issues with an invalid one.
|
|
37
|
+
|
|
38
|
+
## Entry points
|
|
85
39
|
|
|
86
|
-
|
|
40
|
+
| Import | For |
|
|
41
|
+
| ------------------------------------- | ---------------------------------------- |
|
|
42
|
+
| `@zappie/tokens` | Token names, the default theme and types |
|
|
43
|
+
| `@zappie/tokens/tokens.css` | The default tokens as CSS |
|
|
44
|
+
| `@zappie/tokens/tailwind.css` | The tokens as a Tailwind theme |
|
|
45
|
+
| `@zappie/tokens/validate` | `validateTheme` |
|
|
46
|
+
| `@zappie/tokens/compile` | `compileTheme` |
|
|
47
|
+
| `@zappie/tokens/schema/theme.v1.json` | The JSON Schema for theme files |
|
|
87
48
|
|
|
88
|
-
|
|
49
|
+
## Tokens
|
|
89
50
|
|
|
90
|
-
|
|
51
|
+
Every name, with its default value. Colours also have dark-mode defaults.
|
|
91
52
|
|
|
92
53
|
<!-- tokens:start -->
|
|
93
54
|
| Token | Default |
|
|
@@ -142,29 +103,10 @@ The table below is generated from the token constants and default values.
|
|
|
142
103
|
| `--z-ease-in-out` | `cubic-bezier(0.4, 0, 0.2, 1)` |
|
|
143
104
|
<!-- tokens:end -->
|
|
144
105
|
|
|
145
|
-
##
|
|
146
|
-
|
|
147
|
-
Existing `StorefrontClientTemplateDefinition.designTokens` remains unchanged. When migrating a template in its own workstream:
|
|
106
|
+
## Status
|
|
148
107
|
|
|
149
|
-
|
|
150
|
-
2. Replace `--cart-review-dialog-width` and `--cart-review-dialog-height` with `--z-dialog-width` and `--z-dialog-height` in components that consume the new contract.
|
|
151
|
-
3. Add version/name and the four required tokens. Move fonts to the `ThemeFont[]` form and provide `logo.alt`.
|
|
152
|
-
4. Validate and compile the theme under the template's scope. Pass `toCheckoutTheme()` output to a checkout that supports the canonical payload.
|
|
153
|
-
|
|
154
|
-
This package does not rename variables in existing host components or migrate templates automatically.
|
|
155
|
-
|
|
156
|
-
## Development
|
|
157
|
-
|
|
158
|
-
The Open Storefronts ESLint override requires braces around every conditional and loop body, with multiline blocks. It covers the public PRD packages (`tokens`, `sdk`, `foundations`, `kit`), themes and their workspace smoke test; it does not change the host or legacy SDK's style rules.
|
|
159
|
-
|
|
160
|
-
```sh
|
|
161
|
-
pnpm --filter @zappie/tokens build
|
|
162
|
-
pnpm --filter @zappie/tokens check-generated
|
|
163
|
-
pnpm --filter @zappie/tokens size
|
|
164
|
-
pnpm vitest run packages/tokens
|
|
165
|
-
pnpm --filter @zappie/tokens check-types
|
|
166
|
-
```
|
|
108
|
+
Tokens are at `0.x`. The list of names can change in a minor release while it settles. Each change is listed in `CHANGELOG.md`.
|
|
167
109
|
|
|
168
|
-
|
|
110
|
+
## License
|
|
169
111
|
|
|
170
|
-
|
|
112
|
+
MIT. `LICENSE.color-name` covers the CSS colour names list.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zappie/tokens",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Semantic design token contract for Zappie storefronts (--z-*).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
39
|
"dist",
|
|
40
|
-
"LICENSE.color-name"
|
|
40
|
+
"LICENSE.color-name",
|
|
41
|
+
"CHANGELOG.md"
|
|
41
42
|
],
|
|
42
43
|
"repository": {
|
|
43
44
|
"type": "git",
|