@kabmo-labs/kabmo 0.18.0 → 0.21.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/README.md +43 -13
- package/dist/client/index.html +3 -3
- package/dist/client/index.js +485 -484
- package/dist/client/static/js/index-0721wrkf.css +1 -0
- package/dist/client/static/js/{index-tc09dtca.js → index-zg32n2sk.js} +778 -777
- package/dist/client/static/{manifest-42r8wcmg.webmanifest → manifest-q6h8k9e0.webmanifest} +1 -1
- package/index.html +1 -1
- package/marketplace/plugins/command-runner/package.json +3 -2
- package/marketplace/plugins/git-forge/package.json +3 -2
- package/marketplace/plugins/session-info/package.json +3 -2
- package/marketplace/plugins/stats/package.json +3 -2
- package/package.json +3 -1
- package/public/manifest.webmanifest +1 -1
- package/src/client/components/auth/login-screen/index.tsx +2 -1
- package/src/client/components/common/ComposerPicker.tsx +1 -1
- package/src/client/components/common/FolderPicker.tsx +2 -2
- package/src/client/components/common/Modal.tsx +2 -2
- package/src/client/components/common/PWAInstallButton.tsx +2 -2
- package/src/client/components/common/ViewportSelector.tsx +1 -1
- package/src/client/components/common/anchored-menu/index.tsx +5 -1
- package/src/client/components/common/batch-selection/SelectionCheckbox.tsx +2 -1
- package/src/client/components/common/brand-wordmark/index.test.tsx +13 -2
- package/src/client/components/common/brand-wordmark/index.tsx +13 -2
- package/src/client/components/common/checkbox/style.test.ts +142 -0
- package/src/client/components/common/checkbox/style.ts +51 -0
- package/src/client/components/common/context-usage-button/index.tsx +2 -2
- package/src/client/components/common/file-icon/index.tsx +23 -9
- package/src/client/components/common/header-controls/MoreMenu.tsx +1 -1
- package/src/client/components/common/markdown-review/ReviewPopover.tsx +1 -1
- package/src/client/components/common/panel-mark/index.test.tsx +124 -0
- package/src/client/components/common/panel-mark/index.tsx +105 -0
- package/src/client/components/common/provider-icon/glyphs.test.ts +1 -1
- package/src/client/components/common/provider-icon/index.test.ts +14 -0
- package/src/client/components/common/provider-icon/index.tsx +4 -0
- package/src/client/components/common/provider-icon/resolve.test.ts +8 -7
- package/src/client/components/common/provider-icon/resolve.ts +16 -3
- package/src/client/components/common/session-actions-menu/index.tsx +1 -1
- package/src/client/components/common/toolbar-row/index.tsx +1 -1
- package/src/client/components/layout/ActivityBar.tsx +22 -3
- package/src/client/components/layout/LeftDock.tsx +9 -2
- package/src/client/components/layout/PanelVisibilityMenu.tsx +1 -1
- package/src/client/components/layout/WindowAura.tsx +27 -0
- package/src/client/components/layout/desktop-layout/LeftColumn.tsx +1 -1
- package/src/client/components/layout/desktop-layout/TopNavbar.tsx +2 -2
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +11 -2
- package/src/client/components/layout/desktop-layout/index.tsx +3 -1
- package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +3 -3
- package/src/client/components/layout/session-sidebar/Header.tsx +1 -1
- package/src/client/components/layout/session-sidebar/OverflowMenu.tsx +1 -1
- package/src/client/components/layout/session-sidebar/Toolbar.tsx +1 -1
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +2 -2
- package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +1 -1
- package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +13 -5
- package/src/client/components/layout/session-sidebar/new-workspace-modal/index.tsx +2 -2
- package/src/client/components/layout/session-sidebar/scheduler-modal/TaskForm.tsx +2 -1
- package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +2 -2
- package/src/client/components/mobile/LayoutWrapper.tsx +3 -1
- package/src/client/components/mobile/mobile-main-view/Header.tsx +2 -2
- package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +1 -1
- package/src/client/components/mobile/mobile-session-sidebar/Toolbar.tsx +1 -1
- package/src/client/components/mobile/panel-chips.tsx +10 -2
- package/src/client/components/settings/Modal.tsx +4 -4
- package/src/client/components/settings/ProjectSelectorDropdown.tsx +2 -2
- package/src/client/components/settings/apply-side-effects.test.ts +30 -0
- package/src/client/components/settings/apply-side-effects.ts +14 -0
- package/src/client/components/settings/categories/AppearanceSettings.tsx +6 -0
- package/src/client/components/settings/categories/appearance-settings/EditorBlameSection.tsx +2 -1
- package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +2 -1
- package/src/client/components/settings/categories/appearance-settings/IconStyleSection.tsx +144 -0
- package/src/client/components/settings/categories/appearance-settings/SurfaceStyleSection.test.tsx +120 -0
- package/src/client/components/settings/categories/appearance-settings/SurfaceStyleSection.tsx +180 -0
- package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +2 -1
- package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +2 -2
- package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +1 -1
- package/src/client/components/settings/categories/panel-plugins/AvailableList.tsx +1 -1
- package/src/client/components/settings/categories/panel-plugins/BuiltinList.tsx +21 -3
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.test.tsx +46 -0
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.tsx +1 -1
- package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +7 -9
- package/src/client/components/settings/categories/panel-plugins/PluginCard.test.tsx +149 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +34 -7
- package/src/client/components/settings/categories/panel-plugins/PluginMark.test.ts +66 -2
- package/src/client/components/settings/categories/panel-plugins/PluginMark.tsx +47 -10
- package/src/client/components/settings/categories/panel-plugins/Section.tsx +7 -1
- package/src/client/components/settings/categories/panel-plugins/Toolbar.tsx +35 -2
- package/src/client/components/settings/categories/plugin-settings/DetailPane.tsx +2 -1
- package/src/client/components/settings/categories/plugin-settings/SettingsSection.tsx +2 -1
- package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +1 -1
- package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
- package/src/client/components/settings/categories/provider-settings/DeleteProviderModal.tsx +2 -2
- package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +3 -2
- package/src/client/components/settings/categories/provider-settings/LogoutProviderModal.tsx +2 -2
- package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +3 -2
- package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +2 -1
- package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +1 -1
- package/src/client/components/workspace/btw-panel/TopicMenu.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/NewChatModal.tsx +3 -3
- package/src/client/components/workspace/chat-timeline/UndoConfirmModal.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/chat-input/GoalModal.tsx +4 -3
- package/src/client/components/workspace/chat-timeline/chat-input/ThinkingLevelDropdown.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/plan-review/index.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +2 -6
- package/src/client/components/workspace/context-panel/CostBreakdownPopover.tsx +1 -1
- package/src/client/components/workspace/diff-panel/index.tsx +2 -2
- package/src/client/components/workspace/editor/PluginRail.tsx +1 -1
- package/src/client/components/workspace/editor/SaveDeletedFileModal.tsx +2 -2
- package/src/client/components/workspace/editor/TabContextMenu.tsx +1 -1
- package/src/client/components/workspace/editor/Tabs.tsx +1 -1
- package/src/client/components/workspace/file-explorer/ContextMenu.tsx +1 -1
- package/src/client/components/workspace/file-explorer/Modals.tsx +10 -10
- package/src/client/components/workspace/file-explorer/RootMenu.tsx +1 -1
- package/src/client/components/workspace/git-panel/BranchToolbar.test.tsx +130 -0
- package/src/client/components/workspace/git-panel/BranchToolbar.tsx +21 -11
- package/src/client/components/workspace/git-panel/CommitBox.tsx +2 -1
- package/src/client/components/workspace/git-panel/Modals.tsx +2 -2
- package/src/client/components/workspace/git-panel/StashSection.tsx +2 -1
- package/src/client/components/workspace/git-panel/branch-modal/DeleteDialog.tsx +2 -1
- package/src/client/components/workspace/git-panel/branch-modal/RenameDialog.tsx +2 -1
- package/src/client/components/workspace/git-panel/commit-modal/index.tsx +2 -2
- package/src/client/components/workspace/git-panel/index.tsx +7 -0
- package/src/client/components/workspace/model-dropdown/Panel.tsx +1 -1
- package/src/client/components/workspace/model-dropdown/SpecsTooltip.tsx +1 -1
- package/src/client/components/workspace/plugin-panel/catalog.tsx +7 -0
- package/src/client/components/workspace/plugin-panel/resolve.tsx +4 -0
- package/src/client/components/workspace/search-panel/Body.tsx +1 -1
- package/src/client/components/workspace/usage-panel/ProviderSelect.tsx +1 -1
- package/src/client/glass-sticky.test.ts +46 -0
- package/src/client/glass.css +795 -0
- package/src/client/glass.test.ts +306 -0
- package/src/client/hooks/ui/glass-support.ts +57 -0
- package/src/client/hooks/ui/icon-style.ts +59 -0
- package/src/client/hooks/ui/stuck-header.test.ts +213 -0
- package/src/client/hooks/ui/stuck-header.ts +122 -0
- package/src/client/hooks/ui/style-attributes.test.ts +120 -0
- package/src/client/hooks/ui/surface-style.ts +56 -0
- package/src/client/hooks/workspace/panel-hues.ts +23 -0
- package/src/client/hooks/workspace/panel-registry.ts +8 -4
- package/src/client/main.tsx +10 -0
- package/src/client/tailwind.css +264 -11
- package/src/server/lib/assets/shell-attributes.server.ts +80 -0
- package/src/server/lib/assets/shell-attributes.test.ts +86 -0
- package/src/server/lib/lifecycle/tls.test.ts +6 -1
- package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +1 -0
- package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +2 -30
- package/src/server/lib/omp/rpc/frame-fold.test.ts +55 -0
- package/src/server/lib/omp/rpc/frame-fold.ts +4 -0
- package/src/server/lib/omp/rpc/manager.ts +2 -2
- package/src/server/lib/omp/rpc/process-helpers.ts +11 -0
- package/src/server/lib/omp/rpc/process.test.ts +106 -0
- package/src/server/lib/omp/rpc/process.ts +28 -4
- package/src/server/lib/omp/rpc/run-settle.server.ts +12 -0
- package/src/server/lib/omp/rpc/run-settle.test.ts +22 -0
- package/src/server/lib/omp/rpc/session-command-guards.ts +5 -0
- package/src/server/lib/omp/rpc/session-commands.test.ts +9 -1
- package/src/server/lib/omp/rpc/session-commands.ts +11 -0
- package/src/server/lib/omp/rpc/terminal-settle.ts +29 -7
- package/src/server/lib/panels/bundled-catalog.server.ts +1 -0
- package/src/server/lib/panels/git-update.server.test.ts +20 -0
- package/src/server/lib/panels/git-update.server.ts +20 -4
- package/src/server/lib/panels/manifest.test.ts +20 -0
- package/src/server/lib/panels/manifest.ts +12 -0
- package/src/server/lib/panels/scan.server.ts +4 -0
- package/src/server/lib/panels/sync.server.ts +9 -1
- package/src/server/lib/panels/update.server.test.ts +193 -0
- package/src/server/lib/panels/update.server.ts +210 -0
- package/src/server/lib/plugins/server-half.server.ts +42 -0
- package/src/server/lib/queue/delivery-dispatch.server.test.ts +48 -0
- package/src/server/lib/queue/delivery-harness.ts +8 -4
- package/src/server/lib/queue/delivery.server.test.ts +29 -0
- package/src/server/lib/queue/delivery.server.ts +39 -0
- package/src/server/lib/queue/store.server.test.ts +22 -2
- package/src/server/lib/queue/store.server.ts +33 -11
- package/src/server/lib/terminal/attach-replay.test.ts +26 -8
- package/src/server/plugins/ssr.ts +22 -5
- package/src/server/routes/panels/install-route.test.ts +238 -0
- package/src/server/routes/panels/install.ts +36 -64
- package/src/server/routes/panels/panel-routes.test-util.ts +6 -1
- package/src/server/routes/panels/routes.test.ts +1 -118
- package/src/shared/lib/icons/file-brand-color.ts +38 -0
- package/src/shared/lib/icons/icon-paint-css.test.ts +235 -0
- package/src/shared/lib/icons/icon-paint-css.ts +285 -0
- package/src/shared/lib/icons/icon-paint-panel.ts +109 -0
- package/src/shared/lib/icons/icon-tone.ts +166 -0
- package/src/shared/lib/icons/tint-hues.generated.ts +277 -0
- package/src/shared/lib/icons/tint.test.ts +333 -0
- package/src/shared/lib/icons/tint.ts +248 -0
- package/src/shared/lib/models/provider/brand-color.test.ts +116 -0
- package/src/shared/lib/models/provider/brand-color.ts +103 -0
- package/src/shared/lib/omp/rpc/frame.test.ts +65 -0
- package/src/shared/lib/omp/rpc/frame.ts +58 -3
- package/src/shared/lib/panels/update.test.ts +107 -0
- package/src/shared/lib/panels/update.ts +73 -0
- package/src/shared/lib/settings/defaults.ts +4 -0
- package/src/shared/lib/theme/catalog.test.ts +5 -4
- package/src/shared/lib/theme/catalog.ts +18 -3
- package/src/shared/lib/theme/color.ts +50 -0
- package/src/shared/lib/theme/glass-support.test.ts +38 -0
- package/src/shared/lib/theme/glass-support.ts +73 -0
- package/src/shared/lib/theme/icon-style.test.ts +74 -0
- package/src/shared/lib/theme/icon-style.ts +90 -0
- package/src/shared/lib/theme/legibility.ts +91 -0
- package/src/shared/lib/theme/palettes/dark-extended.ts +152 -0
- package/src/shared/lib/theme/palettes/light-extended.ts +157 -0
- package/src/shared/lib/theme/surface-style.test.ts +68 -0
- package/src/shared/lib/theme/surface-style.ts +91 -0
- package/src/shared/lib/theme/theme.test.ts +11 -7
- package/src/shared/lib/workspace/panel-hues.test.ts +68 -0
- package/src/shared/lib/workspace/panel-hues.ts +57 -0
- package/src/shared/types/panels-registry.ts +6 -0
- package/src/shared/types/panels.ts +14 -0
- package/src/shared/types/settings/state.ts +26 -0
- package/src/test-support/fake-omp-frames.ts +163 -0
- package/dist/client/static/js/index-hp75vsv9.css +0 -1
- /package/src/{client/components/common/file-icon/brand-paths.ts → shared/lib/icons/file-brand-paths.ts} +0 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, expect, test } from 'bun:test';
|
|
7
|
+
import { THEMES } from '@/shared/lib/theme/catalog';
|
|
8
|
+
import { mixHex } from '@/shared/lib/theme/color';
|
|
9
|
+
import { contrastRatio } from '@/shared/lib/theme/legibility';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The composer's `glass` style is a STYLE, not a surface style: it is offered in
|
|
13
|
+
* the classic look too, where `[data-surface="glass"]` is not set. A `--glass-*`
|
|
14
|
+
* token that is only declared inside that attribute block therefore does not
|
|
15
|
+
* exist for the composer, and `background-color: var(--glass-card)` silently
|
|
16
|
+
* computes to `rgba(0,0,0,0)` — a card with no fill at all. That is not
|
|
17
|
+
* hypothetical: it shipped for the length of one edit, and the browser reported
|
|
18
|
+
* it as a transparent composer while `getComputedStyle` on the token returned an
|
|
19
|
+
* empty string.
|
|
20
|
+
*
|
|
21
|
+
* This asserts the shape of the contract rather than one value: every material
|
|
22
|
+
* token the composer rule READS has to be declared where the rule can see it,
|
|
23
|
+
* i.e. in `:root` (or a variant block), never only under the surface attribute.
|
|
24
|
+
*/
|
|
25
|
+
const read = (file: string): Promise<string> => Bun.file(new URL(file, import.meta.url)).text();
|
|
26
|
+
|
|
27
|
+
/** The body of the first rule whose selector starts a line, e.g. `[x] {`. */
|
|
28
|
+
function ruleBody(css: string, selector: string): string {
|
|
29
|
+
const start = css.search(new RegExp(`^${selector.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')} \\{`, 'm'));
|
|
30
|
+
if (start < 0) throw new Error(`no rule for ${selector}`);
|
|
31
|
+
const open = css.indexOf('{', start);
|
|
32
|
+
const close = css.indexOf('\n}', open);
|
|
33
|
+
if (close < 0) throw new Error(`unterminated rule for ${selector}`);
|
|
34
|
+
return css.slice(open + 1, close);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe('glass composer material', () => {
|
|
38
|
+
test('every --glass token the composer reads is declared in :root', async () => {
|
|
39
|
+
const [glass, tailwind] = await Promise.all([read('./glass.css'), read('./tailwind.css')]);
|
|
40
|
+
const composer = ruleBody(tailwind, '[data-composer-style="glass"]');
|
|
41
|
+
const root = ruleBody(glass, ':root');
|
|
42
|
+
|
|
43
|
+
const readTokens = [...new Set([...composer.matchAll(/var\((--glass-[a-z-]+)\)/g)].map((m) => m[1]))];
|
|
44
|
+
// The rule reads its whole material from tokens; a literal here would mean a
|
|
45
|
+
// second recipe for the same material, which is the defect this file guards.
|
|
46
|
+
expect(readTokens.length).toBeGreaterThanOrEqual(6);
|
|
47
|
+
|
|
48
|
+
for (const token of readTokens) {
|
|
49
|
+
expect({ token, declared: new RegExp(`${token}\\s*:`).test(root) }).toEqual({ token, declared: true });
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('the card carries a tint, transmitted light, a reflection and an edge', async () => {
|
|
54
|
+
const [glass, tailwind] = await Promise.all([read('./glass.css'), read('./tailwind.css')]);
|
|
55
|
+
const composer = ruleBody(tailwind, '[data-composer-style="glass"]');
|
|
56
|
+
const root = ruleBody(glass, ':root');
|
|
57
|
+
|
|
58
|
+
// Tint only is what read 1.03:1 against the surface beside it — a card you
|
|
59
|
+
// could not see. The four layers are the material.
|
|
60
|
+
expect(composer).toContain('background-color: var(--glass-card)');
|
|
61
|
+
expect(composer).toContain('background-image: var(--glass-sheen), var(--glass-bloom)');
|
|
62
|
+
expect(composer).toContain('box-shadow: var(--glass-card-edge), var(--glass-shadow)');
|
|
63
|
+
// The CARD's rim, not the window's: the window edge carries `#fff 95%` at
|
|
64
|
+
// 1.5px, which is a hard white line across a 620px card ("silau").
|
|
65
|
+
expect(root).toContain('--glass-card-edge:');
|
|
66
|
+
const cardEdge = root.slice(root.indexOf('--glass-card-edge:'), root.indexOf('--glass-edge:'));
|
|
67
|
+
expect(cardEdge).not.toContain('#fff 95%');
|
|
68
|
+
expect(root).toContain('--glass-bloom:');
|
|
69
|
+
// The bloom is light that came THROUGH the pane: its hue is the palette's,
|
|
70
|
+
// never a hardcoded colour — and it is the DARK variant's, because a palette
|
|
71
|
+
// hue is darker than paper and smudges a light card instead of lighting it.
|
|
72
|
+
const dark = glass.slice(glass.indexOf('[data-theme-variant="dark"]'));
|
|
73
|
+
expect(dark).toContain('--glass-bloom:');
|
|
74
|
+
expect(dark.slice(dark.indexOf('--glass-bloom:'))).toContain('var(--theme-info)');
|
|
75
|
+
expect(root).toContain('--glass-bloom: none;');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('a browser without a blur gets no bloom either', async () => {
|
|
79
|
+
const glass = await read('./glass.css');
|
|
80
|
+
// Two blocks restate the token list because CSS cannot OR a `@supports` with
|
|
81
|
+
// a `@media`; both have to drop the bloom, or the decoration outlives the
|
|
82
|
+
// translucency it exists for.
|
|
83
|
+
const supports = glass.slice(glass.indexOf('@supports not ('), glass.indexOf('@media (prefers-reduced-transparency'));
|
|
84
|
+
const reduced = glass.slice(glass.indexOf('@media (prefers-reduced-transparency'));
|
|
85
|
+
for (const block of [supports, reduced]) {
|
|
86
|
+
for (const token of ['--glass-bloom', '--glass-popover-bloom', '--glass-overlay-filter']) {
|
|
87
|
+
expect({ token, dropped: block.includes(`${token}: none;`) }).toEqual({ token, dropped: true });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The popover tier is the same argument as the composer's, one size down: a
|
|
95
|
+
* dropdown that carries only a tint reads as a LIFTED BOX, because on a dark
|
|
96
|
+
* palette a translucent paper only ever darkens it. Measured on the
|
|
97
|
+
* session-actions menu before the bloom — corner `(56,61,71)` over a body of
|
|
98
|
+
* `(41,44,52)` on a sidebar of `(51,58,67)`, 1.09:1 against what it covers.
|
|
99
|
+
*/
|
|
100
|
+
describe('glass popover material', () => {
|
|
101
|
+
test('the popover adds its own bloom on top of the shared material', async () => {
|
|
102
|
+
const [glass, tailwind] = await Promise.all([read('./glass.css'), read('./tailwind.css')]);
|
|
103
|
+
const root = ruleBody(glass, ':root');
|
|
104
|
+
expect(root).toContain('--glass-popover-bloom:');
|
|
105
|
+
|
|
106
|
+
// The shared block styles BOTH tiers and carries no bloom; the popover's own
|
|
107
|
+
// rule is the one that paints it, and it must name the popover ALONE — a
|
|
108
|
+
// shared rule would put a bloom inside a dialog's paragraph.
|
|
109
|
+
expect(glass).toContain(
|
|
110
|
+
'[data-surface="glass"] .glass-popover {\n background-image: var(--glass-sheen), var(--glass-popover-bloom);',
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const shared = glass.split('[data-surface="glass"] .glass-overlay,')[1] ?? '';
|
|
114
|
+
const sharedBody = shared.slice(0, shared.indexOf('}'));
|
|
115
|
+
expect(sharedBody).not.toContain('--glass-popover-bloom');
|
|
116
|
+
expect(sharedBody).toContain('background-image: linear-gradient(');
|
|
117
|
+
|
|
118
|
+
// A dialog keeps the sheen and the rim it was measured with: a dialog has
|
|
119
|
+
// prose in the middle, and the bloom's whole point is that it stays in the
|
|
120
|
+
// corners — which a dialog cannot afford to guess at.
|
|
121
|
+
expect(tailwind).toContain('[data-composer-style="glass"]');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('an anchored menu is a popover by construction, not by its caller', async () => {
|
|
125
|
+
const menu = await read('./components/common/anchored-menu/index.tsx');
|
|
126
|
+
const list = await read('./components/common/session-actions-menu/index.tsx');
|
|
127
|
+
// The primitive stamps the tier, so a caller that forgets it is the only way
|
|
128
|
+
// an anchored menu stays opaque under the glass surface.
|
|
129
|
+
expect(menu).toContain('glass-popover fixed');
|
|
130
|
+
expect(list).toContain('glass-popover fixed');
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* A workspace column is the same chrome as the sidebar beside it. Every view
|
|
136
|
+
* under it opens with its own `bg-paper` root, which is right in the classic look
|
|
137
|
+
* and wrong under the glass surface — measured, the 293px column composited to
|
|
138
|
+
* the palette's solid paper while the sidebar was the plane's chrome.
|
|
139
|
+
*/
|
|
140
|
+
describe('glass column material', () => {
|
|
141
|
+
test('a workspace column is chrome, and its view roots step aside for it', async () => {
|
|
142
|
+
const [glass, panels] = await Promise.all([
|
|
143
|
+
read('./glass.css'),
|
|
144
|
+
read('./components/layout/desktop-layout/WorkspacePanels.tsx'),
|
|
145
|
+
]);
|
|
146
|
+
// Measured: every right-panel view opens with its own `bg-paper` root, so the
|
|
147
|
+
// 293px column composited to solid paper while the sidebar beside it was the
|
|
148
|
+
// plane's chrome — two materials in one window ("right panel juga belum glass
|
|
149
|
+
// banget"). The marker is on the SLOT (one owner), never on each view.
|
|
150
|
+
expect(panels).toContain('data-panel-chrome=""');
|
|
151
|
+
expect(panels).toContain('glass-chrome w-full h-full');
|
|
152
|
+
expect(glass).toContain('[data-surface="glass"] [data-panel-chrome] > .bg-paper,');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('a PLUGIN panel is reached through its scope span', async () => {
|
|
156
|
+
const [glass, dock] = await Promise.all([
|
|
157
|
+
read('./glass.css'),
|
|
158
|
+
read('./components/layout/LeftDock.tsx'),
|
|
159
|
+
]);
|
|
160
|
+
// A plugin's component renders inside `<span data-plugin-surface style="display: contents">`
|
|
161
|
+
// — the scope the server wraps its stylesheet in — and that span has a BOX
|
|
162
|
+
// even though it paints none, so the child combinator stops there. Measured
|
|
163
|
+
// on the three bundled marketplace plugins, every one painted
|
|
164
|
+
// `rgb(40,44,52)` over the column before this selector existed.
|
|
165
|
+
expect(glass).toContain('[data-surface="glass"] [data-panel-chrome] > [data-plugin-surface] > .bg-paper {');
|
|
166
|
+
// And the LEFT column carries the same marker: a plugin placed on the left
|
|
167
|
+
// draws its own `bg-paper` root too.
|
|
168
|
+
expect(dock).toContain('data-panel-chrome=""');
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* A dialog is the largest surface in the app and the one that showed the least:
|
|
174
|
+
* at 96% tint the veil contributes 4%, so a settings panel measured as a uniform
|
|
175
|
+
* fill with no material at all ("setting modal juga belum glass"). The material
|
|
176
|
+
* is LOCAL light plus a frosted veil, and both have to survive the fallbacks.
|
|
177
|
+
*/
|
|
178
|
+
describe('glass dialog material', () => {
|
|
179
|
+
test('the dialog paints its own light, and the popover does not borrow it', async () => {
|
|
180
|
+
const glass = await read('./glass.css');
|
|
181
|
+
expect(ruleBody(glass, ':root')).toContain('--glass-dialog-bloom:');
|
|
182
|
+
expect(glass).toContain('[data-surface="glass"] .glass-overlay {\n background-image: var(--glass-dialog-bloom);');
|
|
183
|
+
|
|
184
|
+
// The peak sits OUTSIDE the frame: on it, the light lands on the settings nav
|
|
185
|
+
// and drags its 12px labels from 3.8:1 to 3.0:1.
|
|
186
|
+
const dialog = glass.slice(glass.indexOf('--glass-dialog-bloom:'));
|
|
187
|
+
const dark = dialog.slice(dialog.indexOf('[data-theme-variant="dark"]'));
|
|
188
|
+
expect(dark.slice(0, dark.indexOf('}'))).toContain('at -4% -8%');
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('a dialog chrome strip steps aside, and only the direct child does', async () => {
|
|
192
|
+
const glass = await read('./glass.css');
|
|
193
|
+
// Measured on the git commit history modal: its 1198x109 `bg-paper` header
|
|
194
|
+
// painted the palette's SOLID paper across the top of a 1200x792 panel, so the
|
|
195
|
+
// panel's highlight and top-left bloom never rendered and the face read as one
|
|
196
|
+
// flat value. The dialog's BODY keeps every card it draws.
|
|
197
|
+
expect(glass).toContain('[data-surface="glass"] .glass-overlay > .bg-paper {\n background-color: transparent;');
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test('a switch knob is not a canvas well, and the exclusion is in the well rule itself', async () => {
|
|
201
|
+
const glass = await read('./glass.css');
|
|
202
|
+
// The knob is `bg-canvas` on `bg-ink/70`: an OPAQUE contrasting disc is what
|
|
203
|
+
// makes the control read as a toggle. It was first exempted by a SECOND rule,
|
|
204
|
+
// and that rule never applied — `[role="switch"] .bg-canvas` is (0,4,0) and
|
|
205
|
+
// the well selector is (0,5,0), so the well won and every knob on every
|
|
206
|
+
// surface (desktop and phone alike) computed `rgba(0,0,0,0)`. Measured on the
|
|
207
|
+
// plugin switches: a plain pill with no "on" position.
|
|
208
|
+
const well = glass.slice(glass.indexOf('[data-surface="glass"] .app-window .bg-canvas'));
|
|
209
|
+
expect(well.slice(0, well.indexOf('{'))).toContain(':not([role="switch"] *)');
|
|
210
|
+
// A same-property override anywhere later would be the same race again, so
|
|
211
|
+
// there must be no second `background-color` rule for that knob at all.
|
|
212
|
+
expect(glass).not.toContain('[data-surface="glass"] .app-window [role="switch"] .bg-canvas');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test('both fallback blocks outrank the dark palette block', async () => {
|
|
216
|
+
const glass = await read('./glass.css');
|
|
217
|
+
// The dark tokens live in `[data-surface="glass"][data-theme-variant="dark"]`
|
|
218
|
+
// (0,2,0). A plain `[data-surface="glass"]` fallback is (0,1,0) and LOSES on
|
|
219
|
+
// every dark palette — measured, `.glass-chrome` kept alpha 0.38 under the
|
|
220
|
+
// block meant to make it opaque, i.e. a translucent plane with no blur behind
|
|
221
|
+
// it, the exact state these blocks exist to prevent. `:root` adds the
|
|
222
|
+
// pseudo-class that ties, and source order then wins.
|
|
223
|
+
const supports = glass.slice(glass.indexOf('@supports not ('), glass.indexOf('@media (prefers-reduced-transparency'));
|
|
224
|
+
const reduced = glass.slice(glass.indexOf('@media (prefers-reduced-transparency'));
|
|
225
|
+
for (const block of [supports, reduced]) {
|
|
226
|
+
expect(block).toContain(':root[data-surface="glass"] {');
|
|
227
|
+
// Not enough on its own: the token list has to be inside that block.
|
|
228
|
+
expect(block).toContain('--glass-chrome: var(--theme-paper);');
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test('the veil is frosted under the glass surface and only there', async () => {
|
|
233
|
+
const [tailwind, glass] = await Promise.all([read('./tailwind.css'), read('./glass.css')]);
|
|
234
|
+
expect(tailwind).toContain("[data-surface='glass'] .modal-scrim {\n backdrop-filter: blur(20px) saturate(120%);");
|
|
235
|
+
|
|
236
|
+
// Both fallback blocks drop it with the rest of the material.
|
|
237
|
+
const supports = glass.slice(glass.indexOf('@supports not ('), glass.indexOf('@media (prefers-reduced-transparency'));
|
|
238
|
+
const reduced = glass.slice(glass.indexOf('@media (prefers-reduced-transparency'));
|
|
239
|
+
for (const block of [supports, reduced]) {
|
|
240
|
+
expect(block).toContain('--glass-dialog-bloom: none;');
|
|
241
|
+
expect(block).toContain('.modal-scrim {\n backdrop-filter: none;');
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* The material has to hold on EVERY palette in the catalog, not on the eighteen
|
|
248
|
+
* it was tuned against.
|
|
249
|
+
*
|
|
250
|
+
* The material is DERIVED from the palette — `--glass-panel` is
|
|
251
|
+
* `color-mix(paper N%, transparent)` and the chrome is one more mix over it — so
|
|
252
|
+
* a theme does not "support glass" by declaring something; it supports it when
|
|
253
|
+
* its two surfaces and its ink survive the composite. That makes a bad port
|
|
254
|
+
* invisible in the classic look and illegible under the material, which is the
|
|
255
|
+
* failure this sweep exists to catch.
|
|
256
|
+
*
|
|
257
|
+
* The alphas are read out of `glass.css` rather than repeated here, so the test
|
|
258
|
+
* cannot drift from the shipped values, and the composite is the browser's own:
|
|
259
|
+
* plane = paper over canvas, chrome/card = paper over plane. The invariant a new
|
|
260
|
+
* palette breaks without anyone noticing is body text keeping the 4.5:1 floor on
|
|
261
|
+
* the chrome and on a card. Measured across all 63 palettes, the worst is
|
|
262
|
+
* `solarized-light` at 4.89:1 — the same number its opaque paper has, which is
|
|
263
|
+
* what "the tint costs no contrast" means.
|
|
264
|
+
*/
|
|
265
|
+
describe('glass material on every catalog palette', () => {
|
|
266
|
+
/** A percentage out of a token, whether bare (`50%`) or inside a `color-mix`. */
|
|
267
|
+
const percentOf = (body: string, token: string): number => {
|
|
268
|
+
const match = new RegExp(`--glass-${token}:\\s*(?:color-mix\\(in srgb, var\\(--theme-paper\\)\\s*)?(\\d+(?:\\.\\d+)?)%`).exec(body);
|
|
269
|
+
if (!match) throw new Error(`--glass-${token} is not a percentage in this block`);
|
|
270
|
+
return Number(match[1]) / 100;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
test('body text keeps the 4.5:1 floor on the plane, the chrome and a card', async () => {
|
|
274
|
+
const glass = await read('./glass.css');
|
|
275
|
+
const surface = ruleBody(glass, '[data-surface="glass"]');
|
|
276
|
+
const surfaceDark = ruleBody(glass, '[data-surface="glass"][data-theme-variant="dark"]');
|
|
277
|
+
const root = ruleBody(glass, ':root');
|
|
278
|
+
const variantDark = ruleBody(glass, '[data-theme-variant="dark"]');
|
|
279
|
+
|
|
280
|
+
// The card's fill is surface-INDEPENDENT (the composer's `glass` style is
|
|
281
|
+
// offered in the classic look too), so it lives on `:root` and the variant
|
|
282
|
+
// block, not under the surface attribute.
|
|
283
|
+
const alphas = {
|
|
284
|
+
light: { tint: percentOf(surface, 'tint'), chrome: percentOf(surface, 'chrome'), card: percentOf(root, 'card') },
|
|
285
|
+
dark: { tint: percentOf(surfaceDark, 'tint'), chrome: percentOf(surfaceDark, 'chrome'), card: percentOf(variantDark, 'card') },
|
|
286
|
+
};
|
|
287
|
+
expect(alphas.light.tint).toBeGreaterThan(alphas.dark.tint - 1);
|
|
288
|
+
expect(alphas.light.chrome).toBeLessThan(alphas.dark.chrome + 0.5);
|
|
289
|
+
|
|
290
|
+
const failures: string[] = [];
|
|
291
|
+
for (const theme of THEMES) {
|
|
292
|
+
const alpha = alphas[theme.variant];
|
|
293
|
+
const plane = mixHex(theme.canvas, theme.paper, alpha.tint);
|
|
294
|
+
const tiers = {
|
|
295
|
+
plane,
|
|
296
|
+
chrome: mixHex(plane, theme.paper, alpha.chrome),
|
|
297
|
+
card: mixHex(plane, theme.paper, alpha.card),
|
|
298
|
+
};
|
|
299
|
+
for (const [tier, fill] of Object.entries(tiers)) {
|
|
300
|
+
const ratio = contrastRatio(theme.ink, fill);
|
|
301
|
+
if (ratio < 4.5) failures.push(`${theme.id} ${tier} ${ratio.toFixed(2)}:1`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
expect(failures).toEqual([]);
|
|
305
|
+
});
|
|
306
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The live answers to "can this engine draw the glass material", subscribed.
|
|
8
|
+
*
|
|
9
|
+
* `glassLimits` states the rule; this hook is the only place that ASKS the
|
|
10
|
+
* platform, so the settings control never touches `window` itself.
|
|
11
|
+
*
|
|
12
|
+
* Three facts about the asking:
|
|
13
|
+
*
|
|
14
|
+
* - **Both spellings are tested.** Chromium shipped `backdrop-filter`
|
|
15
|
+
* unprefixed only in 76, and the Android shell's floor is `minSdk 24`; the
|
|
16
|
+
* stylesheets always write the `-webkit-` pair, so the probe tests the pair
|
|
17
|
+
* too. Testing one and not the other reports "unsupported" on a device that
|
|
18
|
+
* renders the frost correctly.
|
|
19
|
+
* - **Computed ONCE.** `CSS.supports` is a parse check on a constant string; it
|
|
20
|
+
* cannot change while the document lives, and calling it per render would be a
|
|
21
|
+
* style recalc for a constant.
|
|
22
|
+
* - **`matchMedia` is SUBSCRIBED.** The OS setting can be toggled while the
|
|
23
|
+
* window is open (System Settings → Accessibility, next to the app), and the
|
|
24
|
+
* media query then flips without a reload — a stale `false` would leave the
|
|
25
|
+
* notice hidden on a window that had just gone opaque.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { useEffect, useState } from 'preact/hooks';
|
|
29
|
+
import { glassLimits, type GlassLimit } from '@/shared/lib/theme/glass-support';
|
|
30
|
+
|
|
31
|
+
const REDUCED_TRANSPARENCY = '(prefers-reduced-transparency: reduce)';
|
|
32
|
+
|
|
33
|
+
function supportsBackdropFilter(): boolean {
|
|
34
|
+
if (typeof CSS === 'undefined' || typeof CSS.supports !== 'function') return false;
|
|
35
|
+
return (
|
|
36
|
+
CSS.supports('backdrop-filter', 'blur(1px)') ||
|
|
37
|
+
CSS.supports('-webkit-backdrop-filter', 'blur(1px)')
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function useGlassLimits(): GlassLimit[] {
|
|
42
|
+
const [reduced, setReduced] = useState(() =>
|
|
43
|
+
typeof window === 'undefined' ? false : window.matchMedia(REDUCED_TRANSPARENCY).matches,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
const media = window.matchMedia(REDUCED_TRANSPARENCY);
|
|
48
|
+
const update = () => setReduced(media.matches);
|
|
49
|
+
// The query can change between the initial render and this effect, so read it
|
|
50
|
+
// once on the way in — the same reason `useViewportAtLeast` does.
|
|
51
|
+
update();
|
|
52
|
+
media.addEventListener('change', update);
|
|
53
|
+
return () => media.removeEventListener('change', update);
|
|
54
|
+
}, []);
|
|
55
|
+
|
|
56
|
+
return glassLimits({ backdropFilter: supportsBackdropFilter(), reducedTransparency: reduced });
|
|
57
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The single writer for the brand-mark paint style.
|
|
8
|
+
*
|
|
9
|
+
* Same contract as `surface-style.ts`: an attribute on `<html>`, read by CSS
|
|
10
|
+
* only, because `ProviderIconPlate` is drawn in 26 places across five surfaces
|
|
11
|
+
* and a prop would be 26 chances to miss one. The rules live in
|
|
12
|
+
* `src/client/tailwind.css` (`[data-icon-style]`) and read the brand table in
|
|
13
|
+
* `provider-icon/brand-colors.ts` — never a colour written at a call site.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { readKabmoSetting } from '@/shared/lib/settings/client';
|
|
17
|
+
import {
|
|
18
|
+
DEFAULT_ICON_STYLE,
|
|
19
|
+
ICON_STYLE_ATTRIBUTE,
|
|
20
|
+
ICON_STYLE_SETTING_KEY,
|
|
21
|
+
resolveIconStyle,
|
|
22
|
+
} from '@/shared/lib/theme/icon-style';
|
|
23
|
+
import {
|
|
24
|
+
ICON_PAINT_STYLE_ELEMENT_ID,
|
|
25
|
+
iconPaintStyleSheet,
|
|
26
|
+
} from '@/shared/lib/icons/icon-paint-css';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Point the document at `style`.
|
|
30
|
+
*
|
|
31
|
+
* The default is REMOVED rather than written, so the ink rule in CSS is the
|
|
32
|
+
* single statement of what "no attribute" means.
|
|
33
|
+
*/
|
|
34
|
+
export function applyIconStyle(style: unknown): void {
|
|
35
|
+
if (typeof document === 'undefined') return;
|
|
36
|
+
const root = document.documentElement;
|
|
37
|
+
const resolved = resolveIconStyle(style);
|
|
38
|
+
if (resolved === DEFAULT_ICON_STYLE) root.removeAttribute(ICON_STYLE_ATTRIBUTE);
|
|
39
|
+
else root.setAttribute(ICON_STYLE_ATTRIBUTE, resolved);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Apply the stored style before the first render, and make sure the generated
|
|
44
|
+
* icon-paint stylesheet is in the document.
|
|
45
|
+
*
|
|
46
|
+
* The stylesheet is written by the server shell (it is generated from a TS
|
|
47
|
+
* table, so the bundler cannot carry it — the same split `themeStyleSheet` uses).
|
|
48
|
+
* This only repairs a document served by a build that predates it; without the
|
|
49
|
+
* repair, `color` mode would set the attribute and paint nothing.
|
|
50
|
+
*/
|
|
51
|
+
export function initIconStyle(): void {
|
|
52
|
+
if (typeof document !== 'undefined' && !document.getElementById(ICON_PAINT_STYLE_ELEMENT_ID)) {
|
|
53
|
+
const style = document.createElement('style');
|
|
54
|
+
style.id = ICON_PAINT_STYLE_ELEMENT_ID;
|
|
55
|
+
style.textContent = iconPaintStyleSheet();
|
|
56
|
+
document.head.appendChild(style);
|
|
57
|
+
}
|
|
58
|
+
applyIconStyle(readKabmoSetting<unknown>(ICON_STYLE_SETTING_KEY));
|
|
59
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `useStuckHeader`: a sticky element's PINNED state.
|
|
8
|
+
*
|
|
9
|
+
* The rule this pins is the one the sidebar depends on: a sticky header paints a
|
|
10
|
+
* surface only while it is overlapping content. Measured with happy-dom's scroll
|
|
11
|
+
* geometry, because the alternative — trusting the CSS — is what shipped a band
|
|
12
|
+
* across a uniform sidebar twice.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { afterAll, afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
16
|
+
import { Window } from 'happy-dom';
|
|
17
|
+
import { h, render } from 'preact';
|
|
18
|
+
import { act } from 'preact/test-utils';
|
|
19
|
+
import { useRef } from 'preact/hooks';
|
|
20
|
+
import { useStuckHeader } from '@/client/hooks/ui/stuck-header';
|
|
21
|
+
|
|
22
|
+
// `requestAnimationFrame` is in the list because the HOOK schedules through it
|
|
23
|
+
// and happy-dom keeps it on its window, not on the runner's global.
|
|
24
|
+
const DOM_GLOBALS = [
|
|
25
|
+
'window',
|
|
26
|
+
'document',
|
|
27
|
+
'navigator',
|
|
28
|
+
'Node',
|
|
29
|
+
'Element',
|
|
30
|
+
'HTMLElement',
|
|
31
|
+
'Event',
|
|
32
|
+
'requestAnimationFrame',
|
|
33
|
+
'cancelAnimationFrame',
|
|
34
|
+
// `preact/test-utils`' `act` reads this one to flush effects.
|
|
35
|
+
'getComputedStyle',
|
|
36
|
+
] as const;
|
|
37
|
+
const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
38
|
+
|
|
39
|
+
let container: HTMLElement;
|
|
40
|
+
let scroller: HTMLElement;
|
|
41
|
+
/** The header's current top, in container coordinates. Mutated per assertion. */
|
|
42
|
+
let headerTop = 0;
|
|
43
|
+
/** The container's scroll offset. Zero is "at rest" — nothing overlapping. */
|
|
44
|
+
let scrollTop = 0;
|
|
45
|
+
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
const win = new Window({ url: 'http://localhost' });
|
|
48
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
49
|
+
for (const key of DOM_GLOBALS) {
|
|
50
|
+
if (!(key in nativeGlobals)) nativeGlobals[key] = win[key as keyof Window];
|
|
51
|
+
target[key] = win[key as keyof Window];
|
|
52
|
+
}
|
|
53
|
+
// A SYNCHRONOUS frame: the hook coalesces scroll events through
|
|
54
|
+
// `requestAnimationFrame`, and a real one is a timer this suite would have to
|
|
55
|
+
// wait on. Running the callback inline measures the same logic with no clock.
|
|
56
|
+
target.requestAnimationFrame = ((callback: FrameRequestCallback) => {
|
|
57
|
+
callback(0);
|
|
58
|
+
return 1;
|
|
59
|
+
}) as typeof requestAnimationFrame;
|
|
60
|
+
target.cancelAnimationFrame = (() => {}) as typeof cancelAnimationFrame;
|
|
61
|
+
|
|
62
|
+
container = document.createElement('div');
|
|
63
|
+
document.body.appendChild(container);
|
|
64
|
+
headerTop = 0;
|
|
65
|
+
scrollTop = 0;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
afterEach(() => {
|
|
69
|
+
render(null, container);
|
|
70
|
+
container.remove();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
afterAll(() => {
|
|
74
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
75
|
+
for (const key of DOM_GLOBALS) {
|
|
76
|
+
if (key in nativeGlobals) target[key] = nativeGlobals[key];
|
|
77
|
+
else delete target[key];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* A scroll container with a sticky header inside it.
|
|
83
|
+
*
|
|
84
|
+
* happy-dom has no layout engine, so the geometry is supplied: the container's
|
|
85
|
+
* `getBoundingClientRect().top` and the header's are both overridden, which is
|
|
86
|
+
* exactly what `useStuckHeader` reads. The header's rect is a LIVE getter over
|
|
87
|
+
* `headerTop`, so a test scrolls by changing one number.
|
|
88
|
+
*/
|
|
89
|
+
function mountHarness(options: { collapsed?: boolean } = {}): HTMLElement {
|
|
90
|
+
function Probe() {
|
|
91
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
92
|
+
const stuck = useStuckHeader(ref);
|
|
93
|
+
return h('div', { ref, 'data-stuck': stuck ? '' : undefined, 'data-testid': 'header' });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
scroller = document.createElement('div');
|
|
97
|
+
scroller.style.overflowY = 'auto';
|
|
98
|
+
// `collapsed` is the phone drawer's mount: the list is inside a hidden screen,
|
|
99
|
+
// so it measures 0x0 and the "does it overflow" test answers false.
|
|
100
|
+
setScrollerSizes(options.collapsed ? 0 : 1000, options.collapsed ? 0 : 300);
|
|
101
|
+
Object.defineProperty(scroller, 'scrollTop', {
|
|
102
|
+
get: () => scrollTop,
|
|
103
|
+
set: (value: number) => {
|
|
104
|
+
scrollTop = value;
|
|
105
|
+
},
|
|
106
|
+
configurable: true,
|
|
107
|
+
});
|
|
108
|
+
scroller.getBoundingClientRect = () => ({ top: 0 }) as DOMRect;
|
|
109
|
+
container.appendChild(scroller);
|
|
110
|
+
|
|
111
|
+
// `act` so the effect runs (and attaches its listener) before the geometry is
|
|
112
|
+
// supplied; without it the mount measurement reads happy-dom's zero rect and
|
|
113
|
+
// no later scroll would be heard.
|
|
114
|
+
act(() => {
|
|
115
|
+
render(h(Probe, null), scroller);
|
|
116
|
+
});
|
|
117
|
+
const header = scroller.querySelector('[data-testid="header"]') as HTMLElement;
|
|
118
|
+
header.getBoundingClientRect = () => ({ top: headerTop, bottom: headerTop + 26 }) as DOMRect;
|
|
119
|
+
return header;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** The container's scroll extent, which is what the hook may NOT use to find it. */
|
|
123
|
+
function setScrollerSizes(scrollHeight: number, clientHeight: number) {
|
|
124
|
+
Object.defineProperty(scroller, 'scrollHeight', { value: scrollHeight, configurable: true });
|
|
125
|
+
Object.defineProperty(scroller, 'clientHeight', { value: clientHeight, configurable: true });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Scroll the harness and wait for the hook's OWN measurement.
|
|
130
|
+
*
|
|
131
|
+
* The hook coalesces scroll events into a `requestAnimationFrame`, so the signal
|
|
132
|
+
* to await is that frame — awaited directly rather than guessed at with a sleep,
|
|
133
|
+
* which would pay real latency per run and still flake under load.
|
|
134
|
+
*/
|
|
135
|
+
/** Move the list: `top` is where the header now sits, `offset` how far it scrolled. */
|
|
136
|
+
function scrollTo(top: number, offset: number) {
|
|
137
|
+
headerTop = top;
|
|
138
|
+
scrollTop = offset;
|
|
139
|
+
act(() => {
|
|
140
|
+
scroller.dispatchEvent(new Event('scroll'));
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
describe('useStuckHeader', () => {
|
|
145
|
+
test('a header below the container top is at rest', () => {
|
|
146
|
+
const header = mountHarness();
|
|
147
|
+
scrollTo(120, 0);
|
|
148
|
+
|
|
149
|
+
expect(header.hasAttribute('data-stuck')).toBe(false);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('a header at the container top is NOT stuck before the list scrolls', () => {
|
|
153
|
+
// The regression this guards: the geometric test alone is true at
|
|
154
|
+
// `scrollTop: 0` for a header that starts at the top edge, so the surface
|
|
155
|
+
// appeared before anything overlapped it.
|
|
156
|
+
const header = mountHarness();
|
|
157
|
+
headerTop = 0;
|
|
158
|
+
scrollTop = 0;
|
|
159
|
+
act(() => {
|
|
160
|
+
scroller.dispatchEvent(new Event('scroll'));
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
expect(header.hasAttribute('data-stuck')).toBe(false);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('a header level with the container top is stuck', () => {
|
|
167
|
+
const header = mountHarness();
|
|
168
|
+
scrollTo(0, 120);
|
|
169
|
+
|
|
170
|
+
expect(header.hasAttribute('data-stuck')).toBe(true);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('a header whose section scrolled past is not painted', () => {
|
|
174
|
+
// It sits entirely above the container: sticky keeps it out of sight, so a
|
|
175
|
+
// fill there is work for a surface nobody can see.
|
|
176
|
+
const header = mountHarness();
|
|
177
|
+
scrollTo(-60, 400);
|
|
178
|
+
|
|
179
|
+
expect(header.hasAttribute('data-stuck')).toBe(false);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('scrolling re-measures, in both directions', () => {
|
|
183
|
+
const header = mountHarness();
|
|
184
|
+
scrollTo(120, 0);
|
|
185
|
+
expect(header.hasAttribute('data-stuck')).toBe(false);
|
|
186
|
+
|
|
187
|
+
// The user scrolls the list: the sticky header is now pinned.
|
|
188
|
+
scrollTo(0, 120);
|
|
189
|
+
expect(header.hasAttribute('data-stuck')).toBe(true);
|
|
190
|
+
|
|
191
|
+
// …and scrolls back to the top: it is the first line of the list again.
|
|
192
|
+
scrollTo(40, 0);
|
|
193
|
+
expect(header.hasAttribute('data-stuck')).toBe(false);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test('a container mounted at 0x0 is still the scrollport (the phone drawer)', () => {
|
|
197
|
+
// Measured in the real drawer at 412x900: the list is mounted inside a
|
|
198
|
+
// `hidden` screen, so `scrollHeight`/`clientHeight` both read 0 at mount. The
|
|
199
|
+
// old container test required an overflow, gave up, and fell back to
|
|
200
|
+
// `window.scrollY` — which never moves for an inner scroller — so the folder
|
|
201
|
+
// header sat PINNED at the container's top edge with no `data-stuck`: an
|
|
202
|
+
// active sticky header painting nothing.
|
|
203
|
+
const header = mountHarness({ collapsed: true });
|
|
204
|
+
scrollTo(120, 0);
|
|
205
|
+
expect(header.hasAttribute('data-stuck')).toBe(false);
|
|
206
|
+
|
|
207
|
+
// The drawer opens (the box gets real) and the user scrolls: the fill must
|
|
208
|
+
// appear, which only happens if the CONTAINER was listened to.
|
|
209
|
+
setScrollerSizes(1000, 300);
|
|
210
|
+
scrollTo(0, 120);
|
|
211
|
+
expect(header.hasAttribute('data-stuck')).toBe(true);
|
|
212
|
+
});
|
|
213
|
+
});
|