@rien7/design-surface 0.0.0-stage → 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 (214) hide show
  1. package/bin/design-surface.mjs +286 -0
  2. package/dist/cli/init.mjs +411 -0
  3. package/dist/cli/propose.mjs +172 -0
  4. package/dist/cli/reviewOps.mjs +127 -0
  5. package/dist/editor/AgentProposalCard.d.ts +10 -0
  6. package/dist/editor/AgentProposalCard.d.ts.map +1 -0
  7. package/dist/editor/AgentProposalCard.js +28 -0
  8. package/dist/editor/AgentProposalCard.js.map +1 -0
  9. package/dist/editor/App.d.ts +2 -0
  10. package/dist/editor/App.d.ts.map +1 -0
  11. package/dist/editor/App.js +1813 -0
  12. package/dist/editor/App.js.map +1 -0
  13. package/dist/editor/CanvasHud.d.ts +12 -0
  14. package/dist/editor/CanvasHud.d.ts.map +1 -0
  15. package/dist/editor/CanvasHud.js +13 -0
  16. package/dist/editor/CanvasHud.js.map +1 -0
  17. package/dist/editor/CanvasSurface.d.ts +20 -0
  18. package/dist/editor/CanvasSurface.d.ts.map +1 -0
  19. package/dist/editor/CanvasSurface.js +252 -0
  20. package/dist/editor/CanvasSurface.js.map +1 -0
  21. package/dist/editor/Changes.d.ts +17 -0
  22. package/dist/editor/Changes.d.ts.map +1 -0
  23. package/dist/editor/Changes.js +59 -0
  24. package/dist/editor/Changes.js.map +1 -0
  25. package/dist/editor/CommentPopover.d.ts +17 -0
  26. package/dist/editor/CommentPopover.d.ts.map +1 -0
  27. package/dist/editor/CommentPopover.js +62 -0
  28. package/dist/editor/CommentPopover.js.map +1 -0
  29. package/dist/editor/Comments.d.ts +13 -0
  30. package/dist/editor/Comments.d.ts.map +1 -0
  31. package/dist/editor/Comments.js +39 -0
  32. package/dist/editor/Comments.js.map +1 -0
  33. package/dist/editor/History.d.ts +7 -0
  34. package/dist/editor/History.d.ts.map +1 -0
  35. package/dist/editor/History.js +43 -0
  36. package/dist/editor/History.js.map +1 -0
  37. package/dist/editor/Inspector.d.ts +22 -0
  38. package/dist/editor/Inspector.d.ts.map +1 -0
  39. package/dist/editor/Inspector.js +241 -0
  40. package/dist/editor/Inspector.js.map +1 -0
  41. package/dist/editor/LazyMount.d.ts +10 -0
  42. package/dist/editor/LazyMount.d.ts.map +1 -0
  43. package/dist/editor/LazyMount.js +29 -0
  44. package/dist/editor/LazyMount.js.map +1 -0
  45. package/dist/editor/LocaleSwitch.d.ts +2 -0
  46. package/dist/editor/LocaleSwitch.d.ts.map +1 -0
  47. package/dist/editor/LocaleSwitch.js +13 -0
  48. package/dist/editor/LocaleSwitch.js.map +1 -0
  49. package/dist/editor/NodeInspector.d.ts +9 -0
  50. package/dist/editor/NodeInspector.d.ts.map +1 -0
  51. package/dist/editor/NodeInspector.js +9 -0
  52. package/dist/editor/NodeInspector.js.map +1 -0
  53. package/dist/editor/PreviewFrame.d.ts +10 -0
  54. package/dist/editor/PreviewFrame.d.ts.map +1 -0
  55. package/dist/editor/PreviewFrame.js +22 -0
  56. package/dist/editor/PreviewFrame.js.map +1 -0
  57. package/dist/editor/ProjectIndex.d.ts +12 -0
  58. package/dist/editor/ProjectIndex.d.ts.map +1 -0
  59. package/dist/editor/ProjectIndex.js +43 -0
  60. package/dist/editor/ProjectIndex.js.map +1 -0
  61. package/dist/editor/StyleEditor.d.ts +37 -0
  62. package/dist/editor/StyleEditor.d.ts.map +1 -0
  63. package/dist/editor/StyleEditor.js +275 -0
  64. package/dist/editor/StyleEditor.js.map +1 -0
  65. package/dist/editor/TokenWorkbench.d.ts +37 -0
  66. package/dist/editor/TokenWorkbench.d.ts.map +1 -0
  67. package/dist/editor/TokenWorkbench.js +146 -0
  68. package/dist/editor/TokenWorkbench.js.map +1 -0
  69. package/dist/editor/Tokens.d.ts +21 -0
  70. package/dist/editor/Tokens.d.ts.map +1 -0
  71. package/dist/editor/Tokens.js +56 -0
  72. package/dist/editor/Tokens.js.map +1 -0
  73. package/dist/editor/VariablesPage.d.ts +28 -0
  74. package/dist/editor/VariablesPage.d.ts.map +1 -0
  75. package/dist/editor/VariablesPage.js +14 -0
  76. package/dist/editor/VariablesPage.js.map +1 -0
  77. package/dist/editor/api.d.ts +13 -0
  78. package/dist/editor/api.d.ts.map +1 -0
  79. package/dist/editor/api.js +70 -0
  80. package/dist/editor/api.js.map +1 -0
  81. package/dist/editor/camera.d.ts +18 -0
  82. package/dist/editor/camera.d.ts.map +1 -0
  83. package/dist/editor/camera.js +40 -0
  84. package/dist/editor/camera.js.map +1 -0
  85. package/dist/editor/canvas.d.ts +26 -0
  86. package/dist/editor/canvas.d.ts.map +1 -0
  87. package/dist/editor/canvas.js +51 -0
  88. package/dist/editor/canvas.js.map +1 -0
  89. package/dist/editor/chrome/EditorChrome.d.ts +42 -0
  90. package/dist/editor/chrome/EditorChrome.d.ts.map +1 -0
  91. package/dist/editor/chrome/EditorChrome.js +21 -0
  92. package/dist/editor/chrome/EditorChrome.js.map +1 -0
  93. package/dist/editor/i18n.d.ts +18 -0
  94. package/dist/editor/i18n.d.ts.map +1 -0
  95. package/dist/editor/i18n.js +762 -0
  96. package/dist/editor/i18n.js.map +1 -0
  97. package/dist/editor/main.d.ts +3 -0
  98. package/dist/editor/main.d.ts.map +1 -0
  99. package/dist/editor/main.js +12 -0
  100. package/dist/editor/main.js.map +1 -0
  101. package/dist/editor/model.d.ts +17 -0
  102. package/dist/editor/model.d.ts.map +1 -0
  103. package/dist/editor/model.js +12 -0
  104. package/dist/editor/model.js.map +1 -0
  105. package/dist/editor/reviewLifecycle.d.ts +9 -0
  106. package/dist/editor/reviewLifecycle.d.ts.map +1 -0
  107. package/dist/editor/reviewLifecycle.js +30 -0
  108. package/dist/editor/reviewLifecycle.js.map +1 -0
  109. package/dist/editor/styles.css +6626 -0
  110. package/dist/editor/ui/Button.d.ts +3 -0
  111. package/dist/editor/ui/Button.d.ts.map +1 -0
  112. package/dist/editor/ui/Button.js +6 -0
  113. package/dist/editor/ui/Button.js.map +1 -0
  114. package/dist/editor/ui/CommentBox.d.ts +23 -0
  115. package/dist/editor/ui/CommentBox.d.ts.map +1 -0
  116. package/dist/editor/ui/CommentBox.js +41 -0
  117. package/dist/editor/ui/CommentBox.js.map +1 -0
  118. package/dist/editor/ui/Icon.d.ts +9 -0
  119. package/dist/editor/ui/Icon.d.ts.map +1 -0
  120. package/dist/editor/ui/Icon.js +6 -0
  121. package/dist/editor/ui/Icon.js.map +1 -0
  122. package/dist/editor/ui/IconButton.d.ts +11 -0
  123. package/dist/editor/ui/IconButton.d.ts.map +1 -0
  124. package/dist/editor/ui/IconButton.js +6 -0
  125. package/dist/editor/ui/IconButton.js.map +1 -0
  126. package/dist/editor/ui/NumberInput.d.ts +14 -0
  127. package/dist/editor/ui/NumberInput.d.ts.map +1 -0
  128. package/dist/editor/ui/NumberInput.js +6 -0
  129. package/dist/editor/ui/NumberInput.js.map +1 -0
  130. package/dist/editor/ui/PageLine.d.ts +14 -0
  131. package/dist/editor/ui/PageLine.d.ts.map +1 -0
  132. package/dist/editor/ui/PageLine.js +7 -0
  133. package/dist/editor/ui/PageLine.js.map +1 -0
  134. package/dist/editor/ui/Select.d.ts +15 -0
  135. package/dist/editor/ui/Select.d.ts.map +1 -0
  136. package/dist/editor/ui/Select.js +11 -0
  137. package/dist/editor/ui/Select.js.map +1 -0
  138. package/dist/editor/ui/TokenField.d.ts +14 -0
  139. package/dist/editor/ui/TokenField.d.ts.map +1 -0
  140. package/dist/editor/ui/TokenField.js +41 -0
  141. package/dist/editor/ui/TokenField.js.map +1 -0
  142. package/dist/editor-ui.d.ts +14 -0
  143. package/dist/editor-ui.d.ts.map +1 -0
  144. package/dist/editor-ui.js +13 -0
  145. package/dist/editor-ui.js.map +1 -0
  146. package/dist/inspector/runtime.d.ts +18 -0
  147. package/dist/inspector/runtime.d.ts.map +1 -0
  148. package/dist/inspector/runtime.js +987 -0
  149. package/dist/inspector/runtime.js.map +1 -0
  150. package/dist/preview/main.d.ts +3 -0
  151. package/dist/preview/main.d.ts.map +1 -0
  152. package/dist/preview/main.js +72 -0
  153. package/dist/preview/main.js.map +1 -0
  154. package/dist/preview/preview.css +39 -0
  155. package/dist/runtime/flow.d.ts +15 -0
  156. package/dist/runtime/flow.d.ts.map +1 -0
  157. package/dist/runtime/flow.js +48 -0
  158. package/dist/runtime/flow.js.map +1 -0
  159. package/dist/runtime/free.d.ts +18 -0
  160. package/dist/runtime/free.d.ts.map +1 -0
  161. package/dist/runtime/free.js +8 -0
  162. package/dist/runtime/free.js.map +1 -0
  163. package/dist/runtime/index.d.ts +11 -0
  164. package/dist/runtime/index.d.ts.map +1 -0
  165. package/dist/runtime/index.js +46 -0
  166. package/dist/runtime/index.js.map +1 -0
  167. package/dist/runtime/types.d.ts +57 -0
  168. package/dist/runtime/types.d.ts.map +1 -0
  169. package/dist/runtime/types.js +14 -0
  170. package/dist/runtime/types.js.map +1 -0
  171. package/dist/shared/prompt.d.mts +13 -0
  172. package/dist/shared/prompt.mjs +97 -0
  173. package/dist/shared/protocol.d.ts +79 -0
  174. package/dist/shared/protocol.d.ts.map +1 -0
  175. package/dist/shared/protocol.js +7 -0
  176. package/dist/shared/protocol.js.map +1 -0
  177. package/dist/shared/tokens.d.ts +66 -0
  178. package/dist/shared/tokens.d.ts.map +1 -0
  179. package/dist/shared/tokens.js +2 -0
  180. package/dist/shared/tokens.js.map +1 -0
  181. package/dist/shared/types.d.ts +301 -0
  182. package/dist/shared/types.d.ts.map +1 -0
  183. package/dist/shared/types.js +13 -0
  184. package/dist/shared/types.js.map +1 -0
  185. package/dist/tokens/adapters/css.mjs +44 -0
  186. package/dist/tokens/adapters/cssInCode.mjs +277 -0
  187. package/dist/tokens/adapters/oxcShared.mjs +59 -0
  188. package/dist/tokens/adapters/preprocessor.mjs +63 -0
  189. package/dist/tokens/adapters/registry.mjs +53 -0
  190. package/dist/tokens/adapters/tailwindcss.mjs +360 -0
  191. package/dist/tokens/adapters/types.mjs +117 -0
  192. package/dist/tokens/extract.mjs +328 -0
  193. package/dist/tokens/pipeline.mjs +688 -0
  194. package/dist/vite/events.d.ts +25 -0
  195. package/dist/vite/events.d.ts.map +1 -0
  196. package/dist/vite/events.js +137 -0
  197. package/dist/vite/events.js.map +1 -0
  198. package/dist/vite/layout.d.ts +4 -0
  199. package/dist/vite/layout.d.ts.map +1 -0
  200. package/dist/vite/layout.js +78 -0
  201. package/dist/vite/layout.js.map +1 -0
  202. package/dist/vite/plugin.d.ts +33 -0
  203. package/dist/vite/plugin.d.ts.map +1 -0
  204. package/dist/vite/plugin.js +403 -0
  205. package/dist/vite/plugin.js.map +1 -0
  206. package/dist/vite/review.d.ts +7 -0
  207. package/dist/vite/review.d.ts.map +1 -0
  208. package/dist/vite/review.js +334 -0
  209. package/dist/vite/review.js.map +1 -0
  210. package/package.json +87 -4
  211. package/skills/design-surface/SKILL.md +190 -0
  212. package/skills/design-surface-authoring/SKILL.md +257 -0
  213. package/skills/design-surface-tokens/SKILL.md +235 -0
  214. package/README.md +0 -3
@@ -0,0 +1,328 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
2
+ import { dirname, join, relative, resolve, sep } from 'node:path'
3
+
4
+ import postcss from 'postcss'
5
+ import valueParser from 'postcss-value-parser'
6
+ import { glob } from 'tinyglobby'
7
+
8
+ import { colorToRgb, loadTokenConfig, readTokenRecords } from './pipeline.mjs'
9
+
10
+ const MULTI_PREFIXES = [
11
+ 'font-size',
12
+ 'font-weight',
13
+ 'font-family',
14
+ 'line-height',
15
+ 'letter-spacing',
16
+ 'border-width',
17
+ 'border-radius',
18
+ ]
19
+
20
+ const toPosix = (file) => file.split(sep).join('/')
21
+
22
+ const titleize = (slug) =>
23
+ slug
24
+ .replace(/[-_]+/g, ' ')
25
+ .replace(/^\w/, (char) => char.toUpperCase())
26
+
27
+ function cssNameToPath(cssName) {
28
+ const raw = cssName.replace(/^--/, '')
29
+ for (const prefix of MULTI_PREFIXES) {
30
+ if (raw.startsWith(`${prefix}-`)) {
31
+ return [prefix, raw.slice(prefix.length + 1)]
32
+ }
33
+ }
34
+ const dash = raw.indexOf('-')
35
+ if (dash > 0) {
36
+ return [raw.slice(0, dash), raw.slice(dash + 1)]
37
+ }
38
+ return [raw]
39
+ }
40
+
41
+ function inferTypeAndValue(value) {
42
+ const trimmed = value.trim()
43
+ if (/^-?\d+(?:\.\d+)?(px|rem|em|%)$/.test(trimmed)) {
44
+ const match = /^(-?\d+(?:\.\d+)?)(px|rem|em|%)$/.exec(trimmed)
45
+ return {
46
+ dtcgType: 'dimension',
47
+ uiType: 'length',
48
+ value: { value: Number(match[1]), unit: match[2] },
49
+ }
50
+ }
51
+ if (
52
+ colorToRgb(trimmed) ||
53
+ /^(?:color-mix|rgba?|hsla?|oklch|oklab|color)\(/i.test(trimmed)
54
+ ) {
55
+ return {
56
+ dtcgType: 'color',
57
+ uiType: 'color',
58
+ value: trimmed,
59
+ }
60
+ }
61
+ return {
62
+ dtcgType: 'string',
63
+ uiType: 'text',
64
+ value: trimmed,
65
+ }
66
+ }
67
+
68
+ function extractCssCustomProperties(cssText, file) {
69
+ const rootAst = postcss.parse(cssText, { from: file })
70
+ const entries = []
71
+ const collectFromContainer = (container) => {
72
+ container.walkDecls((decl) => {
73
+ if (decl.parent !== container) return
74
+ if (!decl.prop.startsWith('--')) return
75
+ const value = decl.value.trim()
76
+ if (!value) return
77
+ entries.push({ cssName: decl.prop, value })
78
+ })
79
+ }
80
+ rootAst.walk((node) => {
81
+ if (node.type === 'atrule' && node.name.toLowerCase() === 'theme') {
82
+ collectFromContainer(node)
83
+ } else if (node.type === 'rule' && /(?:^|[,\s]):root(?:\b|$|\s|,)/.test(node.selector)) {
84
+ collectFromContainer(node)
85
+ }
86
+ })
87
+ return entries
88
+ }
89
+
90
+ function extractSingleVarAlias(value) {
91
+ const parsed = valueParser(value)
92
+ const meaningful = parsed.nodes.filter(
93
+ (node) => node.type !== 'space' && node.type !== 'comment',
94
+ )
95
+ if (meaningful.length !== 1) return null
96
+ const node = meaningful[0]
97
+ if (node.type !== 'function' || node.value.toLowerCase() !== 'var') return null
98
+ const arg = (node.nodes ?? []).find(
99
+ (child) => child.type === 'word' && child.value.startsWith('--'),
100
+ )
101
+ return arg ? arg.value : null
102
+ }
103
+
104
+ function readJsonOrEmpty(file) {
105
+ if (!existsSync(file)) return {}
106
+ try {
107
+ return JSON.parse(readFileSync(file, 'utf8'))
108
+ } catch {
109
+ return {}
110
+ }
111
+ }
112
+
113
+ function insertToken(rootObj, tokenPath, leaf, tier, groupName) {
114
+ if (tokenPath.length === 1) {
115
+ const [key] = tokenPath
116
+ if (key in rootObj) return false
117
+ rootObj[key] = {
118
+ ...leaf,
119
+ $extensions: {
120
+ 'design-surface': {
121
+ tier,
122
+ group: groupName,
123
+ ...leaf.$extensions['design-surface'],
124
+ },
125
+ },
126
+ }
127
+ return true
128
+ }
129
+ const [head, ...rest] = tokenPath
130
+ if (!(head in rootObj)) {
131
+ rootObj[head] = {
132
+ $extensions: {
133
+ 'design-surface': {
134
+ tier,
135
+ group: groupName,
136
+ label: titleize(head),
137
+ },
138
+ },
139
+ }
140
+ }
141
+ let cursor = rootObj[head]
142
+ if (!cursor || typeof cursor !== 'object' || Array.isArray(cursor) || '$value' in cursor) {
143
+ return false
144
+ }
145
+ for (let i = 0; i < rest.length - 1; i += 1) {
146
+ const segment = rest[i]
147
+ if (!(segment in cursor)) cursor[segment] = {}
148
+ cursor = cursor[segment]
149
+ if (!cursor || typeof cursor !== 'object' || Array.isArray(cursor) || '$value' in cursor) {
150
+ return false
151
+ }
152
+ }
153
+ const leafKey = rest[rest.length - 1]
154
+ if (leafKey in cursor) return false
155
+ cursor[leafKey] = leaf
156
+ return true
157
+ }
158
+
159
+ export async function extractTokensFromCss({ root = process.cwd(), files = [], dryRun = false } = {}) {
160
+ const config = loadTokenConfig(root)
161
+ const generatedCssAbs = resolve(root, config.cssOut)
162
+ let targetFiles = []
163
+
164
+ if (files.length === 0) {
165
+ targetFiles = await glob(['src/**/*.css'], {
166
+ cwd: root,
167
+ absolute: true,
168
+ onlyFiles: true,
169
+ ignore: ['**/node_modules/**', '**/dist/**', '**/tokens.generated.css'],
170
+ })
171
+ } else {
172
+ for (const entry of files) {
173
+ if (/[*?[\]{}]/.test(entry)) {
174
+ const matched = await glob([entry], {
175
+ cwd: root,
176
+ absolute: true,
177
+ onlyFiles: true,
178
+ ignore: ['**/node_modules/**', '**/dist/**', '**/tokens.generated.css'],
179
+ })
180
+ targetFiles.push(...matched)
181
+ } else {
182
+ const abs = resolve(root, entry)
183
+ if (!existsSync(abs)) throw new Error(`CSS file not found: ${entry}`)
184
+ targetFiles.push(abs)
185
+ }
186
+ }
187
+ }
188
+
189
+ targetFiles = [...new Set(targetFiles)]
190
+ .filter((file) => file !== generatedCssAbs)
191
+ .sort()
192
+
193
+ const declared = new Map()
194
+ for (const file of targetFiles) {
195
+ const text = readFileSync(file, 'utf8')
196
+ for (const item of extractCssCustomProperties(text, file)) {
197
+ declared.set(item.cssName, item.value)
198
+ }
199
+ }
200
+
201
+ let existingRecords = []
202
+ try {
203
+ existingRecords = readTokenRecords(root, config.tokenDir).records
204
+ } catch {
205
+ existingRecords = []
206
+ }
207
+
208
+ const existingCss = new Set(existingRecords.map((record) => record.cssName))
209
+ const existingPaths = new Set(existingRecords.map((record) => record.path.join('.')))
210
+ const cssToPath = new Map(existingRecords.map((record) => [record.cssName, record.path.join('.')]))
211
+ const pathToType = new Map(existingRecords.map((record) => [record.path.join('.'), record.dtcgType]))
212
+
213
+ const pendingPrimitives = []
214
+ const pendingSemantics = []
215
+ const skippedExisting = []
216
+
217
+ for (const [cssName, value] of declared) {
218
+ const tokenPath = cssNameToPath(cssName)
219
+ const pathStr = tokenPath.join('.')
220
+ if (existingCss.has(cssName) || existingPaths.has(pathStr)) {
221
+ skippedExisting.push(cssName)
222
+ continue
223
+ }
224
+ const targetCss = extractSingleVarAlias(value.trim())
225
+ if (targetCss) {
226
+ pendingSemantics.push({ cssName, tokenPath, pathStr, rawValue: value.trim(), targetCss })
227
+ } else {
228
+ const inferred = inferTypeAndValue(value)
229
+ pendingPrimitives.push({ cssName, tokenPath, pathStr, ...inferred })
230
+ cssToPath.set(cssName, pathStr)
231
+ pathToType.set(pathStr, inferred.dtcgType)
232
+ }
233
+ }
234
+
235
+ for (const item of pendingSemantics) {
236
+ cssToPath.set(item.cssName, item.pathStr)
237
+ }
238
+ const semanticByCss = new Map(pendingSemantics.map((item) => [item.cssName, item]))
239
+ const resolveAliasType = (cssName, visited = new Set()) => {
240
+ if (visited.has(cssName)) return 'string'
241
+ visited.add(cssName)
242
+ const mappedPath = cssToPath.get(cssName)
243
+ if (mappedPath && pathToType.has(mappedPath)) {
244
+ return pathToType.get(mappedPath)
245
+ }
246
+ const nextSemantic = semanticByCss.get(cssName)
247
+ if (nextSemantic) {
248
+ const resolved = resolveAliasType(nextSemantic.targetCss, visited)
249
+ pathToType.set(nextSemantic.pathStr, resolved)
250
+ return resolved
251
+ }
252
+ return 'string'
253
+ }
254
+
255
+ const tokenRoot = resolve(root, config.tokenDir)
256
+ const primitiveFile = join(tokenRoot, 'primitive.tokens.json')
257
+ const semanticFile = join(tokenRoot, 'semantic.tokens.json')
258
+ const primitiveJson = readJsonOrEmpty(primitiveFile)
259
+ const semanticJson = readJsonOrEmpty(semanticFile)
260
+
261
+ const addedPrimitives = []
262
+ for (const item of pendingPrimitives) {
263
+ const leaf = {
264
+ $type: item.dtcgType,
265
+ $value: item.value,
266
+ $extensions: {
267
+ 'design-surface': {
268
+ label: titleize(item.tokenPath[item.tokenPath.length - 1]),
269
+ uiType: item.uiType,
270
+ },
271
+ },
272
+ }
273
+ if (insertToken(primitiveJson, item.tokenPath, leaf, 'primitive', item.tokenPath[0])) {
274
+ addedPrimitives.push({ cssName: item.cssName, path: item.pathStr, value: item.value, type: item.dtcgType })
275
+ }
276
+ }
277
+
278
+ const addedSemantics = []
279
+ for (const item of pendingSemantics) {
280
+ const targetPath = cssToPath.get(item.targetCss)
281
+ const dtcgType = targetPath
282
+ ? resolveAliasType(item.targetCss, new Set([item.cssName]))
283
+ : 'string'
284
+ pathToType.set(item.pathStr, dtcgType)
285
+ const uiType = dtcgType === 'color' ? 'color' : dtcgType === 'dimension' ? 'length' : 'text'
286
+ const tokenValue = targetPath ? `{${targetPath}}` : item.rawValue
287
+ const leaf = {
288
+ $type: dtcgType,
289
+ $value: tokenValue,
290
+ $extensions: {
291
+ 'design-surface': {
292
+ label: titleize(item.tokenPath[item.tokenPath.length - 1]),
293
+ uiType,
294
+ },
295
+ },
296
+ }
297
+ if (insertToken(semanticJson, item.tokenPath, leaf, 'semantic', item.tokenPath[0])) {
298
+ addedSemantics.push({
299
+ cssName: item.cssName,
300
+ path: item.pathStr,
301
+ value: tokenValue,
302
+ type: dtcgType,
303
+ })
304
+ }
305
+ }
306
+
307
+ if (!dryRun) {
308
+ mkdirSync(tokenRoot, { recursive: true })
309
+ if (addedPrimitives.length) {
310
+ mkdirSync(dirname(primitiveFile), { recursive: true })
311
+ writeFileSync(primitiveFile, `${JSON.stringify(primitiveJson, null, 2)}\n`)
312
+ }
313
+ if (addedSemantics.length) {
314
+ mkdirSync(dirname(semanticFile), { recursive: true })
315
+ writeFileSync(semanticFile, `${JSON.stringify(semanticJson, null, 2)}\n`)
316
+ }
317
+ }
318
+
319
+ return {
320
+ dryRun,
321
+ scannedFiles: targetFiles.map((file) => toPosix(relative(root, file))),
322
+ primitiveFile: toPosix(relative(root, primitiveFile)),
323
+ semanticFile: toPosix(relative(root, semanticFile)),
324
+ addedPrimitives,
325
+ addedSemantics,
326
+ skippedExisting,
327
+ }
328
+ }