@uvalib/web-components 0.0.0-stage → 1.0.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/CHANGELOG.md +172 -0
- package/README.md +1164 -2
- package/bin/install-skill.mjs +139 -0
- package/dist/base/UvalibElement.d.ts +21 -0
- package/dist/base/UvalibElement.js +68 -0
- package/dist/base/UvalibElement.js.map +1 -0
- package/dist/base/analytics.d.ts +44 -0
- package/dist/base/analytics.js +59 -0
- package/dist/base/analytics.js.map +1 -0
- package/dist/base/color-scheme.d.ts +93 -0
- package/dist/base/color-scheme.js +267 -0
- package/dist/base/color-scheme.js.map +1 -0
- package/dist/base/define.d.ts +2 -0
- package/dist/base/define.js +6 -0
- package/dist/base/define.js.map +1 -0
- package/dist/base/heading-level.d.ts +12 -0
- package/dist/base/heading-level.js +52 -0
- package/dist/base/heading-level.js.map +1 -0
- package/dist/base/light-dom-styles.d.ts +18 -0
- package/dist/base/light-dom-styles.js +134 -0
- package/dist/base/light-dom-styles.js.map +1 -0
- package/dist/base.css +30 -0
- package/dist/base.d.ts +5 -0
- package/dist/base.js +5 -0
- package/dist/base.js.map +1 -0
- package/dist/components/bento-box/ArticlesSection.d.ts +19 -0
- package/dist/components/bento-box/ArticlesSection.js +22 -0
- package/dist/components/bento-box/ArticlesSection.js.map +1 -0
- package/dist/components/bento-box/BentoBox.d.ts +85 -0
- package/dist/components/bento-box/BentoBox.js +366 -0
- package/dist/components/bento-box/BentoBox.js.map +1 -0
- package/dist/components/bento-box/BentoSection.d.ts +115 -0
- package/dist/components/bento-box/BentoSection.js +486 -0
- package/dist/components/bento-box/BentoSection.js.map +1 -0
- package/dist/components/bento-box/CatalogSection.d.ts +18 -0
- package/dist/components/bento-box/CatalogSection.js +19 -0
- package/dist/components/bento-box/CatalogSection.js.map +1 -0
- package/dist/components/bento-box/LibGuidesSection.d.ts +24 -0
- package/dist/components/bento-box/LibGuidesSection.js +73 -0
- package/dist/components/bento-box/LibGuidesSection.js.map +1 -0
- package/dist/components/bento-box/VirgoSection.d.ts +19 -0
- package/dist/components/bento-box/VirgoSection.js +58 -0
- package/dist/components/bento-box/VirgoSection.js.map +1 -0
- package/dist/components/bento-box/WebsiteSection.d.ts +25 -0
- package/dist/components/bento-box/WebsiteSection.js +40 -0
- package/dist/components/bento-box/WebsiteSection.js.map +1 -0
- package/dist/components/bento-box/bento-box.d.ts +1 -0
- package/dist/components/bento-box/bento-box.js +13 -0
- package/dist/components/bento-box/bento-box.js.map +1 -0
- package/dist/components/bento-box/bento-data.d.ts +147 -0
- package/dist/components/bento-box/bento-data.js +422 -0
- package/dist/components/bento-box/bento-data.js.map +1 -0
- package/dist/components/events-section/EventsSection.d.ts +91 -0
- package/dist/components/events-section/EventsSection.js +435 -0
- package/dist/components/events-section/EventsSection.js.map +1 -0
- package/dist/components/events-section/events-data.d.ts +90 -0
- package/dist/components/events-section/events-data.js +174 -0
- package/dist/components/events-section/events-data.js.map +1 -0
- package/dist/components/events-section/events-section.d.ts +1 -0
- package/dist/components/events-section/events-section.js +4 -0
- package/dist/components/events-section/events-section.js.map +1 -0
- package/dist/components/library-hours/hours-data.d.ts +104 -0
- package/dist/components/library-hours/hours-data.js +267 -0
- package/dist/components/library-hours/hours-data.js.map +1 -0
- package/dist/components/library-hours-setup/LibraryHoursSetup.d.ts +21 -0
- package/dist/components/library-hours-setup/LibraryHoursSetup.js +59 -0
- package/dist/components/library-hours-setup/LibraryHoursSetup.js.map +1 -0
- package/dist/components/library-hours-setup/library-hours-setup.d.ts +1 -0
- package/dist/components/library-hours-setup/library-hours-setup.js +5 -0
- package/dist/components/library-hours-setup/library-hours-setup.js.map +1 -0
- package/dist/components/library-weekly-hours/LibraryWeeklyHours.d.ts +107 -0
- package/dist/components/library-weekly-hours/LibraryWeeklyHours.js +502 -0
- package/dist/components/library-weekly-hours/LibraryWeeklyHours.js.map +1 -0
- package/dist/components/library-weekly-hours/library-weekly-hours.d.ts +1 -0
- package/dist/components/library-weekly-hours/library-weekly-hours.js +4 -0
- package/dist/components/library-weekly-hours/library-weekly-hours.js.map +1 -0
- package/dist/components/link.d.ts +2 -0
- package/dist/components/link.js +7 -0
- package/dist/components/link.js.map +1 -0
- package/dist/components/site-analytics/SiteAnalytics.d.ts +44 -0
- package/dist/components/site-analytics/SiteAnalytics.js +161 -0
- package/dist/components/site-analytics/SiteAnalytics.js.map +1 -0
- package/dist/components/site-analytics/SiteAnalyticsMixin.d.ts +8 -0
- package/dist/components/site-analytics/SiteAnalyticsMixin.js +22 -0
- package/dist/components/site-analytics/SiteAnalyticsMixin.js.map +1 -0
- package/dist/components/site-analytics/site-analytics.d.ts +1 -0
- package/dist/components/site-analytics/site-analytics.js +4 -0
- package/dist/components/site-analytics/site-analytics.js.map +1 -0
- package/dist/components/site-footer/SiteFooter.d.ts +34 -0
- package/dist/components/site-footer/SiteFooter.js +275 -0
- package/dist/components/site-footer/SiteFooter.js.map +1 -0
- package/dist/components/site-footer/icons.d.ts +4 -0
- package/dist/components/site-footer/icons.js +7 -0
- package/dist/components/site-footer/icons.js.map +1 -0
- package/dist/components/site-footer/site-footer.d.ts +1 -0
- package/dist/components/site-footer/site-footer.js +4 -0
- package/dist/components/site-footer/site-footer.js.map +1 -0
- package/dist/components/site-header/SiteHeader.d.ts +154 -0
- package/dist/components/site-header/SiteHeader.js +845 -0
- package/dist/components/site-header/SiteHeader.js.map +1 -0
- package/dist/components/site-header/site-header.d.ts +1 -0
- package/dist/components/site-header/site-header.js +12 -0
- package/dist/components/site-header/site-header.js.map +1 -0
- package/dist/components/site-hours-section/SiteHoursSection.d.ts +63 -0
- package/dist/components/site-hours-section/SiteHoursSection.js +243 -0
- package/dist/components/site-hours-section/SiteHoursSection.js.map +1 -0
- package/dist/components/site-hours-section/site-hours-section.d.ts +1 -0
- package/dist/components/site-hours-section/site-hours-section.js +4 -0
- package/dist/components/site-hours-section/site-hours-section.js.map +1 -0
- package/dist/components/site-main-nav/SiteMainNav.d.ts +136 -0
- package/dist/components/site-main-nav/SiteMainNav.js +678 -0
- package/dist/components/site-main-nav/SiteMainNav.js.map +1 -0
- package/dist/components/site-main-nav/main-nav-data.d.ts +5 -0
- package/dist/components/site-main-nav/main-nav-data.js +90 -0
- package/dist/components/site-main-nav/main-nav-data.js.map +1 -0
- package/dist/components/site-main-nav/main-nav-items.d.ts +49 -0
- package/dist/components/site-main-nav/main-nav-items.js +138 -0
- package/dist/components/site-main-nav/main-nav-items.js.map +1 -0
- package/dist/components/site-main-nav/site-main-nav.d.ts +1 -0
- package/dist/components/site-main-nav/site-main-nav.js +4 -0
- package/dist/components/site-main-nav/site-main-nav.js.map +1 -0
- package/dist/components/site-page/SitePage.d.ts +145 -0
- package/dist/components/site-page/SitePage.js +480 -0
- package/dist/components/site-page/SitePage.js.map +1 -0
- package/dist/components/site-page/alerts.d.ts +24 -0
- package/dist/components/site-page/alerts.js +78 -0
- package/dist/components/site-page/alerts.js.map +1 -0
- package/dist/components/site-page/site-page.d.ts +1 -0
- package/dist/components/site-page/site-page.js +7 -0
- package/dist/components/site-page/site-page.js.map +1 -0
- package/dist/components/site-style/SiteStyle.d.ts +37 -0
- package/dist/components/site-style/SiteStyle.js +76 -0
- package/dist/components/site-style/SiteStyle.js.map +1 -0
- package/dist/components/site-style/site-style.d.ts +1 -0
- package/dist/components/site-style/site-style.js +4 -0
- package/dist/components/site-style/site-style.js.map +1 -0
- package/dist/components/uvalib-analytics/UvalibAnalytics.d.ts +10 -0
- package/dist/components/uvalib-analytics/UvalibAnalytics.js +11 -0
- package/dist/components/uvalib-analytics/UvalibAnalytics.js.map +1 -0
- package/dist/components/uvalib-analytics/UvalibAnalyticsMixin.d.ts +13 -0
- package/dist/components/uvalib-analytics/UvalibAnalyticsMixin.js +25 -0
- package/dist/components/uvalib-analytics/UvalibAnalyticsMixin.js.map +1 -0
- package/dist/components/uvalib-analytics/uvalib-analytics.d.ts +1 -0
- package/dist/components/uvalib-analytics/uvalib-analytics.js +4 -0
- package/dist/components/uvalib-analytics/uvalib-analytics.js.map +1 -0
- package/dist/components/uvalib-date-range/UvalibDateRange.d.ts +46 -0
- package/dist/components/uvalib-date-range/UvalibDateRange.js +339 -0
- package/dist/components/uvalib-date-range/UvalibDateRange.js.map +1 -0
- package/dist/components/uvalib-date-range/uvalib-date-range.d.ts +1 -0
- package/dist/components/uvalib-date-range/uvalib-date-range.js +4 -0
- package/dist/components/uvalib-date-range/uvalib-date-range.js.map +1 -0
- package/dist/components/uvalib-filter/UvalibFilter.d.ts +73 -0
- package/dist/components/uvalib-filter/UvalibFilter.js +279 -0
- package/dist/components/uvalib-filter/UvalibFilter.js.map +1 -0
- package/dist/components/uvalib-filter/uvalib-filter.d.ts +1 -0
- package/dist/components/uvalib-filter/uvalib-filter.js +4 -0
- package/dist/components/uvalib-filter/uvalib-filter.js.map +1 -0
- package/dist/custom-elements.json +15178 -0
- package/dist/data/fetch-json.d.ts +28 -0
- package/dist/data/fetch-json.js +43 -0
- package/dist/data/fetch-json.js.map +1 -0
- package/dist/data/new-york.d.ts +5 -0
- package/dist/data/new-york.js +23 -0
- package/dist/data/new-york.js.map +1 -0
- package/dist/data/sites.d.ts +12 -0
- package/dist/data/sites.js +89 -0
- package/dist/data/sites.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/styles/accessible.d.ts +1 -0
- package/dist/styles/accessible.js +37 -0
- package/dist/styles/accessible.js.map +1 -0
- package/dist/styles/base.d.ts +2 -0
- package/dist/styles/base.js +41 -0
- package/dist/styles/base.js.map +1 -0
- package/dist/styles/color-scheme.d.ts +1 -0
- package/dist/styles/color-scheme.js +81 -0
- package/dist/styles/color-scheme.js.map +1 -0
- package/dist/styles/tokens.d.ts +1 -0
- package/dist/styles/tokens.js +85 -0
- package/dist/styles/tokens.js.map +1 -0
- package/dist/styles/w3-subset.d.ts +1 -0
- package/dist/styles/w3-subset.js +33 -0
- package/dist/styles/w3-subset.js.map +1 -0
- package/dist/tokens.css +152 -0
- package/dist-cdn/base.css +30 -0
- package/dist-cdn/bento-box.js +1035 -0
- package/dist-cdn/bento-box.js.map +1 -0
- package/dist-cdn/chunks/SiteAnalytics-T1Wx3lsb.js +174 -0
- package/dist-cdn/chunks/SiteAnalytics-T1Wx3lsb.js.map +1 -0
- package/dist-cdn/chunks/UvalibElement-BnI-eRRR.js +695 -0
- package/dist-cdn/chunks/UvalibElement-BnI-eRRR.js.map +1 -0
- package/dist-cdn/chunks/accessible-GqhVn5_H.js +40 -0
- package/dist-cdn/chunks/accessible-GqhVn5_H.js.map +1 -0
- package/dist-cdn/chunks/analytics-C8D8n_wt.js +55 -0
- package/dist-cdn/chunks/analytics-C8D8n_wt.js.map +1 -0
- package/dist-cdn/chunks/base-DCGd2Oii.js +117 -0
- package/dist-cdn/chunks/base-DCGd2Oii.js.map +1 -0
- package/dist-cdn/chunks/fetch-json-Cyqv-gLU.js +25 -0
- package/dist-cdn/chunks/fetch-json-Cyqv-gLU.js.map +1 -0
- package/dist-cdn/chunks/heading-level-DIuNS44-.js +31 -0
- package/dist-cdn/chunks/heading-level-DIuNS44-.js.map +1 -0
- package/dist-cdn/chunks/hours-data-Bw6vkIw7.js +181 -0
- package/dist-cdn/chunks/hours-data-Bw6vkIw7.js.map +1 -0
- package/dist-cdn/chunks/library-weekly-hours-ByQ8ugxh.js +346 -0
- package/dist-cdn/chunks/library-weekly-hours-ByQ8ugxh.js.map +1 -0
- package/dist-cdn/chunks/link-DbJSwj16.js +7 -0
- package/dist-cdn/chunks/link-DbJSwj16.js.map +1 -0
- package/dist-cdn/chunks/new-york-DkcnqvJ4.js +18 -0
- package/dist-cdn/chunks/new-york-DkcnqvJ4.js.map +1 -0
- package/dist-cdn/chunks/repeat-CIFUYkyh.js +101 -0
- package/dist-cdn/chunks/repeat-CIFUYkyh.js.map +1 -0
- package/dist-cdn/chunks/site-header-BwDkZ2LL.js +802 -0
- package/dist-cdn/chunks/site-header-BwDkZ2LL.js.map +1 -0
- package/dist-cdn/chunks/site-main-nav-BLAAunnr.js +605 -0
- package/dist-cdn/chunks/site-main-nav-BLAAunnr.js.map +1 -0
- package/dist-cdn/chunks/static-html-1mTAG6nS.js +22 -0
- package/dist-cdn/chunks/static-html-1mTAG6nS.js.map +1 -0
- package/dist-cdn/custom-elements.json +15178 -0
- package/dist-cdn/events-section.js +401 -0
- package/dist-cdn/events-section.js.map +1 -0
- package/dist-cdn/library-hours-setup.js +28 -0
- package/dist-cdn/library-hours-setup.js.map +1 -0
- package/dist-cdn/library-weekly-hours.js +1 -0
- package/dist-cdn/manifest.json +23 -0
- package/dist-cdn/site-analytics.js +6 -0
- package/dist-cdn/site-analytics.js.map +1 -0
- package/dist-cdn/site-footer.js +267 -0
- package/dist-cdn/site-footer.js.map +1 -0
- package/dist-cdn/site-header.js +1 -0
- package/dist-cdn/site-hours-section.js +145 -0
- package/dist-cdn/site-hours-section.js.map +1 -0
- package/dist-cdn/site-main-nav.js +1 -0
- package/dist-cdn/site-page.js +317 -0
- package/dist-cdn/site-page.js.map +1 -0
- package/dist-cdn/site-style.js +42 -0
- package/dist-cdn/site-style.js.map +1 -0
- package/dist-cdn/skills/uvalib-web-components/SKILL.md +276 -0
- package/dist-cdn/skills/uvalib-web-components/reference/components.md +631 -0
- package/dist-cdn/skills/uvalib-web-components/reference/migration.md +74 -0
- package/dist-cdn/skills/uvalib-web-components/reference/snippets.md +147 -0
- package/dist-cdn/tokens.css +152 -0
- package/dist-cdn/uvalib-analytics.js +6 -0
- package/dist-cdn/uvalib-analytics.js.map +1 -0
- package/dist-cdn/uvalib-date-range.js +262 -0
- package/dist-cdn/uvalib-date-range.js.map +1 -0
- package/dist-cdn/uvalib-filter.js +184 -0
- package/dist-cdn/uvalib-filter.js.map +1 -0
- package/package.json +152 -4
- package/skills/uvalib-web-components/SKILL.md +276 -0
- package/skills/uvalib-web-components/reference/components.md +631 -0
- package/skills/uvalib-web-components/reference/migration.md +74 -0
- package/skills/uvalib-web-components/reference/snippets.md +147 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Usage: npx @uvalib/web-components install-skill [--dir .claude/skills] [--force]
|
|
3
|
+
// npx @uvalib/web-components install-skill --check [--dir .claude/skills] [--strict]
|
|
4
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
const PACKAGE = '@uvalib/web-components';
|
|
9
|
+
const SKILL = 'uvalib-web-components';
|
|
10
|
+
/** Written next to SKILL.md in every installed copy. */
|
|
11
|
+
const STAMP = 'installed.json';
|
|
12
|
+
|
|
13
|
+
const usage = `Usage: npx ${PACKAGE} install-skill [--dir <skills-dir>] [--force]
|
|
14
|
+
npx ${PACKAGE} install-skill --check [--dir <skills-dir>] [--strict]
|
|
15
|
+
|
|
16
|
+
Copies the ${SKILL} agent skill into <skills-dir>/${SKILL}
|
|
17
|
+
(default: .claude/skills) and records the package version in ${STAMP}.
|
|
18
|
+
Refuses to overwrite an existing copy without --force.
|
|
19
|
+
|
|
20
|
+
--check compares an installed copy with the latest release on npm. It prints one
|
|
21
|
+
line, with the update command, only when the copy is missing or out of date, and
|
|
22
|
+
exits 0 (so it can run as a Claude Code SessionStart hook); --strict exits 1
|
|
23
|
+
instead. A network failure only warns.`;
|
|
24
|
+
|
|
25
|
+
const args = process.argv.slice(2);
|
|
26
|
+
if (args[0] !== 'install-skill') {
|
|
27
|
+
console.error(usage);
|
|
28
|
+
process.exit(args[0] === '--help' || args[0] === '-h' ? 0 : 1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let dir = '.claude/skills';
|
|
32
|
+
let force = false;
|
|
33
|
+
let check = false;
|
|
34
|
+
let strict = false;
|
|
35
|
+
for (let i = 1; i < args.length; i++) {
|
|
36
|
+
if (args[i] === '--force') force = true;
|
|
37
|
+
else if (args[i] === '--check') check = true;
|
|
38
|
+
else if (args[i] === '--strict') strict = true;
|
|
39
|
+
else if (args[i] === '--dir' && args[i + 1]) dir = args[++i];
|
|
40
|
+
else {
|
|
41
|
+
console.error(usage);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const pkgRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
47
|
+
const version = JSON.parse(readFileSync(join(pkgRoot, 'package.json'), 'utf8')).version;
|
|
48
|
+
const dest = join(resolve(dir), SKILL);
|
|
49
|
+
const updateCommand = `npx ${PACKAGE}@latest install-skill --dir ${dir} --force`;
|
|
50
|
+
|
|
51
|
+
if (check) await runCheck();
|
|
52
|
+
else install();
|
|
53
|
+
|
|
54
|
+
function install() {
|
|
55
|
+
const src = join(pkgRoot, 'skills', SKILL);
|
|
56
|
+
if (existsSync(dest)) {
|
|
57
|
+
if (!force) {
|
|
58
|
+
console.error(`${dest} already exists; pass --force to overwrite.`);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
rmSync(dest, { recursive: true, force: true });
|
|
62
|
+
}
|
|
63
|
+
mkdirSync(dirname(dest), { recursive: true });
|
|
64
|
+
cpSync(src, dest, { recursive: true });
|
|
65
|
+
const stamp = { package: PACKAGE, version, installedAt: new Date().toISOString() };
|
|
66
|
+
writeFileSync(join(dest, STAMP), JSON.stringify(stamp, null, 2) + '\n');
|
|
67
|
+
console.log(`Installed ${SKILL} skill ${version} to ${dest}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** -1, 0 or 1 for x.y.z versions (a pre-release sorts before its release). */
|
|
71
|
+
function compare(a, b) {
|
|
72
|
+
const parse = (v) => {
|
|
73
|
+
const [core, pre = ''] = String(v).split('-', 2);
|
|
74
|
+
return { nums: core.split('.').map((n) => Number.parseInt(n, 10) || 0), pre };
|
|
75
|
+
};
|
|
76
|
+
const x = parse(a);
|
|
77
|
+
const y = parse(b);
|
|
78
|
+
for (let i = 0; i < 3; i++) {
|
|
79
|
+
const [p, q] = [x.nums[i] ?? 0, y.nums[i] ?? 0];
|
|
80
|
+
if (p !== q) return p < q ? -1 : 1;
|
|
81
|
+
}
|
|
82
|
+
if (x.pre === y.pre) return 0;
|
|
83
|
+
if (!x.pre) return 1;
|
|
84
|
+
if (!y.pre) return -1;
|
|
85
|
+
return x.pre < y.pre ? -1 : 1;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The latest published version, or null (after a warning) when it cannot be read. */
|
|
89
|
+
async function latestVersion() {
|
|
90
|
+
// UVALIB_SKILL_REGISTRY points tests (or a mirror) at another npm registry.
|
|
91
|
+
const registry = (process.env.UVALIB_SKILL_REGISTRY || 'https://registry.npmjs.org').replace(
|
|
92
|
+
/\/$/,
|
|
93
|
+
'',
|
|
94
|
+
);
|
|
95
|
+
const url = `${registry}/${PACKAGE.replace('/', '%2f')}/latest`;
|
|
96
|
+
try {
|
|
97
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(5000) });
|
|
98
|
+
if (res.status === 404) {
|
|
99
|
+
console.error(`${SKILL}: ${PACKAGE} has no release on npm yet; nothing to compare.`);
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
103
|
+
const latest = (await res.json()).version;
|
|
104
|
+
if (typeof latest !== 'string') throw new Error('no version in the response');
|
|
105
|
+
return latest;
|
|
106
|
+
} catch (err) {
|
|
107
|
+
console.error(`${SKILL}: could not check for updates (${err.message}).`);
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function runCheck() {
|
|
113
|
+
const report = (message) => {
|
|
114
|
+
console.log(message);
|
|
115
|
+
process.exit(strict ? 1 : 0);
|
|
116
|
+
};
|
|
117
|
+
if (!existsSync(join(dest, 'SKILL.md'))) {
|
|
118
|
+
report(`The ${SKILL} agent skill is not installed in ${dir}. Install it: ${updateCommand}`);
|
|
119
|
+
}
|
|
120
|
+
let installed = null;
|
|
121
|
+
try {
|
|
122
|
+
installed = JSON.parse(readFileSync(join(dest, STAMP), 'utf8')).version ?? null;
|
|
123
|
+
} catch {
|
|
124
|
+
// Copies installed before version stamps existed have none.
|
|
125
|
+
}
|
|
126
|
+
const latest = await latestVersion();
|
|
127
|
+
if (!latest) process.exit(0);
|
|
128
|
+
if (!installed) {
|
|
129
|
+
report(
|
|
130
|
+
`The ${SKILL} agent skill in ${dir} has no version stamp (it predates ${STAMP}); the latest is ${latest}. Update it: ${updateCommand}`,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
if (compare(installed, latest) < 0) {
|
|
134
|
+
report(
|
|
135
|
+
`The ${SKILL} agent skill in ${dir} is ${installed}; ${latest} is available. Update it: ${updateCommand}`,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
process.exit(0);
|
|
139
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LitElement, type CSSResultGroup, type CSSResultOrNative } from 'lit';
|
|
2
|
+
/** Base class for all UVA Library components: optional light DOM, optional style opt-out. */
|
|
3
|
+
export declare class UvalibElement extends LitElement {
|
|
4
|
+
/**
|
|
5
|
+
* Whether the host gets the colour-scheme rule. Off for elements that wrap the site's own
|
|
6
|
+
* content (`<site-page>`, `<site-style>`), which must keep inheriting the page's scheme.
|
|
7
|
+
*/
|
|
8
|
+
protected static hostColorScheme: boolean;
|
|
9
|
+
/** Every component's styles start with the host colour-scheme rule (unless opted out). */
|
|
10
|
+
protected static finalizeStyles(styles?: CSSResultGroup): CSSResultOrNative[];
|
|
11
|
+
static shadowRootOptions: ShadowRootInit;
|
|
12
|
+
noShadowDom: boolean;
|
|
13
|
+
noStyle: boolean;
|
|
14
|
+
/** Fixed at the first createRenderRoot(); later attribute changes have no effect. */
|
|
15
|
+
private _lightDom?;
|
|
16
|
+
protected get lightDom(): boolean;
|
|
17
|
+
protected createRenderRoot(): HTMLElement | DocumentFragment;
|
|
18
|
+
connectedCallback(): void;
|
|
19
|
+
/** Light mode: install `static styles` into `root`, scoped to the tag. Subclasses may override. */
|
|
20
|
+
protected installLightStyles(root?: Document | ShadowRoot): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { LitElement, css } from 'lit';
|
|
8
|
+
import { property } from 'lit/decorators.js';
|
|
9
|
+
import { installLightDomStyles } from './light-dom-styles.js';
|
|
10
|
+
/**
|
|
11
|
+
* Each component's own `color-scheme`: `light` unless the page opted in to dark mode (then
|
|
12
|
+
* the root's `--uva-color-scheme`), so a host page's `color-scheme` never turns a component
|
|
13
|
+
* dark, and native controls, scrollbars and light-dark() colours inside follow the chosen one.
|
|
14
|
+
*/
|
|
15
|
+
const hostColorScheme = css `
|
|
16
|
+
:host {
|
|
17
|
+
color-scheme: var(--uva-color-scheme, light);
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
/** Base class for all UVA Library components: optional light DOM, optional style opt-out. */
|
|
21
|
+
export class UvalibElement extends LitElement {
|
|
22
|
+
constructor() {
|
|
23
|
+
super(...arguments);
|
|
24
|
+
this.noShadowDom = false;
|
|
25
|
+
this.noStyle = false;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Whether the host gets the colour-scheme rule. Off for elements that wrap the site's own
|
|
29
|
+
* content (`<site-page>`, `<site-style>`), which must keep inheriting the page's scheme.
|
|
30
|
+
*/
|
|
31
|
+
static { this.hostColorScheme = true; }
|
|
32
|
+
/** Every component's styles start with the host colour-scheme rule (unless opted out). */
|
|
33
|
+
static finalizeStyles(styles) {
|
|
34
|
+
const own = super.finalizeStyles(styles);
|
|
35
|
+
return own.length && this.hostColorScheme ? [hostColorScheme, ...own] : own;
|
|
36
|
+
}
|
|
37
|
+
static { this.shadowRootOptions = { ...LitElement.shadowRootOptions, mode: 'open' }; }
|
|
38
|
+
get lightDom() {
|
|
39
|
+
return this._lightDom ?? false;
|
|
40
|
+
}
|
|
41
|
+
createRenderRoot() {
|
|
42
|
+
this._lightDom ??= this.hasAttribute('no-shadow-dom') || this.noShadowDom;
|
|
43
|
+
if (this.lightDom)
|
|
44
|
+
return this;
|
|
45
|
+
const root = super.createRenderRoot();
|
|
46
|
+
if (this.noStyle)
|
|
47
|
+
root.adoptedStyleSheets = [];
|
|
48
|
+
return root;
|
|
49
|
+
}
|
|
50
|
+
connectedCallback() {
|
|
51
|
+
super.connectedCallback(); // creates the render root
|
|
52
|
+
if (this.lightDom && !this.noStyle) {
|
|
53
|
+
const node = this.getRootNode();
|
|
54
|
+
this.installLightStyles(node instanceof ShadowRoot || node instanceof Document ? node : undefined);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Light mode: install `static styles` into `root`, scoped to the tag. Subclasses may override. */
|
|
58
|
+
installLightStyles(root) {
|
|
59
|
+
installLightDomStyles(this.localName, this.constructor.elementStyles, { root });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
__decorate([
|
|
63
|
+
property({ type: Boolean, attribute: 'no-shadow-dom' })
|
|
64
|
+
], UvalibElement.prototype, "noShadowDom", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
property({ type: Boolean, attribute: 'no-style' })
|
|
67
|
+
], UvalibElement.prototype, "noStyle", void 0);
|
|
68
|
+
//# sourceMappingURL=UvalibElement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UvalibElement.js","sourceRoot":"","sources":["../../src/base/UvalibElement.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAA+C,MAAM,KAAK,CAAC;AACnF,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;;GAIG;AACH,MAAM,eAAe,GAAG,GAAG,CAAA;;;;CAI1B,CAAC;AAEF,6FAA6F;AAC7F,MAAM,OAAO,aAAc,SAAQ,UAAU;IAA7C;;QAe2D,gBAAW,GAAG,KAAK,CAAC;QACzB,YAAO,GAAG,KAAK,CAAC;IAkCtE,CAAC;IAjDC;;;OAGG;aACc,oBAAe,GAAG,IAAI,AAAP,CAAQ;IAExC,0FAA0F;IAChF,MAAM,CAAU,cAAc,CAAC,MAAuB;QAC9D,MAAM,GAAG,GAAG,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QACzC,OAAO,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,eAAe,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAC9E,CAAC;aAEM,sBAAiB,GAAmB,EAAE,GAAG,UAAU,CAAC,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,AAApE,CAAqE;IAO7F,IAAc,QAAQ;QACpB,OAAO,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC;IACjC,CAAC;IAEkB,gBAAgB;QACjC,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC;QAC1E,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAC;QAC/B,MAAM,IAAI,GAAG,KAAK,CAAC,gBAAgB,EAAgB,CAAC;QACpD,IAAI,IAAI,CAAC,OAAO;YAAE,IAAI,CAAC,kBAAkB,GAAG,EAAE,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;IAEQ,iBAAiB;QACxB,KAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC,0BAA0B;QACrD,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YACnC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;YAChC,IAAI,CAAC,kBAAkB,CACrB,IAAI,YAAY,UAAU,IAAI,IAAI,YAAY,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAC1E,CAAC;QACJ,CAAC;IACH,CAAC;IAED,mGAAmG;IACzF,kBAAkB,CAAC,IAA4B;QACvD,qBAAqB,CACnB,IAAI,CAAC,SAAS,EACb,IAAI,CAAC,WAAiC,CAAC,aAA+B,EACvE,EAAE,IAAI,EAAE,CACT,CAAC;IACJ,CAAC;;AAlCwD;IAAxD,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC;kDAAqB;AACzB;IAAnD,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;8CAAiB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Report to the page's analytics element, if there is one. Each helper dispatches a bubbling,
|
|
3
|
+
* composed `uvalib-analytics-*` event from `el`; `<uvalib-analytics>` and `<site-analytics>`
|
|
4
|
+
* (and the old v0.0.12 `<uvalib-analytics>`) listen on `document` and forward it to Matomo.
|
|
5
|
+
* Without a listener nothing happens. Never pass titles, URLs or other personal text.
|
|
6
|
+
*/
|
|
7
|
+
/** A Matomo event: category, action, then optional name and numeric value. */
|
|
8
|
+
export type AnalyticsEvent = [category: string, action: string, name?: string, value?: number];
|
|
9
|
+
/** A Matomo event (`trackEvent`), e.g. `['site-main-nav', 'menu-open', 'Research']`. */
|
|
10
|
+
export declare function trackEvent(el: EventTarget, parts: AnalyticsEvent): void;
|
|
11
|
+
/**
|
|
12
|
+
* A Matomo site search (`trackSiteSearch`): the keyword, its category (e.g. a result section)
|
|
13
|
+
* and the result count, left out when unknown.
|
|
14
|
+
*/
|
|
15
|
+
export declare function trackSearch(el: EventTarget, query: string, category?: string, count?: number): void;
|
|
16
|
+
/** One analytics element on the page, as the shared state sees it. */
|
|
17
|
+
export interface AnalyticsTracker {
|
|
18
|
+
/** Has no Matomo site id: it neither loads Matomo nor forwards events. */
|
|
19
|
+
off: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* State shared by every analytics element on the page, whichever tag, and whichever copy of
|
|
23
|
+
* the bundle defined it (an npm build and a CDN script, or two CDN versions): `Symbol.for`
|
|
24
|
+
* gives every copy the same key. Keep its shape stable across versions.
|
|
25
|
+
*/
|
|
26
|
+
export interface AnalyticsState {
|
|
27
|
+
/** Connected elements, in connection order; the first one not `off` forwards events. */
|
|
28
|
+
trackers: AnalyticsTracker[];
|
|
29
|
+
/** Matomo is set up on the page (by an element, or by a snippet found there first). */
|
|
30
|
+
booted: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** The page's shared analytics state. */
|
|
33
|
+
export declare function analyticsState(): AnalyticsState;
|
|
34
|
+
/** Every event type the analytics elements listen for, in both families. */
|
|
35
|
+
export declare const ANALYTICS_EVENTS: string[];
|
|
36
|
+
/**
|
|
37
|
+
* Keep the analytics events fired while no element forwards them (an element's code is still
|
|
38
|
+
* loading), to hand over once one does. `flush()` fires them again on `doc`; `drop()` forgets
|
|
39
|
+
* them. Either one stops the buffering.
|
|
40
|
+
*/
|
|
41
|
+
export declare function bufferAnalytics(doc: Document): {
|
|
42
|
+
flush(): void;
|
|
43
|
+
drop(): void;
|
|
44
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Report to the page's analytics element, if there is one. Each helper dispatches a bubbling,
|
|
3
|
+
* composed `uvalib-analytics-*` event from `el`; `<uvalib-analytics>` and `<site-analytics>`
|
|
4
|
+
* (and the old v0.0.12 `<uvalib-analytics>`) listen on `document` and forward it to Matomo.
|
|
5
|
+
* Without a listener nothing happens. Never pass titles, URLs or other personal text.
|
|
6
|
+
*/
|
|
7
|
+
const send = (el, type, detail) => {
|
|
8
|
+
el.dispatchEvent(new CustomEvent(`uvalib-analytics-${type}`, { detail, bubbles: true, composed: true }));
|
|
9
|
+
};
|
|
10
|
+
/** A Matomo event (`trackEvent`), e.g. `['site-main-nav', 'menu-open', 'Research']`. */
|
|
11
|
+
export function trackEvent(el, parts) {
|
|
12
|
+
send(el, 'event', { event: parts });
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A Matomo site search (`trackSiteSearch`): the keyword, its category (e.g. a result section)
|
|
16
|
+
* and the result count, left out when unknown.
|
|
17
|
+
*/
|
|
18
|
+
export function trackSearch(el, query, category, count) {
|
|
19
|
+
send(el, 'search', { searchQuery: query, searchCategory: category, resultCount: count });
|
|
20
|
+
}
|
|
21
|
+
const STATE = Symbol.for('@uvalib/web-components/analytics');
|
|
22
|
+
/** The page's shared analytics state. */
|
|
23
|
+
export function analyticsState() {
|
|
24
|
+
const w = window;
|
|
25
|
+
return (w[STATE] ??= { trackers: [], booted: false });
|
|
26
|
+
}
|
|
27
|
+
/** Every event type the analytics elements listen for, in both families. */
|
|
28
|
+
export const ANALYTICS_EVENTS = ['uvalib-analytics', 'site-analytics'].flatMap((f) => ['event', 'search', 'pageview'].map((t) => `${f}-${t}`));
|
|
29
|
+
/**
|
|
30
|
+
* Keep the analytics events fired while no element forwards them (an element's code is still
|
|
31
|
+
* loading), to hand over once one does. `flush()` fires them again on `doc`; `drop()` forgets
|
|
32
|
+
* them. Either one stops the buffering.
|
|
33
|
+
*/
|
|
34
|
+
export function bufferAnalytics(doc) {
|
|
35
|
+
const kept = [];
|
|
36
|
+
const keep = (e) => {
|
|
37
|
+
if (analyticsState().trackers.some((t) => !t.off))
|
|
38
|
+
return; // someone forwards it
|
|
39
|
+
kept.push({ type: e.type, detail: e.detail });
|
|
40
|
+
};
|
|
41
|
+
for (const t of ANALYTICS_EVENTS)
|
|
42
|
+
doc.addEventListener(t, keep);
|
|
43
|
+
const stop = () => {
|
|
44
|
+
for (const t of ANALYTICS_EVENTS)
|
|
45
|
+
doc.removeEventListener(t, keep);
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
flush() {
|
|
49
|
+
stop();
|
|
50
|
+
for (const { type, detail } of kept.splice(0))
|
|
51
|
+
doc.dispatchEvent(new CustomEvent(type, { detail }));
|
|
52
|
+
},
|
|
53
|
+
drop() {
|
|
54
|
+
stop();
|
|
55
|
+
kept.length = 0;
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=analytics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["../../src/base/analytics.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,MAAM,IAAI,GAAG,CAAC,EAAe,EAAE,IAAY,EAAE,MAAc,EAAQ,EAAE;IACnE,EAAE,CAAC,aAAa,CACd,IAAI,WAAW,CAAC,oBAAoB,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CACvF,CAAC;AACJ,CAAC,CAAC;AAEF,wFAAwF;AACxF,MAAM,UAAU,UAAU,CAAC,EAAe,EAAE,KAAqB;IAC/D,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CACzB,EAAe,EACf,KAAa,EACb,QAAiB,EACjB,KAAc;IAEd,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;AAC3F,CAAC;AAoBD,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;AAE7D,yCAAyC;AACzC,MAAM,UAAU,cAAc;IAC5B,MAAM,CAAC,GAAG,MAA+D,CAAC;IAC1E,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AACxD,CAAC;AAED,4EAA4E;AAC5E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CACnF,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CACxD,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,GAAa;IAC3C,MAAM,IAAI,GAAwC,EAAE,CAAC;IACrD,MAAM,IAAI,GAAG,CAAC,CAAQ,EAAE,EAAE;QACxB,IAAI,cAAc,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;YAAE,OAAO,CAAC,sBAAsB;QACjF,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,EAAG,CAAiB,CAAC,MAAM,EAAE,CAAC,CAAC;IACjE,CAAC,CAAC;IACF,KAAK,MAAM,CAAC,IAAI,gBAAgB;QAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,GAAG,EAAE;QAChB,KAAK,MAAM,CAAC,IAAI,gBAAgB;YAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACrE,CAAC,CAAC;IACF,OAAO;QACL,KAAK;YACH,IAAI,EAAE,CAAC;YACP,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC3C,GAAG,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QACzD,CAAC;QACD,IAAI;YACF,IAAI,EAAE,CAAC;YACP,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
/** The visitor's choice: follow the OS (`system`, the default) or pin `light` or `dark`. */
|
|
3
|
+
export type ColorSchemePreference = 'light' | 'dark' | 'system';
|
|
4
|
+
/** What is shown: the preference, with `system` resolved from `prefers-color-scheme`. */
|
|
5
|
+
export type ResolvedColorScheme = 'light' | 'dark';
|
|
6
|
+
/** localStorage key, per site (origin): `light` or `dark`; absent means `system`. */
|
|
7
|
+
export declare const COLOR_SCHEME_STORAGE_KEY = "uvalib-color-scheme";
|
|
8
|
+
/** Attribute on the root element that turns the opt-in dark-mode rules on. */
|
|
9
|
+
export declare const COLOR_SCHEME_ATTR = "data-uva-color-scheme";
|
|
10
|
+
/** Dark mode needs light-dark(); without it nothing is shown or set, and the page stays light. */
|
|
11
|
+
export declare function colorSchemeSupported(doc?: Document): boolean;
|
|
12
|
+
/** The stored preference: this page's in-memory choice if storage failed, else localStorage. */
|
|
13
|
+
export declare function readPreference(doc?: Document): ColorSchemePreference;
|
|
14
|
+
/** Whether the OS asks for dark. */
|
|
15
|
+
export declare function systemIsDark(doc?: Document): boolean;
|
|
16
|
+
export declare function resolvePreference(pref: ColorSchemePreference, doc?: Document): ResolvedColorScheme;
|
|
17
|
+
/**
|
|
18
|
+
* Show `pref` on the page: `data-uva-color-scheme` on the root element, and with `inline`
|
|
19
|
+
* (for `no-style`, where no stylesheet maps the attribute) `color-scheme` as an inline style.
|
|
20
|
+
*/
|
|
21
|
+
export declare function applyPreference(doc: Document, pref: ColorSchemePreference, inline?: boolean): void;
|
|
22
|
+
/** Turn dark mode off again: remove the attribute and any inline `color-scheme`. */
|
|
23
|
+
export declare function clearPreference(doc: Document): void;
|
|
24
|
+
/**
|
|
25
|
+
* Remember and show `pref`. `system` removes the stored value; storage that throws keeps the
|
|
26
|
+
* choice in memory for this page. Every connected control is told.
|
|
27
|
+
*/
|
|
28
|
+
export declare function setPreference(doc: Document, pref: ColorSchemePreference, inline?: boolean): void;
|
|
29
|
+
/** The opt-in rules on the document (layered, so host CSS wins), for pages without tokens.css. */
|
|
30
|
+
export declare function installColorSchemeStyles(doc: Document): void;
|
|
31
|
+
/** The scheme the root element shows: from `data-uva-color-scheme`, or null when dark mode is off. */
|
|
32
|
+
export declare function rootColorScheme(doc?: Document): ResolvedColorScheme | null;
|
|
33
|
+
/**
|
|
34
|
+
* A component's view of dark mode. While `enabled()` and supported (`active`), it owns
|
|
35
|
+
* `data-uva-color-scheme` on the root element: it sets it, keeps it current with the
|
|
36
|
+
* stored preference (any control on the page, another tab through the `storage` event) and
|
|
37
|
+
* removes it when the last owner in the document is turned off or disconnected. A connected
|
|
38
|
+
* controller that is not enabled removes a stray attribute (for example from the inline
|
|
39
|
+
* snippet on a page without the switch) unless another one owns it.
|
|
40
|
+
*
|
|
41
|
+
* Every connected controller also follows the root's scheme (`rootDark`) and the OS
|
|
42
|
+
* preference (`systemDark`), so a header without the switch never shows the navy logo on a
|
|
43
|
+
* dark page. A controller that is off on a page where dark mode is off stays inert: it reads
|
|
44
|
+
* no storage and queries no media, and listens only for the controllers' own change event.
|
|
45
|
+
*/
|
|
46
|
+
export declare class ColorSchemeController implements ReactiveController {
|
|
47
|
+
private readonly host;
|
|
48
|
+
private readonly enabled;
|
|
49
|
+
private readonly inline;
|
|
50
|
+
/** Whether the host renders anything from this state (and so needs updates). */
|
|
51
|
+
private readonly renders;
|
|
52
|
+
preference: ColorSchemePreference;
|
|
53
|
+
/** What "System" resolves to: the OS preference. */
|
|
54
|
+
systemDark: boolean;
|
|
55
|
+
/** Whether the root element currently shows the dark scheme. */
|
|
56
|
+
rootDark: boolean;
|
|
57
|
+
/** Whether forced colors (a contrast theme) are on. */
|
|
58
|
+
forcedColors: boolean;
|
|
59
|
+
/** Whether the root element has `data-uva-color-scheme` (dark mode is on for the page). */
|
|
60
|
+
rootOn: boolean;
|
|
61
|
+
/** Enabled and supported: this controller owns the root attribute. */
|
|
62
|
+
active: boolean;
|
|
63
|
+
/** Set while sync() runs, so its own change events do not request a second update. */
|
|
64
|
+
private syncing;
|
|
65
|
+
private listening?;
|
|
66
|
+
constructor(host: ReactiveControllerHost & HTMLElement, enabled: () => boolean, inline: () => boolean,
|
|
67
|
+
/** Whether the host renders anything from this state (and so needs updates). */
|
|
68
|
+
renders?: boolean);
|
|
69
|
+
hostConnected(): void;
|
|
70
|
+
hostDisconnected(): void;
|
|
71
|
+
/** Call when `enabled()` may have changed (from the host's `willUpdate`). */
|
|
72
|
+
sync(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Whether to show the reversed (white) logo: only while the page shows dark mode, and under
|
|
75
|
+
* forced colors (a contrast theme repaints the header) only when the OS theme is dark.
|
|
76
|
+
*/
|
|
77
|
+
get logoDark(): boolean;
|
|
78
|
+
/** The visitor picked `pref` in a control. */
|
|
79
|
+
choose(pref: ColorSchemePreference): void;
|
|
80
|
+
/** Stop owning the attribute; the last owner to go removes it. */
|
|
81
|
+
private release;
|
|
82
|
+
private readonly onChange;
|
|
83
|
+
private readonly onStorage;
|
|
84
|
+
private refresh;
|
|
85
|
+
/**
|
|
86
|
+
* What to listen to: nothing without `light-dark()` support; everything (storage, the OS
|
|
87
|
+
* and forced-colors queries) while this controller owns the attribute or the page shows
|
|
88
|
+
* dark mode; otherwise only the controllers' own change event, which tells an inert
|
|
89
|
+
* controller that another one turned dark mode on.
|
|
90
|
+
*/
|
|
91
|
+
private listenLevel;
|
|
92
|
+
private listen;
|
|
93
|
+
}
|