@kolkrabbi/kol-component 0.256.0 → 0.258.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
CHANGED
package/src/organisms/Canvas.jsx
CHANGED
|
@@ -368,15 +368,27 @@ export function PanViewport({ backdrop, children }) {
|
|
|
368
368
|
* clamps, the anchor math, the wheel handling and the chip layout are the
|
|
369
369
|
* source's — fxr is the reference for this set. */
|
|
370
370
|
|
|
371
|
-
|
|
372
|
-
|
|
371
|
+
/* The clamps are in REAL terms — screen px per frame px, `zoom × fit` (CanvasViewCommands, kol-fxr
|
|
372
|
+
* 2026-10-13). They were 0.1–8 relative to the fitted frame, so a 1080 frame fitted at ~0.58 capped
|
|
373
|
+
* at ~464% real and Affinity's 800% could not be reached. */
|
|
374
|
+
const ZOOM_MIN_REAL = 0.02
|
|
375
|
+
const ZOOM_MAX_REAL = 32
|
|
376
|
+
const FIT_MARGIN = 24 /* screen px around a rect fitted by `kol:zoom-fit` */
|
|
377
|
+
|
|
378
|
+
/* The fit scale: the frame's LAYOUT width (untransformed) over its virtual width. 1 without a frame. */
|
|
379
|
+
function fitOf(node) {
|
|
380
|
+
const w = node?.querySelector('[data-canvas-frame]')?.offsetWidth
|
|
381
|
+
return w ? w / CANVAS_VIRTUAL_W : 1
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const clampZoom = (z, fit) => Math.min(ZOOM_MAX_REAL / fit, Math.max(ZOOM_MIN_REAL / fit, z))
|
|
373
385
|
|
|
374
386
|
/* Anchor a zoom change at a screen point (sx, sy relative to the viewport
|
|
375
387
|
* top-left) so the content under the cursor stays put. Transform is
|
|
376
388
|
* `translate(x,y) scale(zoom)` with origin 0,0, so screen = p*zoom + pan;
|
|
377
389
|
* inverting for a fixed p gives the new pan below. */
|
|
378
|
-
function zoomAt(v, factor, sx, sy) {
|
|
379
|
-
const z2 =
|
|
390
|
+
function zoomAt(v, factor, sx, sy, fit = 1) {
|
|
391
|
+
const z2 = clampZoom(v.zoom * factor, fit)
|
|
380
392
|
return {
|
|
381
393
|
zoom: z2,
|
|
382
394
|
x: sx - (sx - v.x) * (z2 / v.zoom),
|
|
@@ -428,7 +440,9 @@ function isTypingTarget(el) {
|
|
|
428
440
|
* `translate() scale()` on the transform layer carries both, so a consumer's
|
|
429
441
|
* screen→virtual math needs no zoom awareness. Pointer events on the
|
|
430
442
|
* transform layer disable while Space is held so layer mousedowns don't fire
|
|
431
|
-
* mid-pan. `f` toggles an fps chip beside the zoom readout.
|
|
443
|
+
* mid-pan. `f` toggles an fps chip beside the zoom readout. From outside: `kol:zoom-at`
|
|
444
|
+
* { clientX, clientY, factor } · `kol:zoom-to` { scale } (real, 1 = 100%) · `kol:zoom-fit` { to:
|
|
445
|
+
* 'frame' | 'width' | { x, y, w, h } } — window events. Zoom is clamped at 2%–3200% real.
|
|
432
446
|
*
|
|
433
447
|
* @param {ReactNode} backdrop placed behind the frame (grid / dark bg); the consumer owns its sizing — oversize it so panning never reveals an edge
|
|
434
448
|
* @param {boolean} showRulers draw the virtual-px rulers (default true)
|
|
@@ -482,11 +496,11 @@ export function PanZoomViewport({
|
|
|
482
496
|
} else if (e.key === '=' || e.key === '+') {
|
|
483
497
|
e.preventDefault()
|
|
484
498
|
const r = containerRef.current?.getBoundingClientRect()
|
|
485
|
-
setView((v) => zoomAt(v, 1.2, (r?.width ?? 0) / 2, (r?.height ?? 0) / 2))
|
|
499
|
+
setView((v) => zoomAt(v, 1.2, (r?.width ?? 0) / 2, (r?.height ?? 0) / 2, fitOf(containerRef.current)))
|
|
486
500
|
} else if (e.key === '-') {
|
|
487
501
|
e.preventDefault()
|
|
488
502
|
const r = containerRef.current?.getBoundingClientRect()
|
|
489
|
-
setView((v) => zoomAt(v, 1 / 1.2, (r?.width ?? 0) / 2, (r?.height ?? 0) / 2))
|
|
503
|
+
setView((v) => zoomAt(v, 1 / 1.2, (r?.width ?? 0) / 2, (r?.height ?? 0) / 2, fitOf(containerRef.current)))
|
|
490
504
|
}
|
|
491
505
|
}
|
|
492
506
|
}
|
|
@@ -540,7 +554,7 @@ export function PanZoomViewport({
|
|
|
540
554
|
const sx = e.clientX - rect.left
|
|
541
555
|
const sy = e.clientY - rect.top
|
|
542
556
|
if (e.ctrlKey || e.metaKey) {
|
|
543
|
-
setView((v) => zoomAt(v, Math.exp(-e.deltaY * 0.0015), sx, sy))
|
|
557
|
+
setView((v) => zoomAt(v, Math.exp(-e.deltaY * 0.0015), sx, sy, fitOf(node)))
|
|
544
558
|
} else {
|
|
545
559
|
setView((v) => ({ ...v, x: v.x - e.deltaX, y: v.y - e.deltaY }))
|
|
546
560
|
}
|
|
@@ -558,10 +572,53 @@ export function PanZoomViewport({
|
|
|
558
572
|
if (!node) return
|
|
559
573
|
const { clientX, clientY, factor } = e.detail
|
|
560
574
|
const rect = node.getBoundingClientRect()
|
|
561
|
-
setView((v) => zoomAt(v, factor, clientX - rect.left, clientY - rect.top))
|
|
575
|
+
setView((v) => zoomAt(v, factor, clientX - rect.left, clientY - rect.top, fitOf(node)))
|
|
576
|
+
}
|
|
577
|
+
/* `kol:zoom-to` { scale } — a REAL scale (1 = 100%: one screen px per frame px), about the
|
|
578
|
+
* viewport centre, so a consumer's 100–800% steps need not measure the fit. */
|
|
579
|
+
const onZoomTo = (e) => {
|
|
580
|
+
const node = containerRef.current
|
|
581
|
+
if (!node) return
|
|
582
|
+
const fit = fitOf(node)
|
|
583
|
+
const r = node.getBoundingClientRect()
|
|
584
|
+
setView((v) => zoomAt(v, e.detail.scale / (v.zoom * fit), r.width / 2, r.height / 2, fit))
|
|
585
|
+
}
|
|
586
|
+
/* `kol:zoom-fit` { to } — `'frame'` (default) is ⌘0's opening view; `'width'` fills the
|
|
587
|
+
* viewport with the frame's width, centred vertically; `{ x, y, w, h }` in frame (virtual) px
|
|
588
|
+
* fills it with that rect, FIT_MARGIN around it, centred. */
|
|
589
|
+
const onZoomFit = (e) => {
|
|
590
|
+
const node = containerRef.current
|
|
591
|
+
const frame = node?.querySelector('[data-canvas-frame]')
|
|
592
|
+
const to = e.detail?.to ?? 'frame'
|
|
593
|
+
if (!frame || to === 'frame') { setView({ zoom: 1, x: 0, y: 0 }); return }
|
|
594
|
+
const fit = fitOf(node)
|
|
595
|
+
const cr = node.getBoundingClientRect()
|
|
596
|
+
const fr = frame.getBoundingClientRect()
|
|
597
|
+
setView((v) => {
|
|
598
|
+
/* the frame's rect at rest (zoom 1, no pan), in viewport px */
|
|
599
|
+
const fx = (fr.left - cr.left - v.x) / v.zoom
|
|
600
|
+
const fy = (fr.top - cr.top - v.y) / v.zoom
|
|
601
|
+
const rect = to === 'width'
|
|
602
|
+
? { x: fx, y: fy, w: frame.offsetWidth, h: frame.offsetHeight }
|
|
603
|
+
: { x: fx + to.x * fit, y: fy + to.y * fit, w: to.w * fit, h: to.h * fit }
|
|
604
|
+
const zoom = clampZoom(to === 'width'
|
|
605
|
+
? cr.width / rect.w
|
|
606
|
+
: Math.min((cr.width - 2 * FIT_MARGIN) / rect.w, (cr.height - 2 * FIT_MARGIN) / rect.h), fit)
|
|
607
|
+
return {
|
|
608
|
+
zoom,
|
|
609
|
+
x: cr.width / 2 - (rect.x + rect.w / 2) * zoom,
|
|
610
|
+
y: cr.height / 2 - (rect.y + rect.h / 2) * zoom,
|
|
611
|
+
}
|
|
612
|
+
})
|
|
562
613
|
}
|
|
563
614
|
window.addEventListener('kol:zoom-at', onZoomEvt)
|
|
564
|
-
|
|
615
|
+
window.addEventListener('kol:zoom-to', onZoomTo)
|
|
616
|
+
window.addEventListener('kol:zoom-fit', onZoomFit)
|
|
617
|
+
return () => {
|
|
618
|
+
window.removeEventListener('kol:zoom-at', onZoomEvt)
|
|
619
|
+
window.removeEventListener('kol:zoom-to', onZoomTo)
|
|
620
|
+
window.removeEventListener('kol:zoom-fit', onZoomFit)
|
|
621
|
+
}
|
|
565
622
|
}, [])
|
|
566
623
|
|
|
567
624
|
/* `f` toggles the fps chip (measured only while shown). Guarded against
|
|
@@ -337,6 +337,7 @@ export function MediaLibraryProvider({
|
|
|
337
337
|
|
|
338
338
|
const value = useMemo(() => {
|
|
339
339
|
const annotated = objects.map((o) => ({ ...o, kind: kindOf(o) }))
|
|
340
|
+
const storageOf = new Map(objects.filter((o) => o.storageKey).map((o) => [o.key, o.storageKey]))
|
|
340
341
|
const scoped = prefix ? annotated.filter((o) => o.key.startsWith(prefix)) : annotated
|
|
341
342
|
const folders = foldersUnder(scoped, prefix)
|
|
342
343
|
/* level = the direct children; flat = every object under the prefix */
|
|
@@ -415,7 +416,9 @@ export function MediaLibraryProvider({
|
|
|
415
416
|
bucket,
|
|
416
417
|
buckets,
|
|
417
418
|
setBucket,
|
|
418
|
-
|
|
419
|
+
/* a PATH resolves to the row's `storageKey` — the object never moves, rename and move edit
|
|
420
|
+
* the row (MediaLibraryUrlOnStorageKey, kol-website 2026-10-13); no `storageKey`, the path */
|
|
421
|
+
mediaUrl: client?.mediaUrl ? (key) => client.mediaUrl(storageOf.get(key) ?? key, bucket ?? undefined) : (key) => key,
|
|
419
422
|
proxied: client?.proxied ?? ((url) => url),
|
|
420
423
|
}
|
|
421
424
|
}, [objects, prefix, flat, sort, search, kinds, paging, pageSize, loading, error, accept, client, bucket, buckets])
|
|
@@ -1081,7 +1084,7 @@ function PickerBrowse({ client, accept, onClose, onSelect, title = 'MEDIA', ...b
|
|
|
1081
1084
|
const [file, setFile] = useState(null)
|
|
1082
1085
|
const ok = !!file && acceptsKind(accept)({ ...file, kind: kindOf(file) })
|
|
1083
1086
|
const use = () => {
|
|
1084
|
-
onSelect?.(client.mediaUrl(file.key, bucket ?? undefined), { contentType: file.contentType, kind: kindOf(file) })
|
|
1087
|
+
onSelect?.(client.mediaUrl(file.storageKey ?? file.key, bucket ?? undefined), { contentType: file.contentType, kind: kindOf(file) })
|
|
1085
1088
|
onClose?.()
|
|
1086
1089
|
}
|
|
1087
1090
|
return (
|
|
@@ -244,7 +244,10 @@ function useBucketLibrary({ client, bucket, defaults, settings: controlled, onSe
|
|
|
244
244
|
const folderInfo = loaded.folders ?? {}
|
|
245
245
|
const setFolderInfo = (fn) => setLoaded((prev) => ({ ...prev, folders: fn(prev.folders ?? {}) }))
|
|
246
246
|
const error = ready ? loaded.error : null
|
|
247
|
-
|
|
247
|
+
/* a PATH resolves to the row's `storageKey` — the object never moves, rename and move edit the
|
|
248
|
+
* row (MediaLibraryUrlOnStorageKey, kol-website 2026-10-13); no `storageKey`, the path */
|
|
249
|
+
const storageOf = useMemo(() => new Map(objects.filter((o) => o.storageKey).map((o) => [o.key, o.storageKey])), [objects])
|
|
250
|
+
const mediaUrl = (key) => client?.mediaUrl?.(storageOf.get(key) ?? key, bucketId ?? undefined) ?? key
|
|
248
251
|
const downloadUrl = (key) => client?.downloadUrl?.(key, bucketId ?? undefined) ?? mediaUrl(key)
|
|
249
252
|
const writable = !!bucketMeta.writable && !!(client?.deleteObject || client?.renameObject)
|
|
250
253
|
/* A CLIENT WITH NO `mediaUrl` HAS NO URLS (kol-fxr 2026-10-08: a stored preset is not a fetchable
|