@tokens-studio/tokenscript-schemas 0.2.0 → 0.3.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokens-studio/tokenscript-schemas",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Schema registry for TokenScript with bundled schemas and validation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -69,7 +69,7 @@
69
69
  "author": "Tokens Studio (https://tokens.studio)",
70
70
  "license": "MPL-2.0",
71
71
  "dependencies": {
72
- "@tokens-studio/tokenscript-interpreter": "^0.17.1",
72
+ "@tokens-studio/tokenscript-interpreter": "^0.21.0",
73
73
  "arktype": "^2.1.25",
74
74
  "cac": "^6.7.14",
75
75
  "ulog": "^2.0.0-beta.19"
@@ -22,6 +22,7 @@ variable result: Color.OKLCH;
22
22
  result.l = color.l;
23
23
  result.c = new_c;
24
24
  result.h = color.h;
25
+ result.alpha = color.alpha;
25
26
 
26
27
  return result;
27
28
 
@@ -72,5 +72,19 @@ describe("adjust_chroma function", () => {
72
72
  expect(Math.abs(r - g)).toBeLessThan(0.02);
73
73
  expect(Math.abs(g - b)).toBeLessThan(0.02);
74
74
  });
75
+
76
+ it("should preserve alpha channel", async () => {
77
+ const result = await executeWithSchema(
78
+ "adjust_chroma",
79
+ "function",
80
+ `
81
+ variable color: Color.OKLCH = oklch(0.5, 0.15, 30, 0.7);
82
+ adjust_chroma(color, 0.05)
83
+ `,
84
+ );
85
+
86
+ expect(result?.constructor.name).toBe("ColorSymbol");
87
+ expect((result as any).alpha).toBe(0.7);
88
+ });
75
89
  });
76
90
  });
@@ -27,6 +27,7 @@ variable result: Color.OKLCH;
27
27
  result.l = color.l;
28
28
  result.c = color.c;
29
29
  result.h = new_h;
30
+ result.alpha = color.alpha;
30
31
 
31
32
  return result;
32
33
 
@@ -64,5 +64,19 @@ describe("adjust_hue function", () => {
64
64
  const r = (result as any).value?.r?.value ?? (result as any).value?.r;
65
65
  expect(r).toBeGreaterThan(0.7);
66
66
  });
67
+
68
+ it("should preserve alpha channel", async () => {
69
+ const result = await executeWithSchema(
70
+ "adjust_hue",
71
+ "function",
72
+ `
73
+ variable color: Color.OKLCH = oklch(0.5, 0.15, 30, 0.7);
74
+ adjust_hue(color, 90)
75
+ `,
76
+ );
77
+
78
+ expect(result?.constructor.name).toBe("ColorSymbol");
79
+ expect((result as any).alpha).toBe(0.7);
80
+ });
67
81
  });
68
82
  });
@@ -26,6 +26,7 @@ variable result: Color.OKLCH;
26
26
  result.l = new_l;
27
27
  result.c = color.c;
28
28
  result.h = color.h;
29
+ result.alpha = color.alpha;
29
30
 
30
31
  return result;
31
32
 
@@ -84,5 +84,19 @@ describe("adjust_lightness function", () => {
84
84
  const r = (result as any).value?.r?.value ?? (result as any).value?.r;
85
85
  expect(r).toBeCloseTo(1, 1);
86
86
  });
87
+
88
+ it("should preserve alpha channel", async () => {
89
+ const result = await executeWithSchema(
90
+ "adjust_lightness",
91
+ "function",
92
+ `
93
+ variable color: Color.OKLCH = oklch(0.5, 0.15, 30, 0.7);
94
+ adjust_lightness(color, 0.1)
95
+ `,
96
+ );
97
+
98
+ expect(result?.constructor.name).toBe("ColorSymbol");
99
+ expect((result as any).alpha).toBe(0.7);
100
+ });
87
101
  });
88
102
  });
@@ -16,6 +16,7 @@ variable result: Color.OKLCH;
16
16
  result.l = color.l;
17
17
  result.c = new_c;
18
18
  result.h = color.h;
19
+ result.alpha = color.alpha;
19
20
 
20
21
  return result;
21
22
 
@@ -56,5 +56,19 @@ describe("clamp_chroma function", () => {
56
56
  expect(Math.abs(r - g)).toBeLessThan(0.1);
57
57
  expect(Math.abs(g - b)).toBeLessThan(0.1);
58
58
  });
59
+
60
+ it("should preserve alpha channel", async () => {
61
+ const result = await executeWithSchema(
62
+ "clamp_chroma",
63
+ "function",
64
+ `
65
+ variable color: Color.OKLCH = oklch(0.5, 0.15, 30, 0.7);
66
+ clamp_chroma(color, 0.05, 0.2)
67
+ `,
68
+ );
69
+
70
+ expect(result?.constructor.name).toBe("ColorSymbol");
71
+ expect((result as any).alpha).toBe(0.7);
72
+ });
59
73
  });
60
74
  });
@@ -16,6 +16,7 @@ variable result: Color.OKLCH;
16
16
  result.l = new_l;
17
17
  result.c = color.c;
18
18
  result.h = color.h;
19
+ result.alpha = color.alpha;
19
20
 
20
21
  return result;
21
22
 
@@ -72,5 +72,19 @@ describe("clamp_lightness function", () => {
72
72
  expect(r).toBeGreaterThan(0.3);
73
73
  expect(r).toBeLessThan(0.7);
74
74
  });
75
+
76
+ it("should preserve alpha channel", async () => {
77
+ const result = await executeWithSchema(
78
+ "clamp_lightness",
79
+ "function",
80
+ `
81
+ variable color: Color.OKLCH = oklch(0.5, 0.15, 30, 0.7);
82
+ clamp_lightness(color, 0.3, 0.7)
83
+ `,
84
+ );
85
+
86
+ expect(result?.constructor.name).toBe("ColorSymbol");
87
+ expect((result as any).alpha).toBe(0.7);
88
+ });
75
89
  });
76
90
  });
@@ -17,6 +17,7 @@ variable result: Color.OKLCH;
17
17
  result.l = color.l;
18
18
  result.c = new_c;
19
19
  result.h = color.h;
20
+ result.alpha = color.alpha;
20
21
 
21
22
  return result;
22
23
 
@@ -75,5 +75,19 @@ describe("scale_chroma function", () => {
75
75
  expect(Math.abs(r - g)).toBeLessThan(0.05);
76
76
  expect(Math.abs(g - b)).toBeLessThan(0.05);
77
77
  });
78
+
79
+ it("should preserve alpha channel", async () => {
80
+ const result = await executeWithSchema(
81
+ "scale_chroma",
82
+ "function",
83
+ `
84
+ variable color: Color.OKLCH = oklch(0.5, 0.15, 30, 0.7);
85
+ scale_chroma(color, 1.5)
86
+ `,
87
+ );
88
+
89
+ expect(result?.constructor.name).toBe("ColorSymbol");
90
+ expect((result as any).alpha).toBe(0.7);
91
+ });
78
92
  });
79
93
  });
@@ -18,6 +18,7 @@ variable result: Color.OKLCH;
18
18
  result.l = new_l;
19
19
  result.c = color.c;
20
20
  result.h = color.h;
21
+ result.alpha = color.alpha;
21
22
 
22
23
  return result;
23
24
 
@@ -69,5 +69,19 @@ describe("scale_lightness function", () => {
69
69
  const r = (result as any).value?.r?.value ?? (result as any).value?.r;
70
70
  expect(r).toBeCloseTo(0, 1);
71
71
  });
72
+
73
+ it("should preserve alpha channel", async () => {
74
+ const result = await executeWithSchema(
75
+ "scale_lightness",
76
+ "function",
77
+ `
78
+ variable color: Color.OKLCH = oklch(0.5, 0.15, 30, 0.7);
79
+ scale_lightness(color, 1.2)
80
+ `,
81
+ );
82
+
83
+ expect(result?.constructor.name).toBe("ColorSymbol");
84
+ expect((result as any).alpha).toBe(0.7);
85
+ });
72
86
  });
73
87
  });
@@ -13,6 +13,7 @@ variable result: Color.OKLCH;
13
13
  result.l = color.l;
14
14
  result.c = target_c;
15
15
  result.h = color.h;
16
+ result.alpha = color.alpha;
16
17
 
17
18
  return result;
18
19
 
@@ -75,5 +75,19 @@ describe("Set Chroma Function", () => {
75
75
  const b = (result as any).value.b.value;
76
76
  expect((r + g + b) / 3).toBeGreaterThan(0.5);
77
77
  });
78
+
79
+ it("should preserve alpha channel", async () => {
80
+ const result = await executeWithSchema(
81
+ "set_chroma",
82
+ "function",
83
+ `
84
+ variable color: Color.OKLCH = oklch(0.5, 0.15, 30, 0.7);
85
+ set_chroma(color, 0.1)
86
+ `,
87
+ );
88
+
89
+ expect(result?.constructor.name).toBe("ColorSymbol");
90
+ expect((result as any).alpha).toBe(0.7);
91
+ });
78
92
  });
79
93
  });
@@ -13,6 +13,7 @@ variable result: Color.OKLCH;
13
13
  result.l = color.l;
14
14
  result.c = color.c;
15
15
  result.h = target_h;
16
+ result.alpha = color.alpha;
16
17
 
17
18
  return result;
18
19
 
@@ -86,5 +86,19 @@ describe("Set Hue Function", () => {
86
86
 
87
87
  expect(result?.constructor.name).toBe("ColorSymbol");
88
88
  });
89
+
90
+ it("should preserve alpha channel", async () => {
91
+ const result = await executeWithSchema(
92
+ "set_hue",
93
+ "function",
94
+ `
95
+ variable color: Color.OKLCH = oklch(0.5, 0.15, 30, 0.7);
96
+ set_hue(color, 180)
97
+ `,
98
+ );
99
+
100
+ expect(result?.constructor.name).toBe("ColorSymbol");
101
+ expect((result as any).alpha).toBe(0.7);
102
+ });
89
103
  });
90
104
  });
@@ -13,6 +13,7 @@ variable result: Color.OKLCH;
13
13
  result.l = target_l;
14
14
  result.c = color.c;
15
15
  result.h = color.h;
16
+ result.alpha = color.alpha;
16
17
 
17
18
  return result;
18
19
 
@@ -76,5 +76,19 @@ describe("Set Lightness Function", () => {
76
76
  expect(r).toBeGreaterThan(g);
77
77
  expect(r).toBeGreaterThan(b);
78
78
  });
79
+
80
+ it("should preserve alpha channel", async () => {
81
+ const result = await executeWithSchema(
82
+ "set_lightness",
83
+ "function",
84
+ `
85
+ variable color: Color.OKLCH = oklch(0.5, 0.15, 30, 0.7);
86
+ set_lightness(color, 0.8)
87
+ `,
88
+ );
89
+
90
+ expect(result?.constructor.name).toBe("ColorSymbol");
91
+ expect((result as any).alpha).toBe(0.7);
92
+ });
79
93
  });
80
94
  });