@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.
- package/README.md +21 -0
- package/bundled/functions/adjust_chroma.json +60 -0
- package/bundled/functions/adjust_hue.json +60 -0
- package/bundled/functions/adjust_lightness.json +60 -0
- package/bundled/functions/adjust_to_contrast.json +67 -0
- package/bundled/functions/alpha_blend.json +31 -0
- package/bundled/functions/alpha_scale.json +27 -0
- package/bundled/functions/analogous.json +32 -0
- package/bundled/functions/apca_contrast.json +27 -0
- package/bundled/functions/are_similar.json +73 -0
- package/bundled/functions/auto_text_color.json +66 -0
- package/bundled/functions/best_contrast.json +28 -0
- package/bundled/functions/chroma.json +54 -0
- package/bundled/functions/clamp_chroma.json +66 -0
- package/bundled/functions/clamp_lightness.json +66 -0
- package/bundled/functions/clamp_to_gamut.json +23 -0
- package/bundled/functions/complement.json +24 -0
- package/bundled/functions/contrast_ratio.json +27 -0
- package/bundled/functions/cooler.json +52 -0
- package/bundled/functions/darken.json +28 -0
- package/bundled/functions/delta_e_2000.json +40 -0
- package/bundled/functions/delta_e_76.json +27 -0
- package/bundled/functions/delta_e_ok.json +27 -0
- package/bundled/functions/desaturate.json +28 -0
- package/bundled/functions/distributed.json +36 -0
- package/bundled/functions/diverging.json +36 -0
- package/bundled/functions/grayscale.json +24 -0
- package/bundled/functions/harmonize.json +65 -0
- package/bundled/functions/hue.json +54 -0
- package/bundled/functions/hue_difference.json +27 -0
- package/bundled/functions/in_gamut.json +27 -0
- package/bundled/functions/interpolate.json +66 -0
- package/bundled/functions/invert.json +1 -1
- package/bundled/functions/is_cool.json +23 -0
- package/bundled/functions/is_dark.json +27 -0
- package/bundled/functions/is_light.json +27 -0
- package/bundled/functions/is_neutral.json +65 -0
- package/bundled/functions/is_warm.json +23 -0
- package/bundled/functions/lighten.json +28 -0
- package/bundled/functions/lightness.json +61 -0
- package/bundled/functions/luminance.json +23 -0
- package/bundled/functions/meets_contrast.json +31 -0
- package/bundled/functions/mix.json +32 -0
- package/bundled/functions/monochromatic.json +28 -0
- package/bundled/functions/muted.json +59 -0
- package/bundled/functions/neutral_variant.json +59 -0
- package/bundled/functions/relative_luminance.json +61 -0
- package/bundled/functions/rotate_hue.json +28 -0
- package/bundled/functions/saturate.json +28 -0
- package/bundled/functions/scale_chroma.json +60 -0
- package/bundled/functions/scale_lightness.json +60 -0
- package/bundled/functions/sepia.json +59 -0
- package/bundled/functions/set_chroma.json +28 -0
- package/bundled/functions/set_hue.json +28 -0
- package/bundled/functions/set_lightness.json +28 -0
- package/bundled/functions/shade_scale.json +28 -0
- package/bundled/functions/split_complement.json +28 -0
- package/bundled/functions/steps.json +32 -0
- package/bundled/functions/tetradic.json +24 -0
- package/bundled/functions/tint_scale.json +36 -0
- package/bundled/functions/to_gamut.json +59 -0
- package/bundled/functions/triadic.json +24 -0
- package/bundled/functions/vibrant.json +59 -0
- package/bundled/functions/warmer.json +52 -0
- package/bundled/functions/wcag_level.json +60 -0
- package/bundled/functions.json +2602 -6
- package/bundled/registry.json +3705 -84
- package/bundled/types/css-color.json +151 -0
- package/bundled/types/hsl-color.json +66 -0
- package/bundled/types/hsv-color.json +57 -0
- package/bundled/types/hwb-color.json +66 -0
- package/bundled/types/lab-color.json +57 -0
- package/bundled/types/lch-color.json +57 -0
- package/bundled/types/okhsl-color.json +57 -0
- package/bundled/types/okhsv-color.json +57 -0
- package/bundled/types/oklab-color.json +87 -0
- package/bundled/types/oklch-color.json +57 -0
- package/bundled/types/p3-color.json +57 -0
- package/bundled/types/p3-linear-color.json +57 -0
- package/bundled/types/rgb-color.json +12 -3
- package/bundled/types/srgb-color.json +77 -0
- package/bundled/types/srgb-linear-color.json +67 -0
- package/bundled/types/xyz-d50-color.json +57 -0
- package/bundled/types/xyz-d65-color.json +77 -0
- package/bundled/types.json +1067 -43
- package/dist/cli/index.cjs +231 -22
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +231 -22
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +5 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
- package/src/bundler/index.ts +7 -0
- package/src/bundler/presets/css.ts +21 -0
- package/src/bundler/presets/index.ts +47 -0
- package/src/bundler/presets/types.ts +10 -0
- package/src/bundler/selective-bundler.ts +9 -0
- package/src/bundler/types.ts +1 -0
- package/src/cli/commands/bundle.test.ts +34 -0
- package/src/cli/commands/bundle.ts +37 -11
- package/src/cli/commands/list.ts +36 -4
- package/src/cli/commands/presets.ts +81 -0
- package/src/cli/index.ts +12 -1
- package/src/cli/output-generator.ts +8 -2
- package/src/cli/version-info.ts +93 -0
- package/src/schemas/types/css-color/from-hsl-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-hwb-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-lab-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-lch-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-oklab-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-oklch-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-p3-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-rgb-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-srgb-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-xyz-d50-color.tokenscript +17 -4
- package/src/schemas/types/css-color/from-xyz-d65-color.tokenscript +17 -4
- package/src/schemas/types/css-color/unit.test.ts +216 -0
- package/src/schemas/types/hex-color/unit.test.ts +18 -0
- package/src/schemas/types/hsl-color/hsla-initializer.tokenscript +17 -0
- package/src/schemas/types/hsl-color/initializer.tokenscript +6 -1
- package/src/schemas/types/hsl-color/schema.json +9 -0
- package/src/schemas/types/hsl-color/unit.test.ts +95 -1
- package/src/schemas/types/hsv-color/initializer.tokenscript +6 -1
- package/src/schemas/types/hsv-color/unit.test.ts +44 -0
- package/src/schemas/types/hwb-color/hwba-initializer.tokenscript +17 -0
- package/src/schemas/types/hwb-color/initializer.tokenscript +6 -1
- package/src/schemas/types/hwb-color/schema.json +9 -0
- package/src/schemas/types/hwb-color/unit.test.ts +70 -0
- package/src/schemas/types/lab-color/initializer.tokenscript +6 -1
- package/src/schemas/types/lab-color/unit.test.ts +44 -0
- package/src/schemas/types/lch-color/initializer.tokenscript +6 -1
- package/src/schemas/types/lch-color/unit.test.ts +44 -0
- package/src/schemas/types/okhsl-color/initializer.tokenscript +8 -1
- package/src/schemas/types/okhsl-color/unit.test.ts +37 -0
- package/src/schemas/types/okhsv-color/initializer.tokenscript +8 -1
- package/src/schemas/types/okhsv-color/unit.test.ts +37 -0
- package/src/schemas/types/oklab-color/initializer.tokenscript +6 -1
- package/src/schemas/types/oklab-color/unit.test.ts +58 -0
- package/src/schemas/types/oklch-color/initializer.tokenscript +6 -1
- package/src/schemas/types/oklch-color/unit.test.ts +58 -0
- package/src/schemas/types/p3-color/initializer.tokenscript +6 -1
- package/src/schemas/types/p3-color/unit.test.ts +47 -0
- package/src/schemas/types/rgb-color/initializer.tokenscript +7 -1
- package/src/schemas/types/rgb-color/rgba-initializer.tokenscript +17 -0
- package/src/schemas/types/rgb-color/schema.json +9 -0
- package/src/schemas/types/rgb-color/unit.test.ts +110 -1
- package/src/schemas/types/srgb-color/initializer.tokenscript +6 -1
- package/src/schemas/types/srgb-color/unit.test.ts +89 -0
- 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
|
-
}
|