@react-aria/color 3.1.0 → 3.1.2
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.
|
@@ -239,8 +239,8 @@ function $1d29bf243d4a9a53$export$9064ff4e44b3729a(props, state, inputRef) {
|
|
|
239
239
|
...thumbInteractions,
|
|
240
240
|
style: {
|
|
241
241
|
position: 'absolute',
|
|
242
|
-
left: outerRadius + x,
|
|
243
|
-
top: outerRadius + y,
|
|
242
|
+
left: (outerRadius + x).toFixed(3) + 'px',
|
|
243
|
+
top: (outerRadius + y).toFixed(3) + 'px',
|
|
244
244
|
transform: 'translate(-50%, -50%)',
|
|
245
245
|
touchAction: 'none',
|
|
246
246
|
...forcedColorAdjustNoneStyle
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA+BM,SAAS,0CAAc,KAA4B,EAAE,KAAsB,EAAE,QAA4C;IAC9H,IAAI,cACF,UAAU,eACV,WAAW,eACX,WAAW,EACX,cAAc,SAAS,QACvB,IAAI,QACJ,IAAI,EACL,GAAG;IAEJ,IAAI,qBAAC,iBAAiB,wBAAE,oBAAoB,EAAC,GAAG,CAAA,GAAA,wCAAiB;IAEjE,IAAI,cAAc,AAAC,CAAA,cAAc,WAAU,IAAK;IAEhD,IAAI,aAAa,CAAA,GAAA,wBAAU,EAAE;QAC3B,IAAI,SAAS,OAAO,EAClB,CAAA,GAAA,2CAAoB,EAAE,SAAS,OAAO;IAE1C,GAAG;QAAC;KAAS;IAEb,CAAA,GAAA,kCAAW,EAAE,UAAU,MAAM,YAAY,EAAE,MAAM,QAAQ;IAEzD,IAAI,kBAAkB,CAAA,GAAA,mBAAK,EAAiC;IAE5D,IAAI,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,wCAAU,EAAE;QAChC,WAAU,CAAC;YACT,kDAAkD;YAClD,IAAI,CAAC,sBAAsB,IAAI,CAAC,EAAE,GAAG,G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EAAE,UAAU,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC;AAC1G","sources":["packages/@react-aria/color/src/useColorWheel.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {AriaColorWheelProps} from '@react-types/color';\nimport {ColorWheelState} from '@react-stately/color';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, mergeProps, useFormReset, useGlobalListeners, useLabels} from '@react-aria/utils';\nimport React, {ChangeEvent, InputHTMLAttributes, useCallback, useRef} from 'react';\nimport {useKeyboard, useMove} from '@react-aria/interactions';\nimport {useLocale} from '@react-aria/i18n';\nimport {useVisuallyHidden} from '@react-aria/visually-hidden';\n\nexport interface AriaColorWheelOptions extends AriaColorWheelProps {\n /** The outer radius of the color wheel. */\n outerRadius: number,\n /** The inner radius of the color wheel. */\n innerRadius: number\n}\n\nexport interface ColorWheelAria {\n /** Props for the track element. */\n trackProps: DOMAttributes,\n /** Props for the thumb element. */\n thumbProps: DOMAttributes,\n /** Props for the visually hidden range input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a color wheel component.\n * Color wheels allow users to adjust the hue of an HSL or HSB color value on a circular track.\n */\nexport function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelState, inputRef: RefObject<HTMLInputElement | null>): ColorWheelAria {\n let {\n isDisabled,\n innerRadius,\n outerRadius,\n 'aria-label': ariaLabel,\n name,\n form\n } = props;\n\n let {addGlobalListener, removeGlobalListener} = useGlobalListeners();\n\n let thumbRadius = (innerRadius + outerRadius) / 2;\n\n let focusInput = useCallback(() => {\n if (inputRef.current) {\n focusWithoutScrolling(inputRef.current);\n }\n }, [inputRef]);\n\n useFormReset(inputRef, state.defaultValue, state.setValue);\n\n let currentPosition = useRef<{x: number, y: number} | null>(null);\n\n let {keyboardProps} = useKeyboard({\n onKeyDown(e) {\n // these are the cases that useMove doesn't handle\n if (!/^(PageUp|PageDown)$/.test(e.key)) {\n e.continuePropagation();\n return;\n }\n // same handling as useMove, don't need to stop propagation, useKeyboard will do that for us\n e.preventDefault();\n // remember to set this and unset it so that onChangeEnd is fired\n state.setDragging(true);\n switch (e.key) {\n case 'PageUp':\n e.preventDefault();\n state.increment(state.pageStep);\n break;\n case 'PageDown':\n e.preventDefault();\n state.decrement(state.pageStep);\n break;\n }\n state.setDragging(false);\n }\n });\n\n let moveHandler = {\n onMoveStart() {\n currentPosition.current = null;\n state.setDragging(true);\n },\n onMove({deltaX, deltaY, pointerType, shiftKey}) {\n if (currentPosition.current == null) {\n currentPosition.current = state.getThumbPosition(thumbRadius);\n }\n currentPosition.current.x += deltaX;\n currentPosition.current.y += deltaY;\n if (pointerType === 'keyboard') {\n if (deltaX > 0 || deltaY < 0) {\n state.increment(shiftKey ? state.pageStep : state.step);\n } else if (deltaX < 0 || deltaY > 0) {\n state.decrement(shiftKey ? state.pageStep : state.step);\n }\n } else {\n state.setHueFromPoint(currentPosition.current.x, currentPosition.current.y, thumbRadius);\n }\n },\n onMoveEnd() {\n isOnTrack.current = false;\n state.setDragging(false);\n focusInput();\n }\n };\n let {moveProps: movePropsThumb} = useMove(moveHandler);\n\n let currentPointer = useRef<number | null | undefined>(undefined);\n let isOnTrack = useRef<boolean>(false);\n let {moveProps: movePropsContainer} = useMove({\n onMoveStart() {\n if (isOnTrack.current) {\n moveHandler.onMoveStart();\n }\n },\n onMove(e) {\n if (isOnTrack.current) {\n moveHandler.onMove(e);\n }\n },\n onMoveEnd() {\n if (isOnTrack.current) {\n moveHandler.onMoveEnd();\n }\n }\n });\n\n let onThumbDown = (id: number | null | undefined) => {\n if (!state.isDragging) {\n currentPointer.current = id;\n focusInput();\n state.setDragging(true);\n\n if (typeof PointerEvent !== 'undefined') {\n addGlobalListener(window, 'pointerup', onThumbUp, false);\n } else {\n addGlobalListener(window, 'mouseup', onThumbUp, false);\n addGlobalListener(window, 'touchend', onThumbUp, false);\n }\n }\n };\n\n let onThumbUp = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (id === currentPointer.current) {\n focusInput();\n state.setDragging(false);\n currentPointer.current = undefined;\n isOnTrack.current = false;\n\n if (typeof PointerEvent !== 'undefined') {\n removeGlobalListener(window, 'pointerup', onThumbUp, false);\n } else {\n removeGlobalListener(window, 'mouseup', onThumbUp, false);\n removeGlobalListener(window, 'touchend', onThumbUp, false);\n }\n }\n };\n\n let onTrackDown = (track: Element, id: number | null | undefined, pageX: number, pageY: number) => {\n let rect = track.getBoundingClientRect();\n let x = pageX - rect.x - rect.width / 2;\n let y = pageY - rect.y - rect.height / 2;\n let radius = Math.sqrt(x * x + y * y);\n if (innerRadius < radius && radius < outerRadius && !state.isDragging && currentPointer.current === undefined) {\n isOnTrack.current = true;\n currentPointer.current = id;\n state.setHueFromPoint(x, y, radius);\n\n focusInput();\n state.setDragging(true);\n\n if (typeof PointerEvent !== 'undefined') {\n addGlobalListener(window, 'pointerup', onTrackUp, false);\n } else {\n addGlobalListener(window, 'mouseup', onTrackUp, false);\n addGlobalListener(window, 'touchend', onTrackUp, false);\n }\n }\n };\n\n let onTrackUp = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (isOnTrack.current && id === currentPointer.current) {\n isOnTrack.current = false;\n currentPointer.current = undefined;\n state.setDragging(false);\n focusInput();\n\n\n if (typeof PointerEvent !== 'undefined') {\n removeGlobalListener(window, 'pointerup', onTrackUp, false);\n } else {\n removeGlobalListener(window, 'mouseup', onTrackUp, false);\n removeGlobalListener(window, 'touchend', onTrackUp, false);\n }\n }\n };\n\n let trackInteractions = isDisabled ? {} : mergeProps({\n ...(typeof PointerEvent !== 'undefined' ? {\n onPointerDown: (e: React.PointerEvent) => {\n if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) {\n return;\n }\n onTrackDown(e.currentTarget, e.pointerId, e.clientX, e.clientY);\n }} : {\n onMouseDown: (e: React.MouseEvent) => {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onTrackDown(e.currentTarget, undefined, e.clientX, e.clientY);\n },\n onTouchStart: (e: React.TouchEvent) => {\n onTrackDown(e.currentTarget, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);\n }\n })\n }, movePropsContainer);\n\n let thumbInteractions = isDisabled ? {} : mergeProps({\n onMouseDown: (e: React.MouseEvent) => {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onThumbDown(undefined);\n },\n onPointerDown: (e: React.PointerEvent) => {\n if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) {\n return;\n }\n onThumbDown(e.pointerId);\n },\n onTouchStart: (e: React.TouchEvent) => {\n onThumbDown(e.changedTouches[0].identifier);\n }\n }, keyboardProps, movePropsThumb);\n let {x, y} = state.getThumbPosition(thumbRadius);\n\n // Provide a default aria-label if none is given\n let {locale} = useLocale();\n if (ariaLabel == null && props['aria-labelledby'] == null) {\n ariaLabel = state.value.getChannelName('hue', locale);\n }\n\n let inputLabellingProps = useLabels({\n ...props,\n 'aria-label': ariaLabel\n });\n\n let {minValue, maxValue, step} = state.value.getChannelRange('hue');\n\n let forcedColorAdjustNoneStyle = {\n forcedColorAdjust: 'none'\n };\n\n let {visuallyHiddenProps} = useVisuallyHidden({\n style: {\n opacity: '0.0001',\n width: '100%',\n height: '100%',\n pointerEvents: 'none'\n }\n });\n\n return {\n trackProps: {\n ...trackInteractions,\n style: {\n position: 'relative',\n touchAction: 'none',\n width: outerRadius * 2,\n height: outerRadius * 2,\n background: `\n conic-gradient(\n from 90deg,\n hsl(0, 100%, 50%),\n hsl(30, 100%, 50%),\n hsl(60, 100%, 50%),\n hsl(90, 100%, 50%),\n hsl(120, 100%, 50%),\n hsl(150, 100%, 50%),\n hsl(180, 100%, 50%),\n hsl(210, 100%, 50%),\n hsl(240, 100%, 50%),\n hsl(270, 100%, 50%),\n hsl(300, 100%, 50%),\n hsl(330, 100%, 50%),\n hsl(360, 100%, 50%)\n )\n `,\n clipPath: `path(evenodd, \"${circlePath(outerRadius, outerRadius, outerRadius)} ${circlePath(outerRadius, outerRadius, innerRadius)}\")`,\n ...forcedColorAdjustNoneStyle\n }\n },\n thumbProps: {\n ...thumbInteractions,\n style: {\n position: 'absolute',\n left: outerRadius + x,\n top: outerRadius + y,\n transform: 'translate(-50%, -50%)',\n touchAction: 'none',\n ...forcedColorAdjustNoneStyle\n }\n },\n inputProps: mergeProps(\n inputLabellingProps,\n {\n type: 'range',\n min: String(minValue),\n max: String(maxValue),\n step: String(step),\n 'aria-valuetext': `${state.value.formatChannelValue('hue', locale)}, ${state.value.getHueName(locale)}`,\n disabled: isDisabled,\n value: `${state.value.getChannelValue('hue')}`,\n name,\n form,\n onChange: (e: ChangeEvent<HTMLInputElement>) => {\n state.setHue(parseFloat(e.target.value));\n },\n style: visuallyHiddenProps.style,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-describedby': props['aria-describedby'],\n 'aria-details': props['aria-details']\n }\n )\n };\n}\n\n// Creates an SVG path string for a circle.\nfunction circlePath(cx: number, cy: number, r: number) {\n return `M ${cx}, ${cy} m ${-r}, 0 a ${r}, ${r}, 0, 1, 0, ${r * 2}, 0 a ${r}, ${r}, 0, 1, 0 ${-r * 2}, 0`;\n}\n"],"names":[],"version":3,"file":"useColorWheel.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA+BM,SAAS,0CAAc,KAA4B,EAAE,KAAsB,EAAE,QA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YACE,MAAM;YACN,KAAK,OAAO;YACZ,KAAK,OAAO;YACZ,MAAM,OAAO;YACb,kBAAkB,GAAG,MAAM,KAAK,CAAC,kBAAkB,CAAC,OAAO,QAAQ,EAAE,EAAE,MAAM,KAAK,CAAC,UAAU,CAAC,SAAS;YACvG,UAAU;YACV,OAAO,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,QAAQ;kBAC9C;kBACA;YACA,UAAU,CAAC;gBACT,MAAM,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,KAAK;YACxC;YACA,OAAO,oBAAoB,KAAK;YAChC,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,oBAAoB,KAAK,CAAC,mBAAmB;YAC7C,gBAAgB,KAAK,CAAC,eAAe;QACvC;IAEJ;AACF;AAEA,2CAA2C;AAC3C,SAAS,iCAAW,EAAU,EAAE,EAAU,EAAE,CAAS;IACnD,OAAO,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC;AAC1G","sources":["packages/@react-aria/color/src/useColorWheel.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {AriaColorWheelProps} from '@react-types/color';\nimport {ColorWheelState} from '@react-stately/color';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, mergeProps, useFormReset, useGlobalListeners, useLabels} from '@react-aria/utils';\nimport React, {ChangeEvent, InputHTMLAttributes, useCallback, useRef} from 'react';\nimport {useKeyboard, useMove} from '@react-aria/interactions';\nimport {useLocale} from '@react-aria/i18n';\nimport {useVisuallyHidden} from '@react-aria/visually-hidden';\n\nexport interface AriaColorWheelOptions extends AriaColorWheelProps {\n /** The outer radius of the color wheel. */\n outerRadius: number,\n /** The inner radius of the color wheel. */\n innerRadius: number\n}\n\nexport interface ColorWheelAria {\n /** Props for the track element. */\n trackProps: DOMAttributes,\n /** Props for the thumb element. */\n thumbProps: DOMAttributes,\n /** Props for the visually hidden range input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a color wheel component.\n * Color wheels allow users to adjust the hue of an HSL or HSB color value on a circular track.\n */\nexport function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelState, inputRef: RefObject<HTMLInputElement | null>): ColorWheelAria {\n let {\n isDisabled,\n innerRadius,\n outerRadius,\n 'aria-label': ariaLabel,\n name,\n form\n } = props;\n\n let {addGlobalListener, removeGlobalListener} = useGlobalListeners();\n\n let thumbRadius = (innerRadius + outerRadius) / 2;\n\n let focusInput = useCallback(() => {\n if (inputRef.current) {\n focusWithoutScrolling(inputRef.current);\n }\n }, [inputRef]);\n\n useFormReset(inputRef, state.defaultValue, state.setValue);\n\n let currentPosition = useRef<{x: number, y: number} | null>(null);\n\n let {keyboardProps} = useKeyboard({\n onKeyDown(e) {\n // these are the cases that useMove doesn't handle\n if (!/^(PageUp|PageDown)$/.test(e.key)) {\n e.continuePropagation();\n return;\n }\n // same handling as useMove, don't need to stop propagation, useKeyboard will do that for us\n e.preventDefault();\n // remember to set this and unset it so that onChangeEnd is fired\n state.setDragging(true);\n switch (e.key) {\n case 'PageUp':\n e.preventDefault();\n state.increment(state.pageStep);\n break;\n case 'PageDown':\n e.preventDefault();\n state.decrement(state.pageStep);\n break;\n }\n state.setDragging(false);\n }\n });\n\n let moveHandler = {\n onMoveStart() {\n currentPosition.current = null;\n state.setDragging(true);\n },\n onMove({deltaX, deltaY, pointerType, shiftKey}) {\n if (currentPosition.current == null) {\n currentPosition.current = state.getThumbPosition(thumbRadius);\n }\n currentPosition.current.x += deltaX;\n currentPosition.current.y += deltaY;\n if (pointerType === 'keyboard') {\n if (deltaX > 0 || deltaY < 0) {\n state.increment(shiftKey ? state.pageStep : state.step);\n } else if (deltaX < 0 || deltaY > 0) {\n state.decrement(shiftKey ? state.pageStep : state.step);\n }\n } else {\n state.setHueFromPoint(currentPosition.current.x, currentPosition.current.y, thumbRadius);\n }\n },\n onMoveEnd() {\n isOnTrack.current = false;\n state.setDragging(false);\n focusInput();\n }\n };\n let {moveProps: movePropsThumb} = useMove(moveHandler);\n\n let currentPointer = useRef<number | null | undefined>(undefined);\n let isOnTrack = useRef<boolean>(false);\n let {moveProps: movePropsContainer} = useMove({\n onMoveStart() {\n if (isOnTrack.current) {\n moveHandler.onMoveStart();\n }\n },\n onMove(e) {\n if (isOnTrack.current) {\n moveHandler.onMove(e);\n }\n },\n onMoveEnd() {\n if (isOnTrack.current) {\n moveHandler.onMoveEnd();\n }\n }\n });\n\n let onThumbDown = (id: number | null | undefined) => {\n if (!state.isDragging) {\n currentPointer.current = id;\n focusInput();\n state.setDragging(true);\n\n if (typeof PointerEvent !== 'undefined') {\n addGlobalListener(window, 'pointerup', onThumbUp, false);\n } else {\n addGlobalListener(window, 'mouseup', onThumbUp, false);\n addGlobalListener(window, 'touchend', onThumbUp, false);\n }\n }\n };\n\n let onThumbUp = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (id === currentPointer.current) {\n focusInput();\n state.setDragging(false);\n currentPointer.current = undefined;\n isOnTrack.current = false;\n\n if (typeof PointerEvent !== 'undefined') {\n removeGlobalListener(window, 'pointerup', onThumbUp, false);\n } else {\n removeGlobalListener(window, 'mouseup', onThumbUp, false);\n removeGlobalListener(window, 'touchend', onThumbUp, false);\n }\n }\n };\n\n let onTrackDown = (track: Element, id: number | null | undefined, pageX: number, pageY: number) => {\n let rect = track.getBoundingClientRect();\n let x = pageX - rect.x - rect.width / 2;\n let y = pageY - rect.y - rect.height / 2;\n let radius = Math.sqrt(x * x + y * y);\n if (innerRadius < radius && radius < outerRadius && !state.isDragging && currentPointer.current === undefined) {\n isOnTrack.current = true;\n currentPointer.current = id;\n state.setHueFromPoint(x, y, radius);\n\n focusInput();\n state.setDragging(true);\n\n if (typeof PointerEvent !== 'undefined') {\n addGlobalListener(window, 'pointerup', onTrackUp, false);\n } else {\n addGlobalListener(window, 'mouseup', onTrackUp, false);\n addGlobalListener(window, 'touchend', onTrackUp, false);\n }\n }\n };\n\n let onTrackUp = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (isOnTrack.current && id === currentPointer.current) {\n isOnTrack.current = false;\n currentPointer.current = undefined;\n state.setDragging(false);\n focusInput();\n\n\n if (typeof PointerEvent !== 'undefined') {\n removeGlobalListener(window, 'pointerup', onTrackUp, false);\n } else {\n removeGlobalListener(window, 'mouseup', onTrackUp, false);\n removeGlobalListener(window, 'touchend', onTrackUp, false);\n }\n }\n };\n\n let trackInteractions = isDisabled ? {} : mergeProps({\n ...(typeof PointerEvent !== 'undefined' ? {\n onPointerDown: (e: React.PointerEvent) => {\n if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) {\n return;\n }\n onTrackDown(e.currentTarget, e.pointerId, e.clientX, e.clientY);\n }} : {\n onMouseDown: (e: React.MouseEvent) => {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onTrackDown(e.currentTarget, undefined, e.clientX, e.clientY);\n },\n onTouchStart: (e: React.TouchEvent) => {\n onTrackDown(e.currentTarget, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);\n }\n })\n }, movePropsContainer);\n\n let thumbInteractions = isDisabled ? {} : mergeProps({\n onMouseDown: (e: React.MouseEvent) => {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onThumbDown(undefined);\n },\n onPointerDown: (e: React.PointerEvent) => {\n if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) {\n return;\n }\n onThumbDown(e.pointerId);\n },\n onTouchStart: (e: React.TouchEvent) => {\n onThumbDown(e.changedTouches[0].identifier);\n }\n }, keyboardProps, movePropsThumb);\n let {x, y} = state.getThumbPosition(thumbRadius);\n\n // Provide a default aria-label if none is given\n let {locale} = useLocale();\n if (ariaLabel == null && props['aria-labelledby'] == null) {\n ariaLabel = state.value.getChannelName('hue', locale);\n }\n\n let inputLabellingProps = useLabels({\n ...props,\n 'aria-label': ariaLabel\n });\n\n let {minValue, maxValue, step} = state.value.getChannelRange('hue');\n\n let forcedColorAdjustNoneStyle = {\n forcedColorAdjust: 'none'\n };\n\n let {visuallyHiddenProps} = useVisuallyHidden({\n style: {\n opacity: '0.0001',\n width: '100%',\n height: '100%',\n pointerEvents: 'none'\n }\n });\n\n return {\n trackProps: {\n ...trackInteractions,\n style: {\n position: 'relative',\n touchAction: 'none',\n width: outerRadius * 2,\n height: outerRadius * 2,\n background: `\n conic-gradient(\n from 90deg,\n hsl(0, 100%, 50%),\n hsl(30, 100%, 50%),\n hsl(60, 100%, 50%),\n hsl(90, 100%, 50%),\n hsl(120, 100%, 50%),\n hsl(150, 100%, 50%),\n hsl(180, 100%, 50%),\n hsl(210, 100%, 50%),\n hsl(240, 100%, 50%),\n hsl(270, 100%, 50%),\n hsl(300, 100%, 50%),\n hsl(330, 100%, 50%),\n hsl(360, 100%, 50%)\n )\n `,\n clipPath: `path(evenodd, \"${circlePath(outerRadius, outerRadius, outerRadius)} ${circlePath(outerRadius, outerRadius, innerRadius)}\")`,\n ...forcedColorAdjustNoneStyle\n }\n },\n thumbProps: {\n ...thumbInteractions,\n style: {\n position: 'absolute',\n left: (outerRadius + x).toFixed(3) + 'px',\n top: (outerRadius + y).toFixed(3) + 'px',\n transform: 'translate(-50%, -50%)',\n touchAction: 'none',\n ...forcedColorAdjustNoneStyle\n }\n },\n inputProps: mergeProps(\n inputLabellingProps,\n {\n type: 'range',\n min: String(minValue),\n max: String(maxValue),\n step: String(step),\n 'aria-valuetext': `${state.value.formatChannelValue('hue', locale)}, ${state.value.getHueName(locale)}`,\n disabled: isDisabled,\n value: `${state.value.getChannelValue('hue')}`,\n name,\n form,\n onChange: (e: ChangeEvent<HTMLInputElement>) => {\n state.setHue(parseFloat(e.target.value));\n },\n style: visuallyHiddenProps.style,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-describedby': props['aria-describedby'],\n 'aria-details': props['aria-details']\n }\n )\n };\n}\n\n// Creates an SVG path string for a circle.\nfunction circlePath(cx: number, cy: number, r: number) {\n return `M ${cx}, ${cy} m ${-r}, 0 a ${r}, ${r}, 0, 1, 0, ${r * 2}, 0 a ${r}, ${r}, 0, 1, 0 ${-r * 2}, 0`;\n}\n"],"names":[],"version":3,"file":"useColorWheel.main.js.map"}
|
package/dist/useColorWheel.mjs
CHANGED
|
@@ -233,8 +233,8 @@ function $b4a0a4fdc900495e$export$9064ff4e44b3729a(props, state, inputRef) {
|
|
|
233
233
|
...thumbInteractions,
|
|
234
234
|
style: {
|
|
235
235
|
position: 'absolute',
|
|
236
|
-
left: outerRadius + x,
|
|
237
|
-
top: outerRadius + y,
|
|
236
|
+
left: (outerRadius + x).toFixed(3) + 'px',
|
|
237
|
+
top: (outerRadius + y).toFixed(3) + 'px',
|
|
238
238
|
transform: 'translate(-50%, -50%)',
|
|
239
239
|
touchAction: 'none',
|
|
240
240
|
...forcedColorAdjustNoneStyle
|
|
@@ -233,8 +233,8 @@ function $b4a0a4fdc900495e$export$9064ff4e44b3729a(props, state, inputRef) {
|
|
|
233
233
|
...thumbInteractions,
|
|
234
234
|
style: {
|
|
235
235
|
position: 'absolute',
|
|
236
|
-
left: outerRadius + x,
|
|
237
|
-
top: outerRadius + y,
|
|
236
|
+
left: (outerRadius + x).toFixed(3) + 'px',
|
|
237
|
+
top: (outerRadius + y).toFixed(3) + 'px',
|
|
238
238
|
transform: 'translate(-50%, -50%)',
|
|
239
239
|
touchAction: 'none',
|
|
240
240
|
...forcedColorAdjustNoneStyle
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA+BM,SAAS,0CAAc,KAA4B,EAAE,KAAsB,EAAE,QAA4C;IAC9H,IAAI,cACF,UAAU,eACV,WAAW,eACX,WAAW,EACX,cAAc,SAAS,QACvB,IAAI,QACJ,IAAI,EACL,GAAG;IAEJ,IAAI,qBAAC,iBAAiB,wBAAE,oBAAoB,EAAC,GAAG,CAAA,GAAA,yBAAiB;IAEjE,IAAI,cAAc,AAAC,CAAA,cAAc,WAAU,IAAK;IAEhD,IAAI,aAAa,CAAA,GAAA,kBAAU,EAAE;QAC3B,IAAI,SAAS,OAAO,EAClB,CAAA,GAAA,4BAAoB,EAAE,SAAS,OAAO;IAE1C,GAAG;QAAC;KAAS;IAEb,CAAA,GAAA,mBAAW,EAAE,UAAU,MAAM,YAAY,EAAE,MAAM,QAAQ;IAEzD,IAAI,kBAAkB,CAAA,GAAA,aAAK,EAAiC;IAE5D,IAAI,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,kBAAU,EAAE;QAChC,WAAU,CAAC;YACT,kDAAkD;YAClD,IAAI,CAAC,sBAAsB,IAAI,CAAC,EAAE,GAAG,GAAG;gBACtC,EAAE,mBAAmB;gBACrB;YACF;YACA,4FAA4F;YAC5F,EAAE,cAAc;YAChB,iEAAiE;YACjE,MAAM,WAAW,CAAC;YAClB,OAAQ,EAAE,GAAG;gBACX,KAAK;oBACH,EAAE,cAAc;oBAChB,MAAM,SAAS,CAAC,MAAM,QAAQ;oBAC9B;gBACF,KAAK;oBACH,EAAE,cAAc;oBAChB,MAAM,SAAS,CAAC,MAAM,QAAQ;oBAC9B;YACJ;YACA,MAAM,WAAW,CAAC;QACpB;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,YAAY;YACV,GAAG,iBAAiB;YACpB,OAAO;gBACL,UAAU;gBACV,MAAM,cAAc;gBACpB,KAAK,cAAc;gBACnB,WAAW;gBACX,aAAa;gBACb,GAAG,0BAA0B;YAC/B;QACF;QACA,YAAY,CAAA,GAAA,iBAAS,EACnB,qBACA;YACE,MAAM;YACN,KAAK,OAAO;YACZ,KAAK,OAAO;YACZ,MAAM,OAAO;YACb,kBAAkB,GAAG,MAAM,KAAK,CAAC,kBAAkB,CAAC,OAAO,QAAQ,EAAE,EAAE,MAAM,KAAK,CAAC,UAAU,CAAC,SAAS;YACvG,UAAU;YACV,OAAO,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,QAAQ;kBAC9C;kBACA;YACA,UAAU,CAAC;gBACT,MAAM,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,KAAK;YACxC;YACA,OAAO,oBAAoB,KAAK;YAChC,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,oBAAoB,KAAK,CAAC,mBAAmB;YAC7C,gBAAgB,KAAK,CAAC,eAAe;QACvC;IAEJ;AACF;AAEA,2CAA2C;AAC3C,SAAS,iCAAW,EAAU,EAAE,EAAU,EAAE,CAAS;IACnD,OAAO,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC;AAC1G","sources":["packages/@react-aria/color/src/useColorWheel.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {AriaColorWheelProps} from '@react-types/color';\nimport {ColorWheelState} from '@react-stately/color';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, mergeProps, useFormReset, useGlobalListeners, useLabels} from '@react-aria/utils';\nimport React, {ChangeEvent, InputHTMLAttributes, useCallback, useRef} from 'react';\nimport {useKeyboard, useMove} from '@react-aria/interactions';\nimport {useLocale} from '@react-aria/i18n';\nimport {useVisuallyHidden} from '@react-aria/visually-hidden';\n\nexport interface AriaColorWheelOptions extends AriaColorWheelProps {\n /** The outer radius of the color wheel. */\n outerRadius: number,\n /** The inner radius of the color wheel. */\n innerRadius: number\n}\n\nexport interface ColorWheelAria {\n /** Props for the track element. */\n trackProps: DOMAttributes,\n /** Props for the thumb element. */\n thumbProps: DOMAttributes,\n /** Props for the visually hidden range input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a color wheel component.\n * Color wheels allow users to adjust the hue of an HSL or HSB color value on a circular track.\n */\nexport function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelState, inputRef: RefObject<HTMLInputElement | null>): ColorWheelAria {\n let {\n isDisabled,\n innerRadius,\n outerRadius,\n 'aria-label': ariaLabel,\n name,\n form\n } = props;\n\n let {addGlobalListener, removeGlobalListener} = useGlobalListeners();\n\n let thumbRadius = (innerRadius + outerRadius) / 2;\n\n let focusInput = useCallback(() => {\n if (inputRef.current) {\n focusWithoutScrolling(inputRef.current);\n }\n }, [inputRef]);\n\n useFormReset(inputRef, state.defaultValue, state.setValue);\n\n let currentPosition = useRef<{x: number, y: number} | null>(null);\n\n let {keyboardProps} = useKeyboard({\n onKeyDown(e) {\n // these are the cases that useMove doesn't handle\n if (!/^(PageUp|PageDown)$/.test(e.key)) {\n e.continuePropagation();\n return;\n }\n // same handling as useMove, don't need to stop propagation, useKeyboard will do that for us\n e.preventDefault();\n // remember to set this and unset it so that onChangeEnd is fired\n state.setDragging(true);\n switch (e.key) {\n case 'PageUp':\n e.preventDefault();\n state.increment(state.pageStep);\n break;\n case 'PageDown':\n e.preventDefault();\n state.decrement(state.pageStep);\n break;\n }\n state.setDragging(false);\n }\n });\n\n let moveHandler = {\n onMoveStart() {\n currentPosition.current = null;\n state.setDragging(true);\n },\n onMove({deltaX, deltaY, pointerType, shiftKey}) {\n if (currentPosition.current == null) {\n currentPosition.current = state.getThumbPosition(thumbRadius);\n }\n currentPosition.current.x += deltaX;\n currentPosition.current.y += deltaY;\n if (pointerType === 'keyboard') {\n if (deltaX > 0 || deltaY < 0) {\n state.increment(shiftKey ? state.pageStep : state.step);\n } else if (deltaX < 0 || deltaY > 0) {\n state.decrement(shiftKey ? state.pageStep : state.step);\n }\n } else {\n state.setHueFromPoint(currentPosition.current.x, currentPosition.current.y, thumbRadius);\n }\n },\n onMoveEnd() {\n isOnTrack.current = false;\n state.setDragging(false);\n focusInput();\n }\n };\n let {moveProps: movePropsThumb} = useMove(moveHandler);\n\n let currentPointer = useRef<number | null | undefined>(undefined);\n let isOnTrack = useRef<boolean>(false);\n let {moveProps: movePropsContainer} = useMove({\n onMoveStart() {\n if (isOnTrack.current) {\n moveHandler.onMoveStart();\n }\n },\n onMove(e) {\n if (isOnTrack.current) {\n moveHandler.onMove(e);\n }\n },\n onMoveEnd() {\n if (isOnTrack.current) {\n moveHandler.onMoveEnd();\n }\n }\n });\n\n let onThumbDown = (id: number | null | undefined) => {\n if (!state.isDragging) {\n currentPointer.current = id;\n focusInput();\n state.setDragging(true);\n\n if (typeof PointerEvent !== 'undefined') {\n addGlobalListener(window, 'pointerup', onThumbUp, false);\n } else {\n addGlobalListener(window, 'mouseup', onThumbUp, false);\n addGlobalListener(window, 'touchend', onThumbUp, false);\n }\n }\n };\n\n let onThumbUp = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (id === currentPointer.current) {\n focusInput();\n state.setDragging(false);\n currentPointer.current = undefined;\n isOnTrack.current = false;\n\n if (typeof PointerEvent !== 'undefined') {\n removeGlobalListener(window, 'pointerup', onThumbUp, false);\n } else {\n removeGlobalListener(window, 'mouseup', onThumbUp, false);\n removeGlobalListener(window, 'touchend', onThumbUp, false);\n }\n }\n };\n\n let onTrackDown = (track: Element, id: number | null | undefined, pageX: number, pageY: number) => {\n let rect = track.getBoundingClientRect();\n let x = pageX - rect.x - rect.width / 2;\n let y = pageY - rect.y - rect.height / 2;\n let radius = Math.sqrt(x * x + y * y);\n if (innerRadius < radius && radius < outerRadius && !state.isDragging && currentPointer.current === undefined) {\n isOnTrack.current = true;\n currentPointer.current = id;\n state.setHueFromPoint(x, y, radius);\n\n focusInput();\n state.setDragging(true);\n\n if (typeof PointerEvent !== 'undefined') {\n addGlobalListener(window, 'pointerup', onTrackUp, false);\n } else {\n addGlobalListener(window, 'mouseup', onTrackUp, false);\n addGlobalListener(window, 'touchend', onTrackUp, false);\n }\n }\n };\n\n let onTrackUp = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (isOnTrack.current && id === currentPointer.current) {\n isOnTrack.current = false;\n currentPointer.current = undefined;\n state.setDragging(false);\n focusInput();\n\n\n if (typeof PointerEvent !== 'undefined') {\n removeGlobalListener(window, 'pointerup', onTrackUp, false);\n } else {\n removeGlobalListener(window, 'mouseup', onTrackUp, false);\n removeGlobalListener(window, 'touchend', onTrackUp, false);\n }\n }\n };\n\n let trackInteractions = isDisabled ? {} : mergeProps({\n ...(typeof PointerEvent !== 'undefined' ? {\n onPointerDown: (e: React.PointerEvent) => {\n if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) {\n return;\n }\n onTrackDown(e.currentTarget, e.pointerId, e.clientX, e.clientY);\n }} : {\n onMouseDown: (e: React.MouseEvent) => {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onTrackDown(e.currentTarget, undefined, e.clientX, e.clientY);\n },\n onTouchStart: (e: React.TouchEvent) => {\n onTrackDown(e.currentTarget, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);\n }\n })\n }, movePropsContainer);\n\n let thumbInteractions = isDisabled ? {} : mergeProps({\n onMouseDown: (e: React.MouseEvent) => {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onThumbDown(undefined);\n },\n onPointerDown: (e: React.PointerEvent) => {\n if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) {\n return;\n }\n onThumbDown(e.pointerId);\n },\n onTouchStart: (e: React.TouchEvent) => {\n onThumbDown(e.changedTouches[0].identifier);\n }\n }, keyboardProps, movePropsThumb);\n let {x, y} = state.getThumbPosition(thumbRadius);\n\n // Provide a default aria-label if none is given\n let {locale} = useLocale();\n if (ariaLabel == null && props['aria-labelledby'] == null) {\n ariaLabel = state.value.getChannelName('hue', locale);\n }\n\n let inputLabellingProps = useLabels({\n ...props,\n 'aria-label': ariaLabel\n });\n\n let {minValue, maxValue, step} = state.value.getChannelRange('hue');\n\n let forcedColorAdjustNoneStyle = {\n forcedColorAdjust: 'none'\n };\n\n let {visuallyHiddenProps} = useVisuallyHidden({\n style: {\n opacity: '0.0001',\n width: '100%',\n height: '100%',\n pointerEvents: 'none'\n }\n });\n\n return {\n trackProps: {\n ...trackInteractions,\n style: {\n position: 'relative',\n touchAction: 'none',\n width: outerRadius * 2,\n height: outerRadius * 2,\n background: `\n conic-gradient(\n from 90deg,\n hsl(0, 100%, 50%),\n hsl(30, 100%, 50%),\n hsl(60, 100%, 50%),\n hsl(90, 100%, 50%),\n hsl(120, 100%, 50%),\n hsl(150, 100%, 50%),\n hsl(180, 100%, 50%),\n hsl(210, 100%, 50%),\n hsl(240, 100%, 50%),\n hsl(270, 100%, 50%),\n hsl(300, 100%, 50%),\n hsl(330, 100%, 50%),\n hsl(360, 100%, 50%)\n )\n `,\n clipPath: `path(evenodd, \"${circlePath(outerRadius, outerRadius, outerRadius)} ${circlePath(outerRadius, outerRadius, innerRadius)}\")`,\n ...forcedColorAdjustNoneStyle\n }\n },\n thumbProps: {\n ...thumbInteractions,\n style: {\n position: 'absolute',\n left: outerRadius + x,\n top: outerRadius + y,\n transform: 'translate(-50%, -50%)',\n touchAction: 'none',\n ...forcedColorAdjustNoneStyle\n }\n },\n inputProps: mergeProps(\n inputLabellingProps,\n {\n type: 'range',\n min: String(minValue),\n max: String(maxValue),\n step: String(step),\n 'aria-valuetext': `${state.value.formatChannelValue('hue', locale)}, ${state.value.getHueName(locale)}`,\n disabled: isDisabled,\n value: `${state.value.getChannelValue('hue')}`,\n name,\n form,\n onChange: (e: ChangeEvent<HTMLInputElement>) => {\n state.setHue(parseFloat(e.target.value));\n },\n style: visuallyHiddenProps.style,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-describedby': props['aria-describedby'],\n 'aria-details': props['aria-details']\n }\n )\n };\n}\n\n// Creates an SVG path string for a circle.\nfunction circlePath(cx: number, cy: number, r: number) {\n return `M ${cx}, ${cy} m ${-r}, 0 a ${r}, ${r}, 0, 1, 0, ${r * 2}, 0 a ${r}, ${r}, 0, 1, 0 ${-r * 2}, 0`;\n}\n"],"names":[],"version":3,"file":"useColorWheel.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA+BM,SAAS,0CAAc,KAA4B,EAAE,KAAsB,EAAE,QAA4C;IAC9H,IAAI,cACF,UAAU,eACV,WAAW,eACX,WAAW,EACX,cAAc,SAAS,QACvB,IAAI,QACJ,IAAI,EACL,GAAG;IAEJ,IAAI,qBAAC,iBAAiB,wBAAE,oBAAoB,EAAC,GAAG,CAAA,GAAA,yBAAiB;IAEjE,IAAI,cAAc,AAAC,CAAA,cAAc,WAAU,IAAK;IAEhD,IAAI,aAAa,CAAA,GAAA,kBAAU,EAAE;QAC3B,IAAI,SAAS,OAAO,EAClB,CAAA,GAAA,4BAAoB,EAAE,SAAS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AO,oBAAoB,KAAK;YAChC,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,oBAAoB,KAAK,CAAC,mBAAmB;YAC7C,gBAAgB,KAAK,CAAC,eAAe;QACvC;IAEJ;AACF;AAEA,2CAA2C;AAC3C,SAAS,iCAAW,EAAU,EAAE,EAAU,EAAE,CAAS;IACnD,OAAO,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC;AAC1G","sources":["packages/@react-aria/color/src/useColorWheel.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {AriaColorWheelProps} from '@react-types/color';\nimport {ColorWheelState} from '@react-stately/color';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, mergeProps, useFormReset, useGlobalListeners, useLabels} from '@react-aria/utils';\nimport React, {ChangeEvent, InputHTMLAttributes, useCallback, useRef} from 'react';\nimport {useKeyboard, useMove} from '@react-aria/interactions';\nimport {useLocale} from '@react-aria/i18n';\nimport {useVisuallyHidden} from '@react-aria/visually-hidden';\n\nexport interface AriaColorWheelOptions extends AriaColorWheelProps {\n /** The outer radius of the color wheel. */\n outerRadius: number,\n /** The inner radius of the color wheel. */\n innerRadius: number\n}\n\nexport interface ColorWheelAria {\n /** Props for the track element. */\n trackProps: DOMAttributes,\n /** Props for the thumb element. */\n thumbProps: DOMAttributes,\n /** Props for the visually hidden range input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a color wheel component.\n * Color wheels allow users to adjust the hue of an HSL or HSB color value on a circular track.\n */\nexport function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelState, inputRef: RefObject<HTMLInputElement | null>): ColorWheelAria {\n let {\n isDisabled,\n innerRadius,\n outerRadius,\n 'aria-label': ariaLabel,\n name,\n form\n } = props;\n\n let {addGlobalListener, removeGlobalListener} = useGlobalListeners();\n\n let thumbRadius = (innerRadius + outerRadius) / 2;\n\n let focusInput = useCallback(() => {\n if (inputRef.current) {\n focusWithoutScrolling(inputRef.current);\n }\n }, [inputRef]);\n\n useFormReset(inputRef, state.defaultValue, state.setValue);\n\n let currentPosition = useRef<{x: number, y: number} | null>(null);\n\n let {keyboardProps} = useKeyboard({\n onKeyDown(e) {\n // these are the cases that useMove doesn't handle\n if (!/^(PageUp|PageDown)$/.test(e.key)) {\n e.continuePropagation();\n return;\n }\n // same handling as useMove, don't need to stop propagation, useKeyboard will do that for us\n e.preventDefault();\n // remember to set this and unset it so that onChangeEnd is fired\n state.setDragging(true);\n switch (e.key) {\n case 'PageUp':\n e.preventDefault();\n state.increment(state.pageStep);\n break;\n case 'PageDown':\n e.preventDefault();\n state.decrement(state.pageStep);\n break;\n }\n state.setDragging(false);\n }\n });\n\n let moveHandler = {\n onMoveStart() {\n currentPosition.current = null;\n state.setDragging(true);\n },\n onMove({deltaX, deltaY, pointerType, shiftKey}) {\n if (currentPosition.current == null) {\n currentPosition.current = state.getThumbPosition(thumbRadius);\n }\n currentPosition.current.x += deltaX;\n currentPosition.current.y += deltaY;\n if (pointerType === 'keyboard') {\n if (deltaX > 0 || deltaY < 0) {\n state.increment(shiftKey ? state.pageStep : state.step);\n } else if (deltaX < 0 || deltaY > 0) {\n state.decrement(shiftKey ? state.pageStep : state.step);\n }\n } else {\n state.setHueFromPoint(currentPosition.current.x, currentPosition.current.y, thumbRadius);\n }\n },\n onMoveEnd() {\n isOnTrack.current = false;\n state.setDragging(false);\n focusInput();\n }\n };\n let {moveProps: movePropsThumb} = useMove(moveHandler);\n\n let currentPointer = useRef<number | null | undefined>(undefined);\n let isOnTrack = useRef<boolean>(false);\n let {moveProps: movePropsContainer} = useMove({\n onMoveStart() {\n if (isOnTrack.current) {\n moveHandler.onMoveStart();\n }\n },\n onMove(e) {\n if (isOnTrack.current) {\n moveHandler.onMove(e);\n }\n },\n onMoveEnd() {\n if (isOnTrack.current) {\n moveHandler.onMoveEnd();\n }\n }\n });\n\n let onThumbDown = (id: number | null | undefined) => {\n if (!state.isDragging) {\n currentPointer.current = id;\n focusInput();\n state.setDragging(true);\n\n if (typeof PointerEvent !== 'undefined') {\n addGlobalListener(window, 'pointerup', onThumbUp, false);\n } else {\n addGlobalListener(window, 'mouseup', onThumbUp, false);\n addGlobalListener(window, 'touchend', onThumbUp, false);\n }\n }\n };\n\n let onThumbUp = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (id === currentPointer.current) {\n focusInput();\n state.setDragging(false);\n currentPointer.current = undefined;\n isOnTrack.current = false;\n\n if (typeof PointerEvent !== 'undefined') {\n removeGlobalListener(window, 'pointerup', onThumbUp, false);\n } else {\n removeGlobalListener(window, 'mouseup', onThumbUp, false);\n removeGlobalListener(window, 'touchend', onThumbUp, false);\n }\n }\n };\n\n let onTrackDown = (track: Element, id: number | null | undefined, pageX: number, pageY: number) => {\n let rect = track.getBoundingClientRect();\n let x = pageX - rect.x - rect.width / 2;\n let y = pageY - rect.y - rect.height / 2;\n let radius = Math.sqrt(x * x + y * y);\n if (innerRadius < radius && radius < outerRadius && !state.isDragging && currentPointer.current === undefined) {\n isOnTrack.current = true;\n currentPointer.current = id;\n state.setHueFromPoint(x, y, radius);\n\n focusInput();\n state.setDragging(true);\n\n if (typeof PointerEvent !== 'undefined') {\n addGlobalListener(window, 'pointerup', onTrackUp, false);\n } else {\n addGlobalListener(window, 'mouseup', onTrackUp, false);\n addGlobalListener(window, 'touchend', onTrackUp, false);\n }\n }\n };\n\n let onTrackUp = (e) => {\n let id = e.pointerId ?? e.changedTouches?.[0].identifier;\n if (isOnTrack.current && id === currentPointer.current) {\n isOnTrack.current = false;\n currentPointer.current = undefined;\n state.setDragging(false);\n focusInput();\n\n\n if (typeof PointerEvent !== 'undefined') {\n removeGlobalListener(window, 'pointerup', onTrackUp, false);\n } else {\n removeGlobalListener(window, 'mouseup', onTrackUp, false);\n removeGlobalListener(window, 'touchend', onTrackUp, false);\n }\n }\n };\n\n let trackInteractions = isDisabled ? {} : mergeProps({\n ...(typeof PointerEvent !== 'undefined' ? {\n onPointerDown: (e: React.PointerEvent) => {\n if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) {\n return;\n }\n onTrackDown(e.currentTarget, e.pointerId, e.clientX, e.clientY);\n }} : {\n onMouseDown: (e: React.MouseEvent) => {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onTrackDown(e.currentTarget, undefined, e.clientX, e.clientY);\n },\n onTouchStart: (e: React.TouchEvent) => {\n onTrackDown(e.currentTarget, e.changedTouches[0].identifier, e.changedTouches[0].clientX, e.changedTouches[0].clientY);\n }\n })\n }, movePropsContainer);\n\n let thumbInteractions = isDisabled ? {} : mergeProps({\n onMouseDown: (e: React.MouseEvent) => {\n if (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey) {\n return;\n }\n onThumbDown(undefined);\n },\n onPointerDown: (e: React.PointerEvent) => {\n if (e.pointerType === 'mouse' && (e.button !== 0 || e.altKey || e.ctrlKey || e.metaKey)) {\n return;\n }\n onThumbDown(e.pointerId);\n },\n onTouchStart: (e: React.TouchEvent) => {\n onThumbDown(e.changedTouches[0].identifier);\n }\n }, keyboardProps, movePropsThumb);\n let {x, y} = state.getThumbPosition(thumbRadius);\n\n // Provide a default aria-label if none is given\n let {locale} = useLocale();\n if (ariaLabel == null && props['aria-labelledby'] == null) {\n ariaLabel = state.value.getChannelName('hue', locale);\n }\n\n let inputLabellingProps = useLabels({\n ...props,\n 'aria-label': ariaLabel\n });\n\n let {minValue, maxValue, step} = state.value.getChannelRange('hue');\n\n let forcedColorAdjustNoneStyle = {\n forcedColorAdjust: 'none'\n };\n\n let {visuallyHiddenProps} = useVisuallyHidden({\n style: {\n opacity: '0.0001',\n width: '100%',\n height: '100%',\n pointerEvents: 'none'\n }\n });\n\n return {\n trackProps: {\n ...trackInteractions,\n style: {\n position: 'relative',\n touchAction: 'none',\n width: outerRadius * 2,\n height: outerRadius * 2,\n background: `\n conic-gradient(\n from 90deg,\n hsl(0, 100%, 50%),\n hsl(30, 100%, 50%),\n hsl(60, 100%, 50%),\n hsl(90, 100%, 50%),\n hsl(120, 100%, 50%),\n hsl(150, 100%, 50%),\n hsl(180, 100%, 50%),\n hsl(210, 100%, 50%),\n hsl(240, 100%, 50%),\n hsl(270, 100%, 50%),\n hsl(300, 100%, 50%),\n hsl(330, 100%, 50%),\n hsl(360, 100%, 50%)\n )\n `,\n clipPath: `path(evenodd, \"${circlePath(outerRadius, outerRadius, outerRadius)} ${circlePath(outerRadius, outerRadius, innerRadius)}\")`,\n ...forcedColorAdjustNoneStyle\n }\n },\n thumbProps: {\n ...thumbInteractions,\n style: {\n position: 'absolute',\n left: (outerRadius + x).toFixed(3) + 'px',\n top: (outerRadius + y).toFixed(3) + 'px',\n transform: 'translate(-50%, -50%)',\n touchAction: 'none',\n ...forcedColorAdjustNoneStyle\n }\n },\n inputProps: mergeProps(\n inputLabellingProps,\n {\n type: 'range',\n min: String(minValue),\n max: String(maxValue),\n step: String(step),\n 'aria-valuetext': `${state.value.formatChannelValue('hue', locale)}, ${state.value.getHueName(locale)}`,\n disabled: isDisabled,\n value: `${state.value.getChannelValue('hue')}`,\n name,\n form,\n onChange: (e: ChangeEvent<HTMLInputElement>) => {\n state.setHue(parseFloat(e.target.value));\n },\n style: visuallyHiddenProps.style,\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-describedby': props['aria-describedby'],\n 'aria-details': props['aria-details']\n }\n )\n };\n}\n\n// Creates an SVG path string for a circle.\nfunction circlePath(cx: number, cy: number, r: number) {\n return `M ${cx}, ${cy} m ${-r}, 0 a ${r}, ${r}, 0, 1, 0, ${r * 2}, 0 a ${r}, ${r}, 0, 1, 0 ${-r * 2}, 0`;\n}\n"],"names":[],"version":3,"file":"useColorWheel.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/color",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -26,18 +26,18 @@
|
|
|
26
26
|
"url": "https://github.com/adobe/react-spectrum"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@react-aria/i18n": "^3.12.
|
|
30
|
-
"@react-aria/interactions": "^3.25.
|
|
31
|
-
"@react-aria/numberfield": "^3.12.
|
|
32
|
-
"@react-aria/slider": "^3.8.
|
|
33
|
-
"@react-aria/spinbutton": "^3.6.
|
|
34
|
-
"@react-aria/textfield": "^3.18.
|
|
35
|
-
"@react-aria/utils": "^3.
|
|
36
|
-
"@react-aria/visually-hidden": "^3.8.
|
|
37
|
-
"@react-stately/color": "^3.9.
|
|
38
|
-
"@react-stately/form": "^3.2.
|
|
39
|
-
"@react-types/color": "^3.1.
|
|
40
|
-
"@react-types/shared": "^3.
|
|
29
|
+
"@react-aria/i18n": "^3.12.13",
|
|
30
|
+
"@react-aria/interactions": "^3.25.6",
|
|
31
|
+
"@react-aria/numberfield": "^3.12.2",
|
|
32
|
+
"@react-aria/slider": "^3.8.2",
|
|
33
|
+
"@react-aria/spinbutton": "^3.6.19",
|
|
34
|
+
"@react-aria/textfield": "^3.18.2",
|
|
35
|
+
"@react-aria/utils": "^3.31.0",
|
|
36
|
+
"@react-aria/visually-hidden": "^3.8.28",
|
|
37
|
+
"@react-stately/color": "^3.9.2",
|
|
38
|
+
"@react-stately/form": "^3.2.2",
|
|
39
|
+
"@react-types/color": "^3.1.2",
|
|
40
|
+
"@react-types/shared": "^3.32.1",
|
|
41
41
|
"@swc/helpers": "^0.5.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "0bda51183baa23306342af32a82012ea0fe0f2dc"
|
|
51
51
|
}
|
package/src/useColorWheel.ts
CHANGED
|
@@ -308,8 +308,8 @@ export function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelSta
|
|
|
308
308
|
...thumbInteractions,
|
|
309
309
|
style: {
|
|
310
310
|
position: 'absolute',
|
|
311
|
-
left: outerRadius + x,
|
|
312
|
-
top: outerRadius + y,
|
|
311
|
+
left: (outerRadius + x).toFixed(3) + 'px',
|
|
312
|
+
top: (outerRadius + y).toFixed(3) + 'px',
|
|
313
313
|
transform: 'translate(-50%, -50%)',
|
|
314
314
|
touchAction: 'none',
|
|
315
315
|
...forcedColorAdjustNoneStyle
|