@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
@@ -300,4 +300,93 @@ describe("sRGB Color Schema", () => {
300
300
  expect((result as any).value.r.value).toBeCloseTo(expected, 10);
301
301
  });
302
302
  });
303
+
304
+ describe("Alpha Channel Support", () => {
305
+ it("should accept optional 4th parameter for alpha", async () => {
306
+ const result = await executeWithSchema(
307
+ "srgb-color",
308
+ "type",
309
+ `
310
+ variable c: Color.SRGB = srgb(1, 0, 0, 0.5);
311
+ c
312
+ `,
313
+ );
314
+
315
+ expect(result?.constructor.name).toBe("ColorSymbol");
316
+ expect((result as any).subType).toBe("SRGB");
317
+ expect((result as any).value.r.value).toBe(1);
318
+ expect((result as any).value.g.value).toBe(0);
319
+ expect((result as any).value.b.value).toBe(0);
320
+ // Alpha is stored directly, not as a Symbol
321
+ expect((result as any).alpha).toBe(0.5);
322
+ });
323
+
324
+ it("should get alpha property", async () => {
325
+ const result = await executeWithSchema(
326
+ "srgb-color",
327
+ "type",
328
+ `
329
+ variable c: Color.SRGB = srgb(1, 0, 0, 0.7);
330
+ c.alpha
331
+ `,
332
+ );
333
+
334
+ // When accessing .alpha it returns a NumberSymbol
335
+ expect((result as any).value).toBe(0.7);
336
+ });
337
+
338
+ it("should set alpha property", async () => {
339
+ const result = await executeWithSchema(
340
+ "srgb-color",
341
+ "type",
342
+ `
343
+ variable c: Color.SRGB = srgb(1, 0, 0);
344
+ c.alpha = 0.3;
345
+ c.alpha
346
+ `,
347
+ );
348
+
349
+ expect((result as any).value).toBe(0.3);
350
+ });
351
+
352
+ it("should handle alpha = 0 (fully transparent)", async () => {
353
+ const result = await executeWithSchema(
354
+ "srgb-color",
355
+ "type",
356
+ `
357
+ variable c: Color.SRGB = srgb(1, 0, 0, 0);
358
+ c.alpha
359
+ `,
360
+ );
361
+
362
+ expect((result as any).value).toBe(0);
363
+ });
364
+
365
+ it("should handle alpha = 1 (fully opaque)", async () => {
366
+ const result = await executeWithSchema(
367
+ "srgb-color",
368
+ "type",
369
+ `
370
+ variable c: Color.SRGB = srgb(1, 0, 0, 1);
371
+ c.alpha
372
+ `,
373
+ );
374
+
375
+ expect((result as any).value).toBe(1);
376
+ });
377
+
378
+ it("should preserve alpha through conversion from RGB", async () => {
379
+ const result = await executeWithSchema(
380
+ "srgb-color",
381
+ "type",
382
+ `
383
+ variable rgb: Color.Rgb = rgb(255, 0, 0, 0.8);
384
+ variable c: Color.SRGB = rgb.to.srgb();
385
+ c.alpha
386
+ `,
387
+ );
388
+
389
+ expect((result as any).value).toBe(0.8);
390
+ });
391
+ });
303
392
  });
@@ -1,89 +0,0 @@
1
- {
2
- "name": "Rgba",
3
- "type": "color",
4
- "description": "RGBA color",
5
- "schema": {
6
- "type": "object",
7
- "properties": {
8
- "r": {
9
- "type": "number"
10
- },
11
- "g": {
12
- "type": "number"
13
- },
14
- "b": {
15
- "type": "number"
16
- },
17
- "a": {
18
- "type": "number"
19
- }
20
- },
21
- "required": [
22
- "r",
23
- "g",
24
- "b",
25
- "a"
26
- ],
27
- "order": [
28
- "r",
29
- "g",
30
- "b",
31
- "a"
32
- ],
33
- "additionalProperties": false
34
- },
35
- "initializers": [
36
- {
37
- "title": "function",
38
- "keyword": "rgba",
39
- "description": "Creates an RGBA color",
40
- "script": {
41
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
42
- "script": "variable color_parts: List = {input};\nvariable output: Color.Rgba;\noutput.r = color_parts.get(0);\noutput.g = color_parts.get(1);\noutput.b = color_parts.get(2);\noutput.a = color_parts.get(3);\nreturn output;"
43
- }
44
- }
45
- ],
46
- "conversions": [
47
- {
48
- "source": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/hex-color/0/",
49
- "target": "$self",
50
- "description": "Converts HEX to RGBA",
51
- "lossless": true,
52
- "script": {
53
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
54
- "script": "variable color_parts: List = {input}.to_string().split('#');\nvariable color: List = color_parts.get(1).split();\nvariable length: Number = color.length();\nvariable rgba: List = 0, 0, 0, 1.0;\nif(length == 3) [\n rgba.update(0, parse_int(color.get(0).concat(color.get(0)), 16));\n rgba.update(1, parse_int(color.get(1).concat(color.get(1)), 16));\n rgba.update(2, parse_int(color.get(2).concat(color.get(2)), 16));\n] else [\n rgba.update(0, parse_int(color.get(0).concat(color.get(1)), 16));\n rgba.update(1, parse_int(color.get(2).concat(color.get(3)), 16));\n rgba.update(2, parse_int(color.get(4).concat(color.get(5)), 16));\n];\n\nvariable output: Color.Rgba;\noutput.r = rgba.get(0);\noutput.g = rgba.get(1);\noutput.b = rgba.get(2);\noutput.a = rgba.get(3);\n\nreturn output;"
55
- }
56
- },
57
- {
58
- "source": "$self",
59
- "target": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/hex-color/0/",
60
- "description": "Converts RGBA to HEX",
61
- "lossless": false,
62
- "script": {
63
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
64
- "script": "variable rgba: List = {input}.r, {input}.g, {input}.b;\nvariable hex: String = \"#\";\nvariable i: Number = 0;\nvariable value: Number = 0;\n\n// Convert RGBA to Hex (excluding alpha)\nwhile( i < rgba.length()) [\n value = round(rgba.get(i));\n if(value < 16) [\n hex = hex.concat(\"0\").concat(value.to_string(16));\n ] else [\n hex = hex.concat(value.to_string(16));\n ];\n i = i + 1;\n];\n\nreturn hex;"
65
- }
66
- },
67
- {
68
- "source": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/rgb-color/0/",
69
- "target": "$self",
70
- "description": "Converts RGB to RGBA",
71
- "lossless": true,
72
- "script": {
73
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
74
- "script": "variable output: Color.Rgba;\noutput.r = {input}.r;\noutput.g = {input}.g;\noutput.b = {input}.b;\noutput.a = 1.0;\nreturn output;"
75
- }
76
- },
77
- {
78
- "source": "$self",
79
- "target": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/rgb-color/0/",
80
- "description": "Converts RGBA to RGB",
81
- "lossless": false,
82
- "script": {
83
- "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
84
- "script": "variable output: Color.Rgb;\noutput.r = {input}.r;\noutput.g = {input}.g;\noutput.b = {input}.b;\nreturn output;"
85
- }
86
- }
87
- ],
88
- "slug": "rgba-color"
89
- }