@kinetixui/cli 0.23.1 → 0.23.3
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/dist/index.js +77 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2468,6 +2468,59 @@ function swiftColor(hex) {
|
|
|
2468
2468
|
const [r, g, b] = swiftUiChannels(`#${h}`);
|
|
2469
2469
|
return `Color(red: ${r}, green: ${g}, blue: ${b})`;
|
|
2470
2470
|
}
|
|
2471
|
+
function swiftShadowColor(hex) {
|
|
2472
|
+
const h = hex.replace("#", "").trim();
|
|
2473
|
+
if (!/^[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/.test(h)) return null;
|
|
2474
|
+
const base = h.slice(0, 6) === "000000" ? "Color.black" : swiftColor(`#${h.slice(0, 6)}`);
|
|
2475
|
+
if (!base) return null;
|
|
2476
|
+
if (h.length === 6) return base;
|
|
2477
|
+
const alpha = Number((parseInt(h.slice(6, 8), 16) / 255).toFixed(3));
|
|
2478
|
+
return `${base}.opacity(${alpha})`;
|
|
2479
|
+
}
|
|
2480
|
+
var RADIUS_STEPS2 = ["sm", "md", "lg", "xl"];
|
|
2481
|
+
var ELEVATION_STEPS = ["sm", "md", "lg", "xl"];
|
|
2482
|
+
var sameLayers = (a, b) => a.length === b.length && a.every((layer, i) => {
|
|
2483
|
+
const other = b[i];
|
|
2484
|
+
return layer.color.toLowerCase() === other.color.toLowerCase() && layer.offsetX === other.offsetX && layer.offsetY === other.offsetY && layer.blur === other.blur && layer.spread === other.spread;
|
|
2485
|
+
});
|
|
2486
|
+
var swiftLength = (value) => Number(Number(value).toFixed(3));
|
|
2487
|
+
function swiftRadii(radius) {
|
|
2488
|
+
if (RADIUS_STEPS2.every((step) => radius[step] === SHIPPED_RADIUS[step])) return "KinetixRadii.default";
|
|
2489
|
+
return [
|
|
2490
|
+
"KinetixRadii(",
|
|
2491
|
+
` field: ${swiftLength(String(radius.sm))},`,
|
|
2492
|
+
` control: ${swiftLength(String(radius.md))},`,
|
|
2493
|
+
` container: ${swiftLength(String(radius.lg))},`,
|
|
2494
|
+
` surface: ${swiftLength(String(radius.xl))}`,
|
|
2495
|
+
" )"
|
|
2496
|
+
].join("\n");
|
|
2497
|
+
}
|
|
2498
|
+
function swiftElevations(elevation) {
|
|
2499
|
+
if (ELEVATION_STEPS.every((s) => sameLayers(elevation[s], SHIPPED_ELEVATION[s]))) return "KinetixElevations.default";
|
|
2500
|
+
const step = (layers) => {
|
|
2501
|
+
if (layers.length === 0) return ".none";
|
|
2502
|
+
const rendered = layers.map((layer) => {
|
|
2503
|
+
const color = swiftShadowColor(layer.color) ?? "Color.black.opacity(0.05)";
|
|
2504
|
+
return [
|
|
2505
|
+
" KinetixShadowLayer(",
|
|
2506
|
+
` color: ${color},`,
|
|
2507
|
+
` radius: ${swiftLength(layer.blur)},`,
|
|
2508
|
+
` x: ${swiftLength(layer.offsetX)},`,
|
|
2509
|
+
` y: ${swiftLength(layer.offsetY)}`,
|
|
2510
|
+
" ),"
|
|
2511
|
+
].join("\n");
|
|
2512
|
+
});
|
|
2513
|
+
return ["KinetixElevation([", ...rendered, " ])"].join("\n");
|
|
2514
|
+
};
|
|
2515
|
+
return [
|
|
2516
|
+
"KinetixElevations(",
|
|
2517
|
+
` sm: ${step(elevation.sm)},`,
|
|
2518
|
+
` md: ${step(elevation.md)},`,
|
|
2519
|
+
` lg: ${step(elevation.lg)},`,
|
|
2520
|
+
` xl: ${step(elevation.xl)}`,
|
|
2521
|
+
" )"
|
|
2522
|
+
].join("\n");
|
|
2523
|
+
}
|
|
2471
2524
|
var SWIFT_COLOR_FIELDS = [
|
|
2472
2525
|
"primary",
|
|
2473
2526
|
"primary-foreground",
|
|
@@ -2534,11 +2587,16 @@ function header3(symbol, theme2) {
|
|
|
2534
2587
|
"// editing this file: it is a rendering of a preset, not a source of one.",
|
|
2535
2588
|
"//",
|
|
2536
2589
|
`// Theme colour ${design.brand} \xB7 ${design.neutral} neutral \xB7 ${design.chartPalette} charts`,
|
|
2590
|
+
`// Radius ${design.radius} \xB7 surface ${design.surface}`,
|
|
2537
2591
|
"//",
|
|
2538
|
-
"//
|
|
2539
|
-
"// elevation are
|
|
2540
|
-
|
|
2541
|
-
"//
|
|
2592
|
+
"// Colours, corner radii and elevation \u2014 the whole design this file can express. Radii and",
|
|
2593
|
+
"// elevation are one value rather than a light/dark pair, because the runtime takes one and the",
|
|
2594
|
+
"// two appearances resolve to the same ladder.",
|
|
2595
|
+
"//",
|
|
2596
|
+
"// ONE THING DOES NOT SURVIVE THE PORT. CSS shadows have `spread`; SwiftUI's `.shadow` has no",
|
|
2597
|
+
"// equivalent, so the spread on this design's larger steps is dropped and they render slightly",
|
|
2598
|
+
"// wider here than on the web. The shipped `KinetixElevations.default` is mapped the same way, so",
|
|
2599
|
+
"// a generated theme and the built-in one differ from the web in exactly the same manner.",
|
|
2542
2600
|
"//",
|
|
2543
2601
|
"// A field written as `KinetixColorsSwiftUI.\u2026` is one this design did not change, and it keeps",
|
|
2544
2602
|
"// following the library.",
|
|
@@ -2556,8 +2614,9 @@ function exportSwiftUi(theme2, options = {}) {
|
|
|
2556
2614
|
"import KinetixUI",
|
|
2557
2615
|
"",
|
|
2558
2616
|
`public enum ${symbol} {`,
|
|
2559
|
-
" /// Apply
|
|
2560
|
-
|
|
2617
|
+
" /// Apply the whole design with",
|
|
2618
|
+
` /// \`KinetixTheme(light: .light, dark: .dark, radii: .radii, elevations: .elevations) { \u2026 }\`,`,
|
|
2619
|
+
" /// or set `\\.kinetixColors` directly to pin one appearance.",
|
|
2561
2620
|
` public static let light = KinetixColors(`,
|
|
2562
2621
|
colorSet3(theme2.light, "light"),
|
|
2563
2622
|
" )",
|
|
@@ -2565,6 +2624,13 @@ function exportSwiftUi(theme2, options = {}) {
|
|
|
2565
2624
|
` public static let dark = KinetixColors(`,
|
|
2566
2625
|
colorSet3(theme2.dark, "dark"),
|
|
2567
2626
|
" )",
|
|
2627
|
+
"",
|
|
2628
|
+
// One value, not a light/dark pair: the runtime takes one, and the resolver produces the same
|
|
2629
|
+
// ladder for both appearances — a card's corner does not change when the lights go out.
|
|
2630
|
+
// `swiftui.test.ts` asserts that equality rather than trusting it.
|
|
2631
|
+
` public static let radii = ${swiftRadii(theme2.light.radius)}`,
|
|
2632
|
+
"",
|
|
2633
|
+
` public static let elevations = ${swiftElevations(theme2.light.elevation)}`,
|
|
2568
2634
|
"}",
|
|
2569
2635
|
""
|
|
2570
2636
|
].join("\n");
|
|
@@ -2636,7 +2702,10 @@ async function presetSwiftUi(input, opts) {
|
|
|
2636
2702
|
const swift = exportSwiftUi(resolveCreateTheme(read(input)), { symbol });
|
|
2637
2703
|
if (opts.output) {
|
|
2638
2704
|
await writeFile3(opts.output, swift, "utf8");
|
|
2639
|
-
console.log(
|
|
2705
|
+
console.log(
|
|
2706
|
+
pc8.green("\u2714"),
|
|
2707
|
+
`Wrote ${opts.output} \u2014 apply it with KinetixTheme(light: ${symbol}.light, dark: ${symbol}.dark, radii: ${symbol}.radii, elevations: ${symbol}.elevations)`
|
|
2708
|
+
);
|
|
2640
2709
|
return;
|
|
2641
2710
|
}
|
|
2642
2711
|
process.stdout.write(swift);
|
|
@@ -2885,7 +2954,7 @@ async function themeBuild(name, options) {
|
|
|
2885
2954
|
// package.json
|
|
2886
2955
|
var package_default = {
|
|
2887
2956
|
name: "@kinetixui/cli",
|
|
2888
|
-
version: "0.23.
|
|
2957
|
+
version: "0.23.3",
|
|
2889
2958
|
description: "Add KinetixUI components and tokens to your project.",
|
|
2890
2959
|
type: "module",
|
|
2891
2960
|
license: "MIT",
|