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time.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {StyleString} from './types';\n// import {RuntimeStyleFunction, RenderProps} from './types';\n\n// taken from: https://stackoverflow.com/questions/51603250/typescript-3-parameter-list-intersection-type/51604379#51604379\n// type ArgTypes<T> = T extends (props: infer V) => any ? NullToObject<V> : never;\n// type NullToObject<T> = T extends (null | undefined) ? {} : T;\n// type BoxedTupleTypes<T extends any[]> = { [P in keyof T]: [ArgTypes<T[P]>] }[Exclude<keyof T, keyof any[]>];\n// type BoxedReturnTypes<T extends any[]> = { [P in keyof T]: [InferReturn<T[P]>] }[Exclude<keyof T, keyof any[]>];\n// type UnboxIntersection<T> = T extends { 0: infer U } ? U : never;\n// type Arg<X, R> = RuntimeStyleFunction<X, R> | null | undefined;\n// type NoInfer<T> = [T, void][T extends any ? 0 : 1];\n// type InferReturn<T> = T extends (props: any) => infer R ? NullToObject<R> : never;\n// type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;\n// type InferReturnType<T extends any[]> = UnboxIntersection<UnionToIntersection<BoxedReturnTypes<T>>>;\n\n// Two overloads:\n// 1. If a render props type is expected based on the return type, forward that type to all arguments.\n// 2. Otherwise, infer the return type based on the arguments.\n// export function merge<R extends RenderProps<string> = never, X = {}>(...args: Arg<NoInfer<X>, NoInfer<R>>[]): RuntimeStyleFunction<X, R>;\n// export function merge<T extends Arg<any, any>[]>(...args: T): RuntimeStyleFunction<InferReturnType<T>, UnboxIntersection<UnionToIntersection<BoxedTupleTypes<T>>>>;\n// export function merge(...args: any[]): RuntimeStyleFunction<any, any> {\n// return (props) => {\n// return mergeStyles(...args.map(f => typeof f === 'function' ? f(props) : null));\n// };\n// }\n\nexport function mergeStyles(...styles: (StyleString | null | undefined)[]): StyleString {\n let definedStyles = styles.filter(Boolean) as StyleString[];\n if (definedStyles.length === 1) {\n return definedStyles[0];\n }\n\n let map = new Map();\n for (let style of definedStyles) {\n for (let [k, v] of parse(style)) {\n map.set(k, v);\n }\n }\n \n let res = '';\n for (let value of map.values()) {\n res += value;\n }\n return res as StyleString;\n}\n\nfunction parse(s: string) {\n let properties = new Map<string, string>();\n let i = 0;\n while (i < s.length) {\n while (i < s.length && s[i] === ' ') {\n i++;\n }\n\n let start = i;\n readValue(); // property index\n\n // read conditions (up to the last segment)\n let condition = i;\n while (i < s.length && s[i] !== ' ') {\n readValue();\n }\n\n let property = s.slice(start, condition);\n properties.set(property, (properties.get(property) || '') + ' ' + s.slice(start, i));\n }\n\n function readValue() {\n if (s[i] === '-') {\n // the beginning and end of arbitrary values are marked with -\n while (i < s.length && s[i] !== ' ') {\n i++;\n if (s[i] === '-') {\n i++;\n break;\n }\n }\n } else {\n while (i < s.length) {\n if (s[i] === '_') {\n i++;\n } else {\n i++;\n break;\n }\n }\n }\n }\n\n return properties;\n}\n"],"names":[],"version":3,"file":"runtime.mjs.map"}