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,623 @@
1
+ // Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
2
+ /**
3
+ * Cover Flow, from Ochre (https://ochreui.dev).
4
+ * Needs ochre.css (the --ui-* tokens), added once by `npx ochreui init`.
5
+ *
6
+ * <ui-cover-flow label="New releases" [items]="albums" [(index)]="front" [itemWidth]="240" [itemHeight]="320" (selected)="open($event.item)">
7
+ * <ng-template uiCoverFlowCover let-item><app-art [seed]="item.id" /></ng-template>
8
+ * </ui-cover-flow>
9
+ * A 3D row of covers over a soft reflection: the front one faces you, the others turn away.
10
+ * Drag, flick, scroll, or use the arrow keys, buttons or ticks; it always settles on a cover.
11
+ *
12
+ * Public styling hooks (set them on the element or any ancestor):
13
+ * --ui-cover-flow-veil wash over the side covers (default: the page colour, 24 % light / 50 % dark)
14
+ * --ui-cover-flow-shadow shadow under each cover
15
+ * --ui-cover-flow-floor soft shadow on the floor under each cover
16
+ * --ui-cover-flow-ring keyboard focus ring around the front cover (default: the focus ring colour)
17
+ */
18
+ import {
19
+ Component,
20
+ DOCUMENT,
21
+ DestroyRef,
22
+ Directive,
23
+ ElementRef,
24
+ TemplateRef,
25
+ afterNextRender,
26
+ afterRenderEffect,
27
+ booleanAttribute,
28
+ computed,
29
+ contentChild,
30
+ effect,
31
+ inject,
32
+ input,
33
+ isDevMode,
34
+ model,
35
+ numberAttribute,
36
+ output,
37
+ signal,
38
+ untracked,
39
+ viewChild,
40
+ viewChildren,
41
+ } from '@angular/core';
42
+ import { NgTemplateOutlet } from '@angular/common';
43
+
44
+ export interface CoverFlowItem {
45
+ id: string | number;
46
+ title?: string;
47
+ subtitle?: string;
48
+ /** Image URL, shown when there is no `uiCoverFlowCover` template. */
49
+ image?: string;
50
+ alt?: string;
51
+ }
52
+
53
+ export interface CoverFlowLabels {
54
+ carousel: string;
55
+ slide: string;
56
+ /** `{n}`, `{total}` and `{title}` are filled in. */
57
+ position: string;
58
+ previous: string;
59
+ next: string;
60
+ /** Tick name; `{title}` is filled in. */
61
+ show: string;
62
+ }
63
+
64
+ export interface CoverFlowContext {
65
+ $implicit: CoverFlowItem;
66
+ index: number;
67
+ }
68
+
69
+ const LABELS: CoverFlowLabels = {
70
+ carousel: 'carousel',
71
+ slide: 'slide',
72
+ position: '{n} of {total}: {title}',
73
+ previous: 'Previous',
74
+ next: 'Next',
75
+ show: 'Show {title}',
76
+ };
77
+
78
+ /** Custom art for every cover: `<ng-template uiCoverFlowCover let-item>`. It is stamped twice, for the cover and its reflection. */
79
+ @Directive({ selector: 'ng-template[uiCoverFlowCover]' })
80
+ export class UiCoverFlowCover {
81
+ readonly template = inject<TemplateRef<CoverFlowContext>>(TemplateRef);
82
+ static ngTemplateContextGuard(_: UiCoverFlowCover, ctx: unknown): ctx is CoverFlowContext {
83
+ return true;
84
+ }
85
+ }
86
+
87
+ /** Replaces the title and subtitle under the row: `<ng-template uiCoverFlowCaption let-item let-i="index">`. */
88
+ @Directive({ selector: 'ng-template[uiCoverFlowCaption]' })
89
+ export class UiCoverFlowCaption {
90
+ readonly template = inject<TemplateRef<CoverFlowContext>>(TemplateRef);
91
+ static ngTemplateContextGuard(_: UiCoverFlowCaption, ctx: unknown): ctx is CoverFlowContext {
92
+ return true;
93
+ }
94
+ }
95
+
96
+ interface Drag {
97
+ id: number;
98
+ x0: number;
99
+ p0: number;
100
+ f0: number;
101
+ moved: boolean;
102
+ dir: number;
103
+ last: number;
104
+ hit: number;
105
+ samples: { t: number; p: number }[];
106
+ }
107
+
108
+ const PX_PER_COVER = 110;
109
+ const WHEEL_PX = 170;
110
+
111
+ @Component({
112
+ selector: 'ui-cover-flow',
113
+ imports: [NgTemplateOutlet],
114
+ host: {
115
+ '[style.--_w]': "w() + 'px'",
116
+ '[style.--_h]': "h() + 'px'",
117
+ '[style.--_k]': 'k()',
118
+ '[style.--_n.px]': 'itemWidth() * 3.2',
119
+ '[attr.data-reflection]': "reflection() ? '' : null",
120
+ },
121
+ template: `
122
+ <div #stage class="stage" role="region" tabindex="0" [attr.aria-roledescription]="t().carousel" [attr.aria-label]="label() || null"
123
+ style="grid-area: 1 / 1; box-sizing: border-box; position: relative; overflow: hidden; block-size: calc(var(--_h) * 1.4); padding-block-start: calc(var(--_h) * 0.08); border-radius: var(--ui-radius-lg); outline: 0; cursor: grab; touch-action: pan-y; user-select: none; -webkit-user-select: none; mask-image: linear-gradient(to right, transparent, #000 4%, #000 96%, transparent)"
124
+ (pointerdown)="down($event)" (keydown)="key($event)" (wheel)="wheel($event)">
125
+ <div style="position: relative; block-size: var(--_h); perspective: calc(1000px * var(--_k))">
126
+ @for (it of items(); track it.id; let i = $index) {
127
+ <div #slide class="slide" role="group" [attr.aria-roledescription]="t().slide" [attr.aria-label]="name(it, i)"
128
+ [attr.aria-hidden]="i === front() ? null : 'true'" [attr.data-active]="i === front() ? '' : null" [attr.data-i]="i"
129
+ style="position: absolute; inset-block-start: 0; left: calc(50% - var(--_w) / 2); inline-size: var(--_w); block-size: var(--_h)">
130
+ <span class="floor" aria-hidden="true"
131
+ style="position: absolute; inset-block-start: calc(100% - 5px); left: 10%; inline-size: 80%; block-size: 8px; border-radius: 50%; filter: blur(5px); opacity: calc(1 - 0.7 * var(--_u, 0)); background: var(--_fl)"></span>
132
+ <div class="card" [attr.inert]="i === front() ? null : ''"><ng-container *ngTemplateOutlet="art; context: { $implicit: it, index: i, hide: false }" /></div>
133
+ @if (reflection()) {
134
+ <div class="refl" aria-hidden="true" inert
135
+ style="position: absolute; inset-block-start: calc(100% + 2px); inset-inline: 0; block-size: calc(var(--_h) * 0.32); overflow: hidden; mask-image: linear-gradient(var(--_rf), transparent 85%)">
136
+ <div class="card" style="block-size: var(--_h); scale: 1 -1; box-shadow: none"><ng-container *ngTemplateOutlet="art; context: { $implicit: it, index: i, hide: true }" /></div>
137
+ </div>
138
+ }
139
+ </div>
140
+ }
141
+ </div>
142
+ </div>
143
+ @if (caption() || controls() || ticks()) {
144
+ <div style="display: grid; justify-items: center; gap: 14px; margin-block-start: calc(var(--_h) * -0.04)">
145
+ <div style="display: flex; align-items: center; justify-content: center; gap: 20px; inline-size: 100%; block-size: 44px">
146
+ @if (controls()) {
147
+ <button type="button" class="nav" style="box-sizing: border-box; display: grid; place-items: center; flex: none; padding: 0; border-radius: 50%; background: var(--ui-bg-surface); color: var(--ui-text); box-shadow: var(--ui-shadow-sm); transition: transform calc(160ms * var(--ui-motion-scale)) var(--ui-ease-out)" [attr.aria-label]="t().previous" [disabled]="front() <= 0" (click)="step(-1)">
148
+ <svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="scale: var(--_s) 1"><path d="M10 3.5 5.5 8l4.5 4.5" /></svg>
149
+ </button>
150
+ }
151
+ <div class="cap" aria-live="polite" style="inline-size: min(220px, 55%); min-inline-size: 0; text-align: center; overflow: hidden">
152
+ @if (caption()) {
153
+ @for (c of current(); track c.id) {
154
+ <div class="in" [style.--_d]="dir()">
155
+ @if (captionTpl(); as tpl) {
156
+ <ng-container *ngTemplateOutlet="tpl.template; context: { $implicit: c, index: front() }" />
157
+ } @else {
158
+ @if (c.title) {<div class="title" style="overflow: hidden; white-space: nowrap; font-size: 15px; line-height: 1.35; font-weight: var(--ui-weight-semibold); letter-spacing: -0.01em">{{ c.title }}</div>}
159
+ @if (c.subtitle) {<div class="sub" style="color: var(--ui-text-muted); font-size: 13px; line-height: 1.4">{{ c.subtitle }}</div>}
160
+ }
161
+ </div>
162
+ }
163
+ }
164
+ </div>
165
+ @if (controls()) {
166
+ <button type="button" class="nav" style="box-sizing: border-box; display: grid; place-items: center; flex: none; padding: 0; border-radius: 50%; background: var(--ui-bg-surface); color: var(--ui-text); box-shadow: var(--ui-shadow-sm); transition: transform calc(160ms * var(--ui-motion-scale)) var(--ui-ease-out)" [attr.aria-label]="t().next" [disabled]="front() >= items().length - 1" (click)="step(1)">
167
+ <svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="scale: var(--_s) 1"><path d="M6 3.5 10.5 8 6 12.5" /></svg>
168
+ </button>
169
+ }
170
+ </div>
171
+ @if (ticks()) {
172
+ <div style="display: flex; gap: 2px">
173
+ @for (it of items(); track it.id; let i = $index) {
174
+ <button type="button" class="tick" tabindex="-1" [attr.aria-label]="fill(t().show, it, i)" [attr.aria-current]="i === front() ? 'true' : null" (click)="go(i)"
175
+ style="box-sizing: border-box; display: grid; place-items: center; inline-size: 14px; block-size: 14px; padding: 0; border: 0; background: none; cursor: pointer"></button>
176
+ }
177
+ </div>
178
+ }
179
+ </div>
180
+ }
181
+ <ng-template #art let-it let-i="index" let-hide="hide">
182
+ <div style="position: absolute; inset-block: 0; left: -8%; inline-size: 116%; translate: var(--_x, 0)">
183
+ @if (coverTpl(); as tpl) {
184
+ <ng-container *ngTemplateOutlet="tpl.template; context: { $implicit: it, index: i }" />
185
+ } @else if (it.image) {
186
+ <img [src]="it.image" [alt]="hide ? '' : (it.alt ?? '')" draggable="false" style="display: block; inline-size: 100%; block-size: 100%; object-fit: cover" />
187
+ }
188
+ </div>
189
+ </ng-template>
190
+ `,
191
+ styles: `
192
+ @layer ui {
193
+ :host { display: grid; inline-size: 100%; min-inline-size: 0; }
194
+ }
195
+ :host {
196
+ --_s: 1;
197
+ --_c: light-dark(var(--ui-text), var(--ui-bg-canvas));
198
+ --_fl: var(--ui-cover-flow-floor, light-dark(color-mix(in srgb, var(--_c) 16%, #0000), color-mix(in srgb, var(--_c) 45%, #0000)));
199
+ --_rf: light-dark(rgb(0 0 0 / 0.22), rgb(0 0 0 / 0.3));
200
+ box-sizing: border-box;
201
+ gap: 4px;
202
+ color: var(--ui-text);
203
+ font-family: var(--ui-font-sans);
204
+ }
205
+ :host::before { content: 'x x x x x x x x' / ''; display: block; block-size: 0; overflow: hidden; font-size: 0; word-spacing: calc(var(--_n) / 7); grid-area: 1 / 1; }
206
+ .card {
207
+ box-sizing: border-box; position: absolute; inset: 0; overflow: hidden; border-radius: var(--ui-radius-lg); background: var(--ui-bg-muted);
208
+ box-shadow: var(--ui-cover-flow-shadow, 0 1px 2px light-dark(color-mix(in srgb, var(--_c) 5%, #0000), color-mix(in srgb, var(--_c) 30%, #0000)), 0 10px 20px -12px light-dark(color-mix(in srgb, var(--_c) 18%, #0000), color-mix(in srgb, var(--_c) 60%, #0000)));
209
+ outline: calc(var(--ui-focus-width) + 1px) solid #0000;
210
+ transition: outline-color calc(180ms * var(--ui-motion-scale));
211
+ }
212
+ .card::before, .card::after { content: ''; position: absolute; z-index: 1; inset: 0; pointer-events: none; }
213
+ .card::before { opacity: calc(var(--_u, 0) * 0.9); background: linear-gradient(var(--_sa, 90deg), color-mix(in srgb, var(--ui-bg-knob) 22%, #0000), #0000 45%); }
214
+ .card::after { opacity: var(--_u, 0); border-radius: inherit; background: var(--ui-cover-flow-veil, light-dark(color-mix(in srgb, var(--ui-bg-canvas) 24%, #0000), color-mix(in srgb, var(--ui-bg-canvas) 50%, #0000))); box-shadow: inset 0 0 0 1px light-dark(color-mix(in srgb, var(--ui-text) 9%, #0000), color-mix(in srgb, var(--ui-text) 16%, #0000)); }
215
+ .stage:focus-visible [data-active] .card { outline-color: var(--ui-cover-flow-ring, var(--ui-focus-ring)); }
216
+ .in { animation: ui-cover-flow-in calc(420ms * var(--ui-motion-scale)) cubic-bezier(0.16, 1, 0.3, 1) both; }
217
+ :host(:dir(rtl)) { --_s: -1; }
218
+ .nav { inline-size: 32px; block-size: 32px; border: 0; cursor: pointer; }
219
+ .nav:active:not(:disabled) { transform: scale(0.92); }
220
+ .nav:disabled { opacity: 0.35; cursor: default; }
221
+ .nav:focus-visible { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset); }
222
+ .tick::before {
223
+ content: ''; inline-size: 5px; block-size: 5px; border-radius: 3px; background: light-dark(color-mix(in srgb, var(--ui-text) 16%, #0000), color-mix(in srgb, var(--ui-text) 20%, #0000));
224
+ transition: inline-size calc(320ms * var(--ui-motion-scale)) cubic-bezier(0.16, 1, 0.3, 1), background-color calc(200ms * var(--ui-motion-scale));
225
+ }
226
+ .tick[aria-current]::before { inline-size: 14px; background: var(--ui-text); }
227
+ @media (hover: hover) { .tick:not([aria-current]):hover::before { background: var(--ui-text-muted); } }
228
+ @media (pointer: coarse) { .nav { inline-size: 40px; block-size: 40px; } }
229
+ @media (forced-colors: active) {
230
+ .card { border: 1px solid CanvasText; outline-width: 0; }
231
+ .stage:focus-visible [data-active] .card { outline: 2px solid Highlight; }
232
+ .refl, .floor { display: none; }
233
+ .nav { border: 1px solid ButtonText; }
234
+ .tick::before { forced-color-adjust: none; background: CanvasText; }
235
+ .tick[aria-current]::before { background: Highlight; }
236
+ }
237
+ @keyframes ui-cover-flow-in { from { opacity: 0; translate: calc(14px * var(--_d, 1) * var(--_s)) 4px; filter: blur(3px); } }
238
+ `,
239
+ })
240
+ export class UiCoverFlow {
241
+ /** The covers, in order. */
242
+ readonly items = input.required<CoverFlowItem[]>();
243
+ /** The cover in front. Bind it two-way; it follows drags as they pass each cover. Left out, the row starts on the middle cover. */
244
+ readonly index = model<number | undefined>();
245
+ /** A click on the front cover, or Enter while the row has focus. */
246
+ readonly selected = output<{ item: CoverFlowItem; index: number }>();
247
+ /** Cover width in px. The row scales down in narrow containers, to half at most. */
248
+ readonly itemWidth = input(280, { transform: numberAttribute });
249
+ /** Cover height in px. */
250
+ readonly itemHeight = input(280, { transform: numberAttribute });
251
+ /** How far side covers turn away, in degrees. */
252
+ readonly angle = input(50, { transform: numberAttribute });
253
+ /** Mirror the covers on the floor. */
254
+ readonly reflection = input(true, { transform: booleanAttribute });
255
+ /** Title and subtitle of the front cover. */
256
+ readonly caption = input(true, { transform: booleanAttribute });
257
+ /** Previous and next buttons beside the caption. */
258
+ readonly controls = input(true, { transform: booleanAttribute });
259
+ /** A row of position ticks; clicking one jumps there. */
260
+ readonly ticks = input(true, { transform: booleanAttribute });
261
+ /** A soft click each time a new cover reaches the front. */
262
+ readonly sound = input(false, { transform: booleanAttribute });
263
+ /** Accessible name of the carousel. */
264
+ readonly label = input('Cover flow');
265
+ /** Every other spoken string. */
266
+ readonly labels = input<Partial<CoverFlowLabels>>({});
267
+
268
+ protected readonly t = computed(() => ({ ...LABELS, ...this.labels() }));
269
+ protected readonly coverTpl = contentChild(UiCoverFlowCover);
270
+ protected readonly captionTpl = contentChild(UiCoverFlowCaption);
271
+ protected readonly front = signal(0);
272
+ protected readonly dir = signal(1);
273
+ protected readonly current = computed(() => {
274
+ const it = this.items()[this.front()];
275
+ return it ? [it] : [];
276
+ });
277
+ private readonly width = signal(0);
278
+ protected readonly k = computed(() => {
279
+ const w = this.width();
280
+ return w ? Math.min(1, Math.max(0.5, w / (3.2 * this.itemWidth()))) : 1;
281
+ });
282
+ protected readonly w = computed(() => this.itemWidth() * this.k());
283
+ protected readonly h = computed(() => this.itemHeight() * this.k());
284
+
285
+ private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
286
+ private readonly doc = inject(DOCUMENT);
287
+ private readonly view = this.doc.defaultView;
288
+ private readonly motion = this.view?.matchMedia?.('(prefers-reduced-motion: reduce)');
289
+ private readonly stage = viewChild.required<ElementRef<HTMLElement>>('stage');
290
+ private readonly slides = viewChildren<ElementRef<HTMLElement>>('slide');
291
+
292
+ private pos = 0;
293
+ private vel = 0;
294
+ private target = 0;
295
+ private count = 0;
296
+ private raf = 0;
297
+ private last = 0;
298
+ private written: number | undefined;
299
+ private drag?: Drag;
300
+ private swallow = false;
301
+ private still = false;
302
+ private unbind?: () => void;
303
+ private wheelFrom = -1;
304
+ private wheelTimer = 0;
305
+ private audio?: AudioContext;
306
+
307
+ constructor() {
308
+ const onVisible = () => {
309
+ if (this.doc.visibilityState === 'hidden') this.snap();
310
+ };
311
+ const onClick = (e: Event) => {
312
+ if (!this.swallow) return;
313
+ this.swallow = false;
314
+ e.preventDefault();
315
+ e.stopPropagation();
316
+ };
317
+ let ro: ResizeObserver | undefined;
318
+
319
+ afterNextRender(() => {
320
+ if (isDevMode() && !this.label()?.trim()) console.warn('ui-cover-flow: give the carousel a name with label="…".', this.host);
321
+ this.doc.addEventListener('visibilitychange', onVisible);
322
+ this.stage().nativeElement.addEventListener('click', onClick, true);
323
+ if (this.view?.ResizeObserver) {
324
+ ro = new this.view.ResizeObserver(() => this.width.set(this.host.clientWidth));
325
+ ro.observe(this.host);
326
+ }
327
+ this.width.set(this.host.clientWidth);
328
+ });
329
+
330
+ effect(() => {
331
+ const n = this.items().length;
332
+ const i = this.index();
333
+ untracked(() => {
334
+ if (n !== this.count) {
335
+ const first = !this.count;
336
+ this.count = n;
337
+ if (first) {
338
+ this.pos = this.target = this.clamp(i ?? Math.floor((n - 1) / 2));
339
+ this.vel = 0;
340
+ this.front.set(this.target);
341
+ this.written = i;
342
+ return;
343
+ }
344
+ this.target = this.clamp(this.target);
345
+ this.pos = Math.min(this.pos, n - 1 + 0.5);
346
+ this.run();
347
+ }
348
+ if (i == null || i === this.written) return;
349
+ this.written = i;
350
+ this.go(i);
351
+ });
352
+ });
353
+
354
+ afterRenderEffect(() => {
355
+ this.slides();
356
+ this.k();
357
+ this.angle();
358
+ untracked(() => {
359
+ this.calm();
360
+ this.paint();
361
+ });
362
+ });
363
+
364
+ inject(DestroyRef).onDestroy(() => {
365
+ this.unbind?.();
366
+ this.stop();
367
+ ro?.disconnect();
368
+ this.view?.clearTimeout(this.wheelTimer);
369
+ this.doc.removeEventListener('visibilitychange', onVisible);
370
+ this.stage().nativeElement.removeEventListener('click', onClick, true);
371
+ this.audio?.close().catch(() => {});
372
+ });
373
+ }
374
+
375
+ protected name(it: CoverFlowItem, i: number): string {
376
+ return this.fill(this.t().position, it, i);
377
+ }
378
+
379
+ protected fill(s: string, it: CoverFlowItem, i: number): string {
380
+ return s
381
+ .replace('{n}', String(i + 1))
382
+ .replace('{total}', String(this.items().length))
383
+ .replace('{title}', it.title ?? '')
384
+ .replace(/[\s:]+$/, '')
385
+ .trim();
386
+ }
387
+
388
+ /** Moves to a cover with the spring. */
389
+ go(i: number): void {
390
+ this.target = this.clamp(i);
391
+ this.run();
392
+ }
393
+
394
+ protected step(d: number): void {
395
+ this.go(Math.round(this.target) + d);
396
+ }
397
+
398
+ protected key(e: KeyboardEvent): void {
399
+ if (e.target !== e.currentTarget || e.altKey || e.ctrlKey || e.metaKey) return;
400
+ const s = this.side();
401
+ const n = this.items().length;
402
+ if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') this.step(e.key === 'ArrowRight' ? s : -s);
403
+ else if (e.key === 'Home') this.go(0);
404
+ else if (e.key === 'End') this.go(n - 1);
405
+ else if (e.key === 'Enter') this.select(this.front());
406
+ else return;
407
+ e.preventDefault();
408
+ }
409
+
410
+ protected down(e: PointerEvent): void {
411
+ if (this.drag || !this.count || (e.pointerType === 'mouse' && e.button !== 0)) return;
412
+ if ((e.target as Element).closest?.('a, button, input, textarea, select')) return;
413
+ const el = this.stage().nativeElement;
414
+ const hit = (e.target as Element).closest?.('[data-i]');
415
+ const d: Drag = {
416
+ id: e.pointerId,
417
+ x0: e.clientX,
418
+ p0: this.pos,
419
+ f0: this.clamp(Math.round(this.pos)),
420
+ moved: false,
421
+ dir: 0,
422
+ last: e.clientX,
423
+ hit: hit ? Number(hit.getAttribute('data-i')) : -1,
424
+ samples: [{ t: e.timeStamp, p: this.pos }],
425
+ };
426
+ this.drag = d;
427
+ this.swallow = false;
428
+ this.calm();
429
+ this.stop();
430
+ this.vel = 0;
431
+ const per = PX_PER_COVER * this.k();
432
+ const move = (ev: PointerEvent) => {
433
+ if (ev.pointerId !== d.id) return;
434
+ if (ev.pointerType === 'mouse' && (ev.buttons & 1) === 0) return end(ev);
435
+ if (!d.moved && Math.abs(ev.clientX - d.x0) > 5) {
436
+ d.moved = true;
437
+ el.setPointerCapture?.(d.id);
438
+ }
439
+ if (!d.moved) return;
440
+ if (ev.clientX !== d.last) d.dir = Math.sign(d.last - ev.clientX) * this.side();
441
+ d.last = ev.clientX;
442
+ const n = this.count - 1;
443
+ let p = d.p0 - ((ev.clientX - d.x0) / per) * this.side();
444
+ if (p < 0) p *= 0.3;
445
+ else if (p > n) p = n + (p - n) * 0.3;
446
+ this.pos = this.target = p;
447
+ d.samples.push({ t: ev.timeStamp, p });
448
+ while (d.samples.length > 2 && ev.timeStamp - d.samples[0].t > 80) d.samples.shift();
449
+ this.paint();
450
+ };
451
+ const end = (ev: PointerEvent) => {
452
+ if (ev.pointerId !== d.id || this.drag !== d) return;
453
+ this.unbind?.();
454
+ this.drag = undefined;
455
+ const inside = ev.type === 'pointerup' && el.contains(ev.target as Node);
456
+ if (!d.moved) {
457
+ if (inside && d.hit >= 0) {
458
+ if (d.hit === this.front()) this.select(d.hit);
459
+ else this.go(d.hit);
460
+ }
461
+ return;
462
+ }
463
+ this.swallow = inside;
464
+ const a = d.samples[0];
465
+ const b = d.samples[d.samples.length - 1];
466
+ const span = b.t - a.t;
467
+ const v = span > 4 && ev.timeStamp - b.t < 60 ? ((b.p - a.p) / span) * 1000 : 0;
468
+ this.vel = Math.max(-35, Math.min(35, v));
469
+ let t = Math.round(this.pos + this.vel * 0.1);
470
+ if (d.dir > 0) t = Math.max(t, d.f0 + 1);
471
+ else if (d.dir < 0) t = Math.min(t, d.f0 - 1);
472
+ this.target = this.clamp(t);
473
+ this.run();
474
+ };
475
+ const on = [el, this.doc];
476
+ for (const t of on) {
477
+ t.addEventListener('pointerup', end as EventListener);
478
+ t.addEventListener('pointercancel', end as EventListener);
479
+ }
480
+ el.addEventListener('pointermove', move);
481
+ this.unbind = () => {
482
+ this.unbind = undefined;
483
+ el.removeEventListener('pointermove', move);
484
+ for (const t of on) {
485
+ t.removeEventListener('pointerup', end as EventListener);
486
+ t.removeEventListener('pointercancel', end as EventListener);
487
+ }
488
+ };
489
+ }
490
+
491
+ protected wheel(e: WheelEvent): void {
492
+ if (Math.abs(e.deltaX) <= Math.abs(e.deltaY) || !this.count || this.drag) return;
493
+ e.preventDefault();
494
+ if (this.wheelFrom < 0) this.wheelFrom = this.clamp(Math.round(this.pos));
495
+ const unit = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? this.host.clientWidth : 1;
496
+ const n = this.count - 1;
497
+ this.target = Math.max(-0.4, Math.min(n + 0.4, this.target + ((e.deltaX * unit) / (WHEEL_PX * this.k())) * this.side()));
498
+ this.run();
499
+ this.view?.clearTimeout(this.wheelTimer);
500
+ this.wheelTimer = this.view?.setTimeout(() => {
501
+ const from = this.wheelFrom;
502
+ const d = this.target - from;
503
+ this.wheelFrom = -1;
504
+ this.target = this.clamp(Math.abs(d) < 0.15 ? from : d > 0 ? Math.ceil(this.target - 0.001) : Math.floor(this.target + 0.001));
505
+ this.run();
506
+ }, 120) ?? 0;
507
+ }
508
+
509
+ private select(i: number): void {
510
+ const item = this.items()[i];
511
+ if (item) this.selected.emit({ item, index: i });
512
+ }
513
+
514
+ private clamp(i: number): number {
515
+ return Math.max(0, Math.min(this.items().length - 1, Math.round(i)));
516
+ }
517
+
518
+ private side(): number {
519
+ try {
520
+ return this.host.matches(':dir(rtl)') ? -1 : 1;
521
+ } catch {
522
+ return this.host.closest('[dir]')?.getAttribute('dir') === 'rtl' ? -1 : 1;
523
+ }
524
+ }
525
+
526
+ /** Reduced motion, or --ui-motion-scale: 0. Read once per drag, run or render to keep paints cheap. */
527
+ private calm(): boolean {
528
+ this.still = !!this.motion?.matches || parseFloat(this.view?.getComputedStyle(this.host).getPropertyValue('--ui-motion-scale') ?? '') === 0;
529
+ return this.still;
530
+ }
531
+
532
+ private run(): void {
533
+ if (this.drag) return;
534
+ if (this.calm() || this.doc.visibilityState === 'hidden' || !this.view) return this.snap();
535
+ if (this.raf) return;
536
+ this.last = 0;
537
+ this.raf = this.view.requestAnimationFrame(this.frame);
538
+ }
539
+
540
+ private stop(): void {
541
+ if (this.raf) this.view?.cancelAnimationFrame(this.raf);
542
+ this.raf = 0;
543
+ }
544
+
545
+ private snap(): void {
546
+ this.stop();
547
+ if (this.drag) return;
548
+ this.pos = this.target = this.clamp(this.target);
549
+ this.vel = 0;
550
+ this.paint();
551
+ }
552
+
553
+ private readonly frame = (now: number) => {
554
+ this.raf = 0;
555
+ let dt = this.last ? Math.min(now - this.last, 32) : 16;
556
+ this.last = now;
557
+ while (dt > 0) {
558
+ const h = Math.min(dt, 1) / 1000;
559
+ this.vel += (250 * (this.target - this.pos) - 33 * this.vel) * h;
560
+ this.pos += this.vel * h;
561
+ dt -= 1;
562
+ }
563
+ const done = Math.abs(this.pos - this.target) < 0.0005 && Math.abs(this.vel) < 0.001;
564
+ if (done) {
565
+ this.pos = this.target;
566
+ this.vel = 0;
567
+ }
568
+ this.paint();
569
+ if (!done && this.view) this.raf = this.view.requestAnimationFrame(this.frame);
570
+ };
571
+
572
+ private paint(): void {
573
+ const els = this.slides();
574
+ const W = this.w();
575
+ const s = this.side();
576
+ const A = this.angle();
577
+ const drift = this.still ? 0 : 1;
578
+ for (const { nativeElement: el } of els) {
579
+ const u = Number(el.getAttribute('data-i')) - this.pos;
580
+ const a = Math.abs(u);
581
+ const c = Math.max(-1, Math.min(1, u));
582
+ const x = (a <= 1 ? 0.78 * u : Math.sign(u) * (0.78 + 0.27 * (a - 1))) * W * s;
583
+ const sc = a <= 1 ? 1 - 0.08 * a : Math.max(0.86, 0.92 - 0.015 * (a - 1));
584
+ const st = el.style;
585
+ st.transform = `translate3d(${x}px,0,${-0.7 * W * Math.min(a, 1)}px) rotateY(${-A * c * s}deg) scale(${sc})`;
586
+ st.zIndex = String(1000 - Math.round(10 * a));
587
+ st.visibility = a > 8 ? 'hidden' : '';
588
+ st.setProperty('--_u', String(Math.min(a, 1)));
589
+ st.setProperty('--_x', `${Math.max(-0.087, Math.min(0.087, -0.058 * u)) * W * s * drift}px`);
590
+ st.setProperty('--_sa', u * s >= 0 ? '90deg' : '-90deg');
591
+ }
592
+ const f = this.clamp(this.pos);
593
+ const prev = this.front();
594
+ if (!this.count || f === prev) return;
595
+ this.dir.set(f > prev ? 1 : -1);
596
+ this.front.set(f);
597
+ this.written = f;
598
+ this.index.set(f);
599
+ if (this.sound()) this.click();
600
+ }
601
+
602
+ private click(): void {
603
+ const Ctx = this.view?.AudioContext;
604
+ if (!Ctx) return;
605
+ try {
606
+ const ac = (this.audio ??= new Ctx());
607
+ if (ac.state === 'suspended') ac.resume().catch(() => {});
608
+ const o = ac.createOscillator();
609
+ const g = ac.createGain();
610
+ const t0 = ac.currentTime;
611
+ o.type = 'triangle';
612
+ o.frequency.setValueAtTime(1800, t0);
613
+ o.frequency.exponentialRampToValueAtTime(700, t0 + 0.03);
614
+ g.gain.setValueAtTime(0.04, t0);
615
+ g.gain.exponentialRampToValueAtTime(0.0001, t0 + 0.035);
616
+ o.connect(g).connect(ac.destination);
617
+ o.start(t0);
618
+ o.stop(t0 + 0.04);
619
+ } catch {
620
+ this.audio = undefined;
621
+ }
622
+ }
623
+ }