Add OBS overlays (goal, timer, counter, alerts) with ETag polling
Align timer state key with rules engine (timer_ends_at). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7155396312
commit
65082fb2f5
10 files changed
+815
No files matched your search
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace StreamGoals\Overlay;
|
||||
|
||||
/** Sanitizes owner-supplied URL styling params into a closed set of CSS custom properties. */
|
||||
final class Style {
|
||||
|
||||
public const THEMES = array( 'dark', 'light', 'neon', 'minimal' );
|
||||
|
||||
private const FONTS = array(
|
||||
'sans' => 'system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif',
|
||||
'serif' => 'Georgia, "Times New Roman", serif',
|
||||
'mono' => 'ui-monospace, "SFMono-Regular", Consolas, monospace',
|
||||
'rounded' => 'ui-rounded, "Nunito", "Varela Round", system-ui, sans-serif',
|
||||
'condensed' => '"Arial Narrow", "Roboto Condensed", Impact, sans-serif',
|
||||
);
|
||||
|
||||
private const COLOR_KEYS = array( 'color' => 'fg', 'accent' => 'accent', 'accent2' => 'accent2', 'track' => 'track', 'bg' => 'bg' );
|
||||
|
||||
public static function color( mixed $v ): ?string {
|
||||
if ( ! is_string( $v ) ) {
|
||||
return null;
|
||||
}
|
||||
$v = ltrim( trim( $v ), '#' );
|
||||
return preg_match( '/^([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/', $v ) ? '#' . strtolower( $v ) : null;
|
||||
}
|
||||
|
||||
/** @return array{theme:string,vars:array<string,string>} */
|
||||
public static function fromQuery( array $q ): array {
|
||||
$theme = isset( $q['theme'] ) && is_string( $q['theme'] ) && in_array( strtolower( $q['theme'] ), self::THEMES, true )
|
||||
? strtolower( $q['theme'] ) : 'dark';
|
||||
$vars = array();
|
||||
foreach ( self::COLOR_KEYS as $param => $var ) {
|
||||
$c = self::color( $q[ $param ] ?? null );
|
||||
if ( null !== $c ) {
|
||||
$vars[ '--sg-' . $var ] = $c;
|
||||
}
|
||||
}
|
||||
if ( isset( $q['font'] ) && is_string( $q['font'] ) ) {
|
||||
$f = trim( $q['font'] );
|
||||
if ( isset( self::FONTS[ strtolower( $f ) ] ) ) {
|
||||
$vars['--sg-font'] = self::FONTS[ strtolower( $f ) ];
|
||||
} elseif ( preg_match( '/^[A-Za-z0-9][A-Za-z0-9 \-]{0,39}$/', $f ) ) {
|
||||
$vars['--sg-font'] = '"' . $f . '", ' . self::FONTS['sans']; // locally installed font name
|
||||
}
|
||||
}
|
||||
if ( isset( $q['scale'] ) && is_scalar( $q['scale'] ) && is_numeric( $q['scale'] ) ) {
|
||||
$vars['--sg-scale'] = (string) round( max( 0.5, min( 3.0, (float) $q['scale'] ) ), 2 );
|
||||
}
|
||||
return array( 'theme' => $theme, 'vars' => $vars );
|
||||
}
|
||||
|
||||
public static function inline( array $vars ): string {
|
||||
$out = '';
|
||||
foreach ( $vars as $k => $v ) {
|
||||
$out .= $k . ':' . $v . ';';
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user