@the-portland-company/shell 0.67.0 → 0.68.0
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 +26 -0
- package/dist/app-chrome.cjs +577 -430
- package/dist/app-chrome.cjs.map +1 -1
- package/dist/app-chrome.d.cts +39 -11
- package/dist/app-chrome.d.ts +39 -11
- package/dist/app-chrome.js +33 -15
- package/dist/app-chrome.js.map +1 -1
- package/dist/chrome.css +96 -16
- package/dist/{chunk-JHIFJZ73.js → chunk-NHBNM5P3.js} +17 -8
- package/dist/chunk-NHBNM5P3.js.map +1 -0
- package/dist/{chunk-T5ERHFNT.js → chunk-ZKYREVCK.js} +528 -376
- package/dist/chunk-ZKYREVCK.js.map +1 -0
- package/dist/index.cjs +12 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/native.cjs +546 -385
- package/dist/native.cjs.map +1 -1
- package/dist/native.d.cts +62 -3
- package/dist/native.d.ts +62 -3
- package/dist/native.js +2 -2
- package/dist/theme-preference.cjs +15 -6
- package/dist/theme-preference.cjs.map +1 -1
- package/dist/theme-preference.d.cts +3 -3
- package/dist/theme-preference.d.ts +3 -3
- package/dist/theme-preference.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-JHIFJZ73.js.map +0 -1
- package/dist/chunk-T5ERHFNT.js.map +0 -1
package/dist/native.d.cts
CHANGED
|
@@ -291,7 +291,22 @@ interface StandardNavOptions {
|
|
|
291
291
|
contactsItem?: {
|
|
292
292
|
href?: string;
|
|
293
293
|
children?: NavItem[];
|
|
294
|
+
/**
|
|
295
|
+
* Live contact count shown right-aligned on the Contacts row, already
|
|
296
|
+
* formatted for display ("31.9K"). Only the owning app knows it.
|
|
297
|
+
* (Specs/Contacts design: `Contacts · 31.9K`.)
|
|
298
|
+
*/
|
|
299
|
+
count?: string | number | null;
|
|
294
300
|
};
|
|
301
|
+
/**
|
|
302
|
+
* Top-level rows to OMIT, by label (case-insensitive), e.g. `['Polls','CTAs']`.
|
|
303
|
+
* The Specs/Contacts design rail lists Relationship → Collect → Account with
|
|
304
|
+
* exactly Dashboard · Contacts · Email broadcast · SMS/MMS blast / Calls to
|
|
305
|
+
* action · Forms · Surveys / My profile · Organization settings; apps that
|
|
306
|
+
* still surface Polls / CTAs keep them by default. A section row with no
|
|
307
|
+
* remaining items is dropped too.
|
|
308
|
+
*/
|
|
309
|
+
hiddenItems?: string[];
|
|
295
310
|
/**
|
|
296
311
|
* App-local override for the Petition-mode "Dashboard" entry, same contract
|
|
297
312
|
* as `contactsItem`: `href`/`children` used verbatim so the Petitions app
|
|
@@ -380,6 +395,12 @@ type NavItem = {
|
|
|
380
395
|
disabled?: boolean;
|
|
381
396
|
/** Tooltip for a disabled row — say why, and how to resolve it. */
|
|
382
397
|
disabledTitle?: string;
|
|
398
|
+
/**
|
|
399
|
+
* Right-aligned count/annotation on the row — e.g. the live contact count
|
|
400
|
+
* on "Contacts" (`31.9K`). Pre-formatted by the app; the shell only draws
|
|
401
|
+
* it (Specs/Contacts design rail). Omitted/null draws nothing.
|
|
402
|
+
*/
|
|
403
|
+
badge?: string | number | null;
|
|
383
404
|
/**
|
|
384
405
|
* Nested sub-items. When present, the row becomes an expandable GROUP header.
|
|
385
406
|
* Clicking it always toggles the children open/closed and rotates the
|
|
@@ -509,6 +530,17 @@ type NavFooter = {
|
|
|
509
530
|
commitDate?: string;
|
|
510
531
|
/** Full name of the commit author (only the first name is shown). */
|
|
511
532
|
commitAuthor?: string;
|
|
533
|
+
/**
|
|
534
|
+
* The signed-in user, drawn as a card (avatar · name · email · chevron)
|
|
535
|
+
* ABOVE the links row. Reference/UI-Platform v30 → Left bar: "The user —
|
|
536
|
+
* avatar, name, email and the user menu — lives in the left bar footer."
|
|
537
|
+
* Clicking it opens the account menu UPWARD. `NavAppShell` fills these from
|
|
538
|
+
* `topBar.user` / `topBar.userMenu` / `topBar.onSignOut` automatically, so
|
|
539
|
+
* standalone `NavSidebar` consumers pass them only when they want the card.
|
|
540
|
+
*/
|
|
541
|
+
user?: NavUser | null;
|
|
542
|
+
userMenu?: NavUserMenu | null;
|
|
543
|
+
onSignOut?: () => void;
|
|
512
544
|
};
|
|
513
545
|
type NavSidebarProps = {
|
|
514
546
|
pathname: string;
|
|
@@ -596,6 +628,15 @@ type NavUserMenu = {
|
|
|
596
628
|
onRemoveAccount?: (id: string) => void;
|
|
597
629
|
addAccountHref?: string;
|
|
598
630
|
onAddAccount?: () => void;
|
|
631
|
+
/**
|
|
632
|
+
* Navigation display (Sub Menu / Tabs Only / Both) — lives in the account
|
|
633
|
+
* menu since 0.68.0; the top-bar `NavDisplayAction` popover is retired from
|
|
634
|
+
* the standard cluster (design: 4 icon buttons + Help).
|
|
635
|
+
*/
|
|
636
|
+
navDisplay?: {
|
|
637
|
+
value: NavDisplayMode;
|
|
638
|
+
onChange: (next: NavDisplayMode) => void;
|
|
639
|
+
};
|
|
599
640
|
/** Theme preference segmented control (Light / System / Dark). */
|
|
600
641
|
theme?: {
|
|
601
642
|
value: ThemePreference;
|
|
@@ -607,7 +648,11 @@ type NavBreadcrumb = {
|
|
|
607
648
|
href?: string;
|
|
608
649
|
};
|
|
609
650
|
type NavTopBarProps = {
|
|
610
|
-
|
|
651
|
+
/**
|
|
652
|
+
* Chrome-owned page title line (`<h1>` above main). Omit when the page body
|
|
653
|
+
* owns its own title (registry `pageTitle: false`, e.g. Contacts).
|
|
654
|
+
*/
|
|
655
|
+
title?: string;
|
|
611
656
|
subtitle?: string;
|
|
612
657
|
/**
|
|
613
658
|
* Breadcrumb trail rendered UNDER the page title (Reference/UI-Platform:
|
|
@@ -653,12 +698,20 @@ type NavTopBarProps = {
|
|
|
653
698
|
* Build notes — a quiet text button that starts the right-hand group
|
|
654
699
|
* (Reference/UI-Platform "Top bar → required elements").
|
|
655
700
|
*/
|
|
701
|
+
/**
|
|
702
|
+
* Where the My Account trigger lives. `'topbar'` (default for a standalone
|
|
703
|
+
* `NavTopBar`) keeps the avatar + name + chevron at the right end of the bar;
|
|
704
|
+
* `'sidebar'` / `'none'` hide it here — `NavAppShell` passes `'sidebar'` and
|
|
705
|
+
* draws the user card in the left-bar footer instead (UI-Platform v30:
|
|
706
|
+
* "There is no My Account badge in the top bar").
|
|
707
|
+
*/
|
|
708
|
+
accountMenu?: 'topbar' | 'sidebar' | 'none';
|
|
656
709
|
buildNotes?: {
|
|
657
710
|
label?: string;
|
|
658
711
|
onOpen?: () => void;
|
|
659
712
|
};
|
|
660
713
|
};
|
|
661
|
-
declare function NavTopBar({ title, subtitle, breadcrumbs, user, userMenu, onSignOut, actionsList, actions, themeToggle, onOpenNav, navOpen, search, buildNotes, }: NavTopBarProps): react_jsx_runtime.JSX.Element;
|
|
714
|
+
declare function NavTopBar({ title, subtitle, breadcrumbs, user, userMenu, onSignOut, actionsList, actions, themeToggle, onOpenNav, navOpen, search, buildNotes, accountMenu, }: NavTopBarProps): react_jsx_runtime.JSX.Element;
|
|
662
715
|
type NavTab = {
|
|
663
716
|
/** Stable identity (used as the React key). */
|
|
664
717
|
key: string;
|
|
@@ -765,8 +818,14 @@ type NavAppShellProps = {
|
|
|
765
818
|
* accent falls back to the global one, exactly as before 0.47.
|
|
766
819
|
*/
|
|
767
820
|
modeId?: string;
|
|
821
|
+
/**
|
|
822
|
+
* Where the user card / account menu renders. `'sidebar'` (default since
|
|
823
|
+
* 0.68.0) draws it in the left-bar footer and hides the top-bar trigger
|
|
824
|
+
* (Reference/UI-Platform v30); `'topbar'` restores the 0.67 top-right badge.
|
|
825
|
+
*/
|
|
826
|
+
accountMenuPlacement?: 'sidebar' | 'topbar';
|
|
768
827
|
children: ReactNode;
|
|
769
828
|
};
|
|
770
|
-
declare function NavAppShell({ sidebar, topBar, betaBanner, contentWrapper, modeId, children, }: NavAppShellProps): react_jsx_runtime.JSX.Element;
|
|
829
|
+
declare function NavAppShell({ sidebar, topBar, betaBanner, contentWrapper, accountMenuPlacement, modeId, children, }: NavAppShellProps): react_jsx_runtime.JSX.Element;
|
|
771
830
|
|
|
772
831
|
export { BETA_BANNER_DISMISS_KEY, CAMPAIGN_FEATURE_AVAILABILITY, CORE_APP_ORIGIN, CORE_BILLING_PATH, type CampaignFeatureAvailability, type ChromeMe, type ChromeNotificationAlert, type ChromeNotificationImport, type ChromeNotificationQuarantine, type ChromeNotificationReply, type ChromeNotificationsPayload, type ChromeOrgSummary, type CommunicationsFuelStatus, FuelAction, type FuelChannelStatus, NavAppShell, type NavAppShellProps, NavBetaBanner, type NavBetaBannerProps, type NavBrand, type NavBreadcrumb, type NavChromeFetcher, NavChromeProvider, NavDisplayAction, type NavDisplayMode, type NavFooter, type NavFooterLink, type NavIcon, type NavItem, type NavLinkComponent, type NavLinkProps, type NavLinkedAccount, type NavMode, type NavModeOption, type NavOrg, type NavOrgOption, type NavRoleBadge, NavSidebar, type NavSidebarProps, type NavTab, NavTabStrip, type NavTabStripProps, NavThemeControl, NavTopBar, type NavTopBarAction, type NavTopBarProps, type NavUser, type NavUserMenu, NotificationsAction, SPECS_ORIGIN, SpecOverlayAction, type StandardNavIconKey, type StandardNavMode, type StandardNavOptions, SupportAction, type ThemePreference, TopBarCountBadge, TopBarPanelArrow, TopBarPopover, TopBarTooltip, TopBarWidgetSlot, clearBetaBannerDismissal, envChipClasses, isNavItemActive, resolveOrgLogoUrl, standardPolitogyNav, topBarIconButtonClass, useChromeMe, useChromeOrgs, useNavChromeFetcher, useThemePreference };
|
package/dist/native.d.ts
CHANGED
|
@@ -291,7 +291,22 @@ interface StandardNavOptions {
|
|
|
291
291
|
contactsItem?: {
|
|
292
292
|
href?: string;
|
|
293
293
|
children?: NavItem[];
|
|
294
|
+
/**
|
|
295
|
+
* Live contact count shown right-aligned on the Contacts row, already
|
|
296
|
+
* formatted for display ("31.9K"). Only the owning app knows it.
|
|
297
|
+
* (Specs/Contacts design: `Contacts · 31.9K`.)
|
|
298
|
+
*/
|
|
299
|
+
count?: string | number | null;
|
|
294
300
|
};
|
|
301
|
+
/**
|
|
302
|
+
* Top-level rows to OMIT, by label (case-insensitive), e.g. `['Polls','CTAs']`.
|
|
303
|
+
* The Specs/Contacts design rail lists Relationship → Collect → Account with
|
|
304
|
+
* exactly Dashboard · Contacts · Email broadcast · SMS/MMS blast / Calls to
|
|
305
|
+
* action · Forms · Surveys / My profile · Organization settings; apps that
|
|
306
|
+
* still surface Polls / CTAs keep them by default. A section row with no
|
|
307
|
+
* remaining items is dropped too.
|
|
308
|
+
*/
|
|
309
|
+
hiddenItems?: string[];
|
|
295
310
|
/**
|
|
296
311
|
* App-local override for the Petition-mode "Dashboard" entry, same contract
|
|
297
312
|
* as `contactsItem`: `href`/`children` used verbatim so the Petitions app
|
|
@@ -380,6 +395,12 @@ type NavItem = {
|
|
|
380
395
|
disabled?: boolean;
|
|
381
396
|
/** Tooltip for a disabled row — say why, and how to resolve it. */
|
|
382
397
|
disabledTitle?: string;
|
|
398
|
+
/**
|
|
399
|
+
* Right-aligned count/annotation on the row — e.g. the live contact count
|
|
400
|
+
* on "Contacts" (`31.9K`). Pre-formatted by the app; the shell only draws
|
|
401
|
+
* it (Specs/Contacts design rail). Omitted/null draws nothing.
|
|
402
|
+
*/
|
|
403
|
+
badge?: string | number | null;
|
|
383
404
|
/**
|
|
384
405
|
* Nested sub-items. When present, the row becomes an expandable GROUP header.
|
|
385
406
|
* Clicking it always toggles the children open/closed and rotates the
|
|
@@ -509,6 +530,17 @@ type NavFooter = {
|
|
|
509
530
|
commitDate?: string;
|
|
510
531
|
/** Full name of the commit author (only the first name is shown). */
|
|
511
532
|
commitAuthor?: string;
|
|
533
|
+
/**
|
|
534
|
+
* The signed-in user, drawn as a card (avatar · name · email · chevron)
|
|
535
|
+
* ABOVE the links row. Reference/UI-Platform v30 → Left bar: "The user —
|
|
536
|
+
* avatar, name, email and the user menu — lives in the left bar footer."
|
|
537
|
+
* Clicking it opens the account menu UPWARD. `NavAppShell` fills these from
|
|
538
|
+
* `topBar.user` / `topBar.userMenu` / `topBar.onSignOut` automatically, so
|
|
539
|
+
* standalone `NavSidebar` consumers pass them only when they want the card.
|
|
540
|
+
*/
|
|
541
|
+
user?: NavUser | null;
|
|
542
|
+
userMenu?: NavUserMenu | null;
|
|
543
|
+
onSignOut?: () => void;
|
|
512
544
|
};
|
|
513
545
|
type NavSidebarProps = {
|
|
514
546
|
pathname: string;
|
|
@@ -596,6 +628,15 @@ type NavUserMenu = {
|
|
|
596
628
|
onRemoveAccount?: (id: string) => void;
|
|
597
629
|
addAccountHref?: string;
|
|
598
630
|
onAddAccount?: () => void;
|
|
631
|
+
/**
|
|
632
|
+
* Navigation display (Sub Menu / Tabs Only / Both) — lives in the account
|
|
633
|
+
* menu since 0.68.0; the top-bar `NavDisplayAction` popover is retired from
|
|
634
|
+
* the standard cluster (design: 4 icon buttons + Help).
|
|
635
|
+
*/
|
|
636
|
+
navDisplay?: {
|
|
637
|
+
value: NavDisplayMode;
|
|
638
|
+
onChange: (next: NavDisplayMode) => void;
|
|
639
|
+
};
|
|
599
640
|
/** Theme preference segmented control (Light / System / Dark). */
|
|
600
641
|
theme?: {
|
|
601
642
|
value: ThemePreference;
|
|
@@ -607,7 +648,11 @@ type NavBreadcrumb = {
|
|
|
607
648
|
href?: string;
|
|
608
649
|
};
|
|
609
650
|
type NavTopBarProps = {
|
|
610
|
-
|
|
651
|
+
/**
|
|
652
|
+
* Chrome-owned page title line (`<h1>` above main). Omit when the page body
|
|
653
|
+
* owns its own title (registry `pageTitle: false`, e.g. Contacts).
|
|
654
|
+
*/
|
|
655
|
+
title?: string;
|
|
611
656
|
subtitle?: string;
|
|
612
657
|
/**
|
|
613
658
|
* Breadcrumb trail rendered UNDER the page title (Reference/UI-Platform:
|
|
@@ -653,12 +698,20 @@ type NavTopBarProps = {
|
|
|
653
698
|
* Build notes — a quiet text button that starts the right-hand group
|
|
654
699
|
* (Reference/UI-Platform "Top bar → required elements").
|
|
655
700
|
*/
|
|
701
|
+
/**
|
|
702
|
+
* Where the My Account trigger lives. `'topbar'` (default for a standalone
|
|
703
|
+
* `NavTopBar`) keeps the avatar + name + chevron at the right end of the bar;
|
|
704
|
+
* `'sidebar'` / `'none'` hide it here — `NavAppShell` passes `'sidebar'` and
|
|
705
|
+
* draws the user card in the left-bar footer instead (UI-Platform v30:
|
|
706
|
+
* "There is no My Account badge in the top bar").
|
|
707
|
+
*/
|
|
708
|
+
accountMenu?: 'topbar' | 'sidebar' | 'none';
|
|
656
709
|
buildNotes?: {
|
|
657
710
|
label?: string;
|
|
658
711
|
onOpen?: () => void;
|
|
659
712
|
};
|
|
660
713
|
};
|
|
661
|
-
declare function NavTopBar({ title, subtitle, breadcrumbs, user, userMenu, onSignOut, actionsList, actions, themeToggle, onOpenNav, navOpen, search, buildNotes, }: NavTopBarProps): react_jsx_runtime.JSX.Element;
|
|
714
|
+
declare function NavTopBar({ title, subtitle, breadcrumbs, user, userMenu, onSignOut, actionsList, actions, themeToggle, onOpenNav, navOpen, search, buildNotes, accountMenu, }: NavTopBarProps): react_jsx_runtime.JSX.Element;
|
|
662
715
|
type NavTab = {
|
|
663
716
|
/** Stable identity (used as the React key). */
|
|
664
717
|
key: string;
|
|
@@ -765,8 +818,14 @@ type NavAppShellProps = {
|
|
|
765
818
|
* accent falls back to the global one, exactly as before 0.47.
|
|
766
819
|
*/
|
|
767
820
|
modeId?: string;
|
|
821
|
+
/**
|
|
822
|
+
* Where the user card / account menu renders. `'sidebar'` (default since
|
|
823
|
+
* 0.68.0) draws it in the left-bar footer and hides the top-bar trigger
|
|
824
|
+
* (Reference/UI-Platform v30); `'topbar'` restores the 0.67 top-right badge.
|
|
825
|
+
*/
|
|
826
|
+
accountMenuPlacement?: 'sidebar' | 'topbar';
|
|
768
827
|
children: ReactNode;
|
|
769
828
|
};
|
|
770
|
-
declare function NavAppShell({ sidebar, topBar, betaBanner, contentWrapper, modeId, children, }: NavAppShellProps): react_jsx_runtime.JSX.Element;
|
|
829
|
+
declare function NavAppShell({ sidebar, topBar, betaBanner, contentWrapper, accountMenuPlacement, modeId, children, }: NavAppShellProps): react_jsx_runtime.JSX.Element;
|
|
771
830
|
|
|
772
831
|
export { BETA_BANNER_DISMISS_KEY, CAMPAIGN_FEATURE_AVAILABILITY, CORE_APP_ORIGIN, CORE_BILLING_PATH, type CampaignFeatureAvailability, type ChromeMe, type ChromeNotificationAlert, type ChromeNotificationImport, type ChromeNotificationQuarantine, type ChromeNotificationReply, type ChromeNotificationsPayload, type ChromeOrgSummary, type CommunicationsFuelStatus, FuelAction, type FuelChannelStatus, NavAppShell, type NavAppShellProps, NavBetaBanner, type NavBetaBannerProps, type NavBrand, type NavBreadcrumb, type NavChromeFetcher, NavChromeProvider, NavDisplayAction, type NavDisplayMode, type NavFooter, type NavFooterLink, type NavIcon, type NavItem, type NavLinkComponent, type NavLinkProps, type NavLinkedAccount, type NavMode, type NavModeOption, type NavOrg, type NavOrgOption, type NavRoleBadge, NavSidebar, type NavSidebarProps, type NavTab, NavTabStrip, type NavTabStripProps, NavThemeControl, NavTopBar, type NavTopBarAction, type NavTopBarProps, type NavUser, type NavUserMenu, NotificationsAction, SPECS_ORIGIN, SpecOverlayAction, type StandardNavIconKey, type StandardNavMode, type StandardNavOptions, SupportAction, type ThemePreference, TopBarCountBadge, TopBarPanelArrow, TopBarPopover, TopBarTooltip, TopBarWidgetSlot, clearBetaBannerDismissal, envChipClasses, isNavItemActive, resolveOrgLogoUrl, standardPolitogyNav, topBarIconButtonClass, useChromeMe, useChromeOrgs, useNavChromeFetcher, useThemePreference };
|
package/dist/native.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
export { BETA_BANNER_DISMISS_KEY, CAMPAIGN_FEATURE_AVAILABILITY, CORE_APP_ORIGIN, CORE_BILLING_PATH, FuelAction, NavAppShell, NavBetaBanner, NavChromeProvider, NavDisplayAction, NavSidebar, NavTabStrip, NavThemeControl, NavTopBar, NotificationsAction, SPECS_ORIGIN, SpecOverlayAction, SupportAction, TopBarCountBadge, TopBarPanelArrow, TopBarPopover, TopBarTooltip, TopBarWidgetSlot, clearBetaBannerDismissal, envChipClasses, isNavItemActive, resolveOrgLogoUrl, standardPolitogyNav, topBarIconButtonClass, useChromeMe, useChromeOrgs, useNavChromeFetcher, useThemePreference } from './chunk-
|
|
3
|
-
import './chunk-
|
|
2
|
+
export { BETA_BANNER_DISMISS_KEY, CAMPAIGN_FEATURE_AVAILABILITY, CORE_APP_ORIGIN, CORE_BILLING_PATH, FuelAction, NavAppShell, NavBetaBanner, NavChromeProvider, NavDisplayAction, NavSidebar, NavTabStrip, NavThemeControl, NavTopBar, NotificationsAction, SPECS_ORIGIN, SpecOverlayAction, SupportAction, TopBarCountBadge, TopBarPanelArrow, TopBarPopover, TopBarTooltip, TopBarWidgetSlot, clearBetaBannerDismissal, envChipClasses, isNavItemActive, resolveOrgLogoUrl, standardPolitogyNav, topBarIconButtonClass, useChromeMe, useChromeOrgs, useNavChromeFetcher, useThemePreference } from './chunk-ZKYREVCK.js';
|
|
3
|
+
import './chunk-NHBNM5P3.js';
|
|
4
4
|
//# sourceMappingURL=native.js.map
|
|
5
5
|
//# sourceMappingURL=native.js.map
|
|
@@ -58,6 +58,15 @@ function clearPendingThemeChoice() {
|
|
|
58
58
|
writeSharedCookie(THEME_PENDING_COOKIE, "", 0);
|
|
59
59
|
}
|
|
60
60
|
function resolveTheme(pref) {
|
|
61
|
+
if (pref === "dark") return "dark";
|
|
62
|
+
if (pref === "system") {
|
|
63
|
+
try {
|
|
64
|
+
if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
|
|
65
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
66
|
+
}
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
}
|
|
61
70
|
return "light";
|
|
62
71
|
}
|
|
63
72
|
function readStoredThemePreference() {
|
|
@@ -75,10 +84,11 @@ function readResolvedTheme() {
|
|
|
75
84
|
}
|
|
76
85
|
function applyThemePreference(pref) {
|
|
77
86
|
if (typeof document === "undefined") return;
|
|
78
|
-
const resolved = resolveTheme();
|
|
87
|
+
const resolved = resolveTheme(pref);
|
|
79
88
|
const d = document.documentElement;
|
|
80
|
-
d.classList.
|
|
89
|
+
d.classList.toggle("dark", resolved === "dark");
|
|
81
90
|
try {
|
|
91
|
+
d.setAttribute("data-theme", resolved);
|
|
82
92
|
d.style.colorScheme = resolved;
|
|
83
93
|
} catch {
|
|
84
94
|
}
|
|
@@ -92,11 +102,10 @@ var ls=null;try{ls=localStorage.getItem(KEY);}catch(e){}
|
|
|
92
102
|
var pref=cookie||ls||"system";
|
|
93
103
|
if(VALID.indexOf(pref)===-1)pref="system";
|
|
94
104
|
if(cookie&&cookie!==ls){try{localStorage.setItem(KEY,cookie);}catch(e){}}
|
|
95
|
-
|
|
96
|
-
// stale dark class a pre-retirement cookie/localStorage value left behind.
|
|
105
|
+
var dark=pref==="dark"||(pref==="system"&&!!(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches));
|
|
97
106
|
var d=document.documentElement;
|
|
98
|
-
d.classList.remove("dark");
|
|
99
|
-
try{d.style.colorScheme="light";}catch(e){}
|
|
107
|
+
if(dark)d.classList.add("dark");else d.classList.remove("dark");
|
|
108
|
+
try{d.setAttribute("data-theme",dark?"dark":"light");d.style.colorScheme=dark?"dark":"light";}catch(e){}
|
|
100
109
|
}catch(e){}})();`;
|
|
101
110
|
|
|
102
111
|
exports.THEME_COOKIE = THEME_COOKIE;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/theme-preference.ts"],"names":[],"mappings":";;;AAqBO,IAAM,iBAAA,GAAoB;AAC1B,IAAM,YAAA,GAAe;AAWrB,IAAM,oBAAA,GAAuB;AAEpC,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,C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AS,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,iBAAiB,CAAA;AAC5D,IAAA,IAAI,iBAAA,CAAkB,MAAM,CAAA,EAAG,OAAO,MAAA;AAAA,EACxC,CAAA,CAAA,MAAQ;AAAA,EAER;AACA,EAAA,OAAO,QAAA;AACT;AAUO,SAAS,iBAAA,GAAsC;AACpD,EAAA,OAAO,YAAA,CAAa,2BAA2B,CAAA;AACjD;AAKO,SAAS,qBAAqB,IAAA,EAA6B;AAChE,EAAA,IAAI,OAAO,aAAa,WAAA,EAAa;AACrC,EAAA,MAAM,QAAA,GAAW,aAAiB,CAAA;AAClC,EAAA,MAAM,IAAI,QAAA,CAAS,eAAA;AACnB,EAAA,CAAA,CAAE,SAAA,CAAU,OAAO,MAAM,CAAA;AACzB,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":"theme-preference.cjs","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\n// A local choice that has NOT yet reached VRM Core `profiles.theme_preference`.\n//\n// Politogy ID (auth.politogyvrm.com) has no chrome-API session to PATCH, so a\n// theme picked on the login screen only ever lands in the cookie. Without this\n// marker the next app booted the stale profile value through the reconcile step\n// below and overwrote the user's fresh choice — the \"I set System and it keeps\n// going back to Light\" bug (HITL 2026-07-23). The flag rides the same\n// cross-subdomain cookie so the first app that CAN talk to the chrome API\n// pushes the choice up instead of pulling the stale one down.\nexport const THEME_PENDING_COOKIE = 'politogy_theme_pending'\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// Write an arbitrary cross-subdomain cookie with the same scoping rules as the\n// theme cookie itself (parent domain on *.politogyvrm.com, host-only elsewhere).\nfunction writeSharedCookie(name: string, value: string, maxAgeSeconds: number): void {\n if (typeof document === 'undefined' || typeof window === 'undefined') return\n const host = window.location.hostname\n const domainAttr = /(^|\\.)politogyvrm\\.com$/i.test(host) ? '; Domain=.politogyvrm.com' : ''\n const secure = window.location.protocol === 'https:' ? '; Secure' : ''\n document.cookie = `${name}=${encodeURIComponent(\n value,\n )}; Path=/; Max-Age=${maxAgeSeconds}; SameSite=Lax${domainAttr}${secure}`\n}\n\n/**\n * Mark the current cookie value as a local choice that still has to reach the\n * user's profile. Call this from any surface that changes the theme WITHOUT a\n * chrome-API session (Politogy ID's login screen is the only one today).\n */\nexport function markThemeChoicePending(pref: ThemePreference): void {\n writeSharedCookie(THEME_PENDING_COOKIE, pref, 31536000)\n}\n\n/** The pending (not-yet-persisted) local choice, if any. */\nexport function readPendingThemeChoice(): ThemePreference | null {\n if (typeof document === 'undefined') return null\n try {\n const m = document.cookie.match(\n new RegExp(`(?:^|;\\\\s*)${THEME_PENDING_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/** Clear the pending marker once the choice has been written to the profile. */\nexport function clearPendingThemeChoice(): void {\n writeSharedCookie(THEME_PENDING_COOKIE, '', 0)\n}\n\n/** Resolve a preference to the concrete light/dark it renders as right now. */\nexport function resolveTheme(pref: ThemePreference): 'light' | 'dark' {\n // Dark Mode was retired platform-wide 2026-09-21 (Reference/UI-Platform →\n // Global Rules). `pref` is still read/stored so old cookies don't throw,\n // but every resolution is light now — no `.dark` class ever applies.\n void pref\n return 'light'\n}\n\n/**\n * Read the stored preference the way the pre-paint script does — cookie →\n * localStorage → `'system'`. Kept in lockstep with THEME_PREPAINT_SCRIPT so a\n * runtime reader can never disagree with what was applied before paint.\n */\nexport function readStoredThemePreference(): ThemePreference {\n const cookie = readThemeCookie()\n if (cookie) return cookie\n try {\n const stored = window.localStorage.getItem(THEME_STORAGE_KEY)\n if (isThemePreference(stored)) return stored\n } catch {\n /* localStorage may be unavailable (private mode) */\n }\n return 'system'\n}\n\n/**\n * The concrete light/dark the document is rendering as right now.\n *\n * This is the value anything theme-derived must follow — notably Chakra's\n * `colorMode`. Chakra used to be pinned to light while this resolved to dark,\n * which rendered dark chrome tokens over light Chakra content (the \"dark\n * labels on a light page\" desync).\n */\nexport function readResolvedTheme(): 'light' | 'dark' {\n return resolveTheme(readStoredThemePreference())\n}\n\n/** Apply a preference to the document. Dark Mode is retired — this always\n * resolves to light and makes sure no stale `.dark` class survives from a\n * pre-retirement cookie/localStorage value. */\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.remove('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){}}\n// Dark Mode retired platform-wide 2026-09-21 — always light, and strip any\n// stale dark class a pre-retirement cookie/localStorage value left behind.\nvar d=document.documentElement;\nd.classList.remove(\"dark\");\ntry{d.style.colorScheme=\"light\";}catch(e){}\n}catch(e){}})();`\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/theme-preference.ts"],"names":[],"mappings":";;;AAqBO,IAAM,iBAAA,GAAoB;AAC1B,IAAM,YAAA,GAAe;AAWrB,IAAM,oBAAA,GAAuB;AAEpC,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,CAAO,KAAA;AAAA,MACxB,IAAI,MAAA,CAAO,CAAA,WAAA,EAAc,YAAY,CAAA,QAAA,CAAU;AAAA,KACjD;AACA,IAAA,MAAM,IAAI,CAAA,GAAI,kBAAA,CAAmB,CAAA,CAAE,CAAC,CAAC,CAAA,GAAI,IAAA;AACzC,IAAA,OAAO,iBAAA,CAAkB,CAAC,CAAA,GAAI,CAAA,GAAI,IAAA;AAAA,EACpC,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AAOO,SAAS,iBAAiB,IAAA,EAA6B;AAC5D,EAAA,IAAI,OAAO,QAAA,KAAa,WAAA,IAAe,OAAO,WAAW,WAAA,EAAa;AACtE,EAAA,MAAM,IAAA,GAAO,OAAO,QAAA,CAAS,QAAA;AAC7B,EAAA,MAAM,cAAA,GAAiB,0BAAA,CAA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EAAA,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,YAAA,CAAa,cAAc,QAAQ,CAAA;AACrC,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,gBAAA","file":"theme-preference.cjs","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\n// A local choice that has NOT yet reached VRM Core `profiles.theme_preference`.\n//\n// Politogy ID (auth.politogyvrm.com) has no chrome-API session to PATCH, so a\n// theme picked on the login screen only ever lands in the cookie. Without this\n// marker the next app booted the stale profile value through the reconcile step\n// below and overwrote the user's fresh choice — the \"I set System and it keeps\n// going back to Light\" bug (HITL 2026-07-23). The flag rides the same\n// cross-subdomain cookie so the first app that CAN talk to the chrome API\n// pushes the choice up instead of pulling the stale one down.\nexport const THEME_PENDING_COOKIE = 'politogy_theme_pending'\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// Write an arbitrary cross-subdomain cookie with the same scoping rules as the\n// theme cookie itself (parent domain on *.politogyvrm.com, host-only elsewhere).\nfunction writeSharedCookie(name: string, value: string, maxAgeSeconds: number): void {\n if (typeof document === 'undefined' || typeof window === 'undefined') return\n const host = window.location.hostname\n const domainAttr = /(^|\\.)politogyvrm\\.com$/i.test(host) ? '; Domain=.politogyvrm.com' : ''\n const secure = window.location.protocol === 'https:' ? '; Secure' : ''\n document.cookie = `${name}=${encodeURIComponent(\n value,\n )}; Path=/; Max-Age=${maxAgeSeconds}; SameSite=Lax${domainAttr}${secure}`\n}\n\n/**\n * Mark the current cookie value as a local choice that still has to reach the\n * user's profile. Call this from any surface that changes the theme WITHOUT a\n * chrome-API session (Politogy ID's login screen is the only one today).\n */\nexport function markThemeChoicePending(pref: ThemePreference): void {\n writeSharedCookie(THEME_PENDING_COOKIE, pref, 31536000)\n}\n\n/** The pending (not-yet-persisted) local choice, if any. */\nexport function readPendingThemeChoice(): ThemePreference | null {\n if (typeof document === 'undefined') return null\n try {\n const m = document.cookie.match(\n new RegExp(`(?:^|;\\\\s*)${THEME_PENDING_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/** Clear the pending marker once the choice has been written to the profile. */\nexport function clearPendingThemeChoice(): void {\n writeSharedCookie(THEME_PENDING_COOKIE, '', 0)\n}\n\n/** Resolve a preference to the concrete light/dark it renders as right now. */\nexport function resolveTheme(pref: ThemePreference): 'light' | 'dark' {\n // Dark is honoured again from 0.68.0 (Specs/Contacts Visual Regression\n // gate runs light AND dark; the chrome ships a `.dark` token block). An\n // explicit 'dark' resolves dark; 'system' follows the OS; anything else —\n // and any environment without matchMedia — is light.\n if (pref === 'dark') return 'dark'\n if (pref === 'system') {\n try {\n if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {\n return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'\n }\n } catch {\n /* fall through */\n }\n }\n return 'light'\n}\n\n/**\n * Read the stored preference the way the pre-paint script does — cookie →\n * localStorage → `'system'`. Kept in lockstep with THEME_PREPAINT_SCRIPT so a\n * runtime reader can never disagree with what was applied before paint.\n */\nexport function readStoredThemePreference(): ThemePreference {\n const cookie = readThemeCookie()\n if (cookie) return cookie\n try {\n const stored = window.localStorage.getItem(THEME_STORAGE_KEY)\n if (isThemePreference(stored)) return stored\n } catch {\n /* localStorage may be unavailable (private mode) */\n }\n return 'system'\n}\n\n/**\n * The concrete light/dark the document is rendering as right now.\n *\n * This is the value anything theme-derived must follow — notably Chakra's\n * `colorMode`. Chakra used to be pinned to light while this resolved to dark,\n * which rendered dark chrome tokens over light Chakra content (the \"dark\n * labels on a light page\" desync).\n */\nexport function readResolvedTheme(): 'light' | 'dark' {\n return resolveTheme(readStoredThemePreference())\n}\n\n/** Apply a preference to the document: toggles `.dark` + `data-theme` on\n * `<html>` (both selectors the chrome's dark token block matches) and sets\n * `color-scheme` so native controls follow. */\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.setAttribute('data-theme', resolved)\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 dark=pref===\"dark\"||(pref===\"system\"&&!!(window.matchMedia&&window.matchMedia(\"(prefers-color-scheme: dark)\").matches));\nvar d=document.documentElement;\nif(dark)d.classList.add(\"dark\");else d.classList.remove(\"dark\");\ntry{d.setAttribute(\"data-theme\",dark?\"dark\":\"light\");d.style.colorScheme=dark?\"dark\":\"light\";}catch(e){}\n}catch(e){}})();`\n"]}
|
|
@@ -33,9 +33,9 @@ declare function readStoredThemePreference(): ThemePreference;
|
|
|
33
33
|
* labels on a light page" desync).
|
|
34
34
|
*/
|
|
35
35
|
declare function readResolvedTheme(): 'light' | 'dark';
|
|
36
|
-
/** Apply a preference to the document
|
|
37
|
-
*
|
|
38
|
-
*
|
|
36
|
+
/** Apply a preference to the document: toggles `.dark` + `data-theme` on
|
|
37
|
+
* `<html>` (both selectors the chrome's dark token block matches) and sets
|
|
38
|
+
* `color-scheme` so native controls follow. */
|
|
39
39
|
declare function applyThemePreference(pref: ThemePreference): void;
|
|
40
40
|
declare const THEME_PREPAINT_SCRIPT: string;
|
|
41
41
|
|
|
@@ -33,9 +33,9 @@ declare function readStoredThemePreference(): ThemePreference;
|
|
|
33
33
|
* labels on a light page" desync).
|
|
34
34
|
*/
|
|
35
35
|
declare function readResolvedTheme(): 'light' | 'dark';
|
|
36
|
-
/** Apply a preference to the document
|
|
37
|
-
*
|
|
38
|
-
*
|
|
36
|
+
/** Apply a preference to the document: toggles `.dark` + `data-theme` on
|
|
37
|
+
* `<html>` (both selectors the chrome's dark token block matches) and sets
|
|
38
|
+
* `color-scheme` so native controls follow. */
|
|
39
39
|
declare function applyThemePreference(pref: ThemePreference): void;
|
|
40
40
|
declare const THEME_PREPAINT_SCRIPT: string;
|
|
41
41
|
|
package/dist/theme-preference.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { THEME_COOKIE, THEME_PENDING_COOKIE, THEME_PREPAINT_SCRIPT, THEME_STORAGE_KEY, applyThemePreference, clearPendingThemeChoice, isThemePreference, markThemeChoicePending, readPendingThemeChoice, readResolvedTheme, readStoredThemePreference, readThemeCookie, resolveTheme, writeThemeCookie } from './chunk-
|
|
1
|
+
export { THEME_COOKIE, THEME_PENDING_COOKIE, THEME_PREPAINT_SCRIPT, THEME_STORAGE_KEY, applyThemePreference, clearPendingThemeChoice, isThemePreference, markThemeChoicePending, readPendingThemeChoice, readResolvedTheme, readStoredThemePreference, readThemeCookie, resolveTheme, writeThemeCookie } from './chunk-NHBNM5P3.js';
|
|
2
2
|
//# sourceMappingURL=theme-preference.js.map
|
|
3
3
|
//# sourceMappingURL=theme-preference.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@the-portland-company/shell",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.68.0",
|
|
4
4
|
"description": "Shared chrome (header, sidebar, footer, theme, auth) for politogy apps. Drop into any Vite SPA to inherit the politogy look and signed-in user.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/theme-preference.ts"],"names":[],"mappings":";AAqBO,IAAM,iBAAA,GAAoB;AAC1B,IAAM,YAAA,GAAe;AAWrB,IAAM,oBAAA,GAAuB;AAEpC,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,CAAO,KAAA;AAAA,MACxB,IAAI,MAAA,CAAO,CAAA,WAAA,EAAc,YAAY,CAAA,QAAA,CAA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,CAAa,2BAA2B,CAAA;AACjD;AAKO,SAAS,qBAAqB,IAAA,EAA6B;AAChE,EAAA,IAAI,OAAO,aAAa,WAAA,EAAa;AACrC,EAAA,MAAM,QAAA,GAAW,aAAiB,CAAA;AAClC,EAAA,MAAM,IAAI,QAAA,CAAS,eAAA;AACnB,EAAA,CAAA,CAAE,SAAA,CAAU,OAAO,MAAM,CAAA;AACzB,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-JHIFJZ73.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\n// A local choice that has NOT yet reached VRM Core `profiles.theme_preference`.\n//\n// Politogy ID (auth.politogyvrm.com) has no chrome-API session to PATCH, so a\n// theme picked on the login screen only ever lands in the cookie. Without this\n// marker the next app booted the stale profile value through the reconcile step\n// below and overwrote the user's fresh choice — the \"I set System and it keeps\n// going back to Light\" bug (HITL 2026-07-23). The flag rides the same\n// cross-subdomain cookie so the first app that CAN talk to the chrome API\n// pushes the choice up instead of pulling the stale one down.\nexport const THEME_PENDING_COOKIE = 'politogy_theme_pending'\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// Write an arbitrary cross-subdomain cookie with the same scoping rules as the\n// theme cookie itself (parent domain on *.politogyvrm.com, host-only elsewhere).\nfunction writeSharedCookie(name: string, value: string, maxAgeSeconds: number): void {\n if (typeof document === 'undefined' || typeof window === 'undefined') return\n const host = window.location.hostname\n const domainAttr = /(^|\\.)politogyvrm\\.com$/i.test(host) ? '; Domain=.politogyvrm.com' : ''\n const secure = window.location.protocol === 'https:' ? '; Secure' : ''\n document.cookie = `${name}=${encodeURIComponent(\n value,\n )}; Path=/; Max-Age=${maxAgeSeconds}; SameSite=Lax${domainAttr}${secure}`\n}\n\n/**\n * Mark the current cookie value as a local choice that still has to reach the\n * user's profile. Call this from any surface that changes the theme WITHOUT a\n * chrome-API session (Politogy ID's login screen is the only one today).\n */\nexport function markThemeChoicePending(pref: ThemePreference): void {\n writeSharedCookie(THEME_PENDING_COOKIE, pref, 31536000)\n}\n\n/** The pending (not-yet-persisted) local choice, if any. */\nexport function readPendingThemeChoice(): ThemePreference | null {\n if (typeof document === 'undefined') return null\n try {\n const m = document.cookie.match(\n new RegExp(`(?:^|;\\\\s*)${THEME_PENDING_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/** Clear the pending marker once the choice has been written to the profile. */\nexport function clearPendingThemeChoice(): void {\n writeSharedCookie(THEME_PENDING_COOKIE, '', 0)\n}\n\n/** Resolve a preference to the concrete light/dark it renders as right now. */\nexport function resolveTheme(pref: ThemePreference): 'light' | 'dark' {\n // Dark Mode was retired platform-wide 2026-09-21 (Reference/UI-Platform →\n // Global Rules). `pref` is still read/stored so old cookies don't throw,\n // but every resolution is light now — no `.dark` class ever applies.\n void pref\n return 'light'\n}\n\n/**\n * Read the stored preference the way the pre-paint script does — cookie →\n * localStorage → `'system'`. Kept in lockstep with THEME_PREPAINT_SCRIPT so a\n * runtime reader can never disagree with what was applied before paint.\n */\nexport function readStoredThemePreference(): ThemePreference {\n const cookie = readThemeCookie()\n if (cookie) return cookie\n try {\n const stored = window.localStorage.getItem(THEME_STORAGE_KEY)\n if (isThemePreference(stored)) return stored\n } catch {\n /* localStorage may be unavailable (private mode) */\n }\n return 'system'\n}\n\n/**\n * The concrete light/dark the document is rendering as right now.\n *\n * This is the value anything theme-derived must follow — notably Chakra's\n * `colorMode`. Chakra used to be pinned to light while this resolved to dark,\n * which rendered dark chrome tokens over light Chakra content (the \"dark\n * labels on a light page\" desync).\n */\nexport function readResolvedTheme(): 'light' | 'dark' {\n return resolveTheme(readStoredThemePreference())\n}\n\n/** Apply a preference to the document. Dark Mode is retired — this always\n * resolves to light and makes sure no stale `.dark` class survives from a\n * pre-retirement cookie/localStorage value. */\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.remove('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){}}\n// Dark Mode retired platform-wide 2026-09-21 — always light, and strip any\n// stale dark class a pre-retirement cookie/localStorage value left behind.\nvar d=document.documentElement;\nd.classList.remove(\"dark\");\ntry{d.style.colorScheme=\"light\";}catch(e){}\n}catch(e){}})();`\n"]}
|