MCPcopy
hub / github.com/tdewolff/minify / minifyProperty

Method minifyProperty

css/css.go:663–1372  ·  view source on GitHub ↗
(prop Hash, values []Token)

Source from the content-addressed store, hash-verified

661}
662
663func (c *cssMinifier) minifyProperty(prop Hash, values []Token) []Token {
664 // limit maximum to prevent slow recursions (e.g. for background's append)
665 if 100 < len(values) {
666 return values
667 }
668
669 switch prop {
670 case Font:
671 if len(values) > 1 { // must contain atleast font-size and font-family
672 // the font-families are separated by commas and are at the end of font
673 // get index for last token before font family names
674 i := len(values) - 1
675 for j, value := range values[2:] {
676 if value.TokenType == css.CommaToken {
677 i = 2 + j - 1 // identifier before first comma is a font-family
678 break
679 }
680 }
681 i--
682
683 // advance i while still at font-families when they contain spaces but no quotes
684 for ; i > 0; i-- { // i cannot be 0, font-family must be prepended by font-size
685 if values[i-1].TokenType == css.DelimToken && values[i-1].Data[0] == '/' {
686 break
687 } else if values[i].TokenType != css.IdentToken && values[i].TokenType != css.StringToken {
688 break
689 } else if h := values[i].Ident; h == Xx_Small || h == X_Small || h == Small || h == Medium || h == Large || h == X_Large || h == Xx_Large || h == Smaller || h == Larger || h == Inherit || h == Initial || h == Unset {
690 // inherit, initial and unset are followed by an IdentToken/StringToken, so must be for font-size
691 break
692 }
693 }
694
695 // font-family minified in place
696 values = append(values[:i+1], c.minifyProperty(Font_Family, values[i+1:])...)
697
698 // fix for IE9, IE10, IE11: font name starting with `-` is not recognized
699 if values[i+1].Data[0] == '-' {
700 v := make([]byte, len(values[i+1].Data)+2)
701 v[0] = '\''
702 copy(v[1:], values[i+1].Data)
703 v[len(v)-1] = '\''
704 values[i+1].Data = v
705 }
706
707 if i > 0 {
708 // line-height
709 if i > 1 && values[i-1].TokenType == css.DelimToken && values[i-1].Data[0] == '/' {
710 if values[i].Ident == Normal {
711 values = append(values[:i-1], values[i+1:]...)
712 }
713 i -= 2
714 }
715
716 // font-size
717 i--
718
719 for ; i > -1; i-- {
720 if values[i].Ident == Normal {

Callers 1

minifyDeclarationMethod · 0.95

Calls 9

lenFunction · 0.85
appendFunction · 0.85
minifyColorFunction · 0.85
minifyLengthPercentageFunction · 0.85
EqualMethod · 0.80
IsLengthPercentageMethod · 0.80
IsZeroMethod · 0.80
IsLengthMethod · 0.80
copyFunction · 0.50

Tested by

no test coverage detected