@astryxdesign/cli 0.6.1 → 0.6.2-canary.2b2113d
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.
- package/CHANGELOG.md +35 -1
- package/README.md +1 -1
- package/api/component/_adapter.mjs +64 -23
- package/api/component/component.doc.mjs +1 -1
- package/api/component/component.type.d.mts +8 -2
- package/api/component/component.type.mjs +5 -2
- package/api/component/integration-import-agreement.test.mjs +162 -6
- package/api/component/list/list.mjs +91 -15
- package/api/doctor/doctor.mjs +5 -16
- package/api/init/init.doc.mjs +2 -2
- package/api/init/init.type.d.mts +1 -1
- package/api/init/init.type.mjs +1 -1
- package/api/init/run/run.mjs +1 -1
- package/api/integration/add-helpers.mjs +2 -1
- package/api/integration/pack-check.mjs +9 -3
- package/api/search/search.d.mts +1 -1
- package/api/search/search.mjs +135 -41
- package/api/theme/build/build.d.mts +45 -17
- package/api/theme/build/build.family.test.mjs +435 -0
- package/api/theme/build/build.mjs +681 -121
- package/api/theme/build/build.packed-old-core.test.mjs +25 -9
- package/api/theme/build/build.test.mjs +142 -0
- package/api/theme/build/core-interception.d.mts +14 -2
- package/api/theme/build/core-interception.mjs +38 -14
- package/api/theme/build/family.d.mts +15 -0
- package/api/theme/build/family.mjs +442 -0
- package/api/theme/palette/generate/generate.mjs +2 -1
- package/assets/docs/theme.doc.dense.mjs +12 -0
- package/assets/docs/theme.doc.mjs +37 -0
- package/assets/docs/working-with-ai.doc.mjs +2 -1
- package/clients/cli/commands/build-theme.mjs +63 -5
- package/clients/cli/commands/component/index.mjs +4 -1
- package/clients/cli/commands/init.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +28 -10
- package/foundation/agent-docs/agent-doc-state.mjs +1 -1
- package/foundation/agent-docs/agent-docs.d.mts +2 -2
- package/foundation/agent-docs/agent-docs.mjs +8 -6
- package/foundation/agent-docs/agent-docs.test.mjs +14 -0
- package/foundation/discovery/__fixtures__/component-both-exports.doc.d.mts +24 -0
- package/foundation/discovery/__fixtures__/component-both-exports.doc.mjs +19 -0
- package/foundation/discovery/__fixtures__/component-default-export.doc.d.mts +14 -0
- package/foundation/discovery/__fixtures__/component-default-export.doc.mjs +13 -0
- package/foundation/discovery/__fixtures__/component-named-export.doc.d.mts +13 -0
- package/foundation/discovery/__fixtures__/component-named-export.doc.mjs +11 -0
- package/foundation/discovery/component-discovery.d.mts +5 -3
- package/foundation/discovery/component-discovery.mjs +25 -9
- package/foundation/discovery/component-loader.mjs +4 -1
- package/foundation/discovery/component-loader.test.mjs +48 -0
- package/foundation/discovery/theming-targets.test.mjs +29 -0
- package/foundation/fs/paths.d.mts +19 -0
- package/foundation/fs/paths.mjs +54 -0
- package/foundation/fs/paths.test.mjs +102 -1
- package/foundation/fs/publish-file-eperm-mutation.test.mjs +62 -0
- package/foundation/fs/publish-file-hardlink-unavailable.test.mjs +107 -0
- package/foundation/fs/publish-file.d.mts +22 -0
- package/foundation/fs/publish-file.mjs +68 -0
- package/foundation/fs/publish-file.test.mjs +136 -0
- package/foundation/integrations/manifest-writer.mjs +2 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +15 -10
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
/**
|
|
3
|
+
* @file Thin family packaging over existing compiler output.
|
|
4
|
+
*/
|
|
5
|
+
const THEME_SCOPE_TO = '[data-astryx-theme]';
|
|
6
|
+
/** @param {string} a @param {string} b */
|
|
7
|
+
const compareText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
8
|
+
/**
|
|
9
|
+
* @param {Array<{theme: any, sourceTheme: any, sourceParent: any, filePath: string}>} members
|
|
10
|
+
* @returns {any[]}
|
|
11
|
+
*/
|
|
12
|
+
export function resolveThemeFamily(members) {
|
|
13
|
+
if (members.length < 2)
|
|
14
|
+
throw new Error(
|
|
15
|
+
'A theme family requires at least two selected theme files.',
|
|
16
|
+
);
|
|
17
|
+
const byName = new Map();
|
|
18
|
+
const sources = new Set();
|
|
19
|
+
for (const member of members) {
|
|
20
|
+
if (sources.has(member.filePath)) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`Duplicate family source: ${member.filePath}. Select each theme file once.`,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
if (byName.has(member.theme.name)) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`Duplicate theme identity "${member.theme.name}" in the selected family.`,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
sources.add(member.filePath);
|
|
31
|
+
byName.set(member.theme.name, member);
|
|
32
|
+
}
|
|
33
|
+
const withParents = members.map(member => {
|
|
34
|
+
const parent = member.sourceParent;
|
|
35
|
+
if (
|
|
36
|
+
parent !== undefined &&
|
|
37
|
+
(!parent ||
|
|
38
|
+
typeof parent !== 'object' ||
|
|
39
|
+
typeof parent.name !== 'string' ||
|
|
40
|
+
parent.name.length === 0)
|
|
41
|
+
) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Theme "${member.theme.name}" has an invalid normalized parent.`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
const parentName = parent?.name ?? null;
|
|
47
|
+
if (parentName && !byName.has(parentName)) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`Theme "${member.theme.name}" is missing selected ancestor "${parentName}".`,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
if (parentName && parent !== byName.get(parentName).sourceTheme) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`Theme "${member.theme.name}" does not extend the selected "${parentName}" source.`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return {...member, parentName};
|
|
58
|
+
});
|
|
59
|
+
const resolved = new Map(
|
|
60
|
+
withParents.map(member => [member.theme.name, member]),
|
|
61
|
+
);
|
|
62
|
+
const marks = new Map();
|
|
63
|
+
/** @param {any} member */
|
|
64
|
+
const visit = member => {
|
|
65
|
+
const mark = marks.get(member.theme.name) ?? 0;
|
|
66
|
+
if (mark === 1)
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Cycle detected in selected theme family at "${member.theme.name}".`,
|
|
69
|
+
);
|
|
70
|
+
if (mark === 2) return;
|
|
71
|
+
marks.set(member.theme.name, 1);
|
|
72
|
+
if (member.parentName) visit(resolved.get(member.parentName));
|
|
73
|
+
marks.set(member.theme.name, 2);
|
|
74
|
+
};
|
|
75
|
+
for (const member of withParents) visit(member);
|
|
76
|
+
const roots = withParents.filter(member => member.parentName === null);
|
|
77
|
+
if (roots.length !== 1) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
`A theme family must have exactly one selected root; found ${roots.length}.`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
const emitted = new Set();
|
|
83
|
+
/** @type {any[]} */
|
|
84
|
+
const ordered = [];
|
|
85
|
+
while (ordered.length < withParents.length) {
|
|
86
|
+
const eligible = withParents
|
|
87
|
+
.filter(
|
|
88
|
+
member =>
|
|
89
|
+
!emitted.has(member.theme.name) &&
|
|
90
|
+
(!member.parentName || emitted.has(member.parentName)),
|
|
91
|
+
)
|
|
92
|
+
.sort((a, b) =>
|
|
93
|
+
compareText(
|
|
94
|
+
`${a.theme.name}\0${a.filePath}`,
|
|
95
|
+
`${b.theme.name}\0${b.filePath}`,
|
|
96
|
+
),
|
|
97
|
+
);
|
|
98
|
+
if (eligible.length === 0)
|
|
99
|
+
throw new Error('Cycle detected in selected theme family.');
|
|
100
|
+
emitted.add(eligible[0].theme.name);
|
|
101
|
+
ordered.push(eligible[0]);
|
|
102
|
+
}
|
|
103
|
+
return ordered;
|
|
104
|
+
}
|
|
105
|
+
/** @param {string} name */
|
|
106
|
+
const themeSelector = name => `[data-astryx-theme=${JSON.stringify(name)}]`;
|
|
107
|
+
/** @param {string[]} names */
|
|
108
|
+
const familyScopeSelector = names =>
|
|
109
|
+
`:where(${names.map(themeSelector).join(', ')})`;
|
|
110
|
+
/** @param {string} rule @returns {{open: number, close: number}} */
|
|
111
|
+
function ruleBounds(rule) {
|
|
112
|
+
let open = -1;
|
|
113
|
+
let depth = 0;
|
|
114
|
+
let paren = 0;
|
|
115
|
+
let urlDepth = 0;
|
|
116
|
+
let quote = '';
|
|
117
|
+
let escaped = false;
|
|
118
|
+
let comment = false;
|
|
119
|
+
for (let index = 0; index < rule.length; index++) {
|
|
120
|
+
const char = rule[index];
|
|
121
|
+
if (comment) {
|
|
122
|
+
if (char === '*' && rule[index + 1] === '/') {
|
|
123
|
+
comment = false;
|
|
124
|
+
index++;
|
|
125
|
+
}
|
|
126
|
+
} else if (escaped) {
|
|
127
|
+
escaped = false;
|
|
128
|
+
} else if (char === '\\') {
|
|
129
|
+
escaped = true;
|
|
130
|
+
} else if (quote) {
|
|
131
|
+
if (char === quote) quote = '';
|
|
132
|
+
} else if (char === '"' || char === "'") {
|
|
133
|
+
quote = char;
|
|
134
|
+
} else if (urlDepth === 0 && char === '/' && rule[index + 1] === '*') {
|
|
135
|
+
comment = true;
|
|
136
|
+
index++;
|
|
137
|
+
} else if (char === '(') {
|
|
138
|
+
paren++;
|
|
139
|
+
if (rule.slice(Math.max(0, index - 3), index).toLowerCase() === 'url') {
|
|
140
|
+
urlDepth = paren;
|
|
141
|
+
}
|
|
142
|
+
} else if (char === ')' && paren > 0) {
|
|
143
|
+
if (urlDepth === paren) urlDepth = 0;
|
|
144
|
+
paren--;
|
|
145
|
+
} else if (char === '{' && paren === 0) {
|
|
146
|
+
if (open === -1) open = index;
|
|
147
|
+
depth++;
|
|
148
|
+
} else if (char === '}' && paren === 0 && open !== -1 && --depth === 0) {
|
|
149
|
+
return {open, close: index};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
throw new Error('Theme compiler emitted a malformed rule.');
|
|
153
|
+
}
|
|
154
|
+
/** @param {string} rule */
|
|
155
|
+
function declarationEntries(rule) {
|
|
156
|
+
const {open, close} = ruleBounds(rule);
|
|
157
|
+
const selector = rule.slice(0, open).trim();
|
|
158
|
+
const body = rule.slice(open + 1, close);
|
|
159
|
+
/** @type {string[]} */
|
|
160
|
+
const declarations = [];
|
|
161
|
+
let start = 0;
|
|
162
|
+
let quote = '';
|
|
163
|
+
let escaped = false;
|
|
164
|
+
let comment = false;
|
|
165
|
+
let paren = 0;
|
|
166
|
+
let urlDepth = 0;
|
|
167
|
+
let braces = 0;
|
|
168
|
+
let brackets = 0;
|
|
169
|
+
for (let index = 0; index < body.length; index++) {
|
|
170
|
+
const char = body[index];
|
|
171
|
+
if (comment) {
|
|
172
|
+
if (char === '*' && body[index + 1] === '/') {
|
|
173
|
+
comment = false;
|
|
174
|
+
index++;
|
|
175
|
+
}
|
|
176
|
+
} else if (escaped) {
|
|
177
|
+
escaped = false;
|
|
178
|
+
} else if (char === '\\') {
|
|
179
|
+
escaped = true;
|
|
180
|
+
} else if (quote) {
|
|
181
|
+
if (char === quote) quote = '';
|
|
182
|
+
} else if (char === '"' || char === "'") {
|
|
183
|
+
quote = char;
|
|
184
|
+
} else if (urlDepth === 0 && char === '/' && body[index + 1] === '*') {
|
|
185
|
+
comment = true;
|
|
186
|
+
index++;
|
|
187
|
+
} else if (char === '(') {
|
|
188
|
+
paren++;
|
|
189
|
+
if (body.slice(Math.max(0, index - 3), index).toLowerCase() === 'url') {
|
|
190
|
+
urlDepth = paren;
|
|
191
|
+
}
|
|
192
|
+
} else if (char === ')' && paren > 0) {
|
|
193
|
+
if (urlDepth === paren) urlDepth = 0;
|
|
194
|
+
paren--;
|
|
195
|
+
} else if (char === '[' && urlDepth === 0) {
|
|
196
|
+
brackets++;
|
|
197
|
+
} else if (char === ']' && urlDepth === 0 && brackets > 0) {
|
|
198
|
+
brackets--;
|
|
199
|
+
} else if (char === '{' && paren === 0) {
|
|
200
|
+
braces++;
|
|
201
|
+
} else if (char === '}' && paren === 0 && braces > 0) {
|
|
202
|
+
braces--;
|
|
203
|
+
} else if (char === ';' && paren === 0 && braces === 0 && brackets === 0) {
|
|
204
|
+
const declaration = body.slice(start, index + 1).trim();
|
|
205
|
+
if (declaration) declarations.push(declaration);
|
|
206
|
+
start = index + 1;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (body.slice(start).trim())
|
|
210
|
+
throw new Error('Theme compiler emitted an unterminated declaration.');
|
|
211
|
+
const counts = new Map();
|
|
212
|
+
return declarations
|
|
213
|
+
.map(declaration => {
|
|
214
|
+
const property = declaration.slice(0, declaration.indexOf(':')).trim();
|
|
215
|
+
const occurrence = counts.get(property) ?? 0;
|
|
216
|
+
counts.set(property, occurrence + 1);
|
|
217
|
+
return {key: `${property}\0${occurrence}`, declaration};
|
|
218
|
+
})
|
|
219
|
+
.map(entry => ({...entry, selector}));
|
|
220
|
+
}
|
|
221
|
+
/** @param {string[]} rules */
|
|
222
|
+
function ruleEntries(rules) {
|
|
223
|
+
const counts = new Map();
|
|
224
|
+
return rules.map(rule => {
|
|
225
|
+
const {open} = ruleBounds(rule);
|
|
226
|
+
const selector = rule.slice(0, open).trim();
|
|
227
|
+
const occurrence = counts.get(selector) ?? 0;
|
|
228
|
+
counts.set(selector, occurrence + 1);
|
|
229
|
+
return {key: `${selector}\0${occurrence}`, rule, selector};
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/** @param {Array<Array<{key: string}>>} sequences @param {string} _description @returns {string[] | null} */
|
|
233
|
+
function orderedKeys(sequences, _description) {
|
|
234
|
+
const rank = new Map();
|
|
235
|
+
const edges = new Map();
|
|
236
|
+
const indegree = new Map();
|
|
237
|
+
let nextRank = 0;
|
|
238
|
+
for (const sequence of sequences) {
|
|
239
|
+
for (const entry of sequence) {
|
|
240
|
+
if (!rank.has(entry.key)) rank.set(entry.key, nextRank++);
|
|
241
|
+
edges.set(entry.key, edges.get(entry.key) ?? new Set());
|
|
242
|
+
indegree.set(entry.key, indegree.get(entry.key) ?? 0);
|
|
243
|
+
}
|
|
244
|
+
for (let index = 1; index < sequence.length; index++) {
|
|
245
|
+
const before = sequence[index - 1].key;
|
|
246
|
+
const after = sequence[index].key;
|
|
247
|
+
if (!edges.get(before).has(after)) {
|
|
248
|
+
edges.get(before).add(after);
|
|
249
|
+
indegree.set(after, indegree.get(after) + 1);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const ready = [...rank.keys()].filter(key => indegree.get(key) === 0);
|
|
254
|
+
/** @type {string[]} */
|
|
255
|
+
const ordered = [];
|
|
256
|
+
while (ready.length > 0) {
|
|
257
|
+
ready.sort((a, b) => rank.get(a) - rank.get(b) || compareText(a, b));
|
|
258
|
+
const key = ready.shift();
|
|
259
|
+
ordered.push(key);
|
|
260
|
+
for (const after of edges.get(key)) {
|
|
261
|
+
indegree.set(after, indegree.get(after) - 1);
|
|
262
|
+
if (indegree.get(after) === 0) ready.push(after);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (ordered.length !== rank.size) return null;
|
|
266
|
+
return ordered;
|
|
267
|
+
}
|
|
268
|
+
/** @param {Array<{names: string[], selector: string, declaration: string}>} items */
|
|
269
|
+
function renderDeclarations(items) {
|
|
270
|
+
/** @type {Array<{scope: string, names: string[], selector: string, declarations: string[]}>} */
|
|
271
|
+
const blocks = [];
|
|
272
|
+
/** @type {{scope: string, names: string[], selector: string, declarations: string[]} | undefined} */
|
|
273
|
+
let current;
|
|
274
|
+
for (const item of items) {
|
|
275
|
+
const scope = `${item.names.join('\0')}\0${item.selector}`;
|
|
276
|
+
if (!current || current.scope !== scope) {
|
|
277
|
+
current = {
|
|
278
|
+
scope,
|
|
279
|
+
names: item.names,
|
|
280
|
+
selector: item.selector,
|
|
281
|
+
declarations: [],
|
|
282
|
+
};
|
|
283
|
+
blocks.push(current);
|
|
284
|
+
}
|
|
285
|
+
current.declarations.push(item.declaration);
|
|
286
|
+
}
|
|
287
|
+
return blocks.map(block => {
|
|
288
|
+
const declarations = block.declarations
|
|
289
|
+
.map(value => ` ${value}`)
|
|
290
|
+
.join('\n');
|
|
291
|
+
return `@scope (${familyScopeSelector(block.names)}) to (${THEME_SCOPE_TO}) {\n ${block.selector} {\n${declarations}\n }\n}`;
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
/** @param {any[]} members @param {string} field */
|
|
295
|
+
function completeMemberRules(members, field) {
|
|
296
|
+
return members
|
|
297
|
+
.filter(member => member.css[field].length > 0)
|
|
298
|
+
.map(
|
|
299
|
+
member =>
|
|
300
|
+
`@scope (${familyScopeSelector([member.theme.name])}) to (${THEME_SCOPE_TO}) {\n${member.css[field].join('\n\n')}\n}`,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
/** @param {any[]} members @param {string} field */
|
|
304
|
+
function factorRules(members, field) {
|
|
305
|
+
const ruleSequences = members.map(member => ruleEntries(member.css[field]));
|
|
306
|
+
const ruleMaps = ruleSequences.map(
|
|
307
|
+
sequence => new Map(sequence.map(entry => [entry.key, entry])),
|
|
308
|
+
);
|
|
309
|
+
/** @type {Array<{names: string[], selector: string, declaration: string}>} */
|
|
310
|
+
const items = [];
|
|
311
|
+
const ruleOrder = orderedKeys(ruleSequences, 'rule');
|
|
312
|
+
if (!ruleOrder) return completeMemberRules(members, field);
|
|
313
|
+
for (const ruleKey of ruleOrder) {
|
|
314
|
+
const declarations = ruleMaps.map(map => {
|
|
315
|
+
const rule = map.get(ruleKey);
|
|
316
|
+
return rule ? declarationEntries(rule.rule) : [];
|
|
317
|
+
});
|
|
318
|
+
const declarationMaps = declarations.map(
|
|
319
|
+
sequence => new Map(sequence.map(entry => [entry.key, entry])),
|
|
320
|
+
);
|
|
321
|
+
const declarationOrder = orderedKeys(declarations, 'declaration');
|
|
322
|
+
if (!declarationOrder) return completeMemberRules(members, field);
|
|
323
|
+
for (const declarationKey of declarationOrder) {
|
|
324
|
+
/** @type {Map<string, {selector: string, declaration: string, names: string[]}>} */
|
|
325
|
+
const groups = new Map();
|
|
326
|
+
for (let index = 0; index < members.length; index++) {
|
|
327
|
+
const entry = declarationMaps[index].get(declarationKey);
|
|
328
|
+
if (!entry) continue;
|
|
329
|
+
const group = groups.get(entry.declaration) ?? {
|
|
330
|
+
selector: entry.selector,
|
|
331
|
+
declaration: entry.declaration,
|
|
332
|
+
names: [],
|
|
333
|
+
};
|
|
334
|
+
group.names.push(members[index].theme.name);
|
|
335
|
+
groups.set(entry.declaration, group);
|
|
336
|
+
}
|
|
337
|
+
items.push(...groups.values());
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return renderDeclarations(items);
|
|
341
|
+
}
|
|
342
|
+
/** Replace only a generated @scope prelude, never authored CSS payloads. @param {string} css @param {string} search @param {string} replacement */
|
|
343
|
+
// prettier-ignore
|
|
344
|
+
function replaceScopeSyntax(css, search, replacement) {
|
|
345
|
+
let output = '', quote = '', escaped = false, comment = false, lastCode = '';
|
|
346
|
+
for (let index = 0; index < css.length; index++) {
|
|
347
|
+
const char = css[index];
|
|
348
|
+
if (comment) {
|
|
349
|
+
output += char;
|
|
350
|
+
if (char === '*' && css[index + 1] === '/') { output += '/'; comment = false; index++; }
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (quote) {
|
|
354
|
+
output += char;
|
|
355
|
+
if (escaped) escaped = false;
|
|
356
|
+
else if (char === '\\') escaped = true;
|
|
357
|
+
else if (char === quote) quote = '';
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (char === '/' && css[index + 1] === '*') { output += '/*'; comment = true; index++; continue; }
|
|
361
|
+
if (char === '"' || char === "'") { output += char; quote = char; continue; }
|
|
362
|
+
if ((lastCode === '' || lastCode === '{' || lastCode === '}') && css.startsWith(search, index)) {
|
|
363
|
+
output += replacement; lastCode = ')'; index += search.length - 1; continue;
|
|
364
|
+
}
|
|
365
|
+
output += char;
|
|
366
|
+
if (!/\s/.test(char)) lastCode = char;
|
|
367
|
+
}
|
|
368
|
+
return output;
|
|
369
|
+
}
|
|
370
|
+
/** @param {string} css @param {string} name */
|
|
371
|
+
const normalizeScope = (css, name) =>
|
|
372
|
+
replaceScopeSyntax(
|
|
373
|
+
css,
|
|
374
|
+
`@scope (${themeSelector(name)})`,
|
|
375
|
+
'@scope (__ASTRYX_FAMILY_SCOPE__)',
|
|
376
|
+
);
|
|
377
|
+
/** @param {string} css @param {string[]} names */
|
|
378
|
+
const applyScope = (css, names) =>
|
|
379
|
+
replaceScopeSyntax(
|
|
380
|
+
css,
|
|
381
|
+
'@scope (__ASTRYX_FAMILY_SCOPE__)',
|
|
382
|
+
`@scope (${familyScopeSelector(names)})`,
|
|
383
|
+
);
|
|
384
|
+
/** @param {any[]} members @param {string} field */
|
|
385
|
+
function factorSections(members, field) {
|
|
386
|
+
/** @type {Map<string, {css: string, names: string[]}>} */
|
|
387
|
+
const groups = new Map();
|
|
388
|
+
for (const member of members) {
|
|
389
|
+
const css = normalizeScope(member.css[field] ?? '', member.theme.name);
|
|
390
|
+
if (!css) continue;
|
|
391
|
+
const group = groups.get(css) ?? {css, names: []};
|
|
392
|
+
group.names.push(member.theme.name);
|
|
393
|
+
groups.set(css, group);
|
|
394
|
+
}
|
|
395
|
+
return [...groups.values()].map(group => applyScope(group.css, group.names));
|
|
396
|
+
}
|
|
397
|
+
/** Keep document rules top-level-active; initialize nested tuple members locally. @param {any[]} members */
|
|
398
|
+
// prettier-ignore
|
|
399
|
+
function colorSchemeSections(members) {
|
|
400
|
+
const groups = new Map();
|
|
401
|
+
for (const member of members) {
|
|
402
|
+
const css = member.css.colorScheme;
|
|
403
|
+
if (!css) continue;
|
|
404
|
+
const names = groups.get(css) ?? []; names.push(member.theme.name); groups.set(css, names);
|
|
405
|
+
}
|
|
406
|
+
return [...groups].reduce((result, [css, names]) => {
|
|
407
|
+
const identities = familyScopeSelector(names), top = `${identities}:not(:where([data-astryx-theme] [data-astryx-theme]))`;
|
|
408
|
+
const active = (/** @type {string} */ selector) => `${selector}${identities},\n${selector}:where(:not([data-astryx-theme])):has(${top})`;
|
|
409
|
+
result.base.push(`@scope (${identities}) to (${THEME_SCOPE_TO}) {\n :where(:scope:not([data-theme]):not(html[data-theme] *)) { color-scheme: light dark; }\n :where(:scope:not([data-theme]):is(html[data-theme="light"] *)) { color-scheme: light; }\n :where(:scope:not([data-theme]):is(html[data-theme="dark"] *)) { color-scheme: dark; }\n}`);
|
|
410
|
+
result.themed.push(css.replace(':root', active(':root')).replace('html[data-theme="light"]', active('html[data-theme="light"]')).replace('html[data-theme="dark"]', active('html[data-theme="dark"]')));
|
|
411
|
+
return result;
|
|
412
|
+
}, /** @type {{base: string[], themed: string[]}} */ ({base: [], themed: []}));
|
|
413
|
+
}
|
|
414
|
+
/** @param {any[]} members */
|
|
415
|
+
export function generateFamilyCSS(members) {
|
|
416
|
+
const root = members[0];
|
|
417
|
+
for (const member of members) {
|
|
418
|
+
if (member.css.base !== root.css.base)
|
|
419
|
+
throw new Error(
|
|
420
|
+
'Theme-independent base CSS changed between family members.',
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
const prose = [
|
|
424
|
+
...factorRules(members, 'prose'),
|
|
425
|
+
...factorSections(members, 'adaptationProse'),
|
|
426
|
+
];
|
|
427
|
+
const schemes = colorSchemeSections(members);
|
|
428
|
+
const themed = [
|
|
429
|
+
...schemes.themed,
|
|
430
|
+
...factorRules(members, 'component'),
|
|
431
|
+
...factorSections(members, 'adaptation'),
|
|
432
|
+
...factorSections(members, 'onMedia'),
|
|
433
|
+
].filter(Boolean);
|
|
434
|
+
const parts = [];
|
|
435
|
+
if (prose.length > 0) parts.push(`@layer reset {\n${prose.join('\n\n')}\n}`);
|
|
436
|
+
const base = [root.css.base, ...schemes.base].filter(Boolean);
|
|
437
|
+
if (base.length > 0)
|
|
438
|
+
parts.push(`@layer astryx-base {\n${base.join('\n\n')}\n}`);
|
|
439
|
+
if (themed.length > 0)
|
|
440
|
+
parts.push(`@layer astryx-theme {\n${themed.join('\n\n')}\n}`);
|
|
441
|
+
return `${parts.join('\n\n')}\n`;
|
|
442
|
+
}
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
assertWithin,
|
|
7
7
|
PathSafetyError,
|
|
8
8
|
} from '../../../../foundation/fs/path-safety.mjs';
|
|
9
|
+
import {publishNewFile} from '../../../../foundation/fs/publish-file.mjs';
|
|
9
10
|
import {ERROR_CODES} from '../../../../foundation/response/error-codes.mjs';
|
|
10
11
|
import {AstryxError} from '../../../error.mjs';
|
|
11
12
|
import {
|
|
@@ -259,7 +260,7 @@ function writeFilesAtomically(files, overwrite) {
|
|
|
259
260
|
} else {
|
|
260
261
|
// Publishing by hard link is an atomic no-replace operation. A target
|
|
261
262
|
// created after the initial existence check therefore remains safe.
|
|
262
|
-
|
|
263
|
+
publishNewFile(file.temporary, file.path);
|
|
263
264
|
file.published = true;
|
|
264
265
|
fs.unlinkSync(file.temporary);
|
|
265
266
|
}
|
|
@@ -128,6 +128,18 @@ export const docsDense = {
|
|
|
128
128
|
null,
|
|
129
129
|
],
|
|
130
130
|
},
|
|
131
|
+
{
|
|
132
|
+
section: 'Building a Theme Family',
|
|
133
|
+
title: 'Family Build',
|
|
134
|
+
content: [
|
|
135
|
+
{
|
|
136
|
+
type: 'prose',
|
|
137
|
+
text: 'theme build --family <base> <descendants...> --family-key <key> emits one keyed .css + .js + .d.ts beside the root; key must differ from every member name. load CSS once; import ESM separately; switch by theme identity only. all members download eagerly. --check compares the trio. use standalone build for one theme.',
|
|
138
|
+
},
|
|
139
|
+
null,
|
|
140
|
+
null,
|
|
141
|
+
],
|
|
142
|
+
},
|
|
131
143
|
{
|
|
132
144
|
section: 'Runtime vs Built Themes',
|
|
133
145
|
title: 'Runtime vs Built',
|
|
@@ -576,6 +576,43 @@ import './themes/ocean.css';
|
|
|
576
576
|
},
|
|
577
577
|
],
|
|
578
578
|
},
|
|
579
|
+
{
|
|
580
|
+
title: 'Building a Theme Family',
|
|
581
|
+
category: 'guide',
|
|
582
|
+
content: [
|
|
583
|
+
{
|
|
584
|
+
type: 'prose',
|
|
585
|
+
text: 'Use family mode when an app switches among one base theme and its selected descendants. The build writes one keyed CSS file containing every member, plus one keyed JavaScript module and one declaration file beside the root source.',
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
type: 'code',
|
|
589
|
+
lang: 'bash',
|
|
590
|
+
label: 'Build one family',
|
|
591
|
+
code: `astryx theme build --family \\
|
|
592
|
+
./src/themes/ocean.mjs \\
|
|
593
|
+
./src/themes/ocean-calm.mjs \\
|
|
594
|
+
./src/themes/ocean-calm-deep.mjs \\
|
|
595
|
+
--family-key ocean-family`,
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
type: 'code',
|
|
599
|
+
lang: 'html',
|
|
600
|
+
label: 'Load native CSS and ESM independently',
|
|
601
|
+
code: `<link rel="stylesheet" href="./src/themes/ocean-family.css" />
|
|
602
|
+
<script type="module">
|
|
603
|
+
import {oceanCalmTheme} from './src/themes/ocean-family.js';
|
|
604
|
+
</script>`,
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
type: 'prose',
|
|
608
|
+
text: 'The family stylesheet eagerly downloads every selected member so first paint is complete. Switching members changes only the theme identity; it does not add, remove, or reorder stylesheets. A bundler such as Vite consumes the same CSS and ESM files.',
|
|
609
|
+
},
|
|
610
|
+
{
|
|
611
|
+
type: 'prose',
|
|
612
|
+
text: 'The family key is only the filename stem (`ocean-family.css`, `.js`, and `.d.ts`) and must differ from every selected member name. Use the ordinary standalone build when an app needs only one complete theme. Add `--check` to compare the exact keyed trio without writing.',
|
|
613
|
+
},
|
|
614
|
+
],
|
|
615
|
+
},
|
|
579
616
|
{
|
|
580
617
|
title: 'Runtime vs Built Themes',
|
|
581
618
|
category: 'guide',
|
|
@@ -50,7 +50,8 @@ export const docs = {
|
|
|
50
50
|
label: 'Manual options',
|
|
51
51
|
code: `npx @astryxdesign/cli init --features agents --agent claude # .claude/CLAUDE.md
|
|
52
52
|
npx @astryxdesign/cli init --features agents --agent cursor # .cursorrules
|
|
53
|
-
npx @astryxdesign/cli init --features agents --agent codex # AGENTS.md (Copilot, Codex, etc.)
|
|
53
|
+
npx @astryxdesign/cli init --features agents --agent codex # AGENTS.md (Copilot, Codex, etc.)
|
|
54
|
+
npx @astryxdesign/cli init --features agents --agent muse # AGENTS.md (Muse)`,
|
|
54
55
|
},
|
|
55
56
|
],
|
|
56
57
|
},
|
|
@@ -18,11 +18,13 @@
|
|
|
18
18
|
* astryx theme build ./src/themes/ocean.ts
|
|
19
19
|
* astryx theme build ./src/themes/ocean.ts --out ./dist/ocean.css
|
|
20
20
|
* astryx theme build ./src/themes/*.ts
|
|
21
|
+
* astryx theme build --family ./src/themes/ocean.ts ./src/themes/ocean-calm.ts --family-key ocean-family
|
|
21
22
|
*
|
|
22
|
-
*
|
|
23
|
+
* Ordinary builds take one or more theme files. Each is compiled by the same
|
|
23
24
|
* single-file API call, in argument order, in one process — so the outputs are
|
|
24
25
|
* byte-identical to running the CLI once per theme, and the first failure stops
|
|
25
|
-
* the run exactly as a shell loop under `set -e` would.
|
|
26
|
+
* the run exactly as a shell loop under `set -e` would. Family mode delegates
|
|
27
|
+
* the selected files once to the API's in-memory family orchestration.
|
|
26
28
|
*/
|
|
27
29
|
|
|
28
30
|
import * as fs from 'node:fs';
|
|
@@ -45,7 +47,11 @@ import {
|
|
|
45
47
|
serializePaletteCandidate,
|
|
46
48
|
themePaletteGenerate,
|
|
47
49
|
} from '../../../api/theme/palette/generate/generate.mjs';
|
|
48
|
-
import {
|
|
50
|
+
import {
|
|
51
|
+
themeBuild,
|
|
52
|
+
themeBuildFamily,
|
|
53
|
+
importSpecifier,
|
|
54
|
+
} from '../../../api/theme/build/build.mjs';
|
|
49
55
|
import {defineCommand} from '../lib/define-command.mjs';
|
|
50
56
|
import {NO_RESULT_SET, resultSet} from '../../../foundation/debug/index.mjs';
|
|
51
57
|
import {doc as themeGroup} from './theme.doc.mjs';
|
|
@@ -400,7 +406,7 @@ export function registerTheme(program) {
|
|
|
400
406
|
fn: themeBuildFn,
|
|
401
407
|
action: async (
|
|
402
408
|
/** @type {string[]} */ files,
|
|
403
|
-
/** @type {{out?: string, watch?: boolean, check?: boolean, iconsSpecifier?: string}} */ options,
|
|
409
|
+
/** @type {{out?: string, watch?: boolean, check?: boolean, iconsSpecifier?: string, family?: boolean, familyKey?: string}} */ options,
|
|
404
410
|
) => {
|
|
405
411
|
const json = program.opts().json || false;
|
|
406
412
|
const entries = files.map(file => ({
|
|
@@ -427,6 +433,28 @@ export function registerTheme(program) {
|
|
|
427
433
|
});
|
|
428
434
|
}
|
|
429
435
|
|
|
436
|
+
// Family mode is a thin orchestration branch over the existing build API.
|
|
437
|
+
// Its key is required exactly with --family, and options that describe one
|
|
438
|
+
// standalone output or a long-running loop remain intentionally separate.
|
|
439
|
+
if (Boolean(options.family) !== Boolean(options.familyKey)) {
|
|
440
|
+
return cliError(
|
|
441
|
+
options.family
|
|
442
|
+
? '--family requires --family-key <key>'
|
|
443
|
+
: '--family-key requires --family',
|
|
444
|
+
{code: ERROR_CODES.ERR_THEME_INVALID},
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
if (options.family && options.out) {
|
|
448
|
+
return cliError('--family cannot be combined with --out', {
|
|
449
|
+
code: ERROR_CODES.ERR_THEME_INVALID,
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
if (options.family && options.watch) {
|
|
453
|
+
return cliError('--family cannot be combined with --watch', {
|
|
454
|
+
code: ERROR_CODES.ERR_THEME_INVALID,
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
|
|
430
458
|
// --check and --watch are mutually exclusive: check is a one-shot,
|
|
431
459
|
// exit-coded verification; watch is a long-running rebuild loop.
|
|
432
460
|
if (options.check && options.watch) {
|
|
@@ -466,6 +494,33 @@ export function registerTheme(program) {
|
|
|
466
494
|
// ✓/warning lines, and the install instructions are all emitted from
|
|
467
495
|
// inside themeBuild via the shared logger.
|
|
468
496
|
logger.setSilent(json);
|
|
497
|
+
|
|
498
|
+
if (options.family) {
|
|
499
|
+
try {
|
|
500
|
+
const result = await themeBuildFamily(
|
|
501
|
+
files,
|
|
502
|
+
{
|
|
503
|
+
familyKey: /** @type {string} */ (options.familyKey),
|
|
504
|
+
check: options.check,
|
|
505
|
+
iconsSpecifier: options.iconsSpecifier,
|
|
506
|
+
},
|
|
507
|
+
{cwd: process.cwd()},
|
|
508
|
+
);
|
|
509
|
+
if (json) jsonOut(result);
|
|
510
|
+
if (result.type === 'theme.build.check' && !result.data.upToDate) {
|
|
511
|
+
process.exitCode = 1;
|
|
512
|
+
}
|
|
513
|
+
return NO_RESULT_SET;
|
|
514
|
+
} catch (e) {
|
|
515
|
+
const err =
|
|
516
|
+
/** @type {import('../../../api/error.mjs').AstryxError} */ (e);
|
|
517
|
+
return cliError(err.message, {
|
|
518
|
+
suggestions: err.suggestions,
|
|
519
|
+
code: err.code,
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
469
524
|
/** @type {Array<{file: string, receipt: import('../../../api/theme/theme.type.mjs').ThemeBuildResponse | import('../../../api/theme/theme.type.mjs').ThemeBuildCheckResponse | null}>} */
|
|
470
525
|
const results = [];
|
|
471
526
|
let stale = false;
|
|
@@ -591,7 +646,10 @@ export function registerTheme(program) {
|
|
|
591
646
|
try {
|
|
592
647
|
result =
|
|
593
648
|
options.list || !slug
|
|
594
|
-
? await themeListAvailable({
|
|
649
|
+
? await themeListAvailable({
|
|
650
|
+
cwd: process.cwd(),
|
|
651
|
+
package: options.package,
|
|
652
|
+
})
|
|
595
653
|
: await themeAdd(slug, {
|
|
596
654
|
targetPath,
|
|
597
655
|
overwrite: options.overwrite,
|
|
@@ -205,7 +205,10 @@ export function registerComponent(program) {
|
|
|
205
205
|
}
|
|
206
206
|
/** @param {import('../../../../api/component/component.type.mjs').ComponentListEntry} item */
|
|
207
207
|
const importCell = item => {
|
|
208
|
-
|
|
208
|
+
// Use a precomputed import when the API supplies one (integration
|
|
209
|
+
// components carry it); only fall back to the core resolver for
|
|
210
|
+
// core components.
|
|
211
|
+
const importPath = item.import ?? resolveImportPath(coreDir, item.name);
|
|
209
212
|
const qualify =
|
|
210
213
|
item.package !== CORE_PKG || (nameCounts.get(item.name)?.size ?? 0) > 1;
|
|
211
214
|
return qualify ? `${importPath} [${item.package}]` : importPath;
|
|
@@ -41,9 +41,9 @@ export const doc = {
|
|
|
41
41
|
{
|
|
42
42
|
flag: '--agent <tool>',
|
|
43
43
|
param: 'options.agent',
|
|
44
|
-
choices: ['claude', 'cursor', 'codex', 'hermes', 'all'],
|
|
44
|
+
choices: ['claude', 'cursor', 'codex', 'hermes', 'muse', 'all'],
|
|
45
45
|
description:
|
|
46
|
-
'Target AI tool for agent docs: claude, cursor, codex, hermes, all',
|
|
46
|
+
'Target AI tool for agent docs: claude, cursor, codex, hermes, muse, all',
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
49
|
flag: '--agent-docs-path <path...>',
|