You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

407 lines
17 KiB

import SwiftUI
import QRCode
// MARK: -
enum QRCodeColor: String, CaseIterable, Hashable {
case black = "black"
case white = "white"
case red = "red"
case blue = "blue"
case green = "green"
case yellow = "yellow"
case purple = "purple"
case orange = "orange"
case pink = "pink"
case cyan = "cyan"
case magenta = "magenta"
case brown = "brown"
case gray = "gray"
case navy = "navy"
case teal = "teal"
case indigo = "indigo"
case lime = "lime"
case maroon = "maroon"
case olive = "olive"
case silver = "silver"
var color: Color {
switch self {
case .black: return Color(red: 0, green: 0, blue: 0)
case .white: return Color(red: 1, green: 1, blue: 1)
case .red: return Color(red: 1, green: 0, blue: 0)
case .blue: return Color(red: 0, green: 0, blue: 1)
case .green: return Color(red: 0, green: 1, blue: 0)
case .yellow: return Color(red: 1, green: 1, blue: 0)
case .purple: return Color(red: 0.5, green: 0, blue: 0.5)
case .orange: return Color(red: 1, green: 0.5, blue: 0)
case .pink: return Color(red: 1, green: 0.75, blue: 0.8)
case .cyan: return Color(red: 0, green: 1, blue: 1)
case .magenta: return Color(red: 1, green: 0, blue: 1)
case .brown: return Color(red: 0.6, green: 0.4, blue: 0.2)
case .gray: return Color(red: 0.5, green: 0.5, blue: 0.5)
case .navy: return Color(red: 0, green: 0, blue: 0.5)
case .teal: return Color(red: 0, green: 0.5, blue: 0.5)
case .indigo: return Color(red: 0.3, green: 0, blue: 0.5)
case .lime: return Color(red: 0.5, green: 1, blue: 0)
case .maroon: return Color(red: 0.5, green: 0, blue: 0)
case .olive: return Color(red: 0.5, green: 0.5, blue: 0)
case .silver: return Color(red: 0.75, green: 0.75, blue: 0.75)
}
}
var cgColor: CGColor {
return color.cgColor!
}
static var foregroundColors: [QRCodeColor] {
return [.black, .red, .blue, .green, .purple, .orange, .pink, .brown, .navy, .teal, .indigo, .maroon, .olive]
}
static var backgroundColors: [QRCodeColor] {
return [.white, .gray, .silver, .cyan, .yellow, .lime]
}
}
// MARK: -
enum QRCodeDotType: String, CaseIterable, Hashable {
case square = "data_square"
case circle = "data_circle"
case roundedRect = "data_roundedRect"
case squircle = "data_squircle"
case diamond = "data_diamond"
case hexagon = "data_hexagon"
case star = "data_star"
case heart = "data_heart"
case flower = "data_flower"
case gear = "data_gear"
case abstract = "data_abstract"
case arrow = "data_arrow"
case blob = "data_blob"
case circuit = "data_circuit"
case crosshatch = "data_crosshatch"
case crt = "data_crt"
case curvePixel = "data_curvePixel"
case diagonal = "data_diagonal"
case diagonalStripes = "data_diagonalStripes"
case donut = "data_donut"
case dripHorizontal = "data_dripHorizontal"
case dripVertical = "data_dripVertical"
case flame = "data_flame"
case grid2x2 = "data_grid2x2"
case grid3x3 = "data_grid3x3"
case grid4x4 = "data_grid4x4"
case horizontal = "data_horizontal"
case koala = "data_koala"
case pointy = "data_pointy"
case razor = "data_razor"
case roundedEndIndent = "data_roundedEndIndent"
case roundedPath = "data_roundedPath"
case roundedTriangle = "data_roundedTriangle"
case sharp = "data_sharp"
case shiny = "data_shiny"
case spikyCircle = "data_spikyCircle"
case stitch = "data_stitch"
case vertical = "data_vertical"
case vortex = "data_vortex"
case wave = "data_wave"
case wex = "data_wex"
var thumbnailName: String {
return rawValue
}
var displayName: String {
switch self {
case .square: return "square".localized
case .circle: return "circle".localized
case .roundedRect: return "rounded_rect".localized
case .squircle: return "squircle".localized
case .diamond: return "diamond".localized
case .hexagon: return "hexagon".localized
case .star: return "star".localized
case .heart: return "heart".localized
case .flower: return "flower".localized
case .gear: return "gear".localized
case .abstract: return "abstract".localized
case .arrow: return "arrow".localized
case .blob: return "blob".localized
case .circuit: return "circuit".localized
case .crosshatch: return "crosshatch".localized
case .crt: return "CRT"
case .curvePixel: return "curve_pixel".localized
case .diagonal: return "diagonal".localized
case .diagonalStripes: return "diagonal_stripes".localized
case .donut: return "donut".localized
case .dripHorizontal: return "drip_horizontal".localized
case .dripVertical: return "drip_vertical".localized
case .flame: return "flame".localized
case .grid2x2: return "grid_2x2".localized
case .grid3x3: return "grid_3x3".localized
case .grid4x4: return "grid_4x4".localized
case .horizontal: return "horizontal".localized
case .koala: return "koala".localized
case .pointy: return "pointy".localized
case .razor: return "razor".localized
case .roundedEndIndent: return "rounded_end_indent".localized
case .roundedPath: return "rounded_path".localized
case .roundedTriangle: return "rounded_triangle".localized
case .sharp: return "sharp".localized
case .shiny: return "shiny".localized
case .spikyCircle: return "spiky_circle".localized
case .stitch: return "stitch".localized
case .vertical: return "vertical".localized
case .vortex: return "vortex".localized
case .wave: return "wave".localized
case .wex: return "wex".localized
}
}
var pixelShape: QRCodePixelShapeGenerator {
switch self {
case .square: return QRCode.PixelShape.Square()
case .circle: return QRCode.PixelShape.Circle()
case .roundedRect: return QRCode.PixelShape.RoundedRect()
case .squircle: return QRCode.PixelShape.Squircle()
case .diamond: return QRCode.PixelShape.Diamond()
case .hexagon: return QRCode.PixelShape.Hexagon()
case .star: return QRCode.PixelShape.Star()
case .heart: return QRCode.PixelShape.Heart()
case .flower: return QRCode.PixelShape.Flower()
case .gear: return QRCode.PixelShape.Gear()
case .abstract: return QRCode.PixelShape.Abstract()
case .arrow: return QRCode.PixelShape.Arrow()
case .blob: return QRCode.PixelShape.Blob()
case .circuit: return QRCode.PixelShape.Circuit()
case .crosshatch: return QRCode.PixelShape.Crosshatch()
case .crt: return QRCode.PixelShape.CRT()
case .curvePixel: return QRCode.PixelShape.CurvePixel()
case .diagonal: return QRCode.PixelShape.Diagonal()
case .diagonalStripes: return QRCode.PixelShape.DiagonalStripes()
case .donut: return QRCode.PixelShape.Donut()
case .dripHorizontal: return QRCode.PixelShape.DripHorizontal()
case .dripVertical: return QRCode.PixelShape.DripVertical()
case .flame: return QRCode.PixelShape.Flame()
case .grid2x2: return QRCode.PixelShape.Grid2x2()
case .grid3x3: return QRCode.PixelShape.Grid3x3()
case .grid4x4: return QRCode.PixelShape.Grid4x4()
case .horizontal: return QRCode.PixelShape.Horizontal()
case .koala: return QRCode.PixelShape.Koala()
case .pointy: return QRCode.PixelShape.Pointy()
case .razor: return QRCode.PixelShape.Razor()
case .roundedEndIndent: return QRCode.PixelShape.RoundedEndIndent()
case .roundedPath: return QRCode.PixelShape.RoundedPath()
case .roundedTriangle: return QRCode.PixelShape.RoundedTriangle()
case .sharp: return QRCode.PixelShape.Sharp()
case .shiny: return QRCode.PixelShape.Shiny()
case .spikyCircle: return QRCode.PixelShape.SpikyCircle()
case .stitch: return QRCode.PixelShape.Stitch()
case .vertical: return QRCode.PixelShape.Vertical()
case .vortex: return QRCode.PixelShape.Vortex()
case .wave: return QRCode.PixelShape.Wave()
case .wex: return QRCode.PixelShape.Wex()
}
}
}
// MARK: -
enum QRCodeEyeType: String, CaseIterable, Hashable {
case square = "eye_square"
case circle = "eye_circle"
case roundedRect = "eye_roundedRect"
case squircle = "eye_squircle"
case arc = "eye_arc"
case barsHorizontal = "eye_barsHorizontal"
case barsVertical = "eye_barsVertical"
case cloud = "eye_cloud"
case cloudCircle = "eye_cloudCircle"
case corneredPixels = "eye_corneredPixels"
case crt = "eye_crt"
case diagonalStripes = "eye_diagonalStripes"
case dotDragHorizontal = "eye_dotDragHorizontal"
case dotDragVertical = "eye_dotDragVertical"
case edges = "eye_edges"
case explode = "eye_explode"
case eye = "eye_eye"
case fabricScissors = "eye_fabricScissors"
case fireball = "eye_fireball"
case flame = "eye_flame"
case headlight = "eye_headlight"
case holePunch = "eye_holePunch"
case leaf = "eye_leaf"
case peacock = "eye_peacock"
case pinch = "eye_pinch"
case pixels = "eye_pixels"
case roundedOuter = "eye_roundedOuter"
case roundedPointingIn = "eye_roundedPointingIn"
case roundedPointingOut = "eye_roundedPointingOut"
case shield = "eye_shield"
case spikyCircle = "eye_spikyCircle"
case squarePeg = "eye_squarePeg"
case surroundingBars = "eye_surroundingBars"
case teardrop = "eye_teardrop"
case ufo = "eye_ufo"
case ufoRounded = "eye_ufoRounded"
case usePixelShape = "eye_usePixelShape"
var thumbnailName: String {
return rawValue
}
var displayName: String {
switch self {
case .square: return "square".localized
case .circle: return "circle".localized
case .roundedRect: return "rounded_rect".localized
case .squircle: return "squircle".localized
case .arc: return "arc".localized
case .barsHorizontal: return "bars_horizontal".localized
case .barsVertical: return "bars_vertical".localized
case .cloud: return "cloud".localized
case .cloudCircle: return "cloud_circle".localized
case .corneredPixels: return "cornered_pixels".localized
case .crt: return "CRT"
case .diagonalStripes: return "diagonal_stripes".localized
case .dotDragHorizontal: return "dot_drag_horizontal".localized
case .dotDragVertical: return "dot_drag_vertical".localized
case .edges: return "edges".localized
case .explode: return "explode".localized
case .eye: return "eye".localized
case .fabricScissors: return "fabric_scissors".localized
case .fireball: return "fireball".localized
case .flame: return "flame".localized
case .headlight: return "headlight".localized
case .holePunch: return "hole_punch".localized
case .leaf: return "leaf".localized
case .peacock: return "peacock".localized
case .pinch: return "pinch".localized
case .pixels: return "pixels".localized
case .roundedOuter: return "rounded_outer".localized
case .roundedPointingIn: return "rounded_pointing_in".localized
case .roundedPointingOut: return "rounded_pointing_out".localized
case .shield: return "shield".localized
case .spikyCircle: return "spiky_circle".localized
case .squarePeg: return "square_peg".localized
case .surroundingBars: return "surrounding_bars".localized
case .teardrop: return "teardrop".localized
case .ufo: return "ufo".localized
case .ufoRounded: return "ufo_rounded".localized
case .usePixelShape: return "use_pixel_shape".localized
}
}
var eyeShape: QRCodeEyeShapeGenerator {
switch self {
case .square: return QRCode.EyeShape.Square()
case .circle: return QRCode.EyeShape.Circle()
case .roundedRect: return QRCode.EyeShape.RoundedRect()
case .squircle: return QRCode.EyeShape.Squircle()
case .arc: return QRCode.EyeShape.Arc()
case .barsHorizontal: return QRCode.EyeShape.BarsHorizontal()
case .barsVertical: return QRCode.EyeShape.BarsVertical()
case .cloud: return QRCode.EyeShape.Cloud()
case .cloudCircle: return QRCode.EyeShape.CloudCircle()
case .corneredPixels: return QRCode.EyeShape.CorneredPixels()
case .crt: return QRCode.EyeShape.CRT()
case .diagonalStripes: return QRCode.EyeShape.DiagonalStripes()
case .dotDragHorizontal: return QRCode.EyeShape.DotDragHorizontal()
case .dotDragVertical: return QRCode.EyeShape.DotDragVertical()
case .edges: return QRCode.EyeShape.Edges()
case .explode: return QRCode.EyeShape.Explode()
case .eye: return QRCode.EyeShape.Eye()
case .fabricScissors: return QRCode.EyeShape.FabricScissors()
case .fireball: return QRCode.EyeShape.Fireball()
case .flame: return QRCode.EyeShape.Flame()
case .headlight: return QRCode.EyeShape.Headlight()
case .holePunch: return QRCode.EyeShape.HolePunch()
case .leaf: return QRCode.EyeShape.Leaf()
case .peacock: return QRCode.EyeShape.Peacock()
case .pinch: return QRCode.EyeShape.Pinch()
case .pixels: return QRCode.EyeShape.Pixels()
case .roundedOuter: return QRCode.EyeShape.RoundedOuter()
case .roundedPointingIn: return QRCode.EyeShape.RoundedPointingIn()
case .roundedPointingOut: return QRCode.EyeShape.RoundedPointingOut()
case .shield: return QRCode.EyeShape.Shield()
case .spikyCircle: return QRCode.EyeShape.SpikyCircle()
case .squarePeg: return QRCode.EyeShape.SquarePeg()
case .surroundingBars: return QRCode.EyeShape.SurroundingBars()
case .teardrop: return QRCode.EyeShape.Teardrop()
case .ufo: return QRCode.EyeShape.UFO()
case .ufoRounded: return QRCode.EyeShape.UFORounded()
case .usePixelShape: return QRCode.EyeShape.UsePixelShape()
}
}
}
// MARK: - Logo
enum QRCodeLogo: String, CaseIterable, Hashable {
case scanMe = "scanMe"
case gmail = "gmail"
case paypal = "paypal"
case googlePlaystore = "googlePlaystore"
case spotify = "spotify"
case telegram = "telegram"
case whatsApp = "whatsApp"
case linkedIn = "linkedIn"
case tikTok = "tikTok"
case snapchat = "snapchat"
case youtube = "youtube"
case x = "x"
case pinterest = "pinterest"
case instagram = "instagram"
case facebook = "facebook"
var thumbnailName: String {
return rawValue
}
var displayName: String {
switch self {
case .scanMe: return "scan_me".localized
case .gmail: return "gmail".localized
case .paypal: return "paypal".localized
case .googlePlaystore: return "google_playstore".localized
case .spotify: return "spotify".localized
case .telegram: return "telegram".localized
case .whatsApp: return "whats_app".localized
case .linkedIn: return "linked_in".localized
case .tikTok: return "tik_tok".localized
case .snapchat: return "snapchat".localized
case .youtube: return "youtube".localized
case .x: return "x".localized
case .pinterest: return "pinterest".localized
case .instagram: return "instagram".localized
case .facebook: return "facebook".localized
}
}
var image: UIImage? {
// 1: Bundle
if let image = UIImage(named: rawValue) {
return image
}
// 2: logos
if let image = UIImage(named: "logos/\(rawValue)") {
return image
}
// 3: Resources/logos
if let path = Bundle.main.path(forResource: rawValue, ofType: "png", inDirectory: "Resources/logos") {
return UIImage(contentsOfFile: path)
}
// 4: BundleResources
if let _ = Bundle.main.path(forResource: "Resources", ofType: nil),
let imagePath = Bundle.main.path(forResource: rawValue, ofType: "png", inDirectory: "logos") {
return UIImage(contentsOfFile: imagePath)
}
// 5: Assets.xcassets
if let image = UIImage(named: rawValue, in: Bundle.main, with: nil) {
return image
}
return nil
}
}