@backgold/template-kit 0.0.0-stage → 0.1.1

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.
Files changed (349) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/chunk-RJAVFRC6.js +67 -0
  4. package/dist/constants-BAIo_Q5U.d-lQbj1e1-.d.ts +48 -0
  5. package/dist/content-api-Cox1-wz5.d.ts +1096 -0
  6. package/dist/contract/content-api-examples.d.ts +72 -0
  7. package/dist/contract/content-api-examples.js +926 -0
  8. package/dist/contract/content-api.d.ts +2 -0
  9. package/dist/contract/content-api.js +1 -0
  10. package/dist/contract/site-templates.d.ts +253 -0
  11. package/dist/contract/site-templates.js +185 -0
  12. package/package.json +70 -3
  13. package/src/components/EntryCard.astro +35 -0
  14. package/src/components/EventMap.astro +118 -0
  15. package/src/components/EventPage.astro +194 -0
  16. package/src/components/FieldValue.astro +41 -0
  17. package/src/components/LeadingHero.astro +21 -0
  18. package/src/components/NotFound.astro +20 -0
  19. package/src/components/PageSections.astro +47 -0
  20. package/src/components/Prose.astro +18 -0
  21. package/src/components/chrome/Brand.astro +61 -0
  22. package/src/components/chrome/ClosingCall.astro +94 -0
  23. package/src/components/chrome/DonateStrip.astro +61 -0
  24. package/src/components/chrome/FooterColumns.astro +32 -0
  25. package/src/components/chrome/FooterContact.astro +28 -0
  26. package/src/components/chrome/MenuList.astro +45 -0
  27. package/src/components/chrome/ModeToggle.astro +125 -0
  28. package/src/components/chrome/SignedInNotice.astro +53 -0
  29. package/src/components/chrome/SignupBand.astro +12 -0
  30. package/src/components/chrome/TakeoverBanner.astro +56 -0
  31. package/src/components/chrome/VisitorAccount.astro +82 -0
  32. package/src/components/entries/AuthorBox.astro +47 -0
  33. package/src/components/entries/EntryFields.astro +29 -0
  34. package/src/components/entries/EntryHeader.astro +77 -0
  35. package/src/components/entries/ListFrame.astro +126 -0
  36. package/src/components/entries/ListSearch.astro +24 -0
  37. package/src/components/entries/Share.astro +24 -0
  38. package/src/components/entries/course/classroom.astro +26 -0
  39. package/src/components/entries/course/lesson.astro +18 -0
  40. package/src/components/entries/course/section.ts +20 -0
  41. package/src/components/entries/course/syllabus.astro +15 -0
  42. package/src/components/entries/index.ts +77 -0
  43. package/src/components/entries/newsletter/issue.astro +41 -0
  44. package/src/components/entries/newsletter/list.astro +26 -0
  45. package/src/components/entries/podcast/episode.astro +42 -0
  46. package/src/components/entries/podcast/list.astro +36 -0
  47. package/src/components/entries/post/article.astro +31 -0
  48. package/src/components/entries/post/list.astro +85 -0
  49. package/src/components/entries/props.ts +61 -0
  50. package/src/components/entries/video/cards.astro +39 -0
  51. package/src/components/entries/video/grid.astro +15 -0
  52. package/src/components/entries/video/watch.astro +41 -0
  53. package/src/components/live/LivePage.astro +215 -0
  54. package/src/components/live/LocalTime.astro +29 -0
  55. package/src/components/sections/About/books.astro +188 -0
  56. package/src/components/sections/About/credentials.ts +80 -0
  57. package/src/components/sections/About/index.astro +60 -0
  58. package/src/components/sections/About/left.astro +57 -0
  59. package/src/components/sections/About/letter.astro +111 -0
  60. package/src/components/sections/About/portrait.astro +308 -0
  61. package/src/components/sections/Advocacy/compact.astro +14 -0
  62. package/src/components/sections/Advocacy/index.astro +14 -0
  63. package/src/components/sections/Band.astro +39 -0
  64. package/src/components/sections/Blog/feature.astro +176 -0
  65. package/src/components/sections/Blog/index.astro +37 -0
  66. package/src/components/sections/Blog/latest.ts +80 -0
  67. package/src/components/sections/Blog/list.astro +186 -0
  68. package/src/components/sections/Booking/index.astro +139 -0
  69. package/src/components/sections/Booking/list.astro +144 -0
  70. package/src/components/sections/Booking/types.ts +60 -0
  71. package/src/components/sections/Calendar/agenda.astro +14 -0
  72. package/src/components/sections/Calendar/index.astro +14 -0
  73. package/src/components/sections/CandidateRoster/ballot.astro +394 -0
  74. package/src/components/sections/CandidateRoster/candidates.ts +69 -0
  75. package/src/components/sections/CandidateRoster/compact.astro +115 -0
  76. package/src/components/sections/CandidateRoster/index.astro +57 -0
  77. package/src/components/sections/CaseStudies/beforeafter.astro +222 -0
  78. package/src/components/sections/CaseStudies/cases.ts +111 -0
  79. package/src/components/sections/CaseStudies/grid.astro +261 -0
  80. package/src/components/sections/CaseStudies/index.astro +333 -0
  81. package/src/components/sections/Classroom/CourseCard.astro +181 -0
  82. package/src/components/sections/Classroom/Courses.astro +88 -0
  83. package/src/components/sections/Classroom/classroom.ts +141 -0
  84. package/src/components/sections/Classroom/index.astro +20 -0
  85. package/src/components/sections/Classroom/list.astro +15 -0
  86. package/src/components/sections/Collection/compact.astro +7 -0
  87. package/src/components/sections/Collection/entries.ts +62 -0
  88. package/src/components/sections/Collection/feature.astro +180 -0
  89. package/src/components/sections/Collection/index.astro +46 -0
  90. package/src/components/sections/Collection/library.astro +271 -0
  91. package/src/components/sections/Collection/list.astro +7 -0
  92. package/src/components/sections/Collection/outline.astro +134 -0
  93. package/src/components/sections/Collection/shelves.astro +191 -0
  94. package/src/components/sections/Comparison/Unlisted.astro +6 -0
  95. package/src/components/sections/Comparison/cards.astro +171 -0
  96. package/src/components/sections/Comparison/index.astro +191 -0
  97. package/src/components/sections/Comparison/sides.ts +98 -0
  98. package/src/components/sections/Comparison/spectrum.astro +261 -0
  99. package/src/components/sections/ContentPost/banner.astro +152 -0
  100. package/src/components/sections/ContentPost/index.astro +35 -0
  101. package/src/components/sections/ContentPost/lesson.ts +126 -0
  102. package/src/components/sections/ContentPost/player.astro +254 -0
  103. package/src/components/sections/ContentPost/prose.astro +80 -0
  104. package/src/components/sections/ContentPost/theater.astro +329 -0
  105. package/src/components/sections/Countdown/index.astro +53 -0
  106. package/src/components/sections/Course/Bar.astro +46 -0
  107. package/src/components/sections/Course/CourseHead.astro +123 -0
  108. package/src/components/sections/Course/Crumbs.astro +44 -0
  109. package/src/components/sections/Course/Icon.astro +29 -0
  110. package/src/components/sections/Course/Ring.astro +62 -0
  111. package/src/components/sections/Course/Syllabus.astro +146 -0
  112. package/src/components/sections/Course/course.ts +146 -0
  113. package/src/components/sections/Course/index.astro +143 -0
  114. package/src/components/sections/Course/outline.astro +39 -0
  115. package/src/components/sections/Cta/banner.astro +64 -0
  116. package/src/components/sections/Cta/card.astro +88 -0
  117. package/src/components/sections/Cta/index.astro +31 -0
  118. package/src/components/sections/Cta/photo.astro +114 -0
  119. package/src/components/sections/Cta/strip.astro +91 -0
  120. package/src/components/sections/Donate/index.astro +136 -0
  121. package/src/components/sections/Donate/story.astro +7 -0
  122. package/src/components/sections/Event/card.astro +14 -0
  123. package/src/components/sections/Event/index.astro +14 -0
  124. package/src/components/sections/EventsList/AgendaMonths.astro +105 -0
  125. package/src/components/sections/EventsList/CalendarLine.astro +23 -0
  126. package/src/components/sections/EventsList/EventRows.astro +196 -0
  127. package/src/components/sections/EventsList/LiveCounts.astro +75 -0
  128. package/src/components/sections/EventsList/TypeTabs.astro +53 -0
  129. package/src/components/sections/EventsList/agenda.astro +55 -0
  130. package/src/components/sections/EventsList/calendar.astro +392 -0
  131. package/src/components/sections/EventsList/cards.astro +186 -0
  132. package/src/components/sections/EventsList/cohorts.astro +205 -0
  133. package/src/components/sections/EventsList/compact.astro +163 -0
  134. package/src/components/sections/EventsList/events.ts +168 -0
  135. package/src/components/sections/EventsList/index.astro +46 -0
  136. package/src/components/sections/EventsList/map.astro +436 -0
  137. package/src/components/sections/EventsList/shifts.astro +355 -0
  138. package/src/components/sections/EventsList/week.astro +361 -0
  139. package/src/components/sections/Faq/Contact.astro +63 -0
  140. package/src/components/sections/Faq/Questions.astro +98 -0
  141. package/src/components/sections/Faq/cards.astro +74 -0
  142. package/src/components/sections/Faq/faq.ts +101 -0
  143. package/src/components/sections/Faq/index.astro +49 -0
  144. package/src/components/sections/Faq/topics.astro +178 -0
  145. package/src/components/sections/Financials/Foot.astro +38 -0
  146. package/src/components/sections/Financials/Head.astro +47 -0
  147. package/src/components/sections/Financials/donut.astro +197 -0
  148. package/src/components/sections/Financials/financials.ts +52 -0
  149. package/src/components/sections/Financials/index.astro +148 -0
  150. package/src/components/sections/Financials/table.astro +157 -0
  151. package/src/components/sections/FormBlock/index.astro +33 -0
  152. package/src/components/sections/FormBlock/wide.astro +7 -0
  153. package/src/components/sections/Hero/cover.astro +176 -0
  154. package/src/components/sections/Hero/donate.astro +209 -0
  155. package/src/components/sections/Hero/field.astro +390 -0
  156. package/src/components/sections/Hero/index.astro +52 -0
  157. package/src/components/sections/Hero/overlap.astro +151 -0
  158. package/src/components/sections/Hero/rotating.astro +30 -0
  159. package/src/components/sections/Hero/split.astro +99 -0
  160. package/src/components/sections/Hero/statement.astro +55 -0
  161. package/src/components/sections/Hero/video.astro +399 -0
  162. package/src/components/sections/Issues/checklist.astro +204 -0
  163. package/src/components/sections/Issues/drawer.astro +237 -0
  164. package/src/components/sections/Issues/index.astro +115 -0
  165. package/src/components/sections/Issues/issues.ts +37 -0
  166. package/src/components/sections/Issues/numbered.astro +79 -0
  167. package/src/components/sections/Issues/rows.astro +137 -0
  168. package/src/components/sections/Issues/steps.astro +81 -0
  169. package/src/components/sections/Issues/tabs.astro +322 -0
  170. package/src/components/sections/Leaderboard/index.astro +29 -0
  171. package/src/components/sections/Lesson/Door.astro +121 -0
  172. package/src/components/sections/Lesson/LessonBody.astro +416 -0
  173. package/src/components/sections/Lesson/Rail.astro +182 -0
  174. package/src/components/sections/Lesson/Tracker.astro +137 -0
  175. package/src/components/sections/Lesson/index.astro +27 -0
  176. package/src/components/sections/Lesson/lesson.ts +233 -0
  177. package/src/components/sections/Lesson/reading.astro +21 -0
  178. package/src/components/sections/Map/CoverageLine.astro +19 -0
  179. package/src/components/sections/Map/RegionMap.astro +109 -0
  180. package/src/components/sections/Map/bar.astro +160 -0
  181. package/src/components/sections/Map/index.astro +192 -0
  182. package/src/components/sections/Map/map.astro +275 -0
  183. package/src/components/sections/MediaKit/BioCard.astro +108 -0
  184. package/src/components/sections/MediaKit/Downloads.astro +88 -0
  185. package/src/components/sections/MediaKit/index.astro +183 -0
  186. package/src/components/sections/MediaKit/kit.ts +140 -0
  187. package/src/components/sections/MediaKit/press.astro +189 -0
  188. package/src/components/sections/MediaKit/speaker.astro +205 -0
  189. package/src/components/sections/Membership/Benefits.astro +42 -0
  190. package/src/components/sections/Membership/Check.astro +12 -0
  191. package/src/components/sections/Membership/Price.astro +61 -0
  192. package/src/components/sections/Membership/compare.astro +312 -0
  193. package/src/components/sections/Membership/index.astro +281 -0
  194. package/src/components/sections/Membership/offers.ts +169 -0
  195. package/src/components/sections/Membership/tiers.astro +217 -0
  196. package/src/components/sections/MovementMap/index.astro +50 -0
  197. package/src/components/sections/MovementTicker/index.astro +43 -0
  198. package/src/components/sections/Pathways/Doors.astro +147 -0
  199. package/src/components/sections/Pathways/Head.astro +37 -0
  200. package/src/components/sections/Pathways/index.astro +27 -0
  201. package/src/components/sections/Pathways/pathways.ts +100 -0
  202. package/src/components/sections/Pathways/quiz.astro +286 -0
  203. package/src/components/sections/Pathways/tabs.astro +271 -0
  204. package/src/components/sections/PdfEmbed/card.astro +99 -0
  205. package/src/components/sections/PdfEmbed/index.astro +26 -0
  206. package/src/components/sections/PdfEmbed/medium.astro +7 -0
  207. package/src/components/sections/PdfEmbed/tall.astro +7 -0
  208. package/src/components/sections/Petition/coverage.astro +14 -0
  209. package/src/components/sections/Petition/image.astro +14 -0
  210. package/src/components/sections/Petition/index.astro +14 -0
  211. package/src/components/sections/Petition/map.astro +14 -0
  212. package/src/components/sections/PlatformPlanks/anchors.ts +66 -0
  213. package/src/components/sections/PlatformPlanks/columns.astro +171 -0
  214. package/src/components/sections/PlatformPlanks/index.astro +56 -0
  215. package/src/components/sections/PlatformPlanks/longread.astro +250 -0
  216. package/src/components/sections/PollBlock/index.astro +30 -0
  217. package/src/components/sections/Portfolio/featured.astro +343 -0
  218. package/src/components/sections/Portfolio/index.astro +571 -0
  219. package/src/components/sections/Portfolio/strip.astro +173 -0
  220. package/src/components/sections/Portfolio/work.ts +100 -0
  221. package/src/components/sections/Progress/MatchClock.astro +166 -0
  222. package/src/components/sections/Progress/compact.astro +150 -0
  223. package/src/components/sections/Progress/index.astro +32 -0
  224. package/src/components/sections/Progress/match.astro +126 -0
  225. package/src/components/sections/Progress/ring.astro +179 -0
  226. package/src/components/sections/QuickDonate/DonateCard.astro +149 -0
  227. package/src/components/sections/QuickDonate/Picker.astro +95 -0
  228. package/src/components/sections/QuickDonate/band.astro +164 -0
  229. package/src/components/sections/QuickDonate/bar.astro +208 -0
  230. package/src/components/sections/QuickDonate/donate.ts +126 -0
  231. package/src/components/sections/QuickDonate/hero.astro +143 -0
  232. package/src/components/sections/QuickDonate/index.astro +73 -0
  233. package/src/components/sections/QuickDonate/jar.astro +225 -0
  234. package/src/components/sections/QuickDonate/ladder.astro +248 -0
  235. package/src/components/sections/QuoteStrip/carousel.astro +340 -0
  236. package/src/components/sections/QuoteStrip/index.astro +58 -0
  237. package/src/components/sections/QuoteStrip/logos.astro +226 -0
  238. package/src/components/sections/QuoteStrip/quotes.ts +61 -0
  239. package/src/components/sections/QuoteStrip/single.astro +92 -0
  240. package/src/components/sections/QuoteStrip/ticker.astro +319 -0
  241. package/src/components/sections/QuoteStrip/wall.astro +113 -0
  242. package/src/components/sections/Resources/band.astro +93 -0
  243. package/src/components/sections/Resources/featured.astro +239 -0
  244. package/src/components/sections/Resources/index.astro +225 -0
  245. package/src/components/sections/Resources/resources.ts +92 -0
  246. package/src/components/sections/SampleBallot/Position.astro +39 -0
  247. package/src/components/sections/SampleBallot/ballot.ts +92 -0
  248. package/src/components/sections/SampleBallot/cards.astro +299 -0
  249. package/src/components/sections/SampleBallot/index.astro +326 -0
  250. package/src/components/sections/SampleBallot/measures.astro +172 -0
  251. package/src/components/sections/Scorecard/grades.astro +141 -0
  252. package/src/components/sections/Scorecard/index.astro +294 -0
  253. package/src/components/sections/Scorecard/promise.astro +167 -0
  254. package/src/components/sections/Scorecard/votes.ts +83 -0
  255. package/src/components/sections/SectionHead.astro +31 -0
  256. package/src/components/sections/Services/Button.astro +24 -0
  257. package/src/components/sections/Services/Check.astro +12 -0
  258. package/src/components/sections/Services/Includes.astro +42 -0
  259. package/src/components/sections/Services/compare.astro +328 -0
  260. package/src/components/sections/Services/index.astro +187 -0
  261. package/src/components/sections/Services/list.astro +181 -0
  262. package/src/components/sections/Services/services.ts +80 -0
  263. package/src/components/sections/ShareKit/Actions.astro +71 -0
  264. package/src/components/sections/ShareKit/Buttons.astro +62 -0
  265. package/src/components/sections/ShareKit/compact.astro +123 -0
  266. package/src/components/sections/ShareKit/index.astro +160 -0
  267. package/src/components/sections/ShareKit/share.ts +60 -0
  268. package/src/components/sections/ShareKit/strip.astro +173 -0
  269. package/src/components/sections/SignupCapture/band.astro +7 -0
  270. package/src/components/sections/SignupCapture/index.astro +103 -0
  271. package/src/components/sections/SignupCapture/inline.astro +7 -0
  272. package/src/components/sections/SocialFeed/index.astro +34 -0
  273. package/src/components/sections/StatCards/feature.astro +143 -0
  274. package/src/components/sections/StatCards/index.astro +51 -0
  275. package/src/components/sections/StatCards/ribbon.astro +113 -0
  276. package/src/components/sections/StatCards/wall.astro +177 -0
  277. package/src/components/sections/Store/featured.astro +14 -0
  278. package/src/components/sections/Store/index.astro +14 -0
  279. package/src/components/sections/Stories/Status.astro +42 -0
  280. package/src/components/sections/Stories/StoryCards.astro +171 -0
  281. package/src/components/sections/Stories/cards.astro +42 -0
  282. package/src/components/sections/Stories/index.astro +238 -0
  283. package/src/components/sections/Stories/stories.ts +97 -0
  284. package/src/components/sections/Stories/timeline.astro +135 -0
  285. package/src/components/sections/TeamGrid/board.astro +280 -0
  286. package/src/components/sections/TeamGrid/index.astro +71 -0
  287. package/src/components/sections/TeamGrid/list.astro +306 -0
  288. package/src/components/sections/TeamGrid/people.ts +178 -0
  289. package/src/components/sections/VideoEmbed/index.astro +52 -0
  290. package/src/components/sections/VideoEmbed/landscape.astro +7 -0
  291. package/src/components/sections/VideoEmbed/portrait.astro +7 -0
  292. package/src/components/sections/VideoEmbed/square.astro +7 -0
  293. package/src/components/sections/VoterTools/DaysLeft.astro +33 -0
  294. package/src/components/sections/VoterTools/Lookup.astro +43 -0
  295. package/src/components/sections/VoterTools/dates.astro +153 -0
  296. package/src/components/sections/VoterTools/index.astro +231 -0
  297. package/src/components/sections/VoterTools/polling.astro +144 -0
  298. package/src/components/sections/VoterTools/voter-tools.ts +71 -0
  299. package/src/components/sections/index.ts +373 -0
  300. package/src/components/sections/modules/Headed.astro +39 -0
  301. package/src/components/sections/modules/ModuleFrame.astro +181 -0
  302. package/src/components/store/CollectionPage.astro +40 -0
  303. package/src/components/store/ProductCard.astro +32 -0
  304. package/src/components/store/ProductGrid.astro +16 -0
  305. package/src/components/store/ProductPage.astro +146 -0
  306. package/src/components/store/StorePage.astro +137 -0
  307. package/src/components/store/StoreScript.astro +572 -0
  308. package/src/components/volunteer/ShiftLive.astro +90 -0
  309. package/src/components/volunteer/detail.astro +247 -0
  310. package/src/components/volunteer/list.astro +298 -0
  311. package/src/components/volunteer/props.ts +21 -0
  312. package/src/env.d.ts +22 -0
  313. package/src/index.d.ts +10 -0
  314. package/src/index.js +63 -0
  315. package/src/layouts/Site.astro +387 -0
  316. package/src/lib/academy.ts +146 -0
  317. package/src/lib/brand.ts +534 -0
  318. package/src/lib/chrome.ts +121 -0
  319. package/src/lib/donate-frame.ts +104 -0
  320. package/src/lib/entries.ts +190 -0
  321. package/src/lib/env.ts +34 -0
  322. package/src/lib/event-map-draw.ts +91 -0
  323. package/src/lib/events.ts +476 -0
  324. package/src/lib/fonts.ts +116 -0
  325. package/src/lib/footer.ts +24 -0
  326. package/src/lib/format.ts +160 -0
  327. package/src/lib/geo.ts +131 -0
  328. package/src/lib/live.ts +55 -0
  329. package/src/lib/menu.ts +48 -0
  330. package/src/lib/petition-text.ts +29 -0
  331. package/src/lib/reading.ts +17 -0
  332. package/src/lib/regions.ts +215 -0
  333. package/src/lib/section.ts +105 -0
  334. package/src/lib/shifts.ts +187 -0
  335. package/src/lib/store.ts +521 -0
  336. package/src/lib/stream-time.ts +20 -0
  337. package/src/lib/stream.ts +141 -0
  338. package/src/lib/visitor.ts +54 -0
  339. package/src/routes/catch-all.astro +435 -0
  340. package/src/routes/form.astro +30 -0
  341. package/src/routes/live.astro +49 -0
  342. package/src/routes/not-found.astro +18 -0
  343. package/src/routes/preview.astro +60 -0
  344. package/src/routes/setup.astro +62 -0
  345. package/src/routes/volunteer-shift.astro +61 -0
  346. package/src/styles/entries.css +784 -0
  347. package/src/styles/site.css +1910 -0
  348. package/src/styles/store.css +634 -0
  349. package/src/template.ts +182 -0
@@ -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,121 @@
1
+ // The site's header and footer as BackGold's operator set them up: GET /site's
2
+ // `chrome` (each part's layout, the header's name beside the logo and the
3
+ // footer's own words), against what the
4
+ // template's template.json `chrome` (its config's manifest) says it draws. A
5
+ // layout the site names that the template does not list is drawn as the
6
+ // template's first, exactly as a section's variant falls back; a `/site`
7
+ // answer with no `chrome` at all (an older BackGold) reads as the template's
8
+ // firsts and no words.
9
+ import type { SiteTemplateManifest } from '#contract/site-templates'
10
+ import { relFor, safeHref } from '@backgold/astro/server'
11
+
12
+ export type HeaderLayout = SiteTemplateManifest['chrome']['header'][number]
13
+ export type FooterLayout = SiteTemplateManifest['chrome']['footer'][number]
14
+
15
+ /** A link on the footer's bottom row, or a closing-call button: its address already checked. */
16
+ export interface ChromeLink {
17
+ label: string
18
+ href: string
19
+ rel: string | undefined
20
+ }
21
+
22
+ /** The footer's closing call (its `closing` layout). */
23
+ export interface ClosingCall {
24
+ headline: string
25
+ body: string | null
26
+ tagline: string | null
27
+ imageUrl: string | null
28
+ buttons: ChromeLink[]
29
+ }
30
+
31
+ export interface SiteChrome {
32
+ /** `showName`: the name in type beside the organization's logo (off unless the operator turned it on). */
33
+ header: { layout: HeaderLayout; showName: boolean }
34
+ footer: {
35
+ layout: FooterLayout
36
+ blurb: string | null
37
+ address: string | null
38
+ phone: string | null
39
+ legalLinks: ChromeLink[]
40
+ copyright: string | null
41
+ closing: ClosingCall | null
42
+ }
43
+ }
44
+
45
+ /** What `/site` carries, read structurally so an older answer still parses. */
46
+ interface Raw {
47
+ chrome?: {
48
+ header?: { layout?: unknown; show_name?: unknown }
49
+ footer?: {
50
+ layout?: unknown
51
+ blurb?: unknown
52
+ address?: unknown
53
+ phone?: unknown
54
+ legal_links?: unknown
55
+ copyright?: unknown
56
+ closing?: {
57
+ headline?: unknown
58
+ body?: unknown
59
+ tagline?: unknown
60
+ image_url?: unknown
61
+ buttons?: unknown
62
+ } | null
63
+ }
64
+ }
65
+ }
66
+
67
+ const str = (value: unknown): string | null => (typeof value === 'string' && value.trim() ? value.trim() : null)
68
+
69
+ /** The layout this template draws for a stored value: the value when listed, else the template's first. */
70
+ function drawn<T extends string>(listed: readonly T[], value: unknown): T {
71
+ return typeof value === 'string' && (listed as readonly string[]).includes(value) ? (value as T) : listed[0]!
72
+ }
73
+
74
+ /** The rows that have a label and an address safe to follow, in order. */
75
+ function linksOf(value: unknown): ChromeLink[] {
76
+ if (!Array.isArray(value)) return []
77
+ const out: ChromeLink[] = []
78
+ for (const row of value as Array<{ label?: unknown; url?: unknown }>) {
79
+ const label = str(row?.label)
80
+ const href = typeof row?.url === 'string' ? safeHref(row.url) : null
81
+ if (label && href) out.push({ label, href, rel: relFor(href) })
82
+ }
83
+ return out
84
+ }
85
+
86
+ export function chromeOf(site: unknown, manifest: SiteTemplateManifest): SiteChrome {
87
+ const raw = ((site ?? {}) as Raw).chrome ?? {}
88
+ const footer = raw.footer ?? {}
89
+ const layout = drawn(manifest.chrome.footer, footer.layout)
90
+ const closingRaw = footer.closing
91
+ const headline = closingRaw ? str(closingRaw.headline) : null
92
+ const image = closingRaw ? str(closingRaw.image_url) : null
93
+ const closing: ClosingCall | null =
94
+ layout === 'closing' && closingRaw && headline
95
+ ? {
96
+ headline,
97
+ body: str(closingRaw.body),
98
+ tagline: str(closingRaw.tagline),
99
+ // The photo only from an address this site would load as an image.
100
+ imageUrl: image && /^https:\/\//.test(image) ? image : null,
101
+ buttons: linksOf(closingRaw.buttons).slice(0, 2),
102
+ }
103
+ : null
104
+ return {
105
+ header: { layout: drawn(manifest.chrome.header, raw.header?.layout), showName: raw.header?.show_name === true },
106
+ footer: {
107
+ layout,
108
+ blurb: str(footer.blurb),
109
+ address: str(footer.address),
110
+ phone: str(footer.phone),
111
+ legalLinks: linksOf(footer.legal_links),
112
+ copyright: str(footer.copyright),
113
+ closing,
114
+ },
115
+ }
116
+ }
117
+
118
+ /** The bottom row's copyright line: the one written, else "© <year> <name>". */
119
+ export function copyrightLine(written: string | null, name: string, year = new Date().getFullYear()): string {
120
+ return written ?? `© ${year} ${name}`
121
+ }