Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,6 @@ temp-*

# auto-generated token files (copied by prepare scripts)
docs/s2-tokens-viewer/tokens/

# Token parser generated output files
tools/token-name-parser/output/
21 changes: 21 additions & 0 deletions packages/structured-tokens/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# @adobe/structured-tokens

## 0.1.0

### Minor Changes

- Initial release of structured tokens package
- Contains structured JSON for layout.json tokens (242 tokens)
- JSON schemas for validation
- Enum schemas for token name parts:
- anatomy-parts
- components
- properties
- modifiers
- sizes
- platforms
- themes
- relationship-connectors
- Base structured-token schema
- Type-specific schemas: spacing, component-property, global-property

91 changes: 91 additions & 0 deletions packages/structured-tokens/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Structured Tokens

Structured, schema-validated design tokens with parsed name parts for Adobe's Spectrum Design System.

## Overview

This package contains design tokens from `packages/tokens/src` that have been parsed into structured JSON objects with validated name components. Each token includes:

* Original token properties (value, uuid, $schema)
* Parsed name parts (type, component, property, size, spaceBetween, etc.)
* Validation status

## Structure

```
packages/structured-tokens/
├── src/ # Structured token data (generated)
│ ├── layout.json
│ ├── icons.json
│ └── ...
├── schemas/ # JSON schemas for validation
│ ├── structured-token.json
│ ├── spacing-token.json
│ ├── component-property-token.json
│ ├── global-property-token.json
│ └── enums/ # Enum definitions for token name parts
│ ├── anatomy-parts.json
│ ├── components.json
│ ├── properties.json
│ ├── modifiers.json
│ ├── sizes.json
│ ├── platforms.json
│ ├── themes.json
│ └── relationship-connectors.json
└── index.js # Package exports
```

## Token Structure

Structured tokens follow this format:

```json
{
"text-to-visual-50": {
"originalName": "text-to-visual-50",
"parsed": {
"type": "spacing",
"spaceBetween": {
"from": "text",
"to": "visual"
},
"size": "50"
},
"uuid": "abc-123...",
"value": "8px",
"$schema": "https://...",
"validation": {
"isValid": true,
"errors": []
}
}
}
```

## Enum Schemas

All token name parts are validated against enum schemas:

* **anatomy-parts**: Component anatomy elements (text, visual, control, icon, edge, etc.)
* **components**: Component names (button, checkbox, field, etc.)
* **properties**: Property names (size, color, radius, spacing, etc.)
* **modifiers**: State modifiers (quiet, disabled, selected, etc.)
* **sizes**: Size scale values (0, 50, 75, 100, 200, etc.)
* **platforms**: Platform identifiers (desktop, mobile, android)
* **themes**: Theme identifiers (light, dark, wireframe)

## Generation

Structured tokens are generated by the `token-name-parser` tool:

```bash
moon run token-name-parser:parse
```

## Validation

All tokens are validated against JSON schemas with enum references to ensure consistent naming.

## License

Apache-2.0
27 changes: 27 additions & 0 deletions packages/structured-tokens/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright 2025 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

import { readFile } from "fs/promises";
import { resolve } from "path";
import { fileURLToPath } from "url";
import { glob } from "glob";

const __dirname = fileURLToPath(new URL(".", import.meta.url));

export const structuredTokenFileNames = await glob(
`${resolve(__dirname, "./src")}/**/*.json`,
);

export const readJson = async (fileName) =>
JSON.parse(await readFile(fileName, "utf8"));

export { __dirname };
27 changes: 27 additions & 0 deletions packages/structured-tokens/moon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2025 Adobe. All rights reserved.
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.

$schema: "https://moonrepo.dev/schemas/project.json"
id: "structured-tokens"
layer: library

fileGroups:
sources:
- "src/**/*"
schemas:
- "schemas/**/*"

tasks:
validate:
command: [node, validate-schemas.js]
platform: node
inputs:
- "@globs(sources)"
- "@globs(schemas)"
27 changes: 27 additions & 0 deletions packages/structured-tokens/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@adobe/structured-tokens",
"version": "0.1.0",
"description": "Structured, schema-validated design tokens with parsed name parts for Spectrum",
"type": "module",
"main": "index.js",
"scripts": {},
"repository": {
"type": "git",
"url": "git+https://github.com/adobe/spectrum-design-data.git",
"directory": "packages/structured-tokens"
},
"author": "Garth Braithwaite <garthdb@gmail.com> (http://garthdb.com/)",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/adobe/spectrum-design-data/issues"
},
"homepage": "https://github.com/adobe/spectrum-design-data/tree/main/packages/structured-tokens#readme",
"private": true,
"dependencies": {
"glob": "^11.0.3"
},
"devDependencies": {
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1"
}
}
78 changes: 78 additions & 0 deletions packages/structured-tokens/schemas/base-token.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://opensource.adobe.com/spectrum-design-data/schemas/structured-tokens/base-token.json",
"title": "Base Anonymous Token",
"description": "Base schema for all anonymous tokens",
"type": "object",
"properties": {
"$schema": {
"type": "string",
"format": "uri",
"description": "Reference to the original token type schema."
},
"name": {
"type": "object",
"description": "The name structure of the token.",
"properties": {
"original": {
"type": "string",
"description": "The original hyphen-delimited name of the token."
},
"structure": {
"type": "object",
"description": "The structured name components following the Token name structure wiki.",
"properties": {
"category": {
"type": "string",
"enum": [
"spacing",
"component-property",
"generic-property",
"semantic-alias",
"color-base",
"color-scale",
"gradient-color",
"typography-base",
"opacity-semantic",
"special",
"unknown"
]
}
},
"required": ["category"]
},
"semanticComplexity": {
"type": "integer",
"minimum": 0,
"description": "Number of semantic fields in the name structure"
}
},
"required": ["original", "structure", "semanticComplexity"]
},
"deprecated": {
"type": "boolean",
"default": false
},
"deprecated_comment": {
"type": "string"
},
"component": {
"type": "string"
},
"private": {
"type": "boolean"
},
"validation": {
"type": "object",
"properties": {
"isValid": { "type": "boolean" },
"errors": {
"type": "array",
"items": { "type": "string" }
}
},
"required": ["isValid", "errors"]
}
},
"required": ["$schema", "name", "validation"]
}
44 changes: 44 additions & 0 deletions packages/structured-tokens/schemas/color-base-token.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://opensource.adobe.com/spectrum-design-data/schemas/structured-tokens/color-base-token.json",
"title": "Base Color Token",
"description": "Schema for base color tokens (white, black)",
"allOf": [
{
"$ref": "base-token.json"
}
],
"properties": {
"name": {
"type": "object",
"properties": {
"original": {
"type": "string",
"description": "Original hyphen-delimited token name"
},
"structure": {
"type": "object",
"properties": {
"category": {
"const": "color-base",
"description": "Token category"
},
"color": {
"$ref": "enums/colors.json",
"description": "Base color name"
}
},
"required": ["category", "color"],
"additionalProperties": false
},
"semanticComplexity": {
"type": "integer",
"minimum": 0,
"description": "Semantic complexity score"
}
},
"required": ["original", "structure", "semanticComplexity"]
}
},
"required": ["name", "$schema", "value", "id"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://opensource.adobe.com/spectrum-design-data/schemas/structured-tokens/color-scale-scale-set-token.json",
"title": "Color Scale Set Token",
"description": "Schema for color scale tokens with light/dark/wireframe sets",
"allOf": [
{
"$ref": "color-set-token.json"
}
],
"properties": {
"name": {
"type": "object",
"properties": {
"original": {
"type": "string",
"description": "Original hyphen-delimited token name"
},
"structure": {
"type": "object",
"properties": {
"category": {
"const": "color-scale",
"description": "Token category"
},
"modifier": {
"$ref": "enums/color-modifiers.json",
"description": "Optional color modifier (transparent, static)"
},
"color": {
"$ref": "enums/colors.json",
"description": "Color name"
},
"index": {
"$ref": "enums/color-indices.json",
"description": "Color scale index"
}
},
"required": ["category", "color", "index"],
"additionalProperties": false
},
"semanticComplexity": {
"type": "integer",
"minimum": 0,
"description": "Semantic complexity score"
}
},
"required": ["original", "structure", "semanticComplexity"]
}
},
"required": ["name", "$schema", "sets", "validation"]
}
Loading