AssetsService.php
2 years ago
AssetsServiceProvider.php
3 years ago
BlockAssetsLoadService.php
3 years ago
PreloadService.php
3 years ago
ScriptsService.php
2 years ago
StylesService.php
3 years ago
StylesService.php
111 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\WordPress\Assets; |
| 4 | |
| 5 | /** |
| 6 | * Handles the component theme. |
| 7 | */ |
| 8 | class StylesService { |
| 9 | /** |
| 10 | * Holds the service container |
| 11 | * |
| 12 | * @var \Pimple\Container |
| 13 | */ |
| 14 | protected $container; |
| 15 | |
| 16 | /** |
| 17 | * Make sure we change the script loader tag for esm loading. |
| 18 | * |
| 19 | * @param \Pimple\Container $container Service Container. |
| 20 | */ |
| 21 | public function __construct( $container ) { |
| 22 | $this->container = $container; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Register the default theme. |
| 27 | * |
| 28 | * @return void |
| 29 | */ |
| 30 | public function register() { |
| 31 | wp_register_style( |
| 32 | 'surecart-themes-default', |
| 33 | trailingslashit( \SureCart::core()->assets()->getUrl() ) . 'dist/components/surecart/surecart.css', |
| 34 | [], |
| 35 | filemtime( trailingslashit( $this->container[ SURECART_CONFIG_KEY ]['app_core']['path'] ) . 'dist/components/surecart/surecart.css' ), |
| 36 | ); |
| 37 | $brand = \SureCart::account()->brand; |
| 38 | |
| 39 | $style = file_get_contents( plugin_dir_path( SURECART_PLUGIN_FILE ) . 'dist/blocks/cloak.css' ); |
| 40 | |
| 41 | $style .= ':root {'; |
| 42 | $style .= '--sc-color-primary-500: #' . ( $brand->color ?? '000' ) . ';'; |
| 43 | $style .= '--sc-focus-ring-color-primary: #' . ( $brand->color ?? '000' ) . ';'; |
| 44 | $style .= '--sc-input-border-color-focus: #' . ( $brand->color ?? '000' ) . ';'; |
| 45 | $style .= '--sc-color-gray-900: #' . ( $brand->heading ?? '000' ) . ';'; |
| 46 | $style .= '--sc-color-primary-text: #' . \SureCart::utility()->color()->calculateForegroundColor( $brand->color ?? '000000' ) . ';'; |
| 47 | $style .= '}'; |
| 48 | |
| 49 | wp_add_inline_style( |
| 50 | 'surecart-themes-default', |
| 51 | $style |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Enqueue the front styles. |
| 57 | * |
| 58 | * @return void |
| 59 | */ |
| 60 | public function enqueueFront() { |
| 61 | // make sure it is registered. |
| 62 | $this->register(); |
| 63 | // enqueue it. |
| 64 | wp_enqueue_style( 'surecart-themes-default' ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Enqueue the editor styles. |
| 69 | * |
| 70 | * @return void |
| 71 | */ |
| 72 | public function enqueueEditor() { |
| 73 | // make sure it is registered. |
| 74 | $this->register(); |
| 75 | // enqueue it. |
| 76 | wp_enqueue_style( 'surecart-themes-default' ); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Add inline brand styles to theme. |
| 81 | * |
| 82 | * @param string $handle The handle to add the styles to. |
| 83 | * |
| 84 | * @return void |
| 85 | */ |
| 86 | public function addInlineBrandColors( $handle ) { |
| 87 | ob_start(); |
| 88 | ?> |
| 89 | :root:root { |
| 90 | --sc-color-primary-500: var(--sc-color-brand-primary); |
| 91 | --sc-focus-ring-color-primary: var(--sc-color-brand-primary); |
| 92 | --sc-input-border-color-focus: var(--sc-color-brand-primary); |
| 93 | --sc-color-gray-900: var(--sc-color-brand-heading); |
| 94 | --sc-color-gray-800: var(--sc-color-brand-text); |
| 95 | --sc-tab-active-color: var(--sc-color-brand-heading); |
| 96 | --sc-tab-active-background: var(--sc-color-brand-main-background); |
| 97 | --sc-tag-default-background-color: var(--sc-color-brand-main-background); |
| 98 | --sc-tag-default-border-color: var(--sc-color-brand-stroke); |
| 99 | --sc-tag-default-color: var(--sc-color-brand-body); |
| 100 | --sc-stacked-list-row-hover-color: var(--sc-color-brand-main-background); |
| 101 | --sc-color-primary-text: white; |
| 102 | } |
| 103 | <?php |
| 104 | |
| 105 | wp_add_inline_style( |
| 106 | $handle, |
| 107 | ob_get_clean() |
| 108 | ); |
| 109 | } |
| 110 | } |
| 111 |