@vobs/ui 0.1.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 (48) hide show
  1. package/LICENSE +21 -0
  2. package/dist/app-shell-dom.d.ts +24 -0
  3. package/dist/app-shell-dom.js +573 -0
  4. package/dist/app-shell.d.ts +199 -0
  5. package/dist/app-shell.js +370 -0
  6. package/dist/base.css +52 -0
  7. package/dist/calendar-picker.d.ts +45 -0
  8. package/dist/calendar-picker.js +217 -0
  9. package/dist/calendar.d.ts +95 -0
  10. package/dist/calendar.js +194 -0
  11. package/dist/complex-inputs.d.ts +300 -0
  12. package/dist/complex-inputs.js +862 -0
  13. package/dist/components.css +4568 -0
  14. package/dist/data-display.d.ts +1063 -0
  15. package/dist/data-display.js +2298 -0
  16. package/dist/feedback.d.ts +88 -0
  17. package/dist/feedback.js +281 -0
  18. package/dist/forms.d.ts +378 -0
  19. package/dist/forms.js +1015 -0
  20. package/dist/icons-config.d.ts +25 -0
  21. package/dist/icons-config.js +14 -0
  22. package/dist/icons.d.ts +41 -0
  23. package/dist/icons.js +185 -0
  24. package/dist/index.d.ts +22 -0
  25. package/dist/index.js +32 -0
  26. package/dist/locale/en-US.d.ts +31 -0
  27. package/dist/locale/en-US.js +20 -0
  28. package/dist/locale/zh-CN.d.ts +31 -0
  29. package/dist/locale/zh-CN.js +20 -0
  30. package/dist/navigation.d.ts +609 -0
  31. package/dist/navigation.js +1707 -0
  32. package/dist/overlay.d.ts +304 -0
  33. package/dist/overlay.js +969 -0
  34. package/dist/primitives.d.ts +268 -0
  35. package/dist/primitives.js +764 -0
  36. package/dist/styles.css +3 -0
  37. package/dist/theme-data.d.ts +363 -0
  38. package/dist/theme-data.js +374 -0
  39. package/dist/theme.d.ts +79 -0
  40. package/dist/theme.js +262 -0
  41. package/dist/tokens.css +449 -0
  42. package/dist/tree.d.ts +144 -0
  43. package/dist/tree.js +469 -0
  44. package/dist/virtual-list.d.ts +190 -0
  45. package/dist/virtual-list.js +521 -0
  46. package/dist/workbench.d.ts +136 -0
  47. package/dist/workbench.js +156 -0
  48. package/package.json +113 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 vobsjs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,24 @@
1
+ /** @license MIT
2
+ * Copyright (c) 2026 vobsjs
3
+ * @vobs/ui
4
+ */
5
+ import { type Owner, type TemplateEnvironment } from '@vobs/runtime-dom';
6
+ import type { AppShellDefinition, AppShellComponentScope, ResolvedAppShellState, ResolvedAppShellStatus } from './app-shell.js';
7
+ export interface AppShellFrame {
8
+ readonly root: HTMLDivElement;
9
+ readonly primaryNav: HTMLElement;
10
+ readonly utilityNav: HTMLElement;
11
+ readonly pageFrame: HTMLElement;
12
+ readonly pageToolbar: HTMLElement;
13
+ readonly statusbar: HTMLElement;
14
+ readonly statusIcon: HTMLElement;
15
+ readonly statusText: HTMLSpanElement;
16
+ readonly pageKicker: HTMLParagraphElement;
17
+ readonly pageTitle: HTMLHeadingElement;
18
+ readonly pageDescription: HTMLParagraphElement;
19
+ readonly version: HTMLSpanElement;
20
+ }
21
+ export declare function createAppShellFrame(shell: AppShellDefinition, scope: AppShellComponentScope, environment: TemplateEnvironment): AppShellFrame;
22
+ export declare function bindAppShellThemeControls(owner: Owner, frame: AppShellFrame, shell: AppShellDefinition, scope: AppShellComponentScope, environment: TemplateEnvironment): void;
23
+ export declare function bindAppShellAccountMenu(owner: Owner, frame: AppShellFrame, shell: AppShellDefinition): void;
24
+ export declare function syncAppShellFrame(frame: AppShellFrame, shell: AppShellDefinition, state: ResolvedAppShellState, status: ResolvedAppShellStatus, scope: AppShellComponentScope, environment: TemplateEnvironment): void;
@@ -0,0 +1,573 @@
1
+ /** @license MIT
2
+ * Copyright (c) 2026 vobsjs
3
+ * @vobs/ui
4
+ */
5
+ import { createIconElement } from '@vobs/icons';
6
+ import {} from '@vobs/runtime-dom';
7
+ import { resolveUiIcon } from './icons.js';
8
+ import { brandPresets, createStorageThemePersistence, createThemeController, resolveBrandColor, } from './theme.js';
9
+ const defaultBrandCycle = brandPresets.map((brand) => brand.id);
10
+ export function createAppShellFrame(shell, scope, environment) {
11
+ const root = document.createElement('div');
12
+ root.className = joinClasses('kui-app-shell', shell.className);
13
+ root.setAttribute('data-vobs-template', 'k-app-shell');
14
+ root.setAttribute('data-vobs-protocol', '1');
15
+ root.setAttribute('data-app-shell', shell.id);
16
+ root.setAttribute('data-sidebar-mode', shell.sidebarMode ?? 'expanded');
17
+ root.setAttribute('data-content-mode', shell.contentMode ?? 'contained');
18
+ setOptionalAttribute(root, 'data-theme-mode', shell.theme?.mode);
19
+ setOptionalAttribute(root, 'data-accent', shell.theme?.accent);
20
+ const topbar = document.createElement('header');
21
+ topbar.className = 'kui-app-shell-topbar';
22
+ topbar.setAttribute('data-app-shell-region', 'topbar');
23
+ topbar.append(createBrand(shell, environment), createTopbarActions(shell, scope, environment));
24
+ const sidebar = document.createElement('aside');
25
+ sidebar.className = 'kui-app-shell-sidebar';
26
+ sidebar.setAttribute('data-app-shell-region', 'sidebar');
27
+ sidebar.setAttribute('aria-label', `${shell.brand.label} navigation`);
28
+ sidebar.setAttribute('data-sidebar-mode', shell.sidebarMode ?? 'expanded');
29
+ const primaryNav = document.createElement('nav');
30
+ primaryNav.className = 'kui-app-shell-nav';
31
+ primaryNav.setAttribute('aria-label', 'Primary');
32
+ const utilityNav = document.createElement('nav');
33
+ utilityNav.className = 'kui-app-shell-utility-nav';
34
+ utilityNav.setAttribute('aria-label', 'Utility');
35
+ sidebar.append(primaryNav, utilityNav);
36
+ const main = document.createElement('main');
37
+ main.className = 'kui-app-shell-main';
38
+ main.setAttribute('data-app-shell-region', 'content');
39
+ main.setAttribute('aria-label', `${shell.brand.label} content`);
40
+ const pageHeader = document.createElement('header');
41
+ pageHeader.className = 'kui-app-shell-page-header';
42
+ pageHeader.setAttribute('data-app-shell-region', 'page-header');
43
+ const pageHeading = document.createElement('div');
44
+ pageHeading.className = 'kui-app-shell-page-heading';
45
+ const pageKicker = document.createElement('p');
46
+ pageKicker.className = 'kui-app-shell-page-kicker';
47
+ const pageTitle = document.createElement('h1');
48
+ pageTitle.className = 'kui-app-shell-page-title';
49
+ pageHeading.append(pageKicker, pageTitle);
50
+ const pageDescription = document.createElement('p');
51
+ pageDescription.className = 'kui-app-shell-page-subtitle';
52
+ pageHeader.append(pageHeading, pageDescription);
53
+ const pageBody = document.createElement('section');
54
+ pageBody.className = 'kui-app-shell-page-body';
55
+ pageBody.setAttribute('data-mode', shell.contentMode ?? 'contained');
56
+ const pageToolbar = document.createElement('div');
57
+ pageToolbar.className = 'kui-app-shell-page-toolbar';
58
+ pageToolbar.setAttribute('role', 'toolbar');
59
+ const pageFrame = document.createElement('section');
60
+ pageFrame.className = 'kui-app-shell-page-frame';
61
+ pageFrame.append(pageHeader, pageToolbar, pageBody);
62
+ main.append(pageFrame);
63
+ const footer = document.createElement('footer');
64
+ footer.className = 'kui-app-shell-statusbar';
65
+ footer.setAttribute('data-app-shell-region', 'statusbar');
66
+ footer.setAttribute('aria-live', 'polite');
67
+ const status = document.createElement('span');
68
+ status.className = 'kui-app-shell-status';
69
+ status.setAttribute('data-app-shell-status', 'runtime');
70
+ const statusIcon = document.createElement('span');
71
+ statusIcon.className = 'kui-app-shell-status-icon';
72
+ const statusText = document.createElement('span');
73
+ statusText.className = 'kui-app-shell-status-text';
74
+ status.append(statusIcon, statusText);
75
+ const version = document.createElement('span');
76
+ version.className = 'kui-app-shell-status-version';
77
+ version.setAttribute('data-app-shell-version', 'true');
78
+ version.textContent = shell.statusbar?.version ?? '';
79
+ footer.append(status, version);
80
+ root.append(topbar, sidebar, main, footer);
81
+ return {
82
+ root,
83
+ primaryNav,
84
+ utilityNav,
85
+ pageFrame,
86
+ pageToolbar,
87
+ statusbar: footer,
88
+ statusIcon,
89
+ statusText,
90
+ pageKicker,
91
+ pageTitle,
92
+ pageDescription,
93
+ version,
94
+ };
95
+ }
96
+ export function bindAppShellThemeControls(owner, frame, shell, scope, environment) {
97
+ if (shell.theme === undefined)
98
+ return;
99
+ const controller = createAppShellThemeController(frame, shell);
100
+ const themeButton = readActionButton(frame.root, 'theme');
101
+ const brandButton = readActionButton(frame.root, 'accent');
102
+ const brandCycle = createBrandCycle(shell);
103
+ const sync = (state) => {
104
+ syncAppShellThemeState(frame, themeButton, brandButton, shell, state, scope, environment);
105
+ };
106
+ sync(controller.state);
107
+ owner.own(controller.subscribe(sync));
108
+ owner.own(() => controller.destroy());
109
+ if (themeButton !== null) {
110
+ const onClick = () => {
111
+ controller.toggleTheme();
112
+ };
113
+ themeButton.addEventListener('click', onClick);
114
+ owner.own(() => themeButton.removeEventListener('click', onClick));
115
+ }
116
+ if (brandButton !== null) {
117
+ const onClick = () => {
118
+ controller.setBrand(nextBrand(controller.brand, brandCycle));
119
+ };
120
+ brandButton.addEventListener('click', onClick);
121
+ owner.own(() => brandButton.removeEventListener('click', onClick));
122
+ }
123
+ }
124
+ export function bindAppShellAccountMenu(owner, frame, shell) {
125
+ const root = frame.root;
126
+ const account = shell.topbar?.account;
127
+ if (account === undefined || (account.menu?.length ?? 0) === 0)
128
+ return;
129
+ const accountRoot = root.querySelector('.kui-app-shell-account');
130
+ const button = root.querySelector('.kui-app-shell-account-button');
131
+ const menu = root.querySelector('.kui-app-shell-account-menu');
132
+ if (!(accountRoot instanceof HTMLElement) ||
133
+ !(button instanceof HTMLButtonElement) ||
134
+ !(menu instanceof HTMLElement)) {
135
+ return;
136
+ }
137
+ const sync = (expanded) => {
138
+ const state = expanded ? 'open' : 'closed';
139
+ accountRoot.setAttribute('data-state', state);
140
+ button.setAttribute('aria-expanded', expanded ? 'true' : 'false');
141
+ button.setAttribute('data-state', state);
142
+ menu.setAttribute('data-state', state);
143
+ menu.hidden = !expanded;
144
+ };
145
+ const expanded = () => button.getAttribute('aria-expanded') === 'true';
146
+ const dispatchToggle = () => {
147
+ button.dispatchEvent(new CustomEvent('vobs:app-shell-account-toggle', {
148
+ bubbles: true,
149
+ detail: { shellId: shell.id, expanded: expanded() },
150
+ }));
151
+ };
152
+ const close = () => {
153
+ if (!expanded())
154
+ return;
155
+ sync(false);
156
+ dispatchToggle();
157
+ };
158
+ const toggle = () => {
159
+ sync(!expanded());
160
+ dispatchToggle();
161
+ };
162
+ const onButtonClick = () => {
163
+ toggle();
164
+ if (expanded())
165
+ focusAccountMenuItem(menu, 'first');
166
+ };
167
+ const onButtonKeyDown = (event) => {
168
+ if (event.key !== 'ArrowDown' && event.key !== 'ArrowUp')
169
+ return;
170
+ event.preventDefault();
171
+ if (!expanded()) {
172
+ sync(true);
173
+ dispatchToggle();
174
+ }
175
+ focusAccountMenuItem(menu, event.key === 'ArrowDown' ? 'first' : 'last');
176
+ };
177
+ const onDocumentPointerDown = (event) => {
178
+ if (!expanded())
179
+ return;
180
+ if (event.target instanceof Node && root.contains(event.target)) {
181
+ if (accountRoot?.contains(event.target))
182
+ return;
183
+ }
184
+ close();
185
+ };
186
+ const onDocumentKeyDown = (event) => {
187
+ if (event.key === 'Escape') {
188
+ close();
189
+ button.focus();
190
+ }
191
+ };
192
+ const onMenuKeyDown = (event) => {
193
+ if (event.key === 'Escape') {
194
+ event.preventDefault();
195
+ event.stopPropagation();
196
+ close();
197
+ button.focus();
198
+ return;
199
+ }
200
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
201
+ event.preventDefault();
202
+ focusAccountMenuItem(menu, event.key === 'ArrowDown' ? 'next' : 'previous');
203
+ return;
204
+ }
205
+ if (event.key === 'Home' || event.key === 'End') {
206
+ event.preventDefault();
207
+ focusAccountMenuItem(menu, event.key === 'Home' ? 'first' : 'last');
208
+ }
209
+ };
210
+ const onMenuClick = (event) => {
211
+ const target = event.target instanceof Element ? event.target : undefined;
212
+ const item = target?.closest('[data-account-menu-id]');
213
+ if (!(item instanceof HTMLElement))
214
+ return;
215
+ const itemId = item.getAttribute('data-account-menu-id');
216
+ if (itemId === null || item.getAttribute('aria-disabled') === 'true') {
217
+ event.preventDefault();
218
+ return;
219
+ }
220
+ item.dispatchEvent(new CustomEvent('vobs:app-shell-account-select', {
221
+ bubbles: true,
222
+ detail: { shellId: shell.id, itemId },
223
+ }));
224
+ close();
225
+ };
226
+ sync(account.menuExpanded === true);
227
+ button.addEventListener('click', onButtonClick);
228
+ button.addEventListener('keydown', onButtonKeyDown);
229
+ menu.addEventListener('click', onMenuClick);
230
+ menu.addEventListener('keydown', onMenuKeyDown);
231
+ root.ownerDocument.addEventListener('pointerdown', onDocumentPointerDown);
232
+ root.ownerDocument.addEventListener('keydown', onDocumentKeyDown);
233
+ owner.own(() => {
234
+ button.removeEventListener('click', onButtonClick);
235
+ button.removeEventListener('keydown', onButtonKeyDown);
236
+ menu.removeEventListener('click', onMenuClick);
237
+ menu.removeEventListener('keydown', onMenuKeyDown);
238
+ root.ownerDocument.removeEventListener('pointerdown', onDocumentPointerDown);
239
+ root.ownerDocument.removeEventListener('keydown', onDocumentKeyDown);
240
+ });
241
+ }
242
+ function focusAccountMenuItem(menu, placement) {
243
+ const items = Array.from(menu.querySelectorAll('.kui-app-shell-account-menu-item:not([aria-disabled="true"])'));
244
+ if (items.length === 0)
245
+ return;
246
+ const currentIndex = items.findIndex((item) => item === menu.ownerDocument.activeElement);
247
+ const nextIndex = placement === 'first'
248
+ ? 0
249
+ : placement === 'last'
250
+ ? items.length - 1
251
+ : placement === 'next'
252
+ ? (Math.max(0, currentIndex) + 1) % items.length
253
+ : currentIndex <= 0
254
+ ? items.length - 1
255
+ : currentIndex - 1;
256
+ items[nextIndex]?.focus();
257
+ }
258
+ export function syncAppShellFrame(frame, shell, state, status, scope, environment) {
259
+ setOptionalAttribute(frame.root, 'data-active-nav', state.activeId);
260
+ setOptionalAttribute(frame.root, 'data-route-pending', status.state === 'pending' ? 'true' : undefined);
261
+ setOptionalAttribute(frame.statusbar, 'data-state', status.state);
262
+ frame.pageKicker.textContent = shell.pageHeader?.kicker ?? shell.title ?? shell.brand.label;
263
+ frame.pageTitle.textContent = state.title;
264
+ frame.pageTitle.setAttribute('data-title', state.title);
265
+ frame.pageDescription.textContent = state.description;
266
+ frame.pageDescription.setAttribute('data-subtitle', state.description);
267
+ frame.statusText.textContent = status.text;
268
+ frame.statusbar.setAttribute('data-status', status.state);
269
+ frame.statusIcon.replaceChildren();
270
+ appendIcon(frame.statusIcon, status.icon, 'kui-app-shell-status-icon', scope, environment);
271
+ frame.version.textContent = shell.statusbar?.version ?? '';
272
+ renderNavItems(frame.primaryNav, shell.navigation?.primary ?? [], state.activeId, scope, environment);
273
+ renderNavItems(frame.utilityNav, shell.navigation?.utility ?? [], state.activeId, scope, environment);
274
+ }
275
+ function createAppShellThemeController(frame, shell) {
276
+ const persistence = shell.theme?.persist === false
277
+ ? undefined
278
+ : createBrowserThemePersistence(frame.root.ownerDocument);
279
+ const options = {
280
+ target: frame.root.ownerDocument.documentElement,
281
+ initialBrand: shell.theme?.brand ?? shell.theme?.accent ?? 'green',
282
+ ...(shell.theme?.mode === undefined ? {} : { initialTheme: shell.theme.mode }),
283
+ ...(persistence === undefined ? {} : { persistence }),
284
+ };
285
+ return createThemeController(options);
286
+ }
287
+ function syncAppShellThemeState(frame, themeButton, brandButton, shell, state, scope, environment) {
288
+ frame.root.setAttribute('data-theme-mode', state.theme);
289
+ frame.root.setAttribute('data-accent', state.brand.id);
290
+ frame.root.setAttribute('data-brand', state.brand.id);
291
+ frame.statusbar.setAttribute('data-theme-mode', state.theme);
292
+ frame.statusbar.setAttribute('data-accent', state.brand.id);
293
+ if (themeButton !== null) {
294
+ themeButton.setAttribute('aria-pressed', state.theme === 'dark' ? 'true' : 'false');
295
+ themeButton.setAttribute('data-state', state.theme);
296
+ themeButton.setAttribute('data-theme-mode', state.theme);
297
+ themeButton.setAttribute('title', `Theme: ${state.theme}`);
298
+ replaceButtonIcon(themeButton, resolveThemeIcon(shell, state), scope, environment);
299
+ }
300
+ if (brandButton !== null) {
301
+ brandButton.setAttribute('aria-pressed', 'false');
302
+ brandButton.setAttribute('data-state', state.brand.id);
303
+ brandButton.setAttribute('data-brand', state.brand.id);
304
+ brandButton.setAttribute('data-color', state.brand.color);
305
+ brandButton.setAttribute('title', `Brand: ${state.brand.label}`);
306
+ brandButton.style.setProperty('--kui-app-shell-current-brand', state.brand.color);
307
+ }
308
+ }
309
+ function resolveThemeIcon(shell, state) {
310
+ return state.theme === 'dark' ? shell.theme?.icons?.dark : shell.theme?.icons?.light;
311
+ }
312
+ function replaceButtonIcon(button, iconName, scope, environment) {
313
+ if (iconName === undefined)
314
+ return;
315
+ for (const icon of Array.from(button.querySelectorAll(':scope > .kui-app-shell-icon'))) {
316
+ icon.remove();
317
+ }
318
+ appendIcon(button, iconName, 'kui-app-shell-icon', scope, environment);
319
+ }
320
+ function createBrandCycle(shell) {
321
+ const inputs = shell.theme?.brands ?? defaultBrandCycle;
322
+ return inputs.map((brand) => resolveBrandColor(brand));
323
+ }
324
+ function nextBrand(current, cycle) {
325
+ if (cycle.length === 0)
326
+ return current;
327
+ const currentIndex = cycle.findIndex((brand) => brand.id === current.id || brand.color === current.color);
328
+ return cycle[(currentIndex + 1) % cycle.length] ?? cycle[0] ?? current;
329
+ }
330
+ function readActionButton(root, actionId) {
331
+ const button = root.querySelector(`[data-action-id="${actionId}"]`);
332
+ return button instanceof HTMLButtonElement ? button : null;
333
+ }
334
+ function createBrowserThemePersistence(document) {
335
+ try {
336
+ const storage = document.defaultView?.localStorage;
337
+ if (storage === undefined)
338
+ return undefined;
339
+ return createStorageThemePersistence(storage);
340
+ }
341
+ catch {
342
+ return undefined;
343
+ }
344
+ }
345
+ function createBrand(shell, environment) {
346
+ const brand = document.createElement('a');
347
+ brand.className = 'kui-app-shell-brand';
348
+ setHref(brand, shell.brand.href ?? '#', environment);
349
+ brand.setAttribute('aria-label', shell.brand.label);
350
+ brand.setAttribute('data-label', shell.brand.label);
351
+ const mark = document.createElement('span');
352
+ mark.className = 'kui-app-shell-brand-mark';
353
+ mark.setAttribute('aria-hidden', 'true');
354
+ mark.textContent = shell.brand.mark ?? shell.brand.label.slice(0, 1);
355
+ const name = document.createElement('span');
356
+ name.className = 'kui-app-shell-brand-name';
357
+ name.textContent = shell.brand.label;
358
+ brand.append(mark, name);
359
+ return brand;
360
+ }
361
+ function createTopbarActions(shell, scope, environment) {
362
+ const actions = document.createElement('div');
363
+ actions.className = 'kui-app-shell-topbar-actions';
364
+ actions.setAttribute('role', 'toolbar');
365
+ actions.setAttribute('aria-label', 'Global actions');
366
+ for (const action of shell.topbar?.actions ?? []) {
367
+ actions.append(createTopbarAction(action, scope, environment));
368
+ }
369
+ const account = shell.topbar?.account;
370
+ if (account !== undefined)
371
+ actions.append(createAccountControl(shell, account, scope, environment));
372
+ return actions;
373
+ }
374
+ function createTopbarAction(action, scope, environment) {
375
+ const button = document.createElement('button');
376
+ button.type = 'button';
377
+ button.className = 'kui-app-shell-icon-button';
378
+ button.setAttribute('aria-label', action.label);
379
+ button.setAttribute('data-action-id', action.id);
380
+ setOptionalAttribute(button, 'data-app-shell-intent', action.intent);
381
+ button.setAttribute('data-state', action.disabled === true ? 'disabled' : action.pressed === true ? 'pressed' : 'idle');
382
+ button.setAttribute('data-has-badge', action.badge === undefined ? 'false' : 'true');
383
+ button.setAttribute('data-badge', action.badge === undefined ? '' : String(action.badge));
384
+ if (action.pressed !== undefined) {
385
+ button.setAttribute('aria-pressed', action.pressed ? 'true' : 'false');
386
+ }
387
+ if (action.disabled === true)
388
+ button.disabled = true;
389
+ appendIcon(button, action.icon, 'kui-app-shell-icon', scope, environment);
390
+ if (action.badge !== undefined) {
391
+ const badge = document.createElement('span');
392
+ badge.className = 'kui-app-shell-icon-button-badge';
393
+ badge.setAttribute('aria-hidden', 'true');
394
+ badge.textContent = String(action.badge);
395
+ button.append(badge);
396
+ }
397
+ return button;
398
+ }
399
+ function createAccountControl(shell, account, scope, environment) {
400
+ const root = document.createElement('div');
401
+ root.className = 'kui-app-shell-account';
402
+ root.setAttribute('data-state', account.menuExpanded === true ? 'open' : 'closed');
403
+ root.append(createAccountButton(shell, account, scope, environment));
404
+ if ((account.menu?.length ?? 0) > 0) {
405
+ root.append(createAccountMenu(shell, account, scope, environment));
406
+ }
407
+ return root;
408
+ }
409
+ function createAccountButton(shell, account, scope, environment) {
410
+ const button = document.createElement('button');
411
+ const menuId = `${shell.id}-account-menu`;
412
+ button.type = 'button';
413
+ button.className = 'kui-app-shell-account-button';
414
+ button.setAttribute('aria-label', account.label);
415
+ button.setAttribute('data-action-id', 'account');
416
+ button.setAttribute('data-app-shell-intent', 'open-account-menu');
417
+ button.setAttribute('data-state', account.menuExpanded === true ? 'open' : 'closed');
418
+ if ((account.menu?.length ?? 0) > 0) {
419
+ button.setAttribute('aria-haspopup', 'menu');
420
+ button.setAttribute('aria-controls', menuId);
421
+ button.setAttribute('aria-expanded', account.menuExpanded === true ? 'true' : 'false');
422
+ }
423
+ const avatar = document.createElement('span');
424
+ avatar.className = 'kui-app-shell-avatar';
425
+ avatar.setAttribute('aria-hidden', 'true');
426
+ appendIcon(avatar, account.icon, 'kui-app-shell-icon', scope, environment);
427
+ if (avatar.childNodes.length === 0)
428
+ avatar.textContent = account.initials ?? account.label.slice(0, 2);
429
+ const name = document.createElement('span');
430
+ name.className = 'kui-app-shell-user-name';
431
+ name.textContent = account.label;
432
+ button.append(avatar, name);
433
+ return button;
434
+ }
435
+ function createAccountMenu(shell, account, scope, environment) {
436
+ const menu = document.createElement('div');
437
+ menu.id = `${shell.id}-account-menu`;
438
+ menu.className = 'kui-app-shell-account-menu';
439
+ menu.setAttribute('role', 'menu');
440
+ menu.setAttribute('aria-label', `${account.label} account menu`);
441
+ menu.setAttribute('data-state', account.menuExpanded === true ? 'open' : 'closed');
442
+ menu.hidden = account.menuExpanded !== true;
443
+ const header = document.createElement('div');
444
+ header.className = 'kui-app-shell-account-menu-header';
445
+ header.setAttribute('aria-hidden', 'true');
446
+ const avatar = document.createElement('span');
447
+ avatar.className = 'kui-app-shell-avatar';
448
+ appendIcon(avatar, account.icon, 'kui-app-shell-icon', scope, environment);
449
+ if (avatar.childNodes.length === 0)
450
+ avatar.textContent = account.initials ?? account.label.slice(0, 2);
451
+ const label = document.createElement('span');
452
+ label.className = 'kui-app-shell-account-menu-label';
453
+ label.textContent = account.label;
454
+ header.append(avatar, label);
455
+ menu.append(header);
456
+ for (const item of account.menu ?? []) {
457
+ menu.append(createAccountMenuItem(item, scope, environment));
458
+ }
459
+ return menu;
460
+ }
461
+ function createAccountMenuItem(item, scope, environment) {
462
+ if (item.kind === 'separator') {
463
+ const separator = document.createElement('div');
464
+ separator.className = 'kui-app-shell-account-menu-separator';
465
+ separator.setAttribute('role', 'separator');
466
+ separator.setAttribute('data-account-menu-id', item.id);
467
+ return separator;
468
+ }
469
+ const href = item.disabled === true ? undefined : (item.href ?? item.route);
470
+ const element = href === undefined ? document.createElement('button') : document.createElement('a');
471
+ element.className = joinClasses('kui-app-shell-account-menu-item', item.tone === 'danger' ? 'kui-app-shell-account-menu-item--danger' : undefined);
472
+ if (href === undefined && element instanceof HTMLButtonElement) {
473
+ element.type = 'button';
474
+ }
475
+ else if (href !== undefined && element instanceof HTMLAnchorElement) {
476
+ setHref(element, href, environment);
477
+ }
478
+ element.setAttribute('role', 'menuitem');
479
+ element.setAttribute('data-account-menu-id', item.id);
480
+ element.setAttribute('data-label', item.label ?? item.id);
481
+ element.setAttribute('data-tone', item.tone ?? 'default');
482
+ if (item.disabled === true) {
483
+ element.setAttribute('aria-disabled', 'true');
484
+ element.setAttribute('tabindex', '-1');
485
+ }
486
+ appendIcon(element, item.icon, 'kui-app-shell-icon', scope, environment);
487
+ const label = document.createElement('span');
488
+ label.className = 'kui-app-shell-account-menu-item-label';
489
+ label.textContent = item.label ?? item.id;
490
+ element.append(label);
491
+ return element;
492
+ }
493
+ function renderNavItems(nav, items, activeId, scope, environment) {
494
+ nav.replaceChildren(...items.map((item) => createNavItemElement(item, activeId, scope, environment)));
495
+ }
496
+ function createNavItemElement(item, activeId, scope, environment) {
497
+ const active = item.id === activeId || item.active === true;
498
+ const disabled = item.disabled === true;
499
+ const anchor = document.createElement('a');
500
+ anchor.className = 'kui-app-shell-nav-item';
501
+ if (!disabled)
502
+ setHref(anchor, routeItemPath(item) ?? '#', environment);
503
+ anchor.setAttribute('aria-label', item.label);
504
+ anchor.setAttribute('data-nav-id', item.id);
505
+ anchor.setAttribute('data-label', item.label);
506
+ anchor.setAttribute('data-tooltip', item.label);
507
+ anchor.setAttribute('data-state', disabled ? 'disabled' : active ? 'active' : (item.state ?? 'ready'));
508
+ anchor.setAttribute('data-tone', item.tone ?? 'default');
509
+ setOptionalAttribute(anchor, 'data-route-target', routeItemPath(item));
510
+ if (active)
511
+ anchor.setAttribute('aria-current', 'page');
512
+ if (disabled) {
513
+ anchor.setAttribute('aria-disabled', 'true');
514
+ anchor.setAttribute('tabindex', '-1');
515
+ }
516
+ const icon = document.createElement('span');
517
+ icon.className = 'kui-app-shell-nav-item-icon';
518
+ appendIcon(icon, item.icon, 'kui-app-shell-icon', scope, environment);
519
+ const label = document.createElement('span');
520
+ label.className = 'kui-app-shell-nav-item-label';
521
+ label.textContent = item.label;
522
+ anchor.append(icon, label);
523
+ if (item.badge !== undefined) {
524
+ const badge = document.createElement('span');
525
+ badge.className = 'kui-app-shell-nav-badge';
526
+ badge.setAttribute('aria-hidden', 'true');
527
+ badge.textContent = String(item.badge);
528
+ anchor.append(badge);
529
+ }
530
+ return anchor;
531
+ }
532
+ function appendIcon(parent, iconName, className, scope, _environment) {
533
+ if (iconName === undefined)
534
+ return;
535
+ const icon = resolveUiIcon(scope.icons, iconName);
536
+ if (icon === undefined)
537
+ return;
538
+ const svg = createIconElement(document, icon, { decorative: true, size: 20 });
539
+ svg.classList.add(className);
540
+ svg.setAttribute('data-icon-name', icon.name);
541
+ parent.append(svg);
542
+ }
543
+ function routeItemPath(item) {
544
+ const path = item.route ?? item.href;
545
+ return path === undefined ? undefined : normalizeRoutePath(path);
546
+ }
547
+ function normalizeRoutePath(path) {
548
+ const [withoutHash] = path.split('#', 1);
549
+ const [withoutQuery] = (withoutHash ?? path).split('?', 1);
550
+ const normalized = withoutQuery === '' ? '/' : (withoutQuery ?? '/');
551
+ return normalized.length > 1 ? normalized.replace(/\/+$/u, '') : normalized;
552
+ }
553
+ function setHref(anchor, href, environment) {
554
+ const resolved = environment.security.urlPolicy.resolve(href, {
555
+ element: 'a',
556
+ attribute: 'href',
557
+ });
558
+ if (resolved !== null)
559
+ anchor.setAttribute('href', resolved);
560
+ }
561
+ function setOptionalAttribute(element, name, value) {
562
+ if (typeof value === 'string' || typeof value === 'number') {
563
+ element.setAttribute(name, String(value));
564
+ }
565
+ else {
566
+ element.removeAttribute(name);
567
+ }
568
+ }
569
+ function joinClasses(...classes) {
570
+ return classes
571
+ .filter((className) => className !== undefined && className.length > 0)
572
+ .join(' ');
573
+ }