ui8kit 1.4.1 → 1.4.2
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 +16 -5
- package/dist/index.js +116 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -241,7 +241,8 @@ Options:
|
|
|
241
241
|
- `[registry]` Path to registry JSON (default: `./src/registry.json`)
|
|
242
242
|
- `-o, --output <path>` Output directory (default: `./packages/registry/r`)
|
|
243
243
|
|
|
244
|
-
The build command also generates `packages/registry/ui8kit.map.json` when
|
|
244
|
+
The build command also generates `packages/registry/ui8kit.map.json` when
|
|
245
|
+
`src/lib/utility-props.map.ts` is available.
|
|
245
246
|
|
|
246
247
|
Generated map shape:
|
|
247
248
|
|
|
@@ -249,13 +250,23 @@ Generated map shape:
|
|
|
249
250
|
{
|
|
250
251
|
"version": "1.0.0",
|
|
251
252
|
"generatedAt": "2026-03-06T12:00:00.000Z",
|
|
252
|
-
"map":
|
|
253
|
-
"
|
|
254
|
-
"
|
|
255
|
-
|
|
253
|
+
"map": [
|
|
254
|
+
"block",
|
|
255
|
+
"display-block",
|
|
256
|
+
"display-flex",
|
|
257
|
+
"m-2",
|
|
258
|
+
"m-4"
|
|
259
|
+
]
|
|
256
260
|
}
|
|
257
261
|
```
|
|
258
262
|
|
|
263
|
+
`map` keeps the existing top-level envelope, but the value is now a flat string
|
|
264
|
+
array of Tailwind classes. The generation reads both:
|
|
265
|
+
|
|
266
|
+
- `src/lib/utility-props.map.ts` — grouped whitelist map by utility prefix.
|
|
267
|
+
- `src/lib/utility-props.ts` — runtime rule source used for special
|
|
268
|
+
expansions (for example `flex` direction handling and semantic `gap` aliases).
|
|
269
|
+
|
|
259
270
|
### Global options
|
|
260
271
|
|
|
261
272
|
These options work for all commands and are defined at the CLI root:
|
package/dist/index.js
CHANGED
|
@@ -66,6 +66,14 @@ var SCHEMA_CONFIG = {
|
|
|
66
66
|
blocks: "./src/blocks",
|
|
67
67
|
variants: "./src/variants"
|
|
68
68
|
},
|
|
69
|
+
// Utility map generation settings
|
|
70
|
+
utilityMap: {
|
|
71
|
+
sources: {
|
|
72
|
+
mapFile: "./src/lib/utility-props.map.ts",
|
|
73
|
+
runtimeFile: "./src/lib/utility-props.ts"
|
|
74
|
+
},
|
|
75
|
+
outputFile: "./packages/registry/ui8kit.map.json"
|
|
76
|
+
},
|
|
69
77
|
// Schema descriptions and titles
|
|
70
78
|
descriptions: {
|
|
71
79
|
config: {
|
|
@@ -2388,6 +2396,93 @@ function normalizeUtilityMap(raw) {
|
|
|
2388
2396
|
}
|
|
2389
2397
|
return ordered;
|
|
2390
2398
|
}
|
|
2399
|
+
function toStringArray(raw) {
|
|
2400
|
+
if (!Array.isArray(raw)) {
|
|
2401
|
+
return [];
|
|
2402
|
+
}
|
|
2403
|
+
return raw.map((item) => typeof item === "string" || typeof item === "number" ? String(item).trim() : "").filter((item) => item.length > 0);
|
|
2404
|
+
}
|
|
2405
|
+
function toStringRecord(raw) {
|
|
2406
|
+
if (!isPlainObject(raw)) {
|
|
2407
|
+
return {};
|
|
2408
|
+
}
|
|
2409
|
+
const result = {};
|
|
2410
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
2411
|
+
if (typeof key === "string" && typeof value === "string") {
|
|
2412
|
+
const normalizedValue = value.trim();
|
|
2413
|
+
if (key.trim() && normalizedValue.length > 0) {
|
|
2414
|
+
result[key.trim()] = normalizedValue;
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
return result;
|
|
2419
|
+
}
|
|
2420
|
+
function parseRuntimeExpansionRules(content) {
|
|
2421
|
+
const sourceFile = ts2.createSourceFile(
|
|
2422
|
+
"utility-props.ts",
|
|
2423
|
+
content,
|
|
2424
|
+
ts2.ScriptTarget.Latest,
|
|
2425
|
+
true
|
|
2426
|
+
);
|
|
2427
|
+
const rules = {
|
|
2428
|
+
flexDirections: /* @__PURE__ */ new Set(),
|
|
2429
|
+
gapSemantic: {}
|
|
2430
|
+
};
|
|
2431
|
+
const visit = (node) => {
|
|
2432
|
+
if (ts2.isVariableStatement(node)) {
|
|
2433
|
+
for (const declaration of node.declarationList.declarations) {
|
|
2434
|
+
if (!ts2.isIdentifier(declaration.name) || !declaration.initializer) {
|
|
2435
|
+
continue;
|
|
2436
|
+
}
|
|
2437
|
+
const value = parseObjectValue(declaration.initializer);
|
|
2438
|
+
if (declaration.name.text === "FLEX_DIR_VALUES") {
|
|
2439
|
+
const values = toStringArray(value);
|
|
2440
|
+
rules.flexDirections = new Set(values);
|
|
2441
|
+
}
|
|
2442
|
+
if (declaration.name.text === "GAP_SEMANTIC") {
|
|
2443
|
+
rules.gapSemantic = toStringRecord(value);
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
ts2.forEachChild(node, visit);
|
|
2448
|
+
};
|
|
2449
|
+
visit(sourceFile);
|
|
2450
|
+
return rules;
|
|
2451
|
+
}
|
|
2452
|
+
function expandUtilityValue(utility, rawValue, rules) {
|
|
2453
|
+
const value = rawValue.trim();
|
|
2454
|
+
if (value.length === 0) {
|
|
2455
|
+
return [utility];
|
|
2456
|
+
}
|
|
2457
|
+
if (utility === "flex" && rules.flexDirections.has(value)) {
|
|
2458
|
+
return ["flex", `flex-${value}`];
|
|
2459
|
+
}
|
|
2460
|
+
if (utility === "gap" && Object.prototype.hasOwnProperty.call(rules.gapSemantic, value)) {
|
|
2461
|
+
return [`gap-${rules.gapSemantic[value]}`];
|
|
2462
|
+
}
|
|
2463
|
+
return [`${utility}-${value}`];
|
|
2464
|
+
}
|
|
2465
|
+
function buildFlatMap(utilityMap, rules) {
|
|
2466
|
+
const flattened = [];
|
|
2467
|
+
for (const [utility, rawValues] of Object.entries(utilityMap)) {
|
|
2468
|
+
const normalizedUtility = utility.trim();
|
|
2469
|
+
if (!normalizedUtility) {
|
|
2470
|
+
continue;
|
|
2471
|
+
}
|
|
2472
|
+
for (const rawValue of rawValues) {
|
|
2473
|
+
if (typeof rawValue !== "string") {
|
|
2474
|
+
continue;
|
|
2475
|
+
}
|
|
2476
|
+
for (const value of expandUtilityValue(normalizedUtility, rawValue, rules)) {
|
|
2477
|
+
const normalizedValue = value.trim();
|
|
2478
|
+
if (normalizedValue.length > 0) {
|
|
2479
|
+
flattened.push(normalizedValue);
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
return [...new Set(flattened)].sort();
|
|
2485
|
+
}
|
|
2391
2486
|
function parseUtilityMapSource(content) {
|
|
2392
2487
|
const fromJson = parseJsonCandidate(content);
|
|
2393
2488
|
if (fromJson !== null) {
|
|
@@ -2400,7 +2495,12 @@ function parseUtilityMapSource(content) {
|
|
|
2400
2495
|
throw new Error("Could not parse utility props map source");
|
|
2401
2496
|
}
|
|
2402
2497
|
async function generateMap(options) {
|
|
2403
|
-
const {
|
|
2498
|
+
const {
|
|
2499
|
+
sourcePath,
|
|
2500
|
+
runtimeSourcePath,
|
|
2501
|
+
outputPath,
|
|
2502
|
+
skipMissing = true
|
|
2503
|
+
} = options;
|
|
2404
2504
|
if (!await fs8.pathExists(sourcePath)) {
|
|
2405
2505
|
if (skipMissing) {
|
|
2406
2506
|
return { generated: false };
|
|
@@ -2410,10 +2510,19 @@ async function generateMap(options) {
|
|
|
2410
2510
|
const content = await fs8.readFile(sourcePath, "utf-8");
|
|
2411
2511
|
const rawMap = parseUtilityMapSource(content);
|
|
2412
2512
|
const map = normalizeUtilityMap(rawMap);
|
|
2513
|
+
let runtimeRules = {
|
|
2514
|
+
flexDirections: /* @__PURE__ */ new Set(),
|
|
2515
|
+
gapSemantic: {}
|
|
2516
|
+
};
|
|
2517
|
+
if (runtimeSourcePath && await fs8.pathExists(runtimeSourcePath)) {
|
|
2518
|
+
const runtimeContent = await fs8.readFile(runtimeSourcePath, "utf-8");
|
|
2519
|
+
runtimeRules = parseRuntimeExpansionRules(runtimeContent);
|
|
2520
|
+
}
|
|
2521
|
+
const flattenedMap = buildFlatMap(map, runtimeRules);
|
|
2413
2522
|
const mapFile = {
|
|
2414
2523
|
version: "1.0.0",
|
|
2415
2524
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2416
|
-
map
|
|
2525
|
+
map: flattenedMap
|
|
2417
2526
|
};
|
|
2418
2527
|
await fs8.ensureDir(path9.dirname(outputPath));
|
|
2419
2528
|
await fs8.writeJson(outputPath, mapFile, { spaces: 2 });
|
|
@@ -2458,10 +2567,13 @@ async function buildCommand(registryPath = "./src/registry.json", options = {})
|
|
|
2458
2567
|
}
|
|
2459
2568
|
spinner.succeed(CLI_MESSAGES.status.builtComponents(registry.items.length));
|
|
2460
2569
|
await createIndexFile(registry, buildOptions.outputDir);
|
|
2461
|
-
const mapSourcePath = path10.join(buildOptions.cwd,
|
|
2462
|
-
const
|
|
2570
|
+
const mapSourcePath = path10.join(buildOptions.cwd, SCHEMA_CONFIG.utilityMap.sources.mapFile);
|
|
2571
|
+
const runtimeSourcePath = path10.join(buildOptions.cwd, SCHEMA_CONFIG.utilityMap.sources.runtimeFile);
|
|
2572
|
+
const mapFileName = path10.basename(SCHEMA_CONFIG.utilityMap.outputFile);
|
|
2573
|
+
const mapOutputPath = path10.join(path10.dirname(buildOptions.outputDir), mapFileName);
|
|
2463
2574
|
const mapResult = await generateMap({
|
|
2464
2575
|
sourcePath: mapSourcePath,
|
|
2576
|
+
runtimeSourcePath,
|
|
2465
2577
|
outputPath: mapOutputPath,
|
|
2466
2578
|
skipMissing: true
|
|
2467
2579
|
});
|