import clamp from 'lodash/clamp' import { computed, toValue } from 'vue' import type { ComputedRef, CSSProperties, MaybeRefOrGetter } from 'vue' import { DeckTexture } from '@/enums' /** * Value selecting a texture: either a {@link DeckTexture} name or the numeric * index of a texture in the {@link DeckTexture} enumeration order. */ export type TexturedDeckValue = DeckTexture | number /** * Reactive inputs driving the textured background. They mirror the * `modelValue`, `size`, `black`, and `backgroundBaseUrl` props of the * `TexturedDeck` component. */ export interface UseTexturedDeckOptions { /** * Texture name or numeric index selecting which texture to display. */ modelValue: MaybeRefOrGetter /** * CSS `background-size` value (cover, contain, auto, 50%, 50% auto, ...). */ size: MaybeRefOrGetter /** * Whether to use the black variant of the texture file. */ black: MaybeRefOrGetter /** * Host where the textures are served from (without trailing slash). */ backgroundBaseUrl: MaybeRefOrGetter } /** * Reactive API returned by {@link useTexturedDeck}. */ export interface UseTexturedDeck { /** * Name of the resolved texture (one of the {@link DeckTexture} values). */ textureName: ComputedRef /** * Texture file name derived from the texture name and the black variant. */ filename: ComputedRef /** * Absolute URL of the texture image, combining the base URL and file name. */ backgroundUrl: ComputedRef /** * Inline style applying the resolved texture as the background image and * propagating the requested background size. */ style: ComputedRef } /** * Derives the background image of the `TexturedDeck` component from a texture * selection: resolves the texture name (accepting either a name or a numeric * index clamped to the available textures), builds the texture file name and * its absolute URL, and exposes the inline style to apply on the host element. * * @param options - Reactive texture options (see {@link UseTexturedDeckOptions}). * @returns The {@link UseTexturedDeck} API: the resolved `textureName`, the * `filename`, the absolute `backgroundUrl`, and the `style` computed for the * template. * @example * // Internal building block of the `TexturedDeck` component; not exported from * // the package root. Inside a `