2021/05/31

Tailwindcssで定義されている色からSwiftUI版の定義を自動生成する

swiftuiswift

Webアプリでは、普段Tailwindcssを重宝しています。とても便利なCSSライブラリです。

colors.jsで定義されている便利な色たちをSwiftUIアプリでも利用したいので、jsonで定義されている色をSwiftUIの定義に変換するスクリプトを作りました。

できたものはこちらです。

import SwiftUI

extension Color {
    init(hex: Int, alpha: Double = 1) {
        let components = (
            R: Double((hex >> 16) & 0xff) / 255,
            G: Double((hex >> 08) & 0xff) / 255,
            B: Double((hex >> 00) & 0xff) / 255
        )
        self.init(
            .sRGB,
            red: components.R,
            green: components.G,
            blue: components.B,
            opacity: alpha
        )
    }
    
    public static var Primary100: Color {
        .LightBlue100
    }
    public static var Primary500: Color {
        .LightBlue500
    }
    public static var Primary600: Color {
        .LightBlue600
    }
    public static var Primary800: Color {
        .LightBlue800
    }
    public static var Black: Color {
        Color(hex: 0x000000)
    }
    public static var White: Color {
        Color(hex: 0xffffff)
    }
    public static var Rose50: Color {
        Color(hex: 0xfff1f2)
    }
    public static var Rose100: Color {
        Color(hex: 0xffe4e6)
    }
    public static var Rose200: Color {
        Color(hex: 0xfecdd3)
    }
    public static var Rose300: Color {
        Color(hex: 0xfda4af)
    }
    public static var Rose400: Color {
        Color(hex: 0xfb7185)
    }
    public static var Rose500: Color {
        Color(hex: 0xf43f5e)
    }
    public static var Rose600: Color {
        Color(hex: 0xe11d48)
    }
    public static var Rose700: Color {
        Color(hex: 0xbe123c)
    }
    public static var Rose800: Color {
        Color(hex: 0x9f1239)
    }
    public static var Rose900: Color {
        Color(hex: 0x881337)
    }
    public static var Pink50: Color {
        Color(hex: 0xfdf2f8)
    }
    public static var Pink100: Color {
        Color(hex: 0xfce7f3)
    }
    public static var Pink200: Color {
        Color(hex: 0xfbcfe8)
    }
    public static var Pink300: Color {
        Color(hex: 0xf9a8d4)
    }
    public static var Pink400: Color {
        Color(hex: 0xf472b6)
    }
    public static var Pink500: Color {
        Color(hex: 0xec4899)
    }
    public static var Pink600: Color {
        Color(hex: 0xdb2777)
    }
    public static var Pink700: Color {
        Color(hex: 0xbe185d)
    }
    public static var Pink800: Color {
        Color(hex: 0x9d174d)
    }
    public static var Pink900: Color {
        Color(hex: 0x831843)
    }
    public static var Fuchsia50: Color {
        Color(hex: 0xfdf4ff)
    }
    public static var Fuchsia100: Color {
        Color(hex: 0xfae8ff)
    }
    public static var Fuchsia200: Color {
        Color(hex: 0xf5d0fe)
    }
    public static var Fuchsia300: Color {
        Color(hex: 0xf0abfc)
    }
    public static var Fuchsia400: Color {
        Color(hex: 0xe879f9)
    }
    public static var Fuchsia500: Color {
        Color(hex: 0xd946ef)
    }
    public static var Fuchsia600: Color {
        Color(hex: 0xc026d3)
    }
    public static var Fuchsia700: Color {
        Color(hex: 0xa21caf)
    }
    public static var Fuchsia800: Color {
        Color(hex: 0x86198f)
    }
    public static var Fuchsia900: Color {
        Color(hex: 0x701a75)
    }
    public static var Purple50: Color {
        Color(hex: 0xfaf5ff)
    }
    public static var Purple100: Color {
        Color(hex: 0xf3e8ff)
    }
    public static var Purple200: Color {
        Color(hex: 0xe9d5ff)
    }
    public static var Purple300: Color {
        Color(hex: 0xd8b4fe)
    }
    public static var Purple400: Color {
        Color(hex: 0xc084fc)
    }
    public static var Purple500: Color {
        Color(hex: 0xa855f7)
    }
    public static var Purple600: Color {
        Color(hex: 0x9333ea)
    }
    public static var Purple700: Color {
        Color(hex: 0x7e22ce)
    }
    public static var Purple800: Color {
        Color(hex: 0x6b21a8)
    }
    public static var Purple900: Color {
        Color(hex: 0x581c87)
    }
    public static var Violet50: Color {
        Color(hex: 0xf5f3ff)
    }
    public static var Violet100: Color {
        Color(hex: 0xede9fe)
    }
    public static var Violet200: Color {
        Color(hex: 0xddd6fe)
    }
    public static var Violet300: Color {
        Color(hex: 0xc4b5fd)
    }
    public static var Violet400: Color {
        Color(hex: 0xa78bfa)
    }
    public static var Violet500: Color {
        Color(hex: 0x8b5cf6)
    }
    public static var Violet600: Color {
        Color(hex: 0x7c3aed)
    }
    public static var Violet700: Color {
        Color(hex: 0x6d28d9)
    }
    public static var Violet800: Color {
        Color(hex: 0x5b21b6)
    }
    public static var Violet900: Color {
        Color(hex: 0x4c1d95)
    }
    public static var Indigo50: Color {
        Color(hex: 0xeef2ff)
    }
    public static var Indigo100: Color {
        Color(hex: 0xe0e7ff)
    }
    public static var Indigo200: Color {
        Color(hex: 0xc7d2fe)
    }
    public static var Indigo300: Color {
        Color(hex: 0xa5b4fc)
    }
    public static var Indigo400: Color {
        Color(hex: 0x818cf8)
    }
    public static var Indigo500: Color {
        Color(hex: 0x6366f1)
    }
    public static var Indigo600: Color {
        Color(hex: 0x4f46e5)
    }
    public static var Indigo700: Color {
        Color(hex: 0x4338ca)
    }
    public static var Indigo800: Color {
        Color(hex: 0x3730a3)
    }
    public static var Indigo900: Color {
        Color(hex: 0x312e81)
    }
    public static var Blue50: Color {
        Color(hex: 0xeff6ff)
    }
    public static var Blue100: Color {
        Color(hex: 0xdbeafe)
    }
    public static var Blue200: Color {
        Color(hex: 0xbfdbfe)
    }
    public static var Blue300: Color {
        Color(hex: 0x93c5fd)
    }
    public static var Blue400: Color {
        Color(hex: 0x60a5fa)
    }
    public static var Blue500: Color {
        Color(hex: 0x3b82f6)
    }
    public static var Blue600: Color {
        Color(hex: 0x2563eb)
    }
    public static var Blue700: Color {
        Color(hex: 0x1d4ed8)
    }
    public static var Blue800: Color {
        Color(hex: 0x1e40af)
    }
    public static var Blue900: Color {
        Color(hex: 0x1e3a8a)
    }
    public static var LightBlue50: Color {
        Color(hex: 0xf0f9ff)
    }
    public static var LightBlue100: Color {
        Color(hex: 0xe0f2fe)
    }
    public static var LightBlue200: Color {
        Color(hex: 0xbae6fd)
    }
    public static var LightBlue300: Color {
        Color(hex: 0x7dd3fc)
    }
    public static var LightBlue400: Color {
        Color(hex: 0x38bdf8)
    }
    public static var LightBlue500: Color {
        Color(hex: 0x0ea5e9)
    }
    public static var LightBlue600: Color {
        Color(hex: 0x0284c7)
    }
    public static var LightBlue700: Color {
        Color(hex: 0x0369a1)
    }
    public static var LightBlue800: Color {
        Color(hex: 0x075985)
    }
    public static var LightBlue900: Color {
        Color(hex: 0x0c4a6e)
    }
    public static var Cyan50: Color {
        Color(hex: 0xecfeff)
    }
    public static var Cyan100: Color {
        Color(hex: 0xcffafe)
    }
    public static var Cyan200: Color {
        Color(hex: 0xa5f3fc)
    }
    public static var Cyan300: Color {
        Color(hex: 0x67e8f9)
    }
    public static var Cyan400: Color {
        Color(hex: 0x22d3ee)
    }
    public static var Cyan500: Color {
        Color(hex: 0x06b6d4)
    }
    public static var Cyan600: Color {
        Color(hex: 0x0891b2)
    }
    public static var Cyan700: Color {
        Color(hex: 0x0e7490)
    }
    public static var Cyan800: Color {
        Color(hex: 0x155e75)
    }
    public static var Cyan900: Color {
        Color(hex: 0x164e63)
    }
    public static var Teal50: Color {
        Color(hex: 0xf0fdfa)
    }
    public static var Teal100: Color {
        Color(hex: 0xccfbf1)
    }
    public static var Teal200: Color {
        Color(hex: 0x99f6e4)
    }
    public static var Teal300: Color {
        Color(hex: 0x5eead4)
    }
    public static var Teal400: Color {
        Color(hex: 0x2dd4bf)
    }
    public static var Teal500: Color {
        Color(hex: 0x14b8a6)
    }
    public static var Teal600: Color {
        Color(hex: 0x0d9488)
    }
    public static var Teal700: Color {
        Color(hex: 0x0f766e)
    }
    public static var Teal800: Color {
        Color(hex: 0x115e59)
    }
    public static var Teal900: Color {
        Color(hex: 0x134e4a)
    }
    public static var Emerald50: Color {
        Color(hex: 0xecfdf5)
    }
    public static var Emerald100: Color {
        Color(hex: 0xd1fae5)
    }
    public static var Emerald200: Color {
        Color(hex: 0xa7f3d0)
    }
    public static var Emerald300: Color {
        Color(hex: 0x6ee7b7)
    }
    public static var Emerald400: Color {
        Color(hex: 0x34d399)
    }
    public static var Emerald500: Color {
        Color(hex: 0x10b981)
    }
    public static var Emerald600: Color {
        Color(hex: 0x059669)
    }
    public static var Emerald700: Color {
        Color(hex: 0x047857)
    }
    public static var Emerald800: Color {
        Color(hex: 0x065f46)
    }
    public static var Emerald900: Color {
        Color(hex: 0x064e3b)
    }
    public static var Green50: Color {
        Color(hex: 0xf0fdf4)
    }
    public static var Green100: Color {
        Color(hex: 0xdcfce7)
    }
    public static var Green200: Color {
        Color(hex: 0xbbf7d0)
    }
    public static var Green300: Color {
        Color(hex: 0x86efac)
    }
    public static var Green400: Color {
        Color(hex: 0x4ade80)
    }
    public static var Green500: Color {
        Color(hex: 0x22c55e)
    }
    public static var Green600: Color {
        Color(hex: 0x16a34a)
    }
    public static var Green700: Color {
        Color(hex: 0x15803d)
    }
    public static var Green800: Color {
        Color(hex: 0x166534)
    }
    public static var Green900: Color {
        Color(hex: 0x14532d)
    }
    public static var Lime50: Color {
        Color(hex: 0xf7fee7)
    }
    public static var Lime100: Color {
        Color(hex: 0xecfccb)
    }
    public static var Lime200: Color {
        Color(hex: 0xd9f99d)
    }
    public static var Lime300: Color {
        Color(hex: 0xbef264)
    }
    public static var Lime400: Color {
        Color(hex: 0xa3e635)
    }
    public static var Lime500: Color {
        Color(hex: 0x84cc16)
    }
    public static var Lime600: Color {
        Color(hex: 0x65a30d)
    }
    public static var Lime700: Color {
        Color(hex: 0x4d7c0f)
    }
    public static var Lime800: Color {
        Color(hex: 0x3f6212)
    }
    public static var Lime900: Color {
        Color(hex: 0x365314)
    }
    public static var Yellow50: Color {
        Color(hex: 0xfefce8)
    }
    public static var Yellow100: Color {
        Color(hex: 0xfef9c3)
    }
    public static var Yellow200: Color {
        Color(hex: 0xfef08a)
    }
    public static var Yellow300: Color {
        Color(hex: 0xfde047)
    }
    public static var Yellow400: Color {
        Color(hex: 0xfacc15)
    }
    public static var Yellow500: Color {
        Color(hex: 0xeab308)
    }
    public static var Yellow600: Color {
        Color(hex: 0xca8a04)
    }
    public static var Yellow700: Color {
        Color(hex: 0xa16207)
    }
    public static var Yellow800: Color {
        Color(hex: 0x854d0e)
    }
    public static var Yellow900: Color {
        Color(hex: 0x713f12)
    }
    public static var Amber50: Color {
        Color(hex: 0xfffbeb)
    }
    public static var Amber100: Color {
        Color(hex: 0xfef3c7)
    }
    public static var Amber200: Color {
        Color(hex: 0xfde68a)
    }
    public static var Amber300: Color {
        Color(hex: 0xfcd34d)
    }
    public static var Amber400: Color {
        Color(hex: 0xfbbf24)
    }
    public static var Amber500: Color {
        Color(hex: 0xf59e0b)
    }
    public static var Amber600: Color {
        Color(hex: 0xd97706)
    }
    public static var Amber700: Color {
        Color(hex: 0xb45309)
    }
    public static var Amber800: Color {
        Color(hex: 0x92400e)
    }
    public static var Amber900: Color {
        Color(hex: 0x78350f)
    }
    public static var Orange50: Color {
        Color(hex: 0xfff7ed)
    }
    public static var Orange100: Color {
        Color(hex: 0xffedd5)
    }
    public static var Orange200: Color {
        Color(hex: 0xfed7aa)
    }
    public static var Orange300: Color {
        Color(hex: 0xfdba74)
    }
    public static var Orange400: Color {
        Color(hex: 0xfb923c)
    }
    public static var Orange500: Color {
        Color(hex: 0xf97316)
    }
    public static var Orange600: Color {
        Color(hex: 0xea580c)
    }
    public static var Orange700: Color {
        Color(hex: 0xc2410c)
    }
    public static var Orange800: Color {
        Color(hex: 0x9a3412)
    }
    public static var Orange900: Color {
        Color(hex: 0x7c2d12)
    }
    public static var Red50: Color {
        Color(hex: 0xfef2f2)
    }
    public static var Red100: Color {
        Color(hex: 0xfee2e2)
    }
    public static var Red200: Color {
        Color(hex: 0xfecaca)
    }
    public static var Red300: Color {
        Color(hex: 0xfca5a5)
    }
    public static var Red400: Color {
        Color(hex: 0xf87171)
    }
    public static var Red500: Color {
        Color(hex: 0xef4444)
    }
    public static var Red600: Color {
        Color(hex: 0xdc2626)
    }
    public static var Red700: Color {
        Color(hex: 0xb91c1c)
    }
    public static var Red800: Color {
        Color(hex: 0x991b1b)
    }
    public static var Red900: Color {
        Color(hex: 0x7f1d1d)
    }
    public static var WarmGray50: Color {
        Color(hex: 0xfafaf9)
    }
    public static var WarmGray100: Color {
        Color(hex: 0xf5f5f4)
    }
    public static var WarmGray200: Color {
        Color(hex: 0xe7e5e4)
    }
    public static var WarmGray300: Color {
        Color(hex: 0xd6d3d1)
    }
    public static var WarmGray400: Color {
        Color(hex: 0xa8a29e)
    }
    public static var WarmGray500: Color {
        Color(hex: 0x78716c)
    }
    public static var WarmGray600: Color {
        Color(hex: 0x57534e)
    }
    public static var WarmGray700: Color {
        Color(hex: 0x44403c)
    }
    public static var WarmGray800: Color {
        Color(hex: 0x292524)
    }
    public static var WarmGray900: Color {
        Color(hex: 0x1c1917)
    }
    public static var TrueGray50: Color {
        Color(hex: 0xfafafa)
    }
    public static var TrueGray100: Color {
        Color(hex: 0xf5f5f5)
    }
    public static var TrueGray200: Color {
        Color(hex: 0xe5e5e5)
    }
    public static var TrueGray300: Color {
        Color(hex: 0xd4d4d4)
    }
    public static var TrueGray400: Color {
        Color(hex: 0xa3a3a3)
    }
    public static var TrueGray500: Color {
        Color(hex: 0x737373)
    }
    public static var TrueGray600: Color {
        Color(hex: 0x525252)
    }
    public static var TrueGray700: Color {
        Color(hex: 0x404040)
    }
    public static var TrueGray800: Color {
        Color(hex: 0x262626)
    }
    public static var TrueGray900: Color {
        Color(hex: 0x171717)
    }
    public static var Gray50: Color {
        Color(hex: 0xfafafa)
    }
    public static var Gray100: Color {
        Color(hex: 0xf4f4f5)
    }
    public static var Gray200: Color {
        Color(hex: 0xe4e4e7)
    }
    public static var Gray300: Color {
        Color(hex: 0xd4d4d8)
    }
    public static var Gray400: Color {
        Color(hex: 0xa1a1aa)
    }
    public static var Gray500: Color {
        Color(hex: 0x71717a)
    }
    public static var Gray600: Color {
        Color(hex: 0x52525b)
    }
    public static var Gray700: Color {
        Color(hex: 0x3f3f46)
    }
    public static var Gray800: Color {
        Color(hex: 0x27272a)
    }
    public static var Gray900: Color {
        Color(hex: 0x18181b)
    }
    public static var CoolGray50: Color {
        Color(hex: 0xf9fafb)
    }
    public static var CoolGray100: Color {
        Color(hex: 0xf3f4f6)
    }
    public static var CoolGray200: Color {
        Color(hex: 0xe5e7eb)
    }
    public static var CoolGray300: Color {
        Color(hex: 0xd1d5db)
    }
    public static var CoolGray400: Color {
        Color(hex: 0x9ca3af)
    }
    public static var CoolGray500: Color {
        Color(hex: 0x6b7280)
    }
    public static var CoolGray600: Color {
        Color(hex: 0x4b5563)
    }
    public static var CoolGray700: Color {
        Color(hex: 0x374151)
    }
    public static var CoolGray800: Color {
        Color(hex: 0x1f2937)
    }
    public static var CoolGray900: Color {
        Color(hex: 0x111827)
    }
    public static var BlueGray50: Color {
        Color(hex: 0xf8fafc)
    }
    public static var BlueGray100: Color {
        Color(hex: 0xf1f5f9)
    }
    public static var BlueGray200: Color {
        Color(hex: 0xe2e8f0)
    }
    public static var BlueGray300: Color {
        Color(hex: 0xcbd5e1)
    }
    public static var BlueGray400: Color {
        Color(hex: 0x94a3b8)
    }
    public static var BlueGray500: Color {
        Color(hex: 0x64748b)
    }
    public static var BlueGray600: Color {
        Color(hex: 0x475569)
    }
    public static var BlueGray700: Color {
        Color(hex: 0x334155)
    }
    public static var BlueGray800: Color {
        Color(hex: 0x1e293b)
    }
    public static var BlueGray900: Color {
        Color(hex: 0x0f172a)
    }
}

作り方

ここの定義を元に作成します。

javascriptでパースしてSwiftUIで使うColorの定義を出力します。
以下のscriptを動かします。(ブラウザの開発ツールのコンソールで動きます。)

var colors = {
  black: '#000',
  white: '#fff',
  rose: {
    50: '#fff1f2',
    100: '#ffe4e6',
    200: '#fecdd3',
    300: '#fda4af',
    400: '#fb7185',
    500: '#f43f5e',
    600: '#e11d48',
    700: '#be123c',
    800: '#9f1239',
    900: '#881337',
  },
  pink: {
    50: '#fdf2f8',
    100: '#fce7f3',
    200: '#fbcfe8',
    300: '#f9a8d4',
    400: '#f472b6',
    500: '#ec4899',
    600: '#db2777',
    700: '#be185d',
    800: '#9d174d',
    900: '#831843',
  },
  fuchsia: {
    50: '#fdf4ff',
    100: '#fae8ff',
    200: '#f5d0fe',
    300: '#f0abfc',
    400: '#e879f9',
    500: '#d946ef',
    600: '#c026d3',
    700: '#a21caf',
    800: '#86198f',
    900: '#701a75',
  },
  purple: {
    50: '#faf5ff',
    100: '#f3e8ff',
    200: '#e9d5ff',
    300: '#d8b4fe',
    400: '#c084fc',
    500: '#a855f7',
    600: '#9333ea',
    700: '#7e22ce',
    800: '#6b21a8',
    900: '#581c87',
  },
  violet: {
    50: '#f5f3ff',
    100: '#ede9fe',
    200: '#ddd6fe',
    300: '#c4b5fd',
    400: '#a78bfa',
    500: '#8b5cf6',
    600: '#7c3aed',
    700: '#6d28d9',
    800: '#5b21b6',
    900: '#4c1d95',
  },
  indigo: {
    50: '#eef2ff',
    100: '#e0e7ff',
    200: '#c7d2fe',
    300: '#a5b4fc',
    400: '#818cf8',
    500: '#6366f1',
    600: '#4f46e5',
    700: '#4338ca',
    800: '#3730a3',
    900: '#312e81',
  },
  blue: {
    50: '#eff6ff',
    100: '#dbeafe',
    200: '#bfdbfe',
    300: '#93c5fd',
    400: '#60a5fa',
    500: '#3b82f6',
    600: '#2563eb',
    700: '#1d4ed8',
    800: '#1e40af',
    900: '#1e3a8a',
  },
  lightBlue: {
    50: '#f0f9ff',
    100: '#e0f2fe',
    200: '#bae6fd',
    300: '#7dd3fc',
    400: '#38bdf8',
    500: '#0ea5e9',
    600: '#0284c7',
    700: '#0369a1',
    800: '#075985',
    900: '#0c4a6e',
  },
  cyan: {
    50: '#ecfeff',
    100: '#cffafe',
    200: '#a5f3fc',
    300: '#67e8f9',
    400: '#22d3ee',
    500: '#06b6d4',
    600: '#0891b2',
    700: '#0e7490',
    800: '#155e75',
    900: '#164e63',
  },
  teal: {
    50: '#f0fdfa',
    100: '#ccfbf1',
    200: '#99f6e4',
    300: '#5eead4',
    400: '#2dd4bf',
    500: '#14b8a6',
    600: '#0d9488',
    700: '#0f766e',
    800: '#115e59',
    900: '#134e4a',
  },
  emerald: {
    50: '#ecfdf5',
    100: '#d1fae5',
    200: '#a7f3d0',
    300: '#6ee7b7',
    400: '#34d399',
    500: '#10b981',
    600: '#059669',
    700: '#047857',
    800: '#065f46',
    900: '#064e3b',
  },
  green: {
    50: '#f0fdf4',
    100: '#dcfce7',
    200: '#bbf7d0',
    300: '#86efac',
    400: '#4ade80',
    500: '#22c55e',
    600: '#16a34a',
    700: '#15803d',
    800: '#166534',
    900: '#14532d',
  },
  lime: {
    50: '#f7fee7',
    100: '#ecfccb',
    200: '#d9f99d',
    300: '#bef264',
    400: '#a3e635',
    500: '#84cc16',
    600: '#65a30d',
    700: '#4d7c0f',
    800: '#3f6212',
    900: '#365314',
  },
  yellow: {
    50: '#fefce8',
    100: '#fef9c3',
    200: '#fef08a',
    300: '#fde047',
    400: '#facc15',
    500: '#eab308',
    600: '#ca8a04',
    700: '#a16207',
    800: '#854d0e',
    900: '#713f12',
  },
  amber: {
    50: '#fffbeb',
    100: '#fef3c7',
    200: '#fde68a',
    300: '#fcd34d',
    400: '#fbbf24',
    500: '#f59e0b',
    600: '#d97706',
    700: '#b45309',
    800: '#92400e',
    900: '#78350f',
  },
  orange: {
    50: '#fff7ed',
    100: '#ffedd5',
    200: '#fed7aa',
    300: '#fdba74',
    400: '#fb923c',
    500: '#f97316',
    600: '#ea580c',
    700: '#c2410c',
    800: '#9a3412',
    900: '#7c2d12',
  },
  red: {
    50: '#fef2f2',
    100: '#fee2e2',
    200: '#fecaca',
    300: '#fca5a5',
    400: '#f87171',
    500: '#ef4444',
    600: '#dc2626',
    700: '#b91c1c',
    800: '#991b1b',
    900: '#7f1d1d',
  },
  warmGray: {
    50: '#fafaf9',
    100: '#f5f5f4',
    200: '#e7e5e4',
    300: '#d6d3d1',
    400: '#a8a29e',
    500: '#78716c',
    600: '#57534e',
    700: '#44403c',
    800: '#292524',
    900: '#1c1917',
  },
  trueGray: {
    50: '#fafafa',
    100: '#f5f5f5',
    200: '#e5e5e5',
    300: '#d4d4d4',
    400: '#a3a3a3',
    500: '#737373',
    600: '#525252',
    700: '#404040',
    800: '#262626',
    900: '#171717',
  },
  gray: {
    50: '#fafafa',
    100: '#f4f4f5',
    200: '#e4e4e7',
    300: '#d4d4d8',
    400: '#a1a1aa',
    500: '#71717a',
    600: '#52525b',
    700: '#3f3f46',
    800: '#27272a',
    900: '#18181b',
  },
  coolGray: {
    50: '#f9fafb',
    100: '#f3f4f6',
    200: '#e5e7eb',
    300: '#d1d5db',
    400: '#9ca3af',
    500: '#6b7280',
    600: '#4b5563',
    700: '#374151',
    800: '#1f2937',
    900: '#111827',
  },
  blueGray: {
    50: '#f8fafc',
    100: '#f1f5f9',
    200: '#e2e8f0',
    300: '#cbd5e1',
    400: '#94a3b8',
    500: '#64748b',
    600: '#475569',
    700: '#334155',
    800: '#1e293b',
    900: '#0f172a',
  },
};

function Color(category, strongValue, hexValue) {
  this.category = category;
  this.strongValue = strongValue;
  this.hexValue = hexValue;

  this.getCategoryName = function() {
    return this.category.charAt(0).toUpperCase() + this.category.slice(1)
  };

  this.strength = function() {
    return this.strongValue || ''
  };

  this.hexForSwift = function() {
    var hex = this.hexValue.replace('#', '');
    if (hex.length === 3) {
      hex = `${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}`
    }
    return `${hex}`
  }

  this.asSwiftUIColor = function() {
    var result = `public static var ${this.getCategoryName()}${this.strength()}: Color {\n`
    result += `    Color(hex: 0x${this.hexForSwift()})\n`
    result += '}'
    return result
  };
};

// val Black = Color(0xff000000)...
(function(colors) {
  Object.keys(colors).forEach(function (category) {
    switch (category) {
      case 'black':
      case 'white':
        var color = new Color(category, undefined, colors[category]);
        console.log(color.asSwiftUIColor());
        break;
      default:
        Object.keys(colors[category]).forEach(function(strongValue) {
          var color = new Color(category, strongValue, colors[category][strongValue])
          console.log(color.asSwiftUIColor());
        });
        break;
    }
  });
})(colors);

16進数をColorに変換する

16進数の数値からSwiftUIのColorに変換するコンストラクターは事前に定義しておきます。(以下)

extension Color {
    init(hex: Int, alpha: Double = 1) {
        let components = (
            R: Double((hex >> 16) & 0xff) / 255,
            G: Double((hex >> 08) & 0xff) / 255,
            B: Double((hex >> 00) & 0xff) / 255
        )
        self.init(
            .sRGB,
            red: components.R,
            green: components.G,
            blue: components.B,
            opacity: alpha
        )
    }
}

javascriptで出力したものを上記と合わせて完成になります。

以上です。