{"version":3,"file":"recompose.cjs","names":["merge"],"sources":["../../../src/states/functions/recompose.ts"],"sourcesContent":["import { DEFAULT_DELIMITER } from '#constants';\nimport { merge } from '#utils';\nimport type { NodeConfig } from '../types';\n\ntype Url_F = <T>(shape: string, value: T) => any;\n\n/**\n * Recompose an object URL based on the provided shape and value.\n *\n * @param shape - The shape of the URL to recompose.\n * @param value - The value to recompose into the URL.\n * @returns A recomposed object URL.\n *\n * @see {@linkcode Url_F} for type details.\n * @see {@linkcode DEFAULT_DELIMITER} for the default delimiter used in the URL.\n */\nconst recomposeObjectUrl: Url_F = (shape, value) => {\n  const obj: any = {};\n  // eslint-disable-next-line @typescript-eslint/no-unused-vars\n  const { states, ...rest } = value as any;\n\n  if (shape === DEFAULT_DELIMITER) {\n    return rest;\n  }\n\n  const keys = shape.split(DEFAULT_DELIMITER).filter(str => str !== '');\n\n  obj.states = {};\n  if (keys.length === 1) {\n    const key = keys.shift()!;\n    obj.states[key] = value;\n  } else {\n    const key = keys.shift()!;\n    const _value = recomposeObjectUrl(keys.join(DEFAULT_DELIMITER), value);\n\n    obj.states[key] = _value;\n  }\n  return obj;\n};\n\nexport type RecomposeConfig_F = <T extends NodeConfig>(\n  shape: T,\n) => NodeConfig;\n\n/**\n * Recompose a configuration object into a nested structure based on the provided shape.\n *\n * @param shape - The shape of the configuration to recompose.\n * @returns A recomposed configuration object.\n *\n * @see {@linkcode RecomposeConfig_F} for type details.\n * @see {@linkcode recomposeObjectUrl} for the implementation of the recomposition logic.\n * @see {@linkcode merge} for merging objects.\n */\nexport const recomposeConfig: RecomposeConfig_F = shape => {\n  const entries = Object.entries(shape);\n  const arr: any[] = [];\n  entries.forEach(([key, value]) => {\n    arr.push(recomposeObjectUrl(key, value));\n  });\n\n  const output = merge(...(arr as [any, ...any[]]));\n  return output as any;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAM,sBAA6B,OAAO,UAAU;CAClD,MAAM,MAAW,EAAE;CAEnB,MAAM,EAAE,QAAQ,GAAG,SAAS;AAE5B,KAAI,UAAA,IACF,QAAO;CAGT,MAAM,OAAO,MAAM,MAAA,IAAwB,CAAC,QAAO,QAAO,QAAQ,GAAG;AAErE,KAAI,SAAS,EAAE;AACf,KAAI,KAAK,WAAW,GAAG;EACrB,MAAM,MAAM,KAAK,OAAO;AACxB,MAAI,OAAO,OAAO;QACb;EACL,MAAM,MAAM,KAAK,OAAO;EACxB,MAAM,SAAS,mBAAmB,KAAK,KAAA,IAAuB,EAAE,MAAM;AAEtE,MAAI,OAAO,OAAO;;AAEpB,QAAO;;;;;;;;;;;;AAiBT,MAAa,mBAAqC,UAAS;CACzD,MAAM,UAAU,OAAO,QAAQ,MAAM;CACrC,MAAM,MAAa,EAAE;AACrB,SAAQ,SAAS,CAAC,KAAK,WAAW;AAChC,MAAI,KAAK,mBAAmB,KAAK,MAAM,CAAC;GACxC;AAGF,QADeA,oBAAAA,MAAM,GAAI,IAAwB"}