(
property: string,
themeProperty: string,
value: Value,
priority: number,
conditions: Set<string>,
skipConditions: Set<string>
)
| 680 | } |
| 681 | |
| 682 | function compileRule( |
| 683 | property: string, |
| 684 | themeProperty: string, |
| 685 | value: Value, |
| 686 | priority: number, |
| 687 | conditions: Set<string>, |
| 688 | skipConditions: Set<string> |
| 689 | ): [number, Rule[]] { |
| 690 | let propertyFunction = properties.get(themeProperty); |
| 691 | if (propertyFunction) { |
| 692 | // Expand value to conditional CSS values, and then to rules. |
| 693 | let propertyValue = value; |
| 694 | let arbitrary = parseArbitraryValue(value); |
| 695 | let cssValue = arbitrary ? arbitrary : propertyFunction.toCSSValue(value); |
| 696 | let cssProperties = propertyFunction.toCSSProperties( |
| 697 | property.startsWith('--') ? property : null, |
| 698 | cssValue |
| 699 | ); |
| 700 | |
| 701 | return conditionalToRules( |
| 702 | cssProperties, |
| 703 | priority, |
| 704 | conditions, |
| 705 | skipConditions, |
| 706 | (value, priority, conditions) => { |
| 707 | let [obj] = value; |
| 708 | let rules: Rule[] = []; |
| 709 | for (let key in obj) { |
| 710 | let k = key as any; |
| 711 | let value = obj[k]; |
| 712 | if (value === undefined) { |
| 713 | continue; |
| 714 | } |
| 715 | if (typeof value === 'string') { |
| 716 | // Replace self() references with variables and track the dependencies. |
| 717 | value = value.replace(/self\(([a-zA-Z]+)/g, (_, v) => { |
| 718 | let prop = properties.get(v); |
| 719 | if (!prop) { |
| 720 | throw new Error(`self(${v}) is invalid. ${v} is not a known property.`); |
| 721 | } |
| 722 | let cssProperties = prop.cssProperties; |
| 723 | if (cssProperties.length !== 1) { |
| 724 | throw new Error( |
| 725 | `self(${v}) is not supported. ${v} expands to multiple CSS properties.` |
| 726 | ); |
| 727 | } |
| 728 | dependencies.add(v); |
| 729 | return `var(--${shortCSSPropertyName(cssProperties[0])}`; |
| 730 | }); |
| 731 | } |
| 732 | |
| 733 | // Generate selector. This consists of three parts: property, conditions, value. |
| 734 | let cssProperty = key; |
| 735 | if (property.startsWith('--')) { |
| 736 | cssProperty = propertyFunction.cssProperties[0]; |
| 737 | } |
| 738 | |
| 739 | let className = classNamePrefix(key, cssProperty); |
no test coverage detected