@tokens-studio/tokenscript-schemas 0.1.2 → 0.2.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 (106) hide show
  1. package/README.md +36 -7
  2. package/dist/cli/index.cjs +142 -88
  3. package/dist/cli/index.cjs.map +1 -1
  4. package/dist/cli/index.js +141 -87
  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/build-dir.test.ts +354 -0
  18. package/src/cli/commands/build-dir.ts +90 -0
  19. package/src/cli/commands/bundle.test.ts +95 -1
  20. package/src/cli/commands/bundle.ts +22 -15
  21. package/src/cli/index.ts +16 -0
  22. package/bundled/functions/adjust_chroma.json +0 -60
  23. package/bundled/functions/adjust_hue.json +0 -60
  24. package/bundled/functions/adjust_lightness.json +0 -60
  25. package/bundled/functions/adjust_to_contrast.json +0 -67
  26. package/bundled/functions/alpha_blend.json +0 -31
  27. package/bundled/functions/alpha_scale.json +0 -27
  28. package/bundled/functions/analogous.json +0 -32
  29. package/bundled/functions/apca_contrast.json +0 -27
  30. package/bundled/functions/are_similar.json +0 -73
  31. package/bundled/functions/auto_text_color.json +0 -66
  32. package/bundled/functions/best_contrast.json +0 -28
  33. package/bundled/functions/chroma.json +0 -54
  34. package/bundled/functions/clamp_chroma.json +0 -66
  35. package/bundled/functions/clamp_lightness.json +0 -66
  36. package/bundled/functions/clamp_to_gamut.json +0 -23
  37. package/bundled/functions/complement.json +0 -24
  38. package/bundled/functions/contrast_ratio.json +0 -27
  39. package/bundled/functions/cooler.json +0 -52
  40. package/bundled/functions/darken.json +0 -28
  41. package/bundled/functions/delta_e_2000.json +0 -40
  42. package/bundled/functions/delta_e_76.json +0 -27
  43. package/bundled/functions/delta_e_ok.json +0 -27
  44. package/bundled/functions/desaturate.json +0 -28
  45. package/bundled/functions/distributed.json +0 -36
  46. package/bundled/functions/diverging.json +0 -36
  47. package/bundled/functions/grayscale.json +0 -24
  48. package/bundled/functions/harmonize.json +0 -65
  49. package/bundled/functions/hue.json +0 -54
  50. package/bundled/functions/hue_difference.json +0 -27
  51. package/bundled/functions/in_gamut.json +0 -27
  52. package/bundled/functions/interpolate.json +0 -66
  53. package/bundled/functions/invert.json +0 -23
  54. package/bundled/functions/is_cool.json +0 -23
  55. package/bundled/functions/is_dark.json +0 -27
  56. package/bundled/functions/is_light.json +0 -27
  57. package/bundled/functions/is_neutral.json +0 -65
  58. package/bundled/functions/is_warm.json +0 -23
  59. package/bundled/functions/lighten.json +0 -28
  60. package/bundled/functions/lightness.json +0 -61
  61. package/bundled/functions/luminance.json +0 -23
  62. package/bundled/functions/meets_contrast.json +0 -31
  63. package/bundled/functions/mix.json +0 -32
  64. package/bundled/functions/monochromatic.json +0 -28
  65. package/bundled/functions/muted.json +0 -59
  66. package/bundled/functions/neutral_variant.json +0 -59
  67. package/bundled/functions/relative_luminance.json +0 -61
  68. package/bundled/functions/rotate_hue.json +0 -28
  69. package/bundled/functions/saturate.json +0 -28
  70. package/bundled/functions/scale_chroma.json +0 -60
  71. package/bundled/functions/scale_lightness.json +0 -60
  72. package/bundled/functions/sepia.json +0 -59
  73. package/bundled/functions/set_chroma.json +0 -28
  74. package/bundled/functions/set_hue.json +0 -28
  75. package/bundled/functions/set_lightness.json +0 -28
  76. package/bundled/functions/shade_scale.json +0 -28
  77. package/bundled/functions/split_complement.json +0 -28
  78. package/bundled/functions/steps.json +0 -32
  79. package/bundled/functions/tetradic.json +0 -24
  80. package/bundled/functions/tint_scale.json +0 -36
  81. package/bundled/functions/to_gamut.json +0 -59
  82. package/bundled/functions/triadic.json +0 -24
  83. package/bundled/functions/vibrant.json +0 -59
  84. package/bundled/functions/warmer.json +0 -52
  85. package/bundled/functions/wcag_level.json +0 -60
  86. package/bundled/functions.json +0 -2624
  87. package/bundled/registry.json +0 -3833
  88. package/bundled/types/css-color.json +0 -151
  89. package/bundled/types/hex-color.json +0 -25
  90. package/bundled/types/hsl-color.json +0 -66
  91. package/bundled/types/hsv-color.json +0 -57
  92. package/bundled/types/hwb-color.json +0 -66
  93. package/bundled/types/lab-color.json +0 -57
  94. package/bundled/types/lch-color.json +0 -57
  95. package/bundled/types/okhsl-color.json +0 -57
  96. package/bundled/types/okhsv-color.json +0 -57
  97. package/bundled/types/oklab-color.json +0 -87
  98. package/bundled/types/oklch-color.json +0 -57
  99. package/bundled/types/p3-color.json +0 -57
  100. package/bundled/types/p3-linear-color.json +0 -57
  101. package/bundled/types/rgb-color.json +0 -73
  102. package/bundled/types/srgb-color.json +0 -77
  103. package/bundled/types/srgb-linear-color.json +0 -67
  104. package/bundled/types/xyz-d50-color.json +0 -57
  105. package/bundled/types/xyz-d65-color.json +0 -77
  106. package/bundled/types.json +0 -1207
@@ -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
- }
@@ -1,28 +0,0 @@
1
- {
2
- "name": "Set Hue",
3
- "type": "function",
4
- "description": "Sets a color's hue to a specific angle in OKLCH space. Preserves lightness and chroma.",
5
- "keyword": "set_hue",
6
- "input": {
7
- "type": "object",
8
- "properties": {
9
- "color": {
10
- "type": "color",
11
- "description": "The color to modify"
12
- },
13
- "hue": {
14
- "type": "number",
15
- "description": "Target hue angle (0-360)"
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 hue to a specific angle\n// Preserves lightness and chroma\n\nvariable input: List = {input};\nvariable color: Color.OKLCH = input.get(0).to.oklch();\nvariable target_h: Number = input.get(1);\n\n// Normalize to 0-360\nwhile (target_h >= 360) [ target_h = target_h - 360; ];\nwhile (target_h < 0) [ target_h = target_h + 360; ];\n\nvariable result: Color.OKLCH;\nresult.l = color.l;\nresult.c = color.c;\nresult.h = target_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_hue"
28
- }
@@ -1,28 +0,0 @@
1
- {
2
- "name": "Set Lightness",
3
- "type": "function",
4
- "description": "Sets a color's lightness to a specific value in OKLCH space. Preserves hue and chroma.",
5
- "keyword": "set_lightness",
6
- "input": {
7
- "type": "object",
8
- "properties": {
9
- "color": {
10
- "type": "color",
11
- "description": "The color to modify"
12
- },
13
- "lightness": {
14
- "type": "number",
15
- "description": "Target lightness (0-1)"
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 lightness to a specific value\n// Preserves hue and chroma\n\nvariable input: List = {input};\nvariable color: Color.OKLCH = input.get(0).to.oklch();\nvariable target_l: Number = input.get(1);\n\n// Clamp to valid range\nif (target_l < 0) [ target_l = 0; ];\nif (target_l > 1) [ target_l = 1; ];\n\nvariable result: Color.OKLCH;\nresult.l = target_l;\nresult.c = color.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_lightness"
28
- }
@@ -1,28 +0,0 @@
1
- {
2
- "name": "Shade Scale",
3
- "type": "function",
4
- "description": "Generates a Tailwind/Material-style shade scale from 50 (lightest) to 900 (darkest). The input color becomes the 500 (middle) value. Perfect for design system color tokens.",
5
- "keyword": "shade_scale",
6
- "input": {
7
- "type": "object",
8
- "properties": {
9
- "color": {
10
- "type": "color",
11
- "description": "Base color (becomes the 500 shade)"
12
- },
13
- "count": {
14
- "type": "number",
15
- "description": "Number of shades. Default is 10 (50-900)"
16
- }
17
- }
18
- },
19
- "script": {
20
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
21
- "script": "// Generate a design system shade scale (like Tailwind 50-900)\n// Input color becomes the middle (500) shade\n//\n// Lightness distribution:\n// 50: ~0.97 (very light)\n// 100: ~0.93\n// 200: ~0.87\n// 300: ~0.78\n// 400: ~0.67\n// 500: input lightness (base)\n// 600: ~0.52\n// 700: ~0.42\n// 800: ~0.32\n// 900: ~0.22 (very dark)\n//\n// Chroma is scaled to avoid washed-out lights and muddy darks\n\nvariable input: List = {input};\nvariable base: Color.OKLCH = input.get(0).to.oklch();\n\nvariable count: Number = 10;\nif (input.length() > 1) [\n count = input.get(1);\n];\n\n// Target lightness values for standard 10-step scale\n// These are perceptually optimized for OKLCH\nvariable lightness_targets: List = 0.97, 0.93, 0.87, 0.78, 0.67, 0.55, 0.45, 0.35, 0.27, 0.20;\n\nvariable base_h: Number = base.h;\nvariable base_c: Number = base.c;\n\nvariable result: List;\nvariable i: Number = 0;\nvariable target_l: Number = 0;\nvariable l_factor: Number = 0;\nvariable scaled_c: Number = 0;\nvariable shade: Color.OKLCH;\n\nwhile (i < count) [\n target_l = lightness_targets.get(i);\n \n // Scale chroma based on lightness\n // Chroma peaks in midtones, reduces at extremes\n l_factor = 1 - abs(target_l - 0.55) * 1.2;\n if (l_factor < 0.3) [ l_factor = 0.3; ];\n if (l_factor > 1.2) [ l_factor = 1.2; ];\n \n scaled_c = base_c * l_factor;\n if (scaled_c > 0.4) [ scaled_c = 0.4; ];\n \n shade.l = target_l;\n shade.c = scaled_c;\n shade.h = base_h;\n \n result = result, shade.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": "shade_scale"
28
- }
@@ -1,28 +0,0 @@
1
- {
2
- "name": "Split Complement",
3
- "type": "function",
4
- "description": "Generates split-complementary colors - base color plus two colors adjacent to its complement. More nuanced than direct complement, less tension than triadic.",
5
- "keyword": "split_complement",
6
- "input": {
7
- "type": "object",
8
- "properties": {
9
- "color": {
10
- "type": "color",
11
- "description": "Base color"
12
- },
13
- "angle": {
14
- "type": "number",
15
- "description": "Degrees from complement for split colors. Default is 30"
16
- }
17
- }
18
- },
19
- "script": {
20
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
21
- "script": "// Generate split-complementary colors\n// Returns [base, complement-angle, complement+angle]\n//\n// Use case: Balanced contrast with more variety than complement\n// Example: Blue → Orange-Red, Orange-Yellow (instead of just Orange)\n\nvariable input: List = {input};\nvariable base: Color.OKLCH = input.get(0).to.oklch();\n\nvariable angle: Number = 30;\nif (input.length() > 1) [\n angle = input.get(1);\n];\n\nvariable complement_h: Number = base.h + 180;\nif (complement_h >= 360) [ complement_h = complement_h - 360; ];\n\nvariable result: List;\n\n// Base color\nresult = result, base.to.srgb();\n\n// Complement - angle\nvariable h2: Number = complement_h - angle;\nif (h2 < 0) [ h2 = h2 + 360; ];\nvariable c2: Color.OKLCH;\nc2.l = base.l; c2.c = base.c; c2.h = h2;\nresult = result, c2.to.srgb();\n\n// Complement + angle\nvariable h3: Number = complement_h + angle;\nif (h3 >= 360) [ h3 = h3 - 360; ];\nvariable c3: Color.OKLCH;\nc3.l = base.l; c3.c = base.c; c3.h = h3;\nresult = result, c3.to.srgb();\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": "split_complement"
28
- }
@@ -1,32 +0,0 @@
1
- {
2
- "name": "Steps",
3
- "type": "function",
4
- "description": "Generates a list of colors interpolated between two colors in OKLCH space. Perfect for gradient stops.",
5
- "keyword": "steps",
6
- "input": {
7
- "type": "object",
8
- "properties": {
9
- "color1": {
10
- "type": "color",
11
- "description": "Start color"
12
- },
13
- "color2": {
14
- "type": "color",
15
- "description": "End color"
16
- },
17
- "count": {
18
- "type": "number",
19
- "description": "Number of steps (including start and end). Default is 5"
20
- }
21
- }
22
- },
23
- "script": {
24
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
25
- "script": "// Generate gradient steps between two colors in OKLCH space\n// Returns a List of colors from start to end (inclusive)\n//\n// Uses perceptually uniform interpolation with shortest hue path\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 count is 5\nvariable count: Number = 5;\nif (input.length() > 2) [\n count = input.get(2);\n];\n\n// Calculate hue difference (shortest path)\nvariable h1: Number = color1.h;\nvariable h2: Number = color2.h;\nvariable h_diff: Number = h2 - h1;\nif (h_diff > 180) [ h_diff = h_diff - 360; ];\nif (h_diff < -180) [ h_diff = h_diff + 360; ];\n\n// Generate steps\nvariable result: List;\nvariable i: Number = 0;\nvariable t: Number = 0;\nvariable step_l: Number = 0;\nvariable step_c: Number = 0;\nvariable step_h: Number = 0;\nvariable step_color: Color.OKLCH;\n\nwhile (i < count) [\n t = i / (count - 1);\n \n // Interpolate each component\n step_l = color1.l + (color2.l - color1.l) * t;\n step_c = color1.c + (color2.c - color1.c) * t;\n step_h = h1 + h_diff * t;\n \n // Normalize hue\n if (step_h < 0) [ step_h = step_h + 360; ];\n if (step_h >= 360) [ step_h = step_h - 360; ];\n \n // Create color and add to list\n step_color.l = step_l;\n step_color.c = step_c;\n step_color.h = step_h;\n \n result = result, step_color.to.srgb();\n i = i + 1;\n];\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": "steps"
32
- }