]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - vendor/oyejorge/less.php/lib/Less/Output/Mapped.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / oyejorge / less.php / lib / Less / Output / Mapped.php
diff --git a/vendor/oyejorge/less.php/lib/Less/Output/Mapped.php b/vendor/oyejorge/less.php/lib/Less/Output/Mapped.php
new file mode 100644 (file)
index 0000000..9e4cc46
--- /dev/null
@@ -0,0 +1,122 @@
+<?php\r
+\r
+/**\r
+ * Parser output with source map\r
+ *\r
+ * @package Less\r
+ * @subpackage Output\r
+ */\r
+class Less_Output_Mapped extends Less_Output {\r
+\r
+       /**\r
+        * The source map generator\r
+        *\r
+        * @var Less_SourceMap_Generator\r
+        */\r
+       protected $generator;\r
+\r
+       /**\r
+        * Current line\r
+        *\r
+        * @var integer\r
+        */\r
+       protected $lineNumber = 0;\r
+\r
+       /**\r
+        * Current column\r
+        *\r
+        * @var integer\r
+        */\r
+       protected $column = 0;\r
+\r
+       /**\r
+        * Array of contents map (file and its content)\r
+        *\r
+        * @var array\r
+        */\r
+       protected $contentsMap = array();\r
+\r
+       /**\r
+        * Constructor\r
+        *\r
+        * @param array $contentsMap Array of filename to contents map\r
+        * @param Less_SourceMap_Generator $generator\r
+        */\r
+       public function __construct(array $contentsMap, $generator){\r
+               $this->contentsMap = $contentsMap;\r
+               $this->generator = $generator;\r
+       }\r
+\r
+       /**\r
+        * Adds a chunk to the stack\r
+        * The $index for less.php may be different from less.js since less.php does not chunkify inputs\r
+        *\r
+        * @param string $chunk\r
+        * @param string $fileInfo\r
+        * @param integer $index\r
+        * @param mixed $mapLines\r
+        */\r
+       public function add($chunk, $fileInfo = null, $index = 0, $mapLines = null){\r
+\r
+               //ignore adding empty strings\r
+               if( $chunk === '' ){\r
+                       return;\r
+               }\r
+\r
+\r
+               $sourceLines = array();\r
+               $sourceColumns = ' ';\r
+\r
+\r
+               if( $fileInfo ){\r
+\r
+                       $url = $fileInfo['currentUri'];\r
+\r
+                       if( isset($this->contentsMap[$url]) ){\r
+                               $inputSource = substr($this->contentsMap[$url], 0, $index);\r
+                               $sourceLines = explode("\n", $inputSource);\r
+                               $sourceColumns = end($sourceLines);\r
+                       }else{\r
+                               throw new Exception('Filename '.$url.' not in contentsMap');\r
+                       }\r
+\r
+               }\r
+\r
+               $lines = explode("\n", $chunk);\r
+               $columns = end($lines);\r
+\r
+               if($fileInfo){\r
+\r
+                       if(!$mapLines){\r
+                               $this->generator->addMapping(\r
+                                               $this->lineNumber + 1,                                  // generated_line\r
+                                               $this->column,                                                  // generated_column\r
+                                               count($sourceLines),                                    // original_line\r
+                                               strlen($sourceColumns),                                 // original_column\r
+                                               $fileInfo\r
+                               );\r
+                       }else{\r
+                               for($i = 0, $count = count($lines); $i < $count; $i++){\r
+                                       $this->generator->addMapping(\r
+                                               $this->lineNumber + $i + 1,                             // generated_line\r
+                                               $i === 0 ? $this->column : 0,                   // generated_column\r
+                                               count($sourceLines) + $i,                               // original_line\r
+                                               $i === 0 ? strlen($sourceColumns) : 0,  // original_column\r
+                                               $fileInfo\r
+                                       );\r
+                               }\r
+                       }\r
+               }\r
+\r
+               if(count($lines) === 1){\r
+                       $this->column += strlen($columns);\r
+               }else{\r
+                       $this->lineNumber += count($lines) - 1;\r
+                       $this->column = strlen($columns);\r
+               }\r
+\r
+               // add only chunk\r
+               parent::add($chunk);\r
+       }\r
+\r
+}
\ No newline at end of file