@tomorrowevening/theatre-studio 1.0.5 → 1.0.6
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/dist/index.js +105 -56
- package/package.json +1 -1
- package/dist/IDBStorage.js +0 -19
- package/dist/PaneManager.js +0 -112
- package/dist/Scrub.js +0 -134
- package/dist/Studio.js +0 -405
- package/dist/StudioBundle.js +0 -21
- package/dist/StudioStore/StudioStore.js +0 -163
- package/dist/StudioStore/createTransactionPrivateApi.js +0 -204
- package/dist/StudioStore/generateDiskStateRevision.js +0 -4
- package/dist/StudioStore/persistStateOfStudio.js +0 -61
- package/dist/TheatreStudio.js +0 -154
- package/dist/UI/UI.js +0 -65
- package/dist/UI/UINonSSRBits.js +0 -60
- package/dist/UIRoot/PanelsRoot.js +0 -19
- package/dist/UIRoot/PointerCapturing.js +0 -96
- package/dist/UIRoot/ProvideTheme.js +0 -9
- package/dist/UIRoot/UIRoot.js +0 -79
- package/dist/UIRoot/useKeyboardShortcuts.js +0 -158
- package/dist/checkForUpdates.js +0 -86
- package/dist/css.js +0 -116
- package/dist/getStudio.js +0 -10
- package/dist/notify.js +0 -328
- package/dist/panels/BasePanel/BasePanel.js +0 -74
- package/dist/panels/BasePanel/ExtensionPaneWrapper.js +0 -138
- package/dist/panels/BasePanel/PanelDragZone.js +0 -88
- package/dist/panels/BasePanel/PanelResizeHandle.js +0 -184
- package/dist/panels/BasePanel/PanelResizers.js +0 -14
- package/dist/panels/BasePanel/PanelWrapper.js +0 -34
- package/dist/panels/BasePanel/common.js +0 -52
- package/dist/panels/DetailPanel/DetailPanel.js +0 -146
- package/dist/panels/DetailPanel/DeterminePropEditorForDetail/DetailCompoundPropEditor.js +0 -169
- package/dist/panels/DetailPanel/DeterminePropEditorForDetail/DetailSimplePropEditor.js +0 -22
- package/dist/panels/DetailPanel/DeterminePropEditorForDetail/SingleRowPropEditor.js +0 -89
- package/dist/panels/DetailPanel/DeterminePropEditorForDetail/getDetailRowHighlightBackground.js +0 -7
- package/dist/panels/DetailPanel/DeterminePropEditorForDetail/rowIndentationFormulaCSS.js +0 -1
- package/dist/panels/DetailPanel/DeterminePropEditorForDetail.js +0 -28
- package/dist/panels/DetailPanel/EmptyState.js +0 -36
- package/dist/panels/DetailPanel/ObjectDetails.js +0 -52
- package/dist/panels/DetailPanel/ProjectDetails/StateConflictRow.js +0 -86
- package/dist/panels/DetailPanel/ProjectDetails.js +0 -98
- package/dist/panels/OutlinePanel/BaseItem.js +0 -136
- package/dist/panels/OutlinePanel/ObjectsList/ObjectItem.js +0 -14
- package/dist/panels/OutlinePanel/ObjectsList/ObjectsList.js +0 -85
- package/dist/panels/OutlinePanel/OutlinePanel.js +0 -73
- package/dist/panels/OutlinePanel/ProjectsList/ProjectListItem.js +0 -38
- package/dist/panels/OutlinePanel/ProjectsList/ProjectsList.js +0 -22
- package/dist/panels/OutlinePanel/SheetsList/SheetInstanceItem.js +0 -36
- package/dist/panels/OutlinePanel/SheetsList/SheetItem.js +0 -23
- package/dist/panels/OutlinePanel/SheetsList/SheetsList.js +0 -15
- package/dist/panels/OutlinePanel/outlinePanelUtils.js +0 -23
- package/dist/panels/SequenceEditorPanel/DopeSheet/DopeSheet.js +0 -21
- package/dist/panels/SequenceEditorPanel/DopeSheet/Left/AnyCompositeRow.js +0 -74
- package/dist/panels/SequenceEditorPanel/DopeSheet/Left/Left.js +0 -25
- package/dist/panels/SequenceEditorPanel/DopeSheet/Left/PrimitivePropRow.js +0 -97
- package/dist/panels/SequenceEditorPanel/DopeSheet/Left/PropWithChildrenRow.js +0 -15
- package/dist/panels/SequenceEditorPanel/DopeSheet/Left/SheetObjectRow.js +0 -19
- package/dist/panels/SequenceEditorPanel/DopeSheet/Left/SheetRow.js +0 -20
- package/dist/panels/SequenceEditorPanel/DopeSheet/Left/usePropHighlightMouseEnter.js +0 -33
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/AggregatedKeyframeTrack/AggregateKeyframeEditor/AggregateKeyframeConnector.js +0 -187
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/AggregatedKeyframeTrack/AggregateKeyframeEditor/AggregateKeyframeDot.js +0 -158
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/AggregatedKeyframeTrack/AggregateKeyframeEditor/AggregateKeyframeEditor.js +0 -32
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/AggregatedKeyframeTrack/AggregateKeyframeEditor/AggregateKeyframeVisualDot.js +0 -61
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/AggregatedKeyframeTrack/AggregateKeyframeEditor/iif.js +0 -3
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/AggregatedKeyframeTrack/AggregateKeyframeEditor/useAggregateKeyframeEditorUtils.js +0 -73
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/AggregatedKeyframeTrack/AggregatedKeyframeTrack.js +0 -407
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/BasicKeyframedTrack.js +0 -108
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/BasicKeyframeConnector.js +0 -185
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/CurveEditorPopover/CurveEditorPopover.js +0 -397
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/CurveEditorPopover/CurveSegmentEditor.js +0 -136
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/CurveEditorPopover/EasingOption.js +0 -52
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/CurveEditorPopover/SVGCurveSegment.js +0 -43
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/CurveEditorPopover/colors.js +0 -3
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/CurveEditorPopover/shared.js +0 -84
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/CurveEditorPopover/useFreezableMemo.js +0 -16
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/CurveEditorPopover/useUIOptionGrid.js +0 -82
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/DeterminePropEditorForSingleKeyframe.js +0 -93
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/SingleKeyframeDot.js +0 -254
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/SingleKeyframeEditor.js +0 -22
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/useSingleKeyframeInlineEditorPopover.js +0 -11
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/useTempTransactionEditingTools.js +0 -43
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/DopeSheetBackground.js +0 -24
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/DopeSheetSelectionView.js +0 -272
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/FocusRangeCurtains.js +0 -88
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/HorizontallyScrollableArea.js +0 -215
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/KeyframeSnapTarget.js +0 -55
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/LengthIndicator/LengthEditorPopover.js +0 -69
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/LengthIndicator/LengthIndicator.js +0 -217
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/PrimitivePropRow.js +0 -25
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/PropWithChildrenRow.js +0 -18
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/Right.js +0 -30
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/Row.js +0 -50
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/SheetObjectRow.js +0 -14
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/SheetRow.js +0 -14
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/collectAggregateKeyframes.js +0 -92
- package/dist/panels/SequenceEditorPanel/DopeSheet/Right/keyframeRowUI/ConnectorLine.js +0 -62
- package/dist/panels/SequenceEditorPanel/DopeSheet/selections.js +0 -149
- package/dist/panels/SequenceEditorPanel/DopeSheet/setCollapsedSheetObjectOrCompoundProp.js +0 -10
- package/dist/panels/SequenceEditorPanel/FrameGrid/FrameGrid.js +0 -92
- package/dist/panels/SequenceEditorPanel/FrameGrid/StampsGrid.js +0 -99
- package/dist/panels/SequenceEditorPanel/FrameGrid/createGrid.js +0 -49
- package/dist/panels/SequenceEditorPanel/FrameStampPositionProvider.js +0 -189
- package/dist/panels/SequenceEditorPanel/GraphEditor/BasicKeyframedTrack/BasicKeyframedTrack.js +0 -91
- package/dist/panels/SequenceEditorPanel/GraphEditor/BasicKeyframedTrack/KeyframeEditor/Curve.js +0 -87
- package/dist/panels/SequenceEditorPanel/GraphEditor/BasicKeyframedTrack/KeyframeEditor/CurveHandle.js +0 -186
- package/dist/panels/SequenceEditorPanel/GraphEditor/BasicKeyframedTrack/KeyframeEditor/GraphEditorDotNonScalar.js +0 -162
- package/dist/panels/SequenceEditorPanel/GraphEditor/BasicKeyframedTrack/KeyframeEditor/GraphEditorDotScalar.js +0 -209
- package/dist/panels/SequenceEditorPanel/GraphEditor/BasicKeyframedTrack/KeyframeEditor/GraphEditorNonScalarDash.js +0 -23
- package/dist/panels/SequenceEditorPanel/GraphEditor/BasicKeyframedTrack/KeyframeEditor/KeyframeEditor.js +0 -30
- package/dist/panels/SequenceEditorPanel/GraphEditor/GraphEditor.js +0 -73
- package/dist/panels/SequenceEditorPanel/GraphEditor/PrimitivePropGraph.js +0 -20
- package/dist/panels/SequenceEditorPanel/GraphEditorToggle.js +0 -59
- package/dist/panels/SequenceEditorPanel/RightOverlay/DopeSnap.js +0 -36
- package/dist/panels/SequenceEditorPanel/RightOverlay/DopeSnapHitZoneUI.js +0 -57
- package/dist/panels/SequenceEditorPanel/RightOverlay/FocusRangeZone/FocusRangeStrip.js +0 -233
- package/dist/panels/SequenceEditorPanel/RightOverlay/FocusRangeZone/FocusRangeThumb.js +0 -217
- package/dist/panels/SequenceEditorPanel/RightOverlay/FocusRangeZone/FocusRangeZone.js +0 -181
- package/dist/panels/SequenceEditorPanel/RightOverlay/FrameStamp.js +0 -65
- package/dist/panels/SequenceEditorPanel/RightOverlay/HorizontalScrollbar.js +0 -235
- package/dist/panels/SequenceEditorPanel/RightOverlay/Markers/MarkerDot.js +0 -184
- package/dist/panels/SequenceEditorPanel/RightOverlay/Markers/MarkerEditorPopover.js +0 -65
- package/dist/panels/SequenceEditorPanel/RightOverlay/Markers/Markers.js +0 -13
- package/dist/panels/SequenceEditorPanel/RightOverlay/Playhead.js +0 -265
- package/dist/panels/SequenceEditorPanel/RightOverlay/PlayheadPositionPopover.js +0 -64
- package/dist/panels/SequenceEditorPanel/RightOverlay/RightOverlay.js +0 -35
- package/dist/panels/SequenceEditorPanel/RightOverlay/TopStrip.js +0 -31
- package/dist/panels/SequenceEditorPanel/SequenceEditorPanel.js +0 -179
- package/dist/panels/SequenceEditorPanel/VerticalScrollContainer.js +0 -42
- package/dist/panels/SequenceEditorPanel/layout/layout.js +0 -166
- package/dist/panels/SequenceEditorPanel/layout/tree.js +0 -139
- package/dist/panels/SequenceEditorPanel/whatPropIsHighlighted.js +0 -58
- package/dist/propEditors/DefaultValueIndicator.js +0 -64
- package/dist/propEditors/NextPrevKeyframeCursors.js +0 -135
- package/dist/propEditors/getNearbyKeyframesOfTrack.js +0 -46
- package/dist/propEditors/simpleEditors/BooleanPropEditor.js +0 -17
- package/dist/propEditors/simpleEditors/FilePropEditor.js +0 -118
- package/dist/propEditors/simpleEditors/ISimplePropEditorReactProps.js +0 -1
- package/dist/propEditors/simpleEditors/ImagePropEditor.js +0 -126
- package/dist/propEditors/simpleEditors/NumberPropEditor.js +0 -9
- package/dist/propEditors/simpleEditors/RgbaPropEditor.js +0 -73
- package/dist/propEditors/simpleEditors/StringLiteralPropEditor.js +0 -10
- package/dist/propEditors/simpleEditors/StringPropEditor.js +0 -6
- package/dist/propEditors/simpleEditors/simplePropEditorByPropType.js +0 -16
- package/dist/propEditors/useEditingToolsForCompoundProp.js +0 -228
- package/dist/propEditors/useEditingToolsForSimpleProp.js +0 -229
- package/dist/propEditors/utils/IEditingTools.js +0 -1
- package/dist/propEditors/utils/PropConfigForType.js +0 -1
- package/dist/propEditors/utils/getPropTypeByPointer.js +0 -48
- package/dist/propEditors/utils/propNameTextCSS.js +0 -7
- package/dist/selectors.js +0 -63
- package/dist/store/index.js +0 -184
- package/dist/store/stateEditors.js +0 -774
- package/dist/store/types/ahistoric.js +0 -1
- package/dist/store/types/ephemeral.js +0 -1
- package/dist/store/types/historic.js +0 -1
- package/dist/store/types/index.js +0 -3
- package/dist/toolbars/ExtensionToolbar/ExtensionToolbar.js +0 -51
- package/dist/toolbars/ExtensionToolbar/Toolset.js +0 -27
- package/dist/toolbars/ExtensionToolbar/tools/ExtensionFlyoutMenu.js +0 -51
- package/dist/toolbars/ExtensionToolbar/tools/IconButton.js +0 -16
- package/dist/toolbars/ExtensionToolbar/tools/Switch.js +0 -20
- package/dist/toolbars/GlobalToolbar.js +0 -142
- package/dist/toolbars/MoreMenu/MoreMenu.js +0 -133
- package/dist/toolbars/PinButton.js +0 -26
- package/dist/uiComponents/DetailPanelButton.js +0 -21
- package/dist/uiComponents/PointerEventsHandler.js +0 -80
- package/dist/uiComponents/Popover/ArrowContext.js +0 -3
- package/dist/uiComponents/Popover/BasicPopover.js +0 -35
- package/dist/uiComponents/Popover/BasicTooltip.js +0 -10
- package/dist/uiComponents/Popover/ErrorTooltip.js +0 -9
- package/dist/uiComponents/Popover/MinimalTooltip.js +0 -6
- package/dist/uiComponents/Popover/PopoverArrow.js +0 -38
- package/dist/uiComponents/Popover/TooltipContext.js +0 -46
- package/dist/uiComponents/Popover/TooltipWrapper.js +0 -103
- package/dist/uiComponents/Popover/usePopover.js +0 -132
- package/dist/uiComponents/Popover/useTooltip.js +0 -33
- package/dist/uiComponents/RoomToClick.js +0 -10
- package/dist/uiComponents/SVGIcon.js +0 -19
- package/dist/uiComponents/ShowMousePosition.js +0 -30
- package/dist/uiComponents/colorPicker/components/EditingProvider.js +0 -15
- package/dist/uiComponents/colorPicker/components/RgbaColorPicker.js +0 -31
- package/dist/uiComponents/colorPicker/components/common/Alpha.js +0 -54
- package/dist/uiComponents/colorPicker/components/common/AlphaColorPicker.js +0 -28
- package/dist/uiComponents/colorPicker/components/common/Hue.js +0 -41
- package/dist/uiComponents/colorPicker/components/common/Interactive.js +0 -142
- package/dist/uiComponents/colorPicker/components/common/Pointer.js +0 -39
- package/dist/uiComponents/colorPicker/components/common/Saturation.js +0 -44
- package/dist/uiComponents/colorPicker/hooks/useColorManipulation.js +0 -77
- package/dist/uiComponents/colorPicker/hooks/useEventCallback.js +0 -10
- package/dist/uiComponents/colorPicker/hooks/useIsomorphicLayoutEffect.js +0 -5
- package/dist/uiComponents/colorPicker/index.js +0 -1
- package/dist/uiComponents/colorPicker/types.js +0 -1
- package/dist/uiComponents/colorPicker/utils/clamp.js +0 -6
- package/dist/uiComponents/colorPicker/utils/compare.js +0 -25
- package/dist/uiComponents/colorPicker/utils/convert.js +0 -165
- package/dist/uiComponents/colorPicker/utils/round.js +0 -3
- package/dist/uiComponents/colorPicker/utils/validate.js +0 -10
- package/dist/uiComponents/createCursorLock.js +0 -2
- package/dist/uiComponents/form/BasicCheckbox.js +0 -5
- package/dist/uiComponents/form/BasicNumberInput.js +0 -261
- package/dist/uiComponents/form/BasicSelect.js +0 -58
- package/dist/uiComponents/form/BasicStringInput.js +0 -151
- package/dist/uiComponents/form/BasicSwitch.js +0 -60
- package/dist/uiComponents/icons/AddImage.js +0 -6
- package/dist/uiComponents/icons/ArrowClockwise.js +0 -6
- package/dist/uiComponents/icons/ArrowsOutCardinal.js +0 -6
- package/dist/uiComponents/icons/Bell.js +0 -6
- package/dist/uiComponents/icons/Camera.js +0 -7
- package/dist/uiComponents/icons/ChevronDown.js +0 -6
- package/dist/uiComponents/icons/ChevronLeft.js +0 -6
- package/dist/uiComponents/icons/ChevronRight.js +0 -6
- package/dist/uiComponents/icons/Cube.js +0 -6
- package/dist/uiComponents/icons/CubeFull.js +0 -6
- package/dist/uiComponents/icons/CubeHalf.js +0 -6
- package/dist/uiComponents/icons/CubeRendered.js +0 -7
- package/dist/uiComponents/icons/Details.js +0 -6
- package/dist/uiComponents/icons/DoubleChevronLeft.js +0 -6
- package/dist/uiComponents/icons/DoubleChevronRight.js +0 -6
- package/dist/uiComponents/icons/Ellipsis.js +0 -6
- package/dist/uiComponents/icons/EllipsisFill.js +0 -6
- package/dist/uiComponents/icons/GlobeSimple.js +0 -6
- package/dist/uiComponents/icons/Outline.js +0 -6
- package/dist/uiComponents/icons/Package.js +0 -6
- package/dist/uiComponents/icons/Resize.js +0 -7
- package/dist/uiComponents/icons/Trash.js +0 -6
- package/dist/uiComponents/icons/index.js +0 -20
- package/dist/uiComponents/isSafari.js +0 -2
- package/dist/uiComponents/onPointerOutside.js +0 -19
- package/dist/uiComponents/selects/BasicSelect.js +0 -24
- package/dist/uiComponents/simpleContextMenu/ContextMenu/BaseMenu.js +0 -40
- package/dist/uiComponents/simpleContextMenu/ContextMenu/ContextMenu.js +0 -87
- package/dist/uiComponents/simpleContextMenu/ContextMenu/Item.js +0 -37
- package/dist/uiComponents/simpleContextMenu/useContextMenu.js +0 -20
- package/dist/uiComponents/simpleContextMenu/useRequestContextMenu.js +0 -22
- package/dist/uiComponents/toolbar/ToolbarDropdownSelect.js +0 -7
- package/dist/uiComponents/toolbar/ToolbarIconButton.js +0 -74
- package/dist/uiComponents/toolbar/ToolbarSwitchSelect.js +0 -12
- package/dist/uiComponents/toolbar/ToolbarSwitchSelectContainer.js +0 -9
- package/dist/uiComponents/useBoundingClientRect.js +0 -13
- package/dist/uiComponents/useDebugRefreshEvery.js +0 -19
- package/dist/uiComponents/useDrag.js +0 -199
- package/dist/uiComponents/useHotspot.js +0 -30
- package/dist/uiComponents/useHover.js +0 -23
- package/dist/uiComponents/useHoverWithoutDescendants.js +0 -33
- package/dist/uiComponents/useKeyDown.js +0 -9
- package/dist/uiComponents/useKeyDownCallback.js +0 -28
- package/dist/uiComponents/useLockSet.js +0 -17
- package/dist/uiComponents/useLogger.js +0 -16
- package/dist/uiComponents/useOnClickOutside.js +0 -25
- package/dist/uiComponents/useOnKeyDown.js +0 -12
- package/dist/uiComponents/usePresence.js +0 -156
- package/dist/uiComponents/useValToAtom.js +0 -11
- package/dist/utils/absoluteDims.js +0 -7
- package/dist/utils/contextualWebComponents.js +0 -44
- package/dist/utils/copyToClipboard.js +0 -28
- package/dist/utils/derive-utils.js +0 -61
- package/dist/utils/devStringify.js +0 -20
- package/dist/utils/invariant.js +0 -79
- package/dist/utils/isMac.js +0 -2
- package/dist/utils/keyboardUtils.js +0 -23
- package/dist/utils/mousePositionD.js +0 -18
- package/dist/utils/redux/actionCreator.js +0 -15
- package/dist/utils/redux/actionCreator.test.js +0 -35
- package/dist/utils/redux/actionReducersBundle.js +0 -18
- package/dist/utils/redux/atomFromReduxStore.js +0 -11
- package/dist/utils/redux/configureStore.js +0 -18
- package/dist/utils/redux/pointerFriendlySelector.js +0 -8
- package/dist/utils/redux/withHistory/withBatchActions.js +0 -13
- package/dist/utils/redux/withHistory/withHistory.js +0 -157
- package/dist/utils/renderInPortalInContext.js +0 -38
- package/dist/utils/selectClosestHTMLAncestor.js +0 -13
- package/dist/utils/tightJsonStringify.js +0 -27
- package/dist/utils/tightJsonStringify.test.js +0 -25
- package/dist/utils/useRefAndState.js +0 -32
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useMemo, useEffect } from 'react';
|
|
2
|
-
import { useEventCallback } from '@tomorrowevening/theatre-studio/uiComponents/colorPicker/hooks/useEventCallback';
|
|
3
|
-
import { clamp } from '@tomorrowevening/theatre-studio/uiComponents/colorPicker/utils/clamp';
|
|
4
|
-
import styled from 'styled-components';
|
|
5
|
-
import { useEditing } from '@tomorrowevening/theatre-studio/uiComponents/colorPicker/components/EditingProvider';
|
|
6
|
-
// Check if an event was triggered by touch
|
|
7
|
-
const isTouch = (event) => 'touches' in event;
|
|
8
|
-
// Finds a proper touch point by its identifier
|
|
9
|
-
const getTouchPoint = (touches, touchId) => {
|
|
10
|
-
for (let i = 0; i < touches.length; i++) {
|
|
11
|
-
if (touches[i].identifier === touchId)
|
|
12
|
-
return touches[i];
|
|
13
|
-
}
|
|
14
|
-
return touches[0];
|
|
15
|
-
};
|
|
16
|
-
// Finds the proper window object to fix iframe embedding issues
|
|
17
|
-
const getParentWindow = (node) => {
|
|
18
|
-
return (node && node.ownerDocument.defaultView) || self;
|
|
19
|
-
};
|
|
20
|
-
// Returns a relative position of the pointer inside the node's bounding box
|
|
21
|
-
const getRelativePosition = (node, event, touchId) => {
|
|
22
|
-
const rect = node.getBoundingClientRect();
|
|
23
|
-
// Get user's pointer position from `touches` array if it's a `TouchEvent`
|
|
24
|
-
const pointer = isTouch(event)
|
|
25
|
-
? getTouchPoint(event.touches, touchId)
|
|
26
|
-
: event;
|
|
27
|
-
return {
|
|
28
|
-
left: clamp((pointer.pageX - (rect.left + getParentWindow(node).pageXOffset)) /
|
|
29
|
-
rect.width),
|
|
30
|
-
top: clamp((pointer.pageY - (rect.top + getParentWindow(node).pageYOffset)) /
|
|
31
|
-
rect.height),
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
// Browsers introduced an intervention, making touch events passive by default.
|
|
35
|
-
// This workaround removes `preventDefault` call from the touch handlers.
|
|
36
|
-
// https://github.com/facebook/react/issues/19651
|
|
37
|
-
const preventDefaultMove = (event) => {
|
|
38
|
-
!isTouch(event) && event.preventDefault();
|
|
39
|
-
};
|
|
40
|
-
// Prevent mobile browsers from handling mouse events (conflicting with touch ones).
|
|
41
|
-
// If we detected a touch interaction before, we prefer reacting to touch events only.
|
|
42
|
-
const isInvalid = (event, hasTouch) => {
|
|
43
|
-
return hasTouch && !isTouch(event);
|
|
44
|
-
};
|
|
45
|
-
const Container = styled.div `
|
|
46
|
-
position: absolute;
|
|
47
|
-
left: 0;
|
|
48
|
-
top: 0;
|
|
49
|
-
right: 0;
|
|
50
|
-
bottom: 0;
|
|
51
|
-
border-radius: inherit;
|
|
52
|
-
outline: none;
|
|
53
|
-
/* Don't trigger the default scrolling behavior when the event is originating from this element */
|
|
54
|
-
touch-action: none;
|
|
55
|
-
`;
|
|
56
|
-
const InteractiveBase = ({ onMove, onKey, ...rest }) => {
|
|
57
|
-
const container = useRef(null);
|
|
58
|
-
const onMoveCallback = useEventCallback(onMove);
|
|
59
|
-
const onKeyCallback = useEventCallback(onKey);
|
|
60
|
-
const touchId = useRef(null);
|
|
61
|
-
const hasTouch = useRef(false);
|
|
62
|
-
const { setEditing } = useEditing();
|
|
63
|
-
const [handleMoveStart, handleKeyDown, toggleDocumentEvents] = useMemo(() => {
|
|
64
|
-
const handleMoveStart = ({ nativeEvent, }) => {
|
|
65
|
-
const el = container.current;
|
|
66
|
-
if (!el)
|
|
67
|
-
return;
|
|
68
|
-
// Prevent text selection
|
|
69
|
-
preventDefaultMove(nativeEvent);
|
|
70
|
-
if (isInvalid(nativeEvent, hasTouch.current) || !el)
|
|
71
|
-
return;
|
|
72
|
-
if (isTouch(nativeEvent)) {
|
|
73
|
-
hasTouch.current = true;
|
|
74
|
-
const changedTouches = nativeEvent.changedTouches || [];
|
|
75
|
-
if (changedTouches.length)
|
|
76
|
-
touchId.current = changedTouches[0].identifier;
|
|
77
|
-
}
|
|
78
|
-
el.focus();
|
|
79
|
-
setEditing(true);
|
|
80
|
-
onMoveCallback(getRelativePosition(el, nativeEvent, touchId.current));
|
|
81
|
-
toggleDocumentEvents(true);
|
|
82
|
-
};
|
|
83
|
-
const handleMove = (event) => {
|
|
84
|
-
// Prevent text selection
|
|
85
|
-
preventDefaultMove(event);
|
|
86
|
-
// If user moves the pointer outside the window or iframe bounds and release it there,
|
|
87
|
-
// `mouseup`/`touchend` won't be fired. In order to stop the picker from following the cursor
|
|
88
|
-
// after the user has moved the mouse/finger back to the document, we check `event.buttons`
|
|
89
|
-
// and `event.touches`. It allows us to detect that the user is just moving his pointer
|
|
90
|
-
// without pressing it down
|
|
91
|
-
// Note: we should use pointer events to fix this, since we don't have strict compatibility
|
|
92
|
-
// requirements.
|
|
93
|
-
const isDown = isTouch(event)
|
|
94
|
-
? event.touches.length > 0
|
|
95
|
-
: event.buttons > 0;
|
|
96
|
-
if (isDown && container.current) {
|
|
97
|
-
onMoveCallback(getRelativePosition(container.current, event, touchId.current));
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
setEditing(false);
|
|
101
|
-
toggleDocumentEvents(false);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
// Use move-end anyway (see above) so we can terminate early if we receive one
|
|
105
|
-
// instead of having to wait for the user to move the mouse, which they might not do.
|
|
106
|
-
const handleMoveEnd = (event) => {
|
|
107
|
-
setEditing(false);
|
|
108
|
-
toggleDocumentEvents(false);
|
|
109
|
-
};
|
|
110
|
-
const handleKeyDown = (event) => {
|
|
111
|
-
const keyCode = event.which || event.keyCode;
|
|
112
|
-
// Ignore all keys except arrow ones
|
|
113
|
-
if (keyCode < 37 || keyCode > 40)
|
|
114
|
-
return;
|
|
115
|
-
// Do not scroll page by arrow keys when document is focused on the element
|
|
116
|
-
event.preventDefault();
|
|
117
|
-
// Send relative offset to the parent component.
|
|
118
|
-
// We use codes (37←, 38↑, 39→, 40↓) instead of keys ('ArrowRight', 'ArrowDown', etc)
|
|
119
|
-
// to reduce the size of the library
|
|
120
|
-
onKeyCallback({
|
|
121
|
-
left: keyCode === 39 ? 0.05 : keyCode === 37 ? -0.05 : 0,
|
|
122
|
-
top: keyCode === 40 ? 0.05 : keyCode === 38 ? -0.05 : 0,
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
function toggleDocumentEvents(state) {
|
|
126
|
-
const touch = hasTouch.current;
|
|
127
|
-
const el = container.current;
|
|
128
|
-
const parentWindow = getParentWindow(el);
|
|
129
|
-
// Add or remove additional pointer event listeners
|
|
130
|
-
const toggleEvent = state
|
|
131
|
-
? parentWindow.addEventListener
|
|
132
|
-
: parentWindow.removeEventListener;
|
|
133
|
-
toggleEvent(touch ? 'touchmove' : 'mousemove', handleMove);
|
|
134
|
-
toggleEvent(touch ? 'touchend' : 'mouseup', handleMoveEnd);
|
|
135
|
-
}
|
|
136
|
-
return [handleMoveStart, handleKeyDown, toggleDocumentEvents];
|
|
137
|
-
}, [onKeyCallback, onMoveCallback]);
|
|
138
|
-
// Remove window event listeners before unmounting
|
|
139
|
-
useEffect(() => toggleDocumentEvents, [toggleDocumentEvents]);
|
|
140
|
-
return (React.createElement(Container, { ...rest, onTouchStart: handleMoveStart, onMouseDown: handleMoveStart, ref: container, onKeyDown: handleKeyDown, tabIndex: 0, role: "slider" }));
|
|
141
|
-
};
|
|
142
|
-
export const Interactive = React.memo(InteractiveBase);
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import styled from 'styled-components';
|
|
3
|
-
import { Interactive } from './Interactive';
|
|
4
|
-
// Create an "empty" styled version, so we can reference it for contextual styling
|
|
5
|
-
const StyledInteractive = styled(Interactive) ``;
|
|
6
|
-
const Container = styled.div `
|
|
7
|
-
position: absolute;
|
|
8
|
-
z-index: 1;
|
|
9
|
-
box-sizing: border-box;
|
|
10
|
-
width: 16px;
|
|
11
|
-
height: 16px;
|
|
12
|
-
transform: translate(-50%, -50%);
|
|
13
|
-
background-color: #fff;
|
|
14
|
-
border: 1px solid #ffffff00;
|
|
15
|
-
border-radius: 2px;
|
|
16
|
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
|
17
|
-
|
|
18
|
-
${StyledInteractive}:focus & {
|
|
19
|
-
transform: translate(-50%, -50%) scale(1.1);
|
|
20
|
-
}
|
|
21
|
-
`;
|
|
22
|
-
const Fill = styled.div `
|
|
23
|
-
content: '';
|
|
24
|
-
position: absolute;
|
|
25
|
-
left: 0;
|
|
26
|
-
top: 0;
|
|
27
|
-
right: 0;
|
|
28
|
-
bottom: 0;
|
|
29
|
-
pointer-events: none;
|
|
30
|
-
border-radius: inherit;
|
|
31
|
-
`;
|
|
32
|
-
export const Pointer = ({ className, color, left, top = 0.5, }) => {
|
|
33
|
-
const style = {
|
|
34
|
-
top: `${top * 100}%`,
|
|
35
|
-
left: `${left * 100}%`,
|
|
36
|
-
};
|
|
37
|
-
return (React.createElement(Container, { style: style, className: className },
|
|
38
|
-
React.createElement(Fill, { style: { backgroundColor: color } })));
|
|
39
|
-
};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Interactive } from './Interactive';
|
|
3
|
-
import { Pointer } from './Pointer';
|
|
4
|
-
import { hsvaToHslString } from '@tomorrowevening/theatre-studio/uiComponents/colorPicker/utils/convert';
|
|
5
|
-
import { clamp } from '@tomorrowevening/theatre-studio/uiComponents/colorPicker/utils/clamp';
|
|
6
|
-
import { round } from '@tomorrowevening/theatre-studio/uiComponents/colorPicker/utils/round';
|
|
7
|
-
import styled from 'styled-components';
|
|
8
|
-
const Container = styled.div `
|
|
9
|
-
position: relative;
|
|
10
|
-
flex-grow: 1;
|
|
11
|
-
border-color: transparent; /* Fixes https://github.com/omgovich/react-colorful/issues/139 */
|
|
12
|
-
border-bottom: 12px solid #000;
|
|
13
|
-
border-radius: 2px;
|
|
14
|
-
background-image: linear-gradient(to top, #000, rgba(0, 0, 0, 0)),
|
|
15
|
-
linear-gradient(to right, #fff, rgba(255, 255, 255, 0));
|
|
16
|
-
|
|
17
|
-
// Improve elements rendering on light backgrounds
|
|
18
|
-
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
|
|
19
|
-
`;
|
|
20
|
-
const StyledPointer = styled(Pointer) `
|
|
21
|
-
z-index: 3;
|
|
22
|
-
`;
|
|
23
|
-
const SaturationBase = ({ hsva, onChange }) => {
|
|
24
|
-
const handleMove = (interaction) => {
|
|
25
|
-
onChange({
|
|
26
|
-
s: interaction.left * 100,
|
|
27
|
-
v: 100 - interaction.top * 100,
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
const handleKey = (offset) => {
|
|
31
|
-
// Saturation and brightness always fit into [0, 100] range
|
|
32
|
-
onChange({
|
|
33
|
-
s: clamp(hsva.s + offset.left * 100, 0, 100),
|
|
34
|
-
v: clamp(hsva.v - offset.top * 100, 0, 100),
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
const containerStyle = {
|
|
38
|
-
backgroundColor: hsvaToHslString({ h: hsva.h, s: 100, v: 100, a: 1 }),
|
|
39
|
-
};
|
|
40
|
-
return (React.createElement(Container, { style: containerStyle },
|
|
41
|
-
React.createElement(Interactive, { onMove: handleMove, onKey: handleKey, "aria-label": "Color", "aria-valuetext": `Saturation ${round(hsva.s)}%, Brightness ${round(hsva.v)}%` },
|
|
42
|
-
React.createElement(StyledPointer, { top: 1 - hsva.v / 100, left: hsva.s / 100, color: hsvaToHslString(hsva) }))));
|
|
43
|
-
};
|
|
44
|
-
export const Saturation = React.memo(SaturationBase);
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useCallback, useRef } from 'react';
|
|
2
|
-
import { equalColorObjects } from '@tomorrowevening/theatre-studio/uiComponents/colorPicker/utils/compare';
|
|
3
|
-
import { useEventCallback } from './useEventCallback';
|
|
4
|
-
import { useEditing } from '@tomorrowevening/theatre-studio/uiComponents/colorPicker/components/EditingProvider';
|
|
5
|
-
export function useColorManipulation(colorModel, color, onTemporarilyChange, onPermanentlyChange) {
|
|
6
|
-
const { editing } = useEditing();
|
|
7
|
-
const [editingValue, setEditingValue] = useState(color);
|
|
8
|
-
// Save onChange callbacks in refs for to avoid unnecessarily updating when parent doesn't use useCallback
|
|
9
|
-
const onTemporarilyChangeCallback = useEventCallback(onTemporarilyChange);
|
|
10
|
-
const onPermanentlyChangeCallback = useEventCallback(onPermanentlyChange);
|
|
11
|
-
// If editing, be uncontrolled, if not editing, be controlled
|
|
12
|
-
let value = editing ? editingValue : color;
|
|
13
|
-
// No matter which color model is used (HEX, RGB(A) or HSL(A)),
|
|
14
|
-
// all internal calculations are in HSVA
|
|
15
|
-
const [hsva, updateHsva] = useState(() => colorModel.toHsva(value));
|
|
16
|
-
// Use refs to prevent infinite update loops. They basically serve as a more
|
|
17
|
-
// explicit hack around the rigidity of React hooks' dep lists, since we want
|
|
18
|
-
// to do all color equality checks in HSVA, without breaking the roles of hooks.
|
|
19
|
-
// We use separate refs for temporary updates and permanent updates,
|
|
20
|
-
// since they are two independent update models.
|
|
21
|
-
const tempCache = useRef({ color: value, hsva });
|
|
22
|
-
const permCache = useRef({ color: value, hsva });
|
|
23
|
-
// When entering editing mode, set the internal state of the uncontrolled mode
|
|
24
|
-
// to the last value of the controlled mode.
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
if (editing) {
|
|
27
|
-
setEditingValue(tempCache.current.color);
|
|
28
|
-
}
|
|
29
|
-
}, [editing]);
|
|
30
|
-
// Trigger `on*Change` callbacks only if an updated color is different from
|
|
31
|
-
// the cached one; save the new color to the ref to prevent unnecessary updates.
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
let newColor = colorModel.fromHsva(hsva);
|
|
34
|
-
if (editing) {
|
|
35
|
-
if (!equalColorObjects(hsva, tempCache.current.hsva) &&
|
|
36
|
-
!colorModel.equal(newColor, tempCache.current.color)) {
|
|
37
|
-
tempCache.current = { hsva, color: newColor };
|
|
38
|
-
setEditingValue(newColor);
|
|
39
|
-
onTemporarilyChangeCallback(newColor);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
if (!equalColorObjects(hsva, permCache.current.hsva) &&
|
|
44
|
-
!colorModel.equal(newColor, permCache.current.color)) {
|
|
45
|
-
permCache.current = { hsva, color: newColor };
|
|
46
|
-
tempCache.current = { hsva, color: newColor };
|
|
47
|
-
onPermanentlyChangeCallback(newColor);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}, [
|
|
51
|
-
editing,
|
|
52
|
-
hsva,
|
|
53
|
-
colorModel,
|
|
54
|
-
onTemporarilyChangeCallback,
|
|
55
|
-
onPermanentlyChangeCallback,
|
|
56
|
-
]);
|
|
57
|
-
// This has to come after the callback calling effect, so that the cache isn't
|
|
58
|
-
// updated before the above effect checks for equality, otherwise no updates would
|
|
59
|
-
// be issued.
|
|
60
|
-
// Note: it doesn't make sense to have an editing version of this effect because
|
|
61
|
-
// the callback calling effect already updates the caches.
|
|
62
|
-
useEffect(() => {
|
|
63
|
-
if (!editing) {
|
|
64
|
-
if (!colorModel.equal(value, permCache.current.color)) {
|
|
65
|
-
const newHsva = colorModel.toHsva(value);
|
|
66
|
-
permCache.current = { hsva: newHsva, color: value };
|
|
67
|
-
updateHsva(newHsva);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}, [editing, value, colorModel]);
|
|
71
|
-
// Merge the current HSVA color object with updated params.
|
|
72
|
-
// For example, when a child component sends `h` or `s` only
|
|
73
|
-
const handleChange = useCallback((params) => {
|
|
74
|
-
updateHsva((current) => Object.assign({}, current, params));
|
|
75
|
-
}, []);
|
|
76
|
-
return [hsva, handleChange];
|
|
77
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { useRef } from 'react';
|
|
2
|
-
// Saves incoming handler to the ref in order to avoid "useCallback hell"
|
|
3
|
-
export function useEventCallback(handler) {
|
|
4
|
-
const callbackRef = useRef(handler);
|
|
5
|
-
const fn = useRef((value) => {
|
|
6
|
-
callbackRef.current && callbackRef.current(value);
|
|
7
|
-
});
|
|
8
|
-
callbackRef.current = handler;
|
|
9
|
-
return fn.current;
|
|
10
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect, useEffect } from 'react';
|
|
2
|
-
// React currently throws a warning when using useLayoutEffect on the server.
|
|
3
|
-
// To get around it, we can conditionally useEffect on the server (no-op) and
|
|
4
|
-
// useLayoutEffect in the browser.
|
|
5
|
-
export const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { RgbaColorPicker } from './components/RgbaColorPicker';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// Clamps a value between an upper and lower bound.
|
|
2
|
-
// We use ternary operators because it makes the minified code
|
|
3
|
-
// 2 times shorter then `Math.min(Math.max(a,b),c)`
|
|
4
|
-
export const clamp = (number, min = 0, max = 1) => {
|
|
5
|
-
return number > max ? max : number < min ? min : number;
|
|
6
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { hexToRgba } from './convert';
|
|
2
|
-
export const equalColorObjects = (first, second) => {
|
|
3
|
-
if (first === second)
|
|
4
|
-
return true;
|
|
5
|
-
for (const prop in first) {
|
|
6
|
-
// The following allows for a type-safe calling of this function (first & second have to be HSL, HSV, or RGB)
|
|
7
|
-
// with type-unsafe iterating over object keys. TS does not allow this without an index (`[key: string]: number`)
|
|
8
|
-
// on an object to define how iteration is normally done. To ensure extra keys are not allowed on our types,
|
|
9
|
-
// we must cast our object to unknown (as RGB demands `r` be a key, while `Record<string, x>` does not care if
|
|
10
|
-
// there is or not), and then as a type TS can iterate over.
|
|
11
|
-
if (first[prop] !==
|
|
12
|
-
second[prop])
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
return true;
|
|
16
|
-
};
|
|
17
|
-
export const equalColorString = (first, second) => {
|
|
18
|
-
return first.replace(/\s/g, '') === second.replace(/\s/g, '');
|
|
19
|
-
};
|
|
20
|
-
export const equalHex = (first, second) => {
|
|
21
|
-
if (first.toLowerCase() === second.toLowerCase())
|
|
22
|
-
return true;
|
|
23
|
-
// To compare colors like `#FFF` and `ffffff` we convert them into RGB objects
|
|
24
|
-
return equalColorObjects(hexToRgba(first), hexToRgba(second));
|
|
25
|
-
};
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { round } from './round';
|
|
2
|
-
/**
|
|
3
|
-
* Valid CSS <angle> units.
|
|
4
|
-
* https://developer.mozilla.org/en-US/docs/Web/CSS/angle
|
|
5
|
-
*/
|
|
6
|
-
const angleUnits = {
|
|
7
|
-
grad: 360 / 400,
|
|
8
|
-
turn: 360,
|
|
9
|
-
rad: 360 / (Math.PI * 2),
|
|
10
|
-
};
|
|
11
|
-
export const hexToHsva = (hex) => rgbaToHsva(hexToRgba(hex));
|
|
12
|
-
export const hexToRgba = (hex) => {
|
|
13
|
-
if (hex[0] === '#')
|
|
14
|
-
hex = hex.substr(1);
|
|
15
|
-
if (hex.length < 6) {
|
|
16
|
-
return {
|
|
17
|
-
r: parseInt(hex[0] + hex[0], 16),
|
|
18
|
-
g: parseInt(hex[1] + hex[1], 16),
|
|
19
|
-
b: parseInt(hex[2] + hex[2], 16),
|
|
20
|
-
a: 1,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
r: parseInt(hex.substr(0, 2), 16),
|
|
25
|
-
g: parseInt(hex.substr(2, 2), 16),
|
|
26
|
-
b: parseInt(hex.substr(4, 2), 16),
|
|
27
|
-
a: 1,
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
export const parseHue = (value, unit = 'deg') => {
|
|
31
|
-
return Number(value) * (angleUnits[unit] || 1);
|
|
32
|
-
};
|
|
33
|
-
export const hslaStringToHsva = (hslString) => {
|
|
34
|
-
const matcher = /hsla?\(?\s*(-?\d*\.?\d+)(deg|rad|grad|turn)?[,\s]+(-?\d*\.?\d+)%?[,\s]+(-?\d*\.?\d+)%?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i;
|
|
35
|
-
const match = matcher.exec(hslString);
|
|
36
|
-
if (!match)
|
|
37
|
-
return { h: 0, s: 0, v: 0, a: 1 };
|
|
38
|
-
return hslaToHsva({
|
|
39
|
-
h: parseHue(match[1], match[2]),
|
|
40
|
-
s: Number(match[3]),
|
|
41
|
-
l: Number(match[4]),
|
|
42
|
-
a: match[5] === undefined ? 1 : Number(match[5]) / (match[6] ? 100 : 1),
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
export const hslStringToHsva = hslaStringToHsva;
|
|
46
|
-
export const hslaToHsva = ({ h, s, l, a }) => {
|
|
47
|
-
s *= (l < 50 ? l : 100 - l) / 100;
|
|
48
|
-
return {
|
|
49
|
-
h: h,
|
|
50
|
-
s: s > 0 ? ((2 * s) / (l + s)) * 100 : 0,
|
|
51
|
-
v: l + s,
|
|
52
|
-
a,
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
export const hsvaToHex = (hsva) => rgbaToHex(hsvaToRgba(hsva));
|
|
56
|
-
export const hsvaToHsla = ({ h, s, v, a }) => {
|
|
57
|
-
const hh = ((200 - s) * v) / 100;
|
|
58
|
-
return {
|
|
59
|
-
h: round(h),
|
|
60
|
-
s: round(hh > 0 && hh < 200
|
|
61
|
-
? ((s * v) / 100 / (hh <= 100 ? hh : 200 - hh)) * 100
|
|
62
|
-
: 0),
|
|
63
|
-
l: round(hh / 2),
|
|
64
|
-
a: round(a, 2),
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
export const hsvaToHslString = (hsva) => {
|
|
68
|
-
const { h, s, l } = hsvaToHsla(hsva);
|
|
69
|
-
return `hsl(${h}, ${s}%, ${l}%)`;
|
|
70
|
-
};
|
|
71
|
-
export const hsvaToHsvString = (hsva) => {
|
|
72
|
-
const { h, s, v } = roundHsva(hsva);
|
|
73
|
-
return `hsv(${h}, ${s}%, ${v}%)`;
|
|
74
|
-
};
|
|
75
|
-
export const hsvaToHsvaString = (hsva) => {
|
|
76
|
-
const { h, s, v, a } = roundHsva(hsva);
|
|
77
|
-
return `hsva(${h}, ${s}%, ${v}%, ${a})`;
|
|
78
|
-
};
|
|
79
|
-
export const hsvaToHslaString = (hsva) => {
|
|
80
|
-
const { h, s, l, a } = hsvaToHsla(hsva);
|
|
81
|
-
return `hsla(${h}, ${s}%, ${l}%, ${a})`;
|
|
82
|
-
};
|
|
83
|
-
export const hsvaToRgba = ({ h, s, v, a }) => {
|
|
84
|
-
h = (h / 360) * 6;
|
|
85
|
-
s = s / 100;
|
|
86
|
-
v = v / 100;
|
|
87
|
-
const hh = Math.floor(h), b = v * (1 - s), c = v * (1 - (h - hh) * s), d = v * (1 - (1 - h + hh) * s), module = hh % 6;
|
|
88
|
-
return {
|
|
89
|
-
r: round([v, c, b, b, d, v][module] * 255),
|
|
90
|
-
g: round([d, v, v, c, b, b][module] * 255),
|
|
91
|
-
b: round([b, b, d, v, v, c][module] * 255),
|
|
92
|
-
a: round(a, 2),
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
export const hsvaToRgbString = (hsva) => {
|
|
96
|
-
const { r, g, b } = hsvaToRgba(hsva);
|
|
97
|
-
return `rgb(${r}, ${g}, ${b})`;
|
|
98
|
-
};
|
|
99
|
-
export const hsvaToRgbaString = (hsva) => {
|
|
100
|
-
const { r, g, b, a } = hsvaToRgba(hsva);
|
|
101
|
-
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
102
|
-
};
|
|
103
|
-
export const hsvaStringToHsva = (hsvString) => {
|
|
104
|
-
const matcher = /hsva?\(?\s*(-?\d*\.?\d+)(deg|rad|grad|turn)?[,\s]+(-?\d*\.?\d+)%?[,\s]+(-?\d*\.?\d+)%?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i;
|
|
105
|
-
const match = matcher.exec(hsvString);
|
|
106
|
-
if (!match)
|
|
107
|
-
return { h: 0, s: 0, v: 0, a: 1 };
|
|
108
|
-
return roundHsva({
|
|
109
|
-
h: parseHue(match[1], match[2]),
|
|
110
|
-
s: Number(match[3]),
|
|
111
|
-
v: Number(match[4]),
|
|
112
|
-
a: match[5] === undefined ? 1 : Number(match[5]) / (match[6] ? 100 : 1),
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
export const hsvStringToHsva = hsvaStringToHsva;
|
|
116
|
-
export const rgbaStringToHsva = (rgbaString) => {
|
|
117
|
-
const matcher = /rgba?\(?\s*(-?\d*\.?\d+)(%)?[,\s]+(-?\d*\.?\d+)(%)?[,\s]+(-?\d*\.?\d+)(%)?,?\s*[/\s]*(-?\d*\.?\d+)?(%)?\s*\)?/i;
|
|
118
|
-
const match = matcher.exec(rgbaString);
|
|
119
|
-
if (!match)
|
|
120
|
-
return { h: 0, s: 0, v: 0, a: 1 };
|
|
121
|
-
return rgbaToHsva({
|
|
122
|
-
r: Number(match[1]) / (match[2] ? 100 / 255 : 1),
|
|
123
|
-
g: Number(match[3]) / (match[4] ? 100 / 255 : 1),
|
|
124
|
-
b: Number(match[5]) / (match[6] ? 100 / 255 : 1),
|
|
125
|
-
a: match[7] === undefined ? 1 : Number(match[7]) / (match[8] ? 100 : 1),
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
export const rgbStringToHsva = rgbaStringToHsva;
|
|
129
|
-
const format = (number) => {
|
|
130
|
-
const hex = number.toString(16);
|
|
131
|
-
return hex.length < 2 ? '0' + hex : hex;
|
|
132
|
-
};
|
|
133
|
-
export const rgbaToHex = ({ r, g, b }) => {
|
|
134
|
-
return '#' + format(r) + format(g) + format(b);
|
|
135
|
-
};
|
|
136
|
-
export const rgbaToHsva = ({ r, g, b, a }) => {
|
|
137
|
-
const max = Math.max(r, g, b);
|
|
138
|
-
const delta = max - Math.min(r, g, b);
|
|
139
|
-
// prettier-ignore
|
|
140
|
-
const hh = delta
|
|
141
|
-
? max === r
|
|
142
|
-
? (g - b) / delta
|
|
143
|
-
: max === g
|
|
144
|
-
? 2 + (b - r) / delta
|
|
145
|
-
: 4 + (r - g) / delta
|
|
146
|
-
: 0;
|
|
147
|
-
return {
|
|
148
|
-
h: round(60 * (hh < 0 ? hh + 6 : hh)),
|
|
149
|
-
s: round(max ? (delta / max) * 100 : 0),
|
|
150
|
-
v: round((max / 255) * 100),
|
|
151
|
-
a,
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
export const roundHsva = (hsva) => ({
|
|
155
|
-
h: round(hsva.h),
|
|
156
|
-
s: round(hsva.s),
|
|
157
|
-
v: round(hsva.v),
|
|
158
|
-
a: round(hsva.a, 2),
|
|
159
|
-
});
|
|
160
|
-
export const rgbaToRgb = ({ r, g, b }) => ({ r, g, b });
|
|
161
|
-
export const hslaToHsl = ({ h, s, l }) => ({ h, s, l });
|
|
162
|
-
export const hsvaToHsv = (hsva) => {
|
|
163
|
-
const { h, s, v } = roundHsva(hsva);
|
|
164
|
-
return { h, s, v };
|
|
165
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const matcher = /^#?([0-9A-F]{3,8})$/i;
|
|
2
|
-
export const validHex = (value, alpha) => {
|
|
3
|
-
const match = matcher.exec(value);
|
|
4
|
-
const length = match ? match[1].length : 0;
|
|
5
|
-
return (length === 3 || // '#rgb' format
|
|
6
|
-
length === 6 || // '#rrggbb' format
|
|
7
|
-
(!!alpha && length === 4) || // '#rgba' format
|
|
8
|
-
(!!alpha && length === 8) // '#rrggbbaa' format
|
|
9
|
-
);
|
|
10
|
-
};
|