ochreui 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +153 -2
  3. package/cli/ochreui.mjs +601 -0
  4. package/mcp/core.mjs +126 -0
  5. package/mcp/docs.json +906 -0
  6. package/mcp/server.mjs +23 -0
  7. package/package.json +393 -3
  8. package/registry/agent-team.ts +350 -0
  9. package/registry/avatar.ts +300 -0
  10. package/registry/badge.ts +207 -0
  11. package/registry/breadcrumb.ts +435 -0
  12. package/registry/button.ts +238 -0
  13. package/registry/card.ts +221 -0
  14. package/registry/change-summary.ts +200 -0
  15. package/registry/checkbox.ts +204 -0
  16. package/registry/code-block.ts +332 -0
  17. package/registry/color-picker.ts +720 -0
  18. package/registry/comment-thread.ts +503 -0
  19. package/registry/context-menu.ts +281 -0
  20. package/registry/cover-flow.ts +623 -0
  21. package/registry/date-picker.ts +799 -0
  22. package/registry/decision-inbox.ts +340 -0
  23. package/registry/dialog.ts +577 -0
  24. package/registry/dropdown-menu.ts +864 -0
  25. package/registry/email-draft.ts +916 -0
  26. package/registry/empty-calendar.ts +199 -0
  27. package/registry/empty-state.ts +164 -0
  28. package/registry/enrichment-orbit.ts +164 -0
  29. package/registry/filter-menu.ts +541 -0
  30. package/registry/form-field.ts +308 -0
  31. package/registry/frost-cloud.ts +381 -0
  32. package/registry/ghosted-chat.ts +210 -0
  33. package/registry/glow-cloud.ts +402 -0
  34. package/registry/grid-background.ts +164 -0
  35. package/registry/hover-card.ts +401 -0
  36. package/registry/icon-button.ts +133 -0
  37. package/registry/index.json +2124 -0
  38. package/registry/integration-beam.ts +588 -0
  39. package/registry/integration-grid.ts +209 -0
  40. package/registry/kbd.ts +176 -0
  41. package/registry/layer-stack.ts +351 -0
  42. package/registry/lead-sourcing.ts +285 -0
  43. package/registry/logo-cluster.ts +239 -0
  44. package/registry/logo-marquee.ts +505 -0
  45. package/registry/message-actions.ts +833 -0
  46. package/registry/model-orbit.ts +583 -0
  47. package/registry/model-wheel.ts +372 -0
  48. package/registry/notification-stack.ts +301 -0
  49. package/registry/number-input.ts +552 -0
  50. package/registry/number-ticker.ts +261 -0
  51. package/registry/ochre.css +917 -0
  52. package/registry/otp-input.ts +704 -0
  53. package/registry/overlay.ts +312 -0
  54. package/registry/pagination.ts +362 -0
  55. package/registry/popover.ts +296 -0
  56. package/registry/profile-menu.ts +332 -0
  57. package/registry/progress-tracker.ts +291 -0
  58. package/registry/rating.ts +461 -0
  59. package/registry/reaction-bar.ts +322 -0
  60. package/registry/region-map.ts +537 -0
  61. package/registry/resizable.ts +489 -0
  62. package/registry/scroll-area.ts +271 -0
  63. package/registry/segmented-control.ts +433 -0
  64. package/registry/select.ts +769 -0
  65. package/registry/separator.ts +97 -0
  66. package/registry/shimmer-loader.ts +211 -0
  67. package/registry/side-folder.ts +152 -0
  68. package/registry/skeleton.ts +136 -0
  69. package/registry/skill/INSTRUCTIONS.md +11 -0
  70. package/registry/skill/SKILL.md +65 -0
  71. package/registry/skill/checklist.md +45 -0
  72. package/registry/skill/references/agent-team.md +105 -0
  73. package/registry/skill/references/avatar.md +88 -0
  74. package/registry/skill/references/badge.md +92 -0
  75. package/registry/skill/references/breadcrumb.md +99 -0
  76. package/registry/skill/references/button.md +82 -0
  77. package/registry/skill/references/card.md +111 -0
  78. package/registry/skill/references/catalog.md +114 -0
  79. package/registry/skill/references/change-summary.md +103 -0
  80. package/registry/skill/references/checkbox.md +105 -0
  81. package/registry/skill/references/code-block.md +109 -0
  82. package/registry/skill/references/color-picker.md +138 -0
  83. package/registry/skill/references/comment-thread.md +164 -0
  84. package/registry/skill/references/context-menu.md +205 -0
  85. package/registry/skill/references/cover-flow.md +128 -0
  86. package/registry/skill/references/date-picker.md +154 -0
  87. package/registry/skill/references/decision-inbox.md +126 -0
  88. package/registry/skill/references/dialog.md +155 -0
  89. package/registry/skill/references/dropdown-menu.md +144 -0
  90. package/registry/skill/references/email-draft.md +182 -0
  91. package/registry/skill/references/empty-calendar.md +74 -0
  92. package/registry/skill/references/empty-state.md +118 -0
  93. package/registry/skill/references/enrichment-orbit.md +71 -0
  94. package/registry/skill/references/filter-menu.md +143 -0
  95. package/registry/skill/references/form-field.md +118 -0
  96. package/registry/skill/references/frost-cloud.md +80 -0
  97. package/registry/skill/references/ghosted-chat.md +75 -0
  98. package/registry/skill/references/glow-cloud.md +84 -0
  99. package/registry/skill/references/grid-background.md +76 -0
  100. package/registry/skill/references/hover-card.md +125 -0
  101. package/registry/skill/references/icon-button.md +99 -0
  102. package/registry/skill/references/integration-beam.md +107 -0
  103. package/registry/skill/references/integration-grid.md +100 -0
  104. package/registry/skill/references/kbd.md +65 -0
  105. package/registry/skill/references/layer-stack.md +115 -0
  106. package/registry/skill/references/lead-sourcing.md +92 -0
  107. package/registry/skill/references/logo-cluster.md +92 -0
  108. package/registry/skill/references/logo-marquee.md +123 -0
  109. package/registry/skill/references/message-actions.md +146 -0
  110. package/registry/skill/references/model-orbit.md +106 -0
  111. package/registry/skill/references/model-wheel.md +84 -0
  112. package/registry/skill/references/notification-stack.md +138 -0
  113. package/registry/skill/references/number-input.md +117 -0
  114. package/registry/skill/references/number-ticker.md +73 -0
  115. package/registry/skill/references/otp-input.md +142 -0
  116. package/registry/skill/references/pagination.md +112 -0
  117. package/registry/skill/references/popover.md +143 -0
  118. package/registry/skill/references/profile-menu.md +123 -0
  119. package/registry/skill/references/progress-tracker.md +122 -0
  120. package/registry/skill/references/rating.md +111 -0
  121. package/registry/skill/references/reaction-bar.md +128 -0
  122. package/registry/skill/references/region-map.md +109 -0
  123. package/registry/skill/references/resizable.md +127 -0
  124. package/registry/skill/references/scroll-area.md +113 -0
  125. package/registry/skill/references/segmented-control.md +96 -0
  126. package/registry/skill/references/select.md +122 -0
  127. package/registry/skill/references/separator.md +69 -0
  128. package/registry/skill/references/shimmer-loader.md +83 -0
  129. package/registry/skill/references/side-folder.md +75 -0
  130. package/registry/skill/references/skeleton.md +95 -0
  131. package/registry/skill/references/smart-recommendation.md +132 -0
  132. package/registry/skill/references/spinner.md +84 -0
  133. package/registry/skill/references/switch.md +79 -0
  134. package/registry/skill/references/tab-overload.md +70 -0
  135. package/registry/skill/references/tag-input.md +126 -0
  136. package/registry/skill/references/team-invite.md +94 -0
  137. package/registry/skill/references/testimonial-wall.md +110 -0
  138. package/registry/skill/references/text-area.md +115 -0
  139. package/registry/skill/references/text-field.md +126 -0
  140. package/registry/skill/references/text-reveal.md +71 -0
  141. package/registry/skill/references/thinking-loader.md +87 -0
  142. package/registry/skill/references/time-picker.md +122 -0
  143. package/registry/skill/references/tips-panel.md +115 -0
  144. package/registry/skill/references/toggle-group.md +98 -0
  145. package/registry/skill/references/tool-call-card.md +151 -0
  146. package/registry/skill/references/tooltip.md +94 -0
  147. package/registry/skill/references/tree-view.md +172 -0
  148. package/registry/skill/theming.md +57 -0
  149. package/registry/smart-recommendation.ts +415 -0
  150. package/registry/spinner.ts +67 -0
  151. package/registry/switch.ts +146 -0
  152. package/registry/tab-overload.ts +211 -0
  153. package/registry/tag-input.ts +620 -0
  154. package/registry/team-invite.ts +248 -0
  155. package/registry/testimonial-wall.ts +521 -0
  156. package/registry/text-area.ts +432 -0
  157. package/registry/text-field.ts +415 -0
  158. package/registry/text-reveal.ts +175 -0
  159. package/registry/theme.ts +68 -0
  160. package/registry/thinking-loader.ts +302 -0
  161. package/registry/time-picker.ts +828 -0
  162. package/registry/tips-panel.ts +312 -0
  163. package/registry/toggle-group.ts +357 -0
  164. package/registry/tool-call-card.ts +578 -0
  165. package/registry/tooltip.ts +486 -0
  166. package/registry/tree-view.ts +454 -0
  167. package/styles/base.css +500 -0
  168. package/styles/tokens.css +415 -0
@@ -0,0 +1,402 @@
1
+ // Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
2
+ /**
3
+ * Glow Cloud, from Ochre (https://ochreui.dev).
4
+ * Needs ochre.css (`npx ochreui init`).
5
+ *
6
+ * <ui-glow-cloud color="blue" label="Your assistant" />
7
+ * A small living mascot: a glowing cloud with pill eyes on a red or blue sky. It floats, blinks and follows
8
+ * the mouse; square up to 380px by default. It runs only while visible and keeps still with reduced motion.
9
+ *
10
+ * Public styling hooks (set them on the element or any ancestor):
11
+ * --ui-glow-cloud-sky-top sky colour at the top (default: deep red, or deep blue; deeper in dark mode)
12
+ * --ui-glow-cloud-sky-bottom sky colour at the bottom (default: warm orange, or light cyan)
13
+ * --ui-glow-cloud-bloom the soft light behind the cloud
14
+ * --ui-glow-cloud-body centre of the glowing body
15
+ * --ui-glow-cloud-body-mid middle of the body
16
+ * --ui-glow-cloud-rim outer edge of the body, inside the white glow
17
+ * --ui-glow-cloud-shine highlight on the top lobe
18
+ * --ui-glow-cloud-eye eyes
19
+ * --ui-glow-cloud-eye-low lower half of each eye
20
+ * --ui-glow-cloud-eye-rim thin rim around each eye
21
+ * --ui-glow-cloud-shadow ground shadow
22
+ */
23
+ import {
24
+ Component,
25
+ DOCUMENT,
26
+ DestroyRef,
27
+ ElementRef,
28
+ afterNextRender,
29
+ booleanAttribute,
30
+ computed,
31
+ inject,
32
+ input,
33
+ viewChild,
34
+ } from '@angular/core';
35
+
36
+ export type GlowCloudColor = 'blue' | 'orange';
37
+
38
+ const PERIOD = 5.7;
39
+ const TAU = Math.PI * 2;
40
+ const GAZE_W = 11.5;
41
+ let nextId = 0;
42
+
43
+ const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));
44
+ const rand = (lo: number, hi: number) => lo + Math.random() * (hi - lo);
45
+ const ease = (x: number) => x * x * (3 - 2 * x);
46
+ /** Eye opening for a blink or wink `x` seconds in, closing in `close` and opening again in `open`. */
47
+ const lid = (x: number, close: number, open: number) =>
48
+ x < 0 || x > close + open ? 1 : x < close ? 1 - 0.9 * ease(x / close) : 0.1 + 0.9 * ease((x - close) / open);
49
+
50
+ @Component({
51
+ selector: 'ui-glow-cloud',
52
+ host: {
53
+ '[attr.role]': "name() ? 'img' : null",
54
+ '[attr.aria-label]': 'name() || null',
55
+ '[attr.aria-hidden]': "name() ? null : 'true'",
56
+ '[attr.data-color]': 'tone()',
57
+ '[attr.data-bg]': "background() ? '' : null",
58
+ '(pointermove)': 'onMove($event)',
59
+ '(pointerleave)': 'onLeave($event)',
60
+ '(pointerdown)': 'onPress()',
61
+ },
62
+ template: `
63
+ <svg viewBox="0 0 240 240" aria-hidden="true" focusable="false">
64
+ <defs>
65
+ <g [attr.id]="id + 'l'">
66
+ <ellipse cx="115.5" cy="98.5" rx="38.7" ry="37.4" />
67
+ <ellipse cx="158.7" cy="114.2" rx="35.1" ry="33.95" />
68
+ <ellipse cx="152.4" cy="152.4" rx="27.9" ry="26.95" />
69
+ <ellipse cx="108.3" cy="152.5" rx="31.5" ry="30.45" />
70
+ <ellipse cx="76.8" cy="127.2" rx="30.6" ry="29.6" />
71
+ <rect x="84" y="104.65" width="72" height="56.5" />
72
+ </g>
73
+ <filter [attr.id]="id + 'g'" filterUnits="userSpaceOnUse" x="0" y="0" width="240" height="240" color-interpolation-filters="sRGB">
74
+ <feGaussianBlur stdDeviation="1" />
75
+ <feColorMatrix values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 30 -14" />
76
+ <feGaussianBlur stdDeviation=".3" />
77
+ </filter>
78
+ <filter [attr.id]="id + 'h'" filterUnits="userSpaceOnUse" x="0" y="0" width="240" height="240"><feGaussianBlur stdDeviation="5" /></filter>
79
+ <filter [attr.id]="id + 's'" filterUnits="userSpaceOnUse" x="0" y="0" width="240" height="240"><feGaussianBlur stdDeviation="5" /></filter>
80
+ <filter [attr.id]="id + 'f'"><feGaussianBlur stdDeviation="1.6" /></filter>
81
+ <filter [attr.id]="id + 'b'" filterUnits="userSpaceOnUse" x="0" y="0" width="240" height="240"><feGaussianBlur stdDeviation="6" /></filter>
82
+ <mask [attr.id]="id + 'm'" maskUnits="userSpaceOnUse" x="0" y="0" width="240" height="240">
83
+ <use [attr.href]="'#' + id + 'l'" fill="#fff" [attr.filter]="url('s')" />
84
+ </mask>
85
+ <radialGradient [attr.id]="id + 'r'" gradientUnits="userSpaceOnUse" cx="116" cy="114" r="84">
86
+ <stop offset="0" style="stop-color: var(--_c0)" />
87
+ <stop offset=".5" style="stop-color: var(--_c1)" />
88
+ <stop offset="1" style="stop-color: var(--_c2)" />
89
+ </radialGradient>
90
+ <linearGradient [attr.id]="id + 'e'" x1="0" y1="0" x2="0" y2="1">
91
+ <stop offset="0" style="stop-color: var(--_e0)" />
92
+ <stop offset=".45" style="stop-color: var(--_e0)" />
93
+ <stop offset="1" style="stop-color: var(--_e1)" />
94
+ </linearGradient>
95
+ <clipPath [attr.id]="id + 'c'"><rect width="18" height="31" rx="9" /></clipPath>
96
+ </defs>
97
+ <g #shadow transform="translate(120 0) scale(.94 1) translate(-120 0)">
98
+ <ellipse cx="120" cy="210" rx="50.75" ry="7" style="fill: var(--_d)" fill-opacity=".58" opacity=".29" [attr.filter]="url('b')" />
99
+ </g>
100
+ <g #float>
101
+ <g #turn>
102
+ <g [attr.filter]="url('h')" opacity=".4"><use [attr.href]="'#' + id + 'w'" /></g>
103
+ <g [attr.id]="id + 'w'" [attr.filter]="url('g')"><g fill="#fff" stroke="#fff" stroke-width="16"><use [attr.href]="'#' + id + 'l'" /><ellipse cx="115.5" cy="96" rx="38" ry="38.5" /></g></g>
104
+ <g [attr.mask]="url('m')">
105
+ <rect width="240" height="240" [attr.fill]="url('r')" />
106
+ </g>
107
+ <ellipse #shine cx="104" cy="80" rx="30" ry="12" style="fill: var(--_c3)" opacity=".62" [attr.filter]="url('b')" />
108
+ <g #eyes>
109
+ @for (x of [96.5, 127.5]; track x; let i = $index) {
110
+ <g [attr.transform]="'translate(' + x + ' 106)'">
111
+ <g [attr.data-eye]="i" [attr.clip-path]="url('c')">
112
+ <rect width="18" height="31" rx="9" style="fill: var(--_e2)" />
113
+ <rect x="1.2" y="3" width="15.6" height="27.2" rx="7.8" [attr.fill]="url('e')" [attr.filter]="url('f')" />
114
+ </g>
115
+ </g>
116
+ }
117
+ </g>
118
+ </g>
119
+ </g>
120
+ </svg>
121
+ `,
122
+ styles: `
123
+ @layer ui {
124
+ :host { display: grid; position: relative; inline-size: min(380px, 100%); aspect-ratio: 1; overflow: hidden; }
125
+ }
126
+ :host {
127
+ --_a: var(--ui-glow-cloud-sky-top, light-dark(#e9412f, #bd261f));
128
+ --_b: var(--ui-glow-cloud-sky-bottom, light-dark(#fa9a42, #ed701c));
129
+ --_g: var(--ui-glow-cloud-bloom, light-dark(rgb(255 196 160 / .5), rgb(255 190 150 / .28)));
130
+ --_c0: var(--ui-glow-cloud-body, #f4512f);
131
+ --_c1: var(--ui-glow-cloud-body-mid, #fb7b48);
132
+ --_c2: var(--ui-glow-cloud-rim, #ffbd8e);
133
+ --_c3: var(--ui-glow-cloud-shine, #ffb398);
134
+ --_e0: var(--ui-glow-cloud-eye, #fff8f3);
135
+ --_e1: var(--ui-glow-cloud-eye-low, #ffe5d6);
136
+ --_e2: var(--ui-glow-cloud-eye-rim, #eda48c);
137
+ --_d: var(--ui-glow-cloud-shadow, #a4230e);
138
+ place-items: center;
139
+ box-sizing: border-box;
140
+ cursor: pointer;
141
+ user-select: none;
142
+ -webkit-user-select: none;
143
+ -webkit-tap-highlight-color: transparent;
144
+ forced-color-adjust: none;
145
+ }
146
+ :host([data-color='blue']) {
147
+ --_a: var(--ui-glow-cloud-sky-top, light-dark(#2373ea, #1658c8));
148
+ --_b: var(--ui-glow-cloud-sky-bottom, light-dark(#4bc9f5, #2aa6e6));
149
+ --_g: var(--ui-glow-cloud-bloom, light-dark(rgb(110 214 255 / .52), rgb(110 200 255 / .34)));
150
+ --_c0: var(--ui-glow-cloud-body, #00a0ff);
151
+ --_c1: var(--ui-glow-cloud-body-mid, #19b2ff);
152
+ --_c2: var(--ui-glow-cloud-rim, #6dd4ff);
153
+ --_c3: var(--ui-glow-cloud-shine, #9fe0ff);
154
+ --_e0: var(--ui-glow-cloud-eye, #f3faff);
155
+ --_e1: var(--ui-glow-cloud-eye-low, #d6ecff);
156
+ --_e2: var(--ui-glow-cloud-eye-rim, #8fbdea);
157
+ --_d: var(--ui-glow-cloud-shadow, #14408c);
158
+ }
159
+ :host([data-bg]) {
160
+ background: radial-gradient(ellipse 38% 50% at 63% 43%, var(--_g), transparent), linear-gradient(var(--_a), var(--_b));
161
+ }
162
+ :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); }
163
+ :host::before, svg { grid-area: 1 / 1; }
164
+ svg {
165
+ display: block;
166
+ inline-size: min(380px, 78%);
167
+ aspect-ratio: 1;
168
+ overflow: visible;
169
+ pointer-events: none;
170
+ }
171
+ `,
172
+ })
173
+ export class UiGlowCloud {
174
+ /** Red-to-orange or blue-to-cyan sky; the cloud's colours follow. */
175
+ readonly color = input<GlowCloudColor>('orange');
176
+ /** Fill the whole box with the sky. `false` leaves the glowing cloud on your own background. */
177
+ readonly background = input(true, { transform: booleanAttribute });
178
+ /** The eyes follow the mouse while it is over the illustration. */
179
+ readonly followPointer = input(true, { transform: booleanAttribute });
180
+ /** What screen readers hear for the picture. An empty string hides it as pure decoration. */
181
+ readonly label = input<string | null | undefined>(undefined);
182
+
183
+ protected readonly name = computed(() => (this.label() ?? 'A glowing cloud with eyes that drifts, glances around and blinks').trim());
184
+ protected readonly tone = computed<GlowCloudColor>(() => (this.color() === 'blue' ? 'blue' : 'orange'));
185
+ protected readonly id = `ui-gc${nextId++}-`;
186
+
187
+ private readonly shadowG = viewChild.required<ElementRef<SVGGElement>>('shadow');
188
+ private readonly floatG = viewChild.required<ElementRef<SVGGElement>>('float');
189
+ private readonly turnG = viewChild.required<ElementRef<SVGGElement>>('turn');
190
+ private readonly shineEl = viewChild.required<ElementRef<SVGEllipseElement>>('shine');
191
+ private readonly eyesG = viewChild.required<ElementRef<SVGGElement>>('eyes');
192
+
193
+ private readonly doc = inject(DOCUMENT);
194
+ private readonly win = this.doc.defaultView;
195
+ private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
196
+
197
+ private raf = 0;
198
+ private last = 0;
199
+ private clock = 0;
200
+ private seen = false;
201
+ private still = false;
202
+ private checkAt = 0;
203
+ private live = false;
204
+ private fresh = true;
205
+ private gx = 0;
206
+ private gy = 0;
207
+ private vx = 0;
208
+ private vy = 0;
209
+ private tx = 0;
210
+ private ty = 0;
211
+ private following = false;
212
+ private nextGlance = 0;
213
+ private nextBlink = 0;
214
+ private blinks: number[] = [];
215
+ private press = -10;
216
+
217
+ constructor() {
218
+ let io: IntersectionObserver | undefined;
219
+ let mq: MediaQueryList | undefined;
220
+ const sync = () => this.sync();
221
+ afterNextRender(() => {
222
+ mq = this.win?.matchMedia?.('(prefers-reduced-motion: reduce)');
223
+ mq?.addEventListener?.('change', sync);
224
+ this.doc.addEventListener('visibilitychange', sync);
225
+ const Observer = this.win?.IntersectionObserver;
226
+ if (Observer) {
227
+ io = new Observer(
228
+ (entries) => {
229
+ this.seen = entries[entries.length - 1].isIntersecting;
230
+ this.sync();
231
+ },
232
+ { threshold: [0, ...Array.from({ length: 10 }, (_, i) => 0.5 / 2 ** i)] },
233
+ );
234
+ io.observe(this.host);
235
+ } else {
236
+ this.seen = true;
237
+ }
238
+ this.sync();
239
+ });
240
+ inject(DestroyRef).onDestroy(() => {
241
+ io?.disconnect();
242
+ mq?.removeEventListener?.('change', sync);
243
+ this.doc.removeEventListener('visibilitychange', sync);
244
+ this.stop();
245
+ });
246
+ }
247
+
248
+ protected url(key: string) {
249
+ return `url(#${this.id}${key})`;
250
+ }
251
+
252
+ protected onMove(e: PointerEvent) {
253
+ if (e.pointerType === 'touch' || !this.live) return;
254
+ if (!this.followPointer()) return this.onLeave(e);
255
+ const r = this.host.getBoundingClientRect();
256
+ if (!r.width || !r.height) return;
257
+ const nx = clamp((1.2 * (e.clientX - r.left - r.width / 2)) / (r.width / 2), -1, 1);
258
+ const ny = clamp((1.2 * (e.clientY - r.top - r.height / 2)) / (r.height / 2), -1, 1);
259
+ this.following = true;
260
+ this.tx = 12 * nx;
261
+ this.ty = 7 * ny;
262
+ }
263
+
264
+ protected onLeave(e: PointerEvent) {
265
+ if (e.pointerType === 'touch' || !this.following) return;
266
+ this.following = false;
267
+ this.tx = this.ty = 0;
268
+ this.nextGlance = this.clock + rand(2.3, 5);
269
+ }
270
+
271
+ protected onPress() {
272
+ if (this.live) this.press = this.clock;
273
+ }
274
+
275
+ private reduced() {
276
+ if (this.win?.matchMedia?.('(prefers-reduced-motion: reduce)').matches) return true;
277
+ const scale = this.win?.getComputedStyle?.(this.host).getPropertyValue('--ui-motion-scale').trim();
278
+ return !!scale && parseFloat(scale) === 0;
279
+ }
280
+
281
+ /** Runs the loop only when visible and motion is allowed; hidden, it freezes and later resumes from the same pose. */
282
+ private sync() {
283
+ this.still = this.reduced();
284
+ const run = this.seen && !this.still && this.doc.visibilityState !== 'hidden' && !!this.win?.requestAnimationFrame;
285
+ if (!run) {
286
+ this.stop();
287
+ if (this.still && !this.fresh) this.rest();
288
+ return;
289
+ }
290
+ if (this.live) return;
291
+ this.live = true;
292
+ if (this.fresh) {
293
+ this.fresh = false;
294
+ this.clock = 0;
295
+ this.gx = this.gy = this.vx = this.vy = this.tx = this.ty = 0;
296
+ this.following = false;
297
+ this.press = -10;
298
+ this.blinks = [];
299
+ this.nextGlance = rand(1.2, 3);
300
+ this.nextBlink = rand(1.5, 3.5);
301
+ }
302
+ this.last = 0;
303
+ this.raf = this.win!.requestAnimationFrame(this.frame);
304
+ }
305
+
306
+ private stop() {
307
+ if (this.raf) this.win?.cancelAnimationFrame(this.raf);
308
+ this.raf = 0;
309
+ this.live = false;
310
+ }
311
+
312
+ private rest() {
313
+ this.fresh = true;
314
+ this.gx = this.gy = 0;
315
+ this.render(-1, 1, 1);
316
+ }
317
+
318
+ private readonly frame = (now: number) => {
319
+ if (now >= this.checkAt) {
320
+ this.checkAt = now + 500;
321
+ if (this.reduced()) {
322
+ this.raf = 0;
323
+ this.sync();
324
+ return;
325
+ }
326
+ }
327
+ this.raf = this.win!.requestAnimationFrame(this.frame);
328
+ const dt = this.last ? Math.min(0.05, (now - this.last) / 1000) : 0;
329
+ this.last = now;
330
+ const c = (this.clock += dt);
331
+
332
+ if (!this.following && c >= this.nextGlance) {
333
+ if ((this.tx || this.ty) && Math.random() < 0.4) {
334
+ this.tx = this.ty = 0;
335
+ } else {
336
+ const a = Math.floor(Math.random() * 8) * (TAU / 8) + rand(-0.25, 0.25);
337
+ const k = rand(0.75, 1);
338
+ this.tx = clamp(12 * k * Math.cos(a), -12, 12);
339
+ this.ty = clamp(5 * k * Math.sin(a), -3.9, 2.5);
340
+ }
341
+ this.nextGlance = c + rand(2.3, 5);
342
+ }
343
+ if (c >= this.nextBlink) {
344
+ this.blinks = Math.random() < 1 / 3 ? [c, c + 0.25] : [c];
345
+ this.nextBlink = c + rand(2.6, 4.7);
346
+ }
347
+
348
+ for (let i = 0; i < 4 && dt; i++) {
349
+ const h = dt / 4;
350
+ this.vx += (GAZE_W * GAZE_W * (this.tx - this.gx) - 2 * GAZE_W * this.vx) * h;
351
+ this.vy += (GAZE_W * GAZE_W * (this.ty - this.gy) - 2 * GAZE_W * this.vy) * h;
352
+ this.gx += this.vx * h;
353
+ this.gy += this.vy * h;
354
+ }
355
+
356
+ const blink = this.blinks.reduce((o, s) => Math.min(o, lid(c - s, 0.065, 0.085)), 1);
357
+ const wink = lid(c - this.press - 0.15, 0.15, 0.2);
358
+ this.render(c, blink, Math.min(blink, wink));
359
+ };
360
+
361
+ /** Writes one frame. `c` < 0 draws the rest pose. */
362
+ private render(c: number, left: number, right: number) {
363
+ const rest = c < 0;
364
+ const env = rest ? 0 : ease(Math.min(1, c / 0.8));
365
+ const ph = (s: number) => Math.cos((TAU * (c - PERIOD / 4 - s)) / PERIOD);
366
+ const y = env * 5.45 * ph(0);
367
+ const x = env * -1.44 * ph(1);
368
+ const br = env * 0.012 * ph(0.85);
369
+ const k = env * ph(-0.43);
370
+ let sx = 1 + br;
371
+ let sy = 1 - br;
372
+ const b = c - this.press;
373
+ if (!rest && b >= 0 && b < 0.9) {
374
+ const d = Math.exp(-b / 0.2) * Math.cos((TAU * b) / 0.42);
375
+ sx += 0.08 * d;
376
+ sy -= 0.1 * d;
377
+ }
378
+ const ex = this.gx;
379
+ const ey = this.gy;
380
+ const lean = (2.5 * ex) / 12;
381
+ const narrow = 1 - (0.025 * Math.abs(ex)) / 12;
382
+ const f = (n: number) => +n.toFixed(3);
383
+
384
+ this.shadowG().nativeElement.setAttribute('transform', `translate(120 0) scale(${f(0.94 - 0.06 * k)} 1) translate(-120 0)`);
385
+ this.shadowG().nativeElement.setAttribute('opacity', `${f((0.29 - 0.05 * k) / 0.29)}`);
386
+ this.floatG().nativeElement.setAttribute(
387
+ 'transform',
388
+ `translate(${f(x + 120)} ${f(y + 168)}) scale(${f(sx)} ${f(sy)}) translate(-120 -168)`,
389
+ );
390
+ this.turnG().nativeElement.setAttribute(
391
+ 'transform',
392
+ `translate(${f((4 * ex) / 12 + 120)} 122) rotate(${f(lean)}) scale(${f(narrow)} 1) translate(-120 -122)`,
393
+ );
394
+ this.shineEl().nativeElement.setAttribute('transform', `translate(${f(-0.583 * ex)} ${f(-0.43 * ey)})`);
395
+ const eyes = this.eyesG().nativeElement;
396
+ eyes.setAttribute('transform', `translate(${f(ex)} ${f(ey)})`);
397
+ eyes.querySelectorAll('[data-eye]').forEach((el, i) => {
398
+ const s = i ? right : left;
399
+ el.setAttribute('transform', s === 1 ? '' : `translate(0 ${f(15.5 * (1 - s))}) scale(1 ${f(s)})`);
400
+ });
401
+ }
402
+ }
@@ -0,0 +1,164 @@
1
+ // Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
2
+ /**
3
+ * Grid Background, from Ochre (https://ochreui.dev).
4
+ * Needs ochre.css (`npx ochreui init`).
5
+ *
6
+ * <ui-grid-background class="hero"><section>…</section></ui-grid-background>
7
+ * A fine drifting line grid behind your content, faded toward the edges and revealed once when it comes into view.
8
+ * Project one element: it fills the box and stays interactive. Give the host a height, or let that element size it.
9
+ *
10
+ * Public styling hooks (set them on the element or any ancestor):
11
+ * --ui-grid-background-line line colour (default: the text colour at 8%, so it follows the theme)
12
+ */
13
+ import {
14
+ Component,
15
+ DOCUMENT,
16
+ DestroyRef,
17
+ ElementRef,
18
+ afterNextRender,
19
+ booleanAttribute,
20
+ computed,
21
+ inject,
22
+ input,
23
+ numberAttribute,
24
+ signal,
25
+ } from '@angular/core';
26
+
27
+ export type GridBackgroundDirection = 'up' | 'down' | 'left' | 'right' | 'diagonal';
28
+
29
+ const STEP: Record<GridBackgroundDirection, readonly [number, number]> = {
30
+ up: [0, -1],
31
+ down: [0, 1],
32
+ left: [-1, 0],
33
+ right: [1, 0],
34
+ diagonal: [-1, 1],
35
+ };
36
+
37
+ @Component({
38
+ selector: 'ui-grid-background',
39
+ host: {
40
+ '[style.--_s.px]': 'size()',
41
+ '[style.--_v.s]': 'speed()',
42
+ '[style.--_f.%]': 'fade()',
43
+ '[style.--_x]': 'step()[0]',
44
+ '[style.--_y]': 'step()[1]',
45
+ '[style.--ui-grid-background-line]': 'color()',
46
+ '[style.--_p]': "awake() ? null : 'paused'",
47
+ '[attr.data-still]': "speed() > 0 && !calm() ? null : ''",
48
+ '[attr.data-wait]': "phase() === 'wait' && reveal() ? '' : null",
49
+ '[attr.data-shown]': "phase() === 'shown' ? '' : null",
50
+ },
51
+ template: `
52
+ <div class="g" aria-hidden="true"><div class="r"><div class="p"></div></div></div>
53
+ <div class="c"><ng-content /></div>
54
+ `,
55
+ styles: `
56
+ @property --_grid-r { syntax: '<percentage>'; inherits: false; initial-value: 105%; }
57
+ :host {
58
+ --_l: var(--ui-grid-background-line, color-mix(in srgb, var(--ui-text) 8%, transparent));
59
+ display: grid;
60
+ position: relative;
61
+ isolation: isolate;
62
+ overflow: hidden;
63
+ box-sizing: border-box;
64
+ }
65
+ .g, .r { position: absolute; inset: 0; pointer-events: none; }
66
+ .g {
67
+ z-index: 0;
68
+ mask: radial-gradient(ellipse farthest-corner, #000 calc(var(--_f) * 0.3), #0000 var(--_f));
69
+ }
70
+ .r { overflow: hidden; }
71
+ :host([data-wait]) .r { --_grid-r: 0%; }
72
+ :host([data-wait]) .r, :host([data-shown]) .r {
73
+ mask: radial-gradient(circle farthest-corner, #000 calc(var(--_grid-r) - 11%), #0000 var(--_grid-r));
74
+ }
75
+ :host([data-shown]) .r {
76
+ animation: ui-grid-r calc(1600ms * var(--ui-motion-scale, 1))
77
+ linear(0, 0.24 3.1%, 0.36 6.25%, 0.57 12.5%, 0.72 18.75%, 0.84 25%, 0.905 31.25%, 0.96 45%, 0.99 65%, 1);
78
+ }
79
+ .p {
80
+ position: absolute;
81
+ inset: calc(-1 * var(--_s));
82
+ background:
83
+ linear-gradient(90deg, var(--_l) 1px, #0000 0) 0 0 / var(--_s) var(--_s),
84
+ linear-gradient(var(--_l) 1px, #0000 0) 0 0 / var(--_s) var(--_s);
85
+ animation: ui-grid-d var(--_v) linear infinite var(--_p, running);
86
+ }
87
+ :host([data-still]) .p { animation: none; }
88
+ @container style(--ui-motion-scale: 0) { .p, .r { animation: none; } }
89
+ .c { position: relative; z-index: 1; display: grid; min-inline-size: 0; }
90
+ @keyframes ui-grid-r { from { --_grid-r: 0%; } }
91
+ @keyframes ui-grid-d { to { translate: calc(var(--_x) * var(--_s)) calc(var(--_y) * var(--_s)); } }
92
+ @media (prefers-reduced-motion: reduce) {
93
+ .p, .r { animation: none !important; mask: none !important; }
94
+ }
95
+ @media (forced-colors: active) {
96
+ .g { display: none; }
97
+ }
98
+ `,
99
+ })
100
+ export class UiGridBackground {
101
+ /** Cell size in px. */
102
+ readonly size = input(48, { transform: (v: unknown) => numberAttribute(v, 48) });
103
+ /** Seconds to drift one cell. 0 keeps the grid still. */
104
+ readonly speed = input(3, { transform: (v: unknown) => numberAttribute(v, 3) });
105
+ /** Drift direction. Physical in every writing direction; `diagonal` runs from top right to bottom left. */
106
+ readonly direction = input<GridBackgroundDirection>('diagonal');
107
+ /** Uncover the grid with a circle growing from the centre, once, when a fifth of it (or of the viewport) first comes into view. */
108
+ readonly reveal = input(true, { transform: booleanAttribute });
109
+ /** Where the edge fade reaches transparent, in % of the distance to the corners. Lines are full strength up to 30% of it. */
110
+ readonly fade = input(70, { transform: (v: unknown) => numberAttribute(v, 70) });
111
+ /** Line colour. Leave it unset to follow the theme through `--ui-grid-background-line`. */
112
+ readonly color = input<string | null>(null);
113
+
114
+ protected readonly step = computed(() => STEP[this.direction()] ?? STEP.diagonal);
115
+ /** `idle` until the first render (so server HTML shows a plain grid), `wait` until in view, then `shown`. */
116
+ protected readonly phase = signal<'idle' | 'wait' | 'shown'>('idle');
117
+ private readonly seen = signal(true);
118
+ /** Reduced motion, or --ui-motion-scale: 0: no drift and no reveal. */
119
+ protected readonly calm = signal(false);
120
+ private readonly visible = signal(true);
121
+ /** On screen in a visible tab: the drift only runs then. */
122
+ protected readonly awake = computed(() => this.seen() && this.visible());
123
+
124
+ private readonly doc = inject(DOCUMENT);
125
+ private readonly win = this.doc.defaultView;
126
+ private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
127
+
128
+ constructor() {
129
+ let io: IntersectionObserver | undefined;
130
+ const onVisibility = () => this.visible.set(this.doc.visibilityState !== 'hidden');
131
+ const motion = this.win?.matchMedia?.('(prefers-reduced-motion: reduce)');
132
+ const onMotion = () => {
133
+ const scale = parseFloat(this.win?.getComputedStyle(this.host).getPropertyValue('--ui-motion-scale') ?? '');
134
+ this.calm.set(!!motion?.matches || scale === 0);
135
+ if (this.calm()) this.phase.set('idle');
136
+ };
137
+ afterNextRender(() => {
138
+ onVisibility();
139
+ this.doc.addEventListener('visibilitychange', onVisibility);
140
+ onMotion();
141
+ motion?.addEventListener?.('change', onMotion);
142
+ const Observer = this.win?.IntersectionObserver;
143
+ if (this.reveal() && !this.calm() && Observer) this.phase.set('wait');
144
+ if (!Observer) return;
145
+ io = new Observer(
146
+ (entries) => {
147
+ const e = entries[entries.length - 1];
148
+ this.seen.set(e.isIntersecting);
149
+ if (this.phase() !== 'wait' || !e.isIntersecting) return;
150
+ const view = e.rootBounds?.height ?? this.win?.innerHeight ?? 0;
151
+ if (e.intersectionRatio >= 0.199 || (view > 0 && e.intersectionRect.height >= 0.2 * view)) this.phase.set('shown');
152
+ },
153
+ { threshold: [0, ...Array.from({ length: 10 }, (_, i) => 0.2 / 2 ** i)] },
154
+ );
155
+ io.observe(this.host);
156
+ });
157
+
158
+ inject(DestroyRef).onDestroy(() => {
159
+ io?.disconnect();
160
+ this.doc.removeEventListener('visibilitychange', onVisibility);
161
+ motion?.removeEventListener?.('change', onMotion);
162
+ });
163
+ }
164
+ }