@adea-ai/ui 0.151.15 → 0.152.1
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/dist/components/composites/accent-picker/accent-picker.d.ts +44 -10
- package/dist/components/composites/accent-picker/accent-picker.d.ts.map +1 -1
- package/dist/components/composites/accent-picker/accent-picker.js +155 -58
- package/dist/components/composites/accent-picker/accent-picker.js.map +1 -1
- package/dist/components/composites/accent-picker/color-math.d.ts +13 -0
- package/dist/components/composites/accent-picker/color-math.d.ts.map +1 -0
- package/dist/components/composites/accent-picker/color-math.js +61 -0
- package/dist/components/composites/accent-picker/color-math.js.map +1 -0
- package/dist/components/composites/accent-picker/custom-color-popover.d.ts +18 -0
- package/dist/components/composites/accent-picker/custom-color-popover.d.ts.map +1 -0
- package/dist/components/composites/accent-picker/custom-color-popover.js +248 -0
- package/dist/components/composites/accent-picker/custom-color-popover.js.map +1 -0
- package/dist/components/composites/accent-picker/index.d.ts +1 -1
- package/dist/components/composites/accent-picker/index.d.ts.map +1 -1
- package/dist/components/composites/accent-picker/index.js +1 -1
- package/dist/components/composites/appearance-editor/appearance-choices.d.ts.map +1 -1
- package/dist/components/composites/appearance-editor/appearance-choices.js +37 -74
- package/dist/components/composites/appearance-editor/appearance-choices.js.map +1 -1
- package/dist/components/composites/icon-picker/icon-picker.js +1 -1
- package/dist/components/composites/icon-picker/icon-picker.js.map +1 -1
- package/dist/components/conversation/scroll-follow.d.ts.map +1 -1
- package/dist/components/conversation/scroll-follow.js +14 -1
- package/dist/components/conversation/scroll-follow.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/r/accent-picker.json +13 -0
- package/dist/r/appearance-editor.json +1 -0
- package/dist/r/registry.json +14 -0
- package/dist/r/src/components/composites/accent-picker/accent-picker.tsx +154 -38
- package/dist/r/src/components/composites/accent-picker/color-math.ts +54 -0
- package/dist/r/src/components/composites/accent-picker/custom-color-popover.tsx +220 -0
- package/dist/r/src/components/composites/accent-picker/index.ts +6 -1
- package/dist/r/src/components/composites/appearance-editor/appearance-choices.tsx +34 -58
- package/dist/r/src/components/composites/icon-picker/icon-picker.tsx +1 -1
- package/dist/r/src/components/conversation/scroll-follow.ts +24 -1
- package/package.json +1 -1
- package/registry.json +14 -0
- package/src/components/composites/accent-picker/accent-picker.tsx +154 -38
- package/src/components/composites/accent-picker/color-math.ts +54 -0
- package/src/components/composites/accent-picker/custom-color-popover.tsx +220 -0
- package/src/components/composites/accent-picker/index.ts +6 -1
- package/src/components/composites/appearance-editor/appearance-choices.tsx +34 -58
- package/src/components/composites/icon-picker/icon-picker.tsx +1 -1
- package/src/components/conversation/scroll-follow.ts +24 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** HSV with hue in degrees [0, 360) and saturation/value in [0, 1]. */
|
|
2
|
+
export type Hsv = Readonly<{ h: number; s: number; v: number }>
|
|
3
|
+
|
|
4
|
+
const clamp = (value: number, min = 0, max = 1) => Math.min(max, Math.max(min, value))
|
|
5
|
+
|
|
6
|
+
/** `#rrggbb` (any case) to HSV; anything else is `undefined`. */
|
|
7
|
+
export function hexToHsv(hex: string): Hsv | undefined {
|
|
8
|
+
const match = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(hex.trim())
|
|
9
|
+
if (!match) return undefined
|
|
10
|
+
const [r, g, b] = match.slice(1).map((part) => Number.parseInt(part, 16) / 255) as [
|
|
11
|
+
number,
|
|
12
|
+
number,
|
|
13
|
+
number,
|
|
14
|
+
]
|
|
15
|
+
const max = Math.max(r, g, b)
|
|
16
|
+
const delta = max - Math.min(r, g, b)
|
|
17
|
+
let h = 0
|
|
18
|
+
if (delta !== 0) {
|
|
19
|
+
if (max === r) h = ((g - b) / delta) % 6
|
|
20
|
+
else if (max === g) h = (b - r) / delta + 2
|
|
21
|
+
else h = (r - g) / delta + 4
|
|
22
|
+
}
|
|
23
|
+
h = (h * 60 + 360) % 360
|
|
24
|
+
return { h, s: max === 0 ? 0 : delta / max, v: max }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** HSV to lowercase `#rrggbb`. */
|
|
28
|
+
export function hsvToHex(hsv: Hsv): `#${string}` {
|
|
29
|
+
const h = ((hsv.h % 360) + 360) % 360
|
|
30
|
+
const s = clamp(hsv.s)
|
|
31
|
+
const v = clamp(hsv.v)
|
|
32
|
+
const c = v * s
|
|
33
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1))
|
|
34
|
+
const m = v - c
|
|
35
|
+
const [r, g, b] =
|
|
36
|
+
h < 60
|
|
37
|
+
? [c, x, 0]
|
|
38
|
+
: h < 120
|
|
39
|
+
? [x, c, 0]
|
|
40
|
+
: h < 180
|
|
41
|
+
? [0, c, x]
|
|
42
|
+
: h < 240
|
|
43
|
+
? [0, x, c]
|
|
44
|
+
: h < 300
|
|
45
|
+
? [x, 0, c]
|
|
46
|
+
: [c, 0, x]
|
|
47
|
+
const part = (channel: number) =>
|
|
48
|
+
Math.round((channel + m) * 255)
|
|
49
|
+
.toString(16)
|
|
50
|
+
.padStart(2, '0')
|
|
51
|
+
return `#${part(r)}${part(g)}${part(b)}`
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { clamp }
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import type { JSX } from 'solid-js'
|
|
2
|
+
import { Show, createSignal } from 'solid-js'
|
|
3
|
+
import { cn } from '../../../lib/utils'
|
|
4
|
+
import { Button } from '../../ui/button'
|
|
5
|
+
import { Input } from '../../ui/input'
|
|
6
|
+
import { Popover, PopoverContent, PopoverTrigger } from '../../ui/popover'
|
|
7
|
+
import { clamp, hexToHsv, hsvToHex, type Hsv } from './color-math'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The Custom entry of the accent picker: a button that opens a colour picker
|
|
11
|
+
* anchored right under it, right edges aligned since Custom ends the row (a
|
|
12
|
+
* saturation/brightness field, a hue strip and a hex field). Nothing is committed while the colour is being explored; Apply (or
|
|
13
|
+
* Enter in the hex field) commits it and closes, Escape or a click outside
|
|
14
|
+
* leaves the stored colour alone. The operating system's colour panel is not
|
|
15
|
+
* used because on macOS it floats wherever it was last left, not by the button.
|
|
16
|
+
*/
|
|
17
|
+
export function CustomColorPopover(props: {
|
|
18
|
+
/** The stored custom colour, or `undefined` while a preset or inherit is chosen. */
|
|
19
|
+
value: string | undefined
|
|
20
|
+
/** Where the picker starts while no custom colour is stored. */
|
|
21
|
+
seed: string
|
|
22
|
+
disabled?: boolean
|
|
23
|
+
onCommit(value: `#${string}`): void
|
|
24
|
+
}) {
|
|
25
|
+
const [open, setOpen] = createSignal(false)
|
|
26
|
+
const [draft, setDraft] = createSignal<Hsv>({ h: 0, s: 0, v: 0 })
|
|
27
|
+
const [hexText, setHexText] = createSignal('')
|
|
28
|
+
const draftHex = () => hsvToHex(draft())
|
|
29
|
+
// The hex field is what Apply commits, so text that is not a colour yet blocks it.
|
|
30
|
+
const typedHex = () => {
|
|
31
|
+
const text = hexText().trim()
|
|
32
|
+
return hexToHsv(text.startsWith('#') ? text : `#${text}`)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const start = () => {
|
|
36
|
+
const initial = hexToHsv(props.value ?? props.seed) ?? { h: 262, s: 0.8, v: 0.9 }
|
|
37
|
+
setDraft(initial)
|
|
38
|
+
setHexText(hsvToHex(initial))
|
|
39
|
+
}
|
|
40
|
+
const update = (next: Hsv) => {
|
|
41
|
+
setDraft(next)
|
|
42
|
+
setHexText(hsvToHex(next))
|
|
43
|
+
}
|
|
44
|
+
const commit = () => {
|
|
45
|
+
if (!typedHex()) return
|
|
46
|
+
props.onCommit(draftHex())
|
|
47
|
+
setOpen(false)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Popover
|
|
52
|
+
open={open()}
|
|
53
|
+
onOpenChange={(next) => {
|
|
54
|
+
if (next) start()
|
|
55
|
+
setOpen(next)
|
|
56
|
+
}}
|
|
57
|
+
placement="bottom-end"
|
|
58
|
+
>
|
|
59
|
+
<PopoverTrigger
|
|
60
|
+
as={Button}
|
|
61
|
+
type="button"
|
|
62
|
+
variant={props.value ? 'secondary' : 'outline'}
|
|
63
|
+
size="sm"
|
|
64
|
+
data-slot="swatch-custom"
|
|
65
|
+
disabled={props.disabled}
|
|
66
|
+
aria-pressed={props.value !== undefined}
|
|
67
|
+
class="shrink-0 gap-1.5"
|
|
68
|
+
>
|
|
69
|
+
<Show when={props.value}>
|
|
70
|
+
{(color) => (
|
|
71
|
+
<span
|
|
72
|
+
aria-hidden="true"
|
|
73
|
+
data-slot="swatch-custom-chip"
|
|
74
|
+
class="size-3 rounded-full border border-border bg-(--swatch-custom)"
|
|
75
|
+
style={{ '--swatch-custom': color() }}
|
|
76
|
+
/>
|
|
77
|
+
)}
|
|
78
|
+
</Show>
|
|
79
|
+
Custom
|
|
80
|
+
</PopoverTrigger>
|
|
81
|
+
<PopoverContent class="w-60" aria-label="Custom colour">
|
|
82
|
+
<div class="flex flex-col gap-3" data-slot="custom-color">
|
|
83
|
+
<DragArea
|
|
84
|
+
label="Saturation and brightness"
|
|
85
|
+
value={Math.round(draft().s * 100)}
|
|
86
|
+
max={100}
|
|
87
|
+
valueText={`Saturation ${Math.round(draft().s * 100)}%, brightness ${Math.round(draft().v * 100)}%`}
|
|
88
|
+
class="h-36 rounded-md"
|
|
89
|
+
style={{
|
|
90
|
+
'background-image': `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, hsl(${draft().h} 100% 50%))`,
|
|
91
|
+
}}
|
|
92
|
+
thumb={{ x: draft().s, y: 1 - draft().v }}
|
|
93
|
+
onPoint={(x, y) => update({ ...draft(), s: x, v: 1 - y })}
|
|
94
|
+
onStep={(dx, dy) =>
|
|
95
|
+
update({ ...draft(), s: clamp(draft().s + dx), v: clamp(draft().v - dy) })
|
|
96
|
+
}
|
|
97
|
+
/>
|
|
98
|
+
<DragArea
|
|
99
|
+
label="Hue"
|
|
100
|
+
value={Math.round(draft().h)}
|
|
101
|
+
max={360}
|
|
102
|
+
valueText={`${Math.round(draft().h)} degrees`}
|
|
103
|
+
class="h-3 rounded-full"
|
|
104
|
+
style={{
|
|
105
|
+
'background-image':
|
|
106
|
+
'linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00)',
|
|
107
|
+
}}
|
|
108
|
+
thumb={{ x: draft().h / 360, y: 0.5 }}
|
|
109
|
+
onPoint={(x) => update({ ...draft(), h: Math.min(359.99, x * 360) })}
|
|
110
|
+
onStep={(dx) =>
|
|
111
|
+
update({ ...draft(), h: Math.min(359.99, Math.max(0, draft().h + dx * 360)) })
|
|
112
|
+
}
|
|
113
|
+
/>
|
|
114
|
+
<div class="flex items-center gap-2">
|
|
115
|
+
<span
|
|
116
|
+
aria-hidden="true"
|
|
117
|
+
class="size-8 shrink-0 rounded-md border border-border bg-(--swatch-draft)"
|
|
118
|
+
style={{ '--swatch-draft': draftHex() }}
|
|
119
|
+
/>
|
|
120
|
+
<Input
|
|
121
|
+
aria-label="Hex colour"
|
|
122
|
+
class="min-w-0 flex-1 font-mono"
|
|
123
|
+
value={hexText()}
|
|
124
|
+
maxLength={7}
|
|
125
|
+
spellcheck={false}
|
|
126
|
+
aria-invalid={typedHex() ? undefined : true}
|
|
127
|
+
onInput={(event) => {
|
|
128
|
+
const text = event.currentTarget.value.trim()
|
|
129
|
+
setHexText(text)
|
|
130
|
+
const parsed = typedHex()
|
|
131
|
+
if (parsed) setDraft(parsed)
|
|
132
|
+
}}
|
|
133
|
+
onKeyDown={(event) => {
|
|
134
|
+
if (event.key === 'Enter') {
|
|
135
|
+
event.preventDefault()
|
|
136
|
+
commit()
|
|
137
|
+
}
|
|
138
|
+
}}
|
|
139
|
+
/>
|
|
140
|
+
<Button type="button" size="sm" disabled={!typedHex()} onClick={commit}>
|
|
141
|
+
Apply
|
|
142
|
+
</Button>
|
|
143
|
+
</div>
|
|
144
|
+
</div>
|
|
145
|
+
</PopoverContent>
|
|
146
|
+
</Popover>
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* A pointer- and keyboard-driven area reporting a position in [0, 1] on each
|
|
152
|
+
* axis: the saturation/brightness field and the hue strip. Its listeners are
|
|
153
|
+
* native (`on:`) rather than delegated, so this module registers nothing on
|
|
154
|
+
* `window.document` when it loads.
|
|
155
|
+
*/
|
|
156
|
+
function DragArea(props: {
|
|
157
|
+
label: string
|
|
158
|
+
/** The value assistive technology reads, from 0 to `max`; the 2D field reports saturation and names both axes in `valueText`. */
|
|
159
|
+
value: number
|
|
160
|
+
max: number
|
|
161
|
+
valueText: string
|
|
162
|
+
class: string
|
|
163
|
+
style: JSX.CSSProperties
|
|
164
|
+
thumb: { x: number; y: number }
|
|
165
|
+
onPoint(x: number, y: number): void
|
|
166
|
+
onStep(dx: number, dy: number): void
|
|
167
|
+
}) {
|
|
168
|
+
const point = (event: PointerEvent) => {
|
|
169
|
+
const rect = (event.currentTarget as HTMLElement).getBoundingClientRect()
|
|
170
|
+
if (rect.width === 0 || rect.height === 0) return
|
|
171
|
+
props.onPoint(
|
|
172
|
+
clamp((event.clientX - rect.left) / rect.width),
|
|
173
|
+
clamp((event.clientY - rect.top) / rect.height)
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
return (
|
|
177
|
+
<div
|
|
178
|
+
role="slider"
|
|
179
|
+
tabIndex={0}
|
|
180
|
+
aria-label={props.label}
|
|
181
|
+
aria-valuemin={0}
|
|
182
|
+
aria-valuemax={props.max}
|
|
183
|
+
aria-valuenow={props.value}
|
|
184
|
+
aria-valuetext={props.valueText}
|
|
185
|
+
data-slot="custom-color-area"
|
|
186
|
+
class={cn(
|
|
187
|
+
'relative w-full cursor-crosshair touch-none border border-border outline-none',
|
|
188
|
+
'focus-visible:ring-3 focus-visible:ring-primary-subtle',
|
|
189
|
+
props.class
|
|
190
|
+
)}
|
|
191
|
+
style={props.style}
|
|
192
|
+
on:pointerdown={(event) => {
|
|
193
|
+
event.currentTarget.setPointerCapture?.(event.pointerId)
|
|
194
|
+
point(event)
|
|
195
|
+
}}
|
|
196
|
+
on:pointermove={(event) => {
|
|
197
|
+
if (event.buttons & 1) point(event)
|
|
198
|
+
}}
|
|
199
|
+
on:keydown={(event) => {
|
|
200
|
+
const step = event.shiftKey ? 0.1 : 0.02
|
|
201
|
+
const moves: Record<string, [number, number]> = {
|
|
202
|
+
ArrowLeft: [-step, 0],
|
|
203
|
+
ArrowRight: [step, 0],
|
|
204
|
+
ArrowUp: [0, -step],
|
|
205
|
+
ArrowDown: [0, step],
|
|
206
|
+
}
|
|
207
|
+
const move = moves[event.key]
|
|
208
|
+
if (!move) return
|
|
209
|
+
event.preventDefault()
|
|
210
|
+
props.onStep(move[0], move[1])
|
|
211
|
+
}}
|
|
212
|
+
>
|
|
213
|
+
<span
|
|
214
|
+
aria-hidden="true"
|
|
215
|
+
class="pointer-events-none absolute size-3.5 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-background shadow-sm ring-1 ring-border"
|
|
216
|
+
style={{ left: `${props.thumb.x * 100}%`, top: `${props.thumb.y * 100}%` }}
|
|
217
|
+
/>
|
|
218
|
+
</div>
|
|
219
|
+
)
|
|
220
|
+
}
|
|
@@ -28,8 +28,7 @@ import { Monitor, Moon, Sun } from 'lucide-solid'
|
|
|
28
28
|
import { For, Show } from 'solid-js'
|
|
29
29
|
import { isThemeAccentId } from '../../../lib/theme-accents'
|
|
30
30
|
import { THEME_DEFAULT_ID } from '../../../lib/theme-defaults'
|
|
31
|
-
import {
|
|
32
|
-
import { Input } from '../../ui/input'
|
|
31
|
+
import { AccentPicker, isCustomAccentValue } from '../accent-picker'
|
|
33
32
|
import { AccentSwatchGroups } from './accent-swatch-groups'
|
|
34
33
|
import type { AppearanceEditorProps } from './appearance-types'
|
|
35
34
|
import { ThemeMiniature, ThemeMiniatureSplit } from './theme-preview'
|
|
@@ -135,15 +134,24 @@ export function AccentChoices(props: AppearanceEditorProps) {
|
|
|
135
134
|
? [{ id: THEME_DEFAULT_ID, label: 'Theme default' }, ...presets]
|
|
136
135
|
: presets
|
|
137
136
|
}
|
|
138
|
-
// The `row` style
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
137
|
+
// The `row` style is the shared AccentPicker every accent setting uses: the
|
|
138
|
+
// swatches, then a Custom button that opens the native colour selector, so the
|
|
139
|
+
// draft only changes once a colour is chosen there. The app has nothing to
|
|
140
|
+
// inherit from, so there is no inherit swatch; "Theme default" leads when the
|
|
141
|
+
// host keeps it.
|
|
142
|
+
const rowOptions = () => {
|
|
143
|
+
const presets = props.accentOptions.filter((option) => option.id !== THEME_DEFAULT_ID)
|
|
144
|
+
return showThemeDefault()
|
|
145
|
+
? [
|
|
146
|
+
{
|
|
147
|
+
id: THEME_DEFAULT_ID,
|
|
148
|
+
label: 'Theme default',
|
|
149
|
+
light: themeDefaultColor(),
|
|
150
|
+
dark: themeDefaultColor(),
|
|
151
|
+
},
|
|
152
|
+
...presets,
|
|
153
|
+
]
|
|
154
|
+
: presets
|
|
147
155
|
}
|
|
148
156
|
return (
|
|
149
157
|
<Show
|
|
@@ -209,53 +217,21 @@ export function AccentChoices(props: AppearanceEditorProps) {
|
|
|
209
217
|
</Radio>
|
|
210
218
|
}
|
|
211
219
|
>
|
|
212
|
-
<
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
/>
|
|
228
|
-
</Radio>
|
|
229
|
-
<Button
|
|
230
|
-
type="button"
|
|
231
|
-
variant="outline"
|
|
232
|
-
size="sm"
|
|
233
|
-
tabIndex={0}
|
|
234
|
-
disabled={props.saving}
|
|
235
|
-
aria-pressed={isCustomAccent(props)}
|
|
236
|
-
onClick={openCustomColor}
|
|
237
|
-
>
|
|
238
|
-
Custom
|
|
239
|
-
</Button>
|
|
240
|
-
<Input
|
|
241
|
-
ref={(element) => {
|
|
242
|
-
colorPicker = element
|
|
243
|
-
}}
|
|
244
|
-
type="color"
|
|
245
|
-
// `w-px` beats the Input's own `w-full`: an absolutely positioned
|
|
246
|
-
// full-width input sized the sheet's scroll width.
|
|
247
|
-
class="sr-only w-px"
|
|
248
|
-
tabIndex={-1}
|
|
249
|
-
aria-label="Custom accent color"
|
|
250
|
-
value={
|
|
251
|
-
/^#[0-9a-f]{6}$/i.test(props.draft.accent)
|
|
252
|
-
? props.draft.accent
|
|
253
|
-
: (props.customAccentValue ?? '#000000')
|
|
254
|
-
}
|
|
255
|
-
disabled={props.saving}
|
|
256
|
-
onChange={(event) => props.onChange({ accent: event.currentTarget.value })}
|
|
257
|
-
/>
|
|
258
|
-
</div>
|
|
220
|
+
<AccentPicker
|
|
221
|
+
label="Accent"
|
|
222
|
+
inherit={false}
|
|
223
|
+
options={rowOptions()}
|
|
224
|
+
layout="row"
|
|
225
|
+
appearance={resolvedAppearance()}
|
|
226
|
+
value={props.draft.accent}
|
|
227
|
+
customSeed={
|
|
228
|
+
isCustomAccentValue(props.customAccentValue) ? props.customAccentValue : '#000000'
|
|
229
|
+
}
|
|
230
|
+
disabled={props.saving}
|
|
231
|
+
onValueChange={(accent) => {
|
|
232
|
+
if (accent !== null) props.onChange({ accent })
|
|
233
|
+
}}
|
|
234
|
+
/>
|
|
259
235
|
</Show>
|
|
260
236
|
)
|
|
261
237
|
}
|
|
@@ -231,7 +231,7 @@ export function IconPickerDropdown(props: IconPickerDropdownProps) {
|
|
|
231
231
|
</span>
|
|
232
232
|
<ChevronDown class="size-4 text-muted-foreground" aria-hidden="true" />
|
|
233
233
|
</PopoverTrigger>
|
|
234
|
-
<PopoverContent class="w-
|
|
234
|
+
<PopoverContent class="w-88 max-w-(--kb-popper-content-available-width)">
|
|
235
235
|
<IconPicker
|
|
236
236
|
{...picker}
|
|
237
237
|
onValueChange={(key) => {
|
|
@@ -55,6 +55,9 @@ export function createScrollFollow(options: {
|
|
|
55
55
|
let readerMovedSinceWrite = false
|
|
56
56
|
let previousTop = -1
|
|
57
57
|
let lastScrollClientHeight = 0
|
|
58
|
+
// The content's last row when the offset was last taken as the reader's own. Rows added
|
|
59
|
+
// after it are what an append put in since.
|
|
60
|
+
let endRow: Element | null = null
|
|
58
61
|
let pendingRestore: { frame: number; fromTop: number; target: number } | undefined
|
|
59
62
|
let pendingRestoreUserIntent = false
|
|
60
63
|
// A hold is the caller saying it is positioning the view (see `hold`): while one is
|
|
@@ -89,6 +92,7 @@ export function createScrollFollow(options: {
|
|
|
89
92
|
onCleanup(reportPosition)
|
|
90
93
|
|
|
91
94
|
const rememberPosition = (element: HTMLDivElement) => {
|
|
95
|
+
endRow = content?.lastElementChild ?? null
|
|
92
96
|
lastWriteTop = element.scrollTop
|
|
93
97
|
lastWriteClientHeight = element.clientHeight
|
|
94
98
|
previousTop = element.scrollTop
|
|
@@ -112,6 +116,14 @@ export function createScrollFollow(options: {
|
|
|
112
116
|
)
|
|
113
117
|
rememberPosition(element)
|
|
114
118
|
}
|
|
119
|
+
// How much the rows appended after `endRow` add to the content's height, or 0 when the
|
|
120
|
+
// content changed in any other way. A tail append never moves the offset, so taking it
|
|
121
|
+
// off the height gives the end the reader had before it.
|
|
122
|
+
const appendedHeight = () => {
|
|
123
|
+
const last = content?.lastElementChild
|
|
124
|
+
if (!last || !endRow || last === endRow || endRow.parentElement !== content) return 0
|
|
125
|
+
return Math.max(0, last.getBoundingClientRect().bottom - endRow.getBoundingClientRect().bottom)
|
|
126
|
+
}
|
|
115
127
|
const pinHeld = (element: HTMLDivElement) => {
|
|
116
128
|
const geom = geometry(element)
|
|
117
129
|
stick = true
|
|
@@ -304,7 +316,18 @@ export function createScrollFollow(options: {
|
|
|
304
316
|
// layout, but deferring it loses a collapse clamp before a later task
|
|
305
317
|
// grows the viewport/output. Ordinary growth needs no other geometry.
|
|
306
318
|
if (scroller.scrollTop >= lastWriteTop - SELF_SCROLL_EPSILON) return
|
|
307
|
-
|
|
319
|
+
const geom = geometry(scroller)
|
|
320
|
+
if (isAtEnd(geom)) return rememberPosition(scroller)
|
|
321
|
+
// Rows that size themselves late can shrink the content, and a layout read
|
|
322
|
+
// anywhere clamps the offset at once, while the scroll event and resize
|
|
323
|
+
// callback that report it wait for the next frame. A turn appended before
|
|
324
|
+
// that frame (WebKit paints late under load) leaves the offset at the end the
|
|
325
|
+
// content had without the new turn, which those callbacks would then measure
|
|
326
|
+
// against the grown content and take for the reader scrolling up. An offset
|
|
327
|
+
// exactly at that earlier end is the clamp; a reveal lands anywhere else.
|
|
328
|
+
const grown = appendedHeight()
|
|
329
|
+
if (grown > 0 && isAtEnd({ ...geom, scrollHeight: geom.scrollHeight - grown }))
|
|
330
|
+
rememberPosition(scroller)
|
|
308
331
|
})
|
|
309
332
|
contentObserver.observe(content, { childList: true, characterData: true, subtree: true })
|
|
310
333
|
}
|
package/package.json
CHANGED
package/registry.json
CHANGED
|
@@ -2248,6 +2248,9 @@
|
|
|
2248
2248
|
"@kobalte/core@^0.13.14"
|
|
2249
2249
|
],
|
|
2250
2250
|
"registryDependencies": [
|
|
2251
|
+
"@adea-ai/ui/button",
|
|
2252
|
+
"@adea-ai/ui/input",
|
|
2253
|
+
"@adea-ai/ui/popover",
|
|
2251
2254
|
"@adea-ai/ui/tooltip",
|
|
2252
2255
|
"lib"
|
|
2253
2256
|
],
|
|
@@ -2257,6 +2260,16 @@
|
|
|
2257
2260
|
"type": "registry:ui",
|
|
2258
2261
|
"target": "components/composites/accent-picker/accent-picker.tsx"
|
|
2259
2262
|
},
|
|
2263
|
+
{
|
|
2264
|
+
"path": "src/components/composites/accent-picker/color-math.ts",
|
|
2265
|
+
"type": "registry:ui",
|
|
2266
|
+
"target": "components/composites/accent-picker/color-math.ts"
|
|
2267
|
+
},
|
|
2268
|
+
{
|
|
2269
|
+
"path": "src/components/composites/accent-picker/custom-color-popover.tsx",
|
|
2270
|
+
"type": "registry:ui",
|
|
2271
|
+
"target": "components/composites/accent-picker/custom-color-popover.tsx"
|
|
2272
|
+
},
|
|
2260
2273
|
{
|
|
2261
2274
|
"path": "src/components/composites/accent-picker/index.ts",
|
|
2262
2275
|
"type": "registry:ui",
|
|
@@ -2328,6 +2341,7 @@
|
|
|
2328
2341
|
"lucide-solid@^1.65.0"
|
|
2329
2342
|
],
|
|
2330
2343
|
"registryDependencies": [
|
|
2344
|
+
"@adea-ai/ui/accent-picker",
|
|
2331
2345
|
"@adea-ai/ui/action-button",
|
|
2332
2346
|
"@adea-ai/ui/button",
|
|
2333
2347
|
"@adea-ai/ui/dropdown-menu",
|