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.
- package/LICENSE +21 -0
- package/README.md +153 -2
- package/cli/ochreui.mjs +601 -0
- package/mcp/core.mjs +126 -0
- package/mcp/docs.json +906 -0
- package/mcp/server.mjs +23 -0
- package/package.json +393 -3
- package/registry/agent-team.ts +350 -0
- package/registry/avatar.ts +300 -0
- package/registry/badge.ts +207 -0
- package/registry/breadcrumb.ts +435 -0
- package/registry/button.ts +238 -0
- package/registry/card.ts +221 -0
- package/registry/change-summary.ts +200 -0
- package/registry/checkbox.ts +204 -0
- package/registry/code-block.ts +332 -0
- package/registry/color-picker.ts +720 -0
- package/registry/comment-thread.ts +503 -0
- package/registry/context-menu.ts +281 -0
- package/registry/cover-flow.ts +623 -0
- package/registry/date-picker.ts +799 -0
- package/registry/decision-inbox.ts +340 -0
- package/registry/dialog.ts +577 -0
- package/registry/dropdown-menu.ts +864 -0
- package/registry/email-draft.ts +916 -0
- package/registry/empty-calendar.ts +199 -0
- package/registry/empty-state.ts +164 -0
- package/registry/enrichment-orbit.ts +164 -0
- package/registry/filter-menu.ts +541 -0
- package/registry/form-field.ts +308 -0
- package/registry/frost-cloud.ts +381 -0
- package/registry/ghosted-chat.ts +210 -0
- package/registry/glow-cloud.ts +402 -0
- package/registry/grid-background.ts +164 -0
- package/registry/hover-card.ts +401 -0
- package/registry/icon-button.ts +133 -0
- package/registry/index.json +2124 -0
- package/registry/integration-beam.ts +588 -0
- package/registry/integration-grid.ts +209 -0
- package/registry/kbd.ts +176 -0
- package/registry/layer-stack.ts +351 -0
- package/registry/lead-sourcing.ts +285 -0
- package/registry/logo-cluster.ts +239 -0
- package/registry/logo-marquee.ts +505 -0
- package/registry/message-actions.ts +833 -0
- package/registry/model-orbit.ts +583 -0
- package/registry/model-wheel.ts +372 -0
- package/registry/notification-stack.ts +301 -0
- package/registry/number-input.ts +552 -0
- package/registry/number-ticker.ts +261 -0
- package/registry/ochre.css +917 -0
- package/registry/otp-input.ts +704 -0
- package/registry/overlay.ts +312 -0
- package/registry/pagination.ts +362 -0
- package/registry/popover.ts +296 -0
- package/registry/profile-menu.ts +332 -0
- package/registry/progress-tracker.ts +291 -0
- package/registry/rating.ts +461 -0
- package/registry/reaction-bar.ts +322 -0
- package/registry/region-map.ts +537 -0
- package/registry/resizable.ts +489 -0
- package/registry/scroll-area.ts +271 -0
- package/registry/segmented-control.ts +433 -0
- package/registry/select.ts +769 -0
- package/registry/separator.ts +97 -0
- package/registry/shimmer-loader.ts +211 -0
- package/registry/side-folder.ts +152 -0
- package/registry/skeleton.ts +136 -0
- package/registry/skill/INSTRUCTIONS.md +11 -0
- package/registry/skill/SKILL.md +65 -0
- package/registry/skill/checklist.md +45 -0
- package/registry/skill/references/agent-team.md +105 -0
- package/registry/skill/references/avatar.md +88 -0
- package/registry/skill/references/badge.md +92 -0
- package/registry/skill/references/breadcrumb.md +99 -0
- package/registry/skill/references/button.md +82 -0
- package/registry/skill/references/card.md +111 -0
- package/registry/skill/references/catalog.md +114 -0
- package/registry/skill/references/change-summary.md +103 -0
- package/registry/skill/references/checkbox.md +105 -0
- package/registry/skill/references/code-block.md +109 -0
- package/registry/skill/references/color-picker.md +138 -0
- package/registry/skill/references/comment-thread.md +164 -0
- package/registry/skill/references/context-menu.md +205 -0
- package/registry/skill/references/cover-flow.md +128 -0
- package/registry/skill/references/date-picker.md +154 -0
- package/registry/skill/references/decision-inbox.md +126 -0
- package/registry/skill/references/dialog.md +155 -0
- package/registry/skill/references/dropdown-menu.md +144 -0
- package/registry/skill/references/email-draft.md +182 -0
- package/registry/skill/references/empty-calendar.md +74 -0
- package/registry/skill/references/empty-state.md +118 -0
- package/registry/skill/references/enrichment-orbit.md +71 -0
- package/registry/skill/references/filter-menu.md +143 -0
- package/registry/skill/references/form-field.md +118 -0
- package/registry/skill/references/frost-cloud.md +80 -0
- package/registry/skill/references/ghosted-chat.md +75 -0
- package/registry/skill/references/glow-cloud.md +84 -0
- package/registry/skill/references/grid-background.md +76 -0
- package/registry/skill/references/hover-card.md +125 -0
- package/registry/skill/references/icon-button.md +99 -0
- package/registry/skill/references/integration-beam.md +107 -0
- package/registry/skill/references/integration-grid.md +100 -0
- package/registry/skill/references/kbd.md +65 -0
- package/registry/skill/references/layer-stack.md +115 -0
- package/registry/skill/references/lead-sourcing.md +92 -0
- package/registry/skill/references/logo-cluster.md +92 -0
- package/registry/skill/references/logo-marquee.md +123 -0
- package/registry/skill/references/message-actions.md +146 -0
- package/registry/skill/references/model-orbit.md +106 -0
- package/registry/skill/references/model-wheel.md +84 -0
- package/registry/skill/references/notification-stack.md +138 -0
- package/registry/skill/references/number-input.md +117 -0
- package/registry/skill/references/number-ticker.md +73 -0
- package/registry/skill/references/otp-input.md +142 -0
- package/registry/skill/references/pagination.md +112 -0
- package/registry/skill/references/popover.md +143 -0
- package/registry/skill/references/profile-menu.md +123 -0
- package/registry/skill/references/progress-tracker.md +122 -0
- package/registry/skill/references/rating.md +111 -0
- package/registry/skill/references/reaction-bar.md +128 -0
- package/registry/skill/references/region-map.md +109 -0
- package/registry/skill/references/resizable.md +127 -0
- package/registry/skill/references/scroll-area.md +113 -0
- package/registry/skill/references/segmented-control.md +96 -0
- package/registry/skill/references/select.md +122 -0
- package/registry/skill/references/separator.md +69 -0
- package/registry/skill/references/shimmer-loader.md +83 -0
- package/registry/skill/references/side-folder.md +75 -0
- package/registry/skill/references/skeleton.md +95 -0
- package/registry/skill/references/smart-recommendation.md +132 -0
- package/registry/skill/references/spinner.md +84 -0
- package/registry/skill/references/switch.md +79 -0
- package/registry/skill/references/tab-overload.md +70 -0
- package/registry/skill/references/tag-input.md +126 -0
- package/registry/skill/references/team-invite.md +94 -0
- package/registry/skill/references/testimonial-wall.md +110 -0
- package/registry/skill/references/text-area.md +115 -0
- package/registry/skill/references/text-field.md +126 -0
- package/registry/skill/references/text-reveal.md +71 -0
- package/registry/skill/references/thinking-loader.md +87 -0
- package/registry/skill/references/time-picker.md +122 -0
- package/registry/skill/references/tips-panel.md +115 -0
- package/registry/skill/references/toggle-group.md +98 -0
- package/registry/skill/references/tool-call-card.md +151 -0
- package/registry/skill/references/tooltip.md +94 -0
- package/registry/skill/references/tree-view.md +172 -0
- package/registry/skill/theming.md +57 -0
- package/registry/smart-recommendation.ts +415 -0
- package/registry/spinner.ts +67 -0
- package/registry/switch.ts +146 -0
- package/registry/tab-overload.ts +211 -0
- package/registry/tag-input.ts +620 -0
- package/registry/team-invite.ts +248 -0
- package/registry/testimonial-wall.ts +521 -0
- package/registry/text-area.ts +432 -0
- package/registry/text-field.ts +415 -0
- package/registry/text-reveal.ts +175 -0
- package/registry/theme.ts +68 -0
- package/registry/thinking-loader.ts +302 -0
- package/registry/time-picker.ts +828 -0
- package/registry/tips-panel.ts +312 -0
- package/registry/toggle-group.ts +357 -0
- package/registry/tool-call-card.ts +578 -0
- package/registry/tooltip.ts +486 -0
- package/registry/tree-view.ts +454 -0
- package/styles/base.css +500 -0
- package/styles/tokens.css +415 -0
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
// Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
|
|
2
|
+
/**
|
|
3
|
+
* Logo Marquee, from Ochre (https://ochreui.dev).
|
|
4
|
+
* Needs ochre.css (tokens and the .ui-sr class), added once by `npx ochreui init`.
|
|
5
|
+
*
|
|
6
|
+
* <ui-logo-marquee [rows]="2" labels="beside" label="Companies that use the product">
|
|
7
|
+
* <ng-template uiLogo name="Fernway" color="var(--ui-hue-green)"><svg viewBox="0 0 24 24" fill="currentColor">…</svg></ng-template>
|
|
8
|
+
* <ng-template uiLogo name="Tessel" src="/logos/tessel.svg" href="/customers/tessel" />
|
|
9
|
+
* </ui-logo-marquee>
|
|
10
|
+
* An endless strip of logos that stops on hover or focus, can be dragged, and lifts the hovered logo to its
|
|
11
|
+
* colour. Under reduced motion it is a still, centred list.
|
|
12
|
+
*
|
|
13
|
+
* Public styling hooks (set them on the element or any ancestor):
|
|
14
|
+
* --ui-logo-marquee-ink marks and names at rest (default: the muted text colour)
|
|
15
|
+
* --ui-logo-marquee-fade width of the soft fade at each end (default: min(20%, 168px); Classic min(14%, 120px))
|
|
16
|
+
*/
|
|
17
|
+
import {
|
|
18
|
+
Component,
|
|
19
|
+
DOCUMENT,
|
|
20
|
+
DestroyRef,
|
|
21
|
+
Directive,
|
|
22
|
+
ElementRef,
|
|
23
|
+
TemplateRef,
|
|
24
|
+
afterNextRender,
|
|
25
|
+
afterRenderEffect,
|
|
26
|
+
booleanAttribute,
|
|
27
|
+
computed,
|
|
28
|
+
contentChildren,
|
|
29
|
+
effect,
|
|
30
|
+
inject,
|
|
31
|
+
input,
|
|
32
|
+
isDevMode,
|
|
33
|
+
model,
|
|
34
|
+
numberAttribute,
|
|
35
|
+
signal,
|
|
36
|
+
untracked,
|
|
37
|
+
viewChildren,
|
|
38
|
+
} from '@angular/core';
|
|
39
|
+
import { NgTemplateOutlet } from '@angular/common';
|
|
40
|
+
|
|
41
|
+
export type LogoMarqueeDirection = 'left' | 'right';
|
|
42
|
+
export type LogoMarqueeLabels = 'none' | 'below' | 'beside';
|
|
43
|
+
|
|
44
|
+
/** One logo: an `<ng-template uiLogo name="…">` holding an inline SVG that fills with currentColor, or empty with `src`. */
|
|
45
|
+
@Directive({ selector: 'ng-template[uiLogo]' })
|
|
46
|
+
export class UiLogo {
|
|
47
|
+
/** The company name: shown as the label and read by screen readers. */
|
|
48
|
+
readonly name = input.required<string>();
|
|
49
|
+
/** The colour the mark lifts to on hover. Without it the mark goes to ink. */
|
|
50
|
+
readonly color = input<string>();
|
|
51
|
+
/** Optical size correction for the mark, 1 = the logo size. */
|
|
52
|
+
readonly scale = input(1, { transform: numberAttribute });
|
|
53
|
+
/** Makes the logo a link. */
|
|
54
|
+
readonly href = input<string>();
|
|
55
|
+
/** An image for the mark, used when the template is empty. */
|
|
56
|
+
readonly src = input<string>();
|
|
57
|
+
readonly template = inject(TemplateRef);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface Drag {
|
|
61
|
+
id: number;
|
|
62
|
+
start: number;
|
|
63
|
+
last: number;
|
|
64
|
+
moved: boolean;
|
|
65
|
+
samples: { t: number; x: number }[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface Row {
|
|
69
|
+
x: number;
|
|
70
|
+
v: number;
|
|
71
|
+
fv: number;
|
|
72
|
+
tau: number;
|
|
73
|
+
lin: number;
|
|
74
|
+
set: number;
|
|
75
|
+
drag?: Drag;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const UP = 0.7;
|
|
79
|
+
const DOWN = 0.33;
|
|
80
|
+
|
|
81
|
+
@Component({
|
|
82
|
+
selector: 'ui-logo-marquee',
|
|
83
|
+
imports: [NgTemplateOutlet],
|
|
84
|
+
host: {
|
|
85
|
+
'[attr.role]': "logos().length ? 'region' : null",
|
|
86
|
+
'[attr.aria-label]': 'logos().length ? label() : null',
|
|
87
|
+
'[attr.tabindex]': 'logos().length && !linked() ? 0 : null',
|
|
88
|
+
'[attr.data-labels]': 'labels()',
|
|
89
|
+
'[attr.data-grayscale]': 'grayscale()',
|
|
90
|
+
'[style.--_gap]': "gap() + 'px'",
|
|
91
|
+
'(pointerenter)': 'hover($event, true)',
|
|
92
|
+
'(pointerleave)': 'hover($event, false)',
|
|
93
|
+
'(focusin)': 'focusIn($event)',
|
|
94
|
+
'(focusout)': 'focusOut($event)',
|
|
95
|
+
'(keydown)': 'key($event)',
|
|
96
|
+
},
|
|
97
|
+
template: `
|
|
98
|
+
@if (still() && logos().length) {
|
|
99
|
+
<ul class="static" style="display: flex; margin: 0; list-style: none">
|
|
100
|
+
@for (l of logos(); track l) {<li style="display: flex; flex: none; margin-inline: var(--_a) var(--_e)"><ng-container *ngTemplateOutlet="logo; context: { $implicit: l, hide: false }" /></li>}
|
|
101
|
+
</ul>
|
|
102
|
+
} @else if (logos().length) {
|
|
103
|
+
@for (row of rowList(); track $index) {
|
|
104
|
+
<div #row class="row" (pointerdown)="down($event, $index)">
|
|
105
|
+
<div class="track" style="display: flex; inline-size: max-content; will-change: transform">
|
|
106
|
+
@for (c of copyList(); track c) {
|
|
107
|
+
<ul style="display: flex; flex: none; margin: 0; padding: 0; list-style: none" [attr.aria-hidden]="c === 1 ? null : 'true'">
|
|
108
|
+
@for (l of row; track l) {<li style="display: flex; flex: none; margin-inline: var(--_a) var(--_e)"><ng-container *ngTemplateOutlet="logo; context: { $implicit: l, hide: c !== 1 }" /></li>}
|
|
109
|
+
</ul>
|
|
110
|
+
}
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
<ng-template #logo let-l let-hide="hide">
|
|
116
|
+
@if (l.href()) {
|
|
117
|
+
<a class="logo" [href]="l.href()" draggable="false" [attr.tabindex]="hide ? -1 : null" [style.--_b]="l.color()"><ng-container *ngTemplateOutlet="inner; context: { $implicit: l }" /></a>
|
|
118
|
+
} @else {
|
|
119
|
+
<span class="logo" [style.--_b]="l.color()"><ng-container *ngTemplateOutlet="inner; context: { $implicit: l }" /></span>
|
|
120
|
+
}
|
|
121
|
+
</ng-template>
|
|
122
|
+
<ng-template #inner let-l>
|
|
123
|
+
<span class="mark" aria-hidden="true" style="place-items: center; flex: none; block-size: var(--_s); min-inline-size: var(--_s); transition: inherit" [attr.data-l]="l.name().charAt(0)" [style.--_k]="l.scale()">@if (!l.src()) {<ng-container *ngTemplateOutlet="l.template" />} @else if (!broken().has(l)) {<img [src]="l.src()" alt="" draggable="false" (error)="fail(l)" />}</span>
|
|
124
|
+
<span [class]="labels() === 'none' ? 'ui-sr' : 'name'" style="white-space: nowrap; overflow: hidden">{{ l.name() }}</span>
|
|
125
|
+
</ng-template>
|
|
126
|
+
`,
|
|
127
|
+
styles: `
|
|
128
|
+
:host {
|
|
129
|
+
--_t: var(--ui-look-tray, 0);
|
|
130
|
+
--_s: var(--ui-space-6);
|
|
131
|
+
--_g: var(--_gap);
|
|
132
|
+
--_m: 0.36;
|
|
133
|
+
--_fs: 0.66;
|
|
134
|
+
--_lh: 1.2;
|
|
135
|
+
--_w: var(--ui-weight-medium);
|
|
136
|
+
--_ls: -0.01em;
|
|
137
|
+
--_p: var(--ui-space-2);
|
|
138
|
+
--_r: var(--ui-space-1-5);
|
|
139
|
+
--_d: 240ms;
|
|
140
|
+
--_o: var(--ui-focus-offset-inset);
|
|
141
|
+
--_f: var(--ui-logo-marquee-fade, min(20%, 168px));
|
|
142
|
+
box-sizing: border-box;
|
|
143
|
+
display: grid;
|
|
144
|
+
gap: var(--ui-space-6);
|
|
145
|
+
container: ui-logo-marquee / inline-size;
|
|
146
|
+
border-radius: var(--ui-space-1-5);
|
|
147
|
+
outline: 0;
|
|
148
|
+
}
|
|
149
|
+
:host(:not([role])) { display: none; }
|
|
150
|
+
:host(:focus-visible), .logo:focus-visible { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--_o); }
|
|
151
|
+
@container ui-logo-marquee (width <= 520px) {
|
|
152
|
+
.row, .static { --_s: calc(var(--ui-space-5) + 2px * var(--_t)); --_g: calc(var(--_gap) * 0.62); }
|
|
153
|
+
}
|
|
154
|
+
.row {
|
|
155
|
+
--_a: 0; --_e: var(--_g);
|
|
156
|
+
box-sizing: border-box; overflow: hidden; padding-block: var(--_p); cursor: grab; touch-action: pan-y; user-select: none; -webkit-user-select: none;
|
|
157
|
+
mask-image: linear-gradient(to right, #0000, #000 var(--_f), #000 calc(100% - var(--_f)), #0000);
|
|
158
|
+
}
|
|
159
|
+
.row[data-drag] { cursor: grabbing; }
|
|
160
|
+
.static { --_a: calc(var(--_g) / 2); --_e: var(--_a); box-sizing: border-box; flex-wrap: wrap; justify-content: center; row-gap: var(--_a); padding: var(--ui-space-2) var(--ui-space-4); }
|
|
161
|
+
@container style(--ui-look-tray: 1) {
|
|
162
|
+
:host {
|
|
163
|
+
--_s: calc(var(--ui-space-6) + 4px); --_m: 0.32; --_fs: 0.68; --_lh: 1.15; --_w: var(--ui-weight-semibold); --_ls: -0.025em;
|
|
164
|
+
--_p: var(--ui-space-1-5); --_r: var(--ui-space-2); --_d: 260ms; --_f: var(--ui-logo-marquee-fade, min(14%, 120px));
|
|
165
|
+
gap: var(--ui-space-5);
|
|
166
|
+
}
|
|
167
|
+
.static { padding: 0 var(--ui-space-2); }
|
|
168
|
+
}
|
|
169
|
+
.logo {
|
|
170
|
+
--_o: var(--ui-focus-offset);
|
|
171
|
+
display: inline-flex; align-items: center; gap: calc(var(--_s) * var(--_m)); block-size: var(--_s); border-radius: var(--_r);
|
|
172
|
+
color: var(--ui-logo-marquee-ink, var(--ui-text-muted)); text-decoration: none; letter-spacing: var(--_ls);
|
|
173
|
+
font: var(--_w) calc(var(--_s) * var(--_fs)) / var(--_lh) var(--ui-font-sans);
|
|
174
|
+
transition: color calc(var(--_d) * var(--ui-motion-scale)) var(--ui-ease-out), opacity calc(var(--_d) * var(--ui-motion-scale));
|
|
175
|
+
}
|
|
176
|
+
.mark { display: grid; }
|
|
177
|
+
.mark > img, .mark > ::ng-deep svg { display: block; block-size: calc(var(--_s) * var(--_k, 1)); inline-size: auto; }
|
|
178
|
+
.mark:empty { inline-size: var(--_s); border-radius: var(--_r); background: currentColor; }
|
|
179
|
+
.mark:empty::before { content: attr(data-l); color: var(--ui-bg-surface); font-size: calc(var(--_s) * 0.55); font-weight: var(--ui-weight-semibold); }
|
|
180
|
+
:host([data-labels='beside']) .mark:empty { display: none; }
|
|
181
|
+
:host([data-labels='below']) .logo { flex-direction: column; block-size: auto; gap: calc(var(--_s) * 0.25); font-size: calc(var(--_s) * 0.5); }
|
|
182
|
+
:host([data-grayscale='false']) .logo, .logo:focus-visible { color: var(--ui-text); }
|
|
183
|
+
:host([data-grayscale='false']) .mark, .logo:focus-visible .mark { color: var(--_b, var(--ui-text)); }
|
|
184
|
+
@media (hover: hover) {
|
|
185
|
+
.logo:hover { color: var(--ui-text); }
|
|
186
|
+
.logo:hover .mark { color: var(--_b, var(--ui-text)); }
|
|
187
|
+
:host([data-grayscale='false']):has(.logo:hover) .logo:not(:hover) { opacity: 0.45; }
|
|
188
|
+
}
|
|
189
|
+
@media (forced-colors: active) {
|
|
190
|
+
.mark:empty { forced-color-adjust: none; background: CanvasText; }
|
|
191
|
+
.mark:empty::before { color: Canvas; }
|
|
192
|
+
}
|
|
193
|
+
`,
|
|
194
|
+
})
|
|
195
|
+
export class UiLogoMarquee {
|
|
196
|
+
/** Pixels per second, so the pace is the same at any width. */
|
|
197
|
+
readonly speed = input(40, { transform: numberAttribute });
|
|
198
|
+
/** Which way the first row runs; a second row runs the other way. Physical, also in right-to-left pages. */
|
|
199
|
+
readonly direction = input<LogoMarqueeDirection>('left');
|
|
200
|
+
/** Two rows share the logos alternately (1st, 3rd… / 2nd, 4th…). */
|
|
201
|
+
readonly rows = input<1 | 2, unknown>(1, { transform: (v) => (Number(v) === 2 ? 2 : 1) });
|
|
202
|
+
/** Space between logos in px; about 60 % of it when the strip is 520px wide or less. */
|
|
203
|
+
readonly gap = input(56, { transform: numberAttribute });
|
|
204
|
+
/** Ease to a stop while the mouse is over the strip. Keyboard focus always stops it. */
|
|
205
|
+
readonly pauseOnHover = input(true, { transform: booleanAttribute });
|
|
206
|
+
/** Quiet grey logos at rest, the hovered one lifts to its colour. Off: full colour, and the others dim on hover. */
|
|
207
|
+
readonly grayscale = input(true, { transform: booleanAttribute });
|
|
208
|
+
/** The name as a wordmark beside the mark, as a caption below it, or only for screen readers. */
|
|
209
|
+
readonly labels = input<LogoMarqueeLabels>('none');
|
|
210
|
+
/** Accessible name of the strip. */
|
|
211
|
+
readonly label = input('Logos of companies using the product');
|
|
212
|
+
/** Stops the strip. A tap on a touch screen toggles it; bind it two-way for your own pause button. */
|
|
213
|
+
readonly paused = model(false);
|
|
214
|
+
|
|
215
|
+
protected readonly logos = contentChildren(UiLogo);
|
|
216
|
+
protected readonly linked = computed(() => this.logos().some((l) => !!l.href()));
|
|
217
|
+
protected readonly rowList = computed(() => {
|
|
218
|
+
const all = this.logos();
|
|
219
|
+
return this.rows() === 2 && all.length > 1 ? [all.filter((_, i) => !(i % 2)), all.filter((_, i) => i % 2)] : [all];
|
|
220
|
+
});
|
|
221
|
+
private readonly copies = signal(3);
|
|
222
|
+
protected readonly copyList = computed(() => Array.from({ length: this.copies() }, (_, i) => i));
|
|
223
|
+
protected readonly broken = signal<ReadonlySet<UiLogo>>(new Set());
|
|
224
|
+
|
|
225
|
+
private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
|
|
226
|
+
private readonly doc = inject(DOCUMENT);
|
|
227
|
+
private readonly view = this.doc.defaultView;
|
|
228
|
+
private readonly motion = this.view?.matchMedia?.('(prefers-reduced-motion: reduce)');
|
|
229
|
+
protected readonly still = signal(!!this.motion?.matches);
|
|
230
|
+
private readonly rowEls = viewChildren<ElementRef<HTMLElement>>('row');
|
|
231
|
+
|
|
232
|
+
private state: Row[] = [];
|
|
233
|
+
private raf = 0;
|
|
234
|
+
private last = 0;
|
|
235
|
+
private inView = false;
|
|
236
|
+
private hovered = false;
|
|
237
|
+
private focused = false;
|
|
238
|
+
private swallow = false;
|
|
239
|
+
private checkAt = 0;
|
|
240
|
+
private ro?: ResizeObserver;
|
|
241
|
+
|
|
242
|
+
constructor() {
|
|
243
|
+
const onMotion = () => this.still.set(this.calm());
|
|
244
|
+
const onVisible = () => this.wake();
|
|
245
|
+
const onClick = (e: Event) => {
|
|
246
|
+
if (!this.swallow) return;
|
|
247
|
+
this.swallow = false;
|
|
248
|
+
e.preventDefault();
|
|
249
|
+
e.stopPropagation();
|
|
250
|
+
};
|
|
251
|
+
let io: IntersectionObserver | undefined;
|
|
252
|
+
|
|
253
|
+
afterNextRender(() => {
|
|
254
|
+
if (isDevMode() && !this.label()?.trim()) {
|
|
255
|
+
console.warn('ui-logo-marquee: give the strip a name with label="…".', this.host);
|
|
256
|
+
}
|
|
257
|
+
onMotion();
|
|
258
|
+
this.motion?.addEventListener?.('change', onMotion);
|
|
259
|
+
this.doc.addEventListener('visibilitychange', onVisible);
|
|
260
|
+
this.host.addEventListener('click', onClick, true);
|
|
261
|
+
if (this.view?.IntersectionObserver) {
|
|
262
|
+
io = new this.view.IntersectionObserver(
|
|
263
|
+
(entries) => {
|
|
264
|
+
this.inView = entries[entries.length - 1].isIntersecting;
|
|
265
|
+
this.wake();
|
|
266
|
+
},
|
|
267
|
+
{ rootMargin: '64px 0px' },
|
|
268
|
+
);
|
|
269
|
+
io.observe(this.host);
|
|
270
|
+
} else {
|
|
271
|
+
this.inView = true;
|
|
272
|
+
}
|
|
273
|
+
if (this.view?.ResizeObserver) this.ro = new this.view.ResizeObserver(() => this.measure());
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
afterRenderEffect(() => {
|
|
277
|
+
const els = this.rowEls();
|
|
278
|
+
this.ro?.disconnect();
|
|
279
|
+
for (const { nativeElement: row } of els) {
|
|
280
|
+
this.ro?.observe(row);
|
|
281
|
+
const real = row.firstElementChild?.children[1];
|
|
282
|
+
if (real) this.ro?.observe(real);
|
|
283
|
+
}
|
|
284
|
+
untracked(() => {
|
|
285
|
+
this.measure();
|
|
286
|
+
this.wake();
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
effect(() => {
|
|
291
|
+
this.speed();
|
|
292
|
+
this.direction();
|
|
293
|
+
this.paused();
|
|
294
|
+
this.pauseOnHover();
|
|
295
|
+
untracked(() => this.wake());
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
inject(DestroyRef).onDestroy(() => {
|
|
299
|
+
this.sleep();
|
|
300
|
+
io?.disconnect();
|
|
301
|
+
this.ro?.disconnect();
|
|
302
|
+
this.motion?.removeEventListener?.('change', onMotion);
|
|
303
|
+
this.doc.removeEventListener('visibilitychange', onVisible);
|
|
304
|
+
this.host.removeEventListener('click', onClick, true);
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
protected fail(l: UiLogo): void {
|
|
309
|
+
this.broken.update((s) => new Set(s).add(l));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
protected hover(e: PointerEvent, on: boolean): void {
|
|
313
|
+
if (e.pointerType !== 'mouse') return;
|
|
314
|
+
this.hovered = on;
|
|
315
|
+
this.wake();
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
protected focusIn(e: FocusEvent): void {
|
|
319
|
+
const t = e.target as HTMLElement;
|
|
320
|
+
if (!t.matches(':focus-visible')) return;
|
|
321
|
+
this.focused = true;
|
|
322
|
+
this.wake();
|
|
323
|
+
const row = t.closest<HTMLElement>('.row');
|
|
324
|
+
const i = this.rowEls().findIndex((r) => r.nativeElement === row);
|
|
325
|
+
if (!row || i < 0 || !this.state[i]) return;
|
|
326
|
+
const box = row.getBoundingClientRect();
|
|
327
|
+
const r = t.getBoundingClientRect();
|
|
328
|
+
const probe = this.doc.createElement('div');
|
|
329
|
+
probe.style.cssText = 'inline-size: var(--_f); block-size: 0';
|
|
330
|
+
row.append(probe);
|
|
331
|
+
const k = row.offsetWidth / box.width || 1;
|
|
332
|
+
const fade = probe.getBoundingClientRect().width * k + 8;
|
|
333
|
+
probe.remove();
|
|
334
|
+
const coast = this.state[i].v * DOWN;
|
|
335
|
+
const left = (r.left - box.left) * k + coast;
|
|
336
|
+
const right = (r.right - box.left) * k + coast;
|
|
337
|
+
const end = box.width * k;
|
|
338
|
+
const delta = left < fade ? fade - left : right > end - fade ? end - fade - right : 0;
|
|
339
|
+
if (delta) this.impulse(this.state[i], delta / 0.13, 0.13, 0);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
protected focusOut(e: FocusEvent): void {
|
|
343
|
+
if (this.host.contains(e.relatedTarget as Node | null)) return;
|
|
344
|
+
this.focused = false;
|
|
345
|
+
this.wake();
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
protected key(e: KeyboardEvent): void {
|
|
349
|
+
if (this.still() || (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') || e.altKey || e.ctrlKey || e.metaKey) return;
|
|
350
|
+
e.preventDefault();
|
|
351
|
+
for (const r of this.state) this.impulse(r, e.key === 'ArrowRight' ? -1150 : 1150, 0.13, 0);
|
|
352
|
+
this.wake();
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
protected down(e: PointerEvent, i: number): void {
|
|
356
|
+
const r = this.state[i];
|
|
357
|
+
const row = this.rowEls()[i]?.nativeElement;
|
|
358
|
+
if (!r || !row || r.drag || (e.pointerType === 'mouse' && e.button !== 0)) return;
|
|
359
|
+
this.swallow = false;
|
|
360
|
+
const d: Drag = { id: e.pointerId, start: e.clientX, last: e.clientX, moved: false, samples: [{ t: e.timeStamp, x: r.x }] };
|
|
361
|
+
r.drag = d;
|
|
362
|
+
r.v = 0;
|
|
363
|
+
r.fv = 0;
|
|
364
|
+
const move = (ev: PointerEvent) => {
|
|
365
|
+
if (ev.pointerId !== d.id) return;
|
|
366
|
+
r.x += ev.clientX - d.last;
|
|
367
|
+
d.last = ev.clientX;
|
|
368
|
+
if (!d.moved && Math.abs(ev.clientX - d.start) > 6) {
|
|
369
|
+
d.moved = true;
|
|
370
|
+
row.setPointerCapture?.(d.id);
|
|
371
|
+
row.setAttribute('data-drag', '');
|
|
372
|
+
}
|
|
373
|
+
d.samples.push({ t: ev.timeStamp, x: r.x });
|
|
374
|
+
while (d.samples.length > 2 && ev.timeStamp - d.samples[0].t > 100) d.samples.shift();
|
|
375
|
+
this.paint(i);
|
|
376
|
+
};
|
|
377
|
+
const end = (ev: PointerEvent) => {
|
|
378
|
+
if (ev.pointerId !== d.id) return;
|
|
379
|
+
row.removeEventListener('pointermove', move);
|
|
380
|
+
row.removeEventListener('pointerup', end);
|
|
381
|
+
row.removeEventListener('pointercancel', end);
|
|
382
|
+
row.removeAttribute('data-drag');
|
|
383
|
+
r.drag = undefined;
|
|
384
|
+
if (ev.type === 'pointerup' && d.moved) {
|
|
385
|
+
const a = d.samples[0];
|
|
386
|
+
const b = d.samples[d.samples.length - 1];
|
|
387
|
+
const span = b.t - a.t;
|
|
388
|
+
const fresh = ev.timeStamp - b.t < 60;
|
|
389
|
+
const vel = span > 0 && fresh ? ((b.x - a.x) / span) * 1000 : 0;
|
|
390
|
+
this.impulse(r, Math.max(-4000, Math.min(4000, vel)), 0.65, 100);
|
|
391
|
+
this.swallow = true;
|
|
392
|
+
} else if (ev.type === 'pointerup' && ev.pointerType !== 'mouse' && !(ev.target as Element).closest?.('a')) {
|
|
393
|
+
this.paused.update((p) => !p);
|
|
394
|
+
}
|
|
395
|
+
this.wake();
|
|
396
|
+
};
|
|
397
|
+
row.addEventListener('pointermove', move);
|
|
398
|
+
row.addEventListener('pointerup', end);
|
|
399
|
+
row.addEventListener('pointercancel', end);
|
|
400
|
+
this.wake();
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
private impulse(r: Row, fv: number, tau: number, lin: number): void {
|
|
404
|
+
r.fv = fv;
|
|
405
|
+
r.tau = tau;
|
|
406
|
+
r.lin = lin;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
private sign(i: number): number {
|
|
410
|
+
const base = this.direction() === 'right' ? 1 : -1;
|
|
411
|
+
return i % 2 ? -base : base;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
private measure(): void {
|
|
415
|
+
const els = this.rowEls();
|
|
416
|
+
let need = 3;
|
|
417
|
+
els.forEach(({ nativeElement: row }, i) => {
|
|
418
|
+
const real = row.firstElementChild?.children[1] as HTMLElement | undefined;
|
|
419
|
+
const set = real ? parseFloat(this.doc.defaultView?.getComputedStyle(real).width ?? '') || real.offsetWidth : 0;
|
|
420
|
+
if (!set) return;
|
|
421
|
+
const r = (this.state[i] ??= { x: 0, v: 0, fv: 0, tau: 0.65, lin: 0, set: 0 });
|
|
422
|
+
if (!r.set) {
|
|
423
|
+
r.x = (this.rtl() ? 1 : -1) * set;
|
|
424
|
+
r.v = 0.7 * this.sign(i) * this.speed();
|
|
425
|
+
}
|
|
426
|
+
r.set = set;
|
|
427
|
+
need = Math.max(need, Math.ceil(row.clientWidth / set) + 2);
|
|
428
|
+
this.paint(i);
|
|
429
|
+
});
|
|
430
|
+
this.state.length = els.length;
|
|
431
|
+
if (need !== this.copies()) this.copies.set(need);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** Reduced motion, or --ui-motion-scale: 0. */
|
|
435
|
+
private calm(): boolean {
|
|
436
|
+
if (this.motion?.matches) return true;
|
|
437
|
+
return parseFloat(this.view?.getComputedStyle(this.host).getPropertyValue('--ui-motion-scale') ?? '') === 0;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
private rtl(): boolean {
|
|
441
|
+
return this.host.matches(':dir(rtl)');
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
private paint(i: number): void {
|
|
445
|
+
const r = this.state[i];
|
|
446
|
+
const track = this.rowEls()[i]?.nativeElement.firstElementChild as HTMLElement | null;
|
|
447
|
+
if (!r?.set || !track) return;
|
|
448
|
+
const s = this.rtl() ? -1 : 1;
|
|
449
|
+
let u = r.x * s;
|
|
450
|
+
while (u >= 0) u -= r.set;
|
|
451
|
+
while (u < -2 * r.set) u += r.set;
|
|
452
|
+
r.x = u * s;
|
|
453
|
+
track.style.transform = `translate3d(${r.x}px, 0, 0)`;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
private live(): boolean {
|
|
457
|
+
return this.inView && this.doc.visibilityState !== 'hidden' && !this.still() && this.state.some((r) => r?.set);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
private wake(): void {
|
|
461
|
+
if (!this.live()) return this.sleep();
|
|
462
|
+
if (this.raf || !this.view) return;
|
|
463
|
+
this.last = 0;
|
|
464
|
+
this.raf = this.view.requestAnimationFrame(this.frame);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
private sleep(): void {
|
|
468
|
+
if (this.raf) this.view?.cancelAnimationFrame(this.raf);
|
|
469
|
+
this.raf = 0;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
private readonly frame = (now: number) => {
|
|
473
|
+
this.raf = 0;
|
|
474
|
+
if (now >= this.checkAt) {
|
|
475
|
+
this.checkAt = now + 500;
|
|
476
|
+
if (this.calm()) return this.still.set(true);
|
|
477
|
+
}
|
|
478
|
+
const dt = this.last ? Math.min(now - this.last, 64) / 1000 : 0;
|
|
479
|
+
this.last = now;
|
|
480
|
+
const stop = this.paused() || this.focused || (this.hovered && this.pauseOnHover());
|
|
481
|
+
const speed = Number.isFinite(this.speed()) ? this.speed() : 0;
|
|
482
|
+
let busy = false;
|
|
483
|
+
this.state.forEach((r, i) => {
|
|
484
|
+
if (!r?.set) return;
|
|
485
|
+
if (r.drag) {
|
|
486
|
+
busy = true;
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
const target = stop ? 0 : this.sign(i) * speed;
|
|
490
|
+
r.v += (target - r.v) * (1 - Math.exp(-dt / (Math.abs(target) > Math.abs(r.v) ? UP : DOWN)));
|
|
491
|
+
if (!target && Math.abs(r.v) < 0.3) r.v = 0;
|
|
492
|
+
r.x += r.v * dt;
|
|
493
|
+
if (r.fv) {
|
|
494
|
+
const k = Math.exp(-dt / r.tau);
|
|
495
|
+
r.x += r.fv * r.tau * (1 - k);
|
|
496
|
+
r.fv *= k;
|
|
497
|
+
r.fv -= Math.sign(r.fv) * Math.min(Math.abs(r.fv), r.lin * dt);
|
|
498
|
+
if (Math.abs(r.fv) < 1) r.fv = 0;
|
|
499
|
+
}
|
|
500
|
+
this.paint(i);
|
|
501
|
+
busy ||= !!(target || r.v || r.fv);
|
|
502
|
+
});
|
|
503
|
+
if (busy && this.live() && this.view) this.raf = this.view.requestAnimationFrame(this.frame);
|
|
504
|
+
};
|
|
505
|
+
}
|