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,302 @@
|
|
|
1
|
+
// Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
|
|
2
|
+
/**
|
|
3
|
+
* Thinking Loader, from Ochre (https://ochreui.dev).
|
|
4
|
+
* Needs ochre.css (the --ui-* tokens and the ui-draw keyframes), which `npx ochreui init` adds once.
|
|
5
|
+
*
|
|
6
|
+
* <ui-thinking-loader [phases]="['Thinking', 'Searching the web', 'Writing response']" [done]="streaming()" />
|
|
7
|
+
* A "model is working" chip: fading rays and a shimmering label that rolls through the phases, then a check
|
|
8
|
+
* and "Thought for 4s". Drive it with [phase] or let it step every `interval` ms.
|
|
9
|
+
*
|
|
10
|
+
* Public styling hooks (set them on the element or any ancestor):
|
|
11
|
+
* --ui-thinking-loader-bg chip fill (default: the surface; the canvas in dark mode)
|
|
12
|
+
* --ui-thinking-loader-shadow chip edge (default: a hairline ring and a soft drop)
|
|
13
|
+
* --ui-thinking-loader-radius corners (default 8px; Classic a full pill)
|
|
14
|
+
* --ui-thinking-loader-ray rays and check (default: blue; Classic the text colour)
|
|
15
|
+
*/
|
|
16
|
+
import {
|
|
17
|
+
Component,
|
|
18
|
+
DOCUMENT,
|
|
19
|
+
DestroyRef,
|
|
20
|
+
ElementRef,
|
|
21
|
+
afterNextRender,
|
|
22
|
+
afterRenderEffect,
|
|
23
|
+
booleanAttribute,
|
|
24
|
+
computed,
|
|
25
|
+
effect,
|
|
26
|
+
inject,
|
|
27
|
+
input,
|
|
28
|
+
isDevMode,
|
|
29
|
+
linkedSignal,
|
|
30
|
+
numberAttribute,
|
|
31
|
+
signal,
|
|
32
|
+
untracked,
|
|
33
|
+
viewChild,
|
|
34
|
+
} from '@angular/core';
|
|
35
|
+
|
|
36
|
+
export type ThinkingLoaderSize = 'sm' | 'md';
|
|
37
|
+
export type ThinkingLoaderVariant = 'pill' | 'plain';
|
|
38
|
+
|
|
39
|
+
export interface ThinkingLoaderLabels {
|
|
40
|
+
/** Used when `phases` is left out or empty. */
|
|
41
|
+
phases: readonly string[];
|
|
42
|
+
/** Used when `doneLabel` is left out; gets the whole seconds since the loader started. */
|
|
43
|
+
done: (seconds: number) => string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const LABELS: ThinkingLoaderLabels = {
|
|
47
|
+
phases: ['Thinking', 'Searching the web', 'Reading sources', 'Writing response'],
|
|
48
|
+
done: (s) => `Thought for ${s}s`,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
interface Slot {
|
|
52
|
+
key: number;
|
|
53
|
+
text: string;
|
|
54
|
+
out: boolean;
|
|
55
|
+
enter: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Component({
|
|
59
|
+
selector: 'ui-thinking-loader',
|
|
60
|
+
host: {
|
|
61
|
+
role: 'status',
|
|
62
|
+
'aria-live': 'polite',
|
|
63
|
+
'[attr.data-size]': 'size()',
|
|
64
|
+
'[attr.data-variant]': 'variant()',
|
|
65
|
+
'[attr.data-done]': 'done() || null',
|
|
66
|
+
'[style.--_p]': "awake() ? null : 'paused'",
|
|
67
|
+
},
|
|
68
|
+
template: `
|
|
69
|
+
<span aria-hidden="true" style="position: relative; flex: none; inline-size: var(--_i); block-size: var(--_i)">
|
|
70
|
+
<svg class="r" viewBox="0 0 16 16" fill="none" stroke-linecap="round"
|
|
71
|
+
style="position: absolute; inset: 0; overflow: visible; stroke: var(--_ray); stroke-width: calc(1.1 + 0.5 * var(--_t)); transition: opacity calc(240ms * var(--_m)) var(--_e), scale calc(420ms * var(--_m)) cubic-bezier(0.3, -1.2, 0.4, 1)">
|
|
72
|
+
@for (i of rays; track i) {
|
|
73
|
+
<line x1="8" y1="1.8" x2="8" y2="4.8" [attr.transform]="'rotate(' + i * 45 + ' 8 8)'" [style.animation-delay.ms]="(i - 8) * 100" [style.animation]="calm() ? 'none' : null" [style.opacity]="calm() ? 0.6 : null" />
|
|
74
|
+
}
|
|
75
|
+
</svg>
|
|
76
|
+
<svg class="c" viewBox="0 0 16 16" fill="none" stroke-linecap="round" stroke-linejoin="round"
|
|
77
|
+
style="position: absolute; inset: 0; overflow: visible; stroke: var(--_ray); stroke-width: calc(1.2 + 0.6 * var(--_t)); transition: opacity calc(240ms * var(--_m)) var(--_e), scale calc(420ms * var(--_m)) var(--_e)">
|
|
78
|
+
<path pathLength="1" stroke-dasharray="1" d="M3 8.5l3.5 3.5 7-7.5" />
|
|
79
|
+
</svg>
|
|
80
|
+
</span>
|
|
81
|
+
<span #box class="l" style="position: relative; block-size: var(--_lh); overflow: hidden">
|
|
82
|
+
@for (s of slots(); track s.key) {
|
|
83
|
+
<span dir="auto" style="display: block; inline-size: max-content; white-space: nowrap" [class.in]="s.enter" [class.out]="s.out"
|
|
84
|
+
[attr.aria-hidden]="s.out || null" (animationend)="s.out && drop(s.key)" (animationcancel)="s.out && cancelled($event, s.key)"><span [class.on]="!s.out && !done() && !calm()">{{ s.text }}</span></span>
|
|
85
|
+
}
|
|
86
|
+
</span>
|
|
87
|
+
`,
|
|
88
|
+
styles: `
|
|
89
|
+
:host {
|
|
90
|
+
--_t: var(--ui-look-tray, 0);
|
|
91
|
+
--_m: var(--ui-motion-scale);
|
|
92
|
+
--_e: var(--ui-ease-out);
|
|
93
|
+
--_i: calc(16px - 1px * var(--_t));
|
|
94
|
+
--_lh: calc(var(--ui-leading-base) - 1.8px * var(--_t));
|
|
95
|
+
--_r: var(--ui-hairline);
|
|
96
|
+
--_ray: var(--ui-thinking-loader-ray, color-mix(in srgb, var(--ui-text) calc(100% * var(--_t)), var(--ui-hue-blue)));
|
|
97
|
+
--_g: color-mix(in srgb, var(--ui-gray-1000) 6%, transparent);
|
|
98
|
+
--_d: calc(460ms * var(--_m));
|
|
99
|
+
display: inline-flex;
|
|
100
|
+
align-items: center;
|
|
101
|
+
vertical-align: middle;
|
|
102
|
+
box-sizing: border-box;
|
|
103
|
+
gap: calc(var(--ui-space-1-5) + 2px * var(--_t));
|
|
104
|
+
block-size: calc(var(--ui-space-8) + 2px * var(--_t));
|
|
105
|
+
padding: 0 calc(var(--ui-space-2-5) + 5px * var(--_t)) 0 calc(var(--ui-space-2) + 4px * var(--_t));
|
|
106
|
+
border-radius: var(--ui-thinking-loader-radius, calc(var(--ui-radius-md) + var(--ui-radius-full) * var(--_t)));
|
|
107
|
+
background: var(--ui-thinking-loader-bg, light-dark(var(--ui-bg-surface), var(--ui-bg-canvas)));
|
|
108
|
+
box-shadow: var(--ui-thinking-loader-shadow, 0 0 0 calc(0.5px - 0.5px * var(--_t)) var(--_r), inset 0 0 0 calc(1px * var(--_t)) var(--_r),
|
|
109
|
+
0 calc(1px - 1px * var(--_t)) 1px -1px var(--_g), 0 1px 2px var(--_g));
|
|
110
|
+
color: var(--ui-text-muted);
|
|
111
|
+
font: calc(var(--ui-weight-medium) - 50 * var(--_t)) calc(var(--ui-text-base) + 1px * var(--_t)) / var(--_lh) var(--ui-font-sans);
|
|
112
|
+
letter-spacing: calc(-0.003em - 0.003em * var(--_t));
|
|
113
|
+
}
|
|
114
|
+
:host([data-size='sm']) {
|
|
115
|
+
--_i: calc(14px - 1px * var(--_t));
|
|
116
|
+
--_lh: calc(var(--ui-leading-sm) - 1.1px * var(--_t));
|
|
117
|
+
gap: calc(5px + 2px * var(--_t));
|
|
118
|
+
block-size: calc(var(--ui-space-6) + 2px + 2px * var(--_t));
|
|
119
|
+
padding: 0 calc(var(--ui-space-2) + 4px * var(--_t)) 0 calc(var(--ui-space-1-5) + 3px * var(--_t));
|
|
120
|
+
font-size: calc(var(--ui-text-sm) + 1px * var(--_t));
|
|
121
|
+
}
|
|
122
|
+
:host([data-variant='plain']) { block-size: auto; padding: 0; background: none; box-shadow: none; outline: 0; }
|
|
123
|
+
line { animation: r 800ms linear infinite var(--_p, running); }
|
|
124
|
+
.c { opacity: 0; scale: 0.6; }
|
|
125
|
+
:host([data-done]) { --_p: paused; }
|
|
126
|
+
:host([data-done]) .r { opacity: 0; scale: 0.85; }
|
|
127
|
+
:host([data-done]) .c { opacity: 1; scale: 1; }
|
|
128
|
+
:host([data-done]) path { animation: ui-draw calc(360ms * var(--_m)) calc(120ms * var(--_m)) var(--_e) both; }
|
|
129
|
+
.l { transition: inline-size var(--_d) var(--_e); }
|
|
130
|
+
:host([data-done]) .l { color: var(--ui-text); }
|
|
131
|
+
.on {
|
|
132
|
+
background: linear-gradient(90deg, var(--ui-text-muted) 39%, light-dark(color-mix(in srgb, var(--ui-text-muted) 35%, var(--ui-bg-surface)), var(--ui-text)) 46% 54%, var(--ui-text-muted) 61%) 0 0 / 300% 100%;
|
|
133
|
+
-webkit-background-clip: text;
|
|
134
|
+
background-clip: text;
|
|
135
|
+
color: transparent;
|
|
136
|
+
animation: s calc(1600ms + 200ms * var(--_t)) linear infinite var(--_p, running);
|
|
137
|
+
}
|
|
138
|
+
.on:dir(rtl) { animation-direction: reverse; }
|
|
139
|
+
.in { animation: i var(--_d) var(--_e) both; }
|
|
140
|
+
.out { position: absolute; animation: o calc(320ms * var(--_m)) var(--_e) both; }
|
|
141
|
+
@keyframes r { from { opacity: 1; } to { opacity: 0.2; } }
|
|
142
|
+
@keyframes s { from { background-position: 100% 0; } to { background-position: 0 0; } }
|
|
143
|
+
@keyframes i { from { opacity: 0; translate: 0 calc(var(--_lh) * 0.7); filter: blur(4px); } 60% { filter: none; } }
|
|
144
|
+
@keyframes o { to { opacity: 0; translate: 0 calc(var(--_lh) * -0.7); filter: blur(4px); } }
|
|
145
|
+
@media (prefers-reduced-motion: reduce) {
|
|
146
|
+
line { animation: none; opacity: 0.6; }
|
|
147
|
+
.on { animation: none; background: none; color: inherit; }
|
|
148
|
+
}
|
|
149
|
+
@media (forced-colors: active) {
|
|
150
|
+
:host { --_ray: CanvasText; outline: 1px solid transparent; outline-offset: -1px; }
|
|
151
|
+
.on { animation: none; background: none; color: CanvasText; }
|
|
152
|
+
}
|
|
153
|
+
`,
|
|
154
|
+
})
|
|
155
|
+
export class UiThinkingLoader {
|
|
156
|
+
/** Labels to walk through, in order: two to four words each. Defaults to the `labels` phases. */
|
|
157
|
+
readonly phases = input<readonly string[]>();
|
|
158
|
+
/** Milliseconds per phase while `phase` is not set. The timer waits while the loader is off-screen or in a hidden tab. */
|
|
159
|
+
readonly interval = input(2200, { transform: numberAttribute });
|
|
160
|
+
/** Shows this index of `phases` and stops the timer. Set it back to undefined to let the timer go on from there. */
|
|
161
|
+
readonly phase = input<number | undefined>();
|
|
162
|
+
/** Starts over after the last phase instead of holding it. */
|
|
163
|
+
readonly loop = input(false, { transform: booleanAttribute });
|
|
164
|
+
/** Swaps the rays for a check and the label for `doneLabel`. Setting it back to false starts over, from `phase` when it is set. */
|
|
165
|
+
readonly done = input(false, { transform: booleanAttribute });
|
|
166
|
+
/** The label once done. A function gets the whole seconds since the loader started (or restarted). */
|
|
167
|
+
readonly doneLabel = input<string | ((seconds: number) => string)>();
|
|
168
|
+
/** 32px tall with a 13px label, or 26px with 12px for `sm`. Classic: 34 or 28px. */
|
|
169
|
+
readonly size = input<ThinkingLoaderSize>('md');
|
|
170
|
+
/** A chip with a hairline edge, or just the rays and the label, for inside a message. */
|
|
171
|
+
readonly variant = input<ThinkingLoaderVariant>('pill');
|
|
172
|
+
/** The default phases and done text, for translation. */
|
|
173
|
+
readonly labels = input<Partial<ThinkingLoaderLabels>>({});
|
|
174
|
+
|
|
175
|
+
protected readonly rays = [0, 1, 2, 3, 4, 5, 6, 7];
|
|
176
|
+
protected readonly slots = signal<Slot[]>([]);
|
|
177
|
+
|
|
178
|
+
private readonly t = computed(() => ({ ...LABELS, ...this.labels() }));
|
|
179
|
+
private readonly list = computed(() => (this.phases()?.length ? this.phases()! : this.t().phases));
|
|
180
|
+
private readonly index = linkedSignal<number | undefined, number>({
|
|
181
|
+
source: this.phase,
|
|
182
|
+
computation: (p, prev) => p ?? prev?.value ?? 0,
|
|
183
|
+
});
|
|
184
|
+
private readonly at = computed(() => Math.min(Math.max(Math.trunc(this.index()), 0), this.list().length - 1));
|
|
185
|
+
private readonly live = signal(false);
|
|
186
|
+
private readonly seen = signal(true);
|
|
187
|
+
private readonly shown = signal(true);
|
|
188
|
+
/** On screen in a visible tab: the rays, the shimmer and the phase timer only run then. */
|
|
189
|
+
protected readonly awake = computed(() => this.seen() && this.shown());
|
|
190
|
+
/** Reduced motion, or --ui-motion-scale: 0: the rays hold still and the label does not shimmer or roll. */
|
|
191
|
+
protected readonly calm = signal(false);
|
|
192
|
+
private readonly box = viewChild.required<ElementRef<HTMLElement>>('box');
|
|
193
|
+
private readonly doc = inject(DOCUMENT);
|
|
194
|
+
private readonly win = this.doc.defaultView;
|
|
195
|
+
private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
|
|
196
|
+
private readonly motion = this.win?.matchMedia?.('(prefers-reduced-motion: reduce)');
|
|
197
|
+
private started = Date.now();
|
|
198
|
+
private wasDone = false;
|
|
199
|
+
private took = 0;
|
|
200
|
+
private key = 0;
|
|
201
|
+
private width = 0;
|
|
202
|
+
private dropTimer?: ReturnType<typeof setTimeout>;
|
|
203
|
+
|
|
204
|
+
constructor() {
|
|
205
|
+
effect(() => {
|
|
206
|
+
const done = this.done();
|
|
207
|
+
if (done !== this.wasDone) {
|
|
208
|
+
this.wasDone = done;
|
|
209
|
+
if (done) this.took = Math.round((Date.now() - this.started) / 1000);
|
|
210
|
+
else {
|
|
211
|
+
this.started = Date.now();
|
|
212
|
+
untracked(() => this.phase() === undefined && this.index.set(0));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const label = this.doneLabel() ?? this.t().done;
|
|
216
|
+
const text = done
|
|
217
|
+
? typeof label === 'function' ? label(this.took) : label
|
|
218
|
+
: this.list()[this.at()];
|
|
219
|
+
untracked(() => this.show(text));
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
effect((onCleanup) => {
|
|
223
|
+
if (!this.live() || !this.awake() || this.done() || this.phase() !== undefined) return;
|
|
224
|
+
const i = this.at();
|
|
225
|
+
const n = this.list().length;
|
|
226
|
+
if (i >= n - 1 && !this.loop()) return;
|
|
227
|
+
const timer = setTimeout(() => this.index.set((i + 1) % n), this.interval());
|
|
228
|
+
onCleanup(() => clearTimeout(timer));
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
let seen: Element | null = null;
|
|
232
|
+
let ro: ResizeObserver | undefined;
|
|
233
|
+
afterRenderEffect(() => {
|
|
234
|
+
this.slots();
|
|
235
|
+
const el = this.box().nativeElement.querySelector(':scope > :not(.out)');
|
|
236
|
+
if (el === seen || !this.win?.ResizeObserver) return;
|
|
237
|
+
ro ??= new this.win.ResizeObserver(() => this.measure());
|
|
238
|
+
if (seen) ro.unobserve(seen);
|
|
239
|
+
if (el) ro.observe(el);
|
|
240
|
+
seen = el;
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
let io: IntersectionObserver | undefined;
|
|
244
|
+
const onVisibility = () => this.shown.set(this.doc.visibilityState !== 'hidden');
|
|
245
|
+
const onMotion = () => this.calm.set(this.still());
|
|
246
|
+
afterNextRender(() => {
|
|
247
|
+
this.live.set(true);
|
|
248
|
+
onVisibility();
|
|
249
|
+
onMotion();
|
|
250
|
+
this.doc.addEventListener('visibilitychange', onVisibility);
|
|
251
|
+
this.motion?.addEventListener?.('change', onMotion);
|
|
252
|
+
if (this.win?.IntersectionObserver) {
|
|
253
|
+
io = new this.win.IntersectionObserver((entries) => this.seen.set(entries[entries.length - 1].isIntersecting));
|
|
254
|
+
io.observe(this.host);
|
|
255
|
+
}
|
|
256
|
+
if (isDevMode() && !this.box().nativeElement.textContent?.trim()) {
|
|
257
|
+
console.warn('ui-thinking-loader: every phase is empty, so screen readers hear nothing. Give it phases with words.', this.box().nativeElement);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
inject(DestroyRef).onDestroy(() => {
|
|
262
|
+
clearTimeout(this.dropTimer);
|
|
263
|
+
ro?.disconnect();
|
|
264
|
+
io?.disconnect();
|
|
265
|
+
this.doc.removeEventListener('visibilitychange', onVisibility);
|
|
266
|
+
this.motion?.removeEventListener?.('change', onMotion);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
protected drop(key: number): void {
|
|
271
|
+
this.slots.update((s) => s.filter((x) => x.key !== key));
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
protected cancelled(e: AnimationEvent, key: number): void {
|
|
275
|
+
const el = e.currentTarget as Element;
|
|
276
|
+
if (e.target === el && !el.getAnimations?.().some((a) => 'animationName' in a)) this.drop(key);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
private show(text: string): void {
|
|
280
|
+
const cur = this.slots().find((s) => !s.out);
|
|
281
|
+
if (cur?.text === text) return;
|
|
282
|
+
const next: Slot = { key: ++this.key, text, out: false, enter: !!cur };
|
|
283
|
+
const still = !cur || !this.motion || this.still();
|
|
284
|
+
this.slots.set(still ? [next] : [{ ...cur, out: true }, next]);
|
|
285
|
+
clearTimeout(this.dropTimer);
|
|
286
|
+
if (!still) this.dropTimer = setTimeout(() => this.drop(cur.key), 400);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
private still(): boolean {
|
|
290
|
+
return !!this.motion?.matches || parseFloat(this.win?.getComputedStyle(this.host).getPropertyValue('--ui-motion-scale') ?? '') === 0;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private measure(): void {
|
|
294
|
+
const box = this.box().nativeElement;
|
|
295
|
+
const el = box.querySelector<HTMLElement>(':scope > :not(.out)');
|
|
296
|
+
const w = el ? Math.ceil(parseFloat(this.win?.getComputedStyle(el).width ?? '') || el.offsetWidth) : 0;
|
|
297
|
+
if (!w || w === this.width) return;
|
|
298
|
+
box.style.transition = this.width ? '' : 'none';
|
|
299
|
+
box.style.inlineSize = `${w}px`;
|
|
300
|
+
this.width = w;
|
|
301
|
+
}
|
|
302
|
+
}
|