aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/scssphp/scssphp/src/Formatter
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/scssphp/scssphp/src/Formatter')
-rw-r--r--vendor/scssphp/scssphp/src/Formatter/Compact.php52
-rw-r--r--vendor/scssphp/scssphp/src/Formatter/Compressed.php83
-rw-r--r--vendor/scssphp/scssphp/src/Formatter/Crunched.php87
-rw-r--r--vendor/scssphp/scssphp/src/Formatter/Debug.php127
-rw-r--r--vendor/scssphp/scssphp/src/Formatter/Expanded.php72
-rw-r--r--vendor/scssphp/scssphp/src/Formatter/Nested.php238
-rw-r--r--vendor/scssphp/scssphp/src/Formatter/OutputBlock.php68
7 files changed, 727 insertions, 0 deletions
diff --git a/vendor/scssphp/scssphp/src/Formatter/Compact.php b/vendor/scssphp/scssphp/src/Formatter/Compact.php
new file mode 100644
index 000000000..22f226889
--- /dev/null
+++ b/vendor/scssphp/scssphp/src/Formatter/Compact.php
@@ -0,0 +1,52 @@
+<?php
+
+/**
+ * SCSSPHP
+ *
+ * @copyright 2012-2020 Leaf Corcoran
+ *
+ * @license http://opensource.org/licenses/MIT MIT
+ *
+ * @link http://scssphp.github.io/scssphp
+ */
+
+namespace ScssPhp\ScssPhp\Formatter;
+
+use ScssPhp\ScssPhp\Formatter;
+
+/**
+ * Compact formatter
+ *
+ * @author Leaf Corcoran <leafot@gmail.com>
+ *
+ * @deprecated since 1.4.0. Use the Compressed formatter instead.
+ *
+ * @internal
+ */
+class Compact extends Formatter
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct()
+ {
+ @trigger_error('The Compact formatter is deprecated since 1.4.0. Use the Compressed formatter instead.', E_USER_DEPRECATED);
+
+ $this->indentLevel = 0;
+ $this->indentChar = '';
+ $this->break = '';
+ $this->open = ' {';
+ $this->close = "}\n\n";
+ $this->tagSeparator = ',';
+ $this->assignSeparator = ':';
+ $this->keepSemicolons = true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function indentStr()
+ {
+ return ' ';
+ }
+}
diff --git a/vendor/scssphp/scssphp/src/Formatter/Compressed.php b/vendor/scssphp/scssphp/src/Formatter/Compressed.php
new file mode 100644
index 000000000..58ebe3f11
--- /dev/null
+++ b/vendor/scssphp/scssphp/src/Formatter/Compressed.php
@@ -0,0 +1,83 @@
+<?php
+
+/**
+ * SCSSPHP
+ *
+ * @copyright 2012-2020 Leaf Corcoran
+ *
+ * @license http://opensource.org/licenses/MIT MIT
+ *
+ * @link http://scssphp.github.io/scssphp
+ */
+
+namespace ScssPhp\ScssPhp\Formatter;
+
+use ScssPhp\ScssPhp\Formatter;
+
+/**
+ * Compressed formatter
+ *
+ * @author Leaf Corcoran <leafot@gmail.com>
+ *
+ * @internal
+ */
+class Compressed extends Formatter
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct()
+ {
+ $this->indentLevel = 0;
+ $this->indentChar = ' ';
+ $this->break = '';
+ $this->open = '{';
+ $this->close = '}';
+ $this->tagSeparator = ',';
+ $this->assignSeparator = ':';
+ $this->keepSemicolons = false;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function blockLines(OutputBlock $block)
+ {
+ $inner = $this->indentStr();
+
+ $glue = $this->break . $inner;
+
+ foreach ($block->lines as $index => $line) {
+ if (substr($line, 0, 2) === '/*' && substr($line, 2, 1) !== '!') {
+ unset($block->lines[$index]);
+ }
+ }
+
+ $this->write($inner . implode($glue, $block->lines));
+
+ if (! empty($block->children)) {
+ $this->write($this->break);
+ }
+ }
+
+ /**
+ * Output block selectors
+ *
+ * @param \ScssPhp\ScssPhp\Formatter\OutputBlock $block
+ */
+ protected function blockSelectors(OutputBlock $block)
+ {
+ assert(! empty($block->selectors));
+
+ $inner = $this->indentStr();
+
+ $this->write(
+ $inner
+ . implode(
+ $this->tagSeparator,
+ str_replace([' > ', ' + ', ' ~ '], ['>', '+', '~'], $block->selectors)
+ )
+ . $this->open . $this->break
+ );
+ }
+}
diff --git a/vendor/scssphp/scssphp/src/Formatter/Crunched.php b/vendor/scssphp/scssphp/src/Formatter/Crunched.php
new file mode 100644
index 000000000..2bc1e9299
--- /dev/null
+++ b/vendor/scssphp/scssphp/src/Formatter/Crunched.php
@@ -0,0 +1,87 @@
+<?php
+
+/**
+ * SCSSPHP
+ *
+ * @copyright 2012-2020 Leaf Corcoran
+ *
+ * @license http://opensource.org/licenses/MIT MIT
+ *
+ * @link http://scssphp.github.io/scssphp
+ */
+
+namespace ScssPhp\ScssPhp\Formatter;
+
+use ScssPhp\ScssPhp\Formatter;
+
+/**
+ * Crunched formatter
+ *
+ * @author Anthon Pang <anthon.pang@gmail.com>
+ *
+ * @deprecated since 1.4.0. Use the Compressed formatter instead.
+ *
+ * @internal
+ */
+class Crunched extends Formatter
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct()
+ {
+ @trigger_error('The Crunched formatter is deprecated since 1.4.0. Use the Compressed formatter instead.', E_USER_DEPRECATED);
+
+ $this->indentLevel = 0;
+ $this->indentChar = ' ';
+ $this->break = '';
+ $this->open = '{';
+ $this->close = '}';
+ $this->tagSeparator = ',';
+ $this->assignSeparator = ':';
+ $this->keepSemicolons = false;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function blockLines(OutputBlock $block)
+ {
+ $inner = $this->indentStr();
+
+ $glue = $this->break . $inner;
+
+ foreach ($block->lines as $index => $line) {
+ if (substr($line, 0, 2) === '/*') {
+ unset($block->lines[$index]);
+ }
+ }
+
+ $this->write($inner . implode($glue, $block->lines));
+
+ if (! empty($block->children)) {
+ $this->write($this->break);
+ }
+ }
+
+ /**
+ * Output block selectors
+ *
+ * @param \ScssPhp\ScssPhp\Formatter\OutputBlock $block
+ */
+ protected function blockSelectors(OutputBlock $block)
+ {
+ assert(! empty($block->selectors));
+
+ $inner = $this->indentStr();
+
+ $this->write(
+ $inner
+ . implode(
+ $this->tagSeparator,
+ str_replace([' > ', ' + ', ' ~ '], ['>', '+', '~'], $block->selectors)
+ )
+ . $this->open . $this->break
+ );
+ }
+}
diff --git a/vendor/scssphp/scssphp/src/Formatter/Debug.php b/vendor/scssphp/scssphp/src/Formatter/Debug.php
new file mode 100644
index 000000000..b3f442253
--- /dev/null
+++ b/vendor/scssphp/scssphp/src/Formatter/Debug.php
@@ -0,0 +1,127 @@
+<?php
+
+/**
+ * SCSSPHP
+ *
+ * @copyright 2012-2020 Leaf Corcoran
+ *
+ * @license http://opensource.org/licenses/MIT MIT
+ *
+ * @link http://scssphp.github.io/scssphp
+ */
+
+namespace ScssPhp\ScssPhp\Formatter;
+
+use ScssPhp\ScssPhp\Formatter;
+
+/**
+ * Debug formatter
+ *
+ * @author Anthon Pang <anthon.pang@gmail.com>
+ *
+ * @deprecated since 1.4.0.
+ *
+ * @internal
+ */
+class Debug extends Formatter
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct()
+ {
+ @trigger_error('The Debug formatter is deprecated since 1.4.0.', E_USER_DEPRECATED);
+
+ $this->indentLevel = 0;
+ $this->indentChar = '';
+ $this->break = "\n";
+ $this->open = ' {';
+ $this->close = ' }';
+ $this->tagSeparator = ', ';
+ $this->assignSeparator = ': ';
+ $this->keepSemicolons = true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function indentStr()
+ {
+ return str_repeat(' ', $this->indentLevel);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function blockLines(OutputBlock $block)
+ {
+ $indent = $this->indentStr();
+
+ if (empty($block->lines)) {
+ $this->write("{$indent}block->lines: []\n");
+
+ return;
+ }
+
+ foreach ($block->lines as $index => $line) {
+ $this->write("{$indent}block->lines[{$index}]: $line\n");
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function blockSelectors(OutputBlock $block)
+ {
+ $indent = $this->indentStr();
+
+ if (empty($block->selectors)) {
+ $this->write("{$indent}block->selectors: []\n");
+
+ return;
+ }
+
+ foreach ($block->selectors as $index => $selector) {
+ $this->write("{$indent}block->selectors[{$index}]: $selector\n");
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function blockChildren(OutputBlock $block)
+ {
+ $indent = $this->indentStr();
+
+ if (empty($block->children)) {
+ $this->write("{$indent}block->children: []\n");
+
+ return;
+ }
+
+ $this->indentLevel++;
+
+ foreach ($block->children as $i => $child) {
+ $this->block($child);
+ }
+
+ $this->indentLevel--;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function block(OutputBlock $block)
+ {
+ $indent = $this->indentStr();
+
+ $this->write("{$indent}block->type: {$block->type}\n" .
+ "{$indent}block->depth: {$block->depth}\n");
+
+ $this->currentBlock = $block;
+
+ $this->blockSelectors($block);
+ $this->blockLines($block);
+ $this->blockChildren($block);
+ }
+}
diff --git a/vendor/scssphp/scssphp/src/Formatter/Expanded.php b/vendor/scssphp/scssphp/src/Formatter/Expanded.php
new file mode 100644
index 000000000..6eb4a0cb7
--- /dev/null
+++ b/vendor/scssphp/scssphp/src/Formatter/Expanded.php
@@ -0,0 +1,72 @@
+<?php
+
+/**
+ * SCSSPHP
+ *
+ * @copyright 2012-2020 Leaf Corcoran
+ *
+ * @license http://opensource.org/licenses/MIT MIT
+ *
+ * @link http://scssphp.github.io/scssphp
+ */
+
+namespace ScssPhp\ScssPhp\Formatter;
+
+use ScssPhp\ScssPhp\Formatter;
+
+/**
+ * Expanded formatter
+ *
+ * @author Leaf Corcoran <leafot@gmail.com>
+ *
+ * @internal
+ */
+class Expanded extends Formatter
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct()
+ {
+ $this->indentLevel = 0;
+ $this->indentChar = ' ';
+ $this->break = "\n";
+ $this->open = ' {';
+ $this->close = '}';
+ $this->tagSeparator = ', ';
+ $this->assignSeparator = ': ';
+ $this->keepSemicolons = true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function indentStr()
+ {
+ return str_repeat($this->indentChar, $this->indentLevel);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function blockLines(OutputBlock $block)
+ {
+ $inner = $this->indentStr();
+
+ $glue = $this->break . $inner;
+
+ foreach ($block->lines as $index => $line) {
+ if (substr($line, 0, 2) === '/*') {
+ $replacedLine = preg_replace('/\r\n?|\n|\f/', $this->break, $line);
+ assert($replacedLine !== null);
+ $block->lines[$index] = $replacedLine;
+ }
+ }
+
+ $this->write($inner . implode($glue, $block->lines));
+
+ if (empty($block->selectors) || ! empty($block->children)) {
+ $this->write($this->break);
+ }
+ }
+}
diff --git a/vendor/scssphp/scssphp/src/Formatter/Nested.php b/vendor/scssphp/scssphp/src/Formatter/Nested.php
new file mode 100644
index 000000000..d5ed85cc2
--- /dev/null
+++ b/vendor/scssphp/scssphp/src/Formatter/Nested.php
@@ -0,0 +1,238 @@
+<?php
+
+/**
+ * SCSSPHP
+ *
+ * @copyright 2012-2020 Leaf Corcoran
+ *
+ * @license http://opensource.org/licenses/MIT MIT
+ *
+ * @link http://scssphp.github.io/scssphp
+ */
+
+namespace ScssPhp\ScssPhp\Formatter;
+
+use ScssPhp\ScssPhp\Formatter;
+use ScssPhp\ScssPhp\Type;
+
+/**
+ * Nested formatter
+ *
+ * @author Leaf Corcoran <leafot@gmail.com>
+ *
+ * @deprecated since 1.4.0. Use the Expanded formatter instead.
+ *
+ * @internal
+ */
+class Nested extends Formatter
+{
+ /**
+ * @var int
+ */
+ private $depth;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct()
+ {
+ @trigger_error('The Nested formatter is deprecated since 1.4.0. Use the Expanded formatter instead.', E_USER_DEPRECATED);
+
+ $this->indentLevel = 0;
+ $this->indentChar = ' ';
+ $this->break = "\n";
+ $this->open = ' {';
+ $this->close = ' }';
+ $this->tagSeparator = ', ';
+ $this->assignSeparator = ': ';
+ $this->keepSemicolons = true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function indentStr()
+ {
+ $n = $this->depth - 1;
+
+ return str_repeat($this->indentChar, max($this->indentLevel + $n, 0));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function blockLines(OutputBlock $block)
+ {
+ $inner = $this->indentStr();
+ $glue = $this->break . $inner;
+
+ foreach ($block->lines as $index => $line) {
+ if (substr($line, 0, 2) === '/*') {
+ $replacedLine = preg_replace('/\r\n?|\n|\f/', $this->break, $line);
+ assert($replacedLine !== null);
+ $block->lines[$index] = $replacedLine;
+ }
+ }
+
+ $this->write($inner . implode($glue, $block->lines));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function block(OutputBlock $block)
+ {
+ static $depths;
+ static $downLevel;
+ static $closeBlock;
+ static $previousEmpty;
+ static $previousHasSelector;
+
+ if ($block->type === 'root') {
+ $depths = [ 0 ];
+ $downLevel = '';
+ $closeBlock = '';
+ $this->depth = 0;
+ $previousEmpty = false;
+ $previousHasSelector = false;
+ }
+
+ $isMediaOrDirective = \in_array($block->type, [Type::T_DIRECTIVE, Type::T_MEDIA]);
+ $isSupport = ($block->type === Type::T_DIRECTIVE
+ && $block->selectors && strpos(implode('', $block->selectors), '@supports') !== false);
+
+ while ($block->depth < end($depths) || ($block->depth == 1 && end($depths) == 1)) {
+ array_pop($depths);
+ $this->depth--;
+
+ if (
+ ! $this->depth && ($block->depth <= 1 || (! $this->indentLevel && $block->type === Type::T_COMMENT)) &&
+ (($block->selectors && ! $isMediaOrDirective) || $previousHasSelector)
+ ) {
+ $downLevel = $this->break;
+ }
+
+ if (empty($block->lines) && empty($block->children)) {
+ $previousEmpty = true;
+ }
+ }
+
+ if (empty($block->lines) && empty($block->children)) {
+ return;
+ }
+
+ $this->currentBlock = $block;
+
+ if (! empty($block->lines) || (! empty($block->children) && ($this->depth < 1 || $isSupport))) {
+ if ($block->depth > end($depths)) {
+ if (! $previousEmpty || $this->depth < 1) {
+ $this->depth++;
+
+ $depths[] = $block->depth;
+ } else {
+ // keep the current depth unchanged but take the block depth as a new reference for following blocks
+ array_pop($depths);
+
+ $depths[] = $block->depth;
+ }
+ }
+ }
+
+ $previousEmpty = ($block->type === Type::T_COMMENT);
+ $previousHasSelector = false;
+
+ if (! empty($block->selectors)) {
+ if ($closeBlock) {
+ $this->write($closeBlock);
+ $closeBlock = '';
+ }
+
+ if ($downLevel) {
+ $this->write($downLevel);
+ $downLevel = '';
+ }
+
+ $this->blockSelectors($block);
+
+ $this->indentLevel++;
+ }
+
+ if (! empty($block->lines)) {
+ if ($closeBlock) {
+ $this->write($closeBlock);
+ $closeBlock = '';
+ }
+
+ if ($downLevel) {
+ $this->write($downLevel);
+ $downLevel = '';
+ }
+
+ $this->blockLines($block);
+
+ $closeBlock = $this->break;
+ }
+
+ if (! empty($block->children)) {
+ if ($this->depth > 0 && ($isMediaOrDirective || ! $this->hasFlatChild($block))) {
+ array_pop($depths);
+
+ $this->depth--;
+ $this->blockChildren($block);
+ $this->depth++;
+
+ $depths[] = $block->depth;
+ } else {
+ $this->blockChildren($block);
+ }
+ }
+
+ // reclear to not be spoiled by children if T_DIRECTIVE
+ if ($block->type === Type::T_DIRECTIVE) {
+ $previousHasSelector = false;
+ }
+
+ if (! empty($block->selectors)) {
+ $this->indentLevel--;
+
+ if (! $this->keepSemicolons) {
+ $this->strippedSemicolon = '';
+ }
+
+ $this->write($this->close);
+
+ $closeBlock = $this->break;
+
+ if ($this->depth > 1 && ! empty($block->children)) {
+ array_pop($depths);
+ $this->depth--;
+ }
+
+ if (! $isMediaOrDirective) {
+ $previousHasSelector = true;
+ }
+ }
+
+ if ($block->type === 'root') {
+ $this->write($this->break);
+ }
+ }
+
+ /**
+ * Block has flat child
+ *
+ * @param \ScssPhp\ScssPhp\Formatter\OutputBlock $block
+ *
+ * @return bool
+ */
+ private function hasFlatChild($block)
+ {
+ foreach ($block->children as $child) {
+ if (empty($child->selectors)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
diff --git a/vendor/scssphp/scssphp/src/Formatter/OutputBlock.php b/vendor/scssphp/scssphp/src/Formatter/OutputBlock.php
new file mode 100644
index 000000000..2799656a4
--- /dev/null
+++ b/vendor/scssphp/scssphp/src/Formatter/OutputBlock.php
@@ -0,0 +1,68 @@
+<?php
+
+/**
+ * SCSSPHP
+ *
+ * @copyright 2012-2020 Leaf Corcoran
+ *
+ * @license http://opensource.org/licenses/MIT MIT
+ *
+ * @link http://scssphp.github.io/scssphp
+ */
+
+namespace ScssPhp\ScssPhp\Formatter;
+
+/**
+ * Output block
+ *
+ * @author Anthon Pang <anthon.pang@gmail.com>
+ *
+ * @internal
+ */
+class OutputBlock
+{
+ /**
+ * @var string|null
+ */
+ public $type;
+
+ /**
+ * @var int
+ */
+ public $depth;
+
+ /**
+ * @var array|null
+ */
+ public $selectors;
+
+ /**
+ * @var string[]
+ */
+ public $lines;
+
+ /**
+ * @var OutputBlock[]
+ */
+ public $children;
+
+ /**
+ * @var OutputBlock|null
+ */
+ public $parent;
+
+ /**
+ * @var string|null
+ */
+ public $sourceName;
+
+ /**
+ * @var int|null
+ */
+ public $sourceLine;
+
+ /**
+ * @var int|null
+ */
+ public $sourceColumn;
+}