@gntik-ai/templates 0.11.0 → 0.12.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.
Files changed (70) hide show
  1. package/dist/index.d.ts +24 -10
  2. package/dist/index.js +304 -266
  3. package/dist/index.js.map +1 -1
  4. package/package.json +8 -8
  5. package/src/assistant-chat/Page.test.tsx +37 -7
  6. package/src/assistant-chat/Page.tsx +98 -137
  7. package/src/assistant-chat/data.ts +69 -1
  8. package/src/assistant-chat/examples/AdapterChat.tsx +9 -0
  9. package/src/assistant-chat/template.meta.ts +1 -1
  10. package/src/board/Lane.tsx +1 -1
  11. package/src/code-editor/Page.test.tsx +12 -0
  12. package/src/code-editor/Page.tsx +2 -1
  13. package/src/code-editor/examples/PaletteTypography.tsx +130 -0
  14. package/src/code-editor/template.meta.ts +1 -1
  15. package/src/contact/Page.test.tsx +106 -0
  16. package/src/contact/Page.tsx +21 -3
  17. package/src/contact/PublicFrame.tsx +2 -17
  18. package/src/contact/examples/CustomFailure.tsx +24 -0
  19. package/src/contact/examples/FailedSend.tsx +19 -0
  20. package/src/contact/template.meta.ts +2 -2
  21. package/src/docs-article/Page.tsx +1 -1
  22. package/src/help-home/Page.test.tsx +10 -0
  23. package/src/help-home/Page.tsx +2 -4
  24. package/src/incident-console/Page.tsx +1 -1
  25. package/src/keyboard-shortcuts/Page.test.tsx +23 -1
  26. package/src/keyboard-shortcuts/Page.tsx +13 -3
  27. package/src/keyboard-shortcuts/ShortcutSheet.tsx +4 -5
  28. package/src/landing/Page.tsx +3 -17
  29. package/src/landing/template.meta.ts +1 -1
  30. package/src/messaging/Page.test.tsx +20 -3
  31. package/src/messaging/Page.tsx +15 -43
  32. package/src/messaging/template.meta.ts +1 -1
  33. package/src/notification-inbox/Page.tsx +1 -1
  34. package/src/pending-activation/Page.test.tsx +1 -1
  35. package/src/pricing/PublicFrame.tsx +2 -17
  36. package/src/pricing/template.meta.ts +1 -1
  37. package/src/resource-detail/Page.default.test.tsx +3 -2
  38. package/src/resource-detail/__snapshots__/Page.default.test.tsx.snap +2 -4
  39. package/src/resource-index/Page.test.tsx +178 -1
  40. package/src/resource-index/Page.tsx +59 -3
  41. package/src/resource-index/examples/UrlSynced.tsx +10 -0
  42. package/src/resource-index/template.meta.ts +1 -1
  43. package/src/resource-tree/Page.tsx +1 -1
  44. package/src/run-trace/Page.tsx +2 -2
  45. package/src/scorecard/Page.test.tsx +54 -0
  46. package/src/scorecard/Page.tsx +2 -0
  47. package/src/scorecard/data.ts +1 -1
  48. package/src/search-results/Page.tsx +3 -6
  49. package/src/settings-appearance/Page.test.tsx +36 -1
  50. package/src/settings-appearance/Page.tsx +15 -2
  51. package/src/settings-appearance/template.meta.ts +2 -1
  52. package/src/settings-profile/__tests__/dom.ts +4 -2
  53. package/src/settings-profile/fixtures/editable.snap +1 -1
  54. package/src/shared/ConsoleShell.context.test.tsx +125 -0
  55. package/src/shared/ConsoleShell.navigation.test.tsx +100 -0
  56. package/src/shared/ConsoleShell.tsx +38 -9
  57. package/src/shell-sidebar/Examples.test.tsx +73 -0
  58. package/src/shell-sidebar/examples/Brand.tsx +16 -0
  59. package/src/shell-sidebar/examples/ContextRegion.tsx +26 -0
  60. package/src/shell-sidebar/examples/PlatformWide.tsx +11 -0
  61. package/src/shell-sidebar/examples/Tenants.tsx +42 -0
  62. package/src/shell-sidebar/examples/UserMenuChildren.tsx +23 -0
  63. package/src/shell-sidebar/template.meta.ts +1 -1
  64. package/src/sign-in/BrandPanel.tsx +2 -2
  65. package/src/sign-in/Page.test.tsx +5 -0
  66. package/src/sso-login/Page.test.tsx +6 -0
  67. package/src/sso-login/Page.tsx +1 -0
  68. package/src/test/public-footer.test.tsx +44 -0
  69. package/src/test/without-forced-colors.test.ts +44 -0
  70. package/src/test/without-forced-colors.ts +14 -0
@@ -11,6 +11,7 @@ import {
11
11
  import {
12
12
  SidebarLayout,
13
13
  useI18n,
14
+ useNavigation,
14
15
  type BreadcrumbItem,
15
16
  type NavGroup,
16
17
  type SidebarLayoutProps,
@@ -21,15 +22,19 @@ import type { ReactNode } from 'react';
21
22
 
22
23
  export interface ConsoleShellProps
23
24
  extends
24
- Pick<AppSidebarHeaderProps, 'currentWorkspaceId' | 'onWorkspaceChange' | 'onCreateWorkspace'>,
25
- Pick<AppSidebarFooterProps, 'usage' | 'helpHref' | 'helpLabel' | 'userMenuItems' | 'onSignOut'>,
25
+ Omit<AppSidebarHeaderProps, 'collapsed' | 'className' | 'workspaces'>,
26
+ Pick<
27
+ AppSidebarFooterProps,
28
+ 'usage' | 'helpHref' | 'helpLabel' | 'userMenuItems' | 'userMenuChildren' | 'onSignOut'
29
+ >,
26
30
  Pick<SidebarLayoutProps, 'sidebarLabel' | 'collapseMode'> {
27
31
  /** Page content (usually a <Page>). */
28
32
  children: ReactNode;
29
- /** Sidebar navigation; defaults to the AppSidebar sample groups. */
33
+ /** Sidebar navigation; defaults to the NavigationProvider's groups, else the AppSidebar sample groups. */
30
34
  nav?: NavGroup[];
31
- /** Href of the current page, marks the active nav item. */
35
+ /** Href of the current page, marks the active nav item; defaults to the NavigationProvider's active menu item. */
32
36
  currentHref?: string;
37
+ /** Topbar trail; defaults to the NavigationProvider's active page. `null` hides it. */
33
38
  breadcrumbs?: BreadcrumbItem[] | null;
34
39
  workspaces?: Workspace[] | null;
35
40
  user?: UserMenuUser | null;
@@ -43,13 +48,15 @@ export interface ConsoleShellProps
43
48
  * The console frame shared by the templates: SidebarLayout with the AppSidebar header, nav and
44
49
  * footer, and the AppTopbar (breadcrumb, ⌘K search, notifications, theme, user menu).
45
50
  * Templates fill it with a Page; products swap the nav, workspaces, user, usage meter, help
46
- * link and user-menu items.
51
+ * link and user-menu items. Inside a NavigationProvider, an omitted `nav`, `currentHref` or
52
+ * `breadcrumbs` comes from the route tree; explicit props always win, and without a provider the
53
+ * defaults are unchanged.
47
54
  */
48
55
  export function ConsoleShell({
49
56
  children,
50
- nav,
51
- currentHref,
52
- breadcrumbs,
57
+ nav: navProp,
58
+ currentHref: currentHrefProp,
59
+ breadcrumbs: breadcrumbsProp,
53
60
  workspaces,
54
61
  currentWorkspaceId,
55
62
  onWorkspaceChange,
@@ -59,13 +66,23 @@ export function ConsoleShell({
59
66
  helpHref,
60
67
  helpLabel,
61
68
  userMenuItems,
69
+ userMenuChildren,
70
+ brand,
62
71
  onSignOut,
63
72
  topbar,
64
73
  storageKey,
65
74
  sidebarLabel,
66
75
  collapseMode,
76
+ ...contextProps
67
77
  }: ConsoleShellProps) {
68
78
  const { locale } = useI18n();
79
+ const navigation = useNavigation();
80
+ const nav = navProp ?? navigation?.groups;
81
+ // No visible menu item for the active page (or no active page) leaves every item unmarked; the
82
+ // raw pathname would re-activate routes getActivePage excludes, such as external ones.
83
+ const currentHref = currentHrefProp ?? (navigation ? (navigation.activePage?.menuHref ?? '') : undefined);
84
+ const breadcrumbs =
85
+ breadcrumbsProp === undefined && navigation ? (navigation.activePage?.breadcrumbs ?? null) : breadcrumbsProp;
69
86
  return (
70
87
  <ChartLocaleProvider locale={locale}>
71
88
  <SidebarLayout
@@ -80,6 +97,8 @@ export function ConsoleShell({
80
97
  currentWorkspaceId={currentWorkspaceId}
81
98
  onWorkspaceChange={onWorkspaceChange}
82
99
  onCreateWorkspace={onCreateWorkspace}
100
+ brand={brand}
101
+ {...contextProps}
83
102
  />
84
103
  )}
85
104
  sidebar={({ collapsed }) => <AppSidebarNav groups={nav} currentHref={currentHref} collapsed={collapsed} />}
@@ -91,10 +110,20 @@ export function ConsoleShell({
91
110
  helpHref={helpHref}
92
111
  helpLabel={helpLabel}
93
112
  userMenuItems={userMenuItems}
113
+ userMenuChildren={userMenuChildren}
94
114
  onSignOut={onSignOut}
95
115
  />
96
116
  )}
97
- topbar={<AppTopbar breadcrumbs={breadcrumbs} user={user} {...topbar} />}
117
+ topbar={
118
+ brand == null ? (
119
+ <AppTopbar breadcrumbs={breadcrumbs} user={user} {...topbar} />
120
+ ) : (
121
+ <>
122
+ <div className="min-w-0 shrink-0 lg:hidden">{brand}</div>
123
+ <AppTopbar breadcrumbs={breadcrumbs} user={user} {...topbar} />
124
+ </>
125
+ )
126
+ }
98
127
  >
99
128
  {children}
100
129
  </SidebarLayout>
@@ -0,0 +1,73 @@
1
+ import { render, screen, within } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { ToastProvider, Toaster } from '@gntik-ai/ui';
4
+
5
+ describe('Sidebar shell examples', () => {
6
+ it('demonstrates the brand slot in the sidebar, rail and mobile topbar', async () => {
7
+ const { default: Brand } = await import('./examples/Brand');
8
+ render(<Brand />);
9
+ expect(within(screen.getByRole('complementary')).getByText('Console identity')).toBeInTheDocument();
10
+ expect(within(screen.getAllByRole('banner')[0]!).getByText('Console identity').parentElement).toHaveClass(
11
+ 'lg:hidden',
12
+ );
13
+ await userEvent.click(screen.getByRole('button', { name: 'Collapse sidebar' }));
14
+ expect(within(screen.getByRole('complementary')).getByText('Console identity')).toBeInTheDocument();
15
+ });
16
+ it('demonstrates language choices alongside standard account actions', async () => {
17
+ const { default: UserMenuChildren } = await import('./examples/UserMenuChildren');
18
+ render(<UserMenuChildren />);
19
+ const sidebar = screen.getByRole('complementary');
20
+ await userEvent.click(within(sidebar).getByRole('button', { name: /Dana Whitfield/ }));
21
+ const menu = await screen.findByRole('menu');
22
+ expect(within(menu).getByRole('menuitem', { name: 'Account settings' })).toBeInTheDocument();
23
+ expect(within(menu).getByRole('menuitemradio', { name: 'English' })).toHaveAttribute('aria-checked', 'true');
24
+ await userEvent.click(within(menu).getByRole('menuitemradio', { name: 'French' }));
25
+ await userEvent.click(within(sidebar).getByRole('button', { name: /Dana Whitfield/ }));
26
+ expect(within(await screen.findByRole('menu')).getByRole('menuitemradio', { name: 'French' })).toHaveAttribute(
27
+ 'aria-checked',
28
+ 'true',
29
+ );
30
+ expect(screen.queryByRole('meter')).toBeNull();
31
+ expect(within(sidebar).queryByRole('link', { name: 'Help & docs' })).toBeNull();
32
+ });
33
+ it('demonstrates a busy context region whose consumer resets it', async () => {
34
+ const { default: ContextRegion } = await import('./examples/ContextRegion');
35
+ render(<ContextRegion />);
36
+ const region = screen.getByRole('region', { name: 'Active context' });
37
+ expect(region).toHaveAttribute('aria-busy', 'true');
38
+ expect(screen.getByRole('status')).toHaveTextContent('Updating context');
39
+ await userEvent.click(screen.getByRole('button', { name: 'Finish context update' }));
40
+ expect(region).toHaveAttribute('aria-busy', 'false');
41
+ expect(screen.getByRole('status')).toHaveTextContent('Context ready');
42
+ });
43
+ it('demonstrates platform-wide context with a brand and no context controls', async () => {
44
+ const { default: PlatformWide } = await import('./examples/PlatformWide');
45
+ render(
46
+ <ToastProvider>
47
+ <PlatformWide />
48
+ <Toaster />
49
+ </ToastProvider>,
50
+ );
51
+ expect(screen.getAllByText('Platform console').length).toBeGreaterThan(0);
52
+ expect(screen.queryByRole('combobox')).toBeNull();
53
+ expect(within(screen.getByRole('complementary')).queryByRole('region')).toBeNull();
54
+ expect(screen.getByRole('region', { name: 'Notifications' })).toBeInTheDocument();
55
+ });
56
+ it('demonstrates tenant selection, clearing and custom workspace copy', async () => {
57
+ const { default: Tenants } = await import('./examples/Tenants');
58
+ render(<Tenants />);
59
+ const user = userEvent.setup();
60
+ const tenant = screen.getByRole('combobox', { name: 'Organization' });
61
+ expect(tenant).toHaveTextContent('One');
62
+ await user.click(tenant);
63
+ await user.click(await screen.findByRole('option', { name: 'Two' }));
64
+ expect(tenant).toHaveTextContent('Two');
65
+ tenant.focus();
66
+ await user.keyboard('{Delete}');
67
+ expect(tenant).toHaveTextContent('Select tenant');
68
+ expect(screen.getByRole('combobox', { name: /Team spaces/ })).toBeInTheDocument();
69
+ expect(screen.getByRole('status')).toHaveTextContent('Platform context');
70
+ await user.click(screen.getByRole('button', { name: 'Show empty tenant list' }));
71
+ expect(tenant).toHaveTextContent('No organizations');
72
+ });
73
+ });
@@ -0,0 +1,16 @@
1
+ import { Text } from '@gntik-ai/ui';
2
+ import ShellSidebarPage from '../Page';
3
+
4
+ export default function Brand() {
5
+ return (
6
+ <ShellSidebarPage
7
+ shell={{
8
+ brand: (
9
+ <Text variant="label" className="truncate">
10
+ Console identity
11
+ </Text>
12
+ ),
13
+ }}
14
+ />
15
+ );
16
+ }
@@ -0,0 +1,26 @@
1
+ import { Badge, Button } from '@gntik-ai/ui';
2
+ import { useState } from 'react';
3
+ import ShellSidebarPage from '../Page';
4
+
5
+ export default function ContextRegion() {
6
+ const [busy, setBusy] = useState(true);
7
+ const [currentTenantId, onTenantSelect] = useState<string | null>('t1');
8
+ return (
9
+ <ShellSidebarPage
10
+ shell={{
11
+ tenants: [
12
+ { id: 't1', name: 'One' },
13
+ { id: 't2', name: 'Two' },
14
+ ],
15
+ currentTenantId,
16
+ onTenantSelect,
17
+ contextRegionLabel: 'Active context',
18
+ // The consumer owns this lifetime and must reset it when loading completes.
19
+ contextBusy: busy,
20
+ contextStatus: <Badge role="status">{busy ? 'Updating context' : 'Context ready'}</Badge>,
21
+ }}
22
+ >
23
+ <Button onClick={() => setBusy(!busy)}>{busy ? 'Finish context update' : 'Reload context'}</Button>
24
+ </ShellSidebarPage>
25
+ );
26
+ }
@@ -0,0 +1,11 @@
1
+ import { Text } from '@gntik-ai/ui';
2
+ import ShellSidebarPage from '../Page';
3
+
4
+ export default function PlatformWide() {
5
+ return (
6
+ <ShellSidebarPage
7
+ title="Platform overview"
8
+ shell={{ hideWorkspaceContext: true, brand: <Text variant="label">Platform console</Text> }}
9
+ />
10
+ );
11
+ }
@@ -0,0 +1,42 @@
1
+ import { useState } from 'react';
2
+ import { Button, Text } from '@gntik-ai/ui';
3
+ import ShellSidebarPage from '../Page';
4
+
5
+ const tenants = [
6
+ { id: 't1', name: 'One' },
7
+ { id: 't2', name: 'Two' },
8
+ ];
9
+ const workspaces = Array.from({ length: 7 }, (_, i) => ({ id: `space-${i}`, name: `Space ${i + 1}` }));
10
+
11
+ export default function Tenants() {
12
+ const [currentTenantId, onTenantSelect] = useState<string | null>('t1');
13
+ const [empty, setEmpty] = useState(false);
14
+ return (
15
+ <ShellSidebarPage
16
+ shell={{
17
+ tenants: empty ? [] : tenants,
18
+ currentTenantId,
19
+ onTenantSelect,
20
+ tenantLabel: 'Organization',
21
+ tenantEmptyText: 'No organizations',
22
+ workspaces,
23
+ workspaceLabel: 'Team spaces',
24
+ workspaceEmptyText: 'No matching team spaces',
25
+ contextStatus: (
26
+ <Text variant="caption" role="status">
27
+ {currentTenantId ? `Organization ${currentTenantId === 't1' ? 'One' : 'Two'}` : 'Platform context'}
28
+ </Text>
29
+ ),
30
+ }}
31
+ >
32
+ <Button
33
+ onClick={() => {
34
+ setEmpty(!empty);
35
+ onTenantSelect(null);
36
+ }}
37
+ >
38
+ {empty ? 'Restore tenants' : 'Show empty tenant list'}
39
+ </Button>
40
+ </ShellSidebarPage>
41
+ );
42
+ }
@@ -0,0 +1,23 @@
1
+ import { MenuGroupLabel, MenuRadioGroup, MenuRadioItem } from '@gntik-ai/ui';
2
+ import { useState } from 'react';
3
+ import ShellSidebarPage from '../Page';
4
+
5
+ export default function UserMenuChildren() {
6
+ const [language, setLanguage] = useState('en');
7
+ return (
8
+ <ShellSidebarPage
9
+ shell={{
10
+ usage: null,
11
+ helpHref: '',
12
+ userMenuItems: [{ label: 'Account settings', href: '#account' }],
13
+ userMenuChildren: (
14
+ <MenuRadioGroup value={language} onValueChange={setLanguage}>
15
+ <MenuGroupLabel>Language</MenuGroupLabel>
16
+ <MenuRadioItem value="en">English</MenuRadioItem>
17
+ <MenuRadioItem value="fr">French</MenuRadioItem>
18
+ </MenuRadioGroup>
19
+ ),
20
+ }}
21
+ />
22
+ );
23
+ }
@@ -6,7 +6,7 @@ export const meta: TemplateMeta = {
6
6
  priority: 'P1',
7
7
  status: 'stable',
8
8
  description:
9
- 'Console starter: app sidebar, topbar and an empty Page with a title, description and a first-run empty state.',
9
+ 'Console starter: app sidebar, topbar and an empty Page. Optional tenant selection, workspace context, a named busy region, account-menu content and a brand slot are shared through ConsoleShell.',
10
10
  layout: 'SidebarLayout',
11
11
  blocks: ['app-sidebar', 'app-topbar', 'page-header', 'empty-states'],
12
12
  };
@@ -12,10 +12,10 @@ export function BrandPanel({ eyebrow, headline, features }: BrandPanelCopy) {
12
12
  return (
13
13
  <Stack gap={8}>
14
14
  <Stack gap={4}>
15
- <Text variant="caption" tone="primary" className="font-mono tracking-[0.18em] uppercase">
15
+ <Text variant="caption" tone="primary" className="font-mono tracking-[0.18em] label-case">
16
16
  {eyebrow}
17
17
  </Text>
18
- <Text variant="display" className="text-[32px] text-balance">
18
+ <Text variant="display" className="text-[32px] font-bold tracking-tight text-balance">
19
19
  {headline}
20
20
  </Text>
21
21
  </Stack>
@@ -4,6 +4,11 @@ import { expectNoAxeViolations } from '../test/a11y';
4
4
  import SignInPage from './Page';
5
5
 
6
6
  describe('SignInPage', () => {
7
+ it('keeps the brand headline bold and tightly tracked at its custom font size', () => {
8
+ render(<SignInPage brand={{ eyebrow: 'Workspace', headline: 'A place for your team', features: [] }} />);
9
+ expect(screen.getByText('A place for your team')).toHaveClass('text-[32px]', 'font-bold', 'tracking-tight');
10
+ });
11
+
7
12
  it('renders the form, SSO options and brand panel', async () => {
8
13
  const { container } = render(<SignInPage />);
9
14
  expect(screen.getByRole('main')).toBeInTheDocument();
@@ -4,6 +4,12 @@ import { expectNoAxeViolations } from '../test/a11y';
4
4
  import SsoLoginPage from './Page';
5
5
 
6
6
  describe('SsoLoginPage', () => {
7
+ it('matches the 44px work email field to the SSO button', () => {
8
+ render(<SsoLoginPage />);
9
+ expect(screen.getByLabelText('Work email').parentElement).toHaveClass('h-11');
10
+ expect(screen.getByRole('button', { name: 'Continue with SSO' })).toHaveClass('h-11');
11
+ });
12
+
7
13
  it('renders the work email step', async () => {
8
14
  const { container } = render(<SsoLoginPage />);
9
15
  expect(screen.getByRole('main')).toBeInTheDocument();
@@ -129,6 +129,7 @@ export default function SsoLoginPage({
129
129
  <Field invalid={invalid}>
130
130
  <FieldLabel>Work email</FieldLabel>
131
131
  <Input
132
+ size="lg"
132
133
  type="email"
133
134
  leadingIcon={Building2}
134
135
  autoComplete="email"
@@ -0,0 +1,44 @@
1
+ import { render, screen, within } from '@testing-library/react';
2
+ import { I18nProvider } from '@gntik-ai/ui';
3
+ import LandingPage from '../landing/Page';
4
+ import PricingPage from '../pricing/Page';
5
+ import ContactPage from '../contact/Page';
6
+ import { expectNoAxeViolations } from './a11y';
7
+
8
+ describe.each([
9
+ ['landing', LandingPage],
10
+ ['pricing', PricingPage],
11
+ ['contact', ContactPage],
12
+ ] as const)('%s public footer', (_name, Page) => {
13
+ it.each(['dark', 'light', 'high_contrast'])(
14
+ 'keeps one footer with the public links (%s)',
15
+ { timeout: 15000 },
16
+ async (theme) => {
17
+ document.documentElement.className = theme;
18
+ const { container } = render(<Page />);
19
+ const footers = screen.getAllByRole('contentinfo');
20
+ expect(footers).toHaveLength(1);
21
+ const footer = footers[0]!;
22
+ expect(footer.querySelector('footer')).toBeNull();
23
+ const nav = within(footer).getByRole('navigation', { name: 'Footer' });
24
+ expect(
25
+ within(nav)
26
+ .getAllByRole('link')
27
+ .map((link) => link.textContent),
28
+ ).toEqual(['Status', 'Privacy', 'Terms']);
29
+ await expectNoAxeViolations(container);
30
+ },
31
+ );
32
+
33
+ it('uses the footer catalog and keeps caller footerLinks and copyright', () => {
34
+ render(
35
+ <I18nProvider locale="es">
36
+ <Page footerLinks={[{ label: 'Custom link', href: '/custom' }]} copyright="© Custom" />
37
+ </I18nProvider>,
38
+ );
39
+ const footer = screen.getByRole('contentinfo');
40
+ const nav = within(footer).getByRole('navigation', { name: 'Pie de página' });
41
+ expect(within(nav).getByRole('link', { name: 'Custom link' })).toHaveAttribute('href', '/custom');
42
+ expect(within(footer).getByText('© Custom')).toBeInTheDocument();
43
+ });
44
+ });
@@ -0,0 +1,44 @@
1
+ import { withoutForcedColors } from './without-forced-colors';
2
+
3
+ describe('withoutForcedColors', () => {
4
+ it('drops an all-forced class attribute but preserves empty and ordinary attributes exactly', () => {
5
+ const element = document.createElement('div');
6
+ element.innerHTML =
7
+ '<i class="forced-colors:block\tforced-colors:bg-[Canvas]"></i><b class=""></b><span class=" \t "></span><em></em>';
8
+
9
+ expect(withoutForcedColors(element).innerHTML).toBe('<i></i><b class=""></b><span class=" \t "></span><em></em>');
10
+ });
11
+
12
+ it('clones the whole DOM and removes only forced-colors class tokens', () => {
13
+ const element = document.createElement('section');
14
+ element.setAttribute('class', 'alpha\tforced-colors:bg-[Canvas]\n beta');
15
+ element.setAttribute('data-state', 'checked');
16
+ element.innerHTML =
17
+ 'Before<!--keep--><span class="first forced-colors:text-[HighlightText] hover:forced-colors:bg-[Canvas] last" aria-label="Choice">Text <b class="bold unchanged">inside</b></span>After<svg class="icon forced-colors:fill-[CanvasText]"><path d="M0 0"></path></svg>';
18
+ const original = element.outerHTML;
19
+
20
+ const filtered = withoutForcedColors(element);
21
+
22
+ expect(filtered.outerHTML).toBe(
23
+ '<section class="alpha beta" data-state="checked">Before<!--keep--><span class="first hover:forced-colors:bg-[Canvas] last" aria-label="Choice">Text <b class="bold unchanged">inside</b></span>After<svg class="icon"><path d="M0 0"></path></svg></section>',
24
+ );
25
+ expect(filtered).not.toBe(element);
26
+ expect(filtered.firstElementChild).not.toBe(element.firstElementChild);
27
+ expect(element.outerHTML).toBe(original);
28
+ });
29
+
30
+ it.each(['class', 'aria-label'])('retains a %s regression in a fixture copy', (attribute) => {
31
+ const element = document.createElement('div');
32
+ element.innerHTML = '<button class="ordinary forced-colors:bg-[Highlight]" aria-label="Save">Save</button>';
33
+ const baseline = '<button class="ordinary" aria-label="Save">Save</button>';
34
+ expect(withoutForcedColors(element).innerHTML).toBe(baseline);
35
+
36
+ const changed = element.cloneNode(true) as HTMLElement;
37
+ changed.firstElementChild!.setAttribute(attribute, 'changed');
38
+
39
+ expect(withoutForcedColors(changed).innerHTML).not.toBe(baseline);
40
+ expect(element.innerHTML).toBe(
41
+ '<button class="ordinary forced-colors:bg-[Highlight]" aria-label="Save">Save</button>',
42
+ );
43
+ });
44
+ });
@@ -0,0 +1,14 @@
1
+ /** Compare pinned ordinary-colour DOM without media-scoped forced-colour classes. */
2
+ export function withoutForcedColors(element: HTMLElement): HTMLElement {
3
+ const clone = element.cloneNode(true) as HTMLElement;
4
+ for (const node of [clone, ...clone.querySelectorAll('[class]')]) {
5
+ const classes = node.getAttribute('class');
6
+ if (classes === null) continue;
7
+ const tokens = classes.split(/\s+/).filter(Boolean);
8
+ const ordinary = tokens.filter((token) => !token.startsWith('forced-colors:'));
9
+ if (ordinary.length === tokens.length) continue;
10
+ if (ordinary.length === 0) node.removeAttribute('class');
11
+ else node.setAttribute('class', ordinary.join(' '));
12
+ }
13
+ return clone;
14
+ }