AssetsService.php
1 year ago
AssetsServiceProvider.php
3 years ago
BlockAssetsLoadService.php
1 year ago
PreloadService.php
1 year ago
ScriptsService.php
2 weeks ago
StylesService.php
1 month ago
StylesService.php
157 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 | array(), |
| 35 | filemtime( trailingslashit( $this->container[ SURECART_CONFIG_KEY ]['app_core']['path'] ) . 'dist/components/surecart/surecart.css' ), |
| 36 | ); |
| 37 | $brand = \SureCart::account()->brand; |
| 38 | $color = preg_replace( '/[^a-fA-F0-9]/', '', \SureCart::theme()->brandColor() ); |
| 39 | $heading = preg_replace( '/[^a-fA-F0-9]/', '', $brand->heading ?? '000' ); |
| 40 | |
| 41 | $style = file_get_contents( plugin_dir_path( SURECART_PLUGIN_FILE ) . 'dist/blocks/cloak.css' ); |
| 42 | |
| 43 | $style .= ':root {'; |
| 44 | $style .= '--sc-color-primary-500: #' . $color . ';'; |
| 45 | $style .= '--sc-focus-ring-color-primary: #' . $color . ';'; |
| 46 | $style .= '--sc-input-border-color-focus: #' . $color . ';'; |
| 47 | $style .= '--sc-color-gray-900: #' . $heading . ';'; |
| 48 | $style .= '--sc-color-primary-text: #' . \SureCart::utility()->color()->calculateForegroundColor( $color ) . ';'; |
| 49 | $style .= '--wp--preset--color--surecart: #' . $color . ';'; |
| 50 | $style .= '}'; |
| 51 | |
| 52 | wp_add_inline_style( |
| 53 | 'surecart-themes-default', |
| 54 | $style |
| 55 | ); |
| 56 | |
| 57 | // blocks-next. |
| 58 | wp_add_inline_style( |
| 59 | 'surecart-theme-base', |
| 60 | $style |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Enqueue the front styles. |
| 66 | * |
| 67 | * @return void |
| 68 | */ |
| 69 | public function enqueueFront() { |
| 70 | // make sure it is registered. |
| 71 | $this->register(); |
| 72 | // enqueue it. |
| 73 | wp_enqueue_style( 'surecart-themes-default' ); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Enqueue the editor styles. |
| 78 | * |
| 79 | * @return void |
| 80 | */ |
| 81 | public function enqueueEditor() { |
| 82 | // make sure it is registered. |
| 83 | $this->register(); |
| 84 | // enqueue it. |
| 85 | wp_enqueue_style( 'surecart-themes-default' ); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Add inline brand styles to theme. |
| 90 | * |
| 91 | * @param string $handle The handle to add the styles to. |
| 92 | * |
| 93 | * @return void |
| 94 | */ |
| 95 | public function addInlineAdminColors( $handle ) { |
| 96 | ob_start(); |
| 97 | ?> |
| 98 | :root:root { |
| 99 | --wp-admin-theme-color: #007cba; |
| 100 | --wp-admin-theme-color-darker-10: #1f63a0; |
| 101 | --wp-admin-theme-color-darker-20: #1a5080; |
| 102 | --sc-color-primary-500: var(--wp-admin-theme-color); |
| 103 | --sc-focus-ring-color-primary: var( |
| 104 | --wp-admin-theme-color |
| 105 | ); |
| 106 | --sc-input-border-color-focus: var( |
| 107 | --wp-admin-theme-color |
| 108 | ); |
| 109 | } |
| 110 | <?php |
| 111 | |
| 112 | wp_add_inline_style( |
| 113 | $handle, |
| 114 | ob_get_clean() |
| 115 | ); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Add inline brand styles to theme. |
| 120 | * |
| 121 | * @param string $handle The handle to add the styles to. |
| 122 | * |
| 123 | * @return void |
| 124 | */ |
| 125 | public function addInlineBrandColors( $handle ) { |
| 126 | ob_start(); |
| 127 | ?> |
| 128 | :root:root { |
| 129 | --sc-color-primary-500: var(--sc-color-brand-primary); |
| 130 | --sc-focus-ring-color-primary: var(--sc-color-brand-primary); |
| 131 | --sc-input-border-color-focus: var(--sc-color-brand-primary); |
| 132 | --sc-color-gray-900: var(--sc-color-brand-heading); |
| 133 | --sc-color-gray-800: var(--sc-color-brand-text); |
| 134 | --sc-tab-active-color: var(--sc-color-brand-primary); |
| 135 | --sc-tab-active-background: transparent; |
| 136 | --sc-tag-default-background-color: var(--sc-color-brand-main-background); |
| 137 | --sc-tag-default-border-color: var(--sc-color-brand-stroke); |
| 138 | --sc-tag-default-color: var(--sc-color-brand-body); |
| 139 | --sc-stacked-list-row-hover-color: var(--sc-color-brand-main-background); |
| 140 | --sc-color-primary-text: white; |
| 141 | } |
| 142 | |
| 143 | sc-tab:not([active]):not(:hover) sc-icon { |
| 144 | color: var(--sc-color-gray-500); |
| 145 | } |
| 146 | sc-tab::part(base) { |
| 147 | font-weight: 400; |
| 148 | } |
| 149 | <?php |
| 150 | |
| 151 | wp_add_inline_style( |
| 152 | $handle, |
| 153 | ob_get_clean() |
| 154 | ); |
| 155 | } |
| 156 | } |
| 157 |