seppia 0.0.0-stage → 0.1.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 +92 -3
- package/dist/chunk-2PABDSNH.cjs +208 -0
- package/dist/chunk-2Z4YKJMT.js +329 -0
- package/dist/chunk-344MRWFO.js +25 -0
- package/dist/chunk-3A2LHCPV.cjs +30 -0
- package/dist/chunk-3NQ776G6.cjs +204 -0
- package/dist/chunk-3XIEBFVO.cjs +130 -0
- package/dist/chunk-4IHNW52F.cjs +197 -0
- package/dist/chunk-4YGBUMQC.js +160 -0
- package/dist/chunk-5ARTY5RT.cjs +66 -0
- package/dist/chunk-5PAJS63K.cjs +156 -0
- package/dist/chunk-5Z32CAHE.cjs +261 -0
- package/dist/chunk-66ITQTT2.js +108 -0
- package/dist/chunk-6EABLOB7.js +190 -0
- package/dist/chunk-6FF73V3S.js +190 -0
- package/dist/chunk-6LRDNOZX.cjs +138 -0
- package/dist/chunk-76MEQHGW.js +192 -0
- package/dist/chunk-7B2YEOYF.js +26 -0
- package/dist/chunk-7Y22U2ZF.js +370 -0
- package/dist/chunk-AFGJQET4.js +186 -0
- package/dist/chunk-AG3OBSP5.cjs +216 -0
- package/dist/chunk-AHRXESD2.js +126 -0
- package/dist/chunk-AJPI65BL.cjs +153 -0
- package/dist/chunk-CCDDQHCS.js +182 -0
- package/dist/chunk-CGX6YCV6.js +130 -0
- package/dist/chunk-CPUW5LDN.cjs +28 -0
- package/dist/chunk-DAO7YH2R.cjs +165 -0
- package/dist/chunk-DO5WEBTN.cjs +139 -0
- package/dist/chunk-DUUDPN7C.cjs +203 -0
- package/dist/chunk-EOPY2VWT.cjs +185 -0
- package/dist/chunk-EUQ6BCML.cjs +175 -0
- package/dist/chunk-EYO4XMKU.js +145 -0
- package/dist/chunk-F7UECO7G.js +175 -0
- package/dist/chunk-FGJDDSUJ.js +303 -0
- package/dist/chunk-G5UZZ2XG.cjs +52 -0
- package/dist/chunk-GJ6WO63L.js +216 -0
- package/dist/chunk-GP32TY6P.cjs +409 -0
- package/dist/chunk-HQLB5Z37.cjs +275 -0
- package/dist/chunk-HSXGQNQ6.js +143 -0
- package/dist/chunk-I2XZ2WMY.js +385 -0
- package/dist/chunk-I525FOTN.cjs +214 -0
- package/dist/chunk-IAPRIVJO.js +157 -0
- package/dist/chunk-IUSSIILO.cjs +393 -0
- package/dist/chunk-JV6GJ3JJ.js +92 -0
- package/dist/chunk-KPG24YFL.js +30 -0
- package/dist/chunk-LGBMJIY6.js +174 -0
- package/dist/chunk-LYEOVFOQ.cjs +148 -0
- package/dist/chunk-LYYMITLC.js +238 -0
- package/dist/chunk-M42F5QS5.cjs +212 -0
- package/dist/chunk-NN3HMY7H.cjs +260 -0
- package/dist/chunk-NU5MGYFP.cjs +167 -0
- package/dist/chunk-OCIKUJ3U.js +117 -0
- package/dist/chunk-PBMXL53R.cjs +39 -0
- package/dist/chunk-PGEK6DFE.cjs +351 -0
- package/dist/chunk-QPWVBVDC.cjs +130 -0
- package/dist/chunk-QWYHH465.cjs +117 -0
- package/dist/chunk-RFCZJPGM.js +116 -0
- package/dist/chunk-RIBXHAKG.cjs +179 -0
- package/dist/chunk-SDWRKTFC.cjs +158 -0
- package/dist/chunk-SMY24MVU.js +92 -0
- package/dist/chunk-SSARMSS3.cjs +325 -0
- package/dist/chunk-T533JPW5.js +131 -0
- package/dist/chunk-T7AMVHIB.js +221 -0
- package/dist/chunk-TVGVZSIA.js +130 -0
- package/dist/chunk-UFU5S3LK.cjs +244 -0
- package/dist/chunk-UFUN2OKY.js +35 -0
- package/dist/chunk-VDSMO63G.cjs +153 -0
- package/dist/chunk-VHXWP5OX.cjs +115 -0
- package/dist/chunk-VW32EE3I.js +153 -0
- package/dist/chunk-WGFJLFTP.js +40 -0
- package/dist/chunk-WSL2OVTO.js +136 -0
- package/dist/chunk-WVWVJSU2.cjs +309 -0
- package/dist/chunk-XLZPYDNI.js +287 -0
- package/dist/chunk-XUBFOAT4.js +239 -0
- package/dist/chunk-Y3UCNSXF.js +253 -0
- package/dist/chunk-YDJMVDAJ.cjs +196 -0
- package/dist/chunk-ZF5HY2K4.cjs +238 -0
- package/dist/chunk-ZXKEYL6L.js +181 -0
- package/dist/chunk-ZZYMYQU2.js +108 -0
- package/dist/components/accordion.cjs +26 -0
- package/dist/components/accordion.d.cts +41 -0
- package/dist/components/accordion.d.ts +41 -0
- package/dist/components/accordion.js +5 -0
- package/dist/components/calendar.cjs +14 -0
- package/dist/components/calendar.d.cts +41 -0
- package/dist/components/calendar.d.ts +41 -0
- package/dist/components/calendar.js +5 -0
- package/dist/components/checkbox.cjs +14 -0
- package/dist/components/checkbox.d.cts +27 -0
- package/dist/components/checkbox.d.ts +27 -0
- package/dist/components/checkbox.js +5 -0
- package/dist/components/chip-select.cjs +14 -0
- package/dist/components/chip-select.d.cts +31 -0
- package/dist/components/chip-select.d.ts +31 -0
- package/dist/components/chip-select.js +5 -0
- package/dist/components/clock.cjs +12 -0
- package/dist/components/clock.d.cts +25 -0
- package/dist/components/clock.d.ts +25 -0
- package/dist/components/clock.js +3 -0
- package/dist/components/color-picker.cjs +14 -0
- package/dist/components/color-picker.d.cts +23 -0
- package/dist/components/color-picker.d.ts +23 -0
- package/dist/components/color-picker.js +5 -0
- package/dist/components/command-palette.cjs +20 -0
- package/dist/components/command-palette.d.cts +53 -0
- package/dist/components/command-palette.d.ts +53 -0
- package/dist/components/command-palette.js +7 -0
- package/dist/components/date-picker.cjs +18 -0
- package/dist/components/date-picker.d.cts +40 -0
- package/dist/components/date-picker.d.ts +40 -0
- package/dist/components/date-picker.js +9 -0
- package/dist/components/drawer.cjs +16 -0
- package/dist/components/drawer.d.cts +22 -0
- package/dist/components/drawer.d.ts +22 -0
- package/dist/components/drawer.js +7 -0
- package/dist/components/floating-panel.cjs +13 -0
- package/dist/components/floating-panel.d.cts +25 -0
- package/dist/components/floating-panel.d.ts +25 -0
- package/dist/components/floating-panel.js +4 -0
- package/dist/components/hold-button.cjs +13 -0
- package/dist/components/hold-button.d.cts +30 -0
- package/dist/components/hold-button.d.ts +30 -0
- package/dist/components/hold-button.js +4 -0
- package/dist/components/knob.cjs +15 -0
- package/dist/components/knob.d.cts +33 -0
- package/dist/components/knob.d.ts +33 -0
- package/dist/components/knob.js +6 -0
- package/dist/components/magnetic-button.cjs +13 -0
- package/dist/components/magnetic-button.d.cts +23 -0
- package/dist/components/magnetic-button.d.ts +23 -0
- package/dist/components/magnetic-button.js +4 -0
- package/dist/components/morph-button.cjs +13 -0
- package/dist/components/morph-button.d.cts +34 -0
- package/dist/components/morph-button.d.ts +34 -0
- package/dist/components/morph-button.js +4 -0
- package/dist/components/morph-dialog.cjs +32 -0
- package/dist/components/morph-dialog.d.cts +30 -0
- package/dist/components/morph-dialog.d.ts +30 -0
- package/dist/components/morph-dialog.js +7 -0
- package/dist/components/number-field.cjs +15 -0
- package/dist/components/number-field.d.cts +32 -0
- package/dist/components/number-field.d.ts +32 -0
- package/dist/components/number-field.js +6 -0
- package/dist/components/pin-input.cjs +14 -0
- package/dist/components/pin-input.d.cts +29 -0
- package/dist/components/pin-input.d.ts +29 -0
- package/dist/components/pin-input.js +5 -0
- package/dist/components/popover.cjs +16 -0
- package/dist/components/popover.d.cts +26 -0
- package/dist/components/popover.d.ts +26 -0
- package/dist/components/popover.js +7 -0
- package/dist/components/progress.cjs +17 -0
- package/dist/components/progress.d.cts +39 -0
- package/dist/components/progress.d.ts +39 -0
- package/dist/components/progress.js +4 -0
- package/dist/components/radial-menu.cjs +14 -0
- package/dist/components/radial-menu.d.cts +31 -0
- package/dist/components/radial-menu.d.ts +31 -0
- package/dist/components/radial-menu.js +5 -0
- package/dist/components/radio-group.cjs +14 -0
- package/dist/components/radio-group.d.cts +34 -0
- package/dist/components/radio-group.d.ts +34 -0
- package/dist/components/radio-group.js +5 -0
- package/dist/components/resizable-panels.cjs +18 -0
- package/dist/components/resizable-panels.d.cts +24 -0
- package/dist/components/resizable-panels.d.ts +24 -0
- package/dist/components/resizable-panels.js +5 -0
- package/dist/components/segmented-control.cjs +14 -0
- package/dist/components/segmented-control.d.cts +34 -0
- package/dist/components/segmented-control.d.ts +34 -0
- package/dist/components/segmented-control.js +5 -0
- package/dist/components/slider.cjs +15 -0
- package/dist/components/slider.d.cts +39 -0
- package/dist/components/slider.d.ts +39 -0
- package/dist/components/slider.js +6 -0
- package/dist/components/sortable-list.cjs +13 -0
- package/dist/components/sortable-list.d.cts +24 -0
- package/dist/components/sortable-list.d.ts +24 -0
- package/dist/components/sortable-list.js +4 -0
- package/dist/components/sparkline.cjs +14 -0
- package/dist/components/sparkline.d.cts +28 -0
- package/dist/components/sparkline.d.ts +28 -0
- package/dist/components/sparkline.js +5 -0
- package/dist/components/swipe-confirm.cjs +13 -0
- package/dist/components/swipe-confirm.d.cts +18 -0
- package/dist/components/swipe-confirm.d.ts +18 -0
- package/dist/components/swipe-confirm.js +4 -0
- package/dist/components/switch.cjs +15 -0
- package/dist/components/switch.d.cts +29 -0
- package/dist/components/switch.d.ts +29 -0
- package/dist/components/switch.js +6 -0
- package/dist/components/tabs.cjs +30 -0
- package/dist/components/tabs.d.cts +29 -0
- package/dist/components/tabs.d.ts +29 -0
- package/dist/components/tabs.js +5 -0
- package/dist/components/tether.cjs +16 -0
- package/dist/components/tether.d.cts +35 -0
- package/dist/components/tether.d.ts +35 -0
- package/dist/components/tether.js +3 -0
- package/dist/components/theme-switch.cjs +14 -0
- package/dist/components/theme-switch.d.cts +24 -0
- package/dist/components/theme-switch.d.ts +24 -0
- package/dist/components/theme-switch.js +5 -0
- package/dist/components/toaster.cjs +21 -0
- package/dist/components/toaster.d.cts +71 -0
- package/dist/components/toaster.d.ts +71 -0
- package/dist/components/toaster.js +4 -0
- package/dist/components/wheel-picker.cjs +15 -0
- package/dist/components/wheel-picker.d.cts +27 -0
- package/dist/components/wheel-picker.d.ts +27 -0
- package/dist/components/wheel-picker.js +6 -0
- package/dist/css/accordion.css +2 -0
- package/dist/css/base.css +2 -0
- package/dist/css/calendar.css +2 -0
- package/dist/css/checkbox.css +2 -0
- package/dist/css/chip-select.css +2 -0
- package/dist/css/clock.css +2 -0
- package/dist/css/color-picker.css +2 -0
- package/dist/css/command-palette.css +2 -0
- package/dist/css/date-picker.css +2 -0
- package/dist/css/drawer.css +2 -0
- package/dist/css/floating-panel.css +2 -0
- package/dist/css/hold-button.css +2 -0
- package/dist/css/knob.css +2 -0
- package/dist/css/magnetic-button.css +2 -0
- package/dist/css/morph-button.css +2 -0
- package/dist/css/morph-dialog.css +2 -0
- package/dist/css/number-field.css +2 -0
- package/dist/css/pin-input.css +2 -0
- package/dist/css/popover.css +2 -0
- package/dist/css/progress.css +2 -0
- package/dist/css/radial-menu.css +2 -0
- package/dist/css/radio-group.css +2 -0
- package/dist/css/resizable-panels.css +2 -0
- package/dist/css/segmented-control.css +2 -0
- package/dist/css/slider.css +2 -0
- package/dist/css/sortable-list.css +2 -0
- package/dist/css/sparkline.css +2 -0
- package/dist/css/swipe-confirm.css +2 -0
- package/dist/css/switch.css +2 -0
- package/dist/css/tabs.css +2 -0
- package/dist/css/tether.css +2 -0
- package/dist/css/theme-switch.css +2 -0
- package/dist/css/toaster.css +2 -0
- package/dist/css/wheel-picker.css +2 -0
- package/dist/index.cjs +249 -0
- package/dist/index.d.cts +77 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +40 -0
- package/dist/styles.css +2 -0
- package/package.json +98 -6
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEscape, useFocusTrap, getFocusable } from './chunk-SMY24MVU.js';
|
|
3
|
+
import { Portal } from './chunk-7B2YEOYF.js';
|
|
4
|
+
import { useIsoLayoutEffect, mergeRefs } from './chunk-WGFJLFTP.js';
|
|
5
|
+
import { useControllableState } from './chunk-KPG24YFL.js';
|
|
6
|
+
import { useMotionPreset, cx } from './chunk-UFUN2OKY.js';
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
import { AnimatePresence, motion } from 'motion/react';
|
|
9
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
10
|
+
|
|
11
|
+
var SPRING = { type: "spring", stiffness: 520, damping: 34, mass: 0.8 };
|
|
12
|
+
var PAD = 8;
|
|
13
|
+
function compute(trigger, content, placement, offset, frame) {
|
|
14
|
+
const [side0, align = "center"] = placement.split("-");
|
|
15
|
+
const vw = frame.width;
|
|
16
|
+
const vh = frame.height;
|
|
17
|
+
const t = { left: trigger.left - frame.left, top: trigger.top - frame.top, right: trigger.right - frame.left, bottom: trigger.bottom - frame.top, width: trigger.width, height: trigger.height };
|
|
18
|
+
let side = side0;
|
|
19
|
+
const fits = (s) => s === "bottom" ? t.bottom + offset + content.height <= vh - PAD : s === "top" ? t.top - offset - content.height >= PAD : s === "right" ? t.right + offset + content.width <= vw - PAD : t.left - offset - content.width >= PAD;
|
|
20
|
+
const opposite = { top: "bottom", bottom: "top", left: "right", right: "left" };
|
|
21
|
+
if (!fits(side) && fits(opposite[side])) side = opposite[side];
|
|
22
|
+
let top = 0;
|
|
23
|
+
let left = 0;
|
|
24
|
+
if (side === "bottom" || side === "top") {
|
|
25
|
+
top = side === "bottom" ? t.bottom + offset : t.top - offset - content.height;
|
|
26
|
+
left = align === "start" ? t.left : align === "end" ? t.right - content.width : t.left + t.width / 2 - content.width / 2;
|
|
27
|
+
} else {
|
|
28
|
+
left = side === "right" ? t.right + offset : t.left - offset - content.width;
|
|
29
|
+
top = align === "start" ? t.top : align === "end" ? t.bottom - content.height : t.top + t.height / 2 - content.height / 2;
|
|
30
|
+
}
|
|
31
|
+
left = Math.min(Math.max(PAD, left), Math.max(PAD, vw - content.width - PAD));
|
|
32
|
+
top = Math.min(Math.max(PAD, top), Math.max(PAD, vh - content.height - PAD));
|
|
33
|
+
const ox = Math.min(Math.max(0, t.left + t.width / 2 - left), content.width);
|
|
34
|
+
const oy = Math.min(Math.max(0, t.top + t.height / 2 - top), content.height);
|
|
35
|
+
const origin = side === "bottom" ? `${ox}px 0px` : side === "top" ? `${ox}px ${content.height}px` : side === "right" ? `0px ${oy}px` : `${content.width}px ${oy}px`;
|
|
36
|
+
return { top, left, side, origin };
|
|
37
|
+
}
|
|
38
|
+
var Popover = React.forwardRef(function Popover2({ open: openProp, defaultOpen = false, onOpenChange, content, children, placement = "bottom", offset = 8, modal = false, matchWidth = false, container, className, style, ...rest }, ref) {
|
|
39
|
+
const [open, setOpen] = useControllableState({ value: openProp, defaultValue: defaultOpen, onChange: onOpenChange });
|
|
40
|
+
const { t, reduced } = useMotionPreset();
|
|
41
|
+
const triggerRef = React.useRef(null);
|
|
42
|
+
const contentRef = React.useRef(null);
|
|
43
|
+
const portalRef = React.useRef(null);
|
|
44
|
+
const [pos, setPos] = React.useState(null);
|
|
45
|
+
const id = React.useId();
|
|
46
|
+
const close = React.useCallback(() => setOpen(false), [setOpen]);
|
|
47
|
+
const update = React.useCallback(() => {
|
|
48
|
+
const trigger2 = triggerRef.current;
|
|
49
|
+
const el = contentRef.current;
|
|
50
|
+
if (!trigger2 || !el) return;
|
|
51
|
+
const frameEl = el.closest(".fl-portal");
|
|
52
|
+
const frame = frameEl?.getBoundingClientRect() ?? new DOMRect(0, 0, window.innerWidth, window.innerHeight);
|
|
53
|
+
setPos(compute(trigger2.getBoundingClientRect(), { width: el.offsetWidth, height: el.offsetHeight }, placement, offset, frame));
|
|
54
|
+
}, [placement, offset]);
|
|
55
|
+
useIsoLayoutEffect(() => {
|
|
56
|
+
if (!open) {
|
|
57
|
+
setPos(null);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
update();
|
|
61
|
+
const onChange = () => update();
|
|
62
|
+
window.addEventListener("resize", onChange);
|
|
63
|
+
window.addEventListener("scroll", onChange, true);
|
|
64
|
+
const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(onChange) : null;
|
|
65
|
+
if (contentRef.current) ro?.observe(contentRef.current);
|
|
66
|
+
return () => {
|
|
67
|
+
window.removeEventListener("resize", onChange);
|
|
68
|
+
window.removeEventListener("scroll", onChange, true);
|
|
69
|
+
ro?.disconnect();
|
|
70
|
+
};
|
|
71
|
+
}, [open, update]);
|
|
72
|
+
React.useEffect(() => {
|
|
73
|
+
if (!open) return;
|
|
74
|
+
const onDown = (event) => {
|
|
75
|
+
const target = event.target;
|
|
76
|
+
if (contentRef.current?.contains(target) || triggerRef.current?.contains(target)) return;
|
|
77
|
+
close();
|
|
78
|
+
};
|
|
79
|
+
document.addEventListener("pointerdown", onDown, true);
|
|
80
|
+
return () => document.removeEventListener("pointerdown", onDown, true);
|
|
81
|
+
}, [open, close]);
|
|
82
|
+
useEscape(open, () => {
|
|
83
|
+
close();
|
|
84
|
+
triggerRef.current?.focus();
|
|
85
|
+
});
|
|
86
|
+
useFocusTrap(contentRef, open && modal);
|
|
87
|
+
React.useEffect(() => {
|
|
88
|
+
if (!open || modal) return;
|
|
89
|
+
const raf = requestAnimationFrame(() => {
|
|
90
|
+
const el = contentRef.current;
|
|
91
|
+
if (!el) return;
|
|
92
|
+
const target = el.querySelector("[data-autofocus]") ?? el.querySelector('[tabindex="0"]') ?? getFocusable(el)[0] ?? el;
|
|
93
|
+
target.focus({ preventScroll: true });
|
|
94
|
+
});
|
|
95
|
+
return () => cancelAnimationFrame(raf);
|
|
96
|
+
}, [open, modal]);
|
|
97
|
+
const child = React.Children.only(children);
|
|
98
|
+
const childRef = child.props.ref ?? child.ref;
|
|
99
|
+
const trigger = React.cloneElement(child, {
|
|
100
|
+
ref: mergeRefs(triggerRef, childRef),
|
|
101
|
+
"aria-haspopup": "dialog",
|
|
102
|
+
"aria-expanded": open,
|
|
103
|
+
"aria-controls": open ? id : void 0,
|
|
104
|
+
"data-state": open ? "open" : "closed",
|
|
105
|
+
onClick: (event) => {
|
|
106
|
+
child.props.onClick?.(event);
|
|
107
|
+
if (!event.defaultPrevented) setOpen(!open);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const side = pos?.side ?? placement.split("-")[0];
|
|
111
|
+
const shift = reduced ? 0 : 6;
|
|
112
|
+
const from = side === "bottom" ? { y: -shift } : side === "top" ? { y: shift } : side === "right" ? { x: -shift } : { x: shift };
|
|
113
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
114
|
+
trigger,
|
|
115
|
+
/* @__PURE__ */ jsx(Portal, { container, anchor: triggerRef.current, children: /* @__PURE__ */ jsx(AnimatePresence, { children: open && /* @__PURE__ */ jsx(
|
|
116
|
+
motion.div,
|
|
117
|
+
{
|
|
118
|
+
...rest,
|
|
119
|
+
ref: mergeRefs(contentRef, ref, (el) => {
|
|
120
|
+
portalRef.current = el?.closest(".fl-portal") ?? null;
|
|
121
|
+
}),
|
|
122
|
+
id,
|
|
123
|
+
role: "dialog",
|
|
124
|
+
tabIndex: -1,
|
|
125
|
+
className: cx("fl-popover", className),
|
|
126
|
+
"data-side": side,
|
|
127
|
+
style: {
|
|
128
|
+
...style,
|
|
129
|
+
top: pos?.top ?? -9999,
|
|
130
|
+
left: pos?.left ?? -9999,
|
|
131
|
+
minWidth: matchWidth ? triggerRef.current?.offsetWidth : void 0,
|
|
132
|
+
transformOrigin: pos?.origin,
|
|
133
|
+
visibility: pos ? "visible" : "hidden"
|
|
134
|
+
},
|
|
135
|
+
initial: { opacity: 0, scale: reduced ? 1 : 0.94, ...from },
|
|
136
|
+
animate: { opacity: 1, scale: 1, x: 0, y: 0 },
|
|
137
|
+
exit: { opacity: 0, scale: reduced ? 1 : 0.96, ...from, transition: { duration: 0.14 } },
|
|
138
|
+
transition: t(SPRING),
|
|
139
|
+
children: typeof content === "function" ? content(close) : content
|
|
140
|
+
}
|
|
141
|
+
) }) })
|
|
142
|
+
] });
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
export { Popover };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useIsoLayoutEffect, haptic, mergeRefs } from './chunk-WGFJLFTP.js';
|
|
3
|
+
import { useControllableState } from './chunk-KPG24YFL.js';
|
|
4
|
+
import { useMotionPreset, cx } from './chunk-UFUN2OKY.js';
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import { motion } from 'motion/react';
|
|
7
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
8
|
+
|
|
9
|
+
var CHECK = "M4.6 9.4 L7.7 12.4 L13.6 6";
|
|
10
|
+
var DASH = "M5 9 L9 9 L13 9";
|
|
11
|
+
var PRESS = { type: "spring", stiffness: 900, damping: 40 };
|
|
12
|
+
var RELEASE = { type: "spring", stiffness: 520, damping: 14, mass: 0.7 };
|
|
13
|
+
var Checkbox = React.forwardRef(function Checkbox2({
|
|
14
|
+
checked: checkedProp,
|
|
15
|
+
defaultChecked = false,
|
|
16
|
+
onCheckedChange,
|
|
17
|
+
variant = "draw",
|
|
18
|
+
size = "md",
|
|
19
|
+
children,
|
|
20
|
+
description,
|
|
21
|
+
haptics = true,
|
|
22
|
+
disabled,
|
|
23
|
+
className,
|
|
24
|
+
style,
|
|
25
|
+
rootProps,
|
|
26
|
+
id,
|
|
27
|
+
...rest
|
|
28
|
+
}, ref) {
|
|
29
|
+
const [state, setState] = useControllableState({
|
|
30
|
+
value: checkedProp,
|
|
31
|
+
defaultValue: defaultChecked,
|
|
32
|
+
onChange: (next) => onCheckedChange?.(next === true)
|
|
33
|
+
});
|
|
34
|
+
const { t, reduced } = useMotionPreset();
|
|
35
|
+
const inputRef = React.useRef(null);
|
|
36
|
+
const boxRef = React.useRef(null);
|
|
37
|
+
const [pressed, setPressed] = React.useState(false);
|
|
38
|
+
const [origin, setOrigin] = React.useState({ x: 50, y: 50 });
|
|
39
|
+
const generatedId = React.useId();
|
|
40
|
+
const inputId = id ?? generatedId;
|
|
41
|
+
const descriptionId = description ? `${inputId}-description` : void 0;
|
|
42
|
+
const labelId = children ? `${inputId}-label` : void 0;
|
|
43
|
+
const checked = state === true;
|
|
44
|
+
const indeterminate = state === "indeterminate";
|
|
45
|
+
const on = checked || indeterminate;
|
|
46
|
+
useIsoLayoutEffect(() => {
|
|
47
|
+
if (inputRef.current) inputRef.current.indeterminate = indeterminate;
|
|
48
|
+
}, [indeterminate]);
|
|
49
|
+
const onPointerDown = (event) => {
|
|
50
|
+
rootProps?.onPointerDown?.(event);
|
|
51
|
+
if (disabled || event.button !== 0) return;
|
|
52
|
+
setPressed(true);
|
|
53
|
+
const rect = boxRef.current?.getBoundingClientRect();
|
|
54
|
+
if (rect && rect.width) {
|
|
55
|
+
const inside = event.clientX >= rect.left && event.clientX <= rect.right && event.clientY >= rect.top && event.clientY <= rect.bottom;
|
|
56
|
+
setOrigin(inside ? { x: (event.clientX - rect.left) / rect.width * 100, y: (event.clientY - rect.top) / rect.height * 100 } : { x: 50, y: 50 });
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const release = () => setPressed(false);
|
|
60
|
+
const scale = pressed ? 0.84 : 1;
|
|
61
|
+
const boxTransition = t(pressed ? PRESS : RELEASE);
|
|
62
|
+
const mark = /* @__PURE__ */ jsx("svg", { className: "fl-checkbox__mark", viewBox: "0 0 18 18", "aria-hidden": true, children: variant === "ink" ? /* @__PURE__ */ jsx(
|
|
63
|
+
motion.path,
|
|
64
|
+
{
|
|
65
|
+
d: indeterminate ? DASH : CHECK,
|
|
66
|
+
initial: false,
|
|
67
|
+
animate: on ? { scale: 1, opacity: 1, rotate: 0 } : { scale: 0.4, opacity: 0, rotate: -12 },
|
|
68
|
+
transition: t({ type: "spring", stiffness: 600, damping: 18, delay: on ? 0.05 : 0 }),
|
|
69
|
+
style: { originX: "9px", originY: "9px" }
|
|
70
|
+
}
|
|
71
|
+
) : /* @__PURE__ */ jsx(
|
|
72
|
+
motion.path,
|
|
73
|
+
{
|
|
74
|
+
initial: false,
|
|
75
|
+
animate: { d: indeterminate ? DASH : CHECK, pathLength: on ? 1 : 0, opacity: on ? 1 : 0 },
|
|
76
|
+
transition: t({
|
|
77
|
+
d: { type: "spring", stiffness: 420, damping: 26 },
|
|
78
|
+
pathLength: on ? { type: "spring", stiffness: 260, damping: 24, delay: 0.05 } : { duration: 0.14, ease: [0.4, 0, 1, 1] },
|
|
79
|
+
opacity: { duration: on ? 0.01 : 0.12, delay: on ? 0.05 : 0.08 }
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
) });
|
|
83
|
+
return /* @__PURE__ */ jsxs(
|
|
84
|
+
"label",
|
|
85
|
+
{
|
|
86
|
+
...rootProps,
|
|
87
|
+
htmlFor: inputId,
|
|
88
|
+
className: cx("fl-checkbox", className, rootProps?.className),
|
|
89
|
+
style: { ...rootProps?.style, ...style },
|
|
90
|
+
"data-variant": variant,
|
|
91
|
+
"data-size": size,
|
|
92
|
+
"data-state": indeterminate ? "indeterminate" : checked ? "checked" : "unchecked",
|
|
93
|
+
"data-disabled": disabled || void 0,
|
|
94
|
+
onPointerDown,
|
|
95
|
+
onPointerUp: release,
|
|
96
|
+
onPointerLeave: release,
|
|
97
|
+
onPointerCancel: release,
|
|
98
|
+
children: [
|
|
99
|
+
/* @__PURE__ */ jsxs("span", { className: "fl-checkbox__control", children: [
|
|
100
|
+
/* @__PURE__ */ jsx(
|
|
101
|
+
"input",
|
|
102
|
+
{
|
|
103
|
+
...rest,
|
|
104
|
+
ref: mergeRefs(inputRef, ref),
|
|
105
|
+
id: inputId,
|
|
106
|
+
type: "checkbox",
|
|
107
|
+
className: "fl-checkbox__input",
|
|
108
|
+
checked,
|
|
109
|
+
disabled,
|
|
110
|
+
"aria-labelledby": labelId,
|
|
111
|
+
"aria-describedby": descriptionId,
|
|
112
|
+
onChange: (event) => {
|
|
113
|
+
if (haptics) haptic(6);
|
|
114
|
+
setState(event.target.checked);
|
|
115
|
+
},
|
|
116
|
+
onKeyDown: (event) => {
|
|
117
|
+
rest.onKeyDown?.(event);
|
|
118
|
+
if (event.key === " " && !event.repeat) {
|
|
119
|
+
setOrigin({ x: 50, y: 50 });
|
|
120
|
+
setPressed(true);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
onKeyUp: (event) => {
|
|
124
|
+
rest.onKeyUp?.(event);
|
|
125
|
+
if (event.key === " ") setPressed(false);
|
|
126
|
+
},
|
|
127
|
+
onBlur: (event) => {
|
|
128
|
+
rest.onBlur?.(event);
|
|
129
|
+
setPressed(false);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
),
|
|
133
|
+
/* @__PURE__ */ jsxs(motion.span, { ref: boxRef, className: "fl-checkbox__box", "aria-hidden": true, initial: false, animate: { scale }, transition: boxTransition, children: [
|
|
134
|
+
variant === "ink" ? /* @__PURE__ */ jsx(
|
|
135
|
+
motion.span,
|
|
136
|
+
{
|
|
137
|
+
className: "fl-checkbox__fill",
|
|
138
|
+
initial: false,
|
|
139
|
+
animate: { clipPath: on ? `circle(150% at ${origin.x}% ${origin.y}%)` : `circle(0% at ${origin.x}% ${origin.y}%)` },
|
|
140
|
+
transition: t(on ? { duration: 0.42, ease: [0.22, 1, 0.36, 1] } : { duration: 0.24, ease: [0.4, 0, 0.6, 1] })
|
|
141
|
+
}
|
|
142
|
+
) : /* @__PURE__ */ jsx(
|
|
143
|
+
motion.span,
|
|
144
|
+
{
|
|
145
|
+
className: "fl-checkbox__fill",
|
|
146
|
+
initial: false,
|
|
147
|
+
animate: on ? { scale: 1, opacity: 1 } : { scale: reduced ? 1 : 0.35, opacity: 0 },
|
|
148
|
+
transition: t(on ? { type: "spring", stiffness: 560, damping: 24 } : { duration: 0.16 })
|
|
149
|
+
}
|
|
150
|
+
),
|
|
151
|
+
mark
|
|
152
|
+
] })
|
|
153
|
+
] }),
|
|
154
|
+
(children || description) && /* @__PURE__ */ jsxs("span", { className: "fl-checkbox__text", children: [
|
|
155
|
+
children && /* @__PURE__ */ jsxs("span", { id: labelId, className: "fl-checkbox__label", children: [
|
|
156
|
+
children,
|
|
157
|
+
variant === "strike" && /* @__PURE__ */ jsx(
|
|
158
|
+
motion.span,
|
|
159
|
+
{
|
|
160
|
+
className: "fl-checkbox__strike",
|
|
161
|
+
"aria-hidden": true,
|
|
162
|
+
initial: false,
|
|
163
|
+
animate: { scaleX: checked ? 1 : 0, originX: checked ? 0 : 1 },
|
|
164
|
+
transition: t({ type: "spring", stiffness: 300, damping: 30, delay: checked ? 0.12 : 0 })
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
] }),
|
|
168
|
+
description && /* @__PURE__ */ jsx("span", { id: descriptionId, className: "fl-checkbox__description", children: description })
|
|
169
|
+
] })
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
export { Checkbox };
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { clamp } from './chunk-344MRWFO.js';
|
|
3
|
+
import { useControllableState } from './chunk-KPG24YFL.js';
|
|
4
|
+
import { cx, useMotionPreset } from './chunk-UFUN2OKY.js';
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import { motion, useTransform, useSpring } from 'motion/react';
|
|
7
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
8
|
+
|
|
9
|
+
// src/components/color-picker/color.ts
|
|
10
|
+
function hsvToRgb({ h, s, v }) {
|
|
11
|
+
const f = (n) => {
|
|
12
|
+
const k = (n + h / 60) % 6;
|
|
13
|
+
return v - v * s * Math.max(0, Math.min(k, 4 - k, 1));
|
|
14
|
+
};
|
|
15
|
+
return { r: Math.round(f(5) * 255), g: Math.round(f(3) * 255), b: Math.round(f(1) * 255) };
|
|
16
|
+
}
|
|
17
|
+
function rgbToHsv(r, g, b) {
|
|
18
|
+
r /= 255;
|
|
19
|
+
g /= 255;
|
|
20
|
+
b /= 255;
|
|
21
|
+
const max = Math.max(r, g, b);
|
|
22
|
+
const min = Math.min(r, g, b);
|
|
23
|
+
const d = max - min;
|
|
24
|
+
let h = 0;
|
|
25
|
+
if (d) {
|
|
26
|
+
if (max === r) h = (g - b) / d % 6;
|
|
27
|
+
else if (max === g) h = (b - r) / d + 2;
|
|
28
|
+
else h = (r - g) / d + 4;
|
|
29
|
+
h *= 60;
|
|
30
|
+
if (h < 0) h += 360;
|
|
31
|
+
}
|
|
32
|
+
return { h, s: max === 0 ? 0 : d / max, v: max };
|
|
33
|
+
}
|
|
34
|
+
var hex2 = (n) => n.toString(16).padStart(2, "0");
|
|
35
|
+
function toHex(c, withAlpha = false) {
|
|
36
|
+
const { r, g, b } = hsvToRgb(c);
|
|
37
|
+
return `#${hex2(r)}${hex2(g)}${hex2(b)}${withAlpha && c.a < 1 ? hex2(Math.round(c.a * 255)) : ""}`;
|
|
38
|
+
}
|
|
39
|
+
function parseHex(input) {
|
|
40
|
+
let s = input.trim().replace(/^#/, "");
|
|
41
|
+
if (/^[0-9a-f]{3,4}$/i.test(s)) s = s.split("").map((ch) => ch + ch).join("");
|
|
42
|
+
if (!/^[0-9a-f]{6}([0-9a-f]{2})?$/i.test(s)) return null;
|
|
43
|
+
const r = parseInt(s.slice(0, 2), 16);
|
|
44
|
+
const g = parseInt(s.slice(2, 4), 16);
|
|
45
|
+
const b = parseInt(s.slice(4, 6), 16);
|
|
46
|
+
const a = s.length === 8 ? parseInt(s.slice(6, 8), 16) / 255 : 1;
|
|
47
|
+
return { ...rgbToHsv(r, g, b), a };
|
|
48
|
+
}
|
|
49
|
+
function luminance(c) {
|
|
50
|
+
const { r, g, b } = hsvToRgb(c);
|
|
51
|
+
const lin = (x) => {
|
|
52
|
+
x /= 255;
|
|
53
|
+
return x <= 0.03928 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
|
|
54
|
+
};
|
|
55
|
+
return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
|
|
56
|
+
}
|
|
57
|
+
var FOLLOW = { stiffness: 900, damping: 50, mass: 0.4 };
|
|
58
|
+
var DEFAULT_SWATCHES = ["#151514", "#ff5b14", "#f2b705", "#18925a", "#1f6feb", "#8250df", "#e5e3dc"];
|
|
59
|
+
var ColorPicker = React.forwardRef(function ColorPicker2({ value, defaultValue = "#ff5b14", onValueChange, variant = "area", swatches = DEFAULT_SWATCHES, alpha = false, eyedropper = true, className, style, ...rest }, ref) {
|
|
60
|
+
const [hex, setHex] = useControllableState({ value, defaultValue, onChange: onValueChange });
|
|
61
|
+
const [color, setColor] = React.useState(() => parseHex(hex) ?? { h: 18, s: 0.9, v: 1, a: 1 });
|
|
62
|
+
const [draft, setDraft] = React.useState(hex);
|
|
63
|
+
const lastEmitted = React.useRef(hex);
|
|
64
|
+
React.useEffect(() => {
|
|
65
|
+
if (hex === lastEmitted.current) return;
|
|
66
|
+
const parsed = parseHex(hex);
|
|
67
|
+
if (parsed) {
|
|
68
|
+
setColor((prev) => parsed.s === 0 || parsed.v === 0 ? { ...parsed, h: prev.h } : parsed);
|
|
69
|
+
setDraft(hex);
|
|
70
|
+
lastEmitted.current = hex;
|
|
71
|
+
}
|
|
72
|
+
}, [hex]);
|
|
73
|
+
const colorRef = React.useRef(color);
|
|
74
|
+
colorRef.current = color;
|
|
75
|
+
const update = (patch) => {
|
|
76
|
+
const next = { ...colorRef.current, ...patch };
|
|
77
|
+
colorRef.current = next;
|
|
78
|
+
const out = toHex(next, alpha);
|
|
79
|
+
lastEmitted.current = out;
|
|
80
|
+
setColor(next);
|
|
81
|
+
setHex(out);
|
|
82
|
+
setDraft(out);
|
|
83
|
+
};
|
|
84
|
+
const canDrop = eyedropper && typeof window !== "undefined" && "EyeDropper" in window;
|
|
85
|
+
const pick = async () => {
|
|
86
|
+
try {
|
|
87
|
+
const Dropper = window.EyeDropper;
|
|
88
|
+
const result = await new Dropper().open();
|
|
89
|
+
const parsed = parseHex(result.sRGBHex);
|
|
90
|
+
if (parsed) update(parsed);
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const solid = toHex({ ...color, a: 1 });
|
|
95
|
+
const dark = luminance(color) > 0.45;
|
|
96
|
+
return /* @__PURE__ */ jsxs(
|
|
97
|
+
"div",
|
|
98
|
+
{
|
|
99
|
+
...rest,
|
|
100
|
+
ref,
|
|
101
|
+
className: cx("fl-color", className),
|
|
102
|
+
"data-variant": variant,
|
|
103
|
+
style: { ...style, ["--fl-color"]: solid, ["--fl-hue"]: `hsl(${color.h} 100% 50%)`, ["--fl-color-mark"]: dark ? "#151514" : "#ffffff" },
|
|
104
|
+
children: [
|
|
105
|
+
variant === "area" ? /* @__PURE__ */ jsx(Area, { color, onChange: update }) : /* @__PURE__ */ jsx(Wheel, { color, onChange: update }),
|
|
106
|
+
/* @__PURE__ */ jsxs("div", { className: "fl-color__rails", children: [
|
|
107
|
+
variant === "area" ? /* @__PURE__ */ jsx(Rail, { label: "Hue", className: "fl-color__hue", value: color.h / 360, onChange: (p) => update({ h: p * 360 }), text: `${Math.round(color.h)}\xB0` }) : /* @__PURE__ */ jsx(Rail, { label: "Brightness", className: "fl-color__value", value: color.v, onChange: (p) => update({ v: p }), text: `${Math.round(color.v * 100)}%` }),
|
|
108
|
+
alpha && /* @__PURE__ */ jsx(Rail, { label: "Opacity", className: "fl-color__alpha", value: color.a, onChange: (p) => update({ a: Math.round(p * 100) / 100 }), text: `${Math.round(color.a * 100)}%` })
|
|
109
|
+
] }),
|
|
110
|
+
/* @__PURE__ */ jsxs("div", { className: "fl-color__fields", children: [
|
|
111
|
+
/* @__PURE__ */ jsx("span", { className: "fl-color__preview", "aria-hidden": true, children: /* @__PURE__ */ jsx("span", { style: { background: toHex(color, true) } }) }),
|
|
112
|
+
/* @__PURE__ */ jsx(
|
|
113
|
+
"input",
|
|
114
|
+
{
|
|
115
|
+
className: "fl-color__hex",
|
|
116
|
+
"aria-label": "Hex colour",
|
|
117
|
+
value: draft,
|
|
118
|
+
spellCheck: false,
|
|
119
|
+
onChange: (e) => {
|
|
120
|
+
const text = e.target.value;
|
|
121
|
+
const parsed = parseHex(text);
|
|
122
|
+
if (parsed) {
|
|
123
|
+
update(parsed);
|
|
124
|
+
setDraft(text);
|
|
125
|
+
} else setDraft(text);
|
|
126
|
+
},
|
|
127
|
+
onBlur: () => setDraft(toHex(color, alpha))
|
|
128
|
+
}
|
|
129
|
+
),
|
|
130
|
+
canDrop && /* @__PURE__ */ jsx("button", { type: "button", className: "fl-reset-button fl-color__dropper", "aria-label": "Pick a colour from the screen", onClick: pick, children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 16 16", width: "14", height: "14", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M10.5 2.5a1.8 1.8 0 0 1 2.5 2.5l-1.3 1.3.8.8-1.1 1.1-.8-.8-4.9 4.9H3.5v-2.2l4.9-4.9-.8-.8 1.1-1.1.8.8Z", fill: "none", stroke: "currentColor", strokeWidth: "1.3", strokeLinejoin: "round" }) }) })
|
|
131
|
+
] }),
|
|
132
|
+
swatches.length > 0 && /* @__PURE__ */ jsx("div", { className: "fl-color__swatches", role: "group", "aria-label": "Swatches", children: swatches.map((s) => {
|
|
133
|
+
const selected = s.toLowerCase() === solid.toLowerCase();
|
|
134
|
+
return /* @__PURE__ */ jsx(
|
|
135
|
+
motion.button,
|
|
136
|
+
{
|
|
137
|
+
type: "button",
|
|
138
|
+
className: "fl-reset-button fl-color__swatch",
|
|
139
|
+
"aria-label": s,
|
|
140
|
+
"aria-pressed": selected,
|
|
141
|
+
style: { background: s },
|
|
142
|
+
whileTap: { scale: 0.86 },
|
|
143
|
+
onClick: () => {
|
|
144
|
+
const parsed = parseHex(s);
|
|
145
|
+
if (parsed) update({ ...parsed, a: color.a });
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
s
|
|
149
|
+
);
|
|
150
|
+
}) })
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
function usePointerDrag(onMove) {
|
|
156
|
+
const [active, setActive] = React.useState(false);
|
|
157
|
+
const onPointerDown = (event) => {
|
|
158
|
+
if (event.button !== 0) return;
|
|
159
|
+
const el = event.currentTarget;
|
|
160
|
+
const rect = el.getBoundingClientRect();
|
|
161
|
+
setActive(true);
|
|
162
|
+
el.setPointerCapture?.(event.pointerId);
|
|
163
|
+
el.focus({ preventScroll: true });
|
|
164
|
+
onMove(event, rect);
|
|
165
|
+
const move = (e) => onMove(e, el.getBoundingClientRect());
|
|
166
|
+
const up = () => {
|
|
167
|
+
setActive(false);
|
|
168
|
+
el.removeEventListener("pointermove", move);
|
|
169
|
+
el.removeEventListener("pointerup", up);
|
|
170
|
+
el.removeEventListener("pointercancel", up);
|
|
171
|
+
};
|
|
172
|
+
el.addEventListener("pointermove", move);
|
|
173
|
+
el.addEventListener("pointerup", up);
|
|
174
|
+
el.addEventListener("pointercancel", up);
|
|
175
|
+
};
|
|
176
|
+
return { active, onPointerDown };
|
|
177
|
+
}
|
|
178
|
+
function useThumb(px, py) {
|
|
179
|
+
const { reduced } = useMotionPreset();
|
|
180
|
+
const x = useSpring(px, reduced ? { stiffness: 1e4, damping: 1e3 } : FOLLOW);
|
|
181
|
+
const y = useSpring(py, reduced ? { stiffness: 1e4, damping: 1e3 } : FOLLOW);
|
|
182
|
+
React.useEffect(() => {
|
|
183
|
+
x.set(px);
|
|
184
|
+
y.set(py);
|
|
185
|
+
}, [px, py]);
|
|
186
|
+
return { x, y };
|
|
187
|
+
}
|
|
188
|
+
function Area({ color, onChange }) {
|
|
189
|
+
const { active, onPointerDown } = usePointerDrag((e, rect) => {
|
|
190
|
+
onChange({ s: clamp((e.clientX - rect.left) / rect.width, 0, 1), v: clamp(1 - (e.clientY - rect.top) / rect.height, 0, 1) });
|
|
191
|
+
});
|
|
192
|
+
const thumb = useThumb(color.s * 100, (1 - color.v) * 100);
|
|
193
|
+
const left = useTransformPercent(thumb.x);
|
|
194
|
+
const top = useTransformPercent(thumb.y);
|
|
195
|
+
return /* @__PURE__ */ jsx(
|
|
196
|
+
"div",
|
|
197
|
+
{
|
|
198
|
+
className: "fl-color__area",
|
|
199
|
+
role: "slider",
|
|
200
|
+
tabIndex: 0,
|
|
201
|
+
"aria-label": "Saturation and brightness",
|
|
202
|
+
"aria-valuetext": `Saturation ${Math.round(color.s * 100)}%, brightness ${Math.round(color.v * 100)}%`,
|
|
203
|
+
"aria-valuenow": Math.round(color.s * 100),
|
|
204
|
+
"data-active": active || void 0,
|
|
205
|
+
onPointerDown,
|
|
206
|
+
onKeyDown: (e) => {
|
|
207
|
+
const step = e.shiftKey ? 0.1 : 0.01;
|
|
208
|
+
const map = {
|
|
209
|
+
ArrowRight: { s: clamp(color.s + step, 0, 1) },
|
|
210
|
+
ArrowLeft: { s: clamp(color.s - step, 0, 1) },
|
|
211
|
+
ArrowUp: { v: clamp(color.v + step, 0, 1) },
|
|
212
|
+
ArrowDown: { v: clamp(color.v - step, 0, 1) }
|
|
213
|
+
};
|
|
214
|
+
if (map[e.key]) {
|
|
215
|
+
e.preventDefault();
|
|
216
|
+
onChange(map[e.key]);
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
children: /* @__PURE__ */ jsx(motion.span, { className: "fl-color__thumb", style: { left, top } })
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
function Wheel({ color, onChange }) {
|
|
224
|
+
const { active, onPointerDown } = usePointerDrag((e, rect) => {
|
|
225
|
+
const cx2 = rect.left + rect.width / 2;
|
|
226
|
+
const cy = rect.top + rect.height / 2;
|
|
227
|
+
const dx = e.clientX - cx2;
|
|
228
|
+
const dy = e.clientY - cy;
|
|
229
|
+
const h = (Math.atan2(dy, dx) * 180 / Math.PI + 450) % 360;
|
|
230
|
+
onChange({ h, s: clamp(Math.hypot(dx, dy) / (rect.width / 2), 0, 1) });
|
|
231
|
+
});
|
|
232
|
+
const rad = (color.h - 90) * Math.PI / 180;
|
|
233
|
+
const thumb = useThumb(50 + Math.cos(rad) * color.s * 50, 50 + Math.sin(rad) * color.s * 50);
|
|
234
|
+
const left = useTransformPercent(thumb.x);
|
|
235
|
+
const top = useTransformPercent(thumb.y);
|
|
236
|
+
return /* @__PURE__ */ jsxs(
|
|
237
|
+
"div",
|
|
238
|
+
{
|
|
239
|
+
className: "fl-color__wheel",
|
|
240
|
+
role: "slider",
|
|
241
|
+
tabIndex: 0,
|
|
242
|
+
"aria-label": "Hue and saturation",
|
|
243
|
+
"aria-valuetext": `Hue ${Math.round(color.h)} degrees, saturation ${Math.round(color.s * 100)}%`,
|
|
244
|
+
"aria-valuenow": Math.round(color.h),
|
|
245
|
+
"data-active": active || void 0,
|
|
246
|
+
style: { ["--fl-wheel-v"]: 1 - color.v },
|
|
247
|
+
onPointerDown,
|
|
248
|
+
onKeyDown: (e) => {
|
|
249
|
+
const step = e.shiftKey ? 10 : 2;
|
|
250
|
+
const map = {
|
|
251
|
+
ArrowRight: { h: (color.h + step) % 360 },
|
|
252
|
+
ArrowLeft: { h: (color.h - step + 360) % 360 },
|
|
253
|
+
ArrowUp: { s: clamp(color.s + step / 100, 0, 1) },
|
|
254
|
+
ArrowDown: { s: clamp(color.s - step / 100, 0, 1) }
|
|
255
|
+
};
|
|
256
|
+
if (map[e.key]) {
|
|
257
|
+
e.preventDefault();
|
|
258
|
+
onChange(map[e.key]);
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
children: [
|
|
262
|
+
/* @__PURE__ */ jsx("span", { className: "fl-color__wheel-dim", "aria-hidden": true }),
|
|
263
|
+
/* @__PURE__ */ jsx(motion.span, { className: "fl-color__thumb", style: { left, top } })
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
function useTransformPercent(v) {
|
|
269
|
+
return useTransform(v, (n) => `${n}%`);
|
|
270
|
+
}
|
|
271
|
+
function Rail({ label, className, value, onChange, text }) {
|
|
272
|
+
const { active, onPointerDown } = usePointerDrag((e, rect) => onChange(clamp((e.clientX - rect.left) / rect.width, 0, 1)));
|
|
273
|
+
const thumb = useThumb(value * 100, 50);
|
|
274
|
+
const left = useTransformPercent(thumb.x);
|
|
275
|
+
return /* @__PURE__ */ jsx(
|
|
276
|
+
"div",
|
|
277
|
+
{
|
|
278
|
+
className: cx("fl-color__rail", className),
|
|
279
|
+
role: "slider",
|
|
280
|
+
tabIndex: 0,
|
|
281
|
+
"aria-label": label,
|
|
282
|
+
"aria-valuemin": 0,
|
|
283
|
+
"aria-valuemax": 100,
|
|
284
|
+
"aria-valuenow": Math.round(value * 100),
|
|
285
|
+
"aria-valuetext": text,
|
|
286
|
+
"data-active": active || void 0,
|
|
287
|
+
onPointerDown,
|
|
288
|
+
onKeyDown: (e) => {
|
|
289
|
+
const step = e.shiftKey ? 0.1 : 0.01;
|
|
290
|
+
if (e.key === "ArrowRight" || e.key === "ArrowUp") {
|
|
291
|
+
e.preventDefault();
|
|
292
|
+
onChange(clamp(value + step, 0, 1));
|
|
293
|
+
} else if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
|
|
294
|
+
e.preventDefault();
|
|
295
|
+
onChange(clamp(value - step, 0, 1));
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
children: /* @__PURE__ */ jsx(motion.span, { className: "fl-color__thumb", style: { left, top: "50%" } })
|
|
299
|
+
}
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export { ColorPicker };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var React = require('react');
|
|
5
|
+
|
|
6
|
+
function _interopNamespace(e) {
|
|
7
|
+
if (e && e.__esModule) return e;
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
25
|
+
|
|
26
|
+
// src/internal/use-controllable-state.ts
|
|
27
|
+
function useControllableState({
|
|
28
|
+
value,
|
|
29
|
+
defaultValue,
|
|
30
|
+
onChange
|
|
31
|
+
}) {
|
|
32
|
+
const [internal, setInternal] = React__namespace.useState(defaultValue);
|
|
33
|
+
const controlled = value !== void 0;
|
|
34
|
+
const current = controlled ? value : internal;
|
|
35
|
+
const ref = React__namespace.useRef(current);
|
|
36
|
+
ref.current = current;
|
|
37
|
+
const onChangeRef = React__namespace.useRef(onChange);
|
|
38
|
+
onChangeRef.current = onChange;
|
|
39
|
+
const set = React__namespace.useCallback(
|
|
40
|
+
(next) => {
|
|
41
|
+
const resolved = typeof next === "function" ? next(ref.current) : next;
|
|
42
|
+
if (Object.is(resolved, ref.current)) return;
|
|
43
|
+
ref.current = resolved;
|
|
44
|
+
if (!controlled) setInternal(resolved);
|
|
45
|
+
onChangeRef.current?.(resolved);
|
|
46
|
+
},
|
|
47
|
+
[controlled]
|
|
48
|
+
);
|
|
49
|
+
return [current, set];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
exports.useControllableState = useControllableState;
|