@socketsecurity/lib 3.0.3 → 3.0.4
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 +8 -1
- package/dist/dlx.js +1 -1
- package/dist/dlx.js.map +2 -2
- package/dist/external/@socketregistry/packageurl-js.js +12 -2
- package/dist/objects.js.map +2 -2
- package/dist/spinner.js +5 -1
- package/dist/spinner.js.map +2 -2
- package/dist/themes/context.js.map +2 -2
- package/dist/themes/index.d.ts +2 -2
- package/dist/themes/index.js +2 -2
- package/dist/themes/index.js.map +1 -1
- package/dist/themes/themes.d.ts +5 -5
- package/dist/themes/themes.js +22 -13
- package/dist/themes/themes.js.map +2 -2
- package/package.json +2 -2
package/dist/objects.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/objects.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview Object manipulation and reflection utilities.\n * Provides type-safe object operations, property access, and structural helpers.\n */\n\nimport {\n kInternalsSymbol,\n LOOP_SENTINEL,\n UNDEFINED_TOKEN,\n} from '#constants/core'\n\nimport { isArray } from './arrays'\nimport { localeCompare } from './sorts'\n\n// Type definitions\n\n/**\n * Record of property keys mapped to getter functions.\n * Used for defining lazy getters on objects.\n */\ntype GetterDefObj = { [key: PropertyKey]: () => unknown }\n\n/**\n * Statistics tracking for lazy getter initialization.\n * Keeps track of which lazy getters have been accessed and initialized.\n */\ntype LazyGetterStats = { initialized?: Set<PropertyKey> | undefined }\n\n/**\n * Configuration options for creating constants objects.\n */\ntype ConstantsObjectOptions = {\n /**\n * Lazy getter definitions to attach to the object.\n * @default undefined\n */\n getters?: GetterDefObj | undefined\n /**\n * Internal properties to store under `kInternalsSymbol`.\n * @default undefined\n */\n internals?: object | undefined\n /**\n * Properties to mix into the object (lower priority than `props`).\n * @default undefined\n */\n mixin?: object | undefined\n}\n\n/**\n * Type helper that creates a remapped type with fresh property mapping.\n * Useful for flattening intersection types into a single object type.\n */\ntype Remap<T> = { [K in keyof T]: T[K] } extends infer O\n ? { [K in keyof O]: O[K] }\n : never\n\n/**\n * Type for dynamic lazy getter record.\n */\ntype LazyGetterRecord<T> = {\n [key: PropertyKey]: () => T\n}\n\n/**\n * Type for generic property bag.\n */\ntype PropertyBag = {\n [key: PropertyKey]: unknown\n}\n\n/**\n * Type for generic sorted object entries.\n */\ntype SortedObject<T> = {\n [key: PropertyKey]: T\n}\n\nexport type { GetterDefObj, LazyGetterStats, ConstantsObjectOptions, Remap }\n\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\nconst ObjectDefineProperties = Object.defineProperties\nconst ObjectDefineProperty = Object.defineProperty\nconst ObjectFreeze = Object.freeze\nconst ObjectFromEntries = Object.fromEntries\nconst ObjectGetOwnPropertyDescriptors = Object.getOwnPropertyDescriptors\nconst ObjectGetOwnPropertyNames = Object.getOwnPropertyNames\nconst ObjectGetPrototypeOf = Object.getPrototypeOf\nconst ObjectHasOwn = Object.hasOwn\nconst ObjectKeys = Object.keys\nconst ObjectPrototype = Object.prototype\nconst ObjectSetPrototypeOf = Object.setPrototypeOf\n// @ts-expect-error - __defineGetter__ exists but not in type definitions.\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\nconst __defineGetter__ = Object.prototype.__defineGetter__\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\nconst ReflectOwnKeys = Reflect.ownKeys\n\n/**\n * Create a lazy getter function that memoizes its result.\n *\n * The returned function will only call the getter once, caching the result\n * for subsequent calls. This is useful for expensive computations or\n * operations that should only happen when needed.\n *\n * @param name - The property key name for the getter (used for debugging and stats)\n * @param getter - Function that computes the value on first access\n * @param stats - Optional stats object to track initialization\n * @returns A memoized getter function\n *\n * @example\n * ```ts\n * const stats = { initialized: new Set() }\n * const getLargeData = createLazyGetter('data', () => {\n * console.log('Computing expensive data...')\n * return { large: 'dataset' }\n * }, stats)\n *\n * getLargeData() // Logs \"Computing expensive data...\" and returns data\n * getLargeData() // Returns cached data without logging\n * console.log(stats.initialized.has('data')) // true\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function createLazyGetter<T>(\n name: PropertyKey,\n getter: () => T,\n stats?: LazyGetterStats | undefined,\n): () => T {\n let lazyValue: T | typeof UNDEFINED_TOKEN = UNDEFINED_TOKEN\n // Dynamically name the getter without using Object.defineProperty.\n const { [name]: lazyGetter } = {\n [name]() {\n if (lazyValue === UNDEFINED_TOKEN) {\n stats?.initialized?.add(name)\n lazyValue = getter()\n }\n return lazyValue as T\n },\n } as LazyGetterRecord<T>\n return lazyGetter as unknown as () => T\n}\n\n/**\n * Create a frozen constants object with lazy getters and internal properties.\n *\n * This function creates an immutable object with:\n * - Regular properties from `props`\n * - Lazy getters that compute values on first access\n * - Internal properties accessible via `kInternalsSymbol`\n * - Mixin properties (lower priority, won't override existing)\n * - Alphabetically sorted keys for consistency\n *\n * The resulting object is deeply frozen and cannot be modified.\n *\n * @param props - Regular properties to include on the object\n * @param options_ - Configuration options\n * @returns A frozen object with all specified properties\n *\n * @example\n * ```ts\n * const config = createConstantsObject(\n * { apiUrl: 'https://api.example.com' },\n * {\n * getters: {\n * client: () => new APIClient(),\n * timestamp: () => Date.now()\n * },\n * internals: {\n * version: '1.0.0'\n * }\n * }\n * )\n *\n * console.log(config.apiUrl) // 'https://api.example.com'\n * console.log(config.client) // APIClient instance (computed on first access)\n * console.log(config[kInternalsSymbol].version) // '1.0.0'\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function createConstantsObject(\n props: object,\n options_?: ConstantsObjectOptions | undefined,\n): Readonly<object> {\n const options = { __proto__: null, ...options_ } as ConstantsObjectOptions\n const attributes = ObjectFreeze({\n __proto__: null,\n getters: options.getters\n ? ObjectFreeze(\n ObjectSetPrototypeOf(toSortedObject(options.getters), null),\n )\n : undefined,\n internals: options.internals\n ? ObjectFreeze(\n ObjectSetPrototypeOf(toSortedObject(options.internals), null),\n )\n : undefined,\n mixin: options.mixin\n ? ObjectFreeze(\n ObjectDefineProperties(\n { __proto__: null },\n ObjectGetOwnPropertyDescriptors(options.mixin),\n ),\n )\n : undefined,\n props: props\n ? ObjectFreeze(ObjectSetPrototypeOf(toSortedObject(props), null))\n : undefined,\n })\n const lazyGetterStats = ObjectFreeze({\n __proto__: null,\n initialized: new Set<PropertyKey>(),\n })\n const object = defineLazyGetters(\n {\n __proto__: null,\n [kInternalsSymbol]: ObjectFreeze({\n __proto__: null,\n get attributes() {\n return attributes\n },\n get lazyGetterStats() {\n return lazyGetterStats\n },\n ...attributes.internals,\n }),\n kInternalsSymbol,\n ...attributes.props,\n },\n attributes.getters,\n lazyGetterStats,\n )\n if (attributes.mixin) {\n ObjectDefineProperties(\n object,\n toSortedObjectFromEntries(\n objectEntries(ObjectGetOwnPropertyDescriptors(attributes.mixin)).filter(\n p => !ObjectHasOwn(object, p[0]),\n ),\n ) as PropertyDescriptorMap,\n )\n }\n return ObjectFreeze(object)\n}\n\n/**\n * Define a getter property on an object.\n *\n * The getter is non-enumerable and configurable, meaning it won't show up\n * in `for...in` loops or `Object.keys()`, but can be redefined later.\n *\n * @param object - The object to define the getter on\n * @param propKey - The property key for the getter\n * @param getter - Function that computes the property value\n * @returns The modified object (for chaining)\n *\n * @example\n * ```ts\n * const obj = {}\n * defineGetter(obj, 'timestamp', () => Date.now())\n * console.log(obj.timestamp) // Current timestamp\n * console.log(obj.timestamp) // Different timestamp (computed each time)\n * console.log(Object.keys(obj)) // [] (non-enumerable)\n * ```\n */\nexport function defineGetter<T>(\n object: object,\n propKey: PropertyKey,\n getter: () => T,\n): object {\n ObjectDefineProperty(object, propKey, {\n get: getter,\n enumerable: false,\n configurable: true,\n })\n return object\n}\n\n/**\n * Define a lazy getter property on an object.\n *\n * Unlike `defineGetter()`, this version memoizes the result so the getter\n * function is only called once. Subsequent accesses return the cached value.\n *\n * @param object - The object to define the lazy getter on\n * @param propKey - The property key for the lazy getter\n * @param getter - Function that computes the value on first access\n * @param stats - Optional stats object to track initialization\n * @returns The modified object (for chaining)\n *\n * @example\n * ```ts\n * const obj = {}\n * defineLazyGetter(obj, 'data', () => {\n * console.log('Loading data...')\n * return { expensive: 'computation' }\n * })\n * console.log(obj.data) // Logs \"Loading data...\" and returns data\n * console.log(obj.data) // Returns same data without logging\n * ```\n */\nexport function defineLazyGetter<T>(\n object: object,\n propKey: PropertyKey,\n getter: () => T,\n stats?: LazyGetterStats | undefined,\n): object {\n return defineGetter(object, propKey, createLazyGetter(propKey, getter, stats))\n}\n\n/**\n * Define multiple lazy getter properties on an object.\n *\n * Each getter in the provided object will be converted to a lazy getter\n * and attached to the target object. All getters share the same stats object\n * for tracking initialization.\n *\n * @param object - The object to define lazy getters on\n * @param getterDefObj - Object mapping property keys to getter functions\n * @param stats - Optional stats object to track initialization\n * @returns The modified object (for chaining)\n *\n * @example\n * ```ts\n * const obj = {}\n * const stats = { initialized: new Set() }\n * defineLazyGetters(obj, {\n * user: () => fetchUser(),\n * config: () => loadConfig(),\n * timestamp: () => Date.now()\n * }, stats)\n *\n * console.log(obj.user) // Fetches user on first access\n * console.log(obj.config) // Loads config on first access\n * console.log(stats.initialized) // Set(['user', 'config'])\n * ```\n */\nexport function defineLazyGetters(\n object: object,\n getterDefObj: GetterDefObj | undefined,\n stats?: LazyGetterStats | undefined,\n): object {\n if (getterDefObj !== null && typeof getterDefObj === 'object') {\n const keys = ReflectOwnKeys(getterDefObj)\n for (let i = 0, { length } = keys; i < length; i += 1) {\n const key = keys[i] as PropertyKey\n defineLazyGetter(object, key, getterDefObj[key] as () => unknown, stats)\n }\n }\n return object\n}\n\n/**\n * Compare two entry arrays by their keys for sorting.\n *\n * Used internally for alphabetically sorting object entries.\n * String keys are compared directly, non-string keys are converted to strings first.\n *\n * @param a - First entry tuple [key, value]\n * @param b - Second entry tuple [key, value]\n * @returns Negative if a < b, positive if a > b, zero if equal\n *\n * @example\n * ```ts\n * const entries = [['zebra', 1], ['apple', 2], ['banana', 3]]\n * entries.sort(entryKeyComparator)\n * // [['apple', 2], ['banana', 3], ['zebra', 1]]\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function entryKeyComparator(\n a: [PropertyKey, unknown],\n b: [PropertyKey, unknown],\n): number {\n const keyA = a[0]\n const keyB = b[0]\n const strKeyA = typeof keyA === 'string' ? keyA : String(keyA)\n const strKeyB = typeof keyB === 'string' ? keyB : String(keyB)\n return localeCompare(strKeyA, strKeyB)\n}\n\n/**\n * Get the enumerable own property keys of an object.\n *\n * This is a safe wrapper around `Object.keys()` that returns an empty array\n * for non-object values instead of throwing an error.\n *\n * @param obj - The value to get keys from\n * @returns Array of enumerable string keys, or empty array for non-objects\n *\n * @example\n * ```ts\n * getKeys({ a: 1, b: 2 }) // ['a', 'b']\n * getKeys([10, 20, 30]) // ['0', '1', '2']\n * getKeys(null) // []\n * getKeys(undefined) // []\n * getKeys('hello') // []\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function getKeys(obj: unknown): string[] {\n return isObject(obj) ? ObjectKeys(obj) : []\n}\n\n/**\n * Get an own property value from an object safely.\n *\n * Returns `undefined` if the value is null/undefined or if the property\n * doesn't exist as an own property (not inherited). This avoids prototype\n * chain lookups and prevents errors on null/undefined values.\n *\n * @param obj - The object to get the property from\n * @param propKey - The property key to look up\n * @returns The property value, or `undefined` if not found or obj is null/undefined\n *\n * @example\n * ```ts\n * const obj = { name: 'Alice', age: 30 }\n * getOwn(obj, 'name') // 'Alice'\n * getOwn(obj, 'missing') // undefined\n * getOwn(obj, 'toString') // undefined (inherited, not own property)\n * getOwn(null, 'name') // undefined\n * getOwn(undefined, 'name') // undefined\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function getOwn(obj: unknown, propKey: PropertyKey): unknown {\n if (obj === null || obj === undefined) {\n return undefined\n }\n return ObjectHasOwn(obj as object, propKey)\n ? (obj as Record<PropertyKey, unknown>)[propKey]\n : undefined\n}\n\n/**\n * Get all own property values from an object.\n *\n * Returns values for all own properties (enumerable and non-enumerable),\n * but not inherited properties. Returns an empty array for null/undefined.\n *\n * @param obj - The object to get values from\n * @returns Array of all own property values, or empty array for null/undefined\n *\n * @example\n * ```ts\n * getOwnPropertyValues({ a: 1, b: 2, c: 3 }) // [1, 2, 3]\n * getOwnPropertyValues([10, 20, 30]) // [10, 20, 30]\n * getOwnPropertyValues(null) // []\n * getOwnPropertyValues(undefined) // []\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function getOwnPropertyValues<T>(\n obj: { [key: PropertyKey]: T } | null | undefined,\n): T[] {\n if (obj === null || obj === undefined) {\n return []\n }\n const keys = ObjectGetOwnPropertyNames(obj)\n const { length } = keys\n const values = Array(length)\n for (let i = 0; i < length; i += 1) {\n values[i] = obj[keys[i] as string]\n }\n return values\n}\n\n/**\n * Check if an object has any enumerable own properties.\n *\n * Returns `true` if the object has at least one enumerable own property,\n * `false` otherwise. Also returns `false` for null/undefined.\n *\n * @param obj - The value to check\n * @returns `true` if obj has enumerable own properties, `false` otherwise\n *\n * @example\n * ```ts\n * hasKeys({ a: 1 }) // true\n * hasKeys({}) // false\n * hasKeys([]) // false\n * hasKeys([1, 2]) // true\n * hasKeys(null) // false\n * hasKeys(undefined) // false\n * hasKeys(Object.create({ inherited: true })) // false (inherited, not own)\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function hasKeys(obj: unknown): obj is PropertyBag {\n if (obj === null || obj === undefined) {\n return false\n }\n for (const key in obj as object) {\n if (ObjectHasOwn(obj as object, key)) {\n return true\n }\n }\n return false\n}\n\n/**\n * Check if an object has an own property.\n *\n * Type-safe wrapper around `Object.hasOwn()` that returns `false` for\n * null/undefined instead of throwing. Only checks own properties, not\n * inherited ones from the prototype chain.\n *\n * @param obj - The value to check\n * @param propKey - The property key to look for\n * @returns `true` if obj has the property as an own property, `false` otherwise\n *\n * @example\n * ```ts\n * const obj = { name: 'Alice' }\n * hasOwn(obj, 'name') // true\n * hasOwn(obj, 'age') // false\n * hasOwn(obj, 'toString') // false (inherited from Object.prototype)\n * hasOwn(null, 'name') // false\n * hasOwn(undefined, 'name') // false\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function hasOwn(\n obj: unknown,\n propKey: PropertyKey,\n): obj is object & PropertyBag {\n if (obj === null || obj === undefined) {\n return false\n }\n return ObjectHasOwn(obj as object, propKey)\n}\n\n/**\n * Check if a value is an object (including arrays).\n *\n * Returns `true` for any object type including arrays, functions, dates, etc.\n * Returns `false` for primitives and `null`.\n *\n * @param value - The value to check\n * @returns `true` if value is an object (including arrays), `false` otherwise\n *\n * @example\n * ```ts\n * isObject({}) // true\n * isObject([]) // true\n * isObject(new Date()) // true\n * isObject(() => {}) // false (functions are not objects for typeof)\n * isObject(null) // false\n * isObject(undefined) // false\n * isObject(42) // false\n * isObject('string') // false\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isObject(\n value: unknown,\n): value is { [key: PropertyKey]: unknown } {\n return value !== null && typeof value === 'object'\n}\n\n/**\n * Check if a value is a plain object (not an array, not a built-in).\n *\n * Returns `true` only for plain objects created with `{}` or `Object.create(null)`.\n * Returns `false` for arrays, built-in objects (Date, RegExp, etc.), and primitives.\n *\n * @param value - The value to check\n * @returns `true` if value is a plain object, `false` otherwise\n *\n * @example\n * ```ts\n * isObjectObject({}) // true\n * isObjectObject({ a: 1 }) // true\n * isObjectObject(Object.create(null)) // true\n * isObjectObject([]) // false\n * isObjectObject(new Date()) // false\n * isObjectObject(null) // false\n * isObjectObject(42) // false\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isObjectObject(\n value: unknown,\n): value is { [key: PropertyKey]: unknown } {\n if (value === null || typeof value !== 'object' || isArray(value)) {\n return false\n }\n const proto = ObjectGetPrototypeOf(value)\n return proto === null || proto === ObjectPrototype\n}\n\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\n\n/**\n * Alias for native `Object.assign`.\n *\n * Copies all enumerable own properties from one or more source objects\n * to a target object and returns the modified target object.\n *\n * @example\n * ```ts\n * const target = { a: 1 }\n * const source = { b: 2, c: 3 }\n * objectAssign(target, source) // { a: 1, b: 2, c: 3 }\n * ```\n */\nexport const objectAssign = Object.assign\n\n/**\n * Get all own property entries (key-value pairs) from an object.\n *\n * Unlike `Object.entries()`, this includes non-enumerable properties and\n * symbol keys. Returns an empty array for null/undefined.\n *\n * @param obj - The object to get entries from\n * @returns Array of [key, value] tuples, or empty array for null/undefined\n *\n * @example\n * ```ts\n * objectEntries({ a: 1, b: 2 }) // [['a', 1], ['b', 2]]\n * const sym = Symbol('key')\n * objectEntries({ [sym]: 'value', x: 10 }) // [[Symbol(key), 'value'], ['x', 10]]\n * objectEntries(null) // []\n * objectEntries(undefined) // []\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function objectEntries(obj: unknown): Array<[PropertyKey, unknown]> {\n if (obj === null || obj === undefined) {\n return []\n }\n const keys = ReflectOwnKeys(obj as object)\n const { length } = keys\n const entries = Array(length)\n const record = obj as Record<PropertyKey, unknown>\n for (let i = 0; i < length; i += 1) {\n const key = keys[i] as PropertyKey\n entries[i] = [key, record[key]]\n }\n return entries\n}\n\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\n\n/**\n * Alias for native `Object.freeze`.\n *\n * Freezes an object, preventing new properties from being added and existing\n * properties from being removed or modified. Makes the object immutable.\n *\n * @example\n * ```ts\n * const obj = { a: 1 }\n * objectFreeze(obj)\n * obj.a = 2 // Silently fails in non-strict mode, throws in strict mode\n * obj.b = 3 // Silently fails in non-strict mode, throws in strict mode\n * ```\n */\nexport const objectFreeze = Object.freeze\n\n/**\n * Deep merge source object into target object.\n *\n * Recursively merges properties from `source` into `target`. Arrays in source\n * completely replace arrays in target (no element-wise merging). Objects are\n * merged recursively. Includes infinite loop detection for safety.\n *\n * @param target - The object to merge into (will be modified)\n * @param source - The object to merge from\n * @returns The modified target object\n *\n * @example\n * ```ts\n * const target = { a: { x: 1 }, b: [1, 2] }\n * const source = { a: { y: 2 }, b: [3, 4, 5], c: 3 }\n * merge(target, source)\n * // { a: { x: 1, y: 2 }, b: [3, 4, 5], c: 3 }\n * ```\n *\n * @example\n * ```ts\n * // Arrays are replaced, not merged\n * merge({ arr: [1, 2] }, { arr: [3] }) // { arr: [3] }\n *\n * // Deep object merging\n * merge(\n * { config: { api: 'v1', timeout: 1000 } },\n * { config: { api: 'v2', retries: 3 } }\n * )\n * // { config: { api: 'v2', timeout: 1000, retries: 3 } }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function merge<T extends object, U extends object>(\n target: T,\n source: U,\n): T & U {\n if (!isObject(target) || !isObject(source)) {\n return target as T & U\n }\n const queue: Array<[unknown, unknown]> = [[target, source]]\n let pos = 0\n let { length: queueLength } = queue\n while (pos < queueLength) {\n if (pos === LOOP_SENTINEL) {\n throw new Error('Detected infinite loop in object crawl of merge')\n }\n const { 0: currentTarget, 1: currentSource } = queue[pos++] as [\n Record<PropertyKey, unknown>,\n Record<PropertyKey, unknown>,\n ]\n\n if (!currentSource || !currentTarget) {\n continue\n }\n\n const isSourceArray = isArray(currentSource)\n const isTargetArray = isArray(currentTarget)\n\n // Skip array merging - arrays in source replace arrays in target\n if (isSourceArray || isTargetArray) {\n continue\n }\n\n const keys = ReflectOwnKeys(currentSource as object)\n for (let i = 0, { length } = keys; i < length; i += 1) {\n const key = keys[i] as PropertyKey\n const srcVal = currentSource[key]\n const targetVal = currentTarget[key]\n if (isArray(srcVal)) {\n // Replace arrays entirely\n currentTarget[key] = srcVal\n } else if (isObject(srcVal)) {\n if (isObject(targetVal) && !isArray(targetVal)) {\n queue[queueLength++] = [targetVal, srcVal]\n } else {\n currentTarget[key] = srcVal\n }\n } else {\n currentTarget[key] = srcVal\n }\n }\n }\n return target as T & U\n}\n\n/**\n * Convert an object to a new object with sorted keys.\n *\n * Creates a new object with the same properties as the input, but with keys\n * sorted alphabetically. Symbol keys are sorted separately and placed first.\n * This is useful for consistent key ordering in serialization or comparisons.\n *\n * @param obj - The object to sort\n * @returns A new object with sorted keys\n *\n * @example\n * ```ts\n * toSortedObject({ z: 1, a: 2, m: 3 })\n * // { a: 2, m: 3, z: 1 }\n *\n * const sym1 = Symbol('first')\n * const sym2 = Symbol('second')\n * toSortedObject({ z: 1, [sym2]: 2, a: 3, [sym1]: 4 })\n * // { [Symbol(first)]: 4, [Symbol(second)]: 2, a: 3, z: 1 }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function toSortedObject<T extends object>(obj: T): T {\n return toSortedObjectFromEntries(objectEntries(obj)) as T\n}\n\n/**\n * Create an object from entries with sorted keys.\n *\n * Takes an iterable of [key, value] entries and creates a new object with\n * keys sorted alphabetically. Symbol keys are sorted separately and placed\n * first in the resulting object.\n *\n * @param entries - Iterable of [key, value] tuples\n * @returns A new object with sorted keys\n *\n * @example\n * ```ts\n * toSortedObjectFromEntries([['z', 1], ['a', 2], ['m', 3]])\n * // { a: 2, m: 3, z: 1 }\n *\n * const entries = new Map([['beta', 2], ['alpha', 1], ['gamma', 3]])\n * toSortedObjectFromEntries(entries)\n * // { alpha: 1, beta: 2, gamma: 3 }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function toSortedObjectFromEntries<T = unknown>(\n entries: Iterable<[PropertyKey, T]>,\n): SortedObject<T> {\n const otherEntries = []\n const symbolEntries = []\n // Use for-of to work with entries iterators.\n for (const entry of entries) {\n if (typeof entry[0] === 'symbol') {\n symbolEntries.push(entry)\n } else {\n otherEntries.push(entry)\n }\n }\n if (!otherEntries.length && !symbolEntries.length) {\n return {}\n }\n return ObjectFromEntries([\n // The String constructor is safe to use with symbols.\n ...symbolEntries.sort(entryKeyComparator),\n ...otherEntries.sort(entryKeyComparator),\n ])\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,kBAIO;AAEP,oBAAwB;AACxB,mBAA8B;AAwE9B,MAAM,yBAAyB,OAAO;AACtC,MAAM,uBAAuB,OAAO;AACpC,MAAM,eAAe,OAAO;AAC5B,MAAM,oBAAoB,OAAO;AACjC,MAAM,kCAAkC,OAAO;AAC/C,MAAM,4BAA4B,OAAO;AACzC,MAAM,uBAAuB,OAAO;AACpC,MAAM,eAAe,OAAO;AAC5B,MAAM,aAAa,OAAO;AAC1B,MAAM,kBAAkB,OAAO;AAC/B,MAAM,uBAAuB,OAAO;AAWpC,MAAM,iBAAiB,QAAQ;AAAA;AA4BxB,SAAS,iBACd,MACA,QACA,OACS;AACT,MAAI,YAAwC;AAE5C,QAAM,EAAE,CAAC,IAAI,GAAG,WAAW,IAAI;AAAA,IAC7B,CAAC,IAAI,IAAI;AACP,UAAI,cAAc,6BAAiB;AACjC,eAAO,aAAa,IAAI,IAAI;AAC5B,oBAAY,OAAO;AAAA,MACrB;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAAA;AAuCO,SAAS,sBACd,OACA,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KAAK,GAAG;AAClC,WAAO,CAAC,IAAI,IAAI,KAAK,CAAC,CAAW;AAAA,EACnC;AACA,SAAO;AACT;AAAA;AAuBO,SAAS,QAAQ,KAAkC;AACxD,MAAI,QAAQ,QAAQ,QAAQ,QAAW;AACrC,WAAO;AAAA,EACT;AACA,aAAW,OAAO,KAAe;AAC/B,QAAI,aAAa,KAAe,GAAG,GAAG;AACpC,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAAA;AAwBO,SAAS,OACd,KACA,SAC6B;AAC7B,MAAI,QAAQ,QAAQ,QAAQ,QAAW;AACrC,WAAO;AAAA,EACT;AACA,SAAO,aAAa,KAAe,OAAO;AAC5C;AAAA;AAwBO,SAAS,SACd,OAC0C;AAC1C,SAAO,UAAU,QAAQ,OAAO,UAAU;AAC5C;AAAA;AAuBO,SAAS,eACd,OAC0C;AAC1C,MAAI,UAAU,QAAQ,OAAO,UAAU,gBAAY,uBAAQ,KAAK,GAAG;AACjE,WAAO;AAAA,EACT;AACA,QAAM,
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview Object manipulation and reflection utilities.\n * Provides type-safe object operations, property access, and structural helpers.\n */\n\nimport {\n kInternalsSymbol,\n LOOP_SENTINEL,\n UNDEFINED_TOKEN,\n} from '#constants/core'\n\nimport { isArray } from './arrays'\nimport { localeCompare } from './sorts'\n\n// Type definitions\n\n/**\n * Record of property keys mapped to getter functions.\n * Used for defining lazy getters on objects.\n */\ntype GetterDefObj = { [key: PropertyKey]: () => unknown }\n\n/**\n * Statistics tracking for lazy getter initialization.\n * Keeps track of which lazy getters have been accessed and initialized.\n */\ntype LazyGetterStats = { initialized?: Set<PropertyKey> | undefined }\n\n/**\n * Configuration options for creating constants objects.\n */\ntype ConstantsObjectOptions = {\n /**\n * Lazy getter definitions to attach to the object.\n * @default undefined\n */\n getters?: GetterDefObj | undefined\n /**\n * Internal properties to store under `kInternalsSymbol`.\n * @default undefined\n */\n internals?: object | undefined\n /**\n * Properties to mix into the object (lower priority than `props`).\n * @default undefined\n */\n mixin?: object | undefined\n}\n\n/**\n * Type helper that creates a remapped type with fresh property mapping.\n * Useful for flattening intersection types into a single object type.\n */\ntype Remap<T> = { [K in keyof T]: T[K] } extends infer O\n ? { [K in keyof O]: O[K] }\n : never\n\n/**\n * Type for dynamic lazy getter record.\n */\ntype LazyGetterRecord<T> = {\n [key: PropertyKey]: () => T\n}\n\n/**\n * Type for generic property bag.\n */\ntype PropertyBag = {\n [key: PropertyKey]: unknown\n}\n\n/**\n * Type for generic sorted object entries.\n */\ntype SortedObject<T> = {\n [key: PropertyKey]: T\n}\n\nexport type { GetterDefObj, LazyGetterStats, ConstantsObjectOptions, Remap }\n\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\nconst ObjectDefineProperties = Object.defineProperties\nconst ObjectDefineProperty = Object.defineProperty\nconst ObjectFreeze = Object.freeze\nconst ObjectFromEntries = Object.fromEntries\nconst ObjectGetOwnPropertyDescriptors = Object.getOwnPropertyDescriptors\nconst ObjectGetOwnPropertyNames = Object.getOwnPropertyNames\nconst ObjectGetPrototypeOf = Object.getPrototypeOf\nconst ObjectHasOwn = Object.hasOwn\nconst ObjectKeys = Object.keys\nconst ObjectPrototype = Object.prototype\nconst ObjectSetPrototypeOf = Object.setPrototypeOf\n// @ts-expect-error - __defineGetter__ exists but not in type definitions.\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\nconst __defineGetter__ = Object.prototype.__defineGetter__\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\nconst ReflectOwnKeys = Reflect.ownKeys\n\n/**\n * Create a lazy getter function that memoizes its result.\n *\n * The returned function will only call the getter once, caching the result\n * for subsequent calls. This is useful for expensive computations or\n * operations that should only happen when needed.\n *\n * @param name - The property key name for the getter (used for debugging and stats)\n * @param getter - Function that computes the value on first access\n * @param stats - Optional stats object to track initialization\n * @returns A memoized getter function\n *\n * @example\n * ```ts\n * const stats = { initialized: new Set() }\n * const getLargeData = createLazyGetter('data', () => {\n * console.log('Computing expensive data...')\n * return { large: 'dataset' }\n * }, stats)\n *\n * getLargeData() // Logs \"Computing expensive data...\" and returns data\n * getLargeData() // Returns cached data without logging\n * console.log(stats.initialized.has('data')) // true\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function createLazyGetter<T>(\n name: PropertyKey,\n getter: () => T,\n stats?: LazyGetterStats | undefined,\n): () => T {\n let lazyValue: T | typeof UNDEFINED_TOKEN = UNDEFINED_TOKEN\n // Dynamically name the getter without using Object.defineProperty.\n const { [name]: lazyGetter } = {\n [name]() {\n if (lazyValue === UNDEFINED_TOKEN) {\n stats?.initialized?.add(name)\n lazyValue = getter()\n }\n return lazyValue as T\n },\n } as LazyGetterRecord<T>\n return lazyGetter as unknown as () => T\n}\n\n/**\n * Create a frozen constants object with lazy getters and internal properties.\n *\n * This function creates an immutable object with:\n * - Regular properties from `props`\n * - Lazy getters that compute values on first access\n * - Internal properties accessible via `kInternalsSymbol`\n * - Mixin properties (lower priority, won't override existing)\n * - Alphabetically sorted keys for consistency\n *\n * The resulting object is deeply frozen and cannot be modified.\n *\n * @param props - Regular properties to include on the object\n * @param options_ - Configuration options\n * @returns A frozen object with all specified properties\n *\n * @example\n * ```ts\n * const config = createConstantsObject(\n * { apiUrl: 'https://api.example.com' },\n * {\n * getters: {\n * client: () => new APIClient(),\n * timestamp: () => Date.now()\n * },\n * internals: {\n * version: '1.0.0'\n * }\n * }\n * )\n *\n * console.log(config.apiUrl) // 'https://api.example.com'\n * console.log(config.client) // APIClient instance (computed on first access)\n * console.log(config[kInternalsSymbol].version) // '1.0.0'\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function createConstantsObject(\n props: object,\n options_?: ConstantsObjectOptions | undefined,\n): Readonly<object> {\n const options = { __proto__: null, ...options_ } as ConstantsObjectOptions\n const attributes = ObjectFreeze({\n __proto__: null,\n getters: options.getters\n ? ObjectFreeze(\n ObjectSetPrototypeOf(toSortedObject(options.getters), null),\n )\n : undefined,\n internals: options.internals\n ? ObjectFreeze(\n ObjectSetPrototypeOf(toSortedObject(options.internals), null),\n )\n : undefined,\n mixin: options.mixin\n ? ObjectFreeze(\n ObjectDefineProperties(\n { __proto__: null },\n ObjectGetOwnPropertyDescriptors(options.mixin),\n ),\n )\n : undefined,\n props: props\n ? ObjectFreeze(ObjectSetPrototypeOf(toSortedObject(props), null))\n : undefined,\n })\n const lazyGetterStats = ObjectFreeze({\n __proto__: null,\n initialized: new Set<PropertyKey>(),\n })\n const object = defineLazyGetters(\n {\n __proto__: null,\n [kInternalsSymbol]: ObjectFreeze({\n __proto__: null,\n get attributes() {\n return attributes\n },\n get lazyGetterStats() {\n return lazyGetterStats\n },\n ...attributes.internals,\n }),\n kInternalsSymbol,\n ...attributes.props,\n },\n attributes.getters,\n lazyGetterStats,\n )\n if (attributes.mixin) {\n ObjectDefineProperties(\n object,\n toSortedObjectFromEntries(\n objectEntries(ObjectGetOwnPropertyDescriptors(attributes.mixin)).filter(\n p => !ObjectHasOwn(object, p[0]),\n ),\n ) as PropertyDescriptorMap,\n )\n }\n return ObjectFreeze(object)\n}\n\n/**\n * Define a getter property on an object.\n *\n * The getter is non-enumerable and configurable, meaning it won't show up\n * in `for...in` loops or `Object.keys()`, but can be redefined later.\n *\n * @param object - The object to define the getter on\n * @param propKey - The property key for the getter\n * @param getter - Function that computes the property value\n * @returns The modified object (for chaining)\n *\n * @example\n * ```ts\n * const obj = {}\n * defineGetter(obj, 'timestamp', () => Date.now())\n * console.log(obj.timestamp) // Current timestamp\n * console.log(obj.timestamp) // Different timestamp (computed each time)\n * console.log(Object.keys(obj)) // [] (non-enumerable)\n * ```\n */\nexport function defineGetter<T>(\n object: object,\n propKey: PropertyKey,\n getter: () => T,\n): object {\n ObjectDefineProperty(object, propKey, {\n get: getter,\n enumerable: false,\n configurable: true,\n })\n return object\n}\n\n/**\n * Define a lazy getter property on an object.\n *\n * Unlike `defineGetter()`, this version memoizes the result so the getter\n * function is only called once. Subsequent accesses return the cached value.\n *\n * @param object - The object to define the lazy getter on\n * @param propKey - The property key for the lazy getter\n * @param getter - Function that computes the value on first access\n * @param stats - Optional stats object to track initialization\n * @returns The modified object (for chaining)\n *\n * @example\n * ```ts\n * const obj = {}\n * defineLazyGetter(obj, 'data', () => {\n * console.log('Loading data...')\n * return { expensive: 'computation' }\n * })\n * console.log(obj.data) // Logs \"Loading data...\" and returns data\n * console.log(obj.data) // Returns same data without logging\n * ```\n */\nexport function defineLazyGetter<T>(\n object: object,\n propKey: PropertyKey,\n getter: () => T,\n stats?: LazyGetterStats | undefined,\n): object {\n return defineGetter(object, propKey, createLazyGetter(propKey, getter, stats))\n}\n\n/**\n * Define multiple lazy getter properties on an object.\n *\n * Each getter in the provided object will be converted to a lazy getter\n * and attached to the target object. All getters share the same stats object\n * for tracking initialization.\n *\n * @param object - The object to define lazy getters on\n * @param getterDefObj - Object mapping property keys to getter functions\n * @param stats - Optional stats object to track initialization\n * @returns The modified object (for chaining)\n *\n * @example\n * ```ts\n * const obj = {}\n * const stats = { initialized: new Set() }\n * defineLazyGetters(obj, {\n * user: () => fetchUser(),\n * config: () => loadConfig(),\n * timestamp: () => Date.now()\n * }, stats)\n *\n * console.log(obj.user) // Fetches user on first access\n * console.log(obj.config) // Loads config on first access\n * console.log(stats.initialized) // Set(['user', 'config'])\n * ```\n */\nexport function defineLazyGetters(\n object: object,\n getterDefObj: GetterDefObj | undefined,\n stats?: LazyGetterStats | undefined,\n): object {\n if (getterDefObj !== null && typeof getterDefObj === 'object') {\n const keys = ReflectOwnKeys(getterDefObj)\n for (let i = 0, { length } = keys; i < length; i += 1) {\n const key = keys[i] as PropertyKey\n defineLazyGetter(object, key, getterDefObj[key] as () => unknown, stats)\n }\n }\n return object\n}\n\n/**\n * Compare two entry arrays by their keys for sorting.\n *\n * Used internally for alphabetically sorting object entries.\n * String keys are compared directly, non-string keys are converted to strings first.\n *\n * @param a - First entry tuple [key, value]\n * @param b - Second entry tuple [key, value]\n * @returns Negative if a < b, positive if a > b, zero if equal\n *\n * @example\n * ```ts\n * const entries = [['zebra', 1], ['apple', 2], ['banana', 3]]\n * entries.sort(entryKeyComparator)\n * // [['apple', 2], ['banana', 3], ['zebra', 1]]\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function entryKeyComparator(\n a: [PropertyKey, unknown],\n b: [PropertyKey, unknown],\n): number {\n const keyA = a[0]\n const keyB = b[0]\n const strKeyA = typeof keyA === 'string' ? keyA : String(keyA)\n const strKeyB = typeof keyB === 'string' ? keyB : String(keyB)\n return localeCompare(strKeyA, strKeyB)\n}\n\n/**\n * Get the enumerable own property keys of an object.\n *\n * This is a safe wrapper around `Object.keys()` that returns an empty array\n * for non-object values instead of throwing an error.\n *\n * @param obj - The value to get keys from\n * @returns Array of enumerable string keys, or empty array for non-objects\n *\n * @example\n * ```ts\n * getKeys({ a: 1, b: 2 }) // ['a', 'b']\n * getKeys([10, 20, 30]) // ['0', '1', '2']\n * getKeys(null) // []\n * getKeys(undefined) // []\n * getKeys('hello') // []\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function getKeys(obj: unknown): string[] {\n return isObject(obj) ? ObjectKeys(obj) : []\n}\n\n/**\n * Get an own property value from an object safely.\n *\n * Returns `undefined` if the value is null/undefined or if the property\n * doesn't exist as an own property (not inherited). This avoids prototype\n * chain lookups and prevents errors on null/undefined values.\n *\n * @param obj - The object to get the property from\n * @param propKey - The property key to look up\n * @returns The property value, or `undefined` if not found or obj is null/undefined\n *\n * @example\n * ```ts\n * const obj = { name: 'Alice', age: 30 }\n * getOwn(obj, 'name') // 'Alice'\n * getOwn(obj, 'missing') // undefined\n * getOwn(obj, 'toString') // undefined (inherited, not own property)\n * getOwn(null, 'name') // undefined\n * getOwn(undefined, 'name') // undefined\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function getOwn(obj: unknown, propKey: PropertyKey): unknown {\n if (obj === null || obj === undefined) {\n return undefined\n }\n return ObjectHasOwn(obj as object, propKey)\n ? (obj as Record<PropertyKey, unknown>)[propKey]\n : undefined\n}\n\n/**\n * Get all own property values from an object.\n *\n * Returns values for all own properties (enumerable and non-enumerable),\n * but not inherited properties. Returns an empty array for null/undefined.\n *\n * @param obj - The object to get values from\n * @returns Array of all own property values, or empty array for null/undefined\n *\n * @example\n * ```ts\n * getOwnPropertyValues({ a: 1, b: 2, c: 3 }) // [1, 2, 3]\n * getOwnPropertyValues([10, 20, 30]) // [10, 20, 30]\n * getOwnPropertyValues(null) // []\n * getOwnPropertyValues(undefined) // []\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function getOwnPropertyValues<T>(\n obj: { [key: PropertyKey]: T } | null | undefined,\n): T[] {\n if (obj === null || obj === undefined) {\n return []\n }\n const keys = ObjectGetOwnPropertyNames(obj)\n const { length } = keys\n const values = Array(length)\n for (let i = 0; i < length; i += 1) {\n values[i] = obj[keys[i] as string]\n }\n return values\n}\n\n/**\n * Check if an object has any enumerable own properties.\n *\n * Returns `true` if the object has at least one enumerable own property,\n * `false` otherwise. Also returns `false` for null/undefined.\n *\n * @param obj - The value to check\n * @returns `true` if obj has enumerable own properties, `false` otherwise\n *\n * @example\n * ```ts\n * hasKeys({ a: 1 }) // true\n * hasKeys({}) // false\n * hasKeys([]) // false\n * hasKeys([1, 2]) // true\n * hasKeys(null) // false\n * hasKeys(undefined) // false\n * hasKeys(Object.create({ inherited: true })) // false (inherited, not own)\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function hasKeys(obj: unknown): obj is PropertyBag {\n if (obj === null || obj === undefined) {\n return false\n }\n for (const key in obj as object) {\n if (ObjectHasOwn(obj as object, key)) {\n return true\n }\n }\n return false\n}\n\n/**\n * Check if an object has an own property.\n *\n * Type-safe wrapper around `Object.hasOwn()` that returns `false` for\n * null/undefined instead of throwing. Only checks own properties, not\n * inherited ones from the prototype chain.\n *\n * @param obj - The value to check\n * @param propKey - The property key to look for\n * @returns `true` if obj has the property as an own property, `false` otherwise\n *\n * @example\n * ```ts\n * const obj = { name: 'Alice' }\n * hasOwn(obj, 'name') // true\n * hasOwn(obj, 'age') // false\n * hasOwn(obj, 'toString') // false (inherited from Object.prototype)\n * hasOwn(null, 'name') // false\n * hasOwn(undefined, 'name') // false\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function hasOwn(\n obj: unknown,\n propKey: PropertyKey,\n): obj is object & PropertyBag {\n if (obj === null || obj === undefined) {\n return false\n }\n return ObjectHasOwn(obj as object, propKey)\n}\n\n/**\n * Check if a value is an object (including arrays).\n *\n * Returns `true` for any object type including arrays, functions, dates, etc.\n * Returns `false` for primitives and `null`.\n *\n * @param value - The value to check\n * @returns `true` if value is an object (including arrays), `false` otherwise\n *\n * @example\n * ```ts\n * isObject({}) // true\n * isObject([]) // true\n * isObject(new Date()) // true\n * isObject(() => {}) // false (functions are not objects for typeof)\n * isObject(null) // false\n * isObject(undefined) // false\n * isObject(42) // false\n * isObject('string') // false\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isObject(\n value: unknown,\n): value is { [key: PropertyKey]: unknown } {\n return value !== null && typeof value === 'object'\n}\n\n/**\n * Check if a value is a plain object (not an array, not a built-in).\n *\n * Returns `true` only for plain objects created with `{}` or `Object.create(null)`.\n * Returns `false` for arrays, built-in objects (Date, RegExp, etc.), and primitives.\n *\n * @param value - The value to check\n * @returns `true` if value is a plain object, `false` otherwise\n *\n * @example\n * ```ts\n * isObjectObject({}) // true\n * isObjectObject({ a: 1 }) // true\n * isObjectObject(Object.create(null)) // true\n * isObjectObject([]) // false\n * isObjectObject(new Date()) // false\n * isObjectObject(null) // false\n * isObjectObject(42) // false\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isObjectObject(\n value: unknown,\n): value is { [key: PropertyKey]: unknown } {\n if (value === null || typeof value !== 'object' || isArray(value)) {\n return false\n }\n const proto: any = ObjectGetPrototypeOf(value)\n return proto === null || proto === ObjectPrototype\n}\n\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\n\n/**\n * Alias for native `Object.assign`.\n *\n * Copies all enumerable own properties from one or more source objects\n * to a target object and returns the modified target object.\n *\n * @example\n * ```ts\n * const target = { a: 1 }\n * const source = { b: 2, c: 3 }\n * objectAssign(target, source) // { a: 1, b: 2, c: 3 }\n * ```\n */\nexport const objectAssign = Object.assign\n\n/**\n * Get all own property entries (key-value pairs) from an object.\n *\n * Unlike `Object.entries()`, this includes non-enumerable properties and\n * symbol keys. Returns an empty array for null/undefined.\n *\n * @param obj - The object to get entries from\n * @returns Array of [key, value] tuples, or empty array for null/undefined\n *\n * @example\n * ```ts\n * objectEntries({ a: 1, b: 2 }) // [['a', 1], ['b', 2]]\n * const sym = Symbol('key')\n * objectEntries({ [sym]: 'value', x: 10 }) // [[Symbol(key), 'value'], ['x', 10]]\n * objectEntries(null) // []\n * objectEntries(undefined) // []\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function objectEntries(obj: unknown): Array<[PropertyKey, unknown]> {\n if (obj === null || obj === undefined) {\n return []\n }\n const keys = ReflectOwnKeys(obj as object)\n const { length } = keys\n const entries = Array(length)\n const record = obj as Record<PropertyKey, unknown>\n for (let i = 0; i < length; i += 1) {\n const key = keys[i] as PropertyKey\n entries[i] = [key, record[key]]\n }\n return entries\n}\n\n// IMPORTANT: Do not use destructuring here - use direct assignment instead.\n// tsgo has a bug that incorrectly transpiles destructured exports, resulting in\n// `exports.SomeName = void 0;` which causes runtime errors.\n// See: https://github.com/SocketDev/socket-packageurl-js/issues/3\n\n/**\n * Alias for native `Object.freeze`.\n *\n * Freezes an object, preventing new properties from being added and existing\n * properties from being removed or modified. Makes the object immutable.\n *\n * @example\n * ```ts\n * const obj = { a: 1 }\n * objectFreeze(obj)\n * obj.a = 2 // Silently fails in non-strict mode, throws in strict mode\n * obj.b = 3 // Silently fails in non-strict mode, throws in strict mode\n * ```\n */\nexport const objectFreeze = Object.freeze\n\n/**\n * Deep merge source object into target object.\n *\n * Recursively merges properties from `source` into `target`. Arrays in source\n * completely replace arrays in target (no element-wise merging). Objects are\n * merged recursively. Includes infinite loop detection for safety.\n *\n * @param target - The object to merge into (will be modified)\n * @param source - The object to merge from\n * @returns The modified target object\n *\n * @example\n * ```ts\n * const target = { a: { x: 1 }, b: [1, 2] }\n * const source = { a: { y: 2 }, b: [3, 4, 5], c: 3 }\n * merge(target, source)\n * // { a: { x: 1, y: 2 }, b: [3, 4, 5], c: 3 }\n * ```\n *\n * @example\n * ```ts\n * // Arrays are replaced, not merged\n * merge({ arr: [1, 2] }, { arr: [3] }) // { arr: [3] }\n *\n * // Deep object merging\n * merge(\n * { config: { api: 'v1', timeout: 1000 } },\n * { config: { api: 'v2', retries: 3 } }\n * )\n * // { config: { api: 'v2', timeout: 1000, retries: 3 } }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function merge<T extends object, U extends object>(\n target: T,\n source: U,\n): T & U {\n if (!isObject(target) || !isObject(source)) {\n return target as T & U\n }\n const queue: Array<[unknown, unknown]> = [[target, source]]\n let pos = 0\n let { length: queueLength } = queue\n while (pos < queueLength) {\n if (pos === LOOP_SENTINEL) {\n throw new Error('Detected infinite loop in object crawl of merge')\n }\n const { 0: currentTarget, 1: currentSource } = queue[pos++] as [\n Record<PropertyKey, unknown>,\n Record<PropertyKey, unknown>,\n ]\n\n if (!currentSource || !currentTarget) {\n continue\n }\n\n const isSourceArray = isArray(currentSource)\n const isTargetArray = isArray(currentTarget)\n\n // Skip array merging - arrays in source replace arrays in target\n if (isSourceArray || isTargetArray) {\n continue\n }\n\n const keys = ReflectOwnKeys(currentSource as object)\n for (let i = 0, { length } = keys; i < length; i += 1) {\n const key = keys[i] as PropertyKey\n const srcVal = currentSource[key]\n const targetVal = currentTarget[key]\n if (isArray(srcVal)) {\n // Replace arrays entirely\n currentTarget[key] = srcVal\n } else if (isObject(srcVal)) {\n if (isObject(targetVal) && !isArray(targetVal)) {\n queue[queueLength++] = [targetVal, srcVal]\n } else {\n currentTarget[key] = srcVal\n }\n } else {\n currentTarget[key] = srcVal\n }\n }\n }\n return target as T & U\n}\n\n/**\n * Convert an object to a new object with sorted keys.\n *\n * Creates a new object with the same properties as the input, but with keys\n * sorted alphabetically. Symbol keys are sorted separately and placed first.\n * This is useful for consistent key ordering in serialization or comparisons.\n *\n * @param obj - The object to sort\n * @returns A new object with sorted keys\n *\n * @example\n * ```ts\n * toSortedObject({ z: 1, a: 2, m: 3 })\n * // { a: 2, m: 3, z: 1 }\n *\n * const sym1 = Symbol('first')\n * const sym2 = Symbol('second')\n * toSortedObject({ z: 1, [sym2]: 2, a: 3, [sym1]: 4 })\n * // { [Symbol(first)]: 4, [Symbol(second)]: 2, a: 3, z: 1 }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function toSortedObject<T extends object>(obj: T): T {\n return toSortedObjectFromEntries(objectEntries(obj)) as T\n}\n\n/**\n * Create an object from entries with sorted keys.\n *\n * Takes an iterable of [key, value] entries and creates a new object with\n * keys sorted alphabetically. Symbol keys are sorted separately and placed\n * first in the resulting object.\n *\n * @param entries - Iterable of [key, value] tuples\n * @returns A new object with sorted keys\n *\n * @example\n * ```ts\n * toSortedObjectFromEntries([['z', 1], ['a', 2], ['m', 3]])\n * // { a: 2, m: 3, z: 1 }\n *\n * const entries = new Map([['beta', 2], ['alpha', 1], ['gamma', 3]])\n * toSortedObjectFromEntries(entries)\n * // { alpha: 1, beta: 2, gamma: 3 }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function toSortedObjectFromEntries<T = unknown>(\n entries: Iterable<[PropertyKey, T]>,\n): SortedObject<T> {\n const otherEntries = []\n const symbolEntries = []\n // Use for-of to work with entries iterators.\n for (const entry of entries) {\n if (typeof entry[0] === 'symbol') {\n symbolEntries.push(entry)\n } else {\n otherEntries.push(entry)\n }\n }\n if (!otherEntries.length && !symbolEntries.length) {\n return {}\n }\n return ObjectFromEntries([\n // The String constructor is safe to use with symbols.\n ...symbolEntries.sort(entryKeyComparator),\n ...otherEntries.sort(entryKeyComparator),\n ])\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,kBAIO;AAEP,oBAAwB;AACxB,mBAA8B;AAwE9B,MAAM,yBAAyB,OAAO;AACtC,MAAM,uBAAuB,OAAO;AACpC,MAAM,eAAe,OAAO;AAC5B,MAAM,oBAAoB,OAAO;AACjC,MAAM,kCAAkC,OAAO;AAC/C,MAAM,4BAA4B,OAAO;AACzC,MAAM,uBAAuB,OAAO;AACpC,MAAM,eAAe,OAAO;AAC5B,MAAM,aAAa,OAAO;AAC1B,MAAM,kBAAkB,OAAO;AAC/B,MAAM,uBAAuB,OAAO;AAWpC,MAAM,iBAAiB,QAAQ;AAAA;AA4BxB,SAAS,iBACd,MACA,QACA,OACS;AACT,MAAI,YAAwC;AAE5C,QAAM,EAAE,CAAC,IAAI,GAAG,WAAW,IAAI;AAAA,IAC7B,CAAC,IAAI,IAAI;AACP,UAAI,cAAc,6BAAiB;AACjC,eAAO,aAAa,IAAI,IAAI;AAC5B,oBAAY,OAAO;AAAA,MACrB;AACA,aAAO;A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AAC3B,QAAI,OAAO,MAAM,CAAC,MAAM,UAAU;AAChC,oBAAc,KAAK,KAAK;AAAA,IAC1B,OAAO;AACL,mBAAa,KAAK,KAAK;AAAA,IACzB;AAAA,EACF;AACA,MAAI,CAAC,aAAa,UAAU,CAAC,cAAc,QAAQ;AACjD,WAAO,CAAC;AAAA,EACV;AACA,SAAO,kBAAkB;AAAA;AAAA,IAEvB,GAAG,cAAc,KAAK,kBAAkB;AAAA,IACxC,GAAG,aAAa,KAAK,kBAAkB;AAAA,EACzC,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/spinner.js
CHANGED
|
@@ -245,7 +245,11 @@ function Spinner(options) {
|
|
|
245
245
|
}
|
|
246
246
|
const wasSpinning = this.isSpinning;
|
|
247
247
|
const normalized = normalizeText(text);
|
|
248
|
-
|
|
248
|
+
if (methodName === "stop" && !normalized) {
|
|
249
|
+
super[methodName]();
|
|
250
|
+
} else {
|
|
251
|
+
super[methodName](normalized);
|
|
252
|
+
}
|
|
249
253
|
const {
|
|
250
254
|
getDefaultLogger,
|
|
251
255
|
incLogCallCountSymbol,
|
package/dist/spinner.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/spinner.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview CLI spinner utilities for long-running operations.\n * Provides animated progress indicators with CI environment detection.\n */\n\nimport type { Writable } from 'stream'\n\n// Note: getAbortSignal is imported lazily to avoid circular dependencies.\nimport { getCI } from '#env/ci'\nimport { generateSocketSpinnerFrames } from './effects/pulse-frames'\nimport type {\n ShimmerColorGradient,\n ShimmerConfig,\n ShimmerDirection,\n ShimmerState,\n} from './effects/text-shimmer'\nimport { applyShimmer, COLOR_INHERIT, DIR_LTR } from './effects/text-shimmer'\nimport yoctoSpinner from './external/@socketregistry/yocto-spinner'\nimport { hasOwn } from './objects'\nimport { isBlankString, stringWidth } from './strings'\nimport { getTheme } from './themes/context'\nimport { resolveColor } from './themes/utils'\n\n/**\n * Named color values supported by the spinner.\n * Maps to standard terminal colors with bright variants.\n */\nexport type ColorName =\n | 'black'\n | 'blue'\n | 'blueBright'\n | 'cyan'\n | 'cyanBright'\n | 'gray'\n | 'green'\n | 'greenBright'\n | 'magenta'\n | 'magentaBright'\n | 'red'\n | 'redBright'\n | 'white'\n | 'whiteBright'\n | 'yellow'\n | 'yellowBright'\n\n/**\n * Special 'inherit' color value that uses the spinner's current color.\n * Used with shimmer effects to dynamically inherit the spinner color.\n */\nexport type ColorInherit = 'inherit'\n\n/**\n * RGB color tuple with values 0-255 for red, green, and blue channels.\n * @example [140, 82, 255] // Socket purple\n * @example [255, 0, 0] // Red\n */\nexport type ColorRgb = readonly [number, number, number]\n\n/**\n * Union of all supported color types: named colors or RGB tuples.\n */\nexport type ColorValue = ColorName | ColorRgb\n\n/**\n * Symbol types for status messages.\n * Maps to log symbols: success (\u2713), fail (\u2717), info (\u2139), warn (\u26A0).\n */\nexport type SymbolType = 'fail' | 'info' | 'success' | 'warn'\n\n// Map color names to RGB values.\nconst colorToRgb: Record<ColorName, ColorRgb> = {\n __proto__: null,\n black: [0, 0, 0],\n blue: [0, 0, 255],\n blueBright: [100, 149, 237],\n cyan: [0, 255, 255],\n cyanBright: [0, 255, 255],\n gray: [128, 128, 128],\n green: [0, 128, 0],\n greenBright: [0, 255, 0],\n magenta: [255, 0, 255],\n magentaBright: [255, 105, 180],\n red: [255, 0, 0],\n redBright: [255, 69, 0],\n white: [255, 255, 255],\n whiteBright: [255, 255, 255],\n yellow: [255, 255, 0],\n yellowBright: [255, 255, 153],\n} as Record<ColorName, ColorRgb>\n\n/**\n * Type guard to check if a color value is an RGB tuple.\n * @param value - Color value to check\n * @returns `true` if value is an RGB tuple, `false` if it's a color name\n */\nfunction isRgbTuple(value: ColorValue): value is ColorRgb {\n return Array.isArray(value)\n}\n\n/**\n * Convert a color value to RGB tuple format.\n * Named colors are looked up in the `colorToRgb` map, RGB tuples are returned as-is.\n * @param color - Color name or RGB tuple\n * @returns RGB tuple with values 0-255\n */\nexport function toRgb(color: ColorValue): ColorRgb {\n if (isRgbTuple(color)) {\n return color\n }\n return colorToRgb[color]\n}\n\n/**\n * Progress tracking information for display in spinner.\n * Used by `progress()` and `progressStep()` methods to show animated progress bars.\n */\nexport type ProgressInfo = {\n /** Current progress value */\n current: number\n /** Total/maximum progress value */\n total: number\n /** Optional unit label displayed after the progress count (e.g., 'files', 'items') */\n unit?: string | undefined\n}\n\n/**\n * Internal shimmer state with color configuration.\n * Extends `ShimmerState` with additional color property that can be inherited from spinner.\n */\nexport type ShimmerInfo = ShimmerState & {\n /** Color for shimmer effect - can inherit from spinner, use explicit color, or gradient */\n color: ColorInherit | ColorValue | ShimmerColorGradient\n}\n\n/**\n * Spinner instance for displaying animated loading indicators.\n * Provides methods for status updates, progress tracking, and text shimmer effects.\n *\n * KEY BEHAVIORS:\n * - Methods WITHOUT \"AndStop\" keep the spinner running (e.g., `success()`, `fail()`)\n * - Methods WITH \"AndStop\" auto-clear the spinner line (e.g., `successAndStop()`, `failAndStop()`)\n * - Status messages (done, success, fail, info, warn, step, substep) go to stderr\n * - Data messages (`log()`) go to stdout\n *\n * @example\n * ```ts\n * import { Spinner } from '@socketsecurity/lib/spinner'\n *\n * const spinner = Spinner({ text: 'Loading\u2026' })\n * spinner.start()\n *\n * // Show success while continuing to spin\n * spinner.success('Step 1 complete')\n *\n * // Stop the spinner with success message\n * spinner.successAndStop('All done!')\n * ```\n */\nexport type Spinner = {\n /** Current spinner color as RGB tuple */\n color: ColorRgb\n /** Current spinner animation style */\n spinner: SpinnerStyle\n\n /** Whether spinner is currently animating */\n get isSpinning(): boolean\n\n /** Get current shimmer state (enabled/disabled and configuration) */\n get shimmerState(): ShimmerInfo | undefined\n\n /** Clear the current line without stopping the spinner */\n clear(): Spinner\n\n /** Show debug message without stopping (only if debug mode enabled) */\n debug(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Show debug message and stop the spinner (only if debug mode enabled) */\n debugAndStop(text?: string | undefined, ...extras: unknown[]): Spinner\n\n /** Alias for `fail()` - show error without stopping */\n error(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Alias for `failAndStop()` - show error and stop */\n errorAndStop(text?: string | undefined, ...extras: unknown[]): Spinner\n\n /** Show failure (\u2717) without stopping the spinner */\n fail(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Show failure (\u2717) and stop the spinner, auto-clearing the line */\n failAndStop(text?: string | undefined, ...extras: unknown[]): Spinner\n\n /** Get current spinner text (getter) or set new text (setter) */\n text(value: string): Spinner\n text(): string\n\n /** Increase indentation by specified spaces (default: 2) */\n indent(spaces?: number | undefined): Spinner\n /** Decrease indentation by specified spaces (default: 2) */\n dedent(spaces?: number | undefined): Spinner\n\n /** Show info (\u2139) message without stopping the spinner */\n info(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Show info (\u2139) message and stop the spinner, auto-clearing the line */\n infoAndStop(text?: string | undefined, ...extras: unknown[]): Spinner\n\n /** Log to stdout without stopping the spinner */\n log(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Log and stop the spinner, auto-clearing the line */\n logAndStop(text?: string | undefined, ...extras: unknown[]): Spinner\n\n /** Start spinning with optional text */\n start(text?: string | undefined): Spinner\n /** Stop spinning and clear internal state, auto-clearing the line */\n stop(text?: string | undefined): Spinner\n /** Stop and show final text without clearing the line */\n stopAndPersist(text?: string | undefined): Spinner\n\n /** Show main step message to stderr without stopping */\n step(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Show indented substep message to stderr without stopping */\n substep(text?: string | undefined, ...extras: unknown[]): Spinner\n\n /** Show success (\u2713) without stopping the spinner */\n success(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Show success (\u2713) and stop the spinner, auto-clearing the line */\n successAndStop(text?: string | undefined, ...extras: unknown[]): Spinner\n\n /** Alias for `success()` - show success without stopping */\n done(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Alias for `successAndStop()` - show success and stop */\n doneAndStop(text?: string | undefined, ...extras: unknown[]): Spinner\n\n /** Update progress bar with current/total values and optional unit */\n progress(current: number, total: number, unit?: string | undefined): Spinner\n /** Increment progress by specified amount (default: 1) */\n progressStep(amount?: number): Spinner\n\n /** Enable shimmer effect (restores saved config or uses defaults) */\n enableShimmer(): Spinner\n /** Disable shimmer effect (preserves config for later re-enable) */\n disableShimmer(): Spinner\n /** Set complete shimmer configuration */\n setShimmer(config: ShimmerConfig): Spinner\n /** Update partial shimmer configuration */\n updateShimmer(config: Partial<ShimmerConfig>): Spinner\n\n /** Show warning (\u26A0) without stopping the spinner */\n warn(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Show warning (\u26A0) and stop the spinner, auto-clearing the line */\n warnAndStop(text?: string | undefined, ...extras: unknown[]): Spinner\n}\n\n/**\n * Configuration options for creating a spinner instance.\n */\nexport type SpinnerOptions = {\n /**\n * Spinner color as RGB tuple or color name.\n * @default [140, 82, 255] Socket purple\n */\n readonly color?: ColorValue | undefined\n /**\n * Shimmer effect configuration or direction string.\n * When enabled, text will have an animated shimmer effect.\n * @default undefined No shimmer effect\n */\n readonly shimmer?: ShimmerConfig | ShimmerDirection | undefined\n /**\n * Animation style with frames and timing.\n * @default 'socket' Custom Socket animation in CLI, minimal in CI\n */\n readonly spinner?: SpinnerStyle | undefined\n /**\n * Abort signal for cancelling the spinner.\n * @default getAbortSignal() from process constants\n */\n readonly signal?: AbortSignal | undefined\n /**\n * Output stream for spinner rendering.\n * @default process.stderr\n */\n readonly stream?: Writable | undefined\n /**\n * Initial text to display with the spinner.\n * @default undefined No initial text\n */\n readonly text?: string | undefined\n}\n\n/**\n * Animation style definition for spinner frames.\n * Defines the visual appearance and timing of the spinner animation.\n */\nexport type SpinnerStyle = {\n /** Array of animation frames (strings to display sequentially) */\n readonly frames: string[]\n /**\n * Milliseconds between frame changes.\n * @default 80 Standard frame rate\n */\n readonly interval?: number | undefined\n}\n\n/**\n * Minimal spinner style for CI environments.\n * Uses empty frame and max interval to effectively disable animation in CI.\n */\nexport const ciSpinner: SpinnerStyle = {\n frames: [''],\n interval: 2_147_483_647,\n}\n\n/**\n * Create a property descriptor for defining non-enumerable properties.\n * Used for adding aliased methods to the Spinner prototype.\n * @param value - Value for the property\n * @returns Property descriptor object\n * @private\n */\nfunction desc(value: unknown) {\n return {\n __proto__: null,\n configurable: true,\n value,\n writable: true,\n }\n}\n\n/**\n * Normalize text input by trimming leading whitespace.\n * Non-string values are converted to empty string.\n * @param value - Text to normalize\n * @returns Normalized string with leading whitespace removed\n * @private\n */\nfunction normalizeText(value: unknown) {\n return typeof value === 'string' ? value.trimStart() : ''\n}\n\n/**\n * Format progress information as a visual progress bar with percentage and count.\n * @param progress - Progress tracking information\n * @returns Formatted string with colored progress bar, percentage, and count\n * @private\n * @example \"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 35% (7/20 files)\"\n */\nfunction formatProgress(progress: ProgressInfo): string {\n const { current, total, unit } = progress\n const percentage = Math.round((current / total) * 100)\n const bar = renderProgressBar(percentage)\n const count = unit ? `${current}/${total} ${unit}` : `${current}/${total}`\n return `${bar} ${percentage}% (${count})`\n}\n\n/**\n * Render a progress bar using block characters (\u2588 for filled, \u2591 for empty).\n * @param percentage - Progress percentage (0-100)\n * @param width - Total width of progress bar in characters\n * @returns Colored progress bar string\n * @default width=20\n * @private\n */\nfunction renderProgressBar(percentage: number, width: number = 20): string {\n const filled = Math.round((percentage / 100) * width)\n const empty = width - filled\n const bar = '\u2588'.repeat(filled) + '\u2591'.repeat(empty)\n // Use cyan color for the progress bar\n const colors = /*@__PURE__*/ require('./external/yoctocolors-cjs')\n return colors.cyan(bar)\n}\n\nlet _cliSpinners: Record<string, SpinnerStyle> | undefined\n\n/**\n * Get available CLI spinner styles or a specific style by name.\n * Extends the standard cli-spinners collection with Socket custom spinners.\n *\n * Custom spinners:\n * - `socket` (default): Socket pulse animation with sparkles and lightning\n *\n * @param styleName - Optional name of specific spinner style to retrieve\n * @returns Specific spinner style if name provided, all styles if omitted, `undefined` if style not found\n * @see https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json\n *\n * @example\n * ```ts\n * // Get all available spinner styles\n * const allSpinners = getCliSpinners()\n *\n * // Get specific style\n * const socketStyle = getCliSpinners('socket')\n * const dotsStyle = getCliSpinners('dots')\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function getCliSpinners(\n styleName?: string | undefined,\n): SpinnerStyle | Record<string, SpinnerStyle> | undefined {\n if (_cliSpinners === undefined) {\n const YoctoCtor = yoctoSpinner as any\n // Get the YoctoSpinner class to access static properties.\n const tempInstance = YoctoCtor({})\n const YoctoSpinnerClass = tempInstance.constructor as any\n // Extend the standard cli-spinners collection with Socket custom spinners.\n _cliSpinners = {\n __proto__: null,\n ...YoctoSpinnerClass.spinners,\n socket: generateSocketSpinnerFrames(),\n }\n }\n if (typeof styleName === 'string' && _cliSpinners) {\n return hasOwn(_cliSpinners, styleName) ? _cliSpinners[styleName] : undefined\n }\n return _cliSpinners\n}\n\nlet _Spinner: {\n new (options?: SpinnerOptions | undefined): Spinner\n}\nlet _defaultSpinner: SpinnerStyle | undefined\n\n/**\n * Create a spinner instance for displaying loading indicators.\n * Provides an animated CLI spinner with status messages, progress tracking, and shimmer effects.\n *\n * AUTO-CLEAR BEHAVIOR:\n * - All *AndStop() methods AUTO-CLEAR the spinner line via yocto-spinner.stop()\n * Examples: `doneAndStop()`, `successAndStop()`, `failAndStop()`, etc.\n *\n * - Methods WITHOUT \"AndStop\" do NOT clear (spinner keeps spinning)\n * Examples: `done()`, `success()`, `fail()`, etc.\n *\n * STREAM USAGE:\n * - Spinner animation: stderr (yocto-spinner default)\n * - Status methods (done, success, fail, info, warn, step, substep): stderr\n * - Data methods (`log()`): stdout\n *\n * COMPARISON WITH LOGGER:\n * - `logger.done()` does NOT auto-clear (requires manual `logger.clearLine()`)\n * - `spinner.doneAndStop()` DOES auto-clear (built into yocto-spinner.stop())\n * - Pattern: `logger.clearLine().done()` vs `spinner.doneAndStop()`\n *\n * @param options - Configuration options for the spinner\n * @returns New spinner instance\n *\n * @example\n * ```ts\n * import { Spinner } from '@socketsecurity/lib/spinner'\n *\n * // Basic usage\n * const spinner = Spinner({ text: 'Loading data\u2026' })\n * spinner.start()\n * await fetchData()\n * spinner.successAndStop('Data loaded!')\n *\n * // With custom color\n * const spinner = Spinner({\n * text: 'Processing\u2026',\n * color: [255, 0, 0] // Red\n * })\n *\n * // With shimmer effect\n * const spinner = Spinner({\n * text: 'Building\u2026',\n * shimmer: { dir: 'ltr', speed: 0.5 }\n * })\n *\n * // Show progress\n * spinner.progress(5, 10, 'files')\n * spinner.progressStep() // Increment by 1\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function Spinner(options?: SpinnerOptions | undefined): Spinner {\n if (_Spinner === undefined) {\n const YoctoCtor = yoctoSpinner as any\n // Get the actual YoctoSpinner class from an instance\n const tempInstance = YoctoCtor({})\n const YoctoSpinnerClass = tempInstance.constructor\n\n /*@__PURE__*/\n _Spinner = class SpinnerClass extends (YoctoSpinnerClass as any) {\n declare isSpinning: boolean\n #baseText: string = ''\n #indentation: string = ''\n #progress?: ProgressInfo | undefined\n #shimmer?: ShimmerInfo | undefined\n #shimmerSavedConfig?: ShimmerInfo | undefined\n\n constructor(options?: SpinnerOptions | undefined) {\n const opts = { __proto__: null, ...options } as SpinnerOptions\n\n // Get default color from theme if not specified\n const theme = getTheme()\n let defaultColor: ColorValue = theme.colors.primary\n if (theme.effects?.spinner?.color) {\n const resolved = resolveColor(\n theme.effects.spinner.color,\n theme.colors,\n )\n // resolveColor can return 'inherit' or gradients which aren't valid for spinner\n // Fall back to primary for these cases\n if (resolved === 'inherit' || Array.isArray(resolved[0])) {\n defaultColor = theme.colors.primary\n } else {\n defaultColor = resolved as ColorValue\n }\n }\n\n // Convert color option to RGB (default from theme).\n const spinnerColor = opts.color ?? defaultColor\n\n // Validate RGB tuple if provided.\n if (\n isRgbTuple(spinnerColor) &&\n (spinnerColor.length !== 3 ||\n !spinnerColor.every(\n n => typeof n === 'number' && n >= 0 && n <= 255,\n ))\n ) {\n throw new TypeError(\n 'RGB color must be an array of 3 numbers between 0 and 255',\n )\n }\n\n const spinnerColorRgb = toRgb(spinnerColor)\n\n // Parse shimmer config - can be object or direction string.\n let shimmerInfo: ShimmerInfo | undefined\n if (opts.shimmer) {\n let shimmerDir: ShimmerDirection\n let shimmerColor:\n | ColorInherit\n | ColorValue\n | ShimmerColorGradient\n | undefined\n // Default: 0.33 steps per frame (~150ms per step).\n let shimmerSpeed: number = 1 / 3\n\n if (typeof opts.shimmer === 'string') {\n shimmerDir = opts.shimmer\n } else {\n const shimmerConfig = {\n __proto__: null,\n ...opts.shimmer,\n } as ShimmerConfig\n shimmerDir = shimmerConfig.dir ?? DIR_LTR\n shimmerColor = shimmerConfig.color ?? COLOR_INHERIT\n shimmerSpeed = shimmerConfig.speed ?? 1 / 3\n }\n\n // Create shimmer info with initial animation state:\n // - COLOR_INHERIT means use spinner color dynamically\n // - ColorValue (name or RGB tuple) is an explicit override color\n // - undefined color defaults to COLOR_INHERIT\n // - speed controls steps per frame (lower = slower, e.g., 0.33 = ~150ms per step)\n shimmerInfo = {\n __proto__: null,\n color: shimmerColor === undefined ? COLOR_INHERIT : shimmerColor,\n currentDir: DIR_LTR,\n mode: shimmerDir,\n speed: shimmerSpeed,\n step: 0,\n } as ShimmerInfo\n }\n\n // eslint-disable-next-line constructor-super\n super({\n signal: require('#constants/process').getAbortSignal(),\n ...opts,\n // Pass RGB color directly to yocto-spinner (it now supports RGB).\n color: spinnerColorRgb,\n // onRenderFrame callback provides full control over frame + text layout.\n // Calculates spacing based on frame width to prevent text jumping.\n onRenderFrame: (\n frame: string,\n text: string,\n applyColor: (text: string) => string,\n ) => {\n const width = stringWidth(frame)\n // Narrow frames (width 1) get 2 spaces, wide frames (width 2) get 1 space.\n // Total width is consistent: 3 characters (frame + spacing) before text.\n const spacing = width === 1 ? ' ' : ' '\n return frame ? `${applyColor(frame)}${spacing}${text}` : text\n },\n // onFrameUpdate callback is called by yocto-spinner whenever a frame advances.\n // This ensures shimmer updates are perfectly synchronized with animation beats.\n onFrameUpdate: shimmerInfo\n ? () => {\n // Update parent's text without triggering render.\n // Parent's #skipRender flag prevents nested render calls.\n // Only update if we have base text to avoid blank frames.\n if (this.#baseText) {\n super.text = this.#buildDisplayText()\n }\n }\n : undefined,\n })\n\n this.#shimmer = shimmerInfo\n this.#shimmerSavedConfig = shimmerInfo\n }\n\n // Override color getter to ensure it's always RGB.\n get color(): ColorRgb {\n const value = super.color\n return isRgbTuple(value) ? value : toRgb(value)\n }\n\n // Override color setter to always convert to RGB before passing to yocto-spinner.\n set color(value: ColorValue | ColorRgb) {\n super.color = isRgbTuple(value) ? value : toRgb(value)\n }\n\n // Getter to expose current shimmer state.\n get shimmerState(): ShimmerInfo | undefined {\n if (!this.#shimmer) {\n return undefined\n }\n return {\n color: this.#shimmer.color,\n currentDir: this.#shimmer.currentDir,\n mode: this.#shimmer.mode,\n speed: this.#shimmer.speed,\n step: this.#shimmer.step,\n } as ShimmerInfo\n }\n\n /**\n * Apply a yocto-spinner method and update logger state.\n * Handles text normalization, extra arguments, and logger tracking.\n * @private\n */\n #apply(methodName: string, args: unknown[]) {\n let extras: unknown[]\n let text = args.at(0)\n if (typeof text === 'string') {\n extras = args.slice(1)\n } else {\n extras = args\n text = ''\n }\n const wasSpinning = this.isSpinning\n const normalized = normalizeText(text)\n super[methodName](normalized)\n const {\n getDefaultLogger,\n incLogCallCountSymbol,\n lastWasBlankSymbol,\n } = /*@__PURE__*/ require('./logger.js')\n const logger = getDefaultLogger()\n if (methodName === 'stop') {\n if (wasSpinning && normalized) {\n logger[lastWasBlankSymbol](isBlankString(normalized))\n logger[incLogCallCountSymbol]()\n }\n } else {\n logger[lastWasBlankSymbol](false)\n logger[incLogCallCountSymbol]()\n }\n if (extras.length) {\n logger.log(...extras)\n logger[lastWasBlankSymbol](false)\n }\n return this\n }\n\n /**\n * Build the complete display text with progress, shimmer, and indentation.\n * Combines base text, progress bar, shimmer effects, and indentation.\n * @private\n */\n #buildDisplayText() {\n let displayText = this.#baseText\n\n if (this.#progress) {\n const progressText = formatProgress(this.#progress)\n displayText = displayText\n ? `${displayText} ${progressText}`\n : progressText\n }\n\n // Apply shimmer effect if enabled.\n if (displayText && this.#shimmer) {\n // If shimmer color is 'inherit', use current spinner color (getter ensures RGB).\n // Otherwise, check if it's a gradient (array of arrays) or single color.\n let shimmerColor: ColorRgb | ShimmerColorGradient\n if (this.#shimmer.color === COLOR_INHERIT) {\n shimmerColor = this.color\n } else if (Array.isArray(this.#shimmer.color[0])) {\n // It's a gradient - use as is.\n shimmerColor = this.#shimmer.color as ShimmerColorGradient\n } else {\n // It's a single color - convert to RGB.\n shimmerColor = toRgb(this.#shimmer.color as ColorValue)\n }\n\n displayText = applyShimmer(displayText, this.#shimmer, {\n color: shimmerColor,\n direction: this.#shimmer.mode,\n })\n }\n\n // Apply indentation\n if (this.#indentation && displayText) {\n displayText = this.#indentation + displayText\n }\n\n return displayText\n }\n\n /**\n * Show a status message without stopping the spinner.\n * Outputs the symbol and message to stderr, then continues spinning.\n */\n #showStatusAndKeepSpinning(symbolType: SymbolType, args: unknown[]) {\n let text = args.at(0)\n let extras: unknown[]\n if (typeof text === 'string') {\n extras = args.slice(1)\n } else {\n extras = args\n text = ''\n }\n\n const {\n LOG_SYMBOLS,\n getDefaultLogger,\n } = /*@__PURE__*/ require('./logger.js')\n // Note: Status messages always go to stderr.\n const logger = getDefaultLogger()\n logger.error(`${LOG_SYMBOLS[symbolType]} ${text}`, ...extras)\n return this\n }\n\n /**\n * Update the spinner's displayed text.\n * Rebuilds display text and triggers render.\n * @private\n */\n #updateSpinnerText() {\n // Call the parent class's text setter, which triggers render.\n super.text = this.#buildDisplayText()\n }\n\n /**\n * Show a debug message (\u2139) without stopping the spinner.\n * Only displays if debug mode is enabled via environment variable.\n * Outputs to stderr and continues spinning.\n *\n * @param text - Debug message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n debug(text?: string | undefined, ...extras: unknown[]) {\n const { isDebug } = /*@__PURE__*/ require('./debug.js')\n if (isDebug()) {\n return this.#showStatusAndKeepSpinning('info', [text, ...extras])\n }\n return this\n }\n\n /**\n * Show a debug message (\u2139) and stop the spinner.\n * Only displays if debug mode is enabled via environment variable.\n * Auto-clears the spinner line before displaying the message.\n *\n * @param text - Debug message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n debugAndStop(text?: string | undefined, ...extras: unknown[]) {\n const { isDebug } = /*@__PURE__*/ require('./debug.js')\n if (isDebug()) {\n return this.#apply('info', [text, ...extras])\n }\n return this\n }\n\n /**\n * Decrease indentation level by removing spaces from the left.\n * Pass 0 to reset indentation to zero completely.\n *\n * @param spaces - Number of spaces to remove\n * @returns This spinner for chaining\n * @default spaces=2\n *\n * @example\n * ```ts\n * spinner.dedent() // Remove 2 spaces\n * spinner.dedent(4) // Remove 4 spaces\n * spinner.dedent(0) // Reset to zero indentation\n * ```\n */\n dedent(spaces?: number | undefined) {\n // Pass 0 to reset indentation\n if (spaces === 0) {\n this.#indentation = ''\n } else {\n const amount = spaces ?? 2\n const newLength = Math.max(0, this.#indentation.length - amount)\n this.#indentation = this.#indentation.slice(0, newLength)\n }\n this.#updateSpinnerText()\n return this\n }\n\n /**\n * Show a done/success message (\u2713) without stopping the spinner.\n * Alias for `success()` with a shorter name.\n *\n * DESIGN DECISION: Unlike yocto-spinner, our `done()` does NOT stop the spinner.\n * Use `doneAndStop()` if you want to stop the spinner.\n *\n * @param text - Message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n done(text?: string | undefined, ...extras: unknown[]) {\n return this.#showStatusAndKeepSpinning('success', [text, ...extras])\n }\n\n /**\n * Show a done/success message (\u2713) and stop the spinner.\n * Auto-clears the spinner line before displaying the success message.\n *\n * @param text - Message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n doneAndStop(text?: string | undefined, ...extras: unknown[]) {\n return this.#apply('success', [text, ...extras])\n }\n\n /**\n * Show a failure message (\u2717) without stopping the spinner.\n * DESIGN DECISION: Unlike yocto-spinner, our `fail()` does NOT stop the spinner.\n * This allows displaying errors while continuing to spin.\n * Use `failAndStop()` if you want to stop the spinner.\n *\n * @param text - Error message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n fail(text?: string | undefined, ...extras: unknown[]) {\n return this.#showStatusAndKeepSpinning('fail', [text, ...extras])\n }\n\n /**\n * Show a failure message (\u2717) and stop the spinner.\n * Auto-clears the spinner line before displaying the error message.\n *\n * @param text - Error message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n failAndStop(text?: string | undefined, ...extras: unknown[]) {\n return this.#apply('error', [text, ...extras])\n }\n\n /**\n * Increase indentation level by adding spaces to the left.\n * Pass 0 to reset indentation to zero completely.\n *\n * @param spaces - Number of spaces to add\n * @returns This spinner for chaining\n * @default spaces=2\n *\n * @example\n * ```ts\n * spinner.indent() // Add 2 spaces\n * spinner.indent(4) // Add 4 spaces\n * spinner.indent(0) // Reset to zero indentation\n * ```\n */\n indent(spaces?: number | undefined) {\n // Pass 0 to reset indentation\n if (spaces === 0) {\n this.#indentation = ''\n } else {\n const amount = spaces ?? 2\n this.#indentation += ' '.repeat(amount)\n }\n this.#updateSpinnerText()\n return this\n }\n\n /**\n * Show an info message (\u2139) without stopping the spinner.\n * Outputs to stderr and continues spinning.\n *\n * @param text - Info message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n info(text?: string | undefined, ...extras: unknown[]) {\n return this.#showStatusAndKeepSpinning('info', [text, ...extras])\n }\n\n /**\n * Show an info message (\u2139) and stop the spinner.\n * Auto-clears the spinner line before displaying the message.\n *\n * @param text - Info message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n infoAndStop(text?: string | undefined, ...extras: unknown[]) {\n return this.#apply('info', [text, ...extras])\n }\n\n /**\n * Log a message to stdout without stopping the spinner.\n * Unlike other status methods, this outputs to stdout for data logging.\n *\n * @param args - Values to log to stdout\n * @returns This spinner for chaining\n */\n log(...args: unknown[]) {\n const { getDefaultLogger } = /*@__PURE__*/ require('./logger.js')\n const logger = getDefaultLogger()\n logger.log(...args)\n return this\n }\n\n /**\n * Log a message to stdout and stop the spinner.\n * Auto-clears the spinner line before displaying the message.\n *\n * @param text - Message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n logAndStop(text?: string | undefined, ...extras: unknown[]) {\n return this.#apply('stop', [text, ...extras])\n }\n\n /**\n * Update progress information displayed with the spinner.\n * Shows a progress bar with percentage and optional unit label.\n *\n * @param current - Current progress value\n * @param total - Total/maximum progress value\n * @param unit - Optional unit label (e.g., 'files', 'items')\n * @returns This spinner for chaining\n *\n * @example\n * ```ts\n * spinner.progress(5, 10) // \"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 50% (5/10)\"\n * spinner.progress(7, 20, 'files') // \"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 35% (7/20 files)\"\n * ```\n */\n progress = (\n current: number,\n total: number,\n unit?: string | undefined,\n ) => {\n this.#progress = {\n __proto__: null,\n current,\n total,\n ...(unit ? { unit } : {}),\n } as ProgressInfo\n this.#updateSpinnerText()\n return this\n }\n\n /**\n * Increment progress by a specified amount.\n * Updates the progress bar displayed with the spinner.\n * Clamps the result between 0 and the total value.\n *\n * @param amount - Amount to increment by\n * @returns This spinner for chaining\n * @default amount=1\n *\n * @example\n * ```ts\n * spinner.progress(0, 10, 'files')\n * spinner.progressStep() // Progress: 1/10\n * spinner.progressStep(3) // Progress: 4/10\n * ```\n */\n progressStep(amount: number = 1) {\n if (this.#progress) {\n const newCurrent = this.#progress.current + amount\n this.#progress = {\n __proto__: null,\n current: Math.max(0, Math.min(newCurrent, this.#progress.total)),\n total: this.#progress.total,\n ...(this.#progress.unit ? { unit: this.#progress.unit } : {}),\n } as ProgressInfo\n this.#updateSpinnerText()\n }\n return this\n }\n\n /**\n * Start the spinner animation with optional text.\n * Begins displaying the animated spinner on stderr.\n *\n * @param text - Optional text to display with the spinner\n * @returns This spinner for chaining\n *\n * @example\n * ```ts\n * spinner.start('Loading\u2026')\n * // Later:\n * spinner.successAndStop('Done!')\n * ```\n */\n start(...args: unknown[]) {\n if (args.length) {\n const text = args.at(0)\n const normalized = normalizeText(text)\n // We clear this.text on start when `text` is falsy because yocto-spinner\n // will not clear it otherwise.\n if (!normalized) {\n this.#baseText = ''\n super.text = ''\n } else {\n this.#baseText = normalized\n }\n }\n\n this.#updateSpinnerText()\n // Don't pass text to yocto-spinner.start() since we already set it via #updateSpinnerText().\n // Passing args would cause duplicate message output.\n return this.#apply('start', [])\n }\n\n /**\n * Log a main step message to stderr without stopping the spinner.\n * Adds a blank line before the message for visual separation.\n * Aligns with `logger.step()` to use stderr for status messages.\n *\n * @param text - Step message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n *\n * @example\n * ```ts\n * spinner.step('Building application')\n * spinner.substep('Compiling TypeScript')\n * spinner.substep('Bundling assets')\n * ```\n */\n step(text?: string | undefined, ...extras: unknown[]) {\n const { getDefaultLogger } = /*@__PURE__*/ require('./logger.js')\n if (typeof text === 'string') {\n const logger = getDefaultLogger()\n // Add blank line before step for visual separation.\n logger.error('')\n // Use error (stderr) to align with logger.step() default stream.\n logger.error(text, ...extras)\n }\n return this\n }\n\n /**\n * Log an indented substep message to stderr without stopping the spinner.\n * Adds 2-space indentation to the message.\n * Aligns with `logger.substep()` to use stderr for status messages.\n *\n * @param text - Substep message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n *\n * @example\n * ```ts\n * spinner.step('Building application')\n * spinner.substep('Compiling TypeScript')\n * spinner.substep('Bundling assets')\n * ```\n */\n substep(text?: string | undefined, ...extras: unknown[]) {\n if (typeof text === 'string') {\n // Add 2-space indent for substep.\n const { getDefaultLogger } = /*@__PURE__*/ require('./logger.js')\n const logger = getDefaultLogger()\n // Use error (stderr) to align with logger.substep() default stream.\n logger.error(` ${text}`, ...extras)\n }\n return this\n }\n\n /**\n * Stop the spinner animation and clear internal state.\n * Auto-clears the spinner line via yocto-spinner.stop().\n * Resets progress, shimmer, and text state.\n *\n * @param text - Optional final text to display after stopping\n * @returns This spinner for chaining\n *\n * @example\n * ```ts\n * spinner.start('Processing\u2026')\n * // Do work\n * spinner.stop() // Just stop, no message\n * // or\n * spinner.stop('Finished processing')\n * ```\n */\n stop(...args: unknown[]) {\n // Clear internal state.\n this.#baseText = ''\n this.#progress = undefined\n // Reset shimmer animation state if shimmer is enabled.\n if (this.#shimmer) {\n this.#shimmer.currentDir = DIR_LTR\n this.#shimmer.step = 0\n }\n // Call parent stop first (clears screen, sets isSpinning = false).\n const result = this.#apply('stop', args)\n // Then clear text to avoid blank frame render.\n // This is safe now because isSpinning is false.\n super.text = ''\n return result\n }\n\n /**\n * Show a success message (\u2713) without stopping the spinner.\n * DESIGN DECISION: Unlike yocto-spinner, our `success()` does NOT stop the spinner.\n * This allows displaying success messages while continuing to spin for multi-step operations.\n * Use `successAndStop()` if you want to stop the spinner.\n *\n * @param text - Success message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n success(text?: string | undefined, ...extras: unknown[]) {\n return this.#showStatusAndKeepSpinning('success', [text, ...extras])\n }\n\n /**\n * Show a success message (\u2713) and stop the spinner.\n * Auto-clears the spinner line before displaying the success message.\n *\n * @param text - Success message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n successAndStop(text?: string | undefined, ...extras: unknown[]) {\n return this.#apply('success', [text, ...extras])\n }\n\n /**\n * Get or set the spinner text.\n * When called with no arguments, returns the current base text.\n * When called with text, updates the display and returns the spinner for chaining.\n *\n * @param value - Text to display (omit to get current text)\n * @returns Current text (getter) or this spinner (setter)\n *\n * @example\n * ```ts\n * // Setter\n * spinner.text('Loading data\u2026')\n * spinner.text('Processing\u2026')\n *\n * // Getter\n * const current = spinner.text()\n * console.log(current) // \"Processing\u2026\"\n * ```\n */\n text(): string\n text(value: string): Spinner\n text(value?: string): string | Spinner {\n // biome-ignore lint/complexity/noArguments: Function overload for getter/setter pattern.\n if (arguments.length === 0) {\n // Getter: return current base text\n return this.#baseText\n }\n // Setter: update base text and refresh display\n this.#baseText = value ?? ''\n this.#updateSpinnerText()\n return this as unknown as Spinner\n }\n\n /**\n * Show a warning message (\u26A0) without stopping the spinner.\n * Outputs to stderr and continues spinning.\n *\n * @param text - Warning message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n warn(text?: string | undefined, ...extras: unknown[]) {\n return this.#showStatusAndKeepSpinning('warn', [text, ...extras])\n }\n\n /**\n * Show a warning message (\u26A0) and stop the spinner.\n * Auto-clears the spinner line before displaying the warning message.\n *\n * @param text - Warning message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n warnAndStop(text?: string | undefined, ...extras: unknown[]) {\n return this.#apply('warning', [text, ...extras])\n }\n\n /**\n * Enable shimmer effect.\n * Restores saved config or uses defaults if no saved config exists.\n *\n * @returns This spinner for chaining\n *\n * @example\n * spinner.enableShimmer()\n */\n enableShimmer(): Spinner {\n if (this.#shimmerSavedConfig) {\n // Restore saved config.\n this.#shimmer = { ...this.#shimmerSavedConfig }\n } else {\n // Create default config.\n this.#shimmer = {\n color: COLOR_INHERIT,\n currentDir: DIR_LTR,\n mode: DIR_LTR,\n speed: 1 / 3,\n step: 0,\n } as ShimmerInfo\n this.#shimmerSavedConfig = this.#shimmer\n }\n\n this.#updateSpinnerText()\n return this as unknown as Spinner\n }\n\n /**\n * Disable shimmer effect.\n * Preserves config for later re-enable via enableShimmer().\n *\n * @returns This spinner for chaining\n *\n * @example\n * spinner.disableShimmer()\n */\n disableShimmer(): Spinner {\n // Disable shimmer but preserve config.\n this.#shimmer = undefined\n this.#updateSpinnerText()\n return this as unknown as Spinner\n }\n\n /**\n * Set complete shimmer configuration.\n * Replaces any existing shimmer config with the provided values.\n *\n * @param config - Complete shimmer configuration\n * @returns This spinner for chaining\n *\n * @example\n * spinner.setShimmer({\n * color: [255, 0, 0],\n * dir: 'rtl',\n * speed: 0.5\n * })\n */\n setShimmer(config: ShimmerConfig): Spinner {\n this.#shimmer = {\n color: config.color,\n currentDir: DIR_LTR,\n mode: config.dir,\n speed: config.speed,\n step: 0,\n } as ShimmerInfo\n this.#shimmerSavedConfig = this.#shimmer\n this.#updateSpinnerText()\n return this as unknown as Spinner\n }\n\n /**\n * Update partial shimmer configuration.\n * Merges with existing config, enabling shimmer if currently disabled.\n *\n * @param config - Partial shimmer configuration to merge\n * @returns This spinner for chaining\n *\n * @example\n * // Update just the speed\n * spinner.updateShimmer({ speed: 0.5 })\n *\n * // Update direction\n * spinner.updateShimmer({ dir: 'rtl' })\n *\n * // Update multiple properties\n * spinner.updateShimmer({ color: [255, 0, 0], speed: 0.8 })\n */\n updateShimmer(config: Partial<ShimmerConfig>): Spinner {\n const partialConfig = {\n __proto__: null,\n ...config,\n } as Partial<ShimmerConfig>\n\n if (this.#shimmer) {\n // Update existing shimmer.\n this.#shimmer = {\n ...this.#shimmer,\n ...(partialConfig.color !== undefined\n ? { color: partialConfig.color }\n : {}),\n ...(partialConfig.dir !== undefined\n ? { mode: partialConfig.dir }\n : {}),\n ...(partialConfig.speed !== undefined\n ? { speed: partialConfig.speed }\n : {}),\n } as ShimmerInfo\n this.#shimmerSavedConfig = this.#shimmer\n } else if (this.#shimmerSavedConfig) {\n // Restore and update.\n this.#shimmer = {\n ...this.#shimmerSavedConfig,\n ...(partialConfig.color !== undefined\n ? { color: partialConfig.color }\n : {}),\n ...(partialConfig.dir !== undefined\n ? { mode: partialConfig.dir }\n : {}),\n ...(partialConfig.speed !== undefined\n ? { speed: partialConfig.speed }\n : {}),\n } as ShimmerInfo\n this.#shimmerSavedConfig = this.#shimmer\n } else {\n // Create new with partial config.\n this.#shimmer = {\n color: partialConfig.color ?? COLOR_INHERIT,\n currentDir: DIR_LTR,\n mode: partialConfig.dir ?? DIR_LTR,\n speed: partialConfig.speed ?? 1 / 3,\n step: 0,\n } as ShimmerInfo\n this.#shimmerSavedConfig = this.#shimmer\n }\n\n this.#updateSpinnerText()\n return this as unknown as Spinner\n }\n } as unknown as {\n new (options?: SpinnerOptions | undefined): Spinner\n }\n // Add aliases.\n Object.defineProperties(_Spinner.prototype, {\n error: desc(_Spinner.prototype.fail),\n errorAndStop: desc(_Spinner.prototype.failAndStop),\n warning: desc(_Spinner.prototype.warn),\n warningAndStop: desc(_Spinner.prototype.warnAndStop),\n })\n _defaultSpinner = getCI()\n ? ciSpinner\n : (getCliSpinners('socket') as SpinnerStyle)\n }\n return new _Spinner({\n spinner: _defaultSpinner,\n ...options,\n })\n}\n\nlet _spinner: ReturnType<typeof Spinner> | undefined\n\n/**\n * Get the default spinner instance.\n * Lazily creates the spinner to avoid circular dependencies during module initialization.\n * Reuses the same instance across calls.\n *\n * @returns Shared default spinner instance\n *\n * @example\n * ```ts\n * import { getDefaultSpinner } from '@socketsecurity/lib/spinner'\n *\n * const spinner = getDefaultSpinner()\n * spinner.start('Loading\u2026')\n * ```\n */\nexport function getDefaultSpinner(): ReturnType<typeof Spinner> {\n if (_spinner === undefined) {\n _spinner = Spinner()\n }\n return _spinner\n}\n\n// REMOVED: Deprecated `spinner` export\n// Migration: Use getDefaultSpinner() instead\n// See: getDefaultSpinner() function above\n\n/**\n * Configuration options for `withSpinner()` helper.\n * @template T - Return type of the async operation\n */\nexport type WithSpinnerOptions<T> = {\n /** Message to display while the spinner is running */\n message: string\n /** Async function to execute while spinner is active */\n operation: () => Promise<T>\n /**\n * Optional spinner instance to use.\n * If not provided, operation runs without spinner.\n */\n spinner?: Spinner | undefined\n /**\n * Optional spinner options to apply during the operation.\n * These options will be pushed when the operation starts and popped when it completes.\n * Supports color and shimmer configuration.\n */\n withOptions?: Partial<Pick<SpinnerOptions, 'color' | 'shimmer'>> | undefined\n}\n\n/**\n * Execute an async operation with spinner lifecycle management.\n * Ensures `spinner.stop()` is always called via try/finally, even if the operation throws.\n * Provides safe cleanup and consistent spinner behavior.\n *\n * @template T - Return type of the operation\n * @param options - Configuration object\n * @param options.message - Message to display while spinner is running\n * @param options.operation - Async function to execute\n * @param options.spinner - Optional spinner instance (if not provided, no spinner is used)\n * @returns Result of the operation\n * @throws Re-throws any error from operation after stopping spinner\n *\n * @example\n * ```ts\n * import { Spinner, withSpinner } from '@socketsecurity/lib/spinner'\n *\n * const spinner = Spinner()\n *\n * // With spinner instance\n * const result = await withSpinner({\n * message: 'Processing\u2026',\n * operation: async () => {\n * return await processData()\n * },\n * spinner\n * })\n *\n * // Without spinner instance (no-op, just runs operation)\n * const result = await withSpinner({\n * message: 'Processing\u2026',\n * operation: async () => {\n * return await processData()\n * }\n * })\n * ```\n */\nexport async function withSpinner<T>(\n options: WithSpinnerOptions<T>,\n): Promise<T> {\n const { message, operation, spinner, withOptions } = {\n __proto__: null,\n ...options,\n } as WithSpinnerOptions<T>\n\n if (!spinner) {\n return await operation()\n }\n\n // Save current options if we're going to change them\n const savedColor =\n withOptions?.color !== undefined ? spinner.color : undefined\n const savedShimmerState =\n withOptions?.shimmer !== undefined ? spinner.shimmerState : undefined\n\n // Apply temporary options\n if (withOptions?.color !== undefined) {\n spinner.color = toRgb(withOptions.color)\n }\n if (withOptions?.shimmer !== undefined) {\n if (typeof withOptions.shimmer === 'string') {\n spinner.updateShimmer({ dir: withOptions.shimmer })\n } else {\n spinner.setShimmer(withOptions.shimmer)\n }\n }\n\n spinner.start(message)\n try {\n return await operation()\n } finally {\n spinner.stop()\n // Restore previous options\n if (savedColor !== undefined) {\n spinner.color = savedColor\n }\n if (withOptions?.shimmer !== undefined) {\n if (savedShimmerState) {\n spinner.setShimmer({\n color: savedShimmerState.color as any,\n dir: savedShimmerState.mode,\n speed: savedShimmerState.speed,\n })\n } else {\n spinner.disableShimmer()\n }\n }\n }\n}\n\n/**\n * Configuration options for `withSpinnerRestore()` helper.\n * @template T - Return type of the async operation\n */\nexport type WithSpinnerRestoreOptions<T> = {\n /** Async function to execute while spinner is stopped */\n operation: () => Promise<T>\n /** Optional spinner instance to restore after operation */\n spinner?: Spinner | undefined\n /** Whether spinner was spinning before the operation (used to conditionally restart) */\n wasSpinning: boolean\n}\n\n/**\n * Execute an async operation with conditional spinner restart.\n * Useful when you need to temporarily stop a spinner for an operation,\n * then restore it to its previous state (if it was spinning).\n *\n * @template T - Return type of the operation\n * @param options - Configuration object\n * @param options.operation - Async function to execute\n * @param options.spinner - Optional spinner instance to manage\n * @param options.wasSpinning - Whether spinner was spinning before the operation\n * @returns Result of the operation\n * @throws Re-throws any error from operation after restoring spinner state\n *\n * @example\n * ```ts\n * import { getDefaultSpinner, withSpinnerRestore } from '@socketsecurity/lib/spinner'\n *\n * const spinner = getDefaultSpinner()\n * const wasSpinning = spinner.isSpinning\n * spinner.stop()\n *\n * const result = await withSpinnerRestore({\n * operation: async () => {\n * // Do work without spinner\n * return await someOperation()\n * },\n * spinner,\n * wasSpinning\n * })\n * // Spinner is automatically restarted if wasSpinning was true\n * ```\n */\nexport async function withSpinnerRestore<T>(\n options: WithSpinnerRestoreOptions<T>,\n): Promise<T> {\n const { operation, spinner, wasSpinning } = {\n __proto__: null,\n ...options,\n } as WithSpinnerRestoreOptions<T>\n\n try {\n return await operation()\n } finally {\n if (spinner && wasSpinning) {\n spinner.start()\n }\n }\n}\n\n/**\n * Configuration options for `withSpinnerSync()` helper.\n * @template T - Return type of the sync operation\n */\nexport type WithSpinnerSyncOptions<T> = {\n /** Message to display while the spinner is running */\n message: string\n /** Synchronous function to execute while spinner is active */\n operation: () => T\n /**\n * Optional spinner instance to use.\n * If not provided, operation runs without spinner.\n */\n spinner?: Spinner | undefined\n /**\n * Optional spinner options to apply during the operation.\n * These options will be pushed when the operation starts and popped when it completes.\n * Supports color and shimmer configuration.\n */\n withOptions?: Partial<Pick<SpinnerOptions, 'color' | 'shimmer'>> | undefined\n}\n\n/**\n * Execute a synchronous operation with spinner lifecycle management.\n * Ensures `spinner.stop()` is always called via try/finally, even if the operation throws.\n * Provides safe cleanup and consistent spinner behavior for sync operations.\n *\n * @template T - Return type of the operation\n * @param options - Configuration object\n * @param options.message - Message to display while spinner is running\n * @param options.operation - Synchronous function to execute\n * @param options.spinner - Optional spinner instance (if not provided, no spinner is used)\n * @returns Result of the operation\n * @throws Re-throws any error from operation after stopping spinner\n *\n * @example\n * ```ts\n * import { Spinner, withSpinnerSync } from '@socketsecurity/lib/spinner'\n *\n * const spinner = Spinner()\n *\n * const result = withSpinnerSync({\n * message: 'Processing\u2026',\n * operation: () => {\n * return processDataSync()\n * },\n * spinner\n * })\n * ```\n */\nexport function withSpinnerSync<T>(options: WithSpinnerSyncOptions<T>): T {\n const { message, operation, spinner, withOptions } = {\n __proto__: null,\n ...options,\n } as WithSpinnerSyncOptions<T>\n\n if (!spinner) {\n return operation()\n }\n\n // Save current options if we're going to change them\n const savedColor =\n withOptions?.color !== undefined ? spinner.color : undefined\n const savedShimmerState =\n withOptions?.shimmer !== undefined ? spinner.shimmerState : undefined\n\n // Apply temporary options\n if (withOptions?.color !== undefined) {\n spinner.color = toRgb(withOptions.color)\n }\n if (withOptions?.shimmer !== undefined) {\n if (typeof withOptions.shimmer === 'string') {\n spinner.updateShimmer({ dir: withOptions.shimmer })\n } else {\n spinner.setShimmer(withOptions.shimmer)\n }\n }\n\n spinner.start(message)\n try {\n return operation()\n } finally {\n spinner.stop()\n // Restore previous options\n if (savedColor !== undefined) {\n spinner.color = savedColor\n }\n if (withOptions?.shimmer !== undefined) {\n if (savedShimmerState) {\n spinner.setShimmer({\n color: savedShimmerState.color as any,\n dir: savedShimmerState.mode,\n speed: savedShimmerState.speed,\n })\n } else {\n spinner.disableShimmer()\n }\n }\n }\n}\n"],
|
|
5
|
-
"mappings":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M,YAAY,KAAK;AAAA,EACzC;AACA,MAAI,aAAa,YAAY,QAAW;AACtC,QAAI,OAAO,YAAY,YAAY,UAAU;AAC3C,cAAQ,cAAc,EAAE,KAAK,YAAY,QAAQ,CAAC;AAAA,IACpD,OAAO;AACL,cAAQ,WAAW,YAAY,OAAO;AAAA,IACxC;AAAA,EACF;AAEA,UAAQ,MAAM,OAAO;AACrB,MAAI;AACF,WAAO,UAAU;AAAA,EACnB,UAAE;AACA,YAAQ,KAAK;AAEb,QAAI,eAAe,QAAW;AAC5B,cAAQ,QAAQ;AAAA,IAClB;AACA,QAAI,aAAa,YAAY,QAAW;AACtC,UAAI,mBAAmB;AACrB,gBAAQ,WAAW;AAAA,UACjB,OAAO,kBAAkB;AAAA,UACzB,KAAK,kBAAkB;AAAA,UACvB,OAAO,kBAAkB;AAAA,QAC3B,CAAC;AAAA,MACH,OAAO;AACL,gBAAQ,eAAe;AAAA,MACzB;AAAA,IACF;AAAA,EACF;AACF;",
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview CLI spinner utilities for long-running operations.\n * Provides animated progress indicators with CI environment detection.\n */\n\nimport type { Writable } from 'stream'\n\n// Note: getAbortSignal is imported lazily to avoid circular dependencies.\nimport { getCI } from '#env/ci'\nimport { generateSocketSpinnerFrames } from './effects/pulse-frames'\nimport type {\n ShimmerColorGradient,\n ShimmerConfig,\n ShimmerDirection,\n ShimmerState,\n} from './effects/text-shimmer'\nimport { applyShimmer, COLOR_INHERIT, DIR_LTR } from './effects/text-shimmer'\nimport yoctoSpinner from './external/@socketregistry/yocto-spinner'\nimport { hasOwn } from './objects'\nimport { isBlankString, stringWidth } from './strings'\nimport { getTheme } from './themes/context'\nimport { resolveColor } from './themes/utils'\n\n/**\n * Named color values supported by the spinner.\n * Maps to standard terminal colors with bright variants.\n */\nexport type ColorName =\n | 'black'\n | 'blue'\n | 'blueBright'\n | 'cyan'\n | 'cyanBright'\n | 'gray'\n | 'green'\n | 'greenBright'\n | 'magenta'\n | 'magentaBright'\n | 'red'\n | 'redBright'\n | 'white'\n | 'whiteBright'\n | 'yellow'\n | 'yellowBright'\n\n/**\n * Special 'inherit' color value that uses the spinner's current color.\n * Used with shimmer effects to dynamically inherit the spinner color.\n */\nexport type ColorInherit = 'inherit'\n\n/**\n * RGB color tuple with values 0-255 for red, green, and blue channels.\n * @example [140, 82, 255] // Socket purple\n * @example [255, 0, 0] // Red\n */\nexport type ColorRgb = readonly [number, number, number]\n\n/**\n * Union of all supported color types: named colors or RGB tuples.\n */\nexport type ColorValue = ColorName | ColorRgb\n\n/**\n * Symbol types for status messages.\n * Maps to log symbols: success (\u2713), fail (\u2717), info (\u2139), warn (\u26A0).\n */\nexport type SymbolType = 'fail' | 'info' | 'success' | 'warn'\n\n// Map color names to RGB values.\nconst colorToRgb: Record<ColorName, ColorRgb> = {\n __proto__: null,\n black: [0, 0, 0],\n blue: [0, 0, 255],\n blueBright: [100, 149, 237],\n cyan: [0, 255, 255],\n cyanBright: [0, 255, 255],\n gray: [128, 128, 128],\n green: [0, 128, 0],\n greenBright: [0, 255, 0],\n magenta: [255, 0, 255],\n magentaBright: [255, 105, 180],\n red: [255, 0, 0],\n redBright: [255, 69, 0],\n white: [255, 255, 255],\n whiteBright: [255, 255, 255],\n yellow: [255, 255, 0],\n yellowBright: [255, 255, 153],\n} as Record<ColorName, ColorRgb>\n\n/**\n * Type guard to check if a color value is an RGB tuple.\n * @param value - Color value to check\n * @returns `true` if value is an RGB tuple, `false` if it's a color name\n */\nfunction isRgbTuple(value: ColorValue): value is ColorRgb {\n return Array.isArray(value)\n}\n\n/**\n * Convert a color value to RGB tuple format.\n * Named colors are looked up in the `colorToRgb` map, RGB tuples are returned as-is.\n * @param color - Color name or RGB tuple\n * @returns RGB tuple with values 0-255\n */\nexport function toRgb(color: ColorValue): ColorRgb {\n if (isRgbTuple(color)) {\n return color\n }\n return colorToRgb[color]\n}\n\n/**\n * Progress tracking information for display in spinner.\n * Used by `progress()` and `progressStep()` methods to show animated progress bars.\n */\nexport type ProgressInfo = {\n /** Current progress value */\n current: number\n /** Total/maximum progress value */\n total: number\n /** Optional unit label displayed after the progress count (e.g., 'files', 'items') */\n unit?: string | undefined\n}\n\n/**\n * Internal shimmer state with color configuration.\n * Extends `ShimmerState` with additional color property that can be inherited from spinner.\n */\nexport type ShimmerInfo = ShimmerState & {\n /** Color for shimmer effect - can inherit from spinner, use explicit color, or gradient */\n color: ColorInherit | ColorValue | ShimmerColorGradient\n}\n\n/**\n * Spinner instance for displaying animated loading indicators.\n * Provides methods for status updates, progress tracking, and text shimmer effects.\n *\n * KEY BEHAVIORS:\n * - Methods WITHOUT \"AndStop\" keep the spinner running (e.g., `success()`, `fail()`)\n * - Methods WITH \"AndStop\" auto-clear the spinner line (e.g., `successAndStop()`, `failAndStop()`)\n * - Status messages (done, success, fail, info, warn, step, substep) go to stderr\n * - Data messages (`log()`) go to stdout\n *\n * @example\n * ```ts\n * import { Spinner } from '@socketsecurity/lib/spinner'\n *\n * const spinner = Spinner({ text: 'Loading\u2026' })\n * spinner.start()\n *\n * // Show success while continuing to spin\n * spinner.success('Step 1 complete')\n *\n * // Stop the spinner with success message\n * spinner.successAndStop('All done!')\n * ```\n */\nexport type Spinner = {\n /** Current spinner color as RGB tuple */\n color: ColorRgb\n /** Current spinner animation style */\n spinner: SpinnerStyle\n\n /** Whether spinner is currently animating */\n get isSpinning(): boolean\n\n /** Get current shimmer state (enabled/disabled and configuration) */\n get shimmerState(): ShimmerInfo | undefined\n\n /** Clear the current line without stopping the spinner */\n clear(): Spinner\n\n /** Show debug message without stopping (only if debug mode enabled) */\n debug(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Show debug message and stop the spinner (only if debug mode enabled) */\n debugAndStop(text?: string | undefined, ...extras: unknown[]): Spinner\n\n /** Alias for `fail()` - show error without stopping */\n error(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Alias for `failAndStop()` - show error and stop */\n errorAndStop(text?: string | undefined, ...extras: unknown[]): Spinner\n\n /** Show failure (\u2717) without stopping the spinner */\n fail(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Show failure (\u2717) and stop the spinner, auto-clearing the line */\n failAndStop(text?: string | undefined, ...extras: unknown[]): Spinner\n\n /** Get current spinner text (getter) or set new text (setter) */\n text(value: string): Spinner\n text(): string\n\n /** Increase indentation by specified spaces (default: 2) */\n indent(spaces?: number | undefined): Spinner\n /** Decrease indentation by specified spaces (default: 2) */\n dedent(spaces?: number | undefined): Spinner\n\n /** Show info (\u2139) message without stopping the spinner */\n info(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Show info (\u2139) message and stop the spinner, auto-clearing the line */\n infoAndStop(text?: string | undefined, ...extras: unknown[]): Spinner\n\n /** Log to stdout without stopping the spinner */\n log(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Log and stop the spinner, auto-clearing the line */\n logAndStop(text?: string | undefined, ...extras: unknown[]): Spinner\n\n /** Start spinning with optional text */\n start(text?: string | undefined): Spinner\n /** Stop spinning and clear internal state, auto-clearing the line */\n stop(text?: string | undefined): Spinner\n /** Stop and show final text without clearing the line */\n stopAndPersist(text?: string | undefined): Spinner\n\n /** Show main step message to stderr without stopping */\n step(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Show indented substep message to stderr without stopping */\n substep(text?: string | undefined, ...extras: unknown[]): Spinner\n\n /** Show success (\u2713) without stopping the spinner */\n success(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Show success (\u2713) and stop the spinner, auto-clearing the line */\n successAndStop(text?: string | undefined, ...extras: unknown[]): Spinner\n\n /** Alias for `success()` - show success without stopping */\n done(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Alias for `successAndStop()` - show success and stop */\n doneAndStop(text?: string | undefined, ...extras: unknown[]): Spinner\n\n /** Update progress bar with current/total values and optional unit */\n progress(current: number, total: number, unit?: string | undefined): Spinner\n /** Increment progress by specified amount (default: 1) */\n progressStep(amount?: number): Spinner\n\n /** Enable shimmer effect (restores saved config or uses defaults) */\n enableShimmer(): Spinner\n /** Disable shimmer effect (preserves config for later re-enable) */\n disableShimmer(): Spinner\n /** Set complete shimmer configuration */\n setShimmer(config: ShimmerConfig): Spinner\n /** Update partial shimmer configuration */\n updateShimmer(config: Partial<ShimmerConfig>): Spinner\n\n /** Show warning (\u26A0) without stopping the spinner */\n warn(text?: string | undefined, ...extras: unknown[]): Spinner\n /** Show warning (\u26A0) and stop the spinner, auto-clearing the line */\n warnAndStop(text?: string | undefined, ...extras: unknown[]): Spinner\n}\n\n/**\n * Configuration options for creating a spinner instance.\n */\nexport type SpinnerOptions = {\n /**\n * Spinner color as RGB tuple or color name.\n * @default [140, 82, 255] Socket purple\n */\n readonly color?: ColorValue | undefined\n /**\n * Shimmer effect configuration or direction string.\n * When enabled, text will have an animated shimmer effect.\n * @default undefined No shimmer effect\n */\n readonly shimmer?: ShimmerConfig | ShimmerDirection | undefined\n /**\n * Animation style with frames and timing.\n * @default 'socket' Custom Socket animation in CLI, minimal in CI\n */\n readonly spinner?: SpinnerStyle | undefined\n /**\n * Abort signal for cancelling the spinner.\n * @default getAbortSignal() from process constants\n */\n readonly signal?: AbortSignal | undefined\n /**\n * Output stream for spinner rendering.\n * @default process.stderr\n */\n readonly stream?: Writable | undefined\n /**\n * Initial text to display with the spinner.\n * @default undefined No initial text\n */\n readonly text?: string | undefined\n}\n\n/**\n * Animation style definition for spinner frames.\n * Defines the visual appearance and timing of the spinner animation.\n */\nexport type SpinnerStyle = {\n /** Array of animation frames (strings to display sequentially) */\n readonly frames: string[]\n /**\n * Milliseconds between frame changes.\n * @default 80 Standard frame rate\n */\n readonly interval?: number | undefined\n}\n\n/**\n * Minimal spinner style for CI environments.\n * Uses empty frame and max interval to effectively disable animation in CI.\n */\nexport const ciSpinner: SpinnerStyle = {\n frames: [''],\n interval: 2_147_483_647,\n}\n\n/**\n * Create a property descriptor for defining non-enumerable properties.\n * Used for adding aliased methods to the Spinner prototype.\n * @param value - Value for the property\n * @returns Property descriptor object\n * @private\n */\nfunction desc(value: unknown) {\n return {\n __proto__: null,\n configurable: true,\n value,\n writable: true,\n }\n}\n\n/**\n * Normalize text input by trimming leading whitespace.\n * Non-string values are converted to empty string.\n * @param value - Text to normalize\n * @returns Normalized string with leading whitespace removed\n * @private\n */\nfunction normalizeText(value: unknown) {\n return typeof value === 'string' ? value.trimStart() : ''\n}\n\n/**\n * Format progress information as a visual progress bar with percentage and count.\n * @param progress - Progress tracking information\n * @returns Formatted string with colored progress bar, percentage, and count\n * @private\n * @example \"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 35% (7/20 files)\"\n */\nfunction formatProgress(progress: ProgressInfo): string {\n const { current, total, unit } = progress\n const percentage = Math.round((current / total) * 100)\n const bar = renderProgressBar(percentage)\n const count = unit ? `${current}/${total} ${unit}` : `${current}/${total}`\n return `${bar} ${percentage}% (${count})`\n}\n\n/**\n * Render a progress bar using block characters (\u2588 for filled, \u2591 for empty).\n * @param percentage - Progress percentage (0-100)\n * @param width - Total width of progress bar in characters\n * @returns Colored progress bar string\n * @default width=20\n * @private\n */\nfunction renderProgressBar(percentage: number, width: number = 20): string {\n const filled = Math.round((percentage / 100) * width)\n const empty = width - filled\n const bar = '\u2588'.repeat(filled) + '\u2591'.repeat(empty)\n // Use cyan color for the progress bar\n const colors =\n /*@__PURE__*/ require('./external/yoctocolors-cjs') as typeof import('yoctocolors-cjs')\n return colors.cyan(bar)\n}\n\nlet _cliSpinners: Record<string, SpinnerStyle> | undefined\n\n/**\n * Get available CLI spinner styles or a specific style by name.\n * Extends the standard cli-spinners collection with Socket custom spinners.\n *\n * Custom spinners:\n * - `socket` (default): Socket pulse animation with sparkles and lightning\n *\n * @param styleName - Optional name of specific spinner style to retrieve\n * @returns Specific spinner style if name provided, all styles if omitted, `undefined` if style not found\n * @see https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json\n *\n * @example\n * ```ts\n * // Get all available spinner styles\n * const allSpinners = getCliSpinners()\n *\n * // Get specific style\n * const socketStyle = getCliSpinners('socket')\n * const dotsStyle = getCliSpinners('dots')\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function getCliSpinners(\n styleName?: string | undefined,\n): SpinnerStyle | Record<string, SpinnerStyle> | undefined {\n if (_cliSpinners === undefined) {\n const YoctoCtor: any = yoctoSpinner as any\n // Get the YoctoSpinner class to access static properties.\n const tempInstance: any = YoctoCtor({})\n const YoctoSpinnerClass: any = tempInstance.constructor as any\n // Extend the standard cli-spinners collection with Socket custom spinners.\n _cliSpinners = {\n __proto__: null,\n ...YoctoSpinnerClass.spinners,\n socket: generateSocketSpinnerFrames(),\n }\n }\n if (typeof styleName === 'string' && _cliSpinners) {\n return hasOwn(_cliSpinners, styleName) ? _cliSpinners[styleName] : undefined\n }\n return _cliSpinners\n}\n\nlet _Spinner: {\n new (options?: SpinnerOptions | undefined): Spinner\n}\nlet _defaultSpinner: SpinnerStyle | undefined\n\n/**\n * Create a spinner instance for displaying loading indicators.\n * Provides an animated CLI spinner with status messages, progress tracking, and shimmer effects.\n *\n * AUTO-CLEAR BEHAVIOR:\n * - All *AndStop() methods AUTO-CLEAR the spinner line via yocto-spinner.stop()\n * Examples: `doneAndStop()`, `successAndStop()`, `failAndStop()`, etc.\n *\n * - Methods WITHOUT \"AndStop\" do NOT clear (spinner keeps spinning)\n * Examples: `done()`, `success()`, `fail()`, etc.\n *\n * STREAM USAGE:\n * - Spinner animation: stderr (yocto-spinner default)\n * - Status methods (done, success, fail, info, warn, step, substep): stderr\n * - Data methods (`log()`): stdout\n *\n * COMPARISON WITH LOGGER:\n * - `logger.done()` does NOT auto-clear (requires manual `logger.clearLine()`)\n * - `spinner.doneAndStop()` DOES auto-clear (built into yocto-spinner.stop())\n * - Pattern: `logger.clearLine().done()` vs `spinner.doneAndStop()`\n *\n * @param options - Configuration options for the spinner\n * @returns New spinner instance\n *\n * @example\n * ```ts\n * import { Spinner } from '@socketsecurity/lib/spinner'\n *\n * // Basic usage\n * const spinner = Spinner({ text: 'Loading data\u2026' })\n * spinner.start()\n * await fetchData()\n * spinner.successAndStop('Data loaded!')\n *\n * // With custom color\n * const spinner = Spinner({\n * text: 'Processing\u2026',\n * color: [255, 0, 0] // Red\n * })\n *\n * // With shimmer effect\n * const spinner = Spinner({\n * text: 'Building\u2026',\n * shimmer: { dir: 'ltr', speed: 0.5 }\n * })\n *\n * // Show progress\n * spinner.progress(5, 10, 'files')\n * spinner.progressStep() // Increment by 1\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function Spinner(options?: SpinnerOptions | undefined): Spinner {\n if (_Spinner === undefined) {\n const YoctoCtor = yoctoSpinner as any\n // Get the actual YoctoSpinner class from an instance\n const tempInstance = YoctoCtor({})\n const YoctoSpinnerClass = tempInstance.constructor\n\n /*@__PURE__*/\n _Spinner = class SpinnerClass extends (YoctoSpinnerClass as any) {\n declare isSpinning: boolean\n #baseText: string = ''\n #indentation: string = ''\n #progress?: ProgressInfo | undefined\n #shimmer?: ShimmerInfo | undefined\n #shimmerSavedConfig?: ShimmerInfo | undefined\n\n constructor(options?: SpinnerOptions | undefined) {\n const opts = { __proto__: null, ...options } as SpinnerOptions\n\n // Get default color from theme if not specified\n const theme = getTheme()\n let defaultColor: ColorValue = theme.colors.primary\n if (theme.effects?.spinner?.color) {\n const resolved = resolveColor(\n theme.effects.spinner.color,\n theme.colors,\n )\n // resolveColor can return 'inherit' or gradients which aren't valid for spinner\n // Fall back to primary for these cases\n if (resolved === 'inherit' || Array.isArray(resolved[0])) {\n defaultColor = theme.colors.primary\n } else {\n defaultColor = resolved as ColorValue\n }\n }\n\n // Convert color option to RGB (default from theme).\n const spinnerColor = opts.color ?? defaultColor\n\n // Validate RGB tuple if provided.\n if (\n isRgbTuple(spinnerColor) &&\n (spinnerColor.length !== 3 ||\n !spinnerColor.every(\n n => typeof n === 'number' && n >= 0 && n <= 255,\n ))\n ) {\n throw new TypeError(\n 'RGB color must be an array of 3 numbers between 0 and 255',\n )\n }\n\n const spinnerColorRgb = toRgb(spinnerColor)\n\n // Parse shimmer config - can be object or direction string.\n let shimmerInfo: ShimmerInfo | undefined\n if (opts.shimmer) {\n let shimmerDir: ShimmerDirection\n let shimmerColor:\n | ColorInherit\n | ColorValue\n | ShimmerColorGradient\n | undefined\n // Default: 0.33 steps per frame (~150ms per step).\n let shimmerSpeed: number = 1 / 3\n\n if (typeof opts.shimmer === 'string') {\n shimmerDir = opts.shimmer\n } else {\n const shimmerConfig = {\n __proto__: null,\n ...opts.shimmer,\n } as ShimmerConfig\n shimmerDir = shimmerConfig.dir ?? DIR_LTR\n shimmerColor = shimmerConfig.color ?? COLOR_INHERIT\n shimmerSpeed = shimmerConfig.speed ?? 1 / 3\n }\n\n // Create shimmer info with initial animation state:\n // - COLOR_INHERIT means use spinner color dynamically\n // - ColorValue (name or RGB tuple) is an explicit override color\n // - undefined color defaults to COLOR_INHERIT\n // - speed controls steps per frame (lower = slower, e.g., 0.33 = ~150ms per step)\n shimmerInfo = {\n __proto__: null,\n color: shimmerColor === undefined ? COLOR_INHERIT : shimmerColor,\n currentDir: DIR_LTR,\n mode: shimmerDir,\n speed: shimmerSpeed,\n step: 0,\n } as ShimmerInfo\n }\n\n // eslint-disable-next-line constructor-super\n super({\n signal: require('#constants/process').getAbortSignal(),\n ...opts,\n // Pass RGB color directly to yocto-spinner (it now supports RGB).\n color: spinnerColorRgb,\n // onRenderFrame callback provides full control over frame + text layout.\n // Calculates spacing based on frame width to prevent text jumping.\n onRenderFrame: (\n frame: string,\n text: string,\n applyColor: (text: string) => string,\n ) => {\n const width = stringWidth(frame)\n // Narrow frames (width 1) get 2 spaces, wide frames (width 2) get 1 space.\n // Total width is consistent: 3 characters (frame + spacing) before text.\n const spacing = width === 1 ? ' ' : ' '\n return frame ? `${applyColor(frame)}${spacing}${text}` : text\n },\n // onFrameUpdate callback is called by yocto-spinner whenever a frame advances.\n // This ensures shimmer updates are perfectly synchronized with animation beats.\n onFrameUpdate: shimmerInfo\n ? () => {\n // Update parent's text without triggering render.\n // Parent's #skipRender flag prevents nested render calls.\n // Only update if we have base text to avoid blank frames.\n if (this.#baseText) {\n super.text = this.#buildDisplayText()\n }\n }\n : undefined,\n })\n\n this.#shimmer = shimmerInfo\n this.#shimmerSavedConfig = shimmerInfo\n }\n\n // Override color getter to ensure it's always RGB.\n get color(): ColorRgb {\n const value = super.color\n return isRgbTuple(value) ? value : toRgb(value)\n }\n\n // Override color setter to always convert to RGB before passing to yocto-spinner.\n set color(value: ColorValue | ColorRgb) {\n super.color = isRgbTuple(value) ? value : toRgb(value)\n }\n\n // Getter to expose current shimmer state.\n get shimmerState(): ShimmerInfo | undefined {\n if (!this.#shimmer) {\n return undefined\n }\n return {\n color: this.#shimmer.color,\n currentDir: this.#shimmer.currentDir,\n mode: this.#shimmer.mode,\n speed: this.#shimmer.speed,\n step: this.#shimmer.step,\n } as ShimmerInfo\n }\n\n /**\n * Apply a yocto-spinner method and update logger state.\n * Handles text normalization, extra arguments, and logger tracking.\n * @private\n */\n #apply(methodName: string, args: unknown[]) {\n let extras: unknown[]\n let text = args.at(0)\n if (typeof text === 'string') {\n extras = args.slice(1)\n } else {\n extras = args\n text = ''\n }\n const wasSpinning = this.isSpinning\n const normalized = normalizeText(text)\n if (methodName === 'stop' && !normalized) {\n super[methodName]()\n } else {\n super[methodName](normalized)\n }\n const {\n getDefaultLogger,\n incLogCallCountSymbol,\n lastWasBlankSymbol,\n } = /*@__PURE__*/ require('./logger.js')\n const logger = getDefaultLogger()\n if (methodName === 'stop') {\n if (wasSpinning && normalized) {\n logger[lastWasBlankSymbol](isBlankString(normalized))\n logger[incLogCallCountSymbol]()\n }\n } else {\n logger[lastWasBlankSymbol](false)\n logger[incLogCallCountSymbol]()\n }\n if (extras.length) {\n logger.log(...extras)\n logger[lastWasBlankSymbol](false)\n }\n return this\n }\n\n /**\n * Build the complete display text with progress, shimmer, and indentation.\n * Combines base text, progress bar, shimmer effects, and indentation.\n * @private\n */\n #buildDisplayText() {\n let displayText = this.#baseText\n\n if (this.#progress) {\n const progressText = formatProgress(this.#progress)\n displayText = displayText\n ? `${displayText} ${progressText}`\n : progressText\n }\n\n // Apply shimmer effect if enabled.\n if (displayText && this.#shimmer) {\n // If shimmer color is 'inherit', use current spinner color (getter ensures RGB).\n // Otherwise, check if it's a gradient (array of arrays) or single color.\n let shimmerColor: ColorRgb | ShimmerColorGradient\n if (this.#shimmer.color === COLOR_INHERIT) {\n shimmerColor = this.color\n } else if (Array.isArray(this.#shimmer.color[0])) {\n // It's a gradient - use as is.\n shimmerColor = this.#shimmer.color as ShimmerColorGradient\n } else {\n // It's a single color - convert to RGB.\n shimmerColor = toRgb(this.#shimmer.color as ColorValue)\n }\n\n displayText = applyShimmer(displayText, this.#shimmer, {\n color: shimmerColor,\n direction: this.#shimmer.mode,\n })\n }\n\n // Apply indentation\n if (this.#indentation && displayText) {\n displayText = this.#indentation + displayText\n }\n\n return displayText\n }\n\n /**\n * Show a status message without stopping the spinner.\n * Outputs the symbol and message to stderr, then continues spinning.\n */\n #showStatusAndKeepSpinning(symbolType: SymbolType, args: unknown[]) {\n let text = args.at(0)\n let extras: unknown[]\n if (typeof text === 'string') {\n extras = args.slice(1)\n } else {\n extras = args\n text = ''\n }\n\n const {\n LOG_SYMBOLS,\n getDefaultLogger,\n } = /*@__PURE__*/ require('./logger.js')\n // Note: Status messages always go to stderr.\n const logger = getDefaultLogger()\n logger.error(`${LOG_SYMBOLS[symbolType]} ${text}`, ...extras)\n return this\n }\n\n /**\n * Update the spinner's displayed text.\n * Rebuilds display text and triggers render.\n * @private\n */\n #updateSpinnerText() {\n // Call the parent class's text setter, which triggers render.\n super.text = this.#buildDisplayText()\n }\n\n /**\n * Show a debug message (\u2139) without stopping the spinner.\n * Only displays if debug mode is enabled via environment variable.\n * Outputs to stderr and continues spinning.\n *\n * @param text - Debug message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n debug(text?: string | undefined, ...extras: unknown[]) {\n const { isDebug } = /*@__PURE__*/ require('./debug.js')\n if (isDebug()) {\n return this.#showStatusAndKeepSpinning('info', [text, ...extras])\n }\n return this\n }\n\n /**\n * Show a debug message (\u2139) and stop the spinner.\n * Only displays if debug mode is enabled via environment variable.\n * Auto-clears the spinner line before displaying the message.\n *\n * @param text - Debug message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n debugAndStop(text?: string | undefined, ...extras: unknown[]) {\n const { isDebug } = /*@__PURE__*/ require('./debug.js')\n if (isDebug()) {\n return this.#apply('info', [text, ...extras])\n }\n return this\n }\n\n /**\n * Decrease indentation level by removing spaces from the left.\n * Pass 0 to reset indentation to zero completely.\n *\n * @param spaces - Number of spaces to remove\n * @returns This spinner for chaining\n * @default spaces=2\n *\n * @example\n * ```ts\n * spinner.dedent() // Remove 2 spaces\n * spinner.dedent(4) // Remove 4 spaces\n * spinner.dedent(0) // Reset to zero indentation\n * ```\n */\n dedent(spaces?: number | undefined) {\n // Pass 0 to reset indentation\n if (spaces === 0) {\n this.#indentation = ''\n } else {\n const amount = spaces ?? 2\n const newLength = Math.max(0, this.#indentation.length - amount)\n this.#indentation = this.#indentation.slice(0, newLength)\n }\n this.#updateSpinnerText()\n return this\n }\n\n /**\n * Show a done/success message (\u2713) without stopping the spinner.\n * Alias for `success()` with a shorter name.\n *\n * DESIGN DECISION: Unlike yocto-spinner, our `done()` does NOT stop the spinner.\n * Use `doneAndStop()` if you want to stop the spinner.\n *\n * @param text - Message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n done(text?: string | undefined, ...extras: unknown[]) {\n return this.#showStatusAndKeepSpinning('success', [text, ...extras])\n }\n\n /**\n * Show a done/success message (\u2713) and stop the spinner.\n * Auto-clears the spinner line before displaying the success message.\n *\n * @param text - Message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n doneAndStop(text?: string | undefined, ...extras: unknown[]) {\n return this.#apply('success', [text, ...extras])\n }\n\n /**\n * Show a failure message (\u2717) without stopping the spinner.\n * DESIGN DECISION: Unlike yocto-spinner, our `fail()` does NOT stop the spinner.\n * This allows displaying errors while continuing to spin.\n * Use `failAndStop()` if you want to stop the spinner.\n *\n * @param text - Error message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n fail(text?: string | undefined, ...extras: unknown[]) {\n return this.#showStatusAndKeepSpinning('fail', [text, ...extras])\n }\n\n /**\n * Show a failure message (\u2717) and stop the spinner.\n * Auto-clears the spinner line before displaying the error message.\n *\n * @param text - Error message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n failAndStop(text?: string | undefined, ...extras: unknown[]) {\n return this.#apply('error', [text, ...extras])\n }\n\n /**\n * Increase indentation level by adding spaces to the left.\n * Pass 0 to reset indentation to zero completely.\n *\n * @param spaces - Number of spaces to add\n * @returns This spinner for chaining\n * @default spaces=2\n *\n * @example\n * ```ts\n * spinner.indent() // Add 2 spaces\n * spinner.indent(4) // Add 4 spaces\n * spinner.indent(0) // Reset to zero indentation\n * ```\n */\n indent(spaces?: number | undefined) {\n // Pass 0 to reset indentation\n if (spaces === 0) {\n this.#indentation = ''\n } else {\n const amount = spaces ?? 2\n this.#indentation += ' '.repeat(amount)\n }\n this.#updateSpinnerText()\n return this\n }\n\n /**\n * Show an info message (\u2139) without stopping the spinner.\n * Outputs to stderr and continues spinning.\n *\n * @param text - Info message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n info(text?: string | undefined, ...extras: unknown[]) {\n return this.#showStatusAndKeepSpinning('info', [text, ...extras])\n }\n\n /**\n * Show an info message (\u2139) and stop the spinner.\n * Auto-clears the spinner line before displaying the message.\n *\n * @param text - Info message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n infoAndStop(text?: string | undefined, ...extras: unknown[]) {\n return this.#apply('info', [text, ...extras])\n }\n\n /**\n * Log a message to stdout without stopping the spinner.\n * Unlike other status methods, this outputs to stdout for data logging.\n *\n * @param args - Values to log to stdout\n * @returns This spinner for chaining\n */\n log(...args: unknown[]) {\n const { getDefaultLogger } = /*@__PURE__*/ require('./logger.js')\n const logger = getDefaultLogger()\n logger.log(...args)\n return this\n }\n\n /**\n * Log a message to stdout and stop the spinner.\n * Auto-clears the spinner line before displaying the message.\n *\n * @param text - Message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n logAndStop(text?: string | undefined, ...extras: unknown[]) {\n return this.#apply('stop', [text, ...extras])\n }\n\n /**\n * Update progress information displayed with the spinner.\n * Shows a progress bar with percentage and optional unit label.\n *\n * @param current - Current progress value\n * @param total - Total/maximum progress value\n * @param unit - Optional unit label (e.g., 'files', 'items')\n * @returns This spinner for chaining\n *\n * @example\n * ```ts\n * spinner.progress(5, 10) // \"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 50% (5/10)\"\n * spinner.progress(7, 20, 'files') // \"\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 35% (7/20 files)\"\n * ```\n */\n progress = (\n current: number,\n total: number,\n unit?: string | undefined,\n ) => {\n this.#progress = {\n __proto__: null,\n current,\n total,\n ...(unit ? { unit } : {}),\n } as ProgressInfo\n this.#updateSpinnerText()\n return this\n }\n\n /**\n * Increment progress by a specified amount.\n * Updates the progress bar displayed with the spinner.\n * Clamps the result between 0 and the total value.\n *\n * @param amount - Amount to increment by\n * @returns This spinner for chaining\n * @default amount=1\n *\n * @example\n * ```ts\n * spinner.progress(0, 10, 'files')\n * spinner.progressStep() // Progress: 1/10\n * spinner.progressStep(3) // Progress: 4/10\n * ```\n */\n progressStep(amount: number = 1) {\n if (this.#progress) {\n const newCurrent = this.#progress.current + amount\n this.#progress = {\n __proto__: null,\n current: Math.max(0, Math.min(newCurrent, this.#progress.total)),\n total: this.#progress.total,\n ...(this.#progress.unit ? { unit: this.#progress.unit } : {}),\n } as ProgressInfo\n this.#updateSpinnerText()\n }\n return this\n }\n\n /**\n * Start the spinner animation with optional text.\n * Begins displaying the animated spinner on stderr.\n *\n * @param text - Optional text to display with the spinner\n * @returns This spinner for chaining\n *\n * @example\n * ```ts\n * spinner.start('Loading\u2026')\n * // Later:\n * spinner.successAndStop('Done!')\n * ```\n */\n start(...args: unknown[]) {\n if (args.length) {\n const text = args.at(0)\n const normalized = normalizeText(text)\n // We clear this.text on start when `text` is falsy because yocto-spinner\n // will not clear it otherwise.\n if (!normalized) {\n this.#baseText = ''\n super.text = ''\n } else {\n this.#baseText = normalized\n }\n }\n\n this.#updateSpinnerText()\n // Don't pass text to yocto-spinner.start() since we already set it via #updateSpinnerText().\n // Passing args would cause duplicate message output.\n return this.#apply('start', [])\n }\n\n /**\n * Log a main step message to stderr without stopping the spinner.\n * Adds a blank line before the message for visual separation.\n * Aligns with `logger.step()` to use stderr for status messages.\n *\n * @param text - Step message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n *\n * @example\n * ```ts\n * spinner.step('Building application')\n * spinner.substep('Compiling TypeScript')\n * spinner.substep('Bundling assets')\n * ```\n */\n step(text?: string | undefined, ...extras: unknown[]) {\n const { getDefaultLogger } = /*@__PURE__*/ require('./logger.js')\n if (typeof text === 'string') {\n const logger = getDefaultLogger()\n // Add blank line before step for visual separation.\n logger.error('')\n // Use error (stderr) to align with logger.step() default stream.\n logger.error(text, ...extras)\n }\n return this\n }\n\n /**\n * Log an indented substep message to stderr without stopping the spinner.\n * Adds 2-space indentation to the message.\n * Aligns with `logger.substep()` to use stderr for status messages.\n *\n * @param text - Substep message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n *\n * @example\n * ```ts\n * spinner.step('Building application')\n * spinner.substep('Compiling TypeScript')\n * spinner.substep('Bundling assets')\n * ```\n */\n substep(text?: string | undefined, ...extras: unknown[]) {\n if (typeof text === 'string') {\n // Add 2-space indent for substep.\n const { getDefaultLogger } = /*@__PURE__*/ require('./logger.js')\n const logger = getDefaultLogger()\n // Use error (stderr) to align with logger.substep() default stream.\n logger.error(` ${text}`, ...extras)\n }\n return this\n }\n\n /**\n * Stop the spinner animation and clear internal state.\n * Auto-clears the spinner line via yocto-spinner.stop().\n * Resets progress, shimmer, and text state.\n *\n * @param text - Optional final text to display after stopping\n * @returns This spinner for chaining\n *\n * @example\n * ```ts\n * spinner.start('Processing\u2026')\n * // Do work\n * spinner.stop() // Just stop, no message\n * // or\n * spinner.stop('Finished processing')\n * ```\n */\n stop(...args: unknown[]) {\n // Clear internal state.\n this.#baseText = ''\n this.#progress = undefined\n // Reset shimmer animation state if shimmer is enabled.\n if (this.#shimmer) {\n this.#shimmer.currentDir = DIR_LTR\n this.#shimmer.step = 0\n }\n // Call parent stop first (clears screen, sets isSpinning = false).\n const result = this.#apply('stop', args)\n // Then clear text to avoid blank frame render.\n // This is safe now because isSpinning is false.\n super.text = ''\n return result\n }\n\n /**\n * Show a success message (\u2713) without stopping the spinner.\n * DESIGN DECISION: Unlike yocto-spinner, our `success()` does NOT stop the spinner.\n * This allows displaying success messages while continuing to spin for multi-step operations.\n * Use `successAndStop()` if you want to stop the spinner.\n *\n * @param text - Success message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n success(text?: string | undefined, ...extras: unknown[]) {\n return this.#showStatusAndKeepSpinning('success', [text, ...extras])\n }\n\n /**\n * Show a success message (\u2713) and stop the spinner.\n * Auto-clears the spinner line before displaying the success message.\n *\n * @param text - Success message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n successAndStop(text?: string | undefined, ...extras: unknown[]) {\n return this.#apply('success', [text, ...extras])\n }\n\n /**\n * Get or set the spinner text.\n * When called with no arguments, returns the current base text.\n * When called with text, updates the display and returns the spinner for chaining.\n *\n * @param value - Text to display (omit to get current text)\n * @returns Current text (getter) or this spinner (setter)\n *\n * @example\n * ```ts\n * // Setter\n * spinner.text('Loading data\u2026')\n * spinner.text('Processing\u2026')\n *\n * // Getter\n * const current = spinner.text()\n * console.log(current) // \"Processing\u2026\"\n * ```\n */\n text(): string\n text(value: string): Spinner\n text(value?: string): string | Spinner {\n // biome-ignore lint/complexity/noArguments: Function overload for getter/setter pattern.\n if (arguments.length === 0) {\n // Getter: return current base text\n return this.#baseText\n }\n // Setter: update base text and refresh display\n this.#baseText = value ?? ''\n this.#updateSpinnerText()\n return this as unknown as Spinner\n }\n\n /**\n * Show a warning message (\u26A0) without stopping the spinner.\n * Outputs to stderr and continues spinning.\n *\n * @param text - Warning message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n warn(text?: string | undefined, ...extras: unknown[]) {\n return this.#showStatusAndKeepSpinning('warn', [text, ...extras])\n }\n\n /**\n * Show a warning message (\u26A0) and stop the spinner.\n * Auto-clears the spinner line before displaying the warning message.\n *\n * @param text - Warning message to display\n * @param extras - Additional values to log\n * @returns This spinner for chaining\n */\n warnAndStop(text?: string | undefined, ...extras: unknown[]) {\n return this.#apply('warning', [text, ...extras])\n }\n\n /**\n * Enable shimmer effect.\n * Restores saved config or uses defaults if no saved config exists.\n *\n * @returns This spinner for chaining\n *\n * @example\n * spinner.enableShimmer()\n */\n enableShimmer(): Spinner {\n if (this.#shimmerSavedConfig) {\n // Restore saved config.\n this.#shimmer = { ...this.#shimmerSavedConfig }\n } else {\n // Create default config.\n this.#shimmer = {\n color: COLOR_INHERIT,\n currentDir: DIR_LTR,\n mode: DIR_LTR,\n speed: 1 / 3,\n step: 0,\n } as ShimmerInfo\n this.#shimmerSavedConfig = this.#shimmer\n }\n\n this.#updateSpinnerText()\n return this as unknown as Spinner\n }\n\n /**\n * Disable shimmer effect.\n * Preserves config for later re-enable via enableShimmer().\n *\n * @returns This spinner for chaining\n *\n * @example\n * spinner.disableShimmer()\n */\n disableShimmer(): Spinner {\n // Disable shimmer but preserve config.\n this.#shimmer = undefined\n this.#updateSpinnerText()\n return this as unknown as Spinner\n }\n\n /**\n * Set complete shimmer configuration.\n * Replaces any existing shimmer config with the provided values.\n *\n * @param config - Complete shimmer configuration\n * @returns This spinner for chaining\n *\n * @example\n * spinner.setShimmer({\n * color: [255, 0, 0],\n * dir: 'rtl',\n * speed: 0.5\n * })\n */\n setShimmer(config: ShimmerConfig): Spinner {\n this.#shimmer = {\n color: config.color,\n currentDir: DIR_LTR,\n mode: config.dir,\n speed: config.speed,\n step: 0,\n } as ShimmerInfo\n this.#shimmerSavedConfig = this.#shimmer\n this.#updateSpinnerText()\n return this as unknown as Spinner\n }\n\n /**\n * Update partial shimmer configuration.\n * Merges with existing config, enabling shimmer if currently disabled.\n *\n * @param config - Partial shimmer configuration to merge\n * @returns This spinner for chaining\n *\n * @example\n * // Update just the speed\n * spinner.updateShimmer({ speed: 0.5 })\n *\n * // Update direction\n * spinner.updateShimmer({ dir: 'rtl' })\n *\n * // Update multiple properties\n * spinner.updateShimmer({ color: [255, 0, 0], speed: 0.8 })\n */\n updateShimmer(config: Partial<ShimmerConfig>): Spinner {\n const partialConfig = {\n __proto__: null,\n ...config,\n } as Partial<ShimmerConfig>\n\n if (this.#shimmer) {\n // Update existing shimmer.\n this.#shimmer = {\n ...this.#shimmer,\n ...(partialConfig.color !== undefined\n ? { color: partialConfig.color }\n : {}),\n ...(partialConfig.dir !== undefined\n ? { mode: partialConfig.dir }\n : {}),\n ...(partialConfig.speed !== undefined\n ? { speed: partialConfig.speed }\n : {}),\n } as ShimmerInfo\n this.#shimmerSavedConfig = this.#shimmer\n } else if (this.#shimmerSavedConfig) {\n // Restore and update.\n this.#shimmer = {\n ...this.#shimmerSavedConfig,\n ...(partialConfig.color !== undefined\n ? { color: partialConfig.color }\n : {}),\n ...(partialConfig.dir !== undefined\n ? { mode: partialConfig.dir }\n : {}),\n ...(partialConfig.speed !== undefined\n ? { speed: partialConfig.speed }\n : {}),\n } as ShimmerInfo\n this.#shimmerSavedConfig = this.#shimmer\n } else {\n // Create new with partial config.\n this.#shimmer = {\n color: partialConfig.color ?? COLOR_INHERIT,\n currentDir: DIR_LTR,\n mode: partialConfig.dir ?? DIR_LTR,\n speed: partialConfig.speed ?? 1 / 3,\n step: 0,\n } as ShimmerInfo\n this.#shimmerSavedConfig = this.#shimmer\n }\n\n this.#updateSpinnerText()\n return this as unknown as Spinner\n }\n } as unknown as {\n new (options?: SpinnerOptions | undefined): Spinner\n }\n // Add aliases.\n Object.defineProperties(_Spinner.prototype, {\n error: desc(_Spinner.prototype.fail),\n errorAndStop: desc(_Spinner.prototype.failAndStop),\n warning: desc(_Spinner.prototype.warn),\n warningAndStop: desc(_Spinner.prototype.warnAndStop),\n })\n _defaultSpinner = getCI()\n ? ciSpinner\n : (getCliSpinners('socket') as SpinnerStyle)\n }\n return new _Spinner({\n spinner: _defaultSpinner,\n ...options,\n })\n}\n\nlet _spinner: ReturnType<typeof Spinner> | undefined\n\n/**\n * Get the default spinner instance.\n * Lazily creates the spinner to avoid circular dependencies during module initialization.\n * Reuses the same instance across calls.\n *\n * @returns Shared default spinner instance\n *\n * @example\n * ```ts\n * import { getDefaultSpinner } from '@socketsecurity/lib/spinner'\n *\n * const spinner = getDefaultSpinner()\n * spinner.start('Loading\u2026')\n * ```\n */\nexport function getDefaultSpinner(): ReturnType<typeof Spinner> {\n if (_spinner === undefined) {\n _spinner = Spinner()\n }\n return _spinner\n}\n\n// REMOVED: Deprecated `spinner` export\n// Migration: Use getDefaultSpinner() instead\n// See: getDefaultSpinner() function above\n\n/**\n * Configuration options for `withSpinner()` helper.\n * @template T - Return type of the async operation\n */\nexport type WithSpinnerOptions<T> = {\n /** Message to display while the spinner is running */\n message: string\n /** Async function to execute while spinner is active */\n operation: () => Promise<T>\n /**\n * Optional spinner instance to use.\n * If not provided, operation runs without spinner.\n */\n spinner?: Spinner | undefined\n /**\n * Optional spinner options to apply during the operation.\n * These options will be pushed when the operation starts and popped when it completes.\n * Supports color and shimmer configuration.\n */\n withOptions?: Partial<Pick<SpinnerOptions, 'color' | 'shimmer'>> | undefined\n}\n\n/**\n * Execute an async operation with spinner lifecycle management.\n * Ensures `spinner.stop()` is always called via try/finally, even if the operation throws.\n * Provides safe cleanup and consistent spinner behavior.\n *\n * @template T - Return type of the operation\n * @param options - Configuration object\n * @param options.message - Message to display while spinner is running\n * @param options.operation - Async function to execute\n * @param options.spinner - Optional spinner instance (if not provided, no spinner is used)\n * @returns Result of the operation\n * @throws Re-throws any error from operation after stopping spinner\n *\n * @example\n * ```ts\n * import { Spinner, withSpinner } from '@socketsecurity/lib/spinner'\n *\n * const spinner = Spinner()\n *\n * // With spinner instance\n * const result = await withSpinner({\n * message: 'Processing\u2026',\n * operation: async () => {\n * return await processData()\n * },\n * spinner\n * })\n *\n * // Without spinner instance (no-op, just runs operation)\n * const result = await withSpinner({\n * message: 'Processing\u2026',\n * operation: async () => {\n * return await processData()\n * }\n * })\n * ```\n */\nexport async function withSpinner<T>(\n options: WithSpinnerOptions<T>,\n): Promise<T> {\n const { message, operation, spinner, withOptions } = {\n __proto__: null,\n ...options,\n } as WithSpinnerOptions<T>\n\n if (!spinner) {\n return await operation()\n }\n\n // Save current options if we're going to change them\n const savedColor =\n withOptions?.color !== undefined ? spinner.color : undefined\n const savedShimmerState =\n withOptions?.shimmer !== undefined ? spinner.shimmerState : undefined\n\n // Apply temporary options\n if (withOptions?.color !== undefined) {\n spinner.color = toRgb(withOptions.color)\n }\n if (withOptions?.shimmer !== undefined) {\n if (typeof withOptions.shimmer === 'string') {\n spinner.updateShimmer({ dir: withOptions.shimmer })\n } else {\n spinner.setShimmer(withOptions.shimmer)\n }\n }\n\n spinner.start(message)\n try {\n return await operation()\n } finally {\n spinner.stop()\n // Restore previous options\n if (savedColor !== undefined) {\n spinner.color = savedColor\n }\n if (withOptions?.shimmer !== undefined) {\n if (savedShimmerState) {\n spinner.setShimmer({\n color: savedShimmerState.color as any,\n dir: savedShimmerState.mode,\n speed: savedShimmerState.speed,\n })\n } else {\n spinner.disableShimmer()\n }\n }\n }\n}\n\n/**\n * Configuration options for `withSpinnerRestore()` helper.\n * @template T - Return type of the async operation\n */\nexport type WithSpinnerRestoreOptions<T> = {\n /** Async function to execute while spinner is stopped */\n operation: () => Promise<T>\n /** Optional spinner instance to restore after operation */\n spinner?: Spinner | undefined\n /** Whether spinner was spinning before the operation (used to conditionally restart) */\n wasSpinning: boolean\n}\n\n/**\n * Execute an async operation with conditional spinner restart.\n * Useful when you need to temporarily stop a spinner for an operation,\n * then restore it to its previous state (if it was spinning).\n *\n * @template T - Return type of the operation\n * @param options - Configuration object\n * @param options.operation - Async function to execute\n * @param options.spinner - Optional spinner instance to manage\n * @param options.wasSpinning - Whether spinner was spinning before the operation\n * @returns Result of the operation\n * @throws Re-throws any error from operation after restoring spinner state\n *\n * @example\n * ```ts\n * import { getDefaultSpinner, withSpinnerRestore } from '@socketsecurity/lib/spinner'\n *\n * const spinner = getDefaultSpinner()\n * const wasSpinning = spinner.isSpinning\n * spinner.stop()\n *\n * const result = await withSpinnerRestore({\n * operation: async () => {\n * // Do work without spinner\n * return await someOperation()\n * },\n * spinner,\n * wasSpinning\n * })\n * // Spinner is automatically restarted if wasSpinning was true\n * ```\n */\nexport async function withSpinnerRestore<T>(\n options: WithSpinnerRestoreOptions<T>,\n): Promise<T> {\n const { operation, spinner, wasSpinning } = {\n __proto__: null,\n ...options,\n } as WithSpinnerRestoreOptions<T>\n\n try {\n return await operation()\n } finally {\n if (spinner && wasSpinning) {\n spinner.start()\n }\n }\n}\n\n/**\n * Configuration options for `withSpinnerSync()` helper.\n * @template T - Return type of the sync operation\n */\nexport type WithSpinnerSyncOptions<T> = {\n /** Message to display while the spinner is running */\n message: string\n /** Synchronous function to execute while spinner is active */\n operation: () => T\n /**\n * Optional spinner instance to use.\n * If not provided, operation runs without spinner.\n */\n spinner?: Spinner | undefined\n /**\n * Optional spinner options to apply during the operation.\n * These options will be pushed when the operation starts and popped when it completes.\n * Supports color and shimmer configuration.\n */\n withOptions?: Partial<Pick<SpinnerOptions, 'color' | 'shimmer'>> | undefined\n}\n\n/**\n * Execute a synchronous operation with spinner lifecycle management.\n * Ensures `spinner.stop()` is always called via try/finally, even if the operation throws.\n * Provides safe cleanup and consistent spinner behavior for sync operations.\n *\n * @template T - Return type of the operation\n * @param options - Configuration object\n * @param options.message - Message to display while spinner is running\n * @param options.operation - Synchronous function to execute\n * @param options.spinner - Optional spinner instance (if not provided, no spinner is used)\n * @returns Result of the operation\n * @throws Re-throws any error from operation after stopping spinner\n *\n * @example\n * ```ts\n * import { Spinner, withSpinnerSync } from '@socketsecurity/lib/spinner'\n *\n * const spinner = Spinner()\n *\n * const result = withSpinnerSync({\n * message: 'Processing\u2026',\n * operation: () => {\n * return processDataSync()\n * },\n * spinner\n * })\n * ```\n */\nexport function withSpinnerSync<T>(options: WithSpinnerSyncOptions<T>): T {\n const { message, operation, spinner, withOptions } = {\n __proto__: null,\n ...options,\n } as WithSpinnerSyncOptions<T>\n\n if (!spinner) {\n return operation()\n }\n\n // Save current options if we're going to change them\n const savedColor =\n withOptions?.color !== undefined ? spinner.color : undefined\n const savedShimmerState =\n withOptions?.shimmer !== undefined ? spinner.shimmerState : undefined\n\n // Apply temporary options\n if (withOptions?.color !== undefined) {\n spinner.color = toRgb(withOptions.color)\n }\n if (withOptions?.shimmer !== undefined) {\n if (typeof withOptions.shimmer === 'string') {\n spinner.updateShimmer({ dir: withOptions.shimmer })\n } else {\n spinner.setShimmer(withOptions.shimmer)\n }\n }\n\n spinner.start(message)\n try {\n return operation()\n } finally {\n spinner.stop()\n // Restore previous options\n if (savedColor !== undefined) {\n spinner.color = savedColor\n }\n if (withOptions?.shimmer !== undefined) {\n if (savedShimmerState) {\n spinner.setShimmer({\n color: savedShimmerState.color as any,\n dir: savedShimmerState.mode,\n speed: savedShimmerState.speed,\n })\n } else {\n spinner.disableShimmer()\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,gBAAsB;AACtB,0BAA4C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YAAY,QAAW;AACtC,QAAI,OAAO,YAAY,YAAY,UAAU;AAC3C,cAAQ,cAAc,EAAE,KAAK,YAAY,QAAQ,CAAC;AAAA,IACpD,OAAO;AACL,cAAQ,WAAW,YAAY,OAAO;AAAA,IACxC;AAAA,EACF;AAEA,UAAQ,MAAM,OAAO;AACrB,MAAI;AACF,WAAO,UAAU;AAAA,EACnB,UAAE;AACA,YAAQ,KAAK;AAEb,QAAI,eAAe,QAAW;AAC5B,cAAQ,QAAQ;AAAA,IAClB;AACA,QAAI,aAAa,YAAY,QAAW;AACtC,UAAI,mBAAmB;AACrB,gBAAQ,WAAW;AAAA,UACjB,OAAO,kBAAkB;AAAA,UACzB,KAAK,kBAAkB;AAAA,UACvB,OAAO,kBAAkB;AAAA,QAC3B,CAAC;AAAA,MACH,OAAO;AACL,gBAAQ,eAAe;AAAA,MACzB;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["yoctoSpinner", "options"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/themes/context.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview Elegant theme context management.\n * Async-aware theming with automatic context isolation via AsyncLocalStorage.\n */\n\nimport { AsyncLocalStorage } from 'node:async_hooks'\n\nimport type { Theme } from './types'\nimport { SOCKET_THEME, THEMES, type ThemeName } from './themes'\n\n/**\n * Theme change event listener signature.\n */\nexport type ThemeChangeListener = (theme: Theme) => void\n\n/**\n * AsyncLocalStorage for theme context isolation.\n */\nconst themeStorage = new AsyncLocalStorage<Theme>()\n\n/**\n * Fallback theme for global context.\n */\nlet fallbackTheme: Theme = SOCKET_THEME\n\n/**\n * Registered theme change listeners.\n */\nconst listeners: Set<ThemeChangeListener> = new Set()\n\n/**\n * Set the global fallback theme.\n *\n * @param theme - Theme name or object\n *\n * @example\n * ```ts\n * setTheme('socket-firewall')\n * ```\n */\nexport function setTheme(theme: Theme | ThemeName): void {\n fallbackTheme = typeof theme === 'string' ? THEMES[theme] : theme\n emitThemeChange(fallbackTheme)\n}\n\n/**\n * Get the active theme from context.\n *\n * @returns Current theme\n *\n * @example\n * ```ts\n * const theme = getTheme()\n * console.log(theme.displayName)\n * ```\n */\nexport function getTheme(): Theme {\n return themeStorage.getStore() ?? fallbackTheme\n}\n\n/**\n * Execute async operation with scoped theme.\n * Theme automatically restored on completion.\n *\n * @template T - Return type\n * @param theme - Scoped theme\n * @param fn - Async operation\n * @returns Operation result\n *\n * @example\n * ```ts\n * await withTheme('ultra', async () => {\n * // Operations use Ultra theme\n * })\n * ```\n */\nexport async function withTheme<T>(\n theme: Theme | ThemeName,\n fn: () => Promise<T>,\n): Promise<T> {\n const resolvedTheme = typeof theme === 'string' ? THEMES[theme] : theme\n return await themeStorage.run(resolvedTheme, async () => {\n emitThemeChange(resolvedTheme)\n return await fn()\n })\n}\n\n/**\n * Execute sync operation with scoped theme.\n * Theme automatically restored on completion.\n *\n * @template T - Return type\n * @param theme - Scoped theme\n * @param fn - Sync operation\n * @returns Operation result\n *\n * @example\n * ```ts\n * const result = withThemeSync('coana', () => {\n * return processData()\n * })\n * ```\n */\nexport function withThemeSync<T>(theme: Theme | ThemeName, fn: () => T): T {\n const resolvedTheme = typeof theme === 'string' ? THEMES[theme] : theme\n return themeStorage.run(resolvedTheme, () => {\n emitThemeChange(resolvedTheme)\n return fn()\n })\n}\n\n/**\n * Subscribe to theme change events.\n *\n * @param listener - Change handler\n * @returns Unsubscribe function\n *\n * @example\n * ```ts\n * const unsubscribe = onThemeChange((theme) => {\n * console.log('Theme:', theme.displayName)\n * })\n *\n * // Cleanup\n * unsubscribe()\n * ```\n */\nexport function onThemeChange(listener: ThemeChangeListener): () => void {\n listeners.add(listener)\n return () => {\n listeners.delete(listener)\n }\n}\n\n/**\n * Emit theme change event to listeners.\n * @private\n */\nfunction emitThemeChange(theme: Theme): void {\n for (const listener of listeners) {\n listener(theme)\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,8BAAkC;AAGlC,oBAAqD;AAUrD,MAAM,eAAe,IAAI,0CAAyB;AAKlD,IAAI,gBAAuB;AAK3B,MAAM,YAAsC,oBAAI,IAAI;AAY7C,SAAS,SAAS,OAAgC;AACvD,kBAAgB,OAAO,UAAU,WAAW,qBAAO,KAAK,IAAI;AAC5D,kBAAgB,aAAa;AAC/B;AAaO,SAAS,WAAkB;AAChC,SAAO,aAAa,SAAS,KAAK;AACpC;AAkBA,eAAsB,UACpB,OACA,IACY;AACZ,QAAM,
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview Elegant theme context management.\n * Async-aware theming with automatic context isolation via AsyncLocalStorage.\n */\n\nimport { AsyncLocalStorage } from 'node:async_hooks'\n\nimport type { Theme } from './types'\nimport { SOCKET_THEME, THEMES, type ThemeName } from './themes'\n\n/**\n * Theme change event listener signature.\n */\nexport type ThemeChangeListener = (theme: Theme) => void\n\n/**\n * AsyncLocalStorage for theme context isolation.\n */\nconst themeStorage = new AsyncLocalStorage<Theme>()\n\n/**\n * Fallback theme for global context.\n */\nlet fallbackTheme: Theme = SOCKET_THEME\n\n/**\n * Registered theme change listeners.\n */\nconst listeners: Set<ThemeChangeListener> = new Set()\n\n/**\n * Set the global fallback theme.\n *\n * @param theme - Theme name or object\n *\n * @example\n * ```ts\n * setTheme('socket-firewall')\n * ```\n */\nexport function setTheme(theme: Theme | ThemeName): void {\n fallbackTheme = typeof theme === 'string' ? THEMES[theme] : theme\n emitThemeChange(fallbackTheme)\n}\n\n/**\n * Get the active theme from context.\n *\n * @returns Current theme\n *\n * @example\n * ```ts\n * const theme = getTheme()\n * console.log(theme.displayName)\n * ```\n */\nexport function getTheme(): Theme {\n return themeStorage.getStore() ?? fallbackTheme\n}\n\n/**\n * Execute async operation with scoped theme.\n * Theme automatically restored on completion.\n *\n * @template T - Return type\n * @param theme - Scoped theme\n * @param fn - Async operation\n * @returns Operation result\n *\n * @example\n * ```ts\n * await withTheme('ultra', async () => {\n * // Operations use Ultra theme\n * })\n * ```\n */\nexport async function withTheme<T>(\n theme: Theme | ThemeName,\n fn: () => Promise<T>,\n): Promise<T> {\n const resolvedTheme: Theme = typeof theme === 'string' ? THEMES[theme] : theme\n return await themeStorage.run(resolvedTheme, async () => {\n emitThemeChange(resolvedTheme)\n return await fn()\n })\n}\n\n/**\n * Execute sync operation with scoped theme.\n * Theme automatically restored on completion.\n *\n * @template T - Return type\n * @param theme - Scoped theme\n * @param fn - Sync operation\n * @returns Operation result\n *\n * @example\n * ```ts\n * const result = withThemeSync('coana', () => {\n * return processData()\n * })\n * ```\n */\nexport function withThemeSync<T>(theme: Theme | ThemeName, fn: () => T): T {\n const resolvedTheme: Theme = typeof theme === 'string' ? THEMES[theme] : theme\n return themeStorage.run(resolvedTheme, () => {\n emitThemeChange(resolvedTheme)\n return fn()\n })\n}\n\n/**\n * Subscribe to theme change events.\n *\n * @param listener - Change handler\n * @returns Unsubscribe function\n *\n * @example\n * ```ts\n * const unsubscribe = onThemeChange((theme) => {\n * console.log('Theme:', theme.displayName)\n * })\n *\n * // Cleanup\n * unsubscribe()\n * ```\n */\nexport function onThemeChange(listener: ThemeChangeListener): () => void {\n listeners.add(listener)\n return () => {\n listeners.delete(listener)\n }\n}\n\n/**\n * Emit theme change event to listeners.\n * @private\n */\nfunction emitThemeChange(theme: Theme): void {\n for (const listener of listeners) {\n listener(theme)\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,8BAAkC;AAGlC,oBAAqD;AAUrD,MAAM,eAAe,IAAI,0CAAyB;AAKlD,IAAI,gBAAuB;AAK3B,MAAM,YAAsC,oBAAI,IAAI;AAY7C,SAAS,SAAS,OAAgC;AACvD,kBAAgB,OAAO,UAAU,WAAW,qBAAO,KAAK,IAAI;AAC5D,kBAAgB,aAAa;AAC/B;AAaO,SAAS,WAAkB;AAChC,SAAO,aAAa,SAAS,KAAK;AACpC;AAkBA,eAAsB,UACpB,OACA,IACY;AACZ,QAAM,gBAAuB,OAAO,UAAU,WAAW,qBAAO,KAAK,IAAI;AACzE,SAAO,MAAM,aAAa,IAAI,eAAe,YAAY;AACvD,oBAAgB,aAAa;AAC7B,WAAO,MAAM,GAAG;AAAA,EAClB,CAAC;AACH;AAkBO,SAAS,cAAiB,OAA0B,IAAgB;AACzE,QAAM,gBAAuB,OAAO,UAAU,WAAW,qBAAO,KAAK,IAAI;AACzE,SAAO,aAAa,IAAI,eAAe,MAAM;AAC3C,oBAAgB,aAAa;AAC7B,WAAO,GAAG;AAAA,EACZ,CAAC;AACH;AAkBO,SAAS,cAAc,UAA2C;AACvE,YAAU,IAAI,QAAQ;AACtB,SAAO,MAAM;AACX,cAAU,OAAO,QAAQ;AAAA,EAC3B;AACF;AAMA,SAAS,gBAAgB,OAAoB;AAC3C,aAAW,YAAY,WAAW;AAChC,aAAS,KAAK;AAAA,EAChB;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/themes/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* import { setTheme, THEMES } from '@socketsecurity/lib/themes'
|
|
8
8
|
*
|
|
9
9
|
* // Set global theme
|
|
10
|
-
* setTheme('
|
|
10
|
+
* setTheme('terracotta')
|
|
11
11
|
* ```
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
// Type system
|
|
47
47
|
export type { ColorReference, Theme, ThemeColors, ThemeEffects, ThemeMeta, } from './types';
|
|
48
48
|
// Curated themes
|
|
49
|
-
export {
|
|
49
|
+
export { LUSH_THEME, SOCKET_THEME, SUNSET_THEME, TERRACOTTA_THEME, THEMES, ULTRA_THEME, type ThemeName, } from './themes';
|
|
50
50
|
// Context management
|
|
51
51
|
export { getTheme, onThemeChange, setTheme, withTheme, withThemeSync, type ThemeChangeListener, } from './context';
|
|
52
52
|
// Composition utilities
|