@astryxdesign/cli 0.7.9-canary.7eee905 → 0.7.9-canary.7fb5cab
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/README.md +1 -1
- package/api/component/__fixtures__/resolutions/modules.txt +2 -2
- package/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +8 -2
- package/api/docs/_adapter.mjs +10 -4
- package/api/docs/detail/section/section.d.mts +5 -2
- package/api/docs/detail/section/section.mjs +6 -2
- package/api/docs/docs.mjs +7 -1
- package/api/search/_candidate-score.mjs +25 -23
- package/api/search/_main-searcher.mjs +1 -1
- package/api/search/_result.d.mts +5 -5
- package/api/search/_words.d.mts +44 -7
- package/api/search/_words.mjs +113 -21
- package/api/search/search.d.mts +1 -1
- package/api/swizzle/_adapter.d.mts +10 -0
- package/api/swizzle/_adapter.mjs +24 -1
- package/api/swizzle/copy/copy.d.mts +17 -1
- package/api/swizzle/copy/copy.mjs +249 -9
- package/api/swizzle/swizzle.doc.mjs +1 -1
- package/api/swizzle/swizzle.type.mjs +1 -1
- package/api/theme/build/build.mjs +278 -38
- package/api/theme/build/icon-imports.d.mts +35 -4
- package/api/theme/build/icon-imports.mjs +299 -38
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/author-a-theme.doc.mjs +3 -1
- package/assets/docs/icons.doc.mjs +29 -0
- package/assets/docs/motion.doc.mjs +1 -1
- package/assets/docs/tree/calendar-systems.doc.mjs +146 -0
- package/assets/docs/tree/calendars.doc.mjs +46 -0
- package/assets/docs/tree/i18n-calendars.doc.mjs +51 -0
- package/assets/docs/tree/internationalization.doc.mjs +3 -3
- package/assets/templates/blocks/components/Hooks/useMergedRefsHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useMergedRefsHookUsage.tsx +78 -0
- package/assets/templates/blocks/components/Hooks/useScrollOverflowHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useScrollOverflowHookUsage.tsx +94 -0
- package/assets/templates/blocks/components/Icon/useIconHookUsage.doc.mjs +19 -0
- package/assets/templates/blocks/components/Icon/useIconHookUsage.tsx +68 -0
- package/assets/templates/blocks/components/Link/useLinkComponentHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Link/useLinkComponentHookUsage.tsx +89 -0
- package/assets/templates/blocks/components/PowerSearch/PowerSearchContentSearch.tsx +8 -7
- package/assets/templates/blocks/components/PowerSearch/PowerSearchFullFeatured.tsx +8 -7
- package/assets/templates/blocks/components/PowerSearch/PowerSearchPresetFilters.tsx +8 -7
- package/assets/templates/blocks/components/PowerSearch/PowerSearchSearchWithTable.tsx +12 -10
- package/assets/templates/blocks/components/PowerSearch/PowerSearchShowcase.tsx +8 -7
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.doc.mjs +2 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +2 -2
- package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +0 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +0 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.doc.mjs +2 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +0 -2
- package/assets/templates/blocks/components/usePanGesture/PanDraggableBox.doc.mjs +15 -0
- package/assets/templates/blocks/components/usePanGesture/PanDraggableBox.tsx +98 -0
- package/assets/templates/blocks/components/usePanGesture/PanPlayingCard.doc.mjs +14 -0
- package/assets/templates/blocks/components/usePanGesture/PanPlayingCard.tsx +147 -0
- package/assets/templates/pages/table-inbox/page.tsx +11 -8
- package/assets/templates/pages/work-item-detail/page.tsx +6 -2
- package/assets/theme.template.ts +14 -2
- package/authoring/debug/parse.d.mts +2 -2
- package/authoring/doctypes/base/type.ts +41 -0
- package/authoring/doctypes/component/component.doc.mjs +7 -1
- package/authoring/doctypes/component/type.ts +5 -0
- package/authoring/index.d.ts +2 -0
- package/clients/cli/commands/ensure-core-built.mjs +399 -43
- package/clients/cli/commands/swizzle.mjs +10 -0
- package/clients/cli/index.mjs +11 -6
- package/clients/cli/lib/component-format.mjs +49 -0
- package/foundation/agent-docs/agent-docs-target.d.mts +49 -0
- package/foundation/agent-docs/agent-docs-target.mjs +201 -0
- package/foundation/agent-docs/agent-docs.d.mts +1 -38
- package/foundation/agent-docs/agent-docs.mjs +16 -181
- package/foundation/config/config-path.d.mts +13 -0
- package/foundation/config/config-path.mjs +42 -0
- package/foundation/config/project.d.mts +1 -10
- package/foundation/config/project.mjs +31 -35
- package/foundation/discovery/component-discovery.mjs +56 -10
- package/foundation/discovery/component-loader.d.mts +1 -1
- package/foundation/discovery/icon-set-paths.d.mts +18 -0
- package/foundation/discovery/icon-set-paths.mjs +23 -0
- package/foundation/discovery/icon-set-writer.d.mts +2 -7
- package/foundation/discovery/icon-set-writer.mjs +3 -12
- package/foundation/env/search-path.d.mts +12 -0
- package/foundation/env/search-path.mjs +71 -43
- package/foundation/fs/module-loader.d.mts +2 -8
- package/foundation/fs/module-loader.mjs +3 -12
- package/foundation/fs/present-files.d.mts +11 -0
- package/foundation/fs/present-files.mjs +25 -0
- package/foundation/integrations/autolink.d.mts +2 -21
- package/foundation/integrations/autolink.mjs +6 -42
- package/foundation/integrations/contribution-fixes.mjs +26 -3
- package/foundation/integrations/contribution-inventory.mjs +1 -1
- package/foundation/integrations/installed-package.d.mts +36 -0
- package/foundation/integrations/installed-package.mjs +57 -0
- package/foundation/integrations/integrations.d.mts +3 -75
- package/foundation/integrations/integrations.mjs +3 -16
- package/foundation/integrations/manifest-paths.d.mts +13 -0
- package/foundation/integrations/manifest-paths.mjs +31 -0
- package/foundation/integrations/manifest-writer.d.mts +3 -4
- package/foundation/integrations/manifest-writer.mjs +5 -3
- package/foundation/release/cache.d.mts +11 -4
- package/foundation/release/cache.mjs +15 -7
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/runtime/locked-versions.mjs +1 -1
- package/foundation/runtime/package-set.mjs +1 -1
- package/foundation/text/levenshtein.d.mts +4 -1
- package/foundation/text/levenshtein.mjs +44 -1
- package/package.json +9 -9
- package/api/swizzle/_github.d.mts +0 -8
- package/api/swizzle/_github.mjs +0 -22
|
@@ -2120,7 +2120,7 @@ export async function validateThemePrivateInputs(
|
|
|
2120
2120
|
* import { defaultIconRegistry } from './icons';
|
|
2121
2121
|
* icons: defaultIconRegistry,
|
|
2122
2122
|
* @param {string} filePath
|
|
2123
|
-
* @param {'icons' | 'indicators'} field
|
|
2123
|
+
* @param {'icons' | 'indicators' | 'componentIcons'} field
|
|
2124
2124
|
* @returns {{exportName: string, importPath: string} | null}
|
|
2125
2125
|
*/
|
|
2126
2126
|
function extractRegistryInfo(filePath, field) {
|
|
@@ -2198,6 +2198,83 @@ function iconNodesExpression(entries, entriesName, nodesName) {
|
|
|
2198
2198
|
})()`;
|
|
2199
2199
|
}
|
|
2200
2200
|
|
|
2201
|
+
/**
|
|
2202
|
+
* A theme's component icon slot values: a theme from defineTheme keeps them
|
|
2203
|
+
* in `__componentIcons` when any is a function (its `componentIcons` is the
|
|
2204
|
+
* static view); otherwise `componentIcons` holds them.
|
|
2205
|
+
* @param {any} theme
|
|
2206
|
+
* @returns {Record<string, unknown> | undefined}
|
|
2207
|
+
*/
|
|
2208
|
+
function themeComponentIcons(theme) {
|
|
2209
|
+
return theme?.__componentIcons ?? theme?.componentIcons;
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
/**
|
|
2213
|
+
* The generated function that merges a theme's own slot values over its
|
|
2214
|
+
* base's, as `defineTheme` does: an own slot replaces the inherited one whole,
|
|
2215
|
+
* and an `undefined` own slot leaves it in place. It reads no global.
|
|
2216
|
+
* @param {string} name - A reserved function name.
|
|
2217
|
+
* @returns {string}
|
|
2218
|
+
*/
|
|
2219
|
+
function componentIconMergeFunction(name) {
|
|
2220
|
+
return `function ${name}(base, own) {
|
|
2221
|
+
const merged = {...base};
|
|
2222
|
+
for (const slot in own) {
|
|
2223
|
+
if (own[slot] !== undefined) merged[slot] = own[slot];
|
|
2224
|
+
}
|
|
2225
|
+
return merged;
|
|
2226
|
+
}
|
|
2227
|
+
`;
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
/**
|
|
2231
|
+
* The generated code that reads the static view of a theme's slot values:
|
|
2232
|
+
* every slot without a function. Like the icon node view, it reads no global
|
|
2233
|
+
* and declares only reserved local names.
|
|
2234
|
+
* @param {string} valuesName - A reserved local name bound to the values.
|
|
2235
|
+
* @param {string} viewName - A reserved local name.
|
|
2236
|
+
* @returns {string}
|
|
2237
|
+
*/
|
|
2238
|
+
function componentIconViewExpression(valuesName, viewName) {
|
|
2239
|
+
return `(() => {
|
|
2240
|
+
const ${viewName} = {};
|
|
2241
|
+
for (const slot in ${valuesName}) {
|
|
2242
|
+
const value = ${valuesName}[slot];
|
|
2243
|
+
if (value !== undefined && typeof value !== 'function') ${viewName}[slot] = value;
|
|
2244
|
+
}
|
|
2245
|
+
return ${viewName};
|
|
2246
|
+
})()`;
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2249
|
+
/**
|
|
2250
|
+
* One import statement for a carried registry or slot binding. Ordinary named
|
|
2251
|
+
* imports stay byte-compatible; paths with quotes or escapes are encoded, and
|
|
2252
|
+
* default, namespace, and aliased bindings are kept.
|
|
2253
|
+
* @param {{importPath: string, importedName: string, localName: string}} binding
|
|
2254
|
+
* @param {string} [specifier] - Replaces the import path when given.
|
|
2255
|
+
* @returns {string}
|
|
2256
|
+
*/
|
|
2257
|
+
function importStatement({importPath, importedName, localName}, specifier) {
|
|
2258
|
+
const source =
|
|
2259
|
+
specifier !== undefined
|
|
2260
|
+
? JSON.stringify(specifier)
|
|
2261
|
+
: /['\\\r\n]/u.test(importPath)
|
|
2262
|
+
? JSON.stringify(importPath)
|
|
2263
|
+
: `'${importPath}'`;
|
|
2264
|
+
const imported = /^[$\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u.test(
|
|
2265
|
+
importedName,
|
|
2266
|
+
)
|
|
2267
|
+
? importedName
|
|
2268
|
+
: JSON.stringify(importedName);
|
|
2269
|
+
const binding =
|
|
2270
|
+
importedName === 'default'
|
|
2271
|
+
? localName
|
|
2272
|
+
: importedName === '*'
|
|
2273
|
+
? `* as ${localName}`
|
|
2274
|
+
: `{ ${imported}${importedName === localName ? '' : ` as ${localName}`} }`;
|
|
2275
|
+
return `import ${binding} from ${source};\n`;
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2201
2278
|
/**
|
|
2202
2279
|
* Generate a minimal JS module for a built theme.
|
|
2203
2280
|
* Includes the theme name, marker, and re-exports the icon registry.
|
|
@@ -2224,10 +2301,15 @@ function iconNodesExpression(entries, entriesName, nodesName) {
|
|
|
2224
2301
|
* renders, and the theme's `icons` and the re-exported registry are the node
|
|
2225
2302
|
* view, each function read at `{size: 'md'}` as `DefinedTheme['icons']` is.
|
|
2226
2303
|
*
|
|
2304
|
+
* Component icon slots without a function are written as JSON. When a slot
|
|
2305
|
+
* value is a function, the module keeps the values, carried through
|
|
2306
|
+
* `componentIconInfo`'s imports, as `__componentIcons`, and the theme's
|
|
2307
|
+
* `componentIcons` is the static view, as `DefinedTheme['componentIcons']` is.
|
|
2308
|
+
*
|
|
2227
2309
|
* @param {any} themeDef
|
|
2228
2310
|
* @param {import('./icon-imports.mjs').IconImports | null} iconInfo
|
|
2229
2311
|
* @param {string} [iconsSpecifier] - Overrides the selected registry specifier.
|
|
2230
|
-
* @param {{themeBinding?: string, iconsExpression?: string, indicatorsExpression?: string, artifactBaseName?: string, exportIcons?: boolean}} [moduleOptions]
|
|
2312
|
+
* @param {{themeBinding?: string, iconsExpression?: string, indicatorsExpression?: string, artifactBaseName?: string, exportIcons?: boolean, componentIconInfo?: {imports: import('./icon-imports.mjs').IconImports['imports'], expression: string, mergeName?: string} | null}} [moduleOptions]
|
|
2231
2313
|
* @returns {string}
|
|
2232
2314
|
*/
|
|
2233
2315
|
function generateBuiltModule(
|
|
@@ -2240,32 +2322,17 @@ function generateBuiltModule(
|
|
|
2240
2322
|
moduleOptions.themeBinding ?? `${toIdentifier(themeDef.name)}Theme`;
|
|
2241
2323
|
const artifactBaseName = moduleOptions.artifactBaseName ?? themeDef.name;
|
|
2242
2324
|
const exportIcons = moduleOptions.exportIcons ?? true;
|
|
2243
|
-
// Keep ordinary direct named imports byte-compatible, while encoding paths
|
|
2244
|
-
// with quotes/escapes and retaining default, namespace, and aliased bindings.
|
|
2245
2325
|
const iconImport = (iconInfo?.imports ?? [])
|
|
2246
|
-
.map(
|
|
2247
|
-
|
|
2326
|
+
.map(binding =>
|
|
2327
|
+
importStatement(
|
|
2328
|
+
binding,
|
|
2248
2329
|
iconsSpecifier !== undefined &&
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
: `'${importPath}'`;
|
|
2256
|
-
const imported = /^[$\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u.test(
|
|
2257
|
-
importedName,
|
|
2258
|
-
)
|
|
2259
|
-
? importedName
|
|
2260
|
-
: JSON.stringify(importedName);
|
|
2261
|
-
const binding =
|
|
2262
|
-
importedName === 'default'
|
|
2263
|
-
? localName
|
|
2264
|
-
: importedName === '*'
|
|
2265
|
-
? `* as ${localName}`
|
|
2266
|
-
: `{ ${imported}${importedName === localName ? '' : ` as ${localName}`} }`;
|
|
2267
|
-
return `import ${binding} from ${specifier};\n`;
|
|
2268
|
-
})
|
|
2330
|
+
binding.importPath === iconInfo?.iconsSpecifierImportPath &&
|
|
2331
|
+
binding.localName === iconInfo?.iconsSpecifierLocalName
|
|
2332
|
+
? iconsSpecifier
|
|
2333
|
+
: undefined,
|
|
2334
|
+
),
|
|
2335
|
+
)
|
|
2269
2336
|
.join('');
|
|
2270
2337
|
const iconDeclaration =
|
|
2271
2338
|
iconInfo && iconInfo.expression !== iconInfo.exportName
|
|
@@ -2295,6 +2362,29 @@ function generateBuiltModule(
|
|
|
2295
2362
|
: `\nexport { ${iconInfo.exportName} };\n`
|
|
2296
2363
|
: '';
|
|
2297
2364
|
|
|
2365
|
+
const componentIconValues = themeComponentIcons(themeDef);
|
|
2366
|
+
const componentIconInfo = moduleOptions.componentIconInfo ?? null;
|
|
2367
|
+
const carriesSlotFunctions = hasFunctionIconEntry(componentIconValues);
|
|
2368
|
+
if (carriesSlotFunctions && !componentIconInfo) {
|
|
2369
|
+
throw new AstryxError(
|
|
2370
|
+
`Theme "${themeDef.name}" has componentIcons slot functions that the build cannot carry. ` +
|
|
2371
|
+
'Import the slot functions from their own module into the theme file.',
|
|
2372
|
+
undefined,
|
|
2373
|
+
ERROR_CODES.ERR_THEME_INVALID,
|
|
2374
|
+
);
|
|
2375
|
+
}
|
|
2376
|
+
const componentIconValuesName = `${themeBinding}ComponentIconValues`;
|
|
2377
|
+
const componentIconPrelude =
|
|
2378
|
+
carriesSlotFunctions && componentIconInfo
|
|
2379
|
+
? componentIconInfo.imports
|
|
2380
|
+
.map(binding => importStatement(binding))
|
|
2381
|
+
.join('') +
|
|
2382
|
+
(componentIconInfo.mergeName
|
|
2383
|
+
? componentIconMergeFunction(componentIconInfo.mergeName)
|
|
2384
|
+
: '') +
|
|
2385
|
+
`const ${componentIconValuesName} = ${componentIconInfo.expression};\n`
|
|
2386
|
+
: '';
|
|
2387
|
+
|
|
2298
2388
|
// Resolve token values — tuples become light-dark() strings
|
|
2299
2389
|
/** @type {Record<string, unknown>} */
|
|
2300
2390
|
const resolvedTokens = {};
|
|
@@ -2365,9 +2455,18 @@ function generateBuiltModule(
|
|
|
2365
2455
|
list ?? [],
|
|
2366
2456
|
]),
|
|
2367
2457
|
),
|
|
2368
|
-
)
|
|
2458
|
+
) +
|
|
2459
|
+
(carriesSlotFunctions
|
|
2460
|
+
? ` componentIcons: ${componentIconViewExpression(
|
|
2461
|
+
componentIconValuesName,
|
|
2462
|
+
`${themeBinding}ComponentIconView`,
|
|
2463
|
+
)
|
|
2464
|
+
.split('\n')
|
|
2465
|
+
.map((line, i) => (i === 0 ? line : ' ' + line))
|
|
2466
|
+
.join('\n')},\n __componentIcons: ${componentIconValuesName},\n`
|
|
2467
|
+
: serializeField('componentIcons', componentIconValues, true));
|
|
2369
2468
|
|
|
2370
|
-
return `${iconImport}${iconDeclaration}${iconNodesDeclaration}/**
|
|
2469
|
+
return `${iconImport}${componentIconPrelude}${iconDeclaration}${iconNodesDeclaration}/**
|
|
2371
2470
|
* ${themeDef.name} theme — built by \`${getCliInvocation()} theme build\`
|
|
2372
2471
|
* Import the CSS file alongside this module:
|
|
2373
2472
|
*
|
|
@@ -2844,12 +2943,29 @@ async function themeBuildInternal(
|
|
|
2844
2943
|
let themeExportName;
|
|
2845
2944
|
/** Paths through the load that interception could not fully observe. */
|
|
2846
2945
|
let loadDegradation;
|
|
2946
|
+
/**
|
|
2947
|
+
* The theme file's bytes as loaded: read before and after the load, and the
|
|
2948
|
+
* registry scan below reads these rather than the file again. An editor's
|
|
2949
|
+
* in-place save truncates before it writes, so a later read can find an
|
|
2950
|
+
* empty file the load never saw; a file that changed while it loaded is not
|
|
2951
|
+
* built from.
|
|
2952
|
+
* @type {string}
|
|
2953
|
+
*/
|
|
2954
|
+
let themeSource;
|
|
2847
2955
|
try {
|
|
2956
|
+
const before = fs.readFileSync(filePath, 'utf8');
|
|
2848
2957
|
const loaded = await extractThemeDefinition(
|
|
2849
2958
|
filePath,
|
|
2850
2959
|
interception,
|
|
2851
2960
|
options.__familyLoader,
|
|
2852
2961
|
);
|
|
2962
|
+
const after = fs.readFileSync(filePath, 'utf8');
|
|
2963
|
+
if (before !== after || before === '') {
|
|
2964
|
+
throw new Error(
|
|
2965
|
+
`${filePath} changed while it was loading. Build again once it is saved.`,
|
|
2966
|
+
);
|
|
2967
|
+
}
|
|
2968
|
+
themeSource = before;
|
|
2853
2969
|
themeDef = loaded.theme;
|
|
2854
2970
|
themeExportName = loaded.exportName;
|
|
2855
2971
|
loadDegradation = loaded.degraded;
|
|
@@ -2938,10 +3054,20 @@ async function themeBuildInternal(
|
|
|
2938
3054
|
]
|
|
2939
3055
|
: []),
|
|
2940
3056
|
];
|
|
3057
|
+
// Names the slot values, their static view, and their merge function take
|
|
3058
|
+
// in the built module.
|
|
3059
|
+
const componentIconNames = [
|
|
3060
|
+
`${toIdentifier(themeDef.name)}ThemeComponentIconValues`,
|
|
3061
|
+
`${toIdentifier(themeDef.name)}ThemeComponentIconView`,
|
|
3062
|
+
`${toIdentifier(themeDef.name)}ThemeMergeComponentIcons`,
|
|
3063
|
+
];
|
|
2941
3064
|
const iconResolution = {
|
|
2942
|
-
readSource: (/** @type {string} */ file) =>
|
|
3065
|
+
readSource: (/** @type {string} */ file) =>
|
|
3066
|
+
path.resolve(file) === path.resolve(filePath)
|
|
3067
|
+
? themeSource
|
|
3068
|
+
: fs.readFileSync(file, 'utf8'),
|
|
2943
3069
|
resolveModule: resolveThemeModule,
|
|
2944
|
-
reservedNames: reservedNames(functionEntries),
|
|
3070
|
+
reservedNames: [...reservedNames(functionEntries), ...componentIconNames],
|
|
2945
3071
|
functionEntries,
|
|
2946
3072
|
rawInput: 'extends' in themeDef,
|
|
2947
3073
|
hasIcons:
|
|
@@ -2951,6 +3077,8 @@ async function themeBuildInternal(
|
|
|
2951
3077
|
let iconInfo = standaloneIcons
|
|
2952
3078
|
? await resolveIconImports(filePath, themeExportName, iconResolution)
|
|
2953
3079
|
: null;
|
|
3080
|
+
/** @type {import('./icon-imports.mjs').IconImports | null} */
|
|
3081
|
+
let componentIconInfo = null;
|
|
2954
3082
|
|
|
2955
3083
|
// Validate component overrides
|
|
2956
3084
|
const warnings = await validateComponentOverrides(themeDef);
|
|
@@ -3073,7 +3201,10 @@ async function themeBuildInternal(
|
|
|
3073
3201
|
...iconResolution,
|
|
3074
3202
|
hasIcons: true,
|
|
3075
3203
|
functionEntries: resolvedFunctionEntries,
|
|
3076
|
-
reservedNames:
|
|
3204
|
+
reservedNames: [
|
|
3205
|
+
...reservedNames(resolvedFunctionEntries),
|
|
3206
|
+
...componentIconNames,
|
|
3207
|
+
],
|
|
3077
3208
|
});
|
|
3078
3209
|
}
|
|
3079
3210
|
// An opaque package base can legitimately have no icons. Its .icons
|
|
@@ -3098,6 +3229,27 @@ async function themeBuildInternal(
|
|
|
3098
3229
|
);
|
|
3099
3230
|
}
|
|
3100
3231
|
|
|
3232
|
+
// A slot function cannot be serialized, so the module imports it from
|
|
3233
|
+
// where the theme source does. Static slot values are written as JSON.
|
|
3234
|
+
if (
|
|
3235
|
+
standaloneIcons &&
|
|
3236
|
+
hasFunctionIconEntry(themeComponentIcons(resolvedTheme))
|
|
3237
|
+
) {
|
|
3238
|
+
componentIconInfo = await resolveIconImports(filePath, themeExportName, {
|
|
3239
|
+
...iconResolution,
|
|
3240
|
+
field: 'componentIcons',
|
|
3241
|
+
mergeName: `${toIdentifier(themeDef.name)}ThemeMergeComponentIcons`,
|
|
3242
|
+
hasIcons: true,
|
|
3243
|
+
functionEntries: true,
|
|
3244
|
+
reservedNames: [
|
|
3245
|
+
...reservedNames(true),
|
|
3246
|
+
...componentIconNames,
|
|
3247
|
+
...(iconInfo?.imports.map(binding => binding.localName) ?? []),
|
|
3248
|
+
...(iconInfo ? [iconInfo.exportName] : []),
|
|
3249
|
+
],
|
|
3250
|
+
});
|
|
3251
|
+
}
|
|
3252
|
+
|
|
3101
3253
|
// Cores that predate adaptations can still resolve typography, color,
|
|
3102
3254
|
// radius, and motion into root tokens, but they do not retain the raw axis
|
|
3103
3255
|
// inputs. Keep the effective metadata captured from the same defineTheme
|
|
@@ -3327,13 +3479,17 @@ async function themeBuildInternal(
|
|
|
3327
3479
|
const cssDtsContent =
|
|
3328
3480
|
generatedHeader(sourceRelative, 'ts', buildCommand, versions) +
|
|
3329
3481
|
'export {};\n';
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3482
|
+
// A family member's module is generated by themeBuildFamily, which carries
|
|
3483
|
+
// its registries and slot functions through the family's own imports.
|
|
3484
|
+
const jsContent = options.__prepareFamily
|
|
3485
|
+
? ''
|
|
3486
|
+
: generatedHeader(sourceRelative, 'js', buildCommand, versions) +
|
|
3487
|
+
generateBuiltModule(
|
|
3488
|
+
resolvedTheme || themeDef,
|
|
3489
|
+
iconInfo,
|
|
3490
|
+
options.iconsSpecifier,
|
|
3491
|
+
{componentIconInfo},
|
|
3492
|
+
);
|
|
3337
3493
|
const dtsContent =
|
|
3338
3494
|
generatedHeader(sourceRelative, 'ts', buildCommand, versions) +
|
|
3339
3495
|
generateBuiltTypes(resolvedTheme || themeDef, iconInfo, variantsFileName);
|
|
@@ -3356,6 +3512,7 @@ async function themeBuildInternal(
|
|
|
3356
3512
|
sourceParent,
|
|
3357
3513
|
iconInfo: extractRegistryInfo(filePath, 'icons'),
|
|
3358
3514
|
indicatorInfo: extractRegistryInfo(filePath, 'indicators'),
|
|
3515
|
+
componentIconInfo: extractRegistryInfo(filePath, 'componentIcons'),
|
|
3359
3516
|
variantDecl,
|
|
3360
3517
|
css: cssPlan,
|
|
3361
3518
|
versions,
|
|
@@ -3675,6 +3832,81 @@ function allocateFamilyBindings(members) {
|
|
|
3675
3832
|
const used = new Map();
|
|
3676
3833
|
return new Map(members.map(member => { const base = familyThemeBinding(member.theme.name), count = used.get(base) ?? 0; used.set(base, count + 1); return [member.theme.name, count === 0 ? base : `${base}${count + 1}`]; }));
|
|
3677
3834
|
}
|
|
3835
|
+
/**
|
|
3836
|
+
* How a family member's module carries slot functions: its parent's values,
|
|
3837
|
+
* then its own. A member supplies its own slot functions through a named
|
|
3838
|
+
* import of its whole `componentIcons` map, merged as `defineTheme` merges;
|
|
3839
|
+
* own static values are written as JSON. Null when the member has no slot
|
|
3840
|
+
* function, so its static values are written as JSON alone.
|
|
3841
|
+
* @param {any} member
|
|
3842
|
+
* @param {any} parent - The member's parent in the family, if any.
|
|
3843
|
+
* @param {{themeBinding: string | undefined, parentBinding: string | null | undefined, outDir: string, registryImports: Array<{specifier: string, exportName: string}>, expression: (own: string | null, inherited: string | null) => string | undefined}} context
|
|
3844
|
+
* @returns {{imports: Array<{importPath: string, importedName: string, localName: string}>, expression: string, mergeName?: string} | null}
|
|
3845
|
+
*/
|
|
3846
|
+
function familyComponentIcons(member, parent, context) {
|
|
3847
|
+
const values = themeComponentIcons(member.theme);
|
|
3848
|
+
if (!hasFunctionIconEntry(values)) return null;
|
|
3849
|
+
const inheritedValues = themeComponentIcons(parent?.theme);
|
|
3850
|
+
const inherited =
|
|
3851
|
+
context.parentBinding && inheritedValues
|
|
3852
|
+
? `${context.parentBinding}.${hasFunctionIconEntry(inheritedValues) ? '__componentIcons' : 'componentIcons'}`
|
|
3853
|
+
: null;
|
|
3854
|
+
/** @type {Array<{importPath: string, importedName: string, localName: string}>} */
|
|
3855
|
+
const imports = [];
|
|
3856
|
+
let own = null;
|
|
3857
|
+
const binding =
|
|
3858
|
+
context.themeBinding ?? `${toIdentifier(member.theme.name)}Theme`;
|
|
3859
|
+
const info = member.componentIconInfo;
|
|
3860
|
+
if (info) {
|
|
3861
|
+
const input = familyRegistryInput(
|
|
3862
|
+
info,
|
|
3863
|
+
member.filePath,
|
|
3864
|
+
context.outDir,
|
|
3865
|
+
undefined,
|
|
3866
|
+
);
|
|
3867
|
+
const importPath = input.specifier ?? info.importPath;
|
|
3868
|
+
own = `${binding}ComponentIconSource`;
|
|
3869
|
+
imports.push({importPath, importedName: info.exportName, localName: own});
|
|
3870
|
+
context.registryImports.push({
|
|
3871
|
+
specifier: importPath,
|
|
3872
|
+
exportName: info.exportName,
|
|
3873
|
+
});
|
|
3874
|
+
} else {
|
|
3875
|
+
// Without an import, a member's own slots are the ones that differ from
|
|
3876
|
+
// its parent's; they must all be static.
|
|
3877
|
+
/** @type {Record<string, unknown>} */
|
|
3878
|
+
const ownValues = {};
|
|
3879
|
+
for (const [slot, value] of Object.entries(values ?? {})) {
|
|
3880
|
+
if (
|
|
3881
|
+
inheritedValues &&
|
|
3882
|
+
Object.hasOwn(inheritedValues, slot) &&
|
|
3883
|
+
inheritedValues[slot] === value
|
|
3884
|
+
)
|
|
3885
|
+
continue;
|
|
3886
|
+
if (typeof value === 'function') {
|
|
3887
|
+
throw new AstryxError(
|
|
3888
|
+
`Theme "${member.theme.name}" must supply its componentIcons slot functions through a named import of its whole componentIcons map for family output.`,
|
|
3889
|
+
undefined,
|
|
3890
|
+
ERROR_CODES.ERR_THEME_INVALID,
|
|
3891
|
+
);
|
|
3892
|
+
}
|
|
3893
|
+
ownValues[slot] = value;
|
|
3894
|
+
}
|
|
3895
|
+
if (Object.keys(ownValues).length > 0) own = JSON.stringify(ownValues);
|
|
3896
|
+
}
|
|
3897
|
+
if (info) {
|
|
3898
|
+
// An imported map can hold an `undefined` slot: it keeps the parent's,
|
|
3899
|
+
// and a root drops it, as `defineTheme` does.
|
|
3900
|
+
const mergeName = `${binding}MergeComponentIcons`;
|
|
3901
|
+
return {
|
|
3902
|
+
imports,
|
|
3903
|
+
expression: `${mergeName}(${inherited ?? '{}'}, ${own})`,
|
|
3904
|
+
mergeName,
|
|
3905
|
+
};
|
|
3906
|
+
}
|
|
3907
|
+
const expression = context.expression(own, inherited);
|
|
3908
|
+
return expression ? {imports, expression} : null;
|
|
3909
|
+
}
|
|
3678
3910
|
/** Rebase a scraped relative registry import to the aggregate module. @param {any} info @param {string} filePath @param {string} outDir @param {string | undefined} override */
|
|
3679
3911
|
// prettier-ignore
|
|
3680
3912
|
function familyRegistryInput(info, filePath, outDir, override) {
|
|
@@ -3887,6 +4119,13 @@ export async function themeBuildFamily(
|
|
|
3887
4119
|
// rebased or overridden specifier replaces the scraped one.
|
|
3888
4120
|
// prettier-ignore
|
|
3889
4121
|
const iconImports = icon.info && ownIcons ? {imports: [{importPath: icon.info.importPath, importedName: icon.info.exportName, localName: ownIcons}], expression: ownIcons, exportName: ownIcons, iconsSpecifierImportPath: icon.info.importPath, iconsSpecifierLocalName: ownIcons} : null;
|
|
4122
|
+
const componentIconInfo = familyComponentIcons(member, parent, {
|
|
4123
|
+
themeBinding,
|
|
4124
|
+
parentBinding,
|
|
4125
|
+
outDir,
|
|
4126
|
+
registryImports,
|
|
4127
|
+
expression,
|
|
4128
|
+
});
|
|
3890
4129
|
return (
|
|
3891
4130
|
indicatorImport +
|
|
3892
4131
|
generateBuiltModule(member.theme, iconImports, icon.specifier, {
|
|
@@ -3895,6 +4134,7 @@ export async function themeBuildFamily(
|
|
|
3895
4134
|
indicatorsExpression: expression(ownIndicators, inheritedIndicators),
|
|
3896
4135
|
artifactBaseName: baseName,
|
|
3897
4136
|
exportIcons: false,
|
|
4137
|
+
componentIconInfo,
|
|
3898
4138
|
})
|
|
3899
4139
|
);
|
|
3900
4140
|
})
|
|
@@ -10,14 +10,23 @@
|
|
|
10
10
|
* base is read for its entries (`__icons`) as well as its node-valued `icons`,
|
|
11
11
|
* and a built base module's `__icons` field is followed instead of `icons`.
|
|
12
12
|
*
|
|
13
|
+
* With `field: 'componentIcons'`, the same tracing carries a theme's slot
|
|
14
|
+
* values: a slot function must come from an import, and an inline object may
|
|
15
|
+
* also hold static values (names, `null`, requests), written as JSON. A built
|
|
16
|
+
* base module is read through its export, like a package theme. A theme's own
|
|
17
|
+
* slots merge over its base's through `mergeName`, which skips an
|
|
18
|
+
* `undefined` slot as `defineTheme` does.
|
|
19
|
+
*
|
|
13
20
|
* @param {string} filePath
|
|
14
21
|
* @param {string | undefined} exportName
|
|
15
|
-
* @param {{hasIcons: boolean, functionEntries?: boolean, readSource: (filename: string) => string, resolveModule: (specifier: string, fromFile: string) => string | Promise<string>, reservedNames?: string[], rawInput?: boolean}} options
|
|
22
|
+
* @param {{hasIcons: boolean, functionEntries?: boolean, field?: 'icons' | 'componentIcons', mergeName?: string, readSource: (filename: string) => string, resolveModule: (specifier: string, fromFile: string) => string | Promise<string>, reservedNames?: string[], rawInput?: boolean}} options
|
|
16
23
|
* @returns {Promise<IconImports | null>}
|
|
17
24
|
*/
|
|
18
|
-
export function resolveIconImports(filePath: string, exportName: string | undefined, { hasIcons, functionEntries, readSource, resolveModule, reservedNames, rawInput, }: {
|
|
25
|
+
export function resolveIconImports(filePath: string, exportName: string | undefined, { hasIcons, functionEntries, field, mergeName, readSource, resolveModule, reservedNames, rawInput, }: {
|
|
19
26
|
hasIcons: boolean;
|
|
20
27
|
functionEntries?: boolean;
|
|
28
|
+
field?: "icons" | "componentIcons";
|
|
29
|
+
mergeName?: string;
|
|
21
30
|
readSource: (filename: string) => string;
|
|
22
31
|
resolveModule: (specifier: string, fromFile: string) => string | Promise<string>;
|
|
23
32
|
reservedNames?: string[];
|
|
@@ -33,6 +42,11 @@ export type IconImports = {
|
|
|
33
42
|
exportName: string;
|
|
34
43
|
iconsSpecifierImportPath?: string | undefined;
|
|
35
44
|
iconsSpecifierLocalName?: string | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* - Set when `expression` calls the slot merge
|
|
47
|
+
* function, which the module must declare under this name.
|
|
48
|
+
*/
|
|
49
|
+
mergeName?: string | undefined;
|
|
36
50
|
};
|
|
37
51
|
export type RegistryReference = {
|
|
38
52
|
kind: "reference";
|
|
@@ -41,8 +55,21 @@ export type RegistryReference = {
|
|
|
41
55
|
members: string[];
|
|
42
56
|
};
|
|
43
57
|
/**
|
|
44
|
-
* `
|
|
45
|
-
*
|
|
58
|
+
* A `merge` with `theme` set merges a theme's own values over its base's;
|
|
59
|
+
* any other merge is a spread inside one object.
|
|
60
|
+
*/
|
|
61
|
+
export type SlotData = {
|
|
62
|
+
json: unknown;
|
|
63
|
+
} | {
|
|
64
|
+
ref: RegistryReference;
|
|
65
|
+
} | {
|
|
66
|
+
object: Array<[string, SlotData]>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* `entries` marks a package theme read for its entries: its public field
|
|
70
|
+
* (node-valued `icons`, or the static `componentIcons` view) merged with the
|
|
71
|
+
* `__` field that holds its functions, if any. `object` is an inline
|
|
72
|
+
* `componentIcons` object: each slot is a static value or an imported one.
|
|
46
73
|
*/
|
|
47
74
|
export type RegistryPlan = {
|
|
48
75
|
kind: "registry";
|
|
@@ -54,4 +81,8 @@ export type RegistryPlan = {
|
|
|
54
81
|
kind: "merge";
|
|
55
82
|
base: RegistryPlan;
|
|
56
83
|
own: RegistryPlan;
|
|
84
|
+
theme?: boolean;
|
|
85
|
+
} | {
|
|
86
|
+
kind: "object";
|
|
87
|
+
entries: Array<[string, SlotData]>;
|
|
57
88
|
};
|