@@ -786,7 +786,6 @@ export class StylePropertiesSection {
786786 let supportsIndex = 0 ;
787787 let nestingIndex = 0 ;
788788 this . nestingLevel = 0 ;
789- const indent = Common . Settings . Settings . instance ( ) . moduleSetting ( 'text-editor-indent' ) . get ( ) ;
790789 for ( const ruleType of rule . ruleTypes ) {
791790 let ancestorRuleElement ;
792791 switch ( ruleType ) {
@@ -808,11 +807,7 @@ export class StylePropertiesSection {
808807 }
809808 if ( ancestorRuleElement ) {
810809 this . #ancestorRuleListElement. prepend ( ancestorRuleElement ) ;
811- const closingBrace = document . createElement ( 'div' ) ;
812- closingBrace . createChild ( 'span' , 'styles-clipboard-only' ) . textContent = indent . repeat ( this . nestingLevel ) ;
813- closingBrace . style . paddingLeft = `${ this . nestingLevel } ch` ;
814- closingBrace . append ( '}' ) ;
815- this . #ancestorClosingBracesElement. prepend ( closingBrace ) ;
810+ this . #ancestorClosingBracesElement. prepend ( this . indentElement ( this . createClosingBrace ( ) , this . nestingLevel ) ) ;
816811 this . nestingLevel ++ ;
817812 }
818813 }
@@ -824,16 +819,30 @@ export class StylePropertiesSection {
824819
825820 let curNestingLevel = 0 ;
826821 for ( const element of this . #ancestorRuleListElement. children ) {
827- const indentElement = document . createElement ( 'span' ) ;
828- indentElement . classList . add ( 'styles-clipboard-only' ) ;
829- indentElement . setAttribute ( 'slot' , 'indent' ) ;
830- indentElement . textContent = indent . repeat ( curNestingLevel ) ;
831- element . prepend ( indentElement ) ;
832- ( element as HTMLElement ) . style . paddingLeft = `${ curNestingLevel } ch` ;
822+ this . indentElement ( element as HTMLElement , curNestingLevel ) ;
833823 curNestingLevel ++ ;
834824 }
835825 }
836826
827+ protected createClosingBrace ( ) : HTMLElement {
828+ const closingBrace = document . createElement ( 'div' ) ;
829+ closingBrace . append ( '}' ) ;
830+ return closingBrace ;
831+ }
832+
833+ protected indentElement ( element : HTMLElement , nestingLevel : number , clipboardOnly ?: boolean ) : HTMLElement {
834+ const indent = Common . Settings . Settings . instance ( ) . moduleSetting ( 'text-editor-indent' ) . get ( ) ;
835+ const indentElement = document . createElement ( 'span' ) ;
836+ indentElement . classList . add ( 'styles-clipboard-only' ) ;
837+ indentElement . setAttribute ( 'slot' , 'indent' ) ;
838+ indentElement . textContent = indent . repeat ( nestingLevel ) ;
839+ element . prepend ( indentElement ) ;
840+ if ( ! clipboardOnly ) {
841+ element . style . paddingLeft = `${ nestingLevel } ch` ;
842+ }
843+ return element ;
844+ }
845+
837846 protected createMediaElement ( media : SDK . CSSMedia . CSSMedia ) : ElementsComponents . CSSQuery . CSSQuery | undefined {
838847 // Don't display trivial non-print media types.
839848 const isMedia = ! media . text || ! media . text . includes ( '(' ) && media . text !== 'print' ;
@@ -1072,7 +1081,10 @@ export class StylePropertiesSection {
10721081 this . parentPane . setActiveProperty ( null ) ;
10731082 this . nextEditorTriggerButtonIdx = 1 ;
10741083 this . propertiesTreeOutline . removeChildren ( ) ;
1075- const style = this . styleInternal ;
1084+ this . populateStyle ( this . styleInternal , this . propertiesTreeOutline ) ;
1085+ }
1086+
1087+ populateStyle ( style : SDK . CSSStyleDeclaration . CSSStyleDeclaration , parent : TreeElementParent ) : void {
10761088 let count = 0 ;
10771089 const properties = style . leadingProperties ( ) ;
10781090 const maxProperties = DEFAULT_MAX_PROPERTIES + properties . length - this . originalPropertiesCount ;
@@ -1100,7 +1112,7 @@ export class StylePropertiesSection {
11001112 } ) ;
11011113 item . setComputedStyles ( this . computedStyles ) ;
11021114 item . setParentsComputedStyles ( this . parentsComputedStyles ) ;
1103- this . propertiesTreeOutline . appendChild ( item ) ;
1115+ parent . appendChild ( item ) ;
11041116 }
11051117
11061118 if ( count < properties . length ) {
@@ -1750,6 +1762,68 @@ export class RegisteredPropertiesSection extends StylePropertiesSection {
17501762 }
17511763}
17521764
1765+ export class FunctionRuleSection extends StylePropertiesSection {
1766+ constructor (
1767+ stylesPane : StylesSidebarPane , matchedStyles : SDK . CSSMatchedStyles . CSSMatchedStyles ,
1768+ style : SDK . CSSStyleDeclaration . CSSStyleDeclaration , children : SDK . CSSRule . CSSNestedStyle [ ] , sectionIdx : number ,
1769+ functionName : string , parameters : string [ ] , expandedByDefault : boolean ) {
1770+ super ( stylesPane , matchedStyles , style , sectionIdx , null , null , `${ functionName } (${ parameters . join ( ', ' ) } )` ) ;
1771+ if ( ! expandedByDefault ) {
1772+ this . element . classList . add ( 'hidden' ) ;
1773+ }
1774+ this . selectorElement . className = 'function-key' ;
1775+ this . addChildren ( children , this . propertiesTreeOutline ) ;
1776+ }
1777+
1778+ createConditionElement ( condition : SDK . CSSRule . CSSNestedStyleCondition ) : HTMLElement | undefined {
1779+ if ( 'media' in condition ) {
1780+ return this . createMediaElement ( condition . media ) ;
1781+ }
1782+ if ( 'container' in condition ) {
1783+ return this . createContainerQueryElement ( condition . container ) ;
1784+ }
1785+ if ( 'supports' in condition ) {
1786+ return this . createSupportsElement ( condition . supports ) ;
1787+ }
1788+ return ;
1789+ }
1790+
1791+ positionNestingElement ( element : HTMLElement ) : HTMLElement {
1792+ // Add this class to get the same margins as a property and syntax highlighting.
1793+ element . classList . add ( 'css-function-inline-block' ) ;
1794+ // Also add the clipboard text, but don't add additional margins because
1795+ // the tree nesting takes care of that.
1796+ return this . indentElement ( element , this . nestingLevel , true ) ;
1797+ }
1798+
1799+ addChildren ( children : SDK . CSSRule . CSSNestedStyle [ ] , parent : TreeElementParent ) : void {
1800+ for ( const child of children ) {
1801+ if ( 'style' in child ) {
1802+ this . populateStyle ( child . style , parent ) ;
1803+ } else if ( 'children' in child ) {
1804+ const conditionElement = this . createConditionElement ( child ) ;
1805+ let newParent = parent ;
1806+ this . nestingLevel ++ ;
1807+ if ( conditionElement ) {
1808+ const treeElement = new UI . TreeOutline . TreeElement ( ) ;
1809+ treeElement . listItemElement . appendChild ( this . positionNestingElement ( conditionElement ) ) ;
1810+ treeElement . setExpandable ( true ) ;
1811+ treeElement . setCollapsible ( false ) ;
1812+ parent . appendChild ( treeElement ) ;
1813+ newParent = treeElement ;
1814+ }
1815+ this . addChildren ( child . children , newParent ) ;
1816+ if ( conditionElement ) {
1817+ const treeElement = new UI . TreeOutline . TreeElement ( ) ;
1818+ treeElement . listItemElement . appendChild ( this . positionNestingElement ( this . createClosingBrace ( ) ) ) ;
1819+ parent . appendChild ( treeElement ) ;
1820+ }
1821+ this . nestingLevel -- ;
1822+ }
1823+ }
1824+ }
1825+ }
1826+
17531827export class FontPaletteValuesRuleSection extends StylePropertiesSection {
17541828 constructor (
17551829 stylesPane : StylesSidebarPane , matchedStyles : SDK . CSSMatchedStyles . CSSMatchedStyles ,
@@ -1832,3 +1906,7 @@ export class HighlightPseudoStylePropertiesSection extends StylePropertiesSectio
18321906 return false ;
18331907 }
18341908}
1909+
1910+ interface TreeElementParent {
1911+ appendChild ( child : UI . TreeOutline . TreeElement ) : void ;
1912+ }
0 commit comments