@kolkrabbi/kol-component 0.295.1 → 0.296.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 +2 -2
- 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 +43 -36
- 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 +144 -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/organisms/Canvas.jsx
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { useCallback,
|
|
1
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'
|
|
2
2
|
import { CanvasZoomContext } from '../hooks/canvasZoom.js'
|
|
3
|
+
import { useCanvasViewport, useFps, zoomAt } from '../hooks/canvasViewport.js'
|
|
3
4
|
import { Tooltip } from '../utilities/Popover.jsx'
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
+
* CanvasEditor — The editor's artboard. the editor's aspect-ratio stage, one of the two surfaces of the
|
|
8
|
+
* canvas family (2026-10-23): a FIXED frame you pan and zoom around, with rulers and guides.
|
|
9
|
+
* `CanvasStudio` is the other — an infinite dotted surface. Both read `useCanvasViewport`
|
|
10
|
+
* (hooks/canvasViewport.js): one set of gestures, one key table (`CANVAS_KEYS`), ⌘ the
|
|
11
|
+
* canvas's modifier. `Canvas` is this component's old name, an alias on the ledger.
|
|
7
12
|
*
|
|
8
13
|
* A letterboxed frame (dashed guide border + mono ratio label) that hosts its
|
|
9
14
|
* children in a **fixed 1080-virtual-pixel coordinate space** and scales the
|
|
@@ -16,8 +21,9 @@ import { Tooltip } from '../utilities/Popover.jsx'
|
|
|
16
21
|
* dividing by the live scale (frameWidth / 1080).
|
|
17
22
|
*
|
|
18
23
|
* Ships from this file: `CanvasZoomContext`, `CanvasFrame` (the bare scale
|
|
19
|
-
* layer), `
|
|
20
|
-
* zoom + rulers + guides), `PanViewport` (pan
|
|
24
|
+
* layer), `CanvasEditor` (the letterbox, default export), `PanZoomViewport` (pan +
|
|
25
|
+
* zoom + rulers + guides — deprecated, the engine is the hook), `PanViewport` (pan
|
|
26
|
+
* only — deprecated) and `useFps` (re-exported from the hook).
|
|
21
27
|
*
|
|
22
28
|
* Ported from kol-fxr's editor with three app-couplings dropped (per lobby
|
|
23
29
|
* spec): the static `ASPECTS` table → an `aspects` prop (+ DEFAULT_ASPECTS);
|
|
@@ -40,6 +46,8 @@ import { Tooltip } from '../utilities/Popover.jsx'
|
|
|
40
46
|
* had, so `import { CanvasZoomContext } from '@kolkrabbi/kol-component'` and
|
|
41
47
|
* every existing deep import keep working. */
|
|
42
48
|
export { CanvasZoomContext }
|
|
49
|
+
/* the fps hook lives with the engine now; the name stays here for every import that had it */
|
|
50
|
+
export { useFps }
|
|
43
51
|
|
|
44
52
|
/* Fixed virtual canvas width — children render in this pixel space and the
|
|
45
53
|
* outer rect scales to fit the viewport via CSS transform. Height is derived
|
|
@@ -168,7 +176,7 @@ export function CanvasFrame({
|
|
|
168
176
|
}
|
|
169
177
|
|
|
170
178
|
/**
|
|
171
|
-
*
|
|
179
|
+
* CanvasEditor — letterboxed stage (default export).
|
|
172
180
|
*
|
|
173
181
|
* The OUTER wrapper letterboxes the inner `<CanvasFrame>` (rect carries the
|
|
174
182
|
* optional `bgColor`, dashed border, label, and virtual-pixel scale layer).
|
|
@@ -197,7 +205,7 @@ export function CanvasFrame({
|
|
|
197
205
|
* @param {Function} onSpaceTap fires when Space was pressed and released WITHOUT panning — a tap, not a drag. fxr binds its transport play/pause here; unset, a tap does nothing
|
|
198
206
|
* @param {ReactNode} children rendered in the 1080-virtual scale layer
|
|
199
207
|
*/
|
|
200
|
-
export default function
|
|
208
|
+
export default function CanvasEditor({
|
|
201
209
|
aspect,
|
|
202
210
|
customRatio,
|
|
203
211
|
aspects,
|
|
@@ -261,6 +269,7 @@ export default function Canvas({
|
|
|
261
269
|
}
|
|
262
270
|
|
|
263
271
|
/**
|
|
272
|
+
* @deprecated 2026-10-23 → `CanvasEditor panEnabled` (the engine is `useCanvasViewport`); kept so a consumer composing its own viewport keeps resolving.
|
|
264
273
|
* PanViewport — Space + drag pan wrapper. **Pan only, no zoom.**
|
|
265
274
|
*
|
|
266
275
|
* Kept for a consumer composing its own viewport, and because it is what
|
|
@@ -362,11 +371,10 @@ export function PanViewport({ backdrop, children }) {
|
|
|
362
371
|
|
|
363
372
|
/* ── Pan + zoom ────────────────────────────────────────────────────────────
|
|
364
373
|
* Ported verbatim from kol-fxr `src/editor/shell/Canvas.jsx` (2026-09-03,
|
|
365
|
-
* `editor-set-is-behind-its-source`)
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
* source's — fxr is the reference for this set. */
|
|
374
|
+
* `editor-set-is-behind-its-source`); the gestures moved into `useCanvasViewport`
|
|
375
|
+
* (hooks/canvasViewport.js) on 2026-10-23 so the studio surface reads the same ones.
|
|
376
|
+
* What stays here is the editor's: the clamps in REAL terms, the fit, the
|
|
377
|
+
* `kol:zoom-*` window events, the rulers, the guides and the chips. */
|
|
370
378
|
|
|
371
379
|
/* The clamps are in REAL terms — screen px per frame px, `zoom × fit` (CanvasViewCommands, kol-fxr
|
|
372
380
|
* 2026-10-13). They were 0.1–8 relative to the fitted frame, so a 1080 frame fitted at ~0.58 capped
|
|
@@ -381,66 +389,17 @@ function fitOf(node) {
|
|
|
381
389
|
return w ? w / CANVAS_VIRTUAL_W : 1
|
|
382
390
|
}
|
|
383
391
|
|
|
384
|
-
const clampZoom = (z, fit) => Math.min(ZOOM_MAX_REAL / fit, Math.max(ZOOM_MIN_REAL / fit, z))
|
|
385
|
-
|
|
386
|
-
/* Anchor a zoom change at a screen point (sx, sy relative to the viewport
|
|
387
|
-
* top-left) so the content under the cursor stays put. Transform is
|
|
388
|
-
* `translate(x,y) scale(zoom)` with origin 0,0, so screen = p*zoom + pan;
|
|
389
|
-
* inverting for a fixed p gives the new pan below. */
|
|
390
|
-
function zoomAt(v, factor, sx, sy, fit = 1) {
|
|
391
|
-
const z2 = clampZoom(v.zoom * factor, fit)
|
|
392
|
-
return {
|
|
393
|
-
zoom: z2,
|
|
394
|
-
x: sx - (sx - v.x) * (z2 / v.zoom),
|
|
395
|
-
y: sy - (sy - v.y) * (z2 / v.zoom),
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/* useFps(enabled) — live framerate, measured only while `enabled` (the RAF
|
|
400
|
-
* idles when off); returns frames per second, updated twice a second.
|
|
401
|
-
* Exported because a consumer's own stage corner renders the same chip.
|
|
402
|
-
*
|
|
403
|
-
* A plain block comment on purpose: `@param` belongs to a destructured props
|
|
404
|
-
* signature, and the props gate pairs a `/** … *\/` block with the next such
|
|
405
|
-
* export — a JSDoc'd positional hook hands its `@param` to the component
|
|
406
|
-
* below it, which is exactly the false positive it reported on this file. */
|
|
407
|
-
export function useFps(enabled) {
|
|
408
|
-
const [fps, setFps] = useState(0)
|
|
409
|
-
useEffect(() => {
|
|
410
|
-
if (!enabled) return
|
|
411
|
-
let raf, frames = 0, last = performance.now()
|
|
412
|
-
const loop = (now) => {
|
|
413
|
-
frames++
|
|
414
|
-
if (now - last >= 500) {
|
|
415
|
-
setFps(Math.round((frames * 1000) / (now - last)))
|
|
416
|
-
frames = 0
|
|
417
|
-
last = now
|
|
418
|
-
}
|
|
419
|
-
raf = requestAnimationFrame(loop)
|
|
420
|
-
}
|
|
421
|
-
raf = requestAnimationFrame(loop)
|
|
422
|
-
return () => cancelAnimationFrame(raf)
|
|
423
|
-
}, [enabled])
|
|
424
|
-
return fps
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
function isTypingTarget(el) {
|
|
428
|
-
if (!el) return false
|
|
429
|
-
const tag = el.tagName
|
|
430
|
-
return tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT' || el.isContentEditable
|
|
431
|
-
}
|
|
432
|
-
|
|
433
392
|
/**
|
|
434
|
-
*
|
|
393
|
+
* @deprecated 2026-10-23 → `CanvasEditor panEnabled`; the pan and zoom are `useCanvasViewport`'s, shared with `CanvasStudio`. Kept so an editor composing its own stage keeps resolving.
|
|
394
|
+
* PanZoomViewport — An infinite canvas to pan and zoom. the editor's viewport (pan + zoom), and the one that
|
|
435
395
|
* publishes `CanvasZoomContext`.
|
|
436
396
|
*
|
|
437
|
-
* Pan: hold Space + drag (cursor grab/grabbing), or two-finger
|
|
438
|
-
* scroll. Zoom:
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
* mid-pan. `f` toggles an fps chip beside the zoom readout. From outside: `kol:zoom-at`
|
|
397
|
+
* Pan: hold Space + drag (cursor grab/grabbing), middle-drag, ⌘-drag, or a plain two-finger
|
|
398
|
+
* scroll. Zoom: ⌘/Ctrl + wheel or a trackpad pinch, anchored at the pointer; ⌘0 resets, ⌘= / ⌘−
|
|
399
|
+
* step-zoom at the viewport centre (`CANVAS_KEYS`). A single `translate() scale()` on the
|
|
400
|
+
* transform layer carries both, so a consumer's screen→virtual math needs no zoom awareness.
|
|
401
|
+
* Pointer events on the transform layer disable while Space is held so layer mousedowns don't
|
|
402
|
+
* fire mid-pan. `F` toggles an fps chip beside the zoom readout. From outside: `kol:zoom-at`
|
|
444
403
|
* { clientX, clientY, factor } · `kol:zoom-to` { scale } (real, 1 = 100%) · `kol:zoom-fit` { to:
|
|
445
404
|
* 'frame' | 'width' | { x, y, w, h } } — window events. Zoom is clamped at 2%–3200% real. Touch:
|
|
446
405
|
* two fingers pinch-zoom + pan; a one-finger tap fires `onSpaceTap`.
|
|
@@ -462,161 +421,20 @@ export function PanZoomViewport({
|
|
|
462
421
|
guidesInteractive = true,
|
|
463
422
|
onSpaceTap,
|
|
464
423
|
}) {
|
|
465
|
-
const containerRef
|
|
466
|
-
const
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
const
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
spaceTapRef.current = onSpaceTap
|
|
480
|
-
|
|
481
|
-
/* Space toggles pan mode; Cmd+0 / Cmd+= / Cmd+- drive zoom from the
|
|
482
|
-
* keyboard (centered on the viewport). Skipped while typing in a field. */
|
|
483
|
-
useEffect(() => {
|
|
484
|
-
const isInputTarget = (el) =>
|
|
485
|
-
el && (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.isContentEditable)
|
|
486
|
-
const onKeyDown = (e) => {
|
|
487
|
-
if (isInputTarget(e.target)) return
|
|
488
|
-
if (e.code === 'Space') {
|
|
489
|
-
e.preventDefault()
|
|
490
|
-
if (!e.repeat) spacePannedRef.current = false
|
|
491
|
-
setSpaceHeld(true)
|
|
492
|
-
return
|
|
493
|
-
}
|
|
494
|
-
if (e.metaKey || e.ctrlKey) {
|
|
495
|
-
if (e.key === '0') {
|
|
496
|
-
e.preventDefault()
|
|
497
|
-
setView({ zoom: 1, x: 0, y: 0 })
|
|
498
|
-
} else if (e.key === '=' || e.key === '+') {
|
|
499
|
-
e.preventDefault()
|
|
500
|
-
const r = containerRef.current?.getBoundingClientRect()
|
|
501
|
-
setView((v) => zoomAt(v, 1.2, (r?.width ?? 0) / 2, (r?.height ?? 0) / 2, fitOf(containerRef.current)))
|
|
502
|
-
} else if (e.key === '-') {
|
|
503
|
-
e.preventDefault()
|
|
504
|
-
const r = containerRef.current?.getBoundingClientRect()
|
|
505
|
-
setView((v) => zoomAt(v, 1 / 1.2, (r?.width ?? 0) / 2, (r?.height ?? 0) / 2, fitOf(containerRef.current)))
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
const onKeyUp = (e) => {
|
|
510
|
-
if (e.code === 'Space') {
|
|
511
|
-
setSpaceHeld(false)
|
|
512
|
-
setDragging(false)
|
|
513
|
-
dragStart.current = null
|
|
514
|
-
/* No pan happened → this was a tap. fxr binds play/pause here; the
|
|
515
|
-
* same input guard as keydown so typing a space in a field is not a
|
|
516
|
-
* tap. Unset, a tap does nothing. */
|
|
517
|
-
if (!spacePannedRef.current && !isInputTarget(e.target)) spaceTapRef.current?.()
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
window.addEventListener('keydown', onKeyDown)
|
|
521
|
-
window.addEventListener('keyup', onKeyUp)
|
|
522
|
-
return () => {
|
|
523
|
-
window.removeEventListener('keydown', onKeyDown)
|
|
524
|
-
window.removeEventListener('keyup', onKeyUp)
|
|
525
|
-
}
|
|
526
|
-
}, [])
|
|
527
|
-
|
|
528
|
-
useEffect(() => {
|
|
529
|
-
if (!dragging) return
|
|
530
|
-
const onMove = (e) => {
|
|
531
|
-
if (!dragStart.current) return
|
|
532
|
-
const { x: sx, y: sy } = dragStart.current
|
|
533
|
-
setView((v) => ({ ...v, x: e.clientX - sx, y: e.clientY - sy }))
|
|
534
|
-
}
|
|
535
|
-
const onUp = () => {
|
|
536
|
-
setDragging(false)
|
|
537
|
-
dragStart.current = null
|
|
538
|
-
}
|
|
539
|
-
window.addEventListener('mousemove', onMove)
|
|
540
|
-
window.addEventListener('mouseup', onUp)
|
|
541
|
-
return () => {
|
|
542
|
-
window.removeEventListener('mousemove', onMove)
|
|
543
|
-
window.removeEventListener('mouseup', onUp)
|
|
544
|
-
}
|
|
545
|
-
}, [dragging])
|
|
546
|
-
|
|
547
|
-
/* Wheel: Cmd/Ctrl+wheel or trackpad pinch (ctrlKey) → zoom at pointer;
|
|
548
|
-
* plain two-finger scroll → pan. Native non-passive listener so we can
|
|
549
|
-
* preventDefault the browser's page-zoom / scroll. */
|
|
550
|
-
useEffect(() => {
|
|
551
|
-
const node = containerRef.current
|
|
552
|
-
if (!node) return
|
|
553
|
-
const onWheel = (e) => {
|
|
554
|
-
e.preventDefault()
|
|
555
|
-
const rect = node.getBoundingClientRect()
|
|
556
|
-
const sx = e.clientX - rect.left
|
|
557
|
-
const sy = e.clientY - rect.top
|
|
558
|
-
if (e.ctrlKey || e.metaKey) {
|
|
559
|
-
setView((v) => zoomAt(v, Math.exp(-e.deltaY * 0.0015), sx, sy, fitOf(node)))
|
|
560
|
-
} else {
|
|
561
|
-
setView((v) => ({ ...v, x: v.x - e.deltaX, y: v.y - e.deltaY }))
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
node.addEventListener('wheel', onWheel, { passive: false })
|
|
565
|
-
return () => node.removeEventListener('wheel', onWheel)
|
|
566
|
-
}, [])
|
|
567
|
-
|
|
568
|
-
/* Touch (ViewportTouchGestures, kol-fxr 2026-10-14): two fingers pinch-zoom at their midpoint and
|
|
569
|
-
* the midpoint's travel pans, in one gesture; the transform layer goes deaf while they are down so
|
|
570
|
-
* a consumer's tool never sees the second finger. One finger stays the consumer's, except a TAP
|
|
571
|
-
* (up within TAP_MS and TAP_PX, no second finger joined) fires `onSpaceTap`. Down is caught in the
|
|
572
|
-
* capture phase on the container; move/up on window, so a finger leaving the frame still ends. */
|
|
573
|
-
useEffect(() => {
|
|
574
|
-
const node = containerRef.current
|
|
575
|
-
if (!node) return
|
|
576
|
-
const TAP_MS = 350, TAP_PX = 12
|
|
577
|
-
const pts = new Map()
|
|
578
|
-
let pinch = null, tap = null
|
|
579
|
-
const pair = () => {
|
|
580
|
-
const [a, b] = [...pts.values()]
|
|
581
|
-
return { mx: (a.x + b.x) / 2, my: (a.y + b.y) / 2, d: Math.hypot(a.x - b.x, a.y - b.y) || 1 }
|
|
582
|
-
}
|
|
583
|
-
const onDown = (e) => {
|
|
584
|
-
if (e.pointerType !== 'touch') return
|
|
585
|
-
pts.set(e.pointerId, { x: e.clientX, y: e.clientY })
|
|
586
|
-
if (pts.size === 1) tap = { id: e.pointerId, t: e.timeStamp, x: e.clientX, y: e.clientY }
|
|
587
|
-
else if (pts.size === 2) { tap = null; pinch = pair(); setPinching(true) }
|
|
588
|
-
}
|
|
589
|
-
const onMove = (e) => {
|
|
590
|
-
if (!pts.has(e.pointerId)) return
|
|
591
|
-
pts.set(e.pointerId, { x: e.clientX, y: e.clientY })
|
|
592
|
-
if (tap && Math.hypot(e.clientX - tap.x, e.clientY - tap.y) > TAP_PX) tap = null
|
|
593
|
-
if (!pinch || pts.size < 2) return
|
|
594
|
-
const prev = pinch, next = pair()
|
|
595
|
-
pinch = next
|
|
596
|
-
const r = node.getBoundingClientRect()
|
|
597
|
-
const fit = fitOf(node)
|
|
598
|
-
setView((v) => {
|
|
599
|
-
const z = zoomAt(v, next.d / prev.d, prev.mx - r.left, prev.my - r.top, fit)
|
|
600
|
-
return { ...z, x: z.x + next.mx - prev.mx, y: z.y + next.my - prev.my }
|
|
601
|
-
})
|
|
602
|
-
}
|
|
603
|
-
const onEnd = (e) => {
|
|
604
|
-
if (!pts.delete(e.pointerId)) return
|
|
605
|
-
if (tap?.id === e.pointerId && e.type === 'pointerup' && e.timeStamp - tap.t < TAP_MS) spaceTapRef.current?.()
|
|
606
|
-
if (tap?.id === e.pointerId) tap = null
|
|
607
|
-
if (pinch && pts.size < 2) { pinch = null; setPinching(false) }
|
|
608
|
-
}
|
|
609
|
-
node.addEventListener('pointerdown', onDown, true)
|
|
610
|
-
window.addEventListener('pointermove', onMove)
|
|
611
|
-
window.addEventListener('pointerup', onEnd)
|
|
612
|
-
window.addEventListener('pointercancel', onEnd)
|
|
613
|
-
return () => {
|
|
614
|
-
node.removeEventListener('pointerdown', onDown, true)
|
|
615
|
-
window.removeEventListener('pointermove', onMove)
|
|
616
|
-
window.removeEventListener('pointerup', onEnd)
|
|
617
|
-
window.removeEventListener('pointercancel', onEnd)
|
|
618
|
-
}
|
|
619
|
-
}, [])
|
|
424
|
+
const containerRef = useRef(null)
|
|
425
|
+
const vp = useCanvasViewport({
|
|
426
|
+
ref: containerRef,
|
|
427
|
+
minZoom: ZOOM_MIN_REAL,
|
|
428
|
+
maxZoom: ZOOM_MAX_REAL,
|
|
429
|
+
fit: () => fitOf(containerRef.current),
|
|
430
|
+
touch: 'editor',
|
|
431
|
+
onSpaceTap,
|
|
432
|
+
})
|
|
433
|
+
const { view, setView, clamp, spaceHeld, pinching, cursor, showFps, fps } = vp
|
|
434
|
+
const setViewRef = useRef(setView)
|
|
435
|
+
setViewRef.current = setView
|
|
436
|
+
const clampRef = useRef(clamp)
|
|
437
|
+
clampRef.current = clamp
|
|
620
438
|
|
|
621
439
|
/* A consumer's zoom TOOL announces clicks as `kol:zoom-at` (client coords +
|
|
622
440
|
* factor) rather than reaching into this state — anchored zoom at the
|
|
@@ -627,7 +445,7 @@ export function PanZoomViewport({
|
|
|
627
445
|
if (!node) return
|
|
628
446
|
const { clientX, clientY, factor } = e.detail
|
|
629
447
|
const rect = node.getBoundingClientRect()
|
|
630
|
-
|
|
448
|
+
setViewRef.current((v) => zoomAt(v, factor, clientX - rect.left, clientY - rect.top, clampRef.current))
|
|
631
449
|
}
|
|
632
450
|
/* `kol:zoom-to` { scale } — a REAL scale (1 = 100%: one screen px per frame px), about the
|
|
633
451
|
* viewport centre, so a consumer's 100–800% steps need not measure the fit. */
|
|
@@ -636,7 +454,7 @@ export function PanZoomViewport({
|
|
|
636
454
|
if (!node) return
|
|
637
455
|
const fit = fitOf(node)
|
|
638
456
|
const r = node.getBoundingClientRect()
|
|
639
|
-
|
|
457
|
+
setViewRef.current((v) => zoomAt(v, e.detail.scale / (v.zoom * fit), r.width / 2, r.height / 2, clampRef.current))
|
|
640
458
|
}
|
|
641
459
|
/* `kol:zoom-fit` { to } — `'frame'` (default) is ⌘0's opening view; `'width'` fills the
|
|
642
460
|
* viewport with the frame's width, centred vertically; `{ x, y, w, h }` in frame (virtual) px
|
|
@@ -645,20 +463,20 @@ export function PanZoomViewport({
|
|
|
645
463
|
const node = containerRef.current
|
|
646
464
|
const frame = node?.querySelector('[data-canvas-frame]')
|
|
647
465
|
const to = e.detail?.to ?? 'frame'
|
|
648
|
-
if (!frame || to === 'frame') {
|
|
466
|
+
if (!frame || to === 'frame') { setViewRef.current({ zoom: 1, x: 0, y: 0 }); return }
|
|
649
467
|
const fit = fitOf(node)
|
|
650
468
|
const cr = node.getBoundingClientRect()
|
|
651
469
|
const fr = frame.getBoundingClientRect()
|
|
652
|
-
|
|
470
|
+
setViewRef.current((v) => {
|
|
653
471
|
/* the frame's rect at rest (zoom 1, no pan), in viewport px */
|
|
654
472
|
const fx = (fr.left - cr.left - v.x) / v.zoom
|
|
655
473
|
const fy = (fr.top - cr.top - v.y) / v.zoom
|
|
656
474
|
const rect = to === 'width'
|
|
657
475
|
? { x: fx, y: fy, w: frame.offsetWidth, h: frame.offsetHeight }
|
|
658
476
|
: { x: fx + to.x * fit, y: fy + to.y * fit, w: to.w * fit, h: to.h * fit }
|
|
659
|
-
const zoom =
|
|
477
|
+
const zoom = clampRef.current(to === 'width'
|
|
660
478
|
? cr.width / rect.w
|
|
661
|
-
: Math.min((cr.width - 2 * FIT_MARGIN) / rect.w, (cr.height - 2 * FIT_MARGIN) / rect.h)
|
|
479
|
+
: Math.min((cr.width - 2 * FIT_MARGIN) / rect.w, (cr.height - 2 * FIT_MARGIN) / rect.h))
|
|
662
480
|
return {
|
|
663
481
|
zoom,
|
|
664
482
|
x: cr.width / 2 - (rect.x + rect.w / 2) * zoom,
|
|
@@ -676,32 +494,6 @@ export function PanZoomViewport({
|
|
|
676
494
|
}
|
|
677
495
|
}, [])
|
|
678
496
|
|
|
679
|
-
/* `f` toggles the fps chip (measured only while shown). Guarded against
|
|
680
|
-
* typing targets so text fields don't flip it. */
|
|
681
|
-
useEffect(() => {
|
|
682
|
-
const onKey = (e) => {
|
|
683
|
-
if (e.key !== 'f' && e.key !== 'F') return
|
|
684
|
-
if (e.metaKey || e.ctrlKey || e.altKey) return
|
|
685
|
-
if (isTypingTarget(e.target)) return
|
|
686
|
-
setShowFps((v) => !v)
|
|
687
|
-
}
|
|
688
|
-
window.addEventListener('keydown', onKey)
|
|
689
|
-
return () => window.removeEventListener('keydown', onKey)
|
|
690
|
-
}, [])
|
|
691
|
-
|
|
692
|
-
const onMouseDown = (e) => {
|
|
693
|
-
if (!spaceHeld) return
|
|
694
|
-
e.preventDefault()
|
|
695
|
-
spacePannedRef.current = true
|
|
696
|
-
dragStart.current = { x: e.clientX - view.x, y: e.clientY - view.y }
|
|
697
|
-
setDragging(true)
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
/* Only override the cursor while actively panning (Space-held / dragging).
|
|
701
|
-
* At rest, leave it unset so consumers above can apply their own cursor
|
|
702
|
-
* (a tool-driven cursor) and have it visible across the backdrop AND the
|
|
703
|
-
* canvas frame, not just the frame area. */
|
|
704
|
-
const cursor = dragging ? 'grabbing' : spaceHeld ? 'grab' : undefined
|
|
705
497
|
const atRest = view.zoom === 1 && view.x === 0 && view.y === 0
|
|
706
498
|
|
|
707
499
|
return (
|
|
@@ -710,7 +502,6 @@ export function PanZoomViewport({
|
|
|
710
502
|
ref={containerRef}
|
|
711
503
|
className="relative w-full h-full overflow-hidden select-none"
|
|
712
504
|
style={{ cursor, touchAction: 'none' }}
|
|
713
|
-
onMouseDown={onMouseDown}
|
|
714
505
|
>
|
|
715
506
|
{/* No transition on the transform: editing chrome (selection
|
|
716
507
|
wireframe, path nodes) sizes itself by 1/zoom from React state,
|
|
@@ -720,7 +511,7 @@ export function PanZoomViewport({
|
|
|
720
511
|
<div
|
|
721
512
|
className="absolute inset-0"
|
|
722
513
|
style={{
|
|
723
|
-
transform:
|
|
514
|
+
transform: vp.transform,
|
|
724
515
|
transformOrigin: '0 0',
|
|
725
516
|
pointerEvents: spaceHeld || pinching ? 'none' : 'auto',
|
|
726
517
|
}}
|
|
@@ -744,7 +535,7 @@ export function PanZoomViewport({
|
|
|
744
535
|
{showRulers && <CanvasRuler containerRef={containerRef} disabled={spaceHeld} />}
|
|
745
536
|
|
|
746
537
|
{/* Zoom % + fps — matching chips. Zoom (click resets to 100% /
|
|
747
|
-
centered) first, fps to its right, shown while `
|
|
538
|
+
centered) first, fps to its right, shown while `F` toggles it. */}
|
|
748
539
|
<div className="absolute bottom-3 right-3 z-[3] flex items-center gap-2">
|
|
749
540
|
<Tooltip label="Reset zoom (⌘0)" asChild>
|
|
750
541
|
<button
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef } from 'react'
|
|
2
|
+
import { CanvasZoomContext } from '../hooks/canvasZoom.js'
|
|
3
|
+
import { useCanvasViewport, CANVAS_GRID_CELL, CANVAS_GRID_IMAGE } from '../hooks/canvasViewport.js'
|
|
4
|
+
import { Tooltip } from '../utilities/Popover.jsx'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* CanvasStudio — An infinite dotted surface to arrange things on. The studio canvas: the background the rack's
|
|
8
|
+
* modules and the desk's channel strips sit on (the canvas family, 2026-10-23). kol-monitor's
|
|
9
|
+
* `RackViewport` and kol-mirror's desk each carried a copy of it — the same dot grid, the same
|
|
10
|
+
* Space-and-drag, their own zoom modifier — and `apps/rack` and `apps/mixer` run on this one now.
|
|
11
|
+
*
|
|
12
|
+
* It is the BACKGROUND ONLY: the dot grid, pan, zoom, the lock and the keys. What sits on it —
|
|
13
|
+
* modules snapping to HP, the patch cables, the workbench, the desk's embla loop — stays the
|
|
14
|
+
* app's, rendered as `children` (in the pan-zoom layer) or `overlay` (screen space, over it).
|
|
15
|
+
* `CanvasEditor` is its sibling: a fixed artboard with rulers; both read `useCanvasViewport`,
|
|
16
|
+
* so a gesture or a key means the same thing on either. The keys are `CANVAS_KEYS`.
|
|
17
|
+
*
|
|
18
|
+
* The grid: a 1px `--kol-fg-12` dot on a 36px cell, the cell scaled by the zoom and the field
|
|
19
|
+
* offset by the pan, so the surface moves under the work. A consumer may host it on a bigger box
|
|
20
|
+
* (monitor's Create paints it on the whole page) through `gridRef` — same cell, same offset.
|
|
21
|
+
*
|
|
22
|
+
* @param {boolean} grid the dot grid (default true); with `onGridChange` it is controlled
|
|
23
|
+
* @param {Function} onGridChange (on) => void — `G` and the consumer's own toggle both land here
|
|
24
|
+
* @param {boolean} locked the view lock — every pan and zoom returns early while on; with `onLockChange` controlled
|
|
25
|
+
* @param {Function} onLockChange (on) => void — `L` lands here
|
|
26
|
+
* @param {{zoom: number, x: number, y: number}} view the view, controlled; `defaultView` seeds an uncontrolled one
|
|
27
|
+
* @param {Object} defaultView `{ zoom, x, y }` (default zoom 1 at 0, 0)
|
|
28
|
+
* @param {Function} onViewChange (view) => void — persist it if you want it back
|
|
29
|
+
* @param {number} minZoom the zoom floor (default 0.1 — a 1716px rack fits a 390 phone)
|
|
30
|
+
* @param {number} maxZoom the zoom ceiling (default 2)
|
|
31
|
+
* @param {boolean} fit FIT THE HEIGHT on open (user 2026-10-23, the rack on a phone: *"youd have to start every time
|
|
32
|
+
* by zooming in"*): the zoom that puts the content's full height in the surface, clamped, at
|
|
33
|
+
* 0, 0 — and ⌘0 returns to that fit, not to 100 %. The width may overhang; pan to it
|
|
34
|
+
* @param {React.RefObject<HTMLElement>} gridRef an element to paint the grid on INSTEAD of the surface — a bigger box
|
|
35
|
+
* @param {React.RefObject<HTMLElement>} surfaceRef a ref to the surface element, for an overlay that measures against it (cables)
|
|
36
|
+
* @param {'studio'|'editor'|'none'} touch the touch policy (default `studio`: one finger pans unless on a control, two pan and pinch)
|
|
37
|
+
* @param {boolean} spaceWhenOver Space grabs only while the pointer is over the surface (an app whose Space is the transport's elsewhere)
|
|
38
|
+
* @param {string} ignore a selector whose matches keep their own wheel and touch (an inner scroller); default fields and `[data-scroll-own]`
|
|
39
|
+
* @param {Function} onSpaceTap a Space press released without a pan
|
|
40
|
+
* @param {ReactNode} backdrop a node behind the children, inside the pan-zoom layer
|
|
41
|
+
* @param {ReactNode} overlay nodes in screen space over the layer — cables, chips
|
|
42
|
+
* @param {string} className on the surface
|
|
43
|
+
* @param {Object} style on the surface, last — `overflow` and `touchAction` may be overridden here
|
|
44
|
+
* @param {ReactNode} children what sits on the surface, in the pan-zoom layer
|
|
45
|
+
*/
|
|
46
|
+
export default function CanvasStudio({
|
|
47
|
+
grid = true,
|
|
48
|
+
onGridChange,
|
|
49
|
+
locked,
|
|
50
|
+
onLockChange,
|
|
51
|
+
view,
|
|
52
|
+
defaultView,
|
|
53
|
+
onViewChange,
|
|
54
|
+
minZoom = 0.1,
|
|
55
|
+
maxZoom = 2,
|
|
56
|
+
fit = false,
|
|
57
|
+
gridRef,
|
|
58
|
+
surfaceRef,
|
|
59
|
+
touch = 'studio',
|
|
60
|
+
spaceWhenOver = false,
|
|
61
|
+
ignore,
|
|
62
|
+
onSpaceTap,
|
|
63
|
+
backdrop,
|
|
64
|
+
overlay,
|
|
65
|
+
className = '',
|
|
66
|
+
style,
|
|
67
|
+
children,
|
|
68
|
+
}) {
|
|
69
|
+
const own = useRef(null)
|
|
70
|
+
const ref = surfaceRef ?? own
|
|
71
|
+
const layer = useRef(null)
|
|
72
|
+
/* the fit: the layer's untransformed height (its own box, so zoom 1) against the surface's; nothing measurable → rest */
|
|
73
|
+
const fitView = () => {
|
|
74
|
+
const sh = ref.current?.clientHeight, h = layer.current?.scrollHeight
|
|
75
|
+
if (!fit || !sh || !h) return undefined
|
|
76
|
+
return { zoom: Math.min(maxZoom, Math.max(minZoom, sh / h)), x: 0, y: 0 }
|
|
77
|
+
}
|
|
78
|
+
const vp = useCanvasViewport({
|
|
79
|
+
ref, view, defaultView, onViewChange, minZoom, maxZoom, rest: fitView,
|
|
80
|
+
locked, onLockChange, grid, onGridChange, gridKey: true, lockKey: true,
|
|
81
|
+
touch, spaceWhenOver, ignore, onSpaceTap,
|
|
82
|
+
})
|
|
83
|
+
const { zoom, x, y } = vp.view
|
|
84
|
+
/* on open, the fit is the view — after layout, so the layer has its height */
|
|
85
|
+
useLayoutEffect(() => { if (fit) vp.reset() }, [fit]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
86
|
+
const cell = `${CANVAS_GRID_CELL * zoom}px ${CANVAS_GRID_CELL * zoom}px`
|
|
87
|
+
const gridStyle = vp.grid && !gridRef ? { backgroundImage: CANVAS_GRID_IMAGE, backgroundSize: cell, backgroundPosition: `${x}px ${y}px` } : null
|
|
88
|
+
|
|
89
|
+
/* a hosted grid rides the same zoom and pan — the host keeps its own colour, only the dots are written */
|
|
90
|
+
useLayoutEffect(() => {
|
|
91
|
+
const el = gridRef?.current
|
|
92
|
+
if (!el) return undefined
|
|
93
|
+
if (vp.grid) {
|
|
94
|
+
el.style.setProperty('background-image', CANVAS_GRID_IMAGE)
|
|
95
|
+
el.style.setProperty('background-size', cell)
|
|
96
|
+
el.style.setProperty('background-position', `${x}px ${y}px`)
|
|
97
|
+
} else {
|
|
98
|
+
el.style.removeProperty('background-image')
|
|
99
|
+
el.style.removeProperty('background-size')
|
|
100
|
+
el.style.removeProperty('background-position')
|
|
101
|
+
}
|
|
102
|
+
return undefined
|
|
103
|
+
}, [gridRef, vp.grid, cell, x, y])
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<CanvasZoomContext.Provider value={zoom}>
|
|
107
|
+
<div
|
|
108
|
+
ref={ref}
|
|
109
|
+
className={`kol-canvas-studio relative overflow-hidden select-none ${className}`.trim()}
|
|
110
|
+
style={{ flex: 1, minHeight: 0, touchAction: touch === 'none' ? undefined : 'none', cursor: vp.cursor, ...gridStyle, ...style }}
|
|
111
|
+
>
|
|
112
|
+
{/* no transition on the transform: chrome that sizes by 1/zoom updates in the same frame */}
|
|
113
|
+
<div ref={layer} style={{ transform: vp.transform, transformOrigin: '0 0', width: '100%', pointerEvents: vp.deaf ? 'none' : 'auto' }}>
|
|
114
|
+
{backdrop}
|
|
115
|
+
{children}
|
|
116
|
+
</div>
|
|
117
|
+
{overlay}
|
|
118
|
+
{vp.showFps && (
|
|
119
|
+
<div className="absolute bottom-3 right-3 z-[3]">
|
|
120
|
+
<Tooltip label="Framerate — press F to hide" asChild>
|
|
121
|
+
<span className="px-2 py-1 rounded border border-fg-08 bg-surface-secondary kol-mono-12 text-emphasis tabular-nums">{vp.fps} fps</span>
|
|
122
|
+
</Tooltip>
|
|
123
|
+
</div>
|
|
124
|
+
)}
|
|
125
|
+
</div>
|
|
126
|
+
</CanvasZoomContext.Provider>
|
|
127
|
+
)
|
|
128
|
+
}
|
|
@@ -71,9 +71,10 @@ const MODE_PLACEHOLDER = { search: 'Search…', add: 'Add…' }
|
|
|
71
71
|
* its keys in place — label left, combo right, never run. The index keeps two keys with one label apart. */
|
|
72
72
|
function shortcutFolds(shortcuts, path) {
|
|
73
73
|
return shortcuts.filter((s) => shortcutInScope(s, path)).map((s) => ({
|
|
74
|
-
/*
|
|
75
|
-
*
|
|
76
|
-
|
|
74
|
+
/* EVERY section starts OPEN (user 2026-10-23: *"you should see the shortcuts expanded, not choose navigate or
|
|
75
|
+
* help, so expand all should be collapse all, with expanded the default"*) — the footer reads Collapse all on
|
|
76
|
+
* open and folds them all in one press. Until then only a section with matching `routes` opened. */
|
|
77
|
+
id: `cat:${s.section}`, label: s.section, group: 'Shortcuts', open: true,
|
|
77
78
|
items: (s.items ?? []).map((it, i) => ({ id: it.id ?? `${i}:${it.label}`, label: it.label, hint: it.combo ?? it.keys })),
|
|
78
79
|
}))
|
|
79
80
|
}
|
|
@@ -93,10 +94,11 @@ function unfold(rows, opened) {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
/**
|
|
96
|
-
* CommandOverlay — The ⌘K overlay: search, add, go, shortcuts. Was `ShellSearchOverlay` (still exported, an
|
|
97
|
+
* CommandOverlay — The ⌘K search modal. The ⌘K overlay: search, add, go, shortcuts. Was `ShellSearchOverlay` (still exported, an
|
|
97
98
|
* alias). `mode` names what the overlay is for — `search` (default) · `add` · `shortcuts` (`go` is search's old name). In
|
|
98
99
|
* `shortcuts` it draws `shortcuts` (the AppHub keymap) with NO field, as fold rows: the current page's sections
|
|
99
|
-
* under "Shortcuts",
|
|
100
|
+
* under "Shortcuts", every one open on arrival (its keys in place, label and combo, never run), the footer's
|
|
101
|
+
* Collapse all folding them. AppHub's `S` opens this; its ⌘K opens `search` over files, pages and the same keymap.
|
|
100
102
|
*
|
|
101
103
|
* FOLD ROWS, any mode: a row with `items` is a category — Enter / → / click opens it in place, ← or Enter again
|
|
102
104
|
* closes it; its children are ordinary rows (Enter selects them). An "All" category is just a fold row holding
|
|
@@ -158,7 +158,7 @@ export default function CurveEditor({ value, onChange, stock = null, validate, k
|
|
|
158
158
|
<span className="kol-helper-10 text-meta">Curve</span>
|
|
159
159
|
<Dropdown size="sm" variant="subtle" className="w-full" options={kinds} value={kind} onChange={setKind} />
|
|
160
160
|
{!isCustom && (
|
|
161
|
-
<p className="kol-
|
|
161
|
+
<p className="kol-mono-10 text-meta">Editing “{stock.label}” forks it to a custom curve.</p>
|
|
162
162
|
)}
|
|
163
163
|
|
|
164
164
|
{kind === 'epicycle' && (
|
|
@@ -7,7 +7,7 @@ import MediaViewer from './MediaViewer.jsx'
|
|
|
7
7
|
const LABELS = { carousel: 'Carousel', grid: 'Grid', waterfall: 'Waterfall' }
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* MediaGalleryModes — One media set, three ways to
|
|
10
|
+
* MediaGalleryModes — One media set, three ways to view it. (MediaGalleryModes, kol-branding
|
|
11
11
|
* 2026-10-21 — the user: *"a carousel is a nice viewing experience, unless you are looking for
|
|
12
12
|
* specific thing, then you might wanna grid or waterfall the images"*.) The viewer switches
|
|
13
13
|
* carousel (`GalleryCarousel`) · grid · waterfall (`MediaTileGallery`); any item opens the one
|