baseline-foundry 0.1.3
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/LICENSE +21 -0
- package/README.md +588 -0
- package/config/experiments/ibm-plex-engine-smoke.json +115 -0
- package/config/experiments/ubuntu-engine-smoke.json +115 -0
- package/config/foundation-theme.json +117 -0
- package/config/tiers/app.json +120 -0
- package/config/tiers/documentation.json +120 -0
- package/config/tiers/editorial.json +120 -0
- package/config/tiers/os.json +120 -0
- package/dist/accordion.d.ts +5 -0
- package/dist/accordion.js +32 -0
- package/dist/application-layout.d.ts +4 -0
- package/dist/application-layout.js +181 -0
- package/dist/baseline-grid-overlay.d.ts +5 -0
- package/dist/baseline-grid-overlay.js +50 -0
- package/dist/baseline-grid-theme.d.ts +3 -0
- package/dist/baseline-grid-theme.js +3 -0
- package/dist/baseline-grid.d.ts +7 -0
- package/dist/baseline-grid.js +35 -0
- package/dist/build.d.ts +21 -0
- package/dist/build.js +440 -0
- package/dist/code-snippet.d.ts +6 -0
- package/dist/code-snippet.js +95 -0
- package/dist/contextual-menu.d.ts +4 -0
- package/dist/contextual-menu.js +156 -0
- package/dist/css-app-tier.d.ts +1 -0
- package/dist/css-app-tier.js +77 -0
- package/dist/css-components/article-pagination.d.ts +13 -0
- package/dist/css-components/article-pagination.js +151 -0
- package/dist/css-components/button-actions.d.ts +7 -0
- package/dist/css-components/button-actions.js +165 -0
- package/dist/css-components/cards-options.d.ts +6 -0
- package/dist/css-components/cards-options.js +180 -0
- package/dist/css-components/chip-badge-status.d.ts +10 -0
- package/dist/css-components/chip-badge-status.js +162 -0
- package/dist/css-components/content-card.d.ts +25 -0
- package/dist/css-components/content-card.js +517 -0
- package/dist/css-components/control-row.d.ts +2 -0
- package/dist/css-components/control-row.js +18 -0
- package/dist/css-components/cta-figure-aspect.d.ts +1 -0
- package/dist/css-components/cta-figure-aspect.js +123 -0
- package/dist/css-components/document-navigation.d.ts +13 -0
- package/dist/css-components/document-navigation.js +400 -0
- package/dist/css-components/editorial-content.d.ts +6 -0
- package/dist/css-components/editorial-content.js +52 -0
- package/dist/css-components/icon.d.ts +1 -0
- package/dist/css-components/icon.js +75 -0
- package/dist/css-components/interactive-feedback.d.ts +2 -0
- package/dist/css-components/interactive-feedback.js +230 -0
- package/dist/css-components/interactive-tables.d.ts +7 -0
- package/dist/css-components/interactive-tables.js +164 -0
- package/dist/css-components/linked-logo-site-layout.d.ts +21 -0
- package/dist/css-components/linked-logo-site-layout.js +214 -0
- package/dist/css-components/list-tree.d.ts +5 -0
- package/dist/css-components/list-tree.js +98 -0
- package/dist/css-components/list.d.ts +3 -0
- package/dist/css-components/list.js +119 -0
- package/dist/css-components/logo-media.d.ts +16 -0
- package/dist/css-components/logo-media.js +219 -0
- package/dist/css-components/navigation-layout.d.ts +5 -0
- package/dist/css-components/navigation-layout.js +151 -0
- package/dist/css-components/panel.d.ts +6 -0
- package/dist/css-components/panel.js +148 -0
- package/dist/css-components/search-box-and-filter.d.ts +9 -0
- package/dist/css-components/search-box-and-filter.js +267 -0
- package/dist/css-components/sites-editorial-ports.d.ts +19 -0
- package/dist/css-components/sites-editorial-ports.js +264 -0
- package/dist/css-components/sites-foundation.d.ts +17 -0
- package/dist/css-components/sites-foundation.js +173 -0
- package/dist/css-components/sites-rich-lists.d.ts +18 -0
- package/dist/css-components/sites-rich-lists.js +364 -0
- package/dist/css-components/static-content-ports.d.ts +14 -0
- package/dist/css-components/static-content-ports.js +206 -0
- package/dist/css-components/tab-section.d.ts +19 -0
- package/dist/css-components/tab-section.js +103 -0
- package/dist/css-components/table.d.ts +7 -0
- package/dist/css-components/table.js +79 -0
- package/dist/css-components/tabs-choice-breadcrumbs.d.ts +9 -0
- package/dist/css-components/tabs-choice-breadcrumbs.js +307 -0
- package/dist/css-components/tiered-list-equal-height-row.d.ts +1 -0
- package/dist/css-components/tiered-list-equal-height-row.js +286 -0
- package/dist/css-components.d.ts +2 -0
- package/dist/css-components.js +2701 -0
- package/dist/css-grid.d.ts +1 -0
- package/dist/css-grid.js +179 -0
- package/dist/css.d.ts +6 -0
- package/dist/css.js +431 -0
- package/dist/experiments/ibm-plex-engine-smoke/styles.css +8969 -0
- package/dist/experiments/ibm-plex-engine-smoke/surfaces.json +604 -0
- package/dist/experiments/ibm-plex-engine-smoke/tokens.json +217 -0
- package/dist/in-page-navigation.d.ts +7 -0
- package/dist/in-page-navigation.js +136 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +18 -0
- package/dist/interactive-feedback.d.ts +14 -0
- package/dist/interactive-feedback.js +96 -0
- package/dist/interactive-tables.d.ts +28 -0
- package/dist/interactive-tables.js +184 -0
- package/dist/list-tree.d.ts +4 -0
- package/dist/list-tree.js +44 -0
- package/dist/panel-drawer.d.ts +4 -0
- package/dist/panel-drawer.js +171 -0
- package/dist/presets/app-tier/styles.css +9459 -0
- package/dist/presets/app-tier/surfaces.json +1225 -0
- package/dist/presets/app-tier/tokens.json +221 -0
- package/dist/presets/prose/styles.css +9442 -0
- package/dist/presets/prose/surfaces.json +1225 -0
- package/dist/presets/prose/tokens.json +221 -0
- package/dist/presets.d.ts +6 -0
- package/dist/presets.js +27 -0
- package/dist/range-controls.d.ts +9 -0
- package/dist/range-controls.js +73 -0
- package/dist/resizable-aside.d.ts +4 -0
- package/dist/resizable-aside.js +328 -0
- package/dist/side-navigation.d.ts +4 -0
- package/dist/side-navigation.js +219 -0
- package/dist/styles.css +9442 -0
- package/dist/surfaces.json +1225 -0
- package/dist/tabs.d.ts +4 -0
- package/dist/tabs.js +88 -0
- package/dist/tier-registry.d.ts +10 -0
- package/dist/tier-registry.js +25 -0
- package/dist/tiers/app/styles.css +9459 -0
- package/dist/tiers/app/surfaces.json +1225 -0
- package/dist/tiers/app/tokens.json +221 -0
- package/dist/tiers/documentation/styles.css +9442 -0
- package/dist/tiers/documentation/surfaces.json +1225 -0
- package/dist/tiers/documentation/tokens.json +221 -0
- package/dist/tiers/editorial/styles.css +9442 -0
- package/dist/tiers/editorial/surfaces.json +1225 -0
- package/dist/tiers/editorial/tokens.json +221 -0
- package/dist/tiers/os/styles.css +9442 -0
- package/dist/tiers/os/surfaces.json +1225 -0
- package/dist/tiers/os/tokens.json +221 -0
- package/dist/tokens.json +221 -0
- package/dist/tooltip.d.ts +4 -0
- package/dist/tooltip.js +70 -0
- package/dist/top-navigation.d.ts +4 -0
- package/dist/top-navigation.js +354 -0
- package/dist/types.d.ts +155 -0
- package/dist/types.js +1 -0
- package/dist/vanilla-theme-colors.d.ts +5 -0
- package/dist/vanilla-theme-colors.js +208 -0
- package/docs/publishing.md +66 -0
- package/package.json +108 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
const ROOT_SELECTOR = ".bf-top-navigation";
|
|
2
|
+
const NAV_SELECTOR = ".bf-top-navigation-nav";
|
|
3
|
+
const SEARCH_SELECTOR = ".bf-top-navigation-search";
|
|
4
|
+
const SEARCH_INPUT_SELECTOR = ".bf-top-navigation-search .bf-search-box-input";
|
|
5
|
+
const DROPDOWN_ITEM_SELECTOR = ".bf-top-navigation-item.is-dropdown-toggle";
|
|
6
|
+
const DROPDOWN_TOGGLE_SELECTOR = ".bf-top-navigation-dropdown-toggle";
|
|
7
|
+
const DROPDOWN_SELECTOR = ".bf-top-navigation-dropdown";
|
|
8
|
+
const MENU_TOGGLE_SELECTOR = ".bf-top-navigation-menu-toggle";
|
|
9
|
+
const SEARCH_TOGGLE_SELECTOR = ".bf-top-navigation-search-toggle";
|
|
10
|
+
const OVERLAY_SELECTOR = ".bf-top-navigation-search-overlay";
|
|
11
|
+
const DROPDOWN_ACTION_SELECTOR = ".bf-top-navigation-dropdown-item";
|
|
12
|
+
const DROPDOWN_ACTIVE_CLASS = "is-active";
|
|
13
|
+
const LARGE_BREAKPOINT = "(min-width: 64.75rem)";
|
|
14
|
+
let generatedIdCounter = 0;
|
|
15
|
+
const lastMenuTriggerByRoot = new WeakMap();
|
|
16
|
+
const lastSearchTriggerByRoot = new WeakMap();
|
|
17
|
+
const lastDropdownTriggerByRoot = new WeakMap();
|
|
18
|
+
const menuOpenRoots = new WeakSet();
|
|
19
|
+
const searchOpenRoots = new WeakSet();
|
|
20
|
+
function queryAllWithinRoot(root, selector) {
|
|
21
|
+
const elements = Array.from(root.querySelectorAll(selector));
|
|
22
|
+
if (root instanceof Element && root.matches(selector)) {
|
|
23
|
+
elements.unshift(root);
|
|
24
|
+
}
|
|
25
|
+
return elements;
|
|
26
|
+
}
|
|
27
|
+
function getRootWindow(root) {
|
|
28
|
+
if (root instanceof Document) {
|
|
29
|
+
return root.defaultView;
|
|
30
|
+
}
|
|
31
|
+
return root.ownerDocument?.defaultView ?? null;
|
|
32
|
+
}
|
|
33
|
+
function getRoots(root) {
|
|
34
|
+
return queryAllWithinRoot(root, ROOT_SELECTOR);
|
|
35
|
+
}
|
|
36
|
+
function getNav(topNavigation) {
|
|
37
|
+
return topNavigation.querySelector(NAV_SELECTOR);
|
|
38
|
+
}
|
|
39
|
+
function getSearch(topNavigation) {
|
|
40
|
+
return topNavigation.querySelector(SEARCH_SELECTOR);
|
|
41
|
+
}
|
|
42
|
+
function getSearchInput(topNavigation) {
|
|
43
|
+
return topNavigation.querySelector(SEARCH_INPUT_SELECTOR);
|
|
44
|
+
}
|
|
45
|
+
function getDropdownItems(topNavigation) {
|
|
46
|
+
return Array.from(topNavigation.querySelectorAll(DROPDOWN_ITEM_SELECTOR));
|
|
47
|
+
}
|
|
48
|
+
function getDropdownToggles(topNavigation) {
|
|
49
|
+
return Array.from(topNavigation.querySelectorAll(DROPDOWN_TOGGLE_SELECTOR));
|
|
50
|
+
}
|
|
51
|
+
function getDropdownItemForToggle(toggle) {
|
|
52
|
+
return toggle.closest(DROPDOWN_ITEM_SELECTOR);
|
|
53
|
+
}
|
|
54
|
+
function getDropdownForToggle(toggle) {
|
|
55
|
+
const controlledId = toggle.getAttribute("aria-controls");
|
|
56
|
+
if (controlledId) {
|
|
57
|
+
const controlledElement = toggle.ownerDocument.getElementById(controlledId);
|
|
58
|
+
if (controlledElement instanceof HTMLElement && controlledElement.matches(DROPDOWN_SELECTOR)) {
|
|
59
|
+
return controlledElement;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const dropdownItem = getDropdownItemForToggle(toggle);
|
|
63
|
+
return dropdownItem?.querySelector(DROPDOWN_SELECTOR) ?? null;
|
|
64
|
+
}
|
|
65
|
+
function getOverlay(topNavigation) {
|
|
66
|
+
return topNavigation.querySelector(OVERLAY_SELECTOR);
|
|
67
|
+
}
|
|
68
|
+
function getMenuToggles(topNavigation) {
|
|
69
|
+
return Array.from(topNavigation.querySelectorAll(MENU_TOGGLE_SELECTOR));
|
|
70
|
+
}
|
|
71
|
+
function getSearchToggles(topNavigation) {
|
|
72
|
+
return Array.from(topNavigation.querySelectorAll(SEARCH_TOGGLE_SELECTOR));
|
|
73
|
+
}
|
|
74
|
+
function isLargeViewport(target) {
|
|
75
|
+
return target.ownerDocument.defaultView?.matchMedia(LARGE_BREAKPOINT).matches ?? false;
|
|
76
|
+
}
|
|
77
|
+
function isMenuOpen(topNavigation) {
|
|
78
|
+
return menuOpenRoots.has(topNavigation);
|
|
79
|
+
}
|
|
80
|
+
function isSearchOpen(topNavigation) {
|
|
81
|
+
return searchOpenRoots.has(topNavigation);
|
|
82
|
+
}
|
|
83
|
+
function setMenuOpen(topNavigation, isOpen) {
|
|
84
|
+
if (isOpen) {
|
|
85
|
+
menuOpenRoots.add(topNavigation);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
menuOpenRoots.delete(topNavigation);
|
|
89
|
+
}
|
|
90
|
+
function setSearchOpen(topNavigation, isOpen) {
|
|
91
|
+
if (isOpen) {
|
|
92
|
+
searchOpenRoots.add(topNavigation);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
searchOpenRoots.delete(topNavigation);
|
|
96
|
+
}
|
|
97
|
+
function isDropdownOpen(dropdownItem) {
|
|
98
|
+
return dropdownItem.classList.contains(DROPDOWN_ACTIVE_CLASS);
|
|
99
|
+
}
|
|
100
|
+
function hasOpenDropdown(topNavigation) {
|
|
101
|
+
return getDropdownItems(topNavigation).some(isDropdownOpen);
|
|
102
|
+
}
|
|
103
|
+
function ensureId(element, prefix) {
|
|
104
|
+
if (!element.id) {
|
|
105
|
+
generatedIdCounter += 1;
|
|
106
|
+
element.id = `${prefix}-${generatedIdCounter}`;
|
|
107
|
+
}
|
|
108
|
+
return element.id;
|
|
109
|
+
}
|
|
110
|
+
function ensureRelationships(topNavigation) {
|
|
111
|
+
const nav = getNav(topNavigation);
|
|
112
|
+
if (nav) {
|
|
113
|
+
const navId = ensureId(nav, "bf-top-navigation-nav");
|
|
114
|
+
for (const toggle of getMenuToggles(topNavigation)) {
|
|
115
|
+
if (!toggle.hasAttribute("aria-controls")) {
|
|
116
|
+
toggle.setAttribute("aria-controls", navId);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const search = getSearch(topNavigation);
|
|
121
|
+
if (search) {
|
|
122
|
+
const searchId = ensureId(search, "bf-top-navigation-search");
|
|
123
|
+
for (const toggle of getSearchToggles(topNavigation)) {
|
|
124
|
+
if (!toggle.hasAttribute("aria-controls")) {
|
|
125
|
+
toggle.setAttribute("aria-controls", searchId);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
for (const toggle of getDropdownToggles(topNavigation)) {
|
|
130
|
+
const dropdown = getDropdownForToggle(toggle);
|
|
131
|
+
if (!dropdown) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const dropdownId = ensureId(dropdown, "bf-top-navigation-dropdown");
|
|
135
|
+
if (!toggle.hasAttribute("aria-controls")) {
|
|
136
|
+
toggle.setAttribute("aria-controls", dropdownId);
|
|
137
|
+
}
|
|
138
|
+
toggle.setAttribute("aria-haspopup", "true");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function closeDropdowns(topNavigation, activeItem) {
|
|
142
|
+
for (const item of getDropdownItems(topNavigation)) {
|
|
143
|
+
item.classList.toggle(DROPDOWN_ACTIVE_CLASS, item === activeItem);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function updateA11y(topNavigation) {
|
|
147
|
+
ensureRelationships(topNavigation);
|
|
148
|
+
const menuOpen = isMenuOpen(topNavigation);
|
|
149
|
+
const searchOpen = isSearchOpen(topNavigation);
|
|
150
|
+
const largeViewport = isLargeViewport(topNavigation);
|
|
151
|
+
for (const toggle of getMenuToggles(topNavigation)) {
|
|
152
|
+
toggle.setAttribute("aria-expanded", String(menuOpen));
|
|
153
|
+
}
|
|
154
|
+
for (const toggle of getSearchToggles(topNavigation)) {
|
|
155
|
+
toggle.setAttribute("aria-expanded", String(searchOpen));
|
|
156
|
+
toggle.setAttribute("aria-pressed", String(searchOpen));
|
|
157
|
+
}
|
|
158
|
+
for (const toggle of getDropdownToggles(topNavigation)) {
|
|
159
|
+
const dropdownItem = getDropdownItemForToggle(toggle);
|
|
160
|
+
const dropdown = getDropdownForToggle(toggle);
|
|
161
|
+
const expanded = dropdownItem ? isDropdownOpen(dropdownItem) : false;
|
|
162
|
+
toggle.setAttribute("aria-expanded", String(expanded));
|
|
163
|
+
dropdown?.setAttribute("aria-hidden", String(!expanded));
|
|
164
|
+
}
|
|
165
|
+
getNav(topNavigation)?.setAttribute("aria-hidden", String(!largeViewport && !menuOpen && !searchOpen));
|
|
166
|
+
getSearch(topNavigation)?.setAttribute("aria-hidden", String(!searchOpen));
|
|
167
|
+
getOverlay(topNavigation)?.setAttribute("aria-hidden", String(!(largeViewport && searchOpen)));
|
|
168
|
+
}
|
|
169
|
+
function focusSearch(topNavigation) {
|
|
170
|
+
const input = getSearchInput(topNavigation);
|
|
171
|
+
if (input) {
|
|
172
|
+
queueMicrotask(() => input.focus());
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const search = getSearch(topNavigation);
|
|
176
|
+
const focusTarget = search?.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
|
|
177
|
+
if (focusTarget) {
|
|
178
|
+
queueMicrotask(() => focusTarget.focus());
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function closeAll(topNavigation, restoreFocus) {
|
|
182
|
+
const hadSearchOpen = isSearchOpen(topNavigation);
|
|
183
|
+
const hadMenuOpen = isMenuOpen(topNavigation);
|
|
184
|
+
const hadDropdownOpen = hasOpenDropdown(topNavigation);
|
|
185
|
+
setMenuOpen(topNavigation, false);
|
|
186
|
+
setSearchOpen(topNavigation, false);
|
|
187
|
+
closeDropdowns(topNavigation);
|
|
188
|
+
updateA11y(topNavigation);
|
|
189
|
+
if (!restoreFocus) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (hadSearchOpen) {
|
|
193
|
+
lastSearchTriggerByRoot.get(topNavigation)?.focus();
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (hadDropdownOpen) {
|
|
197
|
+
lastDropdownTriggerByRoot.get(topNavigation)?.focus();
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (hadMenuOpen) {
|
|
201
|
+
lastMenuTriggerByRoot.get(topNavigation)?.focus();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function openMenu(topNavigation, trigger) {
|
|
205
|
+
setSearchOpen(topNavigation, false);
|
|
206
|
+
closeDropdowns(topNavigation);
|
|
207
|
+
setMenuOpen(topNavigation, true);
|
|
208
|
+
updateA11y(topNavigation);
|
|
209
|
+
if (trigger) {
|
|
210
|
+
lastMenuTriggerByRoot.set(topNavigation, trigger);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function openSearch(topNavigation, trigger) {
|
|
214
|
+
closeDropdowns(topNavigation);
|
|
215
|
+
setMenuOpen(topNavigation, false);
|
|
216
|
+
setSearchOpen(topNavigation, true);
|
|
217
|
+
updateA11y(topNavigation);
|
|
218
|
+
if (trigger) {
|
|
219
|
+
lastSearchTriggerByRoot.set(topNavigation, trigger);
|
|
220
|
+
}
|
|
221
|
+
focusSearch(topNavigation);
|
|
222
|
+
}
|
|
223
|
+
function openDropdown(topNavigation, trigger) {
|
|
224
|
+
const dropdownItem = getDropdownItemForToggle(trigger);
|
|
225
|
+
if (!dropdownItem) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
setSearchOpen(topNavigation, false);
|
|
229
|
+
closeDropdowns(topNavigation, dropdownItem);
|
|
230
|
+
updateA11y(topNavigation);
|
|
231
|
+
lastDropdownTriggerByRoot.set(topNavigation, trigger);
|
|
232
|
+
}
|
|
233
|
+
function syncInitialState(root) {
|
|
234
|
+
for (const topNavigation of getRoots(root)) {
|
|
235
|
+
ensureRelationships(topNavigation);
|
|
236
|
+
if (isLargeViewport(topNavigation)) {
|
|
237
|
+
setMenuOpen(topNavigation, false);
|
|
238
|
+
}
|
|
239
|
+
if (isMenuOpen(topNavigation) && isSearchOpen(topNavigation)) {
|
|
240
|
+
setMenuOpen(topNavigation, false);
|
|
241
|
+
}
|
|
242
|
+
if (isSearchOpen(topNavigation) || (!isLargeViewport(topNavigation) && !isMenuOpen(topNavigation))) {
|
|
243
|
+
closeDropdowns(topNavigation);
|
|
244
|
+
}
|
|
245
|
+
updateA11y(topNavigation);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
export function initTopNavigations(options = {}) {
|
|
249
|
+
const root = options.root ?? document;
|
|
250
|
+
const rootWindow = getRootWindow(root);
|
|
251
|
+
syncInitialState(root);
|
|
252
|
+
const onClick = (event) => {
|
|
253
|
+
const target = event.target;
|
|
254
|
+
if (!(target instanceof Element)) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const menuToggle = target.closest(MENU_TOGGLE_SELECTOR);
|
|
258
|
+
if (menuToggle) {
|
|
259
|
+
const topNavigation = menuToggle.closest(ROOT_SELECTOR);
|
|
260
|
+
if (!topNavigation) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
event.preventDefault();
|
|
264
|
+
if (isMenuOpen(topNavigation)) {
|
|
265
|
+
closeAll(topNavigation, false);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
openMenu(topNavigation, menuToggle);
|
|
269
|
+
}
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const searchToggle = target.closest(SEARCH_TOGGLE_SELECTOR);
|
|
273
|
+
if (searchToggle) {
|
|
274
|
+
const topNavigation = searchToggle.closest(ROOT_SELECTOR);
|
|
275
|
+
if (!topNavigation) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
event.preventDefault();
|
|
279
|
+
if (isSearchOpen(topNavigation)) {
|
|
280
|
+
closeAll(topNavigation, true);
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
openSearch(topNavigation, searchToggle);
|
|
284
|
+
}
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const dropdownToggle = target.closest(DROPDOWN_TOGGLE_SELECTOR);
|
|
288
|
+
if (dropdownToggle) {
|
|
289
|
+
const topNavigation = dropdownToggle.closest(ROOT_SELECTOR);
|
|
290
|
+
const dropdownItem = getDropdownItemForToggle(dropdownToggle);
|
|
291
|
+
if (!topNavigation || !dropdownItem) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
event.preventDefault();
|
|
295
|
+
lastDropdownTriggerByRoot.set(topNavigation, dropdownToggle);
|
|
296
|
+
if (isDropdownOpen(dropdownItem)) {
|
|
297
|
+
closeDropdowns(topNavigation);
|
|
298
|
+
updateA11y(topNavigation);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
openDropdown(topNavigation, dropdownToggle);
|
|
302
|
+
}
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const overlay = target.closest(OVERLAY_SELECTOR);
|
|
306
|
+
if (overlay) {
|
|
307
|
+
const topNavigation = overlay.closest(ROOT_SELECTOR);
|
|
308
|
+
if (!topNavigation) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
event.preventDefault();
|
|
312
|
+
closeAll(topNavigation, true);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const dropdownAction = target.closest(DROPDOWN_ACTION_SELECTOR);
|
|
316
|
+
if (dropdownAction) {
|
|
317
|
+
const topNavigation = dropdownAction.closest(ROOT_SELECTOR);
|
|
318
|
+
if (topNavigation && hasOpenDropdown(topNavigation)) {
|
|
319
|
+
closeAll(topNavigation, false);
|
|
320
|
+
}
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
const clickedTopNavigation = target.closest(ROOT_SELECTOR);
|
|
324
|
+
for (const topNavigation of getRoots(root)) {
|
|
325
|
+
if (clickedTopNavigation && topNavigation === clickedTopNavigation) {
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
if (isMenuOpen(topNavigation) || isSearchOpen(topNavigation) || hasOpenDropdown(topNavigation)) {
|
|
329
|
+
closeAll(topNavigation, false);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
const onKeyDown = (event) => {
|
|
334
|
+
if (!(event instanceof KeyboardEvent) || event.key !== "Escape") {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
for (const topNavigation of getRoots(root)) {
|
|
338
|
+
if (isMenuOpen(topNavigation) || isSearchOpen(topNavigation) || hasOpenDropdown(topNavigation)) {
|
|
339
|
+
closeAll(topNavigation, true);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
const onResize = () => {
|
|
344
|
+
syncInitialState(root);
|
|
345
|
+
};
|
|
346
|
+
root.addEventListener("click", onClick);
|
|
347
|
+
root.addEventListener("keydown", onKeyDown);
|
|
348
|
+
rootWindow?.addEventListener("resize", onResize);
|
|
349
|
+
return () => {
|
|
350
|
+
root.removeEventListener("click", onClick);
|
|
351
|
+
root.removeEventListener("keydown", onKeyDown);
|
|
352
|
+
rootWindow?.removeEventListener("resize", onResize);
|
|
353
|
+
};
|
|
354
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
export interface ThemeFontFile {
|
|
2
|
+
family: string;
|
|
3
|
+
path: string;
|
|
4
|
+
cssFamily?: string;
|
|
5
|
+
fontStyle?: string;
|
|
6
|
+
fontWeight?: string;
|
|
7
|
+
fontStretch?: string;
|
|
8
|
+
fontDisplay?: string;
|
|
9
|
+
emitFontFace?: boolean;
|
|
10
|
+
runtimeOnly?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface ThemeElementConfig {
|
|
13
|
+
identifier: string;
|
|
14
|
+
fontSize: number;
|
|
15
|
+
lineHeight: number;
|
|
16
|
+
spaceAfter: number;
|
|
17
|
+
fontFamily?: string;
|
|
18
|
+
fontWeight?: number;
|
|
19
|
+
fontStyle?: string;
|
|
20
|
+
fontVariantCaps?: string;
|
|
21
|
+
letterSpacing?: string;
|
|
22
|
+
textTransform?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ThemeLayoutConfig {
|
|
25
|
+
contentMaxWidthRem: number;
|
|
26
|
+
contentPaddingInlineRem: number;
|
|
27
|
+
measureRem: number;
|
|
28
|
+
sectionSpaceBaselineUnits: number;
|
|
29
|
+
sectionSpaceShallowBaselineUnits: number;
|
|
30
|
+
sectionSpaceDeepBaselineUnits: number;
|
|
31
|
+
stripSpaceBaselineUnits: number;
|
|
32
|
+
gridGapInlineBaselineUnits: number;
|
|
33
|
+
gridGapBlockBaselineUnits: number;
|
|
34
|
+
pageMarginBaselineUnits: number;
|
|
35
|
+
}
|
|
36
|
+
export interface ThemeComponentsConfig {
|
|
37
|
+
borderWidthPx: number;
|
|
38
|
+
radiusRem: number;
|
|
39
|
+
controlBlockPaddingRem: number;
|
|
40
|
+
controlCompactBlockPaddingRem?: number;
|
|
41
|
+
controlInlinePaddingRem: number;
|
|
42
|
+
controlInlinePaddingActionRem?: number;
|
|
43
|
+
controlInlinePaddingFieldRem?: number;
|
|
44
|
+
controlVisualSizeRem: number;
|
|
45
|
+
fieldGapBaselineUnits: number;
|
|
46
|
+
panelPaddingInlineBaselineUnits: number;
|
|
47
|
+
panelPaddingBlockBaselineUnits: number;
|
|
48
|
+
accordionIndentBaselineUnits: number;
|
|
49
|
+
}
|
|
50
|
+
export interface ThemeConfig {
|
|
51
|
+
baselineUnit: number;
|
|
52
|
+
fontFiles: ThemeFontFile[];
|
|
53
|
+
fontStacks: Record<string, string>;
|
|
54
|
+
elements: ThemeElementConfig[];
|
|
55
|
+
roles: Record<string, string>;
|
|
56
|
+
layout: ThemeLayoutConfig;
|
|
57
|
+
components: ThemeComponentsConfig;
|
|
58
|
+
}
|
|
59
|
+
export interface BaselineGeneratorElementToken {
|
|
60
|
+
fontSize: string;
|
|
61
|
+
lineHeight: string;
|
|
62
|
+
fontFamily?: string;
|
|
63
|
+
fontWeight?: number;
|
|
64
|
+
fontStyle?: string;
|
|
65
|
+
spaceAfter: string;
|
|
66
|
+
nudgeTop: string;
|
|
67
|
+
}
|
|
68
|
+
export interface BaselineGeneratorTokens {
|
|
69
|
+
baselineUnit: string;
|
|
70
|
+
fontFiles: ThemeFontFile[];
|
|
71
|
+
elements: Record<string, BaselineGeneratorElementToken>;
|
|
72
|
+
}
|
|
73
|
+
export interface TypographyToken extends BaselineGeneratorElementToken {
|
|
74
|
+
identifier: string;
|
|
75
|
+
fontStack: string;
|
|
76
|
+
marginBottom: string;
|
|
77
|
+
fontVariantCaps?: string;
|
|
78
|
+
letterSpacing?: string;
|
|
79
|
+
textTransform?: string;
|
|
80
|
+
}
|
|
81
|
+
export interface LayoutTokens {
|
|
82
|
+
contentMaxWidth: string;
|
|
83
|
+
contentPaddingInline: string;
|
|
84
|
+
measure: string;
|
|
85
|
+
sectionSpace: string;
|
|
86
|
+
sectionSpaceShallow: string;
|
|
87
|
+
sectionSpaceDeep: string;
|
|
88
|
+
stripSpace: string;
|
|
89
|
+
gridGapInline: string;
|
|
90
|
+
gridGapBlock: string;
|
|
91
|
+
pageMargin: string;
|
|
92
|
+
}
|
|
93
|
+
export interface ComponentTokens {
|
|
94
|
+
borderWidth: string;
|
|
95
|
+
barThickness: string;
|
|
96
|
+
radius: string;
|
|
97
|
+
controlBlockPadding: string;
|
|
98
|
+
controlCompactBlockPadding: string;
|
|
99
|
+
controlInlinePadding: string;
|
|
100
|
+
controlInlinePaddingAction: string;
|
|
101
|
+
controlInlinePaddingField: string;
|
|
102
|
+
controlVisualSize: string;
|
|
103
|
+
fieldGap: string;
|
|
104
|
+
panelPaddingInline: string;
|
|
105
|
+
panelPaddingBlock: string;
|
|
106
|
+
accordionIndent: string;
|
|
107
|
+
}
|
|
108
|
+
export interface ThemeTokens {
|
|
109
|
+
baselineUnit: string;
|
|
110
|
+
fontFiles: ThemeFontFile[];
|
|
111
|
+
fontStacks: Record<string, string>;
|
|
112
|
+
roles: Record<string, TypographyToken>;
|
|
113
|
+
elements: Record<string, TypographyToken>;
|
|
114
|
+
layout: LayoutTokens;
|
|
115
|
+
components: ComponentTokens;
|
|
116
|
+
}
|
|
117
|
+
export interface ThemeSurface {
|
|
118
|
+
name: string;
|
|
119
|
+
label?: string;
|
|
120
|
+
className?: string;
|
|
121
|
+
engine: string;
|
|
122
|
+
configPath: string;
|
|
123
|
+
baselineConfigPath: string;
|
|
124
|
+
baselineTokensPath: string;
|
|
125
|
+
tokens: ThemeTokens;
|
|
126
|
+
metrics: BaselineGeneratorTokens;
|
|
127
|
+
}
|
|
128
|
+
export interface ThemeSurfaceManifestEntry {
|
|
129
|
+
label?: string;
|
|
130
|
+
className?: string;
|
|
131
|
+
engine: string;
|
|
132
|
+
tokens: ThemeTokens;
|
|
133
|
+
metrics: BaselineGeneratorTokens;
|
|
134
|
+
}
|
|
135
|
+
export interface ThemeSurfaceManifest {
|
|
136
|
+
defaultSurface: string;
|
|
137
|
+
surfaces: Record<string, ThemeSurfaceManifestEntry>;
|
|
138
|
+
}
|
|
139
|
+
export interface BuildThemeResult {
|
|
140
|
+
configPath: string;
|
|
141
|
+
baselineConfigPath: string;
|
|
142
|
+
baselineTokensPath: string;
|
|
143
|
+
tokensPath: string;
|
|
144
|
+
cssPath: string;
|
|
145
|
+
surfaceManifestPath: string;
|
|
146
|
+
tokens: ThemeTokens;
|
|
147
|
+
css: string;
|
|
148
|
+
surfaces: ThemeSurfaceManifest;
|
|
149
|
+
}
|
|
150
|
+
export interface DeriveBaselineTokensResult {
|
|
151
|
+
configPath: string;
|
|
152
|
+
baselineConfigPath: string;
|
|
153
|
+
baselineTokensPath: string;
|
|
154
|
+
tokens: BaselineGeneratorTokens;
|
|
155
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type ThemeTone = "light" | "dark";
|
|
2
|
+
export declare function vanillaThemeColorVars(tone: ThemeTone): string;
|
|
3
|
+
export declare function foundryThemeRootColorVars(tone: ThemeTone): string;
|
|
4
|
+
export declare function foundryComponentColorVars(tone: ThemeTone): string;
|
|
5
|
+
export {};
|