Initial commit
This commit is contained in:
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
namespace Sabberworm\CSS\Value; class CSSFunction extends ValueList { protected $sName; public function __construct($sName, $aArguments, $sSeparator = ',', $iLineNo = 0) { if($aArguments instanceof RuleValueList) { $sSeparator = $aArguments->getListSeparator(); $aArguments = $aArguments->getListComponents(); } $this->sName = $sName; $this->iLineNo = $iLineNo; parent::__construct($aArguments, $sSeparator, $iLineNo); } public function getName() { return $this->sName; } public function setName($sName) { $this->sName = $sName; } public function getArguments() { return $this->aComponents; } public function __toString() { return $this->render(new \Sabberworm\CSS\OutputFormat()); } public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) { $aArguments = parent::render($oOutputFormat); return "{$this->sName}({$aArguments})"; } }
|
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
namespace Sabberworm\CSS\Value; class CSSString extends PrimitiveValue { private $sString; public function __construct($sString, $iLineNo = 0) { $this->sString = $sString; parent::__construct($iLineNo); } public function setString($sString) { $this->sString = $sString; } public function getString() { return $this->sString; } public function __toString() { return $this->render(new \Sabberworm\CSS\OutputFormat()); } public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) { $sString = addslashes($this->sString); $sString = str_replace("\n", '\A', $sString); return $oOutputFormat->getStringQuotingType() . $sString . $oOutputFormat->getStringQuotingType(); } }
|
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
namespace Sabberworm\CSS\Value; class CalcFunction extends CSSFunction { const T_OPERAND = 1; const T_OPERATOR = 2; }
|
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
namespace Sabberworm\CSS\Value; class CalcRuleValueList extends RuleValueList { public function __construct($iLineNo = 0) { parent::__construct(array(), ',', $iLineNo); } public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) { return $oOutputFormat->implode(' ', $this->aComponents); } }
|
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
namespace Sabberworm\CSS\Value; class Color extends CSSFunction { public function __construct($aColor, $iLineNo = 0) { parent::__construct(implode('', array_keys($aColor)), $aColor, ',', $iLineNo); } public function getColor() { return $this->aComponents; } public function setColor($aColor) { $this->setName(implode('', array_keys($aColor))); $this->aComponents = $aColor; } public function getColorDescription() { return $this->getName(); } public function __toString() { return $this->render(new \Sabberworm\CSS\OutputFormat()); } public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) { if($oOutputFormat->getRGBHashNotation() && implode('', array_keys($this->aComponents)) === 'rgb') { $sResult = sprintf( '%02x%02x%02x', $this->aComponents['r']->getSize(), $this->aComponents['g']->getSize(), $this->aComponents['b']->getSize() ); return '#'.(($sResult[0] == $sResult[1]) && ($sResult[2] == $sResult[3]) && ($sResult[4] == $sResult[5]) ? "$sResult[0]$sResult[2]$sResult[4]" : $sResult); } return parent::render($oOutputFormat); } }
|
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
namespace Sabberworm\CSS\Value; class LineName extends ValueList { public function __construct($aComponents = array(), $iLineNo = 0) { parent::__construct($aComponents, ' ', $iLineNo); } public function __toString() { return $this->render(new \Sabberworm\CSS\OutputFormat()); } public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) { return '[' . parent::render(\Sabberworm\CSS\OutputFormat::createCompact()) . ']'; } }
|
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
namespace Sabberworm\CSS\Value; abstract class PrimitiveValue extends Value { public function __construct($iLineNo = 0) { parent::__construct($iLineNo); } }
|
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
namespace Sabberworm\CSS\Value; class RuleValueList extends ValueList { public function __construct($sSeparator = ',', $iLineNo = 0) { parent::__construct(array(), $sSeparator, $iLineNo); } }
|
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
namespace Sabberworm\CSS\Value; class Size extends PrimitiveValue { const ABSOLUTE_SIZE_UNITS = 'px/cm/mm/mozmm/in/pt/pc/vh/vw/vm/vmin/vmax/rem'; const RELATIVE_SIZE_UNITS = '%/em/ex/ch/fr'; const NON_SIZE_UNITS = 'deg/grad/rad/s/ms/turns/Hz/kHz'; private $fSize; private $sUnit; private $bIsColorComponent; public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $iLineNo = 0) { parent::__construct($iLineNo); $this->fSize = floatval($fSize); $this->sUnit = $sUnit; $this->bIsColorComponent = $bIsColorComponent; } public function setUnit($sUnit) { $this->sUnit = $sUnit; } public function getUnit() { return $this->sUnit; } public function setSize($fSize) { $this->fSize = floatval($fSize); } public function getSize() { return $this->fSize; } public function isColorComponent() { return $this->bIsColorComponent; } public function isSize() { if (in_array($this->sUnit, explode('/', self::NON_SIZE_UNITS))) { return false; } return !$this->isColorComponent(); } public function isRelative() { if (in_array($this->sUnit, explode('/', self::RELATIVE_SIZE_UNITS))) { return true; } if ($this->sUnit === null && $this->fSize != 0) { return true; } return false; } public function __toString() { return $this->render(new \Sabberworm\CSS\OutputFormat()); } public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) { $l = localeconv(); $sPoint = preg_quote($l['decimal_point'], '/'); return preg_replace(array("/$sPoint/", "/^(-?)0\./"), array('.', '$1.'), $this->fSize) . ($this->sUnit === null ? '' : $this->sUnit); } }
|
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
namespace Sabberworm\CSS\Value; class URL extends PrimitiveValue { private $oURL; public function __construct(CSSString $oURL, $iLineNo = 0) { parent::__construct($iLineNo); $this->oURL = $oURL; } public function setURL(CSSString $oURL) { $this->oURL = $oURL; } public function getURL() { return $this->oURL; } public function __toString() { return $this->render(new \Sabberworm\CSS\OutputFormat()); } public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) { return "url({$this->oURL->render($oOutputFormat)})"; } }
|
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
namespace Sabberworm\CSS\Value; use Sabberworm\CSS\Renderable; abstract class Value implements Renderable { protected $iLineNo; public function __construct($iLineNo = 0) { $this->iLineNo = $iLineNo; } public function getLineNo() { return $this->iLineNo; } }
|
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
namespace Sabberworm\CSS\Value; abstract class ValueList extends Value { protected $aComponents; protected $sSeparator; public function __construct($aComponents = array(), $sSeparator = ',', $iLineNo = 0) { parent::__construct($iLineNo); if (!is_array($aComponents)) { $aComponents = array($aComponents); } $this->aComponents = $aComponents; $this->sSeparator = $sSeparator; } public function addListComponent($mComponent) { $this->aComponents[] = $mComponent; } public function getListComponents() { return $this->aComponents; } public function setListComponents($aComponents) { $this->aComponents = $aComponents; } public function getListSeparator() { return $this->sSeparator; } public function setListSeparator($sSeparator) { $this->sSeparator = $sSeparator; } public function __toString() { return $this->render(new \Sabberworm\CSS\OutputFormat()); } public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) { return $oOutputFormat->implode($oOutputFormat->spaceBeforeListArgumentSeparator($this->sSeparator) . $this->sSeparator . $oOutputFormat->spaceAfterListArgumentSeparator($this->sSeparator), $this->aComponents); } }
|
Reference in New Issue
Block a user