@astryxdesign/cli 0.7.5-canary.fccd771 → 0.7.5

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 (117) hide show
  1. package/CHANGELOG.md +91 -3
  2. package/README.md +2 -2
  3. package/api/hook/detail/detail.test.mjs +11 -0
  4. package/api/integration/pack-check.lifecycle-output.test.mjs +24 -1
  5. package/api/integration/pack-check.mjs +10 -4
  6. package/api/integration/pack-check.test.mjs +5 -1
  7. package/api/swizzle/copy/copy.mjs +1 -1
  8. package/api/template/tokenizer-showcase.test.mjs +47 -0
  9. package/api/theme/build/build.adaptation-enrollment.test.mjs +4 -0
  10. package/api/theme/build/build.icon-entry-variants.test.mjs +134 -0
  11. package/api/theme/build/build.icon-function-entries.test.mjs +499 -0
  12. package/api/theme/build/build.icon-variants.test.mjs +105 -0
  13. package/api/theme/build/build.mjs +371 -113
  14. package/api/theme/build/build.project-core.test.mjs +63 -8
  15. package/api/theme/build/build.test.mjs +77 -0
  16. package/api/theme/build/icon-imports.d.mts +12 -2
  17. package/api/theme/build/icon-imports.mjs +36 -11
  18. package/api/upgrade/_adapter.d.mts +47 -2
  19. package/api/upgrade/_adapter.mjs +58 -2
  20. package/api/upgrade/run/failure-receipt.test.mjs +212 -0
  21. package/api/upgrade/run/outcomes.test.mjs +646 -0
  22. package/api/upgrade/run/run.d.mts +36 -0
  23. package/api/upgrade/run/run.mjs +670 -44
  24. package/api/upgrade/upgrade.doc.mjs +4 -4
  25. package/api/upgrade/upgrade.mjs +19 -4
  26. package/api/upgrade/upgrade.type.d.mts +36 -1
  27. package/api/upgrade/upgrade.type.mjs +29 -4
  28. package/assets/codemods/__tests__/registry.test.mjs +1 -0
  29. package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
  30. package/assets/codemods/__tests__/runner.unparseable.test.mjs +457 -0
  31. package/assets/codemods/integration-runner.mjs +8 -2
  32. package/assets/codemods/integration-runner.protection.test.mjs +53 -0
  33. package/assets/codemods/outcome.mjs +79 -0
  34. package/assets/codemods/outcome.test.mjs +40 -0
  35. package/assets/codemods/parse.mjs +94 -0
  36. package/assets/codemods/registry.mjs +1 -0
  37. package/assets/codemods/run-codemod.mjs +109 -5
  38. package/assets/codemods/runner.mjs +119 -13
  39. package/assets/codemods/transform-prop.mjs +99 -49
  40. package/assets/codemods/transform-prop.test.mjs +36 -1
  41. package/assets/codemods/transforms/v0.1.2/rename-text-color-active-to-accent.mjs +1 -1
  42. package/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs +216 -2
  43. package/assets/codemods/transforms/v0.1.3/migrate-layout-components-to-experimental.mjs +88 -6
  44. package/assets/codemods/transforms/v0.1.5/rename-switch-label-spacing-default-to-hug.mjs +1 -1
  45. package/assets/codemods/transforms/v0.1.7/migrate-table-tableprops-to-direct-props.mjs +1 -1
  46. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +1 -1
  47. package/assets/codemods/transforms/v0.2.0/remove-tablist-orientation.mjs +1 -1
  48. package/assets/codemods/transforms/v0.2.1/migrate-dialog-position-to-logical.mjs +1 -1
  49. package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +4 -3
  50. package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs +207 -6
  51. package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +143 -70
  52. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface-v0.6-data.mjs +6 -1
  53. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +244 -42
  54. package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +23 -78
  55. package/assets/codemods/transforms/v0.7.5/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
  56. package/assets/codemods/transforms/v0.7.5/index.mjs +20 -0
  57. package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +315 -0
  58. package/assets/docs/README.md +13 -13
  59. package/assets/docs/author-a-theme.doc.mjs +5 -1
  60. package/assets/docs/getting-started.doc.mjs +5 -5
  61. package/assets/docs/icons.doc.mjs +82 -1
  62. package/assets/docs/motion.doc.mjs +1 -1
  63. package/assets/docs/theme.doc.dense.mjs +8 -0
  64. package/assets/docs/theme.doc.mjs +16 -0
  65. package/assets/docs/theme.doc.zh.mjs +11 -0
  66. package/assets/docs/tree/i18n-library-integration.doc.mjs +1 -1
  67. package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
  68. package/assets/docs/tree/template-styles.doc.mjs +1 -1
  69. package/assets/docs/tree/tokens-color.doc.mjs +145 -1
  70. package/assets/docs/tree/tokens-ease.doc.mjs +4 -0
  71. package/assets/docs/tree/tokens.doc.mjs +1 -1
  72. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +6 -4
  73. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +61 -55
  74. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +6 -4
  75. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +68 -37
  76. package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
  77. package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
  78. package/assets/templates/blocks/components/Thumbnail/ThumbnailDisabled.doc.mjs +1 -1
  79. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +13 -6
  80. package/assets/templates/pages/dashboard-alert-rail/page.tsx +3 -3
  81. package/assets/templates/pages/library/page.tsx +1 -2
  82. package/assets/templates/pages/table-comparison/page.tsx +12 -3
  83. package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +3 -2
  84. package/assets/templates/themes/butter/butterTheme.ts +47 -44
  85. package/assets/templates/themes/chocolate/chocolateTheme.ts +15 -2
  86. package/assets/templates/themes/gothic/gothicTheme.ts +21 -16
  87. package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +1 -1
  88. package/assets/templates/themes/matcha/matchaTheme.ts +15 -2
  89. package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +4 -4
  90. package/assets/templates/themes/neutral/neutralTheme.ts +24 -119
  91. package/assets/templates/themes/stone/stoneTheme.ts +46 -21
  92. package/assets/templates/themes/y2k/y2kTheme.ts +20 -16
  93. package/assets/theme.template.ts +19 -6
  94. package/authoring/codemod/type.ts +10 -0
  95. package/authoring/config/config.doc.mjs +1 -1
  96. package/clients/cli/commands/build-theme.adaptations.test.mjs +110 -0
  97. package/clients/cli/commands/build-theme.outside-project.test.mjs +140 -0
  98. package/clients/cli/commands/swizzle.routing.test.mjs +1 -1
  99. package/clients/cli/commands/upgrade.doc.mjs +47 -2
  100. package/clients/cli/commands/upgrade.file-protection.test.mjs +175 -0
  101. package/clients/cli/commands/upgrade.flag-help.test.mjs +37 -0
  102. package/clients/cli/commands/upgrade.integration-policy.test.mjs +103 -0
  103. package/clients/cli/commands/upgrade.mjs +9 -2
  104. package/clients/cli/commands/upgrade.outcomes.test.mjs +350 -0
  105. package/foundation/agent-docs/agent-docs.mjs +1 -0
  106. package/foundation/agent-docs/agent-docs.test.mjs +5 -0
  107. package/foundation/config/project.d.mts +1 -1
  108. package/foundation/config/project.mjs +1 -1
  109. package/foundation/debug/redact.test.mjs +1 -1
  110. package/foundation/doc-compiler/doc-loads.test.mjs +2 -6
  111. package/foundation/response/base.d.ts +7 -0
  112. package/foundation/response/error-codes.doc.mjs +3 -2
  113. package/foundation/response/error-codes.mjs +1 -1
  114. package/foundation/response/json.d.mts +10 -3
  115. package/foundation/response/json.mjs +16 -4
  116. package/foundation/response/response-types.doc.mjs +1 -1
  117. package/package.json +13 -12
@@ -0,0 +1,20 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file next transform manifest
5
+ *
6
+ * Staged codemods for the next release. The Version Packages PR promotes
7
+ * this file into the resolved version folder.
8
+ */
9
+
10
+ import migrateCodeBlockTokenizerToLanguage, {
11
+ meta as migrateCodeBlockTokenizerToLanguageMeta,
12
+ } from './migrate-codeblock-tokenizer-to-language.mjs';
13
+
14
+ export default [
15
+ {
16
+ name: 'migrate-codeblock-tokenizer-to-language',
17
+ transform: migrateCodeBlockTokenizerToLanguage,
18
+ meta: migrateCodeBlockTokenizerToLanguageMeta,
19
+ },
20
+ ];
@@ -0,0 +1,315 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Codemod: migrate CodeBlock tokenizer to a custom language value
5
+ *
6
+ * `tokenizer={fn}` beside a static `language="x"` other than `plaintext`
7
+ * becomes `language={createCodeLanguage({name: 'x', identifiers: ['x'],
8
+ * tokenize: fn})}` (`component:CodeBlock` FR13). The custom language paints
9
+ * with the same function, labels `x`, and reflects `data-language="x"`, so the
10
+ * block looks the same. `createCodeLanguage` is imported from
11
+ * `@astryxdesign/core/CodeBlock` when the file does not import it yet, under
12
+ * a free alias when the file already binds the name to something else. A
13
+ * `tokenizer` that is a name or a call-free property may be undefined at run
14
+ * time, so it is guarded: `fn ? createCodeLanguage({...}) : 'x'`.
15
+ *
16
+ * Built on the shared `transformProp` helper, so it does not follow
17
+ * variables, helpers, wrappers, or types. Where a CodeBlock writes
18
+ * `tokenizer` but the codemod cannot prove the result, it keeps the old prop
19
+ * and leaves a TODO instead of guessing: a computed or missing `language`, a
20
+ * `tokenizer` value that is neither a function literal nor a name or property
21
+ * (a name or property is guarded with `fn ? createCodeLanguage(...) : 'x'`,
22
+ * since it may be undefined), a
23
+ * `plaintext` language (which shows no label today, while a language value
24
+ * does), and any CodeBlock that also spreads props. The deprecated prop keeps
25
+ * working there. Comments are the codemod's only report channel, and each is
26
+ * added once, so a second run changes nothing.
27
+ */
28
+
29
+ import {transformProp} from '../../transform-prop.mjs';
30
+
31
+ export const meta = {
32
+ title: 'Migrate CodeBlock tokenizer to a custom language',
33
+ description:
34
+ 'Replaces `tokenizer={fn}` beside a static `language="x"` with ' +
35
+ "`language={createCodeLanguage({name: 'x', identifiers: ['x'], tokenize: fn})}`. " +
36
+ 'Keeps the old prop with a TODO where the language is computed, missing, ' +
37
+ 'or `plaintext`, and where the CodeBlock also spreads props; the ' +
38
+ 'deprecated prop still works there.',
39
+ };
40
+
41
+ const OLD_NAME = 'tokenizer';
42
+ const CORE_IMPORT_RE = /^@(astryxdesign|xds)\/core(?:\/|$)/;
43
+ const CODEBLOCK_SOURCE = '@astryxdesign/core/CodeBlock';
44
+ const COMPONENT_PROPS = new Map([['CodeBlock', new Set([OLD_NAME])]]);
45
+
46
+ const UNPROVEN_COMMENT =
47
+ ' TODO(astryx upgrade): tokenizer is deprecated. Pass ' +
48
+ 'language={createCodeLanguage({name, identifiers, tokenize})} instead, ' +
49
+ 'with this function as tokenize; the language here is computed, missing, ' +
50
+ 'or plaintext, so it was left unchanged. ';
51
+ const VALUE_COMMENT =
52
+ ' TODO(astryx upgrade): tokenizer is deprecated. Pass ' +
53
+ 'language={createCodeLanguage({name, identifiers, tokenize})} instead; ' +
54
+ 'this tokenizer value is computed (not a function, a name, or a ' +
55
+ 'call-free property), so it was left unchanged. ';
56
+ const SPREAD_COMMENT =
57
+ ' TODO(astryx upgrade): tokenizer is deprecated, but this CodeBlock also ' +
58
+ 'spreads props that may set language or tokenizer, so it was left ' +
59
+ 'unchanged. Pass language={createCodeLanguage({name, identifiers, ' +
60
+ 'tokenize})} by hand. ';
61
+
62
+ const TYPE_WRAPPERS = new Set([
63
+ 'TSAsExpression',
64
+ 'TSSatisfiesExpression',
65
+ 'TSTypeAssertion',
66
+ 'TSNonNullExpression',
67
+ 'TypeCastExpression',
68
+ 'ParenthesizedExpression',
69
+ ]);
70
+
71
+ /** @param {any} node */
72
+ function unwrap(node) {
73
+ let current = node;
74
+ while (current && TYPE_WRAPPERS.has(current.type)) {
75
+ current = current.expression;
76
+ }
77
+ return current;
78
+ }
79
+
80
+ /** @param {any} attribute */
81
+ function attributeValue(attribute) {
82
+ return attribute.value?.type === 'JSXExpressionContainer'
83
+ ? attribute.value.expression
84
+ : attribute.value;
85
+ }
86
+
87
+ /** The static string of a node, or null. @param {any} node */
88
+ function staticString(node) {
89
+ const value = unwrap(node);
90
+ if (
91
+ value != null &&
92
+ (value.type === 'StringLiteral' || value.type === 'Literal') &&
93
+ typeof value.value === 'string'
94
+ ) {
95
+ return value.value;
96
+ }
97
+ if (
98
+ value?.type === 'TemplateLiteral' &&
99
+ value.expressions.length === 0 &&
100
+ value.quasis.length === 1
101
+ ) {
102
+ return value.quasis[0].value.cooked;
103
+ }
104
+ return null;
105
+ }
106
+
107
+ /**
108
+ * A name, or a property chain on one with no call and no computed key other
109
+ * than a literal: safe to read twice, and narrowed by a `?:` guard.
110
+ * @param {any} node
111
+ * @returns {boolean}
112
+ */
113
+ function isCallFreeChain(node) {
114
+ const value = unwrap(node);
115
+ if (value == null) {
116
+ return false;
117
+ }
118
+ if (value.type === 'Identifier' || value.type === 'ThisExpression') {
119
+ return true;
120
+ }
121
+ if (value.type === 'MemberExpression') {
122
+ const key = value.property;
123
+ const literalKey =
124
+ !value.computed ||
125
+ key.type === 'StringLiteral' ||
126
+ key.type === 'NumericLiteral' ||
127
+ key.type === 'Literal';
128
+ return (
129
+ literalKey && value.optional !== true && isCallFreeChain(value.object)
130
+ );
131
+ }
132
+ return false;
133
+ }
134
+
135
+ /** @param {any} j @param {any} node @param {string} text */
136
+ function addComment(j, node, text) {
137
+ node.comments ??= [];
138
+ if (node.comments.some((/** @type {any} */ c) => c.value === text)) {
139
+ return false;
140
+ }
141
+ node.comments.push(j.commentBlock(text, true, false));
142
+ return true;
143
+ }
144
+
145
+ /**
146
+ * The local name `createCodeLanguage` is imported under, adding the import
147
+ * when the file has none.
148
+ * @param {any} j @param {any} root
149
+ */
150
+ function ensureCreateImport(j, root) {
151
+ let local = null;
152
+ root
153
+ .find(j.ImportDeclaration)
154
+ .filter((/** @type {any} */ p) => CORE_IMPORT_RE.test(p.node.source.value))
155
+ .forEach((/** @type {any} */ p) => {
156
+ for (const specifier of p.node.specifiers ?? []) {
157
+ if (
158
+ specifier.type === 'ImportSpecifier' &&
159
+ specifier.imported.name === 'createCodeLanguage'
160
+ ) {
161
+ local = specifier.local?.name ?? 'createCodeLanguage';
162
+ }
163
+ }
164
+ });
165
+ if (local != null) {
166
+ return local;
167
+ }
168
+ // Any other binding of the name (a local import or function) would clash,
169
+ // so the import takes the first free alias instead.
170
+ const name = freeName(j, root, 'createCodeLanguage');
171
+ const specifier =
172
+ name === 'createCodeLanguage'
173
+ ? j.importSpecifier(j.identifier('createCodeLanguage'))
174
+ : j.importSpecifier(
175
+ j.identifier('createCodeLanguage'),
176
+ j.identifier(name),
177
+ );
178
+ const existing = root.find(j.ImportDeclaration).filter(
179
+ (/** @type {any} */ p) =>
180
+ p.node.source.value === CODEBLOCK_SOURCE &&
181
+ p.node.importKind !== 'type' &&
182
+ // A namespace import cannot take a named specifier beside it.
183
+ !(p.node.specifiers ?? []).some(
184
+ (/** @type {any} */ s) => s.type === 'ImportNamespaceSpecifier',
185
+ ),
186
+ );
187
+ if (existing.size() > 0) {
188
+ existing.get().node.specifiers.push(specifier);
189
+ } else {
190
+ const declaration = j.importDeclaration(
191
+ [specifier],
192
+ j.stringLiteral(CODEBLOCK_SOURCE),
193
+ );
194
+ const imports = root.find(j.ImportDeclaration);
195
+ if (imports.size() > 0) {
196
+ imports.at(imports.size() - 1).insertAfter(declaration);
197
+ } else {
198
+ root.get().node.program.body.unshift(declaration);
199
+ }
200
+ }
201
+ return name;
202
+ }
203
+
204
+ /**
205
+ * `preferred`, or `preferred` with a numeric suffix, whichever no binding or
206
+ * reference in the file already uses.
207
+ * @param {any} j @param {any} root @param {string} preferred
208
+ */
209
+ function freeName(j, root, preferred) {
210
+ const used = new Set();
211
+ root.find(j.Identifier).forEach((/** @type {any} */ p) => {
212
+ used.add(p.node.name);
213
+ });
214
+ if (!used.has(preferred)) {
215
+ return preferred;
216
+ }
217
+ let n = 2;
218
+ while (used.has(`${preferred}${n}`)) {
219
+ n++;
220
+ }
221
+ return `${preferred}${n}`;
222
+ }
223
+
224
+ /**
225
+ * @param {import('../../../../authoring/codemod/type').AstryxCodemodFile} file
226
+ * @param {import('../../../../authoring/codemod/type').CodemodTransformApi} api
227
+ * @returns {string | null | undefined}
228
+ */
229
+ export default function transformer(file, api) {
230
+ const j = api.jscodeshift;
231
+ const root = j(file.source);
232
+ let hasChanges = false;
233
+ /** @type {Array<() => void>} */
234
+ const rewrites = [];
235
+
236
+ transformProp(
237
+ root,
238
+ j,
239
+ {
240
+ matchesImport: source => CORE_IMPORT_RE.test(source),
241
+ components: COMPONENT_PROPS,
242
+ },
243
+ propPath => {
244
+ const opening = propPath.parent?.node;
245
+ const attributes = opening?.attributes ?? [];
246
+ const prop = propPath.node;
247
+ if (
248
+ attributes.some(
249
+ (/** @type {any} */ a) => a.type === 'JSXSpreadAttribute',
250
+ )
251
+ ) {
252
+ hasChanges = addComment(j, prop, SPREAD_COMMENT) || hasChanges;
253
+ return;
254
+ }
255
+ const languageAttribute = attributes.find(
256
+ (/** @type {any} */ a) =>
257
+ a.type === 'JSXAttribute' && a.name?.name === 'language',
258
+ );
259
+ const language =
260
+ languageAttribute == null
261
+ ? null
262
+ : staticString(attributeValue(languageAttribute));
263
+ const tokenize = attributeValue(prop);
264
+ const tokenizeNode = unwrap(tokenize);
265
+ // A function literal is always a function. A name or property may be
266
+ // undefined at run time (a forwarded optional prop), so it is guarded:
267
+ // `fn ? createCodeLanguage({...}) : 'x'` keeps the plain block the
268
+ // released prop drew without one. Anything else is reported.
269
+ const isFunction =
270
+ tokenizeNode?.type === 'ArrowFunctionExpression' ||
271
+ tokenizeNode?.type === 'FunctionExpression';
272
+ const isGuardable = isCallFreeChain(tokenizeNode);
273
+ if (language == null || language === '' || language === 'plaintext') {
274
+ hasChanges = addComment(j, prop, UNPROVEN_COMMENT) || hasChanges;
275
+ return;
276
+ }
277
+ if (!(isFunction || isGuardable)) {
278
+ hasChanges = addComment(j, prop, VALUE_COMMENT) || hasChanges;
279
+ return;
280
+ }
281
+ rewrites.push(() => {
282
+ const create = ensureCreateImport(j, root);
283
+ const value = j.callExpression(j.identifier(create), [
284
+ j.objectExpression([
285
+ j.objectProperty(j.identifier('name'), j.stringLiteral(language)),
286
+ j.objectProperty(
287
+ j.identifier('identifiers'),
288
+ j.arrayExpression([j.stringLiteral(language)]),
289
+ ),
290
+ j.objectProperty(j.identifier('tokenize'), tokenize),
291
+ ]),
292
+ ]);
293
+ languageAttribute.value = j.jsxExpressionContainer(
294
+ isFunction
295
+ ? value
296
+ : j.conditionalExpression(
297
+ tokenize,
298
+ value,
299
+ j.stringLiteral(language),
300
+ ),
301
+ );
302
+ opening.attributes = opening.attributes.filter(
303
+ (/** @type {any} */ a) => a !== prop,
304
+ );
305
+ });
306
+ },
307
+ );
308
+
309
+ for (const rewrite of rewrites) {
310
+ rewrite();
311
+ hasChanges = true;
312
+ }
313
+ if (!hasChanges) return undefined;
314
+ return root.toSource({quote: 'single'});
315
+ }
@@ -32,22 +32,22 @@ A public authoring-quality rubric is also caller-facing when it helps someone ev
32
32
 
33
33
  ## Where the rest goes
34
34
 
35
- The material is usually good; the finding is placement, not quality. It goes in the [wiki](https://github.com/facebook/astryx/wiki) — **as a section on the page that already covers it, not a new page.** The wiki is at nearly 60 pages, several of them overlapping, because every stray section got its own.
35
+ The material is usually good; the finding is placement, not quality. It goes in the [wiki](https://github.com/meta/astryx/wiki) — **as a section on the page that already covers it, not a new page.** The wiki is at nearly 60 pages, several of them overlapping, because every stray section got its own.
36
36
 
37
37
  | what you wrote | where it goes |
38
38
  | --------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
39
- | how a component is graded — checks, scoring | [Component-Audit-Rubric](https://github.com/facebook/astryx/wiki/Component-Audit-Rubric) |
40
- | lab → core promotion, what a component must satisfy | [Component-Lifecycle](https://github.com/facebook/astryx/wiki/Component-Lifecycle) |
41
- | how to build a new component | [Component-Authoring-Guide](https://github.com/facebook/astryx/wiki/Component-Authoring-Guide), [Creating-New-Components](https://github.com/facebook/astryx/wiki/Creating-New-Components) |
42
- | what a component must be hardened against | [Component-Hardening-Protocol](https://github.com/facebook/astryx/wiki/Component-Hardening-Protocol), [Hardening-Audit-Guide](https://github.com/facebook/astryx/wiki/Hardening-Audit-Guide) |
43
- | a11y requirements as checks we run | [Accessibility-Checklist](https://github.com/facebook/astryx/wiki/Accessibility-Checklist) |
44
- | how the system is put together | [System-Architecture](https://github.com/facebook/astryx/wiki/System-Architecture), [Theming-Infrastructure](https://github.com/facebook/astryx/wiki/Theming-Infrastructure) |
45
- | API naming and shape decisions | [API-Conventions](https://github.com/facebook/astryx/wiki/API-Conventions), [API-Arbitration](https://github.com/facebook/astryx/wiki/API-Arbitration) |
46
- | contributor workflow, PR process | [Contributing](https://github.com/facebook/astryx/wiki/Contributing), [Contributing-with-AI-Assistants](https://github.com/facebook/astryx/wiki/Contributing-with-AI-Assistants) |
47
- | release mechanics | [Release-Process](https://github.com/facebook/astryx/wiki/Release-Process) |
48
- | what a nightly agent role does | the Night-Watch pages, from [Night-Watch-Overview](https://github.com/facebook/astryx/wiki/Night-Watch-Overview) |
49
-
50
- **Fits no row?** It is still not caller-facing. Default it to [Contributing](https://github.com/facebook/astryx/wiki/Contributing), or `CONTRIBUTING.md` when it is a step someone follows with the repo cloned. Never default it back to this directory.
39
+ | how a component is graded — checks, scoring | [Component-Audit-Rubric](https://github.com/meta/astryx/wiki/Component-Audit-Rubric) |
40
+ | lab → core promotion, what a component must satisfy | [Component-Lifecycle](https://github.com/meta/astryx/wiki/Component-Lifecycle) |
41
+ | how to build a new component | [Component-Authoring-Guide](https://github.com/meta/astryx/wiki/Component-Authoring-Guide), [Creating-New-Components](https://github.com/meta/astryx/wiki/Creating-New-Components) |
42
+ | what a component must be hardened against | [Component-Hardening-Protocol](https://github.com/meta/astryx/wiki/Component-Hardening-Protocol), [Hardening-Audit-Guide](https://github.com/meta/astryx/wiki/Hardening-Audit-Guide) |
43
+ | a11y requirements as checks we run | [Accessibility-Checklist](https://github.com/meta/astryx/wiki/Accessibility-Checklist) |
44
+ | how the system is put together | [System-Architecture](https://github.com/meta/astryx/wiki/System-Architecture), [Theming-Infrastructure](https://github.com/meta/astryx/wiki/Theming-Infrastructure) |
45
+ | API naming and shape decisions | [API-Conventions](https://github.com/meta/astryx/wiki/API-Conventions), [API-Arbitration](https://github.com/meta/astryx/wiki/API-Arbitration) |
46
+ | contributor workflow, PR process | [Contributing](https://github.com/meta/astryx/wiki/Contributing), [Contributing-with-AI-Assistants](https://github.com/meta/astryx/wiki/Contributing-with-AI-Assistants) |
47
+ | release mechanics | [Release-Process](https://github.com/meta/astryx/wiki/Release-Process) |
48
+ | what a nightly agent role does | the Night-Watch pages, from [Night-Watch-Overview](https://github.com/meta/astryx/wiki/Night-Watch-Overview) |
49
+
50
+ **Fits no row?** It is still not caller-facing. Default it to [Contributing](https://github.com/meta/astryx/wiki/Contributing), or `CONTRIBUTING.md` when it is a step someone follows with the repo cloned. Never default it back to this directory.
51
51
 
52
52
  Worked example: a responsive-and-interaction readiness rubric is grading criteria → **Component-Audit-Rubric**, or **Component-Lifecycle** if it is a promotion gate.
53
53
 
@@ -55,9 +55,11 @@ export const docs = {
55
55
  ['tokens', 'Base tokens are copied first, then child tokens override on top.'],
56
56
  ['components', 'Deep-merged: child component rules override matching keys from the base.'],
57
57
  ['icons', 'Shallow-merged: child icons override matching names from the base.'],
58
+ ['iconVariants', 'Replaced, never merged: a child that sets iconVariants replaces the base list; a child that omits it inherits the list.'],
58
59
  ['indicators', 'Shallow-merged: child indicators override matching names from the base.'],
59
60
  ['onDark, onLight', "Deep-merged per surface: the base's resolved surface first, then the child's overrides."],
60
- ['typography, motion, radius, color', 'Child config replaces base entirely (these are scale inputs, not additive).'],
61
+ ['motion', "Field by field: the child's `fast`, `medium` and `ratio` regenerate the fast and medium duration tokens; `slow` and `easing` left unset keep the base theme's tokens, so an inherited slow band stays at the base's ratio."],
62
+ ['typography, radius, color', 'Child config replaces base entirely (these are scale inputs, not additive).'],
61
63
  ['adaptations', 'Width-breakpoint overrides merge by fixed name. Inherited ordered rules keep their relative order; child rules append and re-resolve against the child root axes.'],
62
64
  ]},
63
65
  {type: 'prose', text: "Inheritance is resolved when the theme is defined, so an extended theme is flat: `{@command theme build}` emits one self-contained stylesheet holding everything the child inherited, and the base theme's CSS does not need to be loaded next to it. A base that is not a theme (most often an import that missed) throws when `defineTheme` runs, rather than producing a theme that silently inherits nothing."},
@@ -134,6 +136,8 @@ export const docs = {
134
136
  {type: 'prose', text: 'In the example above, the generated theme imports `./icons.mjs` from `dist`. If the second command is skipped, `theme build` can still succeed, but loading or bundling the generated module fails because `dist/icons.mjs` is missing. `--icons-specifier` changes the emitted import; it does not create or verify the target file. Match the specifier to a module that resolves from the generated JS file.'},
135
137
  {type: 'prose', text: 'Without `--icons-specifier`, the detected source import specifier is emitted unchanged. In the default flow without `--out`, a bundler can resolve an extensionless `./icons` to the neighboring `icons.tsx` source, but Node ESM does not perform that lookup and reports `ERR_MODULE_NOT_FOUND`. Moving the output with `--out` also changes where relative imports resolve from.'},
136
138
  {type: 'prose', text: 'Keep `react` and the icon library external so the registry does not bundle its own copies of those dependencies.'},
139
+ {type: 'prose', text: "A registry entry can be a function of `{size, variant}`. The built theme keeps the function, so `Icon` asks it for the size and variant it renders, as the runtime theme does, including for entries inherited from a built or package theme. The built theme's `icons` field and the registry its module re-exports are React nodes, with each function read at size `md`. A function written in the theme file itself cannot be carried, so the build fails; move it into the registry module."},
140
+ {type: 'prose', text: "A theme that lists `iconVariants` also writes an `IconVariantMap` augmentation into `<theme>.variants.d.ts`, so `Icon`'s `variant` accepts those names wherever the theme's types load. Its declaration carries the list too, so a theme that extends the built theme types `variant` in its icon entries by that list."},
137
141
  ],
138
142
  },
139
143
  {
@@ -193,22 +193,22 @@ const overrides = stylex.create({
193
193
  [
194
194
  'Next.js',
195
195
  'Next.js + theme CSS',
196
- '[apps/example-nextjs](https://github.com/facebook/astryx/tree/main/apps/example-nextjs)',
196
+ '[apps/example-nextjs](https://github.com/meta/astryx/tree/main/apps/example-nextjs)',
197
197
  ],
198
198
  [
199
199
  'Next.js + StyleX',
200
200
  'Next.js + StyleX for custom styles',
201
- '[apps/example-nextjs-stylex](https://github.com/facebook/astryx/tree/main/apps/example-nextjs-stylex)',
201
+ '[apps/example-nextjs-stylex](https://github.com/meta/astryx/tree/main/apps/example-nextjs-stylex)',
202
202
  ],
203
203
  [
204
204
  'Next.js + Tailwind',
205
205
  'Next.js + Tailwind bridge',
206
- '[apps/example-nextjs-tailwind](https://github.com/facebook/astryx/tree/main/apps/example-nextjs-tailwind)',
206
+ '[apps/example-nextjs-tailwind](https://github.com/meta/astryx/tree/main/apps/example-nextjs-tailwind)',
207
207
  ],
208
208
  [
209
209
  'Vite + Tailwind',
210
210
  'Vite + Tailwind bridge',
211
- '[apps/example-vite-tailwind](https://github.com/facebook/astryx/tree/main/apps/example-vite-tailwind)',
211
+ '[apps/example-vite-tailwind](https://github.com/meta/astryx/tree/main/apps/example-vite-tailwind)',
212
212
  ],
213
213
  ],
214
214
  },
@@ -216,7 +216,7 @@ const overrides = stylex.create({
216
216
  type: 'code',
217
217
  lang: 'bash',
218
218
  label: 'Clone and run an example',
219
- code: `git clone https://github.com/facebook/astryx.git
219
+ code: `git clone https://github.com/meta/astryx.git
220
220
  cd astryx/apps/example-nextjs
221
221
  {@pm install}
222
222
  {@pm run dev}`,
@@ -101,11 +101,92 @@ export const brandTheme = defineTheme({
101
101
  },
102
102
  });`,
103
103
  },
104
+ {
105
+ type: 'prose',
106
+ text: "An entry can also be a function of the request, so the theme maps Icon's size to its icon library's own props or artwork. `Icon` calls it with `{size, variant}`, where `size` is the size it renders at (`xsm`, `sm`, `md`, or `lg`: an explicit `size`, else the owning component's default, else `md`). Reads that return one node — `getIcon()`, `useIcon()`, `getIconRegistry()`, and the theme's `icons` field — call it with `{size: 'md'}`. The same entry shape works in `registerIcons()`.",
107
+ },
108
+ {
109
+ type: 'code',
110
+ lang: 'tsx',
111
+ label: 'A size-aware icon entry',
112
+ code: `import {defineTheme} from '@astryxdesign/core/theme';
113
+ import {Info} from 'lucide-react';
114
+
115
+ export const brandTheme = defineTheme({
116
+ name: 'brand',
117
+ icons: {
118
+ // A heavier stroke keeps the small size legible.
119
+ info: ({size}) => <Info strokeWidth={size === 'sm' || size === 'xsm' ? 2.5 : 2} />,
120
+ },
121
+ });`,
122
+ },
123
+ {
124
+ type: 'prose',
125
+ text: 'Keep the function pure and synchronous: it computes its result from the request only, with no hooks, DOM or SVG measurement, browser globals, network access, mutable module state, or side effects. Its result is final. Returning `null` draws no glyph instead of falling back to a registered or built-in icon, while a `null` or `undefined` node entry still falls back. A child theme that sets an entry for a key replaces the inherited entry for that key.',
126
+ },
104
127
  ],
105
128
  },
106
129
  {
107
- title: 'Component and Library Icons',
130
+ title: 'Icon Variants',
108
131
  category: 'foundations',
132
+ content: [
133
+ {
134
+ type: 'prose',
135
+ text: "A theme lists the icon variant names it supports once, with `iconVariants` in `defineTheme()`. The list belongs to the whole theme, never to one icon, and Astryx defines no names of its own. Inside `defineTheme`, an entry function receives `variant` typed as the listed names, or `undefined`, so a misspelled name is a type error. An entry that receives `undefined` draws its normal artwork.",
136
+ },
137
+ {
138
+ type: 'code',
139
+ lang: 'tsx',
140
+ label: 'Listing variants and mapping them to artwork',
141
+ code: `import {defineTheme} from '@astryxdesign/core/theme';
142
+ import {InfoFilledIcon, InfoIcon} from './brand-icons';
143
+
144
+ export const brandTheme = defineTheme({
145
+ name: 'brand',
146
+ iconVariants: ['outline', 'filled'],
147
+ icons: {
148
+ info: ({size, variant}) =>
149
+ variant === 'filled' ? <InfoFilledIcon /> : <InfoIcon bold={size === 'sm'} />,
150
+ },
151
+ });
152
+
153
+ brandTheme.iconVariants; // ['outline', 'filled']`,
154
+ },
155
+ {
156
+ type: 'prose',
157
+ text: 'A theme that `extends` another inherits its list unless it sets its own; a list it sets replaces the inherited one instead of merging with it.',
158
+ },
159
+ {
160
+ type: 'prose',
161
+ text: "Request a variant with `Icon`'s `variant` prop. The entry receives it only when the active theme lists it; an entry the theme inherited also needs the theme that defined it to list it. Otherwise the entry receives `undefined` and draws its normal artwork, so an unlisted variant never breaks rendering. A `registerIcons()` entry receives the variants the active theme lists, and a node entry draws the same node for every variant. An icon component passed directly to `Icon` never receives `variant`, and `variant` is never written to the DOM: it selects artwork, so there is no theming selector for it.",
162
+ },
163
+ {
164
+ type: 'code',
165
+ lang: 'tsx',
166
+ label: 'Requesting a variant',
167
+ code: `<Icon icon="info" variant="filled" /> // brandTheme: the filled artwork
168
+ <Icon icon="info" /> // the normal artwork`,
169
+ },
170
+ {
171
+ type: 'prose',
172
+ text: 'An application declares the variant names it uses by augmenting `IconVariantMap` from `@astryxdesign/core/Icon`. `IconVariant` is those names, and an entry passed to `registerIcons()` receives `variant` typed as `IconVariant`. `astryx theme build` writes this augmentation for a built theme\'s list.',
173
+ },
174
+ {
175
+ type: 'code',
176
+ lang: 'ts',
177
+ label: 'Declaring the variant names an application uses',
178
+ code: `declare module '@astryxdesign/core/Icon' {
179
+ interface IconVariantMap {
180
+ outline: true;
181
+ filled: true;
182
+ }
183
+ }`,
184
+ },
185
+ ],
186
+ },
187
+ {
188
+ title: 'Component and Library Icons',
189
+ category: 'foundations',
109
190
  content: [
110
191
  {
111
192
  type: 'prose',
@@ -50,7 +50,7 @@ export const docs = {
50
50
  content: [
51
51
  {
52
52
  type: 'prose',
53
- text: 'One easing curve, `--ease-standard`.',
53
+ text: 'Two easing curves. `--ease-standard` decelerates, for things arriving and state changes. `--ease-exit` accelerates, for things leaving: it moves off from rest and leaves fast, so the travel stays visible for the whole duration.',
54
54
  },
55
55
  {
56
56
  type: 'token-ref',
@@ -21,6 +21,14 @@ export const docsDense = {
21
21
  {type: 'prose', text: "new palette: `astryx theme palette generate palette.config.json --out palette.generated.ts` → review + commit module and receipt → `import {palette} from './palette.generated';` → map semantic tokens to stable stops such as `palette.neutral.light[100]` / `palette.neutral.dark[15]`. regeneration updates mapped roles; generation does not rewrite the theme."},
22
22
  ],
23
23
  },
24
+ {
25
+ section: 'Icon sizes',
26
+ title: 'Icon sizes',
27
+ content: [
28
+ {type: 'prose', text: "theme sets each Icon size's glyph dimension: `width` + `height` on `components.icon['size:sm']` (or xsm/md/lg); semantic names + SVG components alike. px or rem only: a semantic icon takes its font size from the dimension, so em also grows its box. unstyled: xsm/sm/md/lg = 12/16/20/24px at 16px root, scale w/ root font size (rem keeps it). size names are fixed."},
29
+ null,
30
+ ],
31
+ },
24
32
  {
25
33
  section: 'Dark mode',
26
34
  title: 'Dark mode',
@@ -53,6 +53,22 @@ export const docs = {
53
53
  },
54
54
  ],
55
55
  },
56
+ {
57
+ id: 'icon-sizes',
58
+ title: 'Icon sizes',
59
+ content: [
60
+ {
61
+ type: 'prose',
62
+ text: "A theme sets the dimension of each Icon size in its stylesheet: `width` and `height` on `components.icon['size:sm']` (or `xsm`, `md`, `lg`) resize that size's glyph, for semantic icon names and SVG components passed to `Icon` alike. Give the dimension in `px` or `rem`: a semantic icon takes its font size from it, so an `em` value would also grow its box. A size the theme leaves alone stays 12, 16, 20, or 24px at a 16px root (`xsm`, `sm`, `md`, `lg`) and scales with the root font size; `rem` keeps that scaling. The four size names are fixed.",
63
+ },
64
+ {
65
+ type: 'code',
66
+ lang: 'tsx',
67
+ label: 'Set Icon size dimensions',
68
+ code: "const brandTheme = defineTheme({\n name: 'brand',\n components: {\n icon: {\n 'size:sm': {width: '1.125rem', height: '1.125rem'},\n 'size:lg': {width: '1.75rem', height: '1.75rem'},\n },\n },\n});",
69
+ },
70
+ ],
71
+ },
56
72
  {
57
73
  id: 'light-dark-mode',
58
74
  title: 'Dark mode',
@@ -25,6 +25,17 @@ export const docsZh = {
25
25
  },
26
26
  ],
27
27
  },
28
+ {
29
+ section: 'Icon sizes',
30
+ title: '图标尺寸',
31
+ content: [
32
+ {
33
+ type: 'prose',
34
+ text: "主题在样式表中设置每个 Icon 尺寸的大小:在 `components.icon['size:sm']`(或 `xsm`、`md`、`lg`)上设置 `width` 和 `height`,即可调整该尺寸的图标,语义图标名称和直接传给 `Icon` 的 SVG 组件都适用。请使用 `px` 或 `rem` 设置尺寸:语义图标会据此设置自身的字号,因此 `em` 值也会放大它的外框。主题未设置的尺寸在 16px 根字号下保持 12、16、20 或 24px(`xsm`、`sm`、`md`、`lg`),并随根字号缩放;`rem` 可保留这种缩放。四个尺寸名称是固定的。",
35
+ },
36
+ null,
37
+ ],
38
+ },
28
39
  {
29
40
  section: 'Dark mode',
30
41
  title: '深色模式',
@@ -111,7 +111,7 @@ export default function App() {
111
111
  },
112
112
  {
113
113
  type: 'prose',
114
- text: "Single-catalog usage (where an external i18n runtime like react-intl or i18next resolves both your app strings AND astryx's strings through one provider) is on the roadmap via a `Translator` adapter. Track [facebook/astryx#4029](https://github.com/facebook/astryx/issues/4029). For now, run the two providers side by side as shown above.",
114
+ text: "Single-catalog usage (where an external i18n runtime like react-intl or i18next resolves both your app strings AND astryx's strings through one provider) is on the roadmap via a `Translator` adapter. Track [meta/astryx#4029](https://github.com/meta/astryx/issues/4029). For now, run the two providers side by side as shown above.",
115
115
  },
116
116
  ],
117
117
  },
@@ -142,7 +142,7 @@ const overrides = stylex.create({
142
142
  },
143
143
  {
144
144
  type: 'prose',
145
- text: 'The upgrade treats a `components` map as a theme when it belongs to a `defineTheme()` call imported from Astryx, an object typed as an Astryx theme, or a theme object with a static `name` whose component entries are style objects. It leaves computed theme keys, unqualified classes, unknown consumer classes, declarations, comments, and CSS inside JavaScript or TypeScript strings unchanged. It adds `TODO(astryx upgrade)` when a map has both an old and a canonical key, and when a bare class Astryx once emitted has no known meaning on the target it qualifies. Review each TODO by hand.',
145
+ text: 'The upgrade treats a `components` map as a theme when it belongs to a `defineTheme()` call imported from Astryx, an object typed as an Astryx theme, or the theme object a same-stem theme descriptor (`<stem>.doc.mjs`) declares: the top-level binding exported as `<stem>`, with a static `name` and component entries that are style objects. A look-alike object anywhere else, such as a theme object from another library in the same file, is not an Astryx theme. It leaves computed theme keys, unqualified classes, unknown consumer classes, declarations, comments, and CSS inside JavaScript or TypeScript strings unchanged. It adds `TODO(astryx upgrade)` when a map has both an old and a canonical key, and when a bare class Astryx once emitted has no known meaning on the target it qualifies. Review each TODO by hand.',
146
146
  },
147
147
  ],
148
148
  },
@@ -56,7 +56,7 @@ import {colorVars} from '@astryxdesign/core/theme/tokens.stylex';
56
56
 
57
57
  const styles = stylex.create({
58
58
  trend: {
59
- color: colorVars['--color-success'],
59
+ color: colorVars['--color-text-success'],
60
60
  minWidth: 0,
61
61
  },
62
62
  });