// The parts Cotton Story's faces share (contract, 17 Nov 2026): the flat// sheet a card is laid on, a line of a scene as the core read it, and that// line drawn the way a screenplay lays it. No face is declared here.importCottonPaperimportCottonValuesimportSwiftUIenumStoryCardKnobs {staticlet corner: CGFloat = 14staticlet inset = EdgeInsets(top: 22, leading: 22, bottom: 20, trailing: 22)staticlet gap: CGFloat = 12staticlet hairline: CGFloat = 1/// How far down a card the scene's lines fade out, from the bottom.staticlet fade: CGFloat = 56}/// A card's flat sheet: the sheet tone on the ground, a hairline round it,/// nothing painted.structStorySheet: ViewModifier {func body(content: Content) -> someView { content .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) .background(RoundedRectangle(cornerRadius: StoryCardKnobs.corner, style: .continuous) .fill(StoryMaterial.sheet.colour) ) .overlay(RoundedRectangle(cornerRadius: StoryCardKnobs.corner, style: .continuous) .strokeBorder(StoryMaterial.hairline.colour, lineWidth: StoryCardKnobs.hairline) ) .clipShape(RoundedRectangle(cornerRadius: StoryCardKnobs.corner, style: .continuous)) }}extensionView {func storySheet() -> someView { modifier(StorySheet()) }/// Fades the bottom of a part that may run past the card, so a long/// scene ends softly rather than cut through a line.func storyFadesOut() -> someView { mask( VStack(spacing: 0) {Rectangle()LinearGradient(colors: [.black, .clear], startPoint: .top, endPoint: .bottom) .frame(height: StoryCardKnobs.fade) } ) }}/// One line of a scene as the core read it (`story.lines`): its kind and its/// words. The card carries them under `lines` (a list of `{kind, text}`);/// a card without them is drawn from its body, every line as action.publicstructStoryLine: Equatable, Sendable {publicenumKind: String, Sendable, Codable {case action, character, dialogue, parenthetical, transition, heading, centered, note, blank }publiclet kind: Kindpubliclet text: Stringpublicinit(_ kind: Kind, _ text: String) {self.kind = kindself.text = text }/// The card's lines: `lines` as the core read them, else its body's/// lines as action, blank lines kept.staticfunc of(_ card: DeckCard) -> [StoryLine] {ifcase .list(let rows)? = card.fields["lines"] {return rows.compactMap { row inguardcase .object(let fields) = row,let kind = fields["kind"]?.text.flatMap(Kind.init(rawValue:)) else { returnnil }returnStoryLine(kind, fields["text"]?.text ?? "") } }guardlet body = card.text("body") else { return [] }return body.components(separatedBy: "\n").map { line in line.trimmingCharacters(in: .whitespaces).isEmpty ? StoryLine(.blank, "") : StoryLine(.action, line) } }/// Lines as the fields a specimen card carries.staticfunc fields(_ lines: [StoryLine]) -> RecordValue { .list(lines.map { .object(["kind": .text($0.kind.rawValue), "text": .text($0.text)]) }) }}/// A scene's lines laid out as a screenplay, small: names centred, speech in/// its narrower column, asides indented, cuts to the right.structStoryScriptLines: View {let lines: [StoryLine]let size: CGFloatvar body: someView {GeometryReader { box in VStack(alignment: .leading, spacing: size * 0.25) {ForEach(Array(lines.enumerated()), id: \.offset) { _, line in row(line, width: box.size.width) } } .frame(width: box.size.width, alignment: .topLeading) } } @ViewBuilderprivatefunc row(_ line: StoryLine, width: CGFloat) -> someView {let font = StoryType.script(size)switch line.kind {case .blank:Color.clear.frame(height: size * 0.3)case .character:Text(verbatim: line.text) .font(font) .foregroundStyle(StoryMaterial.ink.colour) .frame(width: width) .multilineTextAlignment(.center)case .dialogue:Text(verbatim: line.text) .font(font) .foregroundStyle(StoryMaterial.ink.colour) .frame(width: width * 0.72, alignment: .leading) .padding(.leading, width * 0.14)case .parenthetical:Text(verbatim: line.text) .font(font) .foregroundStyle(StoryMaterial.quiet.colour) .frame(width: width * 0.56, alignment: .leading) .padding(.leading, width * 0.22)case .transition:Text(verbatim: line.text) .font(font) .foregroundStyle(StoryMaterial.ink.colour) .frame(width: width, alignment: .trailing)case .centered:Text(verbatim: line.text) .font(font) .foregroundStyle(StoryMaterial.ink.colour) .frame(width: width) .multilineTextAlignment(.center)case .heading:Text(verbatim: line.text) .font(font.bold()) .foregroundStyle(StoryMaterial.ink.colour) .frame(width: width, alignment: .leading)case .note:Text(verbatim: line.text) .font(font.italic()) .foregroundStyle(StoryMaterial.quiet.colour) .frame(width: width, alignment: .leading)case .action:Text(verbatim: line.text) .font(font) .foregroundStyle(StoryMaterial.ink.colour) .frame(width: width, alignment: .leading) } }}/// The small line at the top of a card: a scene's number, a status.structStoryQuietLine: View {let text: Stringvar body: someView {Text(verbatim: text) .font(StoryType.sans(.footnote, weight: .medium)) .foregroundStyle(StoryMaterial.quiet.colour) .fixedSize(horizontal: false, vertical: true) }}