// The SECRET face (Passwords, references `passwords.png`, `passwords-id.png`,// the API key and card cases and the house references 19/49, 20/50, 72 and// 73), on the core's places (KINDS, 0a0a099c3): the framed cream card with// what kind of secret it is typed small where it is not a password (`state`:// "API key", "Card"), its name typed heavy, the site under it, then the facts// down the left on dotted rules — the username, a masked number under its// label, the card's other facts — and when it was last used by hand at the// foot under its label; the old brass key stands along the right, and an// ID's own picture (its scan) is mounted under the heading instead. The// secret itself is never on the card: copying it is an act of the fan.// Every word is the core's (`DeckCard`).importCottonPaperimportCottonValuesimportSwiftUIenumSecretFaceKnobs {staticlet inset = EdgeInsets(top: 28, leading: 26, bottom: 22, trailing: 20)staticlet nameSize: CGFloat = 28/// The most a long name shrinks before it takes its second line.staticlet nameShrink: CGFloat = 0.7staticlet siteSize: CGFloat = 16staticlet siteGap: CGFloat = 8staticlet valueSize: CGFloat = 18staticlet maskSize: CGFloat = 16staticlet maskTracking: CGFloat = 1.5staticlet factsTop: CGFloat = 20staticlet factGap: CGFloat = 10staticlet dateSize: CGFloat = 17staticlet dateRuleGap: CGFloat = 4/// The last-used rule's length, as a share of the card's width.staticlet dateShare: CGFloat = 0.5/// The words' column beside the key, as a share of the card's width.staticlet wordsShare: CGFloat = 0.54/// The name's width over the key's ring, as a share of the card's width.staticlet titleShare: CGFloat = 0.62staticlet artShare: CGFloat = 0.4/// Where the key starts down the card, as a share of its height.staticlet artTop: CGFloat = 0.17staticlet pictureShare: CGFloat = 0.36/// The vault's own line at the foot when this device cannot open it.staticlet sealedSize: CGFloat = 13}publicstructSecretFace<Picture: View>: View {let card: DeckCard/// An ID's scan filling its frame, when the record keeps one.var picture: Picture?publicinit(card: DeckCard, picture: Picture? = nil) {self.card = cardself.picture = picture }publicvar body: someView {GeometryReader { sheet inlet words = picture == nil ? sheet.size.width * SecretFaceKnobs.wordsShare : .infinity ZStack(alignment: .topLeading) {if picture == nil {FaceArt(name: "face-art-key") .frame(width: sheet.size.width * SecretFaceKnobs.artShare) .frame(maxWidth: .infinity, alignment: .trailing) .padding(.top, sheet.size.height * SecretFaceKnobs.artTop) .padding(.trailing, SecretFaceKnobs.inset.trailing) } VStack(alignment: .leading, spacing: 0) {iflet kind = card.text("state") {FaceKind(words: kind) .padding(.bottom, 8) .facePart(.state) }iflet name = card.text("title") {HeavyType(words: name, size: SecretFaceKnobs.nameSize) .lineLimit(2) .minimumScaleFactor(SecretFaceKnobs.nameShrink) .frame(maxWidth: picture == nil ? sheet.size.width * SecretFaceKnobs.titleShare : .infinity, alignment: .leading) .accessibilityIdentifier("deck-title") .facePart(.title) }iflet site = card.text("subtitle") {Text(site) .font(CottonFonts.type(SecretFaceKnobs.siteSize)) .lineLimit(1) .minimumScaleFactor(SecretFaceKnobs.nameShrink) .faceInk(.ink) .frame(maxWidth: words, alignment: .leading) .padding(.top, SecretFaceKnobs.siteGap) .facePart(.subtitle) }iflet picture {MountedPrint(photo: picture) .frame(height: sheet.size.height * SecretFaceKnobs.pictureShare) .padding(.top, 14) .facePart(.picture) } facts .frame(maxWidth: words, alignment: .leading) .padding(.top, SecretFaceKnobs.factsTop)Spacer(minLength: 8)iflet used = card.text("date") { VStack(alignment: .leading, spacing: SecretFaceKnobs.dateRuleGap) {FaceFact(label: card.label("date"), value: used, hand: true, size: SecretFaceKnobs.dateSize)FaceHairline() } .frame(maxWidth: sheet.size.width * SecretFaceKnobs.dateShare, alignment: .leading) .facePart(.when) }// The vault this device cannot open, in its own words:// the card names the secret, its value stays shut.iflet sealed = card.text("sealed") {Text(sealed) .font(CottonFonts.type(SecretFaceKnobs.sealedSize)) .lineLimit(3) .fixedSize(horizontal: false, vertical: true) .faceInk(.pencil) .frame(maxWidth: words, alignment: .leading) .padding(.top, SecretFaceKnobs.factGap) .accessibilityIdentifier("deck-sealed") } } .padding(SecretFaceKnobs.inset)iflet corner = card.corner {RubberStamp(words: corner) .facePart(.when) .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomTrailing) .padding(SecretFaceKnobs.inset) } } } .onCardPaper(SecretFaceCatalogue.stock.laid(card.pace)) }/// The username, a masked number under its label and the card's other/// facts, each closed by a dotted rule.privatevar facts: someView { VStack(alignment: .leading, spacing: SecretFaceKnobs.factGap) {if card.text("body") != nil || card.text("mask") != nil || !StudioReading.facts(card).isEmpty {DottedRule() }iflet user = card.text("body") {FaceFact(value: user, size: SecretFaceKnobs.valueSize, lines: 1) .facePart(.body)DottedRule() }iflet mask = card.text("mask") { VStack(alignment: .leading, spacing: FacePartsKnobs.labelGap) {iflet label = card.label("mask") { FaceLabel(words: label) }Text(mask) .font(CottonFonts.type(SecretFaceKnobs.maskSize)) .tracking(SecretFaceKnobs.maskTracking) .lineLimit(1) .minimumScaleFactor(SecretFaceKnobs.nameShrink) .faceInk(.ink) } .accessibilityElement(children: .combine)DottedRule() }ForEach(Array(StudioReading.facts(card).enumerated()), id: \.offset) { _, fact inFaceFact(label: fact.label, value: fact.said, size: SecretFaceKnobs.maskSize, lines: 1)DottedRule() } } }}/// A rule of dots across the card, between the facts.structDottedRule: View { @Environment(\.theme) privatevar themevar body: someView {Line() .stroke(theme.print(.pencil).opacity(0.5), style: StrokeStyle(lineWidth: 0.9, dash: [1.5, 3])) .frame(height: 1) .blendMode(theme.printBlend) .accessibilityHidden(true) }privatestructLine: Shape {func path(in rect: CGRect) -> Path {var path = Path() path.move(to: CGPoint(x: rect.minX, y: rect.midY)) path.addLine(to: CGPoint(x: rect.maxX, y: rect.midY))return path } }}/// The secret face, by the kind's name, and the cards it is reviewed in. A/// deck draws a secret with no picture: an ID's scan is its own page's.publicenumSecretFaceCatalogue {publicstaticlet stock: FaceStock = .framedpublicstaticlet ground: FaceGround = .paperpublicstaticlet face = Face(id: "secret", specimens: [Specimen("login", login), Specimen("apiKey", apiKey)]) { card, _, _ inSecretFace<EmptyView>(card: card, picture: nil) }publicstaticlet login = DeckCard(face: .secret, fields: ["title": .text("Example Mail"),"subtitle": .text("example.com"),"body": .text("priya@example.com"), ])publicstaticlet apiKey = DeckCard(face: .secret, fields: ["state": .text("API key"),"title": .text("Example Labs"),"subtitle": .text("console.example.com"),"body": .text("priya-dev"), ])}