@spfx-fast/sharepoint-ui 0.4.3 → 0.5.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 (282) hide show
  1. package/QUICKSTART.md +13 -128
  2. package/README.md +19 -26
  3. package/components.json +240 -5834
  4. package/dist/accordion.d.ts +11 -0
  5. package/dist/accordion.js +4 -0
  6. package/dist/alert.d.ts +3 -0
  7. package/dist/alert.js +4 -0
  8. package/dist/attachment-list.d.ts +15 -0
  9. package/dist/attachment-list.js +14 -0
  10. package/dist/avatar-group.d.ts +12 -0
  11. package/dist/avatar-group.js +7 -0
  12. package/dist/avatar.d.ts +6 -0
  13. package/dist/avatar.js +5 -0
  14. package/dist/badge.d.ts +3 -0
  15. package/dist/badge.js +4 -0
  16. package/dist/breadcrumb.d.ts +10 -0
  17. package/dist/breadcrumb.js +9 -0
  18. package/dist/button-group.d.ts +6 -0
  19. package/dist/button-group.js +4 -0
  20. package/dist/button.d.ts +3 -0
  21. package/dist/button.js +4 -0
  22. package/dist/card.d.ts +3 -0
  23. package/dist/card.js +4 -0
  24. package/dist/carousel.d.ts +11 -0
  25. package/dist/carousel.js +6 -0
  26. package/dist/checkbox.d.ts +3 -0
  27. package/dist/checkbox.js +4 -0
  28. package/dist/combobox.d.ts +9 -0
  29. package/dist/combobox.js +6 -0
  30. package/dist/command-bar.d.ts +6 -0
  31. package/dist/command-bar.js +4 -0
  32. package/dist/copy-button.d.ts +7 -0
  33. package/dist/copy-button.js +19 -0
  34. package/dist/data-grid.d.ts +25 -0
  35. package/dist/data-grid.js +39 -0
  36. package/dist/date-range-picker.d.ts +12 -0
  37. package/dist/date-range-picker.js +4 -0
  38. package/dist/dialog.d.ts +9 -0
  39. package/dist/dialog.js +21 -0
  40. package/dist/divider.d.ts +3 -0
  41. package/dist/divider.js +4 -0
  42. package/dist/drawer.d.ts +6 -0
  43. package/dist/drawer.js +5 -0
  44. package/dist/empty-state.d.ts +7 -0
  45. package/dist/empty-state.js +5 -0
  46. package/dist/field.d.ts +15 -0
  47. package/dist/field.js +11 -0
  48. package/dist/file-dropzone.d.ts +15 -0
  49. package/dist/file-dropzone.js +21 -0
  50. package/dist/filter-bar.d.ts +9 -0
  51. package/dist/filter-bar.js +9 -0
  52. package/dist/image.d.ts +5 -0
  53. package/dist/image.js +4 -0
  54. package/dist/index.d.ts +68 -78
  55. package/dist/index.js +60 -68
  56. package/dist/input.d.ts +3 -0
  57. package/dist/input.js +4 -0
  58. package/dist/label.d.ts +3 -0
  59. package/dist/label.js +4 -0
  60. package/dist/link.d.ts +3 -0
  61. package/dist/link.js +9 -0
  62. package/dist/list-view.d.ts +29 -0
  63. package/dist/list-view.js +14 -0
  64. package/dist/list.d.ts +6 -0
  65. package/dist/list.js +5 -0
  66. package/dist/lookup-picker.d.ts +12 -0
  67. package/dist/lookup-picker.js +4 -0
  68. package/dist/menu.d.ts +6 -0
  69. package/dist/menu.js +4 -0
  70. package/dist/nav.d.ts +12 -0
  71. package/dist/nav.js +4 -0
  72. package/dist/pagination.d.ts +11 -0
  73. package/dist/pagination.js +5 -0
  74. package/dist/person-picker.d.ts +13 -0
  75. package/dist/person-picker.js +4 -0
  76. package/dist/persona.d.ts +7 -0
  77. package/dist/persona.js +5 -0
  78. package/dist/popover.d.ts +6 -0
  79. package/dist/popover.js +4 -0
  80. package/dist/progress-bar.d.ts +5 -0
  81. package/dist/progress-bar.js +5 -0
  82. package/dist/radio-group.d.ts +6 -0
  83. package/dist/radio-group.js +4 -0
  84. package/dist/radio.d.ts +3 -0
  85. package/dist/radio.js +4 -0
  86. package/dist/rating.d.ts +8 -0
  87. package/dist/rating.js +5 -0
  88. package/dist/react.d.ts +1 -4715
  89. package/dist/react.js +1 -7097
  90. package/dist/select.d.ts +3 -0
  91. package/dist/select.js +4 -0
  92. package/dist/sharepoint-field.d.ts +18 -0
  93. package/dist/sharepoint-field.js +54 -0
  94. package/dist/skeleton.d.ts +6 -0
  95. package/dist/skeleton.js +9 -0
  96. package/dist/spinner.d.ts +5 -0
  97. package/dist/spinner.js +4 -0
  98. package/dist/swatch-picker.d.ts +17 -0
  99. package/dist/swatch-picker.js +11 -0
  100. package/dist/switch.d.ts +3 -0
  101. package/dist/switch.js +4 -0
  102. package/dist/table.d.ts +6 -0
  103. package/dist/table.js +4 -0
  104. package/dist/tabs.d.ts +14 -0
  105. package/dist/tabs.js +30 -0
  106. package/dist/tag-group.d.ts +6 -0
  107. package/dist/tag-group.js +4 -0
  108. package/dist/tag-picker.d.ts +12 -0
  109. package/dist/tag-picker.js +4 -0
  110. package/dist/tag.d.ts +7 -0
  111. package/dist/tag.js +5 -0
  112. package/dist/text.d.ts +5 -0
  113. package/dist/text.js +4 -0
  114. package/dist/textarea.d.ts +3 -0
  115. package/dist/textarea.js +4 -0
  116. package/dist/theme.d.ts +15 -175
  117. package/dist/theme.js +36 -239
  118. package/dist/toast.d.ts +9 -0
  119. package/dist/toast.js +12 -0
  120. package/dist/tree.d.ts +13 -0
  121. package/dist/tree.js +9 -0
  122. package/dist/view-card.d.ts +8 -0
  123. package/dist/view-card.js +4 -0
  124. package/dist/view-switcher.d.ts +13 -0
  125. package/dist/view-switcher.js +7 -0
  126. package/dist/virtual-list.d.ts +11 -0
  127. package/dist/virtual-list.js +25 -0
  128. package/measurements.json +365 -0
  129. package/package.json +14 -46
  130. package/src/theme.css +125 -0
  131. package/AGENTS.md +0 -231
  132. package/dist/appearance.d.ts +0 -6
  133. package/dist/appearance.js +0 -217
  134. package/dist/elements/accordion.d.ts +0 -9
  135. package/dist/elements/accordion.js +0 -338
  136. package/dist/elements/alert.d.ts +0 -2
  137. package/dist/elements/alert.js +0 -86
  138. package/dist/elements/avatar-group-primitives.d.ts +0 -3
  139. package/dist/elements/avatar-group-primitives.js +0 -189
  140. package/dist/elements/avatar-group.d.ts +0 -2
  141. package/dist/elements/avatar-group.js +0 -110
  142. package/dist/elements/avatar.d.ts +0 -4
  143. package/dist/elements/avatar.js +0 -251
  144. package/dist/elements/badge.d.ts +0 -8
  145. package/dist/elements/badge.js +0 -182
  146. package/dist/elements/breadcrumb.d.ts +0 -4
  147. package/dist/elements/breadcrumb.js +0 -233
  148. package/dist/elements/button-group.d.ts +0 -1
  149. package/dist/elements/button-group.js +0 -20
  150. package/dist/elements/button-variants.d.ts +0 -6
  151. package/dist/elements/button-variants.js +0 -339
  152. package/dist/elements/button.d.ts +0 -5
  153. package/dist/elements/button.js +0 -233
  154. package/dist/elements/card-primitives.d.ts +0 -3
  155. package/dist/elements/card-primitives.js +0 -83
  156. package/dist/elements/card.d.ts +0 -5
  157. package/dist/elements/card.js +0 -213
  158. package/dist/elements/carousel.d.ts +0 -92
  159. package/dist/elements/carousel.js +0 -1115
  160. package/dist/elements/color-picker.d.ts +0 -24
  161. package/dist/elements/color-picker.js +0 -1004
  162. package/dist/elements/combobox.d.ts +0 -1
  163. package/dist/elements/combobox.js +0 -1012
  164. package/dist/elements/data-grid-model.d.ts +0 -120
  165. package/dist/elements/data-grid-model.js +0 -294
  166. package/dist/elements/data-grid.d.ts +0 -30
  167. package/dist/elements/data-grid.js +0 -1576
  168. package/dist/elements/date-picker.d.ts +0 -1
  169. package/dist/elements/date-picker.js +0 -486
  170. package/dist/elements/dialog.d.ts +0 -23
  171. package/dist/elements/dialog.js +0 -409
  172. package/dist/elements/divider.d.ts +0 -2
  173. package/dist/elements/divider.js +0 -66
  174. package/dist/elements/drawer.d.ts +0 -3
  175. package/dist/elements/drawer.js +0 -308
  176. package/dist/elements/field-composition.d.ts +0 -26
  177. package/dist/elements/field-composition.js +0 -133
  178. package/dist/elements/field.d.ts +0 -1
  179. package/dist/elements/field.js +0 -67
  180. package/dist/elements/file-upload.d.ts +0 -6
  181. package/dist/elements/file-upload.js +0 -211
  182. package/dist/elements/floating-position.d.ts +0 -36
  183. package/dist/elements/floating-position.js +0 -92
  184. package/dist/elements/image.d.ts +0 -28
  185. package/dist/elements/image.js +0 -38
  186. package/dist/elements/info.d.ts +0 -9
  187. package/dist/elements/info.js +0 -102
  188. package/dist/elements/input.d.ts +0 -5
  189. package/dist/elements/input.js +0 -255
  190. package/dist/elements/label.d.ts +0 -15
  191. package/dist/elements/label.js +0 -56
  192. package/dist/elements/link.d.ts +0 -1
  193. package/dist/elements/link.js +0 -92
  194. package/dist/elements/list.d.ts +0 -19
  195. package/dist/elements/list.js +0 -297
  196. package/dist/elements/menu.d.ts +0 -33
  197. package/dist/elements/menu.js +0 -1103
  198. package/dist/elements/message-bar.d.ts +0 -10
  199. package/dist/elements/message-bar.js +0 -327
  200. package/dist/elements/nav.d.ts +0 -32
  201. package/dist/elements/nav.js +0 -794
  202. package/dist/elements/overflow.d.ts +0 -10
  203. package/dist/elements/overflow.js +0 -218
  204. package/dist/elements/persona.d.ts +0 -3
  205. package/dist/elements/persona.js +0 -125
  206. package/dist/elements/popover.d.ts +0 -77
  207. package/dist/elements/popover.js +0 -840
  208. package/dist/elements/progress-bar.d.ts +0 -4
  209. package/dist/elements/progress-bar.js +0 -82
  210. package/dist/elements/radio-group.d.ts +0 -1
  211. package/dist/elements/radio-group.js +0 -303
  212. package/dist/elements/rating-display.d.ts +0 -2
  213. package/dist/elements/rating-display.js +0 -125
  214. package/dist/elements/rating.d.ts +0 -2
  215. package/dist/elements/rating.js +0 -206
  216. package/dist/elements/rich-text-editor.d.ts +0 -32
  217. package/dist/elements/rich-text-editor.js +0 -1367
  218. package/dist/elements/search.d.ts +0 -3
  219. package/dist/elements/search.js +0 -200
  220. package/dist/elements/select.d.ts +0 -6
  221. package/dist/elements/select.js +0 -291
  222. package/dist/elements/shared.d.ts +0 -22
  223. package/dist/elements/shared.js +0 -409
  224. package/dist/elements/sharepoint-field-basic-controls.d.ts +0 -1
  225. package/dist/elements/sharepoint-field-basic-controls.js +0 -14
  226. package/dist/elements/sharepoint-fields.d.ts +0 -29
  227. package/dist/elements/sharepoint-fields.js +0 -460
  228. package/dist/elements/skeleton.d.ts +0 -6
  229. package/dist/elements/skeleton.js +0 -91
  230. package/dist/elements/slider.d.ts +0 -1
  231. package/dist/elements/slider.js +0 -248
  232. package/dist/elements/spin-button.d.ts +0 -7
  233. package/dist/elements/spin-button.js +0 -499
  234. package/dist/elements/spinner.d.ts +0 -4
  235. package/dist/elements/spinner.js +0 -124
  236. package/dist/elements/swatch-picker.d.ts +0 -5
  237. package/dist/elements/swatch-picker.js +0 -363
  238. package/dist/elements/table.d.ts +0 -21
  239. package/dist/elements/table.js +0 -261
  240. package/dist/elements/tabs.d.ts +0 -1
  241. package/dist/elements/tabs.js +0 -276
  242. package/dist/elements/tag-picker.d.ts +0 -29
  243. package/dist/elements/tag-picker.js +0 -715
  244. package/dist/elements/tags.d.ts +0 -21
  245. package/dist/elements/tags.js +0 -421
  246. package/dist/elements/teaching-popover.d.ts +0 -32
  247. package/dist/elements/teaching-popover.js +0 -412
  248. package/dist/elements/text.d.ts +0 -9
  249. package/dist/elements/text.js +0 -75
  250. package/dist/elements/textarea.d.ts +0 -1
  251. package/dist/elements/textarea.js +0 -182
  252. package/dist/elements/toast.d.ts +0 -25
  253. package/dist/elements/toast.js +0 -337
  254. package/dist/elements/toaster.d.ts +0 -6
  255. package/dist/elements/toaster.js +0 -357
  256. package/dist/elements/toggle.d.ts +0 -2
  257. package/dist/elements/toggle.js +0 -246
  258. package/dist/elements/toolbar.d.ts +0 -12
  259. package/dist/elements/toolbar.js +0 -381
  260. package/dist/elements/tooltip.d.ts +0 -76
  261. package/dist/elements/tooltip.js +0 -527
  262. package/dist/elements/tree-model.d.ts +0 -19
  263. package/dist/elements/tree-model.js +0 -34
  264. package/dist/elements/tree.d.ts +0 -5
  265. package/dist/elements/tree.js +0 -273
  266. package/dist/elements/view-card.d.ts +0 -2
  267. package/dist/elements/view-card.js +0 -78
  268. package/dist/elements/virtual-list.d.ts +0 -41
  269. package/dist/elements/virtual-list.js +0 -369
  270. package/dist/elements.d.ts +0 -73
  271. package/dist/elements.js +0 -210
  272. package/dist/sharepoint-fields.d.ts +0 -135
  273. package/dist/sharepoint-fields.js +0 -402
  274. package/dist/virtualizer-hooks.d.ts +0 -80
  275. package/dist/virtualizer-hooks.js +0 -253
  276. package/scripts/generate-token-index.mjs +0 -43
  277. package/scripts/sync-component-catalog-signatures.mjs +0 -55
  278. package/scripts/validate-component-catalog.mjs +0 -44
  279. package/skills/sharepoint-ui/SKILL.md +0 -12
  280. package/skills/sharepoint-ui/references/choosing-components.md +0 -20
  281. package/skills/sharepoint-ui/references/sharepoint-patterns.md +0 -17
  282. package/tokens.json +0 -3777
@@ -1,794 +0,0 @@
1
- import { base } from "./shared.js";
2
- import { buttonControlCss } from "./button.js";
3
- let nextNavId = 0;
4
- export function defineNav() {
5
- defineNavItem();
6
- defineAppItem();
7
- defineAppItemStatic();
8
- defineSplitNavItem();
9
- defineHamburger();
10
- defineNavDrawer();
11
- defineNavDrawerHeader();
12
- defineNavDrawerBody();
13
- defineNavDrawerFooter();
14
- defineNavCategory();
15
- defineNavCategoryItem();
16
- defineNavSubItemGroup();
17
- defineNavSubItem();
18
- defineNavDivider();
19
- defineNavSectionHeader();
20
- if (customElements.get("spui-nav"))
21
- return;
22
- class SpuiNav extends HTMLElement {
23
- static observedAttributes = ["label", "aria-label", "density", "multiple", "tabbable", "open", "open-label", "close-label", "collapsible", "collapsed", "full-width", "expand-label", "collapse-label"];
24
- observer;
25
- events;
26
- breakpoint;
27
- current = null;
28
- currentCategory = null;
29
- currentControlled = false;
30
- currentCategoryControlled = false;
31
- categoriesOpen = new Set();
32
- categoriesOpenControlled = false;
33
- drawerOpenControlled = false;
34
- drawerOpen = false;
35
- reflectingOpen = false;
36
- collapsedControlled = false;
37
- reflectingCollapsed = false;
38
- nextGroupId = 0;
39
- get open() { return this.drawerOpen; }
40
- set open(value) { this.drawerOpenControlled = true; this.setDrawerOpen(Boolean(value)); }
41
- get defaultOpen() { return this.drawerOpen; }
42
- set defaultOpen(value) { if (!this.drawerOpenControlled)
43
- this.setDrawerOpen(Boolean(value)); }
44
- get collapsed() { return this.hasAttribute("collapsed"); }
45
- set collapsed(value) { this.collapsedControlled = true; this.setCollapsed(Boolean(value)); }
46
- get defaultCollapsed() { return this.collapsed; }
47
- set defaultCollapsed(value) { if (!this.collapsedControlled)
48
- this.setCollapsed(Boolean(value)); }
49
- get fullWidth() { return this.hasAttribute("full-width"); }
50
- set fullWidth(value) { this.toggleAttribute("full-width", Boolean(value)); }
51
- connectedCallback() {
52
- if (!this.shadowRoot)
53
- this.render();
54
- this.observer = new MutationObserver(() => this.sync());
55
- this.observer.observe(this, { childList: true, subtree: true });
56
- this.events?.abort();
57
- this.events = new AbortController();
58
- this.breakpoint?.removeEventListener("change", this.onBreakpointChange);
59
- this.breakpoint = window.matchMedia("(max-width: 640px)");
60
- this.breakpoint.addEventListener("change", this.onBreakpointChange);
61
- window.addEventListener("resize", this.onBreakpointChange);
62
- this.addEventListener("click", event => this.onClick(event), { signal: this.events.signal });
63
- this.addEventListener("keydown", event => {
64
- if (this.handleRovingKeydown(event))
65
- return;
66
- if (event.key !== "Escape" || !this.drawerOpen)
67
- return;
68
- if (this.getAttribute("data-drawer-type") === "inline")
69
- this.requestOpen(false);
70
- requestAnimationFrame(() => this.shadowRoot?.querySelector(".mobile-toggle")?.focus());
71
- }, { signal: this.events.signal });
72
- this.addEventListener("focusin", event => this.syncTabStops(event.composedPath().find(node => node instanceof HTMLElement && this.navControl(node))), { signal: this.events.signal });
73
- const nav = this.shadowRoot?.querySelector("nav");
74
- nav?.addEventListener("toggle", () => this.onPopoverToggle(), { signal: this.events.signal });
75
- this.sync();
76
- this.syncResponsive();
77
- }
78
- disconnectedCallback() { this.observer?.disconnect(); this.events?.abort(); this.breakpoint?.removeEventListener("change", this.onBreakpointChange); window.removeEventListener("resize", this.onBreakpointChange); }
79
- attributeChangedCallback(name) {
80
- if (name === "open" && !this.reflectingOpen) {
81
- this.drawerOpenControlled = true;
82
- this.drawerOpen = this.hasAttribute("open");
83
- }
84
- if (name === "collapsed" && !this.reflectingCollapsed)
85
- this.syncResponsive();
86
- if (!this.isConnected)
87
- return;
88
- if (name === "label" || name === "aria-label")
89
- this.shadowRoot?.querySelector("nav")?.setAttribute("aria-label", this.getAttribute("aria-label") ?? this.getAttribute("label") ?? "Navigation");
90
- this.sync();
91
- }
92
- get selectedValue() { return this.current; }
93
- set selectedValue(value) { this.currentControlled = true; this.current = value; this.sync(); }
94
- get defaultSelectedValue() { return this.current; }
95
- set defaultSelectedValue(value) { if (!this.currentControlled) {
96
- this.current = value;
97
- this.sync();
98
- } }
99
- get selectedCategoryValue() { return this.currentCategory; }
100
- set selectedCategoryValue(value) { this.currentCategoryControlled = true; this.currentCategory = value; this.sync(); }
101
- get defaultSelectedCategoryValue() { return this.currentCategory; }
102
- set defaultSelectedCategoryValue(value) { if (!this.currentCategoryControlled) {
103
- this.currentCategory = value;
104
- this.sync();
105
- } }
106
- get openCategories() { return [...this.categoriesOpen]; }
107
- set openCategories(values) { this.categoriesOpenControlled = true; this.categoriesOpen = new Set(values); this.sync(); }
108
- get defaultOpenCategories() { return [...this.categoriesOpen]; }
109
- set defaultOpenCategories(values) { if (!this.categoriesOpenControlled) {
110
- this.categoriesOpen = new Set(this.allowsMultipleCategories() ? values : values.slice(0, 1));
111
- this.sync();
112
- } }
113
- allowsMultipleCategories() { return this.getAttribute("multiple") !== "false"; }
114
- onBreakpointChange = () => {
115
- if (!this.breakpoint?.matches && this.drawerOpen)
116
- this.requestOpen(false);
117
- this.syncResponsive();
118
- };
119
- navControls() {
120
- return [...this.querySelectorAll("spui-nav-item, spui-app-item, spui-nav-sub-item, spui-nav-category-item")].filter(host => {
121
- if (host.hasAttribute("disabled") || host.closest("spui-nav-sub-item-group")?.hidden)
122
- return false;
123
- return Boolean(this.navControl(host));
124
- });
125
- }
126
- navControl(host) { return host.shadowRoot?.querySelector("a,button") ?? null; }
127
- syncTabStops(preferred) {
128
- const items = this.navControls();
129
- const roving = this.getAttribute("tabbable") === "false";
130
- const active = preferred ?? items.find(item => item.shadowRoot?.activeElement) ?? items.find(item => item.hasAttribute("selected")) ?? items[0];
131
- for (const item of items)
132
- this.navControl(item)?.setAttribute("tabindex", String(!roving || item === active ? 0 : -1));
133
- }
134
- handleRovingKeydown(event) {
135
- if (this.getAttribute("tabbable") !== "false")
136
- return false;
137
- const host = event.composedPath().find(node => node instanceof HTMLElement && this.navControl(node));
138
- if (!host)
139
- return false;
140
- const items = this.navControls();
141
- const current = items.indexOf(host);
142
- if (current < 0)
143
- return false;
144
- let next = current;
145
- if (event.key === "ArrowDown")
146
- next = Math.min(items.length - 1, current + 1);
147
- else if (event.key === "ArrowUp")
148
- next = Math.max(0, current - 1);
149
- else if (event.key === "Home")
150
- next = 0;
151
- else if (event.key === "End")
152
- next = items.length - 1;
153
- else
154
- return false;
155
- event.preventDefault();
156
- this.syncTabStops(items[next]);
157
- this.navControl(items[next])?.focus();
158
- return true;
159
- }
160
- setDrawerOpen(value, notify = false) {
161
- if (value === this.drawerOpen) {
162
- this.syncResponsive();
163
- return;
164
- }
165
- this.drawerOpen = value;
166
- this.reflectingOpen = true;
167
- this.toggleAttribute("open", value);
168
- this.reflectingOpen = false;
169
- this.syncResponsive();
170
- if (notify)
171
- this.dispatchEvent(new CustomEvent("spui-nav-open-change", { bubbles: true, composed: true, detail: { open: value } }));
172
- }
173
- requestOpen(value) {
174
- if (this.drawerOpenControlled) {
175
- if (value !== this.drawerOpen)
176
- this.dispatchEvent(new CustomEvent("spui-nav-open-change", { bubbles: true, composed: true, detail: { open: value } }));
177
- }
178
- else
179
- this.setDrawerOpen(value, true);
180
- }
181
- onPopoverToggle() {
182
- const nav = this.shadowRoot?.querySelector("nav");
183
- const value = nav?.matches(":popover-open") ?? false;
184
- if (value === this.drawerOpen)
185
- return;
186
- if (this.drawerOpenControlled)
187
- this.dispatchEvent(new CustomEvent("spui-nav-open-change", { bubbles: true, composed: true, detail: { open: value } }));
188
- else
189
- this.setDrawerOpen(value, true);
190
- }
191
- syncResponsive() {
192
- const nav = this.shadowRoot?.querySelector("nav");
193
- const toggle = this.shadowRoot?.querySelector(".mobile-toggle");
194
- const close = this.shadowRoot?.querySelector(".mobile-close");
195
- const railToggle = this.shadowRoot?.querySelector(".rail-toggle");
196
- if (!nav || !toggle || !close || !railToggle)
197
- return;
198
- const mobile = this.breakpoint?.matches ?? window.matchMedia("(max-width: 640px)").matches;
199
- const inlineDrawer = this.getAttribute("data-drawer-type") === "inline";
200
- this.toggleAttribute("data-mobile", mobile);
201
- this.toggleAttribute("data-collapsed", !mobile && this.collapsed);
202
- this.dataset.direction = getComputedStyle(this).direction;
203
- toggle.hidden = !mobile;
204
- toggle.setAttribute("aria-expanded", String(mobile && this.drawerOpen));
205
- toggle.setAttribute("aria-label", this.drawerOpen ? this.getAttribute("close-label") ?? "Close navigation" : this.getAttribute("open-label") ?? "Open navigation");
206
- close.setAttribute("aria-label", this.getAttribute("close-label") ?? "Close navigation");
207
- close.hidden = !mobile;
208
- railToggle.hidden = mobile || !this.hasAttribute("collapsible");
209
- railToggle.setAttribute("aria-expanded", String(!this.collapsed));
210
- railToggle.setAttribute("aria-label", this.getAttribute(this.collapsed ? "expand-label" : "collapse-label") ?? (this.collapsed ? "Expand navigation" : "Collapse navigation"));
211
- railToggle.title = this.getAttribute(this.collapsed ? "expand-label" : "collapse-label") ?? (this.collapsed ? "Expand navigation" : "Collapse navigation");
212
- for (const item of this.querySelectorAll("spui-nav-item, spui-app-item, spui-nav-sub-item, spui-nav-category-item, spui-nav-sub-item-group, spui-nav-divider, spui-nav-section-header"))
213
- item.toggleAttribute("compact", !mobile && this.collapsed);
214
- if (!mobile) {
215
- if (nav.matches(":popover-open"))
216
- nav.hidePopover();
217
- nav.removeAttribute("popover");
218
- nav.hidden = false;
219
- }
220
- else if (inlineDrawer) {
221
- if (nav.matches(":popover-open"))
222
- nav.hidePopover();
223
- nav.removeAttribute("popover");
224
- nav.hidden = !this.drawerOpen;
225
- }
226
- else if (typeof nav.showPopover === "function") {
227
- nav.hidden = false;
228
- if (!nav.hasAttribute("popover"))
229
- nav.setAttribute("popover", "auto");
230
- if (this.drawerOpen && !nav.matches(":popover-open"))
231
- nav.showPopover();
232
- else if (!this.drawerOpen && nav.matches(":popover-open"))
233
- nav.hidePopover();
234
- }
235
- else {
236
- this.toggleAttribute("data-popover-fallback", true);
237
- nav.hidden = !this.drawerOpen;
238
- }
239
- }
240
- onClick(event) {
241
- const path = event.composedPath();
242
- const mobile = this.breakpoint?.matches ?? false;
243
- if (mobile && this.getAttribute("data-drawer-type") === "inline" && path.some(node => node instanceof HTMLElement && node.classList.contains("mobile-toggle"))) {
244
- event.preventDefault();
245
- this.requestOpen(!this.drawerOpen);
246
- return;
247
- }
248
- if (mobile && this.getAttribute("data-drawer-type") === "inline" && path.some(node => node instanceof HTMLElement && node.classList.contains("mobile-close"))) {
249
- event.preventDefault();
250
- this.requestOpen(false);
251
- this.shadowRoot?.querySelector(".mobile-toggle")?.focus();
252
- return;
253
- }
254
- if (path.some(node => node instanceof HTMLElement && node.classList.contains("rail-toggle"))) {
255
- const collapsed = !this.collapsed;
256
- if (this.collapsedControlled)
257
- this.dispatchEvent(new CustomEvent("spui-nav-collapsed-change", { bubbles: true, composed: true, detail: { collapsed } }));
258
- else
259
- this.setCollapsed(collapsed, true);
260
- return;
261
- }
262
- const categoryItem = path.find(node => node instanceof HTMLElement && node.localName === "spui-nav-category-item");
263
- if (categoryItem) {
264
- const category = categoryItem.parentElement?.closest("spui-nav-category");
265
- const value = category?.getAttribute("value") ?? "";
266
- if (!value || category?.hasAttribute("disabled"))
267
- return;
268
- if (!this.currentCategoryControlled)
269
- this.currentCategory = value;
270
- const next = new Set(this.categoriesOpen);
271
- if (next.has(value))
272
- next.delete(value);
273
- else {
274
- if (!this.allowsMultipleCategories())
275
- next.clear();
276
- next.add(value);
277
- }
278
- if (!this.categoriesOpenControlled)
279
- this.categoriesOpen = next;
280
- this.sync();
281
- const categoryIndex = path.indexOf(category);
282
- const parentCategory = categoryIndex >= 0 ? path.slice(categoryIndex + 1).find((node) => node instanceof HTMLElement && node.localName === "spui-nav-category") ?? null : null;
283
- this.dispatchEvent(new CustomEvent("spui-nav-category-toggle", { bubbles: true, composed: true, detail: { value, categoryValue: parentCategory?.getAttribute("value") ?? undefined, open: next.has(value), openCategories: [...next], event, type: "click" } }));
284
- return;
285
- }
286
- const item = path.find(node => node instanceof HTMLElement && (node.localName === "spui-nav-item" || node.localName === "spui-app-item" || node.localName === "spui-nav-sub-item"));
287
- if (!item)
288
- return;
289
- if (item.hasAttribute("disabled")) {
290
- event.preventDefault();
291
- return;
292
- }
293
- const value = item.getAttribute("value") ?? "";
294
- if (!value)
295
- return;
296
- if (!this.currentControlled)
297
- this.current = value;
298
- this.sync();
299
- const category = path.find((node) => node instanceof HTMLElement && node.localName === "spui-nav-category") ?? null;
300
- this.dispatchEvent(new CustomEvent("spui-nav-item-select", { bubbles: true, composed: true, detail: { value, href: item.getAttribute("href"), label: item.textContent?.trim() ?? "", categoryValue: category?.getAttribute("value") ?? undefined, event, type: "click" } }));
301
- if (this.breakpoint?.matches && this.drawerOpen)
302
- this.requestOpen(false);
303
- }
304
- setCollapsed(value, notify = false) {
305
- if (value === this.collapsed)
306
- return;
307
- this.reflectingCollapsed = true;
308
- this.toggleAttribute("collapsed", value);
309
- this.reflectingCollapsed = false;
310
- this.sync();
311
- if (notify)
312
- this.dispatchEvent(new CustomEvent("spui-nav-collapsed-change", { bubbles: true, composed: true, detail: { collapsed: value } }));
313
- }
314
- sync() {
315
- const nav = this.shadowRoot?.querySelector("nav");
316
- if (!nav)
317
- return;
318
- nav.setAttribute("aria-label", this.getAttribute("aria-label") ?? this.getAttribute("label") ?? "Navigation");
319
- let categories = 0;
320
- for (const category of this.querySelectorAll("spui-nav-category")) {
321
- const value = category.getAttribute("value") ?? "";
322
- const categoryItem = category.querySelector("spui-nav-category-item");
323
- const group = category.querySelector("spui-nav-sub-item-group");
324
- if (!category.dataset.spuiGroupId)
325
- category.dataset.spuiGroupId = `spui-nav-group-${++this.nextGroupId}`;
326
- const isOpen = this.categoriesOpen.has(value);
327
- if (categoryItem) {
328
- categoryItem.toggleAttribute("expanded", isOpen);
329
- categoryItem.toggleAttribute("disabled", category.hasAttribute("disabled"));
330
- categoryItem.setAttribute("controls", category.dataset.spuiGroupId);
331
- }
332
- if (group) {
333
- group.id = category.dataset.spuiGroupId;
334
- const navGroup = group;
335
- if (navGroup.setExpanded)
336
- navGroup.setExpanded(isOpen);
337
- else
338
- group.hidden = !isOpen;
339
- }
340
- categories++;
341
- }
342
- for (const item of this.querySelectorAll("spui-nav-item, spui-app-item, spui-nav-sub-item")) {
343
- const selected = item.getAttribute("value") === this.current;
344
- item.toggleAttribute("selected", selected);
345
- }
346
- for (const category of this.querySelectorAll("spui-nav-category")) {
347
- const selected = category.getAttribute("value") === this.currentCategory;
348
- category.toggleAttribute("selected", selected);
349
- category.querySelector("spui-nav-category-item")?.toggleAttribute("selected", selected);
350
- }
351
- this.dataset.density = this.getAttribute("density") ?? "medium";
352
- this.toggleAttribute("data-has-categories", categories > 0);
353
- this.syncTabStops();
354
- this.syncResponsive();
355
- }
356
- render() {
357
- const shadow = this.attachShadow({ mode: "open" });
358
- const nav = document.createElement("nav");
359
- nav.setAttribute("aria-label", this.getAttribute("aria-label") ?? this.getAttribute("label") ?? "Navigation");
360
- nav.part.add("navigation");
361
- nav.id = this.id ? `${this.id}-panel` : `spui-nav-panel-${++nextNavId}`;
362
- const mobileHeader = document.createElement("div");
363
- mobileHeader.className = "mobile-header";
364
- mobileHeader.part.add("mobile-header");
365
- const mobileTitle = document.createElement("span");
366
- mobileTitle.textContent = this.getAttribute("label") ?? "Navigation";
367
- const closeButton = document.createElement("button");
368
- closeButton.type = "button";
369
- closeButton.className = "mobile-close";
370
- closeButton.part.add("mobile-close");
371
- closeButton.setAttribute("popovertarget", nav.id);
372
- closeButton.setAttribute("popovertargetaction", "hide");
373
- closeButton.setAttribute("aria-label", this.getAttribute("close-label") ?? "Close navigation");
374
- const closeIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
375
- closeIcon.setAttribute("viewBox", "0 0 24 24");
376
- closeIcon.setAttribute("width", "20");
377
- closeIcon.setAttribute("height", "20");
378
- closeIcon.setAttribute("aria-hidden", "true");
379
- const closePath = document.createElementNS("http://www.w3.org/2000/svg", "path");
380
- closePath.setAttribute("d", "M5 5l14 14M19 5 5 19");
381
- closePath.setAttribute("fill", "none");
382
- closePath.setAttribute("stroke", "currentColor");
383
- closePath.setAttribute("stroke-width", "1.8");
384
- closePath.setAttribute("stroke-linecap", "round");
385
- closeIcon.append(closePath);
386
- closeButton.append(closeIcon);
387
- mobileHeader.append(mobileTitle, closeButton);
388
- const slot = document.createElement("slot");
389
- nav.append(slot);
390
- nav.prepend(mobileHeader);
391
- const railToggle = document.createElement("button");
392
- railToggle.type = "button";
393
- railToggle.className = "rail-toggle";
394
- railToggle.part.add("rail-toggle");
395
- railToggle.setAttribute("aria-controls", nav.id);
396
- railToggle.setAttribute("aria-expanded", String(!this.collapsed));
397
- railToggle.setAttribute("aria-label", this.getAttribute("collapse-label") ?? "Collapse navigation");
398
- const railIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
399
- railIcon.setAttribute("viewBox", "0 0 24 24");
400
- railIcon.setAttribute("width", "18");
401
- railIcon.setAttribute("height", "18");
402
- railIcon.setAttribute("aria-hidden", "true");
403
- const railPath = document.createElementNS("http://www.w3.org/2000/svg", "path");
404
- railPath.setAttribute("d", "M14 5 7 12l7 7");
405
- railPath.setAttribute("fill", "none");
406
- railPath.setAttribute("stroke", "currentColor");
407
- railPath.setAttribute("stroke-width", "2");
408
- railPath.setAttribute("stroke-linecap", "round");
409
- railPath.setAttribute("stroke-linejoin", "round");
410
- railIcon.append(railPath);
411
- railToggle.append(railIcon);
412
- const toggle = document.createElement("button");
413
- toggle.type = "button";
414
- toggle.className = "mobile-toggle";
415
- toggle.part.add("mobile-toggle");
416
- toggle.setAttribute("popovertarget", nav.id);
417
- toggle.setAttribute("popovertargetaction", "toggle");
418
- toggle.setAttribute("aria-controls", nav.id);
419
- toggle.setAttribute("aria-expanded", "false");
420
- toggle.setAttribute("aria-label", this.getAttribute("open-label") ?? "Open navigation");
421
- const menuIcon = document.createElementNS("http://www.w3.org/2000/svg", "svg");
422
- menuIcon.setAttribute("viewBox", "0 0 24 24");
423
- menuIcon.setAttribute("width", "22");
424
- menuIcon.setAttribute("height", "22");
425
- menuIcon.setAttribute("aria-hidden", "true");
426
- const menuPath = document.createElementNS("http://www.w3.org/2000/svg", "path");
427
- menuPath.setAttribute("d", "M4 6h16M4 12h16M4 18h16");
428
- menuPath.setAttribute("fill", "none");
429
- menuPath.setAttribute("stroke", "currentColor");
430
- menuPath.setAttribute("stroke-width", "1.8");
431
- menuPath.setAttribute("stroke-linecap", "round");
432
- menuIcon.append(menuPath);
433
- toggle.append(menuIcon);
434
- const style = document.createElement("style");
435
- style.textContent = `${base}
436
- :host{display:block;width:var(--spui-nav-width,260px);max-width:100%;min-width:0;color:var(--spui-ui-text,var(--spui-semantic-body-text,#242424));font:inherit}:host([data-collapsed]){width:var(--spui-nav-collapsed-width,64px)}
437
- @media(min-width:641px){:host([full-width]:not([data-collapsed])){width:100%}}
438
- nav{display:grid;grid-template-columns:minmax(0,1fr);gap:2px;width:100%;min-width:0;font-family:var(--spui-font-family,inherit);font-size:var(--spui-nav-font-size,14px);color:inherit}nav[hidden]{display:none}nav slot{min-width:0}
439
- :host([density=small]) nav{--spui-nav-item-block:5px;--spui-nav-font-size:13px}
440
- :host([density=large]) nav{--spui-nav-item-block:10px;--spui-nav-font-size:15px}
441
- .mobile-toggle,.mobile-header{display:none}.rail-toggle{box-sizing:border-box;display:flex;align-items:center;justify-content:flex-start;width:100%;min-height:36px;padding:6px 12px;border:0;border-radius:var(--spui-control-radius,6px);background:transparent;color:inherit;cursor:pointer}.rail-toggle:hover{background:var(--spui-ui-surface-hover,var(--spui-semantic-subtle-background,#f5f5f5))}.rail-toggle:focus-visible{outline:2px solid var(--spui-focus-ring,var(--spui-semantic-focus-border,#005a9e));outline-offset:2px}.rail-toggle[hidden]{display:none}.rail-toggle svg{transition:transform var(--spui-motion-duration-fast,120ms) var(--spui-motion-easing-standard,cubic-bezier(.2,0,0,1))}:host([data-collapsed]) .rail-toggle{justify-content:center;padding-inline:4px}:host([data-collapsed][data-direction=ltr]) .rail-toggle svg,:host([data-direction=rtl]) .rail-toggle svg{transform:rotate(180deg)}:host([data-collapsed][data-direction=rtl]) .rail-toggle svg{transform:none}
442
- .mobile-toggle[hidden],.mobile-close[hidden]{display:none}
443
- .mobile-toggle,.mobile-close{box-sizing:border-box;place-items:center;width:44px;height:44px;border:0;border-radius:var(--spui-control-radius,6px);background:transparent;color:inherit;cursor:pointer}
444
- .mobile-toggle:hover,.mobile-close:hover{background:var(--spui-ui-surface-hover,var(--spui-semantic-subtle-background,#f5f5f5))}
445
- .mobile-toggle:focus-visible,.mobile-close:focus-visible{outline:2px solid var(--spui-focus-ring,var(--spui-semantic-focus-border,#005a9e));outline-offset:2px}
446
- .mobile-header{align-items:center;justify-content:space-between;gap:12px;min-height:44px;margin:0 0 8px;padding-block-end:8px;border-block-end:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1));font-weight:600}
447
- .mobile-header[part]{min-width:0}
448
- .mobile-header span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
449
- ::slotted(spui-nav-item),::slotted(spui-nav-category),::slotted(spui-nav-divider),::slotted(spui-nav-section-header){min-width:0}
450
- @media(max-width:640px){
451
- :host{width:auto;max-width:none}
452
- .mobile-toggle{display:grid}
453
- :host([data-drawer-type=inline]) nav{box-sizing:border-box;width:100%;padding:8px 12px;border:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1));border-radius:var(--spui-surface-radius,var(--spui-card-radius,8px));background:var(--spui-ui-surface,var(--spui-semantic-card-background,#fff))}
454
- :host([data-drawer-type=inline]) .mobile-header{display:flex}
455
- nav[popover]:popover-open{position:fixed;inset-block:0;inset-inline:0 auto;box-sizing:border-box;display:grid;align-content:start;gap:2px;width:min(var(--spui-nav-width,260px),calc(100vw - 32px));height:100dvh;max-height:none;margin:0;padding:8px 12px;overflow:auto;border:0;border-inline-end:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1));background:var(--spui-card-background,var(--spui-ui-surface,#fff));color:var(--spui-ui-text,var(--spui-semantic-body-text,#242424));box-shadow:0 12px 36px color-mix(in srgb,var(--spui-ui-text,#242424) 20%,transparent)}
456
- nav[popover]:popover-open .mobile-header{display:flex}
457
- nav[popover]::backdrop{background:color-mix(in srgb,var(--spui-ui-text,#242424) 36%,transparent);backdrop-filter:blur(1px)}
458
- :host([data-direction=rtl]) nav[popover]:popover-open{border-inline-end:0;border-inline-start:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1))}
459
- }
460
- @media(prefers-reduced-motion:reduce){.rail-toggle svg{transition:none}}
461
- @media(forced-colors:active){nav{color:CanvasText}nav[popover]:popover-open{border:1px solid CanvasText;background:Canvas;color:CanvasText;box-shadow:none}nav[popover]::backdrop{background:Canvas}}
462
- `;
463
- shadow.append(style, toggle, railToggle, nav);
464
- }
465
- }
466
- customElements.define("spui-nav", SpuiNav);
467
- }
468
- function defineNavItemElement(tag) {
469
- if (customElements.get(tag))
470
- return;
471
- class SpuiNavItem extends HTMLElement {
472
- static observedAttributes = ["href", "disabled", "selected", "value", "compact", "aria-label"];
473
- connectedCallback() { if (!this.shadowRoot)
474
- this.render(); this.sync(); }
475
- attributeChangedCallback() { if (this.isConnected)
476
- this.sync(); }
477
- sync() {
478
- const action = this.shadowRoot?.querySelector("a,button");
479
- if (!action)
480
- return;
481
- const href = this.getAttribute("href");
482
- if (href && action.localName === "a")
483
- action.setAttribute("href", href);
484
- else if (href && action.localName === "button") {
485
- const anchor = document.createElement("a");
486
- anchor.setAttribute("href", href);
487
- anchor.part.add("action");
488
- anchor.innerHTML = "<slot name=avatar></slot><slot name=icon></slot><span part=label><slot></slot></span><span part=compact-fallback aria-hidden=true></span>";
489
- action.replaceWith(anchor);
490
- }
491
- else if (!href && action.localName === "a") {
492
- const button = document.createElement("button");
493
- button.type = "button";
494
- button.part.add("action");
495
- button.innerHTML = "<slot name=avatar></slot><slot name=icon></slot><span part=label><slot></slot></span><span part=compact-fallback aria-hidden=true></span>";
496
- action.replaceWith(button);
497
- }
498
- const control = this.shadowRoot?.querySelector("a,button");
499
- if (!control)
500
- return;
501
- if (control.localName === "button")
502
- control.disabled = this.hasAttribute("disabled");
503
- else {
504
- if (this.hasAttribute("disabled")) {
505
- control.setAttribute("aria-disabled", "true");
506
- control.setAttribute("tabindex", "-1");
507
- }
508
- else {
509
- control.removeAttribute("aria-disabled");
510
- control.removeAttribute("tabindex");
511
- }
512
- }
513
- if (this.hasAttribute("selected"))
514
- control.setAttribute("aria-current", "page");
515
- else
516
- control.removeAttribute("aria-current");
517
- const label = this.getAttribute("aria-label") ?? this.textContent?.trim() ?? "";
518
- control.setAttribute("aria-label", label);
519
- control.title = this.hasAttribute("compact") ? label : "";
520
- const fallback = control.querySelector("[part=compact-fallback]");
521
- if (fallback) {
522
- fallback.textContent = Array.from(label)[0] ?? "";
523
- fallback.hidden = Boolean(this.querySelector('[slot="icon"],[slot="avatar"]'));
524
- }
525
- }
526
- render() {
527
- const shadow = this.attachShadow({ mode: "open" });
528
- const control = this.hasAttribute("href") ? document.createElement("a") : document.createElement("button");
529
- if (control.localName === "button")
530
- control.type = "button";
531
- control.part.add("action");
532
- control.innerHTML = "<slot name=avatar></slot><slot name=icon></slot><span part=label><slot></slot></span><span part=compact-fallback aria-hidden=true></span>";
533
- const style = document.createElement("style");
534
- style.textContent = `${base}:host{display:block;min-width:0}a,button{box-sizing:border-box;display:flex;align-items:center;gap:12px;width:100%;min-height:36px;padding:var(--spui-nav-item-block,7px) 12px;border:0;border-radius:var(--spui-nav-item-radius,5px);background:transparent;color:var(--spui-ui-text,var(--spui-semantic-body-text,#242424));font:inherit;text-align:start;text-decoration:none;cursor:pointer}a:hover,button:hover{background:var(--spui-ui-surface-hover,var(--spui-semantic-subtle-background,#f5f5f5))}:host([selected]) a,:host([selected]) button{background:color-mix(in srgb,var(--spui-ui-accent,#78716c) 12%,var(--spui-ui-surface,#fff));font-weight:600}:host([disabled]) a,:host([disabled]) button{opacity:.55;cursor:not-allowed}a:focus-visible,button:focus-visible{outline:2px solid var(--spui-focus-ring,var(--spui-semantic-focus-border,#005a9e));outline-offset:2px}::slotted([slot=icon]){inline-size:20px;block-size:20px;flex:none}::slotted([slot=avatar]){inline-size:28px;block-size:28px;flex:none}[part=compact-fallback]{display:none}:host([compact]) a,:host([compact]) button{justify-content:center;gap:0;padding-inline:4px}:host([compact]) [part=label]{position:absolute;inline-size:1px;block-size:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}:host([compact]) [part=compact-fallback]:not([hidden]){display:grid;place-items:center;inline-size:28px;block-size:28px;border-radius:50%;background:var(--spui-ui-surface-hover,var(--spui-semantic-subtle-background,#f5f5f5));font-size:12px;font-weight:600}:host(spui-nav-sub-item){padding-inline-start:14px}:host(spui-app-item) a,:host(spui-app-item) button{font-weight:600}:host(spui-app-item) [part=label]{font-size:var(--spui-nav-app-item-font-size,15px)}@media(forced-colors:active){a,button{color:LinkText}:host([selected]) a,:host([selected]) button{outline:1px solid Highlight}}`;
535
- shadow.append(style, control);
536
- }
537
- }
538
- customElements.define(tag, SpuiNavItem);
539
- }
540
- export function defineNavItem() { defineNavItemElement("spui-nav-item"); }
541
- export function defineNavSubItem() { defineNavItemElement("spui-nav-sub-item"); }
542
- export function defineAppItem() { defineNavItemElement("spui-app-item"); }
543
- function defineNavPart(tag, styleText, role) {
544
- if (customElements.get(tag))
545
- return;
546
- class SpuiNavPart extends HTMLElement {
547
- connectedCallback() {
548
- if (role)
549
- this.setAttribute("role", role);
550
- if (this.shadowRoot)
551
- return;
552
- const shadow = this.attachShadow({ mode: "open" });
553
- const style = document.createElement("style");
554
- style.textContent = `${base}${styleText}`;
555
- shadow.append(style, document.createElement("slot"));
556
- }
557
- }
558
- customElements.define(tag, SpuiNavPart);
559
- }
560
- export function defineAppItemStatic() {
561
- defineNavPart("spui-app-item-static", ":host{box-sizing:border-box;display:flex;align-items:center;gap:12px;min-height:40px;padding:8px 12px;color:var(--spui-ui-text,var(--spui-semantic-body-text,#242424));font:600 15px/1.3 var(--spui-font-family,inherit)}::slotted([slot=icon]){inline-size:20px;block-size:20px;flex:none}");
562
- }
563
- export function defineSplitNavItem() {
564
- if (customElements.get("spui-split-nav-item"))
565
- return;
566
- class SpuiSplitNavItem extends HTMLElement {
567
- connectedCallback() { if (this.shadowRoot)
568
- return; const shadow = this.attachShadow({ mode: "open" }); const style = document.createElement("style"); style.textContent = `${base}:host{display:grid;grid-template-columns:minmax(0,1fr) auto auto auto;align-items:center;min-width:0}slot[name=action],slot[name=menu-button],slot[name=toggle-button]{display:grid;place-items:center}::slotted(spui-nav-item),::slotted(spui-nav-sub-item){min-width:0}::slotted([slot=action]),::slotted([slot=menu-button]),::slotted([slot=toggle-button]){min-width:36px;min-height:36px}`; shadow.append(style, document.createElement("slot"), Object.assign(document.createElement("slot"), { name: "action" }), Object.assign(document.createElement("slot"), { name: "menu-button" }), Object.assign(document.createElement("slot"), { name: "toggle-button" })); }
569
- }
570
- customElements.define("spui-split-nav-item", SpuiSplitNavItem);
571
- }
572
- export function defineHamburger() {
573
- if (customElements.get("spui-hamburger"))
574
- return;
575
- class SpuiHamburger extends HTMLElement {
576
- static observedAttributes = ["disabled", "disabled-focusable", "aria-label", "aria-expanded", "appearance", "size", "shape", "icon-position", "type", "title"];
577
- connectedCallback() { if (!this.hasAttribute("aria-label"))
578
- this.setAttribute("aria-label", "Toggle navigation"); this.render(); }
579
- attributeChangedCallback() { if (this.isConnected)
580
- this.render(); }
581
- render() {
582
- const shadow = this.shadowRoot ?? this.attachShadow({ mode: "open", delegatesFocus: true });
583
- const previous = shadow.querySelector("button");
584
- const restoreFocus = previous !== null && shadow.activeElement === previous;
585
- const button = document.createElement("button");
586
- button.className = this.getAttribute("appearance") || "secondary";
587
- button.type = this.getAttribute("type") === "submit" || this.getAttribute("type") === "reset" ? this.getAttribute("type") : "button";
588
- const disabled = this.hasAttribute("disabled");
589
- const disabledFocusable = this.hasAttribute("disabled-focusable");
590
- button.disabled = disabled && !disabledFocusable;
591
- if (disabledFocusable) {
592
- button.tabIndex = 0;
593
- button.setAttribute("aria-disabled", "true");
594
- }
595
- for (const attribute of this.attributes) {
596
- if (attribute.name.startsWith("aria-") || attribute.name === "title")
597
- button.setAttribute(attribute.name, attribute.value);
598
- }
599
- button.setAttribute("aria-label", this.getAttribute("aria-label") || "Toggle navigation");
600
- if (disabledFocusable)
601
- button.addEventListener("click", event => { event.preventDefault(); event.stopImmediatePropagation(); });
602
- const iconSlot = document.createElement("slot");
603
- iconSlot.name = "icon";
604
- const icon = document.createElement("span");
605
- icon.className = "icon";
606
- icon.append(iconSlot);
607
- const content = document.createElement("span");
608
- content.className = "content";
609
- content.append(document.createElement("slot"));
610
- const style = document.createElement("style");
611
- style.textContent = `${base}${buttonControlCss}:host{display:inline-flex;vertical-align:middle}button{min-width:44px;min-height:44px;padding:8px}::slotted([slot=icon]){display:inline-flex;align-items:center;justify-content:center;line-height:0}::slotted([slot=icon]) svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round}@media(forced-colors:active){button:focus-visible{outline-color:Highlight}}`;
612
- button.append(icon, content);
613
- shadow.replaceChildren(style, button);
614
- if (restoreFocus)
615
- button.focus();
616
- }
617
- }
618
- customElements.define("spui-hamburger", SpuiHamburger);
619
- }
620
- export function defineNavDrawer() { defineNavPart("spui-nav-drawer", ":host{display:block;min-width:0}"); }
621
- export function defineNavDrawerHeader() { defineNavPart("spui-nav-drawer-header", ":host{display:flex;align-items:center;gap:12px;min-height:44px;padding:8px 12px;border-block-end:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1));font-weight:600}"); }
622
- export function defineNavDrawerBody() { defineNavPart("spui-nav-drawer-body", ":host{display:grid;align-content:start;gap:2px;min-width:0}"); }
623
- export function defineNavDrawerFooter() { defineNavPart("spui-nav-drawer-footer", ":host{display:grid;gap:4px;margin-block-start:auto;padding:8px 0;border-block-start:1px solid var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1))}"); }
624
- export function defineNavCategory() {
625
- if (customElements.get("spui-nav-category"))
626
- return;
627
- class SpuiNavCategory extends HTMLElement {
628
- connectedCallback() { if (!this.shadowRoot) {
629
- const shadow = this.attachShadow({ mode: "open" });
630
- const style = document.createElement("style");
631
- style.textContent = `${base}:host{display:block;min-width:0}`;
632
- shadow.append(style, document.createElement("slot"));
633
- } }
634
- }
635
- customElements.define("spui-nav-category", SpuiNavCategory);
636
- }
637
- export function defineNavCategoryItem() {
638
- if (customElements.get("spui-nav-category-item"))
639
- return;
640
- class SpuiNavCategoryItem extends HTMLElement {
641
- static observedAttributes = ["expanded", "controls", "disabled", "compact", "selected", "aria-label"];
642
- connectedCallback() { if (!this.shadowRoot)
643
- this.render(); this.sync(); }
644
- attributeChangedCallback() { if (this.isConnected)
645
- this.sync(); }
646
- sync() { const button = this.shadowRoot?.querySelector("button"); if (!button)
647
- return; button.setAttribute("aria-expanded", String(this.hasAttribute("expanded"))); if (this.hasAttribute("selected"))
648
- button.setAttribute("aria-current", "page");
649
- else
650
- button.removeAttribute("aria-current"); const controls = this.getAttribute("controls"); if (controls)
651
- button.setAttribute("aria-controls", controls); button.disabled = this.hasAttribute("disabled"); const defaultSlot = button.querySelector("slot:not([name])"); const label = this.getAttribute("aria-label") ?? defaultSlot?.assignedNodes({ flatten: true }).map(node => node.textContent ?? "").join("").trim() ?? ""; button.setAttribute("aria-label", label); button.title = this.hasAttribute("compact") ? label : ""; const fallback = button.querySelector("[part=compact-fallback]"); if (fallback) {
652
- fallback.textContent = Array.from(label)[0] ?? "";
653
- fallback.hidden = Boolean(this.querySelector('[slot="icon"],[slot="avatar"]'));
654
- } }
655
- render() { const shadow = this.attachShadow({ mode: "open" }); const button = document.createElement("button"); button.type = "button"; button.part.add("action"); button.innerHTML = "<slot name=avatar></slot><slot name=icon></slot><span part=label><slot></slot></span><span part=compact-fallback aria-hidden=true></span><span aria-hidden=true part=chevron><slot name=expand-icon></slot></span>"; const chevron = button.querySelector("[part=chevron]"); const expandIconSlot = button.querySelector('slot[name="expand-icon"]'); expandIconSlot.addEventListener("slotchange", () => chevron.classList.toggle("custom", expandIconSlot.assignedNodes({ flatten: true }).length > 0)); button.querySelector("slot:not([name])")?.addEventListener("slotchange", () => this.sync()); const style = document.createElement("style"); style.textContent = `${base}:host{display:block}button{box-sizing:border-box;display:flex;align-items:center;gap:12px;width:100%;min-height:36px;padding:var(--spui-nav-item-block,7px) 12px;border:0;border-radius:var(--spui-nav-item-radius,5px);background:transparent;color:var(--spui-ui-text,var(--spui-semantic-body-text,#242424));font:inherit;text-align:start;cursor:pointer}button:hover{background:var(--spui-ui-hover,var(--spui-semantic-subtle-background,#f5f5f5))}button[aria-current=page]{background:color-mix(in srgb,var(--spui-ui-accent,#78716c) 12%,var(--spui-ui-surface,#fff));font-weight:600}button:focus-visible{outline:2px solid var(--spui-focus-ring,var(--spui-semantic-focus-border,#005a9e));outline-offset:2px}::slotted([slot=avatar]){inline-size:28px;block-size:28px;flex:none}[part=compact-fallback]{display:none}:host([compact]) button{justify-content:center;gap:0;padding-inline:4px}:host([compact]) [part=label]{position:absolute;inline-size:1px;block-size:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}:host([compact]) [part=compact-fallback]:not([hidden]){display:grid;place-items:center;inline-size:28px;block-size:28px;border-radius:50%;background:var(--spui-ui-surface-hover,var(--spui-semantic-subtle-background,#f5f5f5));font-size:12px;font-weight:600}:host([compact]) [part=chevron]{display:none}span[part=chevron]:not(.custom){box-sizing:border-box;width:7px;height:7px;margin-inline-start:auto;border:solid currentColor;border-width:0 1.5px 1.5px 0;transform:translateY(-2px) rotate(45deg);transition:transform var(--spui-motion-duration-fast,.12s) var(--spui-motion-easing-standard,cubic-bezier(.2,0,0,1))}:host([expanded]) span[part=chevron]:not(.custom){transform:translateY(2px) rotate(225deg)}span[part=chevron].custom{display:inline-flex;align-items:center;justify-content:center;flex:none;margin-inline-start:auto}:host([disabled]) button{opacity:.55;cursor:not-allowed}@media(prefers-reduced-motion:reduce){span[part=chevron]:not(.custom){transition:none}}@media(forced-colors:active){button{color:ButtonText}}`; shadow.append(style, button); }
656
- }
657
- customElements.define("spui-nav-category-item", SpuiNavCategoryItem);
658
- }
659
- export function defineNavSubItemGroup() {
660
- if (customElements.get("spui-nav-sub-item-group"))
661
- return;
662
- class SpuiNavSubItemGroup extends HTMLElement {
663
- expanded = false;
664
- exitPending = false;
665
- exitGeneration = 0;
666
- hasSynced = false;
667
- connectedCallback() {
668
- if (!this.shadowRoot) {
669
- const shadow = this.attachShadow({ mode: "open" });
670
- const style = document.createElement("style");
671
- style.textContent = `${base}:host{display:grid;gap:2px;padding-inline-start:16px}:host([compact]){padding-inline-start:0}:host([hidden]){display:none}`;
672
- shadow.append(style, document.createElement("slot"));
673
- }
674
- }
675
- setExpanded(open) {
676
- if (!this.hasSynced) {
677
- this.hasSynced = true;
678
- this.expanded = open;
679
- this.hidden = !open;
680
- this.inert = !open;
681
- if (open)
682
- this.removeAttribute("aria-hidden");
683
- else
684
- this.setAttribute("aria-hidden", "true");
685
- this.toggleAttribute("motion-visible", open);
686
- return;
687
- }
688
- this.expanded = open;
689
- this.toggleAttribute("motion-visible", open);
690
- if (open) {
691
- this.exitGeneration++;
692
- this.exitPending = false;
693
- this.hidden = false;
694
- this.inert = false;
695
- this.removeAttribute("aria-hidden");
696
- return;
697
- }
698
- if (!this.hasAttribute("motion") || this.hidden) {
699
- this.exitPending = false;
700
- this.hidden = true;
701
- return;
702
- }
703
- this.exitPending = true;
704
- this.hidden = false;
705
- this.inert = true;
706
- this.setAttribute("aria-hidden", "true");
707
- const generation = ++this.exitGeneration;
708
- requestAnimationFrame(() => requestAnimationFrame(() => {
709
- const animations = new Set();
710
- const visit = (element) => {
711
- for (const animation of element.getAnimations())
712
- if (animation.playState === "running")
713
- animations.add(animation);
714
- if (element.shadowRoot)
715
- for (const child of element.shadowRoot.children)
716
- visit(child);
717
- if (element instanceof HTMLSlotElement)
718
- for (const child of element.assignedElements({ flatten: true }))
719
- visit(child);
720
- for (const child of element.children)
721
- visit(child);
722
- };
723
- visit(this);
724
- const finish = () => {
725
- if (generation !== this.exitGeneration || this.expanded || !this.exitPending)
726
- return;
727
- this.exitPending = false;
728
- this.hidden = true;
729
- };
730
- if (animations.size)
731
- void Promise.allSettled([...animations].map(animation => animation.finished)).then(finish);
732
- else
733
- finish();
734
- }));
735
- }
736
- }
737
- customElements.define("spui-nav-sub-item-group", SpuiNavSubItemGroup);
738
- }
739
- export function defineNavDivider() {
740
- if (customElements.get("spui-nav-divider"))
741
- return;
742
- class SpuiNavDivider extends HTMLElement {
743
- static observedAttributes = ["align-content", "appearance", "inset", "vertical", "aria-label", "aria-labelledby"];
744
- connectedCallback() { if (!this.shadowRoot)
745
- this.render(); this.sync(); }
746
- attributeChangedCallback() { if (this.isConnected)
747
- this.sync(); }
748
- sync() {
749
- const vertical = this.hasAttribute("vertical");
750
- this.dataset.orientation = vertical ? "vertical" : "horizontal";
751
- this.dataset.alignContent = this.getAttribute("align-content") ?? "center";
752
- this.dataset.dividerAppearance = this.getAttribute("appearance") ?? "default";
753
- this.setAttribute("role", "separator");
754
- this.setAttribute("aria-orientation", vertical ? "vertical" : "horizontal");
755
- const wrapper = this.shadowRoot?.querySelector('slot[name="wrapper"]');
756
- const hasWrapper = Boolean(wrapper?.assignedNodes().some(node => node.nodeType === Node.ELEMENT_NODE || Boolean(node.textContent?.trim())));
757
- this.dataset.hasLabel = String(hasWrapper);
758
- }
759
- render() {
760
- const shadow = this.attachShadow({ mode: "open" });
761
- const before = document.createElement("span");
762
- before.className = "line";
763
- before.part.add("line");
764
- before.setAttribute("aria-hidden", "true");
765
- const wrapper = document.createElement("slot");
766
- wrapper.name = "wrapper";
767
- wrapper.addEventListener("slotchange", () => this.sync());
768
- const after = document.createElement("span");
769
- after.className = "line";
770
- after.part.add("line");
771
- after.setAttribute("aria-hidden", "true");
772
- const style = document.createElement("style");
773
- style.textContent = `${base}:host{box-sizing:border-box;display:flex;align-items:center;gap:var(--spui-divider-gap,12px);min-width:0;margin-block:var(--spui-divider-margin-block,12px);color:var(--spui-ui-muted,var(--spui-semantic-body-subtext,#616161));font:inherit}:host([data-orientation=vertical]){display:inline-flex;flex-direction:column;align-self:stretch;min-height:1em;width:1px;margin-inline:var(--spui-divider-margin-inline,12px);margin-block:0}:host([data-has-label=false]) slot{display:none}:host([data-has-label=false]) .line:last-child{display:none}:host([data-has-label=true]) slot{min-width:0;font-size:.875em;line-height:1.25;text-align:center}.line{flex:1;min-height:1px;background:var(--spui-divider-color,var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1)))}:host([data-orientation=vertical]) .line{min-width:1px;min-height:0;width:1px;height:auto;background:var(--spui-divider-color,var(--spui-ui-stroke,var(--spui-semantic-body-divider,#d1d1d1)))}:host([data-divider-appearance=brand]) .line{background:var(--spui-divider-color,var(--spui-base-accent,var(--spui-ui-accent,#0078d4)))}:host([data-divider-appearance=strong]) .line{background:var(--spui-divider-color,color-mix(in srgb,var(--spui-ui-text,#242424) 44%,var(--spui-ui-stroke,#d1d1d1)))}:host([data-divider-appearance=subtle]) .line{background:var(--spui-divider-color,color-mix(in srgb,var(--spui-ui-stroke,#d1d1d1) 56%,transparent))}:host([data-align-content=start]) .line:first-child{flex:0}:host([data-align-content=end]) .line:last-child{flex:0}:host([data-align-content=center]) .line{flex:1}:host([inset]){margin-inline:var(--spui-divider-inset,16px)}@media(forced-colors:active){.line{background:CanvasText}}`;
774
- shadow.append(style, before, wrapper, after);
775
- }
776
- }
777
- customElements.define("spui-nav-divider", SpuiNavDivider);
778
- }
779
- export function defineNavSectionHeader() {
780
- if (customElements.get("spui-nav-section-header"))
781
- return;
782
- class SpuiNavSectionHeader extends HTMLElement {
783
- connectedCallback() { if (!this.hasAttribute("role"))
784
- this.setAttribute("role", "heading"); if (!this.hasAttribute("aria-level"))
785
- this.setAttribute("aria-level", "3"); if (!this.shadowRoot) {
786
- const shadow = this.attachShadow({ mode: "open" });
787
- const label = document.createElement("slot");
788
- const style = document.createElement("style");
789
- style.textContent = `${base}:host{display:block;padding:12px 12px 4px;color:var(--spui-ui-muted,var(--spui-semantic-body-subtext,#616161));font:600 12px/1.3 var(--spui-font-family,inherit);letter-spacing:.02em;text-transform:uppercase}:host([compact]){display:none}`;
790
- shadow.append(style, label);
791
- } }
792
- }
793
- customElements.define("spui-nav-section-header", SpuiNavSectionHeader);
794
- }