@cube-dev/ui-kit 0.98.8 → 0.99.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/es/_internal/hooks/index.js +10 -10
- package/es/_internal/hooks/use-chained-callback.js +2 -2
- package/es/_internal/hooks/use-debounced-value.js +1 -1
- package/es/_internal/hooks/use-deprecation-warning.js +2 -2
- package/es/_internal/hooks/use-effect-once.js +1 -1
- package/es/_internal/hooks/use-event.js +2 -2
- package/es/_internal/hooks/use-is-first-render.js +1 -1
- package/es/_internal/hooks/use-sync-ref.js +2 -2
- package/es/_internal/hooks/use-timer/index.js +3 -3
- package/es/_internal/hooks/use-timer/timer.js +1 -1
- package/es/_internal/hooks/use-timer/use-timer.js +3 -3
- package/es/_internal/hooks/use-update-effect.js +2 -2
- package/es/_internal/hooks/use-warn.js +3 -3
- package/es/_internal/index.js +2 -2
- package/es/components/Block.js +2 -2
- package/es/components/CollectionItem.js +3 -3
- package/es/components/GlobalStyles.js +56 -65
- package/es/components/GridProvider.js +4 -4
- package/es/components/HiddenInput.js +2 -2
- package/es/components/OpenTrasition.js +1 -1
- package/es/components/Root.js +22 -64
- package/es/components/actions/Action/Action.js +3 -3
- package/es/components/actions/Button/Button.js +12 -12
- package/es/components/actions/Button/index.js +2 -2
- package/es/components/actions/ButtonGroup/ButtonGroup.js +4 -4
- package/es/components/actions/CommandMenu/CommandMenu.js +11 -11
- package/es/components/actions/CommandMenu/index.js +2 -2
- package/es/components/actions/CommandMenu/styled.js +2 -2
- package/es/components/actions/ItemAction/ItemAction.js +9 -9
- package/es/components/actions/ItemAction/index.js +2 -2
- package/es/components/actions/ItemActionContext.js +1 -1
- package/es/components/actions/ItemButton/ItemButton.js +9 -9
- package/es/components/actions/ItemButton/index.js +2 -2
- package/es/components/actions/Link/Link.js +2 -2
- package/es/components/actions/Menu/Menu.js +10 -10
- package/es/components/actions/Menu/MenuItem.js +7 -7
- package/es/components/actions/Menu/MenuSection.js +4 -4
- package/es/components/actions/Menu/MenuTrigger.js +6 -6
- package/es/components/actions/Menu/SubMenuTrigger.js +6 -6
- package/es/components/actions/Menu/SubmenuTriggerContext.js +1 -1
- package/es/components/actions/Menu/context.js +1 -1
- package/es/components/actions/Menu/index.js +10 -10
- package/es/components/actions/Menu/styled.js +5 -5
- package/es/components/actions/index.js +13 -13
- package/es/components/actions/use-action.js +7 -7
- package/es/components/actions/use-anchored-menu.js +6 -6
- package/es/components/actions/use-context-menu.js +6 -6
- package/es/components/content/ActiveZone/ActiveZone.js +4 -4
- package/es/components/content/Alert/Alert.js +4 -4
- package/es/components/content/Alert/index.js +2 -2
- package/es/components/content/Alert/types.js +1 -1
- package/es/components/content/Alert/use-alert.js +3 -3
- package/es/components/content/Avatar/Avatar.js +2 -2
- package/es/components/content/Badge/Badge.js +4 -4
- package/es/components/content/Card/Card.js +2 -2
- package/es/components/content/Content.js +3 -3
- package/es/components/content/CopyPasteBlock/CopyPasteBlock.js +8 -8
- package/es/components/content/CopyPasteBlock/index.js +2 -2
- package/es/components/content/CopySnippet/CopySnippet.js +9 -9
- package/es/components/content/CopySnippet/index.js +2 -2
- package/es/components/content/Disclosure/Disclosure.js +6 -6
- package/es/components/content/Disclosure/index.js +2 -2
- package/es/components/content/Divider.js +3 -3
- package/es/components/content/Footer.js +3 -3
- package/es/components/content/Header.js +3 -3
- package/es/components/content/HotKeys/HotKeys.js +5 -5
- package/es/components/content/HotKeys/index.js +2 -2
- package/es/components/content/Item/Item.js +25 -20
- package/es/components/content/Item/index.js +3 -3
- package/es/components/content/ItemBadge/ItemBadge.js +8 -8
- package/es/components/content/ItemBadge/index.js +2 -2
- package/es/components/content/Layout/GridLayout.js +13 -13
- package/es/components/content/Layout/Layout.js +7 -6
- package/es/components/content/Layout/LayoutBlock.js +4 -3
- package/es/components/content/Layout/LayoutCenter.js +3 -3
- package/es/components/content/Layout/LayoutContainer.js +4 -4
- package/es/components/content/Layout/LayoutContent.js +6 -5
- package/es/components/content/Layout/LayoutContext.js +1 -1
- package/es/components/content/Layout/LayoutFlex.js +4 -3
- package/es/components/content/Layout/LayoutFooter.js +4 -3
- package/es/components/content/Layout/LayoutGrid.js +4 -3
- package/es/components/content/Layout/LayoutHeader.js +8 -7
- package/es/components/content/Layout/LayoutPane.js +8 -7
- package/es/components/content/Layout/LayoutPanel.js +10 -9
- package/es/components/content/Layout/LayoutPanelHeader.js +7 -7
- package/es/components/content/Layout/LayoutToolbar.js +4 -3
- package/es/components/content/Layout/hooks/useTinyScrollbar.js +1 -1
- package/es/components/content/Layout/index.js +16 -16
- package/es/components/content/Layout/utils.js +1 -1
- package/es/components/content/List/SectionHeading.js +3 -3
- package/es/components/content/List/index.js +2 -2
- package/es/components/content/Paragraph.js +3 -3
- package/es/components/content/Placeholder/Placeholder.js +2 -2
- package/es/components/content/PrismCode/PrismCode.js +7 -7
- package/es/components/content/PrismCode/prismSetup.js +1 -1
- package/es/components/content/PrismDiffCode/PrismDiffCode.js +2 -2
- package/es/components/content/Result/Result.js +4 -4
- package/es/components/content/Skeleton/Skeleton.js +5 -5
- package/es/components/content/Tag/Tag.js +4 -4
- package/es/components/content/Text.js +3 -3
- package/es/components/content/TextItem/TextItem.js +5 -5
- package/es/components/content/TextItem/index.js +2 -2
- package/es/components/content/Title.js +4 -4
- package/es/components/content/highlightText.js +2 -2
- package/es/components/content/use-auto-tooltip.js +2 -2
- package/es/components/fields/Checkbox/Checkbox.js +12 -12
- package/es/components/fields/Checkbox/CheckboxGroup.js +7 -7
- package/es/components/fields/Checkbox/context.js +1 -1
- package/es/components/fields/Checkbox/index.js +3 -3
- package/es/components/fields/ComboBox/ComboBox.js +18 -18
- package/es/components/fields/ComboBox/index.js +2 -2
- package/es/components/fields/DatePicker/DateInput.js +10 -10
- package/es/components/fields/DatePicker/DateInputBase.js +6 -6
- package/es/components/fields/DatePicker/DatePicker.js +14 -14
- package/es/components/fields/DatePicker/DatePickerButton.js +4 -4
- package/es/components/fields/DatePicker/DatePickerElement.js +3 -3
- package/es/components/fields/DatePicker/DatePickerInput.js +5 -5
- package/es/components/fields/DatePicker/DatePickerSegment.js +2 -2
- package/es/components/fields/DatePicker/DateRangePicker.js +15 -15
- package/es/components/fields/DatePicker/DateRangeSeparatedPicker.js +15 -15
- package/es/components/fields/DatePicker/TimeInput.js +9 -9
- package/es/components/fields/DatePicker/index.js +8 -8
- package/es/components/fields/DatePicker/intl.js +1 -1
- package/es/components/fields/DatePicker/parseDate.js +1 -1
- package/es/components/fields/DatePicker/props.js +1 -1
- package/es/components/fields/DatePicker/types.js +1 -1
- package/es/components/fields/DatePicker/utils.js +1 -1
- package/es/components/fields/FileInput/FileInput.js +6 -6
- package/es/components/fields/FilterListBox/FilterListBox.js +10 -10
- package/es/components/fields/FilterListBox/index.js +2 -2
- package/es/components/fields/FilterPicker/FilterPicker.js +14 -14
- package/es/components/fields/FilterPicker/index.js +2 -2
- package/es/components/fields/Input/Input.js +6 -6
- package/es/components/fields/Input/index.js +2 -2
- package/es/components/fields/ListBox/ListBox.js +14 -14
- package/es/components/fields/ListBox/index.js +2 -2
- package/es/components/fields/NumberInput/NumberInput.js +8 -8
- package/es/components/fields/NumberInput/StepButton.js +4 -4
- package/es/components/fields/PasswordInput/PasswordInput.js +8 -8
- package/es/components/fields/Picker/Picker.js +13 -13
- package/es/components/fields/Picker/index.js +2 -2
- package/es/components/fields/RadioGroup/Radio.js +10 -10
- package/es/components/fields/RadioGroup/RadioGroup.js +7 -7
- package/es/components/fields/RadioGroup/context.js +1 -1
- package/es/components/fields/RadioGroup/index.js +3 -3
- package/es/components/fields/SearchInput/SearchInput.js +8 -8
- package/es/components/fields/SearchInput/index.js +2 -2
- package/es/components/fields/Select/Select.js +20 -20
- package/es/components/fields/Select/index.js +2 -2
- package/es/components/fields/Slider/Gradation.js +2 -2
- package/es/components/fields/Slider/Header.js +1 -1
- package/es/components/fields/Slider/RangeSlider.js +5 -5
- package/es/components/fields/Slider/Slider.js +7 -7
- package/es/components/fields/Slider/SliderBase.js +6 -6
- package/es/components/fields/Slider/SliderInput.js +2 -2
- package/es/components/fields/Slider/SliderThumb.js +3 -3
- package/es/components/fields/Slider/SliderTrack.js +2 -2
- package/es/components/fields/Slider/elements.js +2 -2
- package/es/components/fields/Slider/index.js +4 -4
- package/es/components/fields/Slider/types.js +1 -1
- package/es/components/fields/Switch/Switch.js +11 -11
- package/es/components/fields/Switch/index.js +2 -2
- package/es/components/fields/TextArea/TextArea.js +7 -7
- package/es/components/fields/TextArea/index.js +2 -2
- package/es/components/fields/TextInput/TextInput.js +6 -6
- package/es/components/fields/TextInput/TextInputBase.js +9 -9
- package/es/components/fields/TextInput/index.js +3 -3
- package/es/components/fields/TextInputMapper/TextInputMapper.js +14 -14
- package/es/components/fields/TextInputMapper/index.js +2 -2
- package/es/components/fields/index.js +20 -20
- package/es/components/form/FieldWrapper/FieldWrapper.js +9 -9
- package/es/components/form/FieldWrapper/extract-field-wrapper-props.js +1 -1
- package/es/components/form/FieldWrapper/index.js +4 -4
- package/es/components/form/FieldWrapper/types.js +1 -1
- package/es/components/form/Form/Field.js +6 -6
- package/es/components/form/Form/Form.js +6 -6
- package/es/components/form/Form/ResetButton/ResetButton.js +6 -6
- package/es/components/form/Form/ResetButton/index.js +2 -2
- package/es/components/form/Form/SubmitButton/SubmitButton.js +4 -4
- package/es/components/form/Form/SubmitButton/index.js +2 -2
- package/es/components/form/Form/SubmitError.js +3 -3
- package/es/components/form/Form/index.js +11 -11
- package/es/components/form/Form/types.js +1 -1
- package/es/components/form/Form/use-field/index.js +4 -4
- package/es/components/form/Form/use-field/types.js +1 -1
- package/es/components/form/Form/use-field/use-field-props.js +6 -6
- package/es/components/form/Form/use-field/use-field.js +4 -4
- package/es/components/form/Form/use-form.js +3 -3
- package/es/components/form/Form/validation.js +1 -1
- package/es/components/form/Label.js +3 -3
- package/es/components/form/index.js +5 -5
- package/es/components/form/wrapper.js +3 -3
- package/es/components/helpers/DisplayTransition/DisplayTransition.js +1 -1
- package/es/components/helpers/DisplayTransition/index.js +2 -2
- package/es/components/helpers/IconSwitch/IconSwitch.js +3 -3
- package/es/components/helpers/index.js +3 -3
- package/es/components/layout/Flex.js +2 -2
- package/es/components/layout/Flow.js +2 -2
- package/es/components/layout/Grid.js +2 -2
- package/es/components/layout/Panel.js +2 -2
- package/es/components/layout/Prefix.js +3 -3
- package/es/components/layout/ResizablePanel.js +5 -5
- package/es/components/layout/Space.js +2 -2
- package/es/components/layout/Suffix.js +3 -3
- package/es/components/organisms/FileTabs/FileTabs.js +8 -8
- package/es/components/organisms/StatsCard/StatsCard.js +4 -4
- package/es/components/other/Calendar/Calendar.js +8 -8
- package/es/components/other/Calendar/CalendarCell.js +2 -2
- package/es/components/other/Calendar/CalendarGrid.js +3 -3
- package/es/components/other/Calendar/RangeCalendar.js +8 -8
- package/es/components/other/CloudLogo/CloudLogo.js +3 -3
- package/es/components/overlays/AlertDialog/AlertDialog.js +11 -10
- package/es/components/overlays/AlertDialog/AlertDialogApiProvider.js +2 -2
- package/es/components/overlays/AlertDialog/AlertDialogZone.js +4 -4
- package/es/components/overlays/AlertDialog/index.js +4 -4
- package/es/components/overlays/AlertDialog/types.js +1 -1
- package/es/components/overlays/Dialog/Dialog.js +7 -7
- package/es/components/overlays/Dialog/DialogContainer.js +3 -3
- package/es/components/overlays/Dialog/DialogForm.js +8 -8
- package/es/components/overlays/Dialog/DialogTrigger.js +4 -4
- package/es/components/overlays/Dialog/context.js +1 -1
- package/es/components/overlays/Dialog/index.js +6 -6
- package/es/components/overlays/Dialog/use-dialog-container.js +4 -4
- package/es/components/overlays/Modal/Modal.js +5 -5
- package/es/components/overlays/Modal/OpenTransition.js +1 -1
- package/es/components/overlays/Modal/Overlay.js +3 -3
- package/es/components/overlays/Modal/Popover.js +4 -4
- package/es/components/overlays/Modal/Tray.js +6 -6
- package/es/components/overlays/Modal/Underlay.js +2 -2
- package/es/components/overlays/Modal/index.js +7 -7
- package/es/components/overlays/Modal/types.js +1 -1
- package/es/components/overlays/NewNotifications/Bar/FloatingNotification.js +5 -5
- package/es/components/overlays/NewNotifications/Bar/NotificationsBar.js +7 -7
- package/es/components/overlays/NewNotifications/Bar/TransitionComponent.js +36 -34
- package/es/components/overlays/NewNotifications/Bar/index.js +2 -2
- package/es/components/overlays/NewNotifications/Dialog/NotificationsDialogContext.js +1 -1
- package/es/components/overlays/NewNotifications/Dialog/NotificationsDialogTrigger.js +8 -8
- package/es/components/overlays/NewNotifications/Dialog/index.js +2 -2
- package/es/components/overlays/NewNotifications/Notification.js +4 -4
- package/es/components/overlays/NewNotifications/NotificationView/NotificationAction.js +5 -5
- package/es/components/overlays/NewNotifications/NotificationView/NotificationCloseButton.js +4 -4
- package/es/components/overlays/NewNotifications/NotificationView/NotificationDescription.js +4 -4
- package/es/components/overlays/NewNotifications/NotificationView/NotificationFooter.js +3 -3
- package/es/components/overlays/NewNotifications/NotificationView/NotificationHeader.js +3 -3
- package/es/components/overlays/NewNotifications/NotificationView/NotificationIcon.js +4 -4
- package/es/components/overlays/NewNotifications/NotificationView/NotificationProvider.js +1 -1
- package/es/components/overlays/NewNotifications/NotificationView/NotificationView.js +12 -12
- package/es/components/overlays/NewNotifications/NotificationView/index.js +3 -3
- package/es/components/overlays/NewNotifications/NotificationView/types.js +1 -1
- package/es/components/overlays/NewNotifications/NotificationsContext/NotificationsContext.js +1 -1
- package/es/components/overlays/NewNotifications/NotificationsContext/NotificationsProvider.js +5 -5
- package/es/components/overlays/NewNotifications/NotificationsContext/index.js +3 -3
- package/es/components/overlays/NewNotifications/NotificationsContext/use-notifications.js +2 -2
- package/es/components/overlays/NewNotifications/NotificationsList/NotificationsList.js +4 -4
- package/es/components/overlays/NewNotifications/NotificationsList/NotificationsListItem.js +5 -5
- package/es/components/overlays/NewNotifications/NotificationsList/index.js +2 -2
- package/es/components/overlays/NewNotifications/NotificationsList/types.js +1 -1
- package/es/components/overlays/NewNotifications/hooks/index.js +6 -6
- package/es/components/overlays/NewNotifications/hooks/types.js +1 -1
- package/es/components/overlays/NewNotifications/hooks/use-notification-list-item.js +1 -1
- package/es/components/overlays/NewNotifications/hooks/use-notifications-api.js +2 -2
- package/es/components/overlays/NewNotifications/hooks/use-notifications-list.js +1 -1
- package/es/components/overlays/NewNotifications/hooks/use-notifications-observer.js +3 -3
- package/es/components/overlays/NewNotifications/index.js +7 -7
- package/es/components/overlays/NewNotifications/types.js +1 -1
- package/es/components/overlays/Notification/Notification.js +7 -7
- package/es/components/overlays/OverlayWrapper.js +2 -2
- package/es/components/overlays/Toasts/Toast.js +4 -4
- package/es/components/overlays/Toasts/index.js +3 -3
- package/es/components/overlays/Toasts/types.js +1 -1
- package/es/components/overlays/Toasts/use-toasts-api.js +2 -2
- package/es/components/overlays/Tooltip/Tooltip.js +4 -4
- package/es/components/overlays/Tooltip/TooltipProvider.js +3 -3
- package/es/components/overlays/Tooltip/TooltipTrigger.js +6 -6
- package/es/components/overlays/Tooltip/context.js +1 -1
- package/es/components/overlays/Tooltip/index.js +4 -4
- package/es/components/portal/Portal.js +2 -2
- package/es/components/portal/PortalProvider.js +1 -1
- package/es/components/portal/index.js +3 -3
- package/es/components/portal/types.js +1 -1
- package/es/components/portal/usePortal.js +2 -2
- package/es/components/shared/InvalidIcon.js +2 -2
- package/es/components/shared/ValidIcon.js +2 -2
- package/es/components/status/LoadingAnimation/LoadingAnimation.js +58 -114
- package/es/components/status/LoadingAnimation/index.js +2 -2
- package/es/components/status/Spin/Cube.js +95 -179
- package/es/components/status/Spin/InternalSpinner.js +5 -5
- package/es/components/status/Spin/Spin.js +4 -4
- package/es/components/status/Spin/SpinsContainer.js +28 -30
- package/es/components/status/Spin/index.js +2 -2
- package/es/components/status/Spin/types.js +1 -1
- package/es/components/status/index.js +3 -3
- package/es/data/item-themes.js +1 -1
- package/es/data/themes.js +1 -1
- package/es/icons/AdjustmentsHorizontalIcon.js +2 -2
- package/es/icons/AdjustmentsIcon.js +2 -2
- package/es/icons/AiIcon.js +2 -2
- package/es/icons/AreaChartIcon.js +2 -2
- package/es/icons/BackwardIcon.js +2 -2
- package/es/icons/BarChartIcon.js +2 -2
- package/es/icons/BellFilledIcon.js +2 -2
- package/es/icons/BellIcon.js +2 -2
- package/es/icons/BooleanIcon.js +2 -2
- package/es/icons/CalendarEditIcon.js +2 -2
- package/es/icons/CalendarIcon.js +2 -2
- package/es/icons/CaretDownIcon.js +2 -2
- package/es/icons/CaretUpIcon.js +2 -2
- package/es/icons/ChartAreaStackedIcon.js +2 -2
- package/es/icons/ChartAreaStackedPercentageIcon.js +2 -2
- package/es/icons/ChartBarGroupedHorizontalIcon.js +2 -2
- package/es/icons/ChartBarGroupedIcon.js +2 -2
- package/es/icons/ChartBarHorizontalIcon.js +2 -2
- package/es/icons/ChartBarLineIcon.js +2 -2
- package/es/icons/ChartBarStackedHorizontalIcon.js +2 -2
- package/es/icons/ChartBarStackedIcon.js +2 -2
- package/es/icons/ChartBarStackedPercentageHorizontalIcon.js +2 -2
- package/es/icons/ChartBarStackedPercentageIcon.js +2 -2
- package/es/icons/ChartBoxPlot2Icon.js +2 -2
- package/es/icons/ChartBoxPlotIcon.js +2 -2
- package/es/icons/ChartBubbleIcon.js +2 -2
- package/es/icons/ChartDonut2Icon.js +2 -2
- package/es/icons/ChartFunnelIcon.js +2 -2
- package/es/icons/ChartHeatmapIcon.js +2 -2
- package/es/icons/ChartKPIIcon.js +2 -2
- package/es/icons/ChartPie2Icon.js +2 -2
- package/es/icons/ChartScatterIcon.js +2 -2
- package/es/icons/CheckCircleFilledIcon.js +2 -2
- package/es/icons/CheckCircleIcon.js +2 -2
- package/es/icons/CheckIcon.js +2 -2
- package/es/icons/CircleFilledIcon.js +2 -2
- package/es/icons/ClearIcon.js +2 -2
- package/es/icons/CloseCircleFilledIcon.js +2 -2
- package/es/icons/CloseCircleIcon.js +2 -2
- package/es/icons/CloseIcon.js +2 -2
- package/es/icons/CodeIcon.js +2 -2
- package/es/icons/ColumnTotalIcon.js +2 -2
- package/es/icons/CopyIcon.js +2 -2
- package/es/icons/CountIcon.js +2 -2
- package/es/icons/CubeIcon.js +2 -2
- package/es/icons/CubePauseIcon.js +2 -2
- package/es/icons/CubePlayIcon.js +2 -2
- package/es/icons/CurrencyDollarIcon.js +2 -2
- package/es/icons/DangerIcon.js +2 -2
- package/es/icons/DashboardIcon.js +2 -2
- package/es/icons/DatabaseIcon.js +2 -2
- package/es/icons/DecimalDecreaseIcon.js +2 -2
- package/es/icons/DecimalIncreaseIcon.js +2 -2
- package/es/icons/DirectionIcon.js +3 -3
- package/es/icons/DonutIcon.js +2 -2
- package/es/icons/DownIcon.js +2 -2
- package/es/icons/EditIcon.js +2 -2
- package/es/icons/ExclamationCircleFilledIcon.js +2 -2
- package/es/icons/ExclamationCircleIcon.js +2 -2
- package/es/icons/ExclamationIcon.js +2 -2
- package/es/icons/EyeIcon.js +2 -2
- package/es/icons/EyeInvisibleIcon.js +2 -2
- package/es/icons/FilterIcon.js +2 -2
- package/es/icons/FolderFilledIcon.js +2 -2
- package/es/icons/FolderIcon.js +2 -2
- package/es/icons/FolderOpenFilledIcon.js +2 -2
- package/es/icons/FolderOpenIcon.js +2 -2
- package/es/icons/ForwardIcon.js +2 -2
- package/es/icons/HierarchyIcon.js +2 -2
- package/es/icons/HierarchyOpenIcon.js +2 -2
- package/es/icons/Icon.js +2 -2
- package/es/icons/InfoCircleIcon.js +2 -2
- package/es/icons/InfoIcon.js +2 -2
- package/es/icons/KeyIcon.js +2 -2
- package/es/icons/LeftIcon.js +2 -2
- package/es/icons/LineChartIcon.js +2 -2
- package/es/icons/LoadingIcon.js +2 -2
- package/es/icons/LockFilledIcon.js +2 -2
- package/es/icons/LockIcon.js +2 -2
- package/es/icons/MoreIcon.js +2 -2
- package/es/icons/NotAllowedIcon.js +2 -2
- package/es/icons/Number123Icon.js +2 -2
- package/es/icons/NumberIcon.js +2 -2
- package/es/icons/PauseCircleFilledIcon.js +2 -2
- package/es/icons/PauseCircleIcon.js +2 -2
- package/es/icons/PauseIcon.js +2 -2
- package/es/icons/PercentageIcon.js +2 -2
- package/es/icons/PieChartIcon.js +2 -2
- package/es/icons/PlayCircleIcon.js +2 -2
- package/es/icons/PlayIcon.js +2 -2
- package/es/icons/PlusIcon.js +2 -2
- package/es/icons/ProgressBarIcon.js +2 -2
- package/es/icons/ReloadIcon.js +2 -2
- package/es/icons/ReportIcon.js +2 -2
- package/es/icons/ReturnIcon.js +2 -2
- package/es/icons/RightIcon.js +2 -2
- package/es/icons/RowTotalsIcon.js +2 -2
- package/es/icons/SchemeIcon.js +2 -2
- package/es/icons/SearchIcon.js +2 -2
- package/es/icons/SemanticQueryIcon.js +12 -0
- package/es/icons/SettingsIcon.js +2 -2
- package/es/icons/ShieldFilledIcon.js +2 -2
- package/es/icons/ShieldIcon.js +2 -2
- package/es/icons/SlashIcon.js +2 -2
- package/es/icons/SparklesIcon.js +2 -2
- package/es/icons/SqlIcon.js +2 -2
- package/es/icons/StatsIcon.js +2 -2
- package/es/icons/StopIcon.js +2 -2
- package/es/icons/StringIcon.js +2 -2
- package/es/icons/SubtotalsIcon.js +2 -2
- package/es/icons/SwitchIcon.js +2 -2
- package/es/icons/TableIcon.js +2 -2
- package/es/icons/ThumbsDownIcon.js +2 -2
- package/es/icons/ThumbsUpIcon.js +2 -2
- package/es/icons/ThunderboltCrossedIcon.js +2 -2
- package/es/icons/ThunderboltFilledIcon.js +2 -2
- package/es/icons/ThunderboltIcon.js +2 -2
- package/es/icons/TimeIcon.js +2 -2
- package/es/icons/TrashIcon.js +2 -2
- package/es/icons/UnlockIcon.js +2 -2
- package/es/icons/UpIcon.js +2 -2
- package/es/icons/UserGroupIcon.js +2 -2
- package/es/icons/UserIcon.js +2 -2
- package/es/icons/UserLockIcon.js +2 -2
- package/es/icons/ViewIcon.js +2 -2
- package/es/icons/WarningFilledIcon.js +2 -2
- package/es/icons/WarningIcon.js +2 -2
- package/es/icons/index.js +129 -128
- package/es/icons/wrap-icon.js +2 -2
- package/es/index.js +73 -74
- package/es/provider.js +4 -10
- package/es/providers/TrackingProvider.js +1 -1
- package/es/providers/navigation.types.js +1 -1
- package/es/providers/navigationAdapter.default.js +1 -1
- package/es/services/notification.js +2 -2
- package/es/shared/form.js +1 -1
- package/es/shared/index.js +2 -2
- package/es/stories/Form.legacy-stories.js +4 -4
- package/es/stories/FormFieldArgs.js +2 -2
- package/es/stories/SimpleLayout.stories.js +2 -2
- package/es/stories/Tasty.stories.js +2 -2
- package/es/stories/components/ConfirmDeletionDialogForm.js +2 -2
- package/es/stories/components/DialogFormApp.js +3 -3
- package/es/stories/components/StyledButton.js +19 -15
- package/es/stories/lists/baseProps.js +2 -2
- package/es/stories/playground/PlaygroundEditor.js +89 -0
- package/es/stories/playground/PlaygroundLayout.js +16 -0
- package/es/stories/playground/PlaygroundOutput.js +92 -0
- package/es/stories/playground/PlaygroundPreview.js +91 -0
- package/es/stories/playground/components/Button.js +45 -0
- package/es/stories/playground/components/Card.js +20 -0
- package/es/stories/playground/components/ScrollProgress.js +17 -0
- package/es/stories/playground/examples.js +158 -0
- package/es/tasty/chunks/cacheKey.js +98 -0
- package/es/tasty/chunks/definitions.js +281 -0
- package/es/tasty/chunks/index.js +12 -0
- package/es/tasty/chunks/renderChunk.js +97 -0
- package/es/tasty/config.js +280 -0
- package/es/tasty/debug.js +195 -9
- package/es/tasty/hooks/index.js +12 -0
- package/es/tasty/hooks/useGlobalStyles.js +67 -0
- package/es/tasty/hooks/useRawCSS.js +40 -0
- package/es/tasty/hooks/useStyles.js +206 -0
- package/es/tasty/index.js +31 -17
- package/es/tasty/injector/index.js +34 -90
- package/es/tasty/injector/injector.js +81 -299
- package/es/tasty/injector/sheet-manager.js +138 -3
- package/es/tasty/injector/types.js +1 -1
- package/es/tasty/keyframes/index.js +301 -0
- package/es/tasty/parser/classify.js +8 -6
- package/es/tasty/parser/const.js +1 -1
- package/es/tasty/parser/lru.js +1 -1
- package/es/tasty/parser/parser.js +18 -5
- package/es/tasty/parser/tokenizer.js +1 -1
- package/es/tasty/parser/types.js +2 -1
- package/es/tasty/pipeline/conditions.js +426 -0
- package/es/tasty/pipeline/exclusive.js +311 -0
- package/es/tasty/pipeline/index.js +543 -0
- package/es/tasty/pipeline/materialize.js +1260 -0
- package/es/tasty/pipeline/parseStateKey.js +592 -0
- package/es/tasty/pipeline/simplify.js +898 -0
- package/es/tasty/plugins/index.js +26 -0
- package/es/tasty/plugins/okhsl-plugin.js +400 -0
- package/es/tasty/plugins/types.js +10 -0
- package/es/tasty/states/index.js +523 -0
- package/es/tasty/static/index.js +47 -0
- package/es/tasty/static/tastyStatic.js +55 -0
- package/es/tasty/static/types.js +34 -0
- package/es/tasty/styles/align.js +1 -1
- package/es/tasty/styles/border.js +2 -2
- package/es/tasty/styles/boxShadow.combinator.js +1 -1
- package/es/tasty/styles/color.js +3 -3
- package/es/tasty/styles/createStyle.js +3 -3
- package/es/tasty/styles/dimension.js +2 -2
- package/es/tasty/styles/display.js +1 -1
- package/es/tasty/styles/fade.js +2 -2
- package/es/tasty/styles/fill.js +11 -21
- package/es/tasty/styles/flow.js +1 -1
- package/es/tasty/styles/font.js +1 -1
- package/es/tasty/styles/fontStyle.js +1 -1
- package/es/tasty/styles/gap.js +2 -2
- package/es/tasty/styles/groupRadius.js +2 -2
- package/es/tasty/styles/height.js +2 -2
- package/es/tasty/styles/index.js +3 -3
- package/es/tasty/styles/inset.js +2 -2
- package/es/tasty/styles/justify.js +1 -1
- package/es/tasty/styles/list.js +1 -1
- package/es/tasty/styles/margin.js +76 -56
- package/es/tasty/styles/outline.js +2 -2
- package/es/tasty/styles/padding.js +76 -56
- package/es/tasty/styles/place.js +1 -1
- package/es/tasty/styles/predefined.js +28 -27
- package/es/tasty/styles/preset.js +2 -2
- package/es/tasty/styles/radius.js +5 -12
- package/es/tasty/styles/reset.js +3 -7
- package/es/tasty/styles/scrollbar.js +2 -2
- package/es/tasty/styles/shadow.js +2 -2
- package/es/tasty/styles/styledScrollbar.js +1 -1
- package/es/tasty/styles/transition.js +10 -3
- package/es/tasty/styles/types.js +1 -1
- package/es/tasty/styles/width.js +2 -2
- package/es/tasty/tasty.js +81 -122
- package/es/tasty/types.js +1 -1
- package/es/tasty/utils/cache-wrapper.js +1 -1
- package/es/tasty/utils/case-converter.js +1 -1
- package/es/tasty/utils/colors.js +1 -1
- package/es/tasty/utils/dotize.js +1 -1
- package/es/tasty/utils/filterBaseProps.js +1 -1
- package/es/tasty/utils/getDisplayName.js +1 -1
- package/es/tasty/utils/isDevEnv.js +1 -1
- package/es/tasty/utils/mergeStyles.js +2 -2
- package/es/tasty/utils/modAttrs.js +3 -3
- package/es/tasty/utils/processTokens.js +88 -2
- package/es/tasty/utils/string.js +1 -1
- package/es/tasty/utils/styles.js +255 -22
- package/es/tasty/utils/typography.js +67 -0
- package/es/tasty/utils/warnings.js +1 -1
- package/es/tasty/zero/babel.js +453 -0
- package/es/tasty/zero/css-writer.js +94 -0
- package/es/tasty/zero/extractor.js +222 -0
- package/es/tasty/zero/index.js +28 -0
- package/es/tasty/zero/next.js +102 -0
- package/es/tokens/base.js +64 -0
- package/es/tokens/colors.js +68 -0
- package/es/tokens/index.js +63 -0
- package/es/tokens/layout.js +26 -0
- package/es/tokens/shadows.js +27 -0
- package/es/tokens/sizes.js +42 -0
- package/es/tokens/spacing.js +22 -0
- package/es/tokens/typography.js +237 -0
- package/es/utils/ResizeSensor.js +1 -1
- package/es/utils/index.js +10 -10
- package/es/utils/modules.js +1 -1
- package/es/utils/promise.js +1 -1
- package/es/utils/raf.js +1 -1
- package/es/utils/random.js +1 -1
- package/es/utils/range.js +1 -1
- package/es/utils/react/RenderCache.js +1 -1
- package/es/utils/react/Slots.js +2 -2
- package/es/utils/react/chain.js +1 -1
- package/es/utils/react/forwardRefWithGenerics.js +1 -1
- package/es/utils/react/index.js +17 -17
- package/es/utils/react/interactions.js +1 -1
- package/es/utils/react/isTextOnly.js +1 -1
- package/es/utils/react/mapProps.js +1 -1
- package/es/utils/react/mergeProps.js +4 -4
- package/es/utils/react/nullableValue.js +1 -1
- package/es/utils/react/resolveIcon.js +1 -1
- package/es/utils/react/sharedStore.js +2 -2
- package/es/utils/react/useCombinedRefs.js +1 -1
- package/es/utils/react/useControlledFocusVisible.js +2 -2
- package/es/utils/react/useEventBus.js +1 -1
- package/es/utils/react/useId.js +2 -2
- package/es/utils/react/useIsDarwin.js +1 -1
- package/es/utils/react/useKeySymbols.js +2 -2
- package/es/utils/react/useLayoutEffect.js +1 -1
- package/es/utils/react/useLocalStorage.js +2 -2
- package/es/utils/react/useQaProps.js +1 -1
- package/es/utils/react/useViewportSize.js +1 -1
- package/es/utils/react/wrapNodeIfPlain.js +1 -1
- package/es/utils/tree.js +1 -1
- package/es/utils/warnings.js +1 -1
- package/es/version.js +2 -2
- package/package.json +14 -4
- package/types/components/GlobalStyles.d.ts +2 -1
- package/types/components/HiddenInput.d.ts +828 -826
- package/types/components/Root.d.ts +1 -0
- package/types/components/actions/Button/Button.d.ts +1649 -1645
- package/types/components/actions/CommandMenu/styled.d.ts +4140 -4130
- package/types/components/actions/ItemActionContext.d.ts +1 -1
- package/types/components/actions/Menu/styled.d.ts +4893 -4883
- package/types/components/actions/use-action.d.ts +1 -1
- package/types/components/content/List/SectionHeading.d.ts +251 -251
- package/types/components/content/Text.d.ts +1487 -1487
- package/types/components/fields/DatePicker/DatePickerElement.d.ts +251 -251
- package/types/components/fields/Select/Select.d.ts +828 -826
- package/types/components/fields/Slider/elements.d.ts +4968 -4956
- package/types/components/overlays/AlertDialog/AlertDialog.d.ts +1 -1
- package/types/components/status/Spin/Cube.d.ts +1 -1
- package/types/components/status/Spin/SpinsContainer.d.ts +6 -3
- package/types/icons/SemanticQueryIcon.d.ts +4 -0
- package/types/icons/index.d.ts +1 -0
- package/types/index.d.ts +1 -4
- package/types/provider.d.ts +1 -2
- package/types/stories/components/StyledButton.d.ts +1 -1
- package/types/stories/playground/PlaygroundEditor.d.ts +6 -0
- package/types/stories/playground/PlaygroundLayout.d.ts +8 -0
- package/types/stories/playground/PlaygroundOutput.d.ts +5 -0
- package/types/stories/playground/PlaygroundPreview.d.ts +6 -0
- package/types/stories/playground/components/Button.d.ts +11 -0
- package/types/stories/playground/components/Card.d.ts +7 -0
- package/types/stories/playground/components/ScrollProgress.d.ts +5 -0
- package/types/stories/playground/examples.d.ts +7 -0
- package/types/tasty/chunks/cacheKey.d.ts +26 -0
- package/types/tasty/chunks/definitions.d.ts +75 -0
- package/types/tasty/chunks/index.d.ts +4 -0
- package/types/tasty/chunks/renderChunk.d.ts +25 -0
- package/types/tasty/config.d.ts +171 -0
- package/types/tasty/debug.d.ts +35 -0
- package/types/tasty/hooks/index.d.ts +4 -0
- package/types/tasty/hooks/useGlobalStyles.d.ts +22 -0
- package/types/tasty/hooks/useRawCSS.d.ts +50 -0
- package/types/tasty/hooks/useStyles.d.ts +35 -0
- package/types/tasty/index.d.ts +14 -4
- package/types/tasty/injector/index.d.ts +30 -19
- package/types/tasty/injector/injector.d.ts +19 -13
- package/types/tasty/injector/sheet-manager.d.ts +25 -1
- package/types/tasty/injector/types.d.ts +23 -2
- package/types/tasty/keyframes/index.d.ts +49 -0
- package/types/tasty/parser/parser.d.ts +4 -0
- package/types/tasty/parser/types.d.ts +1 -0
- package/types/tasty/pipeline/conditions.d.ts +243 -0
- package/types/tasty/pipeline/exclusive.d.ts +103 -0
- package/types/tasty/pipeline/index.d.ts +67 -0
- package/types/tasty/pipeline/materialize.d.ts +162 -0
- package/types/tasty/pipeline/parseStateKey.d.ts +20 -0
- package/types/tasty/pipeline/simplify.d.ts +28 -0
- package/types/tasty/plugins/index.d.ts +17 -0
- package/types/tasty/plugins/okhsl-plugin.d.ts +45 -0
- package/types/tasty/plugins/types.d.ts +34 -0
- package/types/tasty/states/index.d.ts +101 -0
- package/types/tasty/static/index.d.ts +39 -0
- package/types/tasty/static/tastyStatic.d.ts +41 -0
- package/types/tasty/static/types.d.ts +44 -0
- package/types/tasty/styles/fill.d.ts +11 -1
- package/types/tasty/styles/margin.d.ts +3 -1
- package/types/tasty/styles/padding.d.ts +3 -1
- package/types/tasty/styles/radius.d.ts +2 -10
- package/types/tasty/styles/types.d.ts +24 -3
- package/types/tasty/tasty.d.ts +892 -840
- package/types/tasty/utils/styles.d.ts +50 -6
- package/types/tasty/utils/typography.d.ts +32 -0
- package/types/tasty/zero/babel.d.ts +63 -0
- package/types/tasty/zero/css-writer.d.ts +41 -0
- package/types/tasty/zero/extractor.d.ts +40 -0
- package/types/tasty/zero/index.d.ts +18 -0
- package/types/tasty/zero/next.d.ts +57 -0
- package/types/tokens/base.d.ts +8 -0
- package/types/tokens/colors.d.ts +6 -0
- package/types/tokens/index.d.ts +41 -0
- package/types/tokens/layout.d.ts +7 -0
- package/types/tokens/shadows.d.ts +12 -0
- package/types/tokens/sizes.d.ts +25 -0
- package/types/tokens/spacing.d.ts +8 -0
- package/types/tokens/typography.d.ts +30 -0
- package/es/components/navigation/LegacyTabs/LegacyTabs.js +0 -275
- package/es/components/other/Base64Upload/Base64Upload.js +0 -103
- package/es/icons/add-new-icon.js +0 -129
- package/es/tasty/providers/BreakpointsProvider.js +0 -16
- package/es/tasty/utils/getModCombinations.js +0 -38
- package/es/tasty/utils/renderStyles.js +0 -1050
- package/es/tasty/utils/responsive.js +0 -60
- package/es/tokens.js +0 -309
- package/types/components/navigation/LegacyTabs/LegacyTabs.d.ts +0 -43
- package/types/components/other/Base64Upload/Base64Upload.d.ts +0 -5
- package/types/icons/add-new-icon.d.ts +0 -2
- package/types/tasty/providers/BreakpointsProvider.d.ts +0 -8
- package/types/tasty/utils/getModCombinations.d.ts +0 -9
- package/types/tasty/utils/renderStyles.d.ts +0 -41
- package/types/tasty/utils/responsive.d.ts +0 -8
- package/types/tokens.d.ts +0 -221
|
@@ -0,0 +1,1260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license MIT
|
|
3
|
+
* author: Cube Dev Team
|
|
4
|
+
* @cube-dev/ui-kit v0.99.0
|
|
5
|
+
* Released under the MIT license.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* CSS Materialization
|
|
10
|
+
*
|
|
11
|
+
* Converts condition trees into CSS selectors and at-rules.
|
|
12
|
+
* This is the final stage that produces actual CSS output.
|
|
13
|
+
*/
|
|
14
|
+
import { Lru } from '../parser/lru.js';
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// Caching
|
|
17
|
+
// ============================================================================
|
|
18
|
+
const conditionCache = new Lru(3000);
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// Main Functions
|
|
21
|
+
// ============================================================================
|
|
22
|
+
/**
|
|
23
|
+
* Convert a condition tree to CSS components
|
|
24
|
+
*/
|
|
25
|
+
export function conditionToCSS(node) {
|
|
26
|
+
// Check cache
|
|
27
|
+
const key = getConditionKey(node);
|
|
28
|
+
const cached = conditionCache.get(key);
|
|
29
|
+
if (cached) {
|
|
30
|
+
return cached;
|
|
31
|
+
}
|
|
32
|
+
const result = conditionToCSSInner(node);
|
|
33
|
+
// Cache result
|
|
34
|
+
conditionCache.set(key, result);
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Clear the condition cache (for testing)
|
|
39
|
+
*/
|
|
40
|
+
export function clearConditionCache() {
|
|
41
|
+
conditionCache.clear();
|
|
42
|
+
}
|
|
43
|
+
// ============================================================================
|
|
44
|
+
// Inner Implementation
|
|
45
|
+
// ============================================================================
|
|
46
|
+
/**
|
|
47
|
+
* Create an empty selector variant
|
|
48
|
+
*/
|
|
49
|
+
function emptyVariant() {
|
|
50
|
+
return {
|
|
51
|
+
modifierConditions: [],
|
|
52
|
+
pseudoConditions: [],
|
|
53
|
+
ownConditions: [],
|
|
54
|
+
mediaConditions: [],
|
|
55
|
+
containerConditions: [],
|
|
56
|
+
supportsConditions: [],
|
|
57
|
+
rootConditions: [],
|
|
58
|
+
startingStyle: false,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function conditionToCSSInner(node) {
|
|
62
|
+
// Base case: TRUE condition - single empty variant (matches everything)
|
|
63
|
+
if (node.kind === 'true') {
|
|
64
|
+
return {
|
|
65
|
+
variants: [emptyVariant()],
|
|
66
|
+
isImpossible: false,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
// Base case: FALSE condition - no variants (matches nothing)
|
|
70
|
+
if (node.kind === 'false') {
|
|
71
|
+
return {
|
|
72
|
+
variants: [],
|
|
73
|
+
isImpossible: true,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// State condition
|
|
77
|
+
if (node.kind === 'state') {
|
|
78
|
+
return stateToCSS(node);
|
|
79
|
+
}
|
|
80
|
+
// Compound condition
|
|
81
|
+
if (node.kind === 'compound') {
|
|
82
|
+
if (node.operator === 'AND') {
|
|
83
|
+
return andToCSS(node.children);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return orToCSS(node.children);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Fallback - single empty variant
|
|
90
|
+
return {
|
|
91
|
+
variants: [emptyVariant()],
|
|
92
|
+
isImpossible: false,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Convert a state condition to CSS
|
|
97
|
+
*/
|
|
98
|
+
function stateToCSS(state) {
|
|
99
|
+
switch (state.type) {
|
|
100
|
+
case 'media': {
|
|
101
|
+
// Media conditions can return multiple variants for negated ranges (OR branches)
|
|
102
|
+
const mediaResults = mediaToParsed(state);
|
|
103
|
+
const variants = mediaResults.map((mediaCond) => {
|
|
104
|
+
const v = emptyVariant();
|
|
105
|
+
v.mediaConditions.push(mediaCond);
|
|
106
|
+
return v;
|
|
107
|
+
});
|
|
108
|
+
return { variants, isImpossible: false };
|
|
109
|
+
}
|
|
110
|
+
default: {
|
|
111
|
+
const variant = emptyVariant();
|
|
112
|
+
switch (state.type) {
|
|
113
|
+
case 'modifier':
|
|
114
|
+
variant.modifierConditions.push(modifierToParsed(state));
|
|
115
|
+
break;
|
|
116
|
+
case 'pseudo':
|
|
117
|
+
variant.pseudoConditions.push(pseudoToParsed(state));
|
|
118
|
+
break;
|
|
119
|
+
case 'container':
|
|
120
|
+
variant.containerConditions.push(containerToParsed(state));
|
|
121
|
+
break;
|
|
122
|
+
case 'supports':
|
|
123
|
+
variant.supportsConditions.push(supportsToParsed(state));
|
|
124
|
+
break;
|
|
125
|
+
case 'root':
|
|
126
|
+
variant.rootConditions.push(rootToParsed(state));
|
|
127
|
+
break;
|
|
128
|
+
case 'own':
|
|
129
|
+
variant.ownConditions.push(...ownToParsed(state));
|
|
130
|
+
break;
|
|
131
|
+
case 'starting':
|
|
132
|
+
variant.startingStyle = !state.negated;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
variants: [variant],
|
|
137
|
+
isImpossible: false,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Convert modifier condition to parsed structure
|
|
144
|
+
*/
|
|
145
|
+
function modifierToParsed(state) {
|
|
146
|
+
return {
|
|
147
|
+
attribute: state.attribute,
|
|
148
|
+
value: state.value,
|
|
149
|
+
operator: state.operator,
|
|
150
|
+
negated: state.negated ?? false,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Convert parsed modifier to CSS selector string (for final output)
|
|
155
|
+
*/
|
|
156
|
+
export function modifierToCSS(mod) {
|
|
157
|
+
let selector;
|
|
158
|
+
if (mod.value !== undefined) {
|
|
159
|
+
// Value attribute: [data-attr="value"]
|
|
160
|
+
const op = mod.operator || '=';
|
|
161
|
+
selector = `[${mod.attribute}${op}"${mod.value}"]`;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
// Boolean attribute: [data-attr]
|
|
165
|
+
selector = `[${mod.attribute}]`;
|
|
166
|
+
}
|
|
167
|
+
if (mod.negated) {
|
|
168
|
+
return `:not(${selector})`;
|
|
169
|
+
}
|
|
170
|
+
return selector;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Convert pseudo condition to parsed structure
|
|
174
|
+
*/
|
|
175
|
+
function pseudoToParsed(state) {
|
|
176
|
+
return {
|
|
177
|
+
pseudo: state.pseudo,
|
|
178
|
+
negated: state.negated ?? false,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Convert parsed pseudo to CSS selector string (for final output)
|
|
183
|
+
*/
|
|
184
|
+
export function pseudoToCSS(pseudo) {
|
|
185
|
+
if (pseudo.negated) {
|
|
186
|
+
// Wrap in :not() if not already
|
|
187
|
+
if (pseudo.pseudo.startsWith(':not(')) {
|
|
188
|
+
// Double negation - remove :not()
|
|
189
|
+
return pseudo.pseudo.slice(5, -1);
|
|
190
|
+
}
|
|
191
|
+
return `:not(${pseudo.pseudo})`;
|
|
192
|
+
}
|
|
193
|
+
return pseudo.pseudo;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Convert media condition to parsed structure(s)
|
|
197
|
+
* Returns an array because negated ranges produce OR branches (two separate conditions)
|
|
198
|
+
*/
|
|
199
|
+
function mediaToParsed(state) {
|
|
200
|
+
if (state.subtype === 'type') {
|
|
201
|
+
// @media:print → @media print (or @media not print)
|
|
202
|
+
const mediaType = state.mediaType || 'all';
|
|
203
|
+
return [
|
|
204
|
+
{
|
|
205
|
+
subtype: 'type',
|
|
206
|
+
negated: state.negated ?? false,
|
|
207
|
+
condition: mediaType,
|
|
208
|
+
mediaType: state.mediaType,
|
|
209
|
+
},
|
|
210
|
+
];
|
|
211
|
+
}
|
|
212
|
+
else if (state.subtype === 'feature') {
|
|
213
|
+
// @media(prefers-contrast: high) → @media (prefers-contrast: high)
|
|
214
|
+
let condition;
|
|
215
|
+
if (state.featureValue) {
|
|
216
|
+
condition = `(${state.feature}: ${state.featureValue})`;
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
condition = `(${state.feature})`;
|
|
220
|
+
}
|
|
221
|
+
return [
|
|
222
|
+
{
|
|
223
|
+
subtype: 'feature',
|
|
224
|
+
negated: state.negated ?? false,
|
|
225
|
+
condition,
|
|
226
|
+
feature: state.feature,
|
|
227
|
+
featureValue: state.featureValue,
|
|
228
|
+
},
|
|
229
|
+
];
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
// Dimension query - negation is handled by inverting the condition
|
|
233
|
+
// because "not (width < x)" doesn't work reliably in browsers
|
|
234
|
+
return dimensionToMediaParsed(state.dimension || 'width', state.lowerBound, state.upperBound, state.negated ?? false);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Convert dimension bounds to parsed media condition(s)
|
|
239
|
+
* Uses CSS Media Queries Level 4 `not (condition)` syntax for negation.
|
|
240
|
+
*/
|
|
241
|
+
function dimensionToMediaParsed(dimension, lowerBound, upperBound, negated) {
|
|
242
|
+
// Build the condition string
|
|
243
|
+
let condition;
|
|
244
|
+
if (lowerBound && upperBound) {
|
|
245
|
+
const lowerOp = lowerBound.inclusive ? '<=' : '<';
|
|
246
|
+
const upperOp = upperBound.inclusive ? '<=' : '<';
|
|
247
|
+
condition = `(${lowerBound.value} ${lowerOp} ${dimension} ${upperOp} ${upperBound.value})`;
|
|
248
|
+
}
|
|
249
|
+
else if (upperBound) {
|
|
250
|
+
const op = upperBound.inclusive ? '<=' : '<';
|
|
251
|
+
condition = `(${dimension} ${op} ${upperBound.value})`;
|
|
252
|
+
}
|
|
253
|
+
else if (lowerBound) {
|
|
254
|
+
const op = lowerBound.inclusive ? '>=' : '>';
|
|
255
|
+
condition = `(${dimension} ${op} ${lowerBound.value})`;
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
condition = `(${dimension})`;
|
|
259
|
+
}
|
|
260
|
+
// For negation, we use CSS `not (condition)` syntax in buildAtRulesFromVariant
|
|
261
|
+
return [
|
|
262
|
+
{
|
|
263
|
+
subtype: 'dimension',
|
|
264
|
+
negated: negated ?? false,
|
|
265
|
+
condition,
|
|
266
|
+
dimension,
|
|
267
|
+
lowerBound,
|
|
268
|
+
upperBound,
|
|
269
|
+
},
|
|
270
|
+
];
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Convert container condition to parsed structure
|
|
274
|
+
* This enables structured analysis for contradiction detection and condition combining
|
|
275
|
+
*/
|
|
276
|
+
function containerToParsed(state) {
|
|
277
|
+
let condition;
|
|
278
|
+
if (state.subtype === 'style') {
|
|
279
|
+
// Style query: style(--prop: value)
|
|
280
|
+
if (state.propertyValue) {
|
|
281
|
+
condition = `style(--${state.property}: ${state.propertyValue})`;
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
condition = `style(--${state.property})`;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
// Dimension query
|
|
289
|
+
condition = dimensionToContainerCondition(state.dimension || 'width', state.lowerBound, state.upperBound);
|
|
290
|
+
}
|
|
291
|
+
return {
|
|
292
|
+
name: state.containerName,
|
|
293
|
+
condition,
|
|
294
|
+
negated: state.negated ?? false,
|
|
295
|
+
subtype: state.subtype,
|
|
296
|
+
property: state.property,
|
|
297
|
+
propertyValue: state.propertyValue,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Convert dimension bounds to container query condition (single string)
|
|
302
|
+
* Container queries support "not (condition)", so no need to invert manually
|
|
303
|
+
*/
|
|
304
|
+
function dimensionToContainerCondition(dimension, lowerBound, upperBound) {
|
|
305
|
+
if (lowerBound && upperBound) {
|
|
306
|
+
const lowerOp = lowerBound.inclusive ? '<=' : '<';
|
|
307
|
+
const upperOp = upperBound.inclusive ? '<=' : '<';
|
|
308
|
+
return `(${lowerBound.value} ${lowerOp} ${dimension} ${upperOp} ${upperBound.value})`;
|
|
309
|
+
}
|
|
310
|
+
else if (upperBound) {
|
|
311
|
+
const op = upperBound.inclusive ? '<=' : '<';
|
|
312
|
+
return `(${dimension} ${op} ${upperBound.value})`;
|
|
313
|
+
}
|
|
314
|
+
else if (lowerBound) {
|
|
315
|
+
const op = lowerBound.inclusive ? '>=' : '>';
|
|
316
|
+
return `(${dimension} ${op} ${lowerBound.value})`;
|
|
317
|
+
}
|
|
318
|
+
return '(width)'; // Fallback
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Convert supports condition to parsed structure
|
|
322
|
+
*/
|
|
323
|
+
function supportsToParsed(state) {
|
|
324
|
+
return {
|
|
325
|
+
subtype: state.subtype,
|
|
326
|
+
condition: state.condition,
|
|
327
|
+
negated: state.negated ?? false,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Convert root condition to parsed structure
|
|
332
|
+
*/
|
|
333
|
+
function rootToParsed(state) {
|
|
334
|
+
return {
|
|
335
|
+
selector: state.selector,
|
|
336
|
+
negated: state.negated ?? false,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Convert parsed root conditions to CSS selector prefix (for final output)
|
|
341
|
+
*/
|
|
342
|
+
export function rootConditionsToCSS(roots) {
|
|
343
|
+
if (roots.length === 0)
|
|
344
|
+
return undefined;
|
|
345
|
+
// Combine all root conditions into a single :root prefix
|
|
346
|
+
// e.g., :root[data-theme="dark"]:not([data-mode="light"])
|
|
347
|
+
let prefix = ':root';
|
|
348
|
+
for (const root of roots) {
|
|
349
|
+
if (root.negated) {
|
|
350
|
+
prefix += `:not(${root.selector})`;
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
prefix += root.selector;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return prefix;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Convert own condition to parsed structures for sub-element
|
|
360
|
+
*/
|
|
361
|
+
function ownToParsed(state) {
|
|
362
|
+
const innerCSS = conditionToCSS(state.innerCondition);
|
|
363
|
+
if (innerCSS.isImpossible || innerCSS.variants.length === 0) {
|
|
364
|
+
return [];
|
|
365
|
+
}
|
|
366
|
+
// Collect all modifier/pseudo conditions from all variants
|
|
367
|
+
const allConditions = [];
|
|
368
|
+
for (const variant of innerCSS.variants) {
|
|
369
|
+
for (const mod of variant.modifierConditions) {
|
|
370
|
+
// Apply outer negation
|
|
371
|
+
allConditions.push({
|
|
372
|
+
...mod,
|
|
373
|
+
negated: state.negated ? !mod.negated : mod.negated,
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
for (const pseudo of variant.pseudoConditions) {
|
|
377
|
+
// Apply outer negation
|
|
378
|
+
allConditions.push({
|
|
379
|
+
...pseudo,
|
|
380
|
+
negated: state.negated ? !pseudo.negated : pseudo.negated,
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return allConditions;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Get unique key for a modifier condition
|
|
388
|
+
*/
|
|
389
|
+
function getModifierKey(mod) {
|
|
390
|
+
const base = mod.value
|
|
391
|
+
? `${mod.attribute}${mod.operator || '='}${mod.value}`
|
|
392
|
+
: mod.attribute;
|
|
393
|
+
return mod.negated ? `!${base}` : base;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Get unique key for a pseudo condition
|
|
397
|
+
*/
|
|
398
|
+
function getPseudoKey(pseudo) {
|
|
399
|
+
return pseudo.negated ? `!${pseudo.pseudo}` : pseudo.pseudo;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Get unique key for a root condition
|
|
403
|
+
*/
|
|
404
|
+
function getRootKey(root) {
|
|
405
|
+
return root.negated ? `!${root.selector}` : root.selector;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Deduplicate modifier conditions
|
|
409
|
+
*/
|
|
410
|
+
function dedupeModifierConditions(conditions) {
|
|
411
|
+
const seen = new Set();
|
|
412
|
+
const result = [];
|
|
413
|
+
for (const c of conditions) {
|
|
414
|
+
const key = getModifierKey(c);
|
|
415
|
+
if (!seen.has(key)) {
|
|
416
|
+
seen.add(key);
|
|
417
|
+
result.push(c);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return result;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Deduplicate pseudo conditions
|
|
424
|
+
*/
|
|
425
|
+
function dedupePseudoConditions(conditions) {
|
|
426
|
+
const seen = new Set();
|
|
427
|
+
const result = [];
|
|
428
|
+
for (const c of conditions) {
|
|
429
|
+
const key = getPseudoKey(c);
|
|
430
|
+
if (!seen.has(key)) {
|
|
431
|
+
seen.add(key);
|
|
432
|
+
result.push(c);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return result;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Deduplicate root conditions
|
|
439
|
+
*/
|
|
440
|
+
function dedupeRootConditions(conditions) {
|
|
441
|
+
const seen = new Set();
|
|
442
|
+
const result = [];
|
|
443
|
+
for (const c of conditions) {
|
|
444
|
+
const key = getRootKey(c);
|
|
445
|
+
if (!seen.has(key)) {
|
|
446
|
+
seen.add(key);
|
|
447
|
+
result.push(c);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return result;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Deduplicate own conditions (modifiers or pseudos)
|
|
454
|
+
*/
|
|
455
|
+
function dedupeOwnConditions(conditions) {
|
|
456
|
+
const seen = new Set();
|
|
457
|
+
const result = [];
|
|
458
|
+
for (const c of conditions) {
|
|
459
|
+
const key = 'attribute' in c
|
|
460
|
+
? `mod:${getModifierKey(c)}`
|
|
461
|
+
: `pseudo:${getPseudoKey(c)}`;
|
|
462
|
+
if (!seen.has(key)) {
|
|
463
|
+
seen.add(key);
|
|
464
|
+
result.push(c);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return result;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Check for modifier contradiction: same attribute with opposite negation
|
|
471
|
+
*/
|
|
472
|
+
function hasModifierContradiction(conditions) {
|
|
473
|
+
const byKey = new Map(); // base key -> isPositive
|
|
474
|
+
for (const mod of conditions) {
|
|
475
|
+
const baseKey = mod.value
|
|
476
|
+
? `${mod.attribute}${mod.operator || '='}${mod.value}`
|
|
477
|
+
: mod.attribute;
|
|
478
|
+
const existing = byKey.get(baseKey);
|
|
479
|
+
if (existing !== undefined && existing !== !mod.negated) {
|
|
480
|
+
return true; // Same attribute with opposite negation
|
|
481
|
+
}
|
|
482
|
+
byKey.set(baseKey, !mod.negated);
|
|
483
|
+
}
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Check for pseudo contradiction: same pseudo with opposite negation
|
|
488
|
+
*/
|
|
489
|
+
function hasPseudoContradiction(conditions) {
|
|
490
|
+
const byKey = new Map(); // pseudo -> isPositive
|
|
491
|
+
for (const pseudo of conditions) {
|
|
492
|
+
const existing = byKey.get(pseudo.pseudo);
|
|
493
|
+
if (existing !== undefined && existing !== !pseudo.negated) {
|
|
494
|
+
return true; // Same pseudo with opposite negation
|
|
495
|
+
}
|
|
496
|
+
byKey.set(pseudo.pseudo, !pseudo.negated);
|
|
497
|
+
}
|
|
498
|
+
return false;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Check for root condition contradiction: same selector with opposite negation
|
|
502
|
+
*/
|
|
503
|
+
function hasRootContradiction(conditions) {
|
|
504
|
+
const byKey = new Map(); // selector -> isPositive
|
|
505
|
+
for (const root of conditions) {
|
|
506
|
+
const existing = byKey.get(root.selector);
|
|
507
|
+
if (existing !== undefined && existing !== !root.negated) {
|
|
508
|
+
return true; // Same selector with opposite negation
|
|
509
|
+
}
|
|
510
|
+
byKey.set(root.selector, !root.negated);
|
|
511
|
+
}
|
|
512
|
+
return false;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Check for own condition contradiction
|
|
516
|
+
*/
|
|
517
|
+
function hasOwnConditionContradiction(conditions) {
|
|
518
|
+
const modifiers = [];
|
|
519
|
+
const pseudos = [];
|
|
520
|
+
for (const c of conditions) {
|
|
521
|
+
if ('attribute' in c) {
|
|
522
|
+
modifiers.push(c);
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
pseudos.push(c);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
return hasModifierContradiction(modifiers) || hasPseudoContradiction(pseudos);
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Merge two selector variants (AND operation)
|
|
532
|
+
* Deduplicates conditions and checks for contradictions
|
|
533
|
+
*/
|
|
534
|
+
function mergeVariants(a, b) {
|
|
535
|
+
// Merge media conditions and check for contradictions
|
|
536
|
+
const mergedMedia = dedupeMediaConditions([
|
|
537
|
+
...a.mediaConditions,
|
|
538
|
+
...b.mediaConditions,
|
|
539
|
+
]);
|
|
540
|
+
if (hasMediaContradiction(mergedMedia)) {
|
|
541
|
+
return null; // Impossible variant
|
|
542
|
+
}
|
|
543
|
+
// Merge root conditions and check for contradictions
|
|
544
|
+
const mergedRoots = dedupeRootConditions([
|
|
545
|
+
...a.rootConditions,
|
|
546
|
+
...b.rootConditions,
|
|
547
|
+
]);
|
|
548
|
+
if (hasRootContradiction(mergedRoots)) {
|
|
549
|
+
return null; // Impossible variant
|
|
550
|
+
}
|
|
551
|
+
// Merge modifier conditions and check for contradictions
|
|
552
|
+
const mergedModifiers = dedupeModifierConditions([
|
|
553
|
+
...a.modifierConditions,
|
|
554
|
+
...b.modifierConditions,
|
|
555
|
+
]);
|
|
556
|
+
if (hasModifierContradiction(mergedModifiers)) {
|
|
557
|
+
return null; // Impossible variant
|
|
558
|
+
}
|
|
559
|
+
// Merge pseudo conditions and check for contradictions
|
|
560
|
+
const mergedPseudos = dedupePseudoConditions([
|
|
561
|
+
...a.pseudoConditions,
|
|
562
|
+
...b.pseudoConditions,
|
|
563
|
+
]);
|
|
564
|
+
if (hasPseudoContradiction(mergedPseudos)) {
|
|
565
|
+
return null; // Impossible variant
|
|
566
|
+
}
|
|
567
|
+
// Merge own conditions and check for contradictions
|
|
568
|
+
const mergedOwn = dedupeOwnConditions([
|
|
569
|
+
...a.ownConditions,
|
|
570
|
+
...b.ownConditions,
|
|
571
|
+
]);
|
|
572
|
+
if (hasOwnConditionContradiction(mergedOwn)) {
|
|
573
|
+
return null; // Impossible variant
|
|
574
|
+
}
|
|
575
|
+
// Merge container conditions and check for contradictions
|
|
576
|
+
const mergedContainers = dedupeContainerConditions([
|
|
577
|
+
...a.containerConditions,
|
|
578
|
+
...b.containerConditions,
|
|
579
|
+
]);
|
|
580
|
+
if (hasContainerStyleContradiction(mergedContainers)) {
|
|
581
|
+
return null; // Impossible variant
|
|
582
|
+
}
|
|
583
|
+
// Merge supports conditions and check for contradictions
|
|
584
|
+
const mergedSupports = dedupeSupportsConditions([
|
|
585
|
+
...a.supportsConditions,
|
|
586
|
+
...b.supportsConditions,
|
|
587
|
+
]);
|
|
588
|
+
if (hasSupportsContradiction(mergedSupports)) {
|
|
589
|
+
return null; // Impossible variant
|
|
590
|
+
}
|
|
591
|
+
return {
|
|
592
|
+
modifierConditions: mergedModifiers,
|
|
593
|
+
pseudoConditions: mergedPseudos,
|
|
594
|
+
ownConditions: mergedOwn,
|
|
595
|
+
mediaConditions: mergedMedia,
|
|
596
|
+
containerConditions: mergedContainers,
|
|
597
|
+
supportsConditions: mergedSupports,
|
|
598
|
+
rootConditions: mergedRoots,
|
|
599
|
+
startingStyle: a.startingStyle || b.startingStyle,
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Deduplicate media conditions by their key (subtype + condition + negated)
|
|
604
|
+
*/
|
|
605
|
+
function dedupeMediaConditions(conditions) {
|
|
606
|
+
const seen = new Set();
|
|
607
|
+
const result = [];
|
|
608
|
+
for (const c of conditions) {
|
|
609
|
+
const key = `${c.subtype}|${c.condition}|${c.negated}`;
|
|
610
|
+
if (!seen.has(key)) {
|
|
611
|
+
seen.add(key);
|
|
612
|
+
result.push(c);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
return result;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Deduplicate container conditions by their key (name + condition + negated)
|
|
619
|
+
*/
|
|
620
|
+
function dedupeContainerConditions(conditions) {
|
|
621
|
+
const seen = new Set();
|
|
622
|
+
const result = [];
|
|
623
|
+
for (const c of conditions) {
|
|
624
|
+
const key = `${c.name ?? ''}|${c.condition}|${c.negated}`;
|
|
625
|
+
if (!seen.has(key)) {
|
|
626
|
+
seen.add(key);
|
|
627
|
+
result.push(c);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return result;
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Deduplicate supports conditions by their key (subtype + condition + negated)
|
|
634
|
+
*/
|
|
635
|
+
function dedupeSupportsConditions(conditions) {
|
|
636
|
+
const seen = new Set();
|
|
637
|
+
const result = [];
|
|
638
|
+
for (const c of conditions) {
|
|
639
|
+
const key = `${c.subtype}|${c.condition}|${c.negated}`;
|
|
640
|
+
if (!seen.has(key)) {
|
|
641
|
+
seen.add(key);
|
|
642
|
+
result.push(c);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return result;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Check if supports conditions contain contradictions
|
|
649
|
+
* e.g., @supports(display: grid) AND NOT @supports(display: grid)
|
|
650
|
+
*/
|
|
651
|
+
function hasSupportsContradiction(conditions) {
|
|
652
|
+
const conditionMap = new Map(); // key -> isPositive
|
|
653
|
+
for (const cond of conditions) {
|
|
654
|
+
const key = `${cond.subtype}|${cond.condition}`;
|
|
655
|
+
const existing = conditionMap.get(key);
|
|
656
|
+
if (existing !== undefined && existing !== !cond.negated) {
|
|
657
|
+
return true; // Contradiction: positive AND negated
|
|
658
|
+
}
|
|
659
|
+
conditionMap.set(key, !cond.negated);
|
|
660
|
+
}
|
|
661
|
+
return false;
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Check if a set of media conditions contains contradictions
|
|
665
|
+
* e.g., (prefers-color-scheme: light) AND NOT (prefers-color-scheme: light)
|
|
666
|
+
* or (width >= 900px) AND (width < 600px)
|
|
667
|
+
*
|
|
668
|
+
* Uses parsed media conditions for efficient analysis without regex parsing.
|
|
669
|
+
*/
|
|
670
|
+
function hasMediaContradiction(conditions) {
|
|
671
|
+
// Track conditions by their key (condition string) to detect A and NOT A
|
|
672
|
+
const featureConditions = new Map(); // key -> isPositive
|
|
673
|
+
const typeConditions = new Map(); // mediaType -> isPositive
|
|
674
|
+
const dimensionConditions = new Map(); // condition -> isPositive
|
|
675
|
+
// Track dimension conditions for range contradiction detection (non-negated only)
|
|
676
|
+
const dimensionsByDim = new Map();
|
|
677
|
+
for (const cond of conditions) {
|
|
678
|
+
if (cond.subtype === 'type') {
|
|
679
|
+
// Type query: check for direct contradiction (print AND NOT print)
|
|
680
|
+
const key = cond.mediaType || 'all';
|
|
681
|
+
const existing = typeConditions.get(key);
|
|
682
|
+
if (existing !== undefined && existing !== !cond.negated) {
|
|
683
|
+
return true; // Contradiction: positive AND negated
|
|
684
|
+
}
|
|
685
|
+
typeConditions.set(key, !cond.negated);
|
|
686
|
+
}
|
|
687
|
+
else if (cond.subtype === 'feature') {
|
|
688
|
+
// Feature query: check for direct contradiction
|
|
689
|
+
const key = cond.condition;
|
|
690
|
+
const existing = featureConditions.get(key);
|
|
691
|
+
if (existing !== undefined && existing !== !cond.negated) {
|
|
692
|
+
return true; // Contradiction: positive AND negated
|
|
693
|
+
}
|
|
694
|
+
featureConditions.set(key, !cond.negated);
|
|
695
|
+
}
|
|
696
|
+
else if (cond.subtype === 'dimension') {
|
|
697
|
+
// First, check for direct contradiction: (width < 600px) AND NOT (width < 600px)
|
|
698
|
+
const condKey = cond.condition;
|
|
699
|
+
const existing = dimensionConditions.get(condKey);
|
|
700
|
+
if (existing !== undefined && existing !== !cond.negated) {
|
|
701
|
+
return true; // Contradiction: positive AND negated
|
|
702
|
+
}
|
|
703
|
+
dimensionConditions.set(condKey, !cond.negated);
|
|
704
|
+
// For range analysis, only consider non-negated conditions
|
|
705
|
+
// Negated conditions are handled via the direct contradiction check above
|
|
706
|
+
if (!cond.negated) {
|
|
707
|
+
const dim = cond.dimension || 'width';
|
|
708
|
+
let bounds = dimensionsByDim.get(dim);
|
|
709
|
+
if (!bounds) {
|
|
710
|
+
bounds = { lowerBound: null, upperBound: null };
|
|
711
|
+
dimensionsByDim.set(dim, bounds);
|
|
712
|
+
}
|
|
713
|
+
// Track the effective bounds
|
|
714
|
+
if (cond.lowerBound?.valueNumeric != null) {
|
|
715
|
+
const value = cond.lowerBound.valueNumeric;
|
|
716
|
+
if (bounds.lowerBound === null || value > bounds.lowerBound) {
|
|
717
|
+
bounds.lowerBound = value;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
if (cond.upperBound?.valueNumeric != null) {
|
|
721
|
+
const value = cond.upperBound.valueNumeric;
|
|
722
|
+
if (bounds.upperBound === null || value < bounds.upperBound) {
|
|
723
|
+
bounds.upperBound = value;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
// Check for impossible range
|
|
727
|
+
if (bounds.lowerBound !== null &&
|
|
728
|
+
bounds.upperBound !== null &&
|
|
729
|
+
bounds.lowerBound >= bounds.upperBound) {
|
|
730
|
+
return true;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
return false;
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Check if container conditions contain contradictions in style queries
|
|
739
|
+
* e.g., style(--variant: danger) and style(--variant: success) together
|
|
740
|
+
* Same property with different values = always false
|
|
741
|
+
*
|
|
742
|
+
* Uses parsed container conditions for efficient analysis without regex parsing.
|
|
743
|
+
*/
|
|
744
|
+
function hasContainerStyleContradiction(conditions) {
|
|
745
|
+
// Track style queries by property name
|
|
746
|
+
// key: property name, value: { hasExistence: boolean, values: Set<string>, hasNegatedExistence: boolean }
|
|
747
|
+
const styleQueries = new Map();
|
|
748
|
+
for (const cond of conditions) {
|
|
749
|
+
// Only analyze style queries
|
|
750
|
+
if (cond.subtype !== 'style' || !cond.property) {
|
|
751
|
+
continue;
|
|
752
|
+
}
|
|
753
|
+
const property = cond.property;
|
|
754
|
+
const value = cond.propertyValue;
|
|
755
|
+
if (!styleQueries.has(property)) {
|
|
756
|
+
styleQueries.set(property, {
|
|
757
|
+
hasExistence: false,
|
|
758
|
+
values: new Set(),
|
|
759
|
+
hasNegatedExistence: false,
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
const entry = styleQueries.get(property);
|
|
763
|
+
if (cond.negated) {
|
|
764
|
+
if (value === undefined) {
|
|
765
|
+
// not style(--prop) - negated existence check
|
|
766
|
+
entry.hasNegatedExistence = true;
|
|
767
|
+
}
|
|
768
|
+
// Negated value checks don't contradict positive value checks directly
|
|
769
|
+
// They just mean "not this value"
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
if (value === undefined) {
|
|
773
|
+
// style(--prop) - existence check
|
|
774
|
+
entry.hasExistence = true;
|
|
775
|
+
}
|
|
776
|
+
else {
|
|
777
|
+
// style(--prop: value) - value check
|
|
778
|
+
entry.values.add(value);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
// Check for contradictions
|
|
783
|
+
for (const [, entry] of styleQueries) {
|
|
784
|
+
// Contradiction: existence check + negated existence check
|
|
785
|
+
if (entry.hasExistence && entry.hasNegatedExistence) {
|
|
786
|
+
return true;
|
|
787
|
+
}
|
|
788
|
+
// Contradiction: multiple different values for same property
|
|
789
|
+
// style(--variant: danger) AND style(--variant: success) is impossible
|
|
790
|
+
if (entry.values.size > 1) {
|
|
791
|
+
return true;
|
|
792
|
+
}
|
|
793
|
+
// Contradiction: negated existence + value check
|
|
794
|
+
// not style(--variant) AND style(--variant: danger) is impossible
|
|
795
|
+
if (entry.hasNegatedExistence && entry.values.size > 0) {
|
|
796
|
+
return true;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
return false;
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Get a unique key for a variant (for deduplication)
|
|
803
|
+
*/
|
|
804
|
+
function getVariantKey(v) {
|
|
805
|
+
const modifierKey = v.modifierConditions.map(getModifierKey).sort().join('|');
|
|
806
|
+
const pseudoKey = v.pseudoConditions.map(getPseudoKey).sort().join('|');
|
|
807
|
+
const ownKey = v.ownConditions
|
|
808
|
+
.map((c) => 'attribute' in c
|
|
809
|
+
? `mod:${getModifierKey(c)}`
|
|
810
|
+
: `pseudo:${getPseudoKey(c)}`)
|
|
811
|
+
.sort()
|
|
812
|
+
.join('|');
|
|
813
|
+
const containerKey = v.containerConditions
|
|
814
|
+
.map((c) => `${c.name ?? ''}:${c.negated ? '!' : ''}${c.condition}`)
|
|
815
|
+
.sort()
|
|
816
|
+
.join('|');
|
|
817
|
+
const mediaKey = v.mediaConditions
|
|
818
|
+
.map((c) => `${c.subtype}:${c.negated ? '!' : ''}${c.condition}`)
|
|
819
|
+
.sort()
|
|
820
|
+
.join('|');
|
|
821
|
+
const supportsKey = v.supportsConditions
|
|
822
|
+
.map((c) => `${c.subtype}:${c.negated ? '!' : ''}${c.condition}`)
|
|
823
|
+
.sort()
|
|
824
|
+
.join('|');
|
|
825
|
+
const rootKey = v.rootConditions.map(getRootKey).sort().join('|');
|
|
826
|
+
return [
|
|
827
|
+
modifierKey,
|
|
828
|
+
pseudoKey,
|
|
829
|
+
ownKey,
|
|
830
|
+
mediaKey,
|
|
831
|
+
containerKey,
|
|
832
|
+
supportsKey,
|
|
833
|
+
rootKey,
|
|
834
|
+
v.startingStyle ? '1' : '0',
|
|
835
|
+
].join('###');
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Check if variant A is a superset of variant B (A is more restrictive)
|
|
839
|
+
*
|
|
840
|
+
* If A has all of B's conditions plus more, then A is redundant
|
|
841
|
+
* because B already covers the same cases (and more).
|
|
842
|
+
*
|
|
843
|
+
* Example:
|
|
844
|
+
* A: :not([size=large]):not([size=medium]):not([size=small])
|
|
845
|
+
* B: :not([size=large])
|
|
846
|
+
* A is a superset of B, so A is redundant when B exists.
|
|
847
|
+
*/
|
|
848
|
+
function isVariantSuperset(a, b) {
|
|
849
|
+
// Must have same context
|
|
850
|
+
if (a.startingStyle !== b.startingStyle)
|
|
851
|
+
return false;
|
|
852
|
+
// Check if a.rootConditions is superset of b.rootConditions
|
|
853
|
+
if (!isRootConditionsSuperset(a.rootConditions, b.rootConditions))
|
|
854
|
+
return false;
|
|
855
|
+
// Check if a.mediaConditions is superset of b.mediaConditions
|
|
856
|
+
if (!isMediaConditionsSuperset(a.mediaConditions, b.mediaConditions))
|
|
857
|
+
return false;
|
|
858
|
+
// Check if a.containerConditions is superset of b.containerConditions
|
|
859
|
+
if (!isContainerConditionsSuperset(a.containerConditions, b.containerConditions))
|
|
860
|
+
return false;
|
|
861
|
+
// Check if a.supportsConditions is superset of b.supportsConditions
|
|
862
|
+
if (!isSupportsConditionsSuperset(a.supportsConditions, b.supportsConditions))
|
|
863
|
+
return false;
|
|
864
|
+
// Check if a.modifierConditions is superset of b.modifierConditions
|
|
865
|
+
if (!isModifierConditionsSuperset(a.modifierConditions, b.modifierConditions))
|
|
866
|
+
return false;
|
|
867
|
+
// Check if a.pseudoConditions is superset of b.pseudoConditions
|
|
868
|
+
if (!isPseudoConditionsSuperset(a.pseudoConditions, b.pseudoConditions))
|
|
869
|
+
return false;
|
|
870
|
+
// Check if a.ownConditions is superset of b.ownConditions
|
|
871
|
+
if (!isOwnConditionsSuperset(a.ownConditions, b.ownConditions))
|
|
872
|
+
return false;
|
|
873
|
+
// A is a superset if it has all of B's items (possibly more)
|
|
874
|
+
// and at least one category has strictly more items
|
|
875
|
+
const aTotal = a.mediaConditions.length +
|
|
876
|
+
a.containerConditions.length +
|
|
877
|
+
a.supportsConditions.length +
|
|
878
|
+
a.modifierConditions.length +
|
|
879
|
+
a.pseudoConditions.length +
|
|
880
|
+
a.rootConditions.length +
|
|
881
|
+
a.ownConditions.length;
|
|
882
|
+
const bTotal = b.mediaConditions.length +
|
|
883
|
+
b.containerConditions.length +
|
|
884
|
+
b.supportsConditions.length +
|
|
885
|
+
b.modifierConditions.length +
|
|
886
|
+
b.pseudoConditions.length +
|
|
887
|
+
b.rootConditions.length +
|
|
888
|
+
b.ownConditions.length;
|
|
889
|
+
return aTotal > bTotal;
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Check if media conditions A is a superset of B
|
|
893
|
+
*/
|
|
894
|
+
function isMediaConditionsSuperset(a, b) {
|
|
895
|
+
const aKeys = new Set(a.map((c) => `${c.subtype}|${c.condition}|${c.negated}`));
|
|
896
|
+
for (const c of b) {
|
|
897
|
+
const key = `${c.subtype}|${c.condition}|${c.negated}`;
|
|
898
|
+
if (!aKeys.has(key))
|
|
899
|
+
return false;
|
|
900
|
+
}
|
|
901
|
+
return true;
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Check if container conditions A is a superset of B
|
|
905
|
+
*/
|
|
906
|
+
function isContainerConditionsSuperset(a, b) {
|
|
907
|
+
const aKeys = new Set(a.map((c) => `${c.name ?? ''}|${c.condition}|${c.negated}`));
|
|
908
|
+
for (const c of b) {
|
|
909
|
+
const key = `${c.name ?? ''}|${c.condition}|${c.negated}`;
|
|
910
|
+
if (!aKeys.has(key))
|
|
911
|
+
return false;
|
|
912
|
+
}
|
|
913
|
+
return true;
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Check if supports conditions A is a superset of B
|
|
917
|
+
*/
|
|
918
|
+
function isSupportsConditionsSuperset(a, b) {
|
|
919
|
+
const aKeys = new Set(a.map((c) => `${c.subtype}|${c.condition}|${c.negated}`));
|
|
920
|
+
for (const c of b) {
|
|
921
|
+
const key = `${c.subtype}|${c.condition}|${c.negated}`;
|
|
922
|
+
if (!aKeys.has(key))
|
|
923
|
+
return false;
|
|
924
|
+
}
|
|
925
|
+
return true;
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Check if modifier conditions A is a superset of B
|
|
929
|
+
*/
|
|
930
|
+
function isModifierConditionsSuperset(a, b) {
|
|
931
|
+
const aKeys = new Set(a.map(getModifierKey));
|
|
932
|
+
for (const c of b) {
|
|
933
|
+
if (!aKeys.has(getModifierKey(c)))
|
|
934
|
+
return false;
|
|
935
|
+
}
|
|
936
|
+
return true;
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* Check if pseudo conditions A is a superset of B
|
|
940
|
+
*/
|
|
941
|
+
function isPseudoConditionsSuperset(a, b) {
|
|
942
|
+
const aKeys = new Set(a.map(getPseudoKey));
|
|
943
|
+
for (const c of b) {
|
|
944
|
+
if (!aKeys.has(getPseudoKey(c)))
|
|
945
|
+
return false;
|
|
946
|
+
}
|
|
947
|
+
return true;
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Check if root conditions A is a superset of B
|
|
951
|
+
*/
|
|
952
|
+
function isRootConditionsSuperset(a, b) {
|
|
953
|
+
const aKeys = new Set(a.map(getRootKey));
|
|
954
|
+
for (const c of b) {
|
|
955
|
+
if (!aKeys.has(getRootKey(c)))
|
|
956
|
+
return false;
|
|
957
|
+
}
|
|
958
|
+
return true;
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Check if own conditions A is a superset of B
|
|
962
|
+
*/
|
|
963
|
+
function isOwnConditionsSuperset(a, b) {
|
|
964
|
+
const aKeys = new Set(a.map((c) => 'attribute' in c
|
|
965
|
+
? `mod:${getModifierKey(c)}`
|
|
966
|
+
: `pseudo:${getPseudoKey(c)}`));
|
|
967
|
+
for (const c of b) {
|
|
968
|
+
const key = 'attribute' in c
|
|
969
|
+
? `mod:${getModifierKey(c)}`
|
|
970
|
+
: `pseudo:${getPseudoKey(c)}`;
|
|
971
|
+
if (!aKeys.has(key))
|
|
972
|
+
return false;
|
|
973
|
+
}
|
|
974
|
+
return true;
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* Deduplicate variants
|
|
978
|
+
*
|
|
979
|
+
* Removes:
|
|
980
|
+
* 1. Exact duplicates (same key)
|
|
981
|
+
* 2. Superset variants (more restrictive selectors that are redundant)
|
|
982
|
+
*/
|
|
983
|
+
function dedupeVariants(variants) {
|
|
984
|
+
// First pass: exact deduplication
|
|
985
|
+
const seen = new Set();
|
|
986
|
+
let result = [];
|
|
987
|
+
for (const v of variants) {
|
|
988
|
+
const key = getVariantKey(v);
|
|
989
|
+
if (!seen.has(key)) {
|
|
990
|
+
seen.add(key);
|
|
991
|
+
result.push(v);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
// Second pass: remove supersets (more restrictive variants)
|
|
995
|
+
// Sort by total condition count (fewer conditions = less restrictive = keep)
|
|
996
|
+
result.sort((a, b) => {
|
|
997
|
+
const aCount = a.modifierConditions.length +
|
|
998
|
+
a.pseudoConditions.length +
|
|
999
|
+
a.ownConditions.length +
|
|
1000
|
+
a.mediaConditions.length +
|
|
1001
|
+
a.containerConditions.length +
|
|
1002
|
+
a.supportsConditions.length +
|
|
1003
|
+
a.rootConditions.length;
|
|
1004
|
+
const bCount = b.modifierConditions.length +
|
|
1005
|
+
b.pseudoConditions.length +
|
|
1006
|
+
b.ownConditions.length +
|
|
1007
|
+
b.mediaConditions.length +
|
|
1008
|
+
b.containerConditions.length +
|
|
1009
|
+
b.supportsConditions.length +
|
|
1010
|
+
b.rootConditions.length;
|
|
1011
|
+
return aCount - bCount;
|
|
1012
|
+
});
|
|
1013
|
+
// Remove variants that are supersets of earlier (less restrictive) variants
|
|
1014
|
+
const filtered = [];
|
|
1015
|
+
for (const candidate of result) {
|
|
1016
|
+
let isRedundant = false;
|
|
1017
|
+
for (const kept of filtered) {
|
|
1018
|
+
if (isVariantSuperset(candidate, kept)) {
|
|
1019
|
+
isRedundant = true;
|
|
1020
|
+
break;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
if (!isRedundant) {
|
|
1024
|
+
filtered.push(candidate);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
return filtered;
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* Combine AND conditions into CSS
|
|
1031
|
+
*
|
|
1032
|
+
* AND of conditions means cartesian product of variants:
|
|
1033
|
+
* (A1 | A2) & (B1 | B2) = A1&B1 | A1&B2 | A2&B1 | A2&B2
|
|
1034
|
+
*
|
|
1035
|
+
* Variants that result in contradictions (e.g., conflicting media rules)
|
|
1036
|
+
* are filtered out.
|
|
1037
|
+
*/
|
|
1038
|
+
function andToCSS(children) {
|
|
1039
|
+
// Start with a single empty variant
|
|
1040
|
+
let currentVariants = [emptyVariant()];
|
|
1041
|
+
for (const child of children) {
|
|
1042
|
+
const childCSS = conditionToCSSInner(child);
|
|
1043
|
+
if (childCSS.isImpossible || childCSS.variants.length === 0) {
|
|
1044
|
+
return { variants: [], isImpossible: true };
|
|
1045
|
+
}
|
|
1046
|
+
// Cartesian product: each current variant × each child variant
|
|
1047
|
+
const newVariants = [];
|
|
1048
|
+
for (const current of currentVariants) {
|
|
1049
|
+
for (const childVariant of childCSS.variants) {
|
|
1050
|
+
const merged = mergeVariants(current, childVariant);
|
|
1051
|
+
// Skip impossible variants (contradictions detected during merge)
|
|
1052
|
+
if (merged !== null) {
|
|
1053
|
+
newVariants.push(merged);
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
if (newVariants.length === 0) {
|
|
1058
|
+
return { variants: [], isImpossible: true };
|
|
1059
|
+
}
|
|
1060
|
+
// Deduplicate after each step to prevent exponential blowup
|
|
1061
|
+
currentVariants = dedupeVariants(newVariants);
|
|
1062
|
+
}
|
|
1063
|
+
return {
|
|
1064
|
+
variants: currentVariants,
|
|
1065
|
+
isImpossible: false,
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Combine OR conditions into CSS
|
|
1070
|
+
*
|
|
1071
|
+
* OR in CSS means multiple selector variants (DNF).
|
|
1072
|
+
* Each variant becomes a separate selector in the comma-separated list,
|
|
1073
|
+
* or multiple CSS rules if they have different at-rules.
|
|
1074
|
+
*
|
|
1075
|
+
* Note: OR exclusivity is handled at the pipeline level (expandOrConditions),
|
|
1076
|
+
* so here we just collect all variants. Any remaining ORs in the condition
|
|
1077
|
+
* tree (e.g., from De Morgan expansion) are handled as simple alternatives.
|
|
1078
|
+
*/
|
|
1079
|
+
function orToCSS(children) {
|
|
1080
|
+
const allVariants = [];
|
|
1081
|
+
for (const child of children) {
|
|
1082
|
+
const childCSS = conditionToCSSInner(child);
|
|
1083
|
+
if (childCSS.isImpossible)
|
|
1084
|
+
continue;
|
|
1085
|
+
allVariants.push(...childCSS.variants);
|
|
1086
|
+
}
|
|
1087
|
+
if (allVariants.length === 0) {
|
|
1088
|
+
return { variants: [], isImpossible: true };
|
|
1089
|
+
}
|
|
1090
|
+
// Deduplicate variants
|
|
1091
|
+
return {
|
|
1092
|
+
variants: dedupeVariants(allVariants),
|
|
1093
|
+
isImpossible: false,
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
// ============================================================================
|
|
1097
|
+
// Utility Functions
|
|
1098
|
+
// ============================================================================
|
|
1099
|
+
/**
|
|
1100
|
+
* Get a cache key for a condition
|
|
1101
|
+
*/
|
|
1102
|
+
function getConditionKey(node) {
|
|
1103
|
+
if (node.kind === 'true')
|
|
1104
|
+
return 'TRUE';
|
|
1105
|
+
if (node.kind === 'false')
|
|
1106
|
+
return 'FALSE';
|
|
1107
|
+
if (node.kind === 'state')
|
|
1108
|
+
return node.uniqueId;
|
|
1109
|
+
if (node.kind === 'compound') {
|
|
1110
|
+
const childKeys = node.children.map(getConditionKey).sort();
|
|
1111
|
+
return `${node.operator}(${childKeys.join(',')})`;
|
|
1112
|
+
}
|
|
1113
|
+
return 'UNKNOWN';
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* Build a complete CSS selector from a single variant
|
|
1117
|
+
*/
|
|
1118
|
+
function buildCSSSelectorFromVariant(className, variant, selectorSuffix = '') {
|
|
1119
|
+
// Start with base class (doubled for specificity)
|
|
1120
|
+
let selector = `.${className}.${className}`;
|
|
1121
|
+
// Add modifier selectors
|
|
1122
|
+
for (const mod of variant.modifierConditions) {
|
|
1123
|
+
selector += modifierToCSS(mod);
|
|
1124
|
+
}
|
|
1125
|
+
// Add pseudo selectors
|
|
1126
|
+
for (const pseudo of variant.pseudoConditions) {
|
|
1127
|
+
selector += pseudoToCSS(pseudo);
|
|
1128
|
+
}
|
|
1129
|
+
// Add selector suffix (e.g., ' [data-element="Label"]')
|
|
1130
|
+
selector += selectorSuffix;
|
|
1131
|
+
// Add own selectors (after sub-element)
|
|
1132
|
+
for (const own of variant.ownConditions) {
|
|
1133
|
+
if ('attribute' in own) {
|
|
1134
|
+
selector += modifierToCSS(own);
|
|
1135
|
+
}
|
|
1136
|
+
else {
|
|
1137
|
+
selector += pseudoToCSS(own);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
// Add root prefix if present
|
|
1141
|
+
const rootPrefix = rootConditionsToCSS(variant.rootConditions);
|
|
1142
|
+
if (rootPrefix) {
|
|
1143
|
+
selector = `${rootPrefix} ${selector}`;
|
|
1144
|
+
}
|
|
1145
|
+
return selector;
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Build at-rules array from a variant
|
|
1149
|
+
*/
|
|
1150
|
+
export function buildAtRulesFromVariant(variant) {
|
|
1151
|
+
const atRules = [];
|
|
1152
|
+
// Add media rules - combine all conditions with "and"
|
|
1153
|
+
if (variant.mediaConditions.length > 0) {
|
|
1154
|
+
const conditionParts = variant.mediaConditions.map((c) => {
|
|
1155
|
+
if (c.subtype === 'type') {
|
|
1156
|
+
// Media type: print, screen, etc.
|
|
1157
|
+
return c.negated ? `not ${c.condition}` : c.condition;
|
|
1158
|
+
}
|
|
1159
|
+
else {
|
|
1160
|
+
// Feature or dimension: use not (condition) syntax for negation
|
|
1161
|
+
// MQ Level 4 requires parentheses around the condition for negation
|
|
1162
|
+
return c.negated ? `(not ${c.condition})` : c.condition;
|
|
1163
|
+
}
|
|
1164
|
+
});
|
|
1165
|
+
atRules.push(`@media ${conditionParts.join(' and ')}`);
|
|
1166
|
+
}
|
|
1167
|
+
// Add container rules - group by container name and combine with "and"
|
|
1168
|
+
if (variant.containerConditions.length > 0) {
|
|
1169
|
+
// Group conditions by container name (undefined = unnamed/nearest)
|
|
1170
|
+
const byName = new Map();
|
|
1171
|
+
for (const cond of variant.containerConditions) {
|
|
1172
|
+
const group = byName.get(cond.name) || [];
|
|
1173
|
+
group.push(cond);
|
|
1174
|
+
byName.set(cond.name, group);
|
|
1175
|
+
}
|
|
1176
|
+
// Build one @container rule per container name
|
|
1177
|
+
for (const [name, conditions] of byName) {
|
|
1178
|
+
// CSS Container Query syntax requires parentheses around negated conditions:
|
|
1179
|
+
// @container (not style(--x)) and style(--y) - NOT @container not style(--x) and style(--y)
|
|
1180
|
+
const conditionParts = conditions.map((c) => c.negated ? `(not ${c.condition})` : c.condition);
|
|
1181
|
+
const namePrefix = name ? `${name} ` : '';
|
|
1182
|
+
atRules.push(`@container ${namePrefix}${conditionParts.join(' and ')}`);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
// Add supports rules - combine all conditions with "and"
|
|
1186
|
+
if (variant.supportsConditions.length > 0) {
|
|
1187
|
+
const conditionParts = variant.supportsConditions.map((c) => {
|
|
1188
|
+
// Build the condition based on subtype
|
|
1189
|
+
// feature: (display: grid) or (not (display: grid))
|
|
1190
|
+
// selector: selector(:has(*)) or (not selector(:has(*)))
|
|
1191
|
+
if (c.subtype === 'selector') {
|
|
1192
|
+
const selectorCond = `selector(${c.condition})`;
|
|
1193
|
+
return c.negated ? `(not ${selectorCond})` : selectorCond;
|
|
1194
|
+
}
|
|
1195
|
+
else {
|
|
1196
|
+
const featureCond = `(${c.condition})`;
|
|
1197
|
+
return c.negated ? `(not ${featureCond})` : featureCond;
|
|
1198
|
+
}
|
|
1199
|
+
});
|
|
1200
|
+
atRules.push(`@supports ${conditionParts.join(' and ')}`);
|
|
1201
|
+
}
|
|
1202
|
+
// Add starting-style
|
|
1203
|
+
if (variant.startingStyle) {
|
|
1204
|
+
atRules.push('@starting-style');
|
|
1205
|
+
}
|
|
1206
|
+
return atRules;
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Get a string key for a variant's at-rules (for grouping)
|
|
1210
|
+
*/
|
|
1211
|
+
function getAtRulesKey(variant) {
|
|
1212
|
+
const atRules = buildAtRulesFromVariant(variant);
|
|
1213
|
+
return atRules.sort().join('|||');
|
|
1214
|
+
}
|
|
1215
|
+
/**
|
|
1216
|
+
* Materialize a computed rule into final CSS format
|
|
1217
|
+
*
|
|
1218
|
+
* Returns an array of CSSRules because OR conditions may require multiple rules
|
|
1219
|
+
* (when different branches have different at-rules)
|
|
1220
|
+
*/
|
|
1221
|
+
function materializeRule(condition, declarations, selectorSuffix, className) {
|
|
1222
|
+
const components = conditionToCSS(condition);
|
|
1223
|
+
if (components.isImpossible || components.variants.length === 0) {
|
|
1224
|
+
return [];
|
|
1225
|
+
}
|
|
1226
|
+
const declarationsStr = Object.entries(declarations)
|
|
1227
|
+
.map(([prop, value]) => `${prop}: ${value};`)
|
|
1228
|
+
.join(' ');
|
|
1229
|
+
// Group variants by their at-rules (variants with same at-rules can be combined with commas)
|
|
1230
|
+
const byAtRules = new Map();
|
|
1231
|
+
for (const variant of components.variants) {
|
|
1232
|
+
const key = getAtRulesKey(variant);
|
|
1233
|
+
const group = byAtRules.get(key) || [];
|
|
1234
|
+
group.push(variant);
|
|
1235
|
+
byAtRules.set(key, group);
|
|
1236
|
+
}
|
|
1237
|
+
// Generate one CSSRule per at-rules group
|
|
1238
|
+
const rules = [];
|
|
1239
|
+
for (const [, variants] of byAtRules) {
|
|
1240
|
+
// All variants in this group have the same at-rules, so combine selectors with commas
|
|
1241
|
+
const selectors = variants.map((v) => buildCSSSelectorFromVariant(className, v, selectorSuffix));
|
|
1242
|
+
const selector = selectors.join(', ');
|
|
1243
|
+
const atRules = buildAtRulesFromVariant(variants[0]);
|
|
1244
|
+
const rule = {
|
|
1245
|
+
selector,
|
|
1246
|
+
declarations: declarationsStr,
|
|
1247
|
+
};
|
|
1248
|
+
if (atRules.length > 0) {
|
|
1249
|
+
rule.atRules = atRules;
|
|
1250
|
+
}
|
|
1251
|
+
const rootPrefix = rootConditionsToCSS(variants[0].rootConditions);
|
|
1252
|
+
if (rootPrefix) {
|
|
1253
|
+
rule.rootPrefix = rootPrefix;
|
|
1254
|
+
}
|
|
1255
|
+
rules.push(rule);
|
|
1256
|
+
}
|
|
1257
|
+
return rules;
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
|