@rokkit/core 1.0.0-next.162 → 1.0.0-next.164

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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/theme.ts +37 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/core",
3
- "version": "1.0.0-next.162",
3
+ "version": "1.0.0-next.164",
4
4
  "description": "Contains core utility functions and classes that can be used in various components.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -46,6 +46,6 @@
46
46
  "ramda": "^0.32.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@rokkit/icons": "1.0.0-next.162"
49
+ "@rokkit/icons": "1.0.0-next.164"
50
50
  }
51
51
  }
package/src/theme.ts CHANGED
@@ -133,8 +133,14 @@ export function semanticShortcuts(name) {
133
133
  */
134
134
  export function contrastShortcuts(name) {
135
135
  return [
136
- [`text-on-${name}`, `text-${name}-50 dark:text-${name}-50`],
137
- [`text-on-${name}-muted`, `text-${name}-100 dark:text-${name}-200`]
136
+ [
137
+ new RegExp(`^text-on-${name}(\\/\\d+)?$`),
138
+ ([, end]) => `text-${name}-50${end || ''} dark:text-${name}-50${end || ''}`
139
+ ],
140
+ [
141
+ new RegExp(`^text-on-${name}-muted(\\/\\d+)?$`),
142
+ ([, end]) => `text-${name}-100${end || ''} dark:text-${name}-200${end || ''}`
143
+ ]
138
144
  ]
139
145
  }
140
146
 
@@ -205,4 +211,33 @@ export class Theme {
205
211
  getShortcuts(name) {
206
212
  return [...semanticShortcuts(name), ...contrastShortcuts(name)]
207
213
  }
214
+
215
+ /**
216
+ * Generates CSS custom property declarations for the semantic z0–z10 tone scale.
217
+ *
218
+ * Returns a CSS string with two blocks:
219
+ * - `:root` — light-mode aliases (z0=50 … z10=950)
220
+ * - `[data-mode="dark"]` — dark-mode aliases (z0=950 … z10=50)
221
+ *
222
+ * These let consumers write `var(--color-primary-z5)` instead of hardcoding
223
+ * numeric shades, and the value automatically adapts to the active mode.
224
+ */
225
+ getZScaleCSS() {
226
+ const names = Object.keys(this.#mapping)
227
+
228
+ const lightLines = names.flatMap((name) =>
229
+ Object.entries(TONE_MAP).map(
230
+ ([zone, light]) => ` --color-${name}-${zone}: var(--color-${name}-${light});`
231
+ )
232
+ )
233
+
234
+ const darkLines = names.flatMap((name) =>
235
+ Object.entries(TONE_MAP).map(([zone, light]) => {
236
+ const dark = 1000 - light
237
+ return ` --color-${name}-${zone}: var(--color-${name}-${dark});`
238
+ })
239
+ )
240
+
241
+ return `:root {\n${lightLines.join('\n')}\n}\n[data-mode="dark"] {\n${darkLines.join('\n')}\n}`
242
+ }
208
243
  }