+ * array(
+ * array(
+ * int $lhs; Symbol on the left-hand side of the rule
+ * int $nrhs; Number of right-hand side symbols in the rule
+ * ),...
+ * );
+ *
+ *
+ * The parser will translate to something like:
+ *
+ *
+ * function yy_r0(){$this->_retvalue = 1;}
+ *
+ */
+ private $_retvalue;
+
+ /**
+ * Perform a reduce action and the shift that must immediately
+ * follow the reduce.
+ *
+ * For a rule such as:
+ *
+ *
+ * A ::= B blah C. { dosomething(); }
+ *
+ *
+ * This function will first call the action, if any, ("dosomething();" in our
+ * example), and then it will pop three states from the stack,
+ * one for each entry on the right-hand side of the expression
+ * (B, blah, and C in our example rule), and then push the result of the action
+ * back on to the stack with the resulting state reduced to (as described in the .out
+ * file)
+ * @param int Number of the rule by which to reduce
+ */
+ function yy_reduce($yyruleno)
+ {
+ //int $yygoto; /* The next state */
+ //int $yyact; /* The next action */
+ //mixed $yygotominor; /* The LHS of the rule reduced */
+ //yyStackEntry $yymsp; /* The top of the parser's stack */
+ //int $yysize; /* Amount to pop the stack */
+ $yymsp = $this->yystack[$this->yyidx];
+ if (self::$yyTraceFILE && $yyruleno >= 0
+ && $yyruleno < count(self::$yyRuleName)) {
+ fprintf(self::$yyTraceFILE, "%sReduce (%d) [%s].\n",
+ self::$yyTracePrompt, $yyruleno,
+ self::$yyRuleName[$yyruleno]);
+ }
+
+ $this->_retvalue = $yy_lefthand_side = null;
+ if (array_key_exists($yyruleno, self::$yyReduceMap)) {
+ // call the action
+ $this->_retvalue = null;
+ $this->{'yy_r' . self::$yyReduceMap[$yyruleno]}();
+ $yy_lefthand_side = $this->_retvalue;
+ }
+ $yygoto = self::$yyRuleInfo[$yyruleno]['lhs'];
+ $yysize = self::$yyRuleInfo[$yyruleno]['rhs'];
+ $this->yyidx -= $yysize;
+ for ($i = $yysize; $i; $i--) {
+ // pop all of the right-hand side parameters
+ array_pop($this->yystack);
+ }
+ $yyact = $this->yy_find_reduce_action($this->yystack[$this->yyidx]->stateno, $yygoto);
+ if ($yyact < self::YYNSTATE) {
+ /* If we are not debugging and the reduce action popped at least
+ ** one element off the stack, then we can push the new element back
+ ** onto the stack here, and skip the stack overflow test in yy_shift().
+ ** That gives a significant speed improvement. */
+ if (!self::$yyTraceFILE && $yysize) {
+ $this->yyidx++;
+ $x = new yyStackEntry;
+ $x->stateno = $yyact;
+ $x->major = $yygoto;
+ $x->minor = $yy_lefthand_side;
+ $this->yystack[$this->yyidx] = $x;
+ } else {
+ $this->yy_shift($yyact, $yygoto, $yy_lefthand_side);
+ }
+ } elseif ($yyact == self::YYNSTATE + self::YYNRULE + 1) {
+ $this->yy_accept();
+ }
+ }
+
+ /**
+ * The following code executes when the parse fails
+ *
+ * Code from %parse_fail is inserted here
+ */
+ function yy_parse_failed()
+ {
+ if (self::$yyTraceFILE) {
+ fprintf(self::$yyTraceFILE, "%sFail!\n", self::$yyTracePrompt);
+ }
+ while ($this->yyidx >= 0) {
+ $this->yy_pop_parser_stack();
+ }
+ /* Here code is inserted which will be executed whenever the
+ ** parser fails */
+ }
+
+ /**
+ * The following code executes when a syntax error first occurs.
+ *
+ * %syntax_error code is inserted here
+ * @param int The major type of the error token
+ * @param mixed The minor type of the error token
+ */
+ function yy_syntax_error($yymajor, $TOKEN)
+ {
+#line 4 "/var/www/coffeescript-php/grammar.y"
+
+ throw new SyntaxError(
+ 'unexpected '.$this->tokenName($yymajor).' in '.self::$FILE.':'
+ . (self::$LINE + 1).'.'
+ );
+#line 3157 "/var/www/coffeescript-php/grammar.php"
+ }
+
+ /**
+ * The following is executed when the parser accepts
+ *
+ * %parse_accept code is inserted here
+ */
+ function yy_accept()
+ {
+ if (self::$yyTraceFILE) {
+ fprintf(self::$yyTraceFILE, "%sAccept!\n", self::$yyTracePrompt);
+ }
+ while ($this->yyidx >= 0) {
+ $stack = $this->yy_pop_parser_stack();
+ }
+ /* Here code is inserted which will be executed whenever the
+ ** parser accepts */
+ }
+
+ /**
+ * The main parser program.
+ *
+ * The first argument is the major token number. The second is
+ * the token value string as scanned from the input.
+ *
+ * @param int $yymajor the token number
+ * @param mixed $yytokenvalue the token value
+ * @param mixed ... any extra arguments that should be passed to handlers
+ *
+ * @return void
+ */
+ function parse($token)
+ {
+ list($yymajor, $yytokenvalue, ) = $token ? $token : array(0, 0);
+ self::$LINE = isset($token[2]) ? $token[2] : -1;
+
+// $yyact; /* The parser action. */
+// $yyendofinput; /* True if we are at the end of input */
+ $yyerrorhit = 0; /* True if yymajor has invoked an error */
+
+ /* (re)initialize the parser, if necessary */
+ if ($this->yyidx === null || $this->yyidx < 0) {
+ /* if ($yymajor == 0) return; // not sure why this was here... */
+ $this->yyidx = 0;
+ $this->yyerrcnt = -1;
+ $x = new yyStackEntry;
+ $x->stateno = 0;
+ $x->major = 0;
+ $this->yystack = array();
+ array_push($this->yystack, $x);
+ }
+ $yyendofinput = ($yymajor==0);
+
+ if (self::$yyTraceFILE) {
+ fprintf(
+ self::$yyTraceFILE,
+ "%sInput %s\n",
+ self::$yyTracePrompt,
+ self::tokenName($yymajor)
+ );
+ }
+
+ do {
+ $yyact = $this->yy_find_shift_action($yymajor);
+ if ($yymajor < self::YYERRORSYMBOL
+ && !$this->yy_is_expected_token($yymajor)
+ ) {
+ // force a syntax error
+ $yyact = self::YY_ERROR_ACTION;
+ }
+ if ($yyact < self::YYNSTATE) {
+ $this->yy_shift($yyact, $yymajor, $yytokenvalue);
+ $this->yyerrcnt--;
+ if ($yyendofinput && $this->yyidx >= 0) {
+ $yymajor = 0;
+ } else {
+ $yymajor = self::YYNOCODE;
+ }
+ } elseif ($yyact < self::YYNSTATE + self::YYNRULE) {
+ $this->yy_reduce($yyact - self::YYNSTATE);
+ } elseif ($yyact == self::YY_ERROR_ACTION) {
+ if (self::$yyTraceFILE) {
+ fprintf(
+ self::$yyTraceFILE,
+ "%sSyntax Error!\n",
+ self::$yyTracePrompt
+ );
+ }
+ if (self::YYERRORSYMBOL) {
+ /* A syntax error has occurred.
+ ** The response to an error depends upon whether or not the
+ ** grammar defines an error token "ERROR".
+ **
+ ** This is what we do if the grammar does define ERROR:
+ **
+ ** * Call the %syntax_error function.
+ **
+ ** * Begin popping the stack until we enter a state where
+ ** it is legal to shift the error symbol, then shift
+ ** the error symbol.
+ **
+ ** * Set the error count to three.
+ **
+ ** * Begin accepting and shifting new tokens. No new error
+ ** processing will occur until three tokens have been
+ ** shifted successfully.
+ **
+ */
+ if ($this->yyerrcnt < 0) {
+ $this->yy_syntax_error($yymajor, $yytokenvalue);
+ }
+ $yymx = $this->yystack[$this->yyidx]->major;
+ if ($yymx == self::YYERRORSYMBOL || $yyerrorhit ) {
+ if (self::$yyTraceFILE) {
+ fprintf(
+ self::$yyTraceFILE,
+ "%sDiscard input token %s\n",
+ self::$yyTracePrompt,
+ self::tokenName($yymajor)
+ );
+ }
+ $this->yy_destructor($yymajor, $yytokenvalue);
+ $yymajor = self::YYNOCODE;
+ } else {
+ while ($this->yyidx >= 0
+ && $yymx != self::YYERRORSYMBOL
+ && ($yyact = $this->yy_find_shift_action(self::YYERRORSYMBOL)) >= self::YYNSTATE
+ ) {
+ $this->yy_pop_parser_stack();
+ }
+ if ($this->yyidx < 0 || $yymajor==0) {
+ $this->yy_destructor($yymajor, $yytokenvalue);
+ $this->yy_parse_failed();
+ $yymajor = self::YYNOCODE;
+ } elseif ($yymx != self::YYERRORSYMBOL) {
+ $u2 = 0;
+ $this->yy_shift($yyact, self::YYERRORSYMBOL, $u2);
+ }
+ }
+ $this->yyerrcnt = 3;
+ $yyerrorhit = 1;
+ } else {
+ /* YYERRORSYMBOL is not defined */
+ /* This is what we do if the grammar does not define ERROR:
+ **
+ ** * Report an error message, and throw away the input token.
+ **
+ ** * If the input token is $, then fail the parse.
+ **
+ ** As before, subsequent error messages are suppressed until
+ ** three input tokens have been successfully shifted.
+ */
+ if ($this->yyerrcnt <= 0) {
+ $this->yy_syntax_error($yymajor, $yytokenvalue);
+ }
+ $this->yyerrcnt = 3;
+ $this->yy_destructor($yymajor, $yytokenvalue);
+ if ($yyendofinput) {
+ $this->yy_parse_failed();
+ }
+ $yymajor = self::YYNOCODE;
+ }
+ } else {
+ $this->yy_accept();
+ $yymajor = self::YYNOCODE;
+ }
+ } while ($yymajor != self::YYNOCODE && $this->yyidx >= 0);
+
+ if ($token === NULL)
+ {
+ return $this->_retvalue;
+ }
+ }
+}
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/Rewriter.php b/sparks/assets/1.5.1/libraries/coffeescript/Rewriter.php
new file mode 100755
index 0000000..1c03a0d
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/Rewriter.php
@@ -0,0 +1,552 @@
+', '=>', '[', '(', '{', '--', '++'
+ );
+
+ static $IMPLICIT_UNSPACED_CALL = array('+', '-');
+
+ static $IMPLICIT_BLOCK = array('->', '=>', '{', '[', ',');
+
+ static $IMPLICIT_END = array('POST_IF', 'FOR', 'WHILE', 'UNTIL', 'WHEN', 'BY', 'LOOP', 'TERMINATOR');
+
+ static $SINGLE_LINERS = array('ELSE', '->', '=>', 'TRY', 'FINALLY', 'THEN');
+ static $SINGLE_CLOSERS = array('TERMINATOR', 'CATCH', 'FINALLY', 'ELSE', 'OUTDENT', 'LEADING_WHEN');
+
+ static $LINEBREAKS = array('TERMINATOR', 'INDENT', 'OUTDENT');
+
+ static $initialized = FALSE;
+
+ static function init()
+ {
+ if (self::$initialized) return;
+
+ self::$initialized = TRUE;
+
+ foreach (self::$BALANCED_PAIRS as $pair)
+ {
+ list($left, $rite) = $pair;
+
+ self::$EXPRESSION_START[] = self::$INVERSES[$rite] = $left;
+ self::$EXPRESSION_END[] = self::$INVERSES[$left] = $rite;
+ }
+
+ self::$EXPRESSION_CLOSE = array_merge(self::$EXPRESSION_CLOSE, self::$EXPRESSION_END);
+ }
+
+ function __construct($tokens)
+ {
+ self::init();
+
+ $this->tokens = $tokens;
+ }
+
+ function add_implicit_braces()
+ {
+ $stack = array();
+ $start = NULL;
+ $starts_line = NULL;
+ $same_line = TRUE;
+ $start_indent = 0;
+
+ $self = $this;
+
+ $condition = function( & $token, $i) use ( & $self, & $same_line, & $starts_line)
+ {
+ $list = array();
+
+ for ($j = 0; $j < 3; $j++)
+ {
+ $k = ($i + 1) + $j;
+ $list[$j] = isset($self->tokens[$k]) ? $self->tokens[$k] : array(NULL, NULL);
+ }
+
+ list($one, $two, $three) = $list;
+
+ if ($one[0] === t('HERECOMMENT'))
+ {
+ return FALSE;
+ }
+
+ $tag = $token[0];
+
+ if (in_array($tag, t(Rewriter::$LINEBREAKS)))
+ {
+ $same_line = FALSE;
+ }
+
+ return
+ ( (in_array($tag, t('TERMINATOR', 'OUTDENT')) || (in_array($tag, t(Rewriter::$IMPLICIT_END)) && $same_line)) &&
+ ( ( ! $starts_line && $self->tag($i - 1) !== t(',')) ||
+ ! ($two[0] === t(':') || $one[0] === t('@') && $three[0] === t(':'))) ) ||
+ ($tag === t(',') &&
+ ! in_array($one[0], t('IDENTIFIER', 'NUMBER', 'STRING', '@', 'TERMINATOR', 'OUTDENT')) );
+ };
+
+ $action = function( & $token, $i) use ( & $self)
+ {
+ $tok = $self->generate(t('}'), '}', $token[2]);
+ array_splice($self->tokens, $i, 0, array($tok));
+ };
+
+ $this->scan_tokens(function( & $token, $i, & $tokens) use (& $self, & $stack, & $start, & $start_indent, & $condition, & $action, & $starts_line, & $same_line)
+ {
+ if (in_array(($tag = $token[0]), t(Rewriter::$EXPRESSION_START)))
+ {
+ $stack[] = array( ($tag === t('INDENT') && $self->tag($i - 1) === t('{')) ? t('{') : $tag, $i );
+ return 1;
+ }
+
+ if (in_array($tag, t(Rewriter::$EXPRESSION_END)))
+ {
+ $start = array_pop($stack);
+ return 1;
+ }
+
+ $len = count($stack) - 1;
+
+ if ( ! ($tag === t(':') && (($ago = $self->tag($i - 2)) === t(':') || ( ! isset($stack[$len]) || $stack[$len][0] !== t('{'))) ))
+ {
+ return 1;
+ }
+
+ $same_line = TRUE;
+
+ $stack[] = array(t('{'));
+ $idx = (isset($ago) && $ago === t('@')) ? $i - 2 : $i - 1;
+
+ while ($self->tag($idx - 2) === t('HERECOMMENT'))
+ {
+ $idx -= 2;
+ }
+
+ $prev_tag = $self->tag($idx - 1);
+
+ $starts_line = ! $prev_tag || in_array($prev_tag, t(Rewriter::$LINEBREAKS));
+
+ $value = wrap('{');
+ $value->generated = TRUE;
+
+ $tok = $self->generate(t('{'), $value, $token[2]);
+
+ array_splice($tokens, $idx, 0, array($tok));
+
+ $self->detect_end($i + 2, $condition, $action);
+
+ return 2;
+ });
+ }
+
+ function add_implicit_indentation()
+ {
+ $self = $this;
+
+ $starter = $indent = $outdent = NULL;
+
+ $condition = function($token, $i) use ( & $starter)
+ {
+ return $token[1] !== ';' && in_array($token[0], t(Rewriter::$SINGLE_CLOSERS)) && ! ($token[0] === t('ELSE') && ! in_array($starter, t('IF', 'THEN')));
+ };
+
+ $action = function($token, $i) use ( & $self, & $outdent)
+ {
+ if ($outdent !== NULL)
+ {
+ array_splice($self->tokens, $self->tag($i - 1) === t(',') ? $i - 1 : $i, 0, array($outdent));
+ }
+ };
+
+ $this->scan_tokens(function( & $token, $i, & $tokens) use ( & $action, & $condition, & $self, & $indent, & $outdent, & $starter)
+ {
+ $tag = $token[0];
+
+ if ($tag === t('TERMINATOR') && $self->tag($i + 1) === t('THEN'))
+ {
+ array_splice($tokens, $i, 1);
+ return 0;
+ }
+
+ if ($tag === t('ELSE') && $self->tag($i - 1) !== t('OUTDENT'))
+ {
+ array_splice($tokens, $i, 0, $self->indentation($token));
+ return 2;
+ }
+
+ if ($tag === t('CATCH') && in_array($self->tag($i + 2), t('OUTDENT', 'TERMINATOR', 'FINALLY')))
+ {
+ array_splice($tokens, $i + 2, 0, $self->indentation($token));
+ return 4;
+ }
+
+ if (in_array($tag, t(Rewriter::$SINGLE_LINERS)) && $self->tag($i + 1) !== t('INDENT') &&
+ ! ($tag === t('ELSE') && $self->tag($i + 1) === t('IF')))
+ {
+ $starter = $tag;
+ list($indent, $outdent) = $self->indentation($token, TRUE);
+
+ if ($starter === t('THEN'))
+ {
+ $indent['fromThen'] = TRUE;
+ }
+
+ array_splice($tokens, $i + 1, 0, array($indent));
+
+ $self->detect_end($i + 2, $condition, $action);
+
+ if ($tag === t('THEN'))
+ {
+ array_splice($tokens, $i, 1);
+ }
+
+ return 1;
+ }
+
+ return 1;
+ });
+ }
+
+ function add_implicit_parentheses()
+ {
+ $no_call = $seen_single = $seen_control = FALSE;
+ $self = $this;
+
+ $condition = function( & $token, $i) use ( & $self, & $seen_single, & $seen_control, & $no_call)
+ {
+ $tag = $token[0];
+
+ if ( ! $seen_single && (isset($token['fromThen']) && $token['fromThen']))
+ {
+ return TRUE;
+ }
+
+ if (in_array($tag, t('IF', 'ELSE', 'CATCH', '->', '=>', 'CLASS')))
+ {
+ $seen_single = TRUE;
+ }
+
+ if (in_array($tag, t('IF', 'ELSE', 'SWITCH', 'TRY', '=')))
+ {
+ $seen_control = TRUE;
+ }
+
+ if (in_array($tag, t('.', '?.', '::')) && $self->tag($i - 1) === t('OUTDENT'))
+ {
+ return TRUE;
+ }
+
+ return ! (isset($token['generated']) && $token['generated']) && $self->tag($i - 1) !== t(',') &&
+ (in_array($tag, t(Rewriter::$IMPLICIT_END)) || ($tag === t('INDENT') && ! $seen_control)) &&
+ ($tag !== t('INDENT') ||
+ ( ! in_array($self->tag($i - 2), t('CLASS', 'EXTENDS')) && ! in_array($self->tag($i - 1), t(Rewriter::$IMPLICIT_BLOCK)) &&
+ ! (($post = isset($self->tokens[$i + 1]) ? $self->tokens[$i + 1] : NULL) && (isset($post['generated']) && $post['generated']) && $post[0] === t('{'))));
+ };
+
+ $action = function( & $token, $i) use ( & $self)
+ {
+ array_splice($self->tokens, $i, 0, array($self->generate(t('CALL_END'), ')', isset($token[2]) ? $token[2] : NULL)));
+ };
+
+ $this->scan_tokens(function( & $token, $i, & $tokens) use ( & $condition, & $action, & $no_call, & $self, & $seen_control, & $seen_single )
+ {
+ $tag = $token[0];
+
+ if (in_array($tag, t('CLASS', 'IF', 'FOR', 'WHILE')))
+ {
+ $no_call = TRUE;
+ }
+
+ $prev = NULL;
+
+ if (isset($tokens[$i - 1]))
+ {
+ $prev = & $tokens[$i - 1];
+ }
+
+ $current = $tokens[$i];
+ $next = isset($tokens[$i + 1]) ? $tokens[$i + 1] : NULL;
+
+ $call_object = ! $no_call && $tag === t('INDENT') &&
+ $next && (isset($next['generated']) && $next['generated']) && $next[0] === t('{') &&
+ $prev && in_array($prev[0], t(Rewriter::$IMPLICIT_FUNC));
+
+ $seen_single = FALSE;
+ $seen_control = FALSE;
+
+ if (in_array($tag, t(Rewriter::$LINEBREAKS)))
+ {
+ $no_call = FALSE;
+ }
+
+ if ($prev && ! (isset($prev['spaced']) && $prev['spaced']) && $tag === t('?'))
+ {
+ $token['call'] = TRUE;
+ }
+
+ if (isset($token['fromThen']) && $token['fromThen'])
+ {
+ return 1;
+ }
+
+ if ( ! ($call_object || ($prev && (isset($prev['spaced']) && $prev['spaced'])) &&
+ ( (isset($prev['call']) && $prev['call']) || in_array($prev[0], t(Rewriter::$IMPLICIT_FUNC)) ) &&
+ ( in_array($tag, t(Rewriter::$IMPLICIT_CALL)) || ! ( (isset($token['spaced']) && $token['spaced']) ||
+ (isset($token['newLine']) && $token['newLine']) ) &&
+ in_array($tag, t(Rewriter::$IMPLICIT_UNSPACED_CALL)) )
+ ))
+ {
+ return 1;
+ }
+
+ array_splice($tokens, $i, 0, array($self->generate(t('CALL_START'), '(', $token[2])));
+
+ $self->detect_end($i + 1, $condition, $action);
+
+ if ($prev[0] === t('?'))
+ {
+ $prev[0] = t('FUNC_EXIST');
+ }
+
+ return 2;
+ });
+ }
+
+ function close_open_calls()
+ {
+ $self = $this;
+
+ $condition = function($token, $i) use ( & $self)
+ {
+ return in_array($token[0], t(')', 'CALL_END')) || $token[0] === t('OUTDENT') &&
+ $self->tag($i - 1) === t(')');
+ };
+
+ $action = function($token, $i) use ( & $self)
+ {
+ $self->tokens[($token[0] === t('OUTDENT') ? $i - 1 : $i)][0] = t('CALL_END');
+ };
+
+ $this->scan_tokens(function($token, $i) use ( & $self, $condition, $action)
+ {
+ if ($token[0] === t('CALL_START'))
+ {
+ $self->detect_end($i + 1, $condition, $action);
+ }
+
+ return 1;
+ });
+ }
+
+ function close_open_indexes()
+ {
+ $condition = function($token, $i)
+ {
+ return in_array($token[0], t(']', 'INDEX_END'));
+ };
+
+ $action = function( & $token, $i)
+ {
+ $token[0] = t('INDEX_END');
+ };
+
+ $self = $this;
+
+ $this->scan_tokens(function($token, $i) use ( & $self, $condition, $action)
+ {
+ if ($token[0] === t('INDEX_START'))
+ {
+ $self->detect_end($i + 1, $condition, $action);
+ }
+
+ return 1;
+ });
+ }
+
+ function detect_end($i, $condition, $action)
+ {
+ $tokens = & $this->tokens;
+ $levels = 0;
+
+ while (isset($tokens[$i]))
+ {
+ $token = & $tokens[$i];
+
+ if ($levels === 0 && $condition($token, $i))
+ {
+ return $action($token, $i);
+ }
+
+ if ( ! $token || $levels < 0)
+ {
+ return $action($token, $i - 1);
+ }
+
+ if (in_array($token[0], t(Rewriter::$EXPRESSION_START)))
+ {
+ $levels++;
+ }
+ else if (in_array($token[0], t(Rewriter::$EXPRESSION_END)))
+ {
+ $levels--;
+ }
+
+ $i++;
+ }
+
+ return $i - 1;
+ }
+
+ function generate($tag, $value, $line)
+ {
+ return array($tag, $value, $line, 'generated' => TRUE);
+ }
+
+ function indentation($token, $implicit = FALSE)
+ {
+ $indent = array(t('INDENT'), 2, $token[2]);
+ $outdent = array(t('OUTDENT'), 2, $token[2]);
+
+ if ($implicit)
+ {
+ $indent['generated'] = $outdent['generated'] = TRUE;
+ }
+
+ return array($indent, $outdent);
+ }
+
+ function remove_leading_newlines()
+ {
+ $key = 0;
+
+ foreach ($this->tokens as $k => $token)
+ {
+ $key = $k;
+ $tag = $token[0];
+
+ if ($tag !== t('TERMINATOR'))
+ {
+ break;
+ }
+ }
+
+ if ($key)
+ {
+ array_splice($this->tokens, 0, $key);
+ }
+ }
+
+ function remove_mid_expression_newlines()
+ {
+ $self = $this;
+
+ $this->scan_tokens(function( & $token, $i, & $tokens) use ( & $self)
+ {
+ if ( ! ($token[0] === t('TERMINATOR') && in_array($self->tag($i + 1), t(Rewriter::$EXPRESSION_CLOSE))))
+ {
+ return 1;
+ }
+
+ array_splice($tokens, $i, 1);
+ return 0;
+ });
+ }
+
+ function rewrite()
+ {
+ $this->remove_leading_newlines();
+ $this->remove_mid_expression_newlines();
+ $this->close_open_calls();
+ $this->close_open_indexes();
+ $this->add_implicit_indentation();
+ $this->tag_postfix_conditionals();
+ $this->add_implicit_braces();
+ $this->add_implicit_parentheses();
+
+ return $this->tokens;
+ }
+
+ function scan_tokens($block)
+ {
+ $i = 0;
+
+ while (isset($this->tokens[$i]))
+ {
+ $i += $block($this->tokens[$i], $i, $this->tokens);
+ }
+
+ return TRUE;
+ }
+
+ function tag($i)
+ {
+ return isset($this->tokens[$i]) ? $this->tokens[$i][0] : NULL;
+ }
+
+ function tag_postfix_conditionals()
+ {
+ $original = NULL;
+
+ $self = $this;
+
+ $condition = function($token, $i)
+ {
+ return in_array($token[0], t('TERMINATOR', 'INDENT'));
+ };
+
+ $action = function($token, $i) use ( & $original, & $self)
+ {
+ if ($token[0] !== t('INDENT') || ((isset($token['generated']) && $token['generated']) && ! (isset($token['fromThen']) && $token['fromThen'])))
+ {
+ $self->tokens[$original][0] = t('POST_'.t_canonical($self->tokens[$original][0]));
+
+ // $original[0] = t('POST_'.t_canonical($original[0]));
+ }
+ };
+
+ $self = $this;
+
+ $this->scan_tokens(function( & $token, $i) use ( & $original, & $condition, & $action, & $self)
+ {
+ if ( ! ($token[0] === t('IF')))
+ {
+ return 1;
+ }
+
+ $original = $i;
+
+ // $original = & $token;
+
+ $self->detect_end($i + 1, $condition, $action);
+
+ return 1;
+ });
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/Scope.php b/sparks/assets/1.5.1/libraries/coffeescript/Scope.php
new file mode 100755
index 0000000..bb52c12
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/Scope.php
@@ -0,0 +1,196 @@
+parent = $parent;
+ $this->expressions = $expressions;
+ $this->method = $method;
+
+ $this->variables = array(
+ array('name' => 'arguments', 'type' => 'arguments')
+ );
+
+ $this->positions = array();
+
+ if ( ! $this->parent)
+ {
+ self::$root = $this;
+ }
+ }
+
+ function add($name, $type, $immediate = FALSE)
+ {
+ $name = ''.$name;
+
+ if ($this->shared && ! $immediate)
+ {
+ return $this->parent->add($name, $type, $immediate);
+ }
+
+ if (isset($this->positions[$name]))
+ {
+ $this->variables[$this->positions[$name]]['type'] = $type;
+ }
+ else
+ {
+ $this->variables[] = array('name' => $name, 'type' => $type);
+ $this->positions[$name] = count($this->variables) - 1;
+ }
+ }
+
+ function assign($name, $value)
+ {
+ $this->add($name, array('value' => $value, 'assigned' => TRUE), TRUE);
+ $this->has_assignments = TRUE;
+ }
+
+ function assigned_variables()
+ {
+ $tmp = array();
+
+ foreach ($this->variables as $v)
+ {
+ $type = $v['type'];
+
+ if (is_array($type) && isset($type['assigned']) && $type['assigned'])
+ {
+ $tmp[] = "{$v['name']} = {$type['value']}";
+ }
+ }
+
+ return $tmp;
+ }
+
+ function check($name, $immediate = FALSE)
+ {
+ $name = ''.$name;
+
+ $found = !! $this->type($name);
+
+ if ($found || $immediate)
+ {
+ return $found;
+ }
+
+ return $this->parent ? $this->parent->check($name) : FALSE;
+ }
+
+ function declared_variables()
+ {
+ $real_vars = array();
+ $temp_vars = array();
+
+ foreach ($this->variables as $v)
+ {
+ if ($v['type'] === 'var')
+ {
+ if ($v['name']{0} === '_')
+ {
+ $temp_vars[] = $v['name'];
+ }
+ else
+ {
+ $real_vars[] = $v['name'];
+ }
+ }
+ }
+
+ asort($real_vars);
+ asort($temp_vars);
+
+ return array_merge($real_vars, $temp_vars);
+ }
+
+ function find($name, $options = array())
+ {
+ if ($this->check($name, $options))
+ {
+ return TRUE;
+ }
+
+ $this->add($name, 'var');
+
+ return FALSE;
+ }
+
+ function free_variable($name, $reserve = TRUE)
+ {
+ $index = 0;
+
+ while ($this->check(($temp = $this->temporary($name, $index))))
+ {
+ $index++;
+ }
+
+ if ($reserve)
+ {
+ $this->add($temp, 'var', TRUE);
+ }
+
+ return $temp;
+ }
+
+ function has_assignments()
+ {
+ return $this->has_assignments;
+ }
+
+ function has_declarations()
+ {
+ return !! count($this->declared_variables());
+ }
+
+ function parameter($name)
+ {
+ if ($this->shared && $this->parent->check($name, TRUE))
+ {
+ return;
+ }
+
+ $this->add($name, 'param');
+ }
+
+ function temporary($name, $index)
+ {
+ if (strlen($name) > 1)
+ {
+ return '_'.$name.($index > 1 ? $index - 1 : '');
+ }
+ else
+ {
+ $val = strval(base_convert($index + intval($name, 36), 10, 36));
+ $val = preg_replace('/\d/', 'a', $val);
+
+ return '_'.$val;
+ }
+ }
+
+ function type($name)
+ {
+ foreach ($this->variables as $v)
+ {
+ if ($v['name'] === $name)
+ {
+ return $v['type'];
+ }
+ }
+
+ return NULL;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/SyntaxError.php b/sparks/assets/1.5.1/libraries/coffeescript/SyntaxError.php
new file mode 100755
index 0000000..680c066
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/SyntaxError.php
@@ -0,0 +1,9 @@
+
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/Value.php b/sparks/assets/1.5.1/libraries/coffeescript/Value.php
new file mode 100755
index 0000000..c1998ac
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/Value.php
@@ -0,0 +1,20 @@
+v = $v;
+ }
+
+ function __toString()
+ {
+ return $this->v;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Access.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Access.php
new file mode 100755
index 0000000..b014b0d
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Access.php
@@ -0,0 +1,31 @@
+name = $name;
+ $this->name->as_key = TRUE;
+
+ $this->soak = $tag === 'soak';
+
+ return $this;
+ }
+
+ function compile($options, $level = NULL)
+ {
+ $name = $this->name->compile($options);
+ return preg_match(IDENTIFIER, $name) ? ".{$name}" : "[{$name}]";
+ }
+
+ function is_complex()
+ {
+ return FALSE;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Arr.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Arr.php
new file mode 100755
index 0000000..cb37656
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Arr.php
@@ -0,0 +1,69 @@
+objects = $objs ? $objs : array();
+
+ return $this;
+ }
+
+ function assigns($name)
+ {
+ foreach ($this->objects as $obj)
+ {
+ if ($obj->assigns($name))
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+ }
+
+ function compile_node($options)
+ {
+ if ( ! count($options))
+ {
+ return '[]';
+ }
+
+ $options['indent'] .= TAB;
+ $objs = $this->filter_implicit_objects($this->objects);
+
+ if (($code = yy_Splat::compile_splatted_array($options, $objs)))
+ {
+ return $code;
+ }
+
+ $code = array();
+
+ foreach ($objs as $obj)
+ {
+ $code[] = $obj->compile($options);
+ }
+
+ $code = implode(', ', $code);
+
+ if (strpos($code, "\n") !== FALSE)
+ {
+ return "[\n{$options['indent']}{$code}\n{$this->tab}]";
+ }
+ else
+ {
+ return "[{$code}]";
+ }
+ }
+
+ function filter_implicit_objects()
+ {
+ return call_user_func_array(array(yy('Call'), __FUNCTION__), func_get_args());
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Assign.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Assign.php
new file mode 100755
index 0000000..73af70b
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Assign.php
@@ -0,0 +1,350 @@
+variable = $variable;
+ $this->value = $value;
+ $this->context = $context;
+ $this->param = $options ? $options['param'] : NULL;
+
+ $this->subpattern = isset($options['subpattern']) ? $options['subpattern'] : NULL;
+
+ $tmp = $this->variable->unwrap_all();
+
+ $forbidden = in_array($name = isset($tmp->value) ? $tmp->value : NULL, Lexer::$STRICT_PROSCRIBED);
+
+ if ($forbidden && $this->context !== 'object')
+ {
+ throw new SyntaxError("variable name may not be $name");
+ }
+
+ return $this;
+ }
+
+ function assigns($name)
+ {
+ if ($this->context === 'object')
+ {
+ return $this->value->assigns($name);
+ }
+ else
+ {
+ return $this->variable->assigns($name);
+ }
+ }
+
+ function compile_conditional($options)
+ {
+ list($left, $right) = $this->variable->cache_reference($options);
+
+ if ( ! count($left->properties) && $left->base instanceof yy_Literal && $left->base->value !== 'this' && ! $options['scope']->check($left->base->value))
+ {
+ throw new Error('the variable "'.$this->left->base->value.'" can\'t be assigned with '.$this->context.' because it has not been defined.');
+ }
+
+ if (strpos($this->context, '?') > -1)
+ {
+ $options['isExistentialEquals'] = TRUE;
+ }
+
+ $tmp = yy('Op', substr($this->context, 0, -1), $left, yy('Assign', $right, $this->value, '='));
+
+ return $tmp->compile($options);
+ }
+
+ function compile_node($options)
+ {
+ if (($is_value = ($this->variable instanceof yy_Value)))
+ {
+ if ($this->variable->is_array() || $this->variable->is_object())
+ {
+ return $this->compile_pattern_match($options);
+ }
+
+ if ($this->variable->is_splice())
+ {
+ return $this->compile_splice($options);
+ }
+
+ if (in_array($this->context, array('||=', '&&=', '?='), TRUE))
+ {
+ return $this->compile_conditional($options);
+ }
+ }
+
+ $name = $this->variable->compile($options, LEVEL_LIST);
+
+ if ( ! $this->context)
+ {
+ if ( ! ( ($var_base = $this->variable->unwrap_all()) && $var_base->is_assignable()))
+ {
+ throw new SyntaxError('"'.$this->variable->compile($options).'" cannot be assigned.');
+ }
+
+ if ( ! (is_callable(array($var_base, 'has_properties')) && $var_base->has_properties()))
+ {
+ if ($this->param)
+ {
+ $options['scope']->add($name, 'var');
+ }
+ else
+ {
+ $options['scope']->find($name);
+ }
+ }
+ }
+
+ if ($this->value instanceof yy_Code && preg_match(METHOD_DEF, ''.$name, $match))
+ {
+ if (isset($match[1]) && $match[1] !== '')
+ {
+ $this->value->klass = $match[1];
+ }
+
+ foreach (range(2, 5) as $i)
+ {
+ if (isset($match[$i]) && $match[$i] !== '')
+ {
+ $this->value->name = $match[$i];
+ break;
+ }
+ }
+ }
+
+ $val = $this->value->compile($options, LEVEL_LIST);
+
+ if ($this->context === 'object')
+ {
+ return "{$name}: {$val}";
+ }
+
+ $val = $name.' '.($this->context ? $this->context : '=').' '.$val;
+
+ return $options['level'] <= LEVEL_LIST ? $val : "({$val})";
+ }
+
+ function compile_pattern_match($options)
+ {
+ $top = $options['level'] === LEVEL_TOP;
+ $value = $this->value;
+ $objects = $this->variable->base->objects;
+
+ if ( ! ($olen = count($objects)))
+ {
+ $code = $value->compile($options);
+ return $options['level'] >= LEVEL_OP ? "({$code})" : $code;
+ }
+
+ $is_object = $this->variable->is_object();
+
+ if ($top && $olen === 1 && ! (($obj = $objects[0]) instanceof yy_Splat))
+ {
+ if ($obj instanceof yy_Assign)
+ {
+ $idx = $obj->variable->base;
+ $obj = $obj->value;
+ }
+ else
+ {
+ if ($obj->base instanceof yy_Parens)
+ {
+ $tmp = yy('Value', $obj->unwrap_all());
+ list($obj, $idx) = $tmp->cache_reference($options);
+ }
+ else
+ {
+ if ($is_object)
+ {
+ $idx = $obj->this ? $obj->properties[0]->name : $obj;
+ }
+ else
+ {
+ $idx = yy('Literal', 0);
+ }
+ }
+ }
+
+ $acc = preg_match(IDENTIFIER, $idx->unwrap()->value);
+ $value = yy('Value', $value);
+
+ if ($acc)
+ {
+ $value->properties[] = yy('Access', $idx);
+ }
+ else
+ {
+ $value->properties[] = yy('Index', $idx);
+ }
+
+ $tmp = $obj->unwrap();
+ $tmp = isset($tmp->value) ? $tmp->value : NULL;
+
+ if (in_array($tmp, Lexer::$COFFEE_RESERVED))
+ {
+ throw new SyntaxError('assignment to a reserved word: '.$obj->compile($options).' = '.$value->compile($options));
+ }
+
+ return yy('Assign', $obj, $value, NULL, array('param' => $this->param))->compile($options, LEVEL_TOP);
+ }
+
+ $vvar = $value->compile($options, LEVEL_LIST);
+ $assigns = array();
+ $splat = FALSE;
+
+ if ( ! preg_match(IDENTIFIER, $vvar) || $this->variable->assigns($vvar))
+ {
+ $assigns[] = ($ref = $options['scope']->free_variable('ref')).' = '.$vvar;
+ $vvar = $ref;
+ }
+
+ foreach ($objects as $i => $obj)
+ {
+ $idx = $i;
+
+ if ($is_object)
+ {
+ if ($obj instanceof yy_Assign)
+ {
+ $idx = $obj->variable->base;
+ $obj = $obj->value;
+ }
+ else
+ {
+ if ($obj->base instanceof yy_Parens)
+ {
+ $tmp = yy('Value', $obj->unwrap_all());
+ list($obj, $idx) = $tmp->cache_reference($options);
+ }
+ else
+ {
+ $idx = $obj->this ? $obj->properties[0]->name : $obj;
+ }
+ }
+ }
+
+ if ( ! $splat && ($obj instanceof yy_Splat))
+ {
+ $name = $obj->name->unwrap()->value;
+ $obj = $obj->unwrap();
+
+ $val = "{$olen} <= {$vvar}.length ? ".utility('slice').".call({$vvar}, {$i}";
+ $ivar = 'undefined';
+
+ if (($rest = $olen - $i - 1))
+ {
+ $ivar = $options['scope']->free_variable('i');
+ $val .= ", {$ivar} = {$vvar}.length - {$rest}) : ({$ivar} = {$i}, [])";
+ }
+ else
+ {
+ $val .= ') : []';
+ }
+
+ $val = yy('Literal', $val);
+ $splat = "{$ivar}++";
+ }
+ else
+ {
+ $name = $obj->unwrap();
+ $name = isset($name->value) ? $name->value : NULL;
+
+ if ($obj instanceof yy_Splat)
+ {
+ $obj = $obj->name->compile($options);
+ throw new SyntaxError("multiple splats are disallowed in an assignment: {$obj}...");
+ }
+
+ if (is_numeric($idx))
+ {
+ $idx = yy('Literal', $splat ? $splat : $idx);
+ $acc = FALSE;
+ }
+ else
+ {
+ $acc = $is_object ? preg_match(IDENTIFIER, $idx->unwrap()->value) : 0;
+ }
+
+ $val = yy('Value', yy('Literal', $vvar), array($acc ? yy('Access', $idx) : yy('Index', $idx)));
+ }
+
+ if (isset($name) && $name && in_array($name, Lexer::$COFFEE_RESERVED))
+ {
+ throw new SyntaxError("assignment to a reserved word: ".$obj->compile($options).' = '.$val->compile($options));
+ }
+
+ $tmp = yy('Assign', $obj, $val, NULL, array('param' => $this->param, 'subpattern' => TRUE));
+ $assigns[] = $tmp->compile($options, LEVEL_TOP);
+ }
+
+ if ( ! ($top || $this->subpattern))
+ {
+ $assigns[] = $vvar;
+ }
+
+ $code = implode(', ', $assigns);
+
+ return $options['level'] < LEVEL_LIST ? $code : "({$code})";
+ }
+
+ function compile_splice($options)
+ {
+ $tmp = array_pop($this->variable->properties);
+
+ $from = $tmp->range->from;
+ $to = $tmp->range->to;
+ $exclusive = $tmp->range->exclusive;
+
+ $name = $this->variable->compile($options);
+
+ list($from_decl, $from_ref) = $from ? $from->cache($options, LEVEL_OP) : array('0', '0');
+
+ if ($to)
+ {
+ if (($from && $from->is_simple_number()) && $to->is_simple_number())
+ {
+ $to = intval($to->compile($options)) - intval($from_ref);
+
+ if ( ! $exclusive)
+ {
+ $to++;
+ }
+ }
+ else
+ {
+ $to = $to->compile($options, LEVEL_ACCESS).' - '. $from_ref;
+
+ if ( ! $exclusive)
+ {
+ $to .= ' + 1';
+ }
+ }
+ }
+ else
+ {
+ $to = '9e9';
+ }
+
+ list($val_def, $val_ref) = $this->value->cache($options, LEVEL_LIST);
+
+ $code = "[].splice.apply({$name}, [{$from_decl}, {$to}].concat({$val_def})), {$val_ref}";
+ return $options['level'] > LEVEL_TOP ? "({$code})" : $code;
+ }
+
+ function is_statement($options)
+ {
+ return isset($options['level']) && $options['level'] === LEVEL_TOP && $this->context && strpos($this->context, '?') > -1;
+ }
+
+ function unfold_soak($options)
+ {
+ return unfold_soak($options, $this, 'variable');
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Base.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Base.php
new file mode 100755
index 0000000..e8e9a7b
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Base.php
@@ -0,0 +1,295 @@
+to_string();
+ }
+
+ function cache($options, $level = NULL, $reused = NULL)
+ {
+ if ( ! $this->is_complex())
+ {
+ $ref = $level ? $this->compile($options, $level) : $this;
+ return array($ref, $ref);
+ }
+ else
+ {
+ $ref = yy('Literal', $reused ? $reused : $options['scope']->free_variable('ref'));
+ $sub = yy('Assign', $ref, $this);
+
+ if ($level)
+ {
+ return array($sub->compile($options, $level), $ref->value);
+ }
+ else
+ {
+ return array($sub, $ref);
+ }
+ }
+ }
+
+ function compile($options, $level = NULL)
+ {
+ if (isset($level))
+ {
+ $options['level'] = $level;
+ }
+
+ if ( ! ($node = $this->unfold_soak($options)))
+ {
+ $node = $this;
+ }
+
+ $node->tab = $options['indent'];
+
+ if ($options['level'] === LEVEL_TOP || ! $node->is_statement($options))
+ {
+ return $node->compile_node($options);
+ }
+
+ return $node->compile_closure($options);
+ }
+
+ function compile_closure($options)
+ {
+ if ($this->jumps())
+ {
+ throw new SyntaxError('cannot use a pure statement in an expression.');
+ }
+
+ $options['sharedScope'] = TRUE;
+
+ $closure = yy_Closure::wrap($this);
+
+ return $closure->compile_node($options);
+ }
+
+ function compile_loop_reference($options, $name)
+ {
+ $src = $tmp = $this->compile($options, LEVEL_LIST);
+
+ if ( ! ( ($src === 0 || $src === '') || preg_match(IDENTIFIER, $src) &&
+ $options['scope']->check($src, TRUE)))
+ {
+ $src = ($tmp = $options['scope']->free_variable($name)).' = '.$src;
+ }
+
+ return array($src, $tmp);
+ }
+
+ function contains($pred)
+ {
+ $contains = FALSE;
+
+ if (is_string($pred))
+ {
+ $tmp = __NAMESPACE__.'\\'.$pred;
+
+ $pred = function($node) use ($tmp)
+ {
+ return call_user_func($tmp, $node);
+ };
+ }
+
+ $this->traverse_children(FALSE, function($node) use ( & $contains, & $pred)
+ {
+ if ($pred($node))
+ {
+ $contains = TRUE;
+ return FALSE;
+ }
+ });
+
+ return $contains;
+ }
+
+ function contains_type($type)
+ {
+ return ($this instanceof $type) || $this->contains(function($node) use ( & $type)
+ {
+ return $node instanceof $type;
+ });
+ }
+
+ function each_child($func)
+ {
+ if ( ! ($this->children))
+ {
+ return $this;
+ }
+
+ foreach ($this->children as $i => $attr)
+ {
+ if (isset($this->{$attr}) && $this->{$attr})
+ {
+ foreach (flatten(array($this->{$attr})) as $i => $child)
+ {
+ if ($func($child) === FALSE)
+ {
+ break 2;
+ }
+ }
+ }
+ }
+
+ return $this;
+ }
+
+ function invert()
+ {
+ return yy('Op', '!', $this);
+ }
+
+ function assigns()
+ {
+ return FALSE;
+ }
+
+ function is_assignable()
+ {
+ return FALSE;
+ }
+
+ function is_complex()
+ {
+ return TRUE;
+ }
+
+ function is_chainable()
+ {
+ return FALSE;
+ }
+
+ function is_object()
+ {
+ return FALSE;
+ }
+
+ function is_statement()
+ {
+ return FALSE;
+ }
+
+ function is_undefined()
+ {
+ return FALSE;
+ }
+
+ function jumps()
+ {
+ return FALSE;
+ }
+
+ function last_non_comment($list)
+ {
+ $i = count($list);
+
+ while ($i--)
+ {
+ if ( ! ($list[$i] instanceof yy_Comment))
+ {
+ return $list[$i];
+ }
+ }
+
+ return NULL;
+ }
+
+ function make_return($res = NULL)
+ {
+ $me = $this->unwrap_all();
+
+ if ($res)
+ {
+ return yy('Call', yy('Literal', "{$res}.push"), array($me));
+ }
+ else
+ {
+ return yy('Return', $me);
+ }
+ }
+
+ function to_string($idt = '', $name = NULL)
+ {
+ if ($name === NULL)
+ {
+ $name = get_class($this);
+ }
+
+ $tree = "\n{$idt}{$name}";
+
+ if ($this->soak)
+ {
+ $tree .= '?';
+ }
+
+ $this->each_child(function($node) use ($idt, & $tree)
+ {
+ $tree .= $node->to_string($idt.TAB);
+ });
+
+ return $tree;
+ }
+
+ function traverse_children($cross_scope, $func)
+ {
+ $this->each_child(function($child) use ($cross_scope, & $func)
+ {
+ if ($func($child) === FALSE)
+ {
+ return FALSE;
+ }
+
+ return $child->traverse_children($cross_scope, $func);
+ });
+ }
+
+ function unfold_soak($options)
+ {
+ return FALSE;
+ }
+
+ function unwrap()
+ {
+ return $this;
+ }
+
+ function unwrap_all()
+ {
+ $node = $this;
+
+ while ($node !== ($node = $node->unwrap()))
+ {
+ continue;
+ }
+
+ return $node;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Block.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Block.php
new file mode 100755
index 0000000..3b2e34d
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Block.php
@@ -0,0 +1,294 @@
+expressions = compact(flatten($nodes));
+
+ return $this;
+ }
+
+ function compile($options, $level = NULL)
+ {
+ if (isset($options['scope']))
+ {
+ return parent::compile($options, $level);
+ }
+ else
+ {
+ return $this->compile_root($options);
+ }
+ }
+
+ function compile_node($options)
+ {
+ $this->tab = $options['indent'];
+
+ $top = $options['level'] === LEVEL_TOP;
+ $codes = array();
+
+ foreach ($this->expressions as $i => $node)
+ {
+ $node = $node->unwrap_all();
+ $node = ($tmp = $node->unfold_soak($options)) ? $tmp : $node;
+
+ if ($node instanceof yy_Block)
+ {
+ $codes[] = $node->compile_node($options);
+ }
+ else if ($top)
+ {
+ $node->front = TRUE;
+ $code = $node->compile($options);
+
+ if ( ! $node->is_statement($options))
+ {
+ $code = "{$this->tab}{$code};";
+
+ if ($node instanceof yy_Literal)
+ {
+ $code = "{$code}\n";
+ }
+ }
+
+ $codes[] = $code;
+ }
+ else
+ {
+ $codes[] = $node->compile($options, LEVEL_LIST);
+ }
+ }
+
+ if ($top)
+ {
+ if (isset($this->spaced) && $this->spaced)
+ {
+ return "\n".implode("\n\n", $codes)."\n";
+ }
+ else
+ {
+ return implode("\n", $codes);
+ }
+ }
+
+ $code = ($tmp = implode(', ', $codes)) ? $tmp : 'void 0';
+
+ if (count($codes) && $options['level'] >= LEVEL_LIST)
+ {
+ return "({$code})";
+ }
+ else
+ {
+ return $code;
+ }
+ }
+
+ function compile_root($options)
+ {
+ $options['indent'] = isset($options['bare']) && $options['bare'] ? '' : TAB;
+ $options['scope'] = new Scope(NULL, $this, NULL);
+ $options['level'] = LEVEL_TOP;
+
+ $this->spaced = TRUE;
+ $prelude = '';
+
+ if ( ! (isset($options['bare']) && $options['bare']))
+ {
+ $prelude_exps = array();
+
+ foreach ($this->expressions as $i => $exp)
+ {
+ if ( ! ($exp->unwrap() instanceof yy_Comment))
+ {
+ break;
+ }
+
+ $prelude_exps[] = $exp;
+ }
+
+ $rest = array_slice($this->expressions, count($prelude_exps));
+ $this->expressions = $prelude_exps;
+
+ if ($prelude_exps)
+ {
+ $prelude = $this->compile_node(array_merge($options, array('indent' => '')))."\n";
+ }
+
+ $this->expressions = $rest;
+ }
+
+ $code = $this->compile_with_declarations($options);
+
+ if (isset($options['bare']) && $options['bare'])
+ {
+ return $code;
+ }
+
+ return "{$prelude}(function() {\n{$code}\n}).call(this);\n";
+ }
+
+ function compile_with_declarations($options)
+ {
+ $code = $post = '';
+
+ foreach ($this->expressions as $i => & $expr)
+ {
+ $expr = $expr->unwrap();
+
+ if ( ! ($expr instanceof yy_Comment || $expr instanceof yy_Literal))
+ {
+ break;
+ }
+ }
+
+ $options = array_merge($options, array('level' => LEVEL_TOP));
+
+ if ($i)
+ {
+ $rest = array_splice($this->expressions, $i, count($this->expressions));
+
+ list($spaced, $this->spaced) = array(isset($this->spaced) && $this->spaced, FALSE);
+ list($code, $this->spaced) = array($this->compile_node($options), $spaced);
+
+ $this->expressions = $rest;
+ }
+
+ $post = $this->compile_node($options);
+
+ $scope = $options['scope'];
+
+ if ($scope->expressions === $this)
+ {
+ $declars = $scope->has_declarations();
+ $assigns = $scope->has_assignments();
+
+ if ($declars or $assigns)
+ {
+ if ($i)
+ {
+ $code .= "\n";
+ }
+
+ $code .= $this->tab.'var ';
+
+ if ($declars)
+ {
+ $code .= implode(', ', $scope->declared_variables());
+ }
+
+ if ($assigns)
+ {
+ if ($declars)
+ {
+ $code .= ",\n{$this->tab}".TAB;
+ }
+
+ $code .= implode(",\n{$this->tab}".TAB, $scope->assigned_variables());
+ }
+
+ $code .= ";\n";
+ }
+ }
+
+ return $code.$post;
+ }
+
+ function is_empty()
+ {
+ return ! count($this->expressions);
+ }
+
+ function is_statement($options)
+ {
+ foreach ($this->expressions as $i => $expr)
+ {
+ if ($expr->is_statement($options))
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+ }
+
+ function jumps($options = array())
+ {
+ foreach ($this->expressions as $i => $expr)
+ {
+ if ($expr->jumps($options))
+ {
+ return $expr;
+ }
+ }
+
+ return FALSE;
+ }
+
+ function make_return($res = NULL)
+ {
+ $len = count($this->expressions);
+
+ while ($len--)
+ {
+ $expr = $this->expressions[$len];
+
+ if ( ! ($expr instanceof yy_Comment))
+ {
+ $this->expressions[$len] = $expr->make_return($res);
+
+ if ($expr instanceof yy_Return && ! $expr->expression)
+ {
+ return array_splice($this->expressions, $len, 1);
+ }
+
+ break;
+ }
+ }
+
+ return $this;
+ }
+
+ function pop()
+ {
+ return array_pop($this->expressions);
+ }
+
+ function push($node)
+ {
+ $this->expressions[] = $node;
+ return $this;
+ }
+
+ function unshift($node)
+ {
+ array_unshift($this->expressions, $node);
+ return $this;
+ }
+
+ function unwrap()
+ {
+ return count($this->expressions) === 1 ? $this->expressions[0] : $this;
+ }
+
+ static function wrap($nodes)
+ {
+ if ( ! is_array($nodes))
+ {
+ $nodes = array($nodes);
+ }
+
+ if (count($nodes) === 1 && $nodes[0] instanceof yy_Block)
+ {
+ return $nodes[0];
+ }
+
+ return yy('Block', $nodes);
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Call.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Call.php
new file mode 100755
index 0000000..0701145
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Call.php
@@ -0,0 +1,283 @@
+args = $args;
+ $this->is_new = FALSE;
+ $this->is_super = $variable === 'super';
+ $this->variable = $this->is_super() ? NULL : $variable;
+ $this->soak = $soak;
+
+ return $this;
+ }
+
+ function compile_node($options)
+ {
+ if ($this->variable)
+ {
+ $this->variable->front = $this->front;
+ }
+
+ if (($code = yy_Splat::compile_splatted_array($options, $this->args, TRUE)))
+ {
+ return $this->compile_splat($options, $code);
+ }
+
+ $args = $this->filter_implicit_objects($this->args);
+ $tmp = array();
+
+ foreach ($args as $arg)
+ {
+ $tmp[] = $arg->compile($options, LEVEL_LIST);
+ }
+
+ $args = implode(', ', $tmp);
+
+ if ($this->is_super())
+ {
+ return $this->super_reference($options).'.call(this'.($args ? ', '.$args : '').')';
+ }
+ else
+ {
+ return ($this->is_new() ? 'new ' : '').$this->variable->compile($options, LEVEL_ACCESS)."({$args})";
+ }
+ }
+
+ function compile_super($args, $options)
+ {
+ return $this->super_reference($options).'.call(this'.(count($args) ? ', ' : '').$args.')';
+ }
+
+ function compile_splat($options, $splat_args)
+ {
+ if ($this->is_super())
+ {
+ return $this->super_reference($options).'.apply(this, '.$splat_args.')';
+ }
+
+ if ($this->is_new())
+ {
+ $idt = $this->tab.TAB;
+
+ return
+ "(function(func, args, ctor) {\n"
+ . "{$idt}ctor.prototype = func.prototype;\n"
+ . "{$idt}var child = new ctor, result = func.apply(child, args), t = typeof result;\n"
+ . "{$idt}return t == \"object\" || t == \"function\" ? result || child : child;\n"
+ . "{$this->tab}})(".$this->variable->compile($options, LEVEL_LIST).", $splat_args, function(){})";
+ }
+
+ $base = yy('Value', $this->variable);
+
+ if (($name = array_pop($base->properties)) && $base->is_complex())
+ {
+ $ref = $options['scope']->free_variable('ref');
+ $fun = "($ref = ".$base->compile($options, LEVEL_LIST).')'.$name->compile($options).'';
+ }
+ else
+ {
+ $fun = $base->compile($options, LEVEL_ACCESS);
+ $fun = preg_match(SIMPLENUM, $fun) ? "($fun)" : $fun;
+
+ if ($name)
+ {
+ $ref = $fun;
+ $fun .= $name->compile($options);
+ }
+ else
+ {
+ $ref = NULL;
+ }
+ }
+
+ $ref = $ref === NULL ? 'null' : $ref;
+
+ return "{$fun}.apply({$ref}, {$splat_args})";
+ }
+
+ function is_new($set = NULL)
+ {
+ if ($set !== NULL)
+ {
+ $this->is_new = !! $set;
+ }
+
+ return $this->is_new;
+ }
+
+ function is_super()
+ {
+ return $this->is_super;
+ }
+
+ function filter_implicit_objects($list)
+ {
+ $nodes = array();
+
+ foreach ($list as $node)
+ {
+ if ( ! ($node->is_object() && $node->base->generated))
+ {
+ $nodes[] = $node;
+ continue;
+ }
+
+ $obj = NULL;
+
+ foreach ($node->base->properties as $prop)
+ {
+ if (($prop instanceof yy_Assign) || $prop instanceof yy_Comment)
+ {
+ if ( ! $obj)
+ {
+ $nodes[] = ($obj = yy('Obj', array(), TRUE));
+ }
+
+ $obj->properties[] = $prop;
+ }
+ else
+ {
+ $nodes[] = $prop;
+ $obj = NULL;
+ }
+ }
+ }
+
+ return $nodes;
+ }
+
+ function new_instance()
+ {
+ $base = isset($this->variable->base) ? $this->variable->base : $this->variable;
+
+ if (($base instanceof yy_Call) && ! $base->is_new())
+ {
+ $base->new_instance();
+ }
+ else
+ {
+ $this->is_new = TRUE;
+ }
+
+ return $this;
+ }
+
+ function super_reference($options)
+ {
+ $method = $options['scope']->method;
+
+ if ($method === NULL)
+ {
+ throw new SyntaxError('cannot call super outside of a function.');
+ }
+
+ $name = isset($method->name) ? $method->name : NULL;
+
+ if ($name === NULL)
+ {
+ throw new SyntaxError('cannot call super on an anonymous function.');
+ }
+
+ if (isset($method->klass) && $method->klass)
+ {
+ $accesses = array(yy('Access', yy('Literal', '__super__')));
+
+ if (isset($method->static) && $method->static)
+ {
+ $accesses[] = yy('Access', yy('Literal', 'constructor'));
+ }
+
+ $accesses[] = yy('Access', yy('Literal', $name));
+
+ return yy('Value', yy('Literal', $method->klass), $accesses)->compile($options);
+ }
+ else
+ {
+ return $name.'.__super__.constructor';
+ }
+ }
+
+ function unfold_soak($options)
+ {
+ if ($this->soak)
+ {
+ if ($this->variable)
+ {
+ if ($ifn = unfold_soak($options, $this, 'variable'))
+ {
+ return $ifn;
+ }
+
+ $tmp = yy('Value', $this->variable);
+ list($left, $rite) = $tmp->cache_reference($options);
+ }
+ else
+ {
+ $left = yy('Literal', $this->super_reference($options));
+ $rite = yy('Value', $left);
+ }
+
+ $rite = yy('Call', $rite, $this->args);
+ $rite->is_new($this->is_new());
+ $left = yy('Literal', 'typeof '.$left->compile($options).' === "function"');
+
+ return yy('If', $left, yy('Value', $rite), array('soak' => TRUE));
+ }
+
+ $call = $this;
+ $list = array();
+
+ while (TRUE)
+ {
+ if ($call->variable instanceof yy_Call)
+ {
+ $list[] = $call;
+ $call = $call->variable;
+
+ continue;
+ }
+
+ if ( ! ($call->variable instanceof yy_Value))
+ {
+ break;
+ }
+
+ $list[] = $call;
+
+ if ( ! (($call = $call->variable->base) instanceof yy_Call))
+ {
+ break;
+ }
+ }
+
+ foreach (array_reverse($list) as $call)
+ {
+ if (isset($ifn))
+ {
+ if ($call->variable instanceof yy_Call)
+ {
+ $call->variable = $ifn;
+ }
+ else
+ {
+ $call->variable->base = $ifn;
+ }
+ }
+
+ $ifn = unfold_soak($options, $call, 'variable');
+ }
+
+ return isset($ifn) ? $ifn : NULL;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Class.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Class.php
new file mode 100755
index 0000000..12bb873
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Class.php
@@ -0,0 +1,282 @@
+variable = $variable;
+ $this->parent = $parent;
+
+ $this->body = $body === NULL ? yy('Block') : $body;
+ $this->body->class_body = TRUE;
+
+ $this->bound_funcs = array();
+
+ return $this;
+ }
+
+ function add_bound_functions($options)
+ {
+ if ($this->bound_funcs)
+ {
+ foreach ($this->bound_funcs as $bvar)
+ {
+ $lhs = yy('Value', yy('Literal', 'this'), array(yy('Access', $bvar)))->compile($options);
+ $this->ctor->body->unshift(yy('Literal', "{$lhs} = ".utility('bind')."({$lhs}, this)"));
+ }
+ }
+ }
+
+ function add_properties($node, $name, $options)
+ {
+ $props = array_slice($node->base->properties, 0);
+ $exprs = array();
+
+ while ($assign = array_shift($props))
+ {
+ if ($assign instanceof yy_Assign)
+ {
+ $base = $assign->variable->base;
+ $func = $assign->value;
+
+ $assign->context = NULL;
+
+ if ($base->value === 'constructor')
+ {
+ if ($this->ctor)
+ {
+ throw new Error('cannot define more than one constructor in a class');
+ }
+
+ if (isset($func->bound) && $func->bound)
+ {
+ throw new Error('cannot define a constructor as a bound functions');
+ }
+
+ if ($func instanceof yy_Code)
+ {
+ $assign = $this->ctor = $func;
+ }
+ else
+ {
+ $this->external_ctor = $options['scope']->free_variable('class');
+ $assign = yy('Assign', yy('Literal', $this->external_ctor), $func);
+ }
+ }
+ else
+ {
+ if (isset($assign->variable->this) && $assign->variable->this)
+ {
+ $func->static = TRUE;
+
+ if (isset($func->bound) && $func->bound)
+ {
+ $func->context = $name;
+ }
+ }
+ else
+ {
+ $assign->variable = yy('Value', yy('Literal', $name), array( yy('Access', yy('Literal', 'prototype')), yy('Access', $base) ));
+
+ if ($func instanceof yy_Code && isset($func->bound) && $func->bound)
+ {
+ $this->bound_funcs[] = $base;
+ $func->bound = FALSE;
+ }
+ }
+ }
+ }
+
+ $exprs[] = $assign;
+ }
+
+ return compact($exprs);
+ }
+
+ function compile_node($options)
+ {
+ $decl = $this->determine_name();
+
+ $name = $decl ? $decl : '_Class';
+
+ if (isset($name->reserved) && $name->reserved)
+ {
+ $name = '_'.$name;
+ }
+
+ $lname = yy('Literal', $name);
+
+ $this->hoist_directive_prologue();
+ $this->set_context($name);
+ $this->walk_body($name, $options);
+ $this->ensure_constructor($name);
+ $this->body->spaced = TRUE;
+
+ if ( ! ($this->ctor instanceof yy_Code))
+ {
+ array_unshift($this->body->expressions, $this->ctor);
+ }
+
+ if ($decl)
+ {
+ array_unshift($this->body->expressions, yy('Assign', yy('Value', yy('Literal', $name), array(yy('Access', yy('Literal', 'name')))), yy('Literal', "'{$name}'")));
+ }
+
+ $this->body->expressions[] = $lname;
+ $this->body->expressions = array_merge($this->directives, $this->body->expressions);
+
+ $this->add_bound_functions($options);
+
+ $call = yy_Closure::wrap($this->body);
+
+ if ($this->parent)
+ {
+ $this->super_class = yy('Literal', $options['scope']->free_variable('super', FALSE));
+ array_unshift($this->body->expressions, yy('Extends', $lname, $this->super_class));
+ $call->args[] = $this->parent;
+
+ if (isset($call->variable->params))
+ {
+ $params = & $call->variable->params;
+ }
+ else
+ {
+ $params = & $call->variable->base->params;
+ }
+
+ $params[] = yy('Param', $this->super_class);
+ }
+
+ $klass = yy('Parens', $call, TRUE);
+
+ if ($this->variable)
+ {
+ $klass = yy('Assign', $this->variable, $klass);
+ }
+
+ return $klass->compile($options);
+ }
+
+ function determine_name()
+ {
+ if ( ! (isset($this->variable) && $this->variable))
+ {
+ return NULL;
+ }
+
+ if (($tail = last($this->variable->properties)))
+ {
+ $decl = $tail instanceof yy_Access ? $tail->name->value : NULL;
+ }
+ else
+ {
+ $decl = $this->variable->base->value;
+ }
+
+ if (in_array($decl, Lexer::$STRICT_PROSCRIBED, TRUE))
+ {
+ throw new SyntaxError("variable name may not be $decl");
+ }
+
+ $decl = $decl ? (preg_match(IDENTIFIER, $decl) ? $decl : NULL) : NULL;
+
+ return $decl;
+ }
+
+ function ensure_constructor($name)
+ {
+ if ( ! (isset($this->ctor) && $this->ctor))
+ {
+ $this->ctor = yy('Code');
+
+ if ($this->parent)
+ {
+ $this->ctor->body->push(yy('Literal', "{$name}.__super__.constructor.apply(this, arguments)"));
+ }
+
+ if (isset($this->external_ctor) && $this->external_ctor)
+ {
+ $this->ctor->body->push(yy('Literal', "{$this->external_ctor}.apply(this, arguments)"));
+ }
+
+ $this->ctor->body->make_return();
+
+ array_unshift($this->body->expressions, $this->ctor);
+ }
+
+ $this->ctor->ctor = $this->ctor->name = $name;
+
+ $this->ctor->klass = NULL;
+ $this->ctor->no_return = TRUE;
+ }
+
+ function hoist_directive_prologue()
+ {
+ $index = 0;
+ $expressions = $this->body->expressions;
+
+ while (isset($expressions[$index]) && ($node = $expressions[$index]) && ( ($node instanceof yy_Comment) || ($node instanceof yy_Value) && $node->is_string() ))
+ {
+ $index++;
+ }
+
+ $this->directives = array_slice($expressions, 0, $index);
+ }
+
+ function set_context($name)
+ {
+ $this->body->traverse_children(FALSE, function($node) use ($name)
+ {
+ if (isset($node->class_body) && $node->class_body)
+ {
+ return FALSE;
+ }
+
+ if ($node instanceof yy_Literal && ''.$node->value === 'this')
+ {
+ $node->value = $name;
+ }
+ else if ($node instanceof yy_Code)
+ {
+ $node->klass = $name;
+
+ if ($node->bound)
+ {
+ $node->context = $name;
+ }
+ }
+ });
+ }
+
+ function walk_body($name, $options)
+ {
+ $self = $this;
+
+ $this->traverse_children(FALSE, function($child) use ($name, $options, & $self)
+ {
+ if ($child instanceof yy_Class)
+ {
+ return FALSE;
+ }
+
+ if ($child instanceof yy_Block)
+ {
+ foreach (($exps = $child->expressions) as $i => $node)
+ {
+ if ($node instanceof yy_Value && $node->is_object(TRUE))
+ {
+ $exps[$i] = $self->add_properties($node, $name, $options);
+ }
+ }
+
+ $child->expressions = $exps = flatten($exps);
+ }
+ });
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Closure.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Closure.php
new file mode 100755
index 0000000..5751ab0
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Closure.php
@@ -0,0 +1,49 @@
+jumps())
+ {
+ return $expressions;
+ }
+
+ $func = yy('Code', array(), yy_Block::wrap(array($expressions)));
+ $args = array();
+
+ if (($mentions_args = $expressions->contains('yy_Closure::literal_args')) ||
+ $expressions->contains('yy_Closure::literal_this'))
+ {
+ $meth = yy('Literal', $mentions_args ? 'apply' : 'call');
+ $args = array(yy('Literal', 'this'));
+
+ if ($mentions_args)
+ {
+ $args[] = yy('Literal', 'arguments');
+ }
+
+ $func = yy('Value', $func, array(yy('Access', $meth)));
+ }
+
+ $func->no_return = $no_return;
+ $call = yy('Call', $func, $args);
+
+ return $statement ? yy_Block::wrap(array($call)) : $call;
+ }
+
+ static function literal_args($node)
+ {
+ return ($node instanceof yy_Literal) && (''.$node->value === 'arguments') && ! $node->as_key;
+ }
+
+ static function literal_this($node)
+ {
+ return (($node instanceof yy_Literal) && (''.$node->value === 'this') && ! $node->as_key) ||
+ ($node instanceof yy_Code && $node->bound);
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Code.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Code.php
new file mode 100755
index 0000000..a1c3d2d
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Code.php
@@ -0,0 +1,200 @@
+params = $params ? $params : array();
+ $this->body = $body ? $body : yy('Block');
+ $this->bound = $tag === 'boundfunc';
+ $this->context = $this->bound ? '_this' : NULL;
+
+ return $this;
+ }
+
+ function compile_node($options)
+ {
+ $options['scope'] = new Scope($options['scope'], $this->body, $this);
+ $options['scope']->shared = del($options, 'sharedScope');
+ $options['indent'] .= TAB;
+
+ unset($options['bare']);
+ unset($options['isExistentialEquals']);
+
+ $params = array();
+ $exprs = array();
+
+ foreach ($this->param_names() as $name)
+ {
+ if ( ! $options['scope']->check($name))
+ {
+ $options['scope']->parameter($name);
+ }
+ }
+
+ foreach ($this->params as $param)
+ {
+ if ($param->splat)
+ {
+ if (isset($param->name->value) && $param->name->value)
+ {
+ $options['scope']->add($param->name->value, 'var', TRUE);
+ }
+
+ $params = array();
+
+ foreach ($this->params as $p)
+ {
+ $params[] = $p->as_reference($options);
+ }
+
+ $splats = yy('Assign', yy('Value', yy('Arr', $params)), yy('Value', yy('Literal', 'arguments')));
+
+ break;
+ }
+ }
+
+ foreach ($this->params as $param)
+ {
+ if ($param->is_complex())
+ {
+ $val = $ref = $param->as_reference($options);
+
+ if (isset($param->value) && $param->value)
+ {
+ $val = yy('Op', '?', $ref, $param->value);
+ }
+
+ $exprs[] = yy('Assign', yy('Value', $param->name), $val, '=', array('param' => TRUE));
+ }
+ else
+ {
+ $ref = $param;
+
+ if ($param->value)
+ {
+ $lit = yy('Literal', $ref->name->value.' == null');
+ $val = yy('Assign', yy('Value', $param->name), $param->value, '=');
+
+ $exprs[] = yy('If', $lit, $val);
+ }
+ }
+
+ if ( ! (isset($splats) && $splats))
+ {
+ $params[] = $ref;
+ }
+ }
+
+ $was_empty = $this->body->is_empty();
+
+ if (isset($splats) && $splats)
+ {
+ array_unshift($exprs, $splats);
+ }
+
+ if ($exprs)
+ {
+ foreach (array_reverse($exprs) as $expr)
+ {
+ array_unshift($this->body->expressions, $expr);
+ }
+ }
+
+ foreach ($params as $i => $p)
+ {
+ $options['scope']->parameter(($params[$i] = $p->compile($options)));
+ }
+
+ $uniqs = array();
+
+ foreach ($this->param_names() as $name)
+ {
+ if (in_array($name, $uniqs))
+ {
+ throw new SyntaxError("multiple parameters named $name");
+ }
+
+ $uniqs[] = $name;
+ }
+
+ if ( ! ($was_empty || $this->no_return))
+ {
+ $this->body->make_return();
+ }
+
+ if ($this->bound)
+ {
+ if (isset($options['scope']->parent->method->bound) && $options['scope']->parent->method->bound)
+ {
+ $this->bound = $this->context = $options['scope']->parent->method->context;
+ }
+ else if ( ! (isset($this->static) && $this->static))
+ {
+ $options['scope']->parent->assign('_this', 'this');
+ }
+ }
+
+ $idt = $options['indent'];
+ $code = 'function';
+
+ if ($this->ctor)
+ {
+ $code .= ' '.$this->name;
+ }
+
+ $code .= '('.implode(', ', $params).') {';
+
+ if ( ! $this->body->is_empty())
+ {
+ $code .= "\n".$this->body->compile_with_declarations($options)."\n{$this->tab}";
+ }
+
+ $code .= '}';
+
+ if ($this->ctor)
+ {
+ return $this->tab.$code;
+ }
+
+ return ($this->front || $options['level'] >= LEVEL_ACCESS) ? "({$code})" : $code;
+ }
+
+ function param_names()
+ {
+ $names = array();
+
+ foreach ($this->params as $param)
+ {
+ $names = array_merge($names, (array) $param->names());
+ }
+
+ return $names;
+ }
+
+ function is_statement()
+ {
+ return !! $this->ctor;
+ }
+
+ function jumps()
+ {
+ return FALSE;
+ }
+
+ function traverse_children($cross_scope, $func)
+ {
+ if ($cross_scope)
+ {
+ return parent::traverse_children($cross_scope, $func);
+ }
+
+ return NULL;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Comment.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Comment.php
new file mode 100755
index 0000000..074ec84
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Comment.php
@@ -0,0 +1,37 @@
+comment = $comment;
+
+ return $this;
+ }
+
+ function compile_node($options, $level = NULL)
+ {
+ $code = '/*'.multident($this->comment, $this->tab)."\n{$this->tab}*/\n";
+
+ if ($level === LEVEL_TOP || $options['level'] === LEVEL_TOP)
+ {
+ $code = $options['indent'].$code;
+ }
+
+ return $code;
+ }
+
+ function is_statement()
+ {
+ return TRUE;
+ }
+
+ function make_return()
+ {
+ return $this;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Existence.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Existence.php
new file mode 100755
index 0000000..dc6726c
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Existence.php
@@ -0,0 +1,42 @@
+expression = $expression;
+
+ return $this;
+ }
+
+ function compile_node($options = array())
+ {
+ $this->expression->front = $this->front;
+ $code = $this->expression->compile($options, LEVEL_OP);
+
+ if (preg_match(IDENTIFIER, $code) && ! $options['scope']->check($code))
+ {
+ list($cmp, $cnj) = $this->negated ? array('===', '||') : array('!==', '&&');
+
+ $code = "typeof {$code} {$cmp} \"undefined\" {$cnj} {$code} {$cmp} null";
+ }
+ else
+ {
+ $code = "{$code} ".($this->negated ? '==' : '!=').' null';
+ }
+
+ return (isset($options['level']) && $options['level'] <= LEVEL_COND) ? $code : "({$code})";
+ }
+
+ function invert()
+ {
+ $this->negated = ! $this->negated;
+ return $this;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Extends.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Extends.php
new file mode 100755
index 0000000..b871927
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Extends.php
@@ -0,0 +1,26 @@
+child = $child;
+ $this->parent = $parent;
+
+ return $this;
+ }
+
+ function compile($options)
+ {
+ $tmp = yy('Call', yy('Value', yy('Literal', utility('extends'))),
+ array($this->child, $this->parent));
+
+ return $tmp->compile($options);
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/For.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/For.php
new file mode 100755
index 0000000..d96e708
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/For.php
@@ -0,0 +1,248 @@
+source = $source['source'];
+ $this->guard = isset($source['guard']) ? $source['guard'] : NULL;
+ $this->step = isset($source['step']) ? $source['step'] : NULL;
+ $this->name = isset($source['name']) ? $source['name'] : NULL;
+ $this->index = isset($source['index']) ? $source['index'] : NULL;
+
+ $this->body = yy_Block::wrap(array($body));
+
+ $this->own = (isset($source['own']) && $source['own']);
+ $this->object = (isset($source['object']) && $source['object']);
+
+ if ($this->object)
+ {
+ $tmp = $this->name;
+ $this->name = $this->index;
+ $this->index = $tmp;
+ }
+
+ if ($this->index instanceof yy_Value)
+ {
+ throw SyntaxError('index cannot be a pattern matching expression');
+ }
+
+ $this->range = $this->source instanceof yy_Value && $this->source->base instanceof yy_Range &&
+ ! count($this->source->properties);
+
+ $this->pattern = $this->name instanceof yy_Value;
+
+ if ($this->range && $this->index)
+ {
+ throw SyntaxError('indexes do not apply to range loops');
+ }
+
+ if ($this->range && $this->pattern)
+ {
+ throw SyntaxError('cannot pattern match over range loops');
+ }
+
+ $this->returns = FALSE;
+
+ return $this;
+ }
+
+ function compile_node($options)
+ {
+ $body = yy_Block::wrap(array($this->body));
+
+ $last_jumps = last($body->expressions);
+ $last_jumps = $last_jumps ? $last_jumps->jumps() : FALSE;
+
+ if ($last_jumps && $last_jumps instanceof yy_Return)
+ {
+ $this->returns = FALSE;
+ }
+
+ if ($this->range)
+ {
+ $source = $this->source->base;
+ }
+ else
+ {
+ $source = $this->source;
+ }
+
+ $scope = $options['scope'];
+
+ $name = $this->name ? $this->name->compile($options, LEVEL_LIST) : FALSE;
+ $index = $this->index ? $this->index->compile($options, LEVEL_LIST) : FALSE;
+
+ if ($name && ! $this->pattern)
+ {
+ $scope->find($name, array('immediate' => TRUE));
+ }
+
+ if ($index)
+ {
+ $scope->find($index, array('immediate' => TRUE));
+ }
+
+ if ($this->returns)
+ {
+ $rvar = $scope->free_variable('results');
+ }
+
+ $ivar = $this->object ? $index : $scope->free_variable('i');
+ $kvar = $this->range ? ($name ? $name : ($index ? $index : $ivar)) : ($index ? $index : $ivar);
+ $kvar_assign = $kvar !== $ivar ? "{$kvar} = " : '';
+
+ if ($this->step && ! $this->range)
+ {
+ $stepvar = $scope->free_variable('step');
+ }
+
+ if ($this->pattern)
+ {
+ $name = $ivar;
+ }
+
+ $var_part = '';
+ $guard_part = '';
+ $def_part = '';
+
+ $idt1 = $this->tab.TAB;
+
+ if ($this->range)
+ {
+ $for_part = $source->compile(array_merge($options, array('index' => $ivar, 'name' => $name, 'step' => $this->step)));
+ }
+ else
+ {
+ $svar = $this->source->compile($options, LEVEL_LIST);
+
+ if (($name || $this->own) && ! preg_match(IDENTIFIER, $svar))
+ {
+ $ref = $scope->free_variable('ref');
+ $def_part = "{$this->tab}{$ref} = {$svar};\n";
+ $svar = $ref;
+ }
+
+ if ($name && ! $this->pattern)
+ {
+ $name_part = "{$name} = {$svar}[{$kvar}]";
+ }
+
+ if ( ! $this->object)
+ {
+ $lvar = $scope->free_variable('len');
+ $for_var_part = "{$kvar_assign}{$ivar} = 0, {$lvar} = {$svar}.length";
+
+ if ($this->step)
+ {
+ $for_var_part .= ", {$stepvar} = ".$this->step->compile($options, LEVEL_OP);
+ }
+
+ $step_part = $kvar_assign.($this->step ? "{$ivar} += {$stepvar}" : ($kvar !== $ivar ? "++{$ivar}" : "{$ivar}++"));
+ $for_part = "{$for_var_part}; {$ivar} < {$lvar}; {$step_part}";
+ }
+ }
+
+ if ($this->returns)
+ {
+ $result_part = "{$this->tab}{$rvar} = [];\n";
+ $return_result = "\n{$this->tab}return {$rvar};";
+ $body->make_return($rvar);
+ }
+
+ if ($this->guard)
+ {
+ if ($body->expressions)
+ {
+ array_unshift($body->expressions, yy('If', yy('Parens', $this->guard)->invert(), yy('Literal', 'continue')));
+ }
+ else
+ {
+ $body = yy_Block::wrap(array(yy('If', $this->guard, $body)));
+ }
+ }
+
+ if ($this->pattern)
+ {
+ array_unshift($body->expressions, yy('Assign', $this->name, yy('Literal', "{$svar}[{$kvar}]")));
+ }
+
+ $def_part .= $this->pluck_direct_call($options, $body);
+
+ if (isset($name_part) && $name_part)
+ {
+ $var_part = "\n{$idt1}{$name_part};";
+ }
+
+ if ($this->object)
+ {
+ $for_part = "{$kvar} in {$svar}";
+
+ if ($this->own)
+ {
+ $guard_part = "\n{$idt1}if (!".utility('hasProp').".call({$svar}, {$kvar})) continue;";
+ }
+ }
+
+ $body = $body->compile(array_merge($options, array('indent' => $idt1)), LEVEL_TOP);
+
+ if ($body)
+ {
+ $body = "\n{$body}\n";
+ }
+
+ return
+ "{$def_part}"
+ . (isset($result_part) ? $result_part : '')
+ . "{$this->tab}for ({$for_part}) {{$guard_part}{$var_part}{$body}{$this->tab}}"
+ . (isset($return_result) ? $return_result : '');
+ }
+
+ function pluck_direct_call($options, $body)
+ {
+ $defs = '';
+
+ foreach ($body->expressions as $idx => $expr)
+ {
+ $expr = $expr->unwrap_all();
+
+ if ( ! ($expr instanceof yy_Call))
+ {
+ continue;
+ }
+
+ $val = $expr->variable->unwrap_all();
+
+ if ( ! ( ($val instanceof yy_Code) ||
+ ($val instanceof yy_Value) &&
+ (isset($val->base) && $val->base && ($val->base->unwrap_all() instanceof yy_Code) &&
+ count($val->properties) === 1 &&
+ isset($val->properties[0]->name) &&
+ in_array($val->properties[0]->name['value'], array('call', 'apply'), TRUE))))
+ {
+ continue;
+ }
+
+ $fn = (isset($val->base) && $val->base) ? $val->base->unwrap_all() : $val;
+ $ref = yy('Literal', $options['scope']->free_variable('fn'));
+ $base = yy('Value', $ref);
+
+ if (isset($val->base) && $val->base)
+ {
+ list($val->base, $base) = array($base, $val);
+ }
+
+ $body->expressions[$idx] = yy('Call', $base, $expr->args);
+ $tmp = yy('Assign', $ref, $fn);
+ $defs .= $this->tab.$tmp->compile($options, LEVEL_TOP).";\n";
+ }
+
+ return $defs;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/If.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/If.php
new file mode 100755
index 0000000..8566d69
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/If.php
@@ -0,0 +1,161 @@
+condition = (isset($options['type']) && $options['type'] === 'unless') ? $condition->invert() : $condition;
+ $this->body = $body;
+ $this->else_body = NULL;
+ $this->is_chain = FALSE;
+ $this->soak = isset($options['soak']) ? $options['soak'] : NULL;
+
+ return $this;
+ }
+
+ function add_else($else_body)
+ {
+ if ($this->is_chain())
+ {
+ $this->else_body_node()->add_else($else_body);
+ }
+ else
+ {
+ $this->is_chain = $else_body instanceof yy_If;
+ $this->else_body = $this->ensure_block($else_body);
+ }
+
+ return $this;
+ }
+
+ function body_node()
+ {
+ return $this->body ? $this->body->unwrap() : NULL;
+ }
+
+ function compile_node($options = array())
+ {
+ return $this->is_statement($options) ? $this->compile_statement($options) : $this->compile_expression($options);
+ }
+
+ function compile_expression($options)
+ {
+ $cond = $this->condition->compile($options, LEVEL_COND);
+ $body = $this->body_node()->compile($options, LEVEL_LIST);
+
+ $alt = ($tmp = $this->else_body_node()) ? $tmp->compile($options, LEVEL_LIST) : 'void 0';
+ $code = "{$cond} ? {$body} : {$alt}";
+
+ return (isset($options['level']) && $options['level'] > LEVEL_COND) ? "({$code})" : $code;
+ }
+
+ function compile_statement($options)
+ {
+ $child = del($options, 'chainChild');
+ $exeq = del($options, 'isExistentialEquals');
+
+ if ($exeq)
+ {
+ return yy('If', $this->condition->invert(), $this->else_body_node(), array('type' => 'if'))->compile($options);
+ }
+
+ $cond = $this->condition->compile($options, LEVEL_PAREN);
+ $options['indent'] .= TAB;
+ $body = $this->ensure_block($this->body);
+ $if_part = "if ({$cond}) {\n".$body->compile($options)."\n{$this->tab}}";
+
+ if ( ! $child)
+ {
+ $if_part = $this->tab.$if_part;
+ }
+
+ if ( ! $this->else_body)
+ {
+ return $if_part;
+ }
+
+ $ret = $if_part.' else ';
+
+ if ($this->is_chain())
+ {
+ $options['indent'] = $this->tab;
+ $options['chainChild'] = TRUE;
+
+ $ret .= $this->else_body->unwrap()->compile($options, LEVEL_TOP);
+ }
+ else
+ {
+ $ret .= "{\n".$this->else_body->compile($options, LEVEL_TOP)."\n{$this->tab}}";
+ }
+
+ return $ret;
+ }
+
+ function else_body_node()
+ {
+ return (isset($this->else_body) && $this->else_body) ? $this->else_body->unwrap() : NULL;
+ }
+
+ function ensure_block($node)
+ {
+ return $node instanceof yy_Block ? $node : yy('Block', array($node));
+ }
+
+ function is_chain()
+ {
+ return $this->is_chain;
+ }
+
+ function is_statement($options = array())
+ {
+ return (isset($options['level']) && $options['level'] === LEVEL_TOP) ||
+ $this->body_node()->is_statement($options) ||
+ (($tmp = $this->else_body_node()) && $tmp->is_statement($options));
+ }
+
+ function jumps($options = array())
+ {
+ $tmp = $this->body->jumps($options);
+
+ if ( ! $tmp && isset($this->else_body))
+ {
+ $tmp = $this->else_body->jumps($options);
+ }
+
+ return $tmp;
+ }
+
+ function make_return($res = NULL)
+ {
+ if ( ! (isset($this->else_body) && $this->else_body))
+ {
+ if ($res)
+ {
+ $this->else_body = yy('Block', array(yy('Literal', 'void 0')));
+ }
+ }
+
+ if ($this->body)
+ {
+ $this->body = yy('Block', array($this->body->make_return($res)));
+ }
+
+ if ($this->else_body)
+ {
+ $this->else_body = yy('Block', array($this->else_body->make_return($res)));
+ }
+
+ return $this;
+ }
+
+ function unfold_soak()
+ {
+ return $this->soak ? $this : FALSE;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/In.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/In.php
new file mode 100755
index 0000000..ea206bc
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/In.php
@@ -0,0 +1,97 @@
+array = $array;
+ $this->object = $object;
+
+ return $this;
+ }
+
+ function compile_node($options = array())
+ {
+ if ($this->array instanceof yy_Value && $this->array->is_array())
+ {
+ $has_splat = FALSE;
+
+ foreach ($this->array->base->objects as $obj)
+ {
+ if ($obj instanceof yy_Splat)
+ {
+ $has_splat = TRUE;
+ break;
+ }
+ }
+
+ if ( ! $has_splat)
+ {
+ return $this->compile_or_test($options);
+ }
+ }
+
+ return $this->compile_loop_test($options);
+ }
+
+ function compile_or_test($options)
+ {
+ if ( ! $this->array->base->objects)
+ {
+ return '!!'.$this->negated;
+ }
+
+ list($sub, $ref) = $this->object->cache($options, LEVEL_OP);
+ list($cmp, $cnj) = $this->negated ? array(' !== ', ' && ') : array(' === ', ' || ');
+
+ $tests = array();
+
+ foreach ($this->array->base->objects as $i => $item)
+ {
+ $tests[] = ($i ? $ref : $sub).$cmp.$item->compile($options, LEVEL_ACCESS);
+ }
+
+ if ( ! $tests)
+ {
+ // In JavaScript '' + false gives 'false', not so in PHP
+ return 'false';
+ }
+
+ $tests = implode($cnj, $tests);
+
+ return (isset($options['level']) && $options['level'] < LEVEL_OP) ? $tests : "({$tests})";
+ }
+
+ function compile_loop_test($options)
+ {
+ list($sub, $ref) = $this->object->cache($options, LEVEL_LIST);
+
+ $code = utility('indexOf').".call(".$this->array->compile($options, LEVEL_LIST).", {$ref}) "
+ .($this->negated ? '< 0' : '>= 0');
+
+ if ($sub === $ref)
+ {
+ return $code;
+ }
+
+ $code = $sub.', '.$code;
+ return (isset($options['level']) && $options['level'] < LEVEL_LIST) ? $code : "({$code})";
+ }
+
+ function invert()
+ {
+ $this->negated = ! $this->negated;
+ return $this;
+ }
+
+ function to_string($idt = '', $name = __CLASS__)
+ {
+ return parent::to_string($idt, $name.($this->negated ? '!' : ''));
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Index.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Index.php
new file mode 100755
index 0000000..c8809fa
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Index.php
@@ -0,0 +1,27 @@
+index = $index;
+
+ return $this;
+ }
+
+ function compile($options)
+ {
+ return '['.$this->index->compile($options, LEVEL_PAREN).']';
+ }
+
+ function is_complex()
+ {
+ return $this->index->is_complex();
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Literal.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Literal.php
new file mode 100755
index 0000000..f900dd7
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Literal.php
@@ -0,0 +1,96 @@
+value = $value;
+
+ return $this;
+ }
+
+ function assigns($name)
+ {
+ return $name === $this->value;
+ }
+
+ function compile_node($options)
+ {
+ if ($this->is_undefined())
+ {
+ $code = $options['level'] >= LEVEL_ACCESS ? '(void 0)' : 'void 0';
+ }
+ else if ($this->value === 'this')
+ {
+ if ( (isset($options['scope']->method->bound) && $options['scope']->method->bound) )
+ {
+ $code = $options['scope']->method->context;
+ }
+ else
+ {
+ $code = $this->value;
+ }
+ }
+ else if (isset($this->value->reserved) && $this->value->reserved)
+ {
+ $code = '"'.$this->value.'"';
+ }
+ else
+ {
+ $code = ''.$this->value;
+ }
+
+ return $this->is_statement() ? "{$this->tab}{$code};" : $code;
+ }
+
+ function is_assignable()
+ {
+ return preg_match(IDENTIFIER, ''.$this->value);
+ }
+
+ function is_complex()
+ {
+ return FALSE;
+ }
+
+ function is_statement()
+ {
+ return in_array(''.$this->value, array('break', 'continue', 'debugger'), TRUE);
+ }
+
+ function is_undefined()
+ {
+ return $this->is_undefined;
+ }
+
+ function jumps($options = array())
+ {
+ if ($this->value === 'break' && ! ( (isset($options['loop']) && $options['loop']) || (isset($options['block']) && $options['block']) ))
+ {
+ return $this;
+ }
+
+ if ($this->value === 'continue' && ! (isset($options['loop']) && $options['loop']))
+ {
+ return $this;
+ }
+
+ return FALSE;
+ }
+
+ function make_return()
+ {
+ return $this->is_statement() ? $this : parent::make_return();
+ }
+
+ function to_string($idt = '', $name = __CLASS__)
+ {
+ return ' "'.$this->value.'"';
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Obj.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Obj.php
new file mode 100755
index 0000000..c3b0b7a
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Obj.php
@@ -0,0 +1,126 @@
+generated = $generated;
+
+ $this->properties = $props ? $props : array();
+ $this->objects = $this->properties;
+
+ return $this;
+ }
+
+ function assigns($name)
+ {
+ foreach ($this->properties as $prop)
+ {
+ if ($prop->assigns($name))
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+ }
+
+ function compile_node($options)
+ {
+ $props = $this->properties;
+ $prop_names = array();
+
+ foreach ($this->properties as $prop)
+ {
+ if ($prop->is_complex())
+ {
+ $prop = isset($prop->variable) ? $prop->variable : NULL;
+ }
+
+ if ($prop)
+ {
+ $prop_name = $prop->unwrap_all();
+ $prop_name = isset($prop_name->value) ? $prop_name->value.'' : NULL;
+
+ if (in_array($prop_name, $prop_names))
+ {
+ throw new SyntaxError('multiple object literal properties named "'.$prop_name.'"');
+ }
+
+ $prop_names[] = $prop_name;
+ }
+ }
+
+ if ( ! count($props))
+ {
+ return ($this->front ? '({})' : '{}');
+ }
+
+ if ($this->generated)
+ {
+ foreach ($props as $node)
+ {
+ if ($node instanceof yy_Value)
+ {
+ throw new Error('cannot have an implicit value in an implicit object');
+ }
+ }
+ }
+
+ $idt = $options['indent'] .= TAB;
+ $last_non_com = $this->last_non_comment($this->properties);
+
+ foreach ($props as $i => $prop)
+ {
+ if ($i === count($props) - 1)
+ {
+ $join = '';
+ }
+ else if ($prop === $last_non_com || $prop instanceof yy_Comment)
+ {
+ $join = "\n";
+ }
+ else
+ {
+ $join = ",\n";
+ }
+
+ $indent = $prop instanceof yy_Comment ? '' : $idt;
+
+ if ($prop instanceof yy_Value && (isset($prop->this) && $prop->this))
+ {
+ $prop = yy('Assign', $prop->properties[0]->name, $prop, 'object');
+ }
+
+ if ( ! ($prop instanceof yy_Comment))
+ {
+ if ( ! ($prop instanceof yy_Assign))
+ {
+ $prop = yy('Assign', $prop, $prop, 'object');
+ }
+
+ if (isset($prop->variable->base))
+ {
+ $prop->variable->base->as_key = TRUE;
+ }
+ else
+ {
+ $prop->variable->as_key = TRUE;
+ }
+ }
+
+ $props[$i] = $indent.$prop->compile($options, LEVEL_TOP).$join;
+ }
+
+ $props = implode('', $props);
+ $obj = '{'.($props ? "\n{$props}\n{$this->tab}" : '').'}';
+
+ return ($this->front ? "({$obj})" : $obj);
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Op.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Op.php
new file mode 100755
index 0000000..51b02ef
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Op.php
@@ -0,0 +1,292 @@
+ '===',
+ '!=' => '!==',
+ 'of' => 'in'
+ );
+
+ static $INVERSIONS = array(
+ '!==' => '===',
+ '===' => '!=='
+ );
+
+ public $children = array('first', 'second');
+
+ public $operator = NULL;
+
+ public $invert = TRUE;
+
+ function constructor($op, $first, $second = NULL, $flip = NULL)
+ {
+ if ($op === 'in')
+ {
+ return yy('In', $first, $second);
+ }
+
+ if ($op === 'do')
+ {
+ return $this->generate_do($first);
+ }
+
+ if ($op === 'new')
+ {
+ if ($first instanceof yy_Call && ! (isset($first->do) && $first->do) && ! (isset($first->is_new) && $first->is_new))
+ {
+ return $first->new_instance();
+ }
+
+ if ($first instanceof yy_Code && $first->bound || (isset($first->do) && $first->do))
+ {
+ $first = yy('Parens', $first);
+ }
+ }
+
+ $this->operator = isset(self::$CONVERSIONS[$op]) ? self::$CONVERSIONS[$op] : $op;
+ $this->first = $first;
+ $this->second = $second;
+ $this->flip = !! $flip;
+
+ return $this;
+ }
+
+ function compile_chain($options)
+ {
+ $tmp = $this->first->second->cache($options);
+
+ $this->first->second = $tmp[0];
+ $shared = $tmp[1];
+
+ $fst = $this->first->compile($options, LEVEL_OP);
+
+ $code = "{$fst} ".($this->invert ? '&&' : '||').' '.$shared->compile($options).' '
+ .$this->operator.' '.$this->second->compile($options, LEVEL_OP);
+
+ return "({$code})";
+ }
+
+ function compile_existence($options)
+ {
+ if ($this->first->is_complex() && $options['level'] > LEVEL_TOP)
+ {
+ $ref = yy('Literal', $options['scope']->free_variable('ref'));
+ $fst = yy('Parens', yy('Assign', $ref, $this->first));
+ }
+ else
+ {
+ $fst = $this->first;
+ $ref = $fst;
+ }
+
+ $tmp = yy('If', yy('Existence', $fst), $ref, array('type' => 'if'));
+ $tmp->add_else($this->second);
+
+ return $tmp->compile($options);
+ }
+
+ function compile_node($options, $level = NULL)
+ {
+ $is_chain = $this->is_chainable() && $this->first->is_chainable();
+
+ if ( ! $is_chain)
+ {
+ $this->first->front = $this->front;
+ }
+
+ $tmp = $this->first->unwrap_all();
+ $tmp = isset($tmp->value) ? $tmp->value : NULL;
+
+ if ($this->operator === 'delete' && $options['scope']->check($tmp))
+ {
+ throw new SyntaxError('delete operand may not be argument or var');
+ }
+
+ if (in_array($this->operator, array('--', '++')) && in_array($tmp, Lexer::$STRICT_PROSCRIBED))
+ {
+ throw new SyntaxError('prefix increment/decrement may not have eval or arguments operand');
+ }
+
+ if ($this->is_unary())
+ {
+ return $this->compile_unary($options);
+ }
+
+ if ($is_chain)
+ {
+ return $this->compile_chain($options);
+ }
+
+ if ($this->operator === '?')
+ {
+ return $this->compile_existence($options);
+ }
+
+ $this->first->front = $this->front;
+
+ $code = $this->first->compile($options, LEVEL_OP).' '.$this->operator.' '
+ .$this->second->compile($options, LEVEL_OP);
+
+ return $options['level'] <= LEVEL_OP ? $code : "({$code})";
+ }
+
+ function compile_unary($options)
+ {
+ if ($options['level'] >= LEVEL_ACCESS)
+ {
+ return yy('Parens', $this)->compile($options);
+ }
+
+ $parts = array($op = $this->operator);
+ $plus_minus = in_array($op, array('+', '-'), TRUE);
+
+ if (in_array($op, array('new', 'typeof', 'delete'), TRUE) ||
+ $plus_minus &&
+ $this->first instanceof yy_Op && $this->first->operator === $op)
+ {
+ $parts[] = ' ';
+ }
+
+ if (($plus_minus && $this->first instanceof yy_Op) || ($op === 'new' && $this->first->is_statement($options)))
+ {
+ $this->first = yy('Parens', $this->first);
+ }
+
+ $parts[] = $this->first->compile($options, LEVEL_OP);
+
+ if ($this->flip)
+ {
+ $parts = array_reverse($parts);
+ }
+
+ return implode('', $parts);
+ }
+
+ function is_chainable()
+ {
+ return in_array($this->operator, array('<', '>', '>=', '<=', '===', '!=='), TRUE);
+ }
+
+ function is_complex()
+ {
+ return ! ($this->is_unary() && in_array($this->operator, array('+', '-'))) || $this->first->is_complex();
+ }
+
+ function invert()
+ {
+ if ($this->is_chainable() && $this->first->is_chainable())
+ {
+ $all_invertable = TRUE;
+ $curr = $this;
+
+ while ($curr && (isset($curr->operator) && $curr->operator))
+ {
+ if ($all_invertable)
+ {
+ $all_invertable = isset(self::$INVERSIONS[$curr->operator]);
+ }
+
+ $curr = $curr->first;
+ }
+
+ if ( ! $all_invertable)
+ {
+ return yy('Parens', $this)->invert();
+ }
+
+ $curr = $this;
+
+ while ($curr && (isset($curr->operator) && $curr->operator))
+ {
+ $curr->invert = ! $curr->invert;
+ $curr->operator = self::$INVERSIONS[$curr->operator];
+ $curr = $curr->first;
+ }
+
+ return $this;
+ }
+ else if (isset(self::$INVERSIONS[$this->operator]) && ($op = self::$INVERSIONS[$this->operator]))
+ {
+ $this->operator = $op;
+
+ if ($this->first->unwrap() instanceof yy_Op)
+ {
+ $this->first->invert();
+ }
+
+ return $this;
+ }
+ else if ($this->second)
+ {
+ return yy('Parens', $this)->invert();
+ }
+ else if ($this->operator === '!' && (($fst = $this->first->unwrap()) instanceof yy_Op) &&
+ in_array($fst->operator, array('!', 'in', 'instanceof'), TRUE))
+ {
+ return $fst;
+ }
+ else
+ {
+ return yy('Op', '!', $this);
+ }
+ }
+
+ function generate_do($exp)
+ {
+ $passed_params = array();
+ $func = $exp;
+
+ if ($exp instanceof yy_Assign && ($ref = $exp->value->unwrap()) instanceof yy_Code)
+ {
+ $func = $ref;
+ }
+
+ foreach ((isset($func->params) && $func->params ? $func->params : array()) as $param)
+ {
+ if (isset($param->value) && $param->value)
+ {
+ $passed_params[] = $param->value;
+ unset($param->value);
+ }
+ else
+ {
+ $passed_params[] = $param;
+ }
+ }
+
+ $call = yy('Call', $exp, $passed_params);
+ $call->do = TRUE;
+
+ return $call;
+ }
+
+ function is_simple_number()
+ {
+ return FALSE;
+ }
+
+ function is_unary()
+ {
+ return ! (isset($this->second) && $this->second);
+ }
+
+ function unfold_soak($options)
+ {
+ if (in_array($this->operator, array('++', '--', 'delete'), TRUE))
+ {
+ return unfold_soak($options, $this, 'first');
+ }
+
+ return NULL;
+ }
+
+ function to_string($idt = '', $name = __CLASS__)
+ {
+ return parent::to_string($idt, $name.' '.$this->operator);
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Param.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Param.php
new file mode 100755
index 0000000..db47bb5
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Param.php
@@ -0,0 +1,119 @@
+name = $name;
+ $this->value = $value;
+ $this->splat = $splat;
+
+ $name = $this->name->unwrap_all();
+ $name = isset($name->value) ? $name->value : NULL;
+
+ if (in_array($name, Lexer::$STRICT_PROSCRIBED))
+ {
+ throw new SyntaxError("parameter name \"$name\" is not allowed");
+ }
+
+ return $this;
+ }
+
+ function as_reference($options)
+ {
+ if (isset($this->reference) && $this->reference)
+ {
+ return $this->reference;
+ }
+
+ $node = $this->name;
+
+ if (isset($node->this) && $node->this)
+ {
+ $node = $node->properties[0]->name;
+
+ if (isset($this->value->reserved) && $this->value->reserved)
+ {
+ $node = yy('Literal', $options['scope']->free_variable($node->value));
+ }
+ }
+ else if ($node->is_complex())
+ {
+ $node = yy('Literal', $options['scope']->free_variable('arg'));
+ }
+
+ $node = yy('Value', $node);
+
+ if ($this->splat)
+ {
+ $node = yy('Splat', $node);
+ }
+
+ return ($this->reference = $node);
+ }
+
+ function compile($options, $level = NULL)
+ {
+ return $this->name->compile($options, LEVEL_LIST);
+ }
+
+ function is_complex()
+ {
+ return $this->name->is_complex();
+ }
+
+ function names($name = NULL)
+ {
+ if ($name === NULL)
+ {
+ $name = $this->name;
+ }
+
+ $at_param = function($obj)
+ {
+ $value = $obj->properties[0]->name;
+
+ return isset($value->reserved) && $value->reserved ? array() : array($value);
+ };
+
+ if ($name instanceof yy_Literal)
+ {
+ return array($name->value);
+ }
+
+ if ($name instanceof yy_Value)
+ {
+ return $at_param($name);
+ }
+
+ $names = array();
+
+ foreach ($name->objects as $obj)
+ {
+ if ($obj instanceof yy_Assign)
+ {
+ $names[] = $obj->variable->base->value;
+ }
+ else if ($obj->is_array() || $obj->is_object())
+ {
+ $names = array_merge($names, (array) $this->names($obj->base));
+ }
+ else if (isset($obj->this) && $obj->this)
+ {
+ $names = array_merge($names, (array) $at_param($obj));
+ }
+ else
+ {
+ $names[] = $obj->base->value;
+ }
+ }
+
+ return $names;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Parens.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Parens.php
new file mode 100755
index 0000000..db4db62
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Parens.php
@@ -0,0 +1,45 @@
+body = $body;
+
+ return $this;
+ }
+
+ function compile_node($options = array())
+ {
+ $expr = $this->body->unwrap();
+
+ if ($expr instanceof yy_Value && $expr->is_atomic())
+ {
+ $expr->front = $this->front;
+ return $expr->compile($options);
+ }
+
+ $code = $expr->compile($options, LEVEL_PAREN);
+
+ $bare = $options['level'] < LEVEL_OP && ($expr instanceof yy_Op || $expr instanceof yy_Call ||
+ ($expr instanceof yy_For && $expr->returns));
+
+ return $bare ? $code : "({$code})";
+ }
+
+ function is_complex()
+ {
+ return $this->body->is_complex();
+ }
+
+ function unwrap()
+ {
+ return $this->body;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Range.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Range.php
new file mode 100755
index 0000000..d941744
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Range.php
@@ -0,0 +1,217 @@
+from = $from;
+ $this->to = $to;
+ $this->exclusive = $tag === 'exclusive';
+ $this->equals = $this->exclusive ? '' : '=';
+
+ return $this;
+ }
+
+ function compile_array($options)
+ {
+ if (self::check($this->from_num) && self::check($this->to_num) && abs($this->from_num - $this->to_num) <= 20)
+ {
+ $range = range($this->from_num, $this->to_num);
+
+ if ($this->exclusive)
+ {
+ array_pop($range);
+ }
+
+ return '['.implode(', ', $range).']';
+ }
+
+ $idt = $this->tab.TAB;
+ $i = $options['scope']->free_variable('i');
+ $result = $options['scope']->free_variable('results');
+ $pre = "\n{$idt}{$result} = [];";
+
+ if (self::check($this->from_num) && self::check($this->to_num))
+ {
+ $options['index'] = $i;
+ $body = $this->compile_node($options);
+ }
+ else
+ {
+ $vars = "{$i} = {$this->from_c}".($this->to_c !== $this->to_var ? ", {$this->to_c}" : '');
+ $cond = "{$this->from_var} <= {$this->to_var}";
+ $body = "var {$vars}; {$cond} ? {$i} <{$this->equals} {$this->to_var} : {$i} >{$this->equals} {$this->to_var}; {$cond} ? {$i}++ : {$i}--";
+ }
+
+ $post = "{ {$result}.push({$i}); }\n{$idt}return {$result};\n{$options['indent']}";
+
+ $has_args = function($node)
+ {
+ return $node->contains(function($n)
+ {
+ return $n instanceof yy_Literal && $n->value === 'arguments' && ! $n->as_key();
+ });
+
+ return FALSE;
+ };
+
+ $args = '';
+
+ if ($has_args($this->from) || $has_args($this->to))
+ {
+ $args = ', arguments';
+ }
+
+ return "(function() {{$pre}\n{$idt}for ({$body}){$post}}).apply(this{$args})";
+ }
+
+ function compile_node($options)
+ {
+ if ( ! (isset($this->from_var) && $this->from_var))
+ {
+ $this->compile_variables($options);
+ }
+
+ if ( ! (isset($options['index']) && $options['index']))
+ {
+ return $this->compile_array($options);
+ }
+
+ $known = self::check($this->from_num) && self::check($this->to_num);
+ $idx = del($options, 'index');
+ $idx_name = del($options, 'name');
+ $named_index = $idx_name && $idx_name !== $idx;
+
+ $var_part = "{$idx} = {$this->from_c}";
+
+ if ($this->to_c !== $this->to_var)
+ {
+ $var_part .= ", {$this->to_c}";
+ }
+
+ if (isset($this->step) && $this->step !== $this->step_var)
+ {
+ $var_part .= ", {$this->step}";
+ }
+
+ list($lt, $gt) = array("{$idx} <{$this->equals}", "{$idx} >{$this->equals}");
+
+ if (isset($this->step_num) && self::check($this->step_num))
+ {
+ $cond_part = intval($this->step_num) > 0 ? "{$lt} {$this->to_var}" : "{$gt} {$this->to_var}";
+ }
+ else if ($known)
+ {
+ list($from, $to) = array(intval($this->from_num), intval($this->to_num));
+ $cond_part = $from <= $to ? "{$lt} {$to}" : "{$gt} {$to}";
+ }
+ else
+ {
+ $cond = "{$this->from_var} <= {$this->to_var}";
+ $cond_part = "{$cond} ? {$lt} {$this->to_var} : {$gt} {$this->to_var}";
+ }
+
+ if (isset($this->step_var) && $this->step_var)
+ {
+ $step_part = "{$idx} += {$this->step_var}";
+ }
+ else if ($known)
+ {
+ if ($named_index)
+ {
+ $step_part = $from <= $to ? "++{$idx}" : "--{$idx}";
+ }
+ else
+ {
+ $step_part = $from <= $to ? "{$idx}++" : "{$idx}--";
+ }
+ }
+ else
+ {
+ if ($named_index)
+ {
+ $step_part = "{$cond} ? ++{$idx} : --{$idx}";
+ }
+ else
+ {
+ $step_part = "{$cond} ? {$idx}++ : {$idx}--";
+ }
+ }
+
+ if ($named_index)
+ {
+ $var_part = "{$idx_name} = {$var_part}";
+ $step_part = "{$idx_name} = {$step_part}";
+ }
+
+ return "{$var_part}; {$cond_part}; {$step_part}";
+ }
+
+ function compile_simple($options)
+ {
+ list($from, $to) = array($this->from_num, $this->to_num);
+
+ $idx = del($options, 'index');
+ $step = del($options, 'step');
+
+ if ($step)
+ {
+ $stepvar = $options['scope']->free_variable('step');
+ }
+
+ $var_part = "{$idx} = {$from}";
+
+ if ($step)
+ {
+ $var_part .= ", {$stepvar} = ".$step->compile($options);
+ }
+
+ $cond_part = $from <= $to ? "{$idx} <{$this->equals} {$to}" : "{$idx} >{$this->equals} {$to}";
+
+ if ($step)
+ {
+ $step_part = "{$idx} += {$stepvar}";
+ }
+ else
+ {
+ $step_part = $from <= $to ? "{$idx}++" : "{$idx}--";
+ }
+
+ return "{$var_part}; {$cond_part}; {$step_part}";
+ }
+
+ function compile_variables($options)
+ {
+ $options = array_merge($options, array('top' => TRUE));
+
+ list($this->from_c, $this->from_var) = $this->from->cache($options, LEVEL_LIST);
+ list($this->to_c, $this->to_var) = $this->to->cache($options, LEVEL_LIST);
+
+ if ($step = del($options, 'step'))
+ {
+ list($this->step, $this->step_var) = $step->cache($options, LEVEL_LIST);
+ }
+
+ list($this->from_num, $this->to_num) = array(preg_match(SIMPLENUM, $this->from_var), preg_match(SIMPLENUM, $this->to_var));
+
+ if (isset($this->step_var) && $this->step_var)
+ {
+ $this->step_num = preg_match(SIMPLENUM, $this->step_var);
+ }
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Return.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Return.php
new file mode 100755
index 0000000..400eabb
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Return.php
@@ -0,0 +1,56 @@
+unwrap()->is_undefined()))
+ {
+ $this->expression = $expr;
+ }
+
+ return $this;
+ }
+
+ function compile($options, $level = NULL)
+ {
+ $expr = (isset($this->expression) && $this->expression) ? $this->expression->make_return() : NULL;
+
+ if ($expr && ! ($expr instanceof yy_Return))
+ {
+ $ret = $expr->compile($options, $level);
+ }
+ else
+ {
+ $ret = parent::compile($options, $level);
+ }
+
+ return $ret;
+ }
+
+ function compile_node($options)
+ {
+ return $this->tab.'return'.(isset($this->expression) && $this->expression ? ' '.$this->expression->compile($options, LEVEL_PAREN) : '').';';
+ }
+
+ function is_statement()
+ {
+ return TRUE;
+ }
+
+ function jumps()
+ {
+ return $this;
+ }
+
+ function make_return()
+ {
+ return $this;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Slice.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Slice.php
new file mode 100755
index 0000000..eb6c4ce
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Slice.php
@@ -0,0 +1,49 @@
+range = $range;
+
+ return $this;
+ }
+
+ function compile_node($options)
+ {
+ $to = $this->range->to;
+ $from = $this->range->from;
+
+ $from_str = $from ? $from->compile($options, LEVEL_PAREN) : '0';
+ $compiled = $to ? $to->compile($options, LEVEL_PAREN) : '';
+
+ if ($to && ! ( ! $this->range->exclusive && intval($compiled) === -1))
+ {
+ $to_str = ', ';
+
+ if ($this->range->exclusive)
+ {
+ $to_str .= $compiled;
+ }
+ else if (preg_match(SIMPLENUM, $compiled))
+ {
+ $to_str .= (intval($compiled) + 1);
+ }
+ else
+ {
+ $compiled = $to->compile($options, LEVEL_ACCESS);
+ $to_str .= "({$compiled} + 1) || 9e9";
+ }
+ }
+
+ return ".slice({$from_str}".(isset($to_str) ? $to_str : '').')';
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Splat.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Splat.php
new file mode 100755
index 0000000..83f41c3
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Splat.php
@@ -0,0 +1,100 @@
+= count($list))
+ {
+ return '';
+ }
+
+ if (count($list) === 1)
+ {
+ $code = $list[0]->compile($options, LEVEL_LIST);
+
+ if ($apply)
+ {
+ return $code;
+ }
+
+ return utility('slice').".call({$code})";
+ }
+
+ $args = array_slice($list, $index);
+
+ foreach ($args as $i => $node)
+ {
+ $code = $node->compile($options, LEVEL_LIST);
+ $args[$i] = ($node instanceof yy_Splat) ? utility('slice').".call({$code})" : "[{$code}]";
+ }
+
+ if ($index === 0)
+ {
+ return $args[0].'.concat('.implode(', ', array_slice($args, 1)).')';
+ }
+
+ $base = array();
+
+ foreach (array_slice($list, 0, $index) as $node)
+ {
+ $base[] = $node->compile($options, LEVEL_LIST);
+ }
+
+ return '['.implode(', ', $base).'].concat('.implode(', ', $args).')';
+ }
+
+ function constructor($name)
+ {
+ if (is_object($name))
+ {
+ $this->name = $name;
+ }
+ else
+ {
+ $this->name = yy('Literal', $name);
+ }
+
+ return $this;
+ }
+
+ function assigns($name)
+ {
+ return $this->name->assigns($name);
+ }
+
+ function compile($options)
+ {
+ if (isset($this->index) && $this->index)
+ {
+ return $this->compile_param($options);
+ }
+ else
+ {
+ return $this->name->compile($options);
+ }
+ }
+
+ function is_assignable()
+ {
+ return TRUE;
+ }
+
+ function unwrap()
+ {
+ return $this->name;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Switch.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Switch.php
new file mode 100755
index 0000000..6748556
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Switch.php
@@ -0,0 +1,121 @@
+subject = $subject;
+ $this->cases = $cases;
+ $this->otherwise = $otherwise;
+
+ return $this;
+ }
+
+ function compile_node($options)
+ {
+ $idt1 = $options['indent'].TAB;
+ $idt2 = $options['indent'] = $idt1.TAB;
+
+ $code = $this->tab.'switch ('
+ .($this->subject ? $this->subject->compile($options, LEVEL_PAREN) : 'false')
+ .") {\n";
+
+ foreach ($this->cases as $i => $case)
+ {
+ list($conditions, $block) = $case;
+
+ foreach (flatten(array($conditions)) as $cond)
+ {
+ if ( ! $this->subject)
+ {
+ $cond = $cond->invert();
+ }
+
+ $code .= $idt1.'case '.$cond->compile($options, LEVEL_PAREN).":\n";
+ }
+
+ if ($body = $block->compile($options, LEVEL_TOP))
+ {
+ $code .= $body."\n";
+ }
+
+ if ($i === (count($this->cases) - 1) && ! $this->otherwise)
+ {
+ break;
+ }
+
+ $expr = $this->last_non_comment($block->expressions);
+
+ if ($expr instanceof yy_Return ||
+ ($expr instanceof yy_Literal && $expr->jumps() && ''.$expr->value !== 'debugger'))
+ {
+ continue;
+ }
+
+ $code .= $idt2."break;\n";
+ }
+
+ if ($this->otherwise && count($this->otherwise->expressions))
+ {
+ $code .= $idt1."default:\n".$this->otherwise->compile($options, LEVEL_TOP)."\n";
+ }
+
+ return $code.$this->tab.'}';
+ }
+
+ function is_statement()
+ {
+ return TRUE;
+ }
+
+ function jumps($options = array())
+ {
+ if ( ! isset($options['block']))
+ {
+ $options['block'] = TRUE;
+ }
+
+ foreach ($this->cases as $case)
+ {
+ list($conds, $block) = $case;
+
+ if ($block->jumps($options))
+ {
+ return $block;
+ }
+ }
+
+ if (isset($this->otherwise) && $this->otherwise)
+ {
+ return $this->otherwise->jumps($options);
+ }
+
+ return FALSE;
+ }
+
+ function make_return($res = NULL)
+ {
+ foreach ($this->cases as $pair)
+ {
+ $pair[1]->make_return($res);
+ }
+
+ if ($res)
+ {
+ $this->otherwise = isset($this->otherwise) && $this->otherwise ? $this->otherwise : yy('Block', array(yy('Literal', 'void 0')));
+ }
+
+ if (isset($this->otherwise) && $this->otherwise)
+ {
+ $this->otherwise->make_return();
+ }
+
+ return $this;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Throw.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Throw.php
new file mode 100755
index 0000000..3a2cf39
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Throw.php
@@ -0,0 +1,37 @@
+expression = $expression;
+
+ return $this;
+ }
+
+ function compile_node($options = array())
+ {
+ return $this->tab.'throw '.$this->expression->compile($options).';';
+ }
+
+ function is_statement()
+ {
+ return TRUE;
+ }
+
+ function jumps()
+ {
+ return FALSE;
+ }
+
+ function make_return()
+ {
+ return $this;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Try.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Try.php
new file mode 100755
index 0000000..fd35fbe
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Try.php
@@ -0,0 +1,79 @@
+attempt = $attempt;
+ $this->error = $error;
+ $this->recovery = $recovery;
+ $this->ensure = $ensure;
+
+ return $this;
+ }
+
+ function compile_node($options = array())
+ {
+ $options['indent'] .= TAB;
+ $error_part = $this->error ? ' ('.$this->error->compile($options).') ' : ' ';
+ $try_part = $this->attempt->compile($options, LEVEL_TOP);
+ $catch_part = '';
+
+ if ($this->recovery)
+ {
+ if (in_array($this->error, Lexer::$STRICT_PROSCRIBED))
+ {
+ throw new SyntaxError('catch variable may not be "'.$this->error->value.'"');
+ }
+
+ if ( ! $options['scope']->check($this->error->value))
+ {
+ $options['scope']->add($this->error->value, 'param');
+ }
+
+ $catch_part = " catch{$error_part}{\n".$this->recovery->compile($options, LEVEL_TOP)."\n{$this->tab}}";
+ }
+ else if ( ! ($this->ensure || $this->recovery))
+ {
+ $catch_part = ' catch (_error) {}';
+ }
+
+ $ensure_part = isset($this->ensure) && $this->ensure ? " finally {\n".$this->ensure->compile($options, LEVEL_TOP)."\n{$this->tab}}" : '';
+
+ return
+ "{$this->tab}try {\n"
+ . $try_part."\n"
+ . "{$this->tab}}{$catch_part}{$ensure_part}";
+ }
+
+ function is_statement()
+ {
+ return TRUE;
+ }
+
+ function jumps($options = array())
+ {
+ return $this->attempt->jumps($options) || (isset($this->recovery) && $this->recovery->jumps($options));
+ }
+
+ function make_return($res)
+ {
+ if ($this->attempt)
+ {
+ $this->attempt = $this->attempt->make_return($res);
+ }
+
+ if ($this->recovery)
+ {
+ $this->recovery = $this->recovery->make_return($res);
+ }
+
+ return $this;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/Value.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/Value.php
new file mode 100755
index 0000000..f0014a8
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/Value.php
@@ -0,0 +1,210 @@
+base = $base;
+ $this->properties = $props ? $props : array();
+
+ if ($tag)
+ {
+ $this->{$tag} = TRUE;
+ }
+
+ return $this;
+ }
+
+ function add($prop)
+ {
+ $this->properties = array_merge($this->properties, is_object($prop) ? array($prop) : (array) $prop);
+
+ return $this;
+ }
+
+ function assigns($name)
+ {
+ return ! count($this->properties) && $this->base->assigns($name);
+ }
+
+ function cache_reference($options)
+ {
+ $name = last($this->properties);
+
+ if (count($this->properties) < 2 && ! $this->base->is_complex() && ! ($name && $name->is_complex()))
+ {
+ return array($this, $this);
+ }
+
+ $base = yy('Value', $this->base, array_slice($this->properties, 0, -1));
+ $bref = NULL;
+
+ if ($base->is_complex())
+ {
+ $bref = yy('Literal', $options['scope']->free_variable('base'));
+ $base = yy('Value', yy('Parens', yy('Assign', $bref, $base)));
+ }
+
+ if ( ! $name)
+ {
+ return array($base, $bref);
+ }
+
+ if ($name->is_complex())
+ {
+ $nref = yy('Literal', $options['scope']->free_variable('name'));
+ $name = yy('Index', yy('Assign', $nref, $name->index));
+ $nref = yy('Index', $nref);
+ }
+
+ $base->add($name);
+
+ return array($base, yy('Value', isset($bref) ? $bref : $base->base, array(isset($nref) ? $nref : $name)));
+ }
+
+ function compile_node($options)
+ {
+ $this->base->front = $this->front;
+ $props = $this->properties;
+
+ $code = $this->base->compile($options, count($props) ? LEVEL_ACCESS : NULL);
+
+ if ( (($this->base instanceof yy_Parens) || count($props)) && preg_match(SIMPLENUM, $code))
+ {
+ $code = $code.'.';
+ }
+
+ foreach ($props as $prop)
+ {
+ $code .= $prop->compile($options);
+ }
+
+ return $code;
+ }
+
+ function has_properties()
+ {
+ return !! count($this->properties);
+ }
+
+ function is_array()
+ {
+ return ! count($this->properties) && $this->base instanceof yy_Arr;
+ }
+
+ function is_assignable()
+ {
+ return $this->has_properties() || $this->base->is_assignable();
+ }
+
+ function is_atomic()
+ {
+ foreach (array_merge($this->properties, array($this->base)) as $node)
+ {
+ if ((isset($node->soak) && $node->soak) || $node instanceof yy_Call)
+ {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+ }
+
+ function is_complex()
+ {
+ return $this->has_properties() || $this->base->is_complex();
+ }
+
+ function is_object($only_generated = FALSE)
+ {
+ if (count($this->properties))
+ {
+ return FALSE;
+ }
+
+ return ($this->base instanceof yy_Obj) && ( ! $only_generated || $this->base->generated);
+ }
+
+ function is_simple_number()
+ {
+ return ($this->base instanceof yy_Literal) && preg_match(SIMPLENUM, ''.$this->base->value);
+ }
+
+ function is_splice()
+ {
+ return last($this->properties) instanceof yy_Slice;
+ }
+
+ function is_string()
+ {
+ return ($this->base instanceof yy_Literal) && preg_match(IS_STRING, ''.$this->base->value);
+ }
+
+ function is_statement($options)
+ {
+ return ! count($this->properties) && $this->base->is_statement($options);
+ }
+
+ function jumps($options = array())
+ {
+ return ! count($this->properties) && $this->base->jumps($options);
+ }
+
+ function unfold_soak($options)
+ {
+ if (isset($this->unfolded_soak))
+ {
+ return $this->unfolded_soak;
+ }
+
+ if (($ifn = $this->base->unfold_soak($options)))
+ {
+ $ifn->body->properties = array_merge($ifn->body->properties, $this->properties);
+ $result = $ifn;
+ }
+ else
+ {
+ foreach ($this->properties as $i => $prop)
+ {
+ if (isset($prop->soak) && $prop->soak)
+ {
+ $prop->soak = FALSE;
+
+ $fst = yy('Value', $this->base, array_slice($this->properties, 0, $i));
+ $snd = yy('Value', $this->base, array_slice($this->properties, $i));
+
+ if ($fst->is_complex())
+ {
+ $ref = yy('Literal', $options['scope']->free_variable('ref'));
+ $fst = yy('Parens', yy('Assign', $ref, $fst));
+ $snd->base = $ref;
+ }
+
+ $result = yy('If', yy('Existence', $fst), $snd, array('soak' => TRUE));
+
+ break;
+ }
+ }
+ }
+
+ $this->unfolded_soak = isset($result) ? $result : FALSE;
+
+ return $this->unfolded_soak;
+ }
+
+ function unwrap()
+ {
+ return count($this->properties) ? $this : $this->base;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/coffeescript/yy/While.php b/sparks/assets/1.5.1/libraries/coffeescript/yy/While.php
new file mode 100755
index 0000000..d764356
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/coffeescript/yy/While.php
@@ -0,0 +1,110 @@
+condition = (isset($options['invert']) && $options['invert']) ?
+ $condition->invert() : $condition;
+
+ $this->guard = isset($options['guard']) ? $options['guard'] : NULL;
+
+ return $this;
+ }
+
+ function add_body($body)
+ {
+ $this->body = $body;
+ return $this;
+ }
+
+ function compile_node($options)
+ {
+ $options['indent'] .= TAB;
+ $set = '';
+ $body = $this->body;
+
+ if ($body->is_empty())
+ {
+ $body = '';
+ }
+ else
+ {
+ if ($this->returns)
+ {
+ $body->make_return($rvar = $options['scope']->free_variable('results'));
+ $set = "{$this->tab}{$rvar} = [];\n";
+ }
+
+ if ($this->guard)
+ {
+ if ($body->expressions)
+ {
+ array_unshift($body->expressions, yy('If', yy('Parens', $this->guard)->invert(), yy('Literal', 'continue')));
+ }
+ else
+ {
+ $body = yy_Block::wrap(array(yy('If', $this->guard, $body)));
+ }
+ }
+
+ $body = "\n".$body->compile($options, LEVEL_TOP)."\n{$this->tab}";
+ }
+
+ $code = $set.$this->tab.'while ('.$this->condition->compile($options, LEVEL_PAREN).") {{$body}}";
+
+ if ($this->returns)
+ {
+ $code .= "\n{$this->tab}return {$rvar};";
+ }
+
+ return $code;
+ }
+
+ function is_statement()
+ {
+ return TRUE;
+ }
+
+ function jumps()
+ {
+ $expressions = isset($this->body->expressions) ? $this->body->expressions : array();
+
+ if ( ! count($expressions))
+ {
+ return FALSE;
+ }
+
+ foreach ($expressions as $node)
+ {
+ if ($node->jumps(array('loop' => TRUE)))
+ {
+ return $node;
+ }
+ }
+
+ return FALSE;
+ }
+
+ function make_return($res = NULL)
+ {
+ if ($res)
+ {
+ return parent::make_return($res);
+ }
+ else
+ {
+ $this->returns = ! $this->jumps(array('loop' => TRUE));
+ }
+
+ return $this;
+ }
+}
+
+?>
diff --git a/sparks/assets/1.5.1/libraries/cssmin.php b/sparks/assets/1.5.1/libraries/cssmin.php
new file mode 100644
index 0000000..5da2cba
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/cssmin.php
@@ -0,0 +1,5081 @@
+
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * --
+ *
+ * @package CssMin
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+/**
+ * Abstract definition of a CSS token class.
+ *
+ * Every token has to extend this class.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+abstract class aCssToken
+ {
+ /**
+ * Returns the token as string.
+ *
+ * @return string
+ */
+ abstract public function __toString();
+ }
+
+/**
+ * Abstract definition of a for a ruleset start token.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+abstract class aCssRulesetStartToken extends aCssToken
+ {
+
+ }
+
+/**
+ * Abstract definition of a for ruleset end token.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+abstract class aCssRulesetEndToken extends aCssToken
+ {
+ /**
+ * Implements {@link aCssToken::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return "}";
+ }
+ }
+
+/**
+ * Abstract definition of a parser plugin.
+ *
+ * Every parser plugin have to extend this class. A parser plugin contains the logic to parse one or aspects of a
+ * stylesheet.
+ *
+ * @package CssMin/Parser/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+abstract class aCssParserPlugin
+ {
+ /**
+ * Plugin configuration.
+ *
+ * @var array
+ */
+ protected $configuration = array();
+ /**
+ * The CssParser of the plugin.
+ *
+ * @var CssParser
+ */
+ protected $parser = null;
+ /**
+ * Plugin buffer.
+ *
+ * @var string
+ */
+ protected $buffer = "";
+ /**
+ * Constructor.
+ *
+ * @param CssParser $parser The CssParser object of this plugin.
+ * @param array $configuration Plugin configuration [optional]
+ * @return void
+ */
+ public function __construct(CssParser $parser, array $configuration = null)
+ {
+ $this->configuration = $configuration;
+ $this->parser = $parser;
+ }
+ /**
+ * Returns the array of chars triggering the parser plugin.
+ *
+ * @return array
+ */
+ abstract public function getTriggerChars();
+ /**
+ * Returns the array of states triggering the parser plugin or FALSE if every state will trigger the parser plugin.
+ *
+ * @return array
+ */
+ abstract public function getTriggerStates();
+ /**
+ * Parser routine of the plugin.
+ *
+ * @param integer $index Current index
+ * @param string $char Current char
+ * @param string $previousChar Previous char
+ * @return mixed TRUE will break the processing; FALSE continue with the next plugin; integer set a new index and break the processing
+ */
+ abstract public function parse($index, $char, $previousChar, $state);
+ }
+
+/**
+ * Abstract definition of a minifier plugin class.
+ *
+ * Minifier plugin process the parsed tokens one by one to apply changes to the token. Every minifier plugin has to
+ * extend this class.
+ *
+ * @package CssMin/Minifier/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+abstract class aCssMinifierPlugin
+ {
+ /**
+ * Plugin configuration.
+ *
+ * @var array
+ */
+ protected $configuration = array();
+ /**
+ * The CssMinifier of the plugin.
+ *
+ * @var CssMinifier
+ */
+ protected $minifier = null;
+ /**
+ * Constructor.
+ *
+ * @param CssMinifier $minifier The CssMinifier object of this plugin.
+ * @param array $configuration Plugin configuration [optional]
+ * @return void
+ */
+ public function __construct(CssMinifier $minifier, array $configuration = array())
+ {
+ $this->configuration = $configuration;
+ $this->minifier = $minifier;
+ }
+ /**
+ * Apply the plugin to the token.
+ *
+ * @param aCssToken $token Token to process
+ * @return boolean Return TRUE to break the processing of this token; FALSE to continue
+ */
+ abstract public function apply(aCssToken &$token);
+ /**
+ * --
+ *
+ * @return array
+ */
+ abstract public function getTriggerTokens();
+ }
+
+/**
+ * Abstract definition of a minifier filter class.
+ *
+ * Minifier filters allows a pre-processing of the parsed token to add, edit or delete tokens. Every minifier filter
+ * has to extend this class.
+ *
+ * @package CssMin/Minifier/Filters
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+abstract class aCssMinifierFilter
+ {
+ /**
+ * Filter configuration.
+ *
+ * @var array
+ */
+ protected $configuration = array();
+ /**
+ * The CssMinifier of the filter.
+ *
+ * @var CssMinifier
+ */
+ protected $minifier = null;
+ /**
+ * Constructor.
+ *
+ * @param CssMinifier $minifier The CssMinifier object of this plugin.
+ * @param array $configuration Filter configuration [optional]
+ * @return void
+ */
+ public function __construct(CssMinifier $minifier, array $configuration = array())
+ {
+ $this->configuration = $configuration;
+ $this->minifier = $minifier;
+ }
+ /**
+ * Filter the tokens.
+ *
+ * @param array $tokens Array of objects of type aCssToken
+ * @return integer Count of added, changed or removed tokens; a return value large than 0 will rebuild the array
+ */
+ abstract public function apply(array &$tokens);
+ }
+
+/**
+ * Abstract formatter definition.
+ *
+ * Every formatter have to extend this class.
+ *
+ * @package CssMin/Formatter
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+abstract class aCssFormatter
+ {
+ /**
+ * Indent string.
+ *
+ * @var string
+ */
+ protected $indent = " ";
+ /**
+ * Declaration padding.
+ *
+ * @var integer
+ */
+ protected $padding = 0;
+ /**
+ * Tokens.
+ *
+ * @var array
+ */
+ protected $tokens = array();
+ /**
+ * Constructor.
+ *
+ * @param array $tokens Array of CssToken
+ * @param string $indent Indent string [optional]
+ * @param integer $padding Declaration value padding [optional]
+ */
+ public function __construct(array $tokens, $indent = null, $padding = null)
+ {
+ $this->tokens = $tokens;
+ $this->indent = !is_null($indent) ? $indent : $this->indent;
+ $this->padding = !is_null($padding) ? $padding : $this->padding;
+ }
+ /**
+ * Returns the array of aCssToken as formatted string.
+ *
+ * @return string
+ */
+ abstract public function __toString();
+ }
+
+/**
+ * Abstract definition of a ruleset declaration token.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+abstract class aCssDeclarationToken extends aCssToken
+ {
+ /**
+ * Is the declaration flagged as important?
+ *
+ * @var boolean
+ */
+ public $IsImportant = false;
+ /**
+ * Is the declaration flagged as last one of the ruleset?
+ *
+ * @var boolean
+ */
+ public $IsLast = false;
+ /**
+ * Property name of the declaration.
+ *
+ * @var string
+ */
+ public $Property = "";
+ /**
+ * Value of the declaration.
+ *
+ * @var string
+ */
+ public $Value = "";
+ /**
+ * Set the properties of the @font-face declaration.
+ *
+ * @param string $property Property of the declaration
+ * @param string $value Value of the declaration
+ * @param boolean $isImportant Is the !important flag is set?
+ * @param boolean $IsLast Is the declaration the last one of the block?
+ * @return void
+ */
+ public function __construct($property, $value, $isImportant = false, $isLast = false)
+ {
+ $this->Property = $property;
+ $this->Value = $value;
+ $this->IsImportant = $isImportant;
+ $this->IsLast = $isLast;
+ }
+ /**
+ * Implements {@link aCssToken::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return $this->Property . ":" . $this->Value . ($this->IsImportant ? " !important" : "") . ($this->IsLast ? "" : ";");
+ }
+ }
+
+/**
+ * Abstract definition of a for at-rule block start token.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+abstract class aCssAtBlockStartToken extends aCssToken
+ {
+
+ }
+
+/**
+ * Abstract definition of a for at-rule block end token.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+abstract class aCssAtBlockEndToken extends aCssToken
+ {
+ /**
+ * Implements {@link aCssToken::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return "}";
+ }
+ }
+
+/**
+ * {@link aCssFromatter Formatter} returning the CSS source in {@link http://goo.gl/etzLs Whitesmiths indent style}.
+ *
+ * @package CssMin/Formatter
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssWhitesmithsFormatter extends aCssFormatter
+ {
+ /**
+ * Implements {@link aCssFormatter::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ $r = array();
+ $level = 0;
+ for ($i = 0, $l = count($this->tokens); $i < $l; $i++)
+ {
+ $token = $this->tokens[$i];
+ $class = get_class($token);
+ $indent = str_repeat($this->indent, $level);
+ if ($class === "CssCommentToken")
+ {
+ $lines = array_map("trim", explode("\n", $token->Comment));
+ for ($ii = 0, $ll = count($lines); $ii < $ll; $ii++)
+ {
+ $r[] = $indent . (substr($lines[$ii], 0, 1) == "*" ? " " : "") . $lines[$ii];
+ }
+ }
+ elseif ($class === "CssAtCharsetToken")
+ {
+ $r[] = $indent . "@charset " . $token->Charset . ";";
+ }
+ elseif ($class === "CssAtFontFaceStartToken")
+ {
+ $r[] = $indent . "@font-face";
+ $r[] = $this->indent . $indent . "{";
+ $level++;
+ }
+ elseif ($class === "CssAtImportToken")
+ {
+ $r[] = $indent . "@import " . $token->Import . " " . implode(", ", $token->MediaTypes) . ";";
+ }
+ elseif ($class === "CssAtKeyframesStartToken")
+ {
+ $r[] = $indent . "@keyframes \"" . $token->Name . "\"";
+ $r[] = $this->indent . $indent . "{";
+ $level++;
+ }
+ elseif ($class === "CssAtMediaStartToken")
+ {
+ $r[] = $indent . "@media " . implode(", ", $token->MediaTypes);
+ $r[] = $this->indent . $indent . "{";
+ $level++;
+ }
+ elseif ($class === "CssAtPageStartToken")
+ {
+ $r[] = $indent . "@page";
+ $r[] = $this->indent . $indent . "{";
+ $level++;
+ }
+ elseif ($class === "CssAtVariablesStartToken")
+ {
+ $r[] = $indent . "@variables " . implode(", ", $token->MediaTypes);
+ $r[] = $this->indent . $indent . "{";
+ $level++;
+ }
+ elseif ($class === "CssRulesetStartToken" || $class === "CssAtKeyframesRulesetStartToken")
+ {
+ $r[] = $indent . implode(", ", $token->Selectors);
+ $r[] = $this->indent . $indent . "{";
+ $level++;
+ }
+ elseif ($class == "CssAtFontFaceDeclarationToken"
+ || $class === "CssAtKeyframesRulesetDeclarationToken"
+ || $class === "CssAtPageDeclarationToken"
+ || $class == "CssAtVariablesDeclarationToken"
+ || $class === "CssRulesetDeclarationToken"
+ )
+ {
+ $declaration = $indent . $token->Property . ": ";
+ if ($this->padding)
+ {
+ $declaration = str_pad($declaration, $this->padding, " ", STR_PAD_RIGHT);
+ }
+ $r[] = $declaration . $token->Value . ($token->IsImportant ? " !important" : "") . ";";
+ }
+ elseif ($class === "CssAtFontFaceEndToken"
+ || $class === "CssAtMediaEndToken"
+ || $class === "CssAtKeyframesEndToken"
+ || $class === "CssAtKeyframesRulesetEndToken"
+ || $class === "CssAtPageEndToken"
+ || $class === "CssAtVariablesEndToken"
+ || $class === "CssRulesetEndToken"
+ )
+ {
+ $r[] = $indent . "}";
+ $level--;
+ }
+ }
+ return implode("\n", $r);
+ }
+ }
+
+/**
+ * This {@link aCssMinifierPlugin} will process var-statement and sets the declaration value to the variable value.
+ *
+ * This plugin only apply the variable values. The variable values itself will get parsed by the
+ * {@link CssVariablesMinifierFilter}.
+ *
+ * Example:
+ *
+ * @variables
+ * {
+ * defaultColor: black;
+ * }
+ * color: var(defaultColor);
+ *
+ *
+ * Will get converted to:
+ *
+ * color:black;
+ *
+ *
+ * @package CssMin/Minifier/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssVariablesMinifierPlugin extends aCssMinifierPlugin
+ {
+ /**
+ * Regular expression matching a value.
+ *
+ * @var string
+ */
+ private $reMatch = "/var\((.+)\)/iSU";
+ /**
+ * Parsed variables.
+ *
+ * @var array
+ */
+ private $variables = null;
+ /**
+ * Returns the variables.
+ *
+ * @return array
+ */
+ public function getVariables()
+ {
+ return $this->variables;
+ }
+ /**
+ * Implements {@link aCssMinifierPlugin::minify()}.
+ *
+ * @param aCssToken $token Token to process
+ * @return boolean Return TRUE to break the processing of this token; FALSE to continue
+ */
+ public function apply(aCssToken &$token)
+ {
+ if (stripos($token->Value, "var") !== false && preg_match_all($this->reMatch, $token->Value, $m))
+ {
+ $mediaTypes = $token->MediaTypes;
+ if (!in_array("all", $mediaTypes))
+ {
+ $mediaTypes[] = "all";
+ }
+ for ($i = 0, $l = count($m[0]); $i < $l; $i++)
+ {
+ $variable = trim($m[1][$i]);
+ foreach ($mediaTypes as $mediaType)
+ {
+ if (isset($this->variables[$mediaType], $this->variables[$mediaType][$variable]))
+ {
+ // Variable value found => set the declaration value to the variable value and return
+ $token->Value = str_replace($m[0][$i], $this->variables[$mediaType][$variable], $token->Value);
+ continue 2;
+ }
+ }
+ // If no value was found trigger an error and replace the token with a CssNullToken
+ CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": No value found for variable " . $variable . " in media types " . implode(", ", $mediaTypes) . "", (string) $token));
+ $token = new CssNullToken();
+ return true;
+ }
+ }
+ return false;
+ }
+ /**
+ * Implements {@link aMinifierPlugin::getTriggerTokens()}
+ *
+ * @return array
+ */
+ public function getTriggerTokens()
+ {
+ return array
+ (
+ "CssAtFontFaceDeclarationToken",
+ "CssAtPageDeclarationToken",
+ "CssRulesetDeclarationToken"
+ );
+ }
+ /**
+ * Sets the variables.
+ *
+ * @param array $variables Variables to set
+ * @return void
+ */
+ public function setVariables(array $variables)
+ {
+ $this->variables = $variables;
+ }
+ }
+
+/**
+ * This {@link aCssMinifierFilter minifier filter} will parse the variable declarations out of @variables at-rule
+ * blocks. The variables will get store in the {@link CssVariablesMinifierPlugin} that will apply the variables to
+ * declaration.
+ *
+ * @package CssMin/Minifier/Filters
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssVariablesMinifierFilter extends aCssMinifierFilter
+ {
+ /**
+ * Implements {@link aCssMinifierFilter::filter()}.
+ *
+ * @param array $tokens Array of objects of type aCssToken
+ * @return integer Count of added, changed or removed tokens; a return value large than 0 will rebuild the array
+ */
+ public function apply(array &$tokens)
+ {
+ $variables = array();
+ $defaultMediaTypes = array("all");
+ $mediaTypes = array();
+ $remove = array();
+ for($i = 0, $l = count($tokens); $i < $l; $i++)
+ {
+ // @variables at-rule block found
+ if (get_class($tokens[$i]) === "CssAtVariablesStartToken")
+ {
+ $remove[] = $i;
+ $mediaTypes = (count($tokens[$i]->MediaTypes) == 0 ? $defaultMediaTypes : $tokens[$i]->MediaTypes);
+ foreach ($mediaTypes as $mediaType)
+ {
+ if (!isset($variables[$mediaType]))
+ {
+ $variables[$mediaType] = array();
+ }
+ }
+ // Read the variable declaration tokens
+ for($i = $i; $i < $l; $i++)
+ {
+ // Found a variable declaration => read the variable values
+ if (get_class($tokens[$i]) === "CssAtVariablesDeclarationToken")
+ {
+ foreach ($mediaTypes as $mediaType)
+ {
+ $variables[$mediaType][$tokens[$i]->Property] = $tokens[$i]->Value;
+ }
+ $remove[] = $i;
+ }
+ // Found the variables end token => break;
+ elseif (get_class($tokens[$i]) === "CssAtVariablesEndToken")
+ {
+ $remove[] = $i;
+ break;
+ }
+ }
+ }
+ }
+ // Variables in @variables at-rule blocks
+ foreach($variables as $mediaType => $null)
+ {
+ foreach($variables[$mediaType] as $variable => $value)
+ {
+ // If a var() statement in a variable value found...
+ if (stripos($value, "var") !== false && preg_match_all("/var\((.+)\)/iSU", $value, $m))
+ {
+ // ... then replace the var() statement with the variable values.
+ for ($i = 0, $l = count($m[0]); $i < $l; $i++)
+ {
+ $variables[$mediaType][$variable] = str_replace($m[0][$i], (isset($variables[$mediaType][$m[1][$i]]) ? $variables[$mediaType][$m[1][$i]] : ""), $variables[$mediaType][$variable]);
+ }
+ }
+ }
+ }
+ // Remove the complete @variables at-rule block
+ foreach ($remove as $i)
+ {
+ $tokens[$i] = null;
+ }
+ if (!($plugin = $this->minifier->getPlugin("CssVariablesMinifierPlugin")))
+ {
+ CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": The plugin CssVariablesMinifierPlugin was not found but is required for " . __CLASS__ . ""));
+ }
+ else
+ {
+ $plugin->setVariables($variables);
+ }
+ return count($remove);
+ }
+ }
+
+/**
+ * {@link aCssParserPlugin Parser plugin} for preserve parsing url() values.
+ *
+ * This plugin return no {@link aCssToken CssToken} but ensures that url() values will get parsed properly.
+ *
+ * @package CssMin/Parser/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssUrlParserPlugin extends aCssParserPlugin
+ {
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerChars()}.
+ *
+ * @return array
+ */
+ public function getTriggerChars()
+ {
+ return array("(", ")");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerStates()}.
+ *
+ * @return array
+ */
+ public function getTriggerStates()
+ {
+ return false;
+ }
+ /**
+ * Implements {@link aCssParserPlugin::parse()}.
+ *
+ * @param integer $index Current index
+ * @param string $char Current char
+ * @param string $previousChar Previous char
+ * @return mixed TRUE will break the processing; FALSE continue with the next plugin; integer set a new index and break the processing
+ */
+ public function parse($index, $char, $previousChar, $state)
+ {
+ // Start of string
+ if ($char === "(" && strtolower(substr($this->parser->getSource(), $index - 3, 4)) === "url(" && $state !== "T_URL")
+ {
+ $this->parser->pushState("T_URL");
+ $this->parser->setExclusive(__CLASS__);
+ }
+ // Escaped LF in url => remove escape backslash and LF
+ elseif ($char === "\n" && $previousChar === "\\" && $state === "T_URL")
+ {
+ $this->parser->setBuffer(substr($this->parser->getBuffer(), 0, -2));
+ }
+ // Parse error: Unescaped LF in string literal
+ elseif ($char === "\n" && $previousChar !== "\\" && $state === "T_URL")
+ {
+ $line = $this->parser->getBuffer();
+ $this->parser->setBuffer(substr($this->parser->getBuffer(), 0, -1) . ")"); // Replace the LF with the url string delimiter
+ $this->parser->popState();
+ $this->parser->unsetExclusive();
+ CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Unterminated string literal", $line . "_"));
+ }
+ // End of string
+ elseif ($char === ")" && $state === "T_URL")
+ {
+ $this->parser->popState();
+ $this->parser->unsetExclusive();
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+
+/**
+ * {@link aCssParserPlugin Parser plugin} for preserve parsing string values.
+ *
+ * This plugin return no {@link aCssToken CssToken} but ensures that string values will get parsed properly.
+ *
+ * @package CssMin/Parser/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssStringParserPlugin extends aCssParserPlugin
+ {
+ /**
+ * Current string delimiter char.
+ *
+ * @var string
+ */
+ private $delimiterChar = null;
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerChars()}.
+ *
+ * @return array
+ */
+ public function getTriggerChars()
+ {
+ return array("\"", "'", "\n");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerStates()}.
+ *
+ * @return array
+ */
+ public function getTriggerStates()
+ {
+ return false;
+ }
+ /**
+ * Implements {@link aCssParserPlugin::parse()}.
+ *
+ * @param integer $index Current index
+ * @param string $char Current char
+ * @param string $previousChar Previous char
+ * @return mixed TRUE will break the processing; FALSE continue with the next plugin; integer set a new index and break the processing
+ */
+ public function parse($index, $char, $previousChar, $state)
+ {
+ // Start of string
+ if (($char === "\"" || $char === "'") && $state !== "T_STRING")
+ {
+ $this->delimiterChar = $char;
+ $this->parser->pushState("T_STRING");
+ $this->parser->setExclusive(__CLASS__);
+ }
+ // Escaped LF in string => remove escape backslash and LF
+ elseif ($char === "\n" && $previousChar === "\\" && $state === "T_STRING")
+ {
+ $this->parser->setBuffer(substr($this->parser->getBuffer(), 0, -2));
+ }
+ // Parse error: Unescaped LF in string literal
+ elseif ($char === "\n" && $previousChar !== "\\" && $state === "T_STRING")
+ {
+ $line = $this->parser->getBuffer();
+ $this->parser->popState();
+ $this->parser->unsetExclusive();
+ $this->parser->setBuffer(substr($this->parser->getBuffer(), 0, -1) . $this->delimiterChar); // Replace the LF with the current string char
+ CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Unterminated string literal", $line . "_"));
+ $this->delimiterChar = null;
+ }
+ // End of string
+ elseif ($char === $this->delimiterChar && $state === "T_STRING")
+ {
+ // If the Previous char is a escape char count the amount of the previous escape chars. If the amount of
+ // escape chars is uneven do not end the string
+ if ($previousChar == "\\")
+ {
+ $source = $this->parser->getSource();
+ $c = 1;
+ $i = $index - 2;
+ while (substr($source, $i, 1) === "\\")
+ {
+ $c++; $i--;
+ }
+ if ($c % 2)
+ {
+ return false;
+ }
+ }
+ $this->parser->popState();
+ $this->parser->unsetExclusive();
+ $this->delimiterChar = null;
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+
+/**
+ * This {@link aCssMinifierFilter minifier filter} sorts the ruleset declarations of a ruleset by name.
+ *
+ * @package CssMin/Minifier/Filters
+ * @link http://code.google.com/p/cssmin/
+ * @author Rowan Beentje
+ * @copyright Rowan Beentje
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssSortRulesetPropertiesMinifierFilter extends aCssMinifierFilter
+ {
+ /**
+ * Implements {@link aCssMinifierFilter::filter()}.
+ *
+ * @param array $tokens Array of objects of type aCssToken
+ * @return integer Count of added, changed or removed tokens; a return value larger than 0 will rebuild the array
+ */
+ public function apply(array &$tokens)
+ {
+ $r = 0;
+ for ($i = 0, $l = count($tokens); $i < $l; $i++)
+ {
+ // Only look for ruleset start rules
+ if (get_class($tokens[$i]) !== "CssRulesetStartToken") { continue; }
+ // Look for the corresponding ruleset end
+ $endIndex = false;
+ for ($ii = $i + 1; $ii < $l; $ii++)
+ {
+ if (get_class($tokens[$ii]) !== "CssRulesetEndToken") { continue; }
+ $endIndex = $ii;
+ break;
+ }
+ if (!$endIndex) { break; }
+ $startIndex = $i;
+ $i = $endIndex;
+ // Skip if there's only one token in this ruleset
+ if ($endIndex - $startIndex <= 2) { continue; }
+ // Ensure that everything between the start and end is a declaration token, for safety
+ for ($ii = $startIndex + 1; $ii < $endIndex; $ii++)
+ {
+ if (get_class($tokens[$ii]) !== "CssRulesetDeclarationToken") { continue(2); }
+ }
+ $declarations = array_slice($tokens, $startIndex + 1, $endIndex - $startIndex - 1);
+ // Check whether a sort is required
+ $sortRequired = $lastPropertyName = false;
+ foreach ($declarations as $declaration)
+ {
+ if ($lastPropertyName)
+ {
+ if (strcmp($lastPropertyName, $declaration->Property) > 0)
+ {
+ $sortRequired = true;
+ break;
+ }
+ }
+ $lastPropertyName = $declaration->Property;
+ }
+ if (!$sortRequired) { continue; }
+ // Arrange the declarations alphabetically by name
+ usort($declarations, array(__CLASS__, "userDefinedSort1"));
+ // Update "IsLast" property
+ for ($ii = 0, $ll = count($declarations) - 1; $ii <= $ll; $ii++)
+ {
+ if ($ii == $ll)
+ {
+ $declarations[$ii]->IsLast = true;
+ }
+ else
+ {
+ $declarations[$ii]->IsLast = false;
+ }
+ }
+ // Splice back into the array.
+ array_splice($tokens, $startIndex + 1, $endIndex - $startIndex - 1, $declarations);
+ $r += $endIndex - $startIndex - 1;
+ }
+ return $r;
+ }
+ /**
+ * User defined sort function.
+ *
+ * @return integer
+ */
+ public static function userDefinedSort1($a, $b)
+ {
+ return strcmp($a->Property, $b->Property);
+ }
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents the start of a ruleset.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssRulesetStartToken extends aCssRulesetStartToken
+ {
+ /**
+ * Array of selectors.
+ *
+ * @var array
+ */
+ public $Selectors = array();
+ /**
+ * Set the properties of a ruleset token.
+ *
+ * @param array $selectors Selectors of the ruleset
+ * @return void
+ */
+ public function __construct(array $selectors = array())
+ {
+ $this->Selectors = $selectors;
+ }
+ /**
+ * Implements {@link aCssToken::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return implode(",", $this->Selectors) . "{";
+ }
+ }
+
+/**
+ * {@link aCssParserPlugin Parser plugin} for parsing ruleset block with including declarations.
+ *
+ * Found rulesets will add a {@link CssRulesetStartToken} and {@link CssRulesetEndToken} to the
+ * parser; including declarations as {@link CssRulesetDeclarationToken}.
+ *
+ * @package CssMin/Parser/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssRulesetParserPlugin extends aCssParserPlugin
+ {
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerChars()}.
+ *
+ * @return array
+ */
+ public function getTriggerChars()
+ {
+ return array(",", "{", "}", ":", ";");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerStates()}.
+ *
+ * @return array
+ */
+ public function getTriggerStates()
+ {
+ return array("T_DOCUMENT", "T_AT_MEDIA", "T_RULESET::SELECTORS", "T_RULESET", "T_RULESET_DECLARATION");
+ }
+ /**
+ * Selectors.
+ *
+ * @var array
+ */
+ private $selectors = array();
+ /**
+ * Implements {@link aCssParserPlugin::parse()}.
+ *
+ * @param integer $index Current index
+ * @param string $char Current char
+ * @param string $previousChar Previous char
+ * @return mixed TRUE will break the processing; FALSE continue with the next plugin; integer set a new index and break the processing
+ */
+ public function parse($index, $char, $previousChar, $state)
+ {
+ // Start of Ruleset and selectors
+ if ($char === "," && ($state === "T_DOCUMENT" || $state === "T_AT_MEDIA" || $state === "T_RULESET::SELECTORS"))
+ {
+ if ($state !== "T_RULESET::SELECTORS")
+ {
+ $this->parser->pushState("T_RULESET::SELECTORS");
+ }
+ $this->selectors[] = $this->parser->getAndClearBuffer(",{");
+ }
+ // End of selectors and start of declarations
+ elseif ($char === "{" && ($state === "T_DOCUMENT" || $state === "T_AT_MEDIA" || $state === "T_RULESET::SELECTORS"))
+ {
+ if ($this->parser->getBuffer() !== "")
+ {
+ $this->selectors[] = $this->parser->getAndClearBuffer(",{");
+ if ($state == "T_RULESET::SELECTORS")
+ {
+ $this->parser->popState();
+ }
+ $this->parser->pushState("T_RULESET");
+ $this->parser->appendToken(new CssRulesetStartToken($this->selectors));
+ $this->selectors = array();
+ }
+ }
+ // Start of declaration
+ elseif ($char === ":" && $state === "T_RULESET")
+ {
+ $this->parser->pushState("T_RULESET_DECLARATION");
+ $this->buffer = $this->parser->getAndClearBuffer(":;", true);
+ }
+ // Unterminated ruleset declaration
+ elseif ($char === ":" && $state === "T_RULESET_DECLARATION")
+ {
+ // Ignore Internet Explorer filter declarations
+ if ($this->buffer === "filter")
+ {
+ return false;
+ }
+ CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Unterminated declaration", $this->buffer . ":" . $this->parser->getBuffer() . "_"));
+ }
+ // End of declaration
+ elseif (($char === ";" || $char === "}") && $state === "T_RULESET_DECLARATION")
+ {
+ $value = $this->parser->getAndClearBuffer(";}");
+ if (strtolower(substr($value, -10, 10)) === "!important")
+ {
+ $value = trim(substr($value, 0, -10));
+ $isImportant = true;
+ }
+ else
+ {
+ $isImportant = false;
+ }
+ $this->parser->popState();
+ $this->parser->appendToken(new CssRulesetDeclarationToken($this->buffer, $value, $this->parser->getMediaTypes(), $isImportant));
+ // Declaration ends with a right curly brace; so we have to end the ruleset
+ if ($char === "}")
+ {
+ $this->parser->appendToken(new CssRulesetEndToken());
+ $this->parser->popState();
+ }
+ $this->buffer = "";
+ }
+ // End of ruleset
+ elseif ($char === "}" && $state === "T_RULESET")
+ {
+ $this->parser->popState();
+ $this->parser->clearBuffer();
+ $this->parser->appendToken(new CssRulesetEndToken());
+ $this->buffer = "";
+ $this->selectors = array();
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents the end of a ruleset.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssRulesetEndToken extends aCssRulesetEndToken
+ {
+
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents a ruleset declaration.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssRulesetDeclarationToken extends aCssDeclarationToken
+ {
+ /**
+ * Media types of the declaration.
+ *
+ * @var array
+ */
+ public $MediaTypes = array("all");
+ /**
+ * Set the properties of a ddocument- or at-rule @media level declaration.
+ *
+ * @param string $property Property of the declaration
+ * @param string $value Value of the declaration
+ * @param mixed $mediaTypes Media types of the declaration
+ * @param boolean $isImportant Is the !important flag is set
+ * @param boolean $isLast Is the declaration the last one of the ruleset
+ * @return void
+ */
+ public function __construct($property, $value, $mediaTypes = null, $isImportant = false, $isLast = false)
+ {
+ parent::__construct($property, $value, $isImportant, $isLast);
+ $this->MediaTypes = $mediaTypes ? $mediaTypes : array("all");
+ }
+ }
+
+/**
+ * This {@link aCssMinifierFilter minifier filter} sets the IsLast property of any last declaration in a ruleset,
+ * @font-face at-rule or @page at-rule block. If the property IsLast is TRUE the decrations will get stringified
+ * without tailing semicolon.
+ *
+ * @package CssMin/Minifier/Filters
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssRemoveLastDelarationSemiColonMinifierFilter extends aCssMinifierFilter
+ {
+ /**
+ * Implements {@link aCssMinifierFilter::filter()}.
+ *
+ * @param array $tokens Array of objects of type aCssToken
+ * @return integer Count of added, changed or removed tokens; a return value large than 0 will rebuild the array
+ */
+ public function apply(array &$tokens)
+ {
+ for ($i = 0, $l = count($tokens); $i < $l; $i++)
+ {
+ $current = get_class($tokens[$i]);
+ $next = isset($tokens[$i+1]) ? get_class($tokens[$i+1]) : false;
+ if (($current === "CssRulesetDeclarationToken" && $next === "CssRulesetEndToken") ||
+ ($current === "CssAtFontFaceDeclarationToken" && $next === "CssAtFontFaceEndToken") ||
+ ($current === "CssAtPageDeclarationToken" && $next === "CssAtPageEndToken"))
+ {
+ $tokens[$i]->IsLast = true;
+ }
+ }
+ return 0;
+ }
+ }
+
+/**
+ * This {@link aCssMinifierFilter minifier filter} will remove any empty rulesets (including @keyframes at-rule block
+ * rulesets).
+ *
+ * @package CssMin/Minifier/Filters
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssRemoveEmptyRulesetsMinifierFilter extends aCssMinifierFilter
+ {
+ /**
+ * Implements {@link aCssMinifierFilter::filter()}.
+ *
+ * @param array $tokens Array of objects of type aCssToken
+ * @return integer Count of added, changed or removed tokens; a return value large than 0 will rebuild the array
+ */
+ public function apply(array &$tokens)
+ {
+ $r = 0;
+ for ($i = 0, $l = count($tokens); $i < $l; $i++)
+ {
+ $current = get_class($tokens[$i]);
+ $next = isset($tokens[$i + 1]) ? get_class($tokens[$i + 1]) : false;
+ if (($current === "CssRulesetStartToken" && $next === "CssRulesetEndToken") ||
+ ($current === "CssAtKeyframesRulesetStartToken" && $next === "CssAtKeyframesRulesetEndToken" && !array_intersect(array("from", "0%", "to", "100%"), array_map("strtolower", $tokens[$i]->Selectors)))
+ )
+ {
+ $tokens[$i] = null;
+ $tokens[$i + 1] = null;
+ $i++;
+ $r = $r + 2;
+ }
+ }
+ return $r;
+ }
+ }
+
+/**
+ * This {@link aCssMinifierFilter minifier filter} will remove any empty @font-face, @keyframes, @media and @page
+ * at-rule blocks.
+ *
+ * @package CssMin/Minifier/Filters
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssRemoveEmptyAtBlocksMinifierFilter extends aCssMinifierFilter
+ {
+ /**
+ * Implements {@link aCssMinifierFilter::filter()}.
+ *
+ * @param array $tokens Array of objects of type aCssToken
+ * @return integer Count of added, changed or removed tokens; a return value large than 0 will rebuild the array
+ */
+ public function apply(array &$tokens)
+ {
+ $r = 0;
+ for ($i = 0, $l = count($tokens); $i < $l; $i++)
+ {
+ $current = get_class($tokens[$i]);
+ $next = isset($tokens[$i + 1]) ? get_class($tokens[$i + 1]) : false;
+ if (($current === "CssAtFontFaceStartToken" && $next === "CssAtFontFaceEndToken") ||
+ ($current === "CssAtKeyframesStartToken" && $next === "CssAtKeyframesEndToken") ||
+ ($current === "CssAtPageStartToken" && $next === "CssAtPageEndToken") ||
+ ($current === "CssAtMediaStartToken" && $next === "CssAtMediaEndToken"))
+ {
+ $tokens[$i] = null;
+ $tokens[$i + 1] = null;
+ $i++;
+ $r = $r + 2;
+ }
+ }
+ return $r;
+ }
+ }
+
+/**
+ * This {@link aCssMinifierFilter minifier filter} will remove any comments from the array of parsed tokens.
+ *
+ * @package CssMin/Minifier/Filters
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssRemoveCommentsMinifierFilter extends aCssMinifierFilter
+ {
+ /**
+ * Implements {@link aCssMinifierFilter::filter()}.
+ *
+ * @param array $tokens Array of objects of type aCssToken
+ * @return integer Count of added, changed or removed tokens; a return value large than 0 will rebuild the array
+ */
+ public function apply(array &$tokens)
+ {
+ $r = 0;
+ for ($i = 0, $l = count($tokens); $i < $l; $i++)
+ {
+ if (get_class($tokens[$i]) === "CssCommentToken")
+ {
+ $tokens[$i] = null;
+ $r++;
+ }
+ }
+ return $r;
+ }
+ }
+
+/**
+ * CSS Parser.
+ *
+ * @package CssMin/Parser
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssParser
+ {
+ /**
+ * Parse buffer.
+ *
+ * @var string
+ */
+ private $buffer = "";
+ /**
+ * {@link aCssParserPlugin Plugins}.
+ *
+ * @var array
+ */
+ private $plugins = array();
+ /**
+ * Source to parse.
+ *
+ * @var string
+ */
+ private $source = "";
+ /**
+ * Current state.
+ *
+ * @var integer
+ */
+ private $state = "T_DOCUMENT";
+ /**
+ * Exclusive state.
+ *
+ * @var string
+ */
+ private $stateExclusive = false;
+ /**
+ * Media types state.
+ *
+ * @var mixed
+ */
+ private $stateMediaTypes = false;
+ /**
+ * State stack.
+ *
+ * @var array
+ */
+ private $states = array("T_DOCUMENT");
+ /**
+ * Parsed tokens.
+ *
+ * @var array
+ */
+ private $tokens = array();
+ /**
+ * Constructer.
+ *
+ * Create instances of the used {@link aCssParserPlugin plugins}.
+ *
+ * @param string $source CSS source [optional]
+ * @param array $plugins Plugin configuration [optional]
+ * @return void
+ */
+ public function __construct($source = null, array $plugins = null)
+ {
+ $plugins = array_merge(array
+ (
+ "Comment" => true,
+ "String" => true,
+ "Url" => true,
+ "Expression" => true,
+ "Ruleset" => true,
+ "AtCharset" => true,
+ "AtFontFace" => true,
+ "AtImport" => true,
+ "AtKeyframes" => true,
+ "AtMedia" => true,
+ "AtPage" => true,
+ "AtVariables" => true
+ ), is_array($plugins) ? $plugins : array());
+ // Create plugin instances
+ foreach ($plugins as $name => $config)
+ {
+ if ($config !== false)
+ {
+ $class = "Css" . $name . "ParserPlugin";
+ $config = is_array($config) ? $config : array();
+ if (class_exists($class))
+ {
+ $this->plugins[] = new $class($this, $config);
+ }
+ else
+ {
+ CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": The plugin " . $name . " with the class name " . $class . " was not found"));
+ }
+ }
+ }
+ if (!is_null($source))
+ {
+ $this->parse($source);
+ }
+ }
+ /**
+ * Append a token to the array of tokens.
+ *
+ * @param aCssToken $token Token to append
+ * @return void
+ */
+ public function appendToken(aCssToken $token)
+ {
+ $this->tokens[] = $token;
+ }
+ /**
+ * Clears the current buffer.
+ *
+ * @return void
+ */
+ public function clearBuffer()
+ {
+ $this->buffer = "";
+ }
+ /**
+ * Returns and clear the current buffer.
+ *
+ * @param string $trim Chars to use to trim the returned buffer
+ * @param boolean $tolower if TRUE the returned buffer will get converted to lower case
+ * @return string
+ */
+ public function getAndClearBuffer($trim = "", $tolower = false)
+ {
+ $r = $this->getBuffer($trim, $tolower);
+ $this->buffer = "";
+ return $r;
+ }
+ /**
+ * Returns the current buffer.
+ *
+ * @param string $trim Chars to use to trim the returned buffer
+ * @param boolean $tolower if TRUE the returned buffer will get converted to lower case
+ * @return string
+ */
+ public function getBuffer($trim = "", $tolower = false)
+ {
+ $r = $this->buffer;
+ if ($trim)
+ {
+ $r = trim($r, " \t\n\r\0\x0B" . $trim);
+ }
+ if ($tolower)
+ {
+ $r = strtolower($r);
+ }
+ return $r;
+ }
+ /**
+ * Returns the current media types state.
+ *
+ * @return array
+ */
+ public function getMediaTypes()
+ {
+ return $this->stateMediaTypes;
+ }
+ /**
+ * Returns the CSS source.
+ *
+ * @return string
+ */
+ public function getSource()
+ {
+ return $this->source;
+ }
+ /**
+ * Returns the current state.
+ *
+ * @return integer The current state
+ */
+ public function getState()
+ {
+ return $this->state;
+ }
+ /**
+ * Returns a plugin by class name.
+ *
+ * @param string $name Class name of the plugin
+ * @return aCssParserPlugin
+ */
+ public function getPlugin($class)
+ {
+ static $index = null;
+ if (is_null($index))
+ {
+ $index = array();
+ for ($i = 0, $l = count($this->plugins); $i < $l; $i++)
+ {
+ $index[get_class($this->plugins[$i])] = $i;
+ }
+ }
+ return isset($index[$class]) ? $this->plugins[$index[$class]] : false;
+ }
+ /**
+ * Returns the parsed tokens.
+ *
+ * @return array
+ */
+ public function getTokens()
+ {
+ return $this->tokens;
+ }
+ /**
+ * Returns if the current state equals the passed state.
+ *
+ * @param integer $state State to compare with the current state
+ * @return boolean TRUE is the state equals to the passed state; FALSE if not
+ */
+ public function isState($state)
+ {
+ return ($this->state == $state);
+ }
+ /**
+ * Parse the CSS source and return a array with parsed tokens.
+ *
+ * @param string $source CSS source
+ * @return array Array with tokens
+ */
+ public function parse($source)
+ {
+ // Reset
+ $this->source = "";
+ $this->tokens = array();
+ // Create a global and plugin lookup table for trigger chars; set array of plugins as local variable and create
+ // several helper variables for plugin handling
+ $globalTriggerChars = "";
+ $plugins = $this->plugins;
+ $pluginCount = count($plugins);
+ $pluginIndex = array();
+ $pluginTriggerStates = array();
+ $pluginTriggerChars = array();
+ for ($i = 0, $l = count($plugins); $i < $l; $i++)
+ {
+ $tPluginClassName = get_class($plugins[$i]);
+ $pluginTriggerChars[$i] = implode("", $plugins[$i]->getTriggerChars());
+ $tPluginTriggerStates = $plugins[$i]->getTriggerStates();
+ $pluginTriggerStates[$i] = $tPluginTriggerStates === false ? false : "|" . implode("|", $tPluginTriggerStates) . "|";
+ $pluginIndex[$tPluginClassName] = $i;
+ for ($ii = 0, $ll = strlen($pluginTriggerChars[$i]); $ii < $ll; $ii++)
+ {
+ $c = substr($pluginTriggerChars[$i], $ii, 1);
+ if (strpos($globalTriggerChars, $c) === false)
+ {
+ $globalTriggerChars .= $c;
+ }
+ }
+ }
+ // Normalise line endings
+ $source = str_replace("\r\n", "\n", $source); // Windows to Unix line endings
+ $source = str_replace("\r", "\n", $source); // Mac to Unix line endings
+ $this->source = $source;
+ // Variables
+ $buffer = &$this->buffer;
+ $exclusive = &$this->stateExclusive;
+ $state = &$this->state;
+ $c = $p = null;
+ // --
+ for ($i = 0, $l = strlen($source); $i < $l; $i++)
+ {
+ // Set the current Char
+ $c = $source[$i]; // Is faster than: $c = substr($source, $i, 1);
+ // Normalize and filter double whitespace characters
+ if ($exclusive === false)
+ {
+ if ($c === "\n" || $c === "\t")
+ {
+ $c = " ";
+ }
+ if ($c === " " && $p === " ")
+ {
+ continue;
+ }
+ }
+ $buffer .= $c;
+ // Extended processing only if the current char is a global trigger char
+ if (strpos($globalTriggerChars, $c) !== false)
+ {
+ // Exclusive state is set; process with the exclusive plugin
+ if ($exclusive)
+ {
+ $tPluginIndex = $pluginIndex[$exclusive];
+ if (strpos($pluginTriggerChars[$tPluginIndex], $c) !== false && ($pluginTriggerStates[$tPluginIndex] === false || strpos($pluginTriggerStates[$tPluginIndex], $state) !== false))
+ {
+ $r = $plugins[$tPluginIndex]->parse($i, $c, $p, $state);
+ // Return value is TRUE => continue with next char
+ if ($r === true)
+ {
+ continue;
+ }
+ // Return value is numeric => set new index and continue with next char
+ elseif ($r !== false && $r != $i)
+ {
+ $i = $r;
+ continue;
+ }
+ }
+ }
+ // Else iterate through the plugins
+ else
+ {
+ $triggerState = "|" . $state . "|";
+ for ($ii = 0, $ll = $pluginCount; $ii < $ll; $ii++)
+ {
+ // Only process if the current char is one of the plugin trigger chars
+ if (strpos($pluginTriggerChars[$ii], $c) !== false && ($pluginTriggerStates[$ii] === false || strpos($pluginTriggerStates[$ii], $triggerState) !== false))
+ {
+ // Process with the plugin
+ $r = $plugins[$ii]->parse($i, $c, $p, $state);
+ // Return value is TRUE => break the plugin loop and and continue with next char
+ if ($r === true)
+ {
+ break;
+ }
+ // Return value is numeric => set new index, break the plugin loop and and continue with next char
+ elseif ($r !== false && $r != $i)
+ {
+ $i = $r;
+ break;
+ }
+ }
+ }
+ }
+ }
+ $p = $c; // Set the parent char
+ }
+ return $this->tokens;
+ }
+ /**
+ * Remove the last state of the state stack and return the removed stack value.
+ *
+ * @return integer Removed state value
+ */
+ public function popState()
+ {
+ $r = array_pop($this->states);
+ $this->state = $this->states[count($this->states) - 1];
+ return $r;
+ }
+ /**
+ * Adds a new state onto the state stack.
+ *
+ * @param integer $state State to add onto the state stack.
+ * @return integer The index of the added state in the state stacks
+ */
+ public function pushState($state)
+ {
+ $r = array_push($this->states, $state);
+ $this->state = $this->states[count($this->states) - 1];
+ return $r;
+ }
+ /**
+ * Sets/restores the buffer.
+ *
+ * @param string $buffer Buffer to set
+ * @return void
+ */
+ public function setBuffer($buffer)
+ {
+ $this->buffer = $buffer;
+ }
+ /**
+ * Set the exclusive state.
+ *
+ * @param string $exclusive Exclusive state
+ * @return void
+ */
+ public function setExclusive($exclusive)
+ {
+ $this->stateExclusive = $exclusive;
+ }
+ /**
+ * Set the media types state.
+ *
+ * @param array $mediaTypes Media types state
+ * @return void
+ */
+ public function setMediaTypes(array $mediaTypes)
+ {
+ $this->stateMediaTypes = $mediaTypes;
+ }
+ /**
+ * Sets the current state in the state stack; equals to {@link CssParser::popState()} + {@link CssParser::pushState()}.
+ *
+ * @param integer $state State to set
+ * @return integer
+ */
+ public function setState($state)
+ {
+ $r = array_pop($this->states);
+ array_push($this->states, $state);
+ $this->state = $this->states[count($this->states) - 1];
+ return $r;
+ }
+ /**
+ * Removes the exclusive state.
+ *
+ * @return void
+ */
+ public function unsetExclusive()
+ {
+ $this->stateExclusive = false;
+ }
+ /**
+ * Removes the media types state.
+ *
+ * @return void
+ */
+ public function unsetMediaTypes()
+ {
+ $this->stateMediaTypes = false;
+ }
+ }
+
+/**
+ * {@link aCssFromatter Formatter} returning the CSS source in {@link http://goo.gl/j4XdU OTBS indent style} (The One True Brace Style).
+ *
+ * @package CssMin/Formatter
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssOtbsFormatter extends aCssFormatter
+ {
+ /**
+ * Implements {@link aCssFormatter::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ $r = array();
+ $level = 0;
+ for ($i = 0, $l = count($this->tokens); $i < $l; $i++)
+ {
+ $token = $this->tokens[$i];
+ $class = get_class($token);
+ $indent = str_repeat($this->indent, $level);
+ if ($class === "CssCommentToken")
+ {
+ $lines = array_map("trim", explode("\n", $token->Comment));
+ for ($ii = 0, $ll = count($lines); $ii < $ll; $ii++)
+ {
+ $r[] = $indent . (substr($lines[$ii], 0, 1) == "*" ? " " : "") . $lines[$ii];
+ }
+ }
+ elseif ($class === "CssAtCharsetToken")
+ {
+ $r[] = $indent . "@charset " . $token->Charset . ";";
+ }
+ elseif ($class === "CssAtFontFaceStartToken")
+ {
+ $r[] = $indent . "@font-face {";
+ $level++;
+ }
+ elseif ($class === "CssAtImportToken")
+ {
+ $r[] = $indent . "@import " . $token->Import . " " . implode(", ", $token->MediaTypes) . ";";
+ }
+ elseif ($class === "CssAtKeyframesStartToken")
+ {
+ $r[] = $indent . "@keyframes \"" . $token->Name . "\" {";
+ $level++;
+ }
+ elseif ($class === "CssAtMediaStartToken")
+ {
+ $r[] = $indent . "@media " . implode(", ", $token->MediaTypes) . " {";
+ $level++;
+ }
+ elseif ($class === "CssAtPageStartToken")
+ {
+ $r[] = $indent . "@page {";
+ $level++;
+ }
+ elseif ($class === "CssAtVariablesStartToken")
+ {
+ $r[] = $indent . "@variables " . implode(", ", $token->MediaTypes) . " {";
+ $level++;
+ }
+ elseif ($class === "CssRulesetStartToken" || $class === "CssAtKeyframesRulesetStartToken")
+ {
+ $r[] = $indent . implode(", ", $token->Selectors) . " {";
+ $level++;
+ }
+ elseif ($class == "CssAtFontFaceDeclarationToken"
+ || $class === "CssAtKeyframesRulesetDeclarationToken"
+ || $class === "CssAtPageDeclarationToken"
+ || $class == "CssAtVariablesDeclarationToken"
+ || $class === "CssRulesetDeclarationToken"
+ )
+ {
+ $declaration = $indent . $token->Property . ": ";
+ if ($this->padding)
+ {
+ $declaration = str_pad($declaration, $this->padding, " ", STR_PAD_RIGHT);
+ }
+ $r[] = $declaration . $token->Value . ($token->IsImportant ? " !important" : "") . ";";
+ }
+ elseif ($class === "CssAtFontFaceEndToken"
+ || $class === "CssAtMediaEndToken"
+ || $class === "CssAtKeyframesEndToken"
+ || $class === "CssAtKeyframesRulesetEndToken"
+ || $class === "CssAtPageEndToken"
+ || $class === "CssAtVariablesEndToken"
+ || $class === "CssRulesetEndToken"
+ )
+ {
+ $level--;
+ $r[] = str_repeat($indent, $level) . "}";
+ }
+ }
+ return implode("\n", $r);
+ }
+ }
+
+/**
+ * This {@link aCssToken CSS token} is a utility token that extends {@link aNullToken} and returns only a empty string.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssNullToken extends aCssToken
+ {
+ /**
+ * Implements {@link aCssToken::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return "";
+ }
+ }
+
+/**
+ * CSS Minifier.
+ *
+ * @package CssMin/Minifier
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssMinifier
+ {
+ /**
+ * {@link aCssMinifierFilter Filters}.
+ *
+ * @var array
+ */
+ private $filters = array();
+ /**
+ * {@link aCssMinifierPlugin Plugins}.
+ *
+ * @var array
+ */
+ private $plugins = array();
+ /**
+ * Minified source.
+ *
+ * @var string
+ */
+ private $minified = "";
+ /**
+ * Constructer.
+ *
+ * Creates instances of {@link aCssMinifierFilter filters} and {@link aCssMinifierPlugin plugins}.
+ *
+ * @param string $source CSS source [optional]
+ * @param array $filters Filter configuration [optional]
+ * @param array $plugins Plugin configuration [optional]
+ * @return void
+ */
+ public function __construct($source = null, array $filters = null, array $plugins = null)
+ {
+ $filters = array_merge(array
+ (
+ "ImportImports" => false,
+ "RemoveComments" => true,
+ "RemoveEmptyRulesets" => true,
+ "RemoveEmptyAtBlocks" => true,
+ "ConvertLevel3Properties" => false,
+ "ConvertLevel3AtKeyframes" => false,
+ "Variables" => true,
+ "RemoveLastDelarationSemiColon" => true
+ ), is_array($filters) ? $filters : array());
+ $plugins = array_merge(array
+ (
+ "Variables" => true,
+ "ConvertFontWeight" => false,
+ "ConvertHslColors" => false,
+ "ConvertRgbColors" => false,
+ "ConvertNamedColors" => false,
+ "CompressColorValues" => false,
+ "CompressUnitValues" => false,
+ "CompressExpressionValues" => false
+ ), is_array($plugins) ? $plugins : array());
+ // Filters
+ foreach ($filters as $name => $config)
+ {
+ if ($config !== false)
+ {
+ $class = "Css" . $name . "MinifierFilter";
+ $config = is_array($config) ? $config : array();
+ if (class_exists($class))
+ {
+ $this->filters[] = new $class($this, $config);
+ }
+ else
+ {
+ CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": The filter " . $name . " with the class name " . $class . " was not found"));
+ }
+ }
+ }
+ // Plugins
+ foreach ($plugins as $name => $config)
+ {
+ if ($config !== false)
+ {
+ $class = "Css" . $name . "MinifierPlugin";
+ $config = is_array($config) ? $config : array();
+ if (class_exists($class))
+ {
+ $this->plugins[] = new $class($this, $config);
+ }
+ else
+ {
+ CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": The plugin " . $name . " with the class name " . $class . " was not found"));
+ }
+ }
+ }
+ // --
+ if (!is_null($source))
+ {
+ $this->minify($source);
+ }
+ }
+ /**
+ * Returns the minified Source.
+ *
+ * @return string
+ */
+ public function getMinified()
+ {
+ return $this->minified;
+ }
+ /**
+ * Returns a plugin by class name.
+ *
+ * @param string $name Class name of the plugin
+ * @return aCssMinifierPlugin
+ */
+ public function getPlugin($class)
+ {
+ static $index = null;
+ if (is_null($index))
+ {
+ $index = array();
+ for ($i = 0, $l = count($this->plugins); $i < $l; $i++)
+ {
+ $index[get_class($this->plugins[$i])] = $i;
+ }
+ }
+ return isset($index[$class]) ? $this->plugins[$index[$class]] : false;
+ }
+ /**
+ * Minifies the CSS source.
+ *
+ * @param string $source CSS source
+ * @return string
+ */
+ public function minify($source)
+ {
+ // Variables
+ $r = "";
+ $parser = new CssParser($source);
+ $tokens = $parser->getTokens();
+ $filters = $this->filters;
+ $filterCount = count($this->filters);
+ $plugins = $this->plugins;
+ $pluginCount = count($plugins);
+ $pluginIndex = array();
+ $pluginTriggerTokens = array();
+ $globalTriggerTokens = array();
+ for ($i = 0, $l = count($plugins); $i < $l; $i++)
+ {
+ $tPluginClassName = get_class($plugins[$i]);
+ $pluginTriggerTokens[$i] = $plugins[$i]->getTriggerTokens();
+ foreach ($pluginTriggerTokens[$i] as $v)
+ {
+ if (!in_array($v, $globalTriggerTokens))
+ {
+ $globalTriggerTokens[] = $v;
+ }
+ }
+ $pluginTriggerTokens[$i] = "|" . implode("|", $pluginTriggerTokens[$i]) . "|";
+ $pluginIndex[$tPluginClassName] = $i;
+ }
+ $globalTriggerTokens = "|" . implode("|", $globalTriggerTokens) . "|";
+ /*
+ * Apply filters
+ */
+ for($i = 0; $i < $filterCount; $i++)
+ {
+ // Apply the filter; if the return value is larger than 0...
+ if ($filters[$i]->apply($tokens) > 0)
+ {
+ // ...then filter null values and rebuild the token array
+ $tokens = array_values(array_filter($tokens));
+ }
+ }
+ $tokenCount = count($tokens);
+ /*
+ * Apply plugins
+ */
+ for($i = 0; $i < $tokenCount; $i++)
+ {
+ $triggerToken = "|" . get_class($tokens[$i]) . "|";
+ if (strpos($globalTriggerTokens, $triggerToken) !== false)
+ {
+ for($ii = 0; $ii < $pluginCount; $ii++)
+ {
+ if (strpos($pluginTriggerTokens[$ii], $triggerToken) !== false || $pluginTriggerTokens[$ii] === false)
+ {
+ // Apply the plugin; if the return value is TRUE continue to the next token
+ if ($plugins[$ii]->apply($tokens[$i]) === true)
+ {
+ continue 2;
+ }
+ }
+ }
+ }
+ }
+ // Stringify the tokens
+ for($i = 0; $i < $tokenCount; $i++)
+ {
+ $r .= (string) $tokens[$i];
+ }
+ $this->minified = $r;
+ return $r;
+ }
+ }
+
+/**
+ * CssMin - A (simple) css minifier with benefits
+ *
+ * --
+ * Copyright (c) 2011 Joe Scylla
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * --
+ *
+ * @package CssMin
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssMin
+ {
+ /**
+ * Index of classes
+ *
+ * @var array
+ */
+ private static $classIndex = array();
+ /**
+ * Parse/minify errors
+ *
+ * @var array
+ */
+ private static $errors = array();
+ /**
+ * Verbose output.
+ *
+ * @var boolean
+ */
+ private static $isVerbose = false;
+ /**
+ * {@link http://goo.gl/JrW54 Autoload} function of CssMin.
+ *
+ * @param string $class Name of the class
+ * @return void
+ */
+ public static function autoload($class)
+ {
+ if (isset(self::$classIndex[$class]))
+ {
+ require(self::$classIndex[$class]);
+ }
+ }
+ /**
+ * Return errors
+ *
+ * @return array of {CssError}.
+ */
+ public static function getErrors()
+ {
+ return self::$errors;
+ }
+ /**
+ * Returns if there were errors.
+ *
+ * @return boolean
+ */
+ public static function hasErrors()
+ {
+ return count(self::$errors) > 0;
+ }
+ /**
+ * Initialises CssMin.
+ *
+ * @return void
+ */
+ public static function initialise()
+ {
+ // Create the class index for autoloading or including
+ $paths = array(dirname(__FILE__));
+ while (list($i, $path) = each($paths))
+ {
+ $subDirectorys = glob($path . "*", GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT);
+ if (is_array($subDirectorys))
+ {
+ foreach ($subDirectorys as $subDirectory)
+ {
+ $paths[] = $subDirectory;
+ }
+ }
+ $files = glob($path . "*.php", 0);
+ if (is_array($files))
+ {
+ foreach ($files as $file)
+ {
+ $class = substr(basename($file), 0, -4);
+ self::$classIndex[$class] = $file;
+ }
+ }
+ }
+ krsort(self::$classIndex);
+ // Only use autoloading if spl_autoload_register() is available and no __autoload() is defined (because
+ // __autoload() breaks if spl_autoload_register() is used.
+ if (function_exists("spl_autoload_register") && !is_callable("__autoload"))
+ {
+ spl_autoload_register(array(__CLASS__, "autoload"));
+ }
+ // Otherwise include all class files
+ else
+ {
+ foreach (self::$classIndex as $class => $file)
+ {
+ if (!class_exists($class))
+ {
+ require_once($file);
+ }
+ }
+ }
+ }
+ /**
+ * Minifies CSS source.
+ *
+ * @param string $source CSS source
+ * @param array $filters Filter configuration [optional]
+ * @param array $plugins Plugin configuration [optional]
+ * @return string Minified CSS
+ */
+ public static function minify($source, array $filters = null, array $plugins = null)
+ {
+ self::$errors = array();
+ $minifier = new CssMinifier($source, $filters, $plugins);
+ return $minifier->getMinified();
+ }
+ /**
+ * Parse the CSS source.
+ *
+ * @param string $source CSS source
+ * @param array $plugins Plugin configuration [optional]
+ * @return array Array of aCssToken
+ */
+ public static function parse($source, array $plugins = null)
+ {
+ self::$errors = array();
+ $parser = new CssParser($source, $plugins);
+ return $parser->getTokens();
+ }
+ /**
+ * --
+ *
+ * @param boolean $to
+ * @return boolean
+ */
+ public static function setVerbose($to)
+ {
+ self::$isVerbose = (boolean) $to;
+ return self::$isVerbose;
+ }
+ /**
+ * --
+ *
+ * @param CssError $error
+ * @return void
+ */
+ public static function triggerError(CssError $error)
+ {
+ self::$errors[] = $error;
+ if (self::$isVerbose)
+ {
+ trigger_error((string) $error, E_USER_WARNING);
+ }
+ }
+ }
+// Initialises CssMin
+CssMin::initialise();
+
+/**
+ * This {@link aCssMinifierFilter minifier filter} import external css files defined with the @import at-rule into the
+ * current stylesheet.
+ *
+ * @package CssMin/Minifier/Filters
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssImportImportsMinifierFilter extends aCssMinifierFilter
+ {
+ /**
+ * Array with already imported external stylesheets.
+ *
+ * @var array
+ */
+ private $imported = array();
+ /**
+ * Implements {@link aCssMinifierFilter::filter()}.
+ *
+ * @param array $tokens Array of objects of type aCssToken
+ * @return integer Count of added, changed or removed tokens; a return value large than 0 will rebuild the array
+ */
+ public function apply(array &$tokens)
+ {
+ if (!isset($this->configuration["BasePath"]) || !is_dir($this->configuration["BasePath"]))
+ {
+ CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Base path " . ($this->configuration["BasePath"] ? $this->configuration["BasePath"] : "null"). " is not a directory"));
+ return 0;
+ }
+ for ($i = 0, $l = count($tokens); $i < $l; $i++)
+ {
+ if (get_class($tokens[$i]) === "CssAtImportToken")
+ {
+ $import = $this->configuration["BasePath"] . "/" . $tokens[$i]->Import;
+ // Import file was not found/is not a file
+ if (!is_file($import))
+ {
+ CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Import file " . $import. " was not found.", (string) $tokens[$i]));
+ }
+ // Import file already imported; remove this @import at-rule to prevent recursions
+ elseif (in_array($import, $this->imported))
+ {
+ CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Import file " . $import. " was already imported.", (string) $tokens[$i]));
+ $tokens[$i] = null;
+ }
+ else
+ {
+ $this->imported[] = $import;
+ $parser = new CssParser(file_get_contents($import));
+ $import = $parser->getTokens();
+ // The @import at-rule has media types defined requiring special handling
+ if (count($tokens[$i]->MediaTypes) > 0 && !(count($tokens[$i]->MediaTypes) == 1 && $tokens[$i]->MediaTypes[0] == "all"))
+ {
+ $blocks = array();
+ /*
+ * Filter or set media types of @import at-rule or remove the @import at-rule if no media type is matching the parent @import at-rule
+ */
+ for($ii = 0, $ll = count($import); $ii < $ll; $ii++)
+ {
+ if (get_class($import[$ii]) === "CssAtImportToken")
+ {
+ // @import at-rule defines no media type or only the "all" media type; set the media types to the one defined in the parent @import at-rule
+ if (count($import[$ii]->MediaTypes) == 0 || (count($import[$ii]->MediaTypes) == 1 && $import[$ii]->MediaTypes[0] == "all"))
+ {
+ $import[$ii]->MediaTypes = $tokens[$i]->MediaTypes;
+ }
+ // @import at-rule defineds one or more media types; filter out media types not matching with the parent @import at-rule
+ elseif (count($import[$ii]->MediaTypes > 0))
+ {
+ foreach ($import[$ii]->MediaTypes as $index => $mediaType)
+ {
+ if (!in_array($mediaType, $tokens[$i]->MediaTypes))
+ {
+ unset($import[$ii]->MediaTypes[$index]);
+ }
+ }
+ $import[$ii]->MediaTypes = array_values($import[$ii]->MediaTypes);
+ // If there are no media types left in the @import at-rule remove the @import at-rule
+ if (count($import[$ii]->MediaTypes) == 0)
+ {
+ $import[$ii] = null;
+ }
+ }
+ }
+ }
+ /*
+ * Remove media types of @media at-rule block not defined in the @import at-rule
+ */
+ for($ii = 0, $ll = count($import); $ii < $ll; $ii++)
+ {
+ if (get_class($import[$ii]) === "CssAtMediaStartToken")
+ {
+ foreach ($import[$ii]->MediaTypes as $index => $mediaType)
+ {
+ if (!in_array($mediaType, $tokens[$i]->MediaTypes))
+ {
+ unset($import[$ii]->MediaTypes[$index]);
+ }
+ $import[$ii]->MediaTypes = array_values($import[$ii]->MediaTypes);
+ }
+ }
+ }
+ /*
+ * If no media types left of the @media at-rule block remove the complete block
+ */
+ for($ii = 0, $ll = count($import); $ii < $ll; $ii++)
+ {
+ if (get_class($import[$ii]) === "CssAtMediaStartToken")
+ {
+ if (count($import[$ii]->MediaTypes) === 0)
+ {
+ for ($iii = $ii; $iii < $ll; $iii++)
+ {
+ if (get_class($import[$iii]) === "CssAtMediaEndToken")
+ {
+ break;
+ }
+ }
+ if (get_class($import[$iii]) === "CssAtMediaEndToken")
+ {
+ array_splice($import, $ii, $iii - $ii + 1, array());
+ $ll = count($import);
+ }
+ }
+ }
+ }
+ /*
+ * If the media types of the @media at-rule equals the media types defined in the @import
+ * at-rule remove the CssAtMediaStartToken and CssAtMediaEndToken token
+ */
+ for($ii = 0, $ll = count($import); $ii < $ll; $ii++)
+ {
+ if (get_class($import[$ii]) === "CssAtMediaStartToken" && count(array_diff($tokens[$i]->MediaTypes, $import[$ii]->MediaTypes)) === 0)
+ {
+ for ($iii = $ii; $iii < $ll; $iii++)
+ {
+ if (get_class($import[$iii]) == "CssAtMediaEndToken")
+ {
+ break;
+ }
+ }
+ if (get_class($import[$iii]) == "CssAtMediaEndToken")
+ {
+ unset($import[$ii]);
+ unset($import[$iii]);
+ $import = array_values($import);
+ $ll = count($import);
+ }
+ }
+ }
+ /**
+ * Extract CssAtImportToken and CssAtCharsetToken tokens
+ */
+ for($ii = 0, $ll = count($import); $ii < $ll; $ii++)
+ {
+ $class = get_class($import[$ii]);
+ if ($class === "CssAtImportToken" || $class === "CssAtCharsetToken")
+ {
+ $blocks = array_merge($blocks, array_splice($import, $ii, 1, array()));
+ $ll = count($import);
+ }
+ }
+ /*
+ * Extract the @font-face, @media and @page at-rule block
+ */
+ for($ii = 0, $ll = count($import); $ii < $ll; $ii++)
+ {
+ $class = get_class($import[$ii]);
+ if ($class === "CssAtFontFaceStartToken" || $class === "CssAtMediaStartToken" || $class === "CssAtPageStartToken" || $class === "CssAtVariablesStartToken")
+ {
+ for ($iii = $ii; $iii < $ll; $iii++)
+ {
+ $class = get_class($import[$iii]);
+ if ($class === "CssAtFontFaceEndToken" || $class === "CssAtMediaEndToken" || $class === "CssAtPageEndToken" || $class === "CssAtVariablesEndToken")
+ {
+ break;
+ }
+ }
+ $class = get_class($import[$iii]);
+ if (isset($import[$iii]) && ($class === "CssAtFontFaceEndToken" || $class === "CssAtMediaEndToken" || $class === "CssAtPageEndToken" || $class === "CssAtVariablesEndToken"))
+ {
+ $blocks = array_merge($blocks, array_splice($import, $ii, $iii - $ii + 1, array()));
+ $ll = count($import);
+ }
+ }
+ }
+ // Create the import array with extracted tokens and the rulesets wrapped into a @media at-rule block
+ $import = array_merge($blocks, array(new CssAtMediaStartToken($tokens[$i]->MediaTypes)), $import, array(new CssAtMediaEndToken()));
+ }
+ // Insert the imported tokens
+ array_splice($tokens, $i, 1, $import);
+ // Modify parameters of the for-loop
+ $i--;
+ $l = count($tokens);
+ }
+ }
+ }
+ }
+ }
+
+/**
+ * {@link aCssParserPlugin Parser plugin} for preserve parsing expression() declaration values.
+ *
+ * This plugin return no {@link aCssToken CssToken} but ensures that expression() declaration values will get parsed
+ * properly.
+ *
+ * @package CssMin/Parser/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssExpressionParserPlugin extends aCssParserPlugin
+ {
+ /**
+ * Count of left braces.
+ *
+ * @var integer
+ */
+ private $leftBraces = 0;
+ /**
+ * Count of right braces.
+ *
+ * @var integer
+ */
+ private $rightBraces = 0;
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerChars()}.
+ *
+ * @return array
+ */
+ public function getTriggerChars()
+ {
+ return array("(", ")", ";", "}");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerStates()}.
+ *
+ * @return array
+ */
+ public function getTriggerStates()
+ {
+ return false;
+ }
+ /**
+ * Implements {@link aCssParserPlugin::parse()}.
+ *
+ * @param integer $index Current index
+ * @param string $char Current char
+ * @param string $previousChar Previous char
+ * @return mixed TRUE will break the processing; FALSE continue with the next plugin; integer set a new index and break the processing
+ */
+ public function parse($index, $char, $previousChar, $state)
+ {
+ // Start of expression
+ if ($char === "(" && strtolower(substr($this->parser->getSource(), $index - 10, 11)) === "expression(" && $state !== "T_EXPRESSION")
+ {
+ $this->parser->pushState("T_EXPRESSION");
+ $this->leftBraces++;
+ }
+ // Count left braces
+ elseif ($char === "(" && $state === "T_EXPRESSION")
+ {
+ $this->leftBraces++;
+ }
+ // Count right braces
+ elseif ($char === ")" && $state === "T_EXPRESSION")
+ {
+ $this->rightBraces++;
+ }
+ // Possible end of expression; if left and right braces are equal the expressen ends
+ elseif (($char === ";" || $char === "}") && $state === "T_EXPRESSION" && $this->leftBraces === $this->rightBraces)
+ {
+ $this->leftBraces = $this->rightBraces = 0;
+ $this->parser->popState();
+ return $index - 1;
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+
+/**
+ * CSS Error.
+ *
+ * @package CssMin
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssError
+ {
+ /**
+ * File.
+ *
+ * @var string
+ */
+ public $File = "";
+ /**
+ * Line.
+ *
+ * @var integer
+ */
+ public $Line = 0;
+ /**
+ * Error message.
+ *
+ * @var string
+ */
+ public $Message = "";
+ /**
+ * Source.
+ *
+ * @var string
+ */
+ public $Source = "";
+ /**
+ * Constructor triggering the error.
+ *
+ * @param string $message Error message
+ * @param string $source Corresponding line [optional]
+ * @return void
+ */
+ public function __construct($file, $line, $message, $source = "")
+ {
+ $this->File = $file;
+ $this->Line = $line;
+ $this->Message = $message;
+ $this->Source = $source;
+ }
+ /**
+ * Returns the error as formatted string.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return $this->Message . ($this->Source ? ": " . $this->Source . "": "") . " in file " . $this->File . " at line " . $this->Line;
+ }
+ }
+
+/**
+ * This {@link aCssMinifierPlugin} will convert a color value in rgb notation to hexadecimal notation.
+ *
+ * Example:
+ *
+ * color: rgb(200,60%,5);
+ *
+ *
+ * Will get converted to:
+ *
+ * color:#c89905;
+ *
+ *
+ * @package CssMin/Minifier/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssConvertRgbColorsMinifierPlugin extends aCssMinifierPlugin
+ {
+ /**
+ * Regular expression matching the value.
+ *
+ * @var string
+ */
+ private $reMatch = "/rgb\s*\(\s*([0-9%]+)\s*,\s*([0-9%]+)\s*,\s*([0-9%]+)\s*\)/iS";
+ /**
+ * Implements {@link aCssMinifierPlugin::minify()}.
+ *
+ * @param aCssToken $token Token to process
+ * @return boolean Return TRUE to break the processing of this token; FALSE to continue
+ */
+ public function apply(aCssToken &$token)
+ {
+ if (stripos($token->Value, "rgb") !== false && preg_match($this->reMatch, $token->Value, $m))
+ {
+ for ($i = 1, $l = count($m); $i < $l; $i++)
+ {
+ if (strpos("%", $m[$i]) !== false)
+ {
+ $m[$i] = substr($m[$i], 0, -1);
+ $m[$i] = (int) (256 * ($m[$i] / 100));
+ }
+ $m[$i] = str_pad(dechex($m[$i]), 2, "0", STR_PAD_LEFT);
+ }
+ $token->Value = str_replace($m[0], "#" . $m[1] . $m[2] . $m[3], $token->Value);
+ }
+ return false;
+ }
+ /**
+ * Implements {@link aMinifierPlugin::getTriggerTokens()}
+ *
+ * @return array
+ */
+ public function getTriggerTokens()
+ {
+ return array
+ (
+ "CssAtFontFaceDeclarationToken",
+ "CssAtPageDeclarationToken",
+ "CssRulesetDeclarationToken"
+ );
+ }
+ }
+
+/**
+ * This {@link aCssMinifierPlugin} will convert named color values to hexadecimal notation.
+ *
+ * Example:
+ *
+ * color: black;
+ * border: 1px solid indigo;
+ *
+ *
+ * Will get converted to:
+ *
+ * color:#000;
+ * border:1px solid #4b0082;
+ *
+ *
+ * @package CssMin/Minifier/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssConvertNamedColorsMinifierPlugin extends aCssMinifierPlugin
+ {
+
+ /**
+ * Regular expression matching the value.
+ *
+ * @var string
+ */
+ private $reMatch = null;
+ /**
+ * Regular expression replacing the value.
+ *
+ * @var string
+ */
+ private $reReplace = "\"\${1}\" . \$this->transformation[strtolower(\"\${2}\")] . \"\${3}\"";
+ /**
+ * Transformation table used by the {@link CssConvertNamedColorsMinifierPlugin::$reReplace replace regular expression}.
+ *
+ * @var array
+ */
+ private $transformation = array
+ (
+ "aliceblue" => "#f0f8ff",
+ "antiquewhite" => "#faebd7",
+ "aqua" => "#0ff",
+ "aquamarine" => "#7fffd4",
+ "azure" => "#f0ffff",
+ "beige" => "#f5f5dc",
+ "black" => "#000",
+ "blue" => "#00f",
+ "blueviolet" => "#8a2be2",
+ "brown" => "#a52a2a",
+ "burlywood" => "#deb887",
+ "cadetblue" => "#5f9ea0",
+ "chartreuse" => "#7fff00",
+ "chocolate" => "#d2691e",
+ "coral" => "#ff7f50",
+ "cornflowerblue" => "#6495ed",
+ "cornsilk" => "#fff8dc",
+ "crimson" => "#dc143c",
+ "darkblue" => "#00008b",
+ "darkcyan" => "#008b8b",
+ "darkgoldenrod" => "#b8860b",
+ "darkgray" => "#a9a9a9",
+ "darkgreen" => "#006400",
+ "darkkhaki" => "#bdb76b",
+ "darkmagenta" => "#8b008b",
+ "darkolivegreen" => "#556b2f",
+ "darkorange" => "#ff8c00",
+ "darkorchid" => "#9932cc",
+ "darkred" => "#8b0000",
+ "darksalmon" => "#e9967a",
+ "darkseagreen" => "#8fbc8f",
+ "darkslateblue" => "#483d8b",
+ "darkslategray" => "#2f4f4f",
+ "darkturquoise" => "#00ced1",
+ "darkviolet" => "#9400d3",
+ "deeppink" => "#ff1493",
+ "deepskyblue" => "#00bfff",
+ "dimgray" => "#696969",
+ "dodgerblue" => "#1e90ff",
+ "firebrick" => "#b22222",
+ "floralwhite" => "#fffaf0",
+ "forestgreen" => "#228b22",
+ "fuchsia" => "#f0f",
+ "gainsboro" => "#dcdcdc",
+ "ghostwhite" => "#f8f8ff",
+ "gold" => "#ffd700",
+ "goldenrod" => "#daa520",
+ "gray" => "#808080",
+ "green" => "#008000",
+ "greenyellow" => "#adff2f",
+ "honeydew" => "#f0fff0",
+ "hotpink" => "#ff69b4",
+ "indianred" => "#cd5c5c",
+ "indigo" => "#4b0082",
+ "ivory" => "#fffff0",
+ "khaki" => "#f0e68c",
+ "lavender" => "#e6e6fa",
+ "lavenderblush" => "#fff0f5",
+ "lawngreen" => "#7cfc00",
+ "lemonchiffon" => "#fffacd",
+ "lightblue" => "#add8e6",
+ "lightcoral" => "#f08080",
+ "lightcyan" => "#e0ffff",
+ "lightgoldenrodyellow" => "#fafad2",
+ "lightgreen" => "#90ee90",
+ "lightgrey" => "#d3d3d3",
+ "lightpink" => "#ffb6c1",
+ "lightsalmon" => "#ffa07a",
+ "lightseagreen" => "#20b2aa",
+ "lightskyblue" => "#87cefa",
+ "lightslategray" => "#789",
+ "lightsteelblue" => "#b0c4de",
+ "lightyellow" => "#ffffe0",
+ "lime" => "#0f0",
+ "limegreen" => "#32cd32",
+ "linen" => "#faf0e6",
+ "maroon" => "#800000",
+ "mediumaquamarine" => "#66cdaa",
+ "mediumblue" => "#0000cd",
+ "mediumorchid" => "#ba55d3",
+ "mediumpurple" => "#9370db",
+ "mediumseagreen" => "#3cb371",
+ "mediumslateblue" => "#7b68ee",
+ "mediumspringgreen" => "#00fa9a",
+ "mediumturquoise" => "#48d1cc",
+ "mediumvioletred" => "#c71585",
+ "midnightblue" => "#191970",
+ "mintcream" => "#f5fffa",
+ "mistyrose" => "#ffe4e1",
+ "moccasin" => "#ffe4b5",
+ "navajowhite" => "#ffdead",
+ "navy" => "#000080",
+ "oldlace" => "#fdf5e6",
+ "olive" => "#808000",
+ "olivedrab" => "#6b8e23",
+ "orange" => "#ffa500",
+ "orangered" => "#ff4500",
+ "orchid" => "#da70d6",
+ "palegoldenrod" => "#eee8aa",
+ "palegreen" => "#98fb98",
+ "paleturquoise" => "#afeeee",
+ "palevioletred" => "#db7093",
+ "papayawhip" => "#ffefd5",
+ "peachpuff" => "#ffdab9",
+ "peru" => "#cd853f",
+ "pink" => "#ffc0cb",
+ "plum" => "#dda0dd",
+ "powderblue" => "#b0e0e6",
+ "purple" => "#800080",
+ "red" => "#f00",
+ "rosybrown" => "#bc8f8f",
+ "royalblue" => "#4169e1",
+ "saddlebrown" => "#8b4513",
+ "salmon" => "#fa8072",
+ "sandybrown" => "#f4a460",
+ "seagreen" => "#2e8b57",
+ "seashell" => "#fff5ee",
+ "sienna" => "#a0522d",
+ "silver" => "#c0c0c0",
+ "skyblue" => "#87ceeb",
+ "slateblue" => "#6a5acd",
+ "slategray" => "#708090",
+ "snow" => "#fffafa",
+ "springgreen" => "#00ff7f",
+ "steelblue" => "#4682b4",
+ "tan" => "#d2b48c",
+ "teal" => "#008080",
+ "thistle" => "#d8bfd8",
+ "tomato" => "#ff6347",
+ "turquoise" => "#40e0d0",
+ "violet" => "#ee82ee",
+ "wheat" => "#f5deb3",
+ "white" => "#fff",
+ "whitesmoke" => "#f5f5f5",
+ "yellow" => "#ff0",
+ "yellowgreen" => "#9acd32"
+ );
+ /**
+ * Overwrites {@link aCssMinifierPlugin::__construct()}.
+ *
+ * The constructor will create the {@link CssConvertNamedColorsMinifierPlugin::$reReplace replace regular expression}
+ * based on the {@link CssConvertNamedColorsMinifierPlugin::$transformation transformation table}.
+ *
+ * @param CssMinifier $minifier The CssMinifier object of this plugin.
+ * @param array $configuration Plugin configuration [optional]
+ * @return void
+ */
+ public function __construct(CssMinifier $minifier, array $configuration = array())
+ {
+ $this->reMatch = "/(^|\s)+(" . implode("|", array_keys($this->transformation)) . ")(\s|$)+/eiS";
+ parent::__construct($minifier, $configuration);
+ }
+ /**
+ * Implements {@link aCssMinifierPlugin::minify()}.
+ *
+ * @param aCssToken $token Token to process
+ * @return boolean Return TRUE to break the processing of this token; FALSE to continue
+ */
+ public function apply(aCssToken &$token)
+ {
+ $lcValue = strtolower($token->Value);
+ // Declaration value equals a value in the transformation table => simple replace
+ if (isset($this->transformation[$lcValue]))
+ {
+ $token->Value = $this->transformation[$lcValue];
+ }
+ // Declaration value contains a value in the transformation table => regular expression replace
+ elseif (preg_match($this->reMatch, $token->Value))
+ {
+ $token->Value = preg_replace($this->reMatch, $this->reReplace, $token->Value);
+ }
+ return false;
+ }
+ /**
+ * Implements {@link aMinifierPlugin::getTriggerTokens()}
+ *
+ * @return array
+ */
+ public function getTriggerTokens()
+ {
+ return array
+ (
+ "CssAtFontFaceDeclarationToken",
+ "CssAtPageDeclarationToken",
+ "CssRulesetDeclarationToken"
+ );
+ }
+ }
+
+/**
+ * This {@link aCssMinifierFilter minifier filter} triggers on CSS Level 3 properties and will add declaration tokens
+ * with browser-specific properties.
+ *
+ * @package CssMin/Minifier/Filters
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssConvertLevel3PropertiesMinifierFilter extends aCssMinifierFilter
+ {
+ /**
+ * Css property transformations table. Used to convert CSS3 and proprietary properties to the browser-specific
+ * counterparts.
+ *
+ * @var array
+ */
+ private $transformations = array
+ (
+ // Property Array(Mozilla, Webkit, Opera, Internet Explorer); NULL values are placeholders and will get ignored
+ "animation" => array(null, "-webkit-animation", null, null),
+ "animation-delay" => array(null, "-webkit-animation-delay", null, null),
+ "animation-direction" => array(null, "-webkit-animation-direction", null, null),
+ "animation-duration" => array(null, "-webkit-animation-duration", null, null),
+ "animation-fill-mode" => array(null, "-webkit-animation-fill-mode", null, null),
+ "animation-iteration-count" => array(null, "-webkit-animation-iteration-count", null, null),
+ "animation-name" => array(null, "-webkit-animation-name", null, null),
+ "animation-play-state" => array(null, "-webkit-animation-play-state", null, null),
+ "animation-timing-function" => array(null, "-webkit-animation-timing-function", null, null),
+ "appearance" => array("-moz-appearance", "-webkit-appearance", null, null),
+ "backface-visibility" => array(null, "-webkit-backface-visibility", null, null),
+ "background-clip" => array(null, "-webkit-background-clip", null, null),
+ "background-composite" => array(null, "-webkit-background-composite", null, null),
+ "background-inline-policy" => array("-moz-background-inline-policy", null, null, null),
+ "background-origin" => array(null, "-webkit-background-origin", null, null),
+ "background-position-x" => array(null, null, null, "-ms-background-position-x"),
+ "background-position-y" => array(null, null, null, "-ms-background-position-y"),
+ "background-size" => array(null, "-webkit-background-size", null, null),
+ "behavior" => array(null, null, null, "-ms-behavior"),
+ "binding" => array("-moz-binding", null, null, null),
+ "border-after" => array(null, "-webkit-border-after", null, null),
+ "border-after-color" => array(null, "-webkit-border-after-color", null, null),
+ "border-after-style" => array(null, "-webkit-border-after-style", null, null),
+ "border-after-width" => array(null, "-webkit-border-after-width", null, null),
+ "border-before" => array(null, "-webkit-border-before", null, null),
+ "border-before-color" => array(null, "-webkit-border-before-color", null, null),
+ "border-before-style" => array(null, "-webkit-border-before-style", null, null),
+ "border-before-width" => array(null, "-webkit-border-before-width", null, null),
+ "border-border-bottom-colors" => array("-moz-border-bottom-colors", null, null, null),
+ "border-bottom-left-radius" => array("-moz-border-radius-bottomleft", "-webkit-border-bottom-left-radius", null, null),
+ "border-bottom-right-radius" => array("-moz-border-radius-bottomright", "-webkit-border-bottom-right-radius", null, null),
+ "border-end" => array("-moz-border-end", "-webkit-border-end", null, null),
+ "border-end-color" => array("-moz-border-end-color", "-webkit-border-end-color", null, null),
+ "border-end-style" => array("-moz-border-end-style", "-webkit-border-end-style", null, null),
+ "border-end-width" => array("-moz-border-end-width", "-webkit-border-end-width", null, null),
+ "border-fit" => array(null, "-webkit-border-fit", null, null),
+ "border-horizontal-spacing" => array(null, "-webkit-border-horizontal-spacing", null, null),
+ "border-image" => array("-moz-border-image", "-webkit-border-image", null, null),
+ "border-left-colors" => array("-moz-border-left-colors", null, null, null),
+ "border-radius" => array("-moz-border-radius", "-webkit-border-radius", null, null),
+ "border-border-right-colors" => array("-moz-border-right-colors", null, null, null),
+ "border-start" => array("-moz-border-start", "-webkit-border-start", null, null),
+ "border-start-color" => array("-moz-border-start-color", "-webkit-border-start-color", null, null),
+ "border-start-style" => array("-moz-border-start-style", "-webkit-border-start-style", null, null),
+ "border-start-width" => array("-moz-border-start-width", "-webkit-border-start-width", null, null),
+ "border-top-colors" => array("-moz-border-top-colors", null, null, null),
+ "border-top-left-radius" => array("-moz-border-radius-topleft", "-webkit-border-top-left-radius", null, null),
+ "border-top-right-radius" => array("-moz-border-radius-topright", "-webkit-border-top-right-radius", null, null),
+ "border-vertical-spacing" => array(null, "-webkit-border-vertical-spacing", null, null),
+ "box-align" => array("-moz-box-align", "-webkit-box-align", null, null),
+ "box-direction" => array("-moz-box-direction", "-webkit-box-direction", null, null),
+ "box-flex" => array("-moz-box-flex", "-webkit-box-flex", null, null),
+ "box-flex-group" => array(null, "-webkit-box-flex-group", null, null),
+ "box-flex-lines" => array(null, "-webkit-box-flex-lines", null, null),
+ "box-ordinal-group" => array("-moz-box-ordinal-group", "-webkit-box-ordinal-group", null, null),
+ "box-orient" => array("-moz-box-orient", "-webkit-box-orient", null, null),
+ "box-pack" => array("-moz-box-pack", "-webkit-box-pack", null, null),
+ "box-reflect" => array(null, "-webkit-box-reflect", null, null),
+ "box-shadow" => array("-moz-box-shadow", "-webkit-box-shadow", null, null),
+ "box-sizing" => array("-moz-box-sizing", null, null, null),
+ "color-correction" => array(null, "-webkit-color-correction", null, null),
+ "column-break-after" => array(null, "-webkit-column-break-after", null, null),
+ "column-break-before" => array(null, "-webkit-column-break-before", null, null),
+ "column-break-inside" => array(null, "-webkit-column-break-inside", null, null),
+ "column-count" => array("-moz-column-count", "-webkit-column-count", null, null),
+ "column-gap" => array("-moz-column-gap", "-webkit-column-gap", null, null),
+ "column-rule" => array("-moz-column-rule", "-webkit-column-rule", null, null),
+ "column-rule-color" => array("-moz-column-rule-color", "-webkit-column-rule-color", null, null),
+ "column-rule-style" => array("-moz-column-rule-style", "-webkit-column-rule-style", null, null),
+ "column-rule-width" => array("-moz-column-rule-width", "-webkit-column-rule-width", null, null),
+ "column-span" => array(null, "-webkit-column-span", null, null),
+ "column-width" => array("-moz-column-width", "-webkit-column-width", null, null),
+ "columns" => array(null, "-webkit-columns", null, null),
+ "filter" => array(__CLASS__, "filter"),
+ "float-edge" => array("-moz-float-edge", null, null, null),
+ "font-feature-settings" => array("-moz-font-feature-settings", null, null, null),
+ "font-language-override" => array("-moz-font-language-override", null, null, null),
+ "font-size-delta" => array(null, "-webkit-font-size-delta", null, null),
+ "font-smoothing" => array(null, "-webkit-font-smoothing", null, null),
+ "force-broken-image-icon" => array("-moz-force-broken-image-icon", null, null, null),
+ "highlight" => array(null, "-webkit-highlight", null, null),
+ "hyphenate-character" => array(null, "-webkit-hyphenate-character", null, null),
+ "hyphenate-locale" => array(null, "-webkit-hyphenate-locale", null, null),
+ "hyphens" => array(null, "-webkit-hyphens", null, null),
+ "force-broken-image-icon" => array("-moz-image-region", null, null, null),
+ "ime-mode" => array(null, null, null, "-ms-ime-mode"),
+ "interpolation-mode" => array(null, null, null, "-ms-interpolation-mode"),
+ "layout-flow" => array(null, null, null, "-ms-layout-flow"),
+ "layout-grid" => array(null, null, null, "-ms-layout-grid"),
+ "layout-grid-char" => array(null, null, null, "-ms-layout-grid-char"),
+ "layout-grid-line" => array(null, null, null, "-ms-layout-grid-line"),
+ "layout-grid-mode" => array(null, null, null, "-ms-layout-grid-mode"),
+ "layout-grid-type" => array(null, null, null, "-ms-layout-grid-type"),
+ "line-break" => array(null, "-webkit-line-break", null, "-ms-line-break"),
+ "line-clamp" => array(null, "-webkit-line-clamp", null, null),
+ "line-grid-mode" => array(null, null, null, "-ms-line-grid-mode"),
+ "logical-height" => array(null, "-webkit-logical-height", null, null),
+ "logical-width" => array(null, "-webkit-logical-width", null, null),
+ "margin-after" => array(null, "-webkit-margin-after", null, null),
+ "margin-after-collapse" => array(null, "-webkit-margin-after-collapse", null, null),
+ "margin-before" => array(null, "-webkit-margin-before", null, null),
+ "margin-before-collapse" => array(null, "-webkit-margin-before-collapse", null, null),
+ "margin-bottom-collapse" => array(null, "-webkit-margin-bottom-collapse", null, null),
+ "margin-collapse" => array(null, "-webkit-margin-collapse", null, null),
+ "margin-end" => array("-moz-margin-end", "-webkit-margin-end", null, null),
+ "margin-start" => array("-moz-margin-start", "-webkit-margin-start", null, null),
+ "margin-top-collapse" => array(null, "-webkit-margin-top-collapse", null, null),
+ "marquee " => array(null, "-webkit-marquee", null, null),
+ "marquee-direction" => array(null, "-webkit-marquee-direction", null, null),
+ "marquee-increment" => array(null, "-webkit-marquee-increment", null, null),
+ "marquee-repetition" => array(null, "-webkit-marquee-repetition", null, null),
+ "marquee-speed" => array(null, "-webkit-marquee-speed", null, null),
+ "marquee-style" => array(null, "-webkit-marquee-style", null, null),
+ "mask" => array(null, "-webkit-mask", null, null),
+ "mask-attachment" => array(null, "-webkit-mask-attachment", null, null),
+ "mask-box-image" => array(null, "-webkit-mask-box-image", null, null),
+ "mask-clip" => array(null, "-webkit-mask-clip", null, null),
+ "mask-composite" => array(null, "-webkit-mask-composite", null, null),
+ "mask-image" => array(null, "-webkit-mask-image", null, null),
+ "mask-origin" => array(null, "-webkit-mask-origin", null, null),
+ "mask-position" => array(null, "-webkit-mask-position", null, null),
+ "mask-position-x" => array(null, "-webkit-mask-position-x", null, null),
+ "mask-position-y" => array(null, "-webkit-mask-position-y", null, null),
+ "mask-repeat" => array(null, "-webkit-mask-repeat", null, null),
+ "mask-repeat-x" => array(null, "-webkit-mask-repeat-x", null, null),
+ "mask-repeat-y" => array(null, "-webkit-mask-repeat-y", null, null),
+ "mask-size" => array(null, "-webkit-mask-size", null, null),
+ "match-nearest-mail-blockquote-color" => array(null, "-webkit-match-nearest-mail-blockquote-color", null, null),
+ "max-logical-height" => array(null, "-webkit-max-logical-height", null, null),
+ "max-logical-width" => array(null, "-webkit-max-logical-width", null, null),
+ "min-logical-height" => array(null, "-webkit-min-logical-height", null, null),
+ "min-logical-width" => array(null, "-webkit-min-logical-width", null, null),
+ "object-fit" => array(null, null, "-o-object-fit", null),
+ "object-position" => array(null, null, "-o-object-position", null),
+ "opacity" => array(__CLASS__, "opacity"),
+ "outline-radius" => array("-moz-outline-radius", null, null, null),
+ "outline-bottom-left-radius" => array("-moz-outline-radius-bottomleft", null, null, null),
+ "outline-bottom-right-radius" => array("-moz-outline-radius-bottomright", null, null, null),
+ "outline-top-left-radius" => array("-moz-outline-radius-topleft", null, null, null),
+ "outline-top-right-radius" => array("-moz-outline-radius-topright", null, null, null),
+ "padding-after" => array(null, "-webkit-padding-after", null, null),
+ "padding-before" => array(null, "-webkit-padding-before", null, null),
+ "padding-end" => array("-moz-padding-end", "-webkit-padding-end", null, null),
+ "padding-start" => array("-moz-padding-start", "-webkit-padding-start", null, null),
+ "perspective" => array(null, "-webkit-perspective", null, null),
+ "perspective-origin" => array(null, "-webkit-perspective-origin", null, null),
+ "perspective-origin-x" => array(null, "-webkit-perspective-origin-x", null, null),
+ "perspective-origin-y" => array(null, "-webkit-perspective-origin-y", null, null),
+ "rtl-ordering" => array(null, "-webkit-rtl-ordering", null, null),
+ "scrollbar-3dlight-color" => array(null, null, null, "-ms-scrollbar-3dlight-color"),
+ "scrollbar-arrow-color" => array(null, null, null, "-ms-scrollbar-arrow-color"),
+ "scrollbar-base-color" => array(null, null, null, "-ms-scrollbar-base-color"),
+ "scrollbar-darkshadow-color" => array(null, null, null, "-ms-scrollbar-darkshadow-color"),
+ "scrollbar-face-color" => array(null, null, null, "-ms-scrollbar-face-color"),
+ "scrollbar-highlight-color" => array(null, null, null, "-ms-scrollbar-highlight-color"),
+ "scrollbar-shadow-color" => array(null, null, null, "-ms-scrollbar-shadow-color"),
+ "scrollbar-track-color" => array(null, null, null, "-ms-scrollbar-track-color"),
+ "stack-sizing" => array("-moz-stack-sizing", null, null, null),
+ "svg-shadow" => array(null, "-webkit-svg-shadow", null, null),
+ "tab-size" => array("-moz-tab-size", null, "-o-tab-size", null),
+ "table-baseline" => array(null, null, "-o-table-baseline", null),
+ "text-align-last" => array(null, null, null, "-ms-text-align-last"),
+ "text-autospace" => array(null, null, null, "-ms-text-autospace"),
+ "text-combine" => array(null, "-webkit-text-combine", null, null),
+ "text-decorations-in-effect" => array(null, "-webkit-text-decorations-in-effect", null, null),
+ "text-emphasis" => array(null, "-webkit-text-emphasis", null, null),
+ "text-emphasis-color" => array(null, "-webkit-text-emphasis-color", null, null),
+ "text-emphasis-position" => array(null, "-webkit-text-emphasis-position", null, null),
+ "text-emphasis-style" => array(null, "-webkit-text-emphasis-style", null, null),
+ "text-fill-color" => array(null, "-webkit-text-fill-color", null, null),
+ "text-justify" => array(null, null, null, "-ms-text-justify"),
+ "text-kashida-space" => array(null, null, null, "-ms-text-kashida-space"),
+ "text-overflow" => array(null, null, "-o-text-overflow", "-ms-text-overflow"),
+ "text-security" => array(null, "-webkit-text-security", null, null),
+ "text-size-adjust" => array(null, "-webkit-text-size-adjust", null, "-ms-text-size-adjust"),
+ "text-stroke" => array(null, "-webkit-text-stroke", null, null),
+ "text-stroke-color" => array(null, "-webkit-text-stroke-color", null, null),
+ "text-stroke-width" => array(null, "-webkit-text-stroke-width", null, null),
+ "text-underline-position" => array(null, null, null, "-ms-text-underline-position"),
+ "transform" => array("-moz-transform", "-webkit-transform", "-o-transform", null),
+ "transform-origin" => array("-moz-transform-origin", "-webkit-transform-origin", "-o-transform-origin", null),
+ "transform-origin-x" => array(null, "-webkit-transform-origin-x", null, null),
+ "transform-origin-y" => array(null, "-webkit-transform-origin-y", null, null),
+ "transform-origin-z" => array(null, "-webkit-transform-origin-z", null, null),
+ "transform-style" => array(null, "-webkit-transform-style", null, null),
+ "transition" => array("-moz-transition", "-webkit-transition", "-o-transition", null),
+ "transition-delay" => array("-moz-transition-delay", "-webkit-transition-delay", "-o-transition-delay", null),
+ "transition-duration" => array("-moz-transition-duration", "-webkit-transition-duration", "-o-transition-duration", null),
+ "transition-property" => array("-moz-transition-property", "-webkit-transition-property", "-o-transition-property", null),
+ "transition-timing-function" => array("-moz-transition-timing-function", "-webkit-transition-timing-function", "-o-transition-timing-function", null),
+ "user-drag" => array(null, "-webkit-user-drag", null, null),
+ "user-focus" => array("-moz-user-focus", null, null, null),
+ "user-input" => array("-moz-user-input", null, null, null),
+ "user-modify" => array("-moz-user-modify", "-webkit-user-modify", null, null),
+ "user-select" => array("-moz-user-select", "-webkit-user-select", null, null),
+ "white-space" => array(__CLASS__, "whiteSpace"),
+ "window-shadow" => array("-moz-window-shadow", null, null, null),
+ "word-break" => array(null, null, null, "-ms-word-break"),
+ "word-wrap" => array(null, null, null, "-ms-word-wrap"),
+ "writing-mode" => array(null, "-webkit-writing-mode", null, "-ms-writing-mode"),
+ "zoom" => array(null, null, null, "-ms-zoom")
+ );
+ /**
+ * Implements {@link aCssMinifierFilter::filter()}.
+ *
+ * @param array $tokens Array of objects of type aCssToken
+ * @return integer Count of added, changed or removed tokens; a return value large than 0 will rebuild the array
+ */
+ public function apply(array &$tokens)
+ {
+ $r = 0;
+ $transformations = &$this->transformations;
+ for ($i = 0, $l = count($tokens); $i < $l; $i++)
+ {
+ if (get_class($tokens[$i]) === "CssRulesetDeclarationToken")
+ {
+ $tProperty = $tokens[$i]->Property;
+ if (isset($transformations[$tProperty]))
+ {
+ $result = array();
+ if (is_callable($transformations[$tProperty]))
+ {
+ $result = call_user_func_array($transformations[$tProperty], array($tokens[$i]));
+ if (!is_array($result) && is_object($result))
+ {
+ $result = array($result);
+ }
+ }
+ else
+ {
+ $tValue = $tokens[$i]->Value;
+ $tMediaTypes = $tokens[$i]->MediaTypes;
+ foreach ($transformations[$tProperty] as $property)
+ {
+ if ($property !== null)
+ {
+ $result[] = new CssRulesetDeclarationToken($property, $tValue, $tMediaTypes);
+ }
+ }
+ }
+ if (count($result) > 0)
+ {
+ array_splice($tokens, $i + 1, 0, $result);
+ $i += count($result);
+ $l += count($result);
+ }
+ }
+ }
+ }
+ return $r;
+ }
+ /**
+ * Transforms the Internet Explorer specific declaration property "filter" to Internet Explorer 8+ compatible
+ * declaratiopn property "-ms-filter".
+ *
+ * @param aCssToken $token
+ * @return array
+ */
+ private static function filter($token)
+ {
+ $r = array
+ (
+ new CssRulesetDeclarationToken("-ms-filter", "\"" . $token->Value . "\"", $token->MediaTypes),
+ );
+ return $r;
+ }
+ /**
+ * Transforms "opacity: {value}" into browser specific counterparts.
+ *
+ * @param aCssToken $token
+ * @return array
+ */
+ private static function opacity($token)
+ {
+ // Calculate the value for Internet Explorer filter statement
+ $ieValue = (int) ((float) $token->Value * 100);
+ $r = array
+ (
+ // Internet Explorer >= 8
+ new CssRulesetDeclarationToken("-ms-filter", "\"alpha(opacity=" . $ieValue . ")\"", $token->MediaTypes),
+ // Internet Explorer >= 4 <= 7
+ new CssRulesetDeclarationToken("filter", "alpha(opacity=" . $ieValue . ")", $token->MediaTypes),
+ new CssRulesetDeclarationToken("zoom", "1", $token->MediaTypes)
+ );
+ return $r;
+ }
+ /**
+ * Transforms "white-space: pre-wrap" into browser specific counterparts.
+ *
+ * @param aCssToken $token
+ * @return array
+ */
+ private static function whiteSpace($token)
+ {
+ if (strtolower($token->Value) === "pre-wrap")
+ {
+ $r = array
+ (
+ // Firefox < 3
+ new CssRulesetDeclarationToken("white-space", "-moz-pre-wrap", $token->MediaTypes),
+ // Webkit
+ new CssRulesetDeclarationToken("white-space", "-webkit-pre-wrap", $token->MediaTypes),
+ // Opera >= 4 <= 6
+ new CssRulesetDeclarationToken("white-space", "-pre-wrap", $token->MediaTypes),
+ // Opera >= 7
+ new CssRulesetDeclarationToken("white-space", "-o-pre-wrap", $token->MediaTypes),
+ // Internet Explorer >= 5.5
+ new CssRulesetDeclarationToken("word-wrap", "break-word", $token->MediaTypes)
+ );
+ return $r;
+ }
+ else
+ {
+ return array();
+ }
+ }
+ }
+
+/**
+ * This {@link aCssMinifierFilter minifier filter} will convert @keyframes at-rule block to browser specific counterparts.
+ *
+ * @package CssMin/Minifier/Filters
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssConvertLevel3AtKeyframesMinifierFilter extends aCssMinifierFilter
+ {
+ /**
+ * Implements {@link aCssMinifierFilter::filter()}.
+ *
+ * @param array $tokens Array of objects of type aCssToken
+ * @return integer Count of added, changed or removed tokens; a return value larger than 0 will rebuild the array
+ */
+ public function apply(array &$tokens)
+ {
+ $r = 0;
+ $transformations = array("-moz-keyframes", "-webkit-keyframes");
+ for ($i = 0, $l = count($tokens); $i < $l; $i++)
+ {
+ if (get_class($tokens[$i]) === "CssAtKeyframesStartToken")
+ {
+ for ($ii = $i; $ii < $l; $ii++)
+ {
+ if (get_class($tokens[$ii]) === "CssAtKeyframesEndToken")
+ {
+ break;
+ }
+ }
+ if (get_class($tokens[$ii]) === "CssAtKeyframesEndToken")
+ {
+ $add = array();
+ $source = array();
+ for ($iii = $i; $iii <= $ii; $iii++)
+ {
+ $source[] = clone($tokens[$iii]);
+ }
+ foreach ($transformations as $transformation)
+ {
+ $t = array();
+ foreach ($source as $token)
+ {
+ $t[] = clone($token);
+ }
+ $t[0]->AtRuleName = $transformation;
+ $add = array_merge($add, $t);
+ }
+ if (isset($this->configuration["RemoveSource"]) && $this->configuration["RemoveSource"] === true)
+ {
+ array_splice($tokens, $i, $ii - $i + 1, $add);
+ }
+ else
+ {
+ array_splice($tokens, $ii + 1, 0, $add);
+ }
+ $l = count($tokens);
+ $i = $ii + count($add);
+ $r += count($add);
+ }
+ }
+ }
+ return $r;
+ }
+ }
+
+/**
+ * This {@link aCssMinifierPlugin} will convert a color value in hsl notation to hexadecimal notation.
+ *
+ * Example:
+ *
+ * color: hsl(232,36%,48%);
+ *
+ *
+ * Will get converted to:
+ *
+ * color:#4e5aa7;
+ *
+ *
+ * @package CssMin/Minifier/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssConvertHslColorsMinifierPlugin extends aCssMinifierPlugin
+ {
+ /**
+ * Regular expression matching the value.
+ *
+ * @var string
+ */
+ private $reMatch = "/^hsl\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*%\s*,\s*([0-9]+)\s*%\s*\)/iS";
+ /**
+ * Implements {@link aCssMinifierPlugin::minify()}.
+ *
+ * @param aCssToken $token Token to process
+ * @return boolean Return TRUE to break the processing of this token; FALSE to continue
+ */
+ public function apply(aCssToken &$token)
+ {
+ if (stripos($token->Value, "hsl") !== false && preg_match($this->reMatch, $token->Value, $m))
+ {
+ $token->Value = str_replace($m[0], $this->hsl2hex($m[1], $m[2], $m[3]), $token->Value);
+ }
+ return false;
+ }
+ /**
+ * Implements {@link aMinifierPlugin::getTriggerTokens()}
+ *
+ * @return array
+ */
+ public function getTriggerTokens()
+ {
+ return array
+ (
+ "CssAtFontFaceDeclarationToken",
+ "CssAtPageDeclarationToken",
+ "CssRulesetDeclarationToken"
+ );
+ }
+ /**
+ * Convert a HSL value to hexadecimal notation.
+ *
+ * Based on: {@link http://www.easyrgb.com/index.php?X=MATH&H=19#text19}.
+ *
+ * @param integer $hue Hue
+ * @param integer $saturation Saturation
+ * @param integer $lightness Lightnesss
+ * @return string
+ */
+ private function hsl2hex($hue, $saturation, $lightness)
+ {
+ $hue = $hue / 360;
+ $saturation = $saturation / 100;
+ $lightness = $lightness / 100;
+ if ($saturation == 0)
+ {
+ $red = $lightness * 255;
+ $green = $lightness * 255;
+ $blue = $lightness * 255;
+ }
+ else
+ {
+ if ($lightness < 0.5 )
+ {
+ $v2 = $lightness * (1 + $saturation);
+ }
+ else
+ {
+ $v2 = ($lightness + $saturation) - ($saturation * $lightness);
+ }
+ $v1 = 2 * $lightness - $v2;
+ $red = 255 * self::hue2rgb($v1, $v2, $hue + (1 / 3));
+ $green = 255 * self::hue2rgb($v1, $v2, $hue);
+ $blue = 255 * self::hue2rgb($v1, $v2, $hue - (1 / 3));
+ }
+ return "#" . str_pad(dechex(round($red)), 2, "0", STR_PAD_LEFT) . str_pad(dechex(round($green)), 2, "0", STR_PAD_LEFT) . str_pad(dechex(round($blue)), 2, "0", STR_PAD_LEFT);
+ }
+ /**
+ * Apply hue to a rgb color value.
+ *
+ * @param integer $v1 Value 1
+ * @param integer $v2 Value 2
+ * @param integer $hue Hue
+ * @return integer
+ */
+ private function hue2rgb($v1, $v2, $hue)
+ {
+ if ($hue < 0)
+ {
+ $hue += 1;
+ }
+ if ($hue > 1)
+ {
+ $hue -= 1;
+ }
+ if ((6 * $hue) < 1)
+ {
+ return ($v1 + ($v2 - $v1) * 6 * $hue);
+ }
+ if ((2 * $hue) < 1)
+ {
+ return ($v2);
+ }
+ if ((3 * $hue) < 2)
+ {
+ return ($v1 + ($v2 - $v1) * (( 2 / 3) - $hue) * 6);
+ }
+ return $v1;
+ }
+ }
+
+/**
+ * This {@link aCssMinifierPlugin} will convert the font-weight values normal and bold to their numeric notation.
+ *
+ * Example:
+ *
+ * font-weight: normal;
+ * font: bold 11px monospace;
+ *
+ *
+ * Will get converted to:
+ *
+ * font-weight:400;
+ * font:700 11px monospace;
+ *
+ *
+ * @package CssMin/Minifier/Pluginsn
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssConvertFontWeightMinifierPlugin extends aCssMinifierPlugin
+ {
+ /**
+ * Array of included declaration properties this plugin will process; others declaration properties will get
+ * ignored.
+ *
+ * @var array
+ */
+ private $include = array
+ (
+ "font",
+ "font-weight"
+ );
+ /**
+ * Regular expression matching the value.
+ *
+ * @var string
+ */
+ private $reMatch = null;
+ /**
+ * Regular expression replace the value.
+ *
+ * @var string
+ */
+ private $reReplace = "\"\${1}\" . \$this->transformation[\"\${2}\"] . \"\${3}\"";
+ /**
+ * Transformation table used by the {@link CssConvertFontWeightMinifierPlugin::$reReplace replace regular expression}.
+ *
+ * @var array
+ */
+ private $transformation = array
+ (
+ "normal" => "400",
+ "bold" => "700"
+ );
+ /**
+ * Overwrites {@link aCssMinifierPlugin::__construct()}.
+ *
+ * The constructor will create the {@link CssConvertFontWeightMinifierPlugin::$reReplace replace regular expression}
+ * based on the {@link CssConvertFontWeightMinifierPlugin::$transformation transformation table}.
+ *
+ * @param CssMinifier $minifier The CssMinifier object of this plugin.
+ * @return void
+ */
+ public function __construct(CssMinifier $minifier)
+ {
+ $this->reMatch = "/(^|\s)+(" . implode("|", array_keys($this->transformation)). ")(\s|$)+/eiS";
+ parent::__construct($minifier);
+ }
+ /**
+ * Implements {@link aCssMinifierPlugin::minify()}.
+ *
+ * @param aCssToken $token Token to process
+ * @return boolean Return TRUE to break the processing of this token; FALSE to continue
+ */
+ public function apply(aCssToken &$token)
+ {
+ if (in_array($token->Property, $this->include) && preg_match($this->reMatch, $token->Value, $m))
+ {
+ $token->Value = preg_replace($this->reMatch, $this->reReplace, $token->Value);
+ }
+ return false;
+ }
+ /**
+ * Implements {@link aMinifierPlugin::getTriggerTokens()}
+ *
+ * @return array
+ */
+ public function getTriggerTokens()
+ {
+ return array
+ (
+ "CssAtFontFaceDeclarationToken",
+ "CssAtPageDeclarationToken",
+ "CssRulesetDeclarationToken"
+ );
+ }
+ }
+
+/**
+ * This {@link aCssMinifierPlugin} will compress several unit values to their short notations. Examples:
+ *
+ *
+ * padding: 0.5em;
+ * border: 0px;
+ * margin: 0 0 0 0;
+ *
+ *
+ * Will get compressed to:
+ *
+ *
+ * padding:.5px;
+ * border:0;
+ * margin:0;
+ *
+ *
+ * --
+ *
+ * @package CssMin/Minifier/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssCompressUnitValuesMinifierPlugin extends aCssMinifierPlugin
+ {
+ /**
+ * Regular expression used for matching and replacing unit values.
+ *
+ * @var array
+ */
+ private $re = array
+ (
+ "/(^| |-)0\.([0-9]+?)(0+)?(%|em|ex|px|in|cm|mm|pt|pc)/iS" => "\${1}.\${2}\${4}",
+ "/(^| )-?(\.?)0(%|em|ex|px|in|cm|mm|pt|pc)/iS" => "\${1}0",
+ "/(^0\s0\s0\s0)|(^0\s0\s0$)|(^0\s0$)/iS" => "0"
+ );
+ /**
+ * Regular expression matching the value.
+ *
+ * @var string
+ */
+ private $reMatch = "/(^| |-)0\.([0-9]+?)(0+)?(%|em|ex|px|in|cm|mm|pt|pc)|(^| )-?(\.?)0(%|em|ex|px|in|cm|mm|pt|pc)|(^0\s0\s0\s0$)|(^0\s0\s0$)|(^0\s0$)/iS";
+ /**
+ * Implements {@link aCssMinifierPlugin::minify()}.
+ *
+ * @param aCssToken $token Token to process
+ * @return boolean Return TRUE to break the processing of this token; FALSE to continue
+ */
+ public function apply(aCssToken &$token)
+ {
+ if (preg_match($this->reMatch, $token->Value))
+ {
+ foreach ($this->re as $reMatch => $reReplace)
+ {
+ $token->Value = preg_replace($reMatch, $reReplace, $token->Value);
+ }
+ }
+ return false;
+ }
+ /**
+ * Implements {@link aMinifierPlugin::getTriggerTokens()}
+ *
+ * @return array
+ */
+ public function getTriggerTokens()
+ {
+ return array
+ (
+ "CssAtFontFaceDeclarationToken",
+ "CssAtPageDeclarationToken",
+ "CssRulesetDeclarationToken"
+ );
+ }
+ }
+
+/**
+ * This {@link aCssMinifierPlugin} compress the content of expresssion() declaration values.
+ *
+ * For compression of expressions {@link https://github.com/rgrove/jsmin-php/ JSMin} will get used. JSMin have to be
+ * already included or loadable via {@link http://goo.gl/JrW54 PHP autoloading}.
+ *
+ * @package CssMin/Minifier/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssCompressExpressionValuesMinifierPlugin extends aCssMinifierPlugin
+ {
+ /**
+ * Implements {@link aCssMinifierPlugin::minify()}.
+ *
+ * @param aCssToken $token Token to process
+ * @return boolean Return TRUE to break the processing of this token; FALSE to continue
+ */
+ public function apply(aCssToken &$token)
+ {
+ if (class_exists("JSMin") && stripos($token->Value, "expression(") !== false)
+ {
+ $value = $token->Value;
+ $value = substr($token->Value, stripos($token->Value, "expression(") + 10);
+ $value = trim(JSMin::minify($value));
+ $token->Value = "expression(" . $value . ")";
+ }
+ return false;
+ }
+ /**
+ * Implements {@link aMinifierPlugin::getTriggerTokens()}
+ *
+ * @return array
+ */
+ public function getTriggerTokens()
+ {
+ return array
+ (
+ "CssAtFontFaceDeclarationToken",
+ "CssAtPageDeclarationToken",
+ "CssRulesetDeclarationToken"
+ );
+ }
+ }
+
+/**
+ * This {@link aCssMinifierPlugin} will convert hexadecimal color value with 6 chars to their 3 char hexadecimal
+ * notation (if possible).
+ *
+ * Example:
+ *
+ * color: #aabbcc;
+ *
+ *
+ * Will get converted to:
+ *
+ * color:#abc;
+ *
+ *
+ * @package CssMin/Minifier/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssCompressColorValuesMinifierPlugin extends aCssMinifierPlugin
+ {
+ /**
+ * Regular expression matching 6 char hexadecimal color values.
+ *
+ * @var string
+ */
+ private $reMatch = "/\#([0-9a-f]{6})/iS";
+ /**
+ * Implements {@link aCssMinifierPlugin::minify()}.
+ *
+ * @param aCssToken $token Token to process
+ * @return boolean Return TRUE to break the processing of this token; FALSE to continue
+ */
+ public function apply(aCssToken &$token)
+ {
+ if (strpos($token->Value, "#") !== false && preg_match($this->reMatch, $token->Value, $m))
+ {
+ $value = strtolower($m[1]);
+ if ($value[0] == $value[1] && $value[2] == $value[3] && $value[4] == $value[5])
+ {
+ $token->Value = str_replace($m[0], "#" . $value[0] . $value[2] . $value[4], $token->Value);
+ }
+ }
+ return false;
+ }
+ /**
+ * Implements {@link aMinifierPlugin::getTriggerTokens()}
+ *
+ * @return array
+ */
+ public function getTriggerTokens()
+ {
+ return array
+ (
+ "CssAtFontFaceDeclarationToken",
+ "CssAtPageDeclarationToken",
+ "CssRulesetDeclarationToken"
+ );
+ }
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents a CSS comment.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssCommentToken extends aCssToken
+ {
+ /**
+ * Comment as Text.
+ *
+ * @var string
+ */
+ public $Comment = "";
+ /**
+ * Set the properties of a comment token.
+ *
+ * @param string $comment Comment including comment delimiters
+ * @return void
+ */
+ public function __construct($comment)
+ {
+ $this->Comment = $comment;
+ }
+ /**
+ * Implements {@link aCssToken::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return $this->Comment;
+ }
+ }
+
+/**
+ * {@link aCssParserPlugin Parser plugin} for parsing comments.
+ *
+ * Adds a {@link CssCommentToken} to the parser if a comment was found.
+ *
+ * @package CssMin/Parser/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssCommentParserPlugin extends aCssParserPlugin
+ {
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerChars()}.
+ *
+ * @return array
+ */
+ public function getTriggerChars()
+ {
+ return array("*", "/");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerStates()}.
+ *
+ * @return array
+ */
+ public function getTriggerStates()
+ {
+ return false;
+ }
+ /**
+ * Stored buffer for restore.
+ *
+ * @var string
+ */
+ private $restoreBuffer = "";
+ /**
+ * Implements {@link aCssParserPlugin::parse()}.
+ *
+ * @param integer $index Current index
+ * @param string $char Current char
+ * @param string $previousChar Previous char
+ * @return mixed TRUE will break the processing; FALSE continue with the next plugin; integer set a new index and break the processing
+ */
+ public function parse($index, $char, $previousChar, $state)
+ {
+ if ($char === "*" && $previousChar === "/" && $state !== "T_COMMENT")
+ {
+ $this->parser->pushState("T_COMMENT");
+ $this->parser->setExclusive(__CLASS__);
+ $this->restoreBuffer = substr($this->parser->getAndClearBuffer(), 0, -2);
+ }
+ elseif ($char === "/" && $previousChar === "*" && $state === "T_COMMENT")
+ {
+ $this->parser->popState();
+ $this->parser->unsetExclusive();
+ $this->parser->appendToken(new CssCommentToken("/*" . $this->parser->getAndClearBuffer()));
+ $this->parser->setBuffer($this->restoreBuffer);
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents the start of a @variables at-rule block.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtVariablesStartToken extends aCssAtBlockStartToken
+ {
+ /**
+ * Media types of the @variables at-rule block.
+ *
+ * @var array
+ */
+ public $MediaTypes = array();
+ /**
+ * Set the properties of a @variables at-rule token.
+ *
+ * @param array $mediaTypes Media types
+ * @return void
+ */
+ public function __construct($mediaTypes = null)
+ {
+ $this->MediaTypes = $mediaTypes ? $mediaTypes : array("all");
+ }
+ /**
+ * Implements {@link aCssToken::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return "";
+ }
+ }
+
+/**
+ * {@link aCssParserPlugin Parser plugin} for parsing @variables at-rule block with including declarations.
+ *
+ * Found @variables at-rule blocks will add a {@link CssAtVariablesStartToken} and {@link CssAtVariablesEndToken} to the
+ * parser; including declarations as {@link CssAtVariablesDeclarationToken}.
+ *
+ * @package CssMin/Parser/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtVariablesParserPlugin extends aCssParserPlugin
+ {
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerChars()}.
+ *
+ * @return array
+ */
+ public function getTriggerChars()
+ {
+ return array("@", "{", "}", ":", ";");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerStates()}.
+ *
+ * @return array
+ */
+ public function getTriggerStates()
+ {
+ return array("T_DOCUMENT", "T_AT_VARIABLES::PREPARE", "T_AT_VARIABLES", "T_AT_VARIABLES_DECLARATION");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::parse()}.
+ *
+ * @param integer $index Current index
+ * @param string $char Current char
+ * @param string $previousChar Previous char
+ * @return mixed TRUE will break the processing; FALSE continue with the next plugin; integer set a new index and break the processing
+ */
+ public function parse($index, $char, $previousChar, $state)
+ {
+ // Start of @variables at-rule block
+ if ($char === "@" && $state === "T_DOCUMENT" && strtolower(substr($this->parser->getSource(), $index, 10)) === "@variables")
+ {
+ $this->parser->pushState("T_AT_VARIABLES::PREPARE");
+ $this->parser->clearBuffer();
+ return $index + 10;
+ }
+ // Start of @variables declarations
+ elseif ($char === "{" && $state === "T_AT_VARIABLES::PREPARE")
+ {
+ $this->parser->setState("T_AT_VARIABLES");
+ $mediaTypes = array_filter(array_map("trim", explode(",", $this->parser->getAndClearBuffer("{"))));
+ $this->parser->appendToken(new CssAtVariablesStartToken($mediaTypes));
+ }
+ // Start of @variables declaration
+ if ($char === ":" && $state === "T_AT_VARIABLES")
+ {
+ $this->buffer = $this->parser->getAndClearBuffer(":");
+ $this->parser->pushState("T_AT_VARIABLES_DECLARATION");
+ }
+ // Unterminated @variables declaration
+ elseif ($char === ":" && $state === "T_AT_VARIABLES_DECLARATION")
+ {
+ // Ignore Internet Explorer filter declarations
+ if ($this->buffer === "filter")
+ {
+ return false;
+ }
+ CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Unterminated @variables declaration", $this->buffer . ":" . $this->parser->getBuffer() . "_"));
+ }
+ // End of @variables declaration
+ elseif (($char === ";" || $char === "}") && $state === "T_AT_VARIABLES_DECLARATION")
+ {
+ $value = $this->parser->getAndClearBuffer(";}");
+ if (strtolower(substr($value, -10, 10)) === "!important")
+ {
+ $value = trim(substr($value, 0, -10));
+ $isImportant = true;
+ }
+ else
+ {
+ $isImportant = false;
+ }
+ $this->parser->popState();
+ $this->parser->appendToken(new CssAtVariablesDeclarationToken($this->buffer, $value, $isImportant));
+ $this->buffer = "";
+ }
+ // End of @variables at-rule block
+ elseif ($char === "}" && $state === "T_AT_VARIABLES")
+ {
+ $this->parser->popState();
+ $this->parser->clearBuffer();
+ $this->parser->appendToken(new CssAtVariablesEndToken());
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents the end of a @variables at-rule block.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtVariablesEndToken extends aCssAtBlockEndToken
+ {
+ /**
+ * Implements {@link aCssToken::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return "";
+ }
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents a declaration of a @variables at-rule block.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtVariablesDeclarationToken extends aCssDeclarationToken
+ {
+ /**
+ * Implements {@link aCssToken::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return "";
+ }
+ }
+
+/**
+* This {@link aCssToken CSS token} represents the start of a @page at-rule block.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtPageStartToken extends aCssAtBlockStartToken
+ {
+ /**
+ * Selector.
+ *
+ * @var string
+ */
+ public $Selector = "";
+ /**
+ * Sets the properties of the @page at-rule.
+ *
+ * @param string $selector Selector
+ * @return void
+ */
+ public function __construct($selector = "")
+ {
+ $this->Selector = $selector;
+ }
+ /**
+ * Implements {@link aCssToken::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return "@page" . ($this->Selector ? " " . $this->Selector : "") . "{";
+ }
+ }
+
+/**
+ * {@link aCssParserPlugin Parser plugin} for parsing @page at-rule block with including declarations.
+ *
+ * Found @page at-rule blocks will add a {@link CssAtPageStartToken} and {@link CssAtPageEndToken} to the
+ * parser; including declarations as {@link CssAtPageDeclarationToken}.
+ *
+ * @package CssMin/Parser/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtPageParserPlugin extends aCssParserPlugin
+ {
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerChars()}.
+ *
+ * @return array
+ */
+ public function getTriggerChars()
+ {
+ return array("@", "{", "}", ":", ";");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerStates()}.
+ *
+ * @return array
+ */
+ public function getTriggerStates()
+ {
+ return array("T_DOCUMENT", "T_AT_PAGE::SELECTOR", "T_AT_PAGE", "T_AT_PAGE_DECLARATION");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::parse()}.
+ *
+ * @param integer $index Current index
+ * @param string $char Current char
+ * @param string $previousChar Previous char
+ * @return mixed TRUE will break the processing; FALSE continue with the next plugin; integer set a new index and break the processing
+ */
+ public function parse($index, $char, $previousChar, $state)
+ {
+ // Start of @page at-rule block
+ if ($char === "@" && $state === "T_DOCUMENT" && strtolower(substr($this->parser->getSource(), $index, 5)) === "@page")
+ {
+ $this->parser->pushState("T_AT_PAGE::SELECTOR");
+ $this->parser->clearBuffer();
+ return $index + 5;
+ }
+ // Start of @page declarations
+ elseif ($char === "{" && $state === "T_AT_PAGE::SELECTOR")
+ {
+ $selector = $this->parser->getAndClearBuffer("{");
+ $this->parser->setState("T_AT_PAGE");
+ $this->parser->clearBuffer();
+ $this->parser->appendToken(new CssAtPageStartToken($selector));
+ }
+ // Start of @page declaration
+ elseif ($char === ":" && $state === "T_AT_PAGE")
+ {
+ $this->parser->pushState("T_AT_PAGE_DECLARATION");
+ $this->buffer = $this->parser->getAndClearBuffer(":", true);
+ }
+ // Unterminated @font-face declaration
+ elseif ($char === ":" && $state === "T_AT_PAGE_DECLARATION")
+ {
+ // Ignore Internet Explorer filter declarations
+ if ($this->buffer === "filter")
+ {
+ return false;
+ }
+ CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Unterminated @page declaration", $this->buffer . ":" . $this->parser->getBuffer() . "_"));
+ }
+ // End of @page declaration
+ elseif (($char === ";" || $char === "}") && $state == "T_AT_PAGE_DECLARATION")
+ {
+ $value = $this->parser->getAndClearBuffer(";}");
+ if (strtolower(substr($value, -10, 10)) == "!important")
+ {
+ $value = trim(substr($value, 0, -10));
+ $isImportant = true;
+ }
+ else
+ {
+ $isImportant = false;
+ }
+ $this->parser->popState();
+ $this->parser->appendToken(new CssAtPageDeclarationToken($this->buffer, $value, $isImportant));
+ // --
+ if ($char === "}")
+ {
+ $this->parser->popState();
+ $this->parser->appendToken(new CssAtPageEndToken());
+ }
+ $this->buffer = "";
+ }
+ // End of @page at-rule block
+ elseif ($char === "}" && $state === "T_AT_PAGE")
+ {
+ $this->parser->popState();
+ $this->parser->clearBuffer();
+ $this->parser->appendToken(new CssAtPageEndToken());
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents the end of a @page at-rule block.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtPageEndToken extends aCssAtBlockEndToken
+ {
+
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents a declaration of a @page at-rule block.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtPageDeclarationToken extends aCssDeclarationToken
+ {
+
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents the start of a @media at-rule block.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtMediaStartToken extends aCssAtBlockStartToken
+ {
+ /**
+ * Sets the properties of the @media at-rule.
+ *
+ * @param array $mediaTypes Media types
+ * @return void
+ */
+ public function __construct(array $mediaTypes = array())
+ {
+ $this->MediaTypes = $mediaTypes;
+ }
+ /**
+ * Implements {@link aCssToken::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return "@media " . implode(",", $this->MediaTypes) . "{";
+ }
+ }
+
+/**
+ * {@link aCssParserPlugin Parser plugin} for parsing @media at-rule block.
+ *
+ * Found @media at-rule blocks will add a {@link CssAtMediaStartToken} and {@link CssAtMediaEndToken} to the parser.
+ * This plugin will also set the the current media types using {@link CssParser::setMediaTypes()} and
+ * {@link CssParser::unsetMediaTypes()}.
+ *
+ * @package CssMin/Parser/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtMediaParserPlugin extends aCssParserPlugin
+ {
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerChars()}.
+ *
+ * @return array
+ */
+ public function getTriggerChars()
+ {
+ return array("@", "{", "}");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerStates()}.
+ *
+ * @return array
+ */
+ public function getTriggerStates()
+ {
+ return array("T_DOCUMENT", "T_AT_MEDIA::PREPARE", "T_AT_MEDIA");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::parse()}.
+ *
+ * @param integer $index Current index
+ * @param string $char Current char
+ * @param string $previousChar Previous char
+ * @return mixed TRUE will break the processing; FALSE continue with the next plugin; integer set a new index and break the processing
+ */
+ public function parse($index, $char, $previousChar, $state)
+ {
+ if ($char === "@" && $state === "T_DOCUMENT" && strtolower(substr($this->parser->getSource(), $index, 6)) === "@media")
+ {
+ $this->parser->pushState("T_AT_MEDIA::PREPARE");
+ $this->parser->clearBuffer();
+ return $index + 6;
+ }
+ elseif ($char === "{" && $state === "T_AT_MEDIA::PREPARE")
+ {
+ $mediaTypes = array_filter(array_map("trim", explode(",", $this->parser->getAndClearBuffer("{"))));
+ $this->parser->setMediaTypes($mediaTypes);
+ $this->parser->setState("T_AT_MEDIA");
+ $this->parser->appendToken(new CssAtMediaStartToken($mediaTypes));
+ }
+ elseif ($char === "}" && $state === "T_AT_MEDIA")
+ {
+ $this->parser->appendToken(new CssAtMediaEndToken());
+ $this->parser->clearBuffer();
+ $this->parser->unsetMediaTypes();
+ $this->parser->popState();
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents the end of a @media at-rule block.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtMediaEndToken extends aCssAtBlockEndToken
+ {
+
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents the start of a @keyframes at-rule block.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtKeyframesStartToken extends aCssAtBlockStartToken
+ {
+ /**
+ * Name of the at-rule.
+ *
+ * @var string
+ */
+ public $AtRuleName = "keyframes";
+ /**
+ * Name
+ *
+ * @var string
+ */
+ public $Name = "";
+ /**
+ * Sets the properties of the @page at-rule.
+ *
+ * @param string $selector Selector
+ * @return void
+ */
+ public function __construct($name, $atRuleName = null)
+ {
+ $this->Name = $name;
+ if (!is_null($atRuleName))
+ {
+ $this->AtRuleName = $atRuleName;
+ }
+ }
+ /**
+ * Implements {@link aCssToken::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return "@" . $this->AtRuleName . " \"" . $this->Name . "\"{";
+ }
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents the start of a ruleset of a @keyframes at-rule block.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtKeyframesRulesetStartToken extends aCssRulesetStartToken
+ {
+ /**
+ * Array of selectors.
+ *
+ * @var array
+ */
+ public $Selectors = array();
+ /**
+ * Set the properties of a ruleset token.
+ *
+ * @param array $selectors Selectors of the ruleset
+ * @return void
+ */
+ public function __construct(array $selectors = array())
+ {
+ $this->Selectors = $selectors;
+ }
+ /**
+ * Implements {@link aCssToken::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return implode(",", $this->Selectors) . "{";
+ }
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents the end of a ruleset of a @keyframes at-rule block.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtKeyframesRulesetEndToken extends aCssRulesetEndToken
+ {
+
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents a ruleset declaration of a @keyframes at-rule block.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtKeyframesRulesetDeclarationToken extends aCssDeclarationToken
+ {
+
+ }
+
+/**
+ * {@link aCssParserPlugin Parser plugin} for parsing @keyframes at-rule blocks, rulesets and declarations.
+ *
+ * @package CssMin/Parser/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtKeyframesParserPlugin extends aCssParserPlugin
+ {
+ /**
+ * @var string Keyword
+ */
+ private $atRuleName = "";
+ /**
+ * Selectors.
+ *
+ * @var array
+ */
+ private $selectors = array();
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerChars()}.
+ *
+ * @return array
+ */
+ public function getTriggerChars()
+ {
+ return array("@", "{", "}", ":", ",", ";");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerStates()}.
+ *
+ * @return array
+ */
+ public function getTriggerStates()
+ {
+ return array("T_DOCUMENT", "T_AT_KEYFRAMES::NAME", "T_AT_KEYFRAMES", "T_AT_KEYFRAMES_RULESETS", "T_AT_KEYFRAMES_RULESET", "T_AT_KEYFRAMES_RULESET_DECLARATION");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::parse()}.
+ *
+ * @param integer $index Current index
+ * @param string $char Current char
+ * @param string $previousChar Previous char
+ * @return mixed TRUE will break the processing; FALSE continue with the next plugin; integer set a new index and break the processing
+ */
+ public function parse($index, $char, $previousChar, $state)
+ {
+ // Start of @keyframes at-rule block
+ if ($char === "@" && $state === "T_DOCUMENT" && strtolower(substr($this->parser->getSource(), $index, 10)) === "@keyframes")
+ {
+ $this->atRuleName = "keyframes";
+ $this->parser->pushState("T_AT_KEYFRAMES::NAME");
+ $this->parser->clearBuffer();
+ return $index + 10;
+ }
+ // Start of @keyframes at-rule block (@-moz-keyframes)
+ elseif ($char === "@" && $state === "T_DOCUMENT" && strtolower(substr($this->parser->getSource(), $index, 15)) === "@-moz-keyframes")
+ {
+ $this->atRuleName = "-moz-keyframes";
+ $this->parser->pushState("T_AT_KEYFRAMES::NAME");
+ $this->parser->clearBuffer();
+ return $index + 15;
+ }
+ // Start of @keyframes at-rule block (@-webkit-keyframes)
+ elseif ($char === "@" && $state === "T_DOCUMENT" && strtolower(substr($this->parser->getSource(), $index, 18)) === "@-webkit-keyframes")
+ {
+ $this->atRuleName = "-webkit-keyframes";
+ $this->parser->pushState("T_AT_KEYFRAMES::NAME");
+ $this->parser->clearBuffer();
+ return $index + 18;
+ }
+ // Start of @keyframes rulesets
+ elseif ($char === "{" && $state === "T_AT_KEYFRAMES::NAME")
+ {
+ $name = $this->parser->getAndClearBuffer("{\"'");
+ $this->parser->setState("T_AT_KEYFRAMES_RULESETS");
+ $this->parser->clearBuffer();
+ $this->parser->appendToken(new CssAtKeyframesStartToken($name, $this->atRuleName));
+ }
+ // Start of @keyframe ruleset and selectors
+ if ($char === "," && $state === "T_AT_KEYFRAMES_RULESETS")
+ {
+ $this->selectors[] = $this->parser->getAndClearBuffer(",{");
+ }
+ // Start of a @keyframes ruleset
+ elseif ($char === "{" && $state === "T_AT_KEYFRAMES_RULESETS")
+ {
+ if ($this->parser->getBuffer() !== "")
+ {
+ $this->selectors[] = $this->parser->getAndClearBuffer(",{");
+ $this->parser->pushState("T_AT_KEYFRAMES_RULESET");
+ $this->parser->appendToken(new CssAtKeyframesRulesetStartToken($this->selectors));
+ $this->selectors = array();
+ }
+ }
+ // Start of @keyframes ruleset declaration
+ elseif ($char === ":" && $state === "T_AT_KEYFRAMES_RULESET")
+ {
+ $this->parser->pushState("T_AT_KEYFRAMES_RULESET_DECLARATION");
+ $this->buffer = $this->parser->getAndClearBuffer(":;", true);
+ }
+ // Unterminated @keyframes ruleset declaration
+ elseif ($char === ":" && $state === "T_AT_KEYFRAMES_RULESET_DECLARATION")
+ {
+ // Ignore Internet Explorer filter declarations
+ if ($this->buffer === "filter")
+ {
+ return false;
+ }
+ CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Unterminated @keyframes ruleset declaration", $this->buffer . ":" . $this->parser->getBuffer() . "_"));
+ }
+ // End of declaration
+ elseif (($char === ";" || $char === "}") && $state === "T_AT_KEYFRAMES_RULESET_DECLARATION")
+ {
+ $value = $this->parser->getAndClearBuffer(";}");
+ if (strtolower(substr($value, -10, 10)) === "!important")
+ {
+ $value = trim(substr($value, 0, -10));
+ $isImportant = true;
+ }
+ else
+ {
+ $isImportant = false;
+ }
+ $this->parser->popState();
+ $this->parser->appendToken(new CssAtKeyframesRulesetDeclarationToken($this->buffer, $value, $isImportant));
+ // Declaration ends with a right curly brace; so we have to end the ruleset
+ if ($char === "}")
+ {
+ $this->parser->appendToken(new CssAtKeyframesRulesetEndToken());
+ $this->parser->popState();
+ }
+ $this->buffer = "";
+ }
+ // End of @keyframes ruleset
+ elseif ($char === "}" && $state === "T_AT_KEYFRAMES_RULESET")
+ {
+ $this->parser->clearBuffer();
+
+ $this->parser->popState();
+ $this->parser->appendToken(new CssAtKeyframesRulesetEndToken());
+ }
+ // End of @keyframes rulesets
+ elseif ($char === "}" && $state === "T_AT_KEYFRAMES_RULESETS")
+ {
+ $this->parser->clearBuffer();
+ $this->parser->popState();
+ $this->parser->appendToken(new CssAtKeyframesEndToken());
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents the end of a @keyframes at-rule block.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtKeyframesEndToken extends aCssAtBlockEndToken
+ {
+
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents a @import at-rule.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1.b1 (2001-02-22)
+ */
+class CssAtImportToken extends aCssToken
+ {
+ /**
+ * Import path of the @import at-rule.
+ *
+ * @var string
+ */
+ public $Import = "";
+ /**
+ * Media types of the @import at-rule.
+ *
+ * @var array
+ */
+ public $MediaTypes = array();
+ /**
+ * Set the properties of a @import at-rule token.
+ *
+ * @param string $import Import path
+ * @param array $mediaTypes Media types
+ * @return void
+ */
+ public function __construct($import, $mediaTypes)
+ {
+ $this->Import = $import;
+ $this->MediaTypes = $mediaTypes ? $mediaTypes : array();
+ }
+ /**
+ * Implements {@link aCssToken::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return "@import \"" . $this->Import . "\"" . (count($this->MediaTypes) > 0 ? " " . implode(",", $this->MediaTypes) : ""). ";";
+ }
+ }
+
+/**
+ * {@link aCssParserPlugin Parser plugin} for parsing @import at-rule.
+ *
+ * If a @import at-rule was found this plugin will add a {@link CssAtImportToken} to the parser.
+ *
+ * @package CssMin/Parser/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtImportParserPlugin extends aCssParserPlugin
+ {
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerChars()}.
+ *
+ * @return array
+ */
+ public function getTriggerChars()
+ {
+ return array("@", ";", ",", "\n");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerStates()}.
+ *
+ * @return array
+ */
+ public function getTriggerStates()
+ {
+ return array("T_DOCUMENT", "T_AT_IMPORT");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::parse()}.
+ *
+ * @param integer $index Current index
+ * @param string $char Current char
+ * @param string $previousChar Previous char
+ * @return mixed TRUE will break the processing; FALSE continue with the next plugin; integer set a new index and break the processing
+ */
+ public function parse($index, $char, $previousChar, $state)
+ {
+ if ($char === "@" && $state === "T_DOCUMENT" && strtolower(substr($this->parser->getSource(), $index, 7)) === "@import")
+ {
+ $this->parser->pushState("T_AT_IMPORT");
+ $this->parser->clearBuffer();
+ return $index + 7;
+ }
+ elseif (($char === ";" || $char === "\n") && $state === "T_AT_IMPORT")
+ {
+ $this->buffer = $this->parser->getAndClearBuffer(";");
+ $pos = false;
+ foreach (array(")", "\"", "'") as $needle)
+ {
+ if (($pos = strrpos($this->buffer, $needle)) !== false)
+ {
+ break;
+ }
+ }
+ $import = substr($this->buffer, 0, $pos + 1);
+ if (stripos($import, "url(") === 0)
+ {
+ $import = substr($import, 4, -1);
+ }
+ $import = trim($import, " \t\n\r\0\x0B'\"");
+ $mediaTypes = array_filter(array_map("trim", explode(",", trim(substr($this->buffer, $pos + 1), " \t\n\r\0\x0B{"))));
+ if ($pos)
+ {
+ $this->parser->appendToken(new CssAtImportToken($import, $mediaTypes));
+ }
+ else
+ {
+ CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Invalid @import at-rule syntax", $this->parser->buffer));
+ }
+ $this->parser->popState();
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents the start of a @font-face at-rule block.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtFontFaceStartToken extends aCssAtBlockStartToken
+ {
+ /**
+ * Implements {@link aCssToken::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return "@font-face{";
+ }
+ }
+
+/**
+ * {@link aCssParserPlugin Parser plugin} for parsing @font-face at-rule block with including declarations.
+ *
+ * Found @font-face at-rule blocks will add a {@link CssAtFontFaceStartToken} and {@link CssAtFontFaceEndToken} to the
+ * parser; including declarations as {@link CssAtFontFaceDeclarationToken}.
+ *
+ * @package CssMin/Parser/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtFontFaceParserPlugin extends aCssParserPlugin
+ {
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerChars()}.
+ *
+ * @return array
+ */
+ public function getTriggerChars()
+ {
+ return array("@", "{", "}", ":", ";");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerStates()}.
+ *
+ * @return array
+ */
+ public function getTriggerStates()
+ {
+ return array("T_DOCUMENT", "T_AT_FONT_FACE::PREPARE", "T_AT_FONT_FACE", "T_AT_FONT_FACE_DECLARATION");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::parse()}.
+ *
+ * @param integer $index Current index
+ * @param string $char Current char
+ * @param string $previousChar Previous char
+ * @return mixed TRUE will break the processing; FALSE continue with the next plugin; integer set a new index and break the processing
+ */
+ public function parse($index, $char, $previousChar, $state)
+ {
+ // Start of @font-face at-rule block
+ if ($char === "@" && $state === "T_DOCUMENT" && strtolower(substr($this->parser->getSource(), $index, 10)) === "@font-face")
+ {
+ $this->parser->pushState("T_AT_FONT_FACE::PREPARE");
+ $this->parser->clearBuffer();
+ return $index + 10;
+ }
+ // Start of @font-face declarations
+ elseif ($char === "{" && $state === "T_AT_FONT_FACE::PREPARE")
+ {
+ $this->parser->setState("T_AT_FONT_FACE");
+ $this->parser->clearBuffer();
+ $this->parser->appendToken(new CssAtFontFaceStartToken());
+ }
+ // Start of @font-face declaration
+ elseif ($char === ":" && $state === "T_AT_FONT_FACE")
+ {
+ $this->parser->pushState("T_AT_FONT_FACE_DECLARATION");
+ $this->buffer = $this->parser->getAndClearBuffer(":", true);
+ }
+ // Unterminated @font-face declaration
+ elseif ($char === ":" && $state === "T_AT_FONT_FACE_DECLARATION")
+ {
+ // Ignore Internet Explorer filter declarations
+ if ($this->buffer === "filter")
+ {
+ return false;
+ }
+ CssMin::triggerError(new CssError(__FILE__, __LINE__, __METHOD__ . ": Unterminated @font-face declaration", $this->buffer . ":" . $this->parser->getBuffer() . "_"));
+ }
+ // End of @font-face declaration
+ elseif (($char === ";" || $char === "}") && $state === "T_AT_FONT_FACE_DECLARATION")
+ {
+ $value = $this->parser->getAndClearBuffer(";}");
+ if (strtolower(substr($value, -10, 10)) === "!important")
+ {
+ $value = trim(substr($value, 0, -10));
+ $isImportant = true;
+ }
+ else
+ {
+ $isImportant = false;
+ }
+ $this->parser->popState();
+ $this->parser->appendToken(new CssAtFontFaceDeclarationToken($this->buffer, $value, $isImportant));
+ $this->buffer = "";
+ // --
+ if ($char === "}")
+ {
+ $this->parser->appendToken(new CssAtFontFaceEndToken());
+ $this->parser->popState();
+ }
+ }
+ // End of @font-face at-rule block
+ elseif ($char === "}" && $state === "T_AT_FONT_FACE")
+ {
+ $this->parser->appendToken(new CssAtFontFaceEndToken());
+ $this->parser->clearBuffer();
+ $this->parser->popState();
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents the end of a @font-face at-rule block.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtFontFaceEndToken extends aCssAtBlockEndToken
+ {
+
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents a declaration of a @font-face at-rule block.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtFontFaceDeclarationToken extends aCssDeclarationToken
+ {
+
+ }
+
+/**
+ * This {@link aCssToken CSS token} represents a @charset at-rule.
+ *
+ * @package CssMin/Tokens
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtCharsetToken extends aCssToken
+ {
+ /**
+ * Charset of the @charset at-rule.
+ *
+ * @var string
+ */
+ public $Charset = "";
+ /**
+ * Set the properties of @charset at-rule token.
+ *
+ * @param string $charset Charset of the @charset at-rule token
+ * @return void
+ */
+ public function __construct($charset)
+ {
+ $this->Charset = $charset;
+ }
+ /**
+ * Implements {@link aCssToken::__toString()}.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return "@charset " . $this->Charset . ";";
+ }
+ }
+
+/**
+ * {@link aCssParserPlugin Parser plugin} for parsing @charset at-rule.
+ *
+ * If a @charset at-rule was found this plugin will add a {@link CssAtCharsetToken} to the parser.
+ *
+ * @package CssMin/Parser/Plugins
+ * @link http://code.google.com/p/cssmin/
+ * @author Joe Scylla
+ * @copyright 2008 - 2011 Joe Scylla
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 3.0.1
+ */
+class CssAtCharsetParserPlugin extends aCssParserPlugin
+ {
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerChars()}.
+ *
+ * @return array
+ */
+ public function getTriggerChars()
+ {
+ return array("@", ";", "\n");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::getTriggerStates()}.
+ *
+ * @return array
+ */
+ public function getTriggerStates()
+ {
+ return array("T_DOCUMENT", "T_AT_CHARSET");
+ }
+ /**
+ * Implements {@link aCssParserPlugin::parse()}.
+ *
+ * @param integer $index Current index
+ * @param string $char Current char
+ * @param string $previousChar Previous char
+ * @return mixed TRUE will break the processing; FALSE continue with the next plugin; integer set a new index and break the processing
+ */
+ public function parse($index, $char, $previousChar, $state)
+ {
+ if ($char === "@" && $state === "T_DOCUMENT" && strtolower(substr($this->parser->getSource(), $index, 8)) === "@charset")
+ {
+ $this->parser->pushState("T_AT_CHARSET");
+ $this->parser->clearBuffer();
+ return $index + 8;
+ }
+ elseif (($char === ";" || $char === "\n") && $state === "T_AT_CHARSET")
+ {
+ $charset = $this->parser->getAndClearBuffer(";");
+ $this->parser->popState();
+ $this->parser->appendToken(new CssAtCharsetToken($charset));
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+
diff --git a/sparks/assets/1.5.1/libraries/jsmin.php b/sparks/assets/1.5.1/libraries/jsmin.php
new file mode 100644
index 0000000..f3718db
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/jsmin.php
@@ -0,0 +1,385 @@
+
+ * @copyright 2002 Douglas Crockford (jsmin.c)
+ * @copyright 2008 Ryan Grove (PHP port)
+ * @copyright 2012 Adam Goforth (Updates)
+ * @license http://opensource.org/licenses/mit-license.php MIT License
+ * @version 1.1.2 (2012-05-01)
+ * @link https://github.com/rgrove/jsmin-php
+ */
+
+class JSMin {
+ const ORD_LF = 10;
+ const ORD_SPACE = 32;
+ const ACTION_KEEP_A = 1;
+ const ACTION_DELETE_A = 2;
+ const ACTION_DELETE_A_B = 3;
+
+ protected $a = '';
+ protected $b = '';
+ protected $input = '';
+ protected $inputIndex = 0;
+ protected $inputLength = 0;
+ protected $lookAhead = null;
+ protected $output = '';
+
+ // -- Public Static Methods --------------------------------------------------
+
+ /**
+ * Minify Javascript
+ *
+ * @uses __construct()
+ * @uses min()
+ * @param string $js Javascript to be minified
+ * @return string
+ */
+ public static function minify($js) {
+ $jsmin = new JSMin($js);
+ return $jsmin->min();
+ }
+
+ // -- Public Instance Methods ------------------------------------------------
+
+ /**
+ * Constructor
+ *
+ * @param string $input Javascript to be minified
+ */
+ public function __construct($input) {
+ $this->input = str_replace("\r\n", "\n", $input);
+ $this->inputLength = strlen($this->input);
+ }
+
+ // -- Protected Instance Methods ---------------------------------------------
+
+ /**
+ * Action -- do something! What to do is determined by the $command argument.
+ *
+ * action treats a string as a single character. Wow!
+ * action recognizes a regular expression if it is preceded by ( or , or =.
+ *
+ * @uses next()
+ * @uses get()
+ * @throws JSMinException If parser errors are found:
+ * - Unterminated string literal
+ * - Unterminated regular expression set in regex literal
+ * - Unterminated regular expression literal
+ * @param int $command One of class constants:
+ * ACTION_KEEP_A Output A. Copy B to A. Get the next B.
+ * ACTION_DELETE_A Copy B to A. Get the next B. (Delete A).
+ * ACTION_DELETE_A_B Get the next B. (Delete B).
+ */
+ protected function action($command) {
+ switch($command) {
+ case self::ACTION_KEEP_A:
+ $this->output .= $this->a;
+
+ case self::ACTION_DELETE_A:
+ $this->a = $this->b;
+
+ if ($this->a === "'" || $this->a === '"') {
+ for (;;) {
+ $this->output .= $this->a;
+ $this->a = $this->get();
+
+ if ($this->a === $this->b) {
+ break;
+ }
+
+ if (ord($this->a) <= self::ORD_LF) {
+ throw new JSMinException('Unterminated string literal.');
+ }
+
+ if ($this->a === '\\') {
+ $this->output .= $this->a;
+ $this->a = $this->get();
+ }
+ }
+ }
+
+ case self::ACTION_DELETE_A_B:
+ $this->b = $this->next();
+
+ if ($this->b === '/' && (
+ $this->a === '(' || $this->a === ',' || $this->a === '=' ||
+ $this->a === ':' || $this->a === '[' || $this->a === '!' ||
+ $this->a === '&' || $this->a === '|' || $this->a === '?' ||
+ $this->a === '{' || $this->a === '}' || $this->a === ';' ||
+ $this->a === "\n" )) {
+
+ $this->output .= $this->a . $this->b;
+
+ for (;;) {
+ $this->a = $this->get();
+
+ if ($this->a === '[') {
+ /*
+ inside a regex [...] set, which MAY contain a '/' itself. Example: mootools Form.Validator near line 460:
+ return Form.Validator.getValidator('IsEmpty').test(element) || (/^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]\.?){0,63}[a-z0-9!#$%&'*+/=?^_`{|}~-]@(?:(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\])$/i).test(element.get('value'));
+ */
+ for (;;) {
+ $this->output .= $this->a;
+ $this->a = $this->get();
+
+ if ($this->a === ']') {
+ break;
+ } elseif ($this->a === '\\') {
+ $this->output .= $this->a;
+ $this->a = $this->get();
+ } elseif (ord($this->a) <= self::ORD_LF) {
+ throw new JSMinException('Unterminated regular expression set in regex literal.');
+ }
+ }
+ } elseif ($this->a === '/') {
+ break;
+ } elseif ($this->a === '\\') {
+ $this->output .= $this->a;
+ $this->a = $this->get();
+ } elseif (ord($this->a) <= self::ORD_LF) {
+ throw new JSMinException('Unterminated regular expression literal.');
+ }
+
+ $this->output .= $this->a;
+ }
+
+ $this->b = $this->next();
+ }
+ }
+ }
+
+ /**
+ * Get next char. Convert ctrl char to space.
+ *
+ * @return string|null
+ */
+ protected function get() {
+ $c = $this->lookAhead;
+ $this->lookAhead = null;
+
+ if ($c === null) {
+ if ($this->inputIndex < $this->inputLength) {
+ $c = substr($this->input, $this->inputIndex, 1);
+ $this->inputIndex += 1;
+ } else {
+ $c = null;
+ }
+ }
+
+ if ($c === "\r") {
+ return "\n";
+ }
+
+ if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) {
+ return $c;
+ }
+
+ return ' ';
+ }
+
+ /**
+ * Is $c a letter, digit, underscore, dollar sign, or non-ASCII character.
+ *
+ * @return bool
+ */
+ protected function isAlphaNum($c) {
+ return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1;
+ }
+
+ /**
+ * Perform minification, return result
+ *
+ * @uses action()
+ * @uses isAlphaNum()
+ * @uses get()
+ * @uses peek()
+ * @return string
+ */
+ protected function min() {
+ if (0 == strncmp($this->peek(), "\xef", 1)) {
+ $this->get();
+ $this->get();
+ $this->get();
+ }
+
+ $this->a = "\n";
+ $this->action(self::ACTION_DELETE_A_B);
+
+ while ($this->a !== null) {
+ switch ($this->a) {
+ case ' ':
+ if ($this->isAlphaNum($this->b)) {
+ $this->action(self::ACTION_KEEP_A);
+ } else {
+ $this->action(self::ACTION_DELETE_A);
+ }
+ break;
+
+ case "\n":
+ switch ($this->b) {
+ case '{':
+ case '[':
+ case '(':
+ case '+':
+ case '-':
+ case '!':
+ case '~':
+ $this->action(self::ACTION_KEEP_A);
+ break;
+
+ case ' ':
+ $this->action(self::ACTION_DELETE_A_B);
+ break;
+
+ default:
+ if ($this->isAlphaNum($this->b)) {
+ $this->action(self::ACTION_KEEP_A);
+ }
+ else {
+ $this->action(self::ACTION_DELETE_A);
+ }
+ }
+ break;
+
+ default:
+ switch ($this->b) {
+ case ' ':
+ if ($this->isAlphaNum($this->a)) {
+ $this->action(self::ACTION_KEEP_A);
+ break;
+ }
+
+ $this->action(self::ACTION_DELETE_A_B);
+ break;
+
+ case "\n":
+ switch ($this->a) {
+ case '}':
+ case ']':
+ case ')':
+ case '+':
+ case '-':
+ case '"':
+ case "'":
+ $this->action(self::ACTION_KEEP_A);
+ break;
+
+ default:
+ if ($this->isAlphaNum($this->a)) {
+ $this->action(self::ACTION_KEEP_A);
+ }
+ else {
+ $this->action(self::ACTION_DELETE_A_B);
+ }
+ }
+ break;
+
+ default:
+ $this->action(self::ACTION_KEEP_A);
+ break;
+ }
+ }
+ }
+
+ return $this->output;
+ }
+
+ /**
+ * Get the next character, skipping over comments. peek() is used to see
+ * if a '/' is followed by a '/' or '*'.
+ *
+ * @uses get()
+ * @uses peek()
+ * @throws JSMinException On unterminated comment.
+ * @return string
+ */
+ protected function next() {
+ $c = $this->get();
+
+ if ($c === '/') {
+ switch($this->peek()) {
+ case '/':
+ for (;;) {
+ $c = $this->get();
+
+ if (ord($c) <= self::ORD_LF) {
+ return $c;
+ }
+ }
+
+ case '*':
+ $this->get();
+
+ for (;;) {
+ switch($this->get()) {
+ case '*':
+ if ($this->peek() === '/') {
+ $this->get();
+ return ' ';
+ }
+ break;
+
+ case null:
+ throw new JSMinException('Unterminated comment.');
+ }
+ }
+
+ default:
+ return $c;
+ }
+ }
+
+ return $c;
+ }
+
+ /**
+ * Get next char. If is ctrl character, translate to a space or newline.
+ *
+ * @uses get()
+ * @return string|null
+ */
+ protected function peek() {
+ $this->lookAhead = $this->get();
+ return $this->lookAhead;
+ }
+}
+
+// -- Exceptions ---------------------------------------------------------------
+class JSMinException extends Exception {}
diff --git a/sparks/assets/1.5.1/libraries/lessc.php b/sparks/assets/1.5.1/libraries/lessc.php
new file mode 100644
index 0000000..e3ed990
--- /dev/null
+++ b/sparks/assets/1.5.1/libraries/lessc.php
@@ -0,0 +1,3320 @@
+
+ * Licensed under MIT or GPLv3, see LICENSE
+ */
+
+
+/**
+ * The less compiler and parser.
+ *
+ * Converting LESS to CSS is a three stage process. The incoming file is parsed
+ * by `lessc_parser` into a syntax tree, then it is compiled into another tree
+ * representing the CSS structure by `lessc`. The CSS tree is fed into a
+ * formatter, like `lessc_formatter` which then outputs CSS as a string.
+ *
+ * During the first compile, all values are *reduced*, which means that their
+ * types are brought to the lowest form before being dump as strings. This
+ * handles math equations, variable dereferences, and the like.
+ *
+ * The `parse` function of `lessc` is the entry point.
+ *
+ * In summary:
+ *
+ * The `lessc` class creates an intstance of the parser, feeds it LESS code,
+ * then transforms the resulting tree to a CSS tree. This class also holds the
+ * evaluation context, such as all available mixins and variables at any given
+ * time.
+ *
+ * The `lessc_parser` class is only concerned with parsing its input.
+ *
+ * The `lessc_formatter` takes a CSS tree, and dumps it to a formatted string,
+ * handling things like indentation.
+ */
+class lessc {
+ static public $VERSION = "v0.3.7";
+ static protected $TRUE = array("keyword", "true");
+ static protected $FALSE = array("keyword", "false");
+
+ protected $libFunctions = array();
+ protected $registeredVars = array();
+ protected $preserveComments = false;
+
+ public $vPrefix = '@'; // prefix of abstract properties
+ public $mPrefix = '$'; // prefix of abstract blocks
+ public $parentSelector = '&';
+
+ public $importDisabled = false;
+ public $importDir = '';
+
+ protected $numberPrecision = null;
+
+ // set to the parser that generated the current line when compiling
+ // so we know how to create error messages
+ protected $sourceParser = null;
+ protected $sourceLoc = null;
+
+ static public $defaultValue = array("keyword", "");
+
+ // attempts to find the path of an import url, returns null for css files
+ protected function findImport($url) {
+ foreach ((array)$this->importDir as $dir) {
+ $full = $dir.(substr($dir, -1) != '/' ? '/' : '').$url;
+ if ($this->fileExists($file = $full.'.less') || $this->fileExists($file = $full)) {
+ return $file;
+ }
+ }
+
+ return null;
+ }
+
+ protected function fileExists($name) {
+ return is_file($name);
+ }
+
+ static public function compressList($items, $delim) {
+ if (!isset($items[1]) && isset($items[0])) return $items[0];
+ else return array('list', $delim, $items);
+ }
+
+ static public function preg_quote($what) {
+ return preg_quote($what, '/');
+ }
+
+ // attempt to import $import into $parentBlock
+ // $props is the property array that will given to $parentBlock at the end
+ protected function mixImport($import, $parentBlock, &$props) {
+ list(, $url, $media) = $import;
+
+ if (is_array($url)) {
+ $url = $this->compileValue($this->lib_e($this->reduce($url)));
+ }
+
+ if (empty($media) && substr_compare($url, '.css', -4, 4) !== 0) {
+ if ($this->importDisabled) {
+ $props[] = array('raw', '/* import disabled */');
+ return true;
+ }
+
+ $realPath = $this->findImport($url);
+ if (!is_null($realPath)) {
+ $this->addParsedFile($realPath);
+
+ $parser = $this->makeParser($realPath);
+ $root = $parser->parse(file_get_contents($realPath));
+ $root->parent = $parentBlock;
+
+ // handle all the imports in the new file
+ $pi = pathinfo($realPath);
+ $this->mixImports($root, $pi['dirname'].'/');
+
+ // bring blocks from import into current block
+ foreach ($root->children as $childName => $child) {
+ if (isset($parentBlock->children[$childName])) {
+ $parentBlock->children[$childName] = array_merge(
+ $parentBlock->children[$childName],
+ $child);
+ } else {
+ $parentBlock->children[$childName] = $child;
+ }
+ }
+
+ // splice in the props
+ foreach ($root->props as $prop) {
+ // leave a reference to the file where it came from
+ if (isset($prop[-1]) && !is_array($prop[-1])) {
+ $prop[-1] = array($parser, $prop[-1]);
+ }
+ $props[] = $prop;
+ }
+
+ return true;
+ }
+ }
+
+ // fallback to regular css import
+ $props[] = array('raw', '@import url("'.$url.'")'.($media ? ' '.$media : '').';');
+ return false;
+ }
+
+ // import all imports mentioned in the block
+ protected function mixImports($block, $importDir = null) {
+ $oldImport = $this->importDir;
+ if ($importDir !== null) {
+ $this->importDir = array_merge((array)$importDir, (array)$this->importDir);
+ }
+
+ $props = array();
+ foreach ($block->props as $prop) {
+ if ($prop[0] == 'import') {
+ $this->mixImport($prop, $block, $props);
+ } else {
+ $props[] = $prop;
+ }
+ }
+ $block->props = $props;
+ $this->importDir = $oldImport;
+ }
+
+
+ /**
+ * Recursively compiles a block.
+ *
+ * A block is analogous to a CSS block in most cases. A single LESS document
+ * is encapsulated in a block when parsed, but it does not have parent tags
+ * so all of it's children appear on the root level when compiled.
+ *
+ * Blocks are made up of props and children.
+ *
+ * Props are property instructions, array tuples which describe an action
+ * to be taken, eg. write a property, set a variable, mixin a block.
+ *
+ * The children of a block are just all the blocks that are defined within.
+ * This is used to look up mixins when performing a mixin.
+ *
+ * Compiling the block involves pushing a fresh environment on the stack,
+ * and iterating through the props, compiling each one.
+ *
+ * See lessc::compileProp()
+ *
+ */
+ protected function compileBlock($block) {
+ switch ($block->type) {
+ case "root":
+ return $this->compileRoot($block);
+ case null:
+ return $this->compileCSSBlock($block);
+ case "media":
+ return $this->compileMedia($block);
+ case "directive":
+ $name = "@" . $block->name;
+ if (!empty($block->value)) {
+ $name .= " " . $this->compileValue($this->reduce($block->value));
+ }
+
+ return $this->compileNestedBlock($block, array($name));
+ default:
+ $this->throwError("unknown block type: $block->type\n");
+ }
+ }
+
+ protected function compileCSSBlock($block) {
+ $env = $this->pushEnv();
+
+ $selectors = $this->compileSelectors($block->tags);
+ $env->selectors = $this->multiplySelectors($selectors);
+ $out = $this->makeOutputBlock(null, $env->selectors);
+
+ $this->scope->children[] = $out;
+ $this->compileProps($block, $out);
+
+ $block->scope = $env; // mixins carry scope with them!
+ $this->popEnv();
+ }
+
+ protected function compileMedia($media) {
+ $env = $this->pushEnv($media);
+ $parentScope = $this->mediaParent($this->scope);
+
+ $query = $this->compileMediaQuery($this->multiplyMedia($env));
+
+ $this->scope = $this->makeOutputBlock($media->type, array($query));
+ $parentScope->children[] = $this->scope;
+
+ $this->compileProps($media, $this->scope);
+
+ if (count($this->scope->lines) > 0) {
+ $orphanSelelectors = $this->findClosestSelectors();
+ if (!is_null($orphanSelelectors)) {
+ $orphan = $this->makeOutputBlock(null, $orphanSelelectors);
+ $orphan->lines = $this->scope->lines;
+ array_unshift($this->scope->children, $orphan);
+ $this->scope->lines = array();
+ }
+ }
+
+ $this->scope = $this->scope->parent;
+ $this->popEnv();
+ }
+
+ protected function mediaParent($scope) {
+ while (!empty($scope->parent)) {
+ if (!empty($scope->type) && $scope->type != "media") {
+ break;
+ }
+ $scope = $scope->parent;
+ }
+
+ return $scope;
+ }
+
+ protected function compileNestedBlock($block, $selectors) {
+ $this->pushEnv($block);
+ $this->scope = $this->makeOutputBlock($block->type, $selectors);
+ $this->scope->parent->children[] = $this->scope;
+
+ $this->compileProps($block, $this->scope);
+
+ $this->scope = $this->scope->parent;
+ $this->popEnv();
+ }
+
+ protected function compileRoot($root) {
+ $this->pushEnv();
+ $this->scope = $this->makeOutputBlock($root->type);
+ $this->compileProps($root, $this->scope);
+ $this->popEnv();
+ }
+
+ protected function compileProps($block, $out) {
+ $this->mixImports($block);
+ foreach ($this->sortProps($block->props) as $prop) {
+ $this->compileProp($prop, $block, $out);
+ }
+ }
+
+ protected function sortProps($props) {
+ $vars = array();
+ $other = array();
+
+ foreach ($props as $prop) {
+ if ($prop[0] == "assign" &&
+ substr($prop[1], 0, 1) == $this->vPrefix) {
+ $vars[] = $prop;
+ } else {
+ $other[] = $prop;
+ }
+ }
+
+ return array_merge($vars, $other);
+ }
+
+ protected function compileMediaQuery($queries) {
+ $compiledQueries = array();
+ foreach ($queries as $query) {
+ $parts = array();
+ foreach ($query as $q) {
+ switch ($q[0]) {
+ case "mediaType":
+ $parts[] = implode(" ", array_slice($q, 1));
+ break;
+ case "mediaExp":
+ if (isset($q[2])) {
+ $parts[] = "($q[1]: " .
+ $this->compileValue($this->reduce($q[2])) . ")";
+ } else {
+ $parts[] = "($q[1])";
+ }
+ break;
+ }
+ }
+
+ if (count($parts) > 0) {
+ $compiledQueries[] = implode(" and ", $parts);
+ }
+ }
+
+ $out = "@media";
+ if (!empty($parts)) {
+ $out .= " " .
+ implode($this->formatter->selectorSeparator, $compiledQueries);
+ }
+ return $out;
+ }
+
+ protected function multiplyMedia($env, $childQueries = null) {
+ if (is_null($env) ||
+ !empty($env->block->type) && $env->block->type != "media")
+ {
+ return $childQueries;
+ }
+
+ // plain old block, skip
+ if (empty($env->block->type)) {
+ return $this->multiplyMedia($env->parent, $childQueries);
+ }
+
+ $out = array();
+ $queries = $env->block->queries;
+ if (is_null($childQueries)) {
+ $out = $queries;
+ } else {
+ foreach ($queries as $parent) {
+ foreach ($childQueries as $child) {
+ $out[] = array_merge($parent, $child);
+ }
+ }
+ }
+
+ return $this->multiplyMedia($env->parent, $out);
+ }
+
+ protected function expandParentSelectors(&$tag, $replace) {
+ $parts = explode("$&$", $tag);
+ $count = 0;
+ foreach ($parts as &$part) {
+ $part = str_replace($this->parentSelector, $replace, $part, $c);
+ $count += $c;
+ }
+ $tag = implode($this->parentSelector, $parts);
+ return $count;
+ }
+
+ protected function findClosestSelectors() {
+ $env = $this->env;
+ $selectors = null;
+ while ($env !== null) {
+ if (isset($env->selectors)) {
+ $selectors = $env->selectors;
+ break;
+ }
+ $env = $env->parent;
+ }
+
+ return $selectors;
+ }
+
+
+ // multiply $selectors against the nearest selectors in env
+ protected function multiplySelectors($selectors) {
+ // find parent selectors
+
+ $parentSelectors = $this->findClosestSelectors();
+ if (is_null($parentSelectors)) {
+ // kill parent reference in top level selector
+ foreach ($selectors as &$s) {
+ $this->expandParentSelectors($s, "");
+ }
+
+ return $selectors;
+ }
+
+ $out = array();
+ foreach ($parentSelectors as $parent) {
+ foreach ($selectors as $child) {
+ $count = $this->expandParentSelectors($child, $parent);
+
+ // don't prepend the parent tag if & was used
+ if ($count > 0) {
+ $out[] = trim($child);
+ } else {
+ $out[] = trim($parent . ' ' . $child);
+ }
+ }
+ }
+
+ return $out;
+ }
+
+ // reduces selector expressions
+ protected function compileSelectors($selectors) {
+ $out = array();
+
+ foreach ($selectors as $s) {
+ if (is_array($s)) {
+ list(, $value) = $s;
+ $out[] = $this->compileValue($this->reduce($value));
+ } else {
+ $out[] = $s;
+ }
+ }
+
+ return $out;
+ }
+
+ protected function eq($left, $right) {
+ return $left == $right;
+ }
+
+ protected function patternMatch($block, $callingArgs) {
+ // match the guards if it has them
+ // any one of the groups must have all its guards pass for a match
+ if (!empty($block->guards)) {
+ $groupPassed = false;
+ foreach ($block->guards as $guardGroup) {
+ foreach ($guardGroup as $guard) {
+ $this->pushEnv();
+ $this->zipSetArgs($block->args, $callingArgs);
+
+ $negate = false;
+ if ($guard[0] == "negate") {
+ $guard = $guard[1];
+ $negate = true;
+ }
+
+ $passed = $this->reduce($guard) == self::$TRUE;
+ if ($negate) $passed = !$passed;
+
+ $this->popEnv();
+
+ if ($passed) {
+ $groupPassed = true;
+ } else {
+ $groupPassed = false;
+ break;
+ }
+ }
+
+ if ($groupPassed) break;
+ }
+
+ if (!$groupPassed) {
+ return false;
+ }
+ }
+
+ $numCalling = count($callingArgs);
+
+ if (empty($block->args)) {
+ return $block->isVararg || $numCalling == 0;
+ }
+
+ $i = -1; // no args
+ // try to match by arity or by argument literal
+ foreach ($block->args as $i => $arg) {
+ switch ($arg[0]) {
+ case "lit":
+ if (empty($callingArgs[$i]) || !$this->eq($arg[1], $callingArgs[$i])) {
+ return false;
+ }
+ break;
+ case "arg":
+ // no arg and no default value
+ if (!isset($callingArgs[$i]) && !isset($arg[2])) {
+ return false;
+ }
+ break;
+ case "rest":
+ $i--; // rest can be empty
+ break 2;
+ }
+ }
+
+ if ($block->isVararg) {
+ return true; // not having enough is handled above
+ } else {
+ $numMatched = $i + 1;
+ // greater than becuase default values always match
+ return $numMatched >= $numCalling;
+ }
+ }
+
+ protected function patternMatchAll($blocks, $callingArgs) {
+ $matches = null;
+ foreach ($blocks as $block) {
+ if ($this->patternMatch($block, $callingArgs)) {
+ $matches[] = $block;
+ }
+ }
+
+ return $matches;
+ }
+
+ // attempt to find blocks matched by path and args
+ protected function findBlocks($searchIn, $path, $args, $seen=array()) {
+ if ($searchIn == null) return null;
+ if (isset($seen[$searchIn->id])) return null;
+ $seen[$searchIn->id] = true;
+
+ $name = $path[0];
+
+ if (isset($searchIn->children[$name])) {
+ $blocks = $searchIn->children[$name];
+ if (count($path) == 1) {
+ $matches = $this->patternMatchAll($blocks, $args);
+ if (!empty($matches)) {
+ // This will return all blocks that match in the closest
+ // scope that has any matching block, like lessjs
+ return $matches;
+ }
+ } else {
+ $matches = array();
+ foreach ($blocks as $subBlock) {
+ $subMatches = $this->findBlocks($subBlock,
+ array_slice($path, 1), $args, $seen);
+
+ if (!is_null($subMatches)) {
+ foreach ($subMatches as $sm) {
+ $matches[] = $sm;
+ }
+ }
+ }
+
+ return count($matches) > 0 ? $matches : null;
+ }
+ }
+
+ if ($searchIn->parent === $searchIn) return null;
+ return $this->findBlocks($searchIn->parent, $path, $args, $seen);
+ }
+
+ // sets all argument names in $args to either the default value
+ // or the one passed in through $values
+ protected function zipSetArgs($args, $values) {
+ $i = 0;
+ $assignedValues = array();
+ foreach ($args as $a) {
+ if ($a[0] == "arg") {
+ if ($i < count($values) && !is_null($values[$i])) {
+ $value = $values[$i];
+ } elseif (isset($a[2])) {
+ $value = $a[2];
+ } else $value = null;
+
+ $value = $this->reduce($value);
+ $this->set($a[1], $value);
+ $assignedValues[] = $value;
+ }
+ $i++;
+ }
+
+ // check for a rest
+ $last = end($args);
+ if ($last[0] == "rest") {
+ $rest = array_slice($values, count($args) - 1);
+ $this->set($last[1], $this->reduce(array("list", " ", $rest)));
+ }
+
+ $this->env->arguments = $assignedValues;
+ }
+
+ // compile a prop and update $lines or $blocks appropriately
+ protected function compileProp($prop, $block, $out) {
+ // set error position context
+ if (isset($prop[-1])) {
+ if (is_array($prop[-1])) {
+ list($parser, $count) = $prop[-1];
+ $this->sourceParser = $parser;
+ $this->sourceLoc = $count;
+ } else {
+ $this->sourceParser = $this->parser;
+ $this->sourceLoc = $prop[-1];
+ }
+ } else {
+ $this->sourceLoc = -1;
+ }
+
+ switch ($prop[0]) {
+ case 'assign':
+ list(, $name, $value) = $prop;
+ if ($name[0] == $this->vPrefix) {
+ $this->set($name, $value);
+ } else {
+ $out->lines[] = $this->formatter->property($name,
+ $this->compileValue($this->reduce($value)));
+ }
+ break;
+ case 'block':
+ list(, $child) = $prop;
+ $this->compileBlock($child);
+ break;
+ case 'mixin':
+ list(, $path, $args, $suffix) = $prop;
+
+ $args = array_map(array($this, "reduce"), (array)$args);
+ $mixins = $this->findBlocks($block, $path, $args);
+ if ($mixins === null) {
+ // echo "failed to find block: ".implode(" > ", $path)."\n";
+ break; // throw error here??
+ }
+
+ foreach ($mixins as $mixin) {
+ $haveScope = false;
+ if (isset($mixin->parent->scope)) {
+ $haveScope = true;
+ $mixinParentEnv = $this->pushEnv();
+ $mixinParentEnv->storeParent = $mixin->parent->scope;
+ }
+
+ $haveArgs = false;
+ if (isset($mixin->args)) {
+ $haveArgs = true;
+ $this->pushEnv();
+ $this->zipSetArgs($mixin->args, $args);
+ }
+
+ $oldParent = $mixin->parent;
+ if ($mixin != $block) $mixin->parent = $block;
+
+ $this->mixImports($mixin);
+ foreach ($this->sortProps($mixin->props) as $subProp) {
+ if ($suffix !== null &&
+ $subProp[0] == "assign" &&
+ is_string($subProp[1]) &&
+ $subProp[1]{0} != $this->vPrefix)
+ {
+ $subProp[2] = array(
+ 'list', ' ',
+ array($subProp[2], array('keyword', $suffix))
+ );
+ }
+
+ $this->compileProp($subProp, $mixin, $out);
+ }
+
+ $mixin->parent = $oldParent;
+
+ if ($haveArgs) $this->popEnv();
+ if ($haveScope) $this->popEnv();
+ }
+
+ break;
+ case 'raw':
+ $out->lines[] = $prop[1];
+ break;
+ case "directive":
+ list(, $name, $value) = $prop;
+ $out->lines[] = "@$name " . $this->compileValue($this->reduce($value)).';';
+ break;
+ case "comment":
+ $out->lines[] = $prop[1];
+ break;
+ default:
+ $this->throwError("unknown op: {$prop[0]}\n");
+ }
+ }
+
+
+ /**
+ * Compiles a primitive value into a CSS property value.
+ *
+ * Values in lessphp are typed by being wrapped in arrays, their format is
+ * typically:
+ *
+ * array(type, contents [, additional_contents]*)
+ *
+ * The input is expected to be reduced. This function will not work on
+ * things like expressions and variables.
+ */
+ protected function compileValue($value) {
+ switch ($value[0]) {
+ case 'list':
+ // [1] - delimiter
+ // [2] - array of values
+ return implode($value[1], array_map(array($this, 'compileValue'), $value[2]));
+ case 'raw_color';
+ case 'keyword':
+ // [1] - the keyword
+ return $value[1];
+ case 'number':
+ list(, $num, $unit) = $value;
+ // [1] - the number
+ // [2] - the unit
+ if ($this->numberPrecision !== null) {
+ $num = round($num, $this->numberPrecision);
+ }
+ return $num . $unit;
+ case 'string':
+ // [1] - contents of string (includes quotes)
+ list(, $delim, $content) = $value;
+ foreach ($content as &$part) {
+ if (is_array($part)) {
+ $part = $this->compileValue($part);
+ }
+ }
+ return $delim . implode($content) . $delim;
+ case 'color':
+ // [1] - red component (either number or a %)
+ // [2] - green component
+ // [3] - blue component
+ // [4] - optional alpha component
+ list(, $r, $g, $b) = $value;
+ $r = round($r);
+ $g = round($g);
+ $b = round($b);
+
+ if (count($value) == 5 && $value[4] != 1) { // rgba
+ return 'rgba('.$r.','.$g.','.$b.','.$value[4].')';
+ }
+
+ $h = sprintf("#%02x%02x%02x", $r, $g, $b);
+
+ if (!empty($this->formatter->compressColors)) {
+ // Converting hex color to short notation (e.g. #003399 to #039)
+ if ($h[1] === $h[2] && $h[3] === $h[4] && $h[5] === $h[6]) {
+ $h = '#' . $h[1] . $h[3] . $h[5];
+ }
+ }
+
+ return $h;
+
+ case 'function':
+ list(, $name, $args) = $value;
+ return $name.'('.$this->compileValue($args).')';
+ default: // assumed to be unit
+ $this->throwError("unknown value type: $value[0]");
+ }
+ }
+
+ protected function lib_isnumber($value) {
+ return $this->toBool($value[0] == "number");
+ }
+
+ protected function lib_isstring($value) {
+ return $this->toBool($value[0] == "string");
+ }
+
+ protected function lib_iscolor($value) {
+ return $this->toBool($this->coerceColor($value));
+ }
+
+ protected function lib_iskeyword($value) {
+ return $this->toBool($value[0] == "keyword");
+ }
+
+ protected function lib_ispixel($value) {
+ return $this->toBool($value[0] == "number" && $value[2] == "px");
+ }
+
+ protected function lib_ispercentage($value) {
+ return $this->toBool($value[0] == "number" && $value[2] == "%");
+ }
+
+ protected function lib_isem($value) {
+ return $this->toBool($value[0] == "number" && $value[2] == "em");
+ }
+
+ protected function lib_rgbahex($color) {
+ $color = $this->coerceColor($color);
+ if (is_null($color))
+ $this->throwError("color expected for rgbahex");
+
+ return sprintf("#%02x%02x%02x%02x",
+ isset($color[4]) ? $color[4]*255 : 0,
+ $color[1],$color[2], $color[3]);
+ }
+
+ protected function lib_argb($color){
+ return $this->lib_rgbahex($color);
+ }
+
+ // utility func to unquote a string
+ protected function lib_e($arg) {
+ switch ($arg[0]) {
+ case "list":
+ $items = $arg[2];
+ if (isset($items[0])) {
+ return $this->lib_e($items[0]);
+ }
+ return self::$defaultValue;
+ case "string":
+ $arg[1] = "";
+ return $arg;
+ case "keyword":
+ return $arg;
+ default:
+ return array("keyword", $this->compileValue($arg));
+ }
+ }
+
+ protected function lib__sprintf($args) {
+ if ($args[0] != "list") return $args;
+ $values = $args[2];
+ $string = array_shift($values);
+ $template = $this->compileValue($this->lib_e($string));
+
+ $i = 0;
+ if (preg_match_all('/%[dsa]/', $template, $m)) {
+ foreach ($m[0] as $match) {
+ $val = isset($values[$i]) ?
+ $this->reduce($values[$i]) : array('keyword', '');
+
+ // lessjs compat, renders fully expanded color, not raw color
+ if ($color = $this->coerceColor($val)) {
+ $val = $color;
+ }
+
+ $i++;
+ $rep = $this->compileValue($this->lib_e($val));
+ $template = preg_replace('/'.self::preg_quote($match).'/',
+ $rep, $template, 1);
+ }
+ }
+
+ $d = $string[0] == "string" ? $string[1] : '"';
+ return array("string", $d, array($template));
+ }
+
+ protected function lib_floor($arg) {
+ $value = $this->assertNumber($arg);
+ return array("number", floor($value), $arg[2]);
+ }
+
+ protected function lib_ceil($arg) {
+ $value = $this->assertNumber($arg);
+ return array("number", ceil($value), $arg[2]);
+ }
+
+ protected function lib_round($arg) {
+ $value = $this->assertNumber($arg);
+ return array("number", round($value), $arg[2]);
+ }
+
+ /**
+ * Helper function to get arguments for color manipulation functions.
+ * takes a list that contains a color like thing and a percentage
+ */
+ protected function colorArgs($args) {
+ if ($args[0] != 'list' || count($args[2]) < 2) {
+ return array(array('color', 0, 0, 0), 0);
+ }
+ list($color, $delta) = $args[2];
+ $color = $this->assertColor($color);
+ $delta = floatval($delta[1]);
+
+ return array($color, $delta);
+ }
+
+ protected function lib_darken($args) {
+ list($color, $delta) = $this->colorArgs($args);
+
+ $hsl = $this->toHSL($color);
+ $hsl[3] = $this->clamp($hsl[3] - $delta, 100);
+ return $this->toRGB($hsl);
+ }
+
+ protected function lib_lighten($args) {
+ list($color, $delta) = $this->colorArgs($args);
+
+ $hsl = $this->toHSL($color);
+ $hsl[3] = $this->clamp($hsl[3] + $delta, 100);
+ return $this->toRGB($hsl);
+ }
+
+ protected function lib_saturate($args) {
+ list($color, $delta) = $this->colorArgs($args);
+
+ $hsl = $this->toHSL($color);
+ $hsl[2] = $this->clamp($hsl[2] + $delta, 100);
+ return $this->toRGB($hsl);
+ }
+
+ protected function lib_desaturate($args) {
+ list($color, $delta) = $this->colorArgs($args);
+
+ $hsl = $this->toHSL($color);
+ $hsl[2] = $this->clamp($hsl[2] - $delta, 100);
+ return $this->toRGB($hsl);
+ }
+
+ protected function lib_spin($args) {
+ list($color, $delta) = $this->colorArgs($args);
+
+ $hsl = $this->toHSL($color);
+
+ $hsl[1] = $hsl[1] + $delta % 360;
+ if ($hsl[1] < 0) $hsl[1] += 360;
+
+ return $this->toRGB($hsl);
+ }
+
+ protected function lib_fadeout($args) {
+ list($color, $delta) = $this->colorArgs($args);
+ $color[4] = $this->clamp((isset($color[4]) ? $color[4] : 1) - $delta/100);
+ return $color;
+ }
+
+ protected function lib_fadein($args) {
+ list($color, $delta) = $this->colorArgs($args);
+ $color[4] = $this->clamp((isset($color[4]) ? $color[4] : 1) + $delta/100);
+ return $color;
+ }
+
+ protected function lib_hue($color) {
+ $hsl = $this->toHSL($this->assertColor($color));
+ return round($hsl[1]);
+ }
+
+ protected function lib_saturation($color) {
+ $hsl = $this->toHSL($this->assertColor($color));
+ return round($hsl[2]);
+ }
+
+ protected function lib_lightness($color) {
+ $hsl = $this->toHSL($this->assertColor($color));
+ return round($hsl[3]);
+ }
+
+ // get the alpha of a color
+ // defaults to 1 for non-colors or colors without an alpha
+ protected function lib_alpha($value) {
+ if (!is_null($color = $this->coerceColor($value))) {
+ return isset($color[4]) ? $color[4] : 1;
+ }
+ }
+
+ // set the alpha of the color
+ protected function lib_fade($args) {
+ list($color, $alpha) = $this->colorArgs($args);
+ $color[4] = $this->clamp($alpha / 100.0);
+ return $color;
+ }
+
+ protected function lib_percentage($arg) {
+ $num = $this->assertNumber($arg);
+ return array("number", $num*100, "%");
+ }
+
+ // mixes two colors by weight
+ // mix(@color1, @color2, @weight);
+ // http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#mix-instance_method
+ protected function lib_mix($args) {
+ if ($args[0] != "list" || count($args[2]) < 3)
+ $this->throwError("mix expects (color1, color2, weight)");
+
+ list($first, $second, $weight) = $args[2];
+ $first = $this->assertColor($first);
+ $second = $this->assertColor($second);
+
+ $first_a = $this->lib_alpha($first);
+ $second_a = $this->lib_alpha($second);
+ $weight = $weight[1] / 100.0;
+
+ $w = $weight * 2 - 1;
+ $a = $first_a - $second_a;
+
+ $w1 = (($w * $a == -1 ? $w : ($w + $a)/(1 + $w * $a)) + 1) / 2.0;
+ $w2 = 1.0 - $w1;
+
+ $new = array('color',
+ $w1 * $first[1] + $w2 * $second[1],
+ $w1 * $first[2] + $w2 * $second[2],
+ $w1 * $first[3] + $w2 * $second[3],
+ );
+
+ if ($first_a != 1.0 || $second_a != 1.0) {
+ $new[] = $first_a * $weight + $second_a * ($weight - 1);
+ }
+
+ return $this->fixColor($new);
+ }
+
+ protected function assertColor($value, $error = "expected color value") {
+ $color = $this->coerceColor($value);
+ if (is_null($color)) $this->throwError($error);
+ return $color;
+ }
+
+ protected function assertNumber($value, $error = "expecting number") {
+ if ($value[0] == "number") return $value[1];
+ $this->throwError($error);
+ }
+
+ protected function toHSL($color) {
+ if ($color[0] == 'hsl') return $color;
+
+ $r = $color[1] / 255;
+ $g = $color[2] / 255;
+ $b = $color[3] / 255;
+
+ $min = min($r, $g, $b);
+ $max = max($r, $g, $b);
+
+ $L = ($min + $max) / 2;
+ if ($min == $max) {
+ $S = $H = 0;
+ } else {
+ if ($L < 0.5)
+ $S = ($max - $min)/($max + $min);
+ else
+ $S = ($max - $min)/(2.0 - $max - $min);
+
+ if ($r == $max) $H = ($g - $b)/($max - $min);
+ elseif ($g == $max) $H = 2.0 + ($b - $r)/($max - $min);
+ elseif ($b == $max) $H = 4.0 + ($r - $g)/($max - $min);
+
+ }
+
+ $out = array('hsl',
+ ($H < 0 ? $H + 6 : $H)*60,
+ $S*100,
+ $L*100,
+ );
+
+ if (count($color) > 4) $out[] = $color[4]; // copy alpha
+ return $out;
+ }
+
+ protected function toRGB_helper($comp, $temp1, $temp2) {
+ if ($comp < 0) $comp += 1.0;
+ elseif ($comp > 1) $comp -= 1.0;
+
+ if (6 * $comp < 1) return $temp1 + ($temp2 - $temp1) * 6 * $comp;
+ if (2 * $comp < 1) return $temp2;
+ if (3 * $comp < 2) return $temp1 + ($temp2 - $temp1)*((2/3) - $comp) * 6;
+
+ return $temp1;
+ }
+
+ /**
+ * Converts a hsl array into a color value in rgb.
+ * Expects H to be in range of 0 to 360, S and L in 0 to 100
+ */
+ protected function toRGB($color) {
+ if ($color == 'color') return $color;
+
+ $H = $color[1] / 360;
+ $S = $color[2] / 100;
+ $L = $color[3] / 100;
+
+ if ($S == 0) {
+ $r = $g = $b = $L;
+ } else {
+ $temp2 = $L < 0.5 ?
+ $L*(1.0 + $S) :
+ $L + $S - $L * $S;
+
+ $temp1 = 2.0 * $L - $temp2;
+
+ $r = $this->toRGB_helper($H + 1/3, $temp1, $temp2);
+ $g = $this->toRGB_helper($H, $temp1, $temp2);
+ $b = $this->toRGB_helper($H - 1/3, $temp1, $temp2);
+ }
+
+ // $out = array('color', round($r*255), round($g*255), round($b*255));
+ $out = array('color', $r*255, $g*255, $b*255);
+ if (count($color) > 4) $out[] = $color[4]; // copy alpha
+ return $out;
+ }
+
+ protected function clamp($v, $max = 1, $min = 0) {
+ return min($max, max($min, $v));
+ }
+
+ /**
+ * Convert the rgb, rgba, hsl color literals of function type
+ * as returned by the parser into values of color type.
+ */
+ protected function funcToColor($func) {
+ $fname = $func[1];
+ if ($func[2][0] != 'list') return false; // need a list of arguments
+ $rawComponents = $func[2][2];
+
+ if ($fname == 'hsl' || $fname == 'hsla') {
+ $hsl = array('hsl');
+ $i = 0;
+ foreach ($rawComponents as $c) {
+ $val = $this->reduce($c);
+ $val = isset($val[1]) ? floatval($val[1]) : 0;
+
+ if ($i == 0) $clamp = 360;
+ elseif ($i < 3) $clamp = 100;
+ else $clamp = 1;
+
+ $hsl[] = $this->clamp($val, $clamp);
+ $i++;
+ }
+
+ while (count($hsl) < 4) $hsl[] = 0;
+ return $this->toRGB($hsl);
+
+ } elseif ($fname == 'rgb' || $fname == 'rgba') {
+ $components = array();
+ $i = 1;
+ foreach ($rawComponents as $c) {
+ $c = $this->reduce($c);
+ if ($i < 4) {
+ if ($c[0] == "number" && $c[2] == "%") {
+ $components[] = 255 * ($c[1] / 100);
+ } else {
+ $components[] = floatval($c[1]);
+ }
+ } elseif ($i == 4) {
+ if ($c[0] == "number" && $c[2] == "%") {
+ $components[] = 1.0 * ($c[1] / 100);
+ } else {
+ $components[] = floatval($c[1]);
+ }
+ } else break;
+
+ $i++;
+ }
+ while (count($components) < 3) $components[] = 0;
+ array_unshift($components, 'color');
+ return $this->fixColor($components);
+ }
+
+ return false;
+ }
+
+ protected function reduce($value) {
+ switch ($value[0]) {
+ case "variable":
+ $key = $value[1];
+ if (is_array($key)) {
+ $key = $this->reduce($key);
+ $key = $this->vPrefix . $this->compileValue($this->lib_e($key));
+ }
+
+ $seen =& $this->env->seenNames;
+
+ if (!empty($seen[$key])) {
+ $this->throwError("infinite loop detected: $key");
+ }
+
+ $seen[$key] = true;
+ $out = $this->reduce($this->get($key, self::$defaultValue));
+ $seen[$key] = false;
+ return $out;
+ case "list":
+ foreach ($value[2] as &$item) {
+ $item = $this->reduce($item);
+ }
+ return $value;
+ case "expression":
+ return $this->evaluate($value);
+ case "string":
+ foreach ($value[2] as &$part) {
+ if (is_array($part)) {
+ $strip = $part[0] == "variable";
+ $part = $this->reduce($part);
+ if ($strip) $part = $this->lib_e($part);
+ }
+ }
+ return $value;
+ case "escape":
+ list(,$inner) = $value;
+ return $this->lib_e($this->reduce($inner));
+ case "function":
+ $color = $this->funcToColor($value);
+ if ($color) return $color;
+
+ list(, $name, $args) = $value;
+ if ($name == "%") $name = "_sprintf";
+ $f = isset($this->libFunctions[$name]) ?
+ $this->libFunctions[$name] : array($this, 'lib_'.$name);
+
+ if (is_callable($f)) {
+ if ($args[0] == 'list')
+ $args = self::compressList($args[2], $args[1]);
+
+ $ret = call_user_func($f, $this->reduce($args), $this);
+
+ if (is_null($ret)) {
+ return array("string", "", array(
+ $name, "(", $args, ")"
+ ));
+ }
+
+ // convert to a typed value if the result is a php primitive
+ if (is_numeric($ret)) $ret = array('number', $ret, "");
+ elseif (!is_array($ret)) $ret = array('keyword', $ret);
+
+ return $ret;
+ }
+
+ // plain function, reduce args
+ $value[2] = $this->reduce($value[2]);
+ return $value;
+ case "unary":
+ list(, $op, $exp) = $value;
+ $exp = $this->reduce($exp);
+
+ if ($exp[0] == "number") {
+ switch ($op) {
+ case "+":
+ return $exp;
+ case "-":
+ $exp[1] *= -1;
+ return $exp;
+ }
+ }
+ return array("string", "", array($op, $exp));
+ default:
+ return $value;
+ }
+ }
+
+
+ // coerce a value for use in color operation
+ protected function coerceColor($value) {
+ switch($value[0]) {
+ case 'color': return $value;
+ case 'raw_color':
+ $c = array("color", 0, 0, 0);
+ $colorStr = substr($value[1], 1);
+ $num = hexdec($colorStr);
+ $width = strlen($colorStr) == 3 ? 16 : 256;
+
+ for ($i = 3; $i > 0; $i--) { // 3 2 1
+ $t = $num % $width;
+ $num /= $width;
+
+ $c[$i] = $t * (256/$width) + $t * floor(16/$width);
+ }
+
+ return $c;
+ case 'keyword':
+ $name = $value[1];
+ if (isset(self::$cssColors[$name])) {
+ list($r, $g, $b) = explode(',', self::$cssColors[$name]);
+ return array('color', $r, $g, $b);
+ }
+ return null;
+ }
+ }
+
+ // make something string like into a string
+ protected function coerceString($value) {
+ switch ($value[0]) {
+ case "string":
+ return $value;
+ case "keyword":
+ return array("string", "", array($value[1]));
+ }
+ return null;
+ }
+
+ protected function toBool($a) {
+ if ($a) return self::$TRUE;
+ else return self::$FALSE;
+ }
+
+ // evaluate an expression
+ protected function evaluate($exp) {
+ list(, $op, $left, $right, $whiteBefore, $whiteAfter) = $exp;
+
+ $left = $this->reduce($left);
+ $right = $this->reduce($right);
+
+ if ($leftColor = $this->coerceColor($left)) {
+ $left = $leftColor;
+ }
+
+ if ($rightColor = $this->coerceColor($right)) {
+ $right = $rightColor;
+ }
+
+ $ltype = $left[0];
+ $rtype = $right[0];
+
+ // operators that work on all types
+ if ($op == "and") {
+ return $this->toBool($left == self::$TRUE && $right == self::$TRUE);
+ }
+
+ if ($op == "=") {
+ return $this->toBool($this->eq($left, $right) );
+ }
+
+ if ($op == "+" && !is_null($str = $this->stringConcatenate($left, $right))) {
+ return $str;
+ }
+
+ // type based operators
+ $fname = "op_${ltype}_${rtype}";
+ if (is_callable(array($this, $fname))) {
+ $out = $this->$fname($op, $left, $right);
+ if (!is_null($out)) return $out;
+ }
+
+ // make the expression look it did before being parsed
+ $paddedOp = $op;
+ if ($whiteBefore) $paddedOp = " " . $paddedOp;
+ if ($whiteAfter) $paddedOp .= " ";
+
+ return array("string", "", array($left, $paddedOp, $right));
+ }
+
+ protected function stringConcatenate($left, $right) {
+ if ($strLeft = $this->coerceString($left)) {
+ if ($right[0] == "string") {
+ $right[1] = "";
+ }
+ $strLeft[2][] = $right;
+ return $strLeft;
+ }
+
+ if ($strRight = $this->coerceString($right)) {
+ array_unshift($strRight[2], $left);
+ return $strRight;
+ }
+ }
+
+
+ // make sure a color's components don't go out of bounds
+ protected function fixColor($c) {
+ foreach (range(1, 3) as $i) {
+ if ($c[$i] < 0) $c[$i] = 0;
+ if ($c[$i] > 255) $c[$i] = 255;
+ }
+
+ return $c;
+ }
+
+ protected function op_number_color($op, $lft, $rgt) {
+ if ($op == '+' || $op == '*') {
+ return $this->op_color_number($op, $rgt, $lft);
+ }
+ }
+
+ protected function op_color_number($op, $lft, $rgt) {
+ if ($rgt[0] == '%') $rgt[1] /= 100;
+
+ return $this->op_color_color($op, $lft,
+ array_fill(1, count($lft) - 1, $rgt[1]));
+ }
+
+ protected function op_color_color($op, $left, $right) {
+ $out = array('color');
+ $max = count($left) > count($right) ? count($left) : count($right);
+ foreach (range(1, $max - 1) as $i) {
+ $lval = isset($left[$i]) ? $left[$i] : 0;
+ $rval = isset($right[$i]) ? $right[$i] : 0;
+ switch ($op) {
+ case '+':
+ $out[] = $lval + $rval;
+ break;
+ case '-':
+ $out[] = $lval - $rval;
+ break;
+ case '*':
+ $out[] = $lval * $rval;
+ break;
+ case '%':
+ $out[] = $lval % $rval;
+ break;
+ case '/':
+ if ($rval == 0) $this->throwError("evaluate error: can't divide by zero");
+ $out[] = $lval / $rval;
+ break;
+ default:
+ $this->throwError('evaluate error: color op number failed on op '.$op);
+ }
+ }
+ return $this->fixColor($out);
+ }
+
+ // operator on two numbers
+ protected function op_number_number($op, $left, $right) {
+ $unit = empty($left[2]) ? $right[2] : $left[2];
+
+ $value = 0;
+ switch ($op) {
+ case '+':
+ $value = $left[1] + $right[1];
+ break;
+ case '*':
+ $value = $left[1] * $right[1];
+ break;
+ case '-':
+ $value = $left[1] - $right[1];
+ break;
+ case '%':
+ $value = $left[1] % $right[1];
+ break;
+ case '/':
+ if ($right[1] == 0) $this->throwError('parse error: divide by zero');
+ $value = $left[1] / $right[1];
+ break;
+ case '<':
+ return $this->toBool($left[1] < $right[1]);
+ case '>':
+ return $this->toBool($left[1] > $right[1]);
+ case '>=':
+ return $this->toBool($left[1] >= $right[1]);
+ case '=<':
+ return $this->toBool($left[1] <= $right[1]);
+ default:
+ $this->throwError('parse error: unknown number operator: '.$op);
+ }
+
+ return array("number", $value, $unit);
+ }
+
+
+ /* environment functions */
+
+ protected function makeOutputBlock($type, $selectors = null) {
+ $b = new stdclass;
+ $b->lines = array();
+ $b->children = array();
+ $b->selectors = $selectors;
+ $b->type = $type;
+ $b->parent = $this->scope;
+ return $b;
+ }
+
+ // the state of execution
+ protected function pushEnv($block = null) {
+ $e = new stdclass;
+ $e->parent = $this->env;
+ $e->store = array();
+ $e->block = $block;
+
+ $this->env = $e;
+ return $e;
+ }
+
+ // pop something off the stack
+ protected function popEnv() {
+ $old = $this->env;
+ $this->env = $this->env->parent;
+ return $old;
+ }
+
+ // set something in the current env
+ protected function set($name, $value) {
+ $this->env->store[$name] = $value;
+ }
+
+
+ // get the highest occurrence entry for a name
+ protected function get($name, $default=null) {
+ $current = $this->env;
+
+ $isArguments = $name == $this->vPrefix . 'arguments';
+ while ($current) {
+ if ($isArguments && isset($current->arguments)) {
+ return array('list', ' ', $current->arguments);
+ }
+
+ if (isset($current->store[$name]))
+ return $current->store[$name];
+ else {
+ $current = isset($current->storeParent) ?
+ $current->storeParent : $current->parent;
+ }
+ }
+
+ return $default;
+ }
+
+ // inject array of unparsed strings into environment as variables
+ protected function injectVariables($args) {
+ $this->pushEnv();
+ $parser = new lessc_parser($this, __METHOD__);
+ foreach ($args as $name => $strValue) {
+ if ($name{0} != '@') $name = '@'.$name;
+ $parser->count = 0;
+ $parser->buffer = (string)$strValue;
+ if (!$parser->propertyValue($value)) {
+ throw new Exception("failed to parse passed in variable $name: $strValue");
+ }
+
+ $this->set($name, $value);
+ }
+ }
+
+ /**
+ * Initialize any static state, can initialize parser for a file
+ * $opts isn't used yet
+ */
+ public function __construct($fname = null) {
+ if ($fname !== null) {
+ // used for deprecated parse method
+ $this->_parseFile = $fname;
+ }
+ }
+
+ public function compile($string, $name = null) {
+ $locale = setlocale(LC_NUMERIC, 0);
+ setlocale(LC_NUMERIC, "C");
+
+ $this->parser = $this->makeParser($name);
+ $root = $this->parser->parse($string);
+
+ $this->env = null;
+ $this->scope = null;
+
+ $this->formatter = $this->newFormatter();
+
+ if (!empty($this->registeredVars)) {
+ $this->injectVariables($this->registeredVars);
+ }
+
+ $this->compileBlock($root);
+
+ ob_start();
+ $this->formatter->block($this->scope);
+ $out = ob_get_clean();
+ setlocale(LC_NUMERIC, $locale);
+ return $out;
+ }
+
+ public function compileFile($fname, $outFname = null) {
+ if (!is_readable($fname)) {
+ throw new Exception('load error: failed to find '.$fname);
+ }
+
+ $pi = pathinfo($fname);
+
+ $oldImport = $this->importDir;
+
+ $this->importDir = (array)$this->importDir;
+ $this->importDir[] = $pi['dirname'].'/';
+
+ $this->allParsedFiles = array();
+ $this->addParsedFile($fname);
+
+ $out = $this->compile(file_get_contents($fname), $fname);
+
+ $this->importDir = $oldImport;
+
+ if ($outFname !== null) {
+ return file_put_contents($outFname, $out);
+ }
+
+ return $out;
+ }
+
+ // compile only if changed input has changed or output doesn't exist
+ public function checkedCompile($in, $out) {
+ if (!is_file($out) || filemtime($in) > filemtime($out)) {
+ $this->compileFile($in, $out);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Execute lessphp on a .less file or a lessphp cache structure
+ *
+ * The lessphp cache structure contains information about a specific
+ * less file having been parsed. It can be used as a hint for future
+ * calls to determine whether or not a rebuild is required.
+ *
+ * The cache structure contains two important keys that may be used
+ * externally:
+ *
+ * compiled: The final compiled CSS
+ * updated: The time (in seconds) the CSS was last compiled
+ *
+ * The cache structure is a plain-ol' PHP associative array and can
+ * be serialized and unserialized without a hitch.
+ *
+ * @param mixed $in Input
+ * @param bool $force Force rebuild?
+ * @return array lessphp cache structure
+ */
+ public function cachedCompile($in, $force = false) {
+ // assume no root
+ $root = null;
+
+ if (is_string($in)) {
+ $root = $in;
+ } elseif (is_array($in) and isset($in['root'])) {
+ if ($force or ! isset($in['files'])) {
+ // If we are forcing a recompile or if for some reason the
+ // structure does not contain any file information we should
+ // specify the root to trigger a rebuild.
+ $root = $in['root'];
+ } elseif (isset($in['files']) and is_array($in['files'])) {
+ foreach ($in['files'] as $fname => $ftime ) {
+ if (!file_exists($fname) or filemtime($fname) > $ftime) {
+ // One of the files we knew about previously has changed
+ // so we should look at our incoming root again.
+ $root = $in['root'];
+ break;
+ }
+ }
+ }
+ } else {
+ // TODO: Throw an exception? We got neither a string nor something
+ // that looks like a compatible lessphp cache structure.
+ return null;
+ }
+
+ if ($root !== null) {
+ // If we have a root value which means we should rebuild.
+ $out = array();
+ $out['root'] = $root;
+ $out['compiled'] = $this->compileFile($root);
+ $out['files'] = $this->allParsedFiles();
+ $out['updated'] = time();
+ return $out;
+ } else {
+ // No changes, pass back the structure
+ // we were given initially.
+ return $in;
+ }
+
+ }
+
+ // parse and compile buffer
+ // This is deprecated
+ public function parse($str = null, $initialVariables = null) {
+ if (is_array($str)) {
+ $initialVariables = $str;
+ $str = null;
+ }
+
+ $oldVars = $this->registeredVars;
+ if ($initialVariables !== null) {
+ $this->setVariables($initialVariables);
+ }
+
+ if ($str == null) {
+ if (empty($this->_parseFile)) {
+ throw new exception("nothing to parse");
+ }
+
+ $out = $this->compileFile($this->_parseFile);
+ } else {
+ $out = $this->compile($str);
+ }
+
+ $this->registeredVars = $oldVars;
+ return $out;
+ }
+
+ protected function makeParser($name) {
+ $parser = new lessc_parser($this, $name);
+ $parser->writeComments = $this->preserveComments;
+
+ return $parser;
+ }
+
+ public function setFormatter($name) {
+ $this->formatterName = $name;
+ }
+
+ protected function newFormatter() {
+ $className = "lessc_formatter_lessjs";
+ if (!empty($this->formatterName)) {
+ if (!is_string($this->formatterName))
+ return $this->formatterName;
+ $className = "lessc_formatter_$this->formatterName";
+ }
+
+ return new $className;
+ }
+
+ public function setPreserveComments($preserve) {
+ $this->preserveComments = $preserve;
+ }
+
+ public function registerFunction($name, $func) {
+ $this->libFunctions[$name] = $func;
+ }
+
+ public function unregisterFunction($name) {
+ unset($this->libFunctions[$name]);
+ }
+
+ public function setVariables($variables) {
+ $this->registeredVars = array_merge($this->registeredVars, $variables);
+ }
+
+ public function unsetVariable($name) {
+ unset($this->registeredVars[name]);
+ }
+
+ public function allParsedFiles() {
+ return $this->allParsedFiles;
+ }
+
+ protected function addParsedFile($file) {
+ $this->allParsedFiles[realpath($file)] = filemtime($file);
+ }
+
+ /**
+ * Uses the current value of $this->count to show line and line number
+ */
+ protected function throwError($msg = null) {
+ if ($this->sourceLoc >= 0) {
+ $this->sourceParser->throwError($msg, $this->sourceLoc);
+ }
+ throw new exception($msg);
+ }
+
+ // compile file $in to file $out if $in is newer than $out
+ // returns true when it compiles, false otherwise
+ public static function ccompile($in, $out, $less = null) {
+ if ($less === null) {
+ $less = new self;
+ }
+ return $less->checkedCompile($in, $out);
+ }
+
+ public static function cexecute($in, $force = false, $less = null) {
+ if ($less === null) {
+ $less = new self;
+ }
+ return $less->cachedCompile($in, $force);
+ }
+
+ static protected $cssColors = array(
+ 'aliceblue' => '240,248,255',
+ 'antiquewhite' => '250,235,215',
+ 'aqua' => '0,255,255',
+ 'aquamarine' => '127,255,212',
+ 'azure' => '240,255,255',
+ 'beige' => '245,245,220',
+ 'bisque' => '255,228,196',
+ 'black' => '0,0,0',
+ 'blanchedalmond' => '255,235,205',
+ 'blue' => '0,0,255',
+ 'blueviolet' => '138,43,226',
+ 'brown' => '165,42,42',
+ 'burlywood' => '222,184,135',
+ 'cadetblue' => '95,158,160',
+ 'chartreuse' => '127,255,0',
+ 'chocolate' => '210,105,30',
+ 'coral' => '255,127,80',
+ 'cornflowerblue' => '100,149,237',
+ 'cornsilk' => '255,248,220',
+ 'crimson' => '220,20,60',
+ 'cyan' => '0,255,255',
+ 'darkblue' => '0,0,139',
+ 'darkcyan' => '0,139,139',
+ 'darkgoldenrod' => '184,134,11',
+ 'darkgray' => '169,169,169',
+ 'darkgreen' => '0,100,0',
+ 'darkgrey' => '169,169,169',
+ 'darkkhaki' => '189,183,107',
+ 'darkmagenta' => '139,0,139',
+ 'darkolivegreen' => '85,107,47',
+ 'darkorange' => '255,140,0',
+ 'darkorchid' => '153,50,204',
+ 'darkred' => '139,0,0',
+ 'darksalmon' => '233,150,122',
+ 'darkseagreen' => '143,188,143',
+ 'darkslateblue' => '72,61,139',
+ 'darkslategray' => '47,79,79',
+ 'darkslategrey' => '47,79,79',
+ 'darkturquoise' => '0,206,209',
+ 'darkviolet' => '148,0,211',
+ 'deeppink' => '255,20,147',
+ 'deepskyblue' => '0,191,255',
+ 'dimgray' => '105,105,105',
+ 'dimgrey' => '105,105,105',
+ 'dodgerblue' => '30,144,255',
+ 'firebrick' => '178,34,34',
+ 'floralwhite' => '255,250,240',
+ 'forestgreen' => '34,139,34',
+ 'fuchsia' => '255,0,255',
+ 'gainsboro' => '220,220,220',
+ 'ghostwhite' => '248,248,255',
+ 'gold' => '255,215,0',
+ 'goldenrod' => '218,165,32',
+ 'gray' => '128,128,128',
+ 'green' => '0,128,0',
+ 'greenyellow' => '173,255,47',
+ 'grey' => '128,128,128',
+ 'honeydew' => '240,255,240',
+ 'hotpink' => '255,105,180',
+ 'indianred' => '205,92,92',
+ 'indigo' => '75,0,130',
+ 'ivory' => '255,255,240',
+ 'khaki' => '240,230,140',
+ 'lavender' => '230,230,250',
+ 'lavenderblush' => '255,240,245',
+ 'lawngreen' => '124,252,0',
+ 'lemonchiffon' => '255,250,205',
+ 'lightblue' => '173,216,230',
+ 'lightcoral' => '240,128,128',
+ 'lightcyan' => '224,255,255',
+ 'lightgoldenrodyellow' => '250,250,210',
+ 'lightgray' => '211,211,211',
+ 'lightgreen' => '144,238,144',
+ 'lightgrey' => '211,211,211',
+ 'lightpink' => '255,182,193',
+ 'lightsalmon' => '255,160,122',
+ 'lightseagreen' => '32,178,170',
+ 'lightskyblue' => '135,206,250',
+ 'lightslategray' => '119,136,153',
+ 'lightslategrey' => '119,136,153',
+ 'lightsteelblue' => '176,196,222',
+ 'lightyellow' => '255,255,224',
+ 'lime' => '0,255,0',
+ 'limegreen' => '50,205,50',
+ 'linen' => '250,240,230',
+ 'magenta' => '255,0,255',
+ 'maroon' => '128,0,0',
+ 'mediumaquamarine' => '102,205,170',
+ 'mediumblue' => '0,0,205',
+ 'mediumorchid' => '186,85,211',
+ 'mediumpurple' => '147,112,219',
+ 'mediumseagreen' => '60,179,113',
+ 'mediumslateblue' => '123,104,238',
+ 'mediumspringgreen' => '0,250,154',
+ 'mediumturquoise' => '72,209,204',
+ 'mediumvioletred' => '199,21,133',
+ 'midnightblue' => '25,25,112',
+ 'mintcream' => '245,255,250',
+ 'mistyrose' => '255,228,225',
+ 'moccasin' => '255,228,181',
+ 'navajowhite' => '255,222,173',
+ 'navy' => '0,0,128',
+ 'oldlace' => '253,245,230',
+ 'olive' => '128,128,0',
+ 'olivedrab' => '107,142,35',
+ 'orange' => '255,165,0',
+ 'orangered' => '255,69,0',
+ 'orchid' => '218,112,214',
+ 'palegoldenrod' => '238,232,170',
+ 'palegreen' => '152,251,152',
+ 'paleturquoise' => '175,238,238',
+ 'palevioletred' => '219,112,147',
+ 'papayawhip' => '255,239,213',
+ 'peachpuff' => '255,218,185',
+ 'peru' => '205,133,63',
+ 'pink' => '255,192,203',
+ 'plum' => '221,160,221',
+ 'powderblue' => '176,224,230',
+ 'purple' => '128,0,128',
+ 'red' => '255,0,0',
+ 'rosybrown' => '188,143,143',
+ 'royalblue' => '65,105,225',
+ 'saddlebrown' => '139,69,19',
+ 'salmon' => '250,128,114',
+ 'sandybrown' => '244,164,96',
+ 'seagreen' => '46,139,87',
+ 'seashell' => '255,245,238',
+ 'sienna' => '160,82,45',
+ 'silver' => '192,192,192',
+ 'skyblue' => '135,206,235',
+ 'slateblue' => '106,90,205',
+ 'slategray' => '112,128,144',
+ 'slategrey' => '112,128,144',
+ 'snow' => '255,250,250',
+ 'springgreen' => '0,255,127',
+ 'steelblue' => '70,130,180',
+ 'tan' => '210,180,140',
+ 'teal' => '0,128,128',
+ 'thistle' => '216,191,216',
+ 'tomato' => '255,99,71',
+ 'turquoise' => '64,224,208',
+ 'violet' => '238,130,238',
+ 'wheat' => '245,222,179',
+ 'white' => '255,255,255',
+ 'whitesmoke' => '245,245,245',
+ 'yellow' => '255,255,0',
+ 'yellowgreen' => '154,205,50'
+ );
+}
+
+// responsible for taking a string of LESS code and converting it into a
+// syntax tree
+class lessc_parser {
+ static protected $nextBlockId = 0; // used to uniquely identify blocks
+
+ static protected $precedence = array(
+ '=<' => 0,
+ '>=' => 0,
+ '=' => 0,
+ '<' => 0,
+ '>' => 0,
+
+ '+' => 1,
+ '-' => 1,
+ '*' => 2,
+ '/' => 2,
+ '%' => 2,
+ );
+
+ static protected $whitePattern;
+ static protected $commentMulti;
+
+ static protected $commentSingle = "//";
+ static protected $commentMultiLeft = "/*";
+ static protected $commentMultiRight = "*/";
+
+ // regex string to match any of the operators
+ static protected $operatorString;
+
+ // these properties will supress division unless it's inside parenthases
+ static protected $supressDivisionProps =
+ array('/border-radius$/i', '/^font$/i');
+
+ protected $blockDirectives = array("font-face", "keyframes", "page", "-moz-document");
+ protected $lineDirectives = array("charset");
+
+ /**
+ * if we are in parens we can be more liberal with whitespace around
+ * operators because it must evaluate to a single value and thus is less
+ * ambiguous.
+ *
+ * Consider:
+ * property1: 10 -5; // is two numbers, 10 and -5
+ * property2: (10 -5); // should evaluate to 5
+ */
+ protected $inParens = false;
+
+ // caches preg escaped literals
+ static protected $literalCache = array();
+
+ public function __construct($lessc, $sourceName = null) {
+ $this->eatWhiteDefault = true;
+ // reference to less needed for vPrefix, mPrefix, and parentSelector
+ $this->lessc = $lessc;
+
+ $this->sourceName = $sourceName; // name used for error messages
+
+ $this->writeComments = false;
+
+ if (!self::$operatorString) {
+ self::$operatorString =
+ '('.implode('|', array_map(array('lessc', 'preg_quote'),
+ array_keys(self::$precedence))).')';
+
+ $commentSingle = lessc::preg_quote(self::$commentSingle);
+ $commentMultiLeft = lessc::preg_quote(self::$commentMultiLeft);
+ $commentMultiRight = lessc::preg_quote(self::$commentMultiRight);
+
+ self::$commentMulti = $commentMultiLeft.'.*?'.$commentMultiRight;
+ self::$whitePattern = '/'.$commentSingle.'[^\n]*\s*|('.self::$commentMulti.')\s*|\s+/Ais';
+ }
+ }
+
+ public function parse($buffer) {
+ $this->count = 0;
+ $this->line = 1;
+
+ $this->env = null; // block stack
+ $this->buffer = $this->writeComments ? $buffer : $this->removeComments($buffer);
+ $this->pushSpecialBlock("root");
+ $this->eatWhiteDefault = true;
+ $this->seenComments = array();
+
+ // trim whitespace on head
+ // if (preg_match('/^\s+/', $this->buffer, $m)) {
+ // $this->line += substr_count($m[0], "\n");
+ // $this->buffer = ltrim($this->buffer);
+ // }
+ $this->whitespace();
+
+ // parse the entire file
+ $lastCount = $this->count;
+ while (false !== $this->parseChunk());
+
+ if ($this->count != strlen($this->buffer))
+ $this->throwError();
+
+ // TODO report where the block was opened
+ if (!is_null($this->env->parent))
+ throw new exception('parse error: unclosed block');
+
+ return $this->env;
+ }
+
+ /**
+ * Parse a single chunk off the head of the buffer and append it to the
+ * current parse environment.
+ * Returns false when the buffer is empty, or when there is an error.
+ *
+ * This function is called repeatedly until the entire document is
+ * parsed.
+ *
+ * This parser is most similar to a recursive descent parser. Single
+ * functions represent discrete grammatical rules for the language, and
+ * they are able to capture the text that represents those rules.
+ *
+ * Consider the function lessc::keyword(). (all parse functions are
+ * structured the same)
+ *
+ * The function takes a single reference argument. When calling the
+ * function it will attempt to match a keyword on the head of the buffer.
+ * If it is successful, it will place the keyword in the referenced
+ * argument, advance the position in the buffer, and return true. If it
+ * fails then it won't advance the buffer and it will return false.
+ *
+ * All of these parse functions are powered by lessc::match(), which behaves
+ * the same way, but takes a literal regular expression. Sometimes it is
+ * more convenient to use match instead of creating a new function.
+ *
+ * Because of the format of the functions, to parse an entire string of
+ * grammatical rules, you can chain them together using &&.
+ *
+ * But, if some of the rules in the chain succeed before one fails, then
+ * the buffer position will be left at an invalid state. In order to
+ * avoid this, lessc::seek() is used to remember and set buffer positions.
+ *
+ * Before parsing a chain, use $s = $this->seek() to remember the current
+ * position into $s. Then if a chain fails, use $this->seek($s) to
+ * go back where we started.
+ */
+ protected function parseChunk() {
+ if (empty($this->buffer)) return false;
+ $s = $this->seek();
+
+ // setting a property
+ if ($this->keyword($key) && $this->assign() &&
+ $this->propertyValue($value, $key) && $this->end())
+ {
+ $this->append(array('assign', $key, $value), $s);
+ return true;
+ } else {
+ $this->seek($s);
+ }
+
+
+ // look for special css blocks
+ if ($this->literal('@', false)) {
+ $this->count--;
+
+ // media
+ if ($this->literal('@media')) {
+ if (($this->mediaQueryList($mediaQueries) || true)
+ && $this->literal('{'))
+ {
+ $media = $this->pushSpecialBlock("media");
+ $media->queries = is_null($mediaQueries) ? array() : $mediaQueries;
+ return true;
+ } else {
+ $this->seek($s);
+ return false;
+ }
+ }
+
+ if ($this->literal("@", false) && $this->keyword($dirName)) {
+ if ($this->isDirective($dirName, $this->blockDirectives)) {
+ if (($this->openString("{", $dirValue, null, array(";")) || true) &&
+ $this->literal("{"))
+ {
+ $dir = $this->pushSpecialBlock("directive");
+ $dir->name = $dirName;
+ if (isset($dirValue)) $dir->value = $dirValue;
+ return true;
+ }
+ } elseif ($this->isDirective($dirName, $this->lineDirectives)) {
+ if ($this->propertyValue($dirValue) && $this->end()) {
+ $this->append(array("directive", $dirName, $dirValue));
+ return true;
+ }
+ }
+ }
+
+ $this->seek($s);
+ }
+
+ // setting a variable
+ if ($this->variable($var) && $this->assign() &&
+ $this->propertyValue($value) && $this->end())
+ {
+ $this->append(array('assign', $var, $value), $s);
+ return true;
+ } else {
+ $this->seek($s);
+ }
+
+ if ($this->import($url, $media)) {
+ $this->append(array('import', $url, $media), $s);
+ return true;
+
+ // don't check .css files
+ if (empty($media) && substr_compare($url, '.css', -4, 4) !== 0) {
+ if ($this->importDisabled) {
+ $this->append(array('raw', '/* import disabled */'));
+ } else {
+ $path = $this->findImport($url);
+ if (!is_null($path)) {
+ $this->append(array('import', $path), $s);
+ return true;
+ }
+ }
+ }
+
+ $this->append(array('raw', '@import url("'.$url.'")'.
+ ($media ? ' '.$media : '').';'), $s);
+ return true;
+ }
+
+ // opening parametric mixin
+ if ($this->tag($tag, true) && $this->argumentDef($args, $isVararg) &&
+ ($this->guards($guards) || true) &&
+ $this->literal('{'))
+ {
+ $block = $this->pushBlock($this->fixTags(array($tag)));
+ $block->args = $args;
+ $block->isVararg = $isVararg;
+ if (!empty($guards)) $block->guards = $guards;
+ return true;
+ } else {
+ $this->seek($s);
+ }
+
+ // opening a simple block
+ if ($this->tags($tags) && $this->literal('{')) {
+ $tags = $this->fixTags($tags);
+ $this->pushBlock($tags);
+ return true;
+ } else {
+ $this->seek($s);
+ }
+
+ // closing a block
+ if ($this->literal('}')) {
+ try {
+ $block = $this->pop();
+ } catch (exception $e) {
+ $this->seek($s);
+ $this->throwError($e->getMessage());
+ }
+
+ $hidden = false;
+ if (is_null($block->type)) {
+ $hidden = true;
+ if (!isset($block->args)) {
+ foreach ($block->tags as $tag) {
+ if (!is_string($tag) || $tag{0} != $this->lessc->mPrefix) {
+ $hidden = false;
+ break;
+ }
+ }
+ }
+
+ foreach ($block->tags as $tag) {
+ if (is_string($tag)) {
+ $this->env->children[$tag][] = $block;
+ }
+ }
+ }
+
+ if (!$hidden) {
+ $this->append(array('block', $block), $s);
+ }
+ return true;
+ }
+
+ // mixin
+ if ($this->mixinTags($tags) &&
+ ($this->argumentValues($argv) || true) &&
+ ($this->keyword($suffix) || true) && $this->end())
+ {
+ $tags = $this->fixTags($tags);
+ $this->append(array('mixin', $tags, $argv, $suffix), $s);
+ return true;
+ } else {
+ $this->seek($s);
+ }
+
+ // spare ;
+ if ($this->literal(';')) return true;
+
+ return false; // got nothing, throw error
+ }
+
+ protected function isDirective($dirname, $directives) {
+ // TODO: cache pattern in parser
+ $pattern = implode("|",
+ array_map(array("lessc", "preg_quote"), $directives));
+ $pattern = '/^(-[a-z-]+-)?(' . $pattern . ')$/i';
+
+ return preg_match($pattern, $dirname);
+ }
+
+ protected function fixTags($tags) {
+ // move @ tags out of variable namespace
+ foreach ($tags as &$tag) {
+ if ($tag{0} == $this->lessc->vPrefix)
+ $tag[0] = $this->lessc->mPrefix;
+ }
+ return $tags;
+ }
+
+ // a list of expressions
+ protected function expressionList(&$exps) {
+ $values = array();
+
+ while ($this->expression($exp)) {
+ $values[] = $exp;
+ }
+
+ if (count($values) == 0) return false;
+
+ $exps = lessc::compressList($values, ' ');
+ return true;
+ }
+
+ /**
+ * Attempt to consume an expression.
+ * @link http://en.wikipedia.org/wiki/Operator-precedence_parser#Pseudo-code
+ */
+ protected function expression(&$out) {
+ if ($this->value($lhs)) {
+ $out = $this->expHelper($lhs, 0);
+
+ // look for / shorthand
+ if (!empty($this->env->supressedDivision)) {
+ unset($this->env->supressedDivision);
+ $s = $this->seek();
+ if ($this->literal("/") && $this->value($rhs)) {
+ $out = array("list", "",
+ array($out, array("keyword", "/"), $rhs));
+ } else {
+ $this->seek($s);
+ }
+ }
+
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * recursively parse infix equation with $lhs at precedence $minP
+ */
+ protected function expHelper($lhs, $minP) {
+ $this->inExp = true;
+ $ss = $this->seek();
+
+ while (true) {
+ $whiteBefore = isset($this->buffer[$this->count - 1]) &&
+ ctype_space($this->buffer[$this->count - 1]);
+
+ // If there is whitespace before the operator, then we require
+ // whitespace after the operator for it to be an expression
+ $needWhite = $whiteBefore && !$this->inParens;
+
+ if ($this->match(self::$operatorString.($needWhite ? '\s' : ''), $m) && self::$precedence[$m[1]] >= $minP) {
+ if (!$this->inParens && isset($this->env->currentProperty) && $m[1] == "/" && empty($this->env->supressedDivision)) {
+ foreach (self::$supressDivisionProps as $pattern) {
+ if (preg_match($pattern, $this->env->currentProperty)) {
+ $this->env->supressedDivision = true;
+ break 2;
+ }
+ }
+ }
+
+
+ $whiteAfter = isset($this->buffer[$this->count - 1]) &&
+ ctype_space($this->buffer[$this->count - 1]);
+
+ if (!$this->value($rhs)) break;
+
+ // peek for next operator to see what to do with rhs
+ if ($this->peek(self::$operatorString, $next) && self::$precedence[$next[1]] > self::$precedence[$m[1]]) {
+ $rhs = $this->expHelper($rhs, self::$precedence[$next[1]]);
+ }
+
+ $lhs = array('expression', $m[1], $lhs, $rhs, $whiteBefore, $whiteAfter);
+ $ss = $this->seek();
+
+ continue;
+ }
+
+ break;
+ }
+
+ $this->seek($ss);
+
+ return $lhs;
+ }
+
+ // consume a list of values for a property
+ public function propertyValue(&$value, $keyName = null) {
+ $values = array();
+
+ if ($keyName !== null) $this->env->currentProperty = $keyName;
+
+ $s = null;
+ while ($this->expressionList($v)) {
+ $values[] = $v;
+ $s = $this->seek();
+ if (!$this->literal(',')) break;
+ }
+
+ if ($s) $this->seek($s);
+
+ if ($keyName !== null) unset($this->env->currentProperty);
+
+ if (count($values) == 0) return false;
+
+ $value = lessc::compressList($values, ', ');
+ return true;
+ }
+
+ protected function parenValue(&$out) {
+ $s = $this->seek();
+
+ // speed shortcut
+ if (isset($this->buffer[$this->count]) && $this->buffer[$this->count] != "(") {
+ return false;
+ }
+
+ $inParens = $this->inParens;
+ if ($this->literal("(") &&
+ ($this->inParens = true) && $this->expression($exp) &&
+ $this->literal(")"))
+ {
+ $out = $exp;
+ $this->inParens = $inParens;
+ return true;
+ } else {
+ $this->inParens = $inParens;
+ $this->seek($s);
+ }
+
+ return false;
+ }
+
+ // a single value
+ protected function value(&$value) {
+ $s = $this->seek();
+
+ // speed shortcut
+ if (isset($this->buffer[$this->count]) && $this->buffer[$this->count] == "-") {
+ // negation
+ if ($this->literal("-", false) &&
+ (($this->variable($inner) && $inner = array("variable", $inner)) ||
+ $this->unit($inner) ||
+ $this->parenValue($inner)))
+ {
+ $value = array("unary", "-", $inner);
+ return true;
+ } else {
+ $this->seek($s);
+ }
+ }
+
+ if ($this->parenValue($value)) return true;
+ if ($this->unit($value)) return true;
+ if ($this->color($value)) return true;
+ if ($this->func($value)) return true;
+ if ($this->string($value)) return true;
+
+ if ($this->keyword($word)) {
+ $value = array('keyword', $word);
+ return true;
+ }
+
+ // try a variable
+ if ($this->variable($var)) {
+ $value = array('variable', $var);
+ return true;
+ }
+
+ // unquote string (should this work on any type?
+ if ($this->literal("~") && $this->string($str)) {
+ $value = array("escape", $str);
+ return true;
+ } else {
+ $this->seek($s);
+ }
+
+ // css hack: \0
+ if ($this->literal('\\') && $this->match('([0-9]+)', $m)) {
+ $value = array('keyword', '\\'.$m[1]);
+ return true;
+ } else {
+ $this->seek($s);
+ }
+
+ return false;
+ }
+
+ // an import statement
+ protected function import(&$url, &$media) {
+ $s = $this->seek();
+ if (!$this->literal('@import')) return false;
+
+ // @import "something.css" media;
+ // @import url("something.css") media;
+ // @import url(something.css) media;
+
+ if ($this->literal('url(')) $parens = true; else $parens = false;
+
+ if (!$this->string($url)) {
+ if ($parens && $this->to(')', $url)) {
+ $parens = false; // got em
+ } else {
+ $this->seek($s);
+ return false;
+ }
+ }
+
+ if ($parens && !$this->literal(')')) {
+ $this->seek($s);
+ return false;
+ }
+
+ // now the rest is media
+ return $this->to(';', $media, false, true);
+ }
+
+ protected function mediaQueryList(&$out) {
+ if ($this->genericList($list, "mediaQuery", ",", false)) {
+ $out = $list[2];
+ return true;
+ }
+ return false;
+ }
+
+ protected function mediaQuery(&$out) {
+ $s = $this->seek();
+
+ $expressions = null;
+ $parts = array();
+
+ if (($this->literal("only") && ($only = true) || $this->literal("not") && ($not = true) || true) && $this->keyword($mediaType)) {
+ $prop = array("mediaType");
+ if (isset($only)) $prop[] = "only";
+ if (isset($not)) $prop[] = "not";
+ $prop[] = $mediaType;
+ $parts[] = $prop;
+ } else {
+ $this->seek($s);
+ }
+
+
+ if (!empty($mediaType) && !$this->literal("and")) {
+ // ~
+ } else {
+ $this->genericList($expressions, "mediaExpression", "and", false);
+ if (is_array($expressions)) $parts = array_merge($parts, $expressions[2]);
+ }
+
+ if (count($parts) == 0) {
+ $this->seek($s);
+ return false;
+ }
+
+ $out = $parts;
+ return true;
+ }
+
+ protected function mediaExpression(&$out) {
+ $s = $this->seek();
+ $value = null;
+ if ($this->literal("(") &&
+ $this->keyword($feature) &&
+ ($this->literal(":") && $this->expression($value) || true) &&
+ $this->literal(")"))
+ {
+ $out = array("mediaExp", $feature);
+ if ($value) $out[] = $value;
+ return true;
+ }
+
+ $this->seek($s);
+ return false;
+ }
+
+ // an unbounded string stopped by $end
+ protected function openString($end, &$out, $nestingOpen=null, $rejectStrs = null) {
+ $oldWhite = $this->eatWhiteDefault;
+ $this->eatWhiteDefault = false;
+
+ $stop = array("'", '"', "@{", $end);
+ $stop = array_map(array("lessc", "preg_quote"), $stop);
+ // $stop[] = self::$commentMulti;
+
+ if (!is_null($rejectStrs)) {
+ $stop = array_merge($stop, $rejectStrs);
+ }
+
+ $patt = '(.*?)('.implode("|", $stop).')';
+
+ $nestingLevel = 0;
+
+ $content = array();
+ while ($this->match($patt, $m, false)) {
+ if (!empty($m[1])) {
+ $content[] = $m[1];
+ if ($nestingOpen) {
+ $nestingLevel += substr_count($m[1], $nestingOpen);
+ }
+ }
+
+ $tok = $m[2];
+
+ $this->count-= strlen($tok);
+ if ($tok == $end) {
+ if ($nestingLevel == 0) {
+ break;
+ } else {
+ $nestingLevel--;
+ }
+ }
+
+ if (($tok == "'" || $tok == '"') && $this->string($str)) {
+ $content[] = $str;
+ continue;
+ }
+
+ if ($tok == "@{" && $this->interpolation($inter)) {
+ $content[] = $inter;
+ continue;
+ }
+
+ if (in_array($tok, $rejectStrs)) {
+ $count = null;
+ break;
+ }
+
+
+ $content[] = $tok;
+ $this->count+= strlen($tok);
+ }
+
+ $this->eatWhiteDefault = $oldWhite;
+
+ if (count($content) == 0) return false;
+
+ // trim the end
+ if (is_string(end($content))) {
+ $content[count($content) - 1] = rtrim(end($content));
+ }
+
+ $out = array("string", "", $content);
+ return true;
+ }
+
+ protected function string(&$out) {
+ $s = $this->seek();
+ if ($this->literal('"', false)) {
+ $delim = '"';
+ } elseif ($this->literal("'", false)) {
+ $delim = "'";
+ } else {
+ return false;
+ }
+
+ $content = array();
+
+ // look for either ending delim , escape, or string interpolation
+ $patt = '([^\n]*?)(@\{|\\\\|' .
+ lessc::preg_quote($delim).')';
+
+ $oldWhite = $this->eatWhiteDefault;
+ $this->eatWhiteDefault = false;
+
+ while ($this->match($patt, $m, false)) {
+ $content[] = $m[1];
+ if ($m[2] == "@{") {
+ $this->count -= strlen($m[2]);
+ if ($this->interpolation($inter, false)) {
+ $content[] = $inter;
+ } else {
+ $this->count += strlen($m[2]);
+ $content[] = "@{"; // ignore it
+ }
+ } elseif ($m[2] == '\\') {
+ $content[] = $m[2];
+ if ($this->literal($delim, false)) {
+ $content[] = $delim;
+ }
+ } else {
+ $this->count -= strlen($delim);
+ break; // delim
+ }
+ }
+
+ $this->eatWhiteDefault = $oldWhite;
+
+ if ($this->literal($delim)) {
+ $out = array("string", $delim, $content);
+ return true;
+ }
+
+ $this->seek($s);
+ return false;
+ }
+
+ protected function interpolation(&$out) {
+ $oldWhite = $this->eatWhiteDefault;
+ $this->eatWhiteDefault = true;
+
+ $s = $this->seek();
+ if ($this->literal("@{") &&
+ $this->keyword($var) &&
+ $this->literal("}", false))
+ {
+ $out = array("variable", $this->lessc->vPrefix . $var);
+ $this->eatWhiteDefault = $oldWhite;
+ if ($this->eatWhiteDefault) $this->whitespace();
+ return true;
+ }
+
+ $this->eatWhiteDefault = $oldWhite;
+ $this->seek($s);
+ return false;
+ }
+
+ protected function unit(&$unit) {
+ // speed shortcut
+ if (isset($this->buffer[$this->count])) {
+ $char = $this->buffer[$this->count];
+ if (!ctype_digit($char) && $char != ".") return false;
+ }
+
+ if ($this->match('([0-9]+(?:\.[0-9]*)?|\.[0-9]+)([%a-zA-Z]+)?', $m)) {
+ $unit = array("number", $m[1], empty($m[2]) ? "" : $m[2]);
+ return true;
+ }
+ return false;
+ }
+
+ // a # color
+ protected function color(&$out) {
+ if ($this->match('(#(?:[0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{3}))', $m)) {
+ if (strlen($m[1]) > 7) {
+ $out = array("string", "", array($m[1]));
+ } else {
+ $out = array("raw_color", $m[1]);
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+ // consume a list of property values delimited by ; and wrapped in ()
+ protected function argumentValues(&$args, $delim = ',') {
+ $s = $this->seek();
+ if (!$this->literal('(')) return false;
+
+ $values = array();
+ while (true) {
+ if ($this->expressionList($value)) $values[] = $value;
+ if (!$this->literal($delim)) break;
+ else {
+ if ($value == null) $values[] = null;
+ $value = null;
+ }
+ }
+
+ if (!$this->literal(')')) {
+ $this->seek($s);
+ return false;
+ }
+
+ $args = $values;
+ return true;
+ }
+
+ // consume an argument definition list surrounded by ()
+ // each argument is a variable name with optional value
+ // or at the end a ... or a variable named followed by ...
+ protected function argumentDef(&$args, &$isVararg, $delim = ',') {
+ $s = $this->seek();
+ if (!$this->literal('(')) return false;
+
+ $values = array();
+
+ $isVararg = false;
+ while (true) {
+ if ($this->literal("...")) {
+ $isVararg = true;
+ break;
+ }
+
+ if ($this->variable($vname)) {
+ $arg = array("arg", $vname);
+ $ss = $this->seek();
+ if ($this->assign() && $this->expressionList($value)) {
+ $arg[] = $value;
+ } else {
+ $this->seek($ss);
+ if ($this->literal("...")) {
+ $arg[0] = "rest";
+ $isVararg = true;
+ }
+ }
+ $values[] = $arg;
+ if ($isVararg) break;
+ continue;
+ }
+
+ if ($this->value($literal)) {
+ $values[] = array("lit", $literal);
+ }
+
+ if (!$this->literal($delim)) break;
+ }
+
+ if (!$this->literal(')')) {
+ $this->seek($s);
+ return false;
+ }
+
+ $args = $values;
+
+ return true;
+ }
+
+ // consume a list of tags
+ // this accepts a hanging delimiter
+ protected function tags(&$tags, $simple = false, $delim = ',') {
+ $tags = array();
+ while ($this->tag($tt, $simple)) {
+ $tags[] = $tt;
+ if (!$this->literal($delim)) break;
+ }
+ if (count($tags) == 0) return false;
+
+ return true;
+ }
+
+ // list of tags of specifying mixin path
+ // optionally separated by > (lazy, accepts extra >)
+ protected function mixinTags(&$tags) {
+ $s = $this->seek();
+ $tags = array();
+ while ($this->tag($tt, true)) {
+ $tags[] = $tt;
+ $this->literal(">");
+ }
+
+ if (count($tags) == 0) return false;
+
+ return true;
+ }
+
+ // a bracketed value (contained within in a tag definition)
+ protected function tagBracket(&$value) {
+ // speed shortcut
+ if (isset($this->buffer[$this->count]) && $this->buffer[$this->count] != "[") {
+ return false;
+ }
+
+ $s = $this->seek();
+ if ($this->literal('[') && $this->to(']', $c, true) && $this->literal(']', false)) {
+ $value = '['.$c.']';
+ // whitespace?
+ if ($this->whitespace()) $value .= " ";
+
+ // escape parent selector, (yuck)
+ $value = str_replace($this->lessc->parentSelector, "$&$", $value);
+ return true;
+ }
+
+ $this->seek($s);
+ return false;
+ }
+
+ protected function tagExpression(&$value) {
+ $s = $this->seek();
+ if ($this->literal("(") && $this->expression($exp) && $this->literal(")")) {
+ $value = array('exp', $exp);
+ return true;
+ }
+
+ $this->seek($s);
+ return false;
+ }
+
+ // a single tag
+ protected function tag(&$tag, $simple = false) {
+ if ($simple)
+ $chars = '^,:;{}\][>\(\) "\'';
+ else
+ $chars = '^,;{}["\'';
+
+ if (!$simple && $this->tagExpression($tag)) {
+ return true;
+ }
+
+ $tag = '';
+ while ($this->tagBracket($first)) $tag .= $first;
+
+ while (true) {
+ if ($this->match('(['.$chars.'0-9]['.$chars.']*)', $m)) {
+ $tag .= $m[1];
+ if ($simple) break;
+
+ while ($this->tagBracket($brack)) $tag .= $brack;
+ continue;
+ } elseif ($this->unit($unit)) { // for keyframes
+ $tag .= $unit[1] . $unit[2];
+ continue;
+ }
+ break;
+ }
+
+
+ $tag = trim($tag);
+ if ($tag == '') return false;
+
+ return true;
+ }
+
+ // a css function
+ protected function func(&$func) {
+ $s = $this->seek();
+
+ if ($this->match('(%|[\w\-_][\w\-_:\.]+|[\w_])', $m) && $this->literal('(')) {
+ $fname = $m[1];
+
+ $sPreArgs = $this->seek();
+
+ $args = array();
+ while (true) {
+ $ss = $this->seek();
+ // this ugly nonsense is for ie filter properties
+ if ($this->keyword($name) && $this->literal('=') && $this->expressionList($value)) {
+ $args[] = array("string", "", array($name, "=", $value));
+ } else {
+ $this->seek($ss);
+ if ($this->expressionList($value)) {
+ $args[] = $value;
+ }
+ }
+
+ if (!$this->literal(',')) break;
+ }
+ $args = array('list', ',', $args);
+
+ if ($this->literal(')')) {
+ $func = array('function', $fname, $args);
+ return true;
+ } elseif ($fname == 'url') {
+ // couldn't parse and in url? treat as string
+ $this->seek($sPreArgs);
+ if ($this->openString(")", $string) && $this->literal(")")) {
+ $func = array('function', $fname, $string);
+ return true;
+ }
+ }
+ }
+
+ $this->seek($s);
+ return false;
+ }
+
+ // consume a less variable
+ protected function variable(&$name) {
+ $s = $this->seek();
+ if ($this->literal($this->lessc->vPrefix, false) &&
+ ($this->variable($sub) || $this->keyword($name)))
+ {
+ if (!empty($sub)) {
+ $name = array('variable', $sub);
+ } else {
+ $name = $this->lessc->vPrefix.$name;
+ }
+ return true;
+ }
+
+ $name = null;
+ $this->seek($s);
+ return false;
+ }
+
+ /**
+ * Consume an assignment operator
+ * Can optionally take a name that will be set to the current property name
+ */
+ protected function assign($name = null) {
+ if ($name) $this->currentProperty = $name;
+ return $this->literal(':') || $this->literal('=');
+ }
+
+ // consume a keyword
+ protected function keyword(&$word) {
+ if ($this->match('([\w_\-\*!"][\w\-_"]*)', $m)) {
+ $word = $m[1];
+ return true;
+ }
+ return false;
+ }
+
+ // consume an end of statement delimiter
+ protected function end() {
+ if ($this->literal(';')) {
+ return true;
+ } elseif ($this->count == strlen($this->buffer) || $this->buffer{$this->count} == '}') {
+ // if there is end of file or a closing block next then we don't need a ;
+ return true;
+ }
+ return false;
+ }
+
+ protected function guards(&$guards) {
+ $s = $this->seek();
+
+ if (!$this->literal("when")) {
+ $this->seek($s);
+ return false;
+ }
+
+ $guards = array();
+
+ while ($this->guardGroup($g)) {
+ $guards[] = $g;
+ if (!$this->literal(",")) break;
+ }
+
+ if (count($guards) == 0) {
+ $guards = null;
+ $this->seek($s);
+ return false;
+ }
+
+ return true;
+ }
+
+ // a bunch of guards that are and'd together
+ // TODO rename to guardGroup
+ protected function guardGroup(&$guardGroup) {
+ $s = $this->seek();
+ $guardGroup = array();
+ while ($this->guard($guard)) {
+ $guardGroup[] = $guard;
+ if (!$this->literal("and")) break;
+ }
+
+ if (count($guardGroup) == 0) {
+ $guardGroup = null;
+ $this->seek($s);
+ return false;
+ }
+
+ return true;
+ }
+
+ protected function guard(&$guard) {
+ $s = $this->seek();
+ $negate = $this->literal("not");
+
+ if ($this->literal("(") && $this->expression($exp) && $this->literal(")")) {
+ $guard = $exp;
+ if ($negate) $guard = array("negate", $guard);
+ return true;
+ }
+
+ $this->seek($s);
+ return false;
+ }
+
+ /* raw parsing functions */
+
+ protected function literal($what, $eatWhitespace = null) {
+ if ($eatWhitespace === null) $eatWhitespace = $this->eatWhiteDefault;
+
+ // shortcut on single letter
+ if (!$eatWhitespace && isset($this->buffer[$this->count]) && !isset($what[1])) {
+ if ($this->buffer[$this->count] == $what) {
+ $this->count++;
+ return true;
+ }
+ else return false;
+ }
+
+ if (!isset(self::$literalCache[$what])) {
+ self::$literalCache[$what] = lessc::preg_quote($what);
+ }
+
+ return $this->match(self::$literalCache[$what], $m, $eatWhitespace);
+ }
+
+ protected function genericList(&$out, $parseItem, $delim="", $flatten=true) {
+ $s = $this->seek();
+ $items = array();
+ while ($this->$parseItem($value)) {
+ $items[] = $value;
+ if ($delim) {
+ if (!$this->literal($delim)) break;
+ }
+ }
+
+ if (count($items) == 0) {
+ $this->seek($s);
+ return false;
+ }
+
+ if ($flatten && count($items) == 1) {
+ $out = $items[0];
+ } else {
+ $out = array("list", $delim, $items);
+ }
+
+ return true;
+ }
+
+
+ // advance counter to next occurrence of $what
+ // $until - don't include $what in advance
+ // $allowNewline, if string, will be used as valid char set
+ protected function to($what, &$out, $until = false, $allowNewline = false) {
+ if (is_string($allowNewline)) {
+ $validChars = $allowNewline;
+ } else {
+ $validChars = $allowNewline ? "." : "[^\n]";
+ }
+ if (!$this->match('('.$validChars.'*?)'.lessc::preg_quote($what), $m, !$until)) return false;
+ if ($until) $this->count -= strlen($what); // give back $what
+ $out = $m[1];
+ return true;
+ }
+
+ // try to match something on head of buffer
+ protected function match($regex, &$out, $eatWhitespace = null) {
+ if ($eatWhitespace === null) $eatWhitespace = $this->eatWhiteDefault;
+
+ $r = '/'.$regex.($eatWhitespace && !$this->writeComments ? '\s*' : '').'/Ais';
+ if (preg_match($r, $this->buffer, $out, null, $this->count)) {
+ $this->count += strlen($out[0]);
+ if ($eatWhitespace && $this->writeComments) $this->whitespace();
+ return true;
+ }
+ return false;
+ }
+
+ // match some whitespace
+ protected function whitespace() {
+ if ($this->writeComments) {
+ $gotWhite = false;
+ while (preg_match(self::$whitePattern, $this->buffer, $m, null, $this->count)) {
+ if (isset($m[1]) && empty($this->commentsSeen[$this->count])) {
+ $this->append(array("comment", $m[1]));
+ $this->commentsSeen[$this->count] = true;
+ }
+ $this->count += strlen($m[0]);
+ $gotWhite = true;
+ }
+ return $gotWhite;
+ } else {
+ $this->match("", $m);
+ return strlen($m[0]) > 0;
+ }
+ }
+
+ // match something without consuming it
+ protected function peek($regex, &$out = null, $from=null) {
+ if (is_null($from)) $from = $this->count;
+ $r = '/'.$regex.'/Ais';
+ $result = preg_match($r, $this->buffer, $out, null, $from);
+
+ return $result;
+ }
+
+ // seek to a spot in the buffer or return where we are on no argument
+ protected function seek($where = null) {
+ if ($where === null) return $this->count;
+ else $this->count = $where;
+ return true;
+ }
+
+ /* misc functions */
+
+ public function throwError($msg = "parse error", $count = null) {
+ $count = is_null($count) ? $this->count : $count;
+
+ $line = $this->line +
+ substr_count(substr($this->buffer, 0, $count), "\n");
+
+ if (!empty($this->sourceName)) {
+ $loc = "$this->sourceName on line $line";
+ } else {
+ $loc = "line: $line";
+ }
+
+ // TODO this depends on $this->count
+ if ($this->peek("(.*?)(\n|$)", $m, $count)) {
+ throw new exception("$msg: failed at `$m[1]` $loc");
+ } else {
+ throw new exception("$msg: $loc");
+ }
+ }
+
+ protected function pushBlock($selectors=null, $type=null) {
+ $b = new stdclass;
+ $b->parent = $this->env;
+
+ $b->type = $type;
+ $b->id = self::$nextBlockId++;
+
+ $b->isVararg = false; // TODO: kill me from here
+ $b->tags = $selectors;
+
+ $b->props = array();
+ $b->children = array();
+
+ $this->env = $b;
+ return $b;
+ }
+
+ // push a block that doesn't multiply tags
+ protected function pushSpecialBlock($type) {
+ return $this->pushBlock(null, $type);
+ }
+
+ // append a property to the current block
+ protected function append($prop, $pos = null) {
+ if ($pos !== null) $prop[-1] = $pos;
+ $this->env->props[] = $prop;
+ }
+
+ // pop something off the stack
+ protected function pop() {
+ $old = $this->env;
+ $this->env = $this->env->parent;
+ return $old;
+ }
+
+ // remove comments from $text
+ // todo: make it work for all functions, not just url
+ protected function removeComments($text) {
+ $look = array(
+ 'url(', '//', '/*', '"', "'"
+ );
+
+ $out = '';
+ $min = null;
+ $done = false;
+ while (true) {
+ // find the next item
+ foreach ($look as $token) {
+ $pos = strpos($text, $token);
+ if ($pos !== false) {
+ if (!isset($min) || $pos < $min[1]) $min = array($token, $pos);
+ }
+ }
+
+ if (is_null($min)) break;
+
+ $count = $min[1];
+ $skip = 0;
+ $newlines = 0;
+ switch ($min[0]) {
+ case 'url(':
+ if (preg_match('/url\(.*?\)/', $text, $m, 0, $count))
+ $count += strlen($m[0]) - strlen($min[0]);
+ break;
+ case '"':
+ case "'":
+ if (preg_match('/'.$min[0].'.*?'.$min[0].'/', $text, $m, 0, $count))
+ $count += strlen($m[0]) - 1;
+ break;
+ case '//':
+ $skip = strpos($text, "\n", $count);
+ if ($skip === false) $skip = strlen($text) - $count;
+ else $skip -= $count;
+ break;
+ case '/*':
+ if (preg_match('/\/\*.*?\*\//s', $text, $m, 0, $count)) {
+ $skip = strlen($m[0]);
+ $newlines = substr_count($m[0], "\n");
+ }
+ break;
+ }
+
+ if ($skip == 0) $count += strlen($min[0]);
+
+ $out .= substr($text, 0, $count).str_repeat("\n", $newlines);
+ $text = substr($text, $count + $skip);
+
+ $min = null;
+ }
+
+ return $out.$text;
+ }
+
+}
+
+class lessc_formatter_classic {
+ public $indentChar = " ";
+
+ public $break = "\n";
+ public $open = " {";
+ public $close = "}";
+ public $selectorSeparator = ", ";
+ public $assignSeparator = ":";
+
+ public $openSingle = " { ";
+ public $closeSingle = " }";
+
+ public $disableSingle = false;
+ public $breakSelectors = false;
+
+ public $compressColors = false;
+
+ public function __construct() {
+ $this->indentLevel = 0;
+ }
+
+ public function indentStr($n = 0) {
+ return str_repeat($this->indentChar, max($this->indentLevel + $n, 0));
+ }
+
+ public function property($name, $value) {
+ return $name . $this->assignSeparator . $value . ";";
+ }
+
+ protected function isEmpty($block) {
+ if (empty($block->lines)) {
+ foreach ($block->children as $child) {
+ if (!$this->isEmpty($child)) return false;
+ }
+
+ return true;
+ }
+ return false;
+
+ if (empty($block->lines) && empty($block->children)) return true;
+ }
+
+ public function block($block) {
+ if ($this->isEmpty($block)) return;
+
+ $inner = $pre = $this->indentStr();
+
+ $isSingle = !$this->disableSingle &&
+ is_null($block->type) && count($block->lines) == 1;
+
+ if (!empty($block->selectors)) {
+ $this->indentLevel++;
+
+ if ($this->breakSelectors) {
+ $selectorSeparator = $this->selectorSeparator . $this->break . $pre;
+ } else {
+ $selectorSeparator = $this->selectorSeparator;
+ }
+
+ echo $pre .
+ implode($selectorSeparator, $block->selectors);
+ if ($isSingle) {
+ echo $this->openSingle;
+ $inner = "";
+ } else {
+ echo $this->open . $this->break;
+ $inner = $this->indentStr();
+ }
+
+ }
+
+ if (!empty($block->lines)) {
+ $glue = $this->break.$inner;
+ echo $inner . implode($glue, $block->lines);
+ if (!$isSingle && !empty($block->children)) {
+ echo $this->break;
+ }
+ }
+
+ foreach ($block->children as $child) {
+ $this->block($child);
+ }
+
+ if (!empty($block->selectors)) {
+ if (!$isSingle && empty($block->children)) echo $this->break;
+
+ if ($isSingle) {
+ echo $this->closeSingle . $this->break;
+ } else {
+ echo $pre . $this->close . $this->break;
+ }
+
+ $this->indentLevel--;
+ }
+ }
+}
+
+class lessc_formatter_compressed extends lessc_formatter_classic {
+ public $disableSingle = true;
+ public $open = "{";
+ public $selectorSeparator = ",";
+ public $assignSeparator = ":";
+ public $break = "";
+ public $compressColors = true;
+
+ public function indentStr($n = 0) {
+ return "";
+ }
+}
+
+class lessc_formatter_lessjs extends lessc_formatter_classic {
+ public $disableSingle = true;
+ public $breakSelectors = true;
+ public $assignSeparator = ": ";
+ public $selectorSeparator = ",";
+}
+
diff --git a/sparks/assets/1.5.1/spark.info b/sparks/assets/1.5.1/spark.info
new file mode 100644
index 0000000..099766d
--- /dev/null
+++ b/sparks/assets/1.5.1/spark.info
@@ -0,0 +1,7 @@
+name: assets
+
+version: 1.5.1
+
+compatibility: 2.1.0
+
+tags: ["assets", "css", "javascript", "lesscss", "cofeescript"]
\ No newline at end of file