// TODO move to service internal static void ApplyStyleQuantum(this StyleAtom styleAtom, StyleQuantum styleQuantum, CaliforniaServiceOptions serviceOptions) // TEST _internal_ cannot be called from service consumer outside solution { if (!serviceOptions.StyleAtomDefaultProperties[styleAtom.StyleAtomType.Value].Contains(styleQuantum.CssProperty)) { throw new InvalidOperationException("Wrong style atom type for css property."); } // replace already applied style quantum for the same css property var appliedQuantumsSameProperty = styleAtom.MappedQuantums.Where(mapping => mapping.StyleQuantum.CssProperty == styleQuantum.CssProperty); var appliedQuantumsCount = appliedQuantumsSameProperty.Count(); if (appliedQuantumsCount > 1) { throw new ApplicationException("Multiple style quantums for the same css property are applied to one style atom."); } else if (appliedQuantumsCount == 1) { appliedQuantumsSameProperty.First().StyleQuantum = styleQuantum; } else { styleAtom.MappedQuantums.Add(new StyleAtomQuantumMapping() { StyleQuantum = styleQuantum }); } var appliedValuesSameProperty = styleAtom.AppliedValues.Where(val => val.CssProperty == styleQuantum.CssProperty); var appliedValuesCount = appliedValuesSameProperty.Count(); if (appliedValuesCount > 1) { throw new ApplicationException("Multiple style values for the same css property are applied to one style atom."); } else if (appliedValuesCount == 1) { appliedValuesSameProperty.First().CssValue = styleQuantum.CssValue; } else { // TODO this should throw if by default a stylevalue must always exist for the css property of an applied quantum styleAtom.AppliedValues.Add(new StyleValue() { CssProperty = styleQuantum.CssProperty, CssValue = styleQuantum.CssValue }); } }
internal static void ApplyStyleAtom(this StyleMolecule styleMolecule, StyleAtom styleAtom, ResponsiveDevice responsiveDevice, string stateModifier) { styleMolecule.ApplyStyleAtomRange(new StyleAtom[] { styleAtom }, responsiveDevice, stateModifier); }