@kinetixui/cli 0.23.2 → 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.
Files changed (2) hide show
  1. package/dist/index.js +77 -9
  2. 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,12 +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
- "// COLOURS ONLY \u2014 and that is now a limit of this exporter rather than of the package. SwiftUI",
2539
- "// gained `KinetixRadii` and `KinetixElevations` alongside `KinetixColors`, so there is somewhere",
2540
- `// for a radius to land; this file does not write one yet. This design's radius (${design.radius}) and`,
2541
- `// surface treatment (${design.surface}) are therefore NOT carried here \u2014 set them by hand for now:`,
2542
- "// `KinetixTheme(light: \u2026, dark: \u2026, radii: \u2026, elevations: \u2026)`. Nothing is silently dropped.",
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.",
2543
2600
  "//",
2544
2601
  "// A field written as `KinetixColorsSwiftUI.\u2026` is one this design did not change, and it keeps",
2545
2602
  "// following the library.",
@@ -2557,8 +2614,9 @@ function exportSwiftUi(theme2, options = {}) {
2557
2614
  "import KinetixUI",
2558
2615
  "",
2559
2616
  `public enum ${symbol} {`,
2560
- " /// Apply with `KinetixTheme(light: .light, dark: .dark) { \u2026 }`, or set",
2561
- " /// `\\.kinetixColors` directly to pin one appearance.",
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.",
2562
2620
  ` public static let light = KinetixColors(`,
2563
2621
  colorSet3(theme2.light, "light"),
2564
2622
  " )",
@@ -2566,6 +2624,13 @@ function exportSwiftUi(theme2, options = {}) {
2566
2624
  ` public static let dark = KinetixColors(`,
2567
2625
  colorSet3(theme2.dark, "dark"),
2568
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)}`,
2569
2634
  "}",
2570
2635
  ""
2571
2636
  ].join("\n");
@@ -2637,7 +2702,10 @@ async function presetSwiftUi(input, opts) {
2637
2702
  const swift = exportSwiftUi(resolveCreateTheme(read(input)), { symbol });
2638
2703
  if (opts.output) {
2639
2704
  await writeFile3(opts.output, swift, "utf8");
2640
- console.log(pc8.green("\u2714"), `Wrote ${opts.output} \u2014 apply it with KinetixTheme(light: ${symbol}.light, dark: ${symbol}.dark)`);
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
+ );
2641
2709
  return;
2642
2710
  }
2643
2711
  process.stdout.write(swift);
@@ -2886,7 +2954,7 @@ async function themeBuild(name, options) {
2886
2954
  // package.json
2887
2955
  var package_default = {
2888
2956
  name: "@kinetixui/cli",
2889
- version: "0.23.2",
2957
+ version: "0.23.3",
2890
2958
  description: "Add KinetixUI components and tokens to your project.",
2891
2959
  type: "module",
2892
2960
  license: "MIT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kinetixui/cli",
3
- "version": "0.23.2",
3
+ "version": "0.23.3",
4
4
  "description": "Add KinetixUI components and tokens to your project.",
5
5
  "type": "module",
6
6
  "license": "MIT",