Styling the Media Masher Editor

The visual appearance of Media Masher can be customized via common web standards like parts, slots, and CSS variables. To instead change the behavior of components and how they load, see the Embedding Guide.

Targeting

The HTML document below can be hosted on any web host to display the Media Masher application in any modern web browser:

Example: Styled HTML
<!DOCTYPE html>
<html lang='en'>
  <head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <title>Media Masher Styled Example</title>
    <script type='importmap'>{ "imports": {
      "lit": "https://cdn.jsdelivr.net/gh/lit/dist@3.2.0/all/lit-all.min.js",
      "@mashermedia/": "https://js.masher.media/0.0.1-beta.36/"
    } }</script>
    <script type='module'>
      import '@mashermedia/client/media-masher.js';
    </script>
    <style> 
      body {
        height: 100vh;
        display: flex;
        margin: 0;
        padding: 0;
        background-color: white; color: black;
      }
      @media(prefers-color-scheme: dark) {
        body { background-color: black; color: white; }
      }
      media-masher::part(player) { 
        --color-chrome-chroma-per: 30%;
      }
    </style>
  </head>
  <body>
    <media-masher></media-masher>
  </body>
</html>

The MEDIA-MASHER element’s constructed CSS includes flex-grow:1, so this example sets display:flex and height:100vh on the BODY element to fill the whole viewport. It also unsets the margin and padding on the BODY, since the editor includes space around and between its subcomponents.

A media query is used to swap the page’s fore and back color when the user’s device is in dark mode. The editor adjusts itself automatically, but the element itself has no coloring.

The --color-chrome-chroma-per variable is used to override the chroma of the color in the headers and footers within the player. The default is 0%, which is grayscale, but we set it here to 30% which results in a blue.

Parts

Without further configuration, the MEDIA-MASHER element will populate itself with all four of the main components (player, browser, timeline, and inspector) as described in the Editing Guide.

Each of these main components contain three vertically stacked subcomponents - a header and footer (chrome), and a content area. These then contain three SPAN elements (left, center, and right) that in turn contain the actual elements the user interacts with.

Left Content Header Footer Center Right

This nested container structure is utilized by the MEDIA-MASHER element to simplify customization of the editor’s appearance. Its exportparts attribute contains not only the main components, but also the subcomponents and SPAN elements.

For instance, the center SPAN element in the player’s contents component is exported as part browser-content-center which can be styled with the following CSS selector:

Example: CSS Parts
media-masher::part(browser-content-center) {
  background-color: red;
}

Slots

The same targeting pattern used with parts can be applied to slots IDs as well. To completely replace a target you can simply add a SLOT child element with its id attriute set to the MEDIA-MASHER element. For instance, the following HTML replaces the left SPAN element in the player’s header component with a custom element containing the text “Media Masher”:

Example: HTML Slots
<media-masher>
  <span slot='player-header-left'>
    Media Masher
  </span>
</media-masher>

If you were to inspect the resultant DOM structure, you’d see SLOT elements that have been created at each tier of the hierarchy. These effectively pass your custom element down to replace the targetted one.

If there are no elements to display in a SPAN, it will not be rendered. Likewise, if there are no SPAN elements in a header or footer component, it will not be rendered. Container components are all styled with display:flex so other child elements fill any available space.

By default, the center slot is not populated in headers or footers so it’s a good place to add your elements. The left and right slots are not populated in the content components.

CSS Variables

The MEDIA-MASHER element defines many core CSS variables that can be used to change the editor’s appearance. Its subcomponents all use these values to calculate variables of their own, which are in turn used by the interface elements they contain. These two types of variables have different limitations on where they can be overridden:

  • A core variable can be overridden globally by redefining it on the MEDIA-MASHER element, or locally to one of its children by redefining it on the corresponding part.
  • A calculated variable must be redefined on a subcomponent of the MEDIA-MASHER element but it can be targeted as low down the hierarchy as needed.

The core variables can be interactively changed from within the editor itself by clicking on the link in the top right corner of the inspector. Changes here adjust the variables on the MEDIA-MASHER element, forcing recalculation throughout the editor. Click the link to copy the changed values to the clipboard - these can then be pasted directly into your CSS.

Visibility

All core visibility variables are defined as boolean values (1 = true, 0 = false) and are used to calculate the total height of content items. They toggle the display of icons, labels, and previews within the following types of elements:

  • timeline clips
  • browser media
Preview Icon Label
Core VariableDescriptionDefault
—view-icon-booShow icons in the items1
—view-label-booShow labels in the items1
—view-preview-booShow preview in the items1

At least one of these variables must be set to 1, otherwise content items will display improperly, with their height calculated from just the padding and border values.

Borders

All core border variable values are defined in pixels, so there are no calculated border variables. Values either represent the size or the radius of the border, and are applied to the following types of elements:

  • button: whether in chrome or content
  • item: timeline clips and browser media content
  • panel: player, browser, timeline, and inspector
  • preview: frame preview within items (no radius)
Core VariableDescriptionDefault
—border-button-radius-pixButton border radius5px
—border-button-stroke-pixButton border size1px
—border-item-radius-pixContent item border radius5px
—border-item-stroke-pixContent item border size1px
—border-panel-radius-pixPanel border radius7px
—border-panel-stroke-pixPanel border size3px
—border-preview-stroke-pixPreview border size1px

Colors

Most of the core color variables define one of the three values in the oklch colorspace (lightness, chroma, and hue) that are used in calculated variables that are then applied to elements.

There are five lightness levels that represent the darkest to lightest values in the editor when in light mode. And there are two pairs of chroma and hue values - one for content areas and another for chrome.

Core VariableDescriptionDefault
—color-brightness-1-perDarkest in light mode15%
—color-brightness-2-perDarker in light mode35%
—color-brightness-3-perNormal in light mode50%
—color-brightness-4-perLighter in light mode70%
—color-brightness-5-perLightest in light mode90%
—color-chrome-chroma-perChroma within headers and footers0%
—color-chrome-hue-degHue within headers and footers281
—color-content-chroma-perChroma within content0%
—color-content-hue-degHue within content281

The core variables are then used to calculate a variety of colors for these specific combinations of usages and states:

  • back: used for background colors
  • fore: used for text, icon, and border colors
  • off: disabled state color
  • on: selected state color
  • over: hover state color
Calculated VariableDescription
—back-chromeBackground color of chrome
—back-contentBackground color of content
—fore-chromeForeground color in chrome
—fore-contentForeground color in content
—off-back-chromeDisabled background color in chrome
—off-fore-chromeDisabled foreground color in chrome
—on-fore-chromeSelected foreground color in chrome
—on-fore-contentSelected foreground color in content
—over-back-chromeHover background color in chrome
—over-back-contentHover background color in content
—over-fore-chromeHover foreground color in chrome
—over-fore-contentHover foreground color in content

These calculations all include one of the lightness values which serves to differentiate between background and foreground colors. But instead of using one of the --color-brightness-* variables directly, one of the --bright-* variables below are used instead. These are redefined in a media query when the user’s device is in dark mode, to effectively invert the color scheme.

Calculated VariableDescription
—bright-1Lightest in dark mode
—bright-2Lighter in dark mode
—bright-3Normal in both modes
—bright-4Darker in dark mode
—bright-5Darkest in dark mode
—color-contrastMash contrasting color
—color-contrast-darkDark color
—color-contrast-lightLight color

The --color-contrast value is used to provide contrast around content item previews. It depends on the current mash color and is automatically set to either --color-contrast-light when the color is dark or --color-contrast-dark when it’s light. The values for these variables are also redefined in a media query as either --fore-content or --back-content depending on the light/dark mode. The lighter of the two will always populate --color-contrast-light while the darker populates --color-contrast-dark.

Padding

All the core padding variables are defined in pixels, so there are no calculated padding variables. Values represent interior element padding as well as gaps between children, and are applied to the following types of elements:

  • button: space around text and icons
  • chrome: space around elements in headers and footers
  • content: space around elements in content areas
  • control: space around selects and inputs in inspector
  • item: space around label and preview in content items
  • panel: space around player, browser, timeline, and inspector
Core VariableDescriptionDefault
—pad-button-pixButton padding and gap4px
—pad-chrome-pixChrome padding and gap5px
—pad-content-pixContent area padding and gap10px
—pad-control-pixControl row padding and gap10px
—pad-item-pixContent item padding and gap3px
—pad-panel-pixMEDIA-MASHER padding and gap20px

Sizing

Many of core sizing variables values are defined as ratios (zero to one) of the --size-base-str variable which is the base size defined as a string. These are then used to calculate the total height of the following types of elements:

  • button: height of buttons
  • control: height of selects and inputs in inspector
  • label: height of labels in content items
  • preview: height of previews in content items
Core VariableDescriptionDefault
—size-base-strBase font size2rem
—size-button-ratButton height to rem ratio0.5
—size-control-ratControl height to rem ratio0.6
—size-label-ratLabel height to rem ratio0.5
—size-preview-ratPreview height to rem ratio0.25

Other core sizing variables are defined either in pixels or ratios of the viewport and are used to calculate the total height of the following specific elements:

  • aside: inspector width and left/right content SPAN elements
  • dialog: import/export dialog width and height
  • player: player containing dimension
  • scrubber: timeline scrub control height and width
Core VariableDescriptionDefault
—size-aside-pixInspector width240px
—size-player-pixPlayer containing dimension360px
—size-dialog-height-ratDialog height to viewport ratio0.5
—size-dialog-width-ratDialog width to viewport ratio0.66
—size-scrubber-height-pixScrubber height13px
—size-scrubber-width-pixScrubber width16px

The --size-player-pix represents the maximum height or width that the player’s preview can be. The preview’s actual size is calculated based on the aspect ratio of the loaded mash.