public final class PrefixCleaner extends Object implements Plugin
If an at-rule is prefixed, most likely any prefixed declarations within that at-rule with a differing prefix can be removed.
This might especially be the case if you are utilizing the Prefixer
plugin, which might automatically create prefixed
versions of at-rules that contain unnecessary prefixed declarations. For example:
@keyframes animation {
from { transform: rotate(0deg) }
from { transform: rotate(360deg) }
}
after prefixing could result in
@-webkit-keyframes animation {
from { -webkit-transform: rotate(0deg); -ms-transform: rotate(0deg); transform: rotate(0deg) }
from { -webkit-transform: rotate(360deg); -ms-transform: rotate(360deg); transform: rotate(360deg) }
}
Notice the -ms-transform
is most likely unnecessary as it is within a -webkit-
prefixed at-rule. The PrefixCleaner
plugin can be utilized to remove such prefixed declarations inside of prefixed at-rules. Use the prefixedAtRules()
instance method or the mismatchedPrefixedUnits()
constructor method to remove these unnecessary
prefixes.
Important: This plugin must be registered after the Prefixer
plugin:
Omakase.source(input)
.use(Prefixer.defaultBrowserSupport())
.use(PrefixCleaner.mismatchedPrefixedUnits())
.process()
You can also specify the only prefix you want to keep with the keep(Prefix)
method, and all other prefixed selectors,
at-rules, declarations, etc... that don't match will be removed. This can be useful if you are generating browser-specific
versions of your CSS. Not yet supported!Constructor and Description |
---|
PrefixCleaner()
Creates a new
PrefixCleaner instance. |
PrefixCleaner(Prefix prefix)
Creates a new
PrefixCleaner instance that will remove all units with a prefix that doesn't match the given one. |
Modifier and Type | Method and Description |
---|---|
void |
atRule(AtRule atRule)
Subscription method - do not call directly.
|
PrefixCleaner |
keep(Prefix prefix)
NOT IMPLEMENTED: Removes all units with a prefix that doesn't match the given one.
|
static PrefixCleaner |
mismatchedPrefixedUnits()
Creates a new
PrefixCleaner that will eliminate prefixed declarations within prefixed at-rules, where the
declaration's prefix doesn't match the at-rule's prefix. |
static PrefixCleaner |
onlyKeep(Prefix prefix)
NOT IMPLEMENTED: Creates a new
PrefixCleaner that will eliminate all units with prefixes that do not match the
given prefix. |
PrefixCleaner |
prefixedAtRules()
For prefixed declarations within prefixed at-rules, this removes the declaration if it has a prefix different from the
at-rule's prefix.
|
public PrefixCleaner()
PrefixCleaner
instance.public PrefixCleaner(Prefix prefix)
PrefixCleaner
instance that will remove all units with a prefix that doesn't match the given one.prefix
- Only keep units with this prefix.public PrefixCleaner keep(Prefix prefix)
prefix
- Only keep units with this prefix.public PrefixCleaner prefixedAtRules()
public void atRule(AtRule atRule)
atRule
- Check this at rule.public static PrefixCleaner mismatchedPrefixedUnits()
PrefixCleaner
that will eliminate prefixed declarations within prefixed at-rules, where the
declaration's prefix doesn't match the at-rule's prefix.PrefixCleaner
instance.public static PrefixCleaner onlyKeep(Prefix prefix)
PrefixCleaner
that will eliminate all units with prefixes that do not match the
given prefix.prefix
- Only keep units with this prefix.PrefixCleaner
instance.Copyright (c) 2019, Salesforce.com, Inc. All rights reserved. Licensed under the BSD 3-Clause license. For full license text, see the LICENSE file in the repository.