@tokens-studio/tokenscript-schemas 0.0.13 → 0.1.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.
Files changed (153) hide show
  1. package/README.md +21 -0
  2. package/bundled/functions/adjust_chroma.json +60 -0
  3. package/bundled/functions/adjust_hue.json +60 -0
  4. package/bundled/functions/adjust_lightness.json +60 -0
  5. package/bundled/functions/adjust_to_contrast.json +67 -0
  6. package/bundled/functions/alpha_blend.json +31 -0
  7. package/bundled/functions/alpha_scale.json +27 -0
  8. package/bundled/functions/analogous.json +32 -0
  9. package/bundled/functions/apca_contrast.json +27 -0
  10. package/bundled/functions/are_similar.json +73 -0
  11. package/bundled/functions/auto_text_color.json +66 -0
  12. package/bundled/functions/best_contrast.json +28 -0
  13. package/bundled/functions/chroma.json +54 -0
  14. package/bundled/functions/clamp_chroma.json +66 -0
  15. package/bundled/functions/clamp_lightness.json +66 -0
  16. package/bundled/functions/clamp_to_gamut.json +23 -0
  17. package/bundled/functions/complement.json +24 -0
  18. package/bundled/functions/contrast_ratio.json +27 -0
  19. package/bundled/functions/cooler.json +52 -0
  20. package/bundled/functions/darken.json +28 -0
  21. package/bundled/functions/delta_e_2000.json +40 -0
  22. package/bundled/functions/delta_e_76.json +27 -0
  23. package/bundled/functions/delta_e_ok.json +27 -0
  24. package/bundled/functions/desaturate.json +28 -0
  25. package/bundled/functions/distributed.json +36 -0
  26. package/bundled/functions/diverging.json +36 -0
  27. package/bundled/functions/grayscale.json +24 -0
  28. package/bundled/functions/harmonize.json +65 -0
  29. package/bundled/functions/hue.json +54 -0
  30. package/bundled/functions/hue_difference.json +27 -0
  31. package/bundled/functions/in_gamut.json +27 -0
  32. package/bundled/functions/interpolate.json +66 -0
  33. package/bundled/functions/invert.json +1 -1
  34. package/bundled/functions/is_cool.json +23 -0
  35. package/bundled/functions/is_dark.json +27 -0
  36. package/bundled/functions/is_light.json +27 -0
  37. package/bundled/functions/is_neutral.json +65 -0
  38. package/bundled/functions/is_warm.json +23 -0
  39. package/bundled/functions/lighten.json +28 -0
  40. package/bundled/functions/lightness.json +61 -0
  41. package/bundled/functions/luminance.json +23 -0
  42. package/bundled/functions/meets_contrast.json +31 -0
  43. package/bundled/functions/mix.json +32 -0
  44. package/bundled/functions/monochromatic.json +28 -0
  45. package/bundled/functions/muted.json +59 -0
  46. package/bundled/functions/neutral_variant.json +59 -0
  47. package/bundled/functions/relative_luminance.json +61 -0
  48. package/bundled/functions/rotate_hue.json +28 -0
  49. package/bundled/functions/saturate.json +28 -0
  50. package/bundled/functions/scale_chroma.json +60 -0
  51. package/bundled/functions/scale_lightness.json +60 -0
  52. package/bundled/functions/sepia.json +59 -0
  53. package/bundled/functions/set_chroma.json +28 -0
  54. package/bundled/functions/set_hue.json +28 -0
  55. package/bundled/functions/set_lightness.json +28 -0
  56. package/bundled/functions/shade_scale.json +28 -0
  57. package/bundled/functions/split_complement.json +28 -0
  58. package/bundled/functions/steps.json +32 -0
  59. package/bundled/functions/tetradic.json +24 -0
  60. package/bundled/functions/tint_scale.json +36 -0
  61. package/bundled/functions/to_gamut.json +59 -0
  62. package/bundled/functions/triadic.json +24 -0
  63. package/bundled/functions/vibrant.json +59 -0
  64. package/bundled/functions/warmer.json +52 -0
  65. package/bundled/functions/wcag_level.json +60 -0
  66. package/bundled/functions.json +2602 -6
  67. package/bundled/registry.json +3705 -84
  68. package/bundled/types/css-color.json +151 -0
  69. package/bundled/types/hsl-color.json +66 -0
  70. package/bundled/types/hsv-color.json +57 -0
  71. package/bundled/types/hwb-color.json +66 -0
  72. package/bundled/types/lab-color.json +57 -0
  73. package/bundled/types/lch-color.json +57 -0
  74. package/bundled/types/okhsl-color.json +57 -0
  75. package/bundled/types/okhsv-color.json +57 -0
  76. package/bundled/types/oklab-color.json +87 -0
  77. package/bundled/types/oklch-color.json +57 -0
  78. package/bundled/types/p3-color.json +57 -0
  79. package/bundled/types/p3-linear-color.json +57 -0
  80. package/bundled/types/rgb-color.json +12 -3
  81. package/bundled/types/srgb-color.json +77 -0
  82. package/bundled/types/srgb-linear-color.json +67 -0
  83. package/bundled/types/xyz-d50-color.json +57 -0
  84. package/bundled/types/xyz-d65-color.json +77 -0
  85. package/bundled/types.json +1067 -43
  86. package/dist/cli/index.cjs +231 -22
  87. package/dist/cli/index.cjs.map +1 -1
  88. package/dist/cli/index.js +231 -22
  89. package/dist/cli/index.js.map +1 -1
  90. package/dist/index.cjs +5 -2
  91. package/dist/index.cjs.map +1 -1
  92. package/dist/index.d.cts +4 -1
  93. package/dist/index.d.ts +4 -1
  94. package/dist/index.js +5 -2
  95. package/dist/index.js.map +1 -1
  96. package/package.json +4 -2
  97. package/src/bundler/index.ts +7 -0
  98. package/src/bundler/presets/css.ts +21 -0
  99. package/src/bundler/presets/index.ts +47 -0
  100. package/src/bundler/presets/types.ts +10 -0
  101. package/src/bundler/selective-bundler.ts +9 -0
  102. package/src/bundler/types.ts +1 -0
  103. package/src/cli/commands/bundle.test.ts +34 -0
  104. package/src/cli/commands/bundle.ts +37 -11
  105. package/src/cli/commands/list.ts +36 -4
  106. package/src/cli/commands/presets.ts +81 -0
  107. package/src/cli/index.ts +12 -1
  108. package/src/cli/output-generator.ts +8 -2
  109. package/src/cli/version-info.ts +93 -0
  110. package/src/schemas/types/css-color/from-hsl-color.tokenscript +17 -4
  111. package/src/schemas/types/css-color/from-hwb-color.tokenscript +17 -4
  112. package/src/schemas/types/css-color/from-lab-color.tokenscript +17 -4
  113. package/src/schemas/types/css-color/from-lch-color.tokenscript +17 -4
  114. package/src/schemas/types/css-color/from-oklab-color.tokenscript +17 -4
  115. package/src/schemas/types/css-color/from-oklch-color.tokenscript +17 -4
  116. package/src/schemas/types/css-color/from-p3-color.tokenscript +17 -4
  117. package/src/schemas/types/css-color/from-rgb-color.tokenscript +17 -4
  118. package/src/schemas/types/css-color/from-srgb-color.tokenscript +17 -4
  119. package/src/schemas/types/css-color/from-xyz-d50-color.tokenscript +17 -4
  120. package/src/schemas/types/css-color/from-xyz-d65-color.tokenscript +17 -4
  121. package/src/schemas/types/css-color/unit.test.ts +216 -0
  122. package/src/schemas/types/hex-color/unit.test.ts +18 -0
  123. package/src/schemas/types/hsl-color/hsla-initializer.tokenscript +17 -0
  124. package/src/schemas/types/hsl-color/initializer.tokenscript +6 -1
  125. package/src/schemas/types/hsl-color/schema.json +9 -0
  126. package/src/schemas/types/hsl-color/unit.test.ts +95 -1
  127. package/src/schemas/types/hsv-color/initializer.tokenscript +6 -1
  128. package/src/schemas/types/hsv-color/unit.test.ts +44 -0
  129. package/src/schemas/types/hwb-color/hwba-initializer.tokenscript +17 -0
  130. package/src/schemas/types/hwb-color/initializer.tokenscript +6 -1
  131. package/src/schemas/types/hwb-color/schema.json +9 -0
  132. package/src/schemas/types/hwb-color/unit.test.ts +70 -0
  133. package/src/schemas/types/lab-color/initializer.tokenscript +6 -1
  134. package/src/schemas/types/lab-color/unit.test.ts +44 -0
  135. package/src/schemas/types/lch-color/initializer.tokenscript +6 -1
  136. package/src/schemas/types/lch-color/unit.test.ts +44 -0
  137. package/src/schemas/types/okhsl-color/initializer.tokenscript +8 -1
  138. package/src/schemas/types/okhsl-color/unit.test.ts +37 -0
  139. package/src/schemas/types/okhsv-color/initializer.tokenscript +8 -1
  140. package/src/schemas/types/okhsv-color/unit.test.ts +37 -0
  141. package/src/schemas/types/oklab-color/initializer.tokenscript +6 -1
  142. package/src/schemas/types/oklab-color/unit.test.ts +58 -0
  143. package/src/schemas/types/oklch-color/initializer.tokenscript +6 -1
  144. package/src/schemas/types/oklch-color/unit.test.ts +58 -0
  145. package/src/schemas/types/p3-color/initializer.tokenscript +6 -1
  146. package/src/schemas/types/p3-color/unit.test.ts +47 -0
  147. package/src/schemas/types/rgb-color/initializer.tokenscript +7 -1
  148. package/src/schemas/types/rgb-color/rgba-initializer.tokenscript +17 -0
  149. package/src/schemas/types/rgb-color/schema.json +9 -0
  150. package/src/schemas/types/rgb-color/unit.test.ts +110 -1
  151. package/src/schemas/types/srgb-color/initializer.tokenscript +6 -1
  152. package/src/schemas/types/srgb-color/unit.test.ts +89 -0
  153. package/bundled/types/rgba-color.json +0 -89
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Presets command - list available bundle presets
3
+ */
4
+
5
+ /// <reference types="../../../types/ulog" />
6
+
7
+ import anylogger from "ulog";
8
+ import { BUNDLE_PRESETS } from "@/bundler/presets/index";
9
+
10
+ const log = anylogger("presets");
11
+
12
+ /**
13
+ * Format preset information for display
14
+ */
15
+ function formatPresetInfo(): string {
16
+ const lines: string[] = [];
17
+
18
+ lines.push("=".repeat(60));
19
+ lines.push("Available Bundle Presets");
20
+ lines.push("=".repeat(60));
21
+
22
+ for (const [key, preset] of Object.entries(BUNDLE_PRESETS)) {
23
+ lines.push("");
24
+ lines.push(`preset:${key}`);
25
+ lines.push(` ${preset.description}`);
26
+
27
+ // Types section
28
+ const typesCount =
29
+ preset.types.length === 1 && preset.types[0] === "*" ? "all" : preset.types.length;
30
+ lines.push("");
31
+ lines.push(` Types (${typesCount}):`);
32
+ if (preset.types.length > 0 && preset.types[0] !== "*") {
33
+ for (const type of preset.types) {
34
+ lines.push(` - ${type}`);
35
+ }
36
+ } else {
37
+ lines.push(` - all`);
38
+ }
39
+
40
+ // Functions section
41
+ const functionsCount =
42
+ preset.functions.length === 1 && preset.functions[0] === "*"
43
+ ? "all"
44
+ : preset.functions.length;
45
+ lines.push("");
46
+ lines.push(` Functions (${functionsCount}):`);
47
+ if (preset.functions.length > 0 && preset.functions[0] !== "*") {
48
+ for (const func of preset.functions) {
49
+ lines.push(` - ${func}`);
50
+ }
51
+ } else {
52
+ lines.push(` - all`);
53
+ }
54
+ }
55
+
56
+ lines.push("");
57
+ lines.push("=".repeat(60));
58
+ lines.push("Usage Examples:");
59
+ lines.push("=".repeat(60));
60
+ lines.push("npx tokenscript-schemas bundle preset:css");
61
+ lines.push("npx tokenscript-schemas bundle preset:css type:oklab-color");
62
+ lines.push("npx tokenscript-schemas bundle type:hex-color function:lighten");
63
+ lines.push("");
64
+ lines.push("Note: You can combine multiple presets and specific schemas!");
65
+
66
+ return lines.join("\n");
67
+ }
68
+
69
+ export async function handlePresetsCommand(): Promise<void> {
70
+ try {
71
+ log.info("Listing available presets");
72
+
73
+ const output = formatPresetInfo();
74
+ console.log(output);
75
+
76
+ log.info(`Listed ${Object.keys(BUNDLE_PRESETS).length} presets`);
77
+ } catch (error) {
78
+ log.error("Failed to list presets:", error);
79
+ throw error;
80
+ }
81
+ }
package/src/cli/index.ts CHANGED
@@ -10,6 +10,7 @@ import cac from "cac";
10
10
  import anylogger from "ulog";
11
11
  import { type BundleOptions, handleBundleCommand } from "./commands/bundle.js";
12
12
  import { handleListCommand, type ListOptions } from "./commands/list.js";
13
+ import { handlePresetsCommand } from "./commands/presets.js";
13
14
 
14
15
  const log = anylogger("cli");
15
16
 
@@ -44,7 +45,17 @@ cli
44
45
  }
45
46
  });
46
47
 
48
+ // Presets command
49
+ cli.command("presets", "List available bundle presets").action(async () => {
50
+ try {
51
+ await handlePresetsCommand();
52
+ } catch (error) {
53
+ log.error("Error:", error);
54
+ process.exit(1);
55
+ }
56
+ });
57
+
47
58
  cli.help();
48
- cli.version("0.0.13");
59
+ cli.version("0.0.14");
49
60
 
50
61
  cli.parse();
@@ -3,10 +3,12 @@
3
3
  */
4
4
 
5
5
  import type { BundledSchemaEntry } from "@/bundler/selective-bundler.js";
6
+ import { getVersionInfo } from "./version-info.js";
6
7
 
7
8
  export interface OutputGeneratorOptions {
8
9
  schemas: BundledSchemaEntry[];
9
10
  includeHelper?: boolean; // Include makeConfig() helper
11
+ generatedBy?: string; // CLI command used to generate
10
12
  }
11
13
 
12
14
  /**
@@ -16,14 +18,18 @@ export function generateOutput(options: OutputGeneratorOptions): string {
16
18
  const { schemas, includeHelper = true } = options;
17
19
 
18
20
  const timestamp = new Date().toISOString();
19
- const schemaList = schemas.map((s) => s.uri).join(", ");
21
+ const versionInfo = getVersionInfo();
20
22
 
21
23
  const lines: string[] = [];
22
24
 
23
25
  // Header comment
24
26
  lines.push("// Auto-generated by @tokens-studio/tokenscript-schemas");
27
+ lines.push(`// Version: ${versionInfo.version}`);
28
+ lines.push(`// GitHub: ${versionInfo.githubUrl}`);
29
+ if (options.generatedBy) {
30
+ lines.push(`// Command: ${options.generatedBy}`);
31
+ }
25
32
  lines.push(`// Generated: ${timestamp}`);
26
- lines.push(`// Schemas: ${schemaList}`);
27
33
  lines.push("");
28
34
 
29
35
  // Import statement
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Get version information for the bundled output
3
+ */
4
+
5
+ import { execSync } from "node:child_process";
6
+ import { readFileSync } from "node:fs";
7
+ import { dirname, join } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = dirname(__filename);
12
+
13
+ export interface VersionInfo {
14
+ version: string; // Package version or git SHA
15
+ githubUrl: string;
16
+ isLocal: boolean; // true if running from local repo (not published package)
17
+ }
18
+
19
+ /**
20
+ * Get the current git SHA
21
+ */
22
+ function getGitSha(): string | null {
23
+ try {
24
+ return execSync("git rev-parse --short HEAD", {
25
+ encoding: "utf-8",
26
+ stdio: ["pipe", "pipe", "ignore"],
27
+ }).trim();
28
+ } catch {
29
+ return null;
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Check if we're running from a local git repo
35
+ */
36
+ function isGitRepo(): boolean {
37
+ try {
38
+ execSync("git rev-parse --git-dir", {
39
+ stdio: ["pipe", "pipe", "ignore"],
40
+ });
41
+ return true;
42
+ } catch {
43
+ return false;
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Get version from package.json
49
+ */
50
+ function getPackageVersion(): string {
51
+ try {
52
+ // Try multiple paths for package.json
53
+ const paths = [
54
+ join(__dirname, "../../package.json"), // From src/cli
55
+ join(__dirname, "../../../package.json"), // From dist/cli
56
+ ];
57
+
58
+ for (const path of paths) {
59
+ try {
60
+ const pkg = JSON.parse(readFileSync(path, "utf-8"));
61
+ return pkg.version || "unknown";
62
+ } catch {
63
+ // Try next path
64
+ }
65
+ }
66
+
67
+ return "unknown";
68
+ } catch {
69
+ return "unknown";
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Get version information for the bundle
75
+ */
76
+ export function getVersionInfo(): VersionInfo {
77
+ const githubUrl = "https://github.com/tokens-studio/tokenscript-schemas";
78
+ const isLocal = isGitRepo();
79
+
80
+ let version: string;
81
+ if (isLocal) {
82
+ const sha = getGitSha();
83
+ version = sha ? `local-${sha}` : "local";
84
+ } else {
85
+ version = getPackageVersion();
86
+ }
87
+
88
+ return {
89
+ version,
90
+ githubUrl,
91
+ isLocal,
92
+ };
93
+ }
@@ -1,16 +1,29 @@
1
1
  // HSL to CSS Conversion
2
2
  // Converts HSL to CSS hsl() syntax
3
- // CSS Color Level 4: hsl(h s l) where s and l are percentages
3
+ // CSS Color Level 4: hsl(h s l) or hsl(h s l / alpha) where s and l are percentages
4
4
  //
5
- // Input: Color.HSL with h (0-360), s (0-1), l (0-1)
6
- // Output: Color.CSS with value like "hsl(120 50% 75%)"
5
+ // Input: Color.HSL with h (0-360), s (0-1), l (0-1), optional alpha (0-1)
6
+ // Output: Color.CSS with value like "hsl(120 50% 75%)" or "hsl(120 50% 75% / 0.5)"
7
+ // Note: Alpha is omitted if null or 1.0 (fully opaque)
7
8
 
8
9
  variable precision: Number = 100;
9
10
  variable h: Number = round({input}.h * precision) / precision;
10
11
  variable s: Number = round({input}.s * 100 * precision) / precision;
11
12
  variable l: Number = round({input}.l * 100 * precision) / precision;
12
13
 
14
+ variable css_value: String = "hsl(".concat(h.to_string()).concat(" ").concat(s.to_string()).concat("% ").concat(l.to_string()).concat("%");
15
+
16
+ // Add alpha if present, not null, and not 1.0 (per CSS convention)
17
+ variable alpha: Number = {input}.alpha;
18
+ if (alpha != null) [
19
+ if (alpha != 1) [
20
+ css_value = css_value.concat(" / ").concat(alpha.to_string());
21
+ ];
22
+ ];
23
+
24
+ css_value = css_value.concat(")");
25
+
13
26
  variable output: Color.CSS;
14
- output.value = "hsl(".concat(h.to_string()).concat(" ").concat(s.to_string()).concat("% ").concat(l.to_string()).concat("%)");
27
+ output.value = css_value;
15
28
  return output;
16
29
 
@@ -1,16 +1,29 @@
1
1
  // HWB to CSS Conversion
2
2
  // Converts HWB to CSS hwb() syntax
3
- // CSS Color Level 4: hwb(h w b) where w and b are percentages
3
+ // CSS Color Level 4: hwb(h w b) or hwb(h w b / alpha) where w and b are percentages
4
4
  //
5
- // Input: Color.HWB with h (0-360), w (0-1), b (0-1)
6
- // Output: Color.CSS with value like "hwb(120 10% 20%)"
5
+ // Input: Color.HWB with h (0-360), w (0-1), b (0-1), optional alpha (0-1)
6
+ // Output: Color.CSS with value like "hwb(120 10% 20%)" or "hwb(120 10% 20% / 0.5)"
7
+ // Note: Alpha is omitted if null or 1.0 (fully opaque)
7
8
 
8
9
  variable precision: Number = 100;
9
10
  variable h: Number = round({input}.h * precision) / precision;
10
11
  variable w: Number = round({input}.w * 100 * precision) / precision;
11
12
  variable b_val: Number = round({input}.b * 100 * precision) / precision;
12
13
 
14
+ variable css_value: String = "hwb(".concat(h.to_string()).concat(" ").concat(w.to_string()).concat("% ").concat(b_val.to_string()).concat("%");
15
+
16
+ // Add alpha if present, not null, and not 1.0 (per CSS convention)
17
+ variable alpha: Number = {input}.alpha;
18
+ if (alpha != null) [
19
+ if (alpha != 1) [
20
+ css_value = css_value.concat(" / ").concat(alpha.to_string());
21
+ ];
22
+ ];
23
+
24
+ css_value = css_value.concat(")");
25
+
13
26
  variable output: Color.CSS;
14
- output.value = "hwb(".concat(h.to_string()).concat(" ").concat(w.to_string()).concat("% ").concat(b_val.to_string()).concat("%)");
27
+ output.value = css_value;
15
28
  return output;
16
29
 
@@ -1,16 +1,29 @@
1
1
  // CIE Lab to CSS Conversion
2
2
  // Converts CIE Lab to CSS lab() syntax
3
- // CSS Color Level 4: lab(L a b) where L is a percentage
3
+ // CSS Color Level 4: lab(L a b) or lab(L a b / alpha) where L is a percentage
4
4
  //
5
- // Input: Color.Lab with l (0-100), a, b
6
- // Output: Color.CSS with value like "lab(75% 20 -30)"
5
+ // Input: Color.Lab with l (0-100), a, b, optional alpha (0-1)
6
+ // Output: Color.CSS with value like "lab(75% 20 -30)" or "lab(75% 20 -30 / 0.5)"
7
+ // Note: Alpha is omitted if null or 1.0 (fully opaque)
7
8
 
8
9
  variable precision: Number = 10000;
9
10
  variable l: Number = round({input}.l * precision) / precision;
10
11
  variable a: Number = round({input}.a * precision) / precision;
11
12
  variable b_val: Number = round({input}.b * precision) / precision;
12
13
 
14
+ variable css_value: String = "lab(".concat(l.to_string()).concat("% ").concat(a.to_string()).concat(" ").concat(b_val.to_string());
15
+
16
+ // Add alpha if present, not null, and not 1.0 (per CSS convention)
17
+ variable alpha: Number = {input}.alpha;
18
+ if (alpha != null) [
19
+ if (alpha != 1) [
20
+ css_value = css_value.concat(" / ").concat(alpha.to_string());
21
+ ];
22
+ ];
23
+
24
+ css_value = css_value.concat(")");
25
+
13
26
  variable output: Color.CSS;
14
- output.value = "lab(".concat(l.to_string()).concat("% ").concat(a.to_string()).concat(" ").concat(b_val.to_string()).concat(")");
27
+ output.value = css_value;
15
28
  return output;
16
29
 
@@ -1,16 +1,29 @@
1
1
  // CIE LCH to CSS Conversion
2
2
  // Converts CIE LCH to CSS lch() syntax
3
- // CSS Color Level 4: lch(L C H) where L is a percentage
3
+ // CSS Color Level 4: lch(L C H) or lch(L C H / alpha) where L is a percentage
4
4
  //
5
- // Input: Color.LCH with l (0-100), c, h (0-360)
6
- // Output: Color.CSS with value like "lch(75% 50 180)"
5
+ // Input: Color.LCH with l (0-100), c, h (0-360), optional alpha (0-1)
6
+ // Output: Color.CSS with value like "lch(75% 50 180)" or "lch(75% 50 180 / 0.5)"
7
+ // Note: Alpha is omitted if null or 1.0 (fully opaque)
7
8
 
8
9
  variable precision: Number = 10000;
9
10
  variable l: Number = round({input}.l * precision) / precision;
10
11
  variable c: Number = round({input}.c * precision) / precision;
11
12
  variable h: Number = round({input}.h * precision) / precision;
12
13
 
14
+ variable css_value: String = "lch(".concat(l.to_string()).concat("% ").concat(c.to_string()).concat(" ").concat(h.to_string());
15
+
16
+ // Add alpha if present, not null, and not 1.0 (per CSS convention)
17
+ variable alpha: Number = {input}.alpha;
18
+ if (alpha != null) [
19
+ if (alpha != 1) [
20
+ css_value = css_value.concat(" / ").concat(alpha.to_string());
21
+ ];
22
+ ];
23
+
24
+ css_value = css_value.concat(")");
25
+
13
26
  variable output: Color.CSS;
14
- output.value = "lch(".concat(l.to_string()).concat("% ").concat(c.to_string()).concat(" ").concat(h.to_string()).concat(")");
27
+ output.value = css_value;
15
28
  return output;
16
29
 
@@ -1,16 +1,29 @@
1
1
  // OKLab to CSS Conversion
2
2
  // Converts OKLab to CSS oklab() syntax
3
- // CSS Color Level 4: oklab(L a b) where L is 0-1 decimal
3
+ // CSS Color Level 4: oklab(L a b) or oklab(L a b / alpha) where L is 0-1 decimal
4
4
  //
5
- // Input: Color.OKLab with l (0-1), a, b
6
- // Output: Color.CSS with value like "oklab(0.7 0.1 -0.05)"
5
+ // Input: Color.OKLab with l (0-1), a, b, optional alpha (0-1)
6
+ // Output: Color.CSS with value like "oklab(0.7 0.1 -0.05)" or "oklab(0.7 0.1 -0.05 / 0.5)"
7
+ // Note: Alpha is omitted if null or 1.0 (fully opaque)
7
8
 
8
9
  variable precision: Number = 100000;
9
10
  variable l: Number = round({input}.l * precision) / precision;
10
11
  variable a: Number = round({input}.a * precision) / precision;
11
12
  variable b_val: Number = round({input}.b * precision) / precision;
12
13
 
14
+ variable css_value: String = "oklab(".concat(l.to_string()).concat(" ").concat(a.to_string()).concat(" ").concat(b_val.to_string());
15
+
16
+ // Add alpha if present, not null, and not 1.0 (per CSS convention)
17
+ variable alpha: Number = {input}.alpha;
18
+ if (alpha != null) [
19
+ if (alpha != 1) [
20
+ css_value = css_value.concat(" / ").concat(alpha.to_string());
21
+ ];
22
+ ];
23
+
24
+ css_value = css_value.concat(")");
25
+
13
26
  variable output: Color.CSS;
14
- output.value = "oklab(".concat(l.to_string()).concat(" ").concat(a.to_string()).concat(" ").concat(b_val.to_string()).concat(")");
27
+ output.value = css_value;
15
28
  return output;
16
29
 
@@ -1,16 +1,29 @@
1
1
  // OKLCH to CSS Conversion
2
2
  // Converts OKLCH to CSS oklch() syntax
3
- // CSS Color Level 4: oklch(L C H) where L is 0-1 decimal
3
+ // CSS Color Level 4: oklch(L C H) or oklch(L C H / alpha) where L is 0-1 decimal
4
4
  //
5
- // Input: Color.OKLCH with l (0-1), c, h (0-360)
6
- // Output: Color.CSS with value like "oklch(0.7 0.15 180)"
5
+ // Input: Color.OKLCH with l (0-1), c, h (0-360), optional alpha (0-1)
6
+ // Output: Color.CSS with value like "oklch(0.7 0.15 180)" or "oklch(0.7 0.15 180 / 0.5)"
7
+ // Note: Alpha is omitted if null or 1.0 (fully opaque)
7
8
 
8
9
  variable precision: Number = 100000;
9
10
  variable l: Number = round({input}.l * precision) / precision;
10
11
  variable c: Number = round({input}.c * precision) / precision;
11
12
  variable h: Number = round({input}.h * precision) / precision;
12
13
 
14
+ variable css_value: String = "oklch(".concat(l.to_string()).concat(" ").concat(c.to_string()).concat(" ").concat(h.to_string());
15
+
16
+ // Add alpha if present, not null, and not 1.0 (per CSS convention)
17
+ variable alpha: Number = {input}.alpha;
18
+ if (alpha != null) [
19
+ if (alpha != 1) [
20
+ css_value = css_value.concat(" / ").concat(alpha.to_string());
21
+ ];
22
+ ];
23
+
24
+ css_value = css_value.concat(")");
25
+
13
26
  variable output: Color.CSS;
14
- output.value = "oklch(".concat(l.to_string()).concat(" ").concat(c.to_string()).concat(" ").concat(h.to_string()).concat(")");
27
+ output.value = css_value;
15
28
  return output;
16
29
 
@@ -1,16 +1,29 @@
1
1
  // Display-P3 to CSS Conversion
2
2
  // Converts Display-P3 to CSS color(display-p3) syntax
3
- // CSS Color Level 4: color(display-p3 r g b)
3
+ // CSS Color Level 4: color(display-p3 r g b) or color(display-p3 r g b / alpha)
4
4
  //
5
- // Input: Color.P3 with r, g, b in 0-1 range
6
- // Output: Color.CSS with value like "color(display-p3 1 0.5 0.25)"
5
+ // Input: Color.P3 with r, g, b in 0-1 range, optional alpha (0-1)
6
+ // Output: Color.CSS with value like "color(display-p3 1 0.5 0.25)" or "color(display-p3 1 0.5 0.25 / 0.5)"
7
+ // Note: Alpha is omitted if null or 1.0 (fully opaque)
7
8
 
8
9
  variable precision: Number = 100000;
9
10
  variable r: Number = round({input}.r * precision) / precision;
10
11
  variable g: Number = round({input}.g * precision) / precision;
11
12
  variable b: Number = round({input}.b * precision) / precision;
12
13
 
14
+ variable css_value: String = "color(display-p3 ".concat(r.to_string()).concat(" ").concat(g.to_string()).concat(" ").concat(b.to_string());
15
+
16
+ // Add alpha if present, not null, and not 1.0 (per CSS convention)
17
+ variable alpha: Number = {input}.alpha;
18
+ if (alpha != null) [
19
+ if (alpha != 1) [
20
+ css_value = css_value.concat(" / ").concat(alpha.to_string());
21
+ ];
22
+ ];
23
+
24
+ css_value = css_value.concat(")");
25
+
13
26
  variable output: Color.CSS;
14
- output.value = "color(display-p3 ".concat(r.to_string()).concat(" ").concat(g.to_string()).concat(" ").concat(b.to_string()).concat(")");
27
+ output.value = css_value;
15
28
  return output;
16
29
 
@@ -1,15 +1,28 @@
1
1
  // RGB to CSS Conversion
2
2
  // Converts RGB (0-255) to CSS rgb() syntax
3
- // CSS Color Level 4 modern syntax: rgb(r g b)
3
+ // CSS Color Level 4 modern syntax: rgb(r g b) or rgb(r g b / alpha)
4
4
  //
5
- // Input: Color.Rgb with r, g, b in 0-255 range
6
- // Output: Color.CSS with value like "rgb(255 128 64)"
5
+ // Input: Color.Rgb with r, g, b in 0-255 range, optional alpha (0-1)
6
+ // Output: Color.CSS with value like "rgb(255 128 64)" or "rgb(255 128 64 / 0.5)"
7
+ // Note: Alpha is omitted if null or 1.0 (fully opaque)
7
8
 
8
9
  variable r: Number = round({input}.r);
9
10
  variable g: Number = round({input}.g);
10
11
  variable b: Number = round({input}.b);
11
12
 
13
+ variable css_value: String = "rgb(".concat(r.to_string()).concat(" ").concat(g.to_string()).concat(" ").concat(b.to_string());
14
+
15
+ // Add alpha if present, not null, and not 1.0 (per CSS convention)
16
+ variable alpha: Number = {input}.alpha;
17
+ if (alpha != null) [
18
+ if (alpha != 1) [
19
+ css_value = css_value.concat(" / ").concat(alpha.to_string());
20
+ ];
21
+ ];
22
+
23
+ css_value = css_value.concat(")");
24
+
12
25
  variable output: Color.CSS;
13
- output.value = "rgb(".concat(r.to_string()).concat(" ").concat(g.to_string()).concat(" ").concat(b.to_string()).concat(")");
26
+ output.value = css_value;
14
27
  return output;
15
28
 
@@ -1,16 +1,29 @@
1
1
  // sRGB to CSS Conversion
2
2
  // Converts sRGB (0-1) to CSS color(srgb) syntax
3
- // CSS Color Level 4: color(srgb r g b)
3
+ // CSS Color Level 4: color(srgb r g b) or color(srgb r g b / alpha)
4
4
  //
5
- // Input: Color.SRGB with r, g, b in 0-1 range
6
- // Output: Color.CSS with value like "color(srgb 1 0.5 0.25)"
5
+ // Input: Color.SRGB with r, g, b in 0-1 range, optional alpha (0-1)
6
+ // Output: Color.CSS with value like "color(srgb 1 0.5 0.25)" or "color(srgb 1 0.5 0.25 / 0.5)"
7
+ // Note: Alpha is omitted if null or 1.0 (fully opaque)
7
8
 
8
9
  variable precision: Number = 100000;
9
10
  variable r: Number = round({input}.r * precision) / precision;
10
11
  variable g: Number = round({input}.g * precision) / precision;
11
12
  variable b: Number = round({input}.b * precision) / precision;
12
13
 
14
+ variable css_value: String = "color(srgb ".concat(r.to_string()).concat(" ").concat(g.to_string()).concat(" ").concat(b.to_string());
15
+
16
+ // Add alpha if present, not null, and not 1.0 (per CSS convention)
17
+ variable alpha: Number = {input}.alpha;
18
+ if (alpha != null) [
19
+ if (alpha != 1) [
20
+ css_value = css_value.concat(" / ").concat(alpha.to_string());
21
+ ];
22
+ ];
23
+
24
+ css_value = css_value.concat(")");
25
+
13
26
  variable output: Color.CSS;
14
- output.value = "color(srgb ".concat(r.to_string()).concat(" ").concat(g.to_string()).concat(" ").concat(b.to_string()).concat(")");
27
+ output.value = css_value;
15
28
  return output;
16
29
 
@@ -1,16 +1,29 @@
1
1
  // XYZ-D50 to CSS Conversion
2
2
  // Converts XYZ-D50 to CSS color(xyz-d50) syntax
3
- // CSS Color Level 4: color(xyz-d50 x y z)
3
+ // CSS Color Level 4: color(xyz-d50 x y z) or color(xyz-d50 x y z / alpha)
4
4
  //
5
- // Input: Color.XYZD50 with x, y, z tristimulus values
6
- // Output: Color.CSS with value like "color(xyz-d50 0.4360 0.2225 0.0139)"
5
+ // Input: Color.XYZD50 with x, y, z tristimulus values, optional alpha (0-1)
6
+ // Output: Color.CSS with value like "color(xyz-d50 0.4360 0.2225 0.0139)" or "color(xyz-d50 0.4360 0.2225 0.0139 / 0.5)"
7
+ // Note: Alpha is omitted if null or 1.0 (fully opaque)
7
8
 
8
9
  variable precision: Number = 100000;
9
10
  variable x: Number = round({input}.x * precision) / precision;
10
11
  variable y: Number = round({input}.y * precision) / precision;
11
12
  variable z: Number = round({input}.z * precision) / precision;
12
13
 
14
+ variable css_value: String = "color(xyz-d50 ".concat(x.to_string()).concat(" ").concat(y.to_string()).concat(" ").concat(z.to_string());
15
+
16
+ // Add alpha if present, not null, and not 1.0 (per CSS convention)
17
+ variable alpha: Number = {input}.alpha;
18
+ if (alpha != null) [
19
+ if (alpha != 1) [
20
+ css_value = css_value.concat(" / ").concat(alpha.to_string());
21
+ ];
22
+ ];
23
+
24
+ css_value = css_value.concat(")");
25
+
13
26
  variable output: Color.CSS;
14
- output.value = "color(xyz-d50 ".concat(x.to_string()).concat(" ").concat(y.to_string()).concat(" ").concat(z.to_string()).concat(")");
27
+ output.value = css_value;
15
28
  return output;
16
29
 
@@ -1,16 +1,29 @@
1
1
  // XYZ-D65 to CSS Conversion
2
2
  // Converts XYZ-D65 to CSS color(xyz-d65) syntax
3
- // CSS Color Level 4: color(xyz-d65 x y z) or color(xyz x y z)
3
+ // CSS Color Level 4: color(xyz-d65 x y z) or color(xyz-d65 x y z / alpha)
4
4
  //
5
- // Input: Color.XYZD65 with x, y, z tristimulus values
6
- // Output: Color.CSS with value like "color(xyz-d65 0.4124 0.2126 0.0193)"
5
+ // Input: Color.XYZD65 with x, y, z tristimulus values, optional alpha (0-1)
6
+ // Output: Color.CSS with value like "color(xyz-d65 0.4124 0.2126 0.0193)" or "color(xyz-d65 0.4124 0.2126 0.0193 / 0.5)"
7
+ // Note: Alpha is omitted if null or 1.0 (fully opaque)
7
8
 
8
9
  variable precision: Number = 100000;
9
10
  variable x: Number = round({input}.x * precision) / precision;
10
11
  variable y: Number = round({input}.y * precision) / precision;
11
12
  variable z: Number = round({input}.z * precision) / precision;
12
13
 
14
+ variable css_value: String = "color(xyz-d65 ".concat(x.to_string()).concat(" ").concat(y.to_string()).concat(" ").concat(z.to_string());
15
+
16
+ // Add alpha if present, not null, and not 1.0 (per CSS convention)
17
+ variable alpha: Number = {input}.alpha;
18
+ if (alpha != null) [
19
+ if (alpha != 1) [
20
+ css_value = css_value.concat(" / ").concat(alpha.to_string());
21
+ ];
22
+ ];
23
+
24
+ css_value = css_value.concat(")");
25
+
13
26
  variable output: Color.CSS;
14
- output.value = "color(xyz-d65 ".concat(x.to_string()).concat(" ").concat(y.to_string()).concat(" ").concat(z.to_string()).concat(")");
27
+ output.value = css_value;
15
28
  return output;
16
29