@aziontech/theme 1.13.0 → 2.0.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.
Files changed (76) hide show
  1. package/README.md +1 -1
  2. package/package.json +19 -21
  3. package/src/scripts/build-tokens.mjs +391 -0
  4. package/src/scripts/compile-primitives.js +165 -0
  5. package/src/scripts/compile-theme.js +117 -0
  6. package/src/{tokens/build → scripts}/css-vars.js +10 -9
  7. package/src/{tokens/build → scripts}/resolve.js +2 -0
  8. package/src/tests/primitives.html +293 -0
  9. package/src/tests/theme.html +310 -0
  10. package/src/tests/tokens.html +84 -0
  11. package/src/tokens/README.md +306 -272
  12. package/src/tokens/index.js +4 -12
  13. package/src/tokens/primitives/animations/animate.js +26 -0
  14. package/src/tokens/primitives/animations/ease.js +7 -0
  15. package/src/tokens/primitives/border-widths.js +9 -0
  16. package/src/tokens/primitives/breakpoints.js +9 -0
  17. package/src/tokens/primitives/colors/alpha.js +104 -0
  18. package/src/tokens/primitives/colors/brand.js +40 -0
  19. package/src/tokens/primitives/colors/colors.js +142 -0
  20. package/src/tokens/primitives/effects/blur.js +11 -0
  21. package/src/tokens/primitives/effects/drop-shadow.js +10 -0
  22. package/src/tokens/primitives/effects/inset-shadow.js +7 -0
  23. package/src/tokens/primitives/effects/opacity.js +8 -0
  24. package/src/tokens/primitives/effects/perspective.js +9 -0
  25. package/src/tokens/primitives/effects/shadow.js +11 -0
  26. package/src/tokens/primitives/ring-offset.js +5 -0
  27. package/src/tokens/primitives/shape/aspect-video.js +3 -0
  28. package/src/tokens/primitives/shape/container.js +17 -0
  29. package/src/tokens/primitives/shape/height.js +32 -0
  30. package/src/tokens/primitives/shape/radius.js +13 -0
  31. package/src/tokens/primitives/shape/shape.js +12 -0
  32. package/src/tokens/primitives/shape/size.js +32 -0
  33. package/src/tokens/primitives/shape/spacing.js +33 -0
  34. package/src/tokens/primitives/shape/width.js +19 -0
  35. package/src/tokens/primitives/typography/font-family.js +7 -0
  36. package/src/tokens/primitives/typography/font-size.js +30 -0
  37. package/src/tokens/primitives/typography/font-weight.js +13 -0
  38. package/src/tokens/primitives/typography/leading.js +9 -0
  39. package/src/tokens/primitives/typography/line-height.js +13 -0
  40. package/src/tokens/primitives/typography/tracking.js +10 -0
  41. package/src/{tailwind/semantic-animations-plugin.js → tokens/semantic/animations.js} +19 -21
  42. package/src/tokens/semantic/colors.js +138 -0
  43. package/src/tokens/semantic/containers.data.js +18 -0
  44. package/src/tokens/semantic/containers.js +70 -0
  45. package/src/tokens/semantic/spacings.data.js +18 -0
  46. package/src/tokens/semantic/spacings.js +163 -0
  47. package/src/tokens/semantic/texts.data.js +103 -0
  48. package/src/{tailwind/semantic-texts-plugin.js → tokens/semantic/texts.js} +30 -9
  49. package/src/tokens/theme/accent.js +18 -0
  50. package/src/tokens/theme/background.js +32 -0
  51. package/src/tokens/theme/border.js +18 -0
  52. package/src/tokens/theme/feedback/danger.js +16 -0
  53. package/src/tokens/theme/feedback/info.js +16 -0
  54. package/src/tokens/theme/feedback/success.js +16 -0
  55. package/src/tokens/theme/feedback/warning.js +16 -0
  56. package/src/tokens/theme/primary.js +18 -0
  57. package/src/tokens/theme/ring.js +12 -0
  58. package/src/tokens/theme/secondary.js +18 -0
  59. package/src/tokens/theme/surfaces.js +23 -0
  60. package/src/tokens/theme/text.js +18 -0
  61. package/src/tokens/theme.js +32 -0
  62. package/colors-brand.js +0 -24
  63. package/src/tailwind/semantic-colors-plugin.js +0 -91
  64. package/src/tailwind/semantic-spacing-plugin.js +0 -151
  65. package/src/tailwind/tailwind-theme.js +0 -54
  66. package/src/tokens/build/preset.js +0 -62
  67. package/src/tokens/build/tailwind-flat-colors.js +0 -75
  68. package/src/tokens/build/tailwind-helper.js +0 -12
  69. package/src/tokens/build/tailwind-plugin.js +0 -175
  70. package/src/tokens/colors-brand.js +0 -24
  71. package/src/tokens/primitives/brand.js +0 -69
  72. package/src/tokens/primitives/colors.js +0 -144
  73. package/src/tokens/semantic/backgrounds.js +0 -46
  74. package/src/tokens/semantic/borders.js +0 -44
  75. package/src/tokens/semantic/text.js +0 -48
  76. /package/src/{tokens/build → scripts}/refs.js +0 -0
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Compile semantic theme tokens into a light/dark CSS variables stylesheet.
3
+ *
4
+ * Resolves `tokenRef(...)` aliases from `tokens/theme/*` (primary, secondary,
5
+ * accent, surfaces, background, border, text, ring, feedback/*) against the
6
+ * primitives + brand + (pre-resolved) surfaces. Emits two blocks (light + dark).
7
+ */
8
+
9
+ import { brandPrimitives, primitives as colorPrimitives } from '../tokens/primitives/colors/colors.js';
10
+ import { accent } from '../tokens/theme/accent.js';
11
+ import { background } from '../tokens/theme/background.js';
12
+ import { border } from '../tokens/theme/border.js';
13
+ import { danger } from '../tokens/theme/feedback/danger.js';
14
+ import { info } from '../tokens/theme/feedback/info.js';
15
+ import { success } from '../tokens/theme/feedback/success.js';
16
+ import { warning } from '../tokens/theme/feedback/warning.js';
17
+ import { primary } from '../tokens/theme/primary.js';
18
+ import { ring } from '../tokens/theme/ring.js';
19
+ import { secondary } from '../tokens/theme/secondary.js';
20
+ import { surfaces } from '../tokens/theme/surfaces.js';
21
+ import { text } from '../tokens/theme/text.js';
22
+ import { isTokenRef } from './refs.js';
23
+
24
+ const VARIANTS = ['light', 'dark'];
25
+
26
+ const getValueByPath = (obj, path) =>
27
+ path.split('.').reduce((acc, key) => {
28
+ if (acc && typeof acc === 'object' && key in acc) return acc[key];
29
+ return undefined;
30
+ }, obj);
31
+
32
+ const resolveRef = (ref, surfacesResolved) => {
33
+ if (ref.startsWith('primitives.')) {
34
+ const v = getValueByPath(colorPrimitives, ref.slice('primitives.'.length));
35
+ return typeof v === 'string' || typeof v === 'number' ? String(v) : null;
36
+ }
37
+ if (ref.startsWith('brand.primary.primary-')) {
38
+ const shade = ref.slice('brand.primary.primary-'.length);
39
+ return brandPrimitives.primary[shade] ?? null;
40
+ }
41
+ if (ref.startsWith('brand.accent.accent-')) {
42
+ const shade = ref.slice('brand.accent.accent-'.length);
43
+ return brandPrimitives.accent[shade] ?? null;
44
+ }
45
+ if (ref.startsWith('brand.absolute.')) {
46
+ const name = ref.slice('brand.absolute.'.length);
47
+ return brandPrimitives.absolute[name] ?? null;
48
+ }
49
+ if (ref.startsWith('theme.surfaces.')) {
50
+ const key = ref.slice('theme.surfaces.'.length);
51
+ return surfacesResolved[key] ?? null;
52
+ }
53
+ return null;
54
+ };
55
+
56
+ const resolveGroup = (group, surfacesResolved) => {
57
+ const result = {};
58
+ Object.entries(group).forEach(([key, value]) => {
59
+ if (!isTokenRef(value)) return;
60
+ const resolved = resolveRef(value.__ref, surfacesResolved);
61
+ if (resolved != null) result[`--${key}`] = String(resolved);
62
+ });
63
+ return result;
64
+ };
65
+
66
+ const compileVariant = (variant) => {
67
+ // Surfaces resolved first — other groups depend on them.
68
+ const surfacesResolved = {};
69
+ Object.entries(surfaces[variant]).forEach(([key, value]) => {
70
+ if (!isTokenRef(value)) return;
71
+ const v = resolveRef(value.__ref, {});
72
+ if (v != null) surfacesResolved[key] = String(v);
73
+ });
74
+
75
+ const vars = {};
76
+ Object.entries(surfacesResolved).forEach(([k, v]) => {
77
+ vars[`--${k}`] = v;
78
+ });
79
+
80
+ const groups = [
81
+ primary[variant],
82
+ secondary[variant],
83
+ accent[variant],
84
+ background[variant],
85
+ border[variant],
86
+ text[variant],
87
+ ring[variant],
88
+ success[variant],
89
+ warning[variant],
90
+ danger[variant],
91
+ info[variant],
92
+ ];
93
+ groups.forEach((g) => Object.assign(vars, resolveGroup(g, surfacesResolved)));
94
+ return vars;
95
+ };
96
+
97
+ export const compileThemeVars = () => Object.fromEntries(VARIANTS.map((v) => [v, compileVariant(v)]));
98
+
99
+ export const compileThemeCss = () => {
100
+ const { light, dark } = compileThemeVars();
101
+ const fmt = (vars) =>
102
+ Object.entries(vars)
103
+ .map(([k, v]) => ` ${k}: ${v};`)
104
+ .join('\n');
105
+ return [
106
+ `:root, [data-theme=light], .azion.azion-light {\n${fmt(light)}\n}`,
107
+ `[data-theme=dark], .dark, .azion.azion-dark {\n${fmt(dark)}\n}`,
108
+ ].join('\n\n');
109
+ };
110
+
111
+ export const injectThemeCss = () => {
112
+ const style = document.createElement('style');
113
+ style.setAttribute('data-azion-theme', 'true');
114
+ style.textContent = compileThemeCss();
115
+ document.head.appendChild(style);
116
+ return style;
117
+ };
@@ -1,12 +1,13 @@
1
1
  /**
2
- * CSS variables initializer for tokens.
2
+ * CSS variables initializer for semantic tokens.
3
+ *
4
+ * Reads the single source-of-truth in `tokens/semantic/colors.js` and resolves
5
+ * its `tokenRef(...)` entries against the primitive trees, producing a flat
6
+ * `{ light, dark }` map of CSS variable names → resolved color values.
3
7
  */
4
8
 
5
- import { primitives } from '../primitives/colors.js';
6
- import { surfacePrimitives, brandPrimitives } from '../primitives/brand.js';
7
- import { textSemantic } from '../semantic/text.js';
8
- import { backgroundSemantic } from '../semantic/backgrounds.js';
9
- import { borderSemantic } from '../semantic/borders.js';
9
+ import { brandPrimitives,primitives, surfacePrimitives } from '../tokens/primitives/colors/colors.js';
10
+ import { semanticColorsData } from '../tokens/semantic/colors.js';
10
11
  import { resolveRefsToCssVars } from './resolve.js';
11
12
 
12
13
  export const createCssVars = () =>
@@ -14,9 +15,9 @@ export const createCssVars = () =>
14
15
  primitives,
15
16
  surfacePrimitives,
16
17
  brandPrimitives,
17
- textSemantic,
18
- backgroundSemantic,
19
- borderSemantic,
18
+ textSemantic: semanticColorsData.text,
19
+ backgroundSemantic: semanticColorsData.background,
20
+ borderSemantic: semanticColorsData.border,
20
21
  });
21
22
 
22
23
  export const cssVarsString = () => {
@@ -37,7 +37,9 @@ export const resolveRefsToCssVars = (tokens) => {
37
37
  surfacePrimitives: tokens.surfacePrimitives,
38
38
  brandPrimitives: tokens.brandPrimitives,
39
39
  };
40
+
40
41
  const baseForVars = { primitives: tokens.primitives, surfacePrimitives: tokens.surfacePrimitives };
42
+
41
43
  const lightSemantic = {
42
44
  text: tokens.textSemantic.light,
43
45
  background: tokens.backgroundSemantic.light,
@@ -0,0 +1,293 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <title>Primitives — Compile &amp; Inject Test</title>
6
+ <style>
7
+ :root { color-scheme: dark; }
8
+ body {
9
+ font-family: ui-sans-serif, system-ui, sans-serif;
10
+ margin: 2rem;
11
+ background: #fafafa;
12
+ color: #171717;
13
+ }
14
+ h1 { margin: 0 0 0.25rem; font-size: 1.25rem; }
15
+ h2 {
16
+ font-size: 0.875rem;
17
+ text-transform: uppercase;
18
+ letter-spacing: 0.04em;
19
+ color: #525252;
20
+ margin: 2rem 0 0.75rem;
21
+ }
22
+ .meta { color: #525252; font-size: 0.875rem; margin-bottom: 1rem; }
23
+ .count { color: #16833f; font-weight: 600; }
24
+ code {
25
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
26
+ font-size: 0.8rem;
27
+ }
28
+ pre {
29
+ background: #fff;
30
+ border: 1px solid #e5e5e5;
31
+ border-radius: 6px;
32
+ padding: 1rem;
33
+ max-height: 70vh;
34
+ overflow: auto;
35
+ font-size: 0.75rem;
36
+ line-height: 1.5;
37
+ white-space: pre;
38
+ }
39
+
40
+ /* Sections */
41
+ .grid {
42
+ display: grid;
43
+ grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
44
+ gap: 0.5rem;
45
+ }
46
+ .card {
47
+ border: 1px solid #e5e5e5;
48
+ border-radius: 6px;
49
+ overflow: hidden;
50
+ background: #fff;
51
+ font-size: 0.7rem;
52
+ }
53
+ .card .swatch { height: 48px; }
54
+ .card .label { padding: 4px 6px; font-family: ui-monospace, monospace; }
55
+ .card .value { padding: 0 6px 6px; color: #737373; font-family: ui-monospace, monospace; }
56
+
57
+ /* Spacing/size demo */
58
+ .scale-row { display: flex; align-items: center; gap: 0.75rem; padding: 4px 0; font-size: 0.75rem; }
59
+ .scale-row .bar { background: #FE601F; height: 12px; border-radius: 2px; }
60
+ .scale-row .name { width: 80px; font-family: ui-monospace, monospace; }
61
+ .scale-row .v { color: #737373; font-family: ui-monospace, monospace; }
62
+
63
+ /* Radius demo */
64
+ .radius-card .swatch { background: #e5e5e5; }
65
+
66
+ /* Type demo */
67
+ .type-row { display: flex; align-items: baseline; gap: 0.75rem; padding: 6px 0; border-bottom: 1px dashed #e5e5e5; }
68
+ .type-row .name { width: 120px; font-family: ui-monospace, monospace; font-size: 0.7rem; color: #525252; }
69
+ .type-row .sample { flex: 1; }
70
+ .type-row .v { color: #737373; font-family: ui-monospace, monospace; font-size: 0.7rem; }
71
+
72
+ /* Blur demo */
73
+ .blur-card .swatch {
74
+ background: linear-gradient(135deg, #FE601F, #8A84EC);
75
+ position: relative;
76
+ }
77
+ .blur-card .swatch::after {
78
+ content: "";
79
+ position: absolute;
80
+ inset: 0;
81
+ backdrop-filter: blur(var(--demo-blur, 0));
82
+ }
83
+ </style>
84
+ </head>
85
+ <body>
86
+ <h1>Primitives — Compile &amp; Inject Test</h1>
87
+ <p class="meta">
88
+ <span class="count" id="count">…</span> CSS variables injected via
89
+ <code>&lt;style data-azion-primitives&gt;</code>
90
+ </p>
91
+
92
+ <h2>Colors</h2>
93
+ <div class="grid" id="colors"></div>
94
+
95
+ <h2>Spacing</h2>
96
+ <div id="spacing"></div>
97
+
98
+ <h2>Size</h2>
99
+ <div id="size"></div>
100
+
101
+ <h2>Radius</h2>
102
+ <div class="grid" id="radius"></div>
103
+
104
+ <h2>Container</h2>
105
+ <div id="container"></div>
106
+
107
+ <h2>Font Family</h2>
108
+ <div id="font-family"></div>
109
+
110
+ <h2>Font Size + Line Height</h2>
111
+ <div id="typography"></div>
112
+
113
+ <h2>Blur</h2>
114
+ <div class="grid" id="blur"></div>
115
+
116
+ <h2>Opacity</h2>
117
+ <div class="grid" id="opacity"></div>
118
+
119
+ <h2>Breakpoints / Border / Ring-offset</h2>
120
+ <pre id="misc"></pre>
121
+
122
+ <h2>Full Generated CSS</h2>
123
+ <pre id="css"></pre>
124
+
125
+ <script type="module">
126
+ import {
127
+ compilePrimitivesCss,
128
+ compilePrimitivesVars,
129
+ injectPrimitivesCss,
130
+ } from '../scripts/compile-primitives.js';
131
+
132
+ const styleTag = injectPrimitivesCss();
133
+ const vars = compilePrimitivesVars();
134
+ const css = compilePrimitivesCss();
135
+
136
+ document.getElementById('count').textContent = Object.keys(vars).length;
137
+ document.getElementById('css').textContent = css;
138
+
139
+ const entriesStartingWith = (prefix) =>
140
+ Object.entries(vars).filter(([k]) => k.startsWith(prefix));
141
+ const entriesMatching = (regex) =>
142
+ Object.entries(vars).filter(([k]) => regex.test(k));
143
+
144
+ // --- Colors (skip alpha for clarity)
145
+ const colorEntries = entriesStartingWith('--color-')
146
+ .filter(([k]) => !k.startsWith('--color-alpha-'));
147
+ const colorsEl = document.getElementById('colors');
148
+ colorEntries.forEach(([name, value]) => {
149
+ const el = document.createElement('div');
150
+ el.className = 'card';
151
+ el.innerHTML = `
152
+ <div class="swatch" style="background: var(${name});"></div>
153
+ <div class="label">${name.replace('--color-', '')}</div>
154
+ <div class="value">${value}</div>
155
+ `;
156
+ colorsEl.appendChild(el);
157
+ });
158
+
159
+ // --- Spacing
160
+ const spacingEntries = entriesStartingWith('--spacing-');
161
+ const spacingEl = document.getElementById('spacing');
162
+ spacingEntries.forEach(([name, value]) => {
163
+ const row = document.createElement('div');
164
+ row.className = 'scale-row';
165
+ row.innerHTML = `
166
+ <span class="name">${name.replace('--', '')}</span>
167
+ <span class="bar" style="width: var(${name});"></span>
168
+ <span class="v">${value}</span>
169
+ `;
170
+ spacingEl.appendChild(row);
171
+ });
172
+
173
+ // --- Size
174
+ const sizeEntries = entriesStartingWith('--size-');
175
+ const sizeEl = document.getElementById('size');
176
+ sizeEntries.forEach(([name, value]) => {
177
+ const row = document.createElement('div');
178
+ row.className = 'scale-row';
179
+ row.innerHTML = `
180
+ <span class="name">${name.replace('--', '')}</span>
181
+ <span class="bar" style="width: var(${name});"></span>
182
+ <span class="v">${value}</span>
183
+ `;
184
+ sizeEl.appendChild(row);
185
+ });
186
+
187
+ // --- Radius
188
+ const radiusEntries = entriesStartingWith('--radius-');
189
+ const radiusEl = document.getElementById('radius');
190
+ radiusEntries.forEach(([name, value]) => {
191
+ const el = document.createElement('div');
192
+ el.className = 'card radius-card';
193
+ el.innerHTML = `
194
+ <div class="swatch" style="border-radius: var(${name});"></div>
195
+ <div class="label">${name.replace('--', '')}</div>
196
+ <div class="value">${value}</div>
197
+ `;
198
+ radiusEl.appendChild(el);
199
+ });
200
+
201
+ // --- Container
202
+ const containerEntries = entriesStartingWith('--container-');
203
+ const containerEl = document.getElementById('container');
204
+ containerEntries.forEach(([name, value]) => {
205
+ const row = document.createElement('div');
206
+ row.className = 'scale-row';
207
+ row.innerHTML = `
208
+ <span class="name">${name.replace('--', '')}</span>
209
+ <span class="bar" style="width: min(var(${name}), 100%);"></span>
210
+ <span class="v">${value}</span>
211
+ `;
212
+ containerEl.appendChild(row);
213
+ });
214
+
215
+ // --- Font family
216
+ const fontFamilyEntries = entriesStartingWith('--font-')
217
+ .filter(([name]) => !name.startsWith('--font-weight-'));
218
+ const fontFamilyEl = document.getElementById('font-family');
219
+ fontFamilyEntries.forEach(([name, value]) => {
220
+ const row = document.createElement('div');
221
+ row.className = 'type-row';
222
+ row.innerHTML = `
223
+ <span class="name">${name.replace('--', '')}</span>
224
+ <span class="sample" style="font-family: var(${name});">The quick brown fox jumps over the lazy dog</span>
225
+ <span class="v">${value}</span>
226
+ `;
227
+ fontFamilyEl.appendChild(row);
228
+ });
229
+
230
+ // --- Font size + line height
231
+ const fontSizeEntries = entriesStartingWith('--font-size-');
232
+ const typographyEl = document.getElementById('typography');
233
+ fontSizeEntries.forEach(([name, value]) => {
234
+ const row = document.createElement('div');
235
+ row.className = 'type-row';
236
+ row.innerHTML = `
237
+ <span class="name">${name.replace('--', '')}</span>
238
+ <span class="sample" style="font-size: var(${name}); line-height: 1.2;">Aa Bb 123</span>
239
+ <span class="v">${value}</span>
240
+ `;
241
+ typographyEl.appendChild(row);
242
+ });
243
+ const lineHeightEntries = entriesStartingWith('--line-height-');
244
+ lineHeightEntries.forEach(([name, value]) => {
245
+ const row = document.createElement('div');
246
+ row.className = 'type-row';
247
+ row.innerHTML = `
248
+ <span class="name">${name.replace('--', '')}</span>
249
+ <span class="sample" style="line-height: var(${name}); font-size: 14px;">line A<br/>line B</span>
250
+ <span class="v">${value}</span>
251
+ `;
252
+ typographyEl.appendChild(row);
253
+ });
254
+
255
+ // --- Blur
256
+ const blurEntries = entriesStartingWith('--blur-');
257
+ const blurEl = document.getElementById('blur');
258
+ blurEntries.forEach(([name, value]) => {
259
+ const el = document.createElement('div');
260
+ el.className = 'card blur-card';
261
+ el.innerHTML = `
262
+ <div class="swatch" style="--demo-blur: var(${name});"></div>
263
+ <div class="label">${name.replace('--', '')}</div>
264
+ <div class="value">${value}</div>
265
+ `;
266
+ blurEl.appendChild(el);
267
+ });
268
+
269
+ // --- Opacity
270
+ const opacityEntries = entriesStartingWith('--opacity-');
271
+ const opacityEl = document.getElementById('opacity');
272
+ opacityEntries.forEach(([name, value]) => {
273
+ const el = document.createElement('div');
274
+ el.className = 'card';
275
+ el.innerHTML = `
276
+ <div class="swatch" style="background: #FE601F; opacity: var(${name});"></div>
277
+ <div class="label">${name.replace('--', '')}</div>
278
+ <div class="value">${value}</div>
279
+ `;
280
+ opacityEl.appendChild(el);
281
+ });
282
+
283
+ // --- Misc (breakpoints, border, ring-offset)
284
+ const misc = entriesMatching(/^--(breakpoint|border|ring-offset)/);
285
+ document.getElementById('misc').textContent = misc
286
+ .map(([k, v]) => `${k}: ${v};`)
287
+ .join('\n');
288
+
289
+ console.info('[primitives] injected', styleTag);
290
+ console.info('[primitives] vars', vars);
291
+ </script>
292
+ </body>
293
+ </html>