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,GAAE;wBAAI,OAAM;wBAAI,QAAO;;kCAClD,gCAAC;wBAAK,MAAK;wBAAU,GAAE;wBAAI,GAAE;wBAAI,OAAM;wBAAI,QAAO;;;;0BAEpD,gCAAC;gBACC,GAAE;gBACF,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;;0BAC5B,gCAAC;gBACC,GAAE;gBACF,MAAM,MAAM,QAAQ;;0BACtB,gCAAC;gBACC,SAAS;gBAQT,GAAE;;;;AAGV","sources":["packages/@react-spectrum/s2/src/ColorHandle.tsx"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {cloneElement, JSX, ReactNode, RefObject, useState} from 'react';\nimport {ColorThumb} from 'react-aria-components';\nimport {createPortal} from 'react-dom';\nimport {keyframes} from '../style/style-macro' with {type: 'macro'};\nimport {style} from '../style' with {type: 'macro'};\nimport {useId, useLayoutEffect} from '@react-aria/utils';\n\nconst HANDLE_SIZE = 16;\nconst LOUPE_HEIGHT = 64; // Does not include borders\nconst LOUPE_WIDTH = 48;\nconst LOUPE_BORDER_WIDTH = 1;\nconst LOUPE_OFFSET = 12; // Offset from handle to loupe\n\ninterface ColorHandleProps {\n containerRef: RefObject<HTMLElement | null>,\n getPosition: () => {x: number, y: number}\n}\n\nexport function ColorHandle({containerRef, getPosition}: ColorHandleProps): ReactNode {\n return (\n <ColorThumb\n className={style({\n transition: '[width, height]',\n size: {\n default: HANDLE_SIZE,\n isFocusVisible: 32\n },\n backgroundColor: {\n isDisabled: 'disabled'\n },\n borderRadius: 'full',\n boxSizing: 'border-box',\n borderStyle: 'solid',\n borderWidth: 2,\n borderColor: {\n default: 'white',\n isDisabled: 'disabled'\n },\n outlineStyle: 'solid',\n outlineWidth: 1,\n outlineColor: {\n default: 'black/42',\n forcedColors: 'ButtonBorder'\n }\n })}\n style={({defaultStyle, isDisabled}) => ({\n background: isDisabled ? undefined : `linear-gradient(${defaultStyle.backgroundColor}, ${defaultStyle.backgroundColor}), repeating-conic-gradient(#E1E1E1 0% 25%, white 0% 50%) 50% / 16px 16px`,\n backgroundColor: undefined,\n top: defaultStyle.top || '50%',\n left: defaultStyle.left || '50%'\n })}>\n {({isDragging, color}) => (<>\n <div\n className={style({\n size: 'full',\n borderRadius: 'full',\n boxSizing: 'border-box',\n borderStyle: 'solid',\n borderWidth: 1,\n borderColor: {\n default: 'black/42',\n forcedColors: 'ButtonBorder'\n }\n })} />\n <ColorLoupePortal isOpen={isDragging}>\n <ColorLoupe containerRef={containerRef} color={color} getPosition={getPosition} />\n </ColorLoupePortal>\n </>)}\n </ColorThumb>\n );\n}\n\n// ColorLoupe is rendered in a portal so that it breaks out of clipped/scrolling containers (e.g. popovers).\nfunction ColorLoupePortal({isOpen, children}: { isOpen: boolean, children: JSX.Element }) {\n let [state, setState] = useState(isOpen ? 'open' : 'closed');\n if (isOpen && state === 'closed') {\n setState('open');\n }\n\n if (!isOpen && state === 'open') {\n setState('exiting');\n }\n\n if (isOpen || state === 'exiting') {\n return createPortal(cloneElement(children, {isExiting: state === 'exiting', onExited: () => setState('closed')}), document.body);\n }\n\n return null;\n}\n\nfunction ColorLoupe({isExiting, onExited, containerRef, loupeRef, getPosition, color}: any) {\n let patternId = useId();\n\n // Get the bounding rectangle of the container (e.g. ColorArea/ColorSlider).\n let [containerRect, setContainerRect] = useState({top: 0, left: 0, width: 0, height: 0});\n useLayoutEffect(() => {\n let rect = containerRef.current?.getBoundingClientRect();\n setContainerRect({\n top: rect?.top || 0,\n left: rect?.left || 0,\n width: rect?.width || 0,\n height: rect?.height || 0\n });\n }, [containerRef]);\n\n // Compute the pixel position of the thumb.\n let {x: thumbLeft, y: thumbTop} = getPosition();\n thumbTop *= containerRect.height;\n thumbLeft *= containerRect.width;\n\n let enterAnimation = keyframes(`\n from {\n transform: translateY(8px);\n opacity: 0;\n }\n `);\n\n let exitAnimation = keyframes(`\n to {\n transform: translateY(8px);\n opacity: 0;\n }\n `);\n\n return (\n <svg\n style={{\n // Position relative to the viewport.\n position: 'fixed',\n top: containerRect.top + thumbTop,\n left: containerRect.left + thumbLeft,\n marginTop: -LOUPE_HEIGHT - LOUPE_BORDER_WIDTH * 2 - HANDLE_SIZE / 2 - LOUPE_OFFSET,\n marginLeft: -LOUPE_WIDTH / 2 - LOUPE_BORDER_WIDTH,\n animationName: isExiting ? exitAnimation : enterAnimation\n }}\n className={style({\n filter: 'elevated',\n pointerEvents: 'none',\n animationDuration: 125,\n animationFillMode: 'forwards',\n animationTimingFunction: 'in-out',\n isolation: 'isolate'\n })}\n onAnimationEnd={e => {\n if (e.animationName === exitAnimation) {\n onExited();\n }\n }}\n width={LOUPE_WIDTH + LOUPE_BORDER_WIDTH * 2}\n height={LOUPE_HEIGHT + LOUPE_BORDER_WIDTH * 2}\n ref={loupeRef}\n aria-hidden=\"true\">\n <pattern id={patternId} x=\"0\" y=\"0\" width=\"16\" height=\"16\" patternUnits=\"userSpaceOnUse\">\n <rect fill=\"white\" x=\"0\" y=\"0\" width=\"16\" height=\"16\" />\n <rect fill=\"#E1E1E1\" x=\"0\" y=\"0\" width=\"8\" height=\"8\" />\n <rect fill=\"#E1E1E1\" x=\"8\" y=\"8\" width=\"8\" height=\"8\" />\n </pattern>\n <path\n d=\"M25 1a24 24 0 0124 24c0 16.255-24 40-24 40S1 41.255 1 25A24 24 0 0125 1z\"\n fill={`url(#${patternId})`} />\n <path\n d=\"M25 1a24 24 0 0124 24c0 16.255-24 40-24 40S1 41.255 1 25A24 24 0 0125 1z\"\n fill={color.toString()} />\n <path\n className={style({\n strokeWidth: 1,\n stroke: {\n default: 'transparent-black-200',\n forcedColors: 'ButtonBorder'\n },\n fill: 'white'\n })}\n d=\"M25 3A21.98 21.98 0 003 25c0 6.2 4 14.794 11.568 24.853A144.233 144.233 0 0025 62.132a144.085 144.085 0 0010.4-12.239C42.99 39.816 47 31.209 47 25A21.98 21.98 0 0025 3m0-2a24 24 0 0124 24c0 16.255-24 40-24 40S1 41.255 1 25A24 24 0 0125 1z\" />\n </svg>\n );\n}\n"],"names":[],"version":3,"file":"ColorHandle.cjs.map"}