| @@ -372,12 +372,10 @@ | ||
| 372 | 372 | . '<body class="easy-invoice-pdf easy-invoice-pdf--design' . ( $has_canvas ? ' easy-invoice-pdf--canvas' : '' ) . '"><div class="' . esc_attr( $type ) . '-content">' |
| 373 | 373 | . $body . $extra . $after . '</div></body></html>'; |
| 374 | 374 | |
| 375 | 375 | // Resolved over the whole document so the compat sheet can refer to the |
| 376 | - // design's own palette (its :root block lives in the body). The compat | |
| 377 | - // sheet's own :root wins: it sits in the head, so document order would | |
| 378 | - // otherwise hand every variable back to the design. | |
| 379 | - $html = self::resolveCssVariables( $html, self::rootVariables( $compat ) ); | |
| 376 | + // design's own palette (its :root block lives in the body). | |
| 377 | + $html = self::resolveCssVariables( $html ); | |
| 380 | 378 | |
| 381 | 379 | /** |
| 382 | 380 | * Filter the complete HTML of a design-based PDF before dompdf sees it. |
| 383 | 381 | * |
| @@ -395,18 +393,14 @@ | ||
| 395 | 393 | * |
| 396 | 394 | * @param string $html Markup with inline <style> blocks. |
| 397 | 395 | * @return string |
| 398 | 396 | */ |
| 399 | - /** | |
| 400 | - * The custom properties declared in every `:root` block of a stylesheet or | |
| 401 | - * document, last declaration winning. | |
| 402 | - * | |
| 403 | - * @param string $css CSS or HTML. | |
| 404 | - * @return array<string, string> | |
| 405 | - */ | |
| 406 | - private static function rootVariables( string $css ): array { | |
| 397 | + public static function resolveCssVariables( string $html ): string { | |
| 398 | + if ( false === strpos( $html, 'var(--' ) ) { | |
| 399 | + return $html; | |
| 400 | + } | |
| 407 | 401 | $vars = []; |
| 408 | - if ( preg_match_all( '/:root\s*\{([^}]*)\}/', $css, $blocks ) ) { | |
| 402 | + if ( preg_match_all( '/:root\s*\{([^}]*)\}/', $html, $blocks ) ) { | |
| 409 | 403 | foreach ( $blocks[1] as $block ) { |
| 410 | 404 | foreach ( explode( ';', $block ) as $declaration ) { |
| 411 | 405 | if ( preg_match( '/--([a-zA-Z0-9\-_]+)\s*:\s*(.+)$/', trim( $declaration ), $m ) ) { |
| 412 | 406 | $vars[ $m[1] ] = trim( $m[2] ); |
| @@ -412,19 +406,8 @@ | ||
| 412 | 406 | $vars[ $m[1] ] = trim( $m[2] ); |
| 413 | 407 | } |
| 414 | 408 | } |
| 415 | 409 | } |
| 416 | - } | |
| 417 | - return $vars; | |
| 418 | - } | |
| 419 | - | |
| 420 | - public static function resolveCssVariables( string $html, array $overrides = [] ): string { | |
| 421 | - if ( false === strpos( $html, 'var(--' ) ) { | |
| 422 | - return $html; | |
| 423 | - } | |
| 424 | - $vars = self::rootVariables( $html ); | |
| 425 | - foreach ( $overrides as $name => $value ) { | |
| 426 | - $vars[ $name ] = $value; | |
| 427 | 410 | } |
| 428 | 411 | // Values may reference other variables; three passes cover any sane chain. |
| 429 | 412 | for ( $i = 0; $i < 3 && false !== strpos( $html, 'var(--' ); $i++ ) { |
| 430 | 413 | $html = (string) preg_replace_callback( |