@kolkrabbi/kol-component 0.295.1 → 0.297.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/CloseButton.jsx +24 -4
- package/src/atoms/IconToggle.jsx +1 -1
- package/src/hooks/canvasViewport.js +400 -0
- package/src/hooks/railRow.js +11 -0
- package/src/index.js +9 -4
- package/src/molecules/AppItem.jsx +60 -38
- package/src/molecules/ContentCard.jsx +6 -3
- package/src/molecules/ContentRow.jsx +5 -3
- package/src/molecules/ContentText.jsx +12 -11
- package/src/molecules/LabeledControl.jsx +3 -1
- package/src/molecules/MenuItem.jsx +1 -1
- package/src/molecules/PageHeader.jsx +2 -1
- package/src/molecules/Rail.jsx +5 -3
- package/src/molecules/SectionText.jsx +6 -2
- package/src/molecules/TabsRow.jsx +65 -9
- package/src/molecules/TextFold.jsx +1 -1
- package/src/organisms/AppItemMenuProvider.jsx +159 -0
- package/src/organisms/Canvas.jsx +49 -258
- package/src/organisms/CanvasStudio.jsx +128 -0
- package/src/organisms/CommandOverlay.jsx +7 -5
- package/src/organisms/CurveEditor.jsx +1 -1
- package/src/organisms/MediaGalleryModes.jsx +1 -1
- package/src/organisms/MediaLibrary.jsx +31 -9
- package/src/organisms/MediaLibraryPages.jsx +30 -6
- package/src/organisms/NavRail.jsx +68 -56
- package/src/organisms/SettingsPanel.jsx +16 -9
- package/src/organisms/SettingsSections.jsx +31 -6
- package/src/utilities/imageToDataUrl.js +39 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolkrabbi/kol-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.297.0",
|
|
4
4
|
"description": "The core component library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -26,8 +26,8 @@
|
|
|
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-
|
|
30
|
-
"@kolkrabbi/kol-
|
|
29
|
+
"@kolkrabbi/kol-markdown": "^0.1.3",
|
|
30
|
+
"@kolkrabbi/kol-search": "^0.3.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@kolkrabbi/kol-icons": ">=0.22.0",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"react-dom": "^18.3.0 || ^19.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@kolkrabbi/kol-icons": "^0.
|
|
41
|
+
"@kolkrabbi/kol-icons": "^0.45.0"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"src",
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import Button from '../atoms/Button.jsx'
|
|
2
2
|
import IconFrame from '../atoms/IconFrame.jsx'
|
|
3
|
+
import { Icon } from '@kolkrabbi/kol-icons'
|
|
4
|
+
import { glyphSize } from '../hooks/glyphLadders.js'
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* CloseButton — the X that dismisses a thing. One component, so there is one.
|
|
@@ -43,14 +45,32 @@ import IconFrame from '../atoms/IconFrame.jsx'
|
|
|
43
45
|
* rung either way — only the state machine differs, which is exactly the
|
|
44
46
|
* distinction IconFrame was promoted for (2026-08-01).
|
|
45
47
|
*
|
|
48
|
+
* TWO SWITCHES, INDEPENDENT (user 2026-10-23: *"why dont we ship close button with and without frame, padding,
|
|
49
|
+
* hover … in this case just remove the hover, nothing else, but some cases might only want the icon not the frame"*).
|
|
50
|
+
* `hover={false}` keeps the box and its padding (the hit area and the alignment do not move) and drops the wash; its
|
|
51
|
+
* ink steps instead, oq-80 at rest and oq-96 on hover (`.kol-ink-step`) —
|
|
52
|
+
* the IconFrame base, which is what `states={false}` always was; `states` stays as its alias. `frame={false}` is the
|
|
53
|
+
* glyph alone: no box, no padding, the rung's solo glyph size at full ink. Both default on, so no close changes.
|
|
54
|
+
*
|
|
46
55
|
* @param {Function} onClick dismiss
|
|
47
|
-
* @param {boolean}
|
|
56
|
+
* @param {boolean} hover the hover wash (default true); false keeps the box, drops the wash
|
|
57
|
+
* @param {boolean} frame the box and its padding (default true); false = the glyph alone
|
|
58
|
+
* @param {boolean} states alias of `hover` (kept — every `states={false}` call site reads the same)
|
|
48
59
|
* @param {'xs'|'sm'|'md'|'lg'} size the rung (default 'sm'); match the row it sits in
|
|
49
60
|
* @param {string} label accessible name (default 'Close')
|
|
50
61
|
* @param {string} className extra classes — positioning, never chrome
|
|
51
62
|
*/
|
|
52
|
-
export default function CloseButton({ onClick, size = 'sm', label = 'Close', states = true, className = '', ...rest }) {
|
|
53
|
-
|
|
63
|
+
export default function CloseButton({ onClick, size = 'sm', label = 'Close', hover, frame = true, states = true, className = '', ...rest }) {
|
|
64
|
+
const washes = hover ?? states
|
|
65
|
+
if (!frame) {
|
|
66
|
+
return (
|
|
67
|
+
<button type="button" onClick={onClick} aria-label={label} className={`inline-flex shrink-0 items-center justify-center bg-transparent border-none p-0 cursor-pointer text-oq-96 ${className}`.trim()} {...rest}>
|
|
68
|
+
<Icon name="x" size={glyphSize(size, true)} />
|
|
69
|
+
</button>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
if (!washes) {
|
|
73
|
+
/* no wash: the INK steps instead — oq-80 at rest, oq-96 on hover (`.kol-ink-step`, kol-theme) */
|
|
54
74
|
return (
|
|
55
75
|
<IconFrame
|
|
56
76
|
name="x"
|
|
@@ -58,7 +78,7 @@ export default function CloseButton({ onClick, size = 'sm', label = 'Close', sta
|
|
|
58
78
|
size={size}
|
|
59
79
|
onClick={onClick}
|
|
60
80
|
aria-label={label}
|
|
61
|
-
className={className}
|
|
81
|
+
className={`kol-ink-step ${className}`.trim()}
|
|
62
82
|
{...rest}
|
|
63
83
|
/>
|
|
64
84
|
)
|
package/src/atoms/IconToggle.jsx
CHANGED
|
@@ -5,7 +5,7 @@ import { Tooltip } from '../utilities/Popover.jsx'
|
|
|
5
5
|
/* taxonomy-ok: atom — one control, Icon + the DS Tooltip */
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* IconToggle — an icon-only toggle: the icon is the control, the state is its INK, the name is the
|
|
8
|
+
* IconToggle — An icon-only toggle whose ink shows its state. an icon-only toggle: the icon is the control, the state is its INK, the name is the
|
|
9
9
|
* tooltip (IconToggle, kol-mirror 2026-10-15 — user: *"why is everything in brackets icon AND TEXT?
|
|
10
10
|
* all of this is also listed in shortcuts so? … because we want to minimise noise"*).
|
|
11
11
|
*
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* useCanvasViewport — the one engine under every canvas (the canvas family, 2026-10-23).
|
|
5
|
+
*
|
|
6
|
+
* `CanvasEditor` (the artboard, a fixed 1080-virtual frame with rulers and guides) and
|
|
7
|
+
* `CanvasStudio` (the infinite dotted surface the rack and the desk sit on) are two surfaces
|
|
8
|
+
* with one set of gestures and one key table. Until this file the gestures lived three times:
|
|
9
|
+
* kol-component's `PanZoomViewport`, kol-monitor's `RackViewport` and kol-mirror's desk — each
|
|
10
|
+
* with its own modifier, its own clamp and its own touch code, drifting on every one (⌘-wheel
|
|
11
|
+
* here, ⌥-scroll there; ⌘0, ⌥0 and a bare 0). The ruling (user, 2026-10-23): ⌘ is the canvas's
|
|
12
|
+
* modifier, globally; ⌥ belongs to the Hub's page keys (⌥1 … ⌥9). Nothing on the canvas reads ⌥.
|
|
13
|
+
*
|
|
14
|
+
* The view is `{ zoom, x, y }` — one `translate(x, y) scale(zoom)` with origin 0 0 on the
|
|
15
|
+
* transform layer, so a consumer's screen → content math divides by the zoom and nothing else.
|
|
16
|
+
* Controlled (`view` + `onViewChange`) or not (`defaultView`); either way `setView` takes a value
|
|
17
|
+
* or an updater, as React's does.
|
|
18
|
+
*
|
|
19
|
+
* Listeners mount on `ref.current` (pointer, wheel) and on the window (keys, move, up), so the
|
|
20
|
+
* component renders a div with the ref and nothing else. Keys never fire while typing in a field.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/* THE KEY TABLE — read by both surfaces, the docs page and a Hub's shortcuts sheet. `surface`
|
|
24
|
+
* narrows a row to one canvas; absent, it is both. */
|
|
25
|
+
export const CANVAS_KEYS = [
|
|
26
|
+
{ id: 'pan-space', label: 'Grab and pan (hold)', combo: 'Space + drag' },
|
|
27
|
+
{ id: 'pan-drag', label: 'Pan', combo: 'Middle-drag, ⌘ drag' },
|
|
28
|
+
{ id: 'pan-wheel', label: 'Pan', combo: 'Scroll (Shift for sideways)' },
|
|
29
|
+
{ id: 'zoom', label: 'Zoom at the pointer', combo: '⌘ scroll, pinch' },
|
|
30
|
+
{ id: 'zoom-in', label: 'Zoom in', combo: '⌘ =' },
|
|
31
|
+
{ id: 'zoom-out', label: 'Zoom out', combo: '⌘ −' },
|
|
32
|
+
{ id: 'zoom-reset', label: 'Reset pan and zoom', combo: '⌘ 0' },
|
|
33
|
+
{ id: 'fps', label: 'Framerate', combo: 'F' },
|
|
34
|
+
{ id: 'grid', label: 'Dot grid', combo: 'G', surface: 'studio' },
|
|
35
|
+
{ id: 'lock', label: 'Lock the view', combo: 'L', surface: 'studio' },
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
/* the dot grid — kol-monitor's and kol-mirror's exact rule, on the token: a 1px fg-12 dot on a
|
|
39
|
+
* 36px cell at zoom 1, the cell scaled by the zoom and the field offset by the pan so the surface
|
|
40
|
+
* moves under the work instead of the work sliding over a static field */
|
|
41
|
+
export const CANVAS_GRID_CELL = 36
|
|
42
|
+
export const CANVAS_GRID_IMAGE = 'radial-gradient(var(--kol-fg-12) 1px, transparent 1px)'
|
|
43
|
+
|
|
44
|
+
/* one rate per input, both surfaces: a mouse wheel notch is ~100 deltaY, a trackpad pinch
|
|
45
|
+
* arrives as a ctrlKey wheel with deltas of a few px — the same exponent would make one of them
|
|
46
|
+
* useless */
|
|
47
|
+
const WHEEL_RATE = 0.0015
|
|
48
|
+
const PINCH_RATE = 0.01
|
|
49
|
+
const STEP = 1.2
|
|
50
|
+
const TAP_MS = 350
|
|
51
|
+
const TAP_PX = 12
|
|
52
|
+
/* on a touch surface a finger on one of these is the control's, not a pan (monitor's useTouchGestures) */
|
|
53
|
+
const CONTROL = '[data-jack-id], button, input, select, textarea, a, [role="button"], [role="slider"]'
|
|
54
|
+
|
|
55
|
+
export function isTypingTarget(el) {
|
|
56
|
+
if (!el || !el.tagName) return false
|
|
57
|
+
const tag = el.tagName
|
|
58
|
+
return tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT' || el.isContentEditable
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const isControl = (t) => {
|
|
62
|
+
if (!t || t === document || !t.closest) return false
|
|
63
|
+
if (t.closest(CONTROL)) return true
|
|
64
|
+
const c = getComputedStyle(t).cursor
|
|
65
|
+
return c !== 'auto' && c !== 'default' && c !== 'grab' && c !== 'grabbing'
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* Anchor a zoom change at a screen point (sx, sy relative to the surface's top-left) so the
|
|
69
|
+
* content under the cursor stays put: screen = p * zoom + pan, inverted for a fixed p. */
|
|
70
|
+
export function zoomAt(v, factor, sx, sy, clamp) {
|
|
71
|
+
const z2 = clamp(v.zoom * factor)
|
|
72
|
+
return {
|
|
73
|
+
zoom: z2,
|
|
74
|
+
x: sx - (sx - v.x) * (z2 / v.zoom),
|
|
75
|
+
y: sy - (sy - v.y) * (z2 / v.zoom),
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* useFps(enabled) — live framerate, measured only while `enabled` (the RAF idles when off);
|
|
80
|
+
* frames per second, updated twice a second. A plain comment on purpose: `@param` belongs to a
|
|
81
|
+
* destructured props signature, and the props gate pairs a doc block with the next such export. */
|
|
82
|
+
export function useFps(enabled) {
|
|
83
|
+
const [fps, setFps] = useState(0)
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (!enabled) return undefined
|
|
86
|
+
let raf, frames = 0, last = performance.now()
|
|
87
|
+
const loop = (now) => {
|
|
88
|
+
frames++
|
|
89
|
+
if (now - last >= 500) {
|
|
90
|
+
setFps(Math.round((frames * 1000) / (now - last)))
|
|
91
|
+
frames = 0
|
|
92
|
+
last = now
|
|
93
|
+
}
|
|
94
|
+
raf = requestAnimationFrame(loop)
|
|
95
|
+
}
|
|
96
|
+
raf = requestAnimationFrame(loop)
|
|
97
|
+
return () => cancelAnimationFrame(raf)
|
|
98
|
+
}, [enabled])
|
|
99
|
+
return fps
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const REST = { zoom: 1, x: 0, y: 0 }
|
|
103
|
+
|
|
104
|
+
/* useCanvasViewport(options) — see the file comment. Options:
|
|
105
|
+
* ref the surface element (required) — pointer and wheel listeners mount on it
|
|
106
|
+
* view, defaultView, onViewChange the view, controlled or not
|
|
107
|
+
* minZoom, maxZoom the clamp (studio: the zoom itself; editor: in REAL terms through `fit`)
|
|
108
|
+
* fit () => number — the editor's fit scale, so the clamp reads zoom × fit
|
|
109
|
+
* rest () => view — what ⌘0 and `reset` return to (default zoom 1 at 0, 0); the studio's `fit` sets it
|
|
110
|
+
* locked, onLockChange the lock, controlled or not; `L` toggles it when `lockKey` is on
|
|
111
|
+
* grid, onGridChange the grid, controlled or not; `G` toggles it when `gridKey` is on
|
|
112
|
+
* gridKey, lockKey whether the surface binds G and L (the studio does, the editor does not)
|
|
113
|
+
* touch 'studio' (one finger pans unless on a control, two pan and pinch) · 'editor'
|
|
114
|
+
* (two pan and pinch, a one-finger tap fires onSpaceTap) · 'none'
|
|
115
|
+
* spaceWhenOver Space grabs only while the pointer is over the surface (a desk whose app
|
|
116
|
+
* gives Space to the transport elsewhere), in the capture phase
|
|
117
|
+
* ignore a selector — wheel and touch pass through what matches (an inner scroller)
|
|
118
|
+
* onSpaceTap a Space press released without a pan, or a one-finger tap on the editor
|
|
119
|
+
* Returns { view, setView, reset, zoomTo, spaceHeld, dragging, pinching, deaf, cursor, locked,
|
|
120
|
+
* setLocked, grid, setGrid, showFps, fps, transform }. */
|
|
121
|
+
export function useCanvasViewport({
|
|
122
|
+
ref,
|
|
123
|
+
view: viewProp,
|
|
124
|
+
defaultView,
|
|
125
|
+
onViewChange,
|
|
126
|
+
minZoom = 0.1,
|
|
127
|
+
maxZoom = 2,
|
|
128
|
+
fit,
|
|
129
|
+
rest,
|
|
130
|
+
locked: lockedProp,
|
|
131
|
+
onLockChange,
|
|
132
|
+
grid: gridProp,
|
|
133
|
+
onGridChange,
|
|
134
|
+
gridKey = false,
|
|
135
|
+
lockKey = false,
|
|
136
|
+
touch = 'studio',
|
|
137
|
+
spaceWhenOver = false,
|
|
138
|
+
ignore = 'input, textarea, select, [data-scroll-own]',
|
|
139
|
+
onSpaceTap,
|
|
140
|
+
}) {
|
|
141
|
+
const [inner, setInner] = useState(defaultView ?? REST)
|
|
142
|
+
const controlled = viewProp !== undefined
|
|
143
|
+
const view = controlled ? viewProp : inner
|
|
144
|
+
const viewRef = useRef(view)
|
|
145
|
+
viewRef.current = view
|
|
146
|
+
const onViewRef = useRef(onViewChange)
|
|
147
|
+
onViewRef.current = onViewChange
|
|
148
|
+
const fitRef = useRef(fit)
|
|
149
|
+
fitRef.current = fit
|
|
150
|
+
const restRef = useRef(rest)
|
|
151
|
+
restRef.current = rest
|
|
152
|
+
const restView = () => restRef.current?.() ?? REST
|
|
153
|
+
const clampRef = useRef(null)
|
|
154
|
+
clampRef.current = (z) => {
|
|
155
|
+
const f = fitRef.current ? fitRef.current() : 1
|
|
156
|
+
return Math.min(maxZoom / f, Math.max(minZoom / f, z))
|
|
157
|
+
}
|
|
158
|
+
const setView = (next) => {
|
|
159
|
+
const v = typeof next === 'function' ? next(viewRef.current) : next
|
|
160
|
+
viewRef.current = v
|
|
161
|
+
if (!controlled) setInner(v)
|
|
162
|
+
onViewRef.current?.(v)
|
|
163
|
+
}
|
|
164
|
+
const setViewRef = useRef(setView)
|
|
165
|
+
setViewRef.current = setView
|
|
166
|
+
|
|
167
|
+
/* lock and grid — controlled or not; handlers read the refs (they are registered once) */
|
|
168
|
+
const [lockedState, setLockedState] = useState(!!lockedProp)
|
|
169
|
+
const locked = onLockChange ? !!lockedProp : lockedState
|
|
170
|
+
const lockedRef = useRef(locked)
|
|
171
|
+
lockedRef.current = locked
|
|
172
|
+
const setLocked = (v) => { const next = typeof v === 'function' ? v(lockedRef.current) : v; lockedRef.current = next; if (onLockChange) onLockChange(next); else setLockedState(next) }
|
|
173
|
+
const setLockedRef = useRef(setLocked)
|
|
174
|
+
setLockedRef.current = setLocked
|
|
175
|
+
|
|
176
|
+
const [gridState, setGridState] = useState(gridProp ?? true)
|
|
177
|
+
const grid = onGridChange ? !!gridProp : gridState
|
|
178
|
+
const gridRef = useRef(grid)
|
|
179
|
+
gridRef.current = grid
|
|
180
|
+
const setGrid = (v) => { const next = typeof v === 'function' ? v(gridRef.current) : v; gridRef.current = next; if (onGridChange) onGridChange(next); else setGridState(next) }
|
|
181
|
+
const setGridRef = useRef(setGrid)
|
|
182
|
+
setGridRef.current = setGrid
|
|
183
|
+
|
|
184
|
+
const [spaceHeld, setSpaceHeld] = useState(false)
|
|
185
|
+
const [dragging, setDragging] = useState(false)
|
|
186
|
+
const [pinching, setPinching] = useState(false)
|
|
187
|
+
const [showFps, setShowFps] = useState(false)
|
|
188
|
+
const fps = useFps(showFps)
|
|
189
|
+
const spaceTapRef = useRef(onSpaceTap)
|
|
190
|
+
spaceTapRef.current = onSpaceTap
|
|
191
|
+
const spacePannedRef = useRef(false)
|
|
192
|
+
const spaceRef = useRef(false)
|
|
193
|
+
const overRef = useRef(!spaceWhenOver)
|
|
194
|
+
const dragStart = useRef(null)
|
|
195
|
+
const optsRef = useRef({ gridKey, lockKey, spaceWhenOver, touch, ignore })
|
|
196
|
+
optsRef.current = { gridKey, lockKey, spaceWhenOver, touch, ignore }
|
|
197
|
+
|
|
198
|
+
/* keys — Space (pan mode, a tap), ⌘0 / ⌘= / ⌘− (zoom), F (fps), G and L where the surface binds them */
|
|
199
|
+
useEffect(() => {
|
|
200
|
+
const onKeyDown = (e) => {
|
|
201
|
+
if (isTypingTarget(e.target)) return
|
|
202
|
+
const o = optsRef.current
|
|
203
|
+
if (e.code === 'Space') {
|
|
204
|
+
if (o.spaceWhenOver && !overRef.current) return
|
|
205
|
+
e.preventDefault()
|
|
206
|
+
if (o.spaceWhenOver) e.stopImmediatePropagation()
|
|
207
|
+
if (!e.repeat) spacePannedRef.current = false
|
|
208
|
+
if (!spaceRef.current) { spaceRef.current = true; setSpaceHeld(true) }
|
|
209
|
+
return
|
|
210
|
+
}
|
|
211
|
+
if (e.metaKey || e.ctrlKey) {
|
|
212
|
+
if (e.altKey) return
|
|
213
|
+
const el = ref.current
|
|
214
|
+
const r = el?.getBoundingClientRect()
|
|
215
|
+
const cx = (r?.width ?? 0) / 2, cy = (r?.height ?? 0) / 2
|
|
216
|
+
if (e.key === '0') { e.preventDefault(); if (!lockedRef.current) setViewRef.current(restView()) }
|
|
217
|
+
else if (e.key === '=' || e.key === '+') { e.preventDefault(); if (!lockedRef.current) setViewRef.current((v) => zoomAt(v, STEP, cx, cy, clampRef.current)) }
|
|
218
|
+
else if (e.key === '-') { e.preventDefault(); if (!lockedRef.current) setViewRef.current((v) => zoomAt(v, 1 / STEP, cx, cy, clampRef.current)) }
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
if (e.altKey) return
|
|
222
|
+
if (e.key === 'f' || e.key === 'F') { setShowFps((v) => !v); return }
|
|
223
|
+
if (o.gridKey && (e.key === 'g' || e.key === 'G')) { e.preventDefault(); setGridRef.current((v) => !v); return }
|
|
224
|
+
if (o.lockKey && (e.key === 'l' || e.key === 'L')) { e.preventDefault(); setLockedRef.current((v) => !v) }
|
|
225
|
+
}
|
|
226
|
+
const onKeyUp = (e) => {
|
|
227
|
+
if (e.code !== 'Space') return
|
|
228
|
+
const was = spaceRef.current
|
|
229
|
+
spaceRef.current = false
|
|
230
|
+
setSpaceHeld(false)
|
|
231
|
+
setDragging(false)
|
|
232
|
+
dragStart.current = null
|
|
233
|
+
if (was && !spacePannedRef.current && !isTypingTarget(e.target)) spaceTapRef.current?.()
|
|
234
|
+
}
|
|
235
|
+
const capture = optsRef.current.spaceWhenOver
|
|
236
|
+
window.addEventListener('keydown', onKeyDown, capture)
|
|
237
|
+
window.addEventListener('keyup', onKeyUp, capture)
|
|
238
|
+
return () => {
|
|
239
|
+
window.removeEventListener('keydown', onKeyDown, capture)
|
|
240
|
+
window.removeEventListener('keyup', onKeyUp, capture)
|
|
241
|
+
}
|
|
242
|
+
}, [ref])
|
|
243
|
+
|
|
244
|
+
/* the pointer — Space+drag, middle-drag and ⌘-drag pan; enter/leave for `spaceWhenOver` */
|
|
245
|
+
useEffect(() => {
|
|
246
|
+
const el = ref.current
|
|
247
|
+
if (!el) return undefined
|
|
248
|
+
const onEnter = () => { if (optsRef.current.spaceWhenOver) overRef.current = true }
|
|
249
|
+
const onLeave = () => { if (optsRef.current.spaceWhenOver) overRef.current = false }
|
|
250
|
+
const onDown = (e) => {
|
|
251
|
+
if (e.pointerType === 'touch') return
|
|
252
|
+
if (lockedRef.current) return
|
|
253
|
+
const wants = spaceRef.current || e.button === 1 || (e.metaKey && e.button === 0)
|
|
254
|
+
if (!wants) return
|
|
255
|
+
e.preventDefault()
|
|
256
|
+
if (spaceRef.current) spacePannedRef.current = true
|
|
257
|
+
const v = viewRef.current
|
|
258
|
+
dragStart.current = { x: e.clientX - v.x, y: e.clientY - v.y }
|
|
259
|
+
setDragging(true)
|
|
260
|
+
}
|
|
261
|
+
const onMove = (e) => {
|
|
262
|
+
const s = dragStart.current
|
|
263
|
+
if (!s) return
|
|
264
|
+
setViewRef.current((v) => ({ ...v, x: e.clientX - s.x, y: e.clientY - s.y }))
|
|
265
|
+
}
|
|
266
|
+
const onUp = () => {
|
|
267
|
+
if (!dragStart.current) return
|
|
268
|
+
dragStart.current = null
|
|
269
|
+
setDragging(false)
|
|
270
|
+
}
|
|
271
|
+
el.addEventListener('pointerenter', onEnter)
|
|
272
|
+
el.addEventListener('pointerleave', onLeave)
|
|
273
|
+
el.addEventListener('pointerdown', onDown)
|
|
274
|
+
window.addEventListener('pointermove', onMove)
|
|
275
|
+
window.addEventListener('pointerup', onUp)
|
|
276
|
+
window.addEventListener('pointercancel', onUp)
|
|
277
|
+
return () => {
|
|
278
|
+
el.removeEventListener('pointerenter', onEnter)
|
|
279
|
+
el.removeEventListener('pointerleave', onLeave)
|
|
280
|
+
el.removeEventListener('pointerdown', onDown)
|
|
281
|
+
window.removeEventListener('pointermove', onMove)
|
|
282
|
+
window.removeEventListener('pointerup', onUp)
|
|
283
|
+
window.removeEventListener('pointercancel', onUp)
|
|
284
|
+
}
|
|
285
|
+
}, [ref])
|
|
286
|
+
|
|
287
|
+
/* the wheel — plain scroll pans (Shift sideways), ⌘-wheel and a pinch (ctrlKey) zoom at the
|
|
288
|
+
* pointer; native and non-passive so the page neither scrolls nor zooms */
|
|
289
|
+
useEffect(() => {
|
|
290
|
+
const el = ref.current
|
|
291
|
+
if (!el) return undefined
|
|
292
|
+
const onWheel = (e) => {
|
|
293
|
+
const ig = optsRef.current.ignore
|
|
294
|
+
if (ig && e.target.closest?.(ig)) return
|
|
295
|
+
e.preventDefault()
|
|
296
|
+
if (lockedRef.current) return
|
|
297
|
+
const r = el.getBoundingClientRect()
|
|
298
|
+
const sx = e.clientX - r.left, sy = e.clientY - r.top
|
|
299
|
+
if (e.ctrlKey) setViewRef.current((v) => zoomAt(v, Math.exp(-e.deltaY * PINCH_RATE), sx, sy, clampRef.current))
|
|
300
|
+
else if (e.metaKey) setViewRef.current((v) => zoomAt(v, Math.exp(-e.deltaY * WHEEL_RATE), sx, sy, clampRef.current))
|
|
301
|
+
else setViewRef.current((v) => ({ ...v, x: v.x - (e.shiftKey ? e.deltaY : e.deltaX), y: v.y - (e.shiftKey ? 0 : e.deltaY) }))
|
|
302
|
+
}
|
|
303
|
+
el.addEventListener('wheel', onWheel, { passive: false })
|
|
304
|
+
return () => el.removeEventListener('wheel', onWheel)
|
|
305
|
+
}, [ref])
|
|
306
|
+
|
|
307
|
+
/* touch — two fingers pan at their midpoint and pinch-zoom anchored there, on both surfaces.
|
|
308
|
+
* studio: a lone finger on empty surface pans (a finger on a control is the control's).
|
|
309
|
+
* editor: a lone finger is the consumer's, except a tap, which fires onSpaceTap. */
|
|
310
|
+
useEffect(() => {
|
|
311
|
+
const el = ref.current
|
|
312
|
+
if (!el || touch === 'none') return undefined
|
|
313
|
+
const pts = new Map()
|
|
314
|
+
let last = null, solo = null, tap = null
|
|
315
|
+
const geom = () => {
|
|
316
|
+
const [a, b] = [...pts.values()]
|
|
317
|
+
return { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2, d: Math.hypot(b.x - a.x, b.y - a.y) || 1 }
|
|
318
|
+
}
|
|
319
|
+
const onDown = (e) => {
|
|
320
|
+
if (e.pointerType !== 'touch') return
|
|
321
|
+
const ig = optsRef.current.ignore
|
|
322
|
+
if (ig && e.target.closest?.(ig)) return
|
|
323
|
+
pts.set(e.pointerId, { x: e.clientX, y: e.clientY })
|
|
324
|
+
if (pts.size === 1) {
|
|
325
|
+
solo = touch === 'studio' && !isControl(e.target) ? { id: e.pointerId, x: e.clientX, y: e.clientY } : null
|
|
326
|
+
tap = touch === 'editor' ? { id: e.pointerId, t: e.timeStamp, x: e.clientX, y: e.clientY } : null
|
|
327
|
+
last = null
|
|
328
|
+
} else if (pts.size === 2) {
|
|
329
|
+
solo = null; tap = null
|
|
330
|
+
last = geom()
|
|
331
|
+
setPinching(true)
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const onMove = (e) => {
|
|
335
|
+
if (!pts.has(e.pointerId)) return
|
|
336
|
+
pts.set(e.pointerId, { x: e.clientX, y: e.clientY })
|
|
337
|
+
if (tap && Math.hypot(e.clientX - tap.x, e.clientY - tap.y) > TAP_PX) tap = null
|
|
338
|
+
if (lockedRef.current) return
|
|
339
|
+
if (pts.size === 1 && solo && solo.id === e.pointerId) {
|
|
340
|
+
const dx = e.clientX - solo.x, dy = e.clientY - solo.y
|
|
341
|
+
solo.x = e.clientX; solo.y = e.clientY
|
|
342
|
+
setViewRef.current((v) => ({ ...v, x: v.x + dx, y: v.y + dy }))
|
|
343
|
+
return
|
|
344
|
+
}
|
|
345
|
+
if (pts.size !== 2 || !last) return
|
|
346
|
+
const prev = last, next = geom()
|
|
347
|
+
last = next
|
|
348
|
+
const r = el.getBoundingClientRect()
|
|
349
|
+
setViewRef.current((v) => {
|
|
350
|
+
const z = zoomAt(v, next.d / prev.d, prev.x - r.left, prev.y - r.top, clampRef.current)
|
|
351
|
+
return { ...z, x: z.x + next.x - prev.x, y: z.y + next.y - prev.y }
|
|
352
|
+
})
|
|
353
|
+
}
|
|
354
|
+
const onUp = (e) => {
|
|
355
|
+
if (!pts.delete(e.pointerId)) return
|
|
356
|
+
if (tap?.id === e.pointerId && e.type === 'pointerup' && e.timeStamp - tap.t < TAP_MS) spaceTapRef.current?.()
|
|
357
|
+
if (tap?.id === e.pointerId) tap = null
|
|
358
|
+
if (solo?.id === e.pointerId) solo = null
|
|
359
|
+
last = pts.size === 2 ? geom() : null
|
|
360
|
+
if (pts.size < 2) setPinching(false)
|
|
361
|
+
}
|
|
362
|
+
el.addEventListener('pointerdown', onDown, true)
|
|
363
|
+
window.addEventListener('pointermove', onMove)
|
|
364
|
+
window.addEventListener('pointerup', onUp)
|
|
365
|
+
window.addEventListener('pointercancel', onUp)
|
|
366
|
+
return () => {
|
|
367
|
+
el.removeEventListener('pointerdown', onDown, true)
|
|
368
|
+
window.removeEventListener('pointermove', onMove)
|
|
369
|
+
window.removeEventListener('pointerup', onUp)
|
|
370
|
+
window.removeEventListener('pointercancel', onUp)
|
|
371
|
+
}
|
|
372
|
+
}, [ref, touch])
|
|
373
|
+
|
|
374
|
+
const cursor = dragging ? 'grabbing' : spaceHeld && !locked ? 'grab' : undefined
|
|
375
|
+
return {
|
|
376
|
+
view,
|
|
377
|
+
setView,
|
|
378
|
+
reset: () => setView(restView()),
|
|
379
|
+
/* a REAL zoom (1 = 100 %) about the surface's centre */
|
|
380
|
+
zoomTo: (scale) => {
|
|
381
|
+
const r = ref.current?.getBoundingClientRect()
|
|
382
|
+
const f = fitRef.current ? fitRef.current() : 1
|
|
383
|
+
setView((v) => zoomAt(v, scale / (v.zoom * f), (r?.width ?? 0) / 2, (r?.height ?? 0) / 2, clampRef.current))
|
|
384
|
+
},
|
|
385
|
+
clamp: (z) => clampRef.current(z),
|
|
386
|
+
spaceHeld,
|
|
387
|
+
dragging,
|
|
388
|
+
pinching,
|
|
389
|
+
/* the transform layer goes deaf while a gesture holds the surface, so a layer mousedown never fires mid-pan */
|
|
390
|
+
deaf: spaceHeld || pinching,
|
|
391
|
+
cursor,
|
|
392
|
+
locked,
|
|
393
|
+
setLocked,
|
|
394
|
+
grid,
|
|
395
|
+
setGrid,
|
|
396
|
+
showFps,
|
|
397
|
+
fps,
|
|
398
|
+
transform: `translate(${view.x}px, ${view.y}px) scale(${view.zoom})`,
|
|
399
|
+
}
|
|
400
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* THE RAIL ROW'S TYPE AND INK — one constant, read by `NavRail` (the rail) and `TabsRow`'s stacked phone tab (the bar),
|
|
2
|
+
* so neither retypes it (studio-hub review 2, § 7.1 — the bar's labels take the rail's row type and ink). The label is
|
|
3
|
+
* `kol-helper-12 uppercase` (single-line chrome, always truncated), the glyph 20, the ink oq-64 at rest and oq-96 on
|
|
4
|
+
* the route. The rail's own L1 row rests at oq-96 too (user: "make the color .96 on every icon in the rail"); its L2
|
|
5
|
+
* rows and the bar's tabs rest a rung quieter. */
|
|
6
|
+
export const RAIL_ROW = {
|
|
7
|
+
label: 'kol-helper-12 uppercase',
|
|
8
|
+
glyph: 20,
|
|
9
|
+
rest: 'var(--kol-oq-64)',
|
|
10
|
+
active: 'var(--kol-oq-96)',
|
|
11
|
+
}
|
package/src/index.js
CHANGED
|
@@ -55,7 +55,7 @@ export { usePopover, PopoverPanel, Tooltip } from './utilities/Popover.jsx'
|
|
|
55
55
|
/* armLongPress — the touch hold the panel value controls report (moved from kol-hardware 2026-10-01) */
|
|
56
56
|
export { armLongPress } from './utilities/armLongPress.js'
|
|
57
57
|
export { default as ContextMenu, useContextMenu } from './molecules/ContextMenu.jsx'
|
|
58
|
-
export { AppItemMenuProvider } from './
|
|
58
|
+
export { default as AppItemMenuProvider } from './organisms/AppItemMenuProvider.jsx'
|
|
59
59
|
export { default as ProsePreview } from './utilities/ProsePreview.jsx'
|
|
60
60
|
export { default as QuantityInput } from './molecules/QuantityInput.jsx'
|
|
61
61
|
/* Knob — the survivor's name (2026-10-02): `variant` dial · panel. `RotaryDial` is the alias, on the ledger. */
|
|
@@ -144,7 +144,7 @@ export { default as SplitToolButton } from './molecules/SplitToolButton.jsx'
|
|
|
144
144
|
export { default as ToolPalette } from './organisms/ToolPalette.jsx'
|
|
145
145
|
export { default as DocumentEditor } from './organisms/DocumentEditor.jsx'
|
|
146
146
|
export { default as SwatchControls, SwatchStack, EyedropPick } from './molecules/SwatchControls.jsx'
|
|
147
|
-
export { default as TabsRow, TABBAR_H } from './molecules/TabsRow.jsx'
|
|
147
|
+
export { default as TabsRow, TABBAR_H, TABBAR_PILL_INSET, tabbarPillWidth } from './molecules/TabsRow.jsx'
|
|
148
148
|
/** @deprecated 2026-10-17 — alias of `TabsRow look="chip"` */
|
|
149
149
|
export { default as TabChips } from './molecules/TabChips.jsx'
|
|
150
150
|
|
|
@@ -156,7 +156,12 @@ export { default as TabChips } from './molecules/TabChips.jsx'
|
|
|
156
156
|
* editor: the viewport publishes the zoom, every piece of editing chrome reads
|
|
157
157
|
* it. Absent from this barrel until 0.185.0, which is why the first port of
|
|
158
158
|
* this set could not keep its chrome screen-constant. */
|
|
159
|
-
|
|
159
|
+
/* THE CANVAS FAMILY (2026-10-23): `CanvasEditor` is the artboard (`Canvas`, its old name, is an alias
|
|
160
|
+
* on the ledger — one default under two names), `CanvasStudio` the infinite dotted surface the rack and
|
|
161
|
+
* the desk sit on; both read `useCanvasViewport`, one engine, one key table (`CANVAS_KEYS`). */
|
|
162
|
+
export { default as CanvasEditor, default as Canvas, CanvasFrame, PanViewport, PanZoomViewport, CanvasZoomContext, useFps, CANVAS_VIRTUAL_W, DEFAULT_ASPECTS, CANVAS_DEFAULTS } from './organisms/Canvas.jsx'
|
|
163
|
+
export { default as CanvasStudio } from './organisms/CanvasStudio.jsx'
|
|
164
|
+
export { useCanvasViewport, CANVAS_KEYS, CANVAS_GRID_CELL, CANVAS_GRID_IMAGE } from './hooks/canvasViewport.js'
|
|
160
165
|
/* The rulers and the guides, public since 2026-09-03 (rulers-and-guides-are-private):
|
|
161
166
|
* they measure the RENDERED rect, so they work over a CSS-zoomed stage with no
|
|
162
167
|
* PanZoomViewport anywhere — which is their second consumer on day one. */
|
|
@@ -176,7 +181,7 @@ export { default as ContentFilters } from './organisms/ContentFilters.jsx'
|
|
|
176
181
|
export { default as PageHeader, PAGE_HEADER_ROLES } from './molecules/PageHeader.jsx'
|
|
177
182
|
/* the one nav rail (2026-10-22) — `variant` app (the flat 48px rail) · site (the grouped site
|
|
178
183
|
* sidebar, kol-framework's SideNav until then). Moved from kol-shell, which re-exports all three. */
|
|
179
|
-
export { default as NavRail } from './organisms/NavRail.jsx'
|
|
184
|
+
export { default as NavRail, RAIL_PRESETS, registerRailPreset } from './organisms/NavRail.jsx'
|
|
180
185
|
export { default as Logomark } from './atoms/Logomark.jsx'
|
|
181
186
|
export { RailSlotProvider, useRailSlot } from './hooks/railSlot.jsx'
|
|
182
187
|
export { MastheadContext, MASTHEADS, useMasthead, mastheadTitleClass } from './utilities/masthead.js'
|