@adobe/spectrum-tokens 13.0.0-beta.2 → 13.0.0-beta.21

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 (84) hide show
  1. package/CHANGELOG.md +1379 -0
  2. package/dist/json/drover.json +826 -473
  3. package/dist/json/variables.json +9794 -6005
  4. package/moon.yml +1 -1
  5. package/package.json +7 -4
  6. package/schemas/components/action-bar.json +1 -1
  7. package/schemas/components/action-button.json +1 -1
  8. package/schemas/components/action-group.json +1 -1
  9. package/schemas/components/alert-banner.json +1 -1
  10. package/schemas/components/alert-dialog.json +1 -1
  11. package/schemas/components/avatar.json +1 -1
  12. package/schemas/components/badge.json +1 -1
  13. package/schemas/components/body.json +1 -1
  14. package/schemas/components/bottom-navigation-android.json +1 -1
  15. package/schemas/components/breadcrumbs.json +1 -1
  16. package/schemas/components/button-group.json +1 -1
  17. package/schemas/components/button.json +1 -1
  18. package/schemas/components/checkbox-group.json +1 -1
  19. package/schemas/components/checkbox.json +1 -1
  20. package/schemas/components/close-button.json +1 -1
  21. package/schemas/components/code.json +1 -1
  22. package/schemas/components/color-area.json +1 -1
  23. package/schemas/components/color-loupe.json +1 -1
  24. package/schemas/components/color-slider.json +1 -1
  25. package/schemas/components/color-wheel.json +1 -1
  26. package/schemas/components/combo-box.json +1 -1
  27. package/schemas/components/contextual-help.json +1 -1
  28. package/schemas/components/detail.json +1 -1
  29. package/schemas/components/divider.json +1 -1
  30. package/schemas/components/field-label.json +1 -1
  31. package/schemas/components/heading.json +1 -1
  32. package/schemas/components/help-text.json +1 -1
  33. package/schemas/components/in-line-alert.json +1 -1
  34. package/schemas/components/link.json +1 -1
  35. package/schemas/components/menu.json +1 -1
  36. package/schemas/components/meter.json +1 -1
  37. package/schemas/components/picker.json +1 -1
  38. package/schemas/components/popover.json +1 -1
  39. package/schemas/components/progress-bar.json +1 -1
  40. package/schemas/components/progress-circle.json +1 -1
  41. package/schemas/components/radio-group.json +1 -1
  42. package/schemas/components/rating.json +1 -1
  43. package/schemas/components/scroll-zoom-bar.json +1 -1
  44. package/schemas/components/side-navigation.json +1 -1
  45. package/schemas/components/slider.json +1 -1
  46. package/schemas/components/status-light.json +1 -1
  47. package/schemas/components/swatch-group.json +1 -1
  48. package/schemas/components/swatch.json +1 -1
  49. package/schemas/components/switch.json +1 -1
  50. package/schemas/components/tab-bar-ios.json +1 -1
  51. package/schemas/components/tabs.json +1 -1
  52. package/schemas/components/tag.json +1 -1
  53. package/schemas/components/text-area.json +1 -1
  54. package/schemas/components/text-field.json +1 -1
  55. package/schemas/components/toast.json +1 -1
  56. package/schemas/components/tooltip.json +1 -1
  57. package/schemas/components/tray.json +1 -1
  58. package/schemas/components/tree-view.json +1 -1
  59. package/schemas/token-types/alias.json +25 -0
  60. package/schemas/token-types/color-set.json +69 -0
  61. package/schemas/token-types/color.json +25 -0
  62. package/schemas/token-types/dimension.json +25 -0
  63. package/schemas/token-types/font-family.json +25 -0
  64. package/schemas/token-types/font-size.json +25 -0
  65. package/schemas/token-types/font-style.json +25 -0
  66. package/schemas/token-types/font-weight.json +25 -0
  67. package/schemas/token-types/multiplier.json +25 -0
  68. package/schemas/token-types/opacity.json +25 -0
  69. package/schemas/token-types/scale-set.json +60 -0
  70. package/schemas/token-types/set.json +22 -0
  71. package/schemas/token-types/text-transform.json +25 -0
  72. package/schemas/token-types/token.json +27 -0
  73. package/src/color-aliases.json +573 -119
  74. package/src/color-component.json +52 -12
  75. package/src/color-palette.json +3038 -414
  76. package/src/icons.json +18 -0
  77. package/src/layout-component.json +5120 -2385
  78. package/src/layout.json +773 -102
  79. package/src/semantic-color-palette.json +101 -1
  80. package/src/typography.json +285 -0
  81. package/test/checkId.test.js +55 -33
  82. package/test/componentSchemaValidator.test.js +74 -0
  83. package/test/schemaValidators/alias.test.js +41 -0
  84. package/test/tokenSchemaValidator.test.js +97 -0
@@ -20,45 +20,67 @@ const files = await Promise.all(
20
20
  ),
21
21
  );
22
22
 
23
- const uuids = [];
24
- const missingUUIDs = [];
25
- const VALUE = "value";
26
- const UUID = "uuid";
23
+ // const uuids = [];
24
+ // const missingUUIDs = [];
25
+ // const VALUE = "value";
26
+ // const UUID = "uuid";
27
27
 
28
- function isObject(a) {
29
- return (
30
- !!a &&
31
- a.constructor &&
32
- (a.constructor === Object || a.constructor.name === "Object")
33
- );
34
- }
28
+ // function isObject(a) {
29
+ // return (
30
+ // !!a &&
31
+ // a.constructor &&
32
+ // (a.constructor === Object || a.constructor.name === "Object")
33
+ // );
34
+ // }
35
35
 
36
- // check for and add uuids
37
- function checkUUID(json, name) {
38
- // if it is in want of uuid, give it one
39
- if (json[VALUE] && !json[UUID]) {
40
- if (!json[UUID] || uuids.includes(json[UUID])) {
41
- if (name) {
42
- missingUUIDs.push(name);
43
- } else {
44
- missingUUIDs.push(json[VALUE]);
45
- }
46
- }
36
+ // // check for uuids
37
+ // function checkUUID(json, name) {
38
+ // if (json[VALUE] && !json[UUID]) {
39
+ // if (!json[UUID]) {
40
+ // if (name) {
41
+ // missingUUIDs.push(name);
42
+ // } else {
43
+ // missingUUIDs.push(json[VALUE]);
44
+ // }
45
+ // }
46
+ // else if (uuids.includes(json[UUID])) {
47
47
 
48
- uuids.push(json[UUID]);
49
- }
48
+ // }
49
+ // uuids.push(json[UUID]);
50
+ // }
50
51
 
51
- // handle the json's children
52
- Object.keys(json).forEach((key) => {
53
- if (isObject(json[key])) {
54
- checkUUID(json[key], key);
52
+ // // handle the json's children
53
+ // Object.keys(json).forEach((key) => {
54
+ // if (isObject(json[key])) {
55
+ // checkUUID(json[key], key);
56
+ // }
57
+ // });
58
+ // }
59
+ const findDuplicateUUIDs = (json) => {
60
+ const uuids = [];
61
+ const duplicateUUIDs = [];
62
+ const gather = (json, name) => {
63
+ if (json.uuid) {
64
+ if (uuids.includes(json.uuid)) {
65
+ duplicateUUIDs.push({ uuid: json.uuid, name });
66
+ }
67
+ uuids.push(json.uuid);
55
68
  }
56
- });
57
- }
69
+ Object.keys(json).forEach((key) => {
70
+ if (typeof json[key] === "object") {
71
+ gather(json[key], key);
72
+ }
73
+ });
74
+ };
75
+ gather(json);
76
+ return duplicateUUIDs;
77
+ };
58
78
 
59
- test("check for uuids", async (t) => {
79
+ test("ensure uuids are unique", async (t) => {
80
+ let allTokens = {};
60
81
  for (const file of files) {
61
- checkUUID(file);
82
+ allTokens = { ...allTokens, ...file };
62
83
  }
63
- t.deepEqual(missingUUIDs, []);
84
+ const duplicateUUIDs = findDuplicateUUIDs(allTokens);
85
+ t.deepEqual(duplicateUUIDs, [], "duplicate uuids found");
64
86
  });
@@ -0,0 +1,74 @@
1
+ /*
2
+ Copyright 2023 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import test from "ava";
14
+ import Ajv from "ajv/dist/2020.js";
15
+ import addFormats from "ajv-formats";
16
+ import { glob } from "glob";
17
+ import { readFile } from "fs/promises";
18
+
19
+ const readJSON = async (filePath) =>
20
+ JSON.parse(await readFile(filePath, "utf8"));
21
+ const componentSchema = await readJSON("schemas/component.json");
22
+
23
+ const fileNames = await glob("schemas/components/*.json");
24
+ const files = await Promise.all(
25
+ fileNames.map(async (fileName) => {
26
+ return { fileName, json: await readJSON(fileName) };
27
+ }),
28
+ );
29
+
30
+ const ajv = new Ajv();
31
+ addFormats(ajv);
32
+ ajv.addMetaSchema(componentSchema);
33
+ const schemaFiles = await glob("schemas/types/*.json");
34
+ for (const schemaFile of schemaFiles) {
35
+ const schema = await readJSON(schemaFile);
36
+ ajv.addSchema(schema);
37
+ }
38
+
39
+ for (const keyword of Object.keys(componentSchema.properties)) {
40
+ ajv.addKeyword({ keyword, metaSchema: componentSchema.properties[keyword] });
41
+ }
42
+
43
+ test("component schema should be valid", async (t) => {
44
+ const valid = ajv.validateSchema(componentSchema);
45
+ t.true(valid);
46
+ });
47
+
48
+ test("Every component schema should validate against the definition", (t) => {
49
+ let valid = true;
50
+ for (const file of files) {
51
+ if (!ajv.validateSchema(file.json)) {
52
+ valid = false;
53
+ console.log(`${file.fileName} failed validation`);
54
+ console.log(ajv.errors);
55
+ }
56
+ }
57
+ t.true(valid);
58
+ });
59
+
60
+ test("component examples should validate against the definition", (t) => {
61
+ let valid = true;
62
+ for (const file of files) {
63
+ const validate = ajv.compile(file.json);
64
+ if (!Object.hasOwn(file.json, "examples")) file.json.examples = [];
65
+ for (const example of file.json.examples) {
66
+ if (!validate(example)) {
67
+ valid = false;
68
+ console.log(`${file.fileName} failed validation`);
69
+ console.log(validate.errors);
70
+ }
71
+ }
72
+ }
73
+ t.true(valid);
74
+ });
@@ -0,0 +1,41 @@
1
+ /*
2
+ Copyright 2023 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import test from "ava";
14
+ import Ajv from "ajv/dist/2020.js";
15
+ import addFormats from "ajv-formats";
16
+ import { readFile } from "fs/promises";
17
+
18
+ const readJSON = async (filePath) =>
19
+ JSON.parse(await readFile(filePath, "utf8"));
20
+
21
+ const ajv = new Ajv();
22
+ addFormats(ajv);
23
+
24
+ ajv.addSchema(await readJSON("schemas/token-types/token.json"));
25
+ const validate = await ajv.compile(
26
+ await readJSON("schemas/token-types/alias.json"),
27
+ );
28
+
29
+ test("Every token schema should validate against the definition", (t) => {
30
+ const alias = {
31
+ component: "swatch",
32
+ $schema:
33
+ "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json",
34
+ value: "{gray-900}",
35
+ uuid: "7da5157d-7f25-405b-8de0-f3669565fb48",
36
+ };
37
+ if (!validate(alias)) {
38
+ console.log(validate.errors);
39
+ }
40
+ t.pass();
41
+ });
@@ -0,0 +1,97 @@
1
+ /*
2
+ Copyright 2023 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import test from "ava";
14
+ import Ajv from "ajv/dist/2020.js";
15
+ import addFormats from "ajv-formats";
16
+ import { glob } from "glob";
17
+ import { readFile } from "fs/promises";
18
+
19
+ const readJSON = async (filePath) =>
20
+ JSON.parse(await readFile(filePath, "utf8"));
21
+
22
+ const ajv = new Ajv();
23
+ addFormats(ajv);
24
+
25
+ test.before(async (t) => {
26
+ const schemaFileNames = await glob("schemas/token-types/*.json");
27
+ const schemaIds = await Promise.all(
28
+ schemaFileNames.map(async (fileName) => {
29
+ const json = await readJSON(fileName);
30
+ try {
31
+ ajv.addSchema(json, json["$id"]);
32
+ } catch (error) {
33
+ console.log(error);
34
+ console.log(`${fileName} error with $id ${json["$id"]}`);
35
+ }
36
+ return json["$id"];
37
+ }),
38
+ );
39
+ t.context.schemaIds = schemaIds;
40
+
41
+ const tokenFilesNames = await glob("src/*.json");
42
+ t.context.tokenFiles = await Promise.all(
43
+ tokenFilesNames.map(async (tokenFile) => {
44
+ return { fileName: tokenFile, data: await readJSON(tokenFile) };
45
+ }),
46
+ );
47
+ });
48
+
49
+ test("Schema should compile without errors", async (t) => {
50
+ try {
51
+ const validate = await ajv.compile({
52
+ $schema: "https://json-schema.org/draft/2020-12/schema",
53
+ type: "object",
54
+ patternProperties: {
55
+ "^(?:(?:[a-z]|\\d)+-?)*(?:[a-z]|\\d)+$": {
56
+ anyOf: t.context.schemaIds.map((schemaId) => ({ $ref: schemaId })),
57
+ },
58
+ },
59
+ });
60
+ } catch (error) {
61
+ console.log(error);
62
+ }
63
+ t.pass();
64
+ });
65
+
66
+ test("Every token should have a $schema property", (t) => {
67
+ t.context.tokenFiles.forEach((tokenFileObj) => {
68
+ Object.keys(tokenFileObj.data).forEach((tokenName) => {
69
+ t.true(
70
+ Object.hasOwn(tokenFileObj.data[tokenName], "$schema"),
71
+ `${tokenName} in ${tokenFileObj.fileName} does not have a $schema property.`,
72
+ );
73
+ });
74
+ });
75
+ });
76
+
77
+ test("Every token schema should validate against the definition", (t) => {
78
+ const errors = [];
79
+ t.context.tokenFiles.forEach((tokenFileObj) => {
80
+ Object.keys(tokenFileObj.data).forEach((tokenName) => {
81
+ if (
82
+ !ajv.validate(
83
+ tokenFileObj.data[tokenName]["$schema"],
84
+ tokenFileObj.data[tokenName],
85
+ )
86
+ ) {
87
+ t.log(`${tokenName} in ${tokenFileObj.fileName} failed validation.`);
88
+ errors.push({
89
+ tokenName,
90
+ fileName: tokenFileObj.fileName,
91
+ errors: ajv.errors,
92
+ });
93
+ }
94
+ });
95
+ });
96
+ t.deepEqual(errors, []);
97
+ });