import { ID, MaybeArray } from "../../types/index.mjs"; import { ContextTrinity } from "../createTrinity/index.mjs"; import { RegistryOptions } from "../createRegistry/index.mjs"; import { GroupContext, GroupTicket, GroupTicketInput } from "../createGroup/index.mjs"; import { Plugin } from "../createPlugin/index.mjs"; import { TokenCollection } from "../createTokens/index.mjs"; import { FeaturesAdapter, FeaturesAdapterFlags, FeaturesAdapterValue } from "./adapters/adapter.mjs"; import "./adapters/index.mjs"; import "../index.mjs"; //#region src/composables/useFeatures/index.d.ts /** * Input type for feature tickets - what users provide to register(). */ interface FeatureTicketInput extends GroupTicketInput {} /** * Output type for feature tickets - what users receive from get(). */ type FeatureTicket = GroupTicket; interface FeatureContext = FeatureTicket> extends Omit, 'register'> { /** * Get the variation value of a feature, or a fallback if not set. * * @param id The feature ID. * @param fallback The fallback value if the feature has no variation. * * @example * ```ts * const features = useFeatures() * features.variation('search', 'v1') // 'v2' or the fallback * ``` */ variation: (id: ID, fallback?: unknown) => unknown; /** * Sync feature flags from an external source. * * @param flags The flags to sync, typically from an adapter. * * @remarks This updates existing flags and registers new ones. * Use this when adapter flags change to update the registry. * * @example * ```ts * features.sync({ * checkout: true, * search: { $value: true, $variation: 'v2' }, * }) * ``` */ sync: (flags: FeaturesAdapterFlags) => void; /** * Register a feature (accepts input type, returns output type). * * @example * ```ts * features.register({ id: 'beta', value: false }) * ``` */ register: (registration?: Partial) => E; /** * Bulk-register multiple features in a single batch. * * @example * ```ts * features.onboard([ * { id: 'beta', value: false }, * { id: 'search', value: { $value: true, $variation: 'v2' } }, * ]) * ``` */ onboard: (registrations: Partial[]) => E[]; /** * Restore every registered flag to its registration default and clear all * recorded user intent (with `persist`, the stored overrides are cleared). * * @remarks Flags disabled after boot stay unselected until re-enabled — * selection ops are guarded on disabled tickets. * * @example * ```ts * const features = useFeatures() * features.toggle('beta') * features.reset() // 'beta' back to its registered default * ``` */ reset: () => void; /** External feature-flag adapter(s), when the plugin was installed with one. */ adapter?: MaybeArray; } interface FeatureOptions extends RegistryOptions { /** * Static feature flags to register. */ features?: Record; } interface FeatureContextOptions extends FeatureOptions { namespace?: string; } interface FeaturePluginOptions extends FeatureContextOptions { /** * Feature flag adapter for external services. * * @remarks Adapters provide dynamic flag values from external services. */ adapter?: MaybeArray; /** * Persist the user's feature-flag overrides to storage and restore them on load. * * @remarks Persists a delta of user-toggled flags relative to each flag's * registration default, shaped `{ enabled: ID[], disabled: ID[] }` — flags * the user never touched are not stored and keep following code defaults. * Toggling a flag back to its registration default drops it from the delta. * The storage key is the plugin namespace with the `v0:` prefix stripped * (`features`). * * On load the delta is applied only to its listed ids; flags that register * later (adapter or runtime registrations) receive their saved override at * registration time. Entries whose flag is not registered are skipped and * pruned from the next persist write. Restored overrides win over an * adapter's first snapshot; later adapter updates still overlay live remote * state. * * User intent is recorded through the context's `select` / `unselect` / * `toggle` methods; ticket self-methods (`ticket.toggle()`) and the bulk * `selectAll` / `unselectAll` / `toggleAll` operations bypass intent * tracking — their changes are not persisted and revert to defaults on * reload. Toggles on disabled flags no-op and record nothing. `reset()` * restores registration defaults in-session and clears the stored delta. * * @default false */ persist?: boolean; } /** * Creates a new features instance. * * @param options The options for the features instance. * @returns A new features instance. * * @see https://0.vuetifyjs.com/composables/plugins/use-features * * @example * ```ts * import { createFeatures } from '@vuetify/v0' * * const features = createFeatures({ * features: { * 'dark-mode': true, * 'theme-color': { $variation: 'blue' }, * }, * }) * ``` */ declare function createFeatures(_options?: FeatureOptions & { adapter?: MaybeArray; }): FeatureContext; declare const createFeaturesContext: <_E extends FeatureContext> = FeatureContext>>(_options?: FeaturePluginOptions | undefined) => ContextTrinity<_E>, createFeaturesPlugin: (_options?: (FeaturePluginOptions & Pick<{ namespace?: string; persist?: boolean; devtools?: boolean; }, "devtools">) | undefined) => Plugin, useFeatures: <_E extends FeatureContext> = FeatureContext>>(namespace?: string) => _E; //#endregion export { FeatureContext, FeatureContextOptions, FeatureOptions, FeaturePluginOptions, FeatureTicket, FeatureTicketInput, FeaturesAdapter, type FeaturesAdapterFlags, type FeaturesAdapterValue, createFeatures, createFeaturesContext, createFeaturesPlugin, useFeatures };