'css_custom_property'] ); } /** * Factory für Spacing Token */ public static function spacing(string $name, string|int $value, string $description = ''): self { return new self( name: $name, type: DesignTokenType::SPACING, value: $value, description: $description ?: "Spacing: " . ucwords(str_replace(['-', '_'], ' ', $name)), metadata: ['source' => 'css_custom_property'] ); } /** * Factory für Typography Token */ public static function typography(string $name, mixed $value, string $description = ''): self { return new self( name: $name, type: DesignTokenType::TYPOGRAPHY, value: $value, description: $description ?: "Typography: " . ucwords(str_replace(['-', '_'], ' ', $name)), metadata: ['source' => 'css_custom_property'] ); } /** * Konvertiert zu Array für Export/Serialisierung * @return array */ public function toArray(): array { return [ 'name' => $this->name, 'type' => $this->type->value, 'value' => $this->serializeValue(), 'description' => $this->description, 'metadata' => $this->metadata, ]; } /** * Erstellt CSS Custom Property String */ public function toCssCustomProperty(): string { $value = match($this->type) { DesignTokenType::COLOR => $this->value instanceof CssColor ? $this->value->toString() : (string) $this->value, default => (string) $this->value }; return "--{$this->name}: {$value};"; } /** * Gibt CSS var() Referenz zurück */ public function toCssVar(): string { return "var(--{$this->name})"; } /** * Prüft ob Token einen bestimmten Wert-Typ hat */ public function hasValueType(string $type): bool { return match($type) { 'color' => $this->value instanceof CssColor, 'string' => is_string($this->value), 'int' => is_int($this->value), 'float' => is_float($this->value), 'array' => is_array($this->value), default => false }; } /** * Gibt Wert als bestimmten Typ zurück */ public function getValueAs(string $type): mixed { return match($type) { 'string' => (string) $this->value, 'int' => (int) $this->value, 'float' => (float) $this->value, 'array' => is_array($this->value) ? $this->value : [$this->value], 'color' => $this->value instanceof CssColor ? $this->value : null, default => $this->value }; } private function serializeValue(): mixed { if ($this->value instanceof CssColor) { return [ 'original' => $this->value->originalValue, 'format' => $this->value->format->value, 'hex' => $this->value->toHex(), 'rgb' => $this->value->toRGB()?->toArray(), ]; } return $this->value; } public function toString(): string { return $this->toCssVar(); } }