@wakeful-cloud/slidev-theme-illinois 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 (82) hide show
  1. package/LICENSE +45 -0
  2. package/README.md +592 -2
  3. package/assets/logos/block-i-blue.svg +54 -0
  4. package/assets/logos/block-i-full.svg +54 -0
  5. package/assets/logos/block-i-orange.svg +54 -0
  6. package/assets/logos/wordmark-blue.svg +94 -0
  7. package/assets/logos/wordmark-formal-blue.svg +234 -0
  8. package/assets/logos/wordmark-formal-full.svg +234 -0
  9. package/assets/logos/wordmark-formal-orange.svg +234 -0
  10. package/assets/logos/wordmark-full.svg +94 -0
  11. package/assets/logos/wordmark-orange.svg +94 -0
  12. package/assets/logos/wordmark-vertical-blue.svg +94 -0
  13. package/assets/logos/wordmark-vertical-full.svg +94 -0
  14. package/assets/logos/wordmark-vertical-orange.svg +94 -0
  15. package/citations/engine.ts +738 -0
  16. package/citations/errors.ts +79 -0
  17. package/citations/plugin.ts +137 -0
  18. package/citations/styles.ts +300 -0
  19. package/citations/syntax.ts +357 -0
  20. package/components/bibliography.vue +185 -0
  21. package/components/callout.vue +42 -0
  22. package/components/card.vue +37 -0
  23. package/components/cite.vue +62 -0
  24. package/components/frame.vue +71 -0
  25. package/components/illinois-logo.vue +45 -0
  26. package/components/math-morph.vue +252 -0
  27. package/components/qr-code.vue +51 -0
  28. package/components/stat.vue +43 -0
  29. package/components/steps.vue +77 -0
  30. package/global.d.ts +14 -0
  31. package/internal/brand-logo.vue +48 -0
  32. package/internal/citations.ts +206 -0
  33. package/internal/kicker.vue +13 -0
  34. package/internal/layout-root.vue +42 -0
  35. package/internal/pattern.vue +20 -0
  36. package/internal/split.vue +147 -0
  37. package/internal/theme.ts +878 -0
  38. package/layouts/agenda.vue +82 -0
  39. package/layouts/appendix-right.vue +15 -0
  40. package/layouts/appendix.vue +25 -0
  41. package/layouts/canvas.vue +21 -0
  42. package/layouts/center.vue +17 -0
  43. package/layouts/compare.vue +48 -0
  44. package/layouts/cover-right.vue +15 -0
  45. package/layouts/cover.vue +170 -0
  46. package/layouts/default.vue +15 -0
  47. package/layouts/end-right.vue +15 -0
  48. package/layouts/end.vue +89 -0
  49. package/layouts/fact-right.vue +15 -0
  50. package/layouts/fact.vue +25 -0
  51. package/layouts/figure.vue +43 -0
  52. package/layouts/grid.vue +33 -0
  53. package/layouts/iframe-left.vue +16 -0
  54. package/layouts/iframe-right.vue +16 -0
  55. package/layouts/image-left.vue +16 -0
  56. package/layouts/image-right.vue +16 -0
  57. package/layouts/image.vue +40 -0
  58. package/layouts/media-left.vue +17 -0
  59. package/layouts/media-right.vue +17 -0
  60. package/layouts/people.vue +98 -0
  61. package/layouts/quote-right.vue +15 -0
  62. package/layouts/quote.vue +41 -0
  63. package/layouts/references.vue +36 -0
  64. package/layouts/section-right.vue +15 -0
  65. package/layouts/section.vue +53 -0
  66. package/layouts/statement-right.vue +15 -0
  67. package/layouts/statement.vue +30 -0
  68. package/layouts/two-cols-header.vue +32 -0
  69. package/layouts/two-cols.vue +31 -0
  70. package/package.json +114 -4
  71. package/setup/mermaid.ts +73 -0
  72. package/setup/shiki.ts +147 -0
  73. package/setup/transformers.ts +21 -0
  74. package/setup/unocss.ts +34 -0
  75. package/setup/vite-plugins.ts +8 -0
  76. package/slide-top.vue +149 -0
  77. package/styles/base.css +309 -0
  78. package/styles/components.css +336 -0
  79. package/styles/index.ts +19 -0
  80. package/styles/layouts.css +1242 -0
  81. package/styles/looks.css +307 -0
  82. package/styles/tokens.css +324 -0
@@ -0,0 +1,878 @@
1
+ /**
2
+ * @file Shared theme state: resolved theme config, per-slide options (surface, density, look,
3
+ * color schema, chrome) and helpers for logos, ratios and slide metadata.
4
+ */
5
+
6
+ import {handleBackground, useDarkMode, useSlideContext} from "@slidev/client";
7
+ import type {SlideRoute} from "@slidev/types";
8
+ import {computed, type CSSProperties} from "vue";
9
+ import blockIBlue from "#assets/logos/block-i-blue.svg";
10
+ import blockIFull from "#assets/logos/block-i-full.svg";
11
+ import blockIOrange from "#assets/logos/block-i-orange.svg";
12
+ import wordmarkBlue from "#assets/logos/wordmark-blue.svg";
13
+ import wordmarkFormalBlue from "#assets/logos/wordmark-formal-blue.svg";
14
+ import wordmarkFormalFull from "#assets/logos/wordmark-formal-full.svg";
15
+ import wordmarkFormalOrange from "#assets/logos/wordmark-formal-orange.svg";
16
+ import wordmarkFull from "#assets/logos/wordmark-full.svg";
17
+ import wordmarkOrange from "#assets/logos/wordmark-orange.svg";
18
+ import wordmarkVerticalBlue from "#assets/logos/wordmark-vertical-blue.svg";
19
+ import wordmarkVerticalFull from "#assets/logos/wordmark-vertical-full.svg";
20
+ import wordmarkVerticalOrange from "#assets/logos/wordmark-vertical-orange.svg";
21
+
22
+ /**
23
+ * Accent color
24
+ */
25
+ type Accent = "blue" | "industrial" | "orange";
26
+
27
+ /**
28
+ * Footer visibility
29
+ */
30
+ type Chrome = "full" | "minimal" | "none";
31
+
32
+ /**
33
+ * Corner style
34
+ */
35
+ type Corners = "rounded" | "square";
36
+
37
+ /**
38
+ * Type scale and spacing
39
+ */
40
+ type Density = "compact" | "regular" | "relaxed";
41
+
42
+ /**
43
+ * Typeface set (`hyperlegible` uses Atkinson Hyperlegible Next)
44
+ */
45
+ type Font = "brand" | "hyperlegible";
46
+
47
+ /**
48
+ * Illinois mark in the footer
49
+ */
50
+ type FooterMark = "block-i" | "none" | "wordmark";
51
+
52
+ /**
53
+ * Heading typeface
54
+ */
55
+ type HeadingFont = "montserrat" | "source-sans";
56
+
57
+ /**
58
+ * Overall look (a preset of the other look options plus look-specific styling)
59
+ */
60
+ type Look = "bold" | "classic" | "minimal" | "swiss";
61
+
62
+ /**
63
+ * Color of the Illinois marks on dark backgrounds
64
+ */
65
+ type MarkColor = "blue" | "orange";
66
+
67
+ /**
68
+ * Official Illinois mark
69
+ */
70
+ export type MarkKind = "block-i" | "formal" | "vertical" | "wordmark";
71
+
72
+ /**
73
+ * Mark color variant (`full` for light backgrounds, `blue`/`orange` for dark ones)
74
+ */
75
+ export type MarkVariant = "blue" | "full" | "orange";
76
+
77
+ /**
78
+ * Background pattern of cover, section and end slides
79
+ */
80
+ export type Pattern = "dots" | "grid" | "lines" | "none";
81
+
82
+ /**
83
+ * Slide background palette
84
+ */
85
+ export type Surface = "auto" | "blue" | "image" | "orange" | "tint";
86
+
87
+ /**
88
+ * A logo/brand reference (unit, affiliation, sponsor)
89
+ */
90
+ export interface BrandRef {
91
+ /**
92
+ * Logo for light backgrounds (URL or `public/` path)
93
+ */
94
+ logo?: string;
95
+
96
+ /**
97
+ * Logo for dark backgrounds
98
+ */
99
+ logoDark?: string;
100
+
101
+ /**
102
+ * Name (shown when there is no logo, and as alternative text)
103
+ */
104
+ name?: string;
105
+
106
+ /**
107
+ * Small note below the logo, e.g. an award number
108
+ */
109
+ note?: string;
110
+
111
+ /**
112
+ * Link target
113
+ */
114
+ url?: string;
115
+ }
116
+
117
+ /**
118
+ * The theme's `themeConfig` options
119
+ */
120
+ interface IllinoisThemeConfig {
121
+ /**
122
+ * Accent color
123
+ */
124
+ accent?: Accent;
125
+
126
+ /**
127
+ * Institution logos on the cover
128
+ */
129
+ affiliations?: (BrandRef | string)[];
130
+
131
+ /**
132
+ * BibTeX or CSL-JSON file(s), relative to the slides file
133
+ */
134
+ bibliography?: string | string[];
135
+
136
+ /**
137
+ * Footer visibility
138
+ */
139
+ chrome: Chrome;
140
+
141
+ /**
142
+ * List each slide's references at its bottom
143
+ */
144
+ citationFooter: boolean;
145
+
146
+ /**
147
+ * Citation locale (default `en-US`)
148
+ */
149
+ citationLang?: string;
150
+
151
+ /**
152
+ * CSL style name or `.csl` path (default `ieee`)
153
+ */
154
+ citationStyle?: string;
155
+
156
+ /**
157
+ * Corner style
158
+ */
159
+ corners?: Corners;
160
+
161
+ /**
162
+ * Type scale and spacing
163
+ */
164
+ density: Density;
165
+
166
+ /**
167
+ * Typeface set
168
+ */
169
+ font: Font;
170
+
171
+ /**
172
+ * Footer text
173
+ */
174
+ footer?: string;
175
+
176
+ /**
177
+ * Illinois mark in the footer
178
+ */
179
+ footerMark: FooterMark;
180
+
181
+ /**
182
+ * Show the sponsor logos in the footer
183
+ */
184
+ footerSponsors: boolean;
185
+
186
+ /**
187
+ * Heading typeface
188
+ */
189
+ headingFont?: HeadingFont;
190
+
191
+ /**
192
+ * Overall look
193
+ */
194
+ look: Look;
195
+
196
+ /**
197
+ * Color of the Illinois marks on dark backgrounds
198
+ */
199
+ markColor?: MarkColor;
200
+
201
+ /**
202
+ * Background pattern of cover, section and end slides
203
+ */
204
+ pattern?: Pattern;
205
+
206
+ /**
207
+ * Surface of section and appendix slides
208
+ */
209
+ sectionSurface?: Surface;
210
+
211
+ /**
212
+ * Sponsors on the end slide (and in the footer)
213
+ */
214
+ sponsors?: (BrandRef | string)[];
215
+
216
+ /**
217
+ * Surface of content slides
218
+ */
219
+ surface?: Surface;
220
+
221
+ /**
222
+ * Surface of cover and end slides
223
+ */
224
+ titleSurface?: Surface;
225
+
226
+ /**
227
+ * Department or college shown on the cover
228
+ */
229
+ unit?: BrandRef | string;
230
+ }
231
+
232
+ /**
233
+ * Route metadata added by Slidev (only the parts used here)
234
+ */
235
+ interface RouteMeta {
236
+ /**
237
+ * Slide information
238
+ */
239
+ slide?: Partial<SlideMeta>;
240
+ }
241
+
242
+ /**
243
+ * Per-slide metadata available on a route
244
+ */
245
+ interface SlideMeta {
246
+ /**
247
+ * Slide frontmatter
248
+ */
249
+ frontmatter: Record<string, unknown>;
250
+
251
+ /**
252
+ * Slide title (from its first heading)
253
+ */
254
+ title: string;
255
+ }
256
+
257
+ /**
258
+ * Footer settings from least to most visible
259
+ */
260
+ const CHROME_ORDER: Chrome[] = ["none", "minimal", "full"];
261
+
262
+ /**
263
+ * Valid option values
264
+ */
265
+ const ACCENTS = new Set<Accent>(["blue", "industrial", "orange"]);
266
+ const CHROMES = new Set<Chrome>(["full", "minimal", "none"]);
267
+ const CORNERS = new Set<Corners>(["rounded", "square"]);
268
+ const DENSITIES = new Set<Density>(["compact", "regular", "relaxed"]);
269
+ const FONTS = new Set<Font>(["brand", "hyperlegible"]);
270
+ const HEADING_FONTS = new Set<HeadingFont>(["montserrat", "source-sans"]);
271
+ const LOOK_NAMES = new Set<Look>(["bold", "classic", "minimal", "swiss"]);
272
+ const MARK_KINDS = new Set<MarkKind>(["block-i", "formal", "vertical", "wordmark"]);
273
+ const PATTERNS = new Set<Pattern>(["dots", "grid", "lines", "none"]);
274
+ const SURFACES = new Set<Surface>(["auto", "blue", "image", "orange", "tint"]);
275
+
276
+ /**
277
+ * Theme config defaults (mirrors package.json `slidev.defaults.themeConfig`, except `citationStyle`,
278
+ * which the Node-side citation engine defaults)
279
+ */
280
+ const DEFAULTS: IllinoisThemeConfig = {
281
+ chrome: "full",
282
+ citationFooter: true,
283
+ density: "regular",
284
+ font: "brand",
285
+ footerMark: "none",
286
+ footerSponsors: false,
287
+ look: "classic",
288
+ };
289
+
290
+ /**
291
+ * Option values of each look (explicit `themeConfig` and frontmatter values take precedence)
292
+ */
293
+ interface LookPreset {
294
+ /**
295
+ * Accent color
296
+ */
297
+ accent: Accent;
298
+
299
+ /**
300
+ * Corner style
301
+ */
302
+ corners: Corners;
303
+
304
+ /**
305
+ * Heading typeface
306
+ */
307
+ headingFont: HeadingFont;
308
+
309
+ /**
310
+ * Background pattern of cover, section and end slides
311
+ */
312
+ pattern: Pattern;
313
+
314
+ /**
315
+ * Surface of section and appendix slides
316
+ */
317
+ sectionSurface: Surface;
318
+
319
+ /**
320
+ * Surface of content slides
321
+ */
322
+ surface: Surface;
323
+
324
+ /**
325
+ * Surface of cover and end slides
326
+ */
327
+ titleSurface: Surface;
328
+ }
329
+
330
+ /**
331
+ * Look presets. Every look is light in light mode: dark surfaces (`blue`, `orange`) are opt-in
332
+ */
333
+ const LOOKS: Record<Look, LookPreset> = {
334
+ // Heavy uppercase Montserrat, grid pattern, accent bars under titles
335
+ bold: {
336
+ accent: "orange",
337
+ corners: "square",
338
+ headingFont: "montserrat",
339
+ pattern: "grid",
340
+ sectionSurface: "tint",
341
+ surface: "auto",
342
+ titleSurface: "tint",
343
+ },
344
+ // Tinted title and section slides, Montserrat headings, orange accents, line pattern
345
+ classic: {
346
+ accent: "orange",
347
+ corners: "rounded",
348
+ headingFont: "montserrat",
349
+ pattern: "lines",
350
+ sectionSurface: "tint",
351
+ surface: "auto",
352
+ titleSurface: "tint",
353
+ },
354
+ // Monochrome Illini Blue, light Montserrat, outlines instead of fills
355
+ minimal: {
356
+ accent: "blue",
357
+ corners: "square",
358
+ headingFont: "montserrat",
359
+ pattern: "none",
360
+ sectionSurface: "auto",
361
+ surface: "auto",
362
+ titleSurface: "auto",
363
+ },
364
+ // International Typographic Style: heavy type at extreme scale, rules and blocks
365
+ swiss: {
366
+ accent: "orange",
367
+ corners: "square",
368
+ headingFont: "montserrat",
369
+ pattern: "none",
370
+ sectionSurface: "auto",
371
+ surface: "auto",
372
+ titleSurface: "auto",
373
+ },
374
+ };
375
+
376
+ /**
377
+ * Defaults of a layout
378
+ */
379
+ interface LayoutDefault {
380
+ /**
381
+ * Footer visibility
382
+ */
383
+ chrome?: Chrome;
384
+
385
+ /**
386
+ * Surface; `section` and `title` stand for the look's section and title surfaces
387
+ */
388
+ surface?: Surface | "section" | "title";
389
+ }
390
+
391
+ /**
392
+ * Per-layout defaults (overridable with `surface:` / `chrome:` frontmatter)
393
+ */
394
+ const LAYOUT_DEFAULTS: Record<string, LayoutDefault> = {
395
+ appendix: {chrome: "none", surface: "section"},
396
+ canvas: {chrome: "minimal"},
397
+ cover: {chrome: "none", surface: "title"},
398
+ end: {chrome: "none", surface: "title"},
399
+ image: {chrome: "none", surface: "image"},
400
+ section: {chrome: "minimal", surface: "section"},
401
+ };
402
+
403
+ /**
404
+ * Mirrored layouts and the layout they mirror
405
+ */
406
+ const MIRRORED_LAYOUTS: Record<string, string> = {
407
+ "appendix-right": "appendix",
408
+ "cover-right": "cover",
409
+ "end-right": "end",
410
+ "fact-right": "fact",
411
+ "quote-right": "quote",
412
+ "section-right": "section",
413
+ "statement-right": "statement",
414
+ };
415
+
416
+ /**
417
+ * Base layout of a (possibly mirrored) layout name
418
+ * @param name Layout name
419
+ * @returns Base layout name
420
+ */
421
+ const baseLayout = (name: unknown) =>
422
+ typeof name === "string" ? (MIRRORED_LAYOUTS[name] ?? name) : undefined;
423
+
424
+ /**
425
+ * Official mark URLs by kind and variant
426
+ */
427
+ const MARKS: Record<MarkKind, Record<MarkVariant, string>> = {
428
+ "block-i": {blue: blockIBlue, full: blockIFull, orange: blockIOrange},
429
+ formal: {blue: wordmarkFormalBlue, full: wordmarkFormalFull, orange: wordmarkFormalOrange},
430
+ vertical: {
431
+ blue: wordmarkVerticalBlue,
432
+ full: wordmarkVerticalFull,
433
+ orange: wordmarkVerticalOrange,
434
+ },
435
+ wordmark: {blue: wordmarkBlue, full: wordmarkFull, orange: wordmarkOrange},
436
+ };
437
+
438
+ /**
439
+ * Vertical alignment values for column layouts
440
+ */
441
+ const ALIGN_ITEMS: Record<string, string> = {
442
+ bottom: "end",
443
+ center: "center",
444
+ top: "start",
445
+ };
446
+
447
+ /**
448
+ * URL of an official Illinois mark
449
+ * @param kind Mark
450
+ * @param variant Color variant
451
+ * @returns Asset URL
452
+ */
453
+ export const markUrl = (kind: MarkKind, variant: MarkVariant) => MARKS[kind][variant];
454
+
455
+ /**
456
+ * Mark kind from a layout's `mark` frontmatter
457
+ * @param value Frontmatter value (`none` or `false` hides the mark)
458
+ * @param fallback Mark used when the value is missing or invalid
459
+ * @returns Mark kind, or `undefined` to hide the mark
460
+ */
461
+ export const markFromFrontmatter = (value: unknown, fallback: MarkKind): MarkKind | undefined => {
462
+ if (value === "none" || value === false) {
463
+ return undefined;
464
+ }
465
+ return MARK_KINDS.has(value as MarkKind) ? (value as MarkKind) : fallback;
466
+ };
467
+
468
+ /**
469
+ * Metadata of a slide route (frontmatter and title)
470
+ * @param route Slide route
471
+ * @returns Slide metadata
472
+ */
473
+ const slideMeta = (route: SlideRoute): SlideMeta => {
474
+ const slide = (route.meta as RouteMeta | undefined)?.slide;
475
+ return {frontmatter: slide?.frontmatter ?? {}, title: slide?.title ?? ""};
476
+ };
477
+
478
+ /**
479
+ * Protocols a link target may use
480
+ */
481
+ const SAFE_PROTOCOLS = new Set(["http:", "https:", "mailto:"]);
482
+
483
+ /**
484
+ * Base that relative link targets are resolved against to find their protocol
485
+ */
486
+ const URL_BASE = "https://relative.invalid/";
487
+
488
+ /**
489
+ * A link target from frontmatter or theme config, allowing only web and mail links (no
490
+ * `javascript:` or `data:` URLs)
491
+ * @param value URL
492
+ * @returns The URL, or `undefined` when it is missing, malformed or uses another scheme
493
+ */
494
+ export const safeUrl = (value: unknown) => {
495
+ if (typeof value !== "string" || value.length === 0) {
496
+ return undefined;
497
+ }
498
+
499
+ // Browsers drop tabs, newlines and leading control characters before they read the scheme
500
+ // (`java\tscript:` runs as `javascript:`), so the URL is parsed the way they parse it instead
501
+ // of matched as text
502
+ try {
503
+ return SAFE_PROTOCOLS.has(new URL(value, URL_BASE).protocol) ? value : undefined;
504
+ } catch {
505
+ return undefined;
506
+ }
507
+ };
508
+
509
+ /**
510
+ * Text alternative of a layout's image from its `alt` frontmatter (empty marks it decorative)
511
+ * @param frontmatter Slide frontmatter
512
+ * @returns Alt text
513
+ */
514
+ export const altText = (frontmatter: Record<string, unknown>) => {
515
+ const value = frontmatter["alt"];
516
+ return typeof value === "string" ? value : "";
517
+ };
518
+
519
+ /**
520
+ * A section listed in the agenda
521
+ */
522
+ interface SectionEntry {
523
+ /**
524
+ * Displayed number (`01`, `02`, ..., or the section's own `number`)
525
+ */
526
+ label: string;
527
+
528
+ /**
529
+ * Route number of the section slide
530
+ */
531
+ no: number;
532
+
533
+ /**
534
+ * Section title (without inline HTML)
535
+ */
536
+ title: string;
537
+ }
538
+
539
+ /**
540
+ * Route number of the first `appendix` slide
541
+ * @param routes Slide routes
542
+ * @returns Route number, or `undefined` without an appendix
543
+ */
544
+ export const appendixStart = (routes: SlideRoute[]) =>
545
+ routes.find(route => baseLayout(slideMeta(route).frontmatter["layout"]) === "appendix")?.no;
546
+
547
+ /**
548
+ * Displayed number of a section
549
+ * @param value The section's `number` frontmatter
550
+ * @param index Automatic number (1-based)
551
+ * @returns Label, or `undefined` when hidden with `number: false`
552
+ */
553
+ export const sectionLabel = (value: unknown, index: number) => {
554
+ if (value === false) {
555
+ return undefined;
556
+ }
557
+ if (typeof value === "string" && value.length > 0) {
558
+ return value;
559
+ }
560
+ const number = typeof value === "number" ? value : index;
561
+ return String(number).padStart(2, "0");
562
+ };
563
+
564
+ /**
565
+ * Sections listed in the agenda: `section` slides before the appendix, without `hideInToc: true`
566
+ * @param routes Slide routes
567
+ * @returns Listed sections, in order
568
+ */
569
+ export const listedSections = (routes: SlideRoute[]): SectionEntry[] => {
570
+ const end = appendixStart(routes) ?? Number.POSITIVE_INFINITY;
571
+
572
+ return routes
573
+ .filter(route => {
574
+ const {frontmatter} = slideMeta(route);
575
+ return (
576
+ route.no < end &&
577
+ baseLayout(frontmatter["layout"]) === "section" &&
578
+ frontmatter["hideInToc"] !== true
579
+ );
580
+ })
581
+ .map((route, index) => {
582
+ const {frontmatter, title} = slideMeta(route);
583
+ return {
584
+ label: sectionLabel(frontmatter["number"], index + 1) ?? "",
585
+ no: route.no,
586
+
587
+ // Slide titles may contain inline HTML
588
+ title: title.replaceAll(/<[^>]+>/gu, "").trim() || "Section",
589
+ };
590
+ });
591
+ };
592
+
593
+ /**
594
+ * Normalize a brand reference given as a plain name or an object
595
+ * @param value Brand reference
596
+ * @returns Brand object, or `undefined`
597
+ */
598
+ export const normalizeBrand = (value: BrandRef | string | null | undefined) => {
599
+ if (value === undefined || value === null) {
600
+ return undefined;
601
+ }
602
+ return typeof value === "string" ? {name: value} : value;
603
+ };
604
+
605
+ /**
606
+ * Normalize a list of brand references, dropping empty entries
607
+ * @param values Brand references (anything else, e.g. `false`, yields no brands)
608
+ * @returns Brand objects
609
+ */
610
+ export const normalizeBrands = (values: unknown): BrandRef[] =>
611
+ Array.isArray(values)
612
+ ? values.flatMap(value => normalizeBrand(value as BrandRef | string | null) ?? [])
613
+ : [];
614
+
615
+ /**
616
+ * Parse a ratio without validating the result (see `parseRatio`)
617
+ * @param value Ratio
618
+ * @returns Fraction (possibly `NaN` or infinite), or `undefined` when not a number or string
619
+ */
620
+ const parseRatioValue = (value: unknown): number | undefined => {
621
+ if (typeof value === "number") {
622
+ return value > 1 ? value / 100 : value;
623
+ }
624
+ if (typeof value !== "string") {
625
+ return undefined;
626
+ }
627
+
628
+ const trimmed = value.trim();
629
+
630
+ // "1/3" means one third; "2:3" means 2 parts to 3 parts
631
+ const fraction = /^(\d+(?:\.\d+)?)\s*([/:])\s*(\d+(?:\.\d+)?)$/u.exec(trimmed);
632
+ if (fraction) {
633
+ const [, a, separator, b] = fraction;
634
+ const numerator = Number(a);
635
+ const denominator = Number(b);
636
+ return separator === ":" ? numerator / (numerator + denominator) : numerator / denominator;
637
+ }
638
+
639
+ // "40%"
640
+ if (trimmed.endsWith("%")) {
641
+ return Number.parseFloat(trimmed) / 100;
642
+ }
643
+
644
+ // "0.4" or "40"
645
+ const number = Number.parseFloat(trimmed);
646
+ return number > 1 ? number / 100 : number;
647
+ };
648
+
649
+ /**
650
+ * Parse a ratio like `1/3`, `2:3`, `40%` or `0.4` into a fraction (0..1)
651
+ * @param value Ratio
652
+ * @param fallback Value used when `value` is missing or invalid
653
+ * @returns Fraction
654
+ */
655
+ export const parseRatio = (value: unknown, fallback: number): number => {
656
+ const result = parseRatioValue(value);
657
+ return result !== undefined && Number.isFinite(result) && result >= 0 ? result : fallback;
658
+ };
659
+
660
+ /**
661
+ * Clamp a column share to 15-85%, so neither column of a two-column layout collapses
662
+ * @param fraction Share of a column
663
+ * @returns Clamped share
664
+ */
665
+ const clampShare = (fraction: number) => Math.min(Math.max(fraction, 0.15), 0.85);
666
+
667
+ /**
668
+ * Grid template for two tracks where the first takes `fraction` of the width
669
+ * @param fraction Share of the first track (clamped to 15-85%)
670
+ * @returns `grid-template-columns` value
671
+ */
672
+ export const tracks = (fraction: number) => {
673
+ const first = clampShare(fraction);
674
+ return `minmax(0, ${first}fr) minmax(0, ${1 - first}fr)`;
675
+ };
676
+
677
+ /**
678
+ * Media side of the split layouts
679
+ */
680
+ export const SPLIT_SIDES: Record<string, "left" | "right"> = {
681
+ "iframe-left": "left",
682
+ "iframe-right": "right",
683
+ "image-left": "left",
684
+ "image-right": "right",
685
+ "media-left": "left",
686
+ "media-right": "right",
687
+ };
688
+
689
+ /**
690
+ * Media share of a split layout's width from its `ratio` frontmatter (15-85%, default half)
691
+ * @param frontmatter Slide frontmatter
692
+ * @returns Share of the media column
693
+ */
694
+ export const mediaShare = (frontmatter: Record<string, unknown>) =>
695
+ clampShare(parseRatio(frontmatter["ratio"], 0.5));
696
+
697
+ /**
698
+ * Grid style of two-column layouts from their `align` and `ratio` (left column share) frontmatter
699
+ * @param frontmatter Slide frontmatter
700
+ * @returns Inline style
701
+ */
702
+ export const columnsStyle = (frontmatter: Record<string, unknown>) => ({
703
+ alignItems: ALIGN_ITEMS[String(frontmatter["align"])] ?? "start",
704
+ gridTemplateColumns: tracks(parseRatio(frontmatter["ratio"], 0.5)),
705
+ });
706
+
707
+ /**
708
+ * First of several candidate values that is valid
709
+ * @param valid Valid values
710
+ * @param candidates Candidates, in order of precedence
711
+ * @returns First valid candidate, or `undefined`
712
+ */
713
+ const firstValid = <T>(valid: Set<T>, ...candidates: unknown[]): T | undefined =>
714
+ candidates.find(candidate => valid.has(candidate as T)) as T | undefined;
715
+
716
+ /**
717
+ * Theme state for the slide this is called from (works in layouts, components and slide layers)
718
+ * @returns Reactive theme state
719
+ */
720
+ export const useIllinois = () => {
721
+ const {$frontmatter, $page, $slidev} = useSlideContext();
722
+ const {isDark} = useDarkMode();
723
+
724
+ // Theme config with defaults applied
725
+ const config = computed<IllinoisThemeConfig>(() => ({
726
+ ...DEFAULTS,
727
+ ...($slidev?.configs?.themeConfig as Partial<IllinoisThemeConfig> | undefined),
728
+ }));
729
+
730
+ // Slide frontmatter
731
+ const frontmatter = computed(() => ($frontmatter ?? {}) as Record<string, unknown>);
732
+
733
+ /**
734
+ * Resolve an option from the slide frontmatter, then the theme config (an invalid value falls
735
+ * through to the next source)
736
+ * @param key Option name
737
+ * @param valid Valid values
738
+ * @param fallback Value used when neither is valid
739
+ * @returns Option value
740
+ */
741
+ const option = <T extends string>(key: keyof IllinoisThemeConfig, valid: Set<T>, fallback: T) =>
742
+ firstValid(valid, frontmatter.value[key], config.value[key]) ?? fallback;
743
+
744
+ // Overall look; its preset supplies the defaults of the options below
745
+ const look = computed(() => option("look", LOOK_NAMES, "classic"));
746
+
747
+ /**
748
+ * Resolve a look option from the slide frontmatter, then the theme config, then the look preset
749
+ * @param key Option name
750
+ * @param valid Valid values
751
+ * @returns Option value
752
+ */
753
+ const lookOption = <K extends keyof LookPreset>(key: K, valid: Set<LookPreset[K]>) =>
754
+ firstValid(valid, frontmatter.value[key], config.value[key]) ?? LOOKS[look.value][key];
755
+
756
+ // Slide layout, without the `-right` of mirrored layouts (Slidev defaults the first slide to
757
+ // `cover`)
758
+ const layout = computed(() => {
759
+ const value = baseLayout(frontmatter.value["layout"]);
760
+ if (value !== undefined) {
761
+ return value;
762
+ }
763
+ return $page.value === 1 ? "cover" : "default";
764
+ });
765
+
766
+ // Background image (`background` frontmatter)
767
+ const background = computed(() => {
768
+ const value = frontmatter.value["background"];
769
+ return typeof value === "string" && value.length > 0 ? value : undefined;
770
+ });
771
+
772
+ const backgroundStyle = computed<CSSProperties>(() =>
773
+ background.value === undefined ? {} : (handleBackground(background.value) as CSSProperties),
774
+ );
775
+
776
+ const accent = computed(() => lookOption("accent", ACCENTS));
777
+ const corners = computed(() => lookOption("corners", CORNERS));
778
+ const density = computed(() => option("density", DENSITIES, "regular"));
779
+ const font = computed(() => option("font", FONTS, "brand"));
780
+ const headingFont = computed(() => lookOption("headingFont", HEADING_FONTS));
781
+ const pattern = computed(() => lookOption("pattern", PATTERNS));
782
+
783
+ // Footer: the slide's own `chrome`, else the more restrictive of the layout default and the
784
+ // deck-wide setting (so `chrome: none` in `themeConfig` also hides section page numbers)
785
+ const chrome = computed<Chrome>(() => {
786
+ const own = firstValid(CHROMES, frontmatter.value["chrome"]);
787
+ if (own !== undefined) {
788
+ return own;
789
+ }
790
+ const deck = firstValid(CHROMES, config.value.chrome) ?? "full";
791
+ const layoutDefault = LAYOUT_DEFAULTS[layout.value]?.chrome ?? deck;
792
+ return CHROME_ORDER.indexOf(layoutDefault) < CHROME_ORDER.indexOf(deck) ? layoutDefault : deck;
793
+ });
794
+
795
+ // Per-slide light/dark override (`colorSchema`)
796
+ const schema = computed(() => {
797
+ const value = frontmatter.value["colorSchema"];
798
+ return value === "dark" || value === "light" ? value : undefined;
799
+ });
800
+
801
+ const surface = computed<Surface>(() => {
802
+ const value = firstValid(SURFACES, frontmatter.value["surface"]);
803
+ if (value !== undefined) {
804
+ return value;
805
+ }
806
+ if (background.value !== undefined) {
807
+ return "image";
808
+ }
809
+
810
+ // Layout default, falling back to the look's content surface
811
+ const layoutDefault = LAYOUT_DEFAULTS[layout.value]?.surface;
812
+ if (layoutDefault === "section") {
813
+ return lookOption("sectionSurface", SURFACES);
814
+ }
815
+ if (layoutDefault === "title") {
816
+ return lookOption("titleSurface", SURFACES);
817
+ }
818
+ return layoutDefault ?? lookOption("surface", SURFACES);
819
+ });
820
+
821
+ // Whether the slide's background is dark (decides which logo variants to use)
822
+ const darkBackground = computed(() => {
823
+ switch (surface.value) {
824
+ case "blue":
825
+ case "image":
826
+ case "orange": {
827
+ return true;
828
+ }
829
+ default: {
830
+ return schema.value === undefined ? isDark.value : schema.value === "dark";
831
+ }
832
+ }
833
+ });
834
+
835
+ // Mark variant matching the slide background
836
+ const markVariant = computed<MarkVariant>(() => {
837
+ if (!darkBackground.value) {
838
+ return "full";
839
+ }
840
+ if (surface.value === "orange" || config.value.markColor === "blue") {
841
+ return "blue";
842
+ }
843
+ return "orange";
844
+ });
845
+
846
+ // Classes applied to layout roots and slide layers
847
+ const classes = computed(() => [
848
+ `il-accent-${accent.value}`,
849
+ `il-corners-${corners.value}`,
850
+ `il-density-${density.value}`,
851
+ `il-heading-${headingFont.value}`,
852
+ `il-look-${look.value}`,
853
+ `il-surface-${surface.value}`,
854
+ font.value === "hyperlegible" ? "il-font-hyperlegible" : "",
855
+ schema.value === undefined ? "" : `il-schema-${schema.value}`,
856
+ ]);
857
+
858
+ const kicker = computed(() => {
859
+ const value = frontmatter.value["kicker"];
860
+ return typeof value === "string" ? value : undefined;
861
+ });
862
+
863
+ return {
864
+ background,
865
+ backgroundStyle,
866
+ chrome,
867
+ classes,
868
+ config,
869
+ darkBackground,
870
+ frontmatter,
871
+ kicker,
872
+ layout,
873
+ markVariant,
874
+ page: $page,
875
+ pattern,
876
+ surface,
877
+ };
878
+ };