@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
@@ -1,6 +1,6 @@
1
1
  // CIE LCH Color Initializer
2
2
  // Creates a LCH color from L, C, H values
3
- // Input: List of [l, c, h] values
3
+ // Input: List of [l, c, h] or [l, c, h, alpha] values
4
4
 
5
5
  variable lch_values: List = {input};
6
6
  variable output: Color.LCH;
@@ -9,6 +9,11 @@ output.l = lch_values.get(0);
9
9
  output.c = lch_values.get(1);
10
10
  output.h = lch_values.get(2);
11
11
 
12
+ // Set alpha if provided as 4th parameter
13
+ if (lch_values.length() > 3) [
14
+ output.alpha = lch_values.get(3);
15
+ ];
16
+
12
17
  return output;
13
18
 
14
19
 
@@ -170,4 +170,48 @@ describe("CIE LCH Color Schema", () => {
170
170
  expect((result as any).value.c.value).toBeLessThan(0.01);
171
171
  });
172
172
  });
173
+
174
+ describe("Alpha Channel Support", () => {
175
+ it("should accept optional 4th parameter for alpha", async () => {
176
+ const result = await executeWithSchema(
177
+ "lch-color",
178
+ "type",
179
+ `
180
+ variable c: Color.LCH = lch(50, 20, 180, 0.7);
181
+ c
182
+ `,
183
+ );
184
+
185
+ expect(result?.constructor.name).toBe("ColorSymbol");
186
+ expect((result as any).subType).toBe("LCH");
187
+ expect((result as any).alpha).toBe(0.7);
188
+ });
189
+
190
+ it("should get alpha property", async () => {
191
+ const result = await executeWithSchema(
192
+ "lch-color",
193
+ "type",
194
+ `
195
+ variable c: Color.LCH = lch(50, 20, 180, 0.5);
196
+ c.alpha
197
+ `,
198
+ );
199
+
200
+ expect((result as any).value).toBe(0.5);
201
+ });
202
+
203
+ it("should set alpha property", async () => {
204
+ const result = await executeWithSchema(
205
+ "lch-color",
206
+ "type",
207
+ `
208
+ variable c: Color.LCH = lch(50, 20, 180);
209
+ c.alpha = 0.8;
210
+ c.alpha
211
+ `,
212
+ );
213
+
214
+ expect((result as any).value).toBe(0.8);
215
+ });
216
+ });
173
217
  });
@@ -9,8 +9,9 @@
9
9
  // - h: Hue angle (0-360 degrees), same as OKLCH hue
10
10
  // - s: Saturation (0-1), normalized to sRGB gamut boundary
11
11
  // - l: Lightness (0-1), perceptually uniform with toe function
12
+ // - alpha: Optional alpha channel (0-1)
12
13
  //
13
- // Input: Object with h, s, l properties
14
+ // Input: Object with h, s, l, and optional alpha properties
14
15
  // Output: Color.OKHSL
15
16
 
16
17
  variable h: Number = input.h;
@@ -21,4 +22,10 @@ variable output: Color.OKHSL;
21
22
  output.h = h;
22
23
  output.s = s;
23
24
  output.l = l;
25
+
26
+ // Set alpha if provided
27
+ if (input.alpha != null) [
28
+ output.alpha = input.alpha;
29
+ ];
30
+
24
31
  output
@@ -511,4 +511,41 @@ describe("OKHSL Color Schema", () => {
511
511
  });
512
512
  });
513
513
  });
514
+
515
+ describe("Alpha Channel Support", () => {
516
+ it("should set and get alpha property", async () => {
517
+ const result = await executeWithSchema(
518
+ "okhsl-color",
519
+ "type",
520
+ `
521
+ variable c: Color.OKHSL;
522
+ c.h = 180;
523
+ c.s = 0.5;
524
+ c.l = 0.5;
525
+ c.alpha = 0.7;
526
+ c.alpha
527
+ `,
528
+ );
529
+
530
+ expect((result as any).value).toBe(0.7);
531
+ });
532
+
533
+ it("should preserve alpha through conversions", async () => {
534
+ const result = await executeWithSchema(
535
+ "okhsl-color",
536
+ "type",
537
+ `
538
+ variable c: Color.OKHSL;
539
+ c.h = 180;
540
+ c.s = 0.5;
541
+ c.l = 0.5;
542
+ c.alpha = 0.6;
543
+ variable oklab: Color.OKLab = c.to.oklab();
544
+ oklab.alpha
545
+ `,
546
+ );
547
+
548
+ expect((result as any).value).toBe(0.6);
549
+ });
550
+ });
514
551
  });
@@ -9,8 +9,9 @@
9
9
  // - h: Hue angle (0-360 degrees), same as OKLCH hue
10
10
  // - s: Saturation (0-1), ratio of chroma to maximum at this value
11
11
  // - v: Value/brightness (0-1), with V=1 being brightest for that saturation
12
+ // - alpha: Optional alpha channel (0-1)
12
13
  //
13
- // Input: Object with h, s, v properties
14
+ // Input: Object with h, s, v, and optional alpha properties
14
15
  // Output: Color.OKHSV
15
16
 
16
17
  variable h: Number = input.h;
@@ -21,4 +22,10 @@ variable output: Color.OKHSV;
21
22
  output.h = h;
22
23
  output.s = s;
23
24
  output.v = v;
25
+
26
+ // Set alpha if provided
27
+ if (input.alpha != null) [
28
+ output.alpha = input.alpha;
29
+ ];
30
+
24
31
  output
@@ -496,4 +496,41 @@ describe("OKHSV Color Schema", () => {
496
496
  });
497
497
  });
498
498
  });
499
+
500
+ describe("Alpha Channel Support", () => {
501
+ it("should set and get alpha property", async () => {
502
+ const result = await executeWithSchema(
503
+ "okhsv-color",
504
+ "type",
505
+ `
506
+ variable c: Color.OKHSV;
507
+ c.h = 180;
508
+ c.s = 0.5;
509
+ c.v = 0.5;
510
+ c.alpha = 0.7;
511
+ c.alpha
512
+ `,
513
+ );
514
+
515
+ expect((result as any).value).toBe(0.7);
516
+ });
517
+
518
+ it("should preserve alpha through conversions", async () => {
519
+ const result = await executeWithSchema(
520
+ "okhsv-color",
521
+ "type",
522
+ `
523
+ variable c: Color.OKHSV;
524
+ c.h = 180;
525
+ c.s = 0.5;
526
+ c.v = 0.5;
527
+ c.alpha = 0.6;
528
+ variable oklab: Color.OKLab = c.to.oklab();
529
+ oklab.alpha
530
+ `,
531
+ );
532
+
533
+ expect((result as any).value).toBe(0.6);
534
+ });
535
+ });
499
536
  });
@@ -1,6 +1,6 @@
1
1
  // OKLab Color Initializer
2
2
  // Creates an OKLab color from L, a, b values
3
- // Input: List of [l, a, b] values
3
+ // Input: List of [l, a, b] or [l, a, b, alpha] values
4
4
 
5
5
  variable lab_values: List = {input};
6
6
  variable output: Color.OKLab;
@@ -9,6 +9,11 @@ output.l = lab_values.get(0);
9
9
  output.a = lab_values.get(1);
10
10
  output.b = lab_values.get(2);
11
11
 
12
+ // Set alpha if provided as 4th parameter
13
+ if (lab_values.length() > 3) [
14
+ output.alpha = lab_values.get(3);
15
+ ];
16
+
12
17
  return output;
13
18
 
14
19
 
@@ -342,4 +342,62 @@ describe("OKLab Color Schema", () => {
342
342
  expect(Math.abs((result as any).value.b.value)).toBeLessThan(1e-5);
343
343
  });
344
344
  });
345
+
346
+ describe("Alpha Channel Support", () => {
347
+ it("should accept optional 4th parameter for alpha", async () => {
348
+ const result = await executeWithSchema(
349
+ "oklab-color",
350
+ "type",
351
+ `
352
+ variable c: Color.OKLab = oklab(0.5, 0.1, 0.2, 0.7);
353
+ c
354
+ `,
355
+ );
356
+
357
+ expect(result?.constructor.name).toBe("ColorSymbol");
358
+ expect((result as any).subType).toBe("OKLab");
359
+ expect((result as any).alpha).toBe(0.7);
360
+ });
361
+
362
+ it("should get alpha property", async () => {
363
+ const result = await executeWithSchema(
364
+ "oklab-color",
365
+ "type",
366
+ `
367
+ variable c: Color.OKLab = oklab(0.5, 0.1, 0.2, 0.5);
368
+ c.alpha
369
+ `,
370
+ );
371
+
372
+ expect((result as any).value).toBe(0.5);
373
+ });
374
+
375
+ it("should set alpha property", async () => {
376
+ const result = await executeWithSchema(
377
+ "oklab-color",
378
+ "type",
379
+ `
380
+ variable c: Color.OKLab = oklab(0.5, 0.1, 0.2);
381
+ c.alpha = 0.8;
382
+ c.alpha
383
+ `,
384
+ );
385
+
386
+ expect((result as any).value).toBe(0.8);
387
+ });
388
+
389
+ it("should preserve alpha through conversions", async () => {
390
+ const result = await executeWithSchema(
391
+ "oklab-color",
392
+ "type",
393
+ `
394
+ variable c: Color.OKLab = oklab(0.5, 0.1, 0.2, 0.6);
395
+ variable oklch: Color.OKLCH = c.to.oklch();
396
+ oklch.alpha
397
+ `,
398
+ );
399
+
400
+ expect((result as any).value).toBe(0.6);
401
+ });
402
+ });
345
403
  });
@@ -1,6 +1,6 @@
1
1
  // OKLCH Color Initializer
2
2
  // Creates an OKLCH color from L, C, H values
3
- // Input: List of [l, c, h] values
3
+ // Input: List of [l, c, h] or [l, c, h, alpha] values
4
4
 
5
5
  variable lch_values: List = {input};
6
6
  variable output: Color.OKLCH;
@@ -9,6 +9,11 @@ output.l = lch_values.get(0);
9
9
  output.c = lch_values.get(1);
10
10
  output.h = lch_values.get(2);
11
11
 
12
+ // Set alpha if provided as 4th parameter
13
+ if (lch_values.length() > 3) [
14
+ output.alpha = lch_values.get(3);
15
+ ];
16
+
12
17
  return output;
13
18
 
14
19
 
@@ -264,4 +264,62 @@ describe("OKLCH Color Schema", () => {
264
264
  expect((result as any).value.c.value).toBeLessThan(1e-5);
265
265
  });
266
266
  });
267
+
268
+ describe("Alpha Channel Support", () => {
269
+ it("should accept optional 4th parameter for alpha", async () => {
270
+ const result = await executeWithSchema(
271
+ "oklch-color",
272
+ "type",
273
+ `
274
+ variable c: Color.OKLCH = oklch(0.5, 0.1, 180, 0.7);
275
+ c
276
+ `,
277
+ );
278
+
279
+ expect(result?.constructor.name).toBe("ColorSymbol");
280
+ expect((result as any).subType).toBe("OKLCH");
281
+ expect((result as any).alpha).toBe(0.7);
282
+ });
283
+
284
+ it("should get alpha property", async () => {
285
+ const result = await executeWithSchema(
286
+ "oklch-color",
287
+ "type",
288
+ `
289
+ variable c: Color.OKLCH = oklch(0.5, 0.1, 180, 0.5);
290
+ c.alpha
291
+ `,
292
+ );
293
+
294
+ expect((result as any).value).toBe(0.5);
295
+ });
296
+
297
+ it("should set alpha property", async () => {
298
+ const result = await executeWithSchema(
299
+ "oklch-color",
300
+ "type",
301
+ `
302
+ variable c: Color.OKLCH = oklch(0.5, 0.1, 180);
303
+ c.alpha = 0.8;
304
+ c.alpha
305
+ `,
306
+ );
307
+
308
+ expect((result as any).value).toBe(0.8);
309
+ });
310
+
311
+ it("should preserve alpha through conversions", async () => {
312
+ const result = await executeWithSchema(
313
+ "oklch-color",
314
+ "type",
315
+ `
316
+ variable c: Color.OKLCH = oklch(0.5, 0.1, 180, 0.6);
317
+ variable oklab: Color.OKLab = c.to.oklab();
318
+ oklab.alpha
319
+ `,
320
+ );
321
+
322
+ expect((result as any).value).toBe(0.6);
323
+ });
324
+ });
267
325
  });
@@ -1,6 +1,6 @@
1
1
  // Display-P3 Color Initializer
2
2
  // Creates a Display-P3 color from 0-1 values
3
- // Input: List of [r, g, b] values
3
+ // Input: List of [r, g, b] or [r, g, b, alpha] values
4
4
 
5
5
  variable color_values: List = {input};
6
6
  variable output: Color.P3;
@@ -9,6 +9,11 @@ output.r = color_values.get(0);
9
9
  output.g = color_values.get(1);
10
10
  output.b = color_values.get(2);
11
11
 
12
+ // Set alpha if provided as 4th parameter
13
+ if (color_values.length() > 3) [
14
+ output.alpha = color_values.get(3);
15
+ ];
16
+
12
17
  return output;
13
18
 
14
19
 
@@ -116,4 +116,51 @@ describe("Display-P3 Color Schema", () => {
116
116
  expect(colorJS_p3Green.coords[0]).toBeLessThan(0);
117
117
  });
118
118
  });
119
+
120
+ describe("Alpha Channel Support", () => {
121
+ it("should accept optional 4th parameter for alpha", async () => {
122
+ const result = await executeWithSchema(
123
+ "p3-color",
124
+ "type",
125
+ `
126
+ variable c: Color.P3 = p3(1, 0, 0, 0.7);
127
+ c
128
+ `,
129
+ );
130
+
131
+ expect(result?.constructor.name).toBe("ColorSymbol");
132
+ expect((result as any).subType).toBe("P3");
133
+ expect((result as any).value.r.value).toBe(1);
134
+ expect((result as any).value.g.value).toBe(0);
135
+ expect((result as any).value.b.value).toBe(0);
136
+ expect((result as any).alpha).toBe(0.7);
137
+ });
138
+
139
+ it("should get alpha property", async () => {
140
+ const result = await executeWithSchema(
141
+ "p3-color",
142
+ "type",
143
+ `
144
+ variable c: Color.P3 = p3(1, 0, 0, 0.5);
145
+ c.alpha
146
+ `,
147
+ );
148
+
149
+ expect((result as any).value).toBe(0.5);
150
+ });
151
+
152
+ it("should set alpha property", async () => {
153
+ const result = await executeWithSchema(
154
+ "p3-color",
155
+ "type",
156
+ `
157
+ variable c: Color.P3 = p3(1, 0, 0);
158
+ c.alpha = 0.8;
159
+ c.alpha
160
+ `,
161
+ );
162
+
163
+ expect((result as any).value).toBe(0.8);
164
+ });
165
+ });
119
166
  });
@@ -2,8 +2,9 @@
2
2
  // Creates an RGB color from r, g, b values (0-255 range)
3
3
  //
4
4
  // Usage: rgb(255, 128, 64) → Color.Rgb { r: 255, g: 128, b: 64 }
5
+ // rgb(255, 128, 64, 0.5) → Color.Rgb { r: 255, g: 128, b: 64, alpha: 0.5 }
5
6
  //
6
- // Input: List of 3 numbers [r, g, b]
7
+ // Input: List of 3 or 4 numbers [r, g, b] or [r, g, b, alpha]
7
8
  // Output: Color.Rgb
8
9
 
9
10
  variable color_parts: List = {input};
@@ -13,4 +14,9 @@ output.r = color_parts.get(0);
13
14
  output.g = color_parts.get(1);
14
15
  output.b = color_parts.get(2);
15
16
 
17
+ // Set alpha if provided as 4th parameter
18
+ if (color_parts.length() > 3) [
19
+ output.alpha = color_parts.get(3);
20
+ ];
21
+
16
22
  return output;
@@ -0,0 +1,17 @@
1
+ // RGBA Color Initializer
2
+ // Creates an RGB color with alpha from r, g, b, a values
3
+ //
4
+ // Usage: rgba(255, 128, 64, 0.5) → Color.Rgb { r: 255, g: 128, b: 64, alpha: 0.5 }
5
+ //
6
+ // Input: List of 4 numbers [r, g, b, alpha]
7
+ // Output: Color.Rgb with alpha
8
+
9
+ variable color_parts: List = {input};
10
+
11
+ variable output: Color.Rgb;
12
+ output.r = color_parts.get(0);
13
+ output.g = color_parts.get(1);
14
+ output.b = color_parts.get(2);
15
+ output.alpha = color_parts.get(3);
16
+
17
+ return output;
@@ -28,6 +28,15 @@
28
28
  "type": "/api/v1/core/tokenscript/0/",
29
29
  "script": "./initializer.tokenscript"
30
30
  }
31
+ },
32
+ {
33
+ "title": "function",
34
+ "keyword": "rgba",
35
+ "description": "Creates an RGB color with alpha",
36
+ "script": {
37
+ "type": "/api/v1/core/tokenscript/0/",
38
+ "script": "./rgba-initializer.tokenscript"
39
+ }
31
40
  }
32
41
  ],
33
42
  "conversions": [
@@ -20,10 +20,13 @@ describe("RGB Color Schema", () => {
20
20
  it("should have initializers defined", async () => {
21
21
  const schema = (await getBundledSchema("rgb-color")) as ColorSpecification;
22
22
 
23
- expect(schema.initializers).toHaveLength(1);
23
+ expect(schema.initializers).toHaveLength(2);
24
24
  expect(schema.initializers[0].keyword).toBe("rgb");
25
25
  expect(schema.initializers[0].script.script).toBeTruthy();
26
26
  expect(schema.initializers[0].script.script).not.toContain("./");
27
+ expect(schema.initializers[1].keyword).toBe("rgba");
28
+ expect(schema.initializers[1].script.script).toBeTruthy();
29
+ expect(schema.initializers[1].script.script).not.toContain("./");
27
30
  });
28
31
 
29
32
  it("should have conversions defined", async () => {
@@ -299,4 +302,110 @@ describe("RGB Color Schema", () => {
299
302
  expect((result as any).value.b.value).toBe(200);
300
303
  });
301
304
  });
305
+
306
+ describe("Alpha Channel Support", () => {
307
+ it("should accept optional 4th parameter for alpha using rgb()", async () => {
308
+ const result = await executeWithSchema(
309
+ "rgb-color",
310
+ "type",
311
+ `
312
+ variable c: Color.Rgb = rgb(255, 128, 64, 0.5);
313
+ c
314
+ `,
315
+ );
316
+
317
+ expect(result?.constructor.name).toBe("ColorSymbol");
318
+ expect((result as any).subType).toBe("Rgb");
319
+ expect((result as any).value.r.value).toBe(255);
320
+ expect((result as any).value.g.value).toBe(128);
321
+ expect((result as any).value.b.value).toBe(64);
322
+ expect((result as any).alpha).toBe(0.5);
323
+ });
324
+
325
+ it("should create color with rgba() initializer", async () => {
326
+ const result = await executeWithSchema(
327
+ "rgb-color",
328
+ "type",
329
+ `
330
+ variable c: Color.Rgb = rgba(200, 100, 50, 0.75);
331
+ c
332
+ `,
333
+ );
334
+
335
+ expect(result?.constructor.name).toBe("ColorSymbol");
336
+ expect((result as any).subType).toBe("Rgb");
337
+ expect((result as any).value.r.value).toBe(200);
338
+ expect((result as any).value.g.value).toBe(100);
339
+ expect((result as any).value.b.value).toBe(50);
340
+ expect((result as any).alpha).toBe(0.75);
341
+ });
342
+
343
+ it("should get alpha property", async () => {
344
+ const result = await executeWithSchema(
345
+ "rgb-color",
346
+ "type",
347
+ `
348
+ variable c: Color.Rgb = rgb(255, 0, 0, 0.3);
349
+ c.alpha
350
+ `,
351
+ );
352
+
353
+ expect((result as any).value).toBe(0.3);
354
+ });
355
+
356
+ it("should set alpha property", async () => {
357
+ const result = await executeWithSchema(
358
+ "rgb-color",
359
+ "type",
360
+ `
361
+ variable c: Color.Rgb = rgb(255, 0, 0);
362
+ c.alpha = 0.9;
363
+ c.alpha
364
+ `,
365
+ );
366
+
367
+ expect((result as any).value).toBe(0.9);
368
+ });
369
+
370
+ it("should handle alpha = 0 (fully transparent)", async () => {
371
+ const result = await executeWithSchema(
372
+ "rgb-color",
373
+ "type",
374
+ `
375
+ variable c: Color.Rgb = rgb(255, 0, 0, 0);
376
+ c.alpha
377
+ `,
378
+ );
379
+
380
+ expect((result as any).value).toBe(0);
381
+ });
382
+
383
+ it("should handle alpha = 1 (fully opaque)", async () => {
384
+ const result = await executeWithSchema(
385
+ "rgb-color",
386
+ "type",
387
+ `
388
+ variable c: Color.Rgb = rgb(255, 0, 0, 1);
389
+ c.alpha
390
+ `,
391
+ );
392
+
393
+ expect((result as any).value).toBe(1);
394
+ });
395
+
396
+ it("should preserve alpha through HEX conversion", async () => {
397
+ const result = await executeWithSchema(
398
+ "rgb-color",
399
+ "type",
400
+ `
401
+ variable c: Color.Rgb = rgb(255, 0, 0, 0.5);
402
+ variable hex: Color.Hex = c.to.hex();
403
+ variable back: Color.Rgb = hex.to.rgb();
404
+ back.alpha
405
+ `,
406
+ );
407
+
408
+ expect((result as any).value).toBe(0.5);
409
+ });
410
+ });
302
411
  });
@@ -1,6 +1,6 @@
1
1
  // sRGB Color Initializer
2
2
  // Creates an sRGB color from normalized 0-1 values
3
- // Input: List of [r, g, b] values in 0-1 range
3
+ // Input: List of [r, g, b] or [r, g, b, alpha] values in 0-1 range
4
4
 
5
5
  variable color_values: List = {input};
6
6
  variable output: Color.SRGB;
@@ -9,6 +9,11 @@ output.r = color_values.get(0);
9
9
  output.g = color_values.get(1);
10
10
  output.b = color_values.get(2);
11
11
 
12
+ // Set alpha if provided as 4th parameter
13
+ if (color_values.length() > 3) [
14
+ output.alpha = color_values.get(3);
15
+ ];
16
+
12
17
  return output;
13
18
 
14
19