@kolkrabbi/kol-component 0.254.0 → 0.256.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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolkrabbi/kol-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.256.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-search": "^0.3.0",
|
|
30
|
+
"@kolkrabbi/kol-markdown": "^0.1.3"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@kolkrabbi/kol-icons": ">=0.22.0",
|
|
@@ -40,13 +40,16 @@ export function MenuItem({
|
|
|
40
40
|
* beside it, so media's phone `···` stood 32 next to a 26 `sm` search field. `size` pins it to the
|
|
41
41
|
* control heights (01-foundations/09-sizes: 22 · 26 · 32 · 40); `md` is the 32 it always was. */
|
|
42
42
|
size = 'md',
|
|
43
|
+
/* the panel's gap below the trigger. A trigger inside a taller bar passes a negative value so
|
|
44
|
+
* the panel's top lands on the bar's own line (MenuItemOffset, kol-fxr 2026-10-13) */
|
|
45
|
+
offset = 4,
|
|
43
46
|
}) {
|
|
44
47
|
const [open, setOpen] = useState(defaultOpen)
|
|
45
48
|
const popover = usePopover({
|
|
46
49
|
open,
|
|
47
50
|
onOpenChange: setOpen,
|
|
48
51
|
placement: align === 'end' ? 'bottom-end' : 'bottom-start',
|
|
49
|
-
offset
|
|
52
|
+
offset,
|
|
50
53
|
role: 'menu',
|
|
51
54
|
})
|
|
52
55
|
|
|
@@ -62,6 +62,7 @@ import { glyphSize } from '../hooks/glyphLadders.js'
|
|
|
62
62
|
* A variant may carry its own `onSelect()` — that row does its own thing instead of `onChange`
|
|
63
63
|
* (Text: "Text" arms the tool, "Kinetic type" inserts a layer). Without `lastPicked` the trigger
|
|
64
64
|
* remembers the last row picked from the menu (kol-fxr ToolPalette, editor-panels-the-held-specs A3).
|
|
65
|
+
* @param {string} props.placement - Where the fold opens, floating-ui's placement — a vertical `ToolPalette` passes `'right-start'` (default: 'bottom-start')
|
|
65
66
|
* @param {string} props.className - Additional classes on the trigger
|
|
66
67
|
*/
|
|
67
68
|
|
|
@@ -87,6 +88,7 @@ const SplitToolButton = ({
|
|
|
87
88
|
onTrigger,
|
|
88
89
|
disabled = false,
|
|
89
90
|
iconComponent: IconC = Icon,
|
|
91
|
+
placement = 'bottom-start',
|
|
90
92
|
className = '',
|
|
91
93
|
'aria-label': ariaLabel,
|
|
92
94
|
}) => {
|
|
@@ -94,7 +96,7 @@ const SplitToolButton = ({
|
|
|
94
96
|
const popover = usePopover({
|
|
95
97
|
open,
|
|
96
98
|
onOpenChange: setOpen,
|
|
97
|
-
placement
|
|
99
|
+
placement,
|
|
98
100
|
offset: 4,
|
|
99
101
|
role: 'menu',
|
|
100
102
|
})
|
package/src/organisms/Canvas.jsx
CHANGED
|
@@ -805,6 +805,29 @@ export function useFrameGeom(containerRef, virtualWidth = CANVAS_VIRTUAL_W) {
|
|
|
805
805
|
*/
|
|
806
806
|
export function CanvasRuler({ containerRef, virtualWidth = CANVAS_VIRTUAL_W, disabled = false }) {
|
|
807
807
|
const geom = useFrameGeom(containerRef, virtualWidth)
|
|
808
|
+
const hPointer = useRef(null)
|
|
809
|
+
const vPointer = useRef(null)
|
|
810
|
+
|
|
811
|
+
/* The pointer line on each ruler follows the container's own pointermove — written straight
|
|
812
|
+
* to the two <line>s, so a mouse move never re-renders a few hundred ticks. */
|
|
813
|
+
useEffect(() => {
|
|
814
|
+
const el = containerRef.current
|
|
815
|
+
if (!el) return
|
|
816
|
+
const move = (e) => {
|
|
817
|
+
const r = el.getBoundingClientRect()
|
|
818
|
+
hPointer.current?.setAttribute('transform', `translate(${e.clientX - r.left} 0)`)
|
|
819
|
+
vPointer.current?.setAttribute('transform', `translate(0 ${e.clientY - r.top})`)
|
|
820
|
+
hPointer.current?.setAttribute('visibility', 'visible')
|
|
821
|
+
vPointer.current?.setAttribute('visibility', 'visible')
|
|
822
|
+
}
|
|
823
|
+
const leave = () => {
|
|
824
|
+
hPointer.current?.setAttribute('visibility', 'hidden')
|
|
825
|
+
vPointer.current?.setAttribute('visibility', 'hidden')
|
|
826
|
+
}
|
|
827
|
+
el.addEventListener('pointermove', move)
|
|
828
|
+
el.addEventListener('pointerleave', leave)
|
|
829
|
+
return () => { el.removeEventListener('pointermove', move); el.removeEventListener('pointerleave', leave) }
|
|
830
|
+
}, [containerRef])
|
|
808
831
|
|
|
809
832
|
const startGuideDrag = (axis) => (e) => {
|
|
810
833
|
if (disabled || e.button !== 0) return
|
|
@@ -815,47 +838,59 @@ export function CanvasRuler({ containerRef, virtualWidth = CANVAS_VIRTUAL_W, dis
|
|
|
815
838
|
}
|
|
816
839
|
|
|
817
840
|
if (!geom || geom.pxPer <= 0) return null
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
841
|
+
/* Three ranks (CanvasRulerGraduated, kol-fxr 2026-10-13): the major at `niceStep`, the medium
|
|
842
|
+
* at half of it, the minor at a tenth — counted by index `k`, not by value, so a 25 step's
|
|
843
|
+
* 2.5 minors never round onto each other. */
|
|
844
|
+
const step = niceStep(geom.pxPer)
|
|
845
|
+
const minor = step / 10
|
|
846
|
+
const graduate = (origin, span) => {
|
|
847
|
+
const out = []
|
|
848
|
+
const last = Math.floor((span - origin) / geom.pxPer / minor)
|
|
849
|
+
for (let k = Math.ceil(-origin / geom.pxPer / minor); k <= last; k++) {
|
|
850
|
+
out.push({ k, s: origin + k * minor * geom.pxPer, rank: k % 10 === 0 ? 0 : k % 5 === 0 ? 1 : 2 })
|
|
851
|
+
}
|
|
852
|
+
return out
|
|
853
|
+
}
|
|
854
|
+
const hTicks = graduate(geom.left, geom.cw)
|
|
855
|
+
const vTicks = graduate(geom.top, geom.ch)
|
|
821
856
|
|
|
822
|
-
/*
|
|
823
|
-
*
|
|
824
|
-
|
|
825
|
-
const tickColor = 'var(--kol-fg-48)'
|
|
857
|
+
/* No band: the bar is transparent and the pasteboard shows through, one hairline at the inner
|
|
858
|
+
* edge. Ink rides the themed fg ramp so it flips with light/dark. */
|
|
859
|
+
const LEN = [RULER, 9, 4]
|
|
860
|
+
const tickColor = ['var(--kol-fg-48)', 'var(--kol-fg-24)', 'var(--kol-fg-24)']
|
|
826
861
|
const textColor = 'var(--kol-fg-64)'
|
|
827
|
-
const barBg = 'var(--kol-fg-08)'
|
|
828
862
|
const borderColor = 'var(--kol-oq-16)'
|
|
829
|
-
const labelStyle = { fontFamily: 'var(--kol-font-family-
|
|
863
|
+
const labelStyle = { fontFamily: 'var(--kol-font-family-sans)', fontSize: 10 }
|
|
864
|
+
const label = (k) => Math.round(k * minor)
|
|
830
865
|
|
|
831
866
|
return (
|
|
832
867
|
<>
|
|
833
868
|
<svg width="100%" height={RULER}
|
|
834
869
|
onPointerDown={startGuideDrag('h')}
|
|
835
870
|
style={{ position: 'absolute', top: 0, left: 0, zIndex: 4, cursor: 'row-resize' }}>
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
<
|
|
840
|
-
<text x={s + 2} y={9} fill={textColor} style={labelStyle}>{v}</text>
|
|
871
|
+
{hTicks.map(({ k, s, rank }) => (
|
|
872
|
+
<g key={k}>
|
|
873
|
+
<line x1={s} y1={RULER - LEN[rank]} x2={s} y2={RULER} stroke={tickColor[rank]} strokeWidth={1} />
|
|
874
|
+
{rank === 0 && <text x={s + 3} y={10} fill={textColor} style={labelStyle}>{label(k)}</text>}
|
|
841
875
|
</g>
|
|
842
876
|
))}
|
|
843
877
|
<line x1={0} y1={RULER - 0.5} x2="100%" y2={RULER - 0.5} stroke={borderColor} strokeWidth={1} />
|
|
878
|
+
<line ref={hPointer} x1={0.5} y1={0} x2={0.5} y2={RULER} stroke={textColor} strokeWidth={1} visibility="hidden" />
|
|
844
879
|
</svg>
|
|
845
880
|
<svg width={RULER} height="100%"
|
|
846
881
|
onPointerDown={startGuideDrag('v')}
|
|
847
882
|
style={{ position: 'absolute', top: 0, left: 0, zIndex: 4, cursor: 'col-resize' }}>
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
transform={`rotate(-90 9 ${s - 2})`}>{v}</text>
|
|
883
|
+
{vTicks.map(({ k, s, rank }) => (
|
|
884
|
+
<g key={k}>
|
|
885
|
+
<line x1={RULER - LEN[rank]} y1={s} x2={RULER} y2={s} stroke={tickColor[rank]} strokeWidth={1} />
|
|
886
|
+
{rank === 0 && <text x={10} y={s - 3} fill={textColor} style={labelStyle}
|
|
887
|
+
transform={`rotate(-90 10 ${s - 3})`}>{label(k)}</text>}
|
|
854
888
|
</g>
|
|
855
889
|
))}
|
|
856
890
|
<line x1={RULER - 0.5} y1={0} x2={RULER - 0.5} y2="100%" stroke={borderColor} strokeWidth={1} />
|
|
891
|
+
<line ref={vPointer} x1={0} y1={0.5} x2={RULER} y2={0.5} stroke={textColor} strokeWidth={1} visibility="hidden" />
|
|
857
892
|
</svg>
|
|
858
|
-
<div style={{ position: 'absolute', top: 0, left: 0, width: RULER, height: RULER,
|
|
893
|
+
<div style={{ position: 'absolute', top: 0, left: 0, width: RULER, height: RULER, borderRight: `1px solid ${borderColor}`, borderBottom: `1px solid ${borderColor}`, zIndex: 4, pointerEvents: 'none', display: 'flex', alignItems: 'center', justifyContent: 'center', color: textColor, ...labelStyle }}>px</div>
|
|
859
894
|
</>
|
|
860
895
|
)
|
|
861
896
|
}
|
|
@@ -28,6 +28,7 @@ import { Tooltip } from '../utilities/Popover.jsx'
|
|
|
28
28
|
* @param {string} props.activeId - The armed tool's id — a `tool` item's, or any variant's of a tool fold
|
|
29
29
|
* @param {Function} props.onSelect - (id) => void — a tool (or a tool variant) was armed
|
|
30
30
|
* @param {Function} props.onAction - (id) => void — an action (or an action variant) was run
|
|
31
|
+
* @param {'horizontal'|'vertical'} props.orientation - A row (default), or a one-button-wide strip: hairline dividers across it, folds opening to its right (ToolPaletteVertical, kol-fxr 2026-10-13)
|
|
31
32
|
* @param {'xs'|'sm'|'md'|'lg'} props.size - The rung — 22 · 26 · 32 · 40 (default: 'md', the source's 32)
|
|
32
33
|
* @param {ElementType} props.iconComponent - Glyph renderer receiving `{ name, size, className, style }` (default: DS `Icon`)
|
|
33
34
|
* @param {string} props.className - Additional classes on the row
|
|
@@ -39,13 +40,18 @@ const ToolPalette = ({
|
|
|
39
40
|
activeId,
|
|
40
41
|
onSelect,
|
|
41
42
|
onAction,
|
|
43
|
+
orientation = 'horizontal',
|
|
42
44
|
size = 'md',
|
|
43
45
|
iconComponent = Icon,
|
|
44
46
|
className = '',
|
|
45
|
-
}) =>
|
|
46
|
-
|
|
47
|
+
}) => {
|
|
48
|
+
const vertical = orientation === 'vertical'
|
|
49
|
+
return (
|
|
50
|
+
<div className={`kol-tool-palette flex items-center gap-1 ${vertical ? 'flex-col min-h-0 overflow-y-auto' : 'min-w-0 overflow-x-auto'} ${className}`.trim()}>
|
|
47
51
|
{items.map((it, i) => {
|
|
48
|
-
if (it.kind === 'divider') return
|
|
52
|
+
if (it.kind === 'divider') return vertical
|
|
53
|
+
? <Divider key={`d${i}`} variant="horizontal" className="my-1.5 shrink-0 self-stretch" />
|
|
54
|
+
: <Divider key={`d${i}`} variant="vertical" height={20} className="mx-1.5 shrink-0" />
|
|
49
55
|
if (it.kind === 'split') {
|
|
50
56
|
const variants = (it.variants ?? []).map((v) => (v.action && !it.action ? { ...v, onSelect: () => onAction?.(v.id) } : v))
|
|
51
57
|
const run = (id) => (it.action ? onAction : onSelect)?.(id)
|
|
@@ -53,7 +59,8 @@ const ToolPalette = ({
|
|
|
53
59
|
<SplitToolButton key={it.id} variants={variants} value={activeId} size={size} iconComponent={iconComponent}
|
|
54
60
|
active={!it.action && variants.some((v) => v.id === activeId && !v.action)}
|
|
55
61
|
onChange={run} onTrigger={it.action ? run : undefined}
|
|
56
|
-
disabled={it.disabled} blurOnClick aria-label={it.label}
|
|
62
|
+
disabled={it.disabled} blurOnClick aria-label={it.label}
|
|
63
|
+
placement={vertical ? 'right-start' : undefined} />
|
|
57
64
|
)
|
|
58
65
|
}
|
|
59
66
|
const isTool = it.kind === 'tool'
|
|
@@ -68,6 +75,7 @@ const ToolPalette = ({
|
|
|
68
75
|
)
|
|
69
76
|
})}
|
|
70
77
|
</div>
|
|
71
|
-
)
|
|
78
|
+
)
|
|
79
|
+
}
|
|
72
80
|
|
|
73
81
|
export default ToolPalette
|
|
@@ -95,6 +95,17 @@ export default function SelectionOverlay({
|
|
|
95
95
|
/* half the rotated box's axis-aligned height — the label hangs below that, centred */
|
|
96
96
|
const rad = (rot * Math.PI) / 180
|
|
97
97
|
const halfBoundsH = (Math.abs(w * Math.sin(rad)) + Math.abs(h * Math.cos(rad))) / 2
|
|
98
|
+
/* …and clear the rotate handle when the box points down (SelectionOverlayLabelClearsRotateHandle,
|
|
99
|
+
* kol-fxr 2026-10-13: at 180° the handle sat on the label's ×). The handle's centre, from the box
|
|
100
|
+
* centre, after the chrome's rotation; if it falls in the label's column below the box, the label
|
|
101
|
+
* hangs under the handle instead. Label width estimated from its text — mono, 12px. */
|
|
102
|
+
const labelText = showLabel ? labelFormatter(box) : ''
|
|
103
|
+
const handleDy = -(h / 2) - ROTATE_OFFSET / zoom + size / 2
|
|
104
|
+
const handleX = -handleDy * Math.sin(rad)
|
|
105
|
+
const handleY = handleDy * Math.cos(rad)
|
|
106
|
+
const labelHalfW = (labelText.length * 7.5 + 12) / 2 / zoom
|
|
107
|
+
const clearsHandle = rotate && handleY > 0 && Math.abs(handleX) < labelHalfW + size / 2
|
|
108
|
+
const labelBelow = Math.max(halfBoundsH, clearsHandle ? handleY + size / 2 : 0)
|
|
98
109
|
|
|
99
110
|
return (
|
|
100
111
|
<>
|
|
@@ -162,7 +173,7 @@ export default function SelectionOverlay({
|
|
|
162
173
|
style={{
|
|
163
174
|
position: 'absolute',
|
|
164
175
|
left: x + w / 2,
|
|
165
|
-
top: y + h / 2 +
|
|
176
|
+
top: y + h / 2 + labelBelow + 6 / zoom,
|
|
166
177
|
/* counter-scale, not just a smaller font: padding, radius and
|
|
167
178
|
* tracking have to stay screen-constant too */
|
|
168
179
|
transform: `translateX(-50%) scale(${1 / zoom})`,
|
|
@@ -179,7 +190,7 @@ export default function SelectionOverlay({
|
|
|
179
190
|
zIndex: 100,
|
|
180
191
|
}}
|
|
181
192
|
>
|
|
182
|
-
{
|
|
193
|
+
{labelText}
|
|
183
194
|
</span>
|
|
184
195
|
)}
|
|
185
196
|
</>
|