@gregogun/radial-menu 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +123 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +763 -0
- package/dist/modules/radialMenu/RadialMenu.d.ts +60 -0
- package/dist/modules/radialMenu/geometry.d.ts +47 -0
- package/dist/modules/radialMenu/shared/context.d.ts +6 -0
- package/dist/modules/radialMenu/shared/theme.d.ts +8 -0
- package/dist/modules/radialMenu/skin/RootRing.d.ts +29 -0
- package/dist/modules/radialMenu/skin/SubBand.d.ts +17 -0
- package/dist/modules/radialMenu/useAngleRouter.d.ts +45 -0
- package/dist/modules/radialMenu/wiring/WedgeItem.d.ts +46 -0
- package/dist/radial-menu.css +152 -0
- package/dist/types.d.ts +54 -0
- package/package.json +77 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,763 @@
|
|
|
1
|
+
import { jsxs as Q, Fragment as Sn, jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect as _, useMemo as ln, useState as cn, useRef as C, useCallback as U, createContext as $n, useContext as An, useImperativeHandle as On } from "react";
|
|
3
|
+
import { ContextMenu as z } from "@base-ui/react/context-menu";
|
|
4
|
+
import { useReducedMotion as hn, useSpring as fn, useTransform as gn, LazyMotion as pn, domAnimation as mn, m as bn } from "motion/react";
|
|
5
|
+
const V = 90, dn = (n) => {
|
|
6
|
+
const t = n % 360;
|
|
7
|
+
return t < 0 ? t + 360 : t;
|
|
8
|
+
}, B = (n, t, e, i) => {
|
|
9
|
+
const s = i * Math.PI / 180;
|
|
10
|
+
return [n + e * Math.cos(s), t + e * Math.sin(s)];
|
|
11
|
+
}, En = (n, t, e, i, s) => {
|
|
12
|
+
const c = s - i > 180 ? 1 : 0, [o, h] = B(n, t, e, i), [g, a] = B(n, t, e, s);
|
|
13
|
+
return `M ${o} ${h} A ${e} ${e} 0 ${c} 1 ${g} ${a}`;
|
|
14
|
+
}, J = (n, t, e, i, s, c) => {
|
|
15
|
+
const o = c - s > 180 ? 1 : 0, [h, g] = B(n, t, i, s), [a, d] = B(n, t, i, c), [r, A] = B(n, t, e, c), [b, R] = B(n, t, e, s);
|
|
16
|
+
return `M ${h} ${g} A ${i} ${i} 0 ${o} 1 ${a} ${d} L ${r} ${A} A ${e} ${e} 0 ${o} 0 ${b} ${R} Z`;
|
|
17
|
+
}, yn = (n, t, e, i, s, c, o) => {
|
|
18
|
+
const h = Math.max(2, Math.ceil(Math.abs(o - c) / 6)), g = [], a = (r) => `${(r / n * 100).toFixed(2)}%`, d = (r, A) => {
|
|
19
|
+
const [b, R] = B(t, e, r, A);
|
|
20
|
+
g.push(`${a(b)} ${a(R)}`);
|
|
21
|
+
};
|
|
22
|
+
for (let r = 0; r <= h; r++) d(s, c + (o - c) * r / h);
|
|
23
|
+
for (let r = h; r >= 0; r--) d(i, c + (o - c) * r / h);
|
|
24
|
+
return `polygon(${g.join(", ")})`;
|
|
25
|
+
};
|
|
26
|
+
function xn(n, t, e) {
|
|
27
|
+
const { count: i, layout: s, direction: c, size: o, ringGap: h, submenuThickness: g } = n, a = 360 / i, d = V + t * a, r = s === "full" ? a : a / 2, A = Math.min(r * e, 360), R = c === "ccw" ? d + a - A : d, y = (o + 24) / 2 + h, M = y + o * g;
|
|
28
|
+
return {
|
|
29
|
+
count: e,
|
|
30
|
+
startAngle: R,
|
|
31
|
+
span: A,
|
|
32
|
+
subStep: A / e,
|
|
33
|
+
innerR: y,
|
|
34
|
+
outerR: M
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function kn(n, t) {
|
|
38
|
+
const e = n.length;
|
|
39
|
+
return (i) => {
|
|
40
|
+
var c;
|
|
41
|
+
const s = ((c = n[i]) == null ? void 0 : c.submenu) ?? [];
|
|
42
|
+
return s.length ? xn({ ...t, count: e }, i, s.length) : null;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const m = {
|
|
46
|
+
c1: "var(--radial-1, #fcfcfd)",
|
|
47
|
+
c2: "var(--radial-2, #f9f9fb)",
|
|
48
|
+
c3: "var(--radial-3, #f0f0f3)",
|
|
49
|
+
c4: "var(--radial-4, #e8e8ec)",
|
|
50
|
+
c11: "var(--radial-11, #60646c)",
|
|
51
|
+
c12: "var(--radial-12, #1c2024)"
|
|
52
|
+
}, Tn = 0.072;
|
|
53
|
+
function Cn({
|
|
54
|
+
selected: n,
|
|
55
|
+
count: t,
|
|
56
|
+
c: e,
|
|
57
|
+
outerR: i,
|
|
58
|
+
step: s
|
|
59
|
+
}) {
|
|
60
|
+
const c = hn(), o = fn(n ?? 0, { damping: 15, stiffness: 180 });
|
|
61
|
+
_(() => {
|
|
62
|
+
if (n === null) return;
|
|
63
|
+
const d = o.get(), r = n + t * Math.round((d - n) / t);
|
|
64
|
+
c ? o.jump(r) : o.set(r);
|
|
65
|
+
}, [n, o, t, c]);
|
|
66
|
+
const h = i + 4, g = i + 12, a = gn(
|
|
67
|
+
o,
|
|
68
|
+
(d) => J(
|
|
69
|
+
e,
|
|
70
|
+
e,
|
|
71
|
+
h,
|
|
72
|
+
g,
|
|
73
|
+
V + d * s,
|
|
74
|
+
V + (d + 1) * s
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
return /* @__PURE__ */ l(pn, { features: mn, strict: !0, children: /* @__PURE__ */ l(
|
|
78
|
+
bn.path,
|
|
79
|
+
{
|
|
80
|
+
d: a,
|
|
81
|
+
fill: m.c11,
|
|
82
|
+
initial: { opacity: 0 },
|
|
83
|
+
animate: { opacity: n !== null ? 1 : 0 },
|
|
84
|
+
transition: { duration: c ? 0 : 0.15 }
|
|
85
|
+
}
|
|
86
|
+
) });
|
|
87
|
+
}
|
|
88
|
+
function In({
|
|
89
|
+
menuItems: n,
|
|
90
|
+
selected: t,
|
|
91
|
+
centerLabel: e,
|
|
92
|
+
geometry: i,
|
|
93
|
+
children: s
|
|
94
|
+
}) {
|
|
95
|
+
const { box: c, c: o, innerR: h, outerR: g, step: a, iconR: d } = i, r = n.length;
|
|
96
|
+
return /* @__PURE__ */ Q(Sn, { children: [
|
|
97
|
+
/* @__PURE__ */ l(
|
|
98
|
+
"circle",
|
|
99
|
+
{
|
|
100
|
+
cx: o,
|
|
101
|
+
cy: o,
|
|
102
|
+
r: (c + 24) / 2,
|
|
103
|
+
fill: m.c2,
|
|
104
|
+
stroke: m.c4,
|
|
105
|
+
strokeWidth: 1
|
|
106
|
+
}
|
|
107
|
+
),
|
|
108
|
+
/* @__PURE__ */ l("circle", { cx: o, cy: o, r: (c + 8) / 2, fill: m.c1 }),
|
|
109
|
+
n.map((A, b) => {
|
|
110
|
+
const R = V + b * a, S = R + a, y = R + a / 2, [M, w] = B(o, o, d, y);
|
|
111
|
+
return /* @__PURE__ */ Q("g", { children: [
|
|
112
|
+
/* @__PURE__ */ l(
|
|
113
|
+
"path",
|
|
114
|
+
{
|
|
115
|
+
d: J(o, o, h, g, R, S),
|
|
116
|
+
stroke: m.c3,
|
|
117
|
+
strokeWidth: 1,
|
|
118
|
+
className: "radial-wedge",
|
|
119
|
+
"data-selected": t === b || void 0,
|
|
120
|
+
style: { fill: t === b ? m.c3 : m.c2 }
|
|
121
|
+
}
|
|
122
|
+
),
|
|
123
|
+
/* @__PURE__ */ l(
|
|
124
|
+
"foreignObject",
|
|
125
|
+
{
|
|
126
|
+
x: M - c / 2,
|
|
127
|
+
y: w - c / 2,
|
|
128
|
+
width: c,
|
|
129
|
+
height: c,
|
|
130
|
+
className: "radial-no-pointer",
|
|
131
|
+
children: /* @__PURE__ */ l(
|
|
132
|
+
"span",
|
|
133
|
+
{
|
|
134
|
+
"aria-hidden": !0,
|
|
135
|
+
className: "radial-icon",
|
|
136
|
+
style: {
|
|
137
|
+
fontSize: c * Tn,
|
|
138
|
+
color: t === b ? m.c12 : m.c11
|
|
139
|
+
},
|
|
140
|
+
children: A.icon
|
|
141
|
+
}
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
)
|
|
145
|
+
] }, A.label);
|
|
146
|
+
}),
|
|
147
|
+
/* @__PURE__ */ l(
|
|
148
|
+
Cn,
|
|
149
|
+
{
|
|
150
|
+
selected: t,
|
|
151
|
+
count: r,
|
|
152
|
+
c: o,
|
|
153
|
+
outerR: g,
|
|
154
|
+
step: a
|
|
155
|
+
}
|
|
156
|
+
),
|
|
157
|
+
/* @__PURE__ */ l("circle", { cx: o, cy: o, r: h, fill: m.c1, stroke: m.c3 }),
|
|
158
|
+
/* @__PURE__ */ l("circle", { cx: o, cy: o, r: h - 5, fill: m.c1, stroke: m.c3 }),
|
|
159
|
+
e && /* @__PURE__ */ l(
|
|
160
|
+
"text",
|
|
161
|
+
{
|
|
162
|
+
x: o,
|
|
163
|
+
y: o,
|
|
164
|
+
textAnchor: "middle",
|
|
165
|
+
dominantBaseline: "central",
|
|
166
|
+
className: "radial-label",
|
|
167
|
+
style: { fontSize: 12, fill: m.c12 },
|
|
168
|
+
children: e
|
|
169
|
+
}
|
|
170
|
+
),
|
|
171
|
+
s
|
|
172
|
+
] });
|
|
173
|
+
}
|
|
174
|
+
function Nn(n, t) {
|
|
175
|
+
return (e) => {
|
|
176
|
+
t(e), typeof n == "function" ? n(e) : n && (n.current = e);
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function Rn({
|
|
180
|
+
label: n,
|
|
181
|
+
clip: t,
|
|
182
|
+
highlighted: e,
|
|
183
|
+
onHi: i,
|
|
184
|
+
captureRef: s,
|
|
185
|
+
itemProps: c,
|
|
186
|
+
extraProps: o
|
|
187
|
+
}) {
|
|
188
|
+
return _(() => {
|
|
189
|
+
i(e);
|
|
190
|
+
}, [e, i]), /* @__PURE__ */ l(
|
|
191
|
+
"div",
|
|
192
|
+
{
|
|
193
|
+
...c,
|
|
194
|
+
...o,
|
|
195
|
+
ref: s ? Nn(c.ref, s) : c.ref,
|
|
196
|
+
"aria-label": n,
|
|
197
|
+
className: "radial-hit",
|
|
198
|
+
style: { clipPath: t, WebkitClipPath: t }
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
function Pn(n, t, e, i) {
|
|
203
|
+
return (s, c) => /* @__PURE__ */ l(
|
|
204
|
+
Rn,
|
|
205
|
+
{
|
|
206
|
+
label: n,
|
|
207
|
+
clip: t,
|
|
208
|
+
highlighted: c.highlighted,
|
|
209
|
+
onHi: e,
|
|
210
|
+
captureRef: i,
|
|
211
|
+
itemProps: s
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
function wn({ item: n, clip: t, onHi: e, captureRef: i, box: s }) {
|
|
216
|
+
return /* @__PURE__ */ l(
|
|
217
|
+
"foreignObject",
|
|
218
|
+
{
|
|
219
|
+
x: 0,
|
|
220
|
+
y: 0,
|
|
221
|
+
width: s,
|
|
222
|
+
height: s,
|
|
223
|
+
className: "radial-no-pointer",
|
|
224
|
+
children: /* @__PURE__ */ l(
|
|
225
|
+
z.Item,
|
|
226
|
+
{
|
|
227
|
+
closeOnClick: n.closeOnSelect !== !1,
|
|
228
|
+
onClick: () => {
|
|
229
|
+
var c;
|
|
230
|
+
return (c = n.onSelect) == null ? void 0 : c.call(n);
|
|
231
|
+
},
|
|
232
|
+
render: Pn(n.label, t, e, i)
|
|
233
|
+
}
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
function zn({
|
|
239
|
+
item: n,
|
|
240
|
+
index: t,
|
|
241
|
+
clip: e,
|
|
242
|
+
onHi: i,
|
|
243
|
+
captureRef: s,
|
|
244
|
+
box: c,
|
|
245
|
+
open: o,
|
|
246
|
+
onOpen: h,
|
|
247
|
+
onClose: g,
|
|
248
|
+
children: a
|
|
249
|
+
}) {
|
|
250
|
+
return /* @__PURE__ */ l(
|
|
251
|
+
"foreignObject",
|
|
252
|
+
{
|
|
253
|
+
x: 0,
|
|
254
|
+
y: 0,
|
|
255
|
+
width: c,
|
|
256
|
+
height: c,
|
|
257
|
+
className: "radial-no-pointer",
|
|
258
|
+
children: /* @__PURE__ */ Q(
|
|
259
|
+
z.SubmenuRoot,
|
|
260
|
+
{
|
|
261
|
+
open: o,
|
|
262
|
+
onOpenChange: (d, r) => {
|
|
263
|
+
if (d) {
|
|
264
|
+
r.reason === "trigger-press" && h(t);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
(r.reason === "escape-key" || r.reason === "outside-press" || r.reason === "item-press" || r.reason === "close-press") && g();
|
|
268
|
+
},
|
|
269
|
+
children: [
|
|
270
|
+
/* @__PURE__ */ l(
|
|
271
|
+
z.SubmenuTrigger,
|
|
272
|
+
{
|
|
273
|
+
render: (d, r) => /* @__PURE__ */ l(
|
|
274
|
+
Rn,
|
|
275
|
+
{
|
|
276
|
+
label: n.label,
|
|
277
|
+
clip: e,
|
|
278
|
+
highlighted: r.highlighted || r.open,
|
|
279
|
+
onHi: i,
|
|
280
|
+
captureRef: s,
|
|
281
|
+
itemProps: d,
|
|
282
|
+
extraProps: { "aria-haspopup": "menu" }
|
|
283
|
+
}
|
|
284
|
+
)
|
|
285
|
+
}
|
|
286
|
+
),
|
|
287
|
+
/* @__PURE__ */ l(z.Portal, { children: /* @__PURE__ */ l(
|
|
288
|
+
z.Positioner,
|
|
289
|
+
{
|
|
290
|
+
align: "center",
|
|
291
|
+
side: "top",
|
|
292
|
+
sideOffset: ({ positioner: d, anchor: r }) => -d.height / 2 - r.height / 2,
|
|
293
|
+
style: { zIndex: 10, pointerEvents: "none", outline: "none" },
|
|
294
|
+
children: /* @__PURE__ */ l(
|
|
295
|
+
z.Popup,
|
|
296
|
+
{
|
|
297
|
+
className: "radial-band-popup",
|
|
298
|
+
children: a
|
|
299
|
+
}
|
|
300
|
+
)
|
|
301
|
+
}
|
|
302
|
+
) })
|
|
303
|
+
]
|
|
304
|
+
}
|
|
305
|
+
)
|
|
306
|
+
}
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
const Fn = 0.24;
|
|
310
|
+
function Hn({
|
|
311
|
+
parent: n,
|
|
312
|
+
parentIndex: t,
|
|
313
|
+
count: e,
|
|
314
|
+
layout: i,
|
|
315
|
+
direction: s,
|
|
316
|
+
size: c,
|
|
317
|
+
ringGap: o,
|
|
318
|
+
submenuThickness: h,
|
|
319
|
+
captureChild: g,
|
|
320
|
+
onActiveLabel: a
|
|
321
|
+
}) {
|
|
322
|
+
const d = ln(() => n.submenu ?? [], [n.submenu]), [r, A] = cn(null), { startAngle: b, span: R, subStep: S, innerR: y, outerR: M } = xn(
|
|
323
|
+
{ count: e, layout: i, direction: s, size: c, ringGap: o, submenuThickness: h },
|
|
324
|
+
t,
|
|
325
|
+
d.length
|
|
326
|
+
), w = R >= 360 - 0.5, T = s === "ccw", O = ln(() => T ? [...d] : d, [T, d]), E = M * 2, f = M, F = hn(), H = fn(r ?? 0, { damping: 22, stiffness: 260 });
|
|
327
|
+
_(() => {
|
|
328
|
+
if (r === null) return;
|
|
329
|
+
const v = w ? r + d.length * Math.round((H.get() - r) / d.length) : r;
|
|
330
|
+
F ? H.jump(v) : H.set(v);
|
|
331
|
+
}, [r, H, w, d.length, F]), _(() => {
|
|
332
|
+
var v;
|
|
333
|
+
a(r !== null ? ((v = O[r]) == null ? void 0 : v.label) ?? null : null);
|
|
334
|
+
}, [r, O, a]), _(() => () => a(null), [a]);
|
|
335
|
+
const j = M + 5, k = M + 12, L = gn(
|
|
336
|
+
H,
|
|
337
|
+
(v) => J(
|
|
338
|
+
f,
|
|
339
|
+
f,
|
|
340
|
+
j,
|
|
341
|
+
k,
|
|
342
|
+
b + v * S,
|
|
343
|
+
b + (v + 1) * S
|
|
344
|
+
)
|
|
345
|
+
);
|
|
346
|
+
return /* @__PURE__ */ l("div", { className: "radial-band-box", style: { width: E, height: E }, children: /* @__PURE__ */ Q(
|
|
347
|
+
"svg",
|
|
348
|
+
{
|
|
349
|
+
"data-radial-band": !0,
|
|
350
|
+
width: E,
|
|
351
|
+
height: E,
|
|
352
|
+
viewBox: `0 0 ${E} ${E}`,
|
|
353
|
+
className: "radial-band-svg",
|
|
354
|
+
children: [
|
|
355
|
+
O.map((v, p) => {
|
|
356
|
+
const $ = b + p * S, I = $ + S, D = ($ + I) / 2, [N, W] = B(f, f, (y + M) / 2, D);
|
|
357
|
+
return /* @__PURE__ */ Q("g", { children: [
|
|
358
|
+
/* @__PURE__ */ l(
|
|
359
|
+
"path",
|
|
360
|
+
{
|
|
361
|
+
d: J(f, f, y, M, $, I),
|
|
362
|
+
className: "radial-wedge",
|
|
363
|
+
"data-selected": r === p || void 0,
|
|
364
|
+
style: { fill: r === p ? m.c3 : m.c2 }
|
|
365
|
+
}
|
|
366
|
+
),
|
|
367
|
+
/* @__PURE__ */ l(
|
|
368
|
+
"path",
|
|
369
|
+
{
|
|
370
|
+
d: J(f, f, M, j, $, I),
|
|
371
|
+
fill: m.c1
|
|
372
|
+
}
|
|
373
|
+
),
|
|
374
|
+
/* @__PURE__ */ l(
|
|
375
|
+
"path",
|
|
376
|
+
{
|
|
377
|
+
d: J(f, f, j, k, $, I),
|
|
378
|
+
fill: m.c2
|
|
379
|
+
}
|
|
380
|
+
),
|
|
381
|
+
[
|
|
382
|
+
{ r: M, strong: !0 },
|
|
383
|
+
{ r: k, strong: !0 }
|
|
384
|
+
].map(({ r: q, strong: X }) => /* @__PURE__ */ l(
|
|
385
|
+
"path",
|
|
386
|
+
{
|
|
387
|
+
d: En(f, f, q, $, I),
|
|
388
|
+
fill: "none",
|
|
389
|
+
stroke: X ? m.c4 : m.c3,
|
|
390
|
+
strokeWidth: 1
|
|
391
|
+
},
|
|
392
|
+
q
|
|
393
|
+
)),
|
|
394
|
+
/* @__PURE__ */ l(
|
|
395
|
+
"foreignObject",
|
|
396
|
+
{
|
|
397
|
+
x: N - E / 2,
|
|
398
|
+
y: W - E / 2,
|
|
399
|
+
width: E,
|
|
400
|
+
height: E,
|
|
401
|
+
className: "radial-no-pointer",
|
|
402
|
+
children: /* @__PURE__ */ l(
|
|
403
|
+
"span",
|
|
404
|
+
{
|
|
405
|
+
"aria-hidden": !0,
|
|
406
|
+
className: "radial-icon",
|
|
407
|
+
style: {
|
|
408
|
+
fontSize: (M - y) * Fn,
|
|
409
|
+
color: r === p ? m.c12 : m.c11
|
|
410
|
+
},
|
|
411
|
+
children: v.icon
|
|
412
|
+
}
|
|
413
|
+
)
|
|
414
|
+
}
|
|
415
|
+
)
|
|
416
|
+
] }, v.label);
|
|
417
|
+
}),
|
|
418
|
+
Array.from(
|
|
419
|
+
{ length: w ? O.length : O.length - 1 },
|
|
420
|
+
(v, p) => {
|
|
421
|
+
const $ = (b + (p + 1) * S) * Math.PI / 180;
|
|
422
|
+
return /* @__PURE__ */ l(
|
|
423
|
+
"line",
|
|
424
|
+
{
|
|
425
|
+
x1: f + y * Math.cos($),
|
|
426
|
+
y1: f + y * Math.sin($),
|
|
427
|
+
x2: f + M * Math.cos($),
|
|
428
|
+
y2: f + M * Math.sin($),
|
|
429
|
+
stroke: m.c3,
|
|
430
|
+
strokeWidth: 1
|
|
431
|
+
},
|
|
432
|
+
`divider-${p}`
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
),
|
|
436
|
+
/* @__PURE__ */ l(pn, { features: mn, strict: !0, children: /* @__PURE__ */ l(
|
|
437
|
+
bn.path,
|
|
438
|
+
{
|
|
439
|
+
d: L,
|
|
440
|
+
fill: m.c11,
|
|
441
|
+
initial: { opacity: 0 },
|
|
442
|
+
animate: { opacity: r !== null ? 1 : 0 },
|
|
443
|
+
transition: { duration: F ? 0 : 0.15 }
|
|
444
|
+
}
|
|
445
|
+
) }),
|
|
446
|
+
O.map((v, p) => {
|
|
447
|
+
const $ = b + p * S, I = $ + S, D = yn(E, f, f, y, M, $, I);
|
|
448
|
+
return /* @__PURE__ */ l(
|
|
449
|
+
wn,
|
|
450
|
+
{
|
|
451
|
+
item: v,
|
|
452
|
+
clip: D,
|
|
453
|
+
box: E,
|
|
454
|
+
onHi: (N) => A((W) => N ? p : W === p ? null : W),
|
|
455
|
+
captureRef: (N) => g(p, N)
|
|
456
|
+
},
|
|
457
|
+
v.label
|
|
458
|
+
);
|
|
459
|
+
})
|
|
460
|
+
]
|
|
461
|
+
}
|
|
462
|
+
) });
|
|
463
|
+
}
|
|
464
|
+
function Dn(n) {
|
|
465
|
+
const t = C([]), e = C([]), i = C(null);
|
|
466
|
+
i.current !== n.openSub && (e.current = [], i.current = n.openSub);
|
|
467
|
+
const s = C(n);
|
|
468
|
+
s.current = n;
|
|
469
|
+
const c = C(null), o = C(null), h = U(() => {
|
|
470
|
+
c.current !== null && (clearTimeout(c.current), c.current = null), o.current = null;
|
|
471
|
+
}, []), g = C(null), a = C(null), d = U((r) => {
|
|
472
|
+
var M;
|
|
473
|
+
if ((M = a.current) == null || M.call(a), a.current = null, h(), g.current = null, !r) return;
|
|
474
|
+
const A = () => {
|
|
475
|
+
const w = document.activeElement;
|
|
476
|
+
w && (t.current.includes(w) || e.current.includes(w)) && w.blur();
|
|
477
|
+
}, b = (w) => {
|
|
478
|
+
!w || w === g.current || (g.current = w, w.dispatchEvent(
|
|
479
|
+
new MouseEvent("mousemove", { bubbles: !0, cancelable: !0 })
|
|
480
|
+
));
|
|
481
|
+
};
|
|
482
|
+
let R = null;
|
|
483
|
+
const S = (w) => {
|
|
484
|
+
var en;
|
|
485
|
+
const { menuItems: T, count: O, box: E, innerR: f, outerR: F, step: H, openDelay: j, subRadii: k, setOpenSub: L, onArm: v, onCancel: p } = s.current;
|
|
486
|
+
R === null && (R = r.getBoundingClientRect(), requestAnimationFrame(() => {
|
|
487
|
+
R = null;
|
|
488
|
+
}));
|
|
489
|
+
const $ = R.width / E, I = R.left + R.width / 2, D = R.top + R.height / 2, N = w.clientX - I, W = w.clientY - D, q = Math.hypot(N, W) / $, X = Math.atan2(W, N) * 180 / Math.PI, nn = i.current;
|
|
490
|
+
if (q < f) {
|
|
491
|
+
h(), nn !== null && L(null), A(), p == null || p(), g.current = null;
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
if (v == null || v(), nn !== null) {
|
|
495
|
+
const u = k(nn);
|
|
496
|
+
if (u && q >= F) {
|
|
497
|
+
const x = dn(X - u.startAngle);
|
|
498
|
+
if (u.span >= 360 - 0.5) {
|
|
499
|
+
const K = Math.min(Math.floor(x / u.subStep), u.count - 1);
|
|
500
|
+
b(e.current[K]);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
const P = x >= 180 ? x - 360 : x, rn = H;
|
|
504
|
+
if (P >= -rn && P < u.span + rn) {
|
|
505
|
+
const K = P < 0 ? 0 : Math.min(Math.floor(P / u.subStep), u.count - 1);
|
|
506
|
+
b(e.current[K]);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
const on = dn(X - V), G = Math.min(Math.floor(on / H), O - 1);
|
|
512
|
+
b(t.current[G]);
|
|
513
|
+
const Y = !!((en = T[G].submenu) != null && en.length);
|
|
514
|
+
Y && i.current !== G ? o.current !== G && (h(), o.current = G, c.current = window.setTimeout(() => {
|
|
515
|
+
L(G), h();
|
|
516
|
+
}, j)) : Y || (h(), i.current !== null && L(null));
|
|
517
|
+
}, y = (w) => {
|
|
518
|
+
var T, O;
|
|
519
|
+
w.key !== "Escape" && ((O = (T = s.current).onArm) == null || O.call(T));
|
|
520
|
+
};
|
|
521
|
+
window.addEventListener("pointermove", S), window.addEventListener("keydown", y, !0), a.current = () => {
|
|
522
|
+
window.removeEventListener("pointermove", S), window.removeEventListener("keydown", y, !0);
|
|
523
|
+
};
|
|
524
|
+
}, [h]);
|
|
525
|
+
return _(
|
|
526
|
+
() => () => {
|
|
527
|
+
var r;
|
|
528
|
+
(r = a.current) == null || r.call(a), h();
|
|
529
|
+
},
|
|
530
|
+
[h]
|
|
531
|
+
), { attachRouter: d, rootEls: t, subEls: e };
|
|
532
|
+
}
|
|
533
|
+
const Mn = $n(
|
|
534
|
+
null
|
|
535
|
+
);
|
|
536
|
+
function Wn() {
|
|
537
|
+
const n = An(Mn);
|
|
538
|
+
if (n === null)
|
|
539
|
+
throw new Error("RadialMenu.Trigger must be rendered inside RadialMenu.Root");
|
|
540
|
+
return n;
|
|
541
|
+
}
|
|
542
|
+
const Z = {
|
|
543
|
+
size: 250,
|
|
544
|
+
layout: "halved",
|
|
545
|
+
direction: "cw",
|
|
546
|
+
submenuThickness: 0.3,
|
|
547
|
+
ringGap: 8,
|
|
548
|
+
openDelay: 280
|
|
549
|
+
};
|
|
550
|
+
function Bn(n) {
|
|
551
|
+
var en;
|
|
552
|
+
const t = n.items, e = n.size ?? Z.size, i = n.layout ?? Z.layout, s = n.direction ?? Z.direction, c = n.submenuThickness ?? Z.submenuThickness, o = n.ringGap ?? Z.ringGap, h = n.openDelay ?? Z.openDelay, g = t.length, a = C(null), d = n.children != null, r = C(null), A = U((u) => {
|
|
553
|
+
a.current = u;
|
|
554
|
+
}, []), b = U((u, x) => {
|
|
555
|
+
const P = a.current;
|
|
556
|
+
P && P.dispatchEvent(
|
|
557
|
+
new MouseEvent("contextmenu", {
|
|
558
|
+
bubbles: !0,
|
|
559
|
+
cancelable: !0,
|
|
560
|
+
clientX: u,
|
|
561
|
+
clientY: x
|
|
562
|
+
})
|
|
563
|
+
);
|
|
564
|
+
}, []);
|
|
565
|
+
On(
|
|
566
|
+
n.actionsRef,
|
|
567
|
+
() => ({
|
|
568
|
+
open: b,
|
|
569
|
+
openAtElement: (u) => {
|
|
570
|
+
const x = u.getBoundingClientRect();
|
|
571
|
+
b(x.left + x.width / 2, x.top + x.height / 2);
|
|
572
|
+
},
|
|
573
|
+
close: () => {
|
|
574
|
+
var u;
|
|
575
|
+
return (u = r.current) == null ? void 0 : u.close();
|
|
576
|
+
}
|
|
577
|
+
}),
|
|
578
|
+
[b]
|
|
579
|
+
);
|
|
580
|
+
const R = ln(() => ({ registerTrigger: A }), [A]), S = C(!1), y = C(null), M = U(() => {
|
|
581
|
+
S.current || (S.current = !0, y.current !== null && (O(y.current), y.current = null));
|
|
582
|
+
}, []), w = U(() => {
|
|
583
|
+
k.current !== null && (cancelAnimationFrame(k.current), k.current = null), S.current = !1, y.current = E.current, O(null);
|
|
584
|
+
}, []), [T, O] = cn(null), E = C(null);
|
|
585
|
+
E.current = T;
|
|
586
|
+
const [f, F] = cn(null), [H, j] = cn(null), k = C(null), L = C(null), v = U((u, x) => {
|
|
587
|
+
if (x) {
|
|
588
|
+
if (!S.current) {
|
|
589
|
+
y.current = u;
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
L.current = u, k.current !== null && cancelAnimationFrame(k.current), k.current = null, O(u);
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
if (!S.current) {
|
|
596
|
+
y.current === u && (y.current = null);
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
u !== L.current && k.current === null && (k.current = requestAnimationFrame(() => {
|
|
600
|
+
k.current = null, O((P) => P === u ? null : P);
|
|
601
|
+
}));
|
|
602
|
+
}, []);
|
|
603
|
+
_(
|
|
604
|
+
() => () => {
|
|
605
|
+
k.current !== null && cancelAnimationFrame(k.current);
|
|
606
|
+
},
|
|
607
|
+
[]
|
|
608
|
+
);
|
|
609
|
+
const p = e, $ = e / 2, I = e / 2, D = e * 0.25, N = 360 / g, W = e * 0.375, q = kn(t, {
|
|
610
|
+
layout: i,
|
|
611
|
+
direction: s,
|
|
612
|
+
size: e,
|
|
613
|
+
ringGap: o,
|
|
614
|
+
submenuThickness: c
|
|
615
|
+
});
|
|
616
|
+
_(() => {
|
|
617
|
+
f !== null && T !== null && T !== f && F(null);
|
|
618
|
+
}, [T, f]);
|
|
619
|
+
const { attachRouter: X, rootEls: nn, subEls: on } = Dn({
|
|
620
|
+
menuItems: t,
|
|
621
|
+
count: g,
|
|
622
|
+
box: p,
|
|
623
|
+
innerR: D,
|
|
624
|
+
outerR: I,
|
|
625
|
+
step: N,
|
|
626
|
+
openDelay: h,
|
|
627
|
+
subRadii: q,
|
|
628
|
+
openSub: f,
|
|
629
|
+
setOpenSub: F,
|
|
630
|
+
onArm: M,
|
|
631
|
+
onCancel: w
|
|
632
|
+
}), G = f !== null && H !== null ? H : T !== null ? ((en = t[T]) == null ? void 0 : en.label) ?? null : null, Y = {};
|
|
633
|
+
return n.open !== void 0 && (Y.open = n.open), n.defaultOpen !== void 0 && (Y.defaultOpen = n.defaultOpen), /* @__PURE__ */ l(Mn.Provider, { value: R, children: /* @__PURE__ */ Q(
|
|
634
|
+
z.Root,
|
|
635
|
+
{
|
|
636
|
+
...Y,
|
|
637
|
+
actionsRef: r,
|
|
638
|
+
onOpenChange: (u) => {
|
|
639
|
+
var x;
|
|
640
|
+
u ? (S.current = !1, y.current = null, O(null)) : (O(null), F(null)), (x = n.onOpenChange) == null || x.call(n, u);
|
|
641
|
+
},
|
|
642
|
+
children: [
|
|
643
|
+
d ? n.children : /* @__PURE__ */ l(
|
|
644
|
+
z.Trigger,
|
|
645
|
+
{
|
|
646
|
+
render: (u) => /* @__PURE__ */ l(
|
|
647
|
+
"span",
|
|
648
|
+
{
|
|
649
|
+
...u,
|
|
650
|
+
ref: A,
|
|
651
|
+
"aria-hidden": !0,
|
|
652
|
+
style: {
|
|
653
|
+
position: "fixed",
|
|
654
|
+
width: 0,
|
|
655
|
+
height: 0,
|
|
656
|
+
overflow: "hidden"
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
)
|
|
660
|
+
}
|
|
661
|
+
),
|
|
662
|
+
/* @__PURE__ */ l(z.Portal, { children: /* @__PURE__ */ l(
|
|
663
|
+
z.Positioner,
|
|
664
|
+
{
|
|
665
|
+
align: "center",
|
|
666
|
+
sideOffset: ({ positioner: u }) => -u.height / 2,
|
|
667
|
+
collisionAvoidance: { side: "shift", align: "shift" },
|
|
668
|
+
collisionPadding: 8,
|
|
669
|
+
style: { zIndex: 20, outline: "none" },
|
|
670
|
+
children: /* @__PURE__ */ l(
|
|
671
|
+
z.Popup,
|
|
672
|
+
{
|
|
673
|
+
className: "radial-popup",
|
|
674
|
+
style: { width: e, height: e },
|
|
675
|
+
children: /* @__PURE__ */ l(
|
|
676
|
+
"svg",
|
|
677
|
+
{
|
|
678
|
+
ref: X,
|
|
679
|
+
"data-radial-root": !0,
|
|
680
|
+
width: p,
|
|
681
|
+
height: p,
|
|
682
|
+
viewBox: `0 0 ${p} ${p}`,
|
|
683
|
+
className: "radial-svg",
|
|
684
|
+
children: /* @__PURE__ */ l(
|
|
685
|
+
In,
|
|
686
|
+
{
|
|
687
|
+
menuItems: t,
|
|
688
|
+
selected: T,
|
|
689
|
+
centerLabel: G,
|
|
690
|
+
geometry: { box: p, c: $, innerR: D, outerR: I, step: N, iconR: W },
|
|
691
|
+
children: t.map((u, x) => {
|
|
692
|
+
var an;
|
|
693
|
+
const P = V + x * N, rn = P + N, K = yn(p, $, $, D, I, P, rn), sn = (tn) => v(x, tn), un = (tn) => {
|
|
694
|
+
nn.current[x] = tn;
|
|
695
|
+
};
|
|
696
|
+
return (an = u.submenu) != null && an.length ? /* @__PURE__ */ l(
|
|
697
|
+
zn,
|
|
698
|
+
{
|
|
699
|
+
item: u,
|
|
700
|
+
index: x,
|
|
701
|
+
clip: K,
|
|
702
|
+
box: p,
|
|
703
|
+
onHi: sn,
|
|
704
|
+
captureRef: un,
|
|
705
|
+
open: f === x,
|
|
706
|
+
onOpen: F,
|
|
707
|
+
onClose: () => F(null),
|
|
708
|
+
children: /* @__PURE__ */ l(
|
|
709
|
+
Hn,
|
|
710
|
+
{
|
|
711
|
+
parent: u,
|
|
712
|
+
parentIndex: x,
|
|
713
|
+
count: g,
|
|
714
|
+
layout: i,
|
|
715
|
+
direction: s,
|
|
716
|
+
size: e,
|
|
717
|
+
ringGap: o,
|
|
718
|
+
submenuThickness: c,
|
|
719
|
+
captureChild: (tn, vn) => {
|
|
720
|
+
on.current[tn] = vn;
|
|
721
|
+
},
|
|
722
|
+
onActiveLabel: j
|
|
723
|
+
}
|
|
724
|
+
)
|
|
725
|
+
},
|
|
726
|
+
u.label
|
|
727
|
+
) : /* @__PURE__ */ l(
|
|
728
|
+
wn,
|
|
729
|
+
{
|
|
730
|
+
item: u,
|
|
731
|
+
clip: K,
|
|
732
|
+
box: p,
|
|
733
|
+
onHi: sn,
|
|
734
|
+
captureRef: un
|
|
735
|
+
},
|
|
736
|
+
u.label
|
|
737
|
+
);
|
|
738
|
+
})
|
|
739
|
+
}
|
|
740
|
+
)
|
|
741
|
+
}
|
|
742
|
+
)
|
|
743
|
+
}
|
|
744
|
+
)
|
|
745
|
+
}
|
|
746
|
+
) })
|
|
747
|
+
]
|
|
748
|
+
}
|
|
749
|
+
) });
|
|
750
|
+
}
|
|
751
|
+
function Ln(n) {
|
|
752
|
+
const { registerTrigger: t } = Wn();
|
|
753
|
+
return /* @__PURE__ */ l(z.Trigger, { ...n, ref: t });
|
|
754
|
+
}
|
|
755
|
+
const Un = {
|
|
756
|
+
Root: Bn,
|
|
757
|
+
Trigger: Ln
|
|
758
|
+
};
|
|
759
|
+
export {
|
|
760
|
+
Un as RadialMenu,
|
|
761
|
+
Bn as RadialMenuRoot,
|
|
762
|
+
Ln as RadialMenuTrigger
|
|
763
|
+
};
|