/** * run * @see Fl_Base::run() */ public function run($options = array()) { $this->options = array_merge($this->options, $options); $this->tokenInstance = $this->getInstance("Fl_Css_Token"); $selectorPos = 0; $sortSelector = $this->options['sort_selector']; $mergeSelector = $this->options['merge_selector']; //是否已经含有charset $hasCharset = false; while ($token = $this->tokenInstance->getNextToken()) { switch ($token['type']) { case FL_TOKEN_CSS_SELECTOR: $this->collectionSelector($token, $selectorPos++); break; case FL_TOKEN_CSS_BRACES_TWO_END: $this->compressSelector(); $this->options['sort_selector'] = $sortSelector; $this->options['merge_selector'] = $mergeSelector; $this->output[] = trim($token['value']); $this->inKeyframes = false; break; case FL_TOKEN_CSS_AT_KEYFRAMES: $this->options['sort_selector'] = false; $this->options['merge_selector'] = false; $this->inKeyframes = true; default: if (Fl_Css_Static::isAtType($token['type'])) { $this->compressSelector(false, false); } //只允许含有一个charset if ($token['type'] === FL_TOKEN_CSS_AT_CHARSET) { if (!$hasCharset) { $this->output[] = trim($token['value']); $hasCharset = true; } } else { $this->output[] = trim($token['value']); } } } $this->compressSelector(); $result = join('', $this->output); return Fl_Css_Static::compressCommon($result); }
/** * * beautify default token * @param array $token */ public function beautifyDefault($token) { //for ;;; if ($token['type'] === FL_TOKEN_CSS_SEMICOLON && $this->preToken['type'] === FL_TOKEN_CSS_SEMICOLON) { return ''; } if (isset($this->preToken['type'])) { //for @ type if ($token['type'] === FL_TOKEN_CSS_AT_KEYFRAMES || $token['type'] === FL_TOKEN_CSS_AT_MOZILLA) { return FL_NEWLINE . $this->getIndentString() . $token['value']; } else { if (Fl_Css_Static::isAtType($token['type'])) { return FL_NEWLINE . $token['value']; } } } if ($token['type'] === FL_TOKEN_CSS_HACK) { return FL_NEWLINE . $this->getIndentString() . $token['value']; } return $token['value']; }