@tokens-studio/tokenscript-schemas 0.1.1 → 0.1.3

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 (105) hide show
  1. package/README.md +31 -7
  2. package/dist/cli/index.cjs +21 -35
  3. package/dist/cli/index.cjs.map +1 -1
  4. package/dist/cli/index.js +21 -35
  5. package/dist/cli/index.js.map +1 -1
  6. package/dist/index.cjs +19 -19
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.cts +3 -3
  9. package/dist/index.d.ts +3 -3
  10. package/dist/index.js +19 -19
  11. package/dist/index.js.map +1 -1
  12. package/package.json +3 -3
  13. package/src/bundler/{bundle-schema.ts → build-schema.ts} +2 -2
  14. package/src/bundler/index.ts +25 -25
  15. package/src/bundler/schema-dependency-resolver.ts +3 -3
  16. package/src/bundler/selective-bundler.ts +3 -3
  17. package/src/cli/commands/bundle.test.ts +95 -1
  18. package/src/cli/commands/bundle.ts +11 -1
  19. package/src/cli/index.ts +1 -0
  20. package/src/cli/version-info.ts +16 -18
  21. package/bundled/functions/adjust_chroma.json +0 -60
  22. package/bundled/functions/adjust_hue.json +0 -60
  23. package/bundled/functions/adjust_lightness.json +0 -60
  24. package/bundled/functions/adjust_to_contrast.json +0 -67
  25. package/bundled/functions/alpha_blend.json +0 -31
  26. package/bundled/functions/alpha_scale.json +0 -27
  27. package/bundled/functions/analogous.json +0 -32
  28. package/bundled/functions/apca_contrast.json +0 -27
  29. package/bundled/functions/are_similar.json +0 -73
  30. package/bundled/functions/auto_text_color.json +0 -66
  31. package/bundled/functions/best_contrast.json +0 -28
  32. package/bundled/functions/chroma.json +0 -54
  33. package/bundled/functions/clamp_chroma.json +0 -66
  34. package/bundled/functions/clamp_lightness.json +0 -66
  35. package/bundled/functions/clamp_to_gamut.json +0 -23
  36. package/bundled/functions/complement.json +0 -24
  37. package/bundled/functions/contrast_ratio.json +0 -27
  38. package/bundled/functions/cooler.json +0 -52
  39. package/bundled/functions/darken.json +0 -28
  40. package/bundled/functions/delta_e_2000.json +0 -40
  41. package/bundled/functions/delta_e_76.json +0 -27
  42. package/bundled/functions/delta_e_ok.json +0 -27
  43. package/bundled/functions/desaturate.json +0 -28
  44. package/bundled/functions/distributed.json +0 -36
  45. package/bundled/functions/diverging.json +0 -36
  46. package/bundled/functions/grayscale.json +0 -24
  47. package/bundled/functions/harmonize.json +0 -65
  48. package/bundled/functions/hue.json +0 -54
  49. package/bundled/functions/hue_difference.json +0 -27
  50. package/bundled/functions/in_gamut.json +0 -27
  51. package/bundled/functions/interpolate.json +0 -66
  52. package/bundled/functions/invert.json +0 -23
  53. package/bundled/functions/is_cool.json +0 -23
  54. package/bundled/functions/is_dark.json +0 -27
  55. package/bundled/functions/is_light.json +0 -27
  56. package/bundled/functions/is_neutral.json +0 -65
  57. package/bundled/functions/is_warm.json +0 -23
  58. package/bundled/functions/lighten.json +0 -28
  59. package/bundled/functions/lightness.json +0 -61
  60. package/bundled/functions/luminance.json +0 -23
  61. package/bundled/functions/meets_contrast.json +0 -31
  62. package/bundled/functions/mix.json +0 -32
  63. package/bundled/functions/monochromatic.json +0 -28
  64. package/bundled/functions/muted.json +0 -59
  65. package/bundled/functions/neutral_variant.json +0 -59
  66. package/bundled/functions/relative_luminance.json +0 -61
  67. package/bundled/functions/rotate_hue.json +0 -28
  68. package/bundled/functions/saturate.json +0 -28
  69. package/bundled/functions/scale_chroma.json +0 -60
  70. package/bundled/functions/scale_lightness.json +0 -60
  71. package/bundled/functions/sepia.json +0 -59
  72. package/bundled/functions/set_chroma.json +0 -28
  73. package/bundled/functions/set_hue.json +0 -28
  74. package/bundled/functions/set_lightness.json +0 -28
  75. package/bundled/functions/shade_scale.json +0 -28
  76. package/bundled/functions/split_complement.json +0 -28
  77. package/bundled/functions/steps.json +0 -32
  78. package/bundled/functions/tetradic.json +0 -24
  79. package/bundled/functions/tint_scale.json +0 -36
  80. package/bundled/functions/to_gamut.json +0 -59
  81. package/bundled/functions/triadic.json +0 -24
  82. package/bundled/functions/vibrant.json +0 -59
  83. package/bundled/functions/warmer.json +0 -52
  84. package/bundled/functions/wcag_level.json +0 -60
  85. package/bundled/functions.json +0 -2624
  86. package/bundled/registry.json +0 -3833
  87. package/bundled/types/css-color.json +0 -151
  88. package/bundled/types/hex-color.json +0 -25
  89. package/bundled/types/hsl-color.json +0 -66
  90. package/bundled/types/hsv-color.json +0 -57
  91. package/bundled/types/hwb-color.json +0 -66
  92. package/bundled/types/lab-color.json +0 -57
  93. package/bundled/types/lch-color.json +0 -57
  94. package/bundled/types/okhsl-color.json +0 -57
  95. package/bundled/types/okhsv-color.json +0 -57
  96. package/bundled/types/oklab-color.json +0 -87
  97. package/bundled/types/oklch-color.json +0 -57
  98. package/bundled/types/p3-color.json +0 -57
  99. package/bundled/types/p3-linear-color.json +0 -57
  100. package/bundled/types/rgb-color.json +0 -73
  101. package/bundled/types/srgb-color.json +0 -77
  102. package/bundled/types/srgb-linear-color.json +0 -67
  103. package/bundled/types/xyz-d50-color.json +0 -57
  104. package/bundled/types/xyz-d65-color.json +0 -77
  105. package/bundled/types.json +0 -1207
@@ -1,61 +0,0 @@
1
- {
2
- "name": "lightness",
3
- "type": "function",
4
- "description": "Extracts the perceptual lightness value from any color using OKLCH. Returns a value from 0 (black) to 1 (white). This is the 'L' in OKLCH, which is perceptually uniform - equal steps in L appear as equal steps in lightness to human vision. Essential for creating perceptually even color scales.",
5
- "keyword": "lightness",
6
- "requirements": [
7
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/srgb-color/0/",
8
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/oklch-color/0/"
9
- ],
10
- "schema": {
11
- "type": "object",
12
- "properties": {
13
- "input": {
14
- "type": "array",
15
- "items": [
16
- {
17
- "description": "Color to extract lightness from",
18
- "type": "color"
19
- }
20
- ],
21
- "minItems": 1,
22
- "maxItems": 1
23
- }
24
- },
25
- "required": [
26
- "input"
27
- ]
28
- },
29
- "returns": {
30
- "type": "number",
31
- "description": "Perceptual lightness value (0-1)"
32
- },
33
- "script": {
34
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
35
- "script": "// lightness: Extract perceptual lightness from a color\n// Reference: OKLCH Color Space (Björn Ottosson)\n// Reference: https://bottosson.github.io/posts/oklab/\n//\n// Returns the L component from OKLCH, which represents\n// perceptually uniform lightness. Range: 0 (black) to 1 (white).\n\nvariable input: List = {input};\nvariable color: Color.OKLCH = input.get(0).to.oklch();\n\nreturn color.l;"
36
- },
37
- "examples": [
38
- {
39
- "description": "White has lightness 1",
40
- "input": [
41
- "#ffffff"
42
- ],
43
- "output": 1
44
- },
45
- {
46
- "description": "Black has lightness 0",
47
- "input": [
48
- "#000000"
49
- ],
50
- "output": 0
51
- },
52
- {
53
- "description": "Mid-gray has lightness ~0.6",
54
- "input": [
55
- "#808080"
56
- ],
57
- "output": 0.6
58
- }
59
- ],
60
- "slug": "lightness"
61
- }
@@ -1,23 +0,0 @@
1
- {
2
- "name": "Luminance",
3
- "type": "function",
4
- "description": "Returns the relative luminance of a color (0-1). Uses the WCAG formula based on linear sRGB. Useful for contrast calculations and accessibility.",
5
- "keyword": "luminance",
6
- "input": {
7
- "type": "object",
8
- "properties": {
9
- "color": {
10
- "type": "color",
11
- "description": "The color to measure"
12
- }
13
- }
14
- },
15
- "script": {
16
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
17
- "script": "// Get relative luminance of a color\n// Per WCAG 2.1: L = 0.2126*R + 0.7152*G + 0.0722*B (linear RGB)\n//\n// Returns: 0 (black) to 1 (white)\n// Used for contrast calculations\n\nvariable input: List = {input};\nvariable color: Color.LinearSRGB = input.get(0).to.linearsrgb();\n\nvariable lum: Number = 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;\n\nreturn lum;"
18
- },
19
- "requirements": [
20
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/srgb-linear-color/0/"
21
- ],
22
- "slug": "luminance"
23
- }
@@ -1,31 +0,0 @@
1
- {
2
- "name": "Meets Contrast",
3
- "type": "function",
4
- "description": "Checks if two colors meet WCAG 2.1 contrast requirements. Returns true if contrast ratio meets the specified level: 'AA' (4.5:1 for normal text, 3:1 for large text), 'AAA' (7:1 for normal text, 4.5:1 for large text), or a custom ratio.",
5
- "keyword": "meets_contrast",
6
- "input": {
7
- "type": "object",
8
- "properties": {
9
- "color1": {
10
- "type": "color",
11
- "description": "First color"
12
- },
13
- "color2": {
14
- "type": "color",
15
- "description": "Second color"
16
- },
17
- "threshold": {
18
- "type": "number",
19
- "description": "Minimum contrast ratio required (default: 4.5 for AA)"
20
- }
21
- }
22
- },
23
- "script": {
24
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
25
- "script": "// Meets Contrast (WCAG 2.1 Compliance Check)\n// Reference: WCAG 2.1 Success Criteria 1.4.3 and 1.4.6\n// Reference: https://www.w3.org/TR/WCAG21/#contrast-minimum\n//\n// WCAG 2.1 Contrast Levels:\n// - Level AA (normal text): 4.5:1\n// - Level AA (large text): 3:1\n// - Level AAA (normal text): 7:1\n// - Level AAA (large text): 4.5:1\n//\n// Large text is defined as:\n// - 14pt (18.66px) bold\n// - 18pt (24px) regular\n//\n// Returns true if the contrast ratio meets or exceeds the threshold.\n\nvariable input: List = {input};\nvariable color1: Color.LinearSRGB = input.get(0).to.linearsrgb();\nvariable color2: Color.LinearSRGB = input.get(1).to.linearsrgb();\n\n// Default threshold is 4.5 (WCAG AA for normal text)\nvariable threshold: Number = 4.5;\nif (input.length() > 2) [\n threshold = input.get(2);\n];\n\n// Calculate relative luminance for each color\n// Formula: L = 0.2126 * R + 0.7152 * G + 0.0722 * B\nvariable lum1: Number = 0.2126 * color1.r + 0.7152 * color1.g + 0.0722 * color1.b;\nvariable lum2: Number = 0.2126 * color2.r + 0.7152 * color2.g + 0.0722 * color2.b;\n\n// Ensure non-negative luminance\nif (lum1 < 0) [ lum1 = 0; ];\nif (lum2 < 0) [ lum2 = 0; ];\n\n// Determine lighter and darker luminance\nvariable lighter: Number = lum1;\nvariable darker: Number = lum2;\nif (lum2 > lum1) [\n lighter = lum2;\n darker = lum1;\n];\n\n// Calculate contrast ratio: (L1 + 0.05) / (L2 + 0.05)\nvariable ratio: Number = (lighter + 0.05) / (darker + 0.05);\n\n// Return whether it meets the threshold\nreturn ratio >= threshold;"
26
- },
27
- "requirements": [
28
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/srgb-linear-color/0/"
29
- ],
30
- "slug": "meets_contrast"
31
- }
@@ -1,32 +0,0 @@
1
- {
2
- "name": "Mix",
3
- "type": "function",
4
- "description": "Blends two colors together in OKLCH space. Amount 0 = first color, 1 = second color, 0.5 = equal blend.",
5
- "keyword": "mix",
6
- "input": {
7
- "type": "object",
8
- "properties": {
9
- "color1": {
10
- "type": "color",
11
- "description": "First color"
12
- },
13
- "color2": {
14
- "type": "color",
15
- "description": "Second color"
16
- },
17
- "amount": {
18
- "type": "number",
19
- "description": "Blend amount (0-1). Default is 0.5"
20
- }
21
- }
22
- },
23
- "script": {
24
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
25
- "script": "// mix: Blend two colors in perceptual space\n// Uses shortest hue path for natural color blending.\n//\n// Algorithm: Linear interpolation on L, C, and shortest-path H\n//\n// Input: Any color space (converted to OKLCH internally)\n// Output: OKLCH (working space)\n// To get sRGB: mix(color1, color2, 0.5).to.srgb()\n\nvariable input: List = {input};\nvariable color1: Color.OKLCH = input.get(0).to.oklch();\nvariable color2: Color.OKLCH = input.get(1).to.oklch();\n\n// Default amount is 0.5 (50/50 blend)\nvariable amount: Number = 0.5;\nif (input.length() > 2) [\n amount = input.get(2);\n];\n\n// Interpolate lightness and chroma linearly\nvariable new_l: Number = color1.l + (color2.l - color1.l) * amount;\nvariable new_c: Number = color1.c + (color2.c - color1.c) * amount;\n\n// Interpolate hue using shortest path\nvariable h1: Number = color1.h;\nvariable h2: Number = color2.h;\nvariable h_diff: Number = h2 - h1;\n\n// Normalize to shortest path (-180 to 180)\nif (h_diff > 180) [ h_diff = h_diff - 360; ];\nif (h_diff < -180) [ h_diff = h_diff + 360; ];\n\nvariable new_h: Number = h1 + h_diff * amount;\nif (new_h < 0) [ new_h = new_h + 360; ];\nif (new_h >= 360) [ new_h = new_h - 360; ];\n\n// Create mixed color\nvariable result: Color.OKLCH;\nresult.l = new_l;\nresult.c = new_c;\nresult.h = new_h;\n\nreturn result;"
26
- },
27
- "requirements": [
28
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/oklch-color/0/",
29
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/srgb-color/0/"
30
- ],
31
- "slug": "mix"
32
- }
@@ -1,28 +0,0 @@
1
- {
2
- "name": "Monochromatic",
3
- "type": "function",
4
- "description": "Generates a monochromatic color palette - variations of a single hue with different lightness and chroma. Useful for creating cohesive single-color schemes. Preserves hue, varies lightness from light to dark.",
5
- "keyword": "monochromatic",
6
- "input": {
7
- "type": "object",
8
- "properties": {
9
- "color": {
10
- "type": "color",
11
- "description": "Base color"
12
- },
13
- "count": {
14
- "type": "number",
15
- "description": "Number of colors to generate (default: 5)"
16
- }
17
- }
18
- },
19
- "script": {
20
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
21
- "script": "// Monochromatic Color Palette\n// Generates variations of a single hue with different lightness\n//\n// A monochromatic scheme uses:\n// - Same hue throughout\n// - Varying lightness (from light tints to dark shades)\n// - Varying chroma (reduced at extremes for natural appearance)\n//\n// This creates harmonious, cohesive palettes ideal for:\n// - UI background/foreground variations\n// - Data visualization with single-variable emphasis\n// - Brand color systems\n\nvariable input: List = {input};\nvariable base: Color.OKLCH = input.get(0).to.oklch();\n\n// Default count is 5\nvariable count: Number = 5;\nif (input.length() > 1) [\n count = input.get(1);\n];\n\n// Preserve the hue\nvariable base_h: Number = base.h;\nvariable base_c: Number = base.c;\n\n// Define lightness range (from light to dark)\nvariable light_start: Number = 0.9;\nvariable light_end: Number = 0.3;\n\nvariable result: List;\nvariable i: Number = 0;\nvariable t: Number = 0;\nvariable step_l: Number = 0;\nvariable l_factor: Number = 0;\nvariable step_c: Number = 0;\nvariable color: Color.OKLCH;\n\nwhile (i < count) [\n // Calculate interpolation factor\n if (count > 1) [\n t = i / (count - 1);\n ] else [\n t = 0.5;\n ];\n \n // Interpolate lightness\n step_l = light_start + (light_end - light_start) * t;\n \n // Scale chroma - reduce at extremes for natural appearance\n // Peak chroma around middle lightness (0.6)\n l_factor = step_l - 0.6;\n if (l_factor < 0) [ l_factor = 0 - l_factor; ];\n l_factor = 1 - l_factor * 1.5;\n if (l_factor < 0.3) [ l_factor = 0.3; ];\n if (l_factor > 1) [ l_factor = 1; ];\n \n step_c = base_c * l_factor;\n \n // Clamp chroma to avoid out-of-gamut\n if (step_c > 0.35) [ step_c = 0.35; ];\n \n color.l = step_l;\n color.c = step_c;\n color.h = base_h;\n \n result = result, color.to.srgb();\n i = i + 1;\n];\n\nreturn result;"
22
- },
23
- "requirements": [
24
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/oklch-color/0/",
25
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/srgb-color/0/"
26
- ],
27
- "slug": "monochromatic"
28
- }
@@ -1,59 +0,0 @@
1
- {
2
- "name": "muted",
3
- "type": "function",
4
- "description": "Decreases a color's chroma toward neutral (gray). Preserves lightness and hue while reducing colorfulness. The optional amount parameter controls the intensity (0-1, default 0.5). Uses OKLCH for perceptually uniform chroma adjustment. Useful for creating subtle backgrounds, disabled states, or calming variations of vibrant colors.",
5
- "keyword": "muted",
6
- "requirements": [
7
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/srgb-color/0/",
8
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/oklch-color/0/"
9
- ],
10
- "schema": {
11
- "type": "object",
12
- "properties": {
13
- "input": {
14
- "type": "array",
15
- "items": [
16
- {
17
- "description": "Color to mute",
18
- "type": "color"
19
- },
20
- {
21
- "description": "Amount (0-1, default 0.5). Higher = more muted.",
22
- "type": "number"
23
- }
24
- ],
25
- "minItems": 1,
26
- "maxItems": 2
27
- }
28
- },
29
- "required": [
30
- "input"
31
- ]
32
- },
33
- "returns": {
34
- "type": "color",
35
- "description": "More muted version of the color"
36
- },
37
- "script": {
38
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
39
- "script": "// muted: Decrease chroma toward neutral (gray)\n// Preserves lightness and hue\n// Amount controls how much to reduce (0-1, 1 = fully gray)\n\nvariable input: List = {input};\nvariable color: Color.OKLCH = input.get(0).to.oklch();\n\n// Default amount\nvariable amount: Number = 0.5;\nif (input.length() > 1) [\n amount = input.get(1);\n];\n\n// Move chroma toward 0 by the specified amount\nvariable current_c: Number = color.c;\nvariable new_c: Number = current_c * (1 - amount);\n\n// Create result\nvariable result: Color.OKLCH;\nresult.l = color.l;\nresult.c = new_c;\nresult.h = color.h;\n\nreturn result;"
40
- },
41
- "examples": [
42
- {
43
- "description": "Mute vibrant red",
44
- "input": [
45
- "#ff0000"
46
- ],
47
- "output": "Desaturated red"
48
- },
49
- {
50
- "description": "Fully muted becomes gray",
51
- "input": [
52
- "#ff0000",
53
- 1
54
- ],
55
- "output": "Gray with same lightness as red"
56
- }
57
- ],
58
- "slug": "muted"
59
- }
@@ -1,59 +0,0 @@
1
- {
2
- "name": "neutral_variant",
3
- "type": "function",
4
- "description": "Creates a neutral (gray) variant of a color while preserving its lightness. Optionally retains a hint of the original hue. Useful for creating subtle backgrounds, disabled states, or neutral UI elements that relate to a brand color. Uses OKLCH for accurate lightness preservation.",
5
- "keyword": "neutral_variant",
6
- "requirements": [
7
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/srgb-color/0/",
8
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/oklch-color/0/"
9
- ],
10
- "schema": {
11
- "type": "object",
12
- "properties": {
13
- "input": {
14
- "type": "array",
15
- "items": [
16
- {
17
- "description": "Source color",
18
- "type": "color"
19
- },
20
- {
21
- "description": "Optional chroma retention (0-1, default 0 for pure gray)",
22
- "type": "number"
23
- }
24
- ],
25
- "minItems": 1,
26
- "maxItems": 2
27
- }
28
- },
29
- "required": [
30
- "input"
31
- ]
32
- },
33
- "returns": {
34
- "type": "color",
35
- "description": "Neutral variant with same lightness"
36
- },
37
- "script": {
38
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
39
- "script": "// neutral_variant: Create gray version of color preserving lightness\n// Optionally retain some chroma for subtle tinting\n\nvariable input: List = {input};\nvariable color: Color.OKLCH = input.get(0).to.oklch();\n\n// Default to pure gray (0 chroma retention)\nvariable retention: Number = 0;\nif (input.length() > 1) [\n retention = input.get(1);\n];\n\n// Calculate retained chroma\nvariable new_c: Number = color.c * retention;\n\n// Create result\nvariable result: Color.OKLCH;\nresult.l = color.l;\nresult.c = new_c;\nresult.h = color.h; // Hue preserved for subtle tinting\n\nreturn result;"
40
- },
41
- "examples": [
42
- {
43
- "description": "Pure gray from blue",
44
- "input": [
45
- "#0066cc"
46
- ],
47
- "output": "Gray with same lightness as blue"
48
- },
49
- {
50
- "description": "Slightly tinted gray",
51
- "input": [
52
- "#ff0000",
53
- 0.02
54
- ],
55
- "output": "Very subtle warm gray"
56
- }
57
- ],
58
- "slug": "neutral_variant"
59
- }
@@ -1,61 +0,0 @@
1
- {
2
- "name": "relative_luminance",
3
- "type": "function",
4
- "description": "Returns the WCAG 2.1 relative luminance of a color. This is the Y value from the XYZ-D65 color space, ranging from 0 (black) to 1 (white). Used in contrast ratio calculations. Different from perceptual lightness - relative luminance is weighted toward green (which human eyes are most sensitive to). Essential for WCAG accessibility calculations.",
5
- "keyword": "relative_luminance",
6
- "requirements": [
7
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/srgb-color/0/",
8
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/xyz-d65-color/0/"
9
- ],
10
- "schema": {
11
- "type": "object",
12
- "properties": {
13
- "input": {
14
- "type": "array",
15
- "items": [
16
- {
17
- "description": "Color to measure",
18
- "type": "color"
19
- }
20
- ],
21
- "minItems": 1,
22
- "maxItems": 1
23
- }
24
- },
25
- "required": [
26
- "input"
27
- ]
28
- },
29
- "returns": {
30
- "type": "number",
31
- "description": "Relative luminance (0-1)"
32
- },
33
- "script": {
34
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
35
- "script": "// relative_luminance: Get WCAG 2.1 relative luminance\n// Reference: WCAG 2.1 Definition of Relative Luminance\n// Reference: https://www.w3.org/TR/WCAG21/#dfn-relative-luminance\n//\n// Returns the Y component from CIE XYZ D65, which is the\n// relative luminance as defined by WCAG. Range is [0, 1]\n// where 0 = black and 1 = reference white.\n//\n// This value is used in WCAG contrast ratio calculations.\n\nvariable input: List = {input};\nvariable color: Color.XYZD65 = input.get(0).to.xyzd65();\n\nreturn color.y;"
36
- },
37
- "examples": [
38
- {
39
- "description": "White has luminance 1",
40
- "input": [
41
- "#ffffff"
42
- ],
43
- "output": 1
44
- },
45
- {
46
- "description": "Black has luminance 0",
47
- "input": [
48
- "#000000"
49
- ],
50
- "output": 0
51
- },
52
- {
53
- "description": "Pure green is brighter than pure blue",
54
- "input": [
55
- "#00ff00"
56
- ],
57
- "output": 0.7152
58
- }
59
- ],
60
- "slug": "relative_luminance"
61
- }
@@ -1,28 +0,0 @@
1
- {
2
- "name": "Rotate Hue",
3
- "type": "function",
4
- "description": "Rotates a color's hue by a specified number of degrees in OKLCH space. Positive values rotate clockwise, negative counterclockwise.",
5
- "keyword": "rotate_hue",
6
- "input": {
7
- "type": "object",
8
- "properties": {
9
- "color": {
10
- "type": "color",
11
- "description": "The color to rotate"
12
- },
13
- "degrees": {
14
- "type": "number",
15
- "description": "Degrees to rotate (-360 to 360)"
16
- }
17
- }
18
- },
19
- "script": {
20
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
21
- "script": "// Rotate a color's hue by specified degrees\n// Preserves lightness and chroma\n\nvariable input: List = {input};\nvariable color: Color.OKLCH = input.get(0).to.oklch();\nvariable degrees: Number = input.get(1);\n\nvariable new_h: Number = color.h + degrees;\n\n// Normalize to 0-360\nwhile (new_h >= 360) [ new_h = new_h - 360; ];\nwhile (new_h < 0) [ new_h = new_h + 360; ];\n\nvariable result: Color.OKLCH;\nresult.l = color.l;\nresult.c = color.c;\nresult.h = new_h;\n\nreturn result;"
22
- },
23
- "requirements": [
24
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/oklch-color/0/",
25
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/srgb-color/0/"
26
- ],
27
- "slug": "rotate_hue"
28
- }
@@ -1,28 +0,0 @@
1
- {
2
- "name": "Saturate",
3
- "type": "function",
4
- "description": "Increases color saturation by boosting chroma in OKLCH space. Amount is 0-1 where 0.25 = 25% more saturated.",
5
- "keyword": "saturate",
6
- "input": {
7
- "type": "object",
8
- "properties": {
9
- "color": {
10
- "type": "color",
11
- "description": "The color to saturate"
12
- },
13
- "amount": {
14
- "type": "number",
15
- "description": "Amount to saturate (0-1). Default is 0.25"
16
- }
17
- }
18
- },
19
- "script": {
20
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
21
- "script": "// Saturate a color by increasing its OKLCH chroma\n// Amount: 0-1 where 0.25 means 25% increase\n//\n// Algorithm: C' = C * (1 + amount)\n// Chroma has no strict upper bound but ~0.4 is practical max for sRGB\n\nvariable input: List = {input};\nvariable color: Color.OKLCH = input.get(0).to.oklch();\n\n// Default amount is 0.25 (25%)\nvariable amount: Number = 0.25;\nif (input.length() > 1) [\n amount = input.get(1);\n];\n\n// Calculate new chroma\nvariable current_c: Number = color.c;\nvariable new_c: Number = current_c * (1 + amount);\n\n// Soft clamp at 0.4 (approximate sRGB gamut max)\nif (new_c > 0.4) [ new_c = 0.4; ];\n\n// Create output in OKLCH, return as sRGB\nvariable result: Color.OKLCH;\nresult.l = color.l;\nresult.c = new_c;\nresult.h = color.h;\n\nreturn result;"
22
- },
23
- "requirements": [
24
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/oklch-color/0/",
25
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/srgb-color/0/"
26
- ],
27
- "slug": "saturate"
28
- }
@@ -1,60 +0,0 @@
1
- {
2
- "name": "scale_chroma",
3
- "type": "function",
4
- "description": "Scales a color's chroma (saturation) by a factor. Unlike set_chroma which sets an absolute value, scale_chroma multiplies the current chroma. A factor of 1.5 increases colorfulness by 50%, while 0.5 decreases it by 50%. Uses OKLCH for perceptually uniform scaling. Useful for creating more or less vivid versions of a color.",
5
- "keyword": "scale_chroma",
6
- "requirements": [
7
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/srgb-color/0/",
8
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/oklch-color/0/"
9
- ],
10
- "schema": {
11
- "type": "object",
12
- "properties": {
13
- "input": {
14
- "type": "array",
15
- "items": [
16
- {
17
- "description": "Color to scale",
18
- "type": "color"
19
- },
20
- {
21
- "description": "Scale factor (e.g., 1.5 for +50%, 0.5 for -50%)",
22
- "type": "number"
23
- }
24
- ],
25
- "minItems": 2,
26
- "maxItems": 2
27
- }
28
- },
29
- "required": [
30
- "input"
31
- ]
32
- },
33
- "returns": {
34
- "type": "color",
35
- "description": "Color with scaled chroma"
36
- },
37
- "script": {
38
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
39
- "script": "// scale_chroma: Multiply chroma by a factor\n// Uses OKLCH for perceptually uniform scaling\n// Chroma cannot be negative; clamps to 0\n\nvariable input: List = {input};\nvariable color: Color.OKLCH = input.get(0).to.oklch();\nvariable factor: Number = input.get(1);\n\n// Scale chroma\nvariable new_c: Number = color.c * factor;\n\n// Clamp to valid range (no negative chroma)\nif (new_c < 0) [ new_c = 0; ];\n\n// Create result\nvariable result: Color.OKLCH;\nresult.l = color.l;\nresult.c = new_c;\nresult.h = color.h;\n\nreturn result;"
40
- },
41
- "examples": [
42
- {
43
- "description": "Make color more vivid",
44
- "input": [
45
- "#cc8080",
46
- 1.5
47
- ],
48
- "output": "More saturated red"
49
- },
50
- {
51
- "description": "Desaturate color",
52
- "input": [
53
- "#ff0000",
54
- 0.5
55
- ],
56
- "output": "Muted red"
57
- }
58
- ],
59
- "slug": "scale_chroma"
60
- }
@@ -1,60 +0,0 @@
1
- {
2
- "name": "scale_lightness",
3
- "type": "function",
4
- "description": "Scales a color's lightness by a factor. Unlike set_lightness which sets an absolute value, scale_lightness multiplies the current lightness. A factor of 1.2 increases lightness by 20%, while 0.8 decreases it by 20%. Uses OKLCH for perceptually uniform scaling. Result is clamped to valid lightness range [0, 1].",
5
- "keyword": "scale_lightness",
6
- "requirements": [
7
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/srgb-color/0/",
8
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/oklch-color/0/"
9
- ],
10
- "schema": {
11
- "type": "object",
12
- "properties": {
13
- "input": {
14
- "type": "array",
15
- "items": [
16
- {
17
- "description": "Color to scale",
18
- "type": "color"
19
- },
20
- {
21
- "description": "Scale factor (e.g., 1.2 for +20%, 0.8 for -20%)",
22
- "type": "number"
23
- }
24
- ],
25
- "minItems": 2,
26
- "maxItems": 2
27
- }
28
- },
29
- "required": [
30
- "input"
31
- ]
32
- },
33
- "returns": {
34
- "type": "color",
35
- "description": "Color with scaled lightness"
36
- },
37
- "script": {
38
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
39
- "script": "// scale_lightness: Multiply lightness by a factor\n// Uses OKLCH for perceptually uniform scaling\n// Clamps result to valid range [0, 1]\n\nvariable input: List = {input};\nvariable color: Color.OKLCH = input.get(0).to.oklch();\nvariable factor: Number = input.get(1);\n\n// Scale lightness\nvariable new_l: Number = color.l * factor;\n\n// Clamp to valid range\nif (new_l < 0) [ new_l = 0; ];\nif (new_l > 1) [ new_l = 1; ];\n\n// Create result\nvariable result: Color.OKLCH;\nresult.l = new_l;\nresult.c = color.c;\nresult.h = color.h;\n\nreturn result;"
40
- },
41
- "examples": [
42
- {
43
- "description": "Brighten color by 20%",
44
- "input": [
45
- "#808080",
46
- 1.2
47
- ],
48
- "output": "Lighter gray"
49
- },
50
- {
51
- "description": "Dim color by 50%",
52
- "input": [
53
- "#ffffff",
54
- 0.5
55
- ],
56
- "output": "Mid-gray"
57
- }
58
- ],
59
- "slug": "scale_lightness"
60
- }
@@ -1,59 +0,0 @@
1
- {
2
- "name": "sepia",
3
- "type": "function",
4
- "description": "Applies a sepia tone to a color, simulating the warm brownish tint of aged photographs. Uses the standard sepia matrix transformation. Amount parameter controls intensity from 0 (no effect) to 1 (full sepia).",
5
- "keyword": "sepia",
6
- "requirements": [
7
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/srgb-color/0/"
8
- ],
9
- "schema": {
10
- "type": "object",
11
- "properties": {
12
- "input": {
13
- "type": "array",
14
- "items": [
15
- {
16
- "description": "Color to transform",
17
- "type": "color"
18
- },
19
- {
20
- "description": "Sepia intensity (0-1), default 1",
21
- "type": "number"
22
- }
23
- ],
24
- "minItems": 1,
25
- "maxItems": 2
26
- }
27
- },
28
- "required": [
29
- "input"
30
- ]
31
- },
32
- "returns": {
33
- "type": "color",
34
- "description": "Color with sepia tone applied"
35
- },
36
- "script": {
37
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
38
- "script": "// sepia: Apply sepia tone transformation\n// Reference: CSS Filter Effects Module Level 1\n// Reference: https://www.w3.org/TR/filter-effects-1/#sepiaEquivalent\n//\n// Uses the standard sepia matrix transformation as defined in CSS.\n// The amount parameter controls intensity (0 = no effect, 1 = full sepia).\n//\n// Matrix coefficients:\n// R' = 0.393R + 0.769G + 0.189B\n// G' = 0.349R + 0.686G + 0.168B\n// B' = 0.272R + 0.534G + 0.131B\n\nvariable input: List = {input};\nvariable color: Color.SRGB = input.get(0).to.srgb();\nvariable amount: Number = 1;\n\nif (input.length() > 1) [\n amount = input.get(1);\n];\n\n// Clamp amount\nif (amount < 0) [ amount = 0; ];\nif (amount > 1) [ amount = 1; ];\n\nvariable r: Number = color.r;\nvariable g: Number = color.g;\nvariable b: Number = color.b;\n\n// Standard sepia matrix transformation (CSS filter spec)\n// R' = 0.393R + 0.769G + 0.189B\n// G' = 0.349R + 0.686G + 0.168B\n// B' = 0.272R + 0.534G + 0.131B\nvariable sepia_r: Number = (r * 0.393) + (g * 0.769) + (b * 0.189);\nvariable sepia_g: Number = (r * 0.349) + (g * 0.686) + (b * 0.168);\nvariable sepia_b: Number = (r * 0.272) + (g * 0.534) + (b * 0.131);\n\n// Clamp sepia values to valid range\nif (sepia_r > 1) [ sepia_r = 1; ];\nif (sepia_g > 1) [ sepia_g = 1; ];\nif (sepia_b > 1) [ sepia_b = 1; ];\n\n// Interpolate between original and sepia based on amount\nvariable new_r: Number = r + (sepia_r - r) * amount;\nvariable new_g: Number = g + (sepia_g - g) * amount;\nvariable new_b: Number = b + (sepia_b - b) * amount;\n\n// Create result\nvariable result: Color.SRGB;\nresult.r = new_r;\nresult.g = new_g;\nresult.b = new_b;\n\nreturn result;"
39
- },
40
- "examples": [
41
- {
42
- "description": "Full sepia",
43
- "input": [
44
- "#808080",
45
- 1
46
- ],
47
- "output": "Warm brownish gray"
48
- },
49
- {
50
- "description": "Partial sepia",
51
- "input": [
52
- "#808080",
53
- 0.5
54
- ],
55
- "output": "Subtly warm gray"
56
- }
57
- ],
58
- "slug": "sepia"
59
- }
@@ -1,28 +0,0 @@
1
- {
2
- "name": "Set Chroma",
3
- "type": "function",
4
- "description": "Sets a color's chroma (saturation) to a specific value in OKLCH space. Preserves hue and lightness.",
5
- "keyword": "set_chroma",
6
- "input": {
7
- "type": "object",
8
- "properties": {
9
- "color": {
10
- "type": "color",
11
- "description": "The color to modify"
12
- },
13
- "chroma": {
14
- "type": "number",
15
- "description": "Target chroma (0-0.4 typical for sRGB)"
16
- }
17
- }
18
- },
19
- "script": {
20
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
21
- "script": "// Set a color's chroma to a specific value\n// Preserves hue and lightness\n\nvariable input: List = {input};\nvariable color: Color.OKLCH = input.get(0).to.oklch();\nvariable target_c: Number = input.get(1);\n\n// Clamp to valid range (0 to ~0.4 for sRGB gamut)\nif (target_c < 0) [ target_c = 0; ];\nif (target_c > 0.4) [ target_c = 0.4; ];\n\nvariable result: Color.OKLCH;\nresult.l = color.l;\nresult.c = target_c;\nresult.h = color.h;\n\nreturn result;"
22
- },
23
- "requirements": [
24
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/oklch-color/0/",
25
- "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/srgb-color/0/"
26
- ],
27
- "slug": "set_chroma"
28
- }