Skip to content

Commit 1e9c9f8

Browse files
Adding support to keyframes
1 parent 71f8d37 commit 1e9c9f8

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Sabberworm\CSS\CSSList;
4+
5+
6+
class KeyFrame extends CSSList {
7+
8+
private $vendorKeyFrame;
9+
private $animationName;
10+
11+
public function __construct() {
12+
parent::__construct();
13+
$this->vendorKeyFrame = null;
14+
$this->animationName = null;
15+
}
16+
17+
public function setVendorKeyFrame($vendorKeyFrame) {
18+
$this->vendorKeyFrame = $vendorKeyFrame;
19+
}
20+
21+
public function getVendorKeyFrame() {
22+
return $this->vendorKeyFrame;
23+
}
24+
25+
public function setAnimationName($animationName) {
26+
$this->animationName = $animationName;
27+
}
28+
29+
public function getAnimationName() {
30+
return $this->animationName;
31+
}
32+
33+
public function __toString() {
34+
$sResult = "@{$this->vendorKeyFrame} {$this->animationName} {";
35+
$sResult .= parent::__toString();
36+
$sResult .= '}';
37+
return $sResult;
38+
}
39+
40+
}

lib/Sabberworm/CSS/Parser.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Sabberworm\CSS\CSSList\CSSList;
66
use Sabberworm\CSS\CSSList\Document;
77
use Sabberworm\CSS\CSSList\MediaQuery;
8+
use Sabberworm\CSS\CSSList\Keyframe;
89
use Sabberworm\CSS\Property\Import;
910
use Sabberworm\CSS\Property\Charset;
1011
use Sabberworm\CSS\RuleSet\AtRule;
@@ -88,7 +89,16 @@ private function parseAtRule() {
8889
$this->consume('@');
8990
$sIdentifier = $this->parseIdentifier();
9091
$this->consumeWhiteSpace();
91-
if ($sIdentifier === 'media') {
92+
if($sIdentifier == 'keyframes' || $sIdentifier == '-webkit-keyframes' || $sIdentifier == '-moz-keyframes' || $sIdentifier == '-o-keyframes') {
93+
$oResult = new KeyFrame();
94+
$oResult->setVendorKeyFrame($sIdentifier);
95+
$oResult->setAnimationName(trim($this->consumeUntil('{')));
96+
$this->consume('{');
97+
$this->consumeWhiteSpace();
98+
$this->parseList($oResult);
99+
return $oResult;
100+
101+
} else if ($sIdentifier === 'media') {
92102
$oResult = new MediaQuery();
93103
$oResult->setQuery(trim($this->consumeUntil('{')));
94104
$this->consume('{');

0 commit comments

Comments
 (0)