@the-portland-company/shell 0.15.0 → 0.16.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/dist/chrome.css CHANGED
@@ -296,3 +296,56 @@
296
296
  --line: #333333;
297
297
  --shadow-soft: 0 4px 16px rgba(0, 0, 0, 0.5);
298
298
  }
299
+
300
+ /* ---------------------------------------------------------------------------
301
+ Top-bar widget slot — normalizes third-party launchers (e.g. DevNotes) to
302
+ the universal top-bar icon treatment (Global Rules: every icon the exact
303
+ same size, every badge the exact same style; no slot ships its own look).
304
+ Wrap the widget in `.topbar-widget-slot` (shell exports <TopBarWidgetSlot>).
305
+ --------------------------------------------------------------------------- */
306
+ .topbar-widget-slot > button,
307
+ .topbar-widget-slot > div > button:first-of-type,
308
+ .topbar-widget-slot > span > button:first-of-type {
309
+ width: var(--topbar-icon-button-size, 32px);
310
+ height: var(--topbar-icon-button-size, 32px);
311
+ display: inline-flex;
312
+ align-items: center;
313
+ justify-content: center;
314
+ border: 1px solid var(--line);
315
+ border-radius: 9999px;
316
+ background: transparent;
317
+ color: var(--topbar-icon-color, var(--muted));
318
+ opacity: 1;
319
+ position: relative;
320
+ transition: background-color 0.15s ease, color 0.15s ease;
321
+ }
322
+ .topbar-widget-slot > button:hover,
323
+ .topbar-widget-slot > div > button:first-of-type:hover,
324
+ .topbar-widget-slot > span > button:first-of-type:hover {
325
+ background: var(--topbar-icon-hover-bg, transparent);
326
+ color: var(--topbar-icon-hover-color, var(--foreground));
327
+ }
328
+ .topbar-widget-slot button svg {
329
+ width: var(--topbar-icon-size, 20px);
330
+ height: var(--topbar-icon-size, 20px);
331
+ opacity: 1;
332
+ }
333
+ /* Match <TopBarCountBadge>: same offset, size, fill and type as every count. */
334
+ .topbar-widget-slot button [class*="rounded-full"][class*="bg-"],
335
+ .topbar-widget-slot button .dn-badge {
336
+ position: absolute;
337
+ top: -4px;
338
+ right: -4px;
339
+ height: 1rem;
340
+ min-width: 1rem;
341
+ display: inline-flex;
342
+ align-items: center;
343
+ justify-content: center;
344
+ padding: 0 0.25rem;
345
+ border-radius: 9999px;
346
+ background: var(--color-race-red, #e63946);
347
+ color: #fff;
348
+ font-size: 10px;
349
+ font-weight: 400;
350
+ line-height: 1;
351
+ }
@@ -0,0 +1,68 @@
1
+ // src/theme-preference.ts
2
+ var THEME_STORAGE_KEY = "politogy_theme";
3
+ var THEME_COOKIE = "politogy_theme";
4
+ var VALID = ["light", "dark", "system"];
5
+ function isThemePreference(v) {
6
+ return typeof v === "string" && VALID.includes(v);
7
+ }
8
+ function readThemeCookie() {
9
+ if (typeof document === "undefined") return null;
10
+ try {
11
+ const m = document.cookie.match(
12
+ new RegExp(`(?:^|;\\s*)${THEME_COOKIE}=([^;]+)`)
13
+ );
14
+ const v = m ? decodeURIComponent(m[1]) : null;
15
+ return isThemePreference(v) ? v : null;
16
+ } catch {
17
+ return null;
18
+ }
19
+ }
20
+ function writeThemeCookie(pref) {
21
+ if (typeof document === "undefined" || typeof window === "undefined") return;
22
+ const host = window.location.hostname;
23
+ const onParentDomain = /(^|\.)politogyvrm\.com$/i.test(host);
24
+ const domainAttr = onParentDomain ? "; Domain=.politogyvrm.com" : "";
25
+ const secure = window.location.protocol === "https:" ? "; Secure" : "";
26
+ document.cookie = `${THEME_COOKIE}=${encodeURIComponent(
27
+ pref
28
+ )}; Path=/; Max-Age=31536000; SameSite=Lax${domainAttr}${secure}`;
29
+ }
30
+ function resolveTheme(pref) {
31
+ if (pref === "system") {
32
+ try {
33
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
34
+ } catch {
35
+ return "light";
36
+ }
37
+ }
38
+ return pref;
39
+ }
40
+ function applyThemePreference(pref) {
41
+ if (typeof document === "undefined") return;
42
+ const resolved = resolveTheme(pref);
43
+ const d = document.documentElement;
44
+ d.classList.toggle("dark", resolved === "dark");
45
+ try {
46
+ d.style.colorScheme = resolved;
47
+ } catch {
48
+ }
49
+ }
50
+ var THEME_PREPAINT_SCRIPT = `(function(){try{
51
+ var KEY=${JSON.stringify(THEME_STORAGE_KEY)};
52
+ var VALID=["light","dark","system"];
53
+ function fromCookie(){try{var m=document.cookie.match(/(?:^|;\\s*)${THEME_COOKIE}=([^;]+)/);return m?decodeURIComponent(m[1]):null;}catch(e){return null;}}
54
+ var cookie=fromCookie();
55
+ var ls=null;try{ls=localStorage.getItem(KEY);}catch(e){}
56
+ var pref=cookie||ls||"system";
57
+ if(VALID.indexOf(pref)===-1)pref="system";
58
+ if(cookie&&cookie!==ls){try{localStorage.setItem(KEY,cookie);}catch(e){}}
59
+ var resolved=pref;
60
+ if(pref==="system"){try{resolved=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";}catch(e){resolved="light";}}
61
+ var d=document.documentElement;
62
+ if(resolved==="dark"){d.classList.add("dark");}else{d.classList.remove("dark");}
63
+ try{d.style.colorScheme=resolved;}catch(e){}
64
+ }catch(e){}})();`;
65
+
66
+ export { THEME_COOKIE, THEME_PREPAINT_SCRIPT, THEME_STORAGE_KEY, applyThemePreference, isThemePreference, readThemeCookie, resolveTheme, writeThemeCookie };
67
+ //# sourceMappingURL=chunk-ZZWM7BZZ.js.map
68
+ //# sourceMappingURL=chunk-ZZWM7BZZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/theme-preference.ts"],"names":[],"mappings":";AAqBO,IAAM,iBAAA,GAAoB;AAC1B,IAAM,YAAA,GAAe;AAE5B,IAAM,KAAA,GAAoC,CAAC,OAAA,EAAS,MAAA,EAAQ,QAAQ,CAAA;AAE7D,SAAS,kBAAkB,CAAA,EAAkC;AAClE,EAAA,OAAO,OAAO,CAAA,KAAM,QAAA,IAAa,KAAA,CAA4B,SAAS,CAAC,CAAA;AACzE;AAGO,SAAS,eAAA,GAA0C;AACxD,EAAA,IAAI,OAAO,QAAA,KAAa,WAAA,EAAa,OAAO,IAAA;AAC5C,EAAA,IAAI;AACF,IAAA,MAAM,CAAA,GAAI,SAAS,MAAA,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,MAAM,QAAA,GAAW,aAAa,IAAI,CAAA;AAClC,EAAA,MAAM,IAAI,QAAA,CAAS,eAAA;AACnB,EAAA,CAAA,CAAE,SAAA,CAAU,MAAA,CAAO,MAAA,EAAQ,QAAA,KAAa,MAAM,CAAA;AAC9C,EAAA,IAAI;AACF,IAAA,CAAA,CAAE,MAAM,WAAA,GAAc,QAAA;AAAA,EACxB,CAAA,CAAA,MAAQ;AAAA,EAER;AACF;AAQO,IAAM,qBAAA,GAAwB,CAAA;AAAA,QAAA,EAC3B,IAAA,CAAK,SAAA,CAAU,iBAAiB,CAAC,CAAA;AAAA;AAAA,kEAAA,EAEyB,YAAY,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAA","file":"chunk-ZZWM7BZZ.js","sourcesContent":["// Universal theme preference — the ONE cross-app contract.\n//\n// One theme choice (Light / Dark / System) follows the authenticated user\n// across every Politogy app + subdomain. Three layers cooperate:\n// 1. VRM Core `profiles.theme_preference` — source of truth, persisted via\n// the chrome API (`PATCH me/preferences { themePreference }`) and read\n// back from `GET me` (`themePreference`).\n// 2. `.politogyvrm.com` cookie `politogy_theme` — zero-flash pre-paint\n// vehicle that crosses subdomains (auth session cookies are host-only).\n// 3. localStorage `politogy_theme` — offline fallback store.\n//\n// Ported verbatim from contacts/apps/web/src/lib/theme.ts (the origin of the\n// contract) so every app runs the identical behavior from npm. This module is\n// server-safe (no 'use client'): layouts import THEME_PREPAINT_SCRIPT for the\n// pre-paint inline script. The client-side hook lives in ./native\n// (useThemePreference).\n\nexport type ThemePreference = 'light' | 'dark' | 'system'\n\n// Single converged key for BOTH the localStorage store and the\n// cross-subdomain cookie, so a choice in one app is the same key in the next.\nexport const THEME_STORAGE_KEY = 'politogy_theme'\nexport const THEME_COOKIE = 'politogy_theme'\n\nconst VALID: readonly ThemePreference[] = ['light', 'dark', 'system']\n\nexport function isThemePreference(v: unknown): v is ThemePreference {\n return typeof v === 'string' && (VALID as readonly string[]).includes(v)\n}\n\n/** Read the shared cookie (browser only; null on the server or when unset). */\nexport function readThemeCookie(): ThemePreference | null {\n if (typeof document === 'undefined') return null\n try {\n const m = document.cookie.match(\n new RegExp(`(?:^|;\\\\s*)${THEME_COOKIE}=([^;]+)`),\n )\n const v = m ? decodeURIComponent(m[1]) : null\n return isThemePreference(v) ? v : null\n } catch {\n return null\n }\n}\n\n// Set the cross-subdomain cookie. On a *.politogyvrm.com host we scope it to\n// the parent domain so every app subdomain reads it; on any other host\n// (localhost, *.pages.dev preview) we fall back to a host-only cookie so\n// local/preview theming still works without a mismatched Domain attribute\n// (which browsers silently drop). 1-year, SameSite=Lax, Secure on https.\nexport function writeThemeCookie(pref: ThemePreference): void {\n if (typeof document === 'undefined' || typeof window === 'undefined') return\n const host = window.location.hostname\n const onParentDomain = /(^|\\.)politogyvrm\\.com$/i.test(host)\n const domainAttr = onParentDomain ? '; Domain=.politogyvrm.com' : ''\n const secure = window.location.protocol === 'https:' ? '; Secure' : ''\n document.cookie = `${THEME_COOKIE}=${encodeURIComponent(\n pref,\n )}; Path=/; Max-Age=31536000; SameSite=Lax${domainAttr}${secure}`\n}\n\n/** Resolve a preference to the concrete light/dark it renders as right now. */\nexport function resolveTheme(pref: ThemePreference): 'light' | 'dark' {\n if (pref === 'system') {\n try {\n return window.matchMedia('(prefers-color-scheme: dark)').matches\n ? 'dark'\n : 'light'\n } catch {\n return 'light'\n }\n }\n return pref\n}\n\n/** Apply a preference to the document (`.dark` class + color-scheme). */\nexport function applyThemePreference(pref: ThemePreference): void {\n if (typeof document === 'undefined') return\n const resolved = resolveTheme(pref)\n const d = document.documentElement\n d.classList.toggle('dark', resolved === 'dark')\n try {\n d.style.colorScheme = resolved\n } catch {\n /* non-fatal */\n }\n}\n\n// Inline pre-paint script — render it in <head> (or as the first child of\n// <body>) so the theme applies before first paint. Resolves the preference\n// from cookie → localStorage → OS, applies the `.dark` class + `color-scheme`,\n// and seeds localStorage from the cookie so the app hydrates to the synced\n// value (the cross-subdomain flash fix). Self-contained, dependency-free, and\n// wrapped so any failure is silent (never blocks paint).\nexport const THEME_PREPAINT_SCRIPT = `(function(){try{\nvar KEY=${JSON.stringify(THEME_STORAGE_KEY)};\nvar VALID=[\"light\",\"dark\",\"system\"];\nfunction fromCookie(){try{var m=document.cookie.match(/(?:^|;\\\\s*)${THEME_COOKIE}=([^;]+)/);return m?decodeURIComponent(m[1]):null;}catch(e){return null;}}\nvar cookie=fromCookie();\nvar ls=null;try{ls=localStorage.getItem(KEY);}catch(e){}\nvar pref=cookie||ls||\"system\";\nif(VALID.indexOf(pref)===-1)pref=\"system\";\nif(cookie&&cookie!==ls){try{localStorage.setItem(KEY,cookie);}catch(e){}}\nvar resolved=pref;\nif(pref===\"system\"){try{resolved=window.matchMedia(\"(prefers-color-scheme: dark)\").matches?\"dark\":\"light\";}catch(e){resolved=\"light\";}}\nvar d=document.documentElement;\nif(resolved===\"dark\"){d.classList.add(\"dark\");}else{d.classList.remove(\"dark\");}\ntry{d.style.colorScheme=resolved;}catch(e){}\n}catch(e){}})();`\n"]}