@use 'sass:selector';

////
/// @package theming
/// @group utilities
////

/// Returns true if the scope where it's called is the root of the document.
/// @access public
/// @example scss - Check if the current scope is root
///   @mixin smart-mixin() {
///     $scope: if(is-root(), ':root', '&');
///
///     #{$scope} {
///       /* style rules here */
///     }
///   }
/// @return {Boolean} Returns a boolean depending on the scope where it's called
@function is-root() {
    @each $selector in & {
        @return $selector == null;
    }
}

/// Returns true if the scope where it's called is :host.
/// @access public
/// @example scss - Check if the current scope is :root
///   @mixin smart-mixin() {
///     $host: is-host();
///
///     @if is-host() {
///       /* style rules here */
///     }
///   }
/// @return {Boolean} Returns a boolean depending on the scope where it's called
@function is-host() {
    @return not(is-root()) and selector.is-superselector(':host', &);
}
