@zappie/tokens 0.1.0 → 0.1.2

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 (3) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +36 -94
  3. package/package.json +8 -7
package/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # @zappie/tokens
2
+
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 9b25eb7: The packages now live in zappie/storefront-packages, and each package's repository, homepage and issues links point there. This release is the first one published from that repository.
8
+
9
+ ## 0.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 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.
14
+
15
+ ## 0.1.0
16
+
17
+ ### Minor Changes
18
+
19
+ - - `@zappie/tokens`: Publish the semantic storefront token contract, CSS aliases, validation and compilation tools.
20
+ - `@zappie/sdk`: Publish the framework-agnostic storefront client and its React, server, checkout, customer, places, visits and URL entries.
21
+ - `@zappie/foundations`: Publish accessible, unstyled React primitives for storefront catalogue, item, fulfilment and cart experiences.
22
+ - `@zappie/theme-base`: Publish the reusable base storefront theme and its catalogue, item and cart surfaces.
23
+ - `@zappie/kit`: Publish the built component registry consumed by the Zappie CLI.
24
+ - `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 closed, framework-independent theme contract for storefronts. No runtime dependencies, DOM access, or host imports. The package remains private until the public-package release phase.
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
- ## Imports
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
- The core exports token constants, defaults and types and stays below **4,000 bytes gzipped**, measured with every core export retained. Color parsing, validation, compilation and checkout projection are separate imports. Those entry points share build chunks but are outside the core budget. Types, including `CheckoutTheme`, can be imported from the core without pulling in runtime helpers.
9
+ ## Use it
15
10
 
16
- ```css
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
- ## Theme JSON
13
+ ```css
14
+ @import "@zappie/tokens/tokens.css";
25
15
 
26
- ```ts
27
- const theme: ThemeJson = {
28
- version: 1,
29
- name: 'My store',
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
- Only background, text, accent and accent-contrast are required. Missing values inherit defaults. Unknown fields and tokens are errors. Validation reports every issue in one pass: structural and syntax errors, plus effective light and dark contrast for every pair whose colours parse. Text/background, text/surface and accent-contrast/accent require 4.5:1; muted/background below 3:1 is a warning. Translucent foregrounds are composited; contrast backgrounds must be opaque. `contrastRatio()` returns `NaN` for unsupported colors or a translucent background.
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
- const checkoutTheme = toCheckoutTheme(theme, {
60
- scheme: 'light', // Resolve auto mode using the caller's current scheme.
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
- The result is `{ version: 1, tokens, logo?, fonts?, copy? }` with only the 13 names in `CHECKOUT_TOKENS`. The checkout runs on its own origin, so the selected logo becomes an absolute `{ url, alt }`: a relative path is resolved against `origin` (HTTPS, or HTTP on localhost), and without one the logo is omitted with an `invalid_logo` warning. `fonts` lists the Google body and display fonts the checkout loads itself; self-hosted fonts are dropped with an `invalid_font` warning and fall back to the rest of the stack. Copy is limited to 40 Unicode code points per field; truncation calls `onWarning` (or `console.warn` when omitted). An omitted scheme uses dark only when `darkMode` is explicitly dark; auto needs a caller-supplied scheme. This workstream defines the payload; it does not wire the hosted checkout to it.
68
-
69
- ## JSON Schema
70
-
71
- The generated schema is exported at `@zappie/tokens/schema/theme.v1.json`. It provides editor structure/completion. Full validation requires its custom color/length formats and semantic keyword, because ordinary JSON Schema cannot calculate WCAG contrast or enforce unique font roles:
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
- AJV is a development dependency only; applications may use `validateTheme()` directly. Schema validation returns a boolean; use `validateTheme()` for detailed semantic issues and warnings. The declared remote schema URL is the intended registry location, not a deployment performed by this package.
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
- ## Defaults and fixtures
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
- Public defaults use system fonts; the host can continue using its licensed Cereal font through its own theme. The palette follows the existing host values in `styles/colors.ts`, inherited by the default template. `fixtures/default-template.theme.json` records this approved reference instead of the PRD's unavailable Inside Out PDF fixture. `valid-minimal`, `valid-full`, `low-contrast` and `unknown-token` cover validation and schema parity. Fixture logo/font URLs are illustrative and are not fetched by the package.
49
+ ## Tokens
89
50
 
90
- The table below is generated from the token constants and default values.
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
- ## Migration from designTokens
146
-
147
- Existing `StorefrontClientTemplateDefinition.designTokens` remains unchanged. When migrating a template in its own workstream:
106
+ ## Status
148
107
 
149
- 1. Map public styling to the closed semantic names. Keep decorative private variables in the template stylesheet, outside `theme.tokens`.
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
- Build regenerates the schema, both CSS exports, and this token table from the source contract. Commit those generated files. CI checks their freshness and the size budgets. Tests live in `test/` because the repository reserves/excludes `tests/` for other test harnesses.
110
+ ## License
169
111
 
170
- The CSS named-color lookup includes MIT-licensed data from color-name; see `LICENSE.color-name`.
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.0",
3
+ "version": "0.1.2",
4
4
  "description": "Semantic design token contract for Zappie storefronts (--z-*).",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -37,21 +37,22 @@
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",
44
- "url": "git+https://github.com/zappie/storefront.git",
45
+ "url": "git+https://github.com/zappie/storefront-packages.git",
45
46
  "directory": "packages/tokens"
46
47
  },
47
48
  "devDependencies": {
48
- "ajv": "^8.18.0",
49
- "esbuild": "^0.27.7"
49
+ "ajv": "^8.20.0",
50
+ "esbuild": "^0.28.2"
50
51
  },
51
52
  "license": "MIT",
52
- "homepage": "https://github.com/zappie/storefront#readme",
53
+ "homepage": "https://github.com/zappie/storefront-packages#readme",
53
54
  "bugs": {
54
- "url": "https://github.com/zappie/storefront/issues"
55
+ "url": "https://github.com/zappie/storefront-packages/issues"
55
56
  },
56
57
  "scripts": {
57
58
  "build": "tsup && node scripts/build-schema.mjs",