@tenphi/glaze 0.2.0 → 0.4.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/dist/index.d.mts CHANGED
@@ -145,6 +145,12 @@ interface GlazeColorToken {
145
145
  resolve(): ResolvedColor;
146
146
  /** Export as a flat token map (no color name key). */
147
147
  token(options?: GlazeTokenOptions): Record<string, string>;
148
+ /**
149
+ * Export as a tasty style-to-state binding (no color name key).
150
+ * Uses `#name` keys and state aliases (`''`, `@dark`, etc.).
151
+ * @see https://cube-ui-kit.vercel.app/?path=/docs/tasty-documentation--docs
152
+ */
153
+ tasty(options?: GlazeTokenOptions): Record<string, string>;
148
154
  /** Export as a flat JSON map (no color name key). */
149
155
  json(options?: GlazeJsonOptions): Record<string, string>;
150
156
  }
@@ -173,10 +179,26 @@ interface GlazeTheme {
173
179
  extend(options: GlazeExtendOptions): GlazeTheme;
174
180
  /** Resolve all colors and return the result map. */
175
181
  resolve(): Map<string, ResolvedColor>;
176
- /** Export as token map. */
177
- tokens(options?: GlazeTokenOptions): Record<string, Record<string, string>>;
182
+ /**
183
+ * Export as a flat token map grouped by scheme variant.
184
+ *
185
+ * ```ts
186
+ * theme.tokens()
187
+ * // → { light: { surface: 'okhsl(...)' }, dark: { surface: 'okhsl(...)' } }
188
+ * ```
189
+ */
190
+ tokens(options?: GlazeJsonOptions): Record<string, Record<string, string>>;
191
+ /**
192
+ * Export as tasty style-to-state bindings.
193
+ * Uses `#name` color token keys and state aliases (`''`, `@dark`, etc.).
194
+ * Spread into component styles or register as a recipe via `configure({ recipes })`.
195
+ * @see https://cube-ui-kit.vercel.app/?path=/docs/tasty-documentation--docs
196
+ */
197
+ tasty(options?: GlazeTokenOptions): Record<string, Record<string, string>>;
178
198
  /** Export as plain JSON. */
179
199
  json(options?: GlazeJsonOptions): Record<string, Record<string, string>>;
200
+ /** Export as CSS custom property declarations. */
201
+ css(options?: GlazeCssOptions): GlazeCssResult;
180
202
  }
181
203
  interface GlazeExtendOptions {
182
204
  hue?: number;
@@ -202,13 +224,46 @@ interface GlazeJsonOptions {
202
224
  /** Output color format. Default: 'okhsl'. */
203
225
  format?: GlazeColorFormat;
204
226
  }
227
+ interface GlazeCssOptions {
228
+ /** Output color format. Default: 'rgb'. */
229
+ format?: GlazeColorFormat;
230
+ /** Suffix appended to each CSS custom property name. Default: '-color'. */
231
+ suffix?: string;
232
+ }
233
+ /** CSS custom property declarations grouped by scheme variant. */
234
+ interface GlazeCssResult {
235
+ light: string;
236
+ dark: string;
237
+ lightContrast: string;
238
+ darkContrast: string;
239
+ }
205
240
  interface GlazePalette {
206
- /** Export all themes as a combined token map. */
207
- tokens(options?: GlazeTokenOptions): Record<string, Record<string, string>>;
241
+ /**
242
+ * Export all themes as a flat token map grouped by scheme variant.
243
+ *
244
+ * ```ts
245
+ * palette.tokens({ prefix: true })
246
+ * // → { light: { 'primary-surface': 'okhsl(...)' }, dark: { 'primary-surface': 'okhsl(...)' } }
247
+ * ```
248
+ */
249
+ tokens(options?: GlazeJsonOptions & {
250
+ prefix?: boolean | Record<string, string>;
251
+ }): Record<string, Record<string, string>>;
252
+ /**
253
+ * Export all themes as tasty style-to-state bindings.
254
+ * Uses `#name` color token keys and state aliases (`''`, `@dark`, etc.).
255
+ * Spread into component styles or register as a recipe via `configure({ recipes })`.
256
+ * @see https://cube-ui-kit.vercel.app/?path=/docs/tasty-documentation--docs
257
+ */
258
+ tasty(options?: GlazeTokenOptions): Record<string, Record<string, string>>;
208
259
  /** Export all themes as plain JSON. */
209
260
  json(options?: GlazeJsonOptions & {
210
261
  prefix?: boolean | Record<string, string>;
211
262
  }): Record<string, Record<string, Record<string, string>>>;
263
+ /** Export all themes as CSS custom property declarations. */
264
+ css(options?: GlazeCssOptions & {
265
+ prefix?: boolean | Record<string, string>;
266
+ }): GlazeCssResult;
212
267
  }
213
268
  //#endregion
214
269
  //#region src/glaze.d.ts
@@ -230,10 +285,16 @@ declare function glaze(hueOrOptions: number | {
230
285
  declare namespace glaze {
231
286
  var configure: (config: GlazeConfig) => void;
232
287
  var palette: (themes: PaletteInput) => {
233
- tokens(options?: GlazeTokenOptions): Record<string, Record<string, string>>;
288
+ tokens(options?: GlazeJsonOptions & {
289
+ prefix?: boolean | Record<string, string>;
290
+ }): Record<string, Record<string, string>>;
291
+ tasty(options?: GlazeTokenOptions): Record<string, Record<string, string>>;
234
292
  json(options?: GlazeJsonOptions & {
235
293
  prefix?: boolean | Record<string, string>;
236
294
  }): Record<string, Record<string, Record<string, string>>>;
295
+ css(options?: GlazeCssOptions & {
296
+ prefix?: boolean | Record<string, string>;
297
+ }): GlazeCssResult;
237
298
  };
238
299
  var from: (data: GlazeThemeExport) => GlazeTheme;
239
300
  var color: (input: GlazeColorInput) => GlazeColorToken;
@@ -304,5 +365,5 @@ declare function formatHsl(h: number, s: number, l: number): string;
304
365
  */
305
366
  declare function formatOklch(h: number, s: number, l: number): string;
306
367
  //#endregion
307
- export { type AdaptationMode, type ColorDef, type ColorMap, type ContrastPreset, type FindLightnessForContrastOptions, type FindLightnessForContrastResult, type GlazeColorFormat, type GlazeColorInput, type GlazeColorToken, type GlazeConfig, type GlazeExtendOptions, type GlazeJsonOptions, type GlazeOutputModes, type GlazePalette, type GlazeTheme, type GlazeThemeExport, type GlazeTokenOptions, type HCPair, type MinContrast, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, contrastRatioFromLuminance, findLightnessForContrast, formatHsl, formatOkhsl, formatOklch, formatRgb, glaze, okhslToLinearSrgb, okhslToOklab, okhslToSrgb, parseHex, relativeLuminanceFromLinearRgb, resolveMinContrast, srgbToOkhsl };
368
+ export { type AdaptationMode, type ColorDef, type ColorMap, type ContrastPreset, type FindLightnessForContrastOptions, type FindLightnessForContrastResult, type GlazeColorFormat, type GlazeColorInput, type GlazeColorToken, type GlazeConfig, type GlazeCssOptions, type GlazeCssResult, type GlazeExtendOptions, type GlazeJsonOptions, type GlazeOutputModes, type GlazePalette, type GlazeTheme, type GlazeThemeExport, type GlazeTokenOptions, type HCPair, type MinContrast, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, contrastRatioFromLuminance, findLightnessForContrast, formatHsl, formatOkhsl, formatOklch, formatRgb, glaze, okhslToLinearSrgb, okhslToOklab, okhslToSrgb, parseHex, relativeLuminanceFromLinearRgb, resolveMinContrast, srgbToOkhsl };
308
369
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -996,6 +996,20 @@ function buildTokenMap(resolved, prefix, states, modes, format = "okhsl") {
996
996
  }
997
997
  return tokens;
998
998
  }
999
+ function buildFlatTokenMap(resolved, prefix, modes, format = "okhsl") {
1000
+ const result = { light: {} };
1001
+ if (modes.dark) result.dark = {};
1002
+ if (modes.highContrast) result.lightContrast = {};
1003
+ if (modes.dark && modes.highContrast) result.darkContrast = {};
1004
+ for (const [name, color] of resolved) {
1005
+ const key = `${prefix}${name}`;
1006
+ result.light[key] = formatVariant(color.light, format);
1007
+ if (modes.dark) result.dark[key] = formatVariant(color.dark, format);
1008
+ if (modes.highContrast) result.lightContrast[key] = formatVariant(color.lightContrast, format);
1009
+ if (modes.dark && modes.highContrast) result.darkContrast[key] = formatVariant(color.darkContrast, format);
1010
+ }
1011
+ return result;
1012
+ }
999
1013
  function buildJsonMap(resolved, modes, format = "okhsl") {
1000
1014
  const result = {};
1001
1015
  for (const [name, color] of resolved) {
@@ -1007,6 +1021,27 @@ function buildJsonMap(resolved, modes, format = "okhsl") {
1007
1021
  }
1008
1022
  return result;
1009
1023
  }
1024
+ function buildCssMap(resolved, prefix, suffix, format) {
1025
+ const lines = {
1026
+ light: [],
1027
+ dark: [],
1028
+ lightContrast: [],
1029
+ darkContrast: []
1030
+ };
1031
+ for (const [name, color] of resolved) {
1032
+ const prop = `--${prefix}${name}${suffix}`;
1033
+ lines.light.push(`${prop}: ${formatVariant(color.light, format)};`);
1034
+ lines.dark.push(`${prop}: ${formatVariant(color.dark, format)};`);
1035
+ lines.lightContrast.push(`${prop}: ${formatVariant(color.lightContrast, format)};`);
1036
+ lines.darkContrast.push(`${prop}: ${formatVariant(color.darkContrast, format)};`);
1037
+ }
1038
+ return {
1039
+ light: lines.light.join("\n"),
1040
+ dark: lines.dark.join("\n"),
1041
+ lightContrast: lines.lightContrast.join("\n"),
1042
+ darkContrast: lines.darkContrast.join("\n")
1043
+ };
1044
+ }
1010
1045
  function createTheme(hue, saturation, initialColors) {
1011
1046
  let colorDefs = initialColors ? { ...initialColors } : {};
1012
1047
  return {
@@ -1056,6 +1091,9 @@ function createTheme(hue, saturation, initialColors) {
1056
1091
  return resolveAllColors(hue, saturation, colorDefs);
1057
1092
  },
1058
1093
  tokens(options) {
1094
+ return buildFlatTokenMap(resolveAllColors(hue, saturation, colorDefs), "", resolveModes(options?.modes), options?.format);
1095
+ },
1096
+ tasty(options) {
1059
1097
  return buildTokenMap(resolveAllColors(hue, saturation, colorDefs), "", {
1060
1098
  dark: options?.states?.dark ?? globalConfig.states.dark,
1061
1099
  highContrast: options?.states?.highContrast ?? globalConfig.states.highContrast
@@ -1063,12 +1101,32 @@ function createTheme(hue, saturation, initialColors) {
1063
1101
  },
1064
1102
  json(options) {
1065
1103
  return buildJsonMap(resolveAllColors(hue, saturation, colorDefs), resolveModes(options?.modes), options?.format);
1104
+ },
1105
+ css(options) {
1106
+ return buildCssMap(resolveAllColors(hue, saturation, colorDefs), "", options?.suffix ?? "-color", options?.format ?? "rgb");
1066
1107
  }
1067
1108
  };
1068
1109
  }
1110
+ function resolvePrefix(options, themeName) {
1111
+ if (options?.prefix === true) return `${themeName}-`;
1112
+ if (typeof options?.prefix === "object" && options.prefix !== null) return options.prefix[themeName] ?? `${themeName}-`;
1113
+ return "";
1114
+ }
1069
1115
  function createPalette(themes) {
1070
1116
  return {
1071
1117
  tokens(options) {
1118
+ const modes = resolveModes(options?.modes);
1119
+ const allTokens = {};
1120
+ for (const [themeName, theme] of Object.entries(themes)) {
1121
+ const tokens = buildFlatTokenMap(theme.resolve(), resolvePrefix(options, themeName), modes, options?.format);
1122
+ for (const variant of Object.keys(tokens)) {
1123
+ if (!allTokens[variant]) allTokens[variant] = {};
1124
+ Object.assign(allTokens[variant], tokens[variant]);
1125
+ }
1126
+ }
1127
+ return allTokens;
1128
+ },
1129
+ tasty(options) {
1072
1130
  const states = {
1073
1131
  dark: options?.states?.dark ?? globalConfig.states.dark,
1074
1132
  highContrast: options?.states?.highContrast ?? globalConfig.states.highContrast
@@ -1076,11 +1134,7 @@ function createPalette(themes) {
1076
1134
  const modes = resolveModes(options?.modes);
1077
1135
  const allTokens = {};
1078
1136
  for (const [themeName, theme] of Object.entries(themes)) {
1079
- const resolved = theme.resolve();
1080
- let prefix = "";
1081
- if (options?.prefix === true) prefix = `${themeName}-`;
1082
- else if (typeof options?.prefix === "object" && options.prefix !== null) prefix = options.prefix[themeName] ?? `${themeName}-`;
1083
- const tokens = buildTokenMap(resolved, prefix, states, modes, options?.format);
1137
+ const tokens = buildTokenMap(theme.resolve(), resolvePrefix(options, themeName), states, modes, options?.format);
1084
1138
  Object.assign(allTokens, tokens);
1085
1139
  }
1086
1140
  return allTokens;
@@ -1090,6 +1144,31 @@ function createPalette(themes) {
1090
1144
  const result = {};
1091
1145
  for (const [themeName, theme] of Object.entries(themes)) result[themeName] = buildJsonMap(theme.resolve(), modes, options?.format);
1092
1146
  return result;
1147
+ },
1148
+ css(options) {
1149
+ const suffix = options?.suffix ?? "-color";
1150
+ const format = options?.format ?? "rgb";
1151
+ const allLines = {
1152
+ light: [],
1153
+ dark: [],
1154
+ lightContrast: [],
1155
+ darkContrast: []
1156
+ };
1157
+ for (const [themeName, theme] of Object.entries(themes)) {
1158
+ const css = buildCssMap(theme.resolve(), resolvePrefix(options, themeName), suffix, format);
1159
+ for (const key of [
1160
+ "light",
1161
+ "dark",
1162
+ "lightContrast",
1163
+ "darkContrast"
1164
+ ]) if (css[key]) allLines[key].push(css[key]);
1165
+ }
1166
+ return {
1167
+ light: allLines.light.join("\n"),
1168
+ dark: allLines.dark.join("\n"),
1169
+ lightContrast: allLines.lightContrast.join("\n"),
1170
+ darkContrast: allLines.darkContrast.join("\n")
1171
+ };
1093
1172
  }
1094
1173
  };
1095
1174
  }
@@ -1109,6 +1188,12 @@ function createColorToken(input) {
1109
1188
  highContrast: options?.states?.highContrast ?? globalConfig.states.highContrast
1110
1189
  }, resolveModes(options?.modes), options?.format)["#__color__"];
1111
1190
  },
1191
+ tasty(options) {
1192
+ return buildTokenMap(resolveAllColors(input.hue, input.saturation, defs), "", {
1193
+ dark: options?.states?.dark ?? globalConfig.states.dark,
1194
+ highContrast: options?.states?.highContrast ?? globalConfig.states.highContrast
1195
+ }, resolveModes(options?.modes), options?.format)["#__color__"];
1196
+ },
1112
1197
  json(options) {
1113
1198
  return buildJsonMap(resolveAllColors(input.hue, input.saturation, defs), resolveModes(options?.modes), options?.format)["__color__"];
1114
1199
  }