@primereact/headless 11.0.0 → 11.2.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/README.md +26 -20
- package/animateonscroll/index.mjs +1 -1
- package/carousel/index.mjs +1 -1
- package/contextmenu/index.mjs +1 -1
- package/datatable/features/index.mjs +8 -8
- package/datatable/index.mjs +8 -8
- package/datepicker/index.mjs +1 -1
- package/dialog/index.mjs +1 -1
- package/dialog/useDialog.d.ts +12 -12
- package/divider/useDivider.d.ts +1 -1
- package/dnd/index.mjs +1 -1
- package/drawer/index.mjs +1 -1
- package/drawer/useDrawer.d.ts +3 -3
- package/gallery/index.mjs +1 -1
- package/gallery/item/index.mjs +1 -1
- package/inputcolor/index.mjs +1 -1
- package/inputpassword/index.mjs +1 -1
- package/listbox/index.mjs +1 -1
- package/menu/checkboxitem/index.mjs +1 -1
- package/menu/index.mjs +1 -1
- package/menu/radioitem/index.mjs +1 -1
- package/message/index.mjs +1 -1
- package/navigationmenu/index.mjs +1 -1
- package/orderlist/index.mjs +1 -1
- package/organizationchart/index.mjs +1 -1
- package/package.json +8 -4
- package/picklist/index.mjs +1 -1
- package/popover/index.mjs +1 -1
- package/progressbar/index.mjs +1 -1
- package/radiobutton/index.mjs +1 -1
- package/radiobuttongroup/index.mjs +1 -1
- package/scrollarea/index.mjs +1 -1
- package/sidebar/index.mjs +1 -1
- package/sidebar/useSidebar.d.ts +79 -25
- package/speeddial/index.mjs +1 -1
- package/styleclass/index.mjs +1 -1
- package/tabs/index.mjs +1 -1
- package/tabs/useTabs.d.ts +6 -0
- package/terminal/index.mjs +1 -1
- package/timeline/useTimeline.d.ts +4 -4
- package/toast/index.mjs +1 -1
- package/toast/useToast.d.ts +1 -1
- package/toaster/index.mjs +1 -1
- package/togglebutton/index.mjs +1 -1
- package/togglebuttongroup/index.mjs +1 -1
- package/toggleswitch/index.mjs +1 -1
- package/toggleswitch/useToggleSwitch.d.ts +14 -0
- package/tooltip/index.mjs +1 -1
- package/tree/index.mjs +1 -1
- package/tree/useTreeKeyboard.d.ts +1 -1
package/dialog/useDialog.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export declare const useDialog: (inProps?: unknown) => import("@primereact/types
|
|
|
62
62
|
'data-open': "";
|
|
63
63
|
'data-scope': string;
|
|
64
64
|
'data-part': string;
|
|
65
|
-
'data-position': "center" | "top" | "left" | "
|
|
65
|
+
'data-position': "center" | "top" | "left" | "bottom" | "right" | "topleft" | "topright" | "bottomleft" | "bottomright" | undefined;
|
|
66
66
|
'data-scroll-behavior': "inside" | "outside" | undefined;
|
|
67
67
|
} | {
|
|
68
68
|
onPointerDown: (event: React.PointerEvent) => void;
|
|
@@ -73,7 +73,7 @@ export declare const useDialog: (inProps?: unknown) => import("@primereact/types
|
|
|
73
73
|
'data-open': "";
|
|
74
74
|
'data-scope': string;
|
|
75
75
|
'data-part': string;
|
|
76
|
-
'data-position': "center" | "top" | "left" | "
|
|
76
|
+
'data-position': "center" | "top" | "left" | "bottom" | "right" | "topleft" | "topright" | "bottomleft" | "bottomright" | undefined;
|
|
77
77
|
'data-scroll-behavior': "inside" | "outside" | undefined;
|
|
78
78
|
} | {
|
|
79
79
|
onPointerDown: (event: React.PointerEvent) => void;
|
|
@@ -84,7 +84,7 @@ export declare const useDialog: (inProps?: unknown) => import("@primereact/types
|
|
|
84
84
|
'data-open': "";
|
|
85
85
|
'data-scope': string;
|
|
86
86
|
'data-part': string;
|
|
87
|
-
'data-position': "center" | "top" | "left" | "
|
|
87
|
+
'data-position': "center" | "top" | "left" | "bottom" | "right" | "topleft" | "topright" | "bottomleft" | "bottomright" | undefined;
|
|
88
88
|
'data-scroll-behavior': "inside" | "outside" | undefined;
|
|
89
89
|
} | {
|
|
90
90
|
onPointerDown: (event: React.PointerEvent) => void;
|
|
@@ -95,7 +95,7 @@ export declare const useDialog: (inProps?: unknown) => import("@primereact/types
|
|
|
95
95
|
'data-open': "";
|
|
96
96
|
'data-scope': string;
|
|
97
97
|
'data-part': string;
|
|
98
|
-
'data-position': "center" | "top" | "left" | "
|
|
98
|
+
'data-position': "center" | "top" | "left" | "bottom" | "right" | "topleft" | "topright" | "bottomleft" | "bottomright" | undefined;
|
|
99
99
|
'data-scroll-behavior': "inside" | "outside" | undefined;
|
|
100
100
|
} | {
|
|
101
101
|
onPointerDown: (event: React.PointerEvent) => void;
|
|
@@ -106,7 +106,7 @@ export declare const useDialog: (inProps?: unknown) => import("@primereact/types
|
|
|
106
106
|
'data-closed': "";
|
|
107
107
|
'data-scope': string;
|
|
108
108
|
'data-part': string;
|
|
109
|
-
'data-position': "center" | "top" | "left" | "
|
|
109
|
+
'data-position': "center" | "top" | "left" | "bottom" | "right" | "topleft" | "topright" | "bottomleft" | "bottomright" | undefined;
|
|
110
110
|
'data-scroll-behavior': "inside" | "outside" | undefined;
|
|
111
111
|
} | {
|
|
112
112
|
onPointerDown: (event: React.PointerEvent) => void;
|
|
@@ -117,7 +117,7 @@ export declare const useDialog: (inProps?: unknown) => import("@primereact/types
|
|
|
117
117
|
'data-closed': "";
|
|
118
118
|
'data-scope': string;
|
|
119
119
|
'data-part': string;
|
|
120
|
-
'data-position': "center" | "top" | "left" | "
|
|
120
|
+
'data-position': "center" | "top" | "left" | "bottom" | "right" | "topleft" | "topright" | "bottomleft" | "bottomright" | undefined;
|
|
121
121
|
'data-scroll-behavior': "inside" | "outside" | undefined;
|
|
122
122
|
} | {
|
|
123
123
|
onPointerDown: (event: React.PointerEvent) => void;
|
|
@@ -128,7 +128,7 @@ export declare const useDialog: (inProps?: unknown) => import("@primereact/types
|
|
|
128
128
|
'data-closed': "";
|
|
129
129
|
'data-scope': string;
|
|
130
130
|
'data-part': string;
|
|
131
|
-
'data-position': "center" | "top" | "left" | "
|
|
131
|
+
'data-position': "center" | "top" | "left" | "bottom" | "right" | "topleft" | "topright" | "bottomleft" | "bottomright" | undefined;
|
|
132
132
|
'data-scroll-behavior': "inside" | "outside" | undefined;
|
|
133
133
|
} | {
|
|
134
134
|
onPointerDown: (event: React.PointerEvent) => void;
|
|
@@ -139,7 +139,7 @@ export declare const useDialog: (inProps?: unknown) => import("@primereact/types
|
|
|
139
139
|
'data-closed': "";
|
|
140
140
|
'data-scope': string;
|
|
141
141
|
'data-part': string;
|
|
142
|
-
'data-position': "center" | "top" | "left" | "
|
|
142
|
+
'data-position': "center" | "top" | "left" | "bottom" | "right" | "topleft" | "topright" | "bottomleft" | "bottomright" | undefined;
|
|
143
143
|
'data-scroll-behavior': "inside" | "outside" | undefined;
|
|
144
144
|
};
|
|
145
145
|
triggerProps: {
|
|
@@ -185,7 +185,7 @@ export declare const useDialog: (inProps?: unknown) => import("@primereact/types
|
|
|
185
185
|
tabIndex: -1;
|
|
186
186
|
'data-scope': string;
|
|
187
187
|
'data-part': string;
|
|
188
|
-
'data-position': "center" | "top" | "left" | "
|
|
188
|
+
'data-position': "center" | "top" | "left" | "bottom" | "right" | "topleft" | "topright" | "bottomleft" | "bottomright" | undefined;
|
|
189
189
|
} | {
|
|
190
190
|
onPointerMove: (event: React.PointerEvent) => void;
|
|
191
191
|
onPointerUp: () => void;
|
|
@@ -199,7 +199,7 @@ export declare const useDialog: (inProps?: unknown) => import("@primereact/types
|
|
|
199
199
|
tabIndex: -1;
|
|
200
200
|
'data-scope': string;
|
|
201
201
|
'data-part': string;
|
|
202
|
-
'data-position': "center" | "top" | "left" | "
|
|
202
|
+
'data-position': "center" | "top" | "left" | "bottom" | "right" | "topleft" | "topright" | "bottomleft" | "bottomright" | undefined;
|
|
203
203
|
} | {
|
|
204
204
|
onPointerMove: (event: React.PointerEvent) => void;
|
|
205
205
|
onPointerUp: () => void;
|
|
@@ -213,7 +213,7 @@ export declare const useDialog: (inProps?: unknown) => import("@primereact/types
|
|
|
213
213
|
tabIndex: -1;
|
|
214
214
|
'data-scope': string;
|
|
215
215
|
'data-part': string;
|
|
216
|
-
'data-position': "center" | "top" | "left" | "
|
|
216
|
+
'data-position': "center" | "top" | "left" | "bottom" | "right" | "topleft" | "topright" | "bottomleft" | "bottomright" | undefined;
|
|
217
217
|
} | {
|
|
218
218
|
onPointerMove: (event: React.PointerEvent) => void;
|
|
219
219
|
onPointerUp: () => void;
|
|
@@ -227,7 +227,7 @@ export declare const useDialog: (inProps?: unknown) => import("@primereact/types
|
|
|
227
227
|
tabIndex: -1;
|
|
228
228
|
'data-scope': string;
|
|
229
229
|
'data-part': string;
|
|
230
|
-
'data-position': "center" | "top" | "left" | "
|
|
230
|
+
'data-position': "center" | "top" | "left" | "bottom" | "right" | "topleft" | "topright" | "bottomleft" | "bottomright" | undefined;
|
|
231
231
|
};
|
|
232
232
|
headerProps: {
|
|
233
233
|
onPointerDown: (event: React.PointerEvent) => void;
|
package/divider/useDivider.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const useDivider: (inProps?: unknown) => import("@primereact/type
|
|
|
5
5
|
role: "separator";
|
|
6
6
|
'aria-orientation': "horizontal" | "vertical" | undefined;
|
|
7
7
|
'data-orientation': "horizontal" | "vertical" | undefined;
|
|
8
|
-
'data-align': "center" | "top" | "left" | "
|
|
8
|
+
'data-align': "center" | "top" | "left" | "bottom" | "right" | undefined;
|
|
9
9
|
};
|
|
10
10
|
contentProps: {
|
|
11
11
|
'data-scope': string;
|
package/dnd/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{withHeadless as pe}from"@primereact/core/headless";import*as T from"react";var J={onSort:void 0,onTransfer:void 0};var Q={dragging:!1,activeContainerId:null,currentContainerId:null,fromIndex:-1,projectedIndex:-1};function ge(n){let t=new Map,o={...Q},s=new Set,p=()=>{for(let u of s)u()};return{uid:n,containers:t,getState(){return o},subscribe(u){return s.add(u),()=>{s.delete(u)}},setState(u){o={...o,...u},p()},onSort:void 0,onTransfer:void 0}}var be=()=>()=>{},Te=pe({name:"useDnd",defaultProps:J,setup({props:n}){let t=T.useId(),o=T.useRef(null);o.current||(o.current=ge(t));let s=o.current;s.onSort=n.onSort,s.onTransfer=n.onTransfer;let p=T.useCallback(y=>s.subscribe(y),[s]),u=T.useCallback(()=>s.getState(),[s]),h={dragging:T.useSyncExternalStore(s?p:be,s?u:()=>Q,()=>Q).dragging},c={"data-scope":"dnd","data-part":"root",...h.dragging?{"data-dragging":""}:void 0};return{state:h,dnd:s,rootProps:c}}});import{withHeadless as he}from"@primereact/core/headless";import*as R from"react";var V={dnd:void 0,id:void 0,disabled:!1,scope:void 0,data:void 0,sensor:"both",pointerOptions:void 0,keyboardOptions:void 0};var ye=()=>()=>{},ke=he({name:"useDraggable",defaultProps:V,setup({props:n,elementRef:t}){let o=n.dnd,s=n.id,p=R.useRef(n.data??{});R.useEffect(()=>{p.current=n.data??{}},[n.data]),R.useEffect(()=>{if(!o||s==null)return;let y=t?.current??null;return o.registerDraggable({id:s,node:y,disabled:n.disabled,scope:n.scope,get data(){return p.current}})},[o,s,n.disabled,n.scope,t]),R.useEffect(()=>{if(!o||s==null||n.disabled)return;let y=t?.current;if(!y)return;let M=[];return n.sensor!=="keyboard"&&M.push(o.attachPointerSensor(y,s,n.pointerOptions)),n.sensor!=="pointer"&&M.push(o.attachKeyboardSensor(y,s,n.keyboardOptions)),()=>{for(let z of M)z()}},[o,s,n.disabled,n.sensor,n.pointerOptions,n.keyboardOptions,t]);let u=R.useCallback(y=>o?o.subscribe(y):()=>{},[o]),C=R.useSyncExternalStore(o?u:ye,()=>o?o.getState().operation?.activeId===s:!1,()=>!1),h={isDragging:C},c=R.useMemo(()=>({"data-scope":"dnd","data-part":"draggable",...C?{"data-dragging":""}:void 0,...n.disabled?{"data-disabled":""}:void 0,tabIndex:n.disabled?-1:0,role:"button","aria-roledescription":"draggable"}),[C,n.disabled]);return{state:h,rootProps:c}}});import{withHeadless as Ie}from"@primereact/core/headless";import*as $ from"react";var W={dnd:void 0,id:void 0,disabled:!1,accept:void 0,data:void 0,canDrop:void 0};var xe=()=>()=>{},Ue=Ie({name:"useDroppable",defaultProps:W,setup({props:n,elementRef:t}){let o=n.dnd,s=n.id;$.useEffect(()=>{if(!o||s==null)return;let c=t?.current??null;return o.registerDroppable({id:s,node:c,disabled:n.disabled,accept:n.accept,data:n.data,canDrop:n.canDrop})},[o,s,n.disabled,n.accept,n.data,n.canDrop,t]);let p=$.useCallback(c=>o?o.subscribe(c):()=>{},[o]),u=$.useSyncExternalStore(o?p:xe,()=>{if(!o||s==null)return!1;let c=o.getState().collisions;return c.length>0&&c[0].id===s},()=>!1),C={isOver:u},h=$.useMemo(()=>({"data-scope":"dnd","data-part":"droppable",...u?{"data-over":""}:void 0,...n.disabled?{"data-disabled":""}:void 0}),[u,n.disabled]);return{state:C,rootProps:h}}});import{withHeadless as Se}from"@primereact/core/headless";import*as N from"react";var Z={dnd:void 0,id:void 0,index:void 0,disabled:!1};var Re=()=>()=>{},Xe=Se({name:"useSortable",defaultProps:Z,setup({props:n}){let t=n.dnd,o=n.id,s=N.useCallback(h=>t?t.subscribe(h):()=>{},[t]),p=N.useSyncExternalStore(t?s:Re,()=>{if(!t||o==null)return!1;let h=t.getState();return h.dragging&&h.fromIndex===n.index},()=>!1),u={isDragging:p},C=N.useMemo(()=>({"data-scope":"dnd","data-part":"sortable",...p?{"data-dragging":""}:void 0,...n.disabled?{"data-disabled":""}:void 0}),[p,n.disabled]);return{state:u,rootProps:C}}});import{withHeadless as Ce}from"@primereact/core/headless";import*as x from"react";import{flushSync as Ee}from"react-dom";var ee={dnd:void 0,id:void 0,items:void 0,disabled:!1,placeholder:"empty",onSort:void 0};var A=n=>Array.from(n.querySelectorAll(":scope > [data-sortable-item]")),Je=Ce({name:"useSortableContainer",defaultProps:ee,setup({props:n}){let t=n.dnd,o=n.id,s=n.items??[],p=n.disabled??!1,u=n.placeholder??"clone",C=n.onSort,h=t?`${t.uid}_${o}`:String(o),c=x.useRef(null);x.useEffect(()=>{if(!(!t||o==null))return t.containers.set(o,{listRef:c,items:s}),()=>{t.containers.delete(o)}},[t,o]);let y=x.useRef(s);y.current=s,x.useEffect(()=>{if(t&&o!=null){let f=t.containers.get(o);f&&(f.items=s)}},[t,o,s]);let[M,z]=x.useState(!1),q=x.useRef(0),L=x.useRef(null),se=(f,i,r,B,Y,X,_)=>{let O=X+_,H=A(f);for(let E=0;E<H.length;E++){let w=E<i?E:E+1,k=0;i<r?w>i&&w<=r&&(k=-O):i>r&&w>=r&&w<i&&(k=O),H[E].style.transform=k?`translateY(${k}px)`:""}Y.style.transform=r!==i?`translateY(${(r-i)*O}px)`:""},ie=f=>{if(f)for(let i of A(f))i.style.transform=""},ae=f=>{let i=A(f);return i.length>1?i[1].getBoundingClientRect().top-i[0].getBoundingClientRect().bottom:4},de=(f,i)=>{let r=f.cloneNode(!0);return r.setAttribute("inert","true"),r.removeAttribute("data-sortable-item"),r.removeAttribute("data-sortable-container"),r.style.position="fixed",r.style.zIndex="9999",r.style.pointerEvents="none",r.style.width=`${i.width}px`,r.style.height=`${i.height}px`,r.style.left=`${i.left}px`,r.style.top=`${i.top}px`,r.style.margin="0",r.style.transform="translate(0px, 0px)",r.style.transition="none",r.style.opacity="0.9",r.style.boxShadow="0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)",document.body.appendChild(r),r},le=()=>{if(t){for(let[f,i]of t.containers)if(!i.listRef.current||!i.listRef.current.isConnected){let r=`${t.uid}_${f}`,B=document.querySelector(`[data-sortable-list="${r}"]`);B&&(i.listRef.current=B)}}},ce=f=>p?{"data-sortable-item":"","data-sortable-container":String(o)}:{"data-sortable-item":"","data-sortable-container":String(o),onPointerDown:i=>{if(i.button!==0||p)return;let r=i.currentTarget,B=r.parentElement;if(B&&(c.current=B,t&&o!=null)){let e=t.containers.get(o);e&&(e.listRef.current=B)}le();let Y=r.getBoundingClientRect(),X=i.clientX,_=i.clientY,O=!1,H=o,E=t?t.containers.size>1:!1,w=new Map;if(t)for(let[e,g]of t.containers)w.set(e,[...g.items]);else w.set(o,[...y.current]);let k=X,U=_,te=()=>{let e=L.current;if(!e)return;let g=e.originContainerId;if(E&&t)for(let[l,S]of t.containers){if(!S.listRef.current||!S.listRef.current.isConnected){let re=`${t.uid}_${l}`,G=document.querySelector(`[data-sortable-list="${re}"]`);G&&(S.listRef.current=G)}let P=S.listRef.current?.getBoundingClientRect();if(P&&k>=P.left&&k<=P.right&&U>=P.top&&U<=P.bottom){g=l;break}}let m=E&&t?t.containers.get(g)?.listRef.current:c.current;if(!m)return;let v=((E&&t?t.containers.get(e.originContainerId)?.listRef.current:c.current)?.scrollTop??0)-e.startScrollTop,F=U-e.startY,d=e.itemHeight+e.gap,b=e.itemsAtStart.get(g)??[],a;if(g===e.originContainerId)a=e.fromIndex+Math.round((F+v)/d),a=Math.max(0,Math.min(b.length-1,a));else{let l=m.getBoundingClientRect(),S=parseFloat(getComputedStyle(m).paddingTop)||0,P=U-l.top-S;a=Math.round(P/d),a=Math.max(0,Math.min(b.length,a))}let I=g!==e.currentContainerId;if(I||a!==e.projectedIndex){if(I&&t){let l=t.containers.get(e.currentContainerId)?.listRef.current;l&&ie(l)}if(e.currentContainerId=g,e.projectedIndex=a,t&&t.setState({currentContainerId:g,projectedIndex:a}),g===e.originContainerId)I&&e.node.parentElement?.insertBefore(e.clone,e.node),e.clone.style.height=`${e.itemHeight}px`,e.clone.style.overflow="",se(m,e.fromIndex,a,e.node,e.clone,e.itemHeight,e.gap);else{let l=A(m),S=l.length>=2?l[1].getBoundingClientRect().top-l[0].getBoundingClientRect().top:e.itemHeight+e.gap;I&&(document.body.appendChild(e.clone),e.clone.style.position="fixed",e.clone.style.height=`${e.itemHeight}px`,e.clone.style.overflow="hidden",e.clone.style.transform="",e.clone.style.margin="0",e.clone.style.zIndex="9998",e.clone.style.pointerEvents="none",e.clone.style.boxSizing="border-box",m.style.position="");let P=m.getBoundingClientRect(),re=m.scrollTop,G=parseFloat(getComputedStyle(m).paddingTop)||0,K;if(l.length===0)K=P.top+G;else if(a<l.length)K=l[a].getBoundingClientRect().top;else{let j=l[l.length-1];K=j.getBoundingClientRect().bottom+(S-j.getBoundingClientRect().height)}e.clone.style.top=`${K}px`,e.clone.style.left=`${P.left}px`,e.clone.style.width=`${P.width}px`,e.clone.style.transform="";for(let j=0;j<l.length;j++)l[j].style.transform=j>=a?`translateY(${S}px)`:""}}return m},ne=e=>{let g=Math.sqrt((e.clientX-X)**2+(e.clientY-_)**2);if(!O&&g<5)return;if(!O){O=!0;let v=c.current,F=v?ae(v):4,d;u==="empty"?d=document.createElement(r.tagName):d=r.cloneNode(!0),d.setAttribute("inert","true"),d.setAttribute("data-sortable-placeholder",""),d.removeAttribute("data-sortable-item"),d.removeAttribute("data-sortable-container"),d.style.width=`${Y.width}px`,d.style.height=`${Y.height}px`,d.style.flexShrink="0",d.style.transition="transform 200ms ease, opacity 150ms ease",d.style.opacity="0",r.parentElement?.insertBefore(d,r),requestAnimationFrame(()=>{d.style.opacity="1"}),c.current?.blur();let b=de(r,Y);r.setAttribute("data-dragging",""),r.removeAttribute("data-sortable-item"),r.style.position="absolute",r.style.visibility="hidden",r.style.pointerEvents="none";let a=r.parentElement;if(a)for(let I of A(a))I!==r&&(I.style.pointerEvents="none",I.style.transition="transform 200ms ease");if(t){for(let[I,l]of t.containers)if(I!==H&&l.listRef.current)for(let S of A(l.listRef.current))S.style.pointerEvents="none",S.style.transition="transform 200ms ease"}L.current={startX:X,startY:_,startScrollTop:v?.scrollTop??0,node:r,ghost:b,clone:d,itemHeight:Y.height,gap:F,fromIndex:f,projectedIndex:f,originContainerId:H,currentContainerId:H,itemsAtStart:w},z(!0),t&&t.setState({dragging:!0,activeContainerId:H,currentContainerId:H,fromIndex:f,projectedIndex:f})}let m=L.current;if(!m)return;k=e.clientX,U=e.clientY,m.ghost.style.transform=`translate(${e.clientX-m.startX}px, ${e.clientY-m.startY}px)`;let D=te();if(cancelAnimationFrame(q.current),D){let d=()=>{let b=D.getBoundingClientRect(),a=U-b.top,I=b.bottom-U,l=!1;a>0&&a<40?(D.scrollTop-=8,l=!0):I>0&&I<40&&(D.scrollTop+=8,l=!0),l&&(L.current&&(L.current.projectedIndex=-1),te(),q.current=requestAnimationFrame(d))};d()}},oe=()=>{document.removeEventListener("pointermove",ne),document.removeEventListener("pointerup",oe),cancelAnimationFrame(q.current);let e=L.current;if(!e)return;let g=e.currentContainerId!==e.originContainerId,m=!1,D=()=>{if(m)return;m=!0,e.ghost.removeEventListener("transitionend",D),cancelAnimationFrame(q.current),e.ghost.remove(),e.clone.remove();let v=[];if(t&&t.containers.size>1)for(let[,b]of t.containers)b.listRef.current&&v.push(b.listRef.current);else c.current&&v.push(c.current);e.node.style.position="",e.node.removeAttribute("data-dragging"),e.node.setAttribute("data-sortable-item","");for(let b of v)for(let a of A(b))a.style.transition="none",a.style.transform="",a.style.pointerEvents="";Ee(()=>{g?t?.onTransfer?.({from:{containerId:e.originContainerId,index:e.fromIndex},to:{containerId:e.currentContainerId,index:e.projectedIndex}}):e.fromIndex!==e.projectedIndex&&(t?.onSort?t.onSort({containerId:e.originContainerId,fromIndex:e.fromIndex,toIndex:e.projectedIndex}):C&&C({containerId:e.originContainerId,fromIndex:e.fromIndex,toIndex:e.projectedIndex}))});for(let b of v){b.offsetHeight;for(let a of A(b))a.style.transition="",a.style.visibility="",a.style.pointerEvents=""}L.current=null,z(!1),t&&t.setState({dragging:!1,activeContainerId:null,currentContainerId:null,fromIndex:-1,projectedIndex:-1});let F=g?e.currentContainerId:e.originContainerId,d=E&&t?t.containers.get(F)?.listRef.current:c.current;d&&(d.dataset.dndFocusIndex=String(e.projectedIndex),d.focus(),delete d.dataset.dndFocusIndex)};e.ghost.style.transition="opacity 150ms ease-out",e.ghost.style.opacity="0",e.ghost.addEventListener("transitionend",D,{once:!0}),setTimeout(()=>{L.current===e&&D()},200)};document.addEventListener("pointermove",ne),document.addEventListener("pointerup",oe)}},ue={dragging:M},fe=x.useMemo(()=>({"data-scope":"dnd","data-part":"sortable-container",...M?{"data-active":""}:void 0,...p?{"data-disabled":""}:void 0}),[M,p]),me=x.useMemo(()=>({"data-sortable-list":h}),[h]);return{state:ue,getItemDndProps:ce,listProps:me,rootProps:fe}}});export{J as defaultDndProps,V as defaultDraggableProps,W as defaultDroppableProps,ee as defaultSortableContainerProps,Z as defaultSortableProps,Te as useDnd,ke as useDraggable,Ue as useDroppable,Xe as useSortable,Je as useSortableContainer};
|
|
1
|
+
import{withHeadless as me}from"@primereact/core/headless";import*as T from"react";var J={onSort:void 0,onTransfer:void 0};var Q={dragging:!1,activeContainerId:null,currentContainerId:null,fromIndex:-1,projectedIndex:-1};function pe(n){let t=new Map,o={...Q},s=new Set,m=()=>{for(let u of s)u()};return{uid:n,containers:t,getState(){return o},subscribe(u){return s.add(u),()=>{s.delete(u)}},setState(u){o={...o,...u},m()},onSort:void 0,onTransfer:void 0}}var ge=()=>()=>{},De=me({name:"useDnd",defaultProps:J,setup({props:n}){let t=T.useId(),o=T.useRef(null);o.current||(o.current=pe(t));let s=o.current;s.onSort=n.onSort,s.onTransfer=n.onTransfer;let m=T.useCallback(y=>s.subscribe(y),[s]),u=T.useCallback(()=>s.getState(),[s]),h={dragging:T.useSyncExternalStore(s?m:ge,s?u:()=>Q,()=>Q).dragging},c={"data-scope":"dnd","data-part":"root",...h.dragging?{"data-dragging":""}:void 0};return{state:h,dnd:s,rootProps:c}}});import{withHeadless as be}from"@primereact/core/headless";import*as R from"react";var V={dnd:void 0,id:void 0,disabled:!1,scope:void 0,data:void 0,sensor:"both",pointerOptions:void 0,keyboardOptions:void 0};var he=()=>()=>{},we=be({name:"useDraggable",defaultProps:V,setup({props:n,elementRef:t}){let o=n.dnd,s=n.id,m=R.useRef(n.data??{});R.useEffect(()=>{m.current=n.data??{}},[n.data]),R.useEffect(()=>{if(!o||s==null)return;let y=t?.current??null;return o.registerDraggable({id:s,node:y,disabled:n.disabled,scope:n.scope,get data(){return m.current}})},[o,s,n.disabled,n.scope,t]),R.useEffect(()=>{if(!o||s==null||n.disabled)return;let y=t?.current;if(!y)return;let M=[];return n.sensor!=="keyboard"&&M.push(o.attachPointerSensor(y,s,n.pointerOptions)),n.sensor!=="pointer"&&M.push(o.attachKeyboardSensor(y,s,n.keyboardOptions)),()=>{for(let q of M)q()}},[o,s,n.disabled,n.sensor,n.pointerOptions,n.keyboardOptions,t]);let u=R.useCallback(y=>o?o.subscribe(y):()=>{},[o]),C=R.useSyncExternalStore(o?u:he,()=>o?o.getState().operation?.activeId===s:!1,()=>!1),h={isDragging:C},c=R.useMemo(()=>({"data-scope":"dnd","data-part":"draggable",...C?{"data-dragging":""}:void 0,...n.disabled?{"data-disabled":""}:void 0,tabIndex:n.disabled?-1:0,role:"button","aria-roledescription":"draggable"}),[C,n.disabled]);return{state:h,rootProps:c}}});import{withHeadless as ye}from"@primereact/core/headless";import*as $ from"react";var W={dnd:void 0,id:void 0,disabled:!1,accept:void 0,data:void 0,canDrop:void 0};var Ie=()=>()=>{},Oe=ye({name:"useDroppable",defaultProps:W,setup({props:n,elementRef:t}){let o=n.dnd,s=n.id;$.useEffect(()=>{if(!o||s==null)return;let c=t?.current??null;return o.registerDroppable({id:s,node:c,disabled:n.disabled,accept:n.accept,data:n.data,canDrop:n.canDrop})},[o,s,n.disabled,n.accept,n.data,n.canDrop,t]);let m=$.useCallback(c=>o?o.subscribe(c):()=>{},[o]),u=$.useSyncExternalStore(o?m:Ie,()=>{if(!o||s==null)return!1;let c=o.getState().collisions;return c.length>0&&c[0].id===s},()=>!1),C={isOver:u},h=$.useMemo(()=>({"data-scope":"dnd","data-part":"droppable",...u?{"data-over":""}:void 0,...n.disabled?{"data-disabled":""}:void 0}),[u,n.disabled]);return{state:C,rootProps:h}}});import{withHeadless as xe}from"@primereact/core/headless";import*as X from"react";var Z={dnd:void 0,id:void 0,index:void 0,disabled:!1};var Se=()=>()=>{},Ne=xe({name:"useSortable",defaultProps:Z,setup({props:n}){let t=n.dnd,o=n.id,s=X.useCallback(h=>t?t.subscribe(h):()=>{},[t]),m=X.useSyncExternalStore(t?s:Se,()=>{if(!t||o==null)return!1;let h=t.getState();return h.dragging&&h.fromIndex===n.index},()=>!1),u={isDragging:m},C=X.useMemo(()=>({"data-scope":"dnd","data-part":"sortable",...m?{"data-dragging":""}:void 0,...n.disabled?{"data-disabled":""}:void 0}),[m,n.disabled]);return{state:u,rootProps:C}}});import{withHeadless as Re}from"@primereact/core/headless";import*as x from"react";import{flushSync as Ce}from"react-dom";var ee={dnd:void 0,id:void 0,items:void 0,disabled:!1,placeholder:"empty",onSort:void 0};var A=n=>Array.from(n.querySelectorAll(":scope > [data-sortable-item]")),Ke=Re({name:"useSortableContainer",defaultProps:ee,setup({props:n}){let t=n.dnd,o=n.id,s=n.items??[],m=n.disabled??!1,u=n.placeholder??"clone",C=n.onSort,h=t?`${t.uid}_${o}`:String(o),c=x.useRef(null);x.useEffect(()=>{if(!(!t||o==null))return t.containers.set(o,{listRef:c,items:s}),()=>{t.containers.delete(o)}},[t,o]);let y=x.useRef(s);y.current=s,x.useEffect(()=>{if(t&&o!=null){let f=t.containers.get(o);f&&(f.items=s)}},[t,o,s]);let[M,q]=x.useState(!1),G=x.useRef(0),L=x.useRef(null),re=(f,i,r,B,F,_,z)=>{let O=_+z,H=A(f);for(let E=0;E<H.length;E++){let w=E<i?E:E+1,k=0;i<r?w>i&&w<=r&&(k=-O):i>r&&w>=r&&w<i&&(k=O),H[E].style.transform=k?`translateY(${k}px)`:""}F.style.transform=r!==i?`translateY(${(r-i)*O}px)`:""},se=f=>{if(f)for(let i of A(f))i.style.transform=""},ie=f=>{let i=A(f);return i.length>1?i[1].getBoundingClientRect().top-i[0].getBoundingClientRect().bottom:4},ae=(f,i)=>{let r=f.cloneNode(!0);return r.setAttribute("inert","true"),r.removeAttribute("data-sortable-item"),r.removeAttribute("data-sortable-container"),r.style.position="fixed",r.style.zIndex="9999",r.style.pointerEvents="none",r.style.width=`${i.width}px`,r.style.height=`${i.height}px`,r.style.left=`${i.left}px`,r.style.top=`${i.top}px`,r.style.margin="0",r.style.transform="translate(0px, 0px)",r.style.transition="none",r.style.opacity="0.9",r.style.boxShadow="0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)",document.body.appendChild(r),r},de=()=>{if(t){for(let[f,i]of t.containers)if(!i.listRef.current||!i.listRef.current.isConnected){let r=`${t.uid}_${f}`,B=document.querySelector(`[data-sortable-list="${r}"]`);B&&(i.listRef.current=B)}}},le=f=>m?{"data-sortable-item":"","data-sortable-container":String(o)}:{"data-sortable-item":"","data-sortable-container":String(o),onPointerDown:i=>{if(i.button!==0||m)return;let r=i.currentTarget,B=r.parentElement;if(B&&(c.current=B,t&&o!=null)){let e=t.containers.get(o);e&&(e.listRef.current=B)}de();let F=r.getBoundingClientRect(),_=i.clientX,z=i.clientY,O=!1,H=o,E=t?t.containers.size>1:!1,w=new Map;if(t)for(let[e,g]of t.containers)w.set(e,[...g.items]);else w.set(o,[...y.current]);let k=_,U=z,te=()=>{let e=L.current;if(!e)return;let g=e.originContainerId;if(E&&t)for(let[l,S]of t.containers){if(!S.listRef.current||!S.listRef.current.isConnected){let K=`${t.uid}_${l}`,j=document.querySelector(`[data-sortable-list="${K}"]`);j&&(S.listRef.current=j)}let P=S.listRef.current?.getBoundingClientRect();if(P&&k>=P.left&&k<=P.right&&U>=P.top&&U<=P.bottom){g=l;break}}let p=E&&t?t.containers.get(g)?.listRef.current:c.current;if(!p)return;let v=((E&&t?t.containers.get(e.originContainerId)?.listRef.current:c.current)?.scrollTop??0)-e.startScrollTop,N=U-e.startY,d=e.itemHeight+e.gap,b=e.itemsAtStart.get(g)??[],a;if(g===e.originContainerId)a=e.fromIndex+Math.round((N+v)/d),a=Math.max(0,Math.min(b.length-1,a));else{let l=p.getBoundingClientRect(),S=parseFloat(getComputedStyle(p).paddingTop)||0,P=U-l.top-S;a=Math.round(P/d),a=Math.max(0,Math.min(b.length,a))}let I=g!==e.currentContainerId;if(I||a!==e.projectedIndex){if(I&&t){let l=t.containers.get(e.currentContainerId)?.listRef.current;l&&se(l)}if(e.currentContainerId=g,e.projectedIndex=a,t&&t.setState({currentContainerId:g,projectedIndex:a}),g===e.originContainerId)I&&e.node.parentElement?.insertBefore(e.clone,e.node),e.clone.style.height=`${e.itemHeight}px`,e.clone.style.overflow="",re(p,e.fromIndex,a,e.node,e.clone,e.itemHeight,e.gap);else{let l=A(p),S=l.length>=2?l[1].getBoundingClientRect().top-l[0].getBoundingClientRect().top:e.itemHeight+e.gap;I&&(document.body.appendChild(e.clone),e.clone.style.position="fixed",e.clone.style.height=`${e.itemHeight}px`,e.clone.style.overflow="hidden",e.clone.style.transform="",e.clone.style.margin="0",e.clone.style.zIndex="9998",e.clone.style.pointerEvents="none",e.clone.style.boxSizing="border-box",p.style.position="");let P=p.getBoundingClientRect(),K=parseFloat(getComputedStyle(p).paddingTop)||0,j;if(l.length===0)j=P.top+K;else if(a<l.length)j=l[a].getBoundingClientRect().top;else{let Y=l[l.length-1];j=Y.getBoundingClientRect().bottom+(S-Y.getBoundingClientRect().height)}e.clone.style.top=`${j}px`,e.clone.style.left=`${P.left}px`,e.clone.style.width=`${P.width}px`,e.clone.style.transform="";for(let Y=0;Y<l.length;Y++)l[Y].style.transform=Y>=a?`translateY(${S}px)`:""}}return p},ne=e=>{let g=Math.sqrt((e.clientX-_)**2+(e.clientY-z)**2);if(!O&&g<5)return;if(!O){O=!0;let v=c.current,N=v?ie(v):4,d;u==="empty"?d=document.createElement(r.tagName):d=r.cloneNode(!0),d.setAttribute("inert","true"),d.setAttribute("data-sortable-placeholder",""),d.removeAttribute("data-sortable-item"),d.removeAttribute("data-sortable-container"),d.style.width=`${F.width}px`,d.style.height=`${F.height}px`,d.style.flexShrink="0",d.style.transition="transform 200ms ease, opacity 150ms ease",d.style.opacity="0",r.parentElement?.insertBefore(d,r),requestAnimationFrame(()=>{d.style.opacity="1"}),c.current?.blur();let b=ae(r,F);r.setAttribute("data-dragging",""),r.removeAttribute("data-sortable-item"),r.style.position="absolute",r.style.visibility="hidden",r.style.pointerEvents="none";let a=r.parentElement;if(a)for(let I of A(a))I!==r&&(I.style.pointerEvents="none",I.style.transition="transform 200ms ease");if(t){for(let[I,l]of t.containers)if(I!==H&&l.listRef.current)for(let S of A(l.listRef.current))S.style.pointerEvents="none",S.style.transition="transform 200ms ease"}L.current={startX:_,startY:z,startScrollTop:v?.scrollTop??0,node:r,ghost:b,clone:d,itemHeight:F.height,gap:N,fromIndex:f,projectedIndex:f,originContainerId:H,currentContainerId:H,itemsAtStart:w},q(!0),t&&t.setState({dragging:!0,activeContainerId:H,currentContainerId:H,fromIndex:f,projectedIndex:f})}let p=L.current;if(!p)return;k=e.clientX,U=e.clientY,p.ghost.style.transform=`translate(${e.clientX-p.startX}px, ${e.clientY-p.startY}px)`;let D=te();if(cancelAnimationFrame(G.current),D){let d=()=>{let b=D.getBoundingClientRect(),a=U-b.top,I=b.bottom-U,l=!1;a>0&&a<40?(D.scrollTop-=8,l=!0):I>0&&I<40&&(D.scrollTop+=8,l=!0),l&&(L.current&&(L.current.projectedIndex=-1),te(),G.current=requestAnimationFrame(d))};d()}},oe=()=>{document.removeEventListener("pointermove",ne),document.removeEventListener("pointerup",oe),cancelAnimationFrame(G.current);let e=L.current;if(!e)return;let g=e.currentContainerId!==e.originContainerId,p=!1,D=()=>{if(p)return;p=!0,e.ghost.removeEventListener("transitionend",D),cancelAnimationFrame(G.current),e.ghost.remove(),e.clone.remove();let v=[];if(t&&t.containers.size>1)for(let[,b]of t.containers)b.listRef.current&&v.push(b.listRef.current);else c.current&&v.push(c.current);e.node.style.position="",e.node.removeAttribute("data-dragging"),e.node.setAttribute("data-sortable-item","");for(let b of v)for(let a of A(b))a.style.transition="none",a.style.transform="",a.style.pointerEvents="";Ce(()=>{g?t?.onTransfer?.({from:{containerId:e.originContainerId,index:e.fromIndex},to:{containerId:e.currentContainerId,index:e.projectedIndex}}):e.fromIndex!==e.projectedIndex&&(t?.onSort?t.onSort({containerId:e.originContainerId,fromIndex:e.fromIndex,toIndex:e.projectedIndex}):C&&C({containerId:e.originContainerId,fromIndex:e.fromIndex,toIndex:e.projectedIndex}))});for(let b of v){b.offsetHeight;for(let a of A(b))a.style.transition="",a.style.visibility="",a.style.pointerEvents=""}L.current=null,q(!1),t&&t.setState({dragging:!1,activeContainerId:null,currentContainerId:null,fromIndex:-1,projectedIndex:-1});let N=g?e.currentContainerId:e.originContainerId,d=E&&t?t.containers.get(N)?.listRef.current:c.current;d&&(d.dataset.dndFocusIndex=String(e.projectedIndex),d.focus(),delete d.dataset.dndFocusIndex)};e.ghost.style.transition="opacity 150ms ease-out",e.ghost.style.opacity="0",e.ghost.addEventListener("transitionend",D,{once:!0}),setTimeout(()=>{L.current===e&&D()},200)};document.addEventListener("pointermove",ne),document.addEventListener("pointerup",oe)}},ce={dragging:M},ue=x.useMemo(()=>({"data-scope":"dnd","data-part":"sortable-container",...M?{"data-active":""}:void 0,...m?{"data-disabled":""}:void 0}),[M,m]),fe=x.useMemo(()=>({"data-sortable-list":h}),[h]);return{state:ce,getItemDndProps:le,listProps:fe,rootProps:ue}}});export{J as defaultDndProps,V as defaultDraggableProps,W as defaultDroppableProps,ee as defaultSortableContainerProps,Z as defaultSortableProps,De as useDnd,we as useDraggable,Oe as useDroppable,Ne as useSortable,Ke as useSortableContainer};
|
package/drawer/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{withHeadless as
|
|
1
|
+
import{withHeadless as G}from"@primereact/core/headless";import{useFocusTrap as J}from"@primereact/headless/focustrap";import{useEventListener as v,useUnmountEffect as Q}from"@primereact/hooks";import{useControlledState as W}from"@primereact/hooks/use-controlled-state";import{$dt as y}from"@primeuix/styled";import{blockBodyScroll as X,focus as Y,toElement as p,unblockBodyScroll as $,ZIndex as c}from"@primeuix/utils";import*as n from"react";var T={open:void 0,defaultOpen:void 0,trapped:!0,blockScroll:!1,dismissable:!0,baseZIndex:0,autoZIndex:!0,position:"left",onOpenChange:void 0,onExitComplete:void 0};var ce=G({name:"useDrawer",defaultProps:T,setup:({props:t,id:u,elementRef:R,$primereact:E})=>{let{onExitComplete:b}=t,[a,k]=W({value:t.open,defaultValue:t.defaultOpen,onChange:t.onOpenChange}),[r,H]=n.useState(null),[s,D]=n.useState(null),d=n.useRef(null),f=n.useRef(null),M=n.useRef(null),w=n.useRef(null),i=n.useRef(null),g={open:!!a,trapped:!!t.trapped,popupElement:r,backdropElement:s},m=J({trapped:!!t.trapped&&!!r,autoFocus:!0});Q(()=>{t.autoZIndex&&d.current&&c.clear(d.current)});let O=n.useCallback(e=>{let o=p(e)??null;o!==d.current&&(d.current=o,m.containerRef.current=o,H(o))},[m.containerRef]),h=n.useCallback(e=>{let o=p(e)??null;o!==f.current&&(f.current=o,D(o))},[]),I=n.useCallback(e=>{let o=p(e)??null;o!==M.current&&(M.current=o)},[]),l=()=>{k([!1,{value:!1}])},C=()=>{let e=!a;k([e,{value:e}])},P=n.useCallback(()=>{},[]),S=n.useCallback(()=>{b?.()},[b]),[Z,B]=v({type:"keydown",listener:e=>j(e)}),[K,U]=v({type:"click",listener:e=>{N(e)&&l()}});n.useEffect(()=>{a?(i.current=document.activeElement,Z(),t.dismissable&&K(),t.blockScroll&&X({variableName:y("scrollbar.width").name})):(B(),U(),t.blockScroll&&$({variableName:y("scrollbar.width").name}),i.current&&(Y(i.current),i.current=null))},[a]),n.useEffect(()=>{if(r){if(t.autoZIndex){let e=(t.baseZIndex??0)+(E.config?.zIndex?.modal??1100);s&&c.set("modal",s,e),c.set("modal",r,e)}return()=>{t.autoZIndex&&(s&&c.clear(s),c.clear(r))}}},[r,s,t.autoZIndex,t.baseZIndex,E.config?.zIndex?.modal]);let N=e=>R.current&&!R.current.contains(e.target),j=e=>{e.code==="Escape"&&l()},L=e=>{w.current=e.target},x=()=>{t.dismissable&&f.current===w.current&&l()},z={id:u,"data-scope":"drawer","data-part":"root",...a?{"data-open":""}:{"data-closed":""},"data-position":t.position},F={"data-scope":"drawer","data-part":"trigger",type:"button","aria-expanded":a??!1,"aria-controls":u??"",onClick:C},V={ref:h,onMouseDown:L,onMouseUp:x},_={"data-scope":"drawer","data-part":"close",type:"button",ref:I,onClick:l},q={id:u+"_header","data-scope":"drawer","data-part":"header"},A={id:u,ref:O,role:"complementary","aria-modal":!0,tabIndex:-1,"data-scope":"drawer","data-part":"root","data-position":t.position,...a&&{"data-open":""}};return{state:g,focusTrap:m,triggerProps:F,rootProps:z,backdropProps:V,closeProps:_,headerProps:q,popupProps:A,close:l,onOpenStateChange:C,onMaskMouseDown:L,onMaskMouseUp:x,onOpenComplete:P,onCloseComplete:S}}});export{T as defaultProps,ce as useDrawer};
|
package/drawer/useDrawer.d.ts
CHANGED
|
@@ -32,13 +32,13 @@ export declare const useDrawer: (inProps?: unknown) => import("@primereact/types
|
|
|
32
32
|
onClick: () => void;
|
|
33
33
|
};
|
|
34
34
|
rootProps: {
|
|
35
|
-
'data-position': "top" | "left" | "
|
|
35
|
+
'data-position': "top" | "left" | "bottom" | "right" | "full" | undefined;
|
|
36
36
|
'data-open': "";
|
|
37
37
|
id: string | undefined;
|
|
38
38
|
'data-scope': string;
|
|
39
39
|
'data-part': string;
|
|
40
40
|
} | {
|
|
41
|
-
'data-position': "top" | "left" | "
|
|
41
|
+
'data-position': "top" | "left" | "bottom" | "right" | "full" | undefined;
|
|
42
42
|
'data-closed': "";
|
|
43
43
|
id: string | undefined;
|
|
44
44
|
'data-scope': string;
|
|
@@ -74,7 +74,7 @@ export declare const useDrawer: (inProps?: unknown) => import("@primereact/types
|
|
|
74
74
|
tabIndex: -1;
|
|
75
75
|
'data-scope': string;
|
|
76
76
|
'data-part': string;
|
|
77
|
-
'data-position': "top" | "left" | "
|
|
77
|
+
'data-position': "top" | "left" | "bottom" | "right" | "full" | undefined;
|
|
78
78
|
};
|
|
79
79
|
close: () => void;
|
|
80
80
|
onOpenStateChange: () => void;
|
package/gallery/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{withHeadless as pe}from"@primereact/core/headless";import{useControlledState as fe}from"@primereact/hooks/use-controlled-state";import*as
|
|
1
|
+
import{withHeadless as pe}from"@primereact/core/headless";import{useControlledState as fe}from"@primereact/hooks/use-controlled-state";import*as a from"react";var F={activeIndex:void 0,defaultActiveIndex:0,fullscreen:void 0,closeOnEscape:!0,onActiveIndexChange:void 0,onFullscreenChange:void 0,onZoomChange:void 0,onRotateChange:void 0,onFlipChange:void 0};var Ce=pe({name:"useGallery",defaultProps:F,setup:({props:v,id:w,elementRef:r})=>{let{fullscreen:o,closeOnEscape:T=!0,onActiveIndexChange:D=void 0,onFullscreenChange:g,onZoomChange:I,onRotateChange:k,onFlipChange:P}=v,z=a.useRef(null),n=a.useRef(0),u=a.useRef(new Set),L=a.useRef(null),G=a.useRef(null),M=a.useRef(null),[O,x]=fe({value:v.activeIndex,defaultValue:v.defaultActiveIndex??0,onChange:D}),i=O??0,R=a.useRef(i);R.current=i;let p=a.useCallback((e,t)=>{x([e,{originalEvent:t,value:e}])},[x]),[H,S]=a.useState(!1),d=o??H,[c,K]=a.useState({zoomed:!1,rotated:!1,flipped:!1}),[U,E]=a.useState(null);a.useEffect(()=>{let e=u.current;return()=>{n.current=0,e.clear()}},[]);let X=a.useCallback(e=>{let t=e;return(t===null||u.current.has(t))&&(t=n.current),u.current.add(t),n.current=Math.max(n.current,t+1),{index:t,unregister:()=>{u.current.delete(t),n.current=u.current.size===0?0:Math.max(...u.current)+1}}},[]),Y=a.useCallback(()=>E(null),[]),f=a.useCallback(e=>{if(n.current<=0)return;let t=(R.current+1)%n.current;p(t,e)},[p]),m=a.useCallback(e=>{if(n.current<=0)return;let t=(R.current-1+n.current)%n.current;p(t,e)},[p]),y=(e,t)=>{e<0||e>=n.current||p(e,t)},l=a.useCallback(e=>()=>{E({type:e,timestamp:Date.now()})},[]),h=a.useCallback(()=>{if(o!==void 0){g?.(!o);return}r.current&&(document.fullscreenElement?document.exitFullscreen?.():r.current.requestFullscreen?.())},[o,g,r]);a.useEffect(()=>{if(o===void 0||!r.current)return;let e=document.fullscreenElement===r.current;o&&!e?r.current.requestFullscreen?.()?.catch(()=>{}):!o&&document.fullscreenElement&&document.exitFullscreen?.()?.catch(()=>{})},[o,r]),a.useEffect(()=>{let e=()=>{let t=document.fullscreenElement===r.current;S(t),o!==void 0&&o!==t&&g?.(t)};return document.addEventListener("fullscreenchange",e),()=>document.removeEventListener("fullscreenchange",e)},[o,g,r]);let A=a.useRef(null),N=a.useCallback(e=>{K({zoomed:e.zoomed,rotated:e.rotated,flipped:e.flipped});let t=A.current;(!t||t.scale!==e.scale)&&I?.(e.scale),(!t||t.rotation!==e.rotation)&&k?.(e.rotation),(!t||t.flip.x!==e.flip.x||t.flip.y!==e.flip.y)&&P?.(e.flip),A.current={scale:e.scale,rotation:e.rotation,flip:e.flip}},[I,k,P]),b=a.useMemo(()=>({zoomIn:l("zoom-in"),zoomOut:l("zoom-out"),rotateLeft:l("rotate-left"),rotateRight:l("rotate-right"),flipX:l("flip-x"),flipY:l("flip-y"),download:l("download"),next:f,prev:m,toggleFullScreen:h}),[l,f,m,h]),s=a.useCallback(e=>{e&&b[e]&&b[e]()},[b]),q={isFullscreen:d,activeIndex:i,zoomed:c.zoomed,rotated:c.rotated,flipped:c.flipped,pendingAction:U},B={ref:r,id:w,tabIndex:0,role:d?"dialog":"group","aria-roledescription":d?void 0:"carousel","aria-modal":d||void 0,"data-scope":"gallery","data-part":"root",onKeyDown:e=>{e.key==="ArrowRight"?(e.preventDefault(),f(e)):e.key==="ArrowLeft"?(e.preventDefault(),m(e)):e.key==="Home"?(e.preventDefault(),y(0,e)):e.key==="End"?(e.preventDefault(),y(n.current-1,e)):e.key==="Escape"&&T&&d&&(e.preventDefault(),h())},...d&&{"data-fullscreen":""},...c.zoomed&&{"data-zoomed":""},...c.rotated&&{"data-rotated":""},...c.flipped&&{"data-flipped":""}},Z={"data-scope":"gallery","data-part":"next",onClick:f},j={"data-scope":"gallery","data-part":"prev",onClick:m},V={"data-scope":"gallery","data-part":"thumbnail",slide:i},J={"data-scope":"gallery","data-part":"thumbnailContent"},Q=e=>{let t=ie=>{e!==void 0&&y(e,ie)},C=e!==void 0&&i===e;return{"data-scope":"gallery","data-part":"thumbnailItem",role:"button","aria-current":C||void 0,...C&&{"data-active":""},onClick:t}},W={"data-scope":"gallery","data-part":"toolbar"},_=e=>({"data-scope":"gallery","data-part":"toolbarItem",onClick:()=>{s(e)}}),$={"data-scope":"gallery","data-part":"header"},ee={"data-scope":"gallery","data-part":"footer"},te={"data-scope":"gallery","data-part":"backdrop"},ae={ref:z,"data-scope":"gallery","data-part":"content"},ne={"data-scope":"gallery","data-part":"download","data-action":"download",onClick:()=>s("download")},oe={"data-scope":"gallery","data-part":"flipX","data-action":"flip-x",onClick:()=>s("flipX")},se={"data-scope":"gallery","data-part":"flipY","data-action":"flip-y",onClick:()=>s("flipY")},re={"data-scope":"gallery","data-part":"rotateLeft","data-action":"rotate-left",onClick:()=>s("rotateLeft")},ce={"data-scope":"gallery","data-part":"rotateRight","data-action":"rotate-right",onClick:()=>s("rotateRight")},le={"data-scope":"gallery","data-part":"fullScreen","data-action":"fullscreen",...d&&{"data-fullscreen":""},onClick:()=>s("toggleFullScreen")},de={"data-scope":"gallery","data-part":"zoomIn","data-action":"zoom-in",disabled:c.zoomed||void 0,onClick:()=>s("zoomIn")},ue={"data-scope":"gallery","data-part":"zoomOut","data-action":"zoom-out",disabled:!c.zoomed||void 0,onClick:()=>s("zoomOut")};return{state:q,registerItem:X,handleNext:f,handlePrev:m,selectItem:y,reportItemState:N,clearPendingAction:Y,toggleFullScreen:h,handleClickAction:s,actions:b,contentRef:z,thumbnailRef:L,prevRef:G,nextRef:M,rootProps:B,nextProps:Z,prevProps:j,thumbnailProps:V,thumbnailContentProps:J,thumbnailItemProps:Q,toolbarProps:W,toolbarItemProps:_,headerProps:$,footerProps:ee,backdropProps:te,contentProps:ae,downloadProps:ne,flipXProps:oe,flipYProps:se,rotateLeftProps:re,rotateRightProps:ce,fullScreenProps:le,zoomInProps:de,zoomOutProps:ue,zoomToggleProps:{"data-scope":"gallery","data-part":"zoomToggle","data-action":"zoom-toggle",onClick:()=>s(c.zoomed?"zoomOut":"zoomIn")},getItemProps:e=>(e>=n.current&&(n.current=e+1),{"data-scope":"gallery","data-part":"item",...i===e&&{"data-active":""}})}}});export{F as defaultProps,Ce as useGallery};
|
package/gallery/item/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{withHeadless as
|
|
1
|
+
import{withHeadless as gt}from"@primereact/core/headless";import*as e from"react";var ut={context:void 0,normalScale:1,zoomedScale:3};var bt=gt({name:"useGalleryItem",defaultProps:ut,setup:({props:lt,elementRef:n})=>{let{context:s,normalScale:d=1,zoomedScale:y=3}=lt,V=s?.clearPendingAction,F=s?.reportItemState,[x,pt]=e.useState(-1),[R,_]=e.useState(!1),[C,w]=e.useState({x:0,y:0}),[g,D]=e.useState(d),[m,J]=e.useState(0),[E,Q]=e.useState({x:1,y:1}),[H,U]=e.useState(!1),L=e.useRef(null),M=e.useRef(new Map),G=e.useRef({x:0,y:0}),Z=e.useRef(0),k=e.useRef(0),W=e.useRef(1),tt=e.useRef(!1),f=e.useRef(1),h=e.useRef({x:0,y:0}),A=e.useRef(!1),O=e.useRef({x:0,y:0}),z=e.useRef(!1),P=e.useRef(null),et=e.useRef(x);et.current=x,e.useLayoutEffect(()=>{if(s?.registerItem){let t=s.registerItem(L.current?.index??null);L.current=t,t.index!==et.current&&pt(t.index)}return()=>{L.current?.unregister(),L.current=null}},[s]),e.useEffect(()=>{f.current=g},[g]),e.useEffect(()=>{h.current=C},[C]);let S=e.useCallback(()=>{if(!s?.contentRef.current||!n.current)return;let t=s?.contentRef.current.getBoundingClientRect(),r=n.current.firstElementChild;if(!r)return;let a=r.naturalWidth||r.offsetWidth,c=r.naturalHeight||r.offsetHeight;if(a===0||c===0)return;let l=Math.abs(m)%180===90;l&&([a,c]=[c,a]);let i=a/c,p=t.width/t.height,o,u;i>p?(o=Math.min(t.width*.99,a),u=o/i):(u=Math.min(t.height*.99,c),o=u*i),l?(r.style.width=`${u}px`,r.style.height=`${o}px`,n.current.style.width=`${u>0?u:"auto"}px`,n.current.style.height=`${o>0?o:"auto"}px`):(r.style.width=`${o}px`,r.style.height=`${u}px`,n.current.style.width=`${o>0?o:"auto"}px`,n.current.style.height=`${u>0?u:"auto"}px`),n.current.style.aspectRatio=`${a/c}`},[s?.contentRef,m,n]),I=e.useCallback(t=>{if(!s?.contentRef.current||!n.current)return{minX:0,maxX:0,minY:0,maxY:0};let r=s?.contentRef.current.getBoundingClientRect(),a=t!==void 0?t:f.current,c=n.current.firstElementChild;if(!c)return{minX:0,maxX:0,minY:0,maxY:0};let l=c.offsetWidth,i=c.offsetHeight;Math.abs(m)%180===90&&([l,i]=[i,l]);let o=l*a,u=i*a,b=r.width/2,v=r.height/2,Y=o/2,X=u/2,xt=Y>b?Y-b:0,mt=Y>b?-(Y-b):0,ht=X>v?X-v:0,yt=X>v?-(X-v):0;return{minX:mt,maxX:xt,minY:yt,maxY:ht}},[s?.contentRef,m,n]),T=e.useCallback(()=>{D(y),n.current&&(n.current.style.cursor="zoom-out")},[y,n]),$=e.useCallback(()=>{D(d),w({x:0,y:0}),n.current&&(n.current.style.cursor="zoom-in")},[d,n]),B=e.useCallback(()=>{U(!0),n.current&&(n.current.style.transition=""),J(t=>t-90)},[n]),j=e.useCallback(()=>{U(!0),n.current&&(n.current.style.transition=""),J(t=>t+90)},[n]),N=e.useCallback(()=>{Q(t=>({...t,x:Math.sign(t.x)*-1}))},[]),q=e.useCallback(()=>{Q(t=>({...t,y:Math.sign(t.y)*-1}))},[]),K=e.useCallback(()=>{if(!n.current)return;let t=n.current.querySelector("img");if(!t||!t.src)return;let r=t.src;if(!/^(https?:|blob:|data:image\/)/i.test(r))return;let c=document.createElement("a");c.href=r;let l=r.split("/"),p=(l[l.length-1]||"").split(/[?#]/)[0].replace(/[\\/:*?"<>|]/g,"")||"image.jpg";c.download=p,c.target="_blank",c.rel="noopener",document.body.appendChild(c),c.click(),document.body.removeChild(c)},[n]),nt=e.useCallback(t=>{if(z.current){z.current=!1;return}if(f.current===d){if(n.current){let r=n.current.getBoundingClientRect(),a=r.width/2,c=r.height/2,l=t.clientX-r.left,i=t.clientY-r.top,p=a-l,o=c-i,u=p*(y-1),b=o*(y-1),v=I(y),Y=Math.max(v.minX,Math.min(v.maxX,u)),X=Math.max(v.minY,Math.min(v.maxY,b));w({x:Y,y:X})}T()}else $()},[d,y,I,T,$,n]),rt=e.useCallback(t=>{t.preventDefault()},[]),ct=e.useCallback(t=>{t.currentTarget.setPointerCapture(t.pointerId),M.current.set(t.pointerId,{x:t.clientX,y:t.clientY}),G.current={x:t.clientX,y:t.clientY},t.pointerType==="touch"&&M.current.size>=2?(A.current=!1,k.current=0,W.current=f.current):f.current>1&&(t.pointerType==="mouse"||t.pointerType==="touch"&&M.current.size===1)&&(A.current=!0,O.current={x:t.clientX-h.current.x,y:t.clientY-h.current.y},z.current=!1)},[]),st=e.useCallback(t=>{if(!M.current.has(t.pointerId)||!n.current)return;n.current.style.transition="none",t.pointerType==="mouse"&&!n.current.style.cursor&&(n.current.style.cursor=f.current>d?"zoom-out":"zoom-in"),M.current.set(t.pointerId,{x:t.clientX,y:t.clientY});let r=Array.from(M.current.values());if(r.length===2){let[a,c]=r,l=Math.hypot(c.x-a.x,c.y-a.y);if(tt.current=!0,z.current=!0,k.current===0)k.current=l,W.current=f.current;else{let i=l/k.current,p=Math.max(d,Math.min(y,W.current*i)),o=I(p),u=Math.max(o.minX,Math.min(o.maxX,h.current.x)),b=Math.max(o.minY,Math.min(o.maxY,h.current.y));f.current=p,h.current={x:u,y:b},n.current.style.setProperty("--px-scale",`${p}`),n.current.style.setProperty("--px-position-x",`${u}px`),n.current.style.setProperty("--px-position-y",`${b}px`)}Z.current=l}else if(r.length===1&&A.current){let a=r[0],c=a.x-O.current.x,l=a.y-O.current.y,i=I(f.current),p=Math.max(i.minX,Math.min(i.maxX,c)),o=Math.max(i.minY,Math.min(i.maxY,l));h.current={x:p,y:o},n.current.style.setProperty("--px-position-x",`${p}px`),n.current.style.setProperty("--px-position-y",`${o}px`),Math.hypot(a.x-G.current.x,a.y-G.current.y)>5&&(z.current=!0)}},[d,y,I,n]),at=e.useCallback(t=>{n.current&&(n.current.style.transition="",t.pointerType==="mouse"&&(n.current.style.cursor=f.current>d?"zoom-out":"zoom-in"),t.currentTarget.releasePointerCapture(t.pointerId),M.current.delete(t.pointerId),M.current.size<2&&(Z.current=0,k.current=0,W.current=1,tt.current=!1),M.current.size===0&&(A.current=!1,D(f.current),w(h.current)))},[d,n]);e.useEffect(()=>{g<=1&&w({x:0,y:0})},[g]),e.useEffect(()=>{s?.state.activeIndex===x&&document.readyState==="complete"&&S()},[s?.state.activeIndex,x,S]),e.useEffect(()=>{s?.state.activeIndex===x&&S()},[m,S,s?.state.activeIndex,x]),e.useEffect(()=>{s?.state.activeIndex===x&&s?.state.isFullscreen!==void 0&&S()},[s?.state.isFullscreen,S,s?.state.activeIndex,x]),e.useEffect(()=>{let t=()=>{s?.state.activeIndex===x&&S()};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[s?.state.activeIndex,x,S]),e.useEffect(()=>{let t=s?.state.pendingAction;if(!(!t||!R)){switch(t.type){case"zoom-in":T();break;case"zoom-out":$();break;case"rotate-left":B();break;case"rotate-right":j();break;case"flip-x":N();break;case"flip-y":q();break;case"download":K();break}V?.()}},[s?.state.pendingAction,R,V,T,$,B,j,N,q,K]),e.useEffect(()=>{let t=n.current;if(!t||!R)return;let r=a=>{if(!a.ctrlKey)return;a.preventDefault(),t.style.transition="none";let l=1+-a.deltaY*.01,i=Math.max(d,Math.min(y,f.current*l)),p=I(i),o=Math.max(p.minX,Math.min(p.maxX,h.current.x)),u=Math.max(p.minY,Math.min(p.maxY,h.current.y));f.current=i,h.current={x:o,y:u},t.style.setProperty("--px-scale",`${i}`),t.style.setProperty("--px-position-x",`${o}px`),t.style.setProperty("--px-position-y",`${u}px`),P.current&&clearTimeout(P.current),P.current=setTimeout(()=>{t.style.transition="",t.style.cursor=f.current>d?"zoom-out":"zoom-in",D(f.current),w(h.current),P.current=null},150)};return t.addEventListener("wheel",r,{passive:!1}),()=>{t.removeEventListener("wheel",r),P.current&&(clearTimeout(P.current),P.current=null)}},[R,d,y,I,n]),e.useEffect(()=>{s?.state.activeIndex===x?_(!0):_(!1)},[s?.state.activeIndex,x]),e.useEffect(()=>{R&&F&&F({zoomed:g>d,rotated:m!==0,flipped:E.x===-1||E.y===-1,scale:g,rotation:m,flip:E})},[R,g,d,m,E,F]),e.useLayoutEffect(()=>{if(!H)return;let t=setTimeout(()=>U(!1),300);return()=>clearTimeout(t)},[H,m]);let ot=e.useMemo(()=>({...R?{"data-active":""}:{},...H?{"data-rotating":""}:{}}),[R,H]),it=e.useMemo(()=>({"--px-position-x":`${C.x}px`,"--px-position-y":`${C.y}px`,"--px-scale":`${g}`,"--px-rotation":`${m}deg`,"--px-flip-x":E.x,"--px-flip-y":E.y}),[C,g,m,E]),dt={index:x,position:C,scale:g,rotation:m,flip:E,isActive:R},ft={ref:n,"data-scope":"gallery","data-part":"item","data-index":x,onClick:nt,onPointerDown:ct,onPointerMove:st,onPointerUp:at,onDragStart:rt,style:it,...ot};return{state:dt,attributes:ot,CSSVariables:it,itemProps:ft,handlePointerUp:at,handlePointerMove:st,handlePointerDown:ct,handleClick:nt,handleDragStart:rt,zoomIn:T,zoomOut:$,rotateLeft:B,rotateRight:j,flipX:N,flipY:q,download:K,calculateConstraints:I,calculateItemSize:S}}});export{ut as defaultItemProps,bt as useGalleryItem};
|
package/inputcolor/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var wt=/hsb\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%)\)|hsba\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d(.\d+)?)\)/,Mt=/hsl\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%)\)|hsla\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d(.\d+)?)\)/,Et=/^#?([a-fA-F0-9]{3,8})$/,Ft=/^rgba?\(\s*([^)]+)\s*\)$/,Nt=/oklch\(\s*([\d.]+)%?\s+([\d.]+)\s+([\d.]+)(deg)?(?:\s*\/\s*([\d.]+))?\)/i;function S(e,t,n){return Math.min(Math.max(e,t),n)}var Pt=(e,t)=>JSON.stringify(e)===JSON.stringify(t),L=(e,t)=>[e[0]*t[0]+e[1]*t[1]+e[2]*t[2],e[3]*t[0]+e[4]*t[1]+e[5]*t[2],e[6]*t[0]+e[7]*t[1]+e[8]*t[2]];function Vt(e,t,n,a){let o=S(e,t,n)-t,i=Math.round(o/a),l=t+i*a,u=(a.toString().split(".")[1]||"").length;return parseFloat(l.toFixed(u))}var k=class{getChannelValue(t){if(t in this)return this[t];throw new Error(`Unknown color channel: ${t}`)}withChannelValue(t,n){let{min:a,max:r}=this.getChannelRange(t);if(t in this){let o=this.clone();return o[t]=S(n,a,r),o}throw new Error(`Unknown color channel: ${t}`)}getSpaceAxes(t){let{xChannel:n,yChannel:a}=t;if(n===a)throw new Error("xChannel and yChannel cannot be the same");let r=this.getChannels().find(o=>o!==n&&o!==a);if(!r)throw new Error("zChannel not found");return{xChannel:n,yChannel:a,zChannel:r}}incChannelValue(t,n){let{min:a,max:r,step:o}=this.getChannelRange(t),i=Vt(S(this.getChannelValue(t)+n,a,r),a,r,o);return this.withChannelValue(t,i)}decChannelValue(t,n){return this.incChannelValue(t,-n)}},D=class e extends k{constructor(t,n,a,r){super(),this.hue=t,this.saturation=n,this.brightness=a,this.alpha=r}static parse(t){let n=t.match(wt);if(!n)return;let[a,r,o,i]=(n[1]??n[2]).split(",").map(l=>Number(l.trim().replace("%","")));return new e(a%360,S(r,0,100),S(o,0,100),S(i??1,0,1))}toRGB(){let t=this.hue,n=this.saturation/100,a=this.brightness/100;function r(o){let i=(o+t/60)%6;return a-a*n*Math.max(0,Math.min(i,4-i,1))}return new A(Math.round(r(5)*255),Math.round(r(3)*255),Math.round(r(1)*255),Number(this.alpha.toFixed(2)))}toHSL(){let t=this.hue,n=this.saturation/100,a=this.brightness/100,r=a*(1-n/2);return r===0||r===1?n=0:n=(a-r)/Math.min(r,1-r),new T(Number(t.toFixed(2)),Number((n*100).toFixed(2)),Number((r*100).toFixed(2)),Number(this.alpha.toFixed(2)))}toFormat(t){switch(t){case"hsba":return this;case"rgba":return this.toRGB();case"hsla":return this.toHSL();case"oklcha":return this.toRGB().toFormat("oklcha");default:throw new Error(`Invalid format: ${t}`)}}toString(t){switch(t){case"css":return this.toHSL().toString("css");case"hex":return this.toRGB().toString("hex");case"hexa":return this.toRGB().toString("hexa");case"hsb":return`hsb(${this.hue}, ${this.saturation.toFixed(2)}%, ${this.brightness.toFixed(2)}%)`;case"hsba":return`hsba(${this.hue}, ${this.saturation.toFixed(2)}%, ${this.brightness.toFixed(2)}%, ${this.alpha})`;case"hsl":return this.toHSL().toString("hsl");case"rgb":return this.toRGB().toString("rgb");case"oklch":return this.toRGB().toFormat("oklcha").toString("oklch");default:return this.toFormat(t).toString(t)}}toJSON(){return{hue:this.hue,saturation:this.saturation,brightness:this.brightness,alpha:this.alpha}}clone(){return new e(this.hue,this.saturation,this.brightness,this.alpha)}getChannelRange(t){switch(t){case"hue":return{min:0,max:360,step:1};case"saturation":case"brightness":return{min:0,max:100,step:1};case"alpha":return{min:0,max:1,step:.01};default:throw new Error(`Unknown color channel: ${t}`)}}getFormat(){return"hsba"}getChannels(){return["hue","saturation","brightness"]}},T=class e extends k{constructor(t,n,a,r){super(),this.hue=t,this.saturation=n,this.lightness=a,this.alpha=r}static parse(t){let n=t.match(Mt);if(!n)return;let[a,r,o,i]=(n[1]||n[2])?.split(",").map(l=>Number(l.trim().replace("%","")))??[];return new e(a%360,S(r,0,100),S(o,0,100),S(i??1,0,1))}toRGB(){let t=this.hue,n=this.saturation/100,a=this.lightness/100;function r(o){let i=(o+t/30)%12,l=n*Math.min(a,1-a);return a-l*Math.max(-1,Math.min(i-3,9-i,1))}return new A(Math.round(r(0)*255),Math.round(r(8)*255),Math.round(r(4)*255),Number(this.alpha.toFixed(2)))}toHSB(){let t=this.hue,n=this.saturation/100,a=this.lightness/100,r=a+n*Math.min(a,1-a);return r===0?n=0:n=2*(1-a/r),new D(Number(t.toFixed(2)),Number((n*100).toFixed(2)),Number((r*100).toFixed(2)),Number(this.alpha.toFixed(2)))}toFormat(t){switch(t){case"hsla":return this;case"rgba":return this.toRGB();case"hsba":return this.toHSB();case"oklcha":return this.toRGB().toFormat("oklcha");default:throw new Error(`Invalid format: ${t}`)}}toString(t){switch(t){case"hex":return this.toRGB().toString("hex");case"hexa":return this.toRGB().toString("hexa");case"hsl":return`hsl(${this.hue}, ${this.saturation.toFixed(2)}%, ${this.lightness.toFixed(2)}%)`;case"css":case"hsla":return`hsla(${this.hue}, ${this.saturation.toFixed(2)}%, ${this.lightness.toFixed(2)}%, ${this.alpha})`;case"rgb":return this.toRGB().toString("rgb");case"hsb":return this.toHSB().toString("hsb");case"oklch":return this.toRGB().toFormat("oklcha").toString("oklch");default:return this.toFormat(t).toString(t)}}toJSON(){return{hue:this.hue,saturation:this.saturation,lightness:this.lightness,alpha:this.alpha}}clone(){return new e(this.hue,this.saturation,this.lightness,this.alpha)}getChannelRange(t){switch(t){case"hue":return{min:0,max:360,step:1};case"saturation":case"lightness":return{min:0,max:100,step:1};case"alpha":return{min:0,max:1,step:.01};default:throw new Error(`Unknown color channel: ${t}`)}}getFormat(){return"hsla"}getChannels(){return["hue","saturation","lightness"]}},A=class e extends k{constructor(t,n,a,r){super(),this.red=t,this.green=n,this.blue=a,this.alpha=r}static parse(t){if(!t)return;let n=t.trim();return this.parseHexColor(n)??this.parseRgbFunction(n)}static expandShortHex(t){return t.split("").map(n=>n+n).join("")}static parseHexColor(t){let n=t.match(Et);if(!n)return;let a=n[1];if(a.length<=4&&(a=this.expandShortHex(a)),![6,8].includes(a.length))return;let r=parseInt(a.slice(0,2),16),o=parseInt(a.slice(2,4),16),i=parseInt(a.slice(4,6),16),l=a.length===8?parseInt(a.slice(6,8),16)/255:1;return new e(r,o,i,l)}static parseRgbFunction(t){let n=t.match(Ft);if(!n?.[1])return;let[a,r,o,i]=n[1].split(",").map(g=>g.trim()),l=S(Number(a),0,255),u=S(Number(r),0,255),c=S(Number(o),0,255),f=i!==void 0?S(Number(i),0,1):1;if(![l,u,c,f].some(g=>Number.isNaN(g)))return new e(l,u,c,f)}toHSB(){let[t,n,a]=[this.red/255,this.green/255,this.blue/255],r=Math.max(t,n,a),o=Math.min(t,n,a),i=r-o,l=r,u=r===0?0:i/r,c=0;if(i!==0){switch(r){case t:c=(n-a)/i%6;break;case n:c=(a-t)/i+2;break;case a:c=(t-n)/i+4;break}c*=60,c<0&&(c+=360)}return new D(Number(c.toFixed(2)),Number((u*100).toFixed(2)),Number((l*100).toFixed(2)),Number(this.alpha.toFixed(2)))}toHSL(){let[t,n,a]=[this.red/255,this.green/255,this.blue/255],r=Math.max(t,n,a),o=Math.min(t,n,a),i=(r+o)/2,l=r-o,u=0,c=-1;if(l!==0){switch(r){case t:u=(n-a)/l%6;break;case n:u=(a-t)/l+2;break;case a:u=(t-n)/l+4;break}u*=60,u<0&&(u+=360)}return i===0||i===1?c=0:c=l/(1-Math.abs(2*r-l-1)),new T(Number(u.toFixed(2)),Number((c*100).toFixed(2)),Number((i*100).toFixed(2)),Number(this.alpha.toFixed(2)))}toOKLCH(){let n=[this.red/255,this.green/255,this.blue/255].map(I=>Math.abs(I)<=.04045?I/12.92:(I<0?-1:1)*((Math.abs(I)+.055)/1.055)**2.4),a=L([.41239079926595934,.357584339383878,.1804807884018343,.21263900587151027,.715168678767756,.07219231536073371,.01933081871559182,.11919477979462598,.9505321522496607],n),o=L([.819022437996703,.3619062600528904,-.1288737815209879,.0329836539323885,.9292868615863434,.0361446663506424,.0481771893596242,.2642395317527308,.6335478284694309],a).map(I=>Math.cbrt(I)),[i,l,u]=L([.210454268309314,.7936177747023054,-.0040720430116193,1.9779985324311684,-2.42859224204858,.450593709617411,.0259040424655478,.7827717124575296,-.8086757549230774],o),c=Math.sqrt(l**2+u**2),f=Math.abs(l)<2e-4&&Math.abs(u)<2e-4?NaN:(Math.atan2(u,l)*180/Math.PI%360+360)%360,g=Number(Math.min(1,Math.max(0,i)).toFixed(4)),_=Number(c.toFixed(4)),d=Number.isNaN(f)?NaN:Number(f.toFixed(2));return new K(g,_,d,Number(this.alpha.toFixed(2)))}toHexInt(){return this.red<<16|this.green<<8|this.blue}toFormat(t){switch(t){case"rgba":return this;case"hsla":return this.toHSL();case"hsba":return this.toHSB();case"oklcha":return this.toOKLCH();default:throw new Error(`Invalid format: ${t}`)}}toString(t){switch(t){case"hex":return`#${this.red.toString(16).padStart(2,"0")}${this.green.toString(16).padStart(2,"0")}${this.blue.toString(16).padStart(2,"0")}`;case"hexa":return`#${this.red.toString(16).padStart(2,"0")}${this.green.toString(16).padStart(2,"0")}${this.blue.toString(16).padStart(2,"0")}${Math.round(this.alpha*255).toString(16).padStart(2,"0")}`;case"rgb":return`rgb(${this.red}, ${this.green}, ${this.blue})`;case"rgba":case"css":return`rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`;case"hsl":return this.toHSL().toString("hsl");case"hsb":return this.toHSB().toString("hsb");case"oklch":return this.toOKLCH().toString("oklch");default:return this.toFormat(t).toString(t)}}toJSON(){return{red:this.red,green:this.green,blue:this.blue,alpha:this.alpha}}clone(){return new e(this.red,this.green,this.blue,this.alpha)}getChannelRange(t){switch(t){case"red":case"green":case"blue":return{min:0,max:255,step:1};case"alpha":return{min:0,max:1,step:.01};default:throw new Error(`Unknown color channel: ${t}`)}}getFormat(){return"rgba"}getChannels(){return["red","green","blue"]}},K=class e extends k{constructor(t,n,a,r){super(),this.L=t,this.C=n,this.H=a,this.alpha=r}static parse(t){if(!t)return;let n=t.trim().match(Nt);if(!n)return;let a=Number(n[1])/100,r=Number(n[2]),o=Number(n[3]),i=n[5]!==void 0?Number(n[5]):1;return new e(a,r,o,i)}toRGB(){let t=this.L,n=Number.isNaN(this.H)?0:this.C*Math.cos(this.H*Math.PI/180),a=Number.isNaN(this.H)?0:this.C*Math.sin(this.H*Math.PI/180),o=L([1,.3963377774,.2158037573,1,-.1055613458,-.0638541728,1,-.0894841775,-1.291485548],[t,n,a]).map(f=>f**3),i=L([1.2268798758,-.5578149945,.2813910457,-.0405757452,1.1122868033,-.0717110581,-.0763729367,-.4214933324,1.5869240198],o),[l,u,c]=L([3.240969942,-1.537383178,-.49861076,-.969243636,1.875967502,.041555057,.05563008,-.203976959,1.056971514],i);return[l,u,c]=[l,u,c].map(f=>Math.abs(f)>.0031308?(f<0?-1:1)*(1.055*Math.abs(f)**(1/2.4)-.055):12.92*f),new A(Math.round(S(l,0,1)*255),Math.round(S(u,0,1)*255),Math.round(S(c,0,1)*255),Number(this.alpha.toFixed(2)))}toJSON(){return{L:this.L,C:this.C,H:this.H,alpha:this.alpha}}clone(){return new e(this.L,this.C,this.H,this.alpha)}toFormat(t){switch(t){case"oklcha":return this;case"rgba":return this.toRGB();case"hsla":return this.toRGB().toFormat("hsla");case"hsba":return this.toRGB().toFormat("hsba");default:throw new Error(`Invalid format: ${t}`)}}toString(t){switch(t){case"hex":return this.toRGB().toString("hex");case"hexa":return this.toRGB().toString("hexa");case"oklch":{let n=Number.isNaN(this.L)?0:Number((this.L*100).toFixed(2)),a=Number.isNaN(this.C)?0:Number(this.C.toFixed(4)),r=Number.isNaN(this.H)?0:Number(this.H.toFixed(2));return`oklch(${n}% ${a} ${r})`}case"oklcha":case"css":{let n=Number.isNaN(this.L)?0:Number((this.L*100).toFixed(2)),a=Number.isNaN(this.C)?0:Number(this.C.toFixed(4)),r=Number.isNaN(this.H)?0:Number(this.H.toFixed(2)),o=Number.isNaN(this.alpha)?1:Number(this.alpha.toFixed(2));return`oklch(${n}% ${a} ${r} / ${o})`}case"hsl":return this.toRGB().toString("hsl");case"hsb":return this.toRGB().toString("hsb");case"rgb":return this.toRGB().toString("rgb");default:return this.toFormat(t).toString(t)}}getChannelRange(t){switch(t){case"L":return{min:0,max:1,step:.01};case"C":return{min:0,max:.4,step:.01};case"H":return{min:0,max:360,step:1};case"alpha":return{min:0,max:1,step:.01};default:throw new Error(`Unknown color channel: ${t}`)}}getFormat(){return"oklcha"}getChannels(){return["L","C","H"]}},H=e=>{let t=A.parse(e)??T.parse(e)??D.parse(e)??void 0;if(!t)throw new Error(`Invalid color: ${e}`);return t};function ot(e,t,n,a=!1){let{min:r,max:o}=t.getChannelRange(e),i=n==="horizontal"?a?"left":"right":"bottom";switch(e){case"hue":return`linear-gradient(to ${i}, rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0) 100%)`;case"lightness":{let l=t.withChannelValue(e,r).toString("css"),u=t.withChannelValue(e,(o-r)/2).toString("css"),c=t.withChannelValue(e,o).toString("css");return`linear-gradient(to ${i}, ${l}, ${u}, ${c})`}case"red":case"green":case"blue":case"saturation":case"brightness":case"alpha":{let l=t.withChannelValue(e,r).toString("css"),u=t.withChannelValue(e,o).toString("css");return`linear-gradient(to ${i}, ${l}, ${u})`}default:throw new Error(`Unknown color channel: ${e}`)}}function it(e,t){switch(t){case"hue":return H(`hsl(${e.getChannelValue("hue")}, 100%, 50%)`);case"red":case"green":case"blue":case"lightness":case"brightness":case"saturation":return e.withChannelValue("alpha",1);case"alpha":return e;default:throw new Error(`Unknown color channel: ${t}`)}}var Ht={hue:e=>[0,60,120,180,240,300,360].map(t=>e.withChannelValue("hue",t).toString("css")).join(", "),saturation:e=>`${e.withChannelValue("saturation",0).toString("css")}, transparent`,lightness:()=>"black, transparent, white",brightness:()=>"black, transparent"};function lt(e,t){let{xChannel:n,zChannel:a}=e.getSpaceAxes(t),r=e.getChannelValue(a),o=e.getFormat(),l=H((o==="rgba"||o==="oklcha"?"hsba":o)==="hsla"?"hsl(0, 100%, 50%)":"hsb(0, 100%, 100%)").withChannelValue(a,r),u=e.getChannels(),c=g=>g===n?"right":"top",f=u.filter(g=>g!==a).map(g=>`linear-gradient(to ${c(g)}, ${Ht[g](l)})`).reverse();return a==="hue"&&f.push(l.toString("css")),{"--px-area-gradient":f.join(", ")}}function z(e,t,n="hsba"){let a=e.getFormat()==="hsla";switch(t){case"hex":return e.getChannelValue("alpha")<e.getChannelRange("alpha").max?e.toString("hexa"):e.toString("hex");case"css":return e.toFormat(n).toString("css");case"red":case"green":case"blue":return e.toFormat("rgba").getChannelValue(t).toString();case"hue":return e.toFormat(a?"hsla":"hsba").getChannelValue("hue").toString();case"saturation":return e.toFormat(a?"hsla":"hsba").getChannelValue("saturation").toString();case"lightness":return e.toFormat("hsla").getChannelValue("lightness").toString();case"brightness":return e.toFormat("hsba").getChannelValue("brightness").toString();case"C":return e.toFormat("oklcha").getChannelValue("C").toString();case"H":return e.toFormat("oklcha").getChannelValue("H").toString();case"L":return e.toFormat("oklcha").getChannelValue("L").toString();default:return e.getChannelValue(t).toString()}}function ht(e,t="hex"){switch(t){case"hex":return{min:H("#000000").toHexInt(),max:H("#FFFFFF").toHexInt(),step:1};case"css":return;case"red":case"green":case"blue":return e.toFormat("rgba").getChannelRange(t);case"hue":case"lightness":case"saturation":return e.toFormat("hsla").getChannelRange(t);case"brightness":return e.toFormat("hsba").getChannelRange(t);case"L":case"C":case"H":return e.toFormat("oklcha").getChannelRange(t);default:return e.getChannelRange(t)}}import{withHeadless as It}from"@primereact/core/headless";import{useControlledState as yt}from"@primereact/hooks/use-controlled-state";import{useDirection as Gt}from"@primereact/hooks/use-direction";import*as F from"react";var ut={defaultValue:void 0,value:void 0,format:"hsba",disabled:!1,onValueChange:void 0,onValueChangeEnd:void 0};var $t=/^[0-9a-fA-F]{3,8}$/;function Bt(e){return $t.test(e)}function vt(e){return e.startsWith("#")?e:Bt(e)?`#${e}`:e}function Lt(e){return e.replace("to bottom","to top")}var Jt=It({name:"useInputColor",defaultProps:ut,setup({props:e}){let{format:t="hsba",disabled:n}=e,[a,r]=F.useState(!1),o=Gt()==="rtl",i=F.useRef([]),l=F.useRef({x:0,y:0}),u=F.useRef(e.defaultValue??H("#ff0000").toFormat(e.format||"hsba")),[c,f]=yt({value:e.value,defaultValue:u.current,onChange:e.onValueChange}),g=F.useMemo(()=>c??H("#ff0000").toFormat(t),[c,t]),_=t.startsWith("hsl")?"hsla":"hsba",d=F.useMemo(()=>g.toFormat(_),[g,_]),I={value:g,isAreaDragging:a},X=(s,h)=>{f([s,{color:s.toString(t),value:s,...h?.originalEvent?{originalEvent:h.originalEvent}:{}}]),U(s)},J=(s,h,R)=>{if(!R||n)return;let m=R.getBoundingClientRect(),C=Math.max(0,Math.min(1,(s-l.current.x-m.left)/m.width)),x=Math.max(0,Math.min(1,(h-l.current.y-m.top)/m.height)),{xChannel:b,yChannel:M}=O(),G=d.getChannelRange(b),y=d.getChannelRange(M),$=C*(G.max-G.min)+G.min,P=(1-x)*(y.max-y.min)+y.min,E=$-d.getChannelValue(b),N=P-d.getChannelValue(M),p=d.incChannelValue(b,E).incChannelValue(M,N);X(p)},Y=s=>{let h=s.currentTarget;if(!h||s.button!==0)return;let m=s.target?.closest?.('[data-part="area-handle"], .p-input-color-area-handle');if(m){let C=m.getBoundingClientRect(),x=C.left+C.width/2,b=C.top+C.height/2;l.current={x:s.clientX-x,y:s.clientY-b}}else l.current={x:0,y:0};h.setPointerCapture(s.pointerId),r(!0),J(s.clientX,s.clientY,h)},j=s=>{a&&J(s.clientX,s.clientY,s.currentTarget)},q=s=>{let h=s.currentTarget;h&&(h.releasePointerCapture(s.pointerId),r(!1),l.current={x:0,y:0},e.onValueChangeEnd&&e.onValueChangeEnd({originalEvent:s,color:g.toString(t),value:g}))},W=s=>{e.onValueChangeEnd&&e.onValueChangeEnd({originalEvent:s,color:g.toString(t),value:g})},Q=s=>{if(n)return;let h=s.key;if(!["ArrowRight","ArrowLeft","ArrowUp","ArrowDown"].includes(h))return;s.preventDefault();let{xChannel:R,yChannel:m}=O(),{step:C}=d.getChannelRange(R),{step:x}=d.getChannelRange(m),b=d;h==="ArrowRight"&&(b=b.incChannelValue(R,C)),h==="ArrowLeft"&&(b=b.decChannelValue(R,C)),h==="ArrowUp"&&(b=b.incChannelValue(m,x)),h==="ArrowDown"&&(b=b.decChannelValue(m,x)),X(b),e.onValueChangeEnd&&e.onValueChangeEnd({originalEvent:s,color:b.toString(t),value:b})},O=()=>{let s=d.getChannels();return{xChannel:s[1],yChannel:s[2]}},Z=()=>{if(typeof window<"u"&&!window.EyeDropper||n)return;new window.EyeDropper().open().then(h=>{let R=H(h.sRGBHex);X(R)}).catch(h=>{console.error("Error opening eyedropper",h)})},w=O(),{min:tt,max:ct}=d.getChannelRange(w.xChannel),{min:et,max:gt}=d.getChannelRange(w.yChannel),dt=d.getChannelValue(w.xChannel),mt=d.getChannelValue(w.yChannel),nt={...lt(d,w),"--px-handle-background":d.withChannelValue("alpha",1).toString("css"),"--px-handle-position-left":(dt-tt)/(ct-tt)*100+"%","--px-handle-position-top":(1-(mt-et)/(gt-et))*100+"%"},at={"--px-swatch-background":g.toString("css")},Ct=({channel:s="hue",orientation:h="horizontal",disabled:R}={})=>{let m=n||R,C=s==="alpha"?d:g.getChannels().includes(s)?g:d.getChannels().includes(s)?d:g.toFormat(t),x=C.getChannelRange(s),b=C.getChannelValue(s),M=ot(s,C,h,o),y={"--px-slider-background":h==="vertical"?Lt(M):M,"--px-slider-handle-background":it(C,s).toString("css")},$=E=>{if(m)return;let N=Array.isArray(E.value)?E.value[0]:E.value;if(N===void 0||Number.isNaN(N))return;let p=C.withChannelValue(s,N);X(p,{originalEvent:E.originalEvent})},P=E=>{if(m||!e.onValueChangeEnd)return;let N=Array.isArray(E.value)?E.value[0]:E.value;if(N===void 0||Number.isNaN(N))return;let p=C.withChannelValue(s,N);e.onValueChangeEnd({originalEvent:E.originalEvent,color:p.toString(t),value:p})};return{"data-scope":"inputcolor","data-part":"slider","data-orientation":h,"data-channel":s,orientation:h,style:y,value:b,min:x.min,max:x.max,step:x.step,disabled:m,onValueChange:$,onValueChangeEnd:P}},pt=s=>{let h=s.elementRef.current;i.current.includes(h)||i.current.push(h)},U=s=>{requestAnimationFrame(()=>{let h=s||g;i.current.forEach(m=>{let C=m.getAttribute("data-channel");if(C){let x=z(h,C,t);m.value=String(x)}})})};F.useEffect(()=>{U()},[g,t]);let[rt,st]=F.useState(null),bt=({channel:s="hex",disabled:h}={})=>{let R=n||h,m=g,C=t,x=ht(m,s),b=z(m,s,C),M=s==="hex"||s==="css",G=M&&rt!==null?rt:b,y=p=>{if(R)return;let V;if(M)try{V=H(s==="hex"?vt(String(p)):String(p))}catch{V=m}else{let B=m;s!=="alpha"&&(B=B.toFormat(C));let v=Number.parseFloat(String(p)),Rt=Number.isNaN(v)?B.getChannelValue(s):v;V=B.withChannelValue(s,Rt)}return X(V),V},$=p=>{let V=p.currentTarget,B=M?V.value:V.valueAsNumber,v=y(B);M&&st(null),!(!v||!e.onValueChangeEnd)&&e.onValueChangeEnd({originalEvent:p,color:v.toString(t),value:v})},P=p=>{let V=p.currentTarget;M?st(V.value):y(V.valueAsNumber)},E=p=>{$(p)},N=p=>{p.defaultPrevented||p.key==="Enter"&&($(p),p.preventDefault())};return{"data-scope":"inputcolor","data-part":"input",type:M?"text":"number",spellCheck:!1,autoComplete:"off",disabled:!!R,"data-channel":s,"aria-label":s,min:x?.min,max:x?.max,step:x?.step,value:G,onChange:P,onBlur:E,onKeyDown:N}},ft={"data-scope":"inputcolor","data-part":"root",...n&&{"data-disabled":""},...a&&{"data-dragging":""}},xt={"data-scope":"inputcolor","data-part":"area",style:nt,onPointerDown:Y,onPointerMove:j,onPointerUp:q},St={"data-scope":"inputcolor","data-part":"area-handle",role:"slider",tabIndex:n?-1:0,"aria-disabled":n,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":d.getChannelValue(w.xChannel),"aria-label":`${w.xChannel} and ${w.yChannel}`,"aria-roledescription":"2d slider","aria-valuetext":`${w.xChannel} ${d.getChannelValue(w.xChannel)}, ${w.yChannel} ${d.getChannelValue(w.yChannel)}`,onKeyDown:Q,onBlur:W};return{state:I,value:c,areaValue:d,areaChannels:w,rootProps:ft,areaProps:xt,areaHandleProps:St,swatchProps:{"data-scope":"inputcolor","data-part":"swatch",style:at},eyeDropperProps:{"data-scope":"inputcolor","data-part":"eye-dropper",disabled:!!n,onClick:Z},sliderHandleProps:{"data-scope":"inputcolor","data-part":"slider-handle",role:"slider",tabIndex:n?-1:0,"aria-disabled":n},getInputProps:bt,getSliderProps:Ct,setValue:f,handleAreaPointerDown:Y,handleAreaPointerMove:j,handleAreaPointerUp:q,handleAreaBlur:W,handleAreaKeyDown:Q,areaStyles:nt,swatchStyles:at,openEyeDropper:Z,syncChannelInputs:U,registerInputEl:pt}}});export{D as HSBColor,T as HSLColor,K as OKLCHColor,A as RGBColor,ut as defaultProps,lt as getAreaGradient,it as getChannelColor,ot as getChannelGradient,ht as getInputChannelRange,z as getInputChannelValue,Pt as isEqual,H as parseColor,Jt as useInputColor};
|
|
1
|
+
var wt=/hsb\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%)\)|hsba\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d(.\d+)?)\)/,Mt=/hsl\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%)\)|hsla\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d(.\d+)?)\)/,Et=/^#?([a-fA-F0-9]{3,8})$/,Ft=/^rgba?\(\s*([^)]+)\s*\)$/,Nt=/oklch\(\s*([\d.]+)%?\s+([\d.]+)\s+([\d.]+)(deg)?(?:\s*\/\s*([\d.]+))?\)/i;function S(e,t,n){return Math.min(Math.max(e,t),n)}var Pt=(e,t)=>JSON.stringify(e)===JSON.stringify(t),L=(e,t)=>[e[0]*t[0]+e[1]*t[1]+e[2]*t[2],e[3]*t[0]+e[4]*t[1]+e[5]*t[2],e[6]*t[0]+e[7]*t[1]+e[8]*t[2]];function Vt(e,t,n,a){let o=S(e,t,n)-t,i=Math.round(o/a),l=t+i*a,u=(a.toString().split(".")[1]||"").length;return parseFloat(l.toFixed(u))}var k=class{getChannelValue(t){if(t in this)return this[t];throw new Error(`Unknown color channel: ${t}`)}withChannelValue(t,n){let{min:a,max:r}=this.getChannelRange(t);if(t in this){let o=this.clone();return o[t]=S(n,a,r),o}throw new Error(`Unknown color channel: ${t}`)}getSpaceAxes(t){let{xChannel:n,yChannel:a}=t;if(n===a)throw new Error("xChannel and yChannel cannot be the same");let r=this.getChannels().find(o=>o!==n&&o!==a);if(!r)throw new Error("zChannel not found");return{xChannel:n,yChannel:a,zChannel:r}}incChannelValue(t,n){let{min:a,max:r,step:o}=this.getChannelRange(t),i=Vt(S(this.getChannelValue(t)+n,a,r),a,r,o);return this.withChannelValue(t,i)}decChannelValue(t,n){return this.incChannelValue(t,-n)}},D=class e extends k{constructor(t,n,a,r){super(),this.hue=t,this.saturation=n,this.brightness=a,this.alpha=r}static parse(t){let n=t.match(wt);if(!n)return;let[a,r,o,i]=(n[1]??n[2]).split(",").map(l=>Number(l.trim().replace("%","")));return new e(a%360,S(r,0,100),S(o,0,100),S(i??1,0,1))}toRGB(){let t=this.hue,n=this.saturation/100,a=this.brightness/100;function r(o){let i=(o+t/60)%6;return a-a*n*Math.max(0,Math.min(i,4-i,1))}return new A(Math.round(r(5)*255),Math.round(r(3)*255),Math.round(r(1)*255),Number(this.alpha.toFixed(2)))}toHSL(){let t=this.hue,n=this.saturation/100,a=this.brightness/100,r=a*(1-n/2);return r===0||r===1?n=0:n=(a-r)/Math.min(r,1-r),new T(Number(t.toFixed(2)),Number((n*100).toFixed(2)),Number((r*100).toFixed(2)),Number(this.alpha.toFixed(2)))}toFormat(t){switch(t){case"hsba":return this;case"rgba":return this.toRGB();case"hsla":return this.toHSL();case"oklcha":return this.toRGB().toFormat("oklcha");default:throw new Error(`Invalid format: ${t}`)}}toString(t){switch(t){case"css":return this.toHSL().toString("css");case"hex":return this.toRGB().toString("hex");case"hexa":return this.toRGB().toString("hexa");case"hsb":return`hsb(${this.hue}, ${this.saturation.toFixed(2)}%, ${this.brightness.toFixed(2)}%)`;case"hsba":return`hsba(${this.hue}, ${this.saturation.toFixed(2)}%, ${this.brightness.toFixed(2)}%, ${this.alpha})`;case"hsl":return this.toHSL().toString("hsl");case"rgb":return this.toRGB().toString("rgb");case"oklch":return this.toRGB().toFormat("oklcha").toString("oklch");default:return this.toFormat(t).toString(t)}}toJSON(){return{hue:this.hue,saturation:this.saturation,brightness:this.brightness,alpha:this.alpha}}clone(){return new e(this.hue,this.saturation,this.brightness,this.alpha)}getChannelRange(t){switch(t){case"hue":return{min:0,max:360,step:1};case"saturation":case"brightness":return{min:0,max:100,step:1};case"alpha":return{min:0,max:1,step:.01};default:throw new Error(`Unknown color channel: ${t}`)}}getFormat(){return"hsba"}getChannels(){return["hue","saturation","brightness"]}},T=class e extends k{constructor(t,n,a,r){super(),this.hue=t,this.saturation=n,this.lightness=a,this.alpha=r}static parse(t){let n=t.match(Mt);if(!n)return;let[a,r,o,i]=(n[1]||n[2])?.split(",").map(l=>Number(l.trim().replace("%","")))??[];return new e(a%360,S(r,0,100),S(o,0,100),S(i??1,0,1))}toRGB(){let t=this.hue,n=this.saturation/100,a=this.lightness/100;function r(o){let i=(o+t/30)%12,l=n*Math.min(a,1-a);return a-l*Math.max(-1,Math.min(i-3,9-i,1))}return new A(Math.round(r(0)*255),Math.round(r(8)*255),Math.round(r(4)*255),Number(this.alpha.toFixed(2)))}toHSB(){let t=this.hue,n=this.saturation/100,a=this.lightness/100,r=a+n*Math.min(a,1-a);return r===0?n=0:n=2*(1-a/r),new D(Number(t.toFixed(2)),Number((n*100).toFixed(2)),Number((r*100).toFixed(2)),Number(this.alpha.toFixed(2)))}toFormat(t){switch(t){case"hsla":return this;case"rgba":return this.toRGB();case"hsba":return this.toHSB();case"oklcha":return this.toRGB().toFormat("oklcha");default:throw new Error(`Invalid format: ${t}`)}}toString(t){switch(t){case"hex":return this.toRGB().toString("hex");case"hexa":return this.toRGB().toString("hexa");case"hsl":return`hsl(${this.hue}, ${this.saturation.toFixed(2)}%, ${this.lightness.toFixed(2)}%)`;case"css":case"hsla":return`hsla(${this.hue}, ${this.saturation.toFixed(2)}%, ${this.lightness.toFixed(2)}%, ${this.alpha})`;case"rgb":return this.toRGB().toString("rgb");case"hsb":return this.toHSB().toString("hsb");case"oklch":return this.toRGB().toFormat("oklcha").toString("oklch");default:return this.toFormat(t).toString(t)}}toJSON(){return{hue:this.hue,saturation:this.saturation,lightness:this.lightness,alpha:this.alpha}}clone(){return new e(this.hue,this.saturation,this.lightness,this.alpha)}getChannelRange(t){switch(t){case"hue":return{min:0,max:360,step:1};case"saturation":case"lightness":return{min:0,max:100,step:1};case"alpha":return{min:0,max:1,step:.01};default:throw new Error(`Unknown color channel: ${t}`)}}getFormat(){return"hsla"}getChannels(){return["hue","saturation","lightness"]}},A=class e extends k{constructor(t,n,a,r){super(),this.red=t,this.green=n,this.blue=a,this.alpha=r}static parse(t){if(!t)return;let n=t.trim();return this.parseHexColor(n)??this.parseRgbFunction(n)}static expandShortHex(t){return t.split("").map(n=>n+n).join("")}static parseHexColor(t){let n=t.match(Et);if(!n)return;let a=n[1];if(a.length<=4&&(a=this.expandShortHex(a)),![6,8].includes(a.length))return;let r=parseInt(a.slice(0,2),16),o=parseInt(a.slice(2,4),16),i=parseInt(a.slice(4,6),16),l=a.length===8?parseInt(a.slice(6,8),16)/255:1;return new e(r,o,i,l)}static parseRgbFunction(t){let n=t.match(Ft);if(!n?.[1])return;let[a,r,o,i]=n[1].split(",").map(g=>g.trim()),l=S(Number(a),0,255),u=S(Number(r),0,255),c=S(Number(o),0,255),f=i!==void 0?S(Number(i),0,1):1;if(![l,u,c,f].some(g=>Number.isNaN(g)))return new e(l,u,c,f)}toHSB(){let[t,n,a]=[this.red/255,this.green/255,this.blue/255],r=Math.max(t,n,a),o=Math.min(t,n,a),i=r-o,l=r,u=r===0?0:i/r,c=0;if(i!==0){switch(r){case t:c=(n-a)/i%6;break;case n:c=(a-t)/i+2;break;case a:c=(t-n)/i+4;break}c*=60,c<0&&(c+=360)}return new D(Number(c.toFixed(2)),Number((u*100).toFixed(2)),Number((l*100).toFixed(2)),Number(this.alpha.toFixed(2)))}toHSL(){let[t,n,a]=[this.red/255,this.green/255,this.blue/255],r=Math.max(t,n,a),o=Math.min(t,n,a),i=(r+o)/2,l=r-o,u=0,c=-1;if(l!==0){switch(r){case t:u=(n-a)/l%6;break;case n:u=(a-t)/l+2;break;case a:u=(t-n)/l+4;break}u*=60,u<0&&(u+=360)}return i===0||i===1?c=0:c=l/(1-Math.abs(2*r-l-1)),new T(Number(u.toFixed(2)),Number((c*100).toFixed(2)),Number((i*100).toFixed(2)),Number(this.alpha.toFixed(2)))}toOKLCH(){let n=[this.red/255,this.green/255,this.blue/255].map(I=>Math.abs(I)<=.04045?I/12.92:(I<0?-1:1)*((Math.abs(I)+.055)/1.055)**2.4),a=L([.41239079926595934,.357584339383878,.1804807884018343,.21263900587151027,.715168678767756,.07219231536073371,.01933081871559182,.11919477979462598,.9505321522496607],n),o=L([.819022437996703,.3619062600528904,-.1288737815209879,.0329836539323885,.9292868615863434,.0361446663506424,.0481771893596242,.2642395317527308,.6335478284694309],a).map(I=>Math.cbrt(I)),[i,l,u]=L([.210454268309314,.7936177747023054,-.0040720430116193,1.9779985324311684,-2.42859224204858,.450593709617411,.0259040424655478,.7827717124575296,-.8086757549230774],o),c=Math.sqrt(l**2+u**2),f=Math.abs(l)<2e-4&&Math.abs(u)<2e-4?NaN:(Math.atan2(u,l)*180/Math.PI%360+360)%360,g=Number(Math.min(1,Math.max(0,i)).toFixed(4)),_=Number(c.toFixed(4)),d=Number.isNaN(f)?NaN:Number(f.toFixed(2));return new K(g,_,d,Number(this.alpha.toFixed(2)))}toHexInt(){return this.red<<16|this.green<<8|this.blue}toFormat(t){switch(t){case"rgba":return this;case"hsla":return this.toHSL();case"hsba":return this.toHSB();case"oklcha":return this.toOKLCH();default:throw new Error(`Invalid format: ${t}`)}}toString(t){switch(t){case"hex":return`#${this.red.toString(16).padStart(2,"0")}${this.green.toString(16).padStart(2,"0")}${this.blue.toString(16).padStart(2,"0")}`;case"hexa":return`#${this.red.toString(16).padStart(2,"0")}${this.green.toString(16).padStart(2,"0")}${this.blue.toString(16).padStart(2,"0")}${Math.round(this.alpha*255).toString(16).padStart(2,"0")}`;case"rgb":return`rgb(${this.red}, ${this.green}, ${this.blue})`;case"rgba":case"css":return`rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`;case"hsl":return this.toHSL().toString("hsl");case"hsb":return this.toHSB().toString("hsb");case"oklch":return this.toOKLCH().toString("oklch");default:return this.toFormat(t).toString(t)}}toJSON(){return{red:this.red,green:this.green,blue:this.blue,alpha:this.alpha}}clone(){return new e(this.red,this.green,this.blue,this.alpha)}getChannelRange(t){switch(t){case"red":case"green":case"blue":return{min:0,max:255,step:1};case"alpha":return{min:0,max:1,step:.01};default:throw new Error(`Unknown color channel: ${t}`)}}getFormat(){return"rgba"}getChannels(){return["red","green","blue"]}},K=class e extends k{constructor(t,n,a,r){super(),this.L=t,this.C=n,this.H=a,this.alpha=r}static parse(t){if(!t)return;let n=t.trim().match(Nt);if(!n)return;let a=Number(n[1])/100,r=Number(n[2]),o=Number(n[3]),i=n[5]!==void 0?Number(n[5]):1;return new e(a,r,o,i)}toRGB(){let t=this.L,n=Number.isNaN(this.H)?0:this.C*Math.cos(this.H*Math.PI/180),a=Number.isNaN(this.H)?0:this.C*Math.sin(this.H*Math.PI/180),o=L([1,.3963377774,.2158037573,1,-.1055613458,-.0638541728,1,-.0894841775,-1.291485548],[t,n,a]).map(f=>f**3),i=L([1.2268798758,-.5578149945,.2813910457,-.0405757452,1.1122868033,-.0717110581,-.0763729367,-.4214933324,1.5869240198],o),[l,u,c]=L([3.240969942,-1.537383178,-.49861076,-.969243636,1.875967502,.041555057,.05563008,-.203976959,1.056971514],i);return[l,u,c]=[l,u,c].map(f=>Math.abs(f)>.0031308?(f<0?-1:1)*(1.055*Math.abs(f)**(1/2.4)-.055):12.92*f),new A(Math.round(S(l,0,1)*255),Math.round(S(u,0,1)*255),Math.round(S(c,0,1)*255),Number(this.alpha.toFixed(2)))}toJSON(){return{L:this.L,C:this.C,H:this.H,alpha:this.alpha}}clone(){return new e(this.L,this.C,this.H,this.alpha)}toFormat(t){switch(t){case"oklcha":return this;case"rgba":return this.toRGB();case"hsla":return this.toRGB().toFormat("hsla");case"hsba":return this.toRGB().toFormat("hsba");default:throw new Error(`Invalid format: ${t}`)}}toString(t){switch(t){case"hex":return this.toRGB().toString("hex");case"hexa":return this.toRGB().toString("hexa");case"oklch":{let n=Number.isNaN(this.L)?0:Number((this.L*100).toFixed(2)),a=Number.isNaN(this.C)?0:Number(this.C.toFixed(4)),r=Number.isNaN(this.H)?0:Number(this.H.toFixed(2));return`oklch(${n}% ${a} ${r})`}case"oklcha":case"css":{let n=Number.isNaN(this.L)?0:Number((this.L*100).toFixed(2)),a=Number.isNaN(this.C)?0:Number(this.C.toFixed(4)),r=Number.isNaN(this.H)?0:Number(this.H.toFixed(2)),o=Number.isNaN(this.alpha)?1:Number(this.alpha.toFixed(2));return`oklch(${n}% ${a} ${r} / ${o})`}case"hsl":return this.toRGB().toString("hsl");case"hsb":return this.toRGB().toString("hsb");case"rgb":return this.toRGB().toString("rgb");default:return this.toFormat(t).toString(t)}}getChannelRange(t){switch(t){case"L":return{min:0,max:1,step:.01};case"C":return{min:0,max:.4,step:.01};case"H":return{min:0,max:360,step:1};case"alpha":return{min:0,max:1,step:.01};default:throw new Error(`Unknown color channel: ${t}`)}}getFormat(){return"oklcha"}getChannels(){return["L","C","H"]}},H=e=>{let t=A.parse(e)??T.parse(e)??D.parse(e)??void 0;if(!t)throw new Error(`Invalid color: ${e}`);return t};function ot(e,t,n,a=!1){let{min:r,max:o}=t.getChannelRange(e),i=n==="horizontal"?a?"left":"right":"bottom";switch(e){case"hue":return`linear-gradient(to ${i}, rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0) 100%)`;case"lightness":{let l=t.withChannelValue(e,r).toString("css"),u=t.withChannelValue(e,(o-r)/2).toString("css"),c=t.withChannelValue(e,o).toString("css");return`linear-gradient(to ${i}, ${l}, ${u}, ${c})`}case"red":case"green":case"blue":case"saturation":case"brightness":case"alpha":{let l=t.withChannelValue(e,r).toString("css"),u=t.withChannelValue(e,o).toString("css");return`linear-gradient(to ${i}, ${l}, ${u})`}default:throw new Error(`Unknown color channel: ${e}`)}}function it(e,t){switch(t){case"hue":return H(`hsl(${e.getChannelValue("hue")}, 100%, 50%)`);case"red":case"green":case"blue":case"lightness":case"brightness":case"saturation":return e.withChannelValue("alpha",1);case"alpha":return e;default:throw new Error(`Unknown color channel: ${t}`)}}var Ht={hue:e=>[0,60,120,180,240,300,360].map(t=>e.withChannelValue("hue",t).toString("css")).join(", "),saturation:e=>`${e.withChannelValue("saturation",0).toString("css")}, transparent`,lightness:()=>"black, transparent, white",brightness:()=>"black, transparent"};function lt(e,t){let{xChannel:n,zChannel:a}=e.getSpaceAxes(t),r=e.getChannelValue(a),o=e.getFormat(),l=H((o==="rgba"||o==="oklcha"?"hsba":o)==="hsla"?"hsl(0, 100%, 50%)":"hsb(0, 100%, 100%)").withChannelValue(a,r),u=e.getChannels(),c=g=>g===n?"right":"top",f=u.filter(g=>g!==a).map(g=>`linear-gradient(to ${c(g)}, ${Ht[g](l)})`).reverse();return a==="hue"&&f.push(l.toString("css")),{"--px-area-gradient":f.join(", ")}}function z(e,t,n="hsba"){let a=e.getFormat()==="hsla";switch(t){case"hex":return e.getChannelValue("alpha")<e.getChannelRange("alpha").max?e.toString("hexa"):e.toString("hex");case"css":return e.toFormat(n).toString("css");case"red":case"green":case"blue":return e.toFormat("rgba").getChannelValue(t).toString();case"hue":return e.toFormat(a?"hsla":"hsba").getChannelValue("hue").toString();case"saturation":return e.toFormat(a?"hsla":"hsba").getChannelValue("saturation").toString();case"lightness":return e.toFormat("hsla").getChannelValue("lightness").toString();case"brightness":return e.toFormat("hsba").getChannelValue("brightness").toString();case"C":return e.toFormat("oklcha").getChannelValue("C").toString();case"H":return e.toFormat("oklcha").getChannelValue("H").toString();case"L":return e.toFormat("oklcha").getChannelValue("L").toString();default:return e.getChannelValue(t).toString()}}function ht(e,t="hex"){switch(t){case"hex":return{min:H("#000000").toHexInt(),max:H("#FFFFFF").toHexInt(),step:1};case"css":return;case"red":case"green":case"blue":return e.toFormat("rgba").getChannelRange(t);case"hue":case"lightness":case"saturation":return e.toFormat("hsla").getChannelRange(t);case"brightness":return e.toFormat("hsba").getChannelRange(t);case"L":case"C":case"H":return e.toFormat("oklcha").getChannelRange(t);default:return e.getChannelRange(t)}}import{withHeadless as It}from"@primereact/core/headless";import{useControlledState as yt}from"@primereact/hooks/use-controlled-state";import{useDirection as Gt}from"@primereact/hooks/use-direction";import*as w from"react";var ut={defaultValue:void 0,value:void 0,format:"hsba",disabled:!1,onValueChange:void 0,onValueChangeEnd:void 0};var $t=/^[0-9a-fA-F]{3,8}$/;function Bt(e){return $t.test(e)}function vt(e){return e.startsWith("#")?e:Bt(e)?`#${e}`:e}function Lt(e){return e.replace("to bottom","to top")}var Jt=It({name:"useInputColor",defaultProps:ut,setup({props:e}){let{format:t="hsba",disabled:n}=e,[a,r]=w.useState(!1),o=Gt()==="rtl",i=w.useRef([]),l=w.useRef({x:0,y:0}),u=w.useRef(e.defaultValue??H("#ff0000").toFormat(e.format||"hsba")),[c,f]=yt({value:e.value,defaultValue:u.current,onChange:e.onValueChange}),g=w.useMemo(()=>c??H("#ff0000").toFormat(t),[c,t]),_=t.startsWith("hsl")?"hsla":"hsba",d=w.useMemo(()=>g.toFormat(_),[g,_]),I={value:g,isAreaDragging:a},X=(s,h)=>{f([s,{color:s.toString(t),value:s,...h?.originalEvent?{originalEvent:h.originalEvent}:{}}]),O(s)},J=(s,h,R)=>{if(!R||n)return;let m=R.getBoundingClientRect(),C=Math.max(0,Math.min(1,(s-l.current.x-m.left)/m.width)),x=Math.max(0,Math.min(1,(h-l.current.y-m.top)/m.height)),{xChannel:b,yChannel:E}=U(),G=d.getChannelRange(b),y=d.getChannelRange(E),$=C*(G.max-G.min)+G.min,P=(1-x)*(y.max-y.min)+y.min,F=$-d.getChannelValue(b),N=P-d.getChannelValue(E),p=d.incChannelValue(b,F).incChannelValue(E,N);X(p)},Y=s=>{let h=s.currentTarget;if(!h||s.button!==0)return;let m=s.target?.closest?.('[data-part="area-handle"], .p-input-color-area-handle');if(m){let C=m.getBoundingClientRect(),x=C.left+C.width/2,b=C.top+C.height/2;l.current={x:s.clientX-x,y:s.clientY-b}}else l.current={x:0,y:0};h.setPointerCapture(s.pointerId),r(!0),J(s.clientX,s.clientY,h)},j=s=>{a&&J(s.clientX,s.clientY,s.currentTarget)},q=s=>{let h=s.currentTarget;h&&(h.releasePointerCapture(s.pointerId),r(!1),l.current={x:0,y:0},e.onValueChangeEnd&&e.onValueChangeEnd({originalEvent:s,color:g.toString(t),value:g}))},W=s=>{e.onValueChangeEnd&&e.onValueChangeEnd({originalEvent:s,color:g.toString(t),value:g})},Q=s=>{if(n)return;let h=s.key;if(!["ArrowRight","ArrowLeft","ArrowUp","ArrowDown"].includes(h))return;s.preventDefault();let{xChannel:R,yChannel:m}=U(),{step:C}=d.getChannelRange(R),{step:x}=d.getChannelRange(m),b=d;h==="ArrowRight"&&(b=b.incChannelValue(R,C)),h==="ArrowLeft"&&(b=b.decChannelValue(R,C)),h==="ArrowUp"&&(b=b.incChannelValue(m,x)),h==="ArrowDown"&&(b=b.decChannelValue(m,x)),X(b),e.onValueChangeEnd&&e.onValueChangeEnd({originalEvent:s,color:b.toString(t),value:b})},U=()=>{let s=d.getChannels();return{xChannel:s[1],yChannel:s[2]}},Z=()=>{if(typeof window<"u"&&!window.EyeDropper||n)return;new window.EyeDropper().open().then(h=>{let R=H(h.sRGBHex);X(R)}).catch(h=>{console.error("Error opening eyedropper",h)})},M=U(),{min:tt,max:ct}=d.getChannelRange(M.xChannel),{min:et,max:gt}=d.getChannelRange(M.yChannel),dt=d.getChannelValue(M.xChannel),mt=d.getChannelValue(M.yChannel),nt={...lt(d,M),"--px-handle-background":d.withChannelValue("alpha",1).toString("css"),"--px-handle-position-left":(dt-tt)/(ct-tt)*100+"%","--px-handle-position-top":(1-(mt-et)/(gt-et))*100+"%"},at={"--px-swatch-background":g.toString("css")},Ct=({channel:s="hue",orientation:h="horizontal",disabled:R}={})=>{let m=n||R,C=s==="alpha"?d:g.getChannels().includes(s)?g:d.getChannels().includes(s)?d:g.toFormat(t),x=C.getChannelRange(s),b=C.getChannelValue(s),E=ot(s,C,h,o),y={"--px-slider-background":h==="vertical"?Lt(E):E,"--px-slider-handle-background":it(C,s).toString("css")},$=F=>{if(m)return;let N=Array.isArray(F.value)?F.value[0]:F.value;if(N===void 0||Number.isNaN(N))return;let p=C.withChannelValue(s,N);X(p,{originalEvent:F.originalEvent})},P=F=>{if(m||!e.onValueChangeEnd)return;let N=Array.isArray(F.value)?F.value[0]:F.value;if(N===void 0||Number.isNaN(N))return;let p=C.withChannelValue(s,N);e.onValueChangeEnd({originalEvent:F.originalEvent,color:p.toString(t),value:p})};return{"data-scope":"inputcolor","data-part":"slider","data-orientation":h,"data-channel":s,orientation:h,style:y,value:b,min:x.min,max:x.max,step:x.step,disabled:m,onValueChange:$,onValueChangeEnd:P}},pt=s=>{let h=s.elementRef.current;i.current.includes(h)||i.current.push(h)},O=w.useCallback(s=>{requestAnimationFrame(()=>{let h=s||g;i.current.forEach(m=>{let C=m.getAttribute("data-channel");if(C){let x=z(h,C,t);m.value=String(x)}})})},[g,t]);w.useEffect(()=>{O()},[O]);let[rt,st]=w.useState(null),bt=({channel:s="hex",disabled:h}={})=>{let R=n||h,m=g,C=t,x=ht(m,s),b=z(m,s,C),E=s==="hex"||s==="css",G=E&&rt!==null?rt:b,y=p=>{if(R)return;let V;if(E)try{V=H(s==="hex"?vt(String(p)):String(p))}catch{V=m}else{let B=m;s!=="alpha"&&(B=B.toFormat(C));let v=Number.parseFloat(String(p)),Rt=Number.isNaN(v)?B.getChannelValue(s):v;V=B.withChannelValue(s,Rt)}return X(V),V},$=p=>{let V=p.currentTarget,B=E?V.value:V.valueAsNumber,v=y(B);E&&st(null),!(!v||!e.onValueChangeEnd)&&e.onValueChangeEnd({originalEvent:p,color:v.toString(t),value:v})},P=p=>{let V=p.currentTarget;E?st(V.value):y(V.valueAsNumber)},F=p=>{$(p)},N=p=>{p.defaultPrevented||p.key==="Enter"&&($(p),p.preventDefault())};return{"data-scope":"inputcolor","data-part":"input",type:E?"text":"number",spellCheck:!1,autoComplete:"off",disabled:!!R,"data-channel":s,"aria-label":s,min:x?.min,max:x?.max,step:x?.step,value:G,onChange:P,onBlur:F,onKeyDown:N}},ft={"data-scope":"inputcolor","data-part":"root",...n&&{"data-disabled":""},...a&&{"data-dragging":""}},xt={"data-scope":"inputcolor","data-part":"area",style:nt,onPointerDown:Y,onPointerMove:j,onPointerUp:q},St={"data-scope":"inputcolor","data-part":"area-handle",role:"slider",tabIndex:n?-1:0,"aria-disabled":n,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":d.getChannelValue(M.xChannel),"aria-label":`${M.xChannel} and ${M.yChannel}`,"aria-roledescription":"2d slider","aria-valuetext":`${M.xChannel} ${d.getChannelValue(M.xChannel)}, ${M.yChannel} ${d.getChannelValue(M.yChannel)}`,onKeyDown:Q,onBlur:W};return{state:I,value:c,areaValue:d,areaChannels:M,rootProps:ft,areaProps:xt,areaHandleProps:St,swatchProps:{"data-scope":"inputcolor","data-part":"swatch",style:at},eyeDropperProps:{"data-scope":"inputcolor","data-part":"eye-dropper",disabled:!!n,onClick:Z},sliderHandleProps:{"data-scope":"inputcolor","data-part":"slider-handle",role:"slider",tabIndex:n?-1:0,"aria-disabled":n},getInputProps:bt,getSliderProps:Ct,setValue:f,handleAreaPointerDown:Y,handleAreaPointerMove:j,handleAreaPointerUp:q,handleAreaBlur:W,handleAreaKeyDown:Q,areaStyles:nt,swatchStyles:at,openEyeDropper:Z,syncChannelInputs:O,registerInputEl:pt}}});export{D as HSBColor,T as HSLColor,K as OKLCHColor,A as RGBColor,ut as defaultProps,lt as getAreaGradient,it as getChannelColor,ot as getChannelGradient,ht as getInputChannelRange,z as getInputChannelValue,Pt as isEqual,H as parseColor,Jt as useInputColor};
|
package/inputpassword/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{withHeadless as m}from"@primereact/core/headless";import{useControlledState as o}from"@primereact/hooks/use-controlled-state";var s={value:void 0,defaultValue:void 0,mask:void 0,defaultMask:!0,onValueChange:void 0,onMaskChange:void 0,invalid:void 0};var k=m({name:"useInputPassword",defaultProps:s,setup({props:e}){let[u,r]=o({value:e.value,defaultValue:e.defaultValue,onChange:e.onValueChange}),[a,d]=o({value:e.mask,defaultValue:e.defaultMask??!0,onChange:e.onMaskChange}),l={value:u,mask:a??!0},p=t=>{let n=t.target.value;r([n,{originalEvent:t,value:n}])},i=()=>{d([!a,{value:!a}])},f={"data-scope":"
|
|
1
|
+
import{withHeadless as m}from"@primereact/core/headless";import{useControlledState as o}from"@primereact/hooks/use-controlled-state";var s={value:void 0,defaultValue:void 0,mask:void 0,defaultMask:!0,onValueChange:void 0,onMaskChange:void 0,invalid:void 0};var k=m({name:"useInputPassword",defaultProps:s,setup({props:e}){let[u,r]=o({value:e.value,defaultValue:e.defaultValue,onChange:e.onValueChange}),[a,d]=o({value:e.mask,defaultValue:e.defaultMask??!0,onChange:e.onMaskChange}),l={value:u,mask:a??!0},p=t=>{let n=t.target.value;r([n,{originalEvent:t,value:n}])},i=()=>{d([!a,{value:!a}])},f={"data-scope":"inputpassword","data-part":"root",type:a?"password":"text",onChange:p,...e.invalid?{"data-invalid":""}:{}};return{state:l,rootProps:f,toggleMask:i}}});export{s as defaultProps,k as useInputPassword};
|
package/listbox/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{withHeadless as
|
|
1
|
+
import{withHeadless as We}from"@primereact/core/headless";import{useControlledState as je}from"@primereact/hooks/use-controlled-state";import{equals as Qe,findLastIndex as $,findSingle as Xe,focus as W,getFirstFocusableElement as pe,isElement as Ye,isNotEmpty as j,isNumber as Ze,isPrintableCharacter as et,isString as be,nextFrame as tt,resolveFieldData as v,toElement as K}from"@primeuix/utils";import*as i from"react";var fe={value:void 0,defaultValue:void 0,options:[],optionKey:void 0,optionLabel:void 0,optionValue:void 0,optionDisabled:void 0,optionGroupLabel:void 0,optionGroupChildren:void 0,disabled:!1,invalid:!1,locale:void 0,multiple:!1,metaKeySelection:!1,autoOptionFocus:!0,selectOnFocus:!1,focusOnHover:!0,tabIndex:void 0,onValueChange:void 0};var it=We({name:"useListbox",defaultProps:fe,setup({id:p,props:o,elementRef:y}){let[d,S]=i.useState(!1),[a,l]=i.useState(-1),[c,q]=je({value:o.value,defaultValue:o.defaultValue??null,onChange:o.onValueChange}),_={value:c,focused:d,focusedOptionIndex:a},I=i.useRef(null),O=i.useRef(null),g=i.useRef(null),L=i.useRef(!1),m=i.useRef(-1),h=i.useRef(null),R=i.useRef(""),r=()=>Be||[],H=e=>`${p}_${e}`,f=e=>o.optionLabel?v(e,o.optionLabel):be(e)||Ze(e)?e:null,b=e=>o.optionValue?v(e,o.optionValue):e,z=e=>o.optionDisabled?!!v(e,o.optionDisabled):!1,Q=e=>!!(o.optionGroupLabel&&e?.optionGroup&&e?.group),he=e=>o.optionGroupLabel?v(e,o.optionGroupLabel):be(e)?e:null,J=i.useCallback(e=>o.optionGroupChildren?v(e,o.optionGroupChildren):null,[o.optionGroupChildren]),V=()=>a!==-1?H(a):void 0,xe=()=>{W(I.current);let e=pe(y.current,":not([data-focus-guard])"),t=K(g);t&&(t.tabIndex=Ye(e)?0:-1);let n=K(O);n&&(n.tabIndex=-1)},Ee=e=>{if(e.relatedTarget===I.current){let s=pe(y.current,":not([data-focus-guard])");s instanceof HTMLElement&&W(s);let u=K(O);u&&(u.tabIndex=0)}else W(K(O));let n=K(g);n&&(n.tabIndex=-1)},Oe=e=>{let t=y.current instanceof HTMLElement&&y.current.contains(e.relatedTarget),n=K(g),s=K(O);!t&&n&&s&&(n.tabIndex=0,s.tabIndex=0)},ge=e=>{let t=e?.currentTarget?.dataset?.dndFocusIndex,n=t!==void 0?parseInt(t,10):a!==-1?a:o.autoOptionFocus?T():ae();S(!0),l(n),B(),C(n)},Re=()=>{S(!1),l(-1),m.current=-1,R.current=""},we=e=>{let t=e.metaKey||e.ctrlKey;switch(e.code){case"ArrowDown":X(e);break;case"ArrowUp":Y(e);break;case"Home":Z(e);break;case"End":ee(e);break;case"PageDown":De(e);break;case"PageUp":Pe(e);break;case"Enter":case"NumpadEnter":case"Space":Te(e);break;case"Tab":break;case"ShiftLeft":case"ShiftRight":ne();break;default:if(o.multiple&&e.code==="KeyA"&&t){let n=r().filter(s=>x(s)).map(s=>b(s));M(e,n),e.preventDefault();break}!t&&et(e.key)&&(Ue(e,e.key),e.preventDefault());break}},G=(e,t,n=-1)=>{o.disabled||z(t)||(o.multiple?Ke(e,t):ke(e,t),L.current=!1,n!==-1&&l(n))},Ie=()=>{o.disabled||(L.current=!0)},ke=(e,t)=>{let n=N(t),s=L.current?!1:o.metaKeySelection,u=!1,E=null;if(s){let A=e&&(e.metaKey||e.ctrlKey);n?A&&(E=null,u=!0):(E=b(t),u=!0)}else E=n?null:b(t),u=!0;u&&M(e,E)},Ke=(e,t)=>{let n=N(t),s=L.current?!1:o.metaKeySelection,u=null;if(s){let E=e.metaKey||e.ctrlKey;n?u=E?ue(t):[b(t)]:(u=E?Array.isArray(c)?c:[]:[],u=[...u,b(t)])}else u=n?ue(t):[...Array.isArray(c)?c:[],b(t)];M(e,u)},P=(e,t=-1,n=-1)=>{if(t=t===-1?ie(n,!0):t,n=n===-1?ie(t):n,t!==-1&&n!==-1){let s=Math.min(t,n),u=Math.max(t,n),E=r().slice(s,u+1).filter(A=>x(A)).map(A=>b(A));M(e,E)}},Se=()=>{l(-1),m.current=-1},Le=()=>{l(-1),m.current=-1},Fe=e=>{switch(e.code){case"ArrowDown":X(e);break;case"ArrowUp":Y(e);break;case"ArrowLeft":case"ArrowRight":He(e,!0);break;case"Home":Z(e,!0);break;case"End":ee(e,!0);break;case"Enter":case"NumpadEnter":te(e);break;case"ShiftLeft":case"ShiftRight":ne();break;default:break}},Me=e=>{o.disabled||M(e,o.multiple?[]:null)},X=e=>{let t=a!==-1?Ce(a):T();o.multiple&&e.shiftKey&&P(e,m.current,t),F(e,t),e.preventDefault()},Y=e=>{let t=a!==-1?Ae(a):Ge();o.multiple&&e.shiftKey&&P(e,t,m.current),F(e,t),e.preventDefault()},He=(e,t=!1)=>{t&&l(-1)},Z=(e,t=!1)=>{if(t){let n=e.currentTarget;e.shiftKey?n?.setSelectionRange(0,n.selectionStart):(n?.setSelectionRange(0,0),l(-1))}else{let n=e.metaKey||e.ctrlKey,s=oe();o.multiple&&e.shiftKey&&n&&P(e,s,m.current),F(e,s)}e.preventDefault()},ee=(e,t=!1)=>{if(t){let n=e.currentTarget,s=n.value.length;e.shiftKey?n.setSelectionRange(n.selectionStart,s):(n.setSelectionRange(s,s),l(-1))}else{let n=e.metaKey||e.ctrlKey,s=se();o.multiple&&e.shiftKey&&n&&P(e,m.current,s),F(e,s)}e.preventDefault()},Pe=e=>{C(0),e.preventDefault()},De=e=>{C(r().length-1),e.preventDefault()},te=e=>{a!==-1&&(o.multiple&&e.shiftKey?P(e,a):G(e,r()[a]))},Te=e=>{e.preventDefault(),te(e)},ne=()=>{m.current=a},U=e=>x(e)&&f(e)?.toLocaleLowerCase(o.locale).startsWith(R.current?.toLocaleLowerCase(o.locale)),x=e=>j(e)&&!z(e)&&!Q(e),k=e=>x(e)&&N(e),D=(e,t)=>Qe(e,t,de),N=e=>{let t=b(e);return o.multiple?Array.isArray(c)&&c.some(n=>D(n,t)):D(c,t)},oe=()=>r().findIndex(e=>x(e)),se=()=>$(r(),e=>x(e)),Ce=e=>{let t=e<r().length-1?r().slice(e+1).findIndex(n=>x(n)):-1;return t>-1?t+e+1:e},Ae=e=>{let t=e>0?$(r().slice(0,e),n=>x(n)):-1;return t>-1?t:e},ae=()=>{if(w())if(o.multiple&&Array.isArray(c))for(let e=c.length-1;e>=0;e--){let t=c[e],n=r().findIndex(s=>k(s)&&D(t,b(s)));if(n>-1)return n}else return r().findIndex(e=>k(e));return-1},ve=()=>w()?r().findIndex(e=>k(e)):-1,Ve=()=>w()?$(r(),e=>k(e)):-1,re=e=>{let t=w()&&e<r().length-1?r().slice(e+1).findIndex(n=>k(n)):-1;return t>-1?t+e+1:-1},ce=e=>{let t=w()&&e>0?$(r().slice(0,e),n=>k(n)):-1;return t>-1?t:-1},ie=(e,t=!1)=>{let n=-1;return w()&&(t?(n=ce(e),n=n===-1?re(e):n):(n=re(e),n=n===-1?ce(e):n)),n>-1?n:e},T=()=>{let e=ve();return e<0?oe():e},Ge=()=>{let e=Ve();return e<0?se():e},Ue=(e,t)=>{R.current=(R.current||"")+t;let n=-1;j(R.current)&&(a!==-1?(n=r().slice(a).findIndex(s=>U(s)),n=n===-1?r().slice(0,a).findIndex(s=>U(s)):n+a):n=r().findIndex(s=>U(s)),n===-1&&a===-1&&(n=T()??-1),n!==-1&&F(e,n)),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{R.current="",h.current=null},500)},ue=e=>Array.isArray(c)?c.filter(t=>!D(t,b(e))):[],F=(e,t=-1)=>{a!==t&&(l(t),C(t),o.selectOnFocus&&!o.multiple&&t!==-1&&G(e,r()[t]))},C=(e=-1)=>{tt().then(()=>{let t=e!==-1?H(e):V();Xe(I.current,`[id="${t}"]`)?.scrollIntoView?.({block:"nearest",inline:"nearest",behavior:"smooth"})})},B=()=>{if(o.selectOnFocus&&o.autoOptionFocus&&!w()&&!o.multiple&&d){let e=T();l(e),G(null,r()[e])}},M=(e,t)=>{q([t,{originalEvent:e,value:t}])},w=()=>j(c),le=i.useRef(B);le.current=B,i.useEffect(()=>(le.current(),()=>{h.current&&(clearTimeout(h.current),h.current=null)}),[]);let Ne=i.useMemo(()=>{let e=[];return(o.options||[]).forEach(t=>{let n=J(t)||[];n?.length&&e.push({optionGroup:t,group:!0},...n)}),e},[o.options,J]),Be=o.optionGroupLabel?Ne:o.options,de=o.optionValue?void 0:o.optionKey,$e={role:"presentation",ref:g,"aria-hidden":!0,"data-focus-guard":"",onFocus:Ee},qe={role:"presentation",ref:O,"aria-hidden":!0,"data-focus-guard":"",onFocus:xe},_e={role:"searchbox",autoComplete:"off",disabled:o.disabled,tabIndex:void 0,"aria-owns":p?`${p}_list`:void 0,"aria-activedescendant":V(),"data-scope":"listbox","data-part":"filter",onBlur:Le,onChange:Se,onKeyDown:Fe},ze={id:`${p}_list`,role:"listbox",ref:I,tabIndex:-1,"aria-activedescendant":d?V():void 0,"data-scope":"listbox","data-part":"list",onFocus:ge,onBlur:Re,onKeyDown:we},Je={id:p,"data-scope":"listbox","data-part":"root","data-disabled":o.disabled||void 0,"data-invalid":o.invalid||void 0,onBlur:Oe};return{state:_,listRef:I,firstHiddenElementRef:O,lastHiddenElementRef:g,rootProps:Je,listProps:ze,filterProps:_e,firstHiddenProps:qe,lastHiddenProps:$e,getOptions:r,getOptionId:H,getOptionLabel:f,getOptionValue:b,isOptionDisabled:z,isOptionGroup:Q,getOptionGroupLabel:he,getOptionGroupChildren:J,getFocusedOptionId:V,onOptionSelect:G,onOptionTouchEnd:Ie,onClearClick:Me,isOptionMatched:U,isValidOption:x,isValidSelectedOption:k,isSelected:N,changeFocusedOptionIndex:F,findSelectedOptionIndex:ae,findFirstFocusedOptionIndex:T,scrollInView:C,updateModel:M,autoUpdateModel:B,equalityKey:de,hasValue:w,isEquals:D}}});import{withHeadless as nt}from"@primereact/core/headless";import*as ye from"react";var me={option:void 0,index:void 0,group:!1,disabled:void 0,context:void 0};var pt=nt({name:"useListboxOption",defaultProps:me,setup({props:p}){let o=p.context,y=p.option,d=p.index??-1,S=p.group??!1,a=o?.isSelected(y)??!1,l=o?.state?.focusedOptionIndex===d,c=p.disabled??o?.isOptionDisabled(y)??!1,q={selected:a,focused:l,disabled:c,group:S},_=ye.useMemo(()=>{if(S)return{};let g=o?.getOptions()??[],L=g.filter(f=>!o?.isOptionGroup(f)).length,m=(o?.props?.optionGroupLabel?d-(g.slice(0,d).filter(f=>o?.isOptionGroup(f)).length||0):d)+1,h=f=>o?.onOptionSelect(f,y,d),R=f=>{o?.changeFocusedOptionIndex(f,d)},r=f=>{o?.props?.focusOnHover&&o?.state?.focused&&o?.changeFocusedOptionIndex(f,d)},H=()=>o?.onOptionTouchEnd();return{id:o?.getOptionId(d)??"",role:"option","aria-selected":a,"aria-disabled":c,"aria-setsize":L,"aria-posinset":m,[a?"data-selected":"data-unselected"]:"",...c&&{"data-disabled":""},...l&&{"data-focused":""},"data-scope":"listbox","data-part":"option",onClick:h,onMouseDown:R,onMouseMove:r,onTouchEnd:H}},[o,y,d,a,c,l,S]),I={role:"presentation","data-scope":"listbox","data-part":"optionGroup"},O={"aria-hidden":!0,"data-scope":"listbox","data-part":"optionindicator",[a?"data-selected":"data-unselected"]:""};return{state:q,optionProps:_,groupProps:I,optionIndicatorProps:O}}});export{me as defaultOptionProps,fe as defaultProps,it as useListbox,pt as useListboxOption};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{withHeadless as
|
|
1
|
+
import{withHeadless as h}from"@primereact/core/headless";import{useCheckbox as m}from"@primereact/headless/checkbox";import*as d from"react";var a={checked:void 0,defaultChecked:void 0,indeterminate:!1,trueValue:!0,falseValue:!1,inputId:void 0,name:void 0,value:void 0,disabled:void 0,closeOnSelect:!1,onSelect:void 0,onCheckedChange:void 0};var k=h({name:"useMenuCheckboxItem",defaultProps:a,setup({props:e}){let{onSelect:o}=e,n=m({...e,onCheckedChange:e.onCheckedChange?c=>e.onCheckedChange(c):void 0}),t=!!n.state.checked,s=!!e.disabled,u=e.closeOnSelect??!1,l=d.useCallback(c=>{s||(n.onChange({target:{checked:!t}}),o?.(c))},[n,t,s,o]);return{...n,state:{...n.state,checked:t},closeOnSelect:u,onSelect:l}}});export{a as defaultProps,k as useMenuCheckboxItem};
|