Class StyleContext
java.lang.Object
dev.jcputney.mjml.context.StyleContext
CSS and font state gathered during head processing. Contains fonts, font URL overrides, styles,
component styles, inline styles, media queries, and fluid-on-mobile tracking.
This is one of three focused sub-contexts extracted from GlobalContext. See also
MetadataContext and AttributeContext.
Thread safety: This class is not thread-safe. Each render pipeline creates its own instance.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordFont definition record.static final recordMedia query definition for responsive column widths. widthValue is the numeric value, widthUnit is "%" or "px". -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new empty style context with no fonts, styles, or media queries registered. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddComponentStyle(String css) Adds a component-specific CSS style block.voidRegisters a font with the given name and URL.voidaddInlineStyle(String css) Adds an inline CSS style block.voidaddMediaQuery(String className, String widthValue, String widthUnit) Adds a media query for responsive column width targeting the given CSS class.voidAdds a CSS style block.booleanaddStyleOnce(String key, String css) Adds a CSS style block only if a style with the given key has not already been registered.Returns an unmodifiable list of all registered component-specific CSS style blocks.getFonts()Returns an unmodifiable set of all registered font definitions.getFontUrlOverride(String name) Returns the overridden URL for the given font name, ornullif no override exists.Returns an unmodifiable map of all font URL overrides, keyed by font name.Returns an unmodifiable list of all registered inline CSS style blocks.Returns an unmodifiable set of all registered media queries.Returns an unmodifiable list of all registered CSS style blocks.booleanReturns whether any component has indicated that fluid-on-mobile behavior is used.voidregisterFontOverride(String name, String href) Registers a font URL override, replacing the default URL for the given font name.voidsetFluidOnMobileUsed(boolean fluidOnMobileUsed) Sets whether fluid-on-mobile behavior is used in the current render.
-
Constructor Details
-
StyleContext
public StyleContext()Creates a new empty style context with no fonts, styles, or media queries registered.
-
-
Method Details
-
addFont
-
getFonts
Returns an unmodifiable set of all registered font definitions.- Returns:
- the registered fonts
-
registerFontOverride
-
getFontUrlOverride
-
getFontUrlOverrides
-
addStyle
Adds a CSS style block. Blank ornullvalues are ignored.- Parameters:
css- the CSS style string to add
-
addStyleOnce
Adds a CSS style block only if a style with the given key has not already been registered. This prevents duplicate style blocks for the same component type.- Parameters:
key- the unique key identifying this style blockcss- the CSS style string to add- Returns:
trueif the style was added,falseif the key was already registered
-
addComponentStyle
Adds a component-specific CSS style block. Blank ornullvalues are ignored.- Parameters:
css- the component CSS style string to add
-
getComponentStyles
-
addInlineStyle
Adds an inline CSS style block. Blank ornullvalues are ignored.- Parameters:
css- the inline CSS style string to add
-
getStyles
-
getInlineStyles
-
addMediaQuery
Adds a media query for responsive column width targeting the given CSS class.- Parameters:
className- the CSS class name for the responsive columnwidthValue- the numeric width valuewidthUnit- the unit for the width value (e.g. "%" or "px")
-
getMediaQueries
Returns an unmodifiable set of all registered media queries.- Returns:
- the media queries
-
isFluidOnMobileUsed
public boolean isFluidOnMobileUsed()Returns whether any component has indicated that fluid-on-mobile behavior is used.- Returns:
trueif fluid-on-mobile is used
-
setFluidOnMobileUsed
public void setFluidOnMobileUsed(boolean fluidOnMobileUsed) Sets whether fluid-on-mobile behavior is used in the current render.- Parameters:
fluidOnMobileUsed-trueif fluid-on-mobile is used
-