@sanity/ui 3.0.0-static.32 → 3.0.0-static.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/_chunks-cjs/_visual-editing.cjs +269 -378
- package/dist/_chunks-cjs/_visual-editing.cjs.map +1 -1
- package/dist/_chunks-cjs/refractor.cjs.map +1 -1
- package/dist/_chunks-es/_visual-editing.js +270 -381
- package/dist/_chunks-es/_visual-editing.js.map +1 -1
- package/dist/_chunks-es/refractor.js.map +1 -1
- package/dist/_visual-editing.cjs +0 -2
- package/dist/_visual-editing.cjs.map +1 -1
- package/dist/_visual-editing.d.cts +2 -894
- package/dist/_visual-editing.d.ts +2 -894
- package/dist/_visual-editing.js +2 -4
- package/dist/css/index.cjs +13 -13
- package/dist/css/index.cjs.map +1 -1
- package/dist/css/index.css +1 -1
- package/dist/css/index.d.cts +805 -14697
- package/dist/css/index.d.ts +805 -14697
- package/dist/css/index.js +13 -13
- package/dist/css/index.js.map +1 -1
- package/dist/index.cjs +242 -367
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +990 -3085
- package/dist/index.d.ts +990 -3085
- package/dist/index.js +244 -361
- package/dist/index.js.map +1 -1
- package/dist/portalProvider-DgNIVviV.d.ts +575 -0
- package/dist/theme.cjs +367 -4288
- package/dist/theme.cjs.map +1 -1
- package/dist/theme.d.cts +272 -1806
- package/dist/theme.d.ts +272 -1806
- package/dist/theme.js +371 -4292
- package/dist/theme.js.map +1 -1
- package/exports/_visual-editing.ts +0 -2
- package/package.json +8 -9
- package/src/core/Root.tsx +6 -4
- package/src/core/RootProvider.tsx +4 -4
- package/src/core/__workshop__/boundary.tsx +1 -1
- package/src/core/__workshop__/index.ts +5 -3
- package/src/core/components/autocomplete/__workshop__/async.tsx +1 -1
- package/src/core/components/autocomplete/__workshop__/constrainedHeight.tsx +2 -2
- package/src/core/components/autocomplete/__workshop__/custom.tsx +2 -2
- package/src/core/components/autocomplete/__workshop__/example.tsx +2 -2
- package/src/core/components/autocomplete/__workshop__/focusAndBlur.tsx +1 -1
- package/src/core/components/autocomplete/__workshop__/fullscreen.tsx +1 -1
- package/src/core/components/autocomplete/__workshop__/index.ts +5 -3
- package/src/core/components/autocomplete/__workshop__/mock/apiStore.ts +1 -1
- package/src/core/components/autocomplete/__workshop__/mock/countries.ts +1 -1
- package/src/core/components/autocomplete/autocomplete.tsx +2 -2
- package/src/core/components/autocomplete/autocompleteOption.tsx +2 -2
- package/src/core/components/autocomplete/constants.ts +2 -2
- package/src/core/components/breadcrumbs/__workshop__/example.tsx +1 -1
- package/src/core/components/breadcrumbs/__workshop__/index.ts +5 -3
- package/src/core/components/breadcrumbs/breadcrumbs.tsx +6 -11
- package/src/core/components/dialog/__workshop__/activate.tsx +1 -1
- package/src/core/components/dialog/__workshop__/autoFocus.tsx +1 -1
- package/src/core/components/dialog/__workshop__/index.ts +5 -3
- package/src/core/components/dialog/__workshop__/layering.tsx +1 -1
- package/src/core/components/dialog/__workshop__/nested.tsx +2 -3
- package/src/core/components/dialog/__workshop__/onScroll.tsx +1 -1
- package/src/core/components/dialog/__workshop__/panes.tsx +1 -1
- package/src/core/components/dialog/__workshop__/position.tsx +1 -1
- package/src/core/components/dialog/__workshop__/props.tsx +1 -1
- package/src/core/components/dialog/__workshop__/provider.tsx +1 -1
- package/src/core/components/dialog/__workshop__/wrapped.tsx +1 -1
- package/src/core/components/dialog/dialog.tsx +5 -6
- package/src/core/components/dialog/dialogCard.tsx +2 -2
- package/src/core/components/dialog/dialogContext.ts +3 -4
- package/src/core/components/dialog/dialogProvider.tsx +2 -2
- package/src/core/components/hotkeys/__workshop__/index.ts +5 -3
- package/src/core/components/hotkeys/__workshop__/plain.tsx +1 -1
- package/src/core/components/hotkeys/hotkeys.tsx +4 -15
- package/src/core/components/menu/__workshop__/asComponent.tsx +1 -1
- package/src/core/components/menu/__workshop__/avatarMenu.tsx +1 -1
- package/src/core/components/menu/__workshop__/closableMenuButton.tsx +1 -1
- package/src/core/components/menu/__workshop__/constrainedInBoundary.tsx +3 -3
- package/src/core/components/menu/__workshop__/customMenuItem.tsx +1 -1
- package/src/core/components/menu/__workshop__/customSelectedState.tsx +1 -1
- package/src/core/components/menu/__workshop__/disableFocusOnClose.tsx +1 -1
- package/src/core/components/menu/__workshop__/groups.tsx +1 -1
- package/src/core/components/menu/__workshop__/index.ts +5 -3
- package/src/core/components/menu/__workshop__/menuButton.tsx +2 -2
- package/src/core/components/menu/__workshop__/menuGroupRight.tsx +1 -1
- package/src/core/components/menu/__workshop__/nestedMenu.tsx +1 -1
- package/src/core/components/menu/__workshop__/onCloseMenuButton.tsx +1 -1
- package/src/core/components/menu/__workshop__/selectedItem.tsx +1 -1
- package/src/core/components/menu/__workshop__/shouldFocus.tsx +1 -1
- package/src/core/components/menu/__workshop__/tones.tsx +3 -3
- package/src/core/components/menu/__workshop__/withoutArrow.tsx +1 -1
- package/src/core/components/menu/menu.test.tsx +2 -1
- package/src/core/components/menu/menu.tsx +7 -22
- package/src/core/components/menu/menuButton.tsx +4 -50
- package/src/core/components/menu/menuContext.ts +3 -15
- package/src/core/components/menu/menuDivider.tsx +2 -2
- package/src/core/components/menu/menuGroup.tsx +10 -15
- package/src/core/components/menu/menuItem.tsx +7 -18
- package/src/core/components/tab/__workshop__/example.tsx +1 -1
- package/src/core/components/tab/__workshop__/index.ts +5 -3
- package/src/core/components/tab/tab.tsx +6 -4
- package/src/core/components/tab/tabList.tsx +3 -8
- package/src/core/components/tab/tabPanel.tsx +2 -2
- package/src/core/components/toast/__workshop__/hook.tsx +1 -1
- package/src/core/components/toast/__workshop__/index.ts +5 -3
- package/src/core/components/toast/__workshop__/toast.tsx +1 -1
- package/src/core/components/toast/toast.test.tsx +2 -1
- package/src/core/components/toast/toast.tsx +2 -2
- package/src/core/components/toast/toastContext.ts +4 -4
- package/src/core/components/toast/toastLayer.tsx +3 -3
- package/src/core/components/tree/__workshop__/basic.perf.ts +1 -1
- package/src/core/components/tree/__workshop__/basic.tsx +1 -1
- package/src/core/components/tree/__workshop__/index.ts +5 -3
- package/src/core/components/tree/__workshop__/tabFromElement.tsx +1 -1
- package/src/core/components/tree/tree.tsx +8 -9
- package/src/core/components/tree/treeContext.ts +4 -4
- package/src/core/components/tree/treeGroup.tsx +6 -8
- package/src/core/components/tree/treeItem.tsx +4 -4
- package/src/core/components/tree/types.ts +1 -1
- package/src/core/components/virtualList/__workshop__/changingProps.tsx +1 -1
- package/src/core/components/virtualList/__workshop__/elementScroll.tsx +1 -1
- package/src/core/components/virtualList/__workshop__/index.ts +5 -3
- package/src/core/components/virtualList/__workshop__/infiniteList.tsx +1 -1
- package/src/core/components/virtualList/__workshop__/windowScrolll.tsx +1 -1
- package/src/core/components/virtualList/virtualList.tsx +2 -2
- package/src/core/constants.ts +0 -18
- package/src/core/hooks/useMediaIndex/__workshop__/index.ts +5 -3
- package/src/core/hooks/useMediaIndex/__workshop__/test.tsx +1 -1
- package/src/core/hooks/useMediaIndex/useMediaIndex.ts +6 -1
- package/src/core/index.ts +1 -24
- package/src/core/lib/createGlobalScopedContext.ts +1 -1
- package/src/core/lib/globalScope.ts +1 -1
- package/src/core/observers/elementSize.ts +1 -1
- package/src/core/primitives/arrow/arrow.tsx +2 -2
- package/src/core/primitives/avatar/__workshop__/asButton.tsx +1 -1
- package/src/core/primitives/avatar/__workshop__/index.ts +5 -3
- package/src/core/primitives/avatar/__workshop__/stack.tsx +1 -1
- package/src/core/primitives/avatar/__workshop__/withinButton.tsx +1 -1
- package/src/core/primitives/avatar/__workshop__/withinMenuItem.tsx +1 -1
- package/src/core/primitives/avatar/avatar.tsx +3 -10
- package/src/core/primitives/avatar/avatarCounter.tsx +2 -2
- package/src/core/primitives/avatar/avatarStack.tsx +2 -4
- package/src/core/primitives/avatar/types.ts +0 -32
- package/src/core/primitives/badge/__workshop__/index.ts +5 -3
- package/src/core/primitives/badge/__workshop__/props.tsx +1 -1
- package/src/core/primitives/badge/__workshop__/tones.tsx +3 -3
- package/src/core/primitives/badge/badge.test.tsx +2 -1
- package/src/core/primitives/badge/badge.tsx +12 -11
- package/src/core/primitives/box/__workshop__/index.ts +5 -3
- package/src/core/primitives/box/__workshop__/props.tsx +1 -1
- package/src/core/primitives/box/__workshop__/responsive.tsx +1 -1
- package/src/core/primitives/box/box.tsx +28 -32
- package/src/core/primitives/button/__workshop__/custom.tsx +5 -5
- package/src/core/primitives/button/__workshop__/customIcons.tsx +1 -1
- package/src/core/primitives/button/__workshop__/disabled.tsx +3 -3
- package/src/core/primitives/button/__workshop__/index.ts +5 -3
- package/src/core/primitives/button/__workshop__/mixedChildren.tsx +1 -1
- package/src/core/primitives/button/__workshop__/props.tsx +1 -1
- package/src/core/primitives/button/__workshop__/sanityUploadButton.tsx +1 -1
- package/src/core/primitives/button/__workshop__/stacked.tsx +1 -1
- package/src/core/primitives/button/__workshop__/styled1.tsx +1 -1
- package/src/core/primitives/button/__workshop__/styled2.tsx +1 -1
- package/src/core/primitives/button/__workshop__/textOverflow.tsx +1 -1
- package/src/core/primitives/button/__workshop__/uploadButton.tsx +1 -1
- package/src/core/primitives/button/button.test.tsx +2 -1
- package/src/core/primitives/button/button.tsx +4 -7
- package/src/core/primitives/button/types.ts +0 -20
- package/src/core/primitives/card/__workshop__/asButton.tsx +2 -2
- package/src/core/primitives/card/__workshop__/asComponent.tsx +1 -1
- package/src/core/primitives/card/__workshop__/checkered.tsx +3 -3
- package/src/core/primitives/card/__workshop__/index.ts +5 -3
- package/src/core/primitives/card/__workshop__/interactive.tsx +1 -1
- package/src/core/primitives/card/__workshop__/listNavigation.tsx +1 -1
- package/src/core/primitives/card/__workshop__/props.tsx +1 -1
- package/src/core/primitives/card/__workshop__/selected.tsx +1 -1
- package/src/core/primitives/card/__workshop__/styled.tsx +1 -1
- package/src/core/primitives/card/__workshop__/tones.tsx +3 -3
- package/src/core/primitives/card/card.tsx +4 -2
- package/src/core/primitives/card/cardContext.ts +1 -1
- package/src/core/primitives/card/cardProvider.tsx +4 -4
- package/src/core/primitives/card/types.ts +5 -19
- package/src/core/primitives/checkbox/__workshop__/example.tsx +1 -1
- package/src/core/primitives/checkbox/__workshop__/index.ts +5 -3
- package/src/core/primitives/checkbox/__workshop__/props.tsx +1 -1
- package/src/core/primitives/checkbox/__workshop__/readOnly.tsx +1 -1
- package/src/core/primitives/checkbox/__workshop__/tones.tsx +3 -3
- package/src/core/primitives/checkbox/checkbox.tsx +2 -2
- package/src/core/primitives/code/__workshop__/index.ts +5 -3
- package/src/core/primitives/code/__workshop__/opticalAlignment.tsx +1 -1
- package/src/core/primitives/code/__workshop__/props.tsx +1 -1
- package/src/core/primitives/code/code.tsx +4 -2
- package/src/core/primitives/code/refractor.tsx +1 -1
- package/src/core/primitives/container/__workshop__/example.tsx +1 -1
- package/src/core/primitives/container/__workshop__/index.ts +5 -3
- package/src/core/primitives/container/container.tsx +2 -2
- package/src/core/primitives/flex/__workshop__/example.tsx +1 -1
- package/src/core/primitives/flex/__workshop__/gap.tsx +1 -1
- package/src/core/primitives/flex/__workshop__/index.ts +5 -3
- package/src/core/primitives/flex/flex.tsx +4 -2
- package/src/core/primitives/grid/__workshop__/index.ts +5 -3
- package/src/core/primitives/grid/__workshop__/responsive.tsx +3 -3
- package/src/core/primitives/grid/grid.tsx +4 -2
- package/src/core/primitives/heading/__workshop__/index.ts +5 -3
- package/src/core/primitives/heading/__workshop__/opticalAlignment.tsx +1 -1
- package/src/core/primitives/heading/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/heading/heading.tsx +2 -4
- package/src/core/primitives/inline/__workshop__/index.ts +5 -3
- package/src/core/primitives/inline/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/inline/inline.tsx +4 -11
- package/src/core/primitives/kbd/__workshop__/index.ts +5 -3
- package/src/core/primitives/kbd/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/kbd/kbd.tsx +4 -2
- package/src/core/primitives/label/__workshop__/index.ts +5 -3
- package/src/core/primitives/label/__workshop__/opticalAlignment.tsx +1 -1
- package/src/core/primitives/label/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/label/label.tsx +2 -4
- package/src/core/primitives/layer/__workshop__/_debug.tsx +1 -1
- package/src/core/primitives/layer/__workshop__/index.ts +5 -3
- package/src/core/primitives/layer/__workshop__/multipleRoots.tsx +1 -1
- package/src/core/primitives/layer/__workshop__/nested.tsx +1 -1
- package/src/core/primitives/layer/__workshop__/responsiveZOffset.tsx +1 -1
- package/src/core/primitives/layer/layer.test.tsx +2 -1
- package/src/core/primitives/layer/layer.tsx +2 -2
- package/src/core/primitives/layer/layerCard.tsx +2 -2
- package/src/core/primitives/layer/layerContext.ts +4 -4
- package/src/core/primitives/layer/layerProvider.tsx +2 -10
- package/src/core/primitives/popover/__workshop__/AlignedStory.tsx +2 -2
- package/src/core/primitives/popover/__workshop__/MarginsStory.tsx +1 -1
- package/src/core/primitives/popover/__workshop__/MatchReferenceWidthStory.tsx +1 -1
- package/src/core/primitives/popover/__workshop__/OpenOnMountStory.tsx +1 -1
- package/src/core/primitives/popover/__workshop__/PlainStory.tsx +2 -2
- package/src/core/primitives/popover/__workshop__/RecursiveStory.tsx +3 -3
- package/src/core/primitives/popover/__workshop__/SidePanelStory.tsx +3 -3
- package/src/core/primitives/popover/__workshop__/index.ts +5 -3
- package/src/core/primitives/popover/popover.tsx +34 -17
- package/src/core/primitives/popover/popoverLayer.tsx +2 -2
- package/src/core/primitives/radio/__workshop__/example.tsx +1 -1
- package/src/core/primitives/radio/__workshop__/index.ts +5 -3
- package/src/core/primitives/radio/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/radio/radio.tsx +2 -2
- package/src/core/primitives/select/__workshop__/index.ts +5 -3
- package/src/core/primitives/select/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/select/__workshop__/readOnly.tsx +1 -1
- package/src/core/primitives/select/select.tsx +5 -15
- package/src/core/primitives/selectable/selectable.tsx +4 -4
- package/src/core/primitives/skeleton/__workshop__/delay.tsx +1 -1
- package/src/core/primitives/skeleton/__workshop__/index.ts +5 -3
- package/src/core/primitives/skeleton/__workshop__/skeleton.tsx +2 -2
- package/src/core/primitives/skeleton/codeSkeleton.tsx +2 -2
- package/src/core/primitives/skeleton/headingSkeleton.tsx +2 -2
- package/src/core/primitives/skeleton/labelSkeleton.tsx +2 -2
- package/src/core/primitives/skeleton/skeleton.tsx +2 -2
- package/src/core/primitives/skeleton/textSkeleton.tsx +2 -2
- package/src/core/primitives/spinner/__workshop__/Props.tsx +1 -1
- package/src/core/primitives/spinner/__workshop__/index.ts +5 -3
- package/src/core/primitives/spinner/animatedSpinnerIcon.tsx +2 -2
- package/src/core/primitives/spinner/spinner.tsx +2 -2
- package/src/core/primitives/srOnly/srOnly.tsx +2 -2
- package/src/core/primitives/stack/__workshop__/index.ts +5 -3
- package/src/core/primitives/stack/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/stack/stack.tsx +5 -10
- package/src/core/primitives/switch/__workshop__/example.tsx +1 -1
- package/src/core/primitives/switch/__workshop__/index.ts +5 -3
- package/src/core/primitives/switch/__workshop__/props.tsx +1 -1
- package/src/core/primitives/switch/switch.tsx +2 -2
- package/src/core/primitives/text/__workshop__/colored.tsx +1 -1
- package/src/core/primitives/text/__workshop__/example.tsx +1 -1
- package/src/core/primitives/text/__workshop__/index.ts +5 -3
- package/src/core/primitives/text/__workshop__/opticalAlignment.tsx +1 -1
- package/src/core/primitives/text/text.tsx +4 -4
- package/src/core/primitives/textArea/__workshop__/index.ts +5 -3
- package/src/core/primitives/textArea/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/textArea/textArea.tsx +5 -15
- package/src/core/primitives/textInput/__workshop__/clearButton.tsx +1 -1
- package/src/core/primitives/textInput/__workshop__/customValidity.tsx +1 -1
- package/src/core/primitives/textInput/__workshop__/index.ts +5 -3
- package/src/core/primitives/textInput/__workshop__/plain.tsx +1 -1
- package/src/core/primitives/textInput/__workshop__/readOnly.tsx +1 -1
- package/src/core/primitives/textInput/__workshop__/states.tsx +1 -1
- package/src/core/primitives/textInput/__workshop__/tones.tsx +1 -1
- package/src/core/primitives/textInput/__workshop__/typed.tsx +1 -1
- package/src/core/primitives/textInput/textInput.tsx +6 -9
- package/src/core/primitives/tooltip/__workshop__/customPortal.tsx +1 -1
- package/src/core/primitives/tooltip/__workshop__/index.ts +5 -3
- package/src/core/primitives/tooltip/__workshop__/overflowingBoundary.tsx +1 -1
- package/src/core/primitives/tooltip/__workshop__/props.tsx +1 -1
- package/src/core/primitives/tooltip/__workshop__/resizableBoundary.tsx +1 -1
- package/src/core/primitives/tooltip/constants.ts +1 -1
- package/src/core/primitives/tooltip/tooltip.test.tsx +2 -4
- package/src/core/primitives/tooltip/tooltip.tsx +5 -9
- package/src/core/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupContext.tsx +4 -2
- package/src/core/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupProvider.tsx +5 -3
- package/src/core/primitives/tooltip/tooltipLayer.tsx +2 -2
- package/src/core/{types/props.ts → types.ts} +27 -0
- package/src/core/utils/boundaryElement/__workshop__/index.ts +5 -3
- package/src/core/utils/boundaryElement/__workshop__/plain.tsx +1 -1
- package/src/core/utils/boundaryElement/boundaryElement.test.tsx +2 -1
- package/src/core/utils/boundaryElement/boundaryElementContext.ts +7 -4
- package/src/core/utils/boundaryElement/boundaryElementProvider.tsx +2 -2
- package/src/core/utils/elementQuery/__workshop__/customMedia.tsx +1 -1
- package/src/core/utils/elementQuery/__workshop__/index.ts +5 -3
- package/src/core/utils/elementQuery/elementQuery.tsx +2 -2
- package/src/core/utils/getElementRef.ts +1 -1
- package/src/core/utils/portal/__workshop__/index.ts +5 -3
- package/src/core/utils/portal/__workshop__/named.tsx +1 -1
- package/src/core/utils/portal/portal.test.tsx +2 -1
- package/src/core/utils/portal/portalContext.ts +5 -2
- package/src/core/utils/portal/portalProvider.tsx +5 -9
- package/src/css/_responsiveClassName.ts +2 -2
- package/src/css/_style.css.ts +1 -1
- package/src/css/components/breadcrumbs/breadcrumbs.css.ts +1 -1
- package/src/css/components/dialog/dialog.css.ts +9 -17
- package/src/css/components/menu/menu.css.ts +2 -2
- package/src/css/components/menu/menu.ts +2 -2
- package/src/css/components/skeleton/skeleton.css.ts +2 -6
- package/src/css/components/toast/toast.css.ts +2 -2
- package/src/css/components/toast/toast.ts +2 -2
- package/src/css/components/tree/tree.css.ts +1 -1
- package/src/css/components/tree/tree.ts +1 -1
- package/src/css/defaultTheme.css.ts +59 -60
- package/src/css/layers.css.ts +4 -1
- package/src/css/primitives/_arrow/_arrow.css.ts +5 -5
- package/src/css/primitives/_input/_input.css.ts +4 -4
- package/src/css/primitives/_selectable/_selectable.css.ts +4 -4
- package/src/css/primitives/_selectable/types.ts +2 -2
- package/src/css/primitives/avatar/avatar.css.ts +10 -10
- package/src/css/primitives/badge/badge.css.ts +4 -4
- package/src/css/primitives/badge/types.ts +8 -2
- package/src/css/primitives/box/box.css.ts +2 -2
- package/src/css/primitives/button/button.css.ts +6 -6
- package/src/css/primitives/button/button.ts +2 -2
- package/src/css/primitives/button/types.ts +3 -3
- package/src/css/primitives/card/__workshop__/color.tsx +9 -9
- package/src/css/primitives/card/__workshop__/index.ts +5 -3
- package/src/css/primitives/card/card.css.ts +12 -18
- package/src/css/primitives/card/types.ts +3 -3
- package/src/css/primitives/checkbox/checkbox.css.ts +3 -3
- package/src/css/primitives/checkbox/checkbox.ts +3 -3
- package/src/css/primitives/code/code.css.ts +4 -3
- package/src/css/primitives/code/types.ts +3 -4
- package/src/css/primitives/container/container.css.ts +1 -1
- package/src/css/primitives/heading/heading.css.ts +5 -4
- package/src/css/primitives/heading/types.ts +3 -6
- package/src/css/primitives/kbd/kbd.css.ts +1 -1
- package/src/css/primitives/label/label.css.ts +5 -4
- package/src/css/primitives/label/types.ts +0 -8
- package/src/css/primitives/popover/popover.css.ts +2 -2
- package/src/css/primitives/popover/popover.ts +2 -2
- package/src/css/primitives/radio/radio.css.ts +3 -3
- package/src/css/primitives/radio/radio.ts +3 -3
- package/src/css/primitives/root/root.css.ts +2 -2
- package/src/css/primitives/root/root.ts +2 -2
- package/src/css/primitives/root/types.ts +3 -3
- package/src/css/primitives/select/select.css.ts +3 -3
- package/src/css/primitives/spinner/spinner.css.ts +2 -6
- package/src/css/primitives/spinner/spinner.ts +2 -2
- package/src/css/primitives/srOnly/srOnly.css.ts +1 -1
- package/src/css/primitives/srOnly/srOnly.ts +1 -1
- package/src/css/primitives/stack/stack.css.ts +1 -1
- package/src/css/primitives/stack/stack.ts +1 -1
- package/src/css/primitives/switch/switch.css.ts +5 -5
- package/src/css/primitives/text/text.css.ts +5 -4
- package/src/css/primitives/text/types.ts +3 -5
- package/src/css/primitives/textArea/textArea.css.ts +1 -1
- package/src/css/primitives/textInput/textInput.css.ts +4 -4
- package/src/css/primitives/tooltip/tooltip.css.ts +1 -1
- package/src/css/props/alignItems/alignItems.ts +1 -1
- package/src/css/props/border/border.ts +1 -16
- package/src/css/props/boxSizing/boxSizing.css.ts +2 -1
- package/src/css/props/boxSizing/boxSizing.ts +0 -3
- package/src/css/props/display/display.ts +1 -10
- package/src/css/props/flex/flex.ts +1 -1
- package/src/css/props/flexDirection/flexDirection.ts +1 -1
- package/src/css/props/flexWrap/flexWrap.ts +1 -1
- package/src/css/props/font/font.css.ts +3 -2
- package/src/css/props/font/font.ts +1 -1
- package/src/css/props/gap/gap.ts +1 -1
- package/src/css/props/gridAutoColumns/gridAutoColumns.css.ts +2 -2
- package/src/css/props/gridAutoColumns/gridAutoColumns.ts +2 -2
- package/src/css/props/gridAutoColumns/types.ts +0 -10
- package/src/css/props/gridAutoFlow/gridAutoFlow.ts +2 -2
- package/src/css/props/gridAutoFlow/types.ts +0 -4
- package/src/css/props/gridAutoRows/gridAutoRows.ts +2 -2
- package/src/css/props/gridAutoRows/types.ts +0 -4
- package/src/css/props/gridColumn/gridColumn.ts +3 -3
- package/src/css/props/gridColumn/types.ts +0 -10
- package/src/css/props/gridColumnEnd/gridColumnEnd.ts +3 -3
- package/src/css/props/gridColumnEnd/types.ts +0 -10
- package/src/css/props/gridColumnStart/gridColumnStart.ts +3 -6
- package/src/css/props/gridColumnStart/types.ts +0 -10
- package/src/css/props/gridRow/gridRow.ts +3 -3
- package/src/css/props/gridRow/types.ts +0 -10
- package/src/css/props/gridRowEnd/gridRowEnd.ts +3 -3
- package/src/css/props/gridRowEnd/types.ts +0 -10
- package/src/css/props/gridRowStart/gridRowStart.ts +3 -3
- package/src/css/props/gridRowStart/types.ts +0 -10
- package/src/css/props/gridTemplateColumns/gridTemplateColumns.ts +2 -2
- package/src/css/props/gridTemplateColumns/types.ts +0 -10
- package/src/css/props/gridTemplateRows/gridTemplateRows.ts +2 -2
- package/src/css/props/gridTemplateRows/types.ts +0 -10
- package/src/css/props/height/height.ts +1 -1
- package/src/css/props/height/types.ts +0 -6
- package/src/css/props/inset/inset.ts +1 -1
- package/src/css/props/justifyContent/justifyContent.ts +1 -1
- package/src/css/props/margin/margin.ts +1 -1
- package/src/css/props/maxWidth/maxWidth.ts +1 -1
- package/src/css/props/minHeight/minHeight.ts +1 -1
- package/src/css/props/minWidth/minWidth.ts +1 -1
- package/src/css/props/outline/outline.ts +1 -1
- package/src/css/props/overflow/overflow.ts +1 -1
- package/src/css/props/overflow/types.ts +0 -6
- package/src/css/props/padding/padding.ts +1 -1
- package/src/css/props/pointerEvents/pointerEvents.ts +1 -1
- package/src/css/props/position/position.ts +1 -1
- package/src/css/props/radius/radius.ts +1 -1
- package/src/css/props/shadow/shadow.ts +1 -1
- package/src/css/props/textAlign/textAlign.ts +1 -1
- package/src/css/props/textOverflow/textOverflow.ts +1 -1
- package/src/css/props/width/width.ts +1 -1
- package/src/css/types.ts +225 -53
- package/src/css/util.ts +2 -2
- package/src/css/vars.css.ts +33 -36
- package/src/theme/{v3/_parseColorToken.ts → _parseColorToken.ts} +2 -2
- package/src/theme/buildTheme.ts +33 -0
- package/src/theme/constants.ts +90 -0
- package/src/theme/defaults/color.ts +197 -0
- package/src/theme/{v2/defaults/config.ts → defaults/common.ts} +3 -16
- package/src/theme/{v3/defaultFonts.ts → defaults/fonts.ts} +2 -2
- package/src/theme/index.ts +4 -5
- package/src/theme/{v3/resolveTokens.ts → resolveTokens.ts} +15 -15
- package/src/theme/types.ts +355 -15
- package/dist/css/layers.css +0 -4
- package/dist/css/primitives/popover/popover.css +0 -4
- package/src/core/__DEV__.ts +0 -5
- package/src/core/_compat/helpers.ts +0 -72
- package/src/core/_compat/styles/_responsive.ts +0 -19
- package/src/core/_compat/theme/theme.test.tsx +0 -73
- package/src/core/_compat/theme/themeColorProvider.tsx +0 -24
- package/src/core/_compat/theme/themeContext.ts +0 -10
- package/src/core/_compat/theme/themeProvider.tsx +0 -68
- package/src/core/_compat/theme/types.ts +0 -10
- package/src/core/_compat/theme/useRootTheme.ts +0 -15
- package/src/core/_compat/theme/useTheme.ts +0 -12
- package/src/core/_compat/types.ts +0 -191
- package/src/core/hooks/useArrayProp.ts +0 -26
- package/src/core/hooks/useClickOutside.test.tsx +0 -481
- package/src/core/hooks/useClickOutside.ts +0 -113
- package/src/core/hooks/useElementRect/__workshop__/example.tsx +0 -30
- package/src/core/hooks/useElementRect/__workshop__/index.ts +0 -14
- package/src/core/hooks/useElementRect/useElementRect.ts +0 -13
- package/src/core/hooks/useForwardedRef.ts +0 -19
- package/src/core/hooks/useIsomorphicEffect.ts +0 -7
- package/src/core/primitives/badge/types.ts +0 -18
- package/src/core/primitives/box/types.ts +0 -22
- package/src/core/primitives/flex/types.ts +0 -27
- package/src/core/primitives/grid/types.ts +0 -17
- package/src/core/primitives/selectable/types.ts +0 -7
- package/src/core/primitives/types.ts +0 -153
- package/src/core/types/gridItem.ts +0 -32
- package/src/core/types/placement.ts +0 -18
- package/src/core/types/radius.ts +0 -7
- package/src/core/types/textAlign.ts +0 -7
- package/src/core/utils/spanWithTextOverflow.tsx +0 -10
- package/src/theme/getScopedTheme.ts +0 -88
- package/src/theme/v0/avatar.ts +0 -10
- package/src/theme/v0/color/_generic.ts +0 -35
- package/src/theme/v0/color/_system.ts +0 -17
- package/src/theme/v0/color/base.ts +0 -21
- package/src/theme/v0/color/button.ts +0 -42
- package/src/theme/v0/color/card.ts +0 -19
- package/src/theme/v0/color/color.ts +0 -40
- package/src/theme/v0/color/index.ts +0 -11
- package/src/theme/v0/color/input.ts +0 -34
- package/src/theme/v0/color/muted.ts +0 -26
- package/src/theme/v0/color/selectable.ts +0 -31
- package/src/theme/v0/color/solid.ts +0 -26
- package/src/theme/v0/color/spot.ts +0 -13
- package/src/theme/v0/css.ts +0 -10
- package/src/theme/v0/focusRing.ts +0 -5
- package/src/theme/v0/font.ts +0 -40
- package/src/theme/v0/index.ts +0 -10
- package/src/theme/v0/input.ts +0 -23
- package/src/theme/v0/layer.ts +0 -6
- package/src/theme/v0/shadow.ts +0 -15
- package/src/theme/v0/styles.ts +0 -13
- package/src/theme/v0/theme.ts +0 -72
- package/src/theme/v2/avatar.ts +0 -12
- package/src/theme/v2/build/_deprecated/color/_selectable/createSelectableTones.ts +0 -76
- package/src/theme/v2/build/_deprecated/color/_solid/createSolidTones.ts +0 -54
- package/src/theme/v2/build/_deprecated/color/button/createButtonModes.ts +0 -22
- package/src/theme/v2/build/_deprecated/color/button/createButtonTones.ts +0 -55
- package/src/theme/v2/build/_deprecated/color/card/createCardStates.ts +0 -60
- package/src/theme/v2/build/_deprecated/color/color.test.ts +0 -63
- package/src/theme/v2/build/_deprecated/color/defaults.ts +0 -390
- package/src/theme/v2/build/_deprecated/color/factory.ts +0 -141
- package/src/theme/v2/build/_deprecated/color/index.ts +0 -1
- package/src/theme/v2/build/_deprecated/color/input/createInputModes.ts +0 -86
- package/src/theme/v2/build/_deprecated/color/muted/createMuted.ts +0 -54
- package/src/theme/v2/build/_deprecated/color/spot/createSpot.ts +0 -20
- package/src/theme/v2/build/buildColorTheme.test.ts +0 -185
- package/src/theme/v2/build/buildColorTheme.ts +0 -494
- package/src/theme/v2/build/buildTheme.test.ts +0 -89
- package/src/theme/v2/build/buildTheme.ts +0 -37
- package/src/theme/v2/build/colorToken/colorToken.ts +0 -19
- package/src/theme/v2/build/colorToken/compileColorToken.ts +0 -21
- package/src/theme/v2/build/colorToken/index.ts +0 -2
- package/src/theme/v2/build/colorToken/types.ts +0 -6
- package/src/theme/v2/build/index.ts +0 -3
- package/src/theme/v2/build/lib/color-fns/blend/index.ts +0 -3
- package/src/theme/v2/build/lib/color-fns/blend/mix.ts +0 -21
- package/src/theme/v2/build/lib/color-fns/blend/multiply.ts +0 -18
- package/src/theme/v2/build/lib/color-fns/blend/screen.ts +0 -18
- package/src/theme/v2/build/lib/color-fns/color-fns.test.ts +0 -68
- package/src/theme/v2/build/lib/color-fns/contrastRatio.ts +0 -34
- package/src/theme/v2/build/lib/color-fns/convert.ts +0 -150
- package/src/theme/v2/build/lib/color-fns/index.ts +0 -6
- package/src/theme/v2/build/lib/color-fns/parse.ts +0 -60
- package/src/theme/v2/build/lib/color-fns/rgba.ts +0 -14
- package/src/theme/v2/build/lib/color-fns/types.ts +0 -28
- package/src/theme/v2/build/lib/isRecord.ts +0 -3
- package/src/theme/v2/build/lib/utils.ts +0 -19
- package/src/theme/v2/build/merge.ts +0 -28
- package/src/theme/v2/build/mixThemeColor.test.ts +0 -23
- package/src/theme/v2/build/mixThemeColor.ts +0 -53
- package/src/theme/v2/build/renderColorTheme.ts +0 -532
- package/src/theme/v2/build/renderColorValue.ts +0 -85
- package/src/theme/v2/build/resolveColorTokens.ts +0 -268
- package/src/theme/v2/color/_constants.ts +0 -45
- package/src/theme/v2/color/_helpers.ts +0 -24
- package/src/theme/v2/color/_system.ts +0 -38
- package/src/theme/v2/color/avatar.ts +0 -11
- package/src/theme/v2/color/badge.ts +0 -12
- package/src/theme/v2/color/button.ts +0 -11
- package/src/theme/v2/color/color.ts +0 -28
- package/src/theme/v2/color/index.ts +0 -13
- package/src/theme/v2/color/input.ts +0 -23
- package/src/theme/v2/color/kbd.ts +0 -6
- package/src/theme/v2/color/selectable.ts +0 -8
- package/src/theme/v2/color/shadow.ts +0 -7
- package/src/theme/v2/color/state.ts +0 -41
- package/src/theme/v2/color/syntax.ts +0 -39
- package/src/theme/v2/config/helpers.ts +0 -48
- package/src/theme/v2/config/index.ts +0 -4
- package/src/theme/v2/config/system.ts +0 -114
- package/src/theme/v2/config/tokens/color/index.ts +0 -1
- package/src/theme/v2/config/tokens/color/types.ts +0 -137
- package/src/theme/v2/config/tokens/index.ts +0 -3
- package/src/theme/v2/config/tokens/parseTokenValue.test.ts +0 -44
- package/src/theme/v2/config/tokens/parseTokenValue.ts +0 -133
- package/src/theme/v2/config/tokens/types.ts +0 -53
- package/src/theme/v2/config/types.ts +0 -47
- package/src/theme/v2/defaults/colorPalette.ts +0 -5
- package/src/theme/v2/defaults/colorTokens.ts +0 -648
- package/src/theme/v2/defaults/fonts.ts +0 -227
- package/src/theme/v2/index.ts +0 -6
- package/src/theme/v2/input.ts +0 -31
- package/src/theme/v2/theme.ts +0 -45
- package/src/theme/v3/_constants.ts +0 -29
- package/src/theme/v3/buildTheme_v3.ts +0 -39
- package/src/theme/v3/color/_constants.ts +0 -15
- package/src/theme/v3/color/avatar.ts +0 -14
- package/src/theme/v3/color/card.ts +0 -79
- package/src/theme/v3/color/color.ts +0 -98
- package/src/theme/v3/color/element.ts +0 -19
- package/src/theme/v3/color/index.ts +0 -7
- package/src/theme/v3/color/token.ts +0 -32
- package/src/theme/v3/color/tokens.ts +0 -5
- package/src/theme/v3/defaultTokens.ts +0 -199
- package/src/theme/v3/index.ts +0 -9
- package/src/theme/v3/palette/constants.ts +0 -15
- package/src/theme/v3/palette/index.ts +0 -2
- package/src/theme/v3/palette/types.ts +0 -7
- package/src/theme/v3/tokens.ts +0 -16
- package/src/theme/v3/types.ts +0 -133
- package/src/theme/versioning/getTheme_v2.ts +0 -58
- package/src/theme/versioning/index.ts +0 -1
- package/src/theme/versioning/is_v0.ts +0 -7
- package/src/theme/versioning/is_v2.ts +0 -7
- package/src/theme/versioning/themeColor_v0_v2.ts +0 -245
- package/src/theme/versioning/themeColor_v2_v2_9.ts +0 -49
- package/src/theme/versioning/themeColor_v3_v2.ts +0 -383
- package/src/theme/versioning/v0_v2.ts +0 -95
- package/src/theme/versioning/v2_v0.ts +0 -127
- package/src/theme/versioning/v3_v2.ts +0 -130
- /package/src/theme/{v3/merge.ts → merge.ts} +0 -0
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import {expect, test} from 'vitest'
|
|
2
|
-
|
|
3
|
-
import {defaultColorPalette} from '../defaults/colorPalette'
|
|
4
|
-
import {buildTheme} from './buildTheme'
|
|
5
|
-
|
|
6
|
-
test('build theme', () => {
|
|
7
|
-
const rootTheme = buildTheme({
|
|
8
|
-
palette: {
|
|
9
|
-
...defaultColorPalette,
|
|
10
|
-
black: '#000000',
|
|
11
|
-
white: '#ffffff',
|
|
12
|
-
},
|
|
13
|
-
color: {
|
|
14
|
-
base: {
|
|
15
|
-
default: {
|
|
16
|
-
bg: ['white/0', 'black/0'],
|
|
17
|
-
fg: ['black', 'white'],
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
button: {
|
|
21
|
-
ghost: {
|
|
22
|
-
default: {
|
|
23
|
-
'*': {
|
|
24
|
-
border: ['white/0', 'black/0'],
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
const {color} = rootTheme.v2!
|
|
33
|
-
|
|
34
|
-
expect({
|
|
35
|
-
light: {
|
|
36
|
-
bg: color.light.default.bg,
|
|
37
|
-
fg: color.light.default.fg,
|
|
38
|
-
default: {
|
|
39
|
-
button: {
|
|
40
|
-
ghost: {
|
|
41
|
-
enabled: {
|
|
42
|
-
border: color.light.default.button.ghost.default.enabled.border,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
dark: {
|
|
49
|
-
bg: color.dark.default.bg,
|
|
50
|
-
fg: color.dark.default.fg,
|
|
51
|
-
default: {
|
|
52
|
-
button: {
|
|
53
|
-
ghost: {
|
|
54
|
-
enabled: {
|
|
55
|
-
border: color.dark.default.button.ghost.default.enabled.border,
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
}).toEqual({
|
|
62
|
-
light: {
|
|
63
|
-
bg: 'rgba(255,255,255,0)',
|
|
64
|
-
fg: '#000000',
|
|
65
|
-
default: {
|
|
66
|
-
button: {
|
|
67
|
-
ghost: {
|
|
68
|
-
enabled: {
|
|
69
|
-
border: 'rgba(246,246,248,0)',
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
dark: {
|
|
76
|
-
bg: 'rgba(0,0,0,0)',
|
|
77
|
-
fg: '#ffffff',
|
|
78
|
-
default: {
|
|
79
|
-
button: {
|
|
80
|
-
ghost: {
|
|
81
|
-
enabled: {
|
|
82
|
-
border: 'rgba(19,20,27,0)',
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
})
|
|
89
|
-
})
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type {RootTheme} from '../../types'
|
|
2
|
-
import {v2_v0} from '../../versioning/v2_v0'
|
|
3
|
-
import type {ThemeConfig} from '../config'
|
|
4
|
-
import {defaultThemeConfig} from '../defaults/config'
|
|
5
|
-
import {defaultThemeFonts} from '../defaults/fonts'
|
|
6
|
-
import type {RootTheme_v2} from '../theme'
|
|
7
|
-
import {buildColorTheme} from './buildColorTheme'
|
|
8
|
-
import {renderThemeColorSchemes} from './renderColorTheme'
|
|
9
|
-
|
|
10
|
-
/** @internal */
|
|
11
|
-
export function buildTheme(config?: ThemeConfig): RootTheme {
|
|
12
|
-
const colorTheme = buildColorTheme(config)
|
|
13
|
-
|
|
14
|
-
const v2: RootTheme_v2 = {
|
|
15
|
-
_version: 2,
|
|
16
|
-
avatar: config?.avatar ?? defaultThemeConfig.avatar,
|
|
17
|
-
button: config?.button ?? defaultThemeConfig.button,
|
|
18
|
-
card: config?.card ?? defaultThemeConfig.card,
|
|
19
|
-
// How colors are generated:
|
|
20
|
-
// 1. Merge custom tokens with default tokens
|
|
21
|
-
// 2. Generate tree of color keys (gray/500, black, white, etc.)
|
|
22
|
-
// 3. Apply mixing and render to hex values
|
|
23
|
-
// render(build(mergeWithDefaults()))
|
|
24
|
-
color: renderThemeColorSchemes(colorTheme, config),
|
|
25
|
-
container: config?.container ?? defaultThemeConfig.container,
|
|
26
|
-
font: config?.font ?? defaultThemeFonts,
|
|
27
|
-
input: config?.input ?? defaultThemeConfig.input,
|
|
28
|
-
layer: config?.layer ?? defaultThemeConfig.layer,
|
|
29
|
-
media: config?.media ?? defaultThemeConfig.media,
|
|
30
|
-
radius: config?.radius ?? defaultThemeConfig.radius,
|
|
31
|
-
shadow: config?.shadow ?? defaultThemeConfig.shadow,
|
|
32
|
-
space: config?.space ?? defaultThemeConfig.space,
|
|
33
|
-
style: config?.style ?? defaultThemeConfig.style,
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return v2_v0(v2)
|
|
37
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {parseTokenValue, type ThemeColorTokenValue} from '../../config'
|
|
2
|
-
import {compileColorTokenValue} from './compileColorToken'
|
|
3
|
-
import type {ColorTokenContext} from './types'
|
|
4
|
-
|
|
5
|
-
const DEFAULT_COLOR_TOKEN_VALUE: ThemeColorTokenValue = ['500', '500']
|
|
6
|
-
|
|
7
|
-
export function resolveColorTokenValue(
|
|
8
|
-
context: ColorTokenContext,
|
|
9
|
-
value: ThemeColorTokenValue = DEFAULT_COLOR_TOKEN_VALUE,
|
|
10
|
-
): string {
|
|
11
|
-
const {hue, scheme} = context
|
|
12
|
-
const node = parseTokenValue(value[scheme === 'light' ? 0 : 1])
|
|
13
|
-
|
|
14
|
-
if (!node || node.type !== 'color') {
|
|
15
|
-
throw new Error(`Invalid color token: ${value[0]}`)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return compileColorTokenValue({...node, hue: node.hue || hue})
|
|
19
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type {TokenColorValueNode} from '../../config'
|
|
2
|
-
|
|
3
|
-
export function compileColorTokenValue(node: TokenColorValueNode): string {
|
|
4
|
-
let key = ''
|
|
5
|
-
|
|
6
|
-
if (node.key === 'black' || node.key === 'white') {
|
|
7
|
-
key = node.key
|
|
8
|
-
} else {
|
|
9
|
-
key = `${node.hue}/${node.tint}`
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (node.mix !== undefined) {
|
|
13
|
-
return `${key} ${node.mix * 100}%`
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (node.opacity !== undefined) {
|
|
17
|
-
key += `/${node.opacity}`
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return key
|
|
21
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type {RGB, RGBA} from '../types'
|
|
2
|
-
|
|
3
|
-
function mixChannel(b: number, s: number, weight: number) {
|
|
4
|
-
const diff = s - b
|
|
5
|
-
|
|
6
|
-
const delta = diff * weight
|
|
7
|
-
|
|
8
|
-
return b + delta
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Apply the \`mix\` blend mode
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
export function mix(b: RGB | RGBA, s: RGB | RGBA, weight: number): RGB {
|
|
16
|
-
return {
|
|
17
|
-
r: mixChannel(b.r, s.r, weight),
|
|
18
|
-
g: mixChannel(b.g, s.g, weight),
|
|
19
|
-
b: mixChannel(b.b, s.b, weight),
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type {RGB, RGBA} from '../types'
|
|
2
|
-
|
|
3
|
-
function multiplyChannel(b: number, s: number) {
|
|
4
|
-
return b * s
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Apply the \`multiply\` blend mode
|
|
9
|
-
* Source: https://www.w3.org/TR/compositing-1/#blendingmultiply
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export function multiply(b: RGB | RGBA, s: RGB | RGBA): RGB {
|
|
13
|
-
return {
|
|
14
|
-
r: multiplyChannel(b.r / 255, s.r / 255) * 255,
|
|
15
|
-
g: multiplyChannel(b.g / 255, s.g / 255) * 255,
|
|
16
|
-
b: multiplyChannel(b.b / 255, s.b / 255) * 255,
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type {RGB, RGBA} from '../types'
|
|
2
|
-
|
|
3
|
-
function screenChannel(b: number, s: number) {
|
|
4
|
-
return b + s - b * s
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Apply the \`screen\` blend mode
|
|
9
|
-
* Source: https://www.w3.org/TR/compositing-1/#blendingscreen
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export function screen(b: RGB | RGBA, s: RGB | RGBA): RGB {
|
|
13
|
-
return {
|
|
14
|
-
r: screenChannel(b.r / 255, s.r / 255) * 255,
|
|
15
|
-
g: screenChannel(b.g / 255, s.g / 255) * 255,
|
|
16
|
-
b: screenChannel(b.b / 255, s.b / 255) * 255,
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import {describe, expect, it} from 'vitest'
|
|
2
|
-
|
|
3
|
-
import {multiply, screen} from './blend'
|
|
4
|
-
import {hexToRgb, rgbToHex} from './convert'
|
|
5
|
-
import {parseColor} from './parse'
|
|
6
|
-
import {rgba} from './rgba'
|
|
7
|
-
|
|
8
|
-
const hues = {
|
|
9
|
-
gray: {
|
|
10
|
-
600: '#6e7683',
|
|
11
|
-
},
|
|
12
|
-
blue: {
|
|
13
|
-
500: '#2276fc',
|
|
14
|
-
},
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
describe('color-fns', () => {
|
|
18
|
-
describe('hexToRgb', () => {
|
|
19
|
-
it('should convert hex to RGB', () => {
|
|
20
|
-
const hex = '#ff0000'
|
|
21
|
-
const rgb = hexToRgb(hex)
|
|
22
|
-
|
|
23
|
-
expect(rgbToHex(rgb)).toEqual('#ff0000')
|
|
24
|
-
})
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
describe('screen', () => {
|
|
28
|
-
it('should blend color using the "screen" mode', () => {
|
|
29
|
-
const backdrop = hexToRgb(hues.blue[500])
|
|
30
|
-
const source = hexToRgb(hues.gray[600])
|
|
31
|
-
const rgb = screen(backdrop, source)
|
|
32
|
-
|
|
33
|
-
expect(rgbToHex(rgb)).toEqual('#81b5fe')
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
describe('multiply', () => {
|
|
38
|
-
it('should blend color using the "multiply" mode', () => {
|
|
39
|
-
const backdrop = hexToRgb(hues.blue[500])
|
|
40
|
-
const source = hexToRgb(hues.gray[600])
|
|
41
|
-
const rgb = multiply(backdrop, source)
|
|
42
|
-
|
|
43
|
-
expect(rgbToHex(rgb)).toEqual('#0f3781')
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
describe('parseColor', () => {
|
|
48
|
-
it('should parse a hex to RGB', () => {
|
|
49
|
-
const rgb = parseColor('#ccc')
|
|
50
|
-
|
|
51
|
-
expect(rgbToHex(rgb)).toEqual('#cccccc')
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it('should parse a HSL to RGB', () => {
|
|
55
|
-
const rgb1 = parseColor('hsl(210, 20%, 50%)')
|
|
56
|
-
const rgb2 = parseColor('hsl(210, 10%, 0%)')
|
|
57
|
-
|
|
58
|
-
expect(rgbToHex(rgb1)).toEqual('#668099')
|
|
59
|
-
expect(rgbToHex(rgb2)).toEqual('#000000')
|
|
60
|
-
})
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
describe('helpers/rgba', () => {
|
|
64
|
-
it('should convert hex to RGBA string', () => {
|
|
65
|
-
expect(rgba('#f00', 0.5)).toBe(`rgba(255,0,0,0.5)`)
|
|
66
|
-
})
|
|
67
|
-
})
|
|
68
|
-
})
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import {parseColor} from './parse'
|
|
2
|
-
import type {RGB, RGBA} from './types'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
* @deprecated Will be removed in next major version
|
|
7
|
-
*/
|
|
8
|
-
export function getContrastRatio(bg: string, fg: string): number {
|
|
9
|
-
const rgb1 = parseColor(bg) // bg: RGB | RGBA, fg: RGB | RGBA
|
|
10
|
-
const rgb2 = parseColor(fg)
|
|
11
|
-
|
|
12
|
-
// convert the two colors from sRGB to linear-light RGB
|
|
13
|
-
const c1 = rgb_lrgb(rgb1)
|
|
14
|
-
const c2 = rgb_lrgb(rgb2)
|
|
15
|
-
|
|
16
|
-
// compute the relative luminances
|
|
17
|
-
const l1 = lrgb_luminance(c1)
|
|
18
|
-
const l2 = lrgb_luminance(c2)
|
|
19
|
-
|
|
20
|
-
// compute the contrast ratio
|
|
21
|
-
return (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function rgb_lrgb({r, g, b}: RGB | RGBA): [number, number, number] {
|
|
25
|
-
return [rgb_lrgb1(r / 255), rgb_lrgb1(g / 255), rgb_lrgb1(b / 255)]
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function rgb_lrgb1(v: number) {
|
|
29
|
-
return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function lrgb_luminance([r, g, b]: [number, number, number]) {
|
|
33
|
-
return 0.2126 * r + 0.7152 * g + 0.0722 * b
|
|
34
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import {clamp, round} from '../utils'
|
|
2
|
-
import type {HSL, RGB, RGBA} from './types'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export function hexToRgb(hex: string): RGB {
|
|
8
|
-
if (hex.length === 4) {
|
|
9
|
-
const hexR = hex.slice(1, 2)
|
|
10
|
-
const hexG = hex.slice(2, 3)
|
|
11
|
-
const hexB = hex.slice(3, 4)
|
|
12
|
-
|
|
13
|
-
return {
|
|
14
|
-
r: parseInt(hexR + hexR, 16),
|
|
15
|
-
g: parseInt(hexG + hexG, 16),
|
|
16
|
-
b: parseInt(hexB + hexB, 16),
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
r: parseInt(hex.slice(1, 3), 16),
|
|
22
|
-
g: parseInt(hex.slice(3, 5), 16),
|
|
23
|
-
b: parseInt(hex.slice(5, 7), 16),
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
export function rgbaToRGBA(rgba: string): RGBA {
|
|
31
|
-
const values = rgba.replace(/rgba\(|\)/g, '').split(',')
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
r: parseInt(values[0]),
|
|
35
|
-
g: parseInt(values[1]),
|
|
36
|
-
b: parseInt(values[2]),
|
|
37
|
-
a: parseFloat(values[3]),
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @internal
|
|
43
|
-
*/
|
|
44
|
-
export function rgbToHex(color: RGB | RGBA): string {
|
|
45
|
-
const r = round(clamp(Math.round(color.r), 0, 255))
|
|
46
|
-
const g = round(clamp(Math.round(color.g), 0, 255))
|
|
47
|
-
const b = round(clamp(Math.round(color.b), 0, 255))
|
|
48
|
-
|
|
49
|
-
if ('a' in color) {
|
|
50
|
-
return `rgba(${r},${g},${b},${color.a})`
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @internal
|
|
58
|
-
* @see https://css-tricks.com/converting-color-spaces-in-javascript/
|
|
59
|
-
*/
|
|
60
|
-
export function rgbToHsl({r, g, b}: RGB): HSL {
|
|
61
|
-
// Make r, g, and b fractions of 1
|
|
62
|
-
r /= 255
|
|
63
|
-
g /= 255
|
|
64
|
-
b /= 255
|
|
65
|
-
|
|
66
|
-
// Find greatest and smallest channel values
|
|
67
|
-
const cmin = Math.min(r, g, b)
|
|
68
|
-
const cmax = Math.max(r, g, b)
|
|
69
|
-
const delta = cmax - cmin
|
|
70
|
-
|
|
71
|
-
let h = 0
|
|
72
|
-
let s = 0
|
|
73
|
-
let l = 0
|
|
74
|
-
|
|
75
|
-
// Calculate hue
|
|
76
|
-
// No difference
|
|
77
|
-
if (delta == 0) h = 0
|
|
78
|
-
// Red is max
|
|
79
|
-
else if (cmax == r) h = ((g - b) / delta) % 6
|
|
80
|
-
// Green is max
|
|
81
|
-
else if (cmax == g) h = (b - r) / delta + 2
|
|
82
|
-
// Blue is max
|
|
83
|
-
else h = (r - g) / delta + 4
|
|
84
|
-
|
|
85
|
-
h = Math.round(h * 60)
|
|
86
|
-
|
|
87
|
-
// Make negative hues positive behind 360°
|
|
88
|
-
if (h < 0) h += 360
|
|
89
|
-
|
|
90
|
-
// Calculate lightness
|
|
91
|
-
l = (cmax + cmin) / 2
|
|
92
|
-
|
|
93
|
-
// Calculate saturation
|
|
94
|
-
s = delta == 0 ? 0 : delta / (1 - Math.abs(2 * l - 1))
|
|
95
|
-
|
|
96
|
-
// Multiply l and s by 100
|
|
97
|
-
s = +(s * 100).toFixed(1)
|
|
98
|
-
l = +(l * 100).toFixed(1)
|
|
99
|
-
|
|
100
|
-
return {h, s, l}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* @internal
|
|
105
|
-
*/
|
|
106
|
-
export function hslToRgb(hsl: HSL): RGB {
|
|
107
|
-
// Must be fractions of 1
|
|
108
|
-
const s = hsl.s / 100
|
|
109
|
-
const l = hsl.l / 100
|
|
110
|
-
|
|
111
|
-
const c = (1 - Math.abs(2 * l - 1)) * s
|
|
112
|
-
const x = c * (1 - Math.abs(((hsl.h / 60) % 2) - 1))
|
|
113
|
-
const m = l - c / 2
|
|
114
|
-
|
|
115
|
-
let r = 0
|
|
116
|
-
let g = 0
|
|
117
|
-
let b = 0
|
|
118
|
-
|
|
119
|
-
if (0 <= hsl.h && hsl.h < 60) {
|
|
120
|
-
r = c
|
|
121
|
-
g = x
|
|
122
|
-
b = 0
|
|
123
|
-
} else if (60 <= hsl.h && hsl.h < 120) {
|
|
124
|
-
r = x
|
|
125
|
-
g = c
|
|
126
|
-
b = 0
|
|
127
|
-
} else if (120 <= hsl.h && hsl.h < 180) {
|
|
128
|
-
r = 0
|
|
129
|
-
g = c
|
|
130
|
-
b = x
|
|
131
|
-
} else if (180 <= hsl.h && hsl.h < 240) {
|
|
132
|
-
r = 0
|
|
133
|
-
g = x
|
|
134
|
-
b = c
|
|
135
|
-
} else if (240 <= hsl.h && hsl.h < 300) {
|
|
136
|
-
r = x
|
|
137
|
-
g = 0
|
|
138
|
-
b = c
|
|
139
|
-
} else if (300 <= hsl.h && hsl.h < 360) {
|
|
140
|
-
r = c
|
|
141
|
-
g = 0
|
|
142
|
-
b = x
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return {
|
|
146
|
-
r: Math.round((r + m) * 255),
|
|
147
|
-
g: Math.round((g + m) * 255),
|
|
148
|
-
b: Math.round((b + m) * 255),
|
|
149
|
-
}
|
|
150
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {hexToRgb, hslToRgb, rgbaToRGBA} from './convert'
|
|
2
|
-
import type {HSL, RGB, RGBA} from './types'
|
|
3
|
-
|
|
4
|
-
const HEX_CHARS = '0123456789ABCDEFabcdef'
|
|
5
|
-
|
|
6
|
-
const HSL_RE = /hsl\(\s*(\d+)\s*,\s*((\d+(?:\.\d+)?)%)\s*,\s*((\d+(?:\.\d+)?)%)\s*\)/i
|
|
7
|
-
|
|
8
|
-
function isHexChars(str: string) {
|
|
9
|
-
for (const c of str) {
|
|
10
|
-
if (HEX_CHARS.indexOf(c) === -1) {
|
|
11
|
-
return false
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return true
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function isHex(str: string) {
|
|
19
|
-
if (str[0] !== '#') return false
|
|
20
|
-
|
|
21
|
-
// Accept both #000 and #000000
|
|
22
|
-
if (!(str.length === 4 || str.length === 7)) return false
|
|
23
|
-
|
|
24
|
-
return isHexChars(str.slice(1))
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function parseHsl(str: string): HSL {
|
|
28
|
-
const res = HSL_RE.exec(str)
|
|
29
|
-
|
|
30
|
-
if (!res) {
|
|
31
|
-
throw new Error(`parseHsl: string is not a HSL color: "${str}"`)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return {h: parseInt(res[1]), s: parseFloat(res[3]), l: parseFloat(res[5])}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
export function parseColor(color: unknown): RGB | RGBA {
|
|
41
|
-
if (!color) return {r: 0, g: 0, b: 0}
|
|
42
|
-
|
|
43
|
-
if (typeof color !== 'string') {
|
|
44
|
-
throw new Error('parseColor: expected a string')
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (isHex(color)) {
|
|
48
|
-
return hexToRgb(color)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (color.startsWith('hsl(')) {
|
|
52
|
-
return hslToRgb(parseHsl(color))
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (color.startsWith('rgba(')) {
|
|
56
|
-
return rgbaToRGBA(color)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
throw new Error(`parseColor: unexpected color format: "${color}"`)
|
|
60
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {parseColor} from './parse'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @internal
|
|
5
|
-
*/
|
|
6
|
-
export function rgba(color: unknown, a: number): string {
|
|
7
|
-
if (typeof color === 'string' && color.startsWith('var(')) {
|
|
8
|
-
return `color-mix(in srgb, transparent, ${color} ${a * 100}%)`
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const rgb = parseColor(color)
|
|
12
|
-
|
|
13
|
-
return `rgba(${rgb.r},${rgb.g},${rgb.b},${a})`
|
|
14
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @internal
|
|
3
|
-
*/
|
|
4
|
-
export interface RGB {
|
|
5
|
-
r: number
|
|
6
|
-
g: number
|
|
7
|
-
b: number
|
|
8
|
-
a?: undefined
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export interface RGBA {
|
|
15
|
-
r: number
|
|
16
|
-
g: number
|
|
17
|
-
b: number
|
|
18
|
-
a: number
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @internal
|
|
23
|
-
*/
|
|
24
|
-
export interface HSL {
|
|
25
|
-
h: number
|
|
26
|
-
s: number
|
|
27
|
-
l: number
|
|
28
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export function lerp(x: number, y: number, a: number): number {
|
|
2
|
-
return x * (1 - a) + y * a
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function invlerp(x: number, y: number, a: number): number {
|
|
6
|
-
return clamp((a - x) / (y - x))
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function clamp(a: number, min = 0, max = 1): number {
|
|
10
|
-
return Math.min(max, Math.max(min, a))
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function range(x1: number, y1: number, x2: number, y2: number, a: number): number {
|
|
14
|
-
return lerp(x2, y2, invlerp(x1, y1, a))
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function round(value: number): number {
|
|
18
|
-
return Math.round(value)
|
|
19
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
|
|
3
|
-
import {isRecord} from './lib/isRecord'
|
|
4
|
-
|
|
5
|
-
export function merge<T extends Record<string, any>>(...records: (T | undefined)[]): T {
|
|
6
|
-
const _records = records.filter(Boolean) as T[]
|
|
7
|
-
|
|
8
|
-
if (_records.length === 0) {
|
|
9
|
-
return {} as T
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return _records.reduce(_merge, {} as T)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function _merge<T extends Record<string, any>>(acc: T, source: T): T {
|
|
16
|
-
for (const key of Object.keys(source)) {
|
|
17
|
-
const prevValue = acc[key]
|
|
18
|
-
const nextValue = source[key]
|
|
19
|
-
|
|
20
|
-
if (isRecord(prevValue) && isRecord(nextValue)) {
|
|
21
|
-
;(acc as any)[key] = merge(prevValue, nextValue)
|
|
22
|
-
} else {
|
|
23
|
-
;(acc as any)[key] = nextValue
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return acc
|
|
28
|
-
}
|