@canonical/design-system 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.
Files changed (231) hide show
  1. package/.mcp.json +8 -0
  2. package/README.md +438 -0
  3. package/biome.json +6 -0
  4. package/bun.lock +349 -0
  5. package/data/apps/component/file_tree.ttl +8 -0
  6. package/data/apps/component/key_value_pair.ttl +8 -0
  7. package/data/apps/component/navigation.ttl +8 -0
  8. package/data/apps/component/skeleton_loading.ttl +8 -0
  9. package/data/apps/component/status_bar.ttl +8 -0
  10. package/data/apps/component/toolbar.ttl +8 -0
  11. package/data/apps/layout/application_layout.ttl +8 -0
  12. package/data/apps/layout/empty_layout.ttl +8 -0
  13. package/data/apps/layout/list_page_layout.ttl +8 -0
  14. package/data/apps/layout/settings_page_layout.ttl +8 -0
  15. package/data/apps/pattern/code_diff.ttl +8 -0
  16. package/data/apps/pattern/data_table.ttl +8 -0
  17. package/data/apps/pattern/destructive_modal.ttl +8 -0
  18. package/data/apps/pattern/key_value_summary.ttl +8 -0
  19. package/data/apps/pattern/keyboard_shortcuts.ttl +8 -0
  20. package/data/apps/pattern/notification_center.ttl +8 -0
  21. package/data/apps/pattern/side_panel.ttl +8 -0
  22. package/data/apps/pattern/sidepanel_stacked.ttl +8 -0
  23. package/data/apps.ttl +5 -0
  24. package/data/apps_wpe.ttl +5 -0
  25. package/data/documentation/layout/documentation_layout.ttl +8 -0
  26. package/data/documentation.ttl +5 -0
  27. package/data/global/component/accordion.ttl +14 -0
  28. package/data/global/component/announcement.ttl +8 -0
  29. package/data/global/component/badge.ttl +9 -0
  30. package/data/global/component/button.ttl +20 -0
  31. package/data/global/component/card.ttl +8 -0
  32. package/data/global/component/chip.ttl +8 -0
  33. package/data/global/component/code_snippet.ttl +8 -0
  34. package/data/global/component/contextual_menu.ttl +8 -0
  35. package/data/global/component/heading.ttl +14 -0
  36. package/data/global/component/icon.ttl +14 -0
  37. package/data/global/component/icon_in_container.ttl +8 -0
  38. package/data/global/component/keyboard_key.ttl +8 -0
  39. package/data/global/component/label.ttl +15 -0
  40. package/data/global/component/link.ttl +8 -0
  41. package/data/global/component/notification_inline.ttl +8 -0
  42. package/data/global/component/notification_toast.ttl +8 -0
  43. package/data/global/component/pagination.ttl +8 -0
  44. package/data/global/component/popover.ttl +8 -0
  45. package/data/global/component/rich_text_editor.ttl +8 -0
  46. package/data/global/component/search_bar.ttl +8 -0
  47. package/data/global/component/table.ttl +8 -0
  48. package/data/global/component/tabs.ttl +8 -0
  49. package/data/global/component/theme_switcher.ttl +8 -0
  50. package/data/global/component/tile.ttl +14 -0
  51. package/data/global/component/tooltip.ttl +8 -0
  52. package/data/global/group/buttons.ttl +8 -0
  53. package/data/global/group/cards.ttl +8 -0
  54. package/data/global/group/tiles.ttl +8 -0
  55. package/data/global/layout/error_layout.ttl +8 -0
  56. package/data/global/layout/form_layout.ttl +8 -0
  57. package/data/global/layout/identity_page_form.ttl +8 -0
  58. package/data/global/modifier/alpha.ttl +6 -0
  59. package/data/global/modifier/beta.ttl +6 -0
  60. package/data/global/modifier/caution.ttl +6 -0
  61. package/data/global/modifier/comfortable.ttl +6 -0
  62. package/data/global/modifier/completed.ttl +6 -0
  63. package/data/global/modifier/constructive.ttl +6 -0
  64. package/data/global/modifier/dark.ttl +6 -0
  65. package/data/global/modifier/dense.ttl +6 -0
  66. package/data/global/modifier/destructive.ttl +6 -0
  67. package/data/global/modifier/editable.ttl +6 -0
  68. package/data/global/modifier/elevated.ttl +6 -0
  69. package/data/global/modifier/error.ttl +6 -0
  70. package/data/global/modifier/experimental.ttl +6 -0
  71. package/data/global/modifier/failed.ttl +6 -0
  72. package/data/global/modifier/focused.ttl +6 -0
  73. package/data/global/modifier/highlighted.ttl +6 -0
  74. package/data/global/modifier/in_progress.ttl +6 -0
  75. package/data/global/modifier/information.ttl +6 -0
  76. package/data/global/modifier/light.ttl +6 -0
  77. package/data/global/modifier/loading.ttl +6 -0
  78. package/data/global/modifier/muted.ttl +6 -0
  79. package/data/global/modifier/paper.ttl +6 -0
  80. package/data/global/modifier/planned.ttl +6 -0
  81. package/data/global/modifier/primary.ttl +6 -0
  82. package/data/global/modifier/secondary.ttl +6 -0
  83. package/data/global/modifier/stable.ttl +6 -0
  84. package/data/global/modifier/success.ttl +6 -0
  85. package/data/global/modifier/tertiary.ttl +6 -0
  86. package/data/global/modifier/warning.ttl +6 -0
  87. package/data/global/modifier/wireframe.ttl +6 -0
  88. package/data/global/modifier_family/_color_luminosity.ttl +7 -0
  89. package/data/global/modifier_family/_emphasis.ttl +7 -0
  90. package/data/global/modifier_family/_other.ttl +7 -0
  91. package/data/global/modifier_family/anticipation.ttl +7 -0
  92. package/data/global/modifier_family/criticality.ttl +7 -0
  93. package/data/global/modifier_family/density.ttl +7 -0
  94. package/data/global/modifier_family/importance.ttl +7 -0
  95. package/data/global/modifier_family/lifecycle.ttl +7 -0
  96. package/data/global/modifier_family/release.ttl +7 -0
  97. package/data/global/pattern/breadcrumbs.ttl +14 -0
  98. package/data/global/pattern/info_table.ttl +8 -0
  99. package/data/global/pattern/modal.ttl +8 -0
  100. package/data/global/pattern/navigation.ttl +8 -0
  101. package/data/global/pattern/select_button.ttl +8 -0
  102. package/data/global/pattern/stepper.ttl +8 -0
  103. package/data/global/pattern/table_of_contents.ttl +8 -0
  104. package/data/global/pattern/timeline.ttl +14 -0
  105. package/data/global/subcomponent/accordion-item.ttl +19 -0
  106. package/data/global/subcomponent/breadcrumbs-item.ttl +19 -0
  107. package/data/global/subcomponent/card-content.ttl +14 -0
  108. package/data/global/subcomponent/card-header.ttl +14 -0
  109. package/data/global/subcomponent/card-image.ttl +20 -0
  110. package/data/global/subcomponent/divider.ttl +8 -0
  111. package/data/global/subcomponent/modal-content.ttl +8 -0
  112. package/data/global/subcomponent/modal-footer.ttl +8 -0
  113. package/data/global/subcomponent/modal-header.ttl +8 -0
  114. package/data/global/subcomponent/spinner.ttl +8 -0
  115. package/data/global/subcomponent/table-cell.ttl +8 -0
  116. package/data/global/subcomponent/table-row.ttl +8 -0
  117. package/data/global/subcomponent/tile-content.ttl +14 -0
  118. package/data/global/subcomponent/tile-header.ttl +14 -0
  119. package/data/global/subcomponent/timeline-content.ttl +14 -0
  120. package/data/global/subcomponent/timeline-event.ttl +31 -0
  121. package/data/global/subcomponent/timeline-footer.ttl +8 -0
  122. package/data/global/subcomponent/timeline-header.ttl +8 -0
  123. package/data/global.ttl +5 -0
  124. package/data/global_form/component/checkbox_input.ttl +8 -0
  125. package/data/global_form/component/choices_input.ttl +8 -0
  126. package/data/global_form/component/combobox_input.ttl +8 -0
  127. package/data/global_form/component/custom_choices_input.ttl +8 -0
  128. package/data/global_form/component/datepicker_input.ttl +8 -0
  129. package/data/global_form/component/rating_input.ttl +8 -0
  130. package/data/global_form/component/segmented_control_input.ttl +8 -0
  131. package/data/global_form/component/slider_input.ttl +8 -0
  132. package/data/global_form/component/switch_input.ttl +8 -0
  133. package/data/global_form/component/text_input.ttl +8 -0
  134. package/data/global_form/component/textarea_input.ttl +8 -0
  135. package/data/global_form/component/wysiwginput.ttl +8 -0
  136. package/data/global_form/pattern/field.ttl +8 -0
  137. package/data/global_form/pattern/form.ttl +8 -0
  138. package/data/global_form/subcomponent/field-description.ttl +8 -0
  139. package/data/global_form/subcomponent/field-label.ttl +8 -0
  140. package/data/global_form.ttl +5 -0
  141. package/data/site/component/quote.ttl +8 -0
  142. package/data/site/component/rule.ttl +8 -0
  143. package/data/site/component/section.ttl +8 -0
  144. package/data/site/layout/site_layout.ttl +8 -0
  145. package/data/site/pattern/hero-github.ttl +8 -0
  146. package/data/site/pattern/hero.ttl +8 -0
  147. package/data/site/pattern/info_table.ttl +8 -0
  148. package/data/site/pattern/skip_link.ttl +8 -0
  149. package/data/site.ttl +5 -0
  150. package/data/stores.ttl +5 -0
  151. package/definitions/ontology.ttl +498 -0
  152. package/package.json +42 -0
  153. package/session/A.DSL.md +429 -0
  154. package/session/B.NOTES.md +84 -0
  155. package/session/global.component.accordion.yaml +13 -0
  156. package/session/global.component.button.yaml +26 -0
  157. package/session/global.component.card.yaml +24 -0
  158. package/session/global.component.icon.yaml +7 -0
  159. package/session/global.component.label.yaml +7 -0
  160. package/session/global.component.tile.yaml +21 -0
  161. package/session/global.component.timeline.yaml +20 -0
  162. package/session/global.pattern.breadcrumbs.yaml +13 -0
  163. package/session/global.subcomponent.accordion-item.yaml +37 -0
  164. package/session/global.subcomponent.breadcrumbs-item.yaml +21 -0
  165. package/session/global.subcomponent.card-content.yaml +7 -0
  166. package/session/global.subcomponent.card-header.yaml +22 -0
  167. package/session/global.subcomponent.card-image.yaml +7 -0
  168. package/session/global.subcomponent.tile-content.yaml +7 -0
  169. package/session/global.subcomponent.tile-header.yaml +8 -0
  170. package/session/global.subcomponent.timeline-content.yaml +13 -0
  171. package/session/global.subcomponent.timeline-event.yaml +20 -0
  172. package/session/global.subcomponent.timeline-footer.yaml +9 -0
  173. package/session/global.subcomponent.timeline-header.yaml +18 -0
  174. package/skills/anatomy-author/ANATOMY_DSL_SPEC.md +423 -0
  175. package/skills/anatomy-author/SKILL.md +911 -0
  176. package/skills/component-specifier/SKILL.md +413 -0
  177. package/skills/design-auditor/SKILL.md +428 -0
  178. package/source.json +101 -0
  179. package/src/cli.ts +45 -0
  180. package/src/collect/generateTurtle.tests.ts +200 -0
  181. package/src/collect/generateTurtle.ts +187 -0
  182. package/src/collect/index.ts +4 -0
  183. package/src/collect/scanAnnotations.tests.ts +138 -0
  184. package/src/collect/scanAnnotations.ts +78 -0
  185. package/src/collect/types.ts +57 -0
  186. package/src/collect/validateCollectConfig.tests.ts +116 -0
  187. package/src/collect/validateCollectConfig.ts +74 -0
  188. package/src/collect-implementations.ts +99 -0
  189. package/src/commands/extract.tests.ts +41 -0
  190. package/src/commands/extract.ts +48 -0
  191. package/src/commands/index.ts +3 -0
  192. package/src/commands/list.tests.ts +26 -0
  193. package/src/commands/list.ts +26 -0
  194. package/src/commands/transform.tests.ts +28 -0
  195. package/src/commands/transform.ts +133 -0
  196. package/src/config/index.ts +2 -0
  197. package/src/config/source.schema.json +110 -0
  198. package/src/config/types.ts +97 -0
  199. package/src/config/validateConfig.tests.ts +46 -0
  200. package/src/config/validateConfig.ts +21 -0
  201. package/src/constants.ts +20 -0
  202. package/src/graph/GraphStore.tests.ts +157 -0
  203. package/src/graph/GraphStore.ts +200 -0
  204. package/src/graph/PrefixMap.tests.ts +129 -0
  205. package/src/graph/PrefixMap.ts +95 -0
  206. package/src/graph/buildUri.tests.ts +158 -0
  207. package/src/graph/buildUri.ts +69 -0
  208. package/src/graph/index.ts +4 -0
  209. package/src/graph/types.ts +20 -0
  210. package/src/providers/CodaProvider.tests.ts +241 -0
  211. package/src/providers/CodaProvider.ts +174 -0
  212. package/src/providers/CodaProvider.types.generated.ts +12236 -0
  213. package/src/providers/index.ts +18 -0
  214. package/src/serializers/JSONSerializer.tests.ts +79 -0
  215. package/src/serializers/JSONSerializer.ts +87 -0
  216. package/src/serializers/TTLSerializer.tests.ts +75 -0
  217. package/src/serializers/TTLSerializer.ts +99 -0
  218. package/src/serializers/index.ts +3 -0
  219. package/src/serializers/types.ts +16 -0
  220. package/src/transform/resolveReferences.tests.ts +63 -0
  221. package/src/transform/resolveReferences.ts +36 -0
  222. package/src/transform/resolveValue.tests.ts +76 -0
  223. package/src/transform/resolveValue.ts +87 -0
  224. package/src/transform/transform.tests.ts +99 -0
  225. package/src/transform/transform.ts +109 -0
  226. package/src/transform/transformRow.tests.ts +269 -0
  227. package/src/transform/transformRow.ts +220 -0
  228. package/src/transform/types.ts +26 -0
  229. package/tsconfig.json +8 -0
  230. package/vite.config.ts +11 -0
  231. package/vitest.config.ts +21 -0
@@ -0,0 +1,21 @@
1
+ ---
2
+ node:
3
+ uri: global.subcomponent.breadcrumbs-item
4
+ styles:
5
+ layout.type: flow
6
+ layout.direction: horizontal
7
+ layout.align: center
8
+ edges:
9
+ - node:
10
+ role: link
11
+ styles:
12
+ typography.color: color/text/link
13
+ relation:
14
+ cardinality: "1"
15
+ slotName: default
16
+ - node:
17
+ role: separator
18
+ styles:
19
+ spacing.external: spacing/small
20
+ relation:
21
+ cardinality: "0..1"
@@ -0,0 +1,7 @@
1
+ ---
2
+ node:
3
+ uri: global.subcomponent.card-content
4
+ styles:
5
+ layout.type: stack
6
+ layout.direction: vertical
7
+ spacing.internal: spacing/medium
@@ -0,0 +1,22 @@
1
+ ---
2
+ node:
3
+ uri: global.subcomponent.card-header
4
+ styles:
5
+ layout.type: flow
6
+ layout.direction: horizontal
7
+ layout.justify: space-between
8
+ layout.align: center
9
+ spacing.internal: spacing/medium
10
+ edges:
11
+ - node:
12
+ role: title
13
+ styles:
14
+ typography.weight: font/weight/semibold
15
+ relation:
16
+ cardinality: "1"
17
+ slotName: default
18
+ - node:
19
+ role: actions
20
+ relation:
21
+ cardinality: "0..1"
22
+ slotName: actions
@@ -0,0 +1,7 @@
1
+ ---
2
+ node:
3
+ uri: global.subcomponent.card-image
4
+ styles:
5
+ layout.type: block
6
+ size.width: fill
7
+ object.fit: cover
@@ -0,0 +1,7 @@
1
+ ---
2
+ node:
3
+ uri: global.subcomponent.tile-content
4
+ styles:
5
+ layout.type: stack
6
+ layout.direction: vertical
7
+ spacing.internal: spacing/medium
@@ -0,0 +1,8 @@
1
+ ---
2
+ node:
3
+ uri: global.subcomponent.tile-header
4
+ styles:
5
+ layout.type: flow
6
+ layout.direction: horizontal
7
+ layout.align: center
8
+ spacing.internal: spacing/medium
@@ -0,0 +1,13 @@
1
+ ---
2
+ # TODO: Timeline axis/line connecting events needs DSL representation
3
+ node:
4
+ uri: global.subcomponent.timeline-content
5
+ styles:
6
+ layout.type: stack
7
+ layout.direction: vertical
8
+ edges:
9
+ - node:
10
+ uri: global.subcomponent.timeline-event
11
+ relation:
12
+ cardinality: "0..*"
13
+ slotName: default # populated via items prop
@@ -0,0 +1,20 @@
1
+ ---
2
+ node:
3
+ uri: global.subcomponent.timeline-event
4
+ styles:
5
+ layout.type: flow
6
+ layout.direction: horizontal
7
+ edges:
8
+ - node:
9
+ role: actor
10
+ relation:
11
+ cardinality: "0..1"
12
+ - node:
13
+ role: datetime
14
+ relation:
15
+ cardinality: "0..1"
16
+ - node:
17
+ role: payload
18
+ relation:
19
+ cardinality: "1"
20
+ slotName: default
@@ -0,0 +1,9 @@
1
+ ---
2
+ node:
3
+ uri: global.subcomponent.timeline-footer
4
+ edges:
5
+ - node:
6
+ role: content
7
+ relation:
8
+ cardinality: "1"
9
+ slotName: default
@@ -0,0 +1,18 @@
1
+ ---
2
+ node:
3
+ uri: global.subcomponent.timeline-header
4
+ styles:
5
+ layout.type: flow
6
+ layout.direction: horizontal
7
+ layout.justify: space-between
8
+ edges:
9
+ - node:
10
+ role: filters
11
+ relation:
12
+ cardinality: "0..1"
13
+ slotName: start
14
+ - node:
15
+ role: sorting
16
+ relation:
17
+ cardinality: "0..1"
18
+ slotName: end
@@ -0,0 +1,423 @@
1
+ # Anatomy DSL Specification
2
+
3
+ This specification presents a DSL to represent design system anatomies, providing an accurate platform-agnostic markup primitive to precede implementation.
4
+
5
+ ## Rationale
6
+
7
+ Design systems need a formal way to describe component structure that:
8
+ - Precedes and guides implementation
9
+ - Is platform-agnostic (works for React, SwiftUI, Flutter, etc.)
10
+ - Supports discussion and review
11
+ - Enables automated tooling (auditing, code generation)
12
+
13
+ ## Intended Usage
14
+
15
+ 1. **Documentation**: Implementation primitive for markup and style bindings
16
+ 2. **Specification**: Using the tree-based DSL to identify entities to implement and/or reuse
17
+ 3. **Discussion**: Using the DSL to discuss across conversations related to DS (e.g., "I believe these nodes should be siblings, not parents of one another")
18
+ 4. **Inference**: Supporting automated inference to audit a codebase against its specifications or to support code generation
19
+
20
+ ## Requirements
21
+
22
+ ### General DSL Requirements
23
+
24
+ - The DSL MUST optimize for readability
25
+ - The DSL MUST be easy to get started with and use a familiar language
26
+ - The scope of the DSL MUST be minimized to cover only the strict necessary - additional specification information being covered in the schema
27
+
28
+ ### Modelling Requirements
29
+
30
+ - The children of a node MUST be modelled through a reified relation for annotation purposes
31
+ - The DSL MUST support anonymous nodes (nodes that are not named components, for instance an unnamed "div"). In this case, the DSL should support role annotations
32
+ - The DSL MUST support reified annotations of cardinality
33
+ - The DSL MUST support all classes of UI Blocks identified in the ontology (Layout, Pattern, Component, Subcomponent)
34
+
35
+ ## Type System
36
+
37
+ We structure the children one-to-many relation following inspiration by [the Relay connection pattern](https://relay.dev/graphql/connections.htm) and propose the following typings.
38
+
39
+ ```typescript
40
+ /* Reusable types */
41
+
42
+ /**
43
+ * Styles use a CTI (Category-Type-Item) inspired flat key structure for
44
+ * platform-agnostic UI properties. This allows to avoid using language
45
+ * specific keys such as CSS.
46
+ *
47
+ * KEY NAMING CONVENTION:
48
+ * Properties follow a dot-notation pattern: "category.type[.item]"
49
+ * - Category: Primary concern (layout, spacing, appearance, typography, size, etc.)
50
+ * - Type: Specific aspect within that category
51
+ * - Item: Optional further specification
52
+ *
53
+ * INVARIANT VS THEMEABLE:
54
+ * Whether a property is invariant (structural) or themeable depends on its
55
+ * semantic meaning and value type, rather than strict rules:
56
+ *
57
+ * Typically invariant (structural decisions):
58
+ * - layout.type: "stack" | "flow" | "grid" // Component structure
59
+ * - layout.direction: "horizontal" | "vertical"
60
+ * - size.width: "fill" | "hug" | "100%" // Structural sizing
61
+ *
62
+ * Typically themeable (brand/theme variations):
63
+ * - appearance.*: Color, shadow, radius values via tokens
64
+ * - spacing.*: When referencing design tokens
65
+ * - typography.*: Font properties via tokens
66
+ *
67
+ * Context-dependent:
68
+ * - size.width: "320px" or "size/card/width" // Token = themeable
69
+ * - size.width: "fill" or "100%" // Structural = invariant
70
+ * - spacing.internal: "16" // Fixed value = invariant
71
+ * - spacing.internal: "spacing/medium" // Token = themeable
72
+ *
73
+ * The distinction is semantic: does this property define structure or appearance?
74
+ */
75
+ type Styles = Record<string, TokenPath | PrimitiveValue>;
76
+
77
+ /**
78
+ * TokenPath represents a forward-slash delimited path to a design token.
79
+ * Follows design token naming conventions referenced by the W3C Design Token Format.
80
+ *
81
+ * Examples:
82
+ * - "spacing/medium"
83
+ * - "color/surface/primary"
84
+ * - "font/size/heading/1"
85
+ * - "border/width/thin"
86
+ * - "shadow/elevated/medium"
87
+ * - "radius/button/default"
88
+ *
89
+ * Token paths are resolved at runtime against the active theme.
90
+ */
91
+ type TokenPath = string;
92
+
93
+ /**
94
+ * PrimitiveValue represents direct values not resolved from tokens.
95
+ * Used for structural decisions and fixed values.
96
+ *
97
+ * Examples:
98
+ * - string: "stack", "flow", "center", "fill", "100%", "1fr"
99
+ * - number: 1.5 (aspect ratio), 2 (column count), -1 (z-index)
100
+ * - boolean: true/false (for wrap, reverse, etc.)
101
+ */
102
+ type PrimitiveValue = string | number | boolean;
103
+
104
+ /* Main types */
105
+
106
+ interface Relation {
107
+ /**
108
+ * Cardinality represents the number of allowed instances of the related node.
109
+ * See https://en.wikipedia.org/wiki/Cardinality_(data_modeling) for reference.
110
+ *
111
+ * Examples:
112
+ * - "1" : Exactly one (required)
113
+ * - "0..1" : Zero or one (optional)
114
+ * - "0..*" : Zero or more
115
+ * - "1..*" : One or more
116
+ * - "2..5" : Between 2 and 5
117
+ */
118
+ cardinality: string;
119
+
120
+ /**
121
+ * Maps content to a specific slot in the parent component.
122
+ *
123
+ * Common values:
124
+ * - "default" : Main content (React children)
125
+ * - "header" : Header slot
126
+ * - "footer" : Footer slot
127
+ * - "icon" : Icon placement
128
+ * - "label" : Text label
129
+ * - Custom slots as needed
130
+ */
131
+ slotName?: string;
132
+ }
133
+
134
+ /**
135
+ * Base interface for all nodes in the anatomy tree.
136
+ */
137
+ interface BaseNode {
138
+ /**
139
+ * Style properties using CTI-inspired keys.
140
+ *
141
+ * Common patterns and their platform mappings:
142
+ *
143
+ * LAYOUT:
144
+ * - "layout.type": "stack" | "flow" | "grid"
145
+ * -> CSS: display + flexDirection | SwiftUI: VStack/HStack | Flutter: Column/Row
146
+ * - "layout.align": "center" | "start" | "end"
147
+ * -> CSS: align-items | SwiftUI: alignment | Flutter: crossAxisAlignment
148
+ *
149
+ * SPACING:
150
+ * - "spacing.internal": "spacing/medium"
151
+ * -> CSS: padding | SwiftUI: .padding() | Flutter: EdgeInsets
152
+ * - "spacing.external": "spacing/large"
153
+ * -> CSS: margin | SwiftUI: frame modifiers | Flutter: Container margin
154
+ * - "spacing.gap": "spacing/small"
155
+ * -> CSS: gap | SwiftUI: spacing parameter | Flutter: SizedBox between
156
+ *
157
+ * APPEARANCE:
158
+ * - "appearance.background": "color/surface/primary"
159
+ * -> CSS: background | SwiftUI: .background() | Flutter: Container color
160
+ * - "appearance.radius": "radius/medium"
161
+ * -> CSS: border-radius | SwiftUI: .cornerRadius() | Flutter: BorderRadius
162
+ *
163
+ * SIZE:
164
+ * - "size.width": "fill" | "hug" | "size/card/width"
165
+ * -> CSS: width: 100% | auto | var() | SwiftUI: .frame() | Flutter: constraints
166
+ *
167
+ * Examples showing invariant vs themeable:
168
+ * {
169
+ * "layout.type": "grid", // Invariant: structural
170
+ * "layout.columns": "1fr 300px 1fr", // Invariant: grid structure
171
+ * "spacing.gap": "spacing/grid/gap", // Themeable: token reference
172
+ * "appearance.background": "color/surface", // Themeable: always
173
+ * "size.width": "fill", // Invariant: structural behavior
174
+ * "size.max.width": "size/container/max", // Themeable: token reference
175
+ * "typography.align": "center", // Invariant: structural
176
+ * "typography.size": "font/size/body", // Themeable: token reference
177
+ * }
178
+ */
179
+ styles?: Styles;
180
+
181
+ /**
182
+ * Child nodes and their relationships.
183
+ * Enables recursive component composition.
184
+ */
185
+ edges?: Edge[];
186
+ }
187
+
188
+ /**
189
+ * Named nodes represent identifiable components in the design system.
190
+ */
191
+ interface NamedNode extends BaseNode {
192
+ /**
193
+ * Unique identifier following "tier:type:name" pattern.
194
+ * Maps to URI field on UI Block in the ontology.
195
+ *
196
+ * Examples:
197
+ * - "core:component:Button"
198
+ * - "core:component:Card"
199
+ * - "app:layout:AppLayout"
200
+ */
201
+ uri: string;
202
+ }
203
+
204
+ /**
205
+ * Anonymous nodes represent structural elements without DS identity.
206
+ */
207
+ interface AnonymousNode extends BaseNode {
208
+ /**
209
+ * Human-readable description of the node's purpose.
210
+ *
211
+ * Examples:
212
+ * - "content wrapper"
213
+ * - "spacer element"
214
+ * - "icon container"
215
+ * - "layout grid cell"
216
+ */
217
+ role: string;
218
+ }
219
+
220
+ /**
221
+ * Union type for all possible nodes.
222
+ */
223
+ type Node = NamedNode | AnonymousNode;
224
+
225
+ /**
226
+ * Represents a parent-child relationship in the anatomy tree.
227
+ */
228
+ interface Edge {
229
+ /** The child node (Named or Anonymous) */
230
+ node: Node;
231
+
232
+ /** Relationship metadata (cardinality, slot) */
233
+ relation: Relation;
234
+ }
235
+
236
+ /**
237
+ * Root specification for a component anatomy.
238
+ * The top-level node must always be Named.
239
+ */
240
+ interface AnatomySpec {
241
+ node: NamedNode;
242
+ }
243
+ ```
244
+
245
+ ## Language Choice
246
+
247
+ We propose the use of YAML, a mature indentation-based configuration syntax based on scalars, maps and lists. The main contender we have considered aside from YAML was JSON, rejected for its verbosity. We have also rejected TOML (maps with difficulty deeply nested nodes), SDLang and KDL (promising markup syntaxes without wide adoption at present).
248
+
249
+ ## Examples
250
+
251
+ ### Accordion
252
+
253
+ ```yaml
254
+ node:
255
+ uri: core:component:Accordion
256
+ styles:
257
+ # Structural (implicitly invariant)
258
+ layout.type: stack
259
+ layout.direction: vertical
260
+
261
+ # Themeable
262
+ appearance.border: border/style/accordion
263
+
264
+ edges:
265
+ - node:
266
+ uri: core:component:AccordionItem
267
+ edges:
268
+ - node:
269
+ uri: core:element:AccordionItemHeader
270
+ styles:
271
+ # Structural (implicitly invariant)
272
+ layout.type: flow
273
+ layout.direction: horizontal
274
+ layout.align: center
275
+
276
+ # Interaction (implicitly invariant)
277
+ interaction.cursor: pointer
278
+ interaction.transition.property: background
279
+ interaction.transition.timing: ease
280
+
281
+ # Themeable
282
+ spacing.internal: spacing/medium
283
+ appearance.background: color/surface/header
284
+ typography.weight: font/weight/semibold
285
+ interaction.transition.duration: transition/duration
286
+
287
+ relation:
288
+ cardinality: "1..1"
289
+ slotName: header
290
+
291
+ - node:
292
+ uri: core:element:AccordionItemContent
293
+ styles:
294
+ # Structural (implicitly invariant)
295
+ layout.display: block
296
+ layout.overflow: hidden
297
+
298
+ # Themeable
299
+ spacing.internal: spacing/large
300
+ appearance.background: color/surface/content
301
+ appearance.border.top: border/style/none
302
+
303
+ relation:
304
+ cardinality: "1..1"
305
+ slotName: default
306
+
307
+ relation:
308
+ cardinality: "1..*"
309
+ ```
310
+
311
+ ### Card
312
+
313
+ ```yaml
314
+ node:
315
+ uri: core:component:Card
316
+ styles:
317
+ # Structural (implicitly invariant)
318
+ layout.type: stack
319
+ layout.direction: vertical
320
+
321
+ # Themeable
322
+ appearance.background: color/surface/card
323
+ appearance.shadow: shadow/card
324
+ appearance.radius: shape/rounded/full
325
+ spacing.gap: spacing/small
326
+
327
+ edges:
328
+ - node:
329
+ uri: core:element:CardHeader
330
+ styles:
331
+ # Structural (implicitly invariant)
332
+ layout.type: flow
333
+ layout.direction: horizontal
334
+ layout.align: center
335
+
336
+ # Themeable
337
+ spacing.internal: spacing/medium
338
+ appearance.border.bottom: border/style/divider
339
+ typography.weight: font/weight/bold
340
+
341
+ relation:
342
+ cardinality: "0..1"
343
+ slotName: header
344
+
345
+ - node:
346
+ uri: core:element:CardMedia
347
+ styles:
348
+ # Structural (implicitly invariant)
349
+ layout.display: block
350
+ size.width: fill
351
+ object.fit: cover
352
+
353
+ # Themeable
354
+ size.max.height: size/media/max
355
+ appearance.radius: shape/rounded/top
356
+
357
+ relation:
358
+ cardinality: "0..1"
359
+ slotName: media
360
+
361
+ - node:
362
+ uri: core:element:CardBody
363
+ styles:
364
+ # Structural (implicitly invariant)
365
+ layout.type: stack
366
+ layout.direction: vertical
367
+ layout.flex: 1
368
+
369
+ # Themeable
370
+ spacing.internal: spacing/large
371
+ typography.color: color/text/body
372
+ typography.size: font/size/medium
373
+
374
+ edges:
375
+ - node:
376
+ role: content wrapper
377
+ styles:
378
+ # Structural (implicitly invariant)
379
+ layout.display: block
380
+
381
+ # Themeable
382
+ spacing.margin.bottom: spacing/small
383
+ appearance.background: color/background/subtle
384
+
385
+ relation:
386
+ cardinality: "1..1"
387
+
388
+ relation:
389
+ cardinality: "1..1"
390
+ slotName: body
391
+
392
+ - node:
393
+ uri: core:element:CardFooter
394
+ styles:
395
+ # Structural (implicitly invariant)
396
+ layout.type: flow
397
+ layout.direction: horizontal
398
+ layout.justify: space-between
399
+
400
+ # Themeable
401
+ spacing.internal: spacing/small
402
+ appearance.border.top: border/style/divider
403
+ typography.size: font/size/small
404
+
405
+ relation:
406
+ cardinality: "0..1"
407
+ slotName: footer
408
+ ```
409
+
410
+ ## Further Work
411
+
412
+ The following features would require additional work to this specification:
413
+
414
+ - Representation of related nodes displayed in portals
415
+ - Representation of conditional display
416
+ - Inheritance reference for styles (e.g., "NetworkCard" inherits the styles from "Card")
417
+
418
+ ## References
419
+
420
+ Two main references have supported our reflection:
421
+
422
+ 1. The work of the [Open UI W3C Working Group](https://open-ui.org/), which takes interest in a code-based anatomy for their specifications ([Example](https://open-ui.org/components/accordion.explainer/))
423
+ 2. The work of Nathan Curtis, exploring a similar syntax in his article "[Components as Data](https://medium.com/@nathanacurtis/components-as-data-2be178777f21)"