ochreui 0.0.0-stage → 0.0.2

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 (168) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +153 -2
  3. package/cli/ochreui.mjs +601 -0
  4. package/mcp/core.mjs +126 -0
  5. package/mcp/docs.json +906 -0
  6. package/mcp/server.mjs +23 -0
  7. package/package.json +393 -3
  8. package/registry/agent-team.ts +350 -0
  9. package/registry/avatar.ts +300 -0
  10. package/registry/badge.ts +207 -0
  11. package/registry/breadcrumb.ts +435 -0
  12. package/registry/button.ts +238 -0
  13. package/registry/card.ts +221 -0
  14. package/registry/change-summary.ts +200 -0
  15. package/registry/checkbox.ts +204 -0
  16. package/registry/code-block.ts +332 -0
  17. package/registry/color-picker.ts +720 -0
  18. package/registry/comment-thread.ts +503 -0
  19. package/registry/context-menu.ts +281 -0
  20. package/registry/cover-flow.ts +623 -0
  21. package/registry/date-picker.ts +799 -0
  22. package/registry/decision-inbox.ts +340 -0
  23. package/registry/dialog.ts +577 -0
  24. package/registry/dropdown-menu.ts +864 -0
  25. package/registry/email-draft.ts +916 -0
  26. package/registry/empty-calendar.ts +199 -0
  27. package/registry/empty-state.ts +164 -0
  28. package/registry/enrichment-orbit.ts +164 -0
  29. package/registry/filter-menu.ts +541 -0
  30. package/registry/form-field.ts +308 -0
  31. package/registry/frost-cloud.ts +381 -0
  32. package/registry/ghosted-chat.ts +210 -0
  33. package/registry/glow-cloud.ts +402 -0
  34. package/registry/grid-background.ts +164 -0
  35. package/registry/hover-card.ts +401 -0
  36. package/registry/icon-button.ts +133 -0
  37. package/registry/index.json +2124 -0
  38. package/registry/integration-beam.ts +588 -0
  39. package/registry/integration-grid.ts +209 -0
  40. package/registry/kbd.ts +176 -0
  41. package/registry/layer-stack.ts +351 -0
  42. package/registry/lead-sourcing.ts +285 -0
  43. package/registry/logo-cluster.ts +239 -0
  44. package/registry/logo-marquee.ts +505 -0
  45. package/registry/message-actions.ts +833 -0
  46. package/registry/model-orbit.ts +583 -0
  47. package/registry/model-wheel.ts +372 -0
  48. package/registry/notification-stack.ts +301 -0
  49. package/registry/number-input.ts +552 -0
  50. package/registry/number-ticker.ts +261 -0
  51. package/registry/ochre.css +917 -0
  52. package/registry/otp-input.ts +704 -0
  53. package/registry/overlay.ts +312 -0
  54. package/registry/pagination.ts +362 -0
  55. package/registry/popover.ts +296 -0
  56. package/registry/profile-menu.ts +332 -0
  57. package/registry/progress-tracker.ts +291 -0
  58. package/registry/rating.ts +461 -0
  59. package/registry/reaction-bar.ts +322 -0
  60. package/registry/region-map.ts +537 -0
  61. package/registry/resizable.ts +489 -0
  62. package/registry/scroll-area.ts +271 -0
  63. package/registry/segmented-control.ts +433 -0
  64. package/registry/select.ts +769 -0
  65. package/registry/separator.ts +97 -0
  66. package/registry/shimmer-loader.ts +211 -0
  67. package/registry/side-folder.ts +152 -0
  68. package/registry/skeleton.ts +136 -0
  69. package/registry/skill/INSTRUCTIONS.md +11 -0
  70. package/registry/skill/SKILL.md +65 -0
  71. package/registry/skill/checklist.md +45 -0
  72. package/registry/skill/references/agent-team.md +105 -0
  73. package/registry/skill/references/avatar.md +88 -0
  74. package/registry/skill/references/badge.md +92 -0
  75. package/registry/skill/references/breadcrumb.md +99 -0
  76. package/registry/skill/references/button.md +82 -0
  77. package/registry/skill/references/card.md +111 -0
  78. package/registry/skill/references/catalog.md +114 -0
  79. package/registry/skill/references/change-summary.md +103 -0
  80. package/registry/skill/references/checkbox.md +105 -0
  81. package/registry/skill/references/code-block.md +109 -0
  82. package/registry/skill/references/color-picker.md +138 -0
  83. package/registry/skill/references/comment-thread.md +164 -0
  84. package/registry/skill/references/context-menu.md +205 -0
  85. package/registry/skill/references/cover-flow.md +128 -0
  86. package/registry/skill/references/date-picker.md +154 -0
  87. package/registry/skill/references/decision-inbox.md +126 -0
  88. package/registry/skill/references/dialog.md +155 -0
  89. package/registry/skill/references/dropdown-menu.md +144 -0
  90. package/registry/skill/references/email-draft.md +182 -0
  91. package/registry/skill/references/empty-calendar.md +74 -0
  92. package/registry/skill/references/empty-state.md +118 -0
  93. package/registry/skill/references/enrichment-orbit.md +71 -0
  94. package/registry/skill/references/filter-menu.md +143 -0
  95. package/registry/skill/references/form-field.md +118 -0
  96. package/registry/skill/references/frost-cloud.md +80 -0
  97. package/registry/skill/references/ghosted-chat.md +75 -0
  98. package/registry/skill/references/glow-cloud.md +84 -0
  99. package/registry/skill/references/grid-background.md +76 -0
  100. package/registry/skill/references/hover-card.md +125 -0
  101. package/registry/skill/references/icon-button.md +99 -0
  102. package/registry/skill/references/integration-beam.md +107 -0
  103. package/registry/skill/references/integration-grid.md +100 -0
  104. package/registry/skill/references/kbd.md +65 -0
  105. package/registry/skill/references/layer-stack.md +115 -0
  106. package/registry/skill/references/lead-sourcing.md +92 -0
  107. package/registry/skill/references/logo-cluster.md +92 -0
  108. package/registry/skill/references/logo-marquee.md +123 -0
  109. package/registry/skill/references/message-actions.md +146 -0
  110. package/registry/skill/references/model-orbit.md +106 -0
  111. package/registry/skill/references/model-wheel.md +84 -0
  112. package/registry/skill/references/notification-stack.md +138 -0
  113. package/registry/skill/references/number-input.md +117 -0
  114. package/registry/skill/references/number-ticker.md +73 -0
  115. package/registry/skill/references/otp-input.md +142 -0
  116. package/registry/skill/references/pagination.md +112 -0
  117. package/registry/skill/references/popover.md +143 -0
  118. package/registry/skill/references/profile-menu.md +123 -0
  119. package/registry/skill/references/progress-tracker.md +122 -0
  120. package/registry/skill/references/rating.md +111 -0
  121. package/registry/skill/references/reaction-bar.md +128 -0
  122. package/registry/skill/references/region-map.md +109 -0
  123. package/registry/skill/references/resizable.md +127 -0
  124. package/registry/skill/references/scroll-area.md +113 -0
  125. package/registry/skill/references/segmented-control.md +96 -0
  126. package/registry/skill/references/select.md +122 -0
  127. package/registry/skill/references/separator.md +69 -0
  128. package/registry/skill/references/shimmer-loader.md +83 -0
  129. package/registry/skill/references/side-folder.md +75 -0
  130. package/registry/skill/references/skeleton.md +95 -0
  131. package/registry/skill/references/smart-recommendation.md +132 -0
  132. package/registry/skill/references/spinner.md +84 -0
  133. package/registry/skill/references/switch.md +79 -0
  134. package/registry/skill/references/tab-overload.md +70 -0
  135. package/registry/skill/references/tag-input.md +126 -0
  136. package/registry/skill/references/team-invite.md +94 -0
  137. package/registry/skill/references/testimonial-wall.md +110 -0
  138. package/registry/skill/references/text-area.md +115 -0
  139. package/registry/skill/references/text-field.md +126 -0
  140. package/registry/skill/references/text-reveal.md +71 -0
  141. package/registry/skill/references/thinking-loader.md +87 -0
  142. package/registry/skill/references/time-picker.md +122 -0
  143. package/registry/skill/references/tips-panel.md +115 -0
  144. package/registry/skill/references/toggle-group.md +98 -0
  145. package/registry/skill/references/tool-call-card.md +151 -0
  146. package/registry/skill/references/tooltip.md +94 -0
  147. package/registry/skill/references/tree-view.md +172 -0
  148. package/registry/skill/theming.md +57 -0
  149. package/registry/smart-recommendation.ts +415 -0
  150. package/registry/spinner.ts +67 -0
  151. package/registry/switch.ts +146 -0
  152. package/registry/tab-overload.ts +211 -0
  153. package/registry/tag-input.ts +620 -0
  154. package/registry/team-invite.ts +248 -0
  155. package/registry/testimonial-wall.ts +521 -0
  156. package/registry/text-area.ts +432 -0
  157. package/registry/text-field.ts +415 -0
  158. package/registry/text-reveal.ts +175 -0
  159. package/registry/theme.ts +68 -0
  160. package/registry/thinking-loader.ts +302 -0
  161. package/registry/time-picker.ts +828 -0
  162. package/registry/tips-panel.ts +312 -0
  163. package/registry/toggle-group.ts +357 -0
  164. package/registry/tool-call-card.ts +578 -0
  165. package/registry/tooltip.ts +486 -0
  166. package/registry/tree-view.ts +454 -0
  167. package/styles/base.css +500 -0
  168. package/styles/tokens.css +415 -0
@@ -0,0 +1,207 @@
1
+ // Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
2
+ /**
3
+ * Badge, from Ochre (https://ochreui.dev).
4
+ * Needs ochre.css (the --ui-* tokens and the ui-ping keyframes), which `npx ochreui init` adds once.
5
+ *
6
+ * Public styling hooks (set them on the element or any ancestor):
7
+ * --ui-badge-radius corners of a text badge (default 4px, 5px for md; a pill with data-ui-look="tray")
8
+ * --ui-badge-pulse one live-dot cycle (default 1800ms; the dot stays still with reduced motion)
9
+ */
10
+ import {
11
+ Component,
12
+ Directive,
13
+ ElementRef,
14
+ LOCALE_ID,
15
+ afterEveryRender,
16
+ booleanAttribute,
17
+ computed,
18
+ contentChild,
19
+ inject,
20
+ input,
21
+ numberAttribute,
22
+ signal,
23
+ viewChild,
24
+ } from '@angular/core';
25
+
26
+ export type BadgeTone = 'neutral' | 'info' | 'success' | 'warning' | 'danger' | 'purple' | 'accent';
27
+ export type BadgeSize = 'sm' | 'md';
28
+
29
+ const formats = new Map<string, Intl.NumberFormat>();
30
+ const formatFor = (locale: string) => {
31
+ let f = formats.get(locale);
32
+ if (!f) formats.set(locale, (f = new Intl.NumberFormat(locale)));
33
+ return f;
34
+ };
35
+
36
+ const toCount = (v: number | string | null | undefined): number | undefined =>
37
+ v === null || v === undefined || v === '' ? undefined : Number(v);
38
+
39
+ /** Marks an icon to show before the text: `<svg uiBadgeIcon …>`. It takes the badge's color and is hidden from screen readers. */
40
+ @Directive({
41
+ selector: '[uiBadgeIcon]',
42
+ host: { class: 'ui-badge-icon', 'aria-hidden': 'true' },
43
+ })
44
+ export class UiBadgeIcon {}
45
+
46
+ @Component({
47
+ selector: 'ui-badge',
48
+ host: {
49
+ '[attr.data-tone]': 'tone()',
50
+ '[attr.data-size]': 'size()',
51
+ '[attr.data-count]': 'countText() === null ? null : ""',
52
+ '[attr.data-lead]': 'countText() === null && (dotted() || icon()) ? "" : null',
53
+ '[attr.data-empty]': 'empty() ? "" : null',
54
+ },
55
+ template: `
56
+ @if (countText() !== null) {
57
+ <span [attr.aria-hidden]="label() ? 'true' : null">{{ countText() }}</span>
58
+ @if (label()) {
59
+ <span class="sr">{{ label() }}</span>
60
+ }
61
+ } @else {
62
+ @if (dotted()) {
63
+ <span class="dot" [class.live]="live()" aria-hidden="true"></span>
64
+ } @else {
65
+ <ng-content select="[uiBadgeIcon]" />
66
+ }
67
+ <span #text class="label"><ng-content /></span>
68
+ @if (label()) {
69
+ <span class="sr">{{ label() }}</span>
70
+ }
71
+ }
72
+ `,
73
+ styles: `
74
+ :host {
75
+ --_t: var(--ui-look-tray, 0);
76
+ --_h: calc(var(--ui-space-4) + var(--ui-space-0-5) * (1 + var(--_t)));
77
+ --_px: calc(var(--ui-space-1-5) + var(--ui-space-0-5) * var(--_t));
78
+ --_r: var(--ui-badge-radius, calc(var(--ui-space-1) + var(--ui-radius-full) * var(--_t)));
79
+ --_ink: var(--ui-text-muted);
80
+ --_tint: var(--ui-bg-muted);
81
+ display: inline-flex;
82
+ align-items: center;
83
+ gap: var(--ui-space-1);
84
+ flex-shrink: 0;
85
+ box-sizing: border-box;
86
+ block-size: var(--_h);
87
+ max-inline-size: 100%;
88
+ padding-inline: var(--_px);
89
+ border-radius: var(--_r);
90
+ outline: 1px solid transparent;
91
+ outline-offset: -1px;
92
+ background: var(--_tint);
93
+ color: var(--_ink);
94
+ font-family: var(--ui-font-sans);
95
+ font-size: var(--ui-text-xs);
96
+ line-height: var(--ui-leading-xs);
97
+ font-weight: var(--ui-weight-medium);
98
+ font-variant-numeric: tabular-nums;
99
+ white-space: nowrap;
100
+ vertical-align: middle;
101
+ }
102
+ :host([data-size='md']) {
103
+ --_h: calc(var(--ui-space-5) + var(--ui-space-0-5) * var(--_t));
104
+ --_px: calc(var(--ui-space-1-5) + 1px + var(--ui-space-0-5) * var(--_t));
105
+ --_r: var(--ui-badge-radius, calc(var(--ui-space-1) + 1px + var(--ui-radius-full) * var(--_t)));
106
+ gap: calc(var(--ui-space-1) + 1px);
107
+ font-size: var(--ui-text-sm);
108
+ }
109
+ :host([data-tone='info']) { --_ink: var(--ui-info); --_tint: var(--ui-info-soft); }
110
+ :host([data-tone='success']) { --_ink: var(--ui-success); --_tint: var(--ui-success-soft); }
111
+ :host([data-tone='warning']) { --_ink: var(--ui-warning); --_tint: var(--ui-warning-soft); }
112
+ :host([data-tone='danger']) { --_ink: var(--ui-danger); --_tint: var(--ui-danger-soft); }
113
+ :host([data-tone='purple']) { --_ink: var(--ui-purple); --_tint: var(--ui-purple-soft); }
114
+ :host([data-tone='accent']) { --_ink: var(--ui-accent); --_tint: var(--ui-accent-soft); }
115
+ :host([data-lead]) { padding-inline-start: calc(var(--_px) - var(--ui-space-0-5)); }
116
+ :host([data-count]) {
117
+ justify-content: center;
118
+ min-inline-size: var(--_h);
119
+ padding-inline: calc(var(--ui-space-1) + 1px + 1px * var(--_t));
120
+ border-radius: var(--ui-radius-full);
121
+ }
122
+ :host([data-empty]) { display: none; }
123
+ .label { min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; }
124
+ .dot {
125
+ position: relative;
126
+ flex: none;
127
+ inline-size: var(--ui-space-1-5);
128
+ block-size: var(--ui-space-1-5);
129
+ margin-inline: 1px;
130
+ border-radius: 50%;
131
+ background: currentColor;
132
+ }
133
+ .live::after {
134
+ content: '';
135
+ position: absolute;
136
+ inset: 0;
137
+ border-radius: inherit;
138
+ background: currentColor;
139
+ opacity: 0;
140
+ animation: ui-ping var(--ui-badge-pulse, 1800ms) ease-out infinite;
141
+ }
142
+ :host ::ng-deep .ui-badge-icon {
143
+ flex: none;
144
+ inline-size: var(--ui-icon-xs);
145
+ block-size: var(--ui-icon-xs);
146
+ color: inherit;
147
+ }
148
+ .sr {
149
+ position: absolute;
150
+ inline-size: 1px;
151
+ block-size: 1px;
152
+ overflow: hidden;
153
+ clip-path: inset(50%);
154
+ white-space: nowrap;
155
+ }
156
+ @media (prefers-reduced-motion: reduce) {
157
+ .live::after { display: none; }
158
+ }
159
+ @container style(--ui-motion-scale: 0) {
160
+ .live::after { display: none; }
161
+ }
162
+ @media (forced-colors: active) {
163
+ .dot { forced-color-adjust: none; background: CanvasText; }
164
+ .live::after { display: none; }
165
+ }
166
+ `,
167
+ })
168
+ export class UiBadge {
169
+ /** Color and meaning: neutral, info (running), success (done), warning (needs you), danger (failed), purple (a kind, like Beta), accent (brand). */
170
+ readonly tone = input<BadgeTone>('neutral');
171
+ /** `sm` on rows, `md` next to larger text. */
172
+ readonly size = input<BadgeSize>('sm');
173
+ /** A small dot in the tone's color before the text. */
174
+ readonly dot = input(false, { transform: booleanAttribute });
175
+ /** The dot pulses softly, for something running right now. Shows the dot. */
176
+ readonly live = input(false, { transform: booleanAttribute });
177
+ /** Makes it a round count instead of text. Never below 0; above `max` it reads "99+". */
178
+ readonly count = input<number | undefined, number | string | null | undefined>(undefined, { transform: toCount });
179
+ /** Highest count shown in full. */
180
+ readonly max = input(99, { transform: numberAttribute });
181
+ /** Spoken meaning of a count ("128 waiting"), or of a dot or icon with no text ("Online"). */
182
+ readonly label = input<string>();
183
+
184
+ private readonly format = formatFor(inject(LOCALE_ID));
185
+ protected readonly icon = contentChild(UiBadgeIcon);
186
+ protected readonly dotted = computed(() => this.dot() || this.live());
187
+ protected readonly countText = computed(() => {
188
+ const n = this.count();
189
+ if (n === undefined || Number.isNaN(n)) return null;
190
+ const max = this.max();
191
+ return n > max ? `${this.format.format(max)}+` : this.format.format(Math.max(0, Math.floor(n)));
192
+ });
193
+
194
+ private readonly text = viewChild<ElementRef<HTMLElement>>('text');
195
+ private readonly blank = signal(false);
196
+ protected readonly empty = computed(() => this.countText() === null && !this.dotted() && !this.icon() && this.blank());
197
+
198
+ constructor() {
199
+ afterEveryRender({
200
+ read: () => {
201
+ if (this.countText() !== null || this.dotted() || this.icon()) return;
202
+ const el = this.text()?.nativeElement;
203
+ this.blank.set(!!el && !el.textContent?.trim() && el.childElementCount === 0);
204
+ },
205
+ });
206
+ }
207
+ }
@@ -0,0 +1,435 @@
1
+ // Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
2
+ /**
3
+ * Breadcrumb, from Ochre (https://ochreui.dev).
4
+ * Needs ochre.css (`npx ochreui init`) and dropdown-menu.ts (`npx ochreui add dropdown-menu`).
5
+ *
6
+ * <ui-breadcrumb>
7
+ * <a uiCrumb routerLink="/projects"><svg uiCrumbIcon …/>Northwind</a>
8
+ * <a uiCrumb routerLink="/projects/design">Design</a>
9
+ * <span uiCrumb>Brand refresh</span>
10
+ * </ui-breadcrumb>
11
+ * Your own links and buttons are the crumbs; the last one is the current page. Past `maxItems`, or when
12
+ * the row gets too narrow, the middle folds into a "…" menu. The row never wraps.
13
+ *
14
+ * Public styling hooks (set them on the element or any ancestor):
15
+ * --ui-breadcrumb-color crumbs and the "…" (default: muted text)
16
+ * --ui-breadcrumb-color-current the current page and hovered crumbs (default: ink)
17
+ * --ui-breadcrumb-separator the separators (default: a quiet grey, decorative)
18
+ * --ui-breadcrumb-max-label longest a crumb gets before "…" (default 200px; the current page is not capped)
19
+ */
20
+ import {
21
+ Component,
22
+ DOCUMENT,
23
+ DestroyRef,
24
+ Directive,
25
+ ElementRef,
26
+ PLATFORM_ID,
27
+ afterNextRender,
28
+ afterRenderEffect,
29
+ computed,
30
+ contentChildren,
31
+ inject,
32
+ input,
33
+ isDevMode,
34
+ numberAttribute,
35
+ signal,
36
+ untracked,
37
+ viewChild,
38
+ } from '@angular/core';
39
+ import { isPlatformBrowser } from '@angular/common';
40
+ import { UiMenu, UiMenuIcon, UiMenuItem } from './dropdown-menu';
41
+
42
+ /** `slash` (Clean's default), `chevron` (Classic's default), or any short text such as "›" or "·". */
43
+ export type BreadcrumbSeparator = 'slash' | 'chevron' | (string & {});
44
+
45
+ export interface BreadcrumbLabels {
46
+ /** Names the navigation landmark. */
47
+ nav: string;
48
+ /** The "…" button, given how many crumbs it holds. */
49
+ more: (count: number) => string;
50
+ /** Names the menu of folded crumbs. */
51
+ menu: string;
52
+ }
53
+
54
+ const LABELS: BreadcrumbLabels = { nav: 'Breadcrumb', more: (n) => `Show ${n} more crumbs`, menu: 'More crumbs' };
55
+
56
+ /** Marks the 14px glyph before a crumb's label: `<svg uiCrumbIcon>`. Hidden from screen readers. */
57
+ @Directive({
58
+ selector: '[uiCrumbIcon]',
59
+ host: { 'aria-hidden': 'true', style: 'flex: none; inline-size: var(--ui-icon-sm); block-size: var(--ui-icon-sm)' },
60
+ })
61
+ export class UiCrumbIcon {}
62
+
63
+ /** One crumb: `<a uiCrumb href>`, `<a uiCrumb routerLink>`, `<button uiCrumb (click)>`, or `<span uiCrumb>` for a level without a page. */
64
+ @Component({
65
+ selector: 'a[uiCrumb], button[uiCrumb], span[uiCrumb]',
66
+ host: {
67
+ '[attr.type]': 'button ? "button" : null',
68
+ '[attr.aria-current]': 'current() ? "page" : null',
69
+ '[attr.tabindex]': 'current() ? -1 : null',
70
+ '(pointerenter)': 'measure()',
71
+ '(animationend)': 'settle($event)',
72
+ '(animationcancel)': 'settle($event)',
73
+ },
74
+ template: `<ng-content select="[uiCrumbIcon]" /><span class="label" dir="auto"><ng-content /></span>`,
75
+ styles: `
76
+ :host {
77
+ --_t: var(--ui-look-tray, 0);
78
+ --_dir: 1;
79
+ display: flex;
80
+ align-items: center;
81
+ gap: var(--ui-space-1-5);
82
+ box-sizing: border-box;
83
+ min-inline-size: 0;
84
+ max-inline-size: 100%;
85
+ margin: 0;
86
+ padding: 0;
87
+ border: 0;
88
+ border-radius: calc(var(--ui-radius-sm) - 2px + 2px * var(--_t));
89
+ outline: none;
90
+ background: none;
91
+ color: var(--ui-breadcrumb-color, var(--ui-text-muted));
92
+ font: inherit;
93
+ text-decoration: none;
94
+ -webkit-tap-highlight-color: transparent;
95
+ transition: color calc(120ms * var(--ui-motion-scale)) var(--ui-ease-out);
96
+ }
97
+ :host(:dir(rtl)) { --_dir: -1; }
98
+ :host(:is(a, button)) { cursor: pointer; }
99
+ :host([aria-current]) { color: var(--ui-breadcrumb-color-current, var(--ui-text)); }
100
+ @media (hover: hover) { :host(:is(a, button):hover) { color: var(--ui-breadcrumb-color-current, var(--ui-text)); } }
101
+ :host([aria-current]) { font-weight: var(--ui-weight-medium); }
102
+ :host(:focus-visible) { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset); }
103
+ :host([data-enter]) { animation: enter calc(260ms * var(--ui-motion-scale)) var(--ui-ease-out); }
104
+ .label { min-inline-size: 0; max-inline-size: var(--ui-breadcrumb-max-label, 200px); overflow: hidden; text-overflow: ellipsis; }
105
+ :host([aria-current]) .label { max-inline-size: none; }
106
+ @keyframes enter { from { opacity: 0; translate: calc(var(--ui-space-1) * -1 * var(--_dir)) 0; } }
107
+ @media (pointer: coarse) {
108
+ :host(:is(a, button)) { position: relative; }
109
+ :host(:is(a, button))::after { content: ''; position: absolute; inset: -10px -4px; }
110
+ }
111
+ @media (forced-colors: active) and (hover: hover) {
112
+ :host(:is(a, button):hover) { text-decoration: underline; }
113
+ }
114
+ `,
115
+ })
116
+ export class UiCrumb {
117
+ /** Its name in the "…" menu. Default: its text. */
118
+ readonly label = input<string>();
119
+
120
+ readonly el = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
121
+ private readonly trail = inject(UiBreadcrumb, { optional: true });
122
+ protected readonly button = this.el.localName === 'button';
123
+ /** The current page: the last crumb. */
124
+ readonly current = computed(() => this.trail?.crumbs().at(-1) === this);
125
+ private titled = false;
126
+
127
+ /** Its name: `label`, else its text. */
128
+ text() {
129
+ return this.label() ?? this.el.textContent?.trim() ?? '';
130
+ }
131
+
132
+ /** Where it links to, for the row that stands in for it while it is folded. */
133
+ href() {
134
+ return this.el.localName === 'a' ? this.el.getAttribute('href') : null;
135
+ }
136
+
137
+ /** Follows it, as a click would: router links navigate, click handlers run. */
138
+ activate() {
139
+ this.el.click();
140
+ }
141
+
142
+ /** Plays the soft slide-in of a new current page. */
143
+ enter() {
144
+ this.el.removeAttribute('data-enter');
145
+ void this.el.offsetWidth;
146
+ this.el.setAttribute('data-enter', '');
147
+ }
148
+
149
+ protected settle(e: Event) {
150
+ if (e.target !== this.el) return;
151
+ if (e.type === 'animationcancel' && this.el.getAnimations?.().some((a) => 'animationName' in a)) return;
152
+ this.el.removeAttribute('data-enter');
153
+ }
154
+
155
+ protected measure() {
156
+ const label = this.el.querySelector('.label');
157
+ if (!label || (this.el.hasAttribute('title') && !this.titled)) return;
158
+ this.titled = label.scrollWidth > label.clientWidth;
159
+ if (this.titled) this.el.title = this.text();
160
+ else this.el.removeAttribute('title');
161
+ }
162
+ }
163
+
164
+ /** The trail. Put the crumbs directly inside, top level first; the last one is the current page. */
165
+ @Component({
166
+ selector: 'ui-breadcrumb',
167
+ imports: [UiMenu, UiMenuItem, UiMenuIcon],
168
+ host: { '(focusin)': 'lastFocus = $event.target', '(focusout)': 'left($event)' },
169
+ template: `
170
+ <nav [attr.aria-label]="l().nav">
171
+ <ol #list class="list" [style.--_st]="sepShape()" [style.--_sep]="sepText()">
172
+ <ng-content />
173
+ <li #fold class="fold" hidden>
174
+ <button #more type="button" class="more" aria-haspopup="menu" [attr.aria-label]="l().more(folded().length)"
175
+ [attr.title]="titles() || null" [attr.aria-expanded]="menu.open()" [attr.aria-controls]="menu.open() ? menu.listId() : null"
176
+ (click)="toggle($event)" (keydown)="key($event)">
177
+ <svg viewBox="0 0 16 16" aria-hidden="true"><circle cx="3.5" cy="8" r="1.25" /><circle cx="8" cy="8" r="1.25" /><circle cx="12.5" cy="8" r="1.25" /></svg>
178
+ </button>
179
+ <ui-menu #menu class="menu" fade [aria-label]="l().menu">
180
+ @for (c of folded(); track $index; let i = $index) {
181
+ @if (c.href(); as href) {
182
+ <a uiMenuItem class="row" [href]="href" [style.--_i]="i" (click)="follow($event, c)">
183
+ <svg uiMenuIcon viewBox="0 0 16 16"><path d="M4.5 2.5v5a3 3 0 0 0 3 3h5M10 8l2.5 2.5L10 13" /></svg>{{ c.text() }}
184
+ </a>
185
+ } @else {
186
+ <button uiMenuItem class="row" [disabled]="c.el.localName === 'span'" [style.--_i]="i" (click)="follow($event, c)">
187
+ <svg uiMenuIcon viewBox="0 0 16 16"><path d="M4.5 2.5v5a3 3 0 0 0 3 3h5M10 8l2.5 2.5L10 13" /></svg>{{ c.text() }}
188
+ </button>
189
+ }
190
+ }
191
+ </ui-menu>
192
+ </li>
193
+ </ol>
194
+ </nav>
195
+ `,
196
+ styles: `
197
+ :host {
198
+ --_t: var(--ui-look-tray, 0);
199
+ --_sc: var(--ui-breadcrumb-separator, color-mix(in srgb, var(--ui-text-muted) calc(45% - 6% * var(--_t)), transparent));
200
+ display: block;
201
+ min-inline-size: 0;
202
+ font: calc(var(--ui-text-base) + 0.5px * var(--_t)) / var(--ui-leading-base) var(--ui-font-sans);
203
+ }
204
+ .list { display: flex; align-items: center; min-inline-size: 0; margin: 0; padding: 0; list-style: none; white-space: nowrap; }
205
+ .list ::ng-deep > li { display: flex; flex: none; align-items: center; min-inline-size: 0; }
206
+ .list ::ng-deep > li:has(> [aria-current]) { display: grid; flex: 0 1 auto; grid-auto-flow: column; grid-auto-columns: minmax(0, max-content); }
207
+ .list ::ng-deep > [hidden] { display: none; }
208
+ .list ::ng-deep > li + li::before {
209
+ --_s: var(--_st, var(--_t));
210
+ content: var(--_sep, '/') / '';
211
+ display: grid;
212
+ flex: none;
213
+ place-items: center;
214
+ box-sizing: border-box;
215
+ inline-size: var(--ui-space-5);
216
+ block-size: var(--ui-leading-base);
217
+ padding: 0 2px;
218
+ color: color-mix(in srgb, var(--_sc) calc(100% - 100% * var(--_s)), transparent);
219
+ background: color-mix(in srgb, var(--_sc) calc(100% * var(--_s)), transparent);
220
+ mask: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><path d='m5.25 3 4 4-4 4'/></svg>") 50% / var(--ui-icon-sm) no-repeat,
221
+ linear-gradient(rgb(0 0 0 / calc(1 - var(--_s))) 0 0);
222
+ }
223
+ .list:dir(rtl) ::ng-deep > li + li::before { scale: calc(1 - 2 * var(--_s)) 1; }
224
+ .more {
225
+ position: relative;
226
+ display: grid;
227
+ place-items: center;
228
+ inline-size: calc(var(--ui-space-6) + 2px * var(--_t));
229
+ block-size: calc(var(--ui-space-5) + 2px * var(--_t));
230
+ padding: 0;
231
+ border: 0;
232
+ border-radius: calc(var(--ui-radius-sm) - 2px + 2px * var(--_t));
233
+ background: transparent;
234
+ color: var(--ui-breadcrumb-color, var(--ui-text-muted));
235
+ cursor: pointer;
236
+ -webkit-tap-highlight-color: transparent;
237
+ transition: calc(120ms * var(--ui-motion-scale)) var(--ui-ease-out);
238
+ transition-property: color, background-color;
239
+ }
240
+ .more[aria-expanded='true'] { background: color-mix(in srgb, var(--ui-text) calc(6% + 3% * var(--_t)), transparent); color: var(--ui-breadcrumb-color-current, var(--ui-text)); }
241
+ @media (hover: hover) { .more:hover { background: color-mix(in srgb, var(--ui-text) calc(6% + 3% * var(--_t)), transparent); color: var(--ui-breadcrumb-color-current, var(--ui-text)); } }
242
+ .more:focus-visible { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset); }
243
+ .more svg { inline-size: var(--ui-icon-md); block-size: var(--ui-icon-md); fill: currentColor; }
244
+ .menu { margin-left: calc(var(--ui-space-1) * -1); }
245
+ .menu:dir(rtl) { margin-left: var(--ui-space-1); }
246
+ .row { padding-inline-start: calc(var(--ui-space-2-5) + var(--ui-space-3) * var(--_i)); }
247
+ .row svg { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
248
+ .row:dir(rtl) svg { scale: -1 1; }
249
+ @media (forced-colors: none) { .row[data-active] svg { color: var(--ui-text-placeholder); } }
250
+ @media (pointer: coarse) {
251
+ .more::after { content: ''; position: absolute; inset: -8px -6px; }
252
+ .row { min-block-size: calc(var(--ui-space-10) + 2px * var(--_t)); }
253
+ }
254
+ @media (forced-colors: active) {
255
+ .list ::ng-deep > li + li::before { forced-color-adjust: none; --_sc: CanvasText; }
256
+ }
257
+ `,
258
+ })
259
+ export class UiBreadcrumb {
260
+ /** Most crumbs shown, the "…" included. Past it, the crumbs after the first fold into the "…" menu. */
261
+ readonly maxItems = input(4, { transform: numberAttribute });
262
+ /** What sits between crumbs. Default: follows the look, a slash in Clean and a chevron in Classic. */
263
+ readonly separator = input<BreadcrumbSeparator | null>(null);
264
+ /** Every visible and spoken string. Pass only the ones you change. */
265
+ readonly labels = input<Partial<BreadcrumbLabels>>({});
266
+
267
+ /** The crumbs, top level first. */
268
+ readonly crumbs = contentChildren(UiCrumb, { descendants: true });
269
+ /** How many crumbs after the first are folded into the "…" menu. */
270
+ readonly count = signal(0);
271
+ readonly folded = computed(() => this.crumbs().slice(1, 1 + this.count()));
272
+
273
+ protected readonly l = computed(() => ({ ...LABELS, ...this.labels() }));
274
+ protected readonly sepShape = computed(() => {
275
+ const s = this.separator();
276
+ return s === null ? null : s === 'chevron' ? 1 : 0;
277
+ });
278
+ protected readonly sepText = computed(() => {
279
+ const s = this.separator();
280
+ return s === null || s === 'slash' || s === 'chevron' ? null : JSON.stringify(s);
281
+ });
282
+ protected lastFocus: EventTarget | null = null;
283
+
284
+ private readonly el = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
285
+ private readonly doc = inject(DOCUMENT);
286
+ private readonly list = viewChild.required<ElementRef<HTMLOListElement>>('list');
287
+ private readonly fold = viewChild.required<ElementRef<HTMLLIElement>>('fold');
288
+ private readonly more = viewChild.required<ElementRef<HTMLButtonElement>>('more');
289
+ private readonly menu = viewChild.required(UiMenu);
290
+ private readonly tick = signal(0);
291
+ private readonly wrappers = new WeakSet<Node>();
292
+ private readonly watched = new Set<Element>();
293
+ private resize?: ResizeObserver;
294
+ private current?: UiCrumb;
295
+ private patched = false;
296
+
297
+ constructor() {
298
+ const browser = isPlatformBrowser(inject(PLATFORM_ID));
299
+ afterNextRender(() => {
300
+ this.menu().registerTrigger(this.more().nativeElement);
301
+ const win = this.doc.defaultView;
302
+ if (win?.ResizeObserver) {
303
+ this.resize = new win.ResizeObserver(() => this.tick.update((n) => n + 1));
304
+ this.resize.observe(this.el);
305
+ }
306
+ if (isDevMode()) {
307
+ for (const c of this.crumbs()) {
308
+ if (!c.text() && !c.el.hasAttribute('aria-label')) console.warn('ui-breadcrumb: a crumb with only an icon needs an aria-label.', c.el);
309
+ if (c.el.parentElement !== this.list().nativeElement && c.el.parentElement?.parentElement !== this.list().nativeElement) {
310
+ console.warn('ui-breadcrumb: put each crumb directly inside <ui-breadcrumb>.', c.el);
311
+ }
312
+ }
313
+ }
314
+ });
315
+ afterRenderEffect(() => {
316
+ const crumbs = this.crumbs();
317
+ const max = this.maxItems();
318
+ this.tick();
319
+ if (browser) untracked(() => this.update(crumbs, max));
320
+ });
321
+ inject(DestroyRef).onDestroy(() => this.resize?.disconnect());
322
+ }
323
+
324
+ protected titles() {
325
+ return this.folded()
326
+ .map((c) => c.text())
327
+ .join(' / ');
328
+ }
329
+
330
+ protected toggle(e: MouseEvent) {
331
+ const menu = this.menu();
332
+ if (menu.open()) return menu.close('trigger');
333
+ if (e.detail === 0) return menu.openWith('first');
334
+ menu.openWith('none');
335
+ menu.items()[0]?.el.focus({ preventScroll: true, focusVisible: false } as FocusOptions);
336
+ }
337
+
338
+ protected key(e: KeyboardEvent) {
339
+ if (e.key !== 'ArrowDown') return;
340
+ e.preventDefault();
341
+ this.menu().openWith('first');
342
+ }
343
+
344
+ protected follow(e: MouseEvent, crumb: UiCrumb) {
345
+ if (e.button !== 0 || e.ctrlKey || e.metaKey || e.shiftKey || e.altKey) return;
346
+ e.preventDefault();
347
+ crumb.activate();
348
+ }
349
+
350
+ protected left(e: FocusEvent) {
351
+ const to = e.relatedTarget as Node | null;
352
+ if (to && !this.el.contains(to)) this.lastFocus = null;
353
+ }
354
+
355
+ private update(crumbs: readonly UiCrumb[], max: number) {
356
+ this.wrap(crumbs);
357
+ this.watch(crumbs);
358
+ const before = this.folded();
359
+ this.layout(crumbs, max);
360
+ if (this.menu().open() && this.folded().some((c, i) => c !== before[i])) this.menu().close('trigger');
361
+ const cur = crumbs.at(-1);
362
+ if (cur === this.current) return;
363
+ const had = this.current;
364
+ this.current = cur;
365
+ if (!had || !cur) return;
366
+ cur.enter();
367
+ this.refocus(cur);
368
+ }
369
+
370
+ /** Gives each crumb its own list item, and keeps Angular's later inserts pointed at those items. */
371
+ private wrap(crumbs: readonly UiCrumb[]) {
372
+ const ol = this.list().nativeElement;
373
+ const fold = this.fold().nativeElement;
374
+ const insert = Node.prototype.insertBefore;
375
+ if (!this.patched) {
376
+ this.patched = true;
377
+ const up = (n: Node | null) => (n && n.parentNode !== ol && this.wrappers.has(n.parentNode!) ? n.parentNode : n);
378
+ ol.insertBefore = ((node: Node, ref: Node | null) => insert.call(ol, up(node)!, up(ref))) as typeof ol.insertBefore;
379
+ }
380
+ for (const c of crumbs) {
381
+ if (c.el.parentNode !== ol) continue;
382
+ const li = this.doc.createElement('li');
383
+ this.wrappers.add(li);
384
+ insert.call(ol, li, c.el);
385
+ li.append(c.el);
386
+ }
387
+ for (const li of [...ol.children]) if (this.wrappers.has(li) && !li.childElementCount) li.remove();
388
+ const first = crumbs[0]?.el.parentElement;
389
+ if (first && first !== ol && first.nextElementSibling !== fold) first.after(fold);
390
+ }
391
+
392
+ private watch(crumbs: readonly UiCrumb[]) {
393
+ if (!this.resize) return;
394
+ const now = new Set<Element>(crumbs.map((c) => c.el));
395
+ for (const el of this.watched) if (!now.has(el)) this.resize.unobserve(el);
396
+ for (const el of now) if (!this.watched.has(el)) this.resize.observe(el);
397
+ this.watched.clear();
398
+ for (const el of now) this.watched.add(el);
399
+ }
400
+
401
+ /** Folds by count, then folds one more at a time while the current page is squeezed under its natural width or the label cap. */
402
+ private layout(crumbs: readonly UiCrumb[], max: number) {
403
+ const n = crumbs.length;
404
+ const most = Math.max(0, n - 2);
405
+ let k = Math.min(most, n > max ? n - Math.max(max, 3) + 1 : 0);
406
+ const ol = this.list().nativeElement;
407
+ const label = crumbs.at(-1)?.el.querySelector('.label');
408
+ const cap = parseFloat(this.doc.defaultView?.getComputedStyle(crumbs[0]?.el.querySelector('.label') ?? ol).maxInlineSize ?? '') || Infinity;
409
+ for (;; k++) {
410
+ this.apply(crumbs, k);
411
+ const fits = !label || (label.clientWidth + 0.5 >= Math.min(label.scrollWidth, cap) && ol.scrollWidth <= ol.clientWidth + 0.5);
412
+ if (fits || k >= most) break;
413
+ }
414
+ this.count.set(k);
415
+ }
416
+
417
+ private apply(crumbs: readonly UiCrumb[], k: number) {
418
+ crumbs.forEach((c, i) => {
419
+ const li = c.el.parentElement;
420
+ if (li && li !== this.list().nativeElement) li.hidden = i > 0 && i <= k;
421
+ });
422
+ this.fold().nativeElement.hidden = k === 0;
423
+ }
424
+
425
+ /** After a crumb or a menu row was followed and the trail changed under it, focus lands on "you are here". */
426
+ private refocus(cur: UiCrumb) {
427
+ const last = this.lastFocus as Element | null;
428
+ if (!last) return;
429
+ const active = this.doc.activeElement;
430
+ const lost = !active || active === this.doc.body;
431
+ if ((active && active !== cur.el && this.el.contains(active)) || (lost && (!last.isConnected || last.checkVisibility?.() === false))) {
432
+ cur.el.focus({ preventScroll: true });
433
+ }
434
+ }
435
+ }