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,381 @@
|
|
|
1
|
+
// Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
|
|
2
|
+
/**
|
|
3
|
+
* Frost Cloud, from Ochre (https://ochreui.dev).
|
|
4
|
+
* Needs ochre.css (the --ui-* tokens), added once by `npx ochreui init`.
|
|
5
|
+
*
|
|
6
|
+
* <ui-frost-cloud />
|
|
7
|
+
* <ui-frost-cloud color="orange" [background]="false" label="Your assistant" />
|
|
8
|
+
* A frosted cloud with two eyes on a blue or red-orange sky. It floats, blinks, follows the pointer and
|
|
9
|
+
* bounces when pressed. Square and up to 380px wide; give it a width and height and the sky fills the box.
|
|
10
|
+
*
|
|
11
|
+
* Public styling hooks (set them on the element or any ancestor):
|
|
12
|
+
* --ui-frost-cloud-sky-top sky at the top
|
|
13
|
+
* --ui-frost-cloud-sky-bottom sky at the bottom
|
|
14
|
+
* --ui-frost-cloud-sky-glow soft light behind the cloud
|
|
15
|
+
* --ui-frost-cloud-tint haze in the lower body, and the edge glow without a background
|
|
16
|
+
* --ui-frost-cloud-eye eye colour (the top of each eye is a step deeper)
|
|
17
|
+
* --ui-frost-cloud-shadow ground shadow
|
|
18
|
+
*/
|
|
19
|
+
import {
|
|
20
|
+
Component,
|
|
21
|
+
DOCUMENT,
|
|
22
|
+
DestroyRef,
|
|
23
|
+
ElementRef,
|
|
24
|
+
afterNextRender,
|
|
25
|
+
booleanAttribute,
|
|
26
|
+
computed,
|
|
27
|
+
inject,
|
|
28
|
+
input,
|
|
29
|
+
} from '@angular/core';
|
|
30
|
+
|
|
31
|
+
export type FrostCloudColor = 'blue' | 'orange';
|
|
32
|
+
|
|
33
|
+
const PERIOD = 5717;
|
|
34
|
+
const LOOKS: readonly (readonly [number, number])[] = [
|
|
35
|
+
[-12.4, 1],
|
|
36
|
+
[12.7, 0],
|
|
37
|
+
[-8.6, 3],
|
|
38
|
+
[8.4, -4],
|
|
39
|
+
[-9, -3.5],
|
|
40
|
+
[9.5, 3],
|
|
41
|
+
[0, 3.5],
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
let nextId = 0;
|
|
45
|
+
|
|
46
|
+
interface Tween {
|
|
47
|
+
x0: number;
|
|
48
|
+
y0: number;
|
|
49
|
+
x: number;
|
|
50
|
+
y: number;
|
|
51
|
+
at: number;
|
|
52
|
+
ms: number;
|
|
53
|
+
pow: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@Component({
|
|
57
|
+
selector: 'ui-frost-cloud',
|
|
58
|
+
host: {
|
|
59
|
+
'[attr.role]': "name() ? 'img' : null",
|
|
60
|
+
'[attr.aria-label]': 'name() || null',
|
|
61
|
+
'[attr.aria-hidden]': "name() ? null : 'true'",
|
|
62
|
+
'[attr.data-color]': 'color()',
|
|
63
|
+
'[attr.data-bg]': "background() ? '' : null",
|
|
64
|
+
},
|
|
65
|
+
template: `
|
|
66
|
+
<svg viewBox="0 0 240 240" aria-hidden="true" focusable="false">
|
|
67
|
+
<defs>
|
|
68
|
+
<filter [id]="id + 'g'" x="-10%" y="-10%" width="120%" height="120%">
|
|
69
|
+
<feGaussianBlur stdDeviation="2.2" />
|
|
70
|
+
<feColorMatrix values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 24 -12" />
|
|
71
|
+
</filter>
|
|
72
|
+
<filter [id]="id + 'a'" x="-30%" y="-30%" width="160%" height="160%"><feGaussianBlur stdDeviation="3.5" /></filter>
|
|
73
|
+
<filter [id]="id + 'b'" x="-40%" y="-40%" width="180%" height="180%"><feGaussianBlur stdDeviation="10" /></filter>
|
|
74
|
+
<filter [id]="id + 'c'" x="-60%" y="-100%" width="220%" height="300%"><feGaussianBlur stdDeviation="4" /></filter>
|
|
75
|
+
<filter [id]="id + 'd'" x="-60%" y="-60%" width="220%" height="220%"><feGaussianBlur stdDeviation="13" /></filter>
|
|
76
|
+
<filter [id]="id + 'f'" x="-40%" y="-200%" width="180%" height="500%"><feGaussianBlur stdDeviation="5.5" /></filter>
|
|
77
|
+
<filter [id]="id + 'e'" x="-40%" y="-40%" width="180%" height="180%"><feGaussianBlur stdDeviation="1.3" /></filter>
|
|
78
|
+
<g [id]="id + 's'">
|
|
79
|
+
<circle cx="115" cy="93" r="42" />
|
|
80
|
+
<circle cx="163" cy="111" r="38.5" />
|
|
81
|
+
<circle cx="156" cy="153.5" r="31" />
|
|
82
|
+
<circle cx="107" cy="155" r="34" />
|
|
83
|
+
<circle cx="73.5" cy="126.5" r="35" />
|
|
84
|
+
<rect x="80" y="95" width="85" height="70" />
|
|
85
|
+
</g>
|
|
86
|
+
<mask [id]="id + 'm'" maskUnits="userSpaceOnUse" x="0" y="0" width="240" height="240">
|
|
87
|
+
<use [attr.href]="'#' + id + 's'" fill="#fff" [attr.filter]="url('g')" />
|
|
88
|
+
</mask>
|
|
89
|
+
<linearGradient [id]="id + 'w'" gradientUnits="userSpaceOnUse" x1="0" y1="50" x2="0" y2="190">
|
|
90
|
+
<stop offset="0.3" stop-color="#fff" />
|
|
91
|
+
<stop offset="1" stop-color="#fff" stop-opacity="0.78" />
|
|
92
|
+
</linearGradient>
|
|
93
|
+
<linearGradient [id]="id + 't'" gradientUnits="userSpaceOnUse" x1="0" y1="50" x2="0" y2="120">
|
|
94
|
+
<stop offset="0.2" stop-color="#fff" />
|
|
95
|
+
<stop offset="1" stop-color="#fff" stop-opacity="0" />
|
|
96
|
+
</linearGradient>
|
|
97
|
+
<linearGradient [id]="id + 'i'" x1="0" y1="0" x2="0" y2="1">
|
|
98
|
+
<stop offset="0" class="i0" />
|
|
99
|
+
<stop offset="1" class="i1" />
|
|
100
|
+
</linearGradient>
|
|
101
|
+
@for (e of eyes; track e) {
|
|
102
|
+
<clipPath [id]="id + 'k' + e"><rect [attr.x]="e" y="106.5" width="18" height="31" rx="9" /></clipPath>
|
|
103
|
+
}
|
|
104
|
+
</defs>
|
|
105
|
+
<ellipse class="sh" cx="120" cy="210" rx="50.75" ry="7" opacity="0.29" [attr.filter]="url('f')" />
|
|
106
|
+
<g class="fl">
|
|
107
|
+
<g class="sq">
|
|
108
|
+
<g class="bd">
|
|
109
|
+
<use class="h" [attr.href]="'#' + id + 's'" opacity="0.75" [attr.filter]="url('b')" />
|
|
110
|
+
<use class="h" [attr.href]="'#' + id + 's'" opacity="0.7" [attr.filter]="url('a')" />
|
|
111
|
+
<g [attr.mask]="url('m')">
|
|
112
|
+
<rect x="30" y="40" width="180" height="160" [attr.fill]="url('w')" />
|
|
113
|
+
<ellipse class="hz" cx="116" cy="148" rx="62" ry="38" [attr.filter]="url('d')" />
|
|
114
|
+
<rect x="30" y="40" width="180" height="160" [attr.fill]="url('t')" />
|
|
115
|
+
<ellipse class="sn" cx="110" cy="56" rx="28" ry="8" fill="#fff" opacity="0.75" [attr.filter]="url('c')" />
|
|
116
|
+
</g>
|
|
117
|
+
<g class="ey">
|
|
118
|
+
@for (e of eyes; track e) {
|
|
119
|
+
<g class="e" [attr.clip-path]="url('k' + e)">
|
|
120
|
+
<rect class="r" [attr.x]="e" y="106.5" width="18" height="31" />
|
|
121
|
+
<rect [attr.x]="e" y="109" width="18" height="31" rx="9" [attr.fill]="url('i')" [attr.filter]="url('e')" />
|
|
122
|
+
</g>
|
|
123
|
+
}
|
|
124
|
+
</g>
|
|
125
|
+
</g>
|
|
126
|
+
</g>
|
|
127
|
+
</g>
|
|
128
|
+
</svg>
|
|
129
|
+
`,
|
|
130
|
+
styles: `
|
|
131
|
+
@layer ui {
|
|
132
|
+
:host { display: grid; inline-size: min(380px, 100%); aspect-ratio: 1; }
|
|
133
|
+
}
|
|
134
|
+
:host {
|
|
135
|
+
--_t: var(--ui-frost-cloud-sky-top, light-dark(#2577ea, #165ac9));
|
|
136
|
+
--_b: var(--ui-frost-cloud-sky-bottom, light-dark(#4ac7f5, #2aa5e5));
|
|
137
|
+
--_g: var(--ui-frost-cloud-sky-glow, light-dark(rgb(120 215 252 / 0.5), rgb(96 192 246 / 0.45)));
|
|
138
|
+
--_h: var(--ui-frost-cloud-tint, #a2d1f6);
|
|
139
|
+
--_e: var(--ui-frost-cloud-eye, #5ccaf9);
|
|
140
|
+
--_s: var(--ui-frost-cloud-shadow, light-dark(#1a66c8, #0b3f96));
|
|
141
|
+
grid-template: minmax(0, 1fr) / minmax(0, 1fr);
|
|
142
|
+
place-items: center;
|
|
143
|
+
box-sizing: border-box;
|
|
144
|
+
cursor: pointer;
|
|
145
|
+
touch-action: manipulation;
|
|
146
|
+
user-select: none;
|
|
147
|
+
-webkit-user-select: none;
|
|
148
|
+
-webkit-tap-highlight-color: transparent;
|
|
149
|
+
forced-color-adjust: none;
|
|
150
|
+
}
|
|
151
|
+
:host([data-color='orange']) {
|
|
152
|
+
--_t: var(--ui-frost-cloud-sky-top, light-dark(#ec4a2c, #be3418));
|
|
153
|
+
--_b: var(--ui-frost-cloud-sky-bottom, light-dark(#fdad47, #ec8a22));
|
|
154
|
+
--_g: var(--ui-frost-cloud-sky-glow, light-dark(rgb(255 190 120 / 0.5), rgb(250 160 90 / 0.45)));
|
|
155
|
+
--_h: var(--ui-frost-cloud-tint, #f7bf9b);
|
|
156
|
+
--_e: var(--ui-frost-cloud-eye, #ffa25a);
|
|
157
|
+
--_s: var(--ui-frost-cloud-shadow, light-dark(#b9381a, #8a2410));
|
|
158
|
+
}
|
|
159
|
+
:host([data-bg]) {
|
|
160
|
+
background:
|
|
161
|
+
radial-gradient(45% 48% at 62% 54%, var(--_g), transparent),
|
|
162
|
+
linear-gradient(var(--_t), var(--_b));
|
|
163
|
+
}
|
|
164
|
+
:host::before { content: 'x x x x x x x x' / ''; display: block; block-size: 0; overflow: hidden; font-size: 0; word-spacing: calc(380px / 7); }
|
|
165
|
+
:host::before, svg { grid-area: 1 / 1; }
|
|
166
|
+
svg { display: block; inline-size: min(380px, 78%); block-size: auto; max-block-size: 78%; aspect-ratio: 1; overflow: visible; }
|
|
167
|
+
.h { fill: #fff; }
|
|
168
|
+
:host(:not([data-bg])) .h { fill: var(--_h); }
|
|
169
|
+
.hz { fill: var(--_h); }
|
|
170
|
+
.r { fill: color-mix(in srgb, var(--_e), #0a4fb0 30%); }
|
|
171
|
+
:host([data-color='orange']) .r { fill: color-mix(in srgb, var(--_e), #b0300a 34%); }
|
|
172
|
+
.i0 { stop-color: color-mix(in srgb, var(--_e), #0d7fd8 55%); }
|
|
173
|
+
:host([data-color='orange']) .i0 { stop-color: color-mix(in srgb, var(--_e), #d8460d 55%); }
|
|
174
|
+
.i1 { stop-color: var(--_e); }
|
|
175
|
+
.sh { fill: var(--_s); }
|
|
176
|
+
`,
|
|
177
|
+
})
|
|
178
|
+
export class UiFrostCloud {
|
|
179
|
+
/** Sky and tint: blue to cyan, or red to orange. */
|
|
180
|
+
readonly color = input<FrostCloudColor>('blue');
|
|
181
|
+
/** Paint the sky over the whole box. Off, the cloud sits on your surface with a soft coloured edge. */
|
|
182
|
+
readonly background = input(true, { transform: booleanAttribute });
|
|
183
|
+
/** The eyes follow the pointer while it is over the box. */
|
|
184
|
+
readonly followPointer = input(true, { transform: booleanAttribute });
|
|
185
|
+
/** What screen readers hear for the picture. An empty string hides it as pure decoration. */
|
|
186
|
+
readonly label = input<string | null | undefined>(undefined);
|
|
187
|
+
|
|
188
|
+
protected readonly name = computed(() => (this.label() ?? 'A friendly frosted cloud with two eyes, gently floating').trim());
|
|
189
|
+
protected readonly id = `ui-frost-cloud-${nextId++}-`;
|
|
190
|
+
protected readonly eyes = [96.5, 127.5] as const;
|
|
191
|
+
|
|
192
|
+
protected url(key: string) {
|
|
193
|
+
return `url(#${this.id}${key})`;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private readonly doc = inject(DOCUMENT);
|
|
197
|
+
private readonly win = this.doc.defaultView;
|
|
198
|
+
private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
|
|
199
|
+
|
|
200
|
+
private clock = 0;
|
|
201
|
+
private last = -1;
|
|
202
|
+
private raf = 0;
|
|
203
|
+
private seen = true;
|
|
204
|
+
private still = false;
|
|
205
|
+
private checkAt = 0;
|
|
206
|
+
private parts: Record<string, Element | null> = {};
|
|
207
|
+
private look: Tween = { x0: 0, y0: 0, x: 0, y: 0, at: 0, ms: 1, pow: 2 };
|
|
208
|
+
private hovering = false;
|
|
209
|
+
private nextGlance = 1500;
|
|
210
|
+
private nextBlink = 2400;
|
|
211
|
+
private blinks: number[] = [];
|
|
212
|
+
private pressAt = -1e9;
|
|
213
|
+
|
|
214
|
+
constructor() {
|
|
215
|
+
const onVisibility = () => this.sync();
|
|
216
|
+
const media = this.win?.matchMedia?.('(prefers-reduced-motion: reduce)');
|
|
217
|
+
const onMedia = () => this.sync();
|
|
218
|
+
const events: [string, (e: PointerEvent) => void][] = [
|
|
219
|
+
['pointermove', (e) => this.aim(e)],
|
|
220
|
+
['pointerdown', (e) => this.press(e)],
|
|
221
|
+
['pointerleave', () => this.leave()],
|
|
222
|
+
['pointercancel', () => this.leave()],
|
|
223
|
+
];
|
|
224
|
+
let io: IntersectionObserver | undefined;
|
|
225
|
+
|
|
226
|
+
afterNextRender(() => {
|
|
227
|
+
for (const k of ['fl', 'sq', 'bd', 'ey', 'sn', 'sh']) this.parts[k] = this.host.querySelector('.' + k);
|
|
228
|
+
const eyes = this.host.querySelectorAll('.e');
|
|
229
|
+
this.parts['l'] = eyes[0];
|
|
230
|
+
this.parts['r'] = eyes[1];
|
|
231
|
+
for (const [type, fn] of events) this.host.addEventListener(type, fn as EventListener);
|
|
232
|
+
this.doc.addEventListener('visibilitychange', onVisibility);
|
|
233
|
+
media?.addEventListener?.('change', onMedia);
|
|
234
|
+
const Observer = this.win?.IntersectionObserver;
|
|
235
|
+
if (Observer) {
|
|
236
|
+
io = new Observer((entries) => {
|
|
237
|
+
this.seen = entries[entries.length - 1].isIntersecting;
|
|
238
|
+
this.sync();
|
|
239
|
+
});
|
|
240
|
+
io.observe(this.host);
|
|
241
|
+
}
|
|
242
|
+
this.sync();
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
inject(DestroyRef).onDestroy(() => {
|
|
246
|
+
io?.disconnect();
|
|
247
|
+
this.stop();
|
|
248
|
+
for (const [type, fn] of events) this.host.removeEventListener(type, fn as EventListener);
|
|
249
|
+
this.doc.removeEventListener('visibilitychange', onVisibility);
|
|
250
|
+
media?.removeEventListener?.('change', onMedia);
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private sync() {
|
|
255
|
+
const scale = this.win?.getComputedStyle?.(this.host).getPropertyValue('--ui-motion-scale').trim();
|
|
256
|
+
this.still = !!this.win?.matchMedia?.('(prefers-reduced-motion: reduce)').matches || (!!scale && parseFloat(scale) === 0);
|
|
257
|
+
if (this.still) {
|
|
258
|
+
this.stop();
|
|
259
|
+
this.rest();
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (this.seen && this.doc.visibilityState !== 'hidden') {
|
|
263
|
+
if (!this.raf && this.win?.requestAnimationFrame) this.raf = this.win.requestAnimationFrame(this.tick);
|
|
264
|
+
} else {
|
|
265
|
+
this.stop();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
private stop() {
|
|
270
|
+
if (this.raf) this.win?.cancelAnimationFrame(this.raf);
|
|
271
|
+
this.raf = 0;
|
|
272
|
+
this.last = -1;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
private readonly tick = (now: number) => {
|
|
276
|
+
if (now >= this.checkAt) {
|
|
277
|
+
this.checkAt = now + 500;
|
|
278
|
+
const s = this.win?.getComputedStyle?.(this.host).getPropertyValue('--ui-motion-scale').trim();
|
|
279
|
+
if (s && parseFloat(s) === 0) {
|
|
280
|
+
this.raf = 0;
|
|
281
|
+
this.sync();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
this.clock += this.last < 0 ? 0 : Math.min(now - this.last, 64);
|
|
286
|
+
this.last = now;
|
|
287
|
+
this.draw(this.clock);
|
|
288
|
+
this.raf = this.win!.requestAnimationFrame(this.tick);
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
private aimAt(x: number, y: number, ms: number, pow: number) {
|
|
292
|
+
const [cx, cy] = this.lookNow(this.clock);
|
|
293
|
+
this.look = { x0: cx, y0: cy, x, y, at: this.clock, ms, pow };
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
private lookNow(t: number): [number, number] {
|
|
297
|
+
const k = this.look;
|
|
298
|
+
const p = Math.min(1, (t - k.at) / k.ms);
|
|
299
|
+
const e = 1 - (1 - p) ** k.pow;
|
|
300
|
+
return [k.x0 + (k.x - k.x0) * e, k.y0 + (k.y - k.y0) * e];
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
private aim(e: PointerEvent) {
|
|
304
|
+
if (this.still || !this.raf || !this.followPointer()) return;
|
|
305
|
+
const svg = this.host.querySelector('svg');
|
|
306
|
+
if (!svg) return;
|
|
307
|
+
const r = svg.getBoundingClientRect();
|
|
308
|
+
const soft = (v: number, cap: number) => v / (1 + Math.abs(v / cap) ** 8) ** 0.125;
|
|
309
|
+
this.hovering = true;
|
|
310
|
+
this.aimAt(soft((e.clientX - r.left - r.width / 2) * 0.034, 13), soft((e.clientY - r.top - r.height / 2) * 0.034, 8), 500, 2);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
private leave() {
|
|
314
|
+
if (!this.hovering) return;
|
|
315
|
+
this.hovering = false;
|
|
316
|
+
this.aimAt(0, 0, 500, 2);
|
|
317
|
+
this.nextGlance = this.clock + 1300;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
private press(e: PointerEvent) {
|
|
321
|
+
if (this.still || !this.raf) return;
|
|
322
|
+
this.pressAt = this.clock;
|
|
323
|
+
if (e.pointerType !== 'mouse') this.aim(e);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
private draw(t: number) {
|
|
327
|
+
if (!this.hovering && t >= this.nextGlance) {
|
|
328
|
+
const [x, y] = (this.look.x || this.look.y) && Math.random() < 0.6 ? [0, 0] : this.pick();
|
|
329
|
+
this.aimAt(x, y, 530, 2.3);
|
|
330
|
+
this.nextGlance = t + 530 + 800 + Math.random() * 3300;
|
|
331
|
+
}
|
|
332
|
+
if (t >= this.nextBlink) {
|
|
333
|
+
this.blinks = Math.random() < 1 / 3 ? [t, t + 250] : [t];
|
|
334
|
+
this.nextBlink = t + 2700 + Math.random() * 2700;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const phase = (2 * Math.PI * t) / PERIOD;
|
|
338
|
+
const up = Math.sin(phase);
|
|
339
|
+
const breathe = 0.011 * Math.cos(phase);
|
|
340
|
+
const [lx, ly] = this.lookNow(t);
|
|
341
|
+
const bx = lx / 4;
|
|
342
|
+
const tilt = lx * 0.24;
|
|
343
|
+
|
|
344
|
+
const since = t - this.pressAt;
|
|
345
|
+
const spring = since < 900 ? Math.exp(-since / 204) * Math.cos((Math.PI * since) / 200) : 0;
|
|
346
|
+
|
|
347
|
+
let lid = 1;
|
|
348
|
+
for (const b of this.blinks) {
|
|
349
|
+
const d = t - b;
|
|
350
|
+
if (d >= 0 && d < 150) lid = Math.min(lid, d < 70 ? 1 - 0.89 * ease(d / 70) : 0.11 + 0.89 * ease((d - 70) / 80));
|
|
351
|
+
}
|
|
352
|
+
const w = since - 115;
|
|
353
|
+
const wink = w >= 0 && w < 350 ? (w < 170 ? ease(w / 170) : 1 - ease((w - 170) / 180)) : 0;
|
|
354
|
+
|
|
355
|
+
const p = this.parts;
|
|
356
|
+
p['fl']?.setAttribute('transform', `translate(0 ${(-4.85 * up).toFixed(2)})`);
|
|
357
|
+
p['sq']?.setAttribute('transform', about(120, 190, `scale(${f(1 + 0.08 * spring)} ${f(1 - 0.09 * spring)})`));
|
|
358
|
+
p['bd']?.setAttribute('transform', `translate(${f(bx)} 0) rotate(${f(tilt)} 120 120) ` + about(120, 120, `scale(${f(1 + breathe)} ${f(1 - breathe)})`));
|
|
359
|
+
p['ey']?.setAttribute('transform', `translate(${f(lx - bx)} ${f(ly)})`);
|
|
360
|
+
p['l']?.setAttribute('transform', about(105.5, 122, `scale(1 ${f(lid * (1 + 0.03 * wink))})`));
|
|
361
|
+
p['r']?.setAttribute('transform', about(136.5, 122, `scale(1 ${f(Math.min(lid, 1 - 0.89 * wink))})`));
|
|
362
|
+
p['sn']?.setAttribute('transform', `translate(${f(-lx * 0.58)} ${f(ly < 0 ? -0.4 * ly : -1.3 * ly)})`);
|
|
363
|
+
p['sh']?.setAttribute('transform', about(120, 210, `scale(${f(1 + 0.064 * up)} 1)`));
|
|
364
|
+
p['sh']?.setAttribute('opacity', f(0.29 + 0.05 * up));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
private pick(): [number, number] {
|
|
368
|
+
const [x, y] = LOOKS[Math.floor(Math.random() * LOOKS.length)];
|
|
369
|
+
const k = 0.7 + Math.random() * 0.3;
|
|
370
|
+
return [x * k, y * k];
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
private rest() {
|
|
374
|
+
for (const el of Object.values(this.parts)) el?.removeAttribute('transform');
|
|
375
|
+
this.parts['sh']?.setAttribute('opacity', '0.29');
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const ease = (x: number) => x * x * (3 - 2 * x);
|
|
380
|
+
const f = (v: number) => v.toFixed(4).replace(/\.?0+$/, '');
|
|
381
|
+
const about = (x: number, y: number, op: string) => `translate(${x} ${y}) ${op} translate(${-x} ${-y})`;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
|
|
2
|
+
/**
|
|
3
|
+
* Ghosted Chat, from Ochre (https://ochreui.dev).
|
|
4
|
+
* Needs ochre.css (`npx ochreui init`).
|
|
5
|
+
*
|
|
6
|
+
* <ui-ghosted-chat />
|
|
7
|
+
* A small card illustration: three chat messages sent, seen and never answered, with a thumbs-down reply on hover.
|
|
8
|
+
* It scales with its width (3:2, up to 560px), reads as one image and stays still with reduced motion.
|
|
9
|
+
*
|
|
10
|
+
* Public styling hooks (set them on the element or any ancestor):
|
|
11
|
+
* --ui-ghosted-chat-bubble message fill (default: the surface)
|
|
12
|
+
* --ui-ghosted-chat-ink message text (default: the text colour, a little softer for the first two)
|
|
13
|
+
* --ui-ghosted-chat-status status line and receipt (default: the muted text colour)
|
|
14
|
+
* --ui-ghosted-chat-reply reply bubble (default: a deep blue)
|
|
15
|
+
* --ui-ghosted-chat-shine the shine on the last message (default: red)
|
|
16
|
+
*/
|
|
17
|
+
import {
|
|
18
|
+
Component,
|
|
19
|
+
DOCUMENT,
|
|
20
|
+
DestroyRef,
|
|
21
|
+
ElementRef,
|
|
22
|
+
Injector,
|
|
23
|
+
afterNextRender,
|
|
24
|
+
computed,
|
|
25
|
+
inject,
|
|
26
|
+
input,
|
|
27
|
+
signal,
|
|
28
|
+
} from '@angular/core';
|
|
29
|
+
|
|
30
|
+
export interface GhostedChatLabels {
|
|
31
|
+
/** The muted line above the messages. */
|
|
32
|
+
status: string;
|
|
33
|
+
/** The three messages, top to bottom. The second wraps over two lines. */
|
|
34
|
+
first: string;
|
|
35
|
+
second: string;
|
|
36
|
+
last: string;
|
|
37
|
+
/** The receipt under the last message. */
|
|
38
|
+
receipt: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const LABELS: GhostedChatLabels = {
|
|
42
|
+
status: 'No messages yet',
|
|
43
|
+
first: 'Hi crew!',
|
|
44
|
+
second: 'Do you have fifteen minutes for a quick call?',
|
|
45
|
+
last: 'Ping!?',
|
|
46
|
+
receipt: 'Seen',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
@Component({
|
|
50
|
+
selector: 'ui-ghosted-chat',
|
|
51
|
+
host: {
|
|
52
|
+
'[attr.role]': "label() ? 'img' : null",
|
|
53
|
+
'[attr.aria-label]': 'label() || null',
|
|
54
|
+
'[attr.aria-hidden]': "label() ? null : 'true'",
|
|
55
|
+
'[attr.data-phase]': 'phase()',
|
|
56
|
+
'[attr.data-asleep]': "awake() ? null : ''",
|
|
57
|
+
},
|
|
58
|
+
template: `
|
|
59
|
+
<div aria-hidden="true" style="position: absolute; inset: 0; container-type: inline-size">
|
|
60
|
+
<div style="position: absolute; inset: 0 auto auto 0; box-sizing: border-box; display: flex; flex-direction: column; align-items: center; width: 360px; height: 240px; padding: 22px 22px 0; direction: ltr; scale: tan(atan2(100cqi, 360px)); transform-origin: 0 0">
|
|
61
|
+
<div style="position: relative; box-sizing: border-box; display: flex; flex-direction: column; align-items: center; flex: none; width: 316px; height: 218px; gap: 14px; scale: 0.86; transform-origin: 50% 45%">
|
|
62
|
+
<div class="st">{{ t().status }}</div>
|
|
63
|
+
<div class="k" style="align-self: stretch; box-sizing: border-box; display: flex; flex-direction: column; align-items: flex-end; gap: 5px; padding-right: 14px; transition: translate calc(400ms * var(--_m)) cubic-bezier(0.4, 0, 0.2, 1)">
|
|
64
|
+
<div class="b e">{{ t().first }}</div>
|
|
65
|
+
<div class="b e">{{ t().second }}</div>
|
|
66
|
+
<div class="e" style="position: relative; display: flex">
|
|
67
|
+
<i style="position: absolute; left: calc(50% - 29.5px); top: 12.25px; width: 59px; height: 22px; border-radius: 50%; filter: blur(12px); opacity: 0.6;
|
|
68
|
+
background: linear-gradient(60deg, color-mix(in srgb, var(--ui-red-light) 60%, transparent) 25%, color-mix(in srgb, var(--ui-purple-light) 38%, transparent) 65%, color-mix(in srgb, var(--ui-blue-light) 25%, transparent))"></i>
|
|
69
|
+
<div class="b" style="max-width: none; padding: 6px 11px; color: var(--_ink); box-shadow: 0 0 0 1px color-mix(in srgb, var(--ui-text) 3%, transparent)"><span class="s">{{ t().last }}</span></div>
|
|
70
|
+
</div>
|
|
71
|
+
<div class="rd">{{ t().receipt }}</div>
|
|
72
|
+
</div>
|
|
73
|
+
<div class="re" style="position: absolute; left: 64px; top: 119.5px; box-sizing: border-box; padding: 6px 12px; border: 1px solid var(--_rp); border-radius: 14px 14px 14px 4px; background: var(--_rp); transform-origin: 0 100%;
|
|
74
|
+
box-shadow: 0 4px 12px light-dark(color-mix(in srgb, var(--_rp) 30%, transparent), color-mix(in srgb, var(--ui-gray-1050) 60%, transparent));
|
|
75
|
+
transition: opacity calc(350ms * var(--_m)) cubic-bezier(0.26, 0.1, 0.24, 1), translate calc(450ms * var(--_m)) var(--ui-ease-spring), scale calc(450ms * var(--_m)) var(--ui-ease-spring)">
|
|
76
|
+
<svg viewBox="0 0 20 20" stroke-width=".6" stroke-linejoin="round"
|
|
77
|
+
style="display: block; width: 19px; height: 19px; margin: -1.25px 0; fill: var(--ui-amber-dark); stroke: color-mix(in srgb, var(--ui-orange-light) 70%, var(--ui-gray-1000))">
|
|
78
|
+
<path d="M2.6 5.6Q2.6 2.6 5.6 2.6h6v10h-3Q5.8 12.6 4.3 11 2.6 9.4 2.6 7.6Z" />
|
|
79
|
+
<rect x="7.6" y="9.2" width="3.3" height="8.8" rx="1.65" />
|
|
80
|
+
<rect x="10.2" y="2.4" width="6.4" height="2.7" rx="1.35" />
|
|
81
|
+
<rect x="10.2" y="5.1" width="6.9" height="2.7" rx="1.35" />
|
|
82
|
+
<rect x="10.2" y="7.8" width="6.6" height="2.7" rx="1.35" />
|
|
83
|
+
<rect x="10.2" y="10.5" width="5.6" height="2.5" rx="1.25" />
|
|
84
|
+
</svg>
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
`,
|
|
90
|
+
styles: `
|
|
91
|
+
@layer ui {
|
|
92
|
+
:host { display: block; position: relative; inline-size: min(560px, 100%); max-inline-size: 100%; aspect-ratio: 3 / 2; overflow: hidden; }
|
|
93
|
+
}
|
|
94
|
+
:host {
|
|
95
|
+
--_m: var(--ui-motion-scale, 1);
|
|
96
|
+
--_bg: var(--ui-ghosted-chat-bubble, var(--ui-bg-surface));
|
|
97
|
+
--_ink: var(--ui-ghosted-chat-ink, var(--ui-text));
|
|
98
|
+
--_rp: var(--ui-ghosted-chat-reply, oklch(from var(--ui-blue-light) 0.555 calc(c * 1.08) h));
|
|
99
|
+
--_sh: var(--ui-ghosted-chat-shine, var(--ui-hue-red));
|
|
100
|
+
box-sizing: border-box;
|
|
101
|
+
font-family: var(--ui-font-sans);
|
|
102
|
+
user-select: none;
|
|
103
|
+
-webkit-user-select: none;
|
|
104
|
+
}
|
|
105
|
+
:host::before { content: 'x x x x x x x x' / ''; display: block; block-size: 0; overflow: hidden; font-size: 0; word-spacing: 80px; }
|
|
106
|
+
.st, .rd {
|
|
107
|
+
color: var(--ui-ghosted-chat-status, var(--ui-text-muted));
|
|
108
|
+
font-size: 11px; line-height: 1.4; letter-spacing: 0.01em; white-space: nowrap;
|
|
109
|
+
transition: opacity var(--ui-duration-4) ease-out;
|
|
110
|
+
--_d: 100ms;
|
|
111
|
+
}
|
|
112
|
+
.rd { margin-top: 8px; font-size: 10.5px; letter-spacing: 0; --_d: 3200ms; }
|
|
113
|
+
.b {
|
|
114
|
+
position: relative; box-sizing: border-box; max-width: 68%; padding: 7px 12px;
|
|
115
|
+
border: 1px solid var(--ui-hairline); border-radius: 14px 14px 4px;
|
|
116
|
+
background: var(--_bg); box-shadow: 0 1.5px 3px color-mix(in srgb, var(--ui-gray-1000) 9%, transparent);
|
|
117
|
+
color: color-mix(in srgb, var(--_ink) 78%, var(--_bg));
|
|
118
|
+
font-size: 12.5px; line-height: 1.3; font-weight: var(--ui-weight-medium); text-wrap: balance;
|
|
119
|
+
}
|
|
120
|
+
.e { transform-origin: 100% 100%; }
|
|
121
|
+
.s {
|
|
122
|
+
background: linear-gradient(90deg, var(--_ink) 41%, color-mix(in srgb, var(--_sh) 60%, var(--ui-gray-1000)) 44%, var(--_sh) 51%,
|
|
123
|
+
color-mix(in srgb, var(--_sh) 50%, var(--ui-gray-1000)) 54%, var(--_ink) 56%) 20% 0 / 400% 100%;
|
|
124
|
+
-webkit-background-clip: text; background-clip: text; color: transparent;
|
|
125
|
+
}
|
|
126
|
+
:host([data-phase='in']:not([data-asleep])) .s { animation: ui-gc-s calc(4500ms * var(--_m)) linear infinite; }
|
|
127
|
+
.re { opacity: 0; translate: 0 14px; scale: 0.92; }
|
|
128
|
+
@media (hover: hover) {
|
|
129
|
+
:host(:hover) .st, :host(:hover) .rd { opacity: 0; }
|
|
130
|
+
:host(:hover) .k { translate: 0 -12px; }
|
|
131
|
+
:host(:hover) .re { opacity: 1; translate: none; scale: none; }
|
|
132
|
+
}
|
|
133
|
+
:host([data-phase='wait']) .st, :host([data-phase='wait']) .e, :host([data-phase='wait']) .rd { opacity: 0; }
|
|
134
|
+
:host([data-phase='in']) .st, :host([data-phase='in']) .rd { animation: ui-gc-f calc(500ms * var(--_m)) calc(var(--_d) * var(--_m)) ease-out backwards; }
|
|
135
|
+
:host([data-phase='in']) .e { animation: ui-gc-e calc(620ms * var(--_m)) calc(var(--_d) * var(--_m)) cubic-bezier(0.22, 1, 0.4, 1) backwards; }
|
|
136
|
+
.e:nth-child(1) { --_d: 500ms; }
|
|
137
|
+
.e:nth-child(2) { --_d: 1300ms; }
|
|
138
|
+
.e:nth-child(3) { --_d: 2300ms; }
|
|
139
|
+
@keyframes ui-gc-f { from { opacity: 0; } }
|
|
140
|
+
@keyframes ui-gc-e { from { opacity: 0; scale: 0.92; translate: 0 10px; } }
|
|
141
|
+
@keyframes ui-gc-s { 0%, 9.33% { background-position: 76% 0; } 26.67%, 100% { background-position: 20% 0; } }
|
|
142
|
+
@media (forced-colors: active) {
|
|
143
|
+
.s { background: none; color: CanvasText; }
|
|
144
|
+
i { display: none; }
|
|
145
|
+
}
|
|
146
|
+
`,
|
|
147
|
+
})
|
|
148
|
+
export class UiGhostedChat {
|
|
149
|
+
/** What screen readers hear for the whole picture. Leave it empty to hide the picture from them. */
|
|
150
|
+
readonly label = input('A one-sided chat: three messages seen, none answered');
|
|
151
|
+
/** The texts in the drawing, for translation. Keep them about as long as the defaults. */
|
|
152
|
+
readonly labels = input<Partial<GhostedChatLabels>>({});
|
|
153
|
+
|
|
154
|
+
protected readonly t = computed(() => ({ ...LABELS, ...this.labels() }));
|
|
155
|
+
/** `idle` until the first render (server HTML shows the rest pose), `wait` until in view, then `in`. */
|
|
156
|
+
protected readonly phase = signal<'idle' | 'wait' | 'in'>('idle');
|
|
157
|
+
private readonly seen = signal(true);
|
|
158
|
+
private readonly shown = signal(true);
|
|
159
|
+
/** On screen in a visible tab: the shine only runs then, and starts over when it comes back. */
|
|
160
|
+
protected readonly awake = computed(() => this.seen() && this.shown());
|
|
161
|
+
|
|
162
|
+
private readonly doc = inject(DOCUMENT);
|
|
163
|
+
private readonly win = this.doc.defaultView;
|
|
164
|
+
private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
|
|
165
|
+
private readonly injector = inject(Injector);
|
|
166
|
+
|
|
167
|
+
constructor() {
|
|
168
|
+
let io: IntersectionObserver | undefined;
|
|
169
|
+
const onVisibility = () => this.shown.set(this.doc.visibilityState !== 'hidden');
|
|
170
|
+
afterNextRender(() => {
|
|
171
|
+
onVisibility();
|
|
172
|
+
this.doc.addEventListener('visibilitychange', onVisibility);
|
|
173
|
+
const Observer = this.win?.IntersectionObserver;
|
|
174
|
+
if (!Observer) {
|
|
175
|
+
this.phase.set('in');
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
this.phase.set('wait');
|
|
179
|
+
io = new Observer(
|
|
180
|
+
(entries) => {
|
|
181
|
+
const e = entries[entries.length - 1];
|
|
182
|
+
this.seen.set(e.isIntersecting);
|
|
183
|
+
if (this.phase() !== 'wait' || !e.isIntersecting) return;
|
|
184
|
+
const view = e.rootBounds?.height ?? this.win?.innerHeight ?? 0;
|
|
185
|
+
if (e.intersectionRatio >= 0.349 || (view > 0 && e.intersectionRect.height >= 0.35 * view)) this.phase.set('in');
|
|
186
|
+
},
|
|
187
|
+
{ threshold: [0, ...Array.from({ length: 10 }, (_, i) => 0.35 / 2 ** i)] },
|
|
188
|
+
);
|
|
189
|
+
io.observe(this.host);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
inject(DestroyRef).onDestroy(() => {
|
|
193
|
+
io?.disconnect();
|
|
194
|
+
this.doc.removeEventListener('visibilitychange', onVisibility);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Plays the entry again from the start, for a Replay button. */
|
|
199
|
+
replay(): void {
|
|
200
|
+
if (this.phase() === 'idle') return;
|
|
201
|
+
this.phase.set('wait');
|
|
202
|
+
afterNextRender(
|
|
203
|
+
() => {
|
|
204
|
+
void this.host.offsetWidth;
|
|
205
|
+
this.phase.set('in');
|
|
206
|
+
},
|
|
207
|
+
{ injector: this.injector },
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
}
|