// The eight paper dyes, and the two other fixed paints a sheet is made of.//// The paper kit's first token. A dye is NOT a palette role: it is the colour of// a piece of paper, measured off the six `paper-*` sheets as// `scripts/gen-cards/export_paper.py` writes them (the mean inside each sheet's// rim, which the exporter prints) — the photographed cards toned toward the bare// paper of the owner's pictures. A photograph is// not a colour, and neither is a paper — `PaletteGuardTests` exempts this file// from the CHANNELS sweep for that sentence and no other.//// WHAT THE MEASUREMENT IS FOR, NOW THAT THE SURFACE IS THE PHOTOGRAPH AGAIN// (`PaperPhoto.swift`): a sheet draws `paper-<dye>` and the measured colour is// what it FALLS BACK to when there is no picture to draw — a Mac without its// resource bundle. It is still the measurement rather than a chosen colour, so// the stand-in is the paper's own tone and is recognisably the same sheet.//// WHY THE NUMBERS ARE THE MEASUREMENT DIVIDED BY `PaperGrain.mean`. The fibre// tile is multiplied over a sheet that has been stretched past its own pixel// density (`PaperGrain.lostToStretch`), and multiplying by 0.96 darkens, so the// paint is the measured colour divided by that one number and the sheet lands// back on the photograph. One constant, in one place, rather than seven// hand-tuned colours that drift apart the first time the tile is re-cut.//// WHICH DYE A RECORD GETS is the todo board's rule, unchanged: a project's cap// colour folded to a paper (`PaperDye.of(_:)`). `newsprint` has no cap and is// never assigned — a news sheet asks for it by name.//// CREAM IS TWO PAPERS. A plain sheet — a note, a statement, a todo's details —// lies AT the page's ground or a hair lighter, the way the pictures draw it; a// todo INDEX CARD reads a shade darker and yellower than the board it lies on,// the way the approved todo reference draws it. One cream cannot do both, so a// card that would be cream is `buff` (`PaperDye.indexCard(_:)`), and every other// dye is the same paper on a card as on a sheet.importSwiftUI/// The papers. The raw value is the todo imageset's name less its `card-`/// prefix, so the six that were photographs answer to the same word they always/// did; `newsprint` was never photographed, and `buff` is the cream card toned/// darker for the todo board.publicenumPaperDye: String, CaseIterable, Sendable {case cream, buff, blue, sage, pink, straw, peach, newsprint/// The paper a project's cap colour dyes; no cap is cream.publicstaticfunc of(_ cap: CapColour?) -> PaperDye {guardlet cap else { return .cream }switch cap {case .navy, .sky: return .bluecase .green, .teal: return .sagecase .red, .pink, .burgundy: return .pinkcase .yellow: return .strawcase .orange: return .peachcase .cream, .silver, .black: return .cream } }/// The paper a todo INDEX CARD is cut from — `of(_:)`, except that cream/// is `buff`, so the card reads darker than the board under it while a/// plain cream sheet sits at the ground. The board card and the open card/// both ask this, so a card does not change paper when it is opened.publicstaticfunc indexCard(_ cap: CapColour?) -> PaperDye {let paper = of(cap)return paper == .cream ? .buff : paper }/// The measured colour of the paper — what a camera read off the master,/// before the grain is multiplied over it. Kept as the measurement so the/// number in the source is the number a re-measurement would print.var measured: (red: Double, green: Double, blue: Double) {switchself {case .cream: return (0.9414, 0.8979, 0.8470)case .buff: return (0.9257, 0.8548, 0.7803)case .blue: return (0.8706, 0.8980, 0.9294)case .sage: return (0.8823, 0.8863, 0.8314)case .pink: return (0.9449, 0.8470, 0.8353)case .straw: return (0.9607, 0.9174, 0.8038)case .peach: return (0.9755, 0.9039, 0.8838)// Cool off-white, read off the sheet in the owner's news reference.case .newsprint: return (0.9021, 0.8940, 0.8705) } }/// The paint a sheet is filled with: the measurement, pre-divided by the/// grain's mean so paint × grain is the measurement.publicvar fill: Color {let paper = measuredreturnSelf.fill(measured: ThemeColor(red: paper.red, green: paper.green, blue: paper.blue)) }/// A paper's fill from its measured colour: the grain multiplies over it,/// so the fill is lifted by the grain's mean to land on the measurement.publicstaticfunc fill(measured paper: ThemeColor) -> Color {Color( red: min(1, paper.red / PaperGrain.mean), green: min(1, paper.green / PaperGrain.mean), blue: min(1, paper.blue / PaperGrain.mean) ) }}/// The one grain tile, and the number every dye is divided by.////// `scripts/gen-cards/export_grain.py` cuts it out of the cream card's master,/// divides out the master's lighting, 4-way mirrors it so it is seamless, and/// normalises it to `mean`. It is written at 3x, which puts the fibre on screen/// at very nearly the frequency the 720 px card photograph shows it at.publicenumPaperGrain {/// The imageset in `Media.xcassets`.publicstaticlet asset = "paper-grain"/// The scale the tile is WRITTEN at, and the scale it must be drawn at on/// either host. 512 px at 3x is a 170.67-point tile, which is the fibre/// frequency the whole kit is tuned to.////// It has to be said out loud because macOS has no 3x, and actool DROPS a/// 3x-only imageset when it compiles for the Mac — which is why the/// shipped Mac app carried no grain at all. The imageset therefore/// declares a `mac` twin at 2x over the SAME 512 px file (the iOS/// catalogue is unchanged: still one universal 3x rendition), and the Mac/// would lay that twin out at 256 points — the paper's weave at half again/// life size on every sheet in the app. So the grain is never read with a/// plain `CottonMedia.image`: it is asked for AT this scale, which sizes/// from the picture's pixels and lands both hosts on the same 170.67/// points. Guards: `ProjectCapsTests`, the grain tile's two tests.publicstaticlet masterScale: CGFloat = 3/// The tile's mean luminance, as the exporter normalises it. A dye's paint/// is its measurement divided by this.publicstaticlet mean: Double = 0.96/// How hard the tile is multiplied on the instant print's white frame,/// which is smooth card rather than fibre — a whisper.////// A sheet's own strength is not a constant any more: the photograph/// carries its fibre, and the tile only puts back what a stretch cost/// (`PaperGrain.lostToStretch`, `PaperGrain.overPhotograph`).publicstaticlet onPrintFrame: Double = 0.45}/// The paints that are not a dye: the instant print's frame, and the corner/// shading every sheet wears.publicenumPaperPaint {/// The white card an instant print is framed in — warm, not paper-white,/// because a print frame photographed on a cream ground never reads as/// 1.0/1.0/1.0. Divided by the grain's mean for the same reason a dye is.publicstaticvar printFrame: Color {Color( red: min(1, 0.9765 / PaperGrain.mean), green: min(1, 0.9686 / PaperGrain.mean), blue: min(1, 0.9490 / PaperGrain.mean) ) }/// The window an instant print's photo sits in before a picture arrives —/// an UNEXPOSED print: pale, warm and flat. Never a mid grey, which reads as/// a photograph that failed to load rather than as a print with nothing on/// it yet, and never a stand-in pretending to be a picture.publicstaticvar printWindow: Color {Color(red: 0.886, green: 0.874, blue: 0.853) }}