@backgold/template-kit 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +12 -2
- package/dist/chunk-KOB36GSF.js +62 -0
- package/dist/constants-DvTNj4JI.d-Batjcj3Z.d.ts +38 -0
- package/dist/content-api-CYeY0vU8.d.ts +849 -0
- package/dist/contract/content-api-examples.d.ts +58 -0
- package/dist/contract/content-api-examples.js +783 -0
- package/dist/contract/content-api.d.ts +2 -0
- package/dist/contract/content-api.js +1 -0
- package/dist/contract/site-templates.d.ts +252 -0
- package/dist/contract/site-templates.js +185 -0
- package/package.json +70 -3
- package/src/components/EntryCard.astro +35 -0
- package/src/components/EventMap.astro +118 -0
- package/src/components/EventPage.astro +194 -0
- package/src/components/FieldValue.astro +41 -0
- package/src/components/LeadingHero.astro +21 -0
- package/src/components/NotFound.astro +20 -0
- package/src/components/PageSections.astro +47 -0
- package/src/components/Prose.astro +18 -0
- package/src/components/chrome/Brand.astro +54 -0
- package/src/components/chrome/ClosingCall.astro +94 -0
- package/src/components/chrome/DonateStrip.astro +61 -0
- package/src/components/chrome/FooterColumns.astro +32 -0
- package/src/components/chrome/FooterContact.astro +28 -0
- package/src/components/chrome/MenuList.astro +45 -0
- package/src/components/chrome/ModeToggle.astro +125 -0
- package/src/components/chrome/SignedInNotice.astro +53 -0
- package/src/components/chrome/SignupBand.astro +12 -0
- package/src/components/chrome/TakeoverBanner.astro +56 -0
- package/src/components/chrome/VisitorAccount.astro +82 -0
- package/src/components/entries/AuthorBox.astro +47 -0
- package/src/components/entries/EntryFields.astro +29 -0
- package/src/components/entries/EntryHeader.astro +77 -0
- package/src/components/entries/ListFrame.astro +126 -0
- package/src/components/entries/ListSearch.astro +24 -0
- package/src/components/entries/Share.astro +24 -0
- package/src/components/entries/course/classroom.astro +26 -0
- package/src/components/entries/course/lesson.astro +18 -0
- package/src/components/entries/course/section.ts +20 -0
- package/src/components/entries/course/syllabus.astro +15 -0
- package/src/components/entries/index.ts +77 -0
- package/src/components/entries/newsletter/issue.astro +41 -0
- package/src/components/entries/newsletter/list.astro +26 -0
- package/src/components/entries/podcast/episode.astro +42 -0
- package/src/components/entries/podcast/list.astro +36 -0
- package/src/components/entries/post/article.astro +31 -0
- package/src/components/entries/post/list.astro +85 -0
- package/src/components/entries/props.ts +61 -0
- package/src/components/entries/video/cards.astro +39 -0
- package/src/components/entries/video/grid.astro +15 -0
- package/src/components/entries/video/watch.astro +41 -0
- package/src/components/live/LivePage.astro +215 -0
- package/src/components/live/LocalTime.astro +29 -0
- package/src/components/sections/About/books.astro +188 -0
- package/src/components/sections/About/credentials.ts +90 -0
- package/src/components/sections/About/index.astro +57 -0
- package/src/components/sections/About/left.astro +54 -0
- package/src/components/sections/About/letter.astro +108 -0
- package/src/components/sections/About/portrait.astro +308 -0
- package/src/components/sections/Advocacy/compact.astro +14 -0
- package/src/components/sections/Advocacy/index.astro +14 -0
- package/src/components/sections/Band.astro +39 -0
- package/src/components/sections/Blog/feature.astro +176 -0
- package/src/components/sections/Blog/index.astro +37 -0
- package/src/components/sections/Blog/latest.ts +80 -0
- package/src/components/sections/Blog/list.astro +186 -0
- package/src/components/sections/Booking/index.astro +139 -0
- package/src/components/sections/Booking/list.astro +144 -0
- package/src/components/sections/Booking/types.ts +60 -0
- package/src/components/sections/Calendar/agenda.astro +14 -0
- package/src/components/sections/Calendar/index.astro +14 -0
- package/src/components/sections/CandidateRoster/ballot.astro +394 -0
- package/src/components/sections/CandidateRoster/candidates.ts +69 -0
- package/src/components/sections/CandidateRoster/compact.astro +115 -0
- package/src/components/sections/CandidateRoster/index.astro +57 -0
- package/src/components/sections/CaseStudies/beforeafter.astro +222 -0
- package/src/components/sections/CaseStudies/cases.ts +111 -0
- package/src/components/sections/CaseStudies/grid.astro +261 -0
- package/src/components/sections/CaseStudies/index.astro +333 -0
- package/src/components/sections/Classroom/CourseCard.astro +181 -0
- package/src/components/sections/Classroom/Courses.astro +88 -0
- package/src/components/sections/Classroom/classroom.ts +141 -0
- package/src/components/sections/Classroom/index.astro +20 -0
- package/src/components/sections/Classroom/list.astro +15 -0
- package/src/components/sections/Collection/compact.astro +7 -0
- package/src/components/sections/Collection/entries.ts +62 -0
- package/src/components/sections/Collection/feature.astro +180 -0
- package/src/components/sections/Collection/index.astro +46 -0
- package/src/components/sections/Collection/library.astro +271 -0
- package/src/components/sections/Collection/list.astro +7 -0
- package/src/components/sections/Collection/outline.astro +134 -0
- package/src/components/sections/Collection/shelves.astro +191 -0
- package/src/components/sections/Comparison/Unlisted.astro +6 -0
- package/src/components/sections/Comparison/cards.astro +171 -0
- package/src/components/sections/Comparison/index.astro +191 -0
- package/src/components/sections/Comparison/sides.ts +98 -0
- package/src/components/sections/Comparison/spectrum.astro +261 -0
- package/src/components/sections/ContentPost/banner.astro +152 -0
- package/src/components/sections/ContentPost/index.astro +35 -0
- package/src/components/sections/ContentPost/lesson.ts +119 -0
- package/src/components/sections/ContentPost/player.astro +254 -0
- package/src/components/sections/ContentPost/theater.astro +329 -0
- package/src/components/sections/Countdown/index.astro +53 -0
- package/src/components/sections/Course/Bar.astro +46 -0
- package/src/components/sections/Course/CourseHead.astro +123 -0
- package/src/components/sections/Course/Crumbs.astro +44 -0
- package/src/components/sections/Course/Icon.astro +29 -0
- package/src/components/sections/Course/Ring.astro +62 -0
- package/src/components/sections/Course/Syllabus.astro +146 -0
- package/src/components/sections/Course/course.ts +146 -0
- package/src/components/sections/Course/index.astro +143 -0
- package/src/components/sections/Course/outline.astro +39 -0
- package/src/components/sections/Cta/banner.astro +64 -0
- package/src/components/sections/Cta/card.astro +88 -0
- package/src/components/sections/Cta/index.astro +31 -0
- package/src/components/sections/Cta/photo.astro +114 -0
- package/src/components/sections/Cta/strip.astro +91 -0
- package/src/components/sections/Donate/index.astro +136 -0
- package/src/components/sections/Donate/story.astro +7 -0
- package/src/components/sections/Event/card.astro +14 -0
- package/src/components/sections/Event/index.astro +14 -0
- package/src/components/sections/EventsList/AgendaMonths.astro +105 -0
- package/src/components/sections/EventsList/CalendarLine.astro +23 -0
- package/src/components/sections/EventsList/EventRows.astro +196 -0
- package/src/components/sections/EventsList/LiveCounts.astro +75 -0
- package/src/components/sections/EventsList/TypeTabs.astro +53 -0
- package/src/components/sections/EventsList/agenda.astro +55 -0
- package/src/components/sections/EventsList/calendar.astro +392 -0
- package/src/components/sections/EventsList/cards.astro +186 -0
- package/src/components/sections/EventsList/cohorts.astro +205 -0
- package/src/components/sections/EventsList/compact.astro +163 -0
- package/src/components/sections/EventsList/events.ts +168 -0
- package/src/components/sections/EventsList/index.astro +46 -0
- package/src/components/sections/EventsList/map.astro +436 -0
- package/src/components/sections/EventsList/shifts.astro +355 -0
- package/src/components/sections/EventsList/week.astro +361 -0
- package/src/components/sections/Faq/Contact.astro +63 -0
- package/src/components/sections/Faq/Questions.astro +98 -0
- package/src/components/sections/Faq/cards.astro +74 -0
- package/src/components/sections/Faq/faq.ts +101 -0
- package/src/components/sections/Faq/index.astro +49 -0
- package/src/components/sections/Faq/topics.astro +178 -0
- package/src/components/sections/Financials/Foot.astro +38 -0
- package/src/components/sections/Financials/Head.astro +47 -0
- package/src/components/sections/Financials/donut.astro +197 -0
- package/src/components/sections/Financials/financials.ts +52 -0
- package/src/components/sections/Financials/index.astro +148 -0
- package/src/components/sections/Financials/table.astro +157 -0
- package/src/components/sections/FormBlock/index.astro +33 -0
- package/src/components/sections/FormBlock/wide.astro +7 -0
- package/src/components/sections/Hero/cover.astro +170 -0
- package/src/components/sections/Hero/donate.astro +209 -0
- package/src/components/sections/Hero/field.astro +390 -0
- package/src/components/sections/Hero/index.astro +52 -0
- package/src/components/sections/Hero/overlap.astro +151 -0
- package/src/components/sections/Hero/rotating.astro +30 -0
- package/src/components/sections/Hero/split.astro +96 -0
- package/src/components/sections/Hero/statement.astro +55 -0
- package/src/components/sections/Hero/video.astro +399 -0
- package/src/components/sections/Issues/checklist.astro +204 -0
- package/src/components/sections/Issues/drawer.astro +237 -0
- package/src/components/sections/Issues/index.astro +115 -0
- package/src/components/sections/Issues/issues.ts +37 -0
- package/src/components/sections/Issues/numbered.astro +79 -0
- package/src/components/sections/Issues/rows.astro +137 -0
- package/src/components/sections/Issues/steps.astro +81 -0
- package/src/components/sections/Issues/tabs.astro +322 -0
- package/src/components/sections/Leaderboard/index.astro +29 -0
- package/src/components/sections/Lesson/Door.astro +121 -0
- package/src/components/sections/Lesson/LessonBody.astro +416 -0
- package/src/components/sections/Lesson/Rail.astro +182 -0
- package/src/components/sections/Lesson/Tracker.astro +137 -0
- package/src/components/sections/Lesson/index.astro +27 -0
- package/src/components/sections/Lesson/lesson.ts +233 -0
- package/src/components/sections/Lesson/reading.astro +21 -0
- package/src/components/sections/Map/CoverageLine.astro +19 -0
- package/src/components/sections/Map/RegionMap.astro +109 -0
- package/src/components/sections/Map/bar.astro +160 -0
- package/src/components/sections/Map/index.astro +192 -0
- package/src/components/sections/Map/map.astro +275 -0
- package/src/components/sections/MediaKit/BioCard.astro +108 -0
- package/src/components/sections/MediaKit/Downloads.astro +88 -0
- package/src/components/sections/MediaKit/index.astro +183 -0
- package/src/components/sections/MediaKit/kit.ts +140 -0
- package/src/components/sections/MediaKit/press.astro +189 -0
- package/src/components/sections/MediaKit/speaker.astro +205 -0
- package/src/components/sections/Membership/Benefits.astro +42 -0
- package/src/components/sections/Membership/Check.astro +12 -0
- package/src/components/sections/Membership/Price.astro +61 -0
- package/src/components/sections/Membership/compare.astro +312 -0
- package/src/components/sections/Membership/index.astro +281 -0
- package/src/components/sections/Membership/offers.ts +169 -0
- package/src/components/sections/Membership/tiers.astro +217 -0
- package/src/components/sections/MovementMap/index.astro +50 -0
- package/src/components/sections/MovementTicker/index.astro +43 -0
- package/src/components/sections/Pathways/Doors.astro +147 -0
- package/src/components/sections/Pathways/Head.astro +37 -0
- package/src/components/sections/Pathways/index.astro +27 -0
- package/src/components/sections/Pathways/pathways.ts +100 -0
- package/src/components/sections/Pathways/quiz.astro +286 -0
- package/src/components/sections/Pathways/tabs.astro +271 -0
- package/src/components/sections/PdfEmbed/card.astro +99 -0
- package/src/components/sections/PdfEmbed/index.astro +26 -0
- package/src/components/sections/PdfEmbed/medium.astro +7 -0
- package/src/components/sections/PdfEmbed/tall.astro +7 -0
- package/src/components/sections/Petition/coverage.astro +14 -0
- package/src/components/sections/Petition/image.astro +14 -0
- package/src/components/sections/Petition/index.astro +14 -0
- package/src/components/sections/Petition/map.astro +14 -0
- package/src/components/sections/PlatformPlanks/anchors.ts +66 -0
- package/src/components/sections/PlatformPlanks/columns.astro +171 -0
- package/src/components/sections/PlatformPlanks/index.astro +56 -0
- package/src/components/sections/PlatformPlanks/longread.astro +250 -0
- package/src/components/sections/PollBlock/index.astro +30 -0
- package/src/components/sections/Portfolio/featured.astro +343 -0
- package/src/components/sections/Portfolio/index.astro +571 -0
- package/src/components/sections/Portfolio/strip.astro +173 -0
- package/src/components/sections/Portfolio/work.ts +100 -0
- package/src/components/sections/Progress/MatchClock.astro +166 -0
- package/src/components/sections/Progress/compact.astro +150 -0
- package/src/components/sections/Progress/index.astro +32 -0
- package/src/components/sections/Progress/match.astro +126 -0
- package/src/components/sections/Progress/ring.astro +179 -0
- package/src/components/sections/QuickDonate/DonateCard.astro +149 -0
- package/src/components/sections/QuickDonate/Picker.astro +95 -0
- package/src/components/sections/QuickDonate/band.astro +164 -0
- package/src/components/sections/QuickDonate/bar.astro +208 -0
- package/src/components/sections/QuickDonate/donate.ts +126 -0
- package/src/components/sections/QuickDonate/hero.astro +143 -0
- package/src/components/sections/QuickDonate/index.astro +73 -0
- package/src/components/sections/QuickDonate/jar.astro +225 -0
- package/src/components/sections/QuickDonate/ladder.astro +248 -0
- package/src/components/sections/QuoteStrip/carousel.astro +340 -0
- package/src/components/sections/QuoteStrip/index.astro +58 -0
- package/src/components/sections/QuoteStrip/logos.astro +226 -0
- package/src/components/sections/QuoteStrip/quotes.ts +61 -0
- package/src/components/sections/QuoteStrip/single.astro +92 -0
- package/src/components/sections/QuoteStrip/ticker.astro +319 -0
- package/src/components/sections/QuoteStrip/wall.astro +113 -0
- package/src/components/sections/Resources/band.astro +93 -0
- package/src/components/sections/Resources/featured.astro +239 -0
- package/src/components/sections/Resources/index.astro +225 -0
- package/src/components/sections/Resources/resources.ts +92 -0
- package/src/components/sections/SampleBallot/Position.astro +39 -0
- package/src/components/sections/SampleBallot/ballot.ts +92 -0
- package/src/components/sections/SampleBallot/cards.astro +299 -0
- package/src/components/sections/SampleBallot/index.astro +326 -0
- package/src/components/sections/SampleBallot/measures.astro +172 -0
- package/src/components/sections/Scorecard/grades.astro +141 -0
- package/src/components/sections/Scorecard/index.astro +294 -0
- package/src/components/sections/Scorecard/promise.astro +167 -0
- package/src/components/sections/Scorecard/votes.ts +83 -0
- package/src/components/sections/SectionHead.astro +31 -0
- package/src/components/sections/Services/Button.astro +24 -0
- package/src/components/sections/Services/Check.astro +12 -0
- package/src/components/sections/Services/Includes.astro +42 -0
- package/src/components/sections/Services/compare.astro +328 -0
- package/src/components/sections/Services/index.astro +187 -0
- package/src/components/sections/Services/list.astro +181 -0
- package/src/components/sections/Services/services.ts +80 -0
- package/src/components/sections/ShareKit/Actions.astro +71 -0
- package/src/components/sections/ShareKit/Buttons.astro +62 -0
- package/src/components/sections/ShareKit/compact.astro +123 -0
- package/src/components/sections/ShareKit/index.astro +160 -0
- package/src/components/sections/ShareKit/share.ts +60 -0
- package/src/components/sections/ShareKit/strip.astro +173 -0
- package/src/components/sections/SignupCapture/band.astro +7 -0
- package/src/components/sections/SignupCapture/index.astro +103 -0
- package/src/components/sections/SignupCapture/inline.astro +7 -0
- package/src/components/sections/SocialFeed/index.astro +34 -0
- package/src/components/sections/StatCards/feature.astro +143 -0
- package/src/components/sections/StatCards/index.astro +51 -0
- package/src/components/sections/StatCards/ribbon.astro +113 -0
- package/src/components/sections/StatCards/wall.astro +177 -0
- package/src/components/sections/Store/featured.astro +14 -0
- package/src/components/sections/Store/index.astro +14 -0
- package/src/components/sections/Stories/Status.astro +42 -0
- package/src/components/sections/Stories/StoryCards.astro +171 -0
- package/src/components/sections/Stories/cards.astro +42 -0
- package/src/components/sections/Stories/index.astro +238 -0
- package/src/components/sections/Stories/stories.ts +97 -0
- package/src/components/sections/Stories/timeline.astro +135 -0
- package/src/components/sections/TeamGrid/board.astro +280 -0
- package/src/components/sections/TeamGrid/index.astro +71 -0
- package/src/components/sections/TeamGrid/list.astro +306 -0
- package/src/components/sections/TeamGrid/people.ts +178 -0
- package/src/components/sections/VideoEmbed/index.astro +52 -0
- package/src/components/sections/VideoEmbed/landscape.astro +7 -0
- package/src/components/sections/VideoEmbed/portrait.astro +7 -0
- package/src/components/sections/VideoEmbed/square.astro +7 -0
- package/src/components/sections/VoterTools/DaysLeft.astro +33 -0
- package/src/components/sections/VoterTools/dates.astro +149 -0
- package/src/components/sections/VoterTools/index.astro +228 -0
- package/src/components/sections/VoterTools/polling.astro +141 -0
- package/src/components/sections/VoterTools/voter-tools.ts +70 -0
- package/src/components/sections/index.ts +370 -0
- package/src/components/sections/modules/Headed.astro +39 -0
- package/src/components/sections/modules/ModuleFrame.astro +179 -0
- package/src/components/volunteer/ShiftLive.astro +90 -0
- package/src/components/volunteer/detail.astro +247 -0
- package/src/components/volunteer/list.astro +298 -0
- package/src/components/volunteer/props.ts +21 -0
- package/src/env.d.ts +22 -0
- package/src/index.d.ts +10 -0
- package/src/index.js +64 -0
- package/src/layouts/Site.astro +371 -0
- package/src/lib/academy.ts +146 -0
- package/src/lib/brand.ts +534 -0
- package/src/lib/chrome.ts +119 -0
- package/src/lib/donate-frame.ts +64 -0
- package/src/lib/entries.ts +190 -0
- package/src/lib/env.ts +34 -0
- package/src/lib/event-map-draw.ts +91 -0
- package/src/lib/events.ts +476 -0
- package/src/lib/fonts.ts +116 -0
- package/src/lib/footer.ts +24 -0
- package/src/lib/format.ts +160 -0
- package/src/lib/geo.ts +131 -0
- package/src/lib/live.ts +54 -0
- package/src/lib/menu.ts +48 -0
- package/src/lib/petition-text.ts +29 -0
- package/src/lib/reading.ts +17 -0
- package/src/lib/regions.ts +215 -0
- package/src/lib/section.ts +94 -0
- package/src/lib/shifts.ts +186 -0
- package/src/lib/stream-time.ts +20 -0
- package/src/lib/stream.ts +141 -0
- package/src/lib/visitor.ts +54 -0
- package/src/routes/catch-all.astro +286 -0
- package/src/routes/form.astro +30 -0
- package/src/routes/live.astro +49 -0
- package/src/routes/not-found.astro +18 -0
- package/src/routes/preview.astro +60 -0
- package/src/routes/setup.astro +62 -0
- package/src/routes/volunteer-shift.astro +61 -0
- package/src/routes/volunteer.astro +37 -0
- package/src/styles/entries.css +784 -0
- package/src/styles/site.css +1839 -0
- package/src/template.ts +182 -0
package/src/lib/brand.ts
ADDED
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
// The site's colours as CSS custom properties: the template's token sheet.
|
|
2
|
+
// A site that wears a saved theme in BackGold (`/site.theme`) paints each
|
|
3
|
+
// mode from that theme's own tokens, the values its hosted pages bake (the
|
|
4
|
+
// page and card colours, the ink, the accent, the hero ground), so a palette
|
|
5
|
+
// look moves to the template whole; a site with no theme paints from the
|
|
6
|
+
// brand in BackGold (`/site.brand`), derived as the boards draw it. The
|
|
7
|
+
// layout writes them into `:root`, a light set and a dark set;
|
|
8
|
+
// src/styles/site.css reads only these names, so restyling starts here or
|
|
9
|
+
// there.
|
|
10
|
+
//
|
|
11
|
+
// Which set shows is the site's appearance (`/site.style`'s `appearance`, the
|
|
12
|
+
// same pin a hosted BackGold site keeps): `light` or `dark` pins one set and
|
|
13
|
+
// the header has no toggle; `auto`, or none, follows the visitor's system and
|
|
14
|
+
// the header's toggle overrides it, by `data-gg-mode` on <html> (the attribute
|
|
15
|
+
// and the `gg-mode` storage key a hosted BackGold site's toggle uses, so a
|
|
16
|
+
// visitor's choice carries over when a site moves to the template).
|
|
17
|
+
//
|
|
18
|
+
// The derivations follow boards A1 and A13 (docs/design/sites-unification-
|
|
19
|
+
// 2026-10/mockups), drawn for a brand of indigo (primary), parchment
|
|
20
|
+
// (secondary) and coral (accent):
|
|
21
|
+
// page the secondary colour when it is light enough to read on
|
|
22
|
+
// (parchment), else a near-white; dark mode: the primary deep
|
|
23
|
+
// in shadow.
|
|
24
|
+
// ink the primary steeped in near-black when the primary is dark
|
|
25
|
+
// (A1's #191c33), else a neutral ink; dark mode: the secondary.
|
|
26
|
+
// accent "accent text": kickers, numerals, date lines, the wordmark's
|
|
27
|
+
// second line. The accent colour itself when it reads at AA on
|
|
28
|
+
// the ground; else taken darker (light grounds) or lighter (dark
|
|
29
|
+
// grounds) a twentieth at a time, only until it does, up to seven
|
|
30
|
+
// twentieths of the way (C1's marigold reads as a dark marigold on
|
|
31
|
+
// the page, not as ink); past that, the band's ink.
|
|
32
|
+
// button the main call (Donate, Join the party): the accent colour, with
|
|
33
|
+
// whichever ink reads on it. In dark mode the accent stays itself
|
|
34
|
+
// when it holds 3:1 against the page, as a fill must (WCAG
|
|
35
|
+
// 1.4.11), and is lightened only until it does. On a ground where
|
|
36
|
+
// the call's ink falls short of AA, or the call nearly matches the
|
|
37
|
+
// ground (under 1.5:1), the primary colour takes its place.
|
|
38
|
+
// `button-2` is the quieter solid button (RSVP, Sign me up): the
|
|
39
|
+
// primary colour. On a dark ground it is the band's ink when the
|
|
40
|
+
// primary would nearly vanish there: under 3:1 in dark mode (a
|
|
41
|
+
// fill's bar, WCAG 1.4.11), under 1.25:1 on light mode's dark
|
|
42
|
+
// bands.
|
|
43
|
+
// link a text link: the primary colour on light grounds.
|
|
44
|
+
// live the state red of something on the air now (the Watch Live
|
|
45
|
+
// item's dot): taken darker on light grounds, lighter on dark
|
|
46
|
+
// ones, a twentieth at a time, only until it holds 3:1 against
|
|
47
|
+
// the ground (WCAG 1.4.11); past half way, the band's ink.
|
|
48
|
+
//
|
|
49
|
+
// A section's `band` is a ground, never a colour. The grounds:
|
|
50
|
+
// plain the page
|
|
51
|
+
// tint a step off the page, deeper in the page's own hue
|
|
52
|
+
// panel the card colour
|
|
53
|
+
// wash the primary colour washed over white
|
|
54
|
+
// contrast the primary itself (dark mode: the secondary), flat
|
|
55
|
+
// brand not a band an organization picks: the primary colour as a
|
|
56
|
+
// ground in both modes (dark mode: lifted a step), for the
|
|
57
|
+
// footer, the announcement strip and a solid card (A1's footer,
|
|
58
|
+
// top bar and the sidebar's call to action)
|
|
59
|
+
// photo not a band an organization picks: the dark scrim the template
|
|
60
|
+
// lays over a photo (Hero · Full photo), the same in both modes
|
|
61
|
+
// Every band gets an ink, a muted ink, an accent, a link colour, two button
|
|
62
|
+
// pairs, a card colour and two rule colours, chosen here so text meets WCAG
|
|
63
|
+
// AA (4.5:1) on that ground whatever the brand is: a brand colour that would
|
|
64
|
+
// fail on a band is swapped for the band's ink.
|
|
65
|
+
|
|
66
|
+
import type { SiteResponse } from '@backgold/content'
|
|
67
|
+
|
|
68
|
+
type Rgb = [number, number, number]
|
|
69
|
+
|
|
70
|
+
export interface BrandColors {
|
|
71
|
+
primary_color?: string | null
|
|
72
|
+
secondary_color?: string | null
|
|
73
|
+
accent_color?: string | null
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The state red of a live stream, before it is held to 3:1 on each ground. */
|
|
77
|
+
const LIVE = '#e0362c'
|
|
78
|
+
|
|
79
|
+
/** Used for any brand colour BackGold does not have. */
|
|
80
|
+
const FALLBACK = { primary: '#1f3a5f', secondary: '#f4efe6', accent: '#b4232c' } as const
|
|
81
|
+
|
|
82
|
+
const PAGE = '#fbfaf8'
|
|
83
|
+
const DARK_PAGE = '#121417'
|
|
84
|
+
const INK = '#16191f'
|
|
85
|
+
const LIGHT_INK = '#ffffff'
|
|
86
|
+
const BLACK = '#000000'
|
|
87
|
+
const AA = 4.5
|
|
88
|
+
/** Buttons and focus rings are not text: 3:1 against their ground (WCAG 1.4.11). */
|
|
89
|
+
const NON_TEXT = 3
|
|
90
|
+
/** A ground lighter than this takes dark text. */
|
|
91
|
+
const LIGHT_GROUND = 0.18
|
|
92
|
+
|
|
93
|
+
function parse(hex: string): Rgb {
|
|
94
|
+
const n = Number.parseInt(hex.slice(1), 16)
|
|
95
|
+
return [(n >> 16) & 255, (n >> 8) & 255, n & 255]
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function hex([r, g, b]: Rgb): string {
|
|
99
|
+
return `#${[r, g, b].map((c) => Math.round(Math.min(255, Math.max(0, c))).toString(16).padStart(2, '0')).join('')}`
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** `#rrggbb` when the value is one, else null. */
|
|
103
|
+
function brandColor(value: unknown): string | null {
|
|
104
|
+
return typeof value === 'string' && /^#[0-9a-f]{6}$/i.test(value.trim()) ? value.trim().toLowerCase() : null
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** `amount` of `a` over `b` (0 = all b, 1 = all a). */
|
|
108
|
+
function mix(a: string, b: string, amount: number): string {
|
|
109
|
+
const x = parse(a)
|
|
110
|
+
const y = parse(b)
|
|
111
|
+
return hex([0, 1, 2].map((i) => x[i]! * amount + y[i]! * (1 - amount)) as Rgb)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** A light colour taken deeper in its own hue: each channel's distance from white times `k` (A1's tint is the page at 1.7). */
|
|
115
|
+
function deepen(color: string, k: number): string {
|
|
116
|
+
return hex(parse(color).map((c) => 255 - (255 - c) * k) as Rgb)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function luminance(color: string): number {
|
|
120
|
+
const [r, g, b] = parse(color).map((c) => {
|
|
121
|
+
const s = c / 255
|
|
122
|
+
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4
|
|
123
|
+
}) as Rgb
|
|
124
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The WCAG contrast ratio of two colours, 1 to 21. */
|
|
128
|
+
function contrast(a: string, b: string): number {
|
|
129
|
+
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x) as [number, number]
|
|
130
|
+
return (hi + 0.05) / (lo + 0.05)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const isLight = (ground: string) => luminance(ground) > LIGHT_GROUND
|
|
134
|
+
|
|
135
|
+
/** Whichever of `dark` and `light` reads better on `ground`. */
|
|
136
|
+
function inkOn(ground: string, dark = INK, light = LIGHT_INK): string {
|
|
137
|
+
return contrast(dark, ground) >= contrast(light, ground) ? dark : light
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** `color` when it reaches `ratio` on every one of `grounds`, else `fallback`. */
|
|
141
|
+
function readable(color: string, grounds: string[], ratio: number, fallback: string): string {
|
|
142
|
+
return grounds.every((g) => contrast(color, g) >= ratio) ? color : fallback
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** The first of `candidates` that reads at AA on `ground`, else `fallback`. */
|
|
146
|
+
function firstReadable(candidates: string[], ground: string, fallback: string): string {
|
|
147
|
+
return candidates.find((c) => contrast(c, ground) >= AA) ?? fallback
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* `color` taken toward `toward` (black or white) a twentieth at a time, at
|
|
152
|
+
* most `limit` of the way, stopping at the first step that reaches `ratio` on
|
|
153
|
+
* `ground`: `color` itself when it already does, else `fallback`.
|
|
154
|
+
*/
|
|
155
|
+
function reaching(color: string, toward: string, limit: number, ground: string, ratio: number, fallback: string): string {
|
|
156
|
+
for (let step = 0; step <= Math.round(limit * 20); step++) {
|
|
157
|
+
const candidate = mix(toward, color, step / 20)
|
|
158
|
+
if (contrast(candidate, ground) >= ratio) return candidate
|
|
159
|
+
}
|
|
160
|
+
return fallback
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** A ground light text reads on: `color`, darkened until white reaches AA. */
|
|
164
|
+
function darkGround(color: string): string {
|
|
165
|
+
let ground = color
|
|
166
|
+
for (let step = 0; step < 20 && contrast(LIGHT_INK, ground) < AA; step++) ground = mix(ground, BLACK, 0.9)
|
|
167
|
+
return ground
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
interface Band {
|
|
171
|
+
ground: string
|
|
172
|
+
ink: string
|
|
173
|
+
muted: string
|
|
174
|
+
accent: string
|
|
175
|
+
link: string
|
|
176
|
+
button: string
|
|
177
|
+
buttonInk: string
|
|
178
|
+
button2: string
|
|
179
|
+
button2Ink: string
|
|
180
|
+
surface: string
|
|
181
|
+
line: string
|
|
182
|
+
lineStrong: string
|
|
183
|
+
live: string
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
type BandName = 'plain' | 'tint' | 'panel' | 'wash' | 'contrast' | 'brand' | 'photo'
|
|
187
|
+
|
|
188
|
+
/** One mode's inks and brand colours, which every band of that mode starts from. */
|
|
189
|
+
interface Mode {
|
|
190
|
+
primary: string
|
|
191
|
+
accent: string
|
|
192
|
+
/** Text on a light ground. */
|
|
193
|
+
darkText: string
|
|
194
|
+
/** Text on a dark ground. */
|
|
195
|
+
lightText: string
|
|
196
|
+
/** The main call's fill in this mode: the accent (dark mode: lightened only as far as a fill needs). */
|
|
197
|
+
call: string
|
|
198
|
+
/**
|
|
199
|
+
* How far the primary must stand off a dark ground to fill the quieter
|
|
200
|
+
* button there; below it the band's ink fills it. Dark mode holds a fill to
|
|
201
|
+
* 3:1 (WCAG 1.4.11); light mode's dark grounds (contrast, brand, photo)
|
|
202
|
+
* keep the looser 1.25 the A boards were drawn with.
|
|
203
|
+
*/
|
|
204
|
+
quietFloor: number
|
|
205
|
+
/** The page's card colour and rules, for every light ground. */
|
|
206
|
+
surface: string
|
|
207
|
+
line: string
|
|
208
|
+
lineStrong: string
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function band(ground: string, m: Mode): Band {
|
|
212
|
+
const light = isLight(ground)
|
|
213
|
+
const ink = light ? readable(m.darkText, [ground], AA, inkOn(ground)) : readable(m.lightText, [ground], AA, inkOn(ground))
|
|
214
|
+
const muted = light
|
|
215
|
+
? firstReadable([0.78, 0.84, 0.9].map((a) => mix(mix(m.primary, ink, 0.5), ground, a)), ground, ink)
|
|
216
|
+
: firstReadable([0.72, 0.78, 0.84, 0.9].map((a) => mix(LIGHT_INK, ground, a)), ground, ink)
|
|
217
|
+
const accent = light ? reaching(m.accent, BLACK, 0.7, ground, AA, ink) : reaching(m.accent, LIGHT_INK, 0.7, ground, AA, ink)
|
|
218
|
+
const link = light ? readable(m.primary, [ground], AA, ink) : firstReadable([mix(LIGHT_INK, m.primary, 0.72)], ground, ink)
|
|
219
|
+
const buttonInk = inkOn(m.call, m.darkText, LIGHT_INK)
|
|
220
|
+
const callReads = contrast(buttonInk, m.call) >= AA && contrast(m.call, ground) >= 1.5
|
|
221
|
+
const button = callReads ? m.call : readable(m.primary, [ground], NON_TEXT, ink)
|
|
222
|
+
const button2 = light ? readable(m.primary, [ground], NON_TEXT, ink) : contrast(m.primary, ground) >= m.quietFloor ? m.primary : ink
|
|
223
|
+
return {
|
|
224
|
+
ground,
|
|
225
|
+
ink,
|
|
226
|
+
muted,
|
|
227
|
+
accent,
|
|
228
|
+
link,
|
|
229
|
+
button,
|
|
230
|
+
buttonInk: callReads ? buttonInk : inkOn(button),
|
|
231
|
+
button2,
|
|
232
|
+
button2Ink: inkOn(button2, m.darkText, m.lightText),
|
|
233
|
+
surface: light ? m.surface : mix(LIGHT_INK, ground, 0.035),
|
|
234
|
+
line: light ? m.line : mix(LIGHT_INK, ground, 0.1),
|
|
235
|
+
lineStrong: light ? m.lineStrong : mix(LIGHT_INK, ground, 0.2),
|
|
236
|
+
live: reaching(LIVE, light ? BLACK : LIGHT_INK, 0.5, ground, NON_TEXT, ink),
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
interface Palette {
|
|
241
|
+
primary: string
|
|
242
|
+
secondary: string
|
|
243
|
+
accent: string
|
|
244
|
+
page: string
|
|
245
|
+
bands: Record<BandName, Band>
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function colorsOf(brand: BrandColors | null | undefined) {
|
|
249
|
+
return {
|
|
250
|
+
primary: brandColor(brand?.primary_color) ?? FALLBACK.primary,
|
|
251
|
+
secondary: brandColor(brand?.secondary_color) ?? FALLBACK.secondary,
|
|
252
|
+
accent: brandColor(brand?.accent_color) ?? FALLBACK.accent,
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** The light palette for a brand; any colour missing or malformed falls back to FALLBACK. */
|
|
257
|
+
function lightPalette(brand: BrandColors | null | undefined): Palette {
|
|
258
|
+
const { primary, secondary, accent } = colorsOf(brand)
|
|
259
|
+
const page = luminance(secondary) >= 0.75 ? secondary : PAGE
|
|
260
|
+
const steeped = mix(primary, '#101010', 0.45)
|
|
261
|
+
const darkText = luminance(primary) < 0.08 && contrast(steeped, page) >= 7 ? steeped : INK
|
|
262
|
+
const darker = luminance(primary) <= luminance(secondary) ? primary : secondary
|
|
263
|
+
const contrastGround = contrast(LIGHT_INK, primary) >= AA ? primary : darkGround(darker)
|
|
264
|
+
const m: Mode = {
|
|
265
|
+
primary,
|
|
266
|
+
accent,
|
|
267
|
+
darkText,
|
|
268
|
+
lightText: contrast(page, contrastGround) >= AA ? page : LIGHT_INK,
|
|
269
|
+
call: accent,
|
|
270
|
+
quietFloor: 1.25,
|
|
271
|
+
surface: mix(LIGHT_INK, page, 0.8),
|
|
272
|
+
line: mix(deepen(page, 2), darkText, 0.95),
|
|
273
|
+
lineStrong: mix(deepen(page, 3), darkText, 0.9),
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
primary,
|
|
277
|
+
secondary,
|
|
278
|
+
accent,
|
|
279
|
+
page,
|
|
280
|
+
bands: {
|
|
281
|
+
plain: band(page, m),
|
|
282
|
+
tint: band(deepen(page, 1.7), m),
|
|
283
|
+
panel: band(m.surface, m),
|
|
284
|
+
wash: band(mix(primary, LIGHT_INK, 0.11), m),
|
|
285
|
+
contrast: band(contrastGround, m),
|
|
286
|
+
brand: band(contrastGround, m),
|
|
287
|
+
photo: band(darkGround(mix(primary, BLACK, 0.4)), m),
|
|
288
|
+
},
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** The theme tokens one mode's palette reads (`/site.theme`'s `light.tokens` and `dark.tokens`). */
|
|
293
|
+
const THEME_TOKENS = ['bg', 'surface', 'surface_2', 'ink', 'line', 'line_strong', 'accent_1', 'accent_text', 'hero_1'] as const
|
|
294
|
+
type ThemeTokens = Record<(typeof THEME_TOKENS)[number], string>
|
|
295
|
+
|
|
296
|
+
/** The theme a site wears, as `/site` sends it; its tokens are read here, its fonts in src/lib/fonts.ts. */
|
|
297
|
+
export type SiteThemeLike = NonNullable<SiteResponse['site']['theme']>
|
|
298
|
+
|
|
299
|
+
/** `mode`'s tokens when every one the palette reads is a `#rrggbb`, else null (the brand palette stands in). */
|
|
300
|
+
function themeTokens(theme: SiteThemeLike | null | undefined, mode: 'light' | 'dark'): ThemeTokens | null {
|
|
301
|
+
const tokens = theme?.[mode]?.tokens as Record<string, unknown> | undefined
|
|
302
|
+
if (!tokens || typeof tokens !== 'object') return null
|
|
303
|
+
const out: Partial<ThemeTokens> = {}
|
|
304
|
+
for (const key of THEME_TOKENS) {
|
|
305
|
+
const value = brandColor(tokens[key])
|
|
306
|
+
if (!value) return null
|
|
307
|
+
out[key] = value
|
|
308
|
+
}
|
|
309
|
+
return out as ThemeTokens
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* A mode's palette from the theme's own tokens: the page is the theme's
|
|
314
|
+
* page, the card its card, the ink its ink, the accent its accent (the fill
|
|
315
|
+
* for the main call, the accent text for kickers), the hero ground for the
|
|
316
|
+
* contrast and brand bands, and the second surface for the tint. Every band
|
|
317
|
+
* still goes through `band`, so text keeps AA on whatever the theme chose.
|
|
318
|
+
* The three brand colours stay the brand's own, for `--bg-brand-*`.
|
|
319
|
+
*/
|
|
320
|
+
function themePalette(t: ThemeTokens, brand: BrandColors | null | undefined, mode: 'light' | 'dark'): Palette {
|
|
321
|
+
const { primary, secondary, accent } = colorsOf(brand)
|
|
322
|
+
const page = t.bg
|
|
323
|
+
const inkIsLight = luminance(t.ink) > 0.5
|
|
324
|
+
const m: Mode = {
|
|
325
|
+
primary: t.accent_1,
|
|
326
|
+
accent: t.accent_text,
|
|
327
|
+
darkText: inkIsLight ? INK : t.ink,
|
|
328
|
+
lightText: inkIsLight ? t.ink : '#f1ede6',
|
|
329
|
+
call: t.accent_1,
|
|
330
|
+
quietFloor: mode === 'dark' ? NON_TEXT : 1.25,
|
|
331
|
+
surface: t.surface,
|
|
332
|
+
line: t.line,
|
|
333
|
+
lineStrong: t.line_strong,
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
primary,
|
|
337
|
+
secondary,
|
|
338
|
+
accent,
|
|
339
|
+
page,
|
|
340
|
+
bands: {
|
|
341
|
+
plain: band(page, m),
|
|
342
|
+
tint: band(t.surface_2, m),
|
|
343
|
+
panel: band(t.surface, m),
|
|
344
|
+
wash: band(mix(t.accent_1, page, 0.11), m),
|
|
345
|
+
contrast: band(t.hero_1, m),
|
|
346
|
+
brand: band(t.hero_1, m),
|
|
347
|
+
photo: band(darkGround(mix(t.hero_1, BLACK, 0.4)), m),
|
|
348
|
+
},
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** The light set: the theme's light tokens when the site wears a theme, else the brand's light palette. */
|
|
353
|
+
function lightOf(brand: BrandColors | null | undefined, theme: SiteThemeLike | null | undefined): Palette {
|
|
354
|
+
const t = themeTokens(theme, 'light')
|
|
355
|
+
return t ? themePalette(t, brand, 'light') : lightPalette(brand)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** The dark set: the theme's dark tokens when the site wears a theme, else the brand's dark palette. */
|
|
359
|
+
function darkOf(brand: BrandColors | null | undefined, theme: SiteThemeLike | null | undefined): Palette {
|
|
360
|
+
const t = themeTokens(theme, 'dark')
|
|
361
|
+
return t ? themePalette(t, brand, 'dark') : darkPalette(brand)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** The dark palette (board A13's other theme): the primary deep in shadow, the secondary as ink, the contrast band light. */
|
|
365
|
+
function darkPalette(brand: BrandColors | null | undefined): Palette {
|
|
366
|
+
const { primary, secondary, accent } = colorsOf(brand)
|
|
367
|
+
const shadowed = mix(primary, BLACK, 0.43)
|
|
368
|
+
const page = luminance(shadowed) < 0.03 ? shadowed : DARK_PAGE
|
|
369
|
+
const lightText = luminance(secondary) >= 0.75 ? mix(secondary, BLACK, 0.98) : '#f1ede6'
|
|
370
|
+
const steeped = mix(primary, '#101010', 0.45)
|
|
371
|
+
const darkText = luminance(primary) < 0.08 ? steeped : INK
|
|
372
|
+
const contrastGround = luminance(secondary) >= 0.75 ? deepen(secondary, 1.3) : '#efe7d6'
|
|
373
|
+
const m: Mode = {
|
|
374
|
+
primary: mix(primary, LIGHT_INK, 0.94),
|
|
375
|
+
accent,
|
|
376
|
+
darkText,
|
|
377
|
+
lightText,
|
|
378
|
+
call: reaching(accent, LIGHT_INK, 0.7, page, NON_TEXT, accent),
|
|
379
|
+
quietFloor: NON_TEXT,
|
|
380
|
+
surface: mix(LIGHT_INK, contrastGround, 0.5),
|
|
381
|
+
line: mix(deepen(contrastGround, 2), darkText, 0.95),
|
|
382
|
+
lineStrong: mix(deepen(contrastGround, 3), darkText, 0.9),
|
|
383
|
+
}
|
|
384
|
+
const lightModeColors = lightPalette(brand)
|
|
385
|
+
return {
|
|
386
|
+
primary,
|
|
387
|
+
secondary,
|
|
388
|
+
accent,
|
|
389
|
+
page,
|
|
390
|
+
bands: {
|
|
391
|
+
plain: band(page, m),
|
|
392
|
+
tint: band(mix(primary, BLACK, 0.55), m),
|
|
393
|
+
panel: band(mix(primary, BLACK, 0.66), m),
|
|
394
|
+
wash: band(mix(primary, BLACK, 0.72), m),
|
|
395
|
+
contrast: band(contrastGround, m),
|
|
396
|
+
brand: band(darkGround(mix(primary, LIGHT_INK, 0.94)), m),
|
|
397
|
+
// A photo does not change with the visitor's theme: its scrim and words are light mode's.
|
|
398
|
+
photo: { ...lightModeColors.bands.photo, button: m.call, buttonInk: inkOn(m.call, INK, LIGHT_INK) },
|
|
399
|
+
},
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function lines(p: Palette): string[] {
|
|
404
|
+
const out = [
|
|
405
|
+
`--bg-brand-primary:${p.primary}`,
|
|
406
|
+
`--bg-brand-secondary:${p.secondary}`,
|
|
407
|
+
`--bg-brand-accent:${p.accent}`,
|
|
408
|
+
`--page:${p.page}`,
|
|
409
|
+
// A shadow is the page's ink on a light page and black on a dark one (a light shadow reads as a glow).
|
|
410
|
+
`--shadow-ink:${isLight(p.page) ? p.bands.plain.ink : BLACK}`,
|
|
411
|
+
]
|
|
412
|
+
for (const [name, b] of Object.entries(p.bands)) {
|
|
413
|
+
out.push(
|
|
414
|
+
`--band-${name}:${b.ground}`,
|
|
415
|
+
`--band-${name}-ink:${b.ink}`,
|
|
416
|
+
`--band-${name}-muted:${b.muted}`,
|
|
417
|
+
`--band-${name}-accent:${b.accent}`,
|
|
418
|
+
`--band-${name}-link:${b.link}`,
|
|
419
|
+
`--band-${name}-button:${b.button}`,
|
|
420
|
+
`--band-${name}-button-ink:${b.buttonInk}`,
|
|
421
|
+
`--band-${name}-button-2:${b.button2}`,
|
|
422
|
+
`--band-${name}-button-2-ink:${b.button2Ink}`,
|
|
423
|
+
`--band-${name}-surface:${b.surface}`,
|
|
424
|
+
`--band-${name}-line:${b.line}`,
|
|
425
|
+
`--band-${name}-line-strong:${b.lineStrong}`,
|
|
426
|
+
`--band-${name}-live:${b.live}`,
|
|
427
|
+
)
|
|
428
|
+
}
|
|
429
|
+
return out
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export type Appearance = 'light' | 'dark' | 'auto'
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* The site's appearance from `/site.style` (a JSON string, or null): its
|
|
436
|
+
* `appearance` when it is `light` or `dark`, else `auto`.
|
|
437
|
+
*/
|
|
438
|
+
export function appearanceOf(style: string | null | undefined): Appearance {
|
|
439
|
+
if (!style) return 'auto'
|
|
440
|
+
try {
|
|
441
|
+
const parsed: unknown = JSON.parse(style)
|
|
442
|
+
const value = parsed && typeof parsed === 'object' ? (parsed as { appearance?: unknown }).appearance : null
|
|
443
|
+
return value === 'light' || value === 'dark' ? value : 'auto'
|
|
444
|
+
} catch {
|
|
445
|
+
return 'auto'
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* The palettes as CSS, from the theme the site wears when it wears one
|
|
451
|
+
* (`theme`, `/site.theme`), else from its brand. A pinned appearance is one `:root` rule. Auto is the
|
|
452
|
+
* light set on `:root`, the dark set under `prefers-color-scheme: dark`
|
|
453
|
+
* unless the visitor chose light, and the dark set when the visitor chose
|
|
454
|
+
* dark. Auto with a template that opens dark (`opensDark`, the template's
|
|
455
|
+
* `defaultAppearance: 'dark'`) is the dark set on `:root` whatever the
|
|
456
|
+
* visitor's system says, and the light set only when the visitor chose light.
|
|
457
|
+
* Every value is a `#rrggbb` built above, never text from BackGold.
|
|
458
|
+
*/
|
|
459
|
+
export function brandCss(
|
|
460
|
+
brand: BrandColors | null | undefined,
|
|
461
|
+
appearance: Appearance = 'auto',
|
|
462
|
+
opensDark = false,
|
|
463
|
+
theme: SiteThemeLike | null | undefined = null,
|
|
464
|
+
): string {
|
|
465
|
+
const light = lines(lightOf(brand, theme)).join(';')
|
|
466
|
+
const dark = lines(darkOf(brand, theme)).join(';')
|
|
467
|
+
if (appearance === 'light') return `:root{color-scheme:light;${light}}`
|
|
468
|
+
if (appearance === 'dark') return `:root{color-scheme:dark;${dark}}`
|
|
469
|
+
if (opensDark) return `:root{color-scheme:dark;${dark}}:root[data-gg-mode="light"]{color-scheme:light;${light}}`
|
|
470
|
+
return (
|
|
471
|
+
`:root{color-scheme:light;${light}}` +
|
|
472
|
+
`@media (prefers-color-scheme:dark){:root:not([data-gg-mode="light"]){color-scheme:dark;${dark}}}` +
|
|
473
|
+
`:root[data-gg-mode="dark"]{color-scheme:dark;${dark}}`
|
|
474
|
+
)
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/** The grounds a section may sit on, as BackGold names them. */
|
|
478
|
+
export const SECTION_BANDS = ['plain', 'tint', 'panel', 'wash', 'contrast'] as const
|
|
479
|
+
export type SectionBand = (typeof SECTION_BANDS)[number]
|
|
480
|
+
|
|
481
|
+
/** One band's colours as a module frame wears them: the band, its ground included, as `#rrggbb`. */
|
|
482
|
+
export type FrameColors = Readonly<Band>
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* A template's change to the colours a module frame is sent (TemplateConfig
|
|
486
|
+
* `frameColors`): given the band's colours, the scheme, which band the frame
|
|
487
|
+
* sits on and every band's colours in that scheme (for a template that
|
|
488
|
+
* draws a band on a ground of its own, derived from the others), the
|
|
489
|
+
* colours to send. Only the eleven the look carries are sent; the ground is
|
|
490
|
+
* there to read.
|
|
491
|
+
*/
|
|
492
|
+
export type FrameColorsAdjust = (
|
|
493
|
+
colors: FrameColors,
|
|
494
|
+
scheme: 'light' | 'dark',
|
|
495
|
+
band: SectionBand,
|
|
496
|
+
bands: Readonly<Record<SectionBand, FrameColors>>,
|
|
497
|
+
) => FrameColors
|
|
498
|
+
|
|
499
|
+
/** A band through a template's adjust; a colour it returns that is not `#rrggbb` keeps the band's, since the api drops a malformed look whole. */
|
|
500
|
+
function adjusted(palette: Palette, band: SectionBand, scheme: 'light' | 'dark', adjust: FrameColorsAdjust | null): Band {
|
|
501
|
+
const b = palette.bands[band]
|
|
502
|
+
if (!adjust) return b
|
|
503
|
+
const out = adjust(b, scheme, band, palette.bands)
|
|
504
|
+
const keep = (key: keyof Band) => (/^#[0-9a-f]{6}$/i.test(out[key] ?? '') ? out[key] : b[key])
|
|
505
|
+
return Object.fromEntries((Object.keys(b) as Array<keyof Band>).map((key) => [key, keep(key)])) as unknown as Band
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** One band's colours as a BackGold module's `look` value: eleven hex colours, no '#', joined by '.'. */
|
|
509
|
+
function lookValue(b: Band): string {
|
|
510
|
+
return [b.ink, b.muted, b.accent, b.link, b.button, b.buttonInk, b.button2, b.button2Ink, b.surface, b.line, b.lineStrong]
|
|
511
|
+
.map((c) => c.slice(1))
|
|
512
|
+
.join('.')
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* The query a BackGold module's frame takes to wear this site where it sits
|
|
517
|
+
* (BackGold's embed look: `look`, `look_dark`): the colours of `band`, the
|
|
518
|
+
* light set, and the dark set unless the appearance pins one, each through
|
|
519
|
+
* the template's `adjust` when it has one. A module drawn in a card sits on
|
|
520
|
+
* the card colour, which is the panel band's ground.
|
|
521
|
+
*/
|
|
522
|
+
export function moduleLook(
|
|
523
|
+
brand: BrandColors | null | undefined,
|
|
524
|
+
band: SectionBand,
|
|
525
|
+
appearance: Appearance,
|
|
526
|
+
theme: SiteThemeLike | null | undefined = null,
|
|
527
|
+
adjust: FrameColorsAdjust | null = null,
|
|
528
|
+
): Record<string, string> {
|
|
529
|
+
const light = lookValue(adjusted(lightOf(brand, theme), band, 'light', adjust))
|
|
530
|
+
const dark = lookValue(adjusted(darkOf(brand, theme), band, 'dark', adjust))
|
|
531
|
+
if (appearance === 'light') return { look: light }
|
|
532
|
+
if (appearance === 'dark') return { look: dark }
|
|
533
|
+
return { look: light, look_dark: dark }
|
|
534
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// The site's header and footer as BackGold's operator set them up: GET /site's
|
|
2
|
+
// `chrome` (each part's layout and the footer's own words), against what the
|
|
3
|
+
// template's template.json `chrome` (its config's manifest) says it draws. A
|
|
4
|
+
// layout the site names that the template does not list is drawn as the
|
|
5
|
+
// template's first, exactly as a section's variant falls back; a `/site`
|
|
6
|
+
// answer with no `chrome` at all (an older BackGold) reads as the template's
|
|
7
|
+
// firsts and no words.
|
|
8
|
+
import type { SiteTemplateManifest } from '#contract/site-templates'
|
|
9
|
+
import { relFor, safeHref } from '@backgold/astro/server'
|
|
10
|
+
|
|
11
|
+
export type HeaderLayout = SiteTemplateManifest['chrome']['header'][number]
|
|
12
|
+
export type FooterLayout = SiteTemplateManifest['chrome']['footer'][number]
|
|
13
|
+
|
|
14
|
+
/** A link on the footer's bottom row, or a closing-call button: its address already checked. */
|
|
15
|
+
export interface ChromeLink {
|
|
16
|
+
label: string
|
|
17
|
+
href: string
|
|
18
|
+
rel: string | undefined
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The footer's closing call (its `closing` layout). */
|
|
22
|
+
export interface ClosingCall {
|
|
23
|
+
headline: string
|
|
24
|
+
body: string | null
|
|
25
|
+
tagline: string | null
|
|
26
|
+
imageUrl: string | null
|
|
27
|
+
buttons: ChromeLink[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface SiteChrome {
|
|
31
|
+
header: { layout: HeaderLayout }
|
|
32
|
+
footer: {
|
|
33
|
+
layout: FooterLayout
|
|
34
|
+
blurb: string | null
|
|
35
|
+
address: string | null
|
|
36
|
+
phone: string | null
|
|
37
|
+
legalLinks: ChromeLink[]
|
|
38
|
+
copyright: string | null
|
|
39
|
+
closing: ClosingCall | null
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** What `/site` carries, read structurally so an older answer still parses. */
|
|
44
|
+
interface Raw {
|
|
45
|
+
chrome?: {
|
|
46
|
+
header?: { layout?: unknown }
|
|
47
|
+
footer?: {
|
|
48
|
+
layout?: unknown
|
|
49
|
+
blurb?: unknown
|
|
50
|
+
address?: unknown
|
|
51
|
+
phone?: unknown
|
|
52
|
+
legal_links?: unknown
|
|
53
|
+
copyright?: unknown
|
|
54
|
+
closing?: {
|
|
55
|
+
headline?: unknown
|
|
56
|
+
body?: unknown
|
|
57
|
+
tagline?: unknown
|
|
58
|
+
image_url?: unknown
|
|
59
|
+
buttons?: unknown
|
|
60
|
+
} | null
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const str = (value: unknown): string | null => (typeof value === 'string' && value.trim() ? value.trim() : null)
|
|
66
|
+
|
|
67
|
+
/** The layout this template draws for a stored value: the value when listed, else the template's first. */
|
|
68
|
+
function drawn<T extends string>(listed: readonly T[], value: unknown): T {
|
|
69
|
+
return typeof value === 'string' && (listed as readonly string[]).includes(value) ? (value as T) : listed[0]!
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The rows that have a label and an address safe to follow, in order. */
|
|
73
|
+
function linksOf(value: unknown): ChromeLink[] {
|
|
74
|
+
if (!Array.isArray(value)) return []
|
|
75
|
+
const out: ChromeLink[] = []
|
|
76
|
+
for (const row of value as Array<{ label?: unknown; url?: unknown }>) {
|
|
77
|
+
const label = str(row?.label)
|
|
78
|
+
const href = typeof row?.url === 'string' ? safeHref(row.url) : null
|
|
79
|
+
if (label && href) out.push({ label, href, rel: relFor(href) })
|
|
80
|
+
}
|
|
81
|
+
return out
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function chromeOf(site: unknown, manifest: SiteTemplateManifest): SiteChrome {
|
|
85
|
+
const raw = ((site ?? {}) as Raw).chrome ?? {}
|
|
86
|
+
const footer = raw.footer ?? {}
|
|
87
|
+
const layout = drawn(manifest.chrome.footer, footer.layout)
|
|
88
|
+
const closingRaw = footer.closing
|
|
89
|
+
const headline = closingRaw ? str(closingRaw.headline) : null
|
|
90
|
+
const image = closingRaw ? str(closingRaw.image_url) : null
|
|
91
|
+
const closing: ClosingCall | null =
|
|
92
|
+
layout === 'closing' && closingRaw && headline
|
|
93
|
+
? {
|
|
94
|
+
headline,
|
|
95
|
+
body: str(closingRaw.body),
|
|
96
|
+
tagline: str(closingRaw.tagline),
|
|
97
|
+
// The photo only from an address this site would load as an image.
|
|
98
|
+
imageUrl: image && /^https:\/\//.test(image) ? image : null,
|
|
99
|
+
buttons: linksOf(closingRaw.buttons).slice(0, 2),
|
|
100
|
+
}
|
|
101
|
+
: null
|
|
102
|
+
return {
|
|
103
|
+
header: { layout: drawn(manifest.chrome.header, raw.header?.layout) },
|
|
104
|
+
footer: {
|
|
105
|
+
layout,
|
|
106
|
+
blurb: str(footer.blurb),
|
|
107
|
+
address: str(footer.address),
|
|
108
|
+
phone: str(footer.phone),
|
|
109
|
+
legalLinks: linksOf(footer.legal_links),
|
|
110
|
+
copyright: str(footer.copyright),
|
|
111
|
+
closing,
|
|
112
|
+
},
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The bottom row's copyright line: the one written, else "© <year> <name>". */
|
|
117
|
+
export function copyrightLine(written: string | null, name: string, year = new Date().getFullYear()): string {
|
|
118
|
+
return written ?? `© ${year} ${name}`
|
|
119
|
+
}
|