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AED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import { IStyleSet, IConcatenatedStyleSet } from './IStyleSet';\nimport { IStyleBase, IStyle } from './IStyle';\nimport { IStyleFunctionOrObject } from './IStyleFunction';\nimport { ObjectOnly } from './ObjectOnly';\n\n/**\n * Combine a set of styles together (but does not register css classes).\n * @param styleSet - The first style set to be concatenated.\n */\nexport function concatStyleSets<TStyleSet>(\n styleSet: TStyleSet | false | null | undefined,\n): IConcatenatedStyleSet<ObjectOnly<TStyleSet>>;\n\n/**\n * Combine a set of styles together (but does not register css classes).\n * @param styleSet1 - The first style set to be concatenated.\n * @param styleSet2 - The second style set to be concatenated.\n */\nexport function concatStyleSets<TStyleSet1, TStyleSet2>(\n styleSet1: TStyleSet1 | false | null | undefined,\n styleSet2: TStyleSet2 | false | null | undefined,\n): IConcatenatedStyleSet<ObjectOnly<TStyleSet1> & ObjectOnly<TStyleSet2>>;\n\n/**\n * Combine a set of styles together (but does not register css classes).\n * @param styleSet1 - The first style set to be concatenated.\n * @param styleSet2 - The second style set to be concatenated.\n * @param styleSet3 - The third style set to be concatenated.\n */\nexport function concatStyleSets<TStyleSet1, TStyleSet2, TStyleSet3>(\n styleSet1: TStyleSet1 | false | null | undefined,\n styleSet2: TStyleSet2 | false | null | undefined,\n styleSet3: TStyleSet3 | false | null | undefined,\n): IConcatenatedStyleSet<ObjectOnly<TStyleSet1> & ObjectOnly<TStyleSet2> & ObjectOnly<TStyleSet3>>;\n\n/**\n * Combine a set of styles together (but does not register css classes).\n * @param styleSet1 - The first style set to be concatenated.\n * @param styleSet2 - The second style set to be concatenated.\n * @param styleSet3 - The third style set to be concatenated.\n * @param styleSet4 - The fourth style set to be concatenated.\n */\nexport function concatStyleSets<TStyleSet1, TStyleSet2, TStyleSet3, TStyleSet4>(\n styleSet1: TStyleSet1 | false | null | undefined,\n styleSet2: TStyleSet2 | false | null | undefined,\n styleSet3: TStyleSet3 | false | null | undefined,\n styleSet4: TStyleSet4 | false | null | undefined,\n): IConcatenatedStyleSet<\n ObjectOnly<TStyleSet1> & ObjectOnly<TStyleSet2> & ObjectOnly<TStyleSet3> & ObjectOnly<TStyleSet4>\n>;\n\n/**\n * Combine a set of styles together (but does not register css classes).\n * @param styleSet1 - The first style set to be concatenated.\n * @param styleSet2 - The second style set to be concatenated.\n * @param styleSet3 - The third style set to be concatenated.\n * @param styleSet4 - The fourth style set to be concatenated.\n * @param styleSet5 - The fifth set to be concatenated.\n */\nexport function concatStyleSets<TStyleSet1, TStyleSet2, TStyleSet3, TStyleSet4, TStyleSet5>(\n styleSet1: TStyleSet1 | false | null | undefined,\n styleSet2: TStyleSet2 | false | null | undefined,\n styleSet3: TStyleSet3 | false | null | undefined,\n styleSet4: TStyleSet4 | false | null | undefined,\n styleSet5: TStyleSet5 | false | null | undefined,\n): IConcatenatedStyleSet<\n ObjectOnly<TStyleSet1> &\n ObjectOnly<TStyleSet2> &\n ObjectOnly<TStyleSet3> &\n ObjectOnly<TStyleSet4> &\n ObjectOnly<TStyleSet5>\n>;\n\n/**\n * Combine a set of styles together (but does not register css classes).\n * @param styleSet1 - The first style set to be concatenated.\n * @param styleSet2 - The second style set to be concatenated.\n * @param styleSet3 - The third style set to be concatenated.\n * @param styleSet4 - The fourth style set to be concatenated.\n * @param styleSet5 - The fifth set to be concatenated.\n * @param styleSet6 - The sixth set to be concatenated.\n */\nexport function concatStyleSets<TStyleSet1, TStyleSet2, TStyleSet3, TStyleSet4, TStyleSet5, TStyleSet6>(\n styleSet1: TStyleSet1 | false | null | undefined,\n styleSet2: TStyleSet2 | false | null | undefined,\n styleSet3: TStyleSet3 | false | null | undefined,\n styleSet4: TStyleSet4 | false | null | undefined,\n styleSet5: TStyleSet5 | false | null | undefined,\n styleSet6: TStyleSet6 | false | null | undefined,\n): IConcatenatedStyleSet<\n ObjectOnly<TStyleSet1> &\n ObjectOnly<TStyleSet2> &\n ObjectOnly<TStyleSet3> &\n ObjectOnly<TStyleSet4> &\n ObjectOnly<TStyleSet5> &\n ObjectOnly<TStyleSet6>\n>;\n\n/**\n * Combine a set of styles together (but does not register css classes).\n * @param styleSets - One or more stylesets to be merged (each param can also be falsy).\n */\nexport function concatStyleSets(...styleSets: (IStyleSet | false | null | undefined)[]): IConcatenatedStyleSet<any>;\n\n/**\n * Combine a set of styles together (but does not register css classes).\n * @param styleSets - One or more stylesets to be merged (each param can also be falsy).\n */\nexport function concatStyleSets(...styleSets: (IStyleSet | false | null | undefined)[]): IConcatenatedStyleSet<any> {\n if (styleSets && styleSets.length === 1 && styleSets[0] && !(styleSets[0] as IStyleSet).subComponentStyles) {\n return styleSets[0] as IConcatenatedStyleSet<any>;\n }\n\n const mergedSet: IConcatenatedStyleSet<any> = {};\n\n // We process sub component styles in two phases. First we collect them, then we combine them into 1 style function.\n const workingSubcomponentStyles: { [key: string]: Array<IStyleFunctionOrObject<any, any>> } = {};\n\n for (const currentSet of styleSets) {\n if (currentSet) {\n for (const prop in currentSet) {\n if (currentSet.hasOwnProperty(prop)) {\n if (prop === 'subComponentStyles' && currentSet.subComponentStyles !== undefined) {\n // subcomponent styles - style functions or objects\n\n const currentComponentStyles = currentSet.subComponentStyles;\n for (const subCompProp in currentComponentStyles) {\n if (currentComponentStyles.hasOwnProperty(subCompProp)) {\n if (workingSubcomponentStyles.hasOwnProperty(subCompProp)) {\n workingSubcomponentStyles[subCompProp].push(currentComponentStyles[subCompProp]);\n } else {\n workingSubcomponentStyles[subCompProp] = [currentComponentStyles[subCompProp]];\n }\n }\n }\n\n continue;\n }\n\n // the as any casts below is a workaround for ts 2.8.\n // todo: remove cast to any in ts 2.9.\n const mergedValue: IStyle = (mergedSet as any)[prop];\n const currentValue = (currentSet as any)[prop];\n\n if (mergedValue === undefined) {\n (mergedSet as any)[prop] = currentValue;\n } else {\n (mergedSet as any)[prop] = [\n // https://github.com/Microsoft/TypeScript/issues/25474\n ...(Array.isArray(mergedValue) ? mergedValue : [mergedValue as IStyleBase]),\n ...(Array.isArray(currentValue) ? currentValue : [currentValue as IStyleBase]),\n ];\n }\n }\n }\n }\n }\n\n if (Object.keys(workingSubcomponentStyles).length > 0) {\n mergedSet.subComponentStyles = {};\n const mergedSubStyles = mergedSet.subComponentStyles;\n\n // now we process the subcomponent styles if there are any\n for (const subCompProp in workingSubcomponentStyles) {\n if (workingSubcomponentStyles.hasOwnProperty(subCompProp)) {\n const workingSet = workingSubcomponentStyles[subCompProp];\n mergedSubStyles[subCompProp] = (styleProps: any) => {\n return concatStyleSets(\n ...workingSet.map((styleFunctionOrObject: IStyleFunctionOrObject<any, any>) =>\n typeof styleFunctionOrObject === 'function' ? styleFunctionOrObject(styleProps) : styleFunctionOrObject,\n ),\n );\n };\n }\n }\n }\n\n return mergedSet;\n}\n"]}
\No newline at end of file