Index

SourceMap

MMO\client\scs · 1 symbol · generated 30 Sep 2026

class

SourceMap

SourceMap.php:17

A source map v3 for the generated css: it tells a browser which .scs file, line and column each piece of css came from, so devtools shows lib.scs:91 instead of mmo.client.css:2043.

class MMO\client\scs\SourceMap implements Stringable
Namespace
MMO\client\scs
Implements
Stringable
The compiler fills it while emitting ([`Emitter::toCss`](https://mmoframework.fr/documentation/mmo.client/php/scs/Emitter.md#emitter-tocss)): one mapping per selector and per declaration, which is the granularity sass gives too. The original sources are embedded (`sourcesContent`), so the map keeps working wherever the css is served from.
$map = new SourceMap('app.css', $sources); $map->add(0, 0, $location); file_put_contents('app.css.map', $map->toJson());

Constants1

BASE64

const BASE64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'

Properties6

contents

protected array $contents
Type
array

directory

protected ?string $directory
Type
null | string

file

protected string $file
Type
string

mappings

protected array $mappings = []
Type
array

names

protected array $names = []
Type
array

sources

protected array $sources = []
Type
array

Methods13

add($line, $column, $location)

SourceMap.php:44

Record that the css being written at this position comes from this source position.

function add(int $line, int $column, ?MMO\client\scs\SourceLocation $location): void
$lineint0 based generated line
$columnint0 based generated column
$locationnull | SourceLocationnull when the css has no source of its own (a wrapper, a comment)
returnsvoid

Comment($url)

staticSourceMap.php:100
static function Comment(string $url): string
$urlstringwhat the css should point at, ex: app.css.map or toDataUri
returnsstringthe comment a browser reads to find this map

encode()

SourceMap.php:114
protected function encode(): string
returnsstringthe mappings field: one group per generated line, each segment relative to the one before it (the column restarts at every line, the source fields never do)

isEmpty()

SourceMap.php:55
function isEmpty(): bool
returnsbooltrue when nothing was mapped: a stylesheet that generated no css

setDirectory($directory)

SourceMap.php:63

The folder the map is written in. Source paths are relative to it, as a build tool expects (../../src/styles/lib.scs).

function setDirectory(?string $directory): void
$directorynull | string
returnsvoid

toDataUri()

SourceMap.php:92
function toDataUri(): string
returnsstringthe map as a data: uri, for a sourceMappingURL that needs no second file

toJson($flags)

SourceMap.php:85
function toJson(int $flags = 320): string
$flags = 320intjson_encode flags
returnsstringthe map as json

Vlq($value)

staticSourceMap.php:146
static function Vlq(int $value): string
$valueint
returnsstringbase64 variable length quantity: the sign goes in the low bit, then 5 bits per digit with the 6th marking a continuation

__construct($file, $contents, $directory)

SourceMap.php:32
function __construct(string $file = '', array $contents = [], ?string $directory = null)
$file = ''stringthe name of the generated css file
$contents = []arrayfilename => source text, embedded so the map needs no file access
$directory = nullnull | stringthe folder the map will be written in: source paths are made relative to it