@tokens-studio/tokenscript-schemas 0.0.10

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 ADDED
@@ -0,0 +1,152 @@
1
+ # @tokens-studio/tokenscript-schemas
2
+
3
+ Schema registry test setup for TokenScript with bundled schemas and validation.
4
+
5
+ ## Overview
6
+
7
+ This package provides a centralized registry of TokenScript schemas with tools to:
8
+
9
+ - **Organize** schemas in a clean, testable structure with file-based script references
10
+ - **Bundle** schemas for distribution with shared bundling logic
11
+ - **Load** schemas at runtime with automatic bundling
12
+ - **Test** schema implementations without requiring a build step
13
+
14
+ ## Usage
15
+
16
+ ### CLI Tool
17
+
18
+ Bundle specific schemas for use in your projects with automatic dependency resolution:
19
+
20
+ ```bash
21
+ # Bundle specific color schemas
22
+ npx @tokens-studio/tokenscript-schemas bundle oklch-color rgb-color -o ./schemas.js
23
+
24
+ # Bundle with functions
25
+ npx @tokens-studio/tokenscript-schemas bundle rgb-color function:invert -o ./schemas.js
26
+
27
+ # Use config file for repeatable builds
28
+ npx @tokens-studio/tokenscript-schemas bundle --config schemas.json
29
+
30
+ # Preview what would be bundled (dry-run)
31
+ npx @tokens-studio/tokenscript-schemas bundle oklch-color rgb-color --dry-run
32
+
33
+ # List available schemas
34
+ npx @tokens-studio/tokenscript-schemas list
35
+ npx @tokens-studio/tokenscript-schemas list --types
36
+ npx @tokens-studio/tokenscript-schemas list --functions
37
+ ```
38
+
39
+ **Config File Format** (`schemas.json`):
40
+
41
+ ```json
42
+ {
43
+ "schemas": ["oklch-color", "rgb-color", "function:invert"],
44
+ "output": "./src/generated/schemas.js"
45
+ }
46
+ ```
47
+
48
+ **Generated Output** (`schemas.js`):
49
+
50
+ ```javascript
51
+ import { Config } from "@tokens-studio/tokenscript-interpreter";
52
+
53
+ export const SCHEMAS = [
54
+ { uri: "https://schema.../rgb-color/0/", schema: { /* bundled schema */ } },
55
+ { uri: "https://schema.../oklch-color/0/", schema: { /* bundled schema */ } },
56
+ // ... all dependencies included
57
+ ];
58
+
59
+ export function makeConfig() {
60
+ return new Config().registerSchemas(SCHEMAS);
61
+ }
62
+ ```
63
+
64
+ **Using in Your Code**:
65
+
66
+ ```javascript
67
+ import { makeConfig } from "./schemas.js";
68
+ import { Interpreter, Lexer, Parser } from "@tokens-studio/tokenscript-interpreter";
69
+
70
+ const config = makeConfig();
71
+
72
+ const code = `
73
+ variable c: Color.Rgb = rgb(255, 128, 64);
74
+ c.to.oklch()
75
+ `;
76
+
77
+ const lexer = new Lexer(code);
78
+ const parser = new Parser(lexer);
79
+ const interpreter = new Interpreter(parser, { config });
80
+ const result = interpreter.interpret();
81
+ ```
82
+
83
+ ## Structure
84
+
85
+ Each schema is self-contained in its own folder with file-based script references:
86
+
87
+ ```
88
+ src/schemas/types/srgb-color/
89
+ ├── schema.json # Complete schema definition (with file references)
90
+ ├── srgb-initializer.tokenscript # Initializer script
91
+ ├── from-hex-color.tokenscript # Conversion: HEX → SRGB
92
+ ├── to-hex-color.tokenscript # Conversion: SRGB → HEX
93
+ └── unit.test.ts # Co-located tests
94
+ ```
95
+
96
+ **Key Points:**
97
+ - `schema.json` contains the complete schema definition with script references like `"./filename.tokenscript"`
98
+ - Scripts are standalone `.tokenscript` files for better readability and syntax highlighting
99
+ - Tests use runtime bundling - no build step required
100
+ - The bundler inlines script content for distribution
101
+
102
+ ## Scripts
103
+
104
+ ### Bundle Schemas
105
+
106
+ ```bash
107
+ npm run bundle
108
+ ```
109
+
110
+ Bundles all schemas using the **shared bundling logic** from `@/bundler/bundle-schema.ts`:
111
+ - Reads `schema.json` from each schema directory
112
+ - Finds all `./file.tokenscript` references in the schema
113
+ - Reads and inlines the script file content
114
+ - Outputs bundled schemas to `bundled/` directory:
115
+ - `registry.json` - Complete registry
116
+ - `types.json` - All type schemas
117
+ - `functions.json` - All function schemas
118
+ - `types/{slug}.json` - Individual type schemas
119
+ - `functions/{slug}.json` - Individual function schemas
120
+
121
+ ### Run Tests
122
+
123
+ ```bash
124
+ # Run all tests (logs disabled by default)
125
+ npm test
126
+
127
+ # Run tests with verbose logging
128
+ npm run test:verbose
129
+ # or
130
+ LOG_LEVEL=info npm test
131
+
132
+ # Run tests with debug logging
133
+ npm run test:debug
134
+ # or
135
+ LOG_LEVEL=debug npm test
136
+
137
+ # Run specific test file
138
+ npm test -- src/schemas/types/rgb-color/unit.test.ts
139
+ ```
140
+
141
+ **Test Logging:**
142
+ - Logs are **disabled by default** to reduce noise (only errors shown)
143
+ - Use `LOG_LEVEL` environment variable to enable logs: `debug`, `info`, `warn`, `error`
144
+ - See [tests/helpers/LOGGING.md](tests/helpers/LOGGING.md) for detailed logging documentation
145
+ - Tests use `bundleSchemaFromDirectory()` from `@/bundler/bundle-schema.ts`
146
+ - No build step required - schemas are bundled on-demand
147
+ - Same bundling logic as build-time for consistency
148
+
149
+ ## Links
150
+
151
+ - [TokenScript Interpreter](https://github.com/tokens-studio/tokenscript-interpreter)
152
+ - [Schema API](https://schema.tokenscript.dev.gcp.tokens.studio/)
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "Invert Color",
3
+ "type": "function",
4
+ "description": "Inverts a color by inverting each RGB channel (R' = 255 - R, G' = 255 - G, B' = 255 - B).",
5
+ "keyword": "invert",
6
+ "input": {
7
+ "type": "object",
8
+ "properties": {
9
+ "color": {
10
+ "type": "color",
11
+ "description": "The color to invert."
12
+ }
13
+ }
14
+ },
15
+ "script": {
16
+ "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
17
+ "script": "variable input: List = {input};\n\nvariable rgb_color: Color.Rgb = input.get(0).to.rgb();\n\nvariable inverted_r: Number = 255 - rgb_color.r;\nvariable inverted_g: Number = 255 - rgb_color.g;\nvariable inverted_b: Number = 255 - rgb_color.b;\n\nvariable inverted_color: Color.Rgb = rgb(inverted_r, inverted_g, inverted_b);\nreturn inverted_color;"
18
+ },
19
+ "requirements": [
20
+ "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/rgb-color/0/"
21
+ ],
22
+ "slug": "invert"
23
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "version": "0.0.10",
3
+ "functions": [
4
+ {
5
+ "name": "Invert Color",
6
+ "type": "function",
7
+ "description": "Inverts a color by inverting each RGB channel (R' = 255 - R, G' = 255 - G, B' = 255 - B).",
8
+ "keyword": "invert",
9
+ "input": {
10
+ "type": "object",
11
+ "properties": {
12
+ "color": {
13
+ "type": "color",
14
+ "description": "The color to invert."
15
+ }
16
+ }
17
+ },
18
+ "script": {
19
+ "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
20
+ "script": "variable input: List = {input};\n\nvariable rgb_color: Color.Rgb = input.get(0).to.rgb();\n\nvariable inverted_r: Number = 255 - rgb_color.r;\nvariable inverted_g: Number = 255 - rgb_color.g;\nvariable inverted_b: Number = 255 - rgb_color.b;\n\nvariable inverted_color: Color.Rgb = rgb(inverted_r, inverted_g, inverted_b);\nreturn inverted_color;"
21
+ },
22
+ "requirements": [
23
+ "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/rgb-color/0/"
24
+ ],
25
+ "slug": "invert"
26
+ }
27
+ ]
28
+ }
@@ -0,0 +1,212 @@
1
+ {
2
+ "version": "0.0.10",
3
+ "types": [
4
+ {
5
+ "name": "Hex",
6
+ "type": "color",
7
+ "description": "A color in hex format, e.g. #ff0000",
8
+ "schema": {
9
+ "type": "object",
10
+ "properties": {
11
+ "value": {
12
+ "type": "string"
13
+ }
14
+ }
15
+ },
16
+ "initializers": [
17
+ {
18
+ "title": "Hex Color Initializer",
19
+ "keyword": "hex",
20
+ "script": {
21
+ "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
22
+ "script": "variable c: Color.Hex;\nc.value = {input};\nreturn c;"
23
+ }
24
+ }
25
+ ],
26
+ "conversions": [],
27
+ "slug": "hex-color"
28
+ },
29
+ {
30
+ "name": "Rgb",
31
+ "type": "color",
32
+ "description": "RGB color",
33
+ "schema": {
34
+ "type": "object",
35
+ "properties": {
36
+ "r": {
37
+ "type": "number"
38
+ },
39
+ "g": {
40
+ "type": "number"
41
+ },
42
+ "b": {
43
+ "type": "number"
44
+ }
45
+ },
46
+ "required": [
47
+ "r",
48
+ "g",
49
+ "b"
50
+ ],
51
+ "order": [
52
+ "r",
53
+ "g",
54
+ "b"
55
+ ],
56
+ "additionalProperties": false
57
+ },
58
+ "initializers": [
59
+ {
60
+ "title": "function",
61
+ "keyword": "rgb",
62
+ "description": "Creates an RGB color",
63
+ "script": {
64
+ "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
65
+ "script": "variable color_parts: List = {input}; \nvariable output: Color.Rgb;\noutput.r = color_parts.get(0);\noutput.g = color_parts.get(1);\noutput.b = color_parts.get(2);\nreturn output;"
66
+ }
67
+ }
68
+ ],
69
+ "conversions": [
70
+ {
71
+ "source": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/hex-color/0/",
72
+ "target": "$self",
73
+ "description": "Converts HEX to RGB",
74
+ "lossless": true,
75
+ "script": {
76
+ "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
77
+ "script": "variable color_parts: List = {input}.to_string().split('#'); \nvariable color: List = color_parts.get(1).split(); \nvariable length: Number = color.length(); \nvariable rgb: List = 0, 0, 0; \nif(length == 3) [ \n rgb.update(0, parse_int(color.get(0).concat(color.get(0)), 16)); \n rgb.update(1, parse_int(color.get(1).concat(color.get(1)), 16)); \n rgb.update(2, parse_int(color.get(2).concat(color.get(2)), 16)); \n] else [ \n rgb.update(0, parse_int(color.get(0).concat(color.get(1)), 16)); \n rgb.update(1, parse_int(color.get(2).concat(color.get(3)), 16)); \n rgb.update(2, parse_int(color.get(4).concat(color.get(5)), 16)); \n]; \n\nvariable output: Color.Rgb; \noutput.r = rgb.get(0); \noutput.g = rgb.get(1); \noutput.b = rgb.get(2); \n\nreturn output;"
78
+ }
79
+ },
80
+ {
81
+ "source": "$self",
82
+ "target": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/hex-color/0/",
83
+ "description": "Converts RGB to HEX",
84
+ "lossless": true,
85
+ "script": {
86
+ "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
87
+ "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\nwhile( i < min(rgba.length(), 3)) [\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\nif (rgba.length() == 4) [\n value = rgba.get(3) * 255; // Convert alpha to 0-255 range\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];\n\nreturn hex;"
88
+ }
89
+ }
90
+ ],
91
+ "slug": "rgb-color"
92
+ },
93
+ {
94
+ "name": "Rgba",
95
+ "type": "color",
96
+ "description": "RGBA color",
97
+ "schema": {
98
+ "type": "object",
99
+ "properties": {
100
+ "r": {
101
+ "type": "number"
102
+ },
103
+ "g": {
104
+ "type": "number"
105
+ },
106
+ "b": {
107
+ "type": "number"
108
+ },
109
+ "a": {
110
+ "type": "number"
111
+ }
112
+ },
113
+ "required": [
114
+ "r",
115
+ "g",
116
+ "b",
117
+ "a"
118
+ ],
119
+ "order": [
120
+ "r",
121
+ "g",
122
+ "b",
123
+ "a"
124
+ ],
125
+ "additionalProperties": false
126
+ },
127
+ "initializers": [
128
+ {
129
+ "title": "function",
130
+ "keyword": "rgba",
131
+ "description": "Creates an RGBA color",
132
+ "script": {
133
+ "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
134
+ "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;"
135
+ }
136
+ }
137
+ ],
138
+ "conversions": [
139
+ {
140
+ "source": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/hex-color/0/",
141
+ "target": "$self",
142
+ "description": "Converts HEX to RGBA",
143
+ "lossless": true,
144
+ "script": {
145
+ "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
146
+ "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;"
147
+ }
148
+ },
149
+ {
150
+ "source": "$self",
151
+ "target": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/hex-color/0/",
152
+ "description": "Converts RGBA to HEX",
153
+ "lossless": false,
154
+ "script": {
155
+ "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
156
+ "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;"
157
+ }
158
+ },
159
+ {
160
+ "source": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/rgb-color/0/",
161
+ "target": "$self",
162
+ "description": "Converts RGB to RGBA",
163
+ "lossless": true,
164
+ "script": {
165
+ "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
166
+ "script": "variable output: Color.Rgba;\noutput.r = {input}.r;\noutput.g = {input}.g;\noutput.b = {input}.b;\noutput.a = 1.0;\nreturn output;"
167
+ }
168
+ },
169
+ {
170
+ "source": "$self",
171
+ "target": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/rgb-color/0/",
172
+ "description": "Converts RGBA to RGB",
173
+ "lossless": false,
174
+ "script": {
175
+ "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
176
+ "script": "variable output: Color.Rgb;\noutput.r = {input}.r;\noutput.g = {input}.g;\noutput.b = {input}.b;\nreturn output;"
177
+ }
178
+ }
179
+ ],
180
+ "slug": "rgba-color"
181
+ }
182
+ ],
183
+ "functions": [
184
+ {
185
+ "name": "Invert Color",
186
+ "type": "function",
187
+ "description": "Inverts a color by inverting each RGB channel (R' = 255 - R, G' = 255 - G, B' = 255 - B).",
188
+ "keyword": "invert",
189
+ "input": {
190
+ "type": "object",
191
+ "properties": {
192
+ "color": {
193
+ "type": "color",
194
+ "description": "The color to invert."
195
+ }
196
+ }
197
+ },
198
+ "script": {
199
+ "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
200
+ "script": "variable input: List = {input};\n\nvariable rgb_color: Color.Rgb = input.get(0).to.rgb();\n\nvariable inverted_r: Number = 255 - rgb_color.r;\nvariable inverted_g: Number = 255 - rgb_color.g;\nvariable inverted_b: Number = 255 - rgb_color.b;\n\nvariable inverted_color: Color.Rgb = rgb(inverted_r, inverted_g, inverted_b);\nreturn inverted_color;"
201
+ },
202
+ "requirements": [
203
+ "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/rgb-color/0/"
204
+ ],
205
+ "slug": "invert"
206
+ }
207
+ ],
208
+ "metadata": {
209
+ "generatedAt": "2025-12-18T10:46:57.800Z",
210
+ "totalSchemas": 4
211
+ }
212
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "Hex",
3
+ "type": "color",
4
+ "description": "A color in hex format, e.g. #ff0000",
5
+ "schema": {
6
+ "type": "object",
7
+ "properties": {
8
+ "value": {
9
+ "type": "string"
10
+ }
11
+ }
12
+ },
13
+ "initializers": [
14
+ {
15
+ "title": "Hex Color Initializer",
16
+ "keyword": "hex",
17
+ "script": {
18
+ "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
19
+ "script": "variable c: Color.Hex;\nc.value = {input};\nreturn c;"
20
+ }
21
+ }
22
+ ],
23
+ "conversions": [],
24
+ "slug": "hex-color"
25
+ }
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "Rgb",
3
+ "type": "color",
4
+ "description": "RGB 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
+ },
18
+ "required": [
19
+ "r",
20
+ "g",
21
+ "b"
22
+ ],
23
+ "order": [
24
+ "r",
25
+ "g",
26
+ "b"
27
+ ],
28
+ "additionalProperties": false
29
+ },
30
+ "initializers": [
31
+ {
32
+ "title": "function",
33
+ "keyword": "rgb",
34
+ "description": "Creates an RGB color",
35
+ "script": {
36
+ "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
37
+ "script": "variable color_parts: List = {input}; \nvariable output: Color.Rgb;\noutput.r = color_parts.get(0);\noutput.g = color_parts.get(1);\noutput.b = color_parts.get(2);\nreturn output;"
38
+ }
39
+ }
40
+ ],
41
+ "conversions": [
42
+ {
43
+ "source": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/hex-color/0/",
44
+ "target": "$self",
45
+ "description": "Converts HEX to RGB",
46
+ "lossless": true,
47
+ "script": {
48
+ "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
49
+ "script": "variable color_parts: List = {input}.to_string().split('#'); \nvariable color: List = color_parts.get(1).split(); \nvariable length: Number = color.length(); \nvariable rgb: List = 0, 0, 0; \nif(length == 3) [ \n rgb.update(0, parse_int(color.get(0).concat(color.get(0)), 16)); \n rgb.update(1, parse_int(color.get(1).concat(color.get(1)), 16)); \n rgb.update(2, parse_int(color.get(2).concat(color.get(2)), 16)); \n] else [ \n rgb.update(0, parse_int(color.get(0).concat(color.get(1)), 16)); \n rgb.update(1, parse_int(color.get(2).concat(color.get(3)), 16)); \n rgb.update(2, parse_int(color.get(4).concat(color.get(5)), 16)); \n]; \n\nvariable output: Color.Rgb; \noutput.r = rgb.get(0); \noutput.g = rgb.get(1); \noutput.b = rgb.get(2); \n\nreturn output;"
50
+ }
51
+ },
52
+ {
53
+ "source": "$self",
54
+ "target": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/hex-color/0/",
55
+ "description": "Converts RGB to HEX",
56
+ "lossless": true,
57
+ "script": {
58
+ "type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
59
+ "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\nwhile( i < min(rgba.length(), 3)) [\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\nif (rgba.length() == 4) [\n value = rgba.get(3) * 255; // Convert alpha to 0-255 range\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];\n\nreturn hex;"
60
+ }
61
+ }
62
+ ],
63
+ "slug": "rgb-color"
64
+ }
@@ -0,0 +1,89 @@
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
+ }