@kolkrabbi/kol-component 0.328.0 → 0.330.0
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/package.json +4 -4
- package/src/atoms/BezierPathEditor.jsx +171 -0
- package/src/atoms/FunctionPlot.jsx +109 -0
- package/src/atoms/OriginPicker.jsx +111 -0
- package/src/index.js +6 -0
- package/src/molecules/Combobox.jsx +5 -5
- package/src/molecules/ContextMenu.jsx +9 -39
- package/src/molecules/Dropdown.jsx +49 -72
- package/src/molecules/Menu.jsx +77 -38
- package/src/molecules/MenuItem.jsx +51 -53
- package/src/molecules/MultiSelect.jsx +44 -41
- package/src/molecules/ParamBindDot.jsx +79 -0
- package/src/molecules/ShapeDropdown.jsx +5 -5
- package/src/molecules/SplitToolButton.jsx +3 -2
- package/src/molecules/StepList.jsx +34 -8
- package/src/organisms/AppItemMenuProvider.jsx +4 -4
- package/src/organisms/ColorPickerPopover.jsx +7 -1
- package/src/organisms/LayerStack.jsx +7 -7
- package/src/organisms/MediaLibrary.jsx +4 -4
- package/src/organisms/MediaLibraryPages.jsx +46 -46
- package/src/organisms/NavRail.jsx +1 -1
- package/src/organisms/SettingsPanel.jsx +3 -6
- package/src/utilities/tone.js +4 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolkrabbi/kol-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.330.0",
|
|
4
4
|
"description": "The core component library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"embla-carousel-react": "^8.6.0",
|
|
27
27
|
"pdfjs-dist": "^6.3.289",
|
|
28
28
|
"react-syntax-highlighter": "^16.1.1",
|
|
29
|
-
"@kolkrabbi/kol-
|
|
29
|
+
"@kolkrabbi/kol-search": "^0.3.0",
|
|
30
30
|
"@kolkrabbi/kol-markdown": "^0.2.0",
|
|
31
|
-
"@kolkrabbi/kol-
|
|
31
|
+
"@kolkrabbi/kol-growth": "^0.4.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@kolkrabbi/kol-icons": ">=0.22.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"react-dom": "^18.3.0 || ^19.0.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@kolkrabbi/kol-icons": "^0.
|
|
42
|
+
"@kolkrabbi/kol-icons": "^0.57.0"
|
|
43
43
|
},
|
|
44
44
|
"files": [
|
|
45
45
|
"src",
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
import { pathD, nearestSegmentT, splitSegment } from '../hooks/pathMath.js'
|
|
3
|
+
|
|
4
|
+
/* anchor · handle radius (px) per control rung; the hit target rides a wider transparent ring */
|
|
5
|
+
const RADII = { xs: [3.5, 2.5], sm: [4.5, 3], md: [5.5, 3.5] }
|
|
6
|
+
const HIT = 6
|
|
7
|
+
|
|
8
|
+
const clamp01 = (v) => Math.min(1, Math.max(0, v))
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* BezierPathEditor — Shape a path by dragging its nodes. a 2D bezier node editor: anchors with in / out
|
|
12
|
+
* handles, drawn in a box of any aspect, holding a value of normalised points.
|
|
13
|
+
*
|
|
14
|
+
* Lobby BezierPathEditor (kol-fxr, 2026-10-31): fxr hand-built two SVG editors for one job — the organic
|
|
15
|
+
* band's edge profile (`ProfileEditor`) and a kinetic layer's custom path (`CustomPathPoints`). KOL's
|
|
16
|
+
* `CurveEditor` authors expressions, not a drawn path, and `PathNodeOverlay` is stage chrome on the
|
|
17
|
+
* 1080-virtual canvas; this is the field-sized control. The geometry is `pathMath`'s (`pathD`,
|
|
18
|
+
* `nearestSegmentT`, `splitSegment`), so the path it draws is the one the editor's engine draws.
|
|
19
|
+
*
|
|
20
|
+
* VALUE. `[{ x, y, hl?, hr? }]`, x and y in 0–1 (0 = left / top). `hl` / `hr` are the in / out handles as
|
|
21
|
+
* OFFSETS from the anchor (`{ x, y }`, same units), so moving an anchor carries its handles; a node without
|
|
22
|
+
* one is a corner on that side. Controlled: every gesture fires `onChange(points)` with a new array, and a
|
|
23
|
+
* consumer with rules (ends locked, endpoints sharing y) enforces them there.
|
|
24
|
+
*
|
|
25
|
+
* GESTURES. Drag an anchor or a handle · double-click the box to add a node (split into the nearest
|
|
26
|
+
* segment, shape-preserving) · alt-click an anchor to delete it (never below `minPoints`). Anchors are
|
|
27
|
+
* clamped to the box; handles may leave it.
|
|
28
|
+
*
|
|
29
|
+
* INKS (the icon ink law — oq, never fg): the box is the control ground (surface-secondary), the path
|
|
30
|
+
* oq-80, leashes oq-24, handles oq-48, anchors the accent. No border.
|
|
31
|
+
*
|
|
32
|
+
* <BezierPathEditor value={pts} onChange={setPts} aspect={2} closed={false} size="sm" />
|
|
33
|
+
*
|
|
34
|
+
* @param {Array<{x:number, y:number, hl?:{x:number,y:number}, hr?:{x:number,y:number}}>} value - The nodes, normalised 0–1; handles are offsets from the anchor
|
|
35
|
+
* @param {(points:Array) => void} onChange - Fired with the next node array on every drag move, add and delete
|
|
36
|
+
* @param {boolean} [closed=false] - Close the path (last node joins the first)
|
|
37
|
+
* @param {number} [aspect=1] - The box's width ÷ height; it fills its container's width
|
|
38
|
+
* @param {'xs'|'sm'|'md'} [size='sm'] - The control rung — the anchor and handle sizes
|
|
39
|
+
* @param {number} [minPoints=2] - Alt-click never deletes below this many nodes
|
|
40
|
+
* @param {string} [ariaLabel='Path editor'] - The box's accessible name
|
|
41
|
+
* @param {string} [className] - Extra classes on the box
|
|
42
|
+
*/
|
|
43
|
+
export default function BezierPathEditor({
|
|
44
|
+
value = [],
|
|
45
|
+
onChange,
|
|
46
|
+
closed = false,
|
|
47
|
+
aspect = 1,
|
|
48
|
+
size = 'sm',
|
|
49
|
+
minPoints = 2,
|
|
50
|
+
ariaLabel = 'Path editor',
|
|
51
|
+
className = '',
|
|
52
|
+
}) {
|
|
53
|
+
const ref = useRef(null)
|
|
54
|
+
const drag = useRef(null) /* { i, part: 'anchor'|'hl'|'hr' } */
|
|
55
|
+
const [box, setBox] = useState({ w: 0, h: 0 })
|
|
56
|
+
const [rA, rH] = RADII[size] ?? RADII.sm
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
const el = ref.current
|
|
60
|
+
if (!el) return
|
|
61
|
+
const ro = new ResizeObserver(([e]) => setBox({ w: e.contentRect.width, h: e.contentRect.height }))
|
|
62
|
+
ro.observe(el)
|
|
63
|
+
return () => ro.disconnect()
|
|
64
|
+
}, [])
|
|
65
|
+
|
|
66
|
+
/* the 0–1 square is inset by an anchor's reach, so a node on an edge draws whole */
|
|
67
|
+
const pad = rA + 2
|
|
68
|
+
const w = Math.max(1, box.w - pad * 2), h = Math.max(1, box.h - pad * 2)
|
|
69
|
+
const pts = Array.isArray(value) ? value : []
|
|
70
|
+
/* normalised value → pathMath's absolute pixel nodes ({ x, y, in, out }) */
|
|
71
|
+
const abs = pts.map((p) => ({
|
|
72
|
+
x: pad + p.x * w, y: pad + p.y * h,
|
|
73
|
+
in: p.hl ? { x: pad + (p.x + p.hl.x) * w, y: pad + (p.y + p.hl.y) * h } : null,
|
|
74
|
+
out: p.hr ? { x: pad + (p.x + p.hr.x) * w, y: pad + (p.y + p.hr.y) * h } : null,
|
|
75
|
+
}))
|
|
76
|
+
const fromAbs = (n) => {
|
|
77
|
+
const p = { x: clamp01((n.x - pad) / w), y: clamp01((n.y - pad) / h) }
|
|
78
|
+
if (n.in) p.hl = { x: (n.in.x - pad) / w - p.x, y: (n.in.y - pad) / h - p.y }
|
|
79
|
+
if (n.out) p.hr = { x: (n.out.x - pad) / w - p.x, y: (n.out.y - pad) / h - p.y }
|
|
80
|
+
return p
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const local = (e) => {
|
|
84
|
+
const r = ref.current.getBoundingClientRect()
|
|
85
|
+
return { x: (e.clientX - r.left - pad) / w, y: (e.clientY - r.top - pad) / h }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const onDown = (i, part) => (e) => {
|
|
89
|
+
e.stopPropagation()
|
|
90
|
+
if (part === 'anchor' && e.altKey) {
|
|
91
|
+
if (pts.length > minPoints) onChange?.(pts.filter((_, k) => k !== i))
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
e.preventDefault()
|
|
95
|
+
drag.current = { i, part }
|
|
96
|
+
try { ref.current.setPointerCapture(e.pointerId) } catch { /* */ }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const onMove = (e) => {
|
|
100
|
+
const d = drag.current
|
|
101
|
+
if (!d) return
|
|
102
|
+
const { x, y } = local(e)
|
|
103
|
+
onChange?.(pts.map((p, k) => {
|
|
104
|
+
if (k !== d.i) return p
|
|
105
|
+
if (d.part === 'anchor') return { ...p, x: clamp01(x), y: clamp01(y) }
|
|
106
|
+
return { ...p, [d.part]: { x: x - p.x, y: y - p.y } }
|
|
107
|
+
}))
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const onUp = (e) => {
|
|
111
|
+
drag.current = null
|
|
112
|
+
try { ref.current.releasePointerCapture(e.pointerId) } catch { /* */ }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const onDoubleClick = (e) => {
|
|
116
|
+
if (e.target.closest('[data-node]')) return
|
|
117
|
+
const { x, y } = local(e)
|
|
118
|
+
const px = pad + x * w, py = pad + y * h
|
|
119
|
+
if (abs.length < 2) {
|
|
120
|
+
onChange?.([...pts, { x: clamp01(x), y: clamp01(y) }])
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
const segs = abs.length - 1 + (closed ? 1 : 0)
|
|
124
|
+
let best = { i: 0, t: 0.5, dist: Infinity }
|
|
125
|
+
for (let i = 0; i < segs; i++) {
|
|
126
|
+
const hit = nearestSegmentT(abs[i], abs[(i + 1) % abs.length], px, py)
|
|
127
|
+
if (hit.dist < best.dist) best = { i, ...hit }
|
|
128
|
+
}
|
|
129
|
+
const j = (best.i + 1) % abs.length
|
|
130
|
+
const sp = splitSegment(abs[best.i], abs[j], best.t)
|
|
131
|
+
const next = pts.slice()
|
|
132
|
+
next[best.i] = fromAbs(sp.a)
|
|
133
|
+
next[j] = fromAbs(sp.b)
|
|
134
|
+
next.splice(best.i + 1, 0, fromAbs(sp.mid))
|
|
135
|
+
onChange?.(next)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return (
|
|
139
|
+
<div
|
|
140
|
+
ref={ref}
|
|
141
|
+
role="group"
|
|
142
|
+
aria-label={ariaLabel}
|
|
143
|
+
className={`kol-bezier-path-editor relative w-full overflow-hidden touch-none select-none rounded-[var(--kol-radius-sm)] bg-[var(--kol-tone-bg,var(--kol-surface-secondary))] ${className}`.trim()}
|
|
144
|
+
style={{ aspectRatio: String(aspect) }}
|
|
145
|
+
onPointerMove={onMove}
|
|
146
|
+
onPointerUp={onUp}
|
|
147
|
+
onPointerCancel={onUp}
|
|
148
|
+
onDoubleClick={onDoubleClick}
|
|
149
|
+
>
|
|
150
|
+
{box.w > 0 && (
|
|
151
|
+
<svg className="absolute inset-0 overflow-visible" width={box.w} height={box.h} viewBox={`0 0 ${box.w} ${box.h}`}>
|
|
152
|
+
<path d={pathD(abs, closed)} fill="none" stroke="var(--kol-oq-80)" strokeWidth="1.5" />
|
|
153
|
+
{abs.map((n, i) => (
|
|
154
|
+
<g key={i} data-node="">
|
|
155
|
+
{['in', 'out'].map((side) => n[side] && (
|
|
156
|
+
<g key={side}>
|
|
157
|
+
<line x1={n.x} y1={n.y} x2={n[side].x} y2={n[side].y} stroke="var(--kol-oq-24)" strokeWidth="1" />
|
|
158
|
+
<circle cx={n[side].x} cy={n[side].y} r={rH + HIT} fill="transparent" className="cursor-grab"
|
|
159
|
+
onPointerDown={onDown(i, side === 'in' ? 'hl' : 'hr')} />
|
|
160
|
+
<circle cx={n[side].x} cy={n[side].y} r={rH} fill="var(--kol-oq-48)" pointerEvents="none" />
|
|
161
|
+
</g>
|
|
162
|
+
))}
|
|
163
|
+
<circle cx={n.x} cy={n.y} r={rA + HIT} fill="transparent" className="cursor-grab" onPointerDown={onDown(i, 'anchor')} />
|
|
164
|
+
<circle cx={n.x} cy={n.y} r={rA} fill="var(--kol-accent-primary)" pointerEvents="none" />
|
|
165
|
+
</g>
|
|
166
|
+
))}
|
|
167
|
+
</svg>
|
|
168
|
+
)}
|
|
169
|
+
</div>
|
|
170
|
+
)
|
|
171
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
const PAD = 6
|
|
4
|
+
const fmt = (v) => (Math.abs(v) >= 100 ? v.toFixed(0) : v.toFixed(2))
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* FunctionPlot — Plot y = f(u) over one loop. a read-only plot of a function over u ∈ 0–1 with a cursor at
|
|
8
|
+
* the current u: the curve faint ahead of the cursor, solid behind it, a dot on the current value.
|
|
9
|
+
*
|
|
10
|
+
* Lobby FunctionPlot (kol-fxr, 2026-10-31): fxr's `params/ModulationEditor.jsx` drew its `ExprPlot` on a
|
|
11
|
+
* hand-built `<canvas>` with hard-coded colours. This is it in SVG on the KOL inks, so it follows light and
|
|
12
|
+
* dark with no colour reads. It samples one point per pixel of its width; it fills its container's width.
|
|
13
|
+
*
|
|
14
|
+
* DATA. `fn(u) → number` (sampled across u = 0…1), or `samples` (evenly spaced over u, used as given).
|
|
15
|
+
* The range is `min` / `max`, or the samples' own extent when unset (a flat line gets ±0.5).
|
|
16
|
+
* A live plot (audio, noise) is the caller re-rendering with a new `fn` or `cursor`.
|
|
17
|
+
*
|
|
18
|
+
* INKS (the icon ink law — oq, never fg): ground oq-04, the zero line oq-24 (drawn only when 0 is in range),
|
|
19
|
+
* the extent labels oq-48, the curve, cursor and dot in the accent.
|
|
20
|
+
*
|
|
21
|
+
* <FunctionPlot fn={(u) => Math.sin(u * Math.PI * 2)} cursor={phase} height={64} />
|
|
22
|
+
*
|
|
23
|
+
* @param {(u:number) => number} [fn] - The function to plot over u ∈ 0–1 (ignored when `samples` is given)
|
|
24
|
+
* @param {number[]} [samples] - Precomputed values, evenly spaced over u = 0…1
|
|
25
|
+
* @param {number} [min] - Bottom of the range (default: the lowest sample)
|
|
26
|
+
* @param {number} [max] - Top of the range (default: the highest sample)
|
|
27
|
+
* @param {number} [cursor] - The current u, 0–1 — draws the cursor line and dot; omit for none
|
|
28
|
+
* @param {number} [height=64] - The plot's height in px
|
|
29
|
+
* @param {boolean} [labels=true] - Show the range's max / min values at the left edge
|
|
30
|
+
* @param {string} [ariaLabel='Function plot'] - The plot's accessible name
|
|
31
|
+
* @param {string} [className] - Extra classes on the plot
|
|
32
|
+
*/
|
|
33
|
+
export default function FunctionPlot({
|
|
34
|
+
fn,
|
|
35
|
+
samples,
|
|
36
|
+
min,
|
|
37
|
+
max,
|
|
38
|
+
cursor,
|
|
39
|
+
height = 64,
|
|
40
|
+
labels = true,
|
|
41
|
+
ariaLabel = 'Function plot',
|
|
42
|
+
className = '',
|
|
43
|
+
}) {
|
|
44
|
+
const ref = useRef(null)
|
|
45
|
+
const [w, setW] = useState(0)
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
const el = ref.current
|
|
49
|
+
if (!el) return
|
|
50
|
+
const ro = new ResizeObserver(([e]) => setW(e.contentRect.width))
|
|
51
|
+
ro.observe(el)
|
|
52
|
+
return () => ro.disconnect()
|
|
53
|
+
}, [])
|
|
54
|
+
|
|
55
|
+
const innerW = Math.max(1, w - PAD * 2)
|
|
56
|
+
const innerH = Math.max(1, height - PAD * 2)
|
|
57
|
+
const vs = samples?.length
|
|
58
|
+
? samples
|
|
59
|
+
: fn ? Array.from({ length: Math.round(innerW) + 1 }, (_, i) => fn(i / Math.round(innerW))) : []
|
|
60
|
+
const finite = vs.filter(Number.isFinite)
|
|
61
|
+
let lo = min ?? (finite.length ? Math.min(...finite) : 0)
|
|
62
|
+
let hi = max ?? (finite.length ? Math.max(...finite) : 1)
|
|
63
|
+
if (hi === lo) { lo -= 0.5; hi += 0.5 }
|
|
64
|
+
const toX = (u) => PAD + u * innerW
|
|
65
|
+
const toY = (v) => PAD + innerH * (1 - (v - lo) / (hi - lo))
|
|
66
|
+
|
|
67
|
+
const n = vs.length - 1
|
|
68
|
+
const pts = vs.map((v, i) => [toX(n > 0 ? i / n : 0), toY(Number.isFinite(v) ? v : lo)])
|
|
69
|
+
const line = (list) => list.map(([x, y], i) => `${i ? 'L' : 'M'}${x.toFixed(1)} ${y.toFixed(1)}`).join('')
|
|
70
|
+
const u = cursor == null ? null : Math.min(1, Math.max(0, cursor))
|
|
71
|
+
const at = u == null || n < 1 ? -1 : Math.round(u * n)
|
|
72
|
+
const cy = at < 0 ? 0 : (fn && !samples?.length ? toY(fn(u)) : pts[at][1])
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<div
|
|
76
|
+
ref={ref}
|
|
77
|
+
role="img"
|
|
78
|
+
aria-label={ariaLabel}
|
|
79
|
+
className={`kol-function-plot relative w-full overflow-hidden rounded-[var(--kol-radius-xs)] bg-[var(--kol-oq-04)] ${className}`.trim()}
|
|
80
|
+
style={{ height }}
|
|
81
|
+
>
|
|
82
|
+
{w > 0 && (
|
|
83
|
+
<svg className="absolute inset-0" width={w} height={height} viewBox={`0 0 ${w} ${height}`} aria-hidden="true">
|
|
84
|
+
{lo < 0 && hi > 0 && (
|
|
85
|
+
<line x1={PAD} x2={w - PAD} y1={toY(0)} y2={toY(0)} stroke="var(--kol-oq-24)" strokeWidth="1" />
|
|
86
|
+
)}
|
|
87
|
+
{pts.length > 1 && (
|
|
88
|
+
<>
|
|
89
|
+
<path d={line(pts)} fill="none" stroke="var(--kol-accent-primary)" strokeOpacity={at < 0 ? 1 : 0.25} strokeWidth={at < 0 ? 1.5 : 1} />
|
|
90
|
+
{at > 0 && <path d={line(pts.slice(0, at + 1))} fill="none" stroke="var(--kol-accent-primary)" strokeWidth="1.5" />}
|
|
91
|
+
</>
|
|
92
|
+
)}
|
|
93
|
+
{at >= 0 && (
|
|
94
|
+
<>
|
|
95
|
+
<line x1={toX(u)} x2={toX(u)} y1={PAD} y2={height - PAD} stroke="var(--kol-accent-primary)" strokeOpacity="0.4" strokeWidth="1" />
|
|
96
|
+
<circle cx={toX(u)} cy={cy} r="2.5" fill="var(--kol-accent-primary)" />
|
|
97
|
+
</>
|
|
98
|
+
)}
|
|
99
|
+
</svg>
|
|
100
|
+
)}
|
|
101
|
+
{labels && (
|
|
102
|
+
<>
|
|
103
|
+
<span className="kol-mono-10 absolute left-2 top-0.5 text-[var(--kol-oq-48)] pointer-events-none">{fmt(hi)}</span>
|
|
104
|
+
<span className="kol-mono-10 absolute left-2 bottom-0.5 text-[var(--kol-oq-48)] pointer-events-none">{fmt(lo)}</span>
|
|
105
|
+
</>
|
|
106
|
+
)}
|
|
107
|
+
</div>
|
|
108
|
+
)
|
|
109
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { useRef } from 'react'
|
|
2
|
+
import { toneClass } from '../utilities/tone.js'
|
|
3
|
+
|
|
4
|
+
const STEPS = [0, 0.5, 1]
|
|
5
|
+
const X_NAME = ['left', 'center', 'right']
|
|
6
|
+
const Y_NAME = ['top', 'center', 'bottom']
|
|
7
|
+
const pointName = (xi, yi) => (xi === 1 && yi === 1 ? 'center' : `${X_NAME[xi]} ${Y_NAME[yi]}`)
|
|
8
|
+
|
|
9
|
+
/* box padding + cell + dot per rung: 2·pad + 3·cell = the field's height (22 · 26 · 32; touch 32 · 32 · 36).
|
|
10
|
+
* The xs touch lift skips a hardware panel, as Input's does. */
|
|
11
|
+
const SIZE = {
|
|
12
|
+
xs: 'p-[2px] [--op-cell:6px] [--op-dot:4px] rounded-[var(--kol-radius-xs)] pointer-coarse:not-[.kol-hw-panel_*]:p-px pointer-coarse:not-[.kol-hw-panel_*]:[--op-cell:10px] pointer-coarse:not-[.kol-hw-panel_*]:[--op-dot:6px]',
|
|
13
|
+
sm: 'p-px [--op-cell:8px] [--op-dot:4px] rounded-[var(--kol-radius-sm)] pointer-coarse:[--op-cell:10px] pointer-coarse:[--op-dot:6px]',
|
|
14
|
+
md: 'p-px [--op-cell:10px] [--op-dot:6px] rounded-[var(--kol-radius-sm)] pointer-coarse:p-[3px]',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* OriginPicker — Pick one of nine anchor points. a 3×3 transform-origin / anchor value picker.
|
|
19
|
+
*
|
|
20
|
+
* Lobby OriginPicker (kol-fxr, 2026-10-31): fxr's layer inspector hand-built it as `AnchorPicker`
|
|
21
|
+
* (nine 6 px radio dots on surface-secondary) beside its X / Y fields. `AlignmentGrid` is not it —
|
|
22
|
+
* that fires align actions and holds no value; this holds one.
|
|
23
|
+
*
|
|
24
|
+
* ON THE CONTROL RAMP. The square is exactly a field's height at the same `size`, so it sits beside
|
|
25
|
+
* an `Input` without a step: xs 22 · sm 26 · md 32 (touch 32 · 32 · 36, as the fields grow). The
|
|
26
|
+
* ground is the control's (`--kol-tone-bg`, else surface-secondary), so `tone` and a toned wrapper
|
|
27
|
+
* reach it as they reach an Input. No border — the field family has none.
|
|
28
|
+
*
|
|
29
|
+
* INKS (the icon ink law — oq, never fg): a point rests at oq-24, a hovered one lifts to oq-48, the
|
|
30
|
+
* selected one is the accent. Focus is the segmented strip's quiet ring, drawn on the square.
|
|
31
|
+
*
|
|
32
|
+
* A11y: a radiogroup of nine radios with a roving tabindex — Tab lands on the selected point,
|
|
33
|
+
* ←/→ move x and ↑/↓ move y (selection and focus together, no wrap).
|
|
34
|
+
*
|
|
35
|
+
* <OriginPicker value={anchor} onChange={setAnchor} ariaLabel="Transform origin" size="sm" />
|
|
36
|
+
*
|
|
37
|
+
* @param {[number, number]} value - The selected point `[x, y]`, each 0 · 0.5 · 1 (0 = left / top)
|
|
38
|
+
* @param {(value:[number, number]) => void} onChange - Fired with the new `[x, y]` on click or arrow key
|
|
39
|
+
* @param {'xs'|'sm'|'md'} [size='sm'] - The control rung — the square matches a field of this size
|
|
40
|
+
* @param {string} [tone='default'] - The control set's tone (the ground); default inherits a wrapper's
|
|
41
|
+
* @param {string} [ariaLabel='Origin'] - The group's accessible name
|
|
42
|
+
* @param {string} [className] - Extra classes on the square
|
|
43
|
+
*/
|
|
44
|
+
export default function OriginPicker({
|
|
45
|
+
value = [0.5, 0.5],
|
|
46
|
+
onChange,
|
|
47
|
+
size = 'sm',
|
|
48
|
+
tone = 'default',
|
|
49
|
+
ariaLabel = 'Origin',
|
|
50
|
+
className = '',
|
|
51
|
+
}) {
|
|
52
|
+
const refs = useRef([])
|
|
53
|
+
const sel = [STEPS.indexOf(value?.[0]), STEPS.indexOf(value?.[1])]
|
|
54
|
+
|
|
55
|
+
const pick = (xi, yi, focus) => {
|
|
56
|
+
onChange?.([STEPS[xi], STEPS[yi]])
|
|
57
|
+
if (focus) refs.current[yi * 3 + xi]?.focus()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const onKeyDown = (e, xi, yi) => {
|
|
61
|
+
const d = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] }[e.key]
|
|
62
|
+
if (!d) return
|
|
63
|
+
e.preventDefault()
|
|
64
|
+
const nx = Math.min(2, Math.max(0, xi + d[0]))
|
|
65
|
+
const ny = Math.min(2, Math.max(0, yi + d[1]))
|
|
66
|
+
if (nx !== xi || ny !== yi) pick(nx, ny, true)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* nothing valid selected → the centre takes the tab stop, so the group is still reachable */
|
|
70
|
+
const tabStop = sel[0] < 0 || sel[1] < 0 ? [1, 1] : sel
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<div
|
|
74
|
+
role="radiogroup"
|
|
75
|
+
aria-label={ariaLabel}
|
|
76
|
+
className={[
|
|
77
|
+
'kol-origin-picker inline-grid grid-cols-3 shrink-0 bg-[var(--kol-tone-bg,var(--kol-surface-secondary))]',
|
|
78
|
+
'has-[:focus-visible]:outline has-[:focus-visible]:outline-1 has-[:focus-visible]:outline-[var(--kol-focus-ring-quiet)] has-[:focus-visible]:-outline-offset-2',
|
|
79
|
+
SIZE[size] ?? SIZE.sm,
|
|
80
|
+
toneClass(tone),
|
|
81
|
+
className,
|
|
82
|
+
].filter(Boolean).join(' ')}
|
|
83
|
+
>
|
|
84
|
+
{STEPS.map((_, yi) => STEPS.map((__, xi) => {
|
|
85
|
+
const on = sel[0] === xi && sel[1] === yi
|
|
86
|
+
const stop = tabStop[0] === xi && tabStop[1] === yi
|
|
87
|
+
return (
|
|
88
|
+
<button
|
|
89
|
+
key={`${xi}${yi}`}
|
|
90
|
+
ref={(el) => { refs.current[yi * 3 + xi] = el }}
|
|
91
|
+
type="button"
|
|
92
|
+
role="radio"
|
|
93
|
+
aria-checked={on}
|
|
94
|
+
aria-label={pointName(xi, yi)}
|
|
95
|
+
tabIndex={stop ? 0 : -1}
|
|
96
|
+
onClick={() => pick(xi, yi, false)}
|
|
97
|
+
onKeyDown={(e) => onKeyDown(e, xi, yi)}
|
|
98
|
+
className={`group grid place-items-center p-0 border-0 bg-transparent cursor-pointer outline-none size-[var(--op-cell)]`}
|
|
99
|
+
>
|
|
100
|
+
<span
|
|
101
|
+
aria-hidden="true"
|
|
102
|
+
className={`block rounded-full transition-colors size-[var(--op-dot)] ${on
|
|
103
|
+
? 'bg-[var(--kol-accent-primary)]'
|
|
104
|
+
: 'bg-[var(--kol-oq-24)] group-hover:bg-[var(--kol-oq-48)]'}`}
|
|
105
|
+
/>
|
|
106
|
+
</button>
|
|
107
|
+
)
|
|
108
|
+
}))}
|
|
109
|
+
</div>
|
|
110
|
+
)
|
|
111
|
+
}
|
package/src/index.js
CHANGED
|
@@ -83,6 +83,12 @@ export { default as TransparentX } from './utilities/TransparentX.jsx'
|
|
|
83
83
|
export { default as ViewToggle } from './atoms/ViewToggle.jsx'
|
|
84
84
|
/* the design-editor parts, taken per row from editor-panels-the-held-specs (2026-09-03) */
|
|
85
85
|
export { default as XYPad } from './atoms/XYPad.jsx'
|
|
86
|
+
/* lobby OriginPicker (kol-fxr, 2026-10-31) — the 3×3 origin / anchor value picker */
|
|
87
|
+
export { default as OriginPicker } from './atoms/OriginPicker.jsx'
|
|
88
|
+
/* lobby kol-fxr plan 51 4.4 (2026-10-31) — the bezier node editor, the function plot, the param bind dot */
|
|
89
|
+
export { default as BezierPathEditor } from './atoms/BezierPathEditor.jsx'
|
|
90
|
+
export { default as FunctionPlot } from './atoms/FunctionPlot.jsx'
|
|
91
|
+
export { default as ParamBindDot } from './molecules/ParamBindDot.jsx'
|
|
86
92
|
export { default as InspectorRail } from './molecules/InspectorRail.jsx'
|
|
87
93
|
/* SelectionOverlay's two siblings — same 1080-virtual contract, same zoom
|
|
88
94
|
* division (editor-panels-the-held-specs B2). `pathMath` is their geometry,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { useState } from 'react'
|
|
2
2
|
import SearchInput from './SearchInput.jsx'
|
|
3
|
-
import {
|
|
3
|
+
import { MenuRow } from './MenuItem.jsx'
|
|
4
4
|
import { PopoverPanel, usePopover } from '../utilities/Popover.jsx'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Combobox — A searchable value field: type to filter, pick a row. (MetricDashboardUpstream, kol-website 2026-10-31 —
|
|
8
8
|
* metric's filter-value picker, plausible.io's.) Built from the parts, never a fork of them: the field is `SearchInput`
|
|
9
9
|
* (outline, sm) and the list is `Dropdown`'s own panel (`kol-dd-panel` · `kol-dd-div` · `kol-dd-list`, rows
|
|
10
|
-
* `
|
|
10
|
+
* `MenuRow` at Dropdown's sm row), matched to the field's width and hung 1px under it.
|
|
11
11
|
*
|
|
12
12
|
* <Combobox value={q} onChange={setQ} options={[{ value: '/blog', label: '/blog' }]} placeholder="Select a value" />
|
|
13
13
|
*
|
|
@@ -44,13 +44,13 @@ export default function Combobox({ value, onChange, options = [], placeholder, a
|
|
|
44
44
|
onChange={(e) => { onChange(e.target?.value ?? e); setOpen(true) }}
|
|
45
45
|
onClear={() => onChange('')}
|
|
46
46
|
/>
|
|
47
|
-
<PopoverPanel popover={popover} panel={false} focus={false} className="kol-
|
|
47
|
+
<PopoverPanel popover={popover} panel={false} focus={false} className="kol-menu-panel kol-menu-panel--fused" style={{ '--kol-dd-max-rows': 8, '--kol-dd-row-h': 'var(--kol-ctl-sm)' }}>
|
|
48
48
|
<div className="kol-dd-div" />
|
|
49
49
|
<div className="kol-dd-list" role="listbox">
|
|
50
50
|
{shown.map((o) => (
|
|
51
|
-
<
|
|
51
|
+
<MenuRow key={o.value} hover={false} size="sm" rowClass={ROW_SM} onClick={() => { onChange(o.value); setOpen(false) }}>
|
|
52
52
|
{o.label}
|
|
53
|
-
</
|
|
53
|
+
</MenuRow>
|
|
54
54
|
))}
|
|
55
55
|
{!shown.length && <div className={`${ROW_SM} flex items-center text-meta`}>No matches</div>}
|
|
56
56
|
</div>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { Menu } from './Menu.jsx'
|
|
3
3
|
import { pushLayer, popLayer } from '../utilities/layerStack.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -10,7 +10,7 @@ import { pushLayer, popLayer } from '../utilities/layerStack.js'
|
|
|
10
10
|
* move, delete) had no surface to be invoked from: the operations existed on
|
|
11
11
|
* the client and nothing could reach them. This is that surface.
|
|
12
12
|
*
|
|
13
|
-
* Built on `
|
|
13
|
+
* Built on `Menu`'s `anchor` (since 2026-10-31; before, `usePopover`'s seam directly) rather than a new floating
|
|
14
14
|
* implementation — a context menu is a popover whose anchor is a point instead
|
|
15
15
|
* of an element, and floating-ui takes a virtual element for exactly this. So
|
|
16
16
|
* it inherits flip, shift, the portal, dismissal and the `.kol-popover` chrome,
|
|
@@ -19,7 +19,7 @@ import { pushLayer, popLayer } from '../utilities/layerStack.js'
|
|
|
19
19
|
* const menu = useContextMenu()
|
|
20
20
|
* <li onContextMenu={(e) => menu.openAt(e, row)}>…</li>
|
|
21
21
|
* <ContextMenu menu={menu}>
|
|
22
|
-
* {(row) => <
|
|
22
|
+
* {(row) => <MenuRow onClick={() => rename(row)}>Rename</MenuRow>}
|
|
23
23
|
* </ContextMenu>
|
|
24
24
|
*
|
|
25
25
|
* `children` may be a render function taking the payload handed to `openAt`,
|
|
@@ -36,31 +36,8 @@ export function useContextMenu() {
|
|
|
36
36
|
|
|
37
37
|
const close = useCallback(() => setState(null), [])
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
onOpenChange: (v) => { if (!v) close() },
|
|
42
|
-
placement: 'right-start',
|
|
43
|
-
offset: 2,
|
|
44
|
-
click: false,
|
|
45
|
-
role: 'menu',
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
/* A VIRTUAL ELEMENT — a zero-size rect at the pointer. It goes through
|
|
49
|
-
* `setPositionReference`, NOT the `elements.reference` option: floating-ui
|
|
50
|
-
* rejects a virtual element there ("must be a real DOM element") because that
|
|
51
|
-
* slot also feeds the interaction hooks, which call `getAttribute` on it.
|
|
52
|
-
* `setPositionReference` is the seam for exactly this — position from a point,
|
|
53
|
-
* interactions from nothing. */
|
|
54
|
-
const { setPositionReference } = popover.refs
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
if (!state) return
|
|
57
|
-
const { x, y } = state
|
|
58
|
-
setPositionReference({
|
|
59
|
-
getBoundingClientRect: () => ({ width: 0, height: 0, x, y, top: y, left: x, right: x, bottom: y }),
|
|
60
|
-
})
|
|
61
|
-
}, [state, setPositionReference])
|
|
62
|
-
|
|
63
|
-
return { open: !!state, payload: state?.payload ?? null, openAt, close, popover }
|
|
39
|
+
/* the point and the panel are `Menu`'s (plan-2026-10-31-menu-engine W1.4): it takes `anchor={{ x, y }}` */
|
|
40
|
+
return { open: !!state, x: state?.x, y: state?.y, payload: state?.payload ?? null, openAt, close }
|
|
64
41
|
}
|
|
65
42
|
|
|
66
43
|
export default function ContextMenu({ menu, children, className = '' }) {
|
|
@@ -73,19 +50,12 @@ export default function ContextMenu({ menu, children, className = '' }) {
|
|
|
73
50
|
}, [menu.open])
|
|
74
51
|
if (!menu.open) return null
|
|
75
52
|
return (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
<PopoverPanel popover={menu.popover} focus={false} className={`kol-dd-list min-w-44 ${className}`.trim()}>
|
|
80
|
-
{/* Any click inside closes — a menu item that leaves the menu open after
|
|
81
|
-
* acting is the one interaction people report as broken. Items keep their
|
|
82
|
-
* own onClick; this runs after it on the way up. */}
|
|
83
|
-
{/* A COLUMN, not a block: the items are `inline-flex`, so in a block they are one line of
|
|
84
|
-
* inline boxes to the float's shrink-to-fit, and the menu took the width of every label
|
|
85
|
-
* side by side — 510px for seven short verbs, past the edge of a phone. */}
|
|
53
|
+
<Menu anchor={{ x: menu.x, y: menu.y }} open onOpenChange={(v) => { if (!v) menu.close() }} panelClassName={`min-w-44 ${className}`.trim()}>
|
|
54
|
+
{/* Any click inside closes — a menu item that leaves the menu open after acting is the one interaction people
|
|
55
|
+
* report as broken. Items keep their own onClick; this runs after it on the way up. */}
|
|
86
56
|
<div onClick={menu.close} role="none" className="flex flex-col">
|
|
87
57
|
{typeof children === 'function' ? children(menu.payload) : children}
|
|
88
58
|
</div>
|
|
89
|
-
</
|
|
59
|
+
</Menu>
|
|
90
60
|
)
|
|
91
61
|
}
|