{"version":3,"file":"deepMerge.cjs","sources":["../../../../src/components/utils/deepMerge.ts"],"sourcesContent":["import { DeepPartial } from \"./deepPartial\";\nimport { ComponentKeys } from \"../ui/props\";\n\nconst isObject = (item: unknown): item is Record<string, unknown> => {\n  return item !== null && typeof item === 'object' && !Array.isArray(item);\n};\n\nexport const deepMerge = <T extends object>(\n  target: T,\n  source: DeepPartial<T>\n): T => {\n  const output = Object.assign(Object.create(Object.getPrototypeOf(target)), target);\n\n  for (const key in source) {\n    if (Object.prototype.hasOwnProperty.call(source, key)) {\n      const sourceValue = source[key as keyof typeof source];\n      const targetValue = output[key];\n\n      if (sourceValue === undefined) {\n        continue;\n      }\n\n      // 'defaults' uses mergeDefaults so exclusive groups (size, appearance, ...) are reset correctly\n      if (\n        key === 'defaults' &&\n        isObject(targetValue) &&\n        isObject(sourceValue)\n      ) {\n        output[key] = mergeDefaults(\n          targetValue as Record<string, boolean>,\n          sourceValue as Record<string, boolean>\n        );\n      }\n      else if (isObject(targetValue) && isObject(sourceValue)) {\n        output[key] = deepMerge(\n          targetValue,\n          sourceValue as DeepPartial<typeof targetValue>\n        );\n      }\n      else {\n        output[key] = sourceValue;\n      }\n    }\n  }\n\n  return output;\n};\n\n// NOTE: deliberately NO visited/identity map — theme nodes shared between\n// components (e.g. a mapper tree used by several ComponentThemes) MUST be\n// forked per occurrence, because themeOverride callbacks mutate cloned nodes\n// in place and rely on per-component isolation.\nexport const deepClone = <T extends object>(source: T): T => {\n  if (Array.isArray(source)) {\n    return source.map(item => (isObject(item) ? deepClone(item) : item)) as unknown as T;\n  }\n\n  if (!isObject(source)) {\n    return source;\n  }\n\n  const output = Object.assign(Object.create(Object.getPrototypeOf(source)), source);\n\n  for (const key in output) {\n    if (Object.prototype.hasOwnProperty.call(output, key)) {\n      output[key] = deepClone(output[key]);\n    }\n  }\n\n  return output;\n}\n\n// reverse-lookup built once at module load (key → its exclusive group)\nconst keyToGroup = new Map<string, readonly string[]>();\nfor (const group of Object.values(ComponentKeys)) {\n  for (const key of group as readonly string[]) {\n    keyToGroup.set(key, group as readonly string[]);\n  }\n}\n\nconst findGroup = (key: string) => keyToGroup.get(key);\n\nexport const mergeDefaults = (\n  baseDefaults: Record<string, boolean>,\n  overrideDefaults: Record<string, boolean>\n): Record<string, boolean> => {\n  const finalDefaults = {...baseDefaults};\n\n  for (const key in overrideDefaults) {\n    if (Object.prototype.hasOwnProperty.call(overrideDefaults, key)) {\n      const overrideValue = overrideDefaults[key];\n\n      // setting one exclusive-group key to true resets the others to false\n      if (overrideValue) {\n        const group = findGroup(key);\n        if (group) {\n          group.forEach(groupKey => {\n            if (groupKey !== key) {\n              finalDefaults[groupKey] = false;\n            }\n          });\n        }\n      }\n\n      finalDefaults[key] = overrideValue;\n    }\n  }\n\n  return finalDefaults;\n};"],"names":["ComponentKeys"],"mappings":";;;;AAGA,MAAM,QAAA,GAAW,CAAC,IAAA,KAAmD;AACnE,EAAA,OAAO,IAAA,KAAS,QAAQ,OAAO,IAAA,KAAS,YAAY,CAAC,KAAA,CAAM,QAAQ,IAAI,CAAA;AACzE,CAAA;AAEO,MAAM,SAAA,GAAY,CACvB,MAAA,EACA,MAAA,KACM;AACN,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,MAAA,CAAO,MAAA,CAAO,MAAA,CAAO,OAAO,cAAA,CAAe,MAAM,CAAC,CAAA,EAAG,MAAM,CAAA;AAEjF,EAAA,KAAA,MAAW,OAAO,MAAA,EAAQ;AACxB,IAAA,IAAI,OAAO,SAAA,CAAU,cAAA,CAAe,IAAA,CAAK,MAAA,EAAQ,GAAG,CAAA,EAAG;AACrD,MAAA,MAAM,WAAA,GAAc,OAAO,GAA0B,CAAA;AACrD,MAAA,MAAM,WAAA,GAAc,OAAO,GAAG,CAAA;AAE9B,MAAA,IAAI,gBAAgB,MAAA,EAAW;AAC7B,QAAA;AAAA,MACF;AAGA,MAAA,IACE,QAAQ,UAAA,IACR,QAAA,CAAS,WAAW,CAAA,IACpB,QAAA,CAAS,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