@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.
- package/LICENSE +21 -0
- package/README.md +12 -2
- package/dist/chunk-RJAVFRC6.js +67 -0
- package/dist/constants-BAIo_Q5U.d-lQbj1e1-.d.ts +48 -0
- package/dist/content-api-Cox1-wz5.d.ts +1096 -0
- package/dist/contract/content-api-examples.d.ts +72 -0
- package/dist/contract/content-api-examples.js +926 -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 +253 -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 +61 -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 +80 -0
- package/src/components/sections/About/index.astro +60 -0
- package/src/components/sections/About/left.astro +57 -0
- package/src/components/sections/About/letter.astro +111 -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 +126 -0
- package/src/components/sections/ContentPost/player.astro +254 -0
- package/src/components/sections/ContentPost/prose.astro +80 -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 +176 -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 +99 -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/Lookup.astro +43 -0
- package/src/components/sections/VoterTools/dates.astro +153 -0
- package/src/components/sections/VoterTools/index.astro +231 -0
- package/src/components/sections/VoterTools/polling.astro +144 -0
- package/src/components/sections/VoterTools/voter-tools.ts +71 -0
- package/src/components/sections/index.ts +373 -0
- package/src/components/sections/modules/Headed.astro +39 -0
- package/src/components/sections/modules/ModuleFrame.astro +181 -0
- package/src/components/store/CollectionPage.astro +40 -0
- package/src/components/store/ProductCard.astro +32 -0
- package/src/components/store/ProductGrid.astro +16 -0
- package/src/components/store/ProductPage.astro +146 -0
- package/src/components/store/StorePage.astro +137 -0
- package/src/components/store/StoreScript.astro +572 -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 +63 -0
- package/src/layouts/Site.astro +387 -0
- package/src/lib/academy.ts +146 -0
- package/src/lib/brand.ts +534 -0
- package/src/lib/chrome.ts +121 -0
- package/src/lib/donate-frame.ts +104 -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 +55 -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 +105 -0
- package/src/lib/shifts.ts +187 -0
- package/src/lib/store.ts +521 -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 +435 -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/styles/entries.css +784 -0
- package/src/styles/site.css +1910 -0
- package/src/styles/store.css +634 -0
- package/src/template.ts +182 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// A Donate frame's share of the page's address. A link to a site's Donate
|
|
2
|
+
// page carries what the gift starts with: QuickDonate's amounts link to
|
|
3
|
+
// `/donate?amount=25`, a donate place that opens a page links to
|
|
4
|
+
// `<page>?place=<slug>`, a mailer's link carries its `utm_*` names. The frame
|
|
5
|
+
// (sections/modules/ModuleFrame.astro) copies those names from the page's
|
|
6
|
+
// address into its own, as BackGold's hosted Donate page copies them into its
|
|
7
|
+
// checkout frame; the checkout inside the frame reads and checks its own
|
|
8
|
+
// address, so a name not copied never reaches it.
|
|
9
|
+
//
|
|
10
|
+
// The edge cache keys a page by its path alone (with a list's `cursor` and
|
|
11
|
+
// `q`), so a page that draws a Donate frame says it reads these names
|
|
12
|
+
// (READS_QUERY_HEADER): its stored copy is never served to a request that
|
|
13
|
+
// carries one, and that request's render is `no-store` (catch-all.astro).
|
|
14
|
+
|
|
15
|
+
import type { Areas, Section } from '@backgold/content'
|
|
16
|
+
|
|
17
|
+
/** The section types that draw BackGold's donate checkout in a frame. */
|
|
18
|
+
const DONATE_FRAME_TYPES = new Set(['Donate', 'QuickDonate'])
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The names the hosted Donate page copies (the platform's
|
|
22
|
+
* DONATE_DOOR_PASSTHROUGH_KEYS, its five `utm_*` included) and the donate
|
|
23
|
+
* place's `place`. Every other `utm_*` name is copied too (UTM_PREFIX).
|
|
24
|
+
*/
|
|
25
|
+
const DONATE_QUERY_NAMES = ['amount', 'frequency', 'fund', 'email', 'ref', 'place', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content']
|
|
26
|
+
const UTM_PREFIX = 'utm_'
|
|
27
|
+
|
|
28
|
+
/** The value of the page's READS_QUERY_HEADER when it draws a Donate frame. */
|
|
29
|
+
export const DONATE_READS_QUERY = [...DONATE_QUERY_NAMES, `${UTM_PREFIX}*`].join(',')
|
|
30
|
+
|
|
31
|
+
function isDonateName(name: string): boolean {
|
|
32
|
+
return DONATE_QUERY_NAMES.includes(name) || name.startsWith(UTM_PREFIX)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Whether a frame of this module type takes the page's donate names. */
|
|
36
|
+
export function isDonateFrame(type: string): boolean {
|
|
37
|
+
return DONATE_FRAME_TYPES.has(type)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The frame's address with the page's donate names added: each name's first
|
|
42
|
+
* value, when it is not empty and the address does not already carry that
|
|
43
|
+
* name (BackGold's own wins).
|
|
44
|
+
*/
|
|
45
|
+
export function withDonateQuery(frame: URL, page: URLSearchParams): void {
|
|
46
|
+
for (const [name, value] of page) {
|
|
47
|
+
if (value && isDonateName(name) && !frame.searchParams.has(name)) frame.searchParams.set(name, value)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Whether the page's address carries a donate name with a value. */
|
|
52
|
+
export function carriesDonateQuery(page: URLSearchParams): boolean {
|
|
53
|
+
for (const [name, value] of page) if (value && isDonateName(name)) return true
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Whether a page with these sections and areas draws a frame of a type `draws` names anywhere. */
|
|
58
|
+
function drawsFrame(sections: Section[], areas: Areas | null, draws: (type: string) => boolean): boolean {
|
|
59
|
+
if (sections.some((s) => draws(s.type))) return true
|
|
60
|
+
for (const items of Object.values(areas ?? {})) {
|
|
61
|
+
for (const item of items) if (item.sections.some((s) => draws(s.type))) return true
|
|
62
|
+
}
|
|
63
|
+
return false
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Whether a page with these sections and areas draws a Donate frame anywhere. */
|
|
67
|
+
export function drawsDonateFrame(sections: Section[], areas: Areas | null): boolean {
|
|
68
|
+
return drawsFrame(sections, areas, isDonateFrame)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ── A form frame's share of the page's address ──────────────────────────────
|
|
72
|
+
//
|
|
73
|
+
// A link to a page's form may name the choice it opens on: a site's open
|
|
74
|
+
// roles link to `/volunteer?pick=Phone%20Banker`, and the form's first
|
|
75
|
+
// Choose-one field offering that value takes it (BackGold's FormBlock frame
|
|
76
|
+
// reads `pick` off its own address). The frame copies the page's `pick`
|
|
77
|
+
// as it copies the donate names, and a page that draws a form frame says it
|
|
78
|
+
// reads the name (READS_QUERY_HEADER) the same way.
|
|
79
|
+
|
|
80
|
+
const FORM_FRAME_TYPES = new Set(['FormBlock'])
|
|
81
|
+
const PICK_NAME = 'pick'
|
|
82
|
+
/** The value of the page's READS_QUERY_HEADER when it draws a form frame. */
|
|
83
|
+
export const FORM_READS_QUERY = PICK_NAME
|
|
84
|
+
|
|
85
|
+
/** Whether a frame of this module type takes the page's `pick`. */
|
|
86
|
+
export function isFormFrame(type: string): boolean {
|
|
87
|
+
return FORM_FRAME_TYPES.has(type)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The frame's address with the page's `pick` added, when the page carries one the address does not. */
|
|
91
|
+
export function withPickQuery(frame: URL, page: URLSearchParams): void {
|
|
92
|
+
const pick = page.get(PICK_NAME)
|
|
93
|
+
if (pick && !frame.searchParams.has(PICK_NAME)) frame.searchParams.set(PICK_NAME, pick)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Whether the page's address carries a `pick` with a value. */
|
|
97
|
+
export function carriesPickQuery(page: URLSearchParams): boolean {
|
|
98
|
+
return !!page.get(PICK_NAME)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Whether a page with these sections and areas draws a form frame anywhere. */
|
|
102
|
+
export function drawsFormFrame(sections: Section[], areas: Areas | null): boolean {
|
|
103
|
+
return drawsFrame(sections, areas, isFormFrame)
|
|
104
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// Reading entries for the entry and list layouts (src/components/entries):
|
|
2
|
+
// where a type's list lives, a term's address, the byline, the reading time,
|
|
3
|
+
// the filter a list offers, the news list's search, and a video's player.
|
|
4
|
+
|
|
5
|
+
import type { BackgoldContent, ContentTypeSummary, EntriesResponse, Entry, EntryAuthor, PageResponse } from '@backgold/content'
|
|
6
|
+
import { isBlogType, type ResolvedType } from '@backgold/astro/server'
|
|
7
|
+
|
|
8
|
+
/** A list's path from its base, the address resolveRoute names it by (`news` is `/news`). */
|
|
9
|
+
export const basePath = (base: string): string => `/${encodeURIComponent(base)}`
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A list's name. The blog types' list (post, podcast and video together, at
|
|
13
|
+
* the organization's blog base) is named by its intro page's title when it
|
|
14
|
+
* has one, else by its address: "News" at `news`, "Blog" at `blog`. Every
|
|
15
|
+
* other type's list is named by its plural.
|
|
16
|
+
*/
|
|
17
|
+
export function listName(type: ResolvedType, base: string, intro: PageResponse | null = null): string {
|
|
18
|
+
if (type !== 'blog' && !isBlogType(type)) return type.plural_label
|
|
19
|
+
const words = base.replace(/-/g, ' ')
|
|
20
|
+
return intro?.page.title?.trim() || words.charAt(0).toUpperCase() + words.slice(1)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The list an entry of `type` is listed in, for its breadcrumb: the type's
|
|
25
|
+
* url_base, which for a blog type is the blog base its types share, and that
|
|
26
|
+
* list's name. Null for a type with no pages, or none.
|
|
27
|
+
*/
|
|
28
|
+
export function listOf(type: ContentTypeSummary | undefined): { path: string; name: string } | null {
|
|
29
|
+
if (!type?.routable || !type.url_base) return null
|
|
30
|
+
return { path: basePath(type.url_base), name: listName(type, type.url_base) }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The address of a term's list under a type's list. */
|
|
34
|
+
export function termPath(base: string, taxonomy: string, slug: string): string {
|
|
35
|
+
return `${base}/${encodeURIComponent(taxonomy)}/${encodeURIComponent(slug)}`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** One byline role and the people under it, in the order the entry lists them. */
|
|
39
|
+
export interface BylineGroup {
|
|
40
|
+
role: string
|
|
41
|
+
people: Array<EntryAuthor & { href: string }>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function bylineGroups(authors: EntryAuthor[]): BylineGroup[] {
|
|
45
|
+
const groups = new Map<string, BylineGroup['people']>()
|
|
46
|
+
for (const author of authors) {
|
|
47
|
+
groups.set(author.role, [...(groups.get(author.role) ?? []), { ...author, href: `/authors/${encodeURIComponent(author.slug)}` }])
|
|
48
|
+
}
|
|
49
|
+
return [...groups].map(([role, people]) => ({ role, people }))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The people who wrote it (or gave the interview), never its editor or photographer. */
|
|
53
|
+
export const writers = (authors: EntryAuthor[]): EntryAuthor[] => authors.filter((a) => a.role === 'Written by' || a.role === 'Interview by')
|
|
54
|
+
|
|
55
|
+
/** Initials for a person with no picture: "Dana K." is "DK". */
|
|
56
|
+
export function initials(name: string): string {
|
|
57
|
+
const letters = name
|
|
58
|
+
.split(/\s+/)
|
|
59
|
+
.map((word) => word.replace(/[^\p{L}]/gu, '').charAt(0))
|
|
60
|
+
.filter(Boolean)
|
|
61
|
+
return (letters.length > 1 ? letters[0]! + letters.at(-1)! : (letters[0] ?? '')).toUpperCase()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Minutes to read a markdown body at 220 words a minute; null for an empty body. */
|
|
65
|
+
export function readingMinutes(markdown: string | undefined): number | null {
|
|
66
|
+
const words = (markdown ?? '').replace(/[#>*_`[\]()!|-]/g, ' ').split(/\s+/).filter(Boolean).length
|
|
67
|
+
return words === 0 ? null : Math.max(1, Math.round(words / 220))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A list's filter: one taxonomy and the terms in it a listed entry carries. */
|
|
71
|
+
export interface ListFilter {
|
|
72
|
+
taxonomy: string
|
|
73
|
+
terms: Array<{ slug: string; label: string }>
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The filter a list offers: its categories, or its tags when no listed entry
|
|
78
|
+
* carries a category. Only terms a listed entry carries are offered, so a term
|
|
79
|
+
* with nothing published under it never shows; they are in label order here,
|
|
80
|
+
* and the list frame puts them in the organization's order (`listTermsOf`).
|
|
81
|
+
*/
|
|
82
|
+
export function filterOf(entries: Entry[]): ListFilter | null {
|
|
83
|
+
for (const taxonomy of ['category', 'tag']) {
|
|
84
|
+
const seen = new Map<string, string>()
|
|
85
|
+
for (const entry of entries) {
|
|
86
|
+
for (const term of entry.terms) if (term.taxonomy === taxonomy && !seen.has(term.slug)) seen.set(term.slug, term.label)
|
|
87
|
+
}
|
|
88
|
+
if (seen.size > 0) {
|
|
89
|
+
const terms = [...seen].map(([slug, label]) => ({ slug, label })).sort((a, b) => a.label.localeCompare(b.label))
|
|
90
|
+
return { taxonomy, terms }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return null
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The term a list frame draws as a link at the end of its filter row instead
|
|
98
|
+
* of as one of its chips (board C10's "Press releases →"): the category with
|
|
99
|
+
* this slug, when the organization has one. Named by its slug, so featuring
|
|
100
|
+
* it asks the Content API for nothing new; an organization that names its
|
|
101
|
+
* press category otherwise gets it as an ordinary chip.
|
|
102
|
+
*/
|
|
103
|
+
const FEATURED_TERM = { taxonomy: 'category', slug: 'press-releases' } as const
|
|
104
|
+
|
|
105
|
+
/** What a list frame's filter row draws: the chips, in order, and the featured term's link. */
|
|
106
|
+
export interface ListTerms {
|
|
107
|
+
chips: ListFilter['terms']
|
|
108
|
+
/** `key` is `<taxonomy>/<slug>`, as a term's list names its term. */
|
|
109
|
+
featured: { key: string; label: string; href: string } | null
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The filter's terms in the organization's order (each term's `position` from
|
|
114
|
+
* GET /terms, label order among equals and for a term /terms does not list),
|
|
115
|
+
* the featured term taken out of them, and the featured term's link under the
|
|
116
|
+
* list at `base` when its taxonomy lists it, whether or not a listed entry
|
|
117
|
+
* carries it.
|
|
118
|
+
*/
|
|
119
|
+
export async function listTermsOf(client: BackgoldContent, base: string, filter: ListFilter | null): Promise<ListTerms> {
|
|
120
|
+
const read = (taxonomy: string) => client.terms(taxonomy).catch(() => null)
|
|
121
|
+
const [own, featuredTaxonomy] = await Promise.all([
|
|
122
|
+
filter ? read(filter.taxonomy) : null,
|
|
123
|
+
filter?.taxonomy === FEATURED_TERM.taxonomy ? null : read(FEATURED_TERM.taxonomy),
|
|
124
|
+
])
|
|
125
|
+
const position = new Map((own?.terms ?? []).map((t) => [t.slug, t.position]))
|
|
126
|
+
const at = (slug: string) => position.get(slug) ?? Number.POSITIVE_INFINITY
|
|
127
|
+
const featuredIn = filter?.taxonomy === FEATURED_TERM.taxonomy ? own : featuredTaxonomy
|
|
128
|
+
const featured = featuredIn?.terms.find((t) => t.slug === FEATURED_TERM.slug) ?? null
|
|
129
|
+
const chips = (filter?.terms ?? [])
|
|
130
|
+
.filter((t) => !(featured && filter?.taxonomy === FEATURED_TERM.taxonomy && t.slug === featured.slug))
|
|
131
|
+
.sort((a, b) => at(a.slug) - at(b.slug) || a.label.localeCompare(b.label))
|
|
132
|
+
return {
|
|
133
|
+
chips,
|
|
134
|
+
featured: featured ? { key: `${FEATURED_TERM.taxonomy}/${featured.slug}`, label: featured.label, href: termPath(base, FEATURED_TERM.taxonomy, featured.slug) } : null,
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The entry's first term in the list's filter taxonomy (else its first term): the line over a row's title. */
|
|
139
|
+
export function rowTerm(entry: Entry, taxonomy: string | undefined): Entry['terms'][number] | null {
|
|
140
|
+
return entry.terms.find((t) => t.taxonomy === taxonomy) ?? entry.terms[0] ?? null
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** A type's singular name for an entry's type key, from GET /types. */
|
|
144
|
+
export function singularOf(types: ContentTypeSummary[], key: string): string | null {
|
|
145
|
+
return types.find((t) => t.key === key)?.singular_label ?? null
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** A YouTube or Vimeo address as its player's address (YouTube's privacy-enhanced one); null for anything else. */
|
|
149
|
+
export function playerOf(url: string): string | null {
|
|
150
|
+
let parsed: URL
|
|
151
|
+
try {
|
|
152
|
+
parsed = new URL(url)
|
|
153
|
+
} catch {
|
|
154
|
+
return null
|
|
155
|
+
}
|
|
156
|
+
const host = parsed.hostname.replace(/^www\./, '')
|
|
157
|
+
const youtube =
|
|
158
|
+
host === 'youtu.be'
|
|
159
|
+
? parsed.pathname.slice(1)
|
|
160
|
+
: host === 'youtube.com' || host === 'm.youtube.com'
|
|
161
|
+
? (parsed.searchParams.get('v') ?? /^\/(?:embed|shorts|live)\/([^/]+)/.exec(parsed.pathname)?.[1] ?? '')
|
|
162
|
+
: ''
|
|
163
|
+
if (/^[A-Za-z0-9_-]{11}$/.test(youtube)) return `https://www.youtube-nocookie.com/embed/${youtube}`
|
|
164
|
+
const vimeo = host === 'vimeo.com' || host === 'player.vimeo.com' ? /(\d{6,12})/.exec(parsed.pathname)?.[1] : undefined
|
|
165
|
+
return vimeo ? `https://player.vimeo.com/video/${vimeo}` : null
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** The shortest and longest search the Content API answers (`GET /entries/:type?q=`). */
|
|
169
|
+
const SEARCH_MIN = 2
|
|
170
|
+
const SEARCH_MAX = 80
|
|
171
|
+
|
|
172
|
+
/** A list's `?q=`, trimmed, when it is a search the api answers (2 to 80 characters); else null. */
|
|
173
|
+
export function searchQuery(raw: string | null): string | null {
|
|
174
|
+
const q = raw?.trim() ?? ''
|
|
175
|
+
const length = Array.from(q).length
|
|
176
|
+
return length >= SEARCH_MIN && length <= SEARCH_MAX ? q : null
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The news list's search: each blog type read with `?q=` (at most 20 entries
|
|
181
|
+
* each, no later page), newest first. Cached under the content version like
|
|
182
|
+
* every other read.
|
|
183
|
+
*/
|
|
184
|
+
export async function searchNews(client: BackgoldContent, q: string): Promise<Entry[]> {
|
|
185
|
+
const { types } = await client.types()
|
|
186
|
+
const pages = await Promise.all(types.filter(isBlogType).map((t) => client.raw<EntriesResponse>(`/entries/${encodeURIComponent(t.key)}`, { q })))
|
|
187
|
+
return pages
|
|
188
|
+
.flatMap((page) => page?.entries ?? [])
|
|
189
|
+
.sort((a, b) => ((a.publish_at ?? '') !== (b.publish_at ?? '') ? ((a.publish_at ?? '') < (b.publish_at ?? '') ? 1 : -1) : a.id < b.id ? 1 : -1))
|
|
190
|
+
}
|
package/src/lib/env.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// The Worker's vars and bindings: the `env` export of the Workers runtime
|
|
2
|
+
// module `cloudflare:workers`, imported on first use so a module that reads
|
|
3
|
+
// it still loads where that module does not exist (there, `{}`).
|
|
4
|
+
|
|
5
|
+
let loaded: Promise<Record<string, unknown>> | undefined
|
|
6
|
+
|
|
7
|
+
/** The Worker's `env`; `{}` where `cloudflare:workers` cannot be imported. */
|
|
8
|
+
export function workerVars(): Promise<Record<string, unknown>> {
|
|
9
|
+
loaded ??= import('cloudflare:workers').then(
|
|
10
|
+
(mod) => mod.env as Record<string, unknown>,
|
|
11
|
+
() => ({}),
|
|
12
|
+
)
|
|
13
|
+
return loaded
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** A string var, trimmed; '' for anything else. */
|
|
17
|
+
export const trimmed = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')
|
|
18
|
+
|
|
19
|
+
const DEFAULT_API_ORIGIN = 'https://api.backgold.com'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Where BackGold's api lives: `BACKGOLD_API_ORIGIN`, else
|
|
23
|
+
* `https://api.backgold.com`, without a trailing slash. Null when the var is
|
|
24
|
+
* not an http(s) URL, or carries a query or a fragment.
|
|
25
|
+
*/
|
|
26
|
+
export function apiOrigin(env: Record<string, unknown>): string | null {
|
|
27
|
+
const origin = (trimmed(env.BACKGOLD_API_ORIGIN) || DEFAULT_API_ORIGIN).replace(/\/+$/, '')
|
|
28
|
+
try {
|
|
29
|
+
const url = new URL(origin)
|
|
30
|
+
return (url.protocol === 'https:' || url.protocol === 'http:') && !url.search && !url.hash ? origin : null
|
|
31
|
+
} catch {
|
|
32
|
+
return null
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// The event page's map (board C6), drawn in the browser by MapLibre GL over
|
|
2
|
+
// OpenFreeMap's vector tiles (the host BackGold's own maps use): the venue's
|
|
3
|
+
// pin in the brand's accent, at street level, with zoom buttons. Scrolling
|
|
4
|
+
// the page never moves it: a wheel zooms only with Ctrl (⌘ on a Mac) held and
|
|
5
|
+
// a finger drags it only with two (MapLibre's cooperative gestures). The
|
|
6
|
+
// credit, OpenFreeMap's and "© OpenStreetMap contributors", opens in the
|
|
7
|
+
// corner and folds to its ⓘ button after five seconds or the first touch of
|
|
8
|
+
// the map; the button opens it again. The map follows the page's light or
|
|
9
|
+
// dark mode (the mode switch's `data-gg-mode`, else the system's). This
|
|
10
|
+
// module is the lazy part of EventMap.astro, loaded when the map nears the
|
|
11
|
+
// screen; MapLibre's tile worker is its own file beside it. Without WebGL the
|
|
12
|
+
// map is not drawn and the place's address and its OpenStreetMap link stay.
|
|
13
|
+
|
|
14
|
+
import { AttributionControl, Map as MapLibreMap, Marker, NavigationControl, setWorkerUrl } from 'maplibre-gl'
|
|
15
|
+
import workerUrl from 'maplibre-gl/dist/maplibre-gl-worker.mjs?url'
|
|
16
|
+
import 'maplibre-gl/dist/maplibre-gl.css'
|
|
17
|
+
|
|
18
|
+
const STYLES = {
|
|
19
|
+
light: 'https://tiles.openfreemap.org/styles/positron',
|
|
20
|
+
dark: 'https://tiles.openfreemap.org/styles/dark',
|
|
21
|
+
} as const
|
|
22
|
+
const OSM_CREDIT = '<a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">© OpenStreetMap contributors</a>'
|
|
23
|
+
const STREET_ZOOM = 15
|
|
24
|
+
const CREDIT_FOLDS_AFTER_MS = 5000
|
|
25
|
+
const PIN =
|
|
26
|
+
'<svg viewBox="0 0 32 42" aria-hidden="true" focusable="false"><path d="M16 41s14-13.2 14-24.5A14 14 0 0 0 2 16.5C2 27.8 16 41 16 41z"/><circle cx="16" cy="16.5" r="5.5"/></svg>'
|
|
27
|
+
|
|
28
|
+
function mode(): keyof typeof STYLES {
|
|
29
|
+
const chosen = document.documentElement.getAttribute('data-gg-mode')
|
|
30
|
+
if (chosen === 'dark' || chosen === 'light') return chosen
|
|
31
|
+
return window.matchMedia?.('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Draws the map into an EventMap figure (`data-lat`, `data-lng`, `data-label`). */
|
|
35
|
+
export function drawEventMap(figure: HTMLElement): void {
|
|
36
|
+
const lat = Number(figure.dataset.lat)
|
|
37
|
+
const lng = Number(figure.dataset.lng)
|
|
38
|
+
const canvas = figure.querySelector<HTMLElement>('[data-event-map-canvas]')
|
|
39
|
+
const fallback = figure.querySelector<HTMLElement>('[data-event-map-fallback]')
|
|
40
|
+
if (!canvas || !Number.isFinite(lat) || !Number.isFinite(lng)) return
|
|
41
|
+
setWorkerUrl(workerUrl)
|
|
42
|
+
let style = mode()
|
|
43
|
+
let map: MapLibreMap
|
|
44
|
+
try {
|
|
45
|
+
map = new MapLibreMap({
|
|
46
|
+
container: canvas,
|
|
47
|
+
style: STYLES[style],
|
|
48
|
+
center: [lng, lat],
|
|
49
|
+
zoom: STREET_ZOOM,
|
|
50
|
+
cooperativeGestures: true,
|
|
51
|
+
attributionControl: false,
|
|
52
|
+
dragRotate: false,
|
|
53
|
+
pitchWithRotate: false,
|
|
54
|
+
touchPitch: false,
|
|
55
|
+
})
|
|
56
|
+
} catch {
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
map.addControl(new AttributionControl({ compact: true, customAttribution: OSM_CREDIT }), 'bottom-right')
|
|
60
|
+
map.addControl(new NavigationControl({ showCompass: false }), 'top-right')
|
|
61
|
+
map.touchZoomRotate.disableRotation()
|
|
62
|
+
map.keyboard.disableRotation()
|
|
63
|
+
const pin = document.createElement('span')
|
|
64
|
+
pin.className = 'event-map-pin'
|
|
65
|
+
pin.innerHTML = PIN
|
|
66
|
+
new Marker({ element: pin, anchor: 'bottom' }).setLngLat([lng, lat]).addTo(map)
|
|
67
|
+
map.getCanvas().setAttribute('aria-label', figure.dataset.label ?? 'Map')
|
|
68
|
+
|
|
69
|
+
// The credit folds to its button once, after a while or the first touch.
|
|
70
|
+
let folded = false
|
|
71
|
+
const fold = () => {
|
|
72
|
+
folded = true
|
|
73
|
+
figure.querySelector('.maplibregl-ctrl-attrib')?.classList.remove('maplibregl-compact-show')
|
|
74
|
+
}
|
|
75
|
+
for (const type of ['pointerdown', 'wheel', 'keydown'] as const) canvas.addEventListener(type, fold, { once: true, passive: true })
|
|
76
|
+
map.once('load', () => {
|
|
77
|
+
if (fallback) fallback.hidden = true
|
|
78
|
+
figure.dataset.drawn = ''
|
|
79
|
+
if (folded) fold()
|
|
80
|
+
else window.setTimeout(fold, CREDIT_FOLDS_AFTER_MS)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const follow = () => {
|
|
84
|
+
const next = mode()
|
|
85
|
+
if (next === style) return
|
|
86
|
+
style = next
|
|
87
|
+
map.setStyle(STYLES[next])
|
|
88
|
+
}
|
|
89
|
+
new MutationObserver(follow).observe(document.documentElement, { attributes: true, attributeFilter: ['data-gg-mode'] })
|
|
90
|
+
window.matchMedia?.('(prefers-color-scheme: dark)').addEventListener?.('change', follow)
|
|
91
|
+
}
|