CKTIS / CSS
Propriedade CSS `mask-mode`
`mask-mode` escolhe por camada se os valores da máscara vêm do alfa, da luminância multiplicada pelo alfa ou do tipo da fonte.
Versão: CSS modules; captured CSSWG editor index includes draft and obsolete features requiring review
Sintaxe
<masking-mode>#mask-mode escolhe por camada se os valores da máscara vêm do alfa, da luminância multiplicada pelo alfa ou do tipo da fonte.
O exemplo rasterizado no Chromium usa preto opaco: alpha mantém-no visível com 255, luminance oculta-o com 0 e match-source produz 255 para um gradiente CSS, mas 0 para um URL de <mask mask-type="luminance">.
Gramática: <masking-mode>#.
match-source significa alfa para uma fonte <image> comum, mas num URL para um SVG <mask> segue o respetivo mask-type; alpha ou luminance explícitos sobrepõem-se. Preto totalmente opaco é assim uma máscara total no modo alfa e nula no modo luminância. O valor inicial é match-source; a lista repete-se ou é truncada ao número de camadas mask-image e não afeta mask-border-source.
Exemplos
<!doctype html><meta charset="utf-8"><svg id="stage" xmlns="http://www.w3.org/2000/svg" width="150" height="20"><defs><mask id="lum" maskUnits="userSpaceOnUse" x="120" y="0" width="30" height="20" mask-type="luminance"><rect x="120" width="30" height="20" fill="black"/></mask></defs><rect id="alphaBox" width="30" height="20" fill="orange" style="mask-image:linear-gradient(black,black);mask-mode:alpha"/><rect id="luminanceBox" x="40" width="30" height="20" fill="orange" style="mask-image:linear-gradient(black,black);mask-mode:luminance"/><rect id="matchImage" x="80" width="30" height="20" fill="orange" style="mask-image:linear-gradient(black,black);mask-mode:match-source"/><rect id="matchMask" x="120" width="30" height="20" fill="orange" style="mask-image:url(#lum);mask-mode:match-source"/></svg><pre id="result"></pre><script>
const rasterize=svg=>new Promise((resolve,reject)=>{const image=new Image();image.onload=()=>{const canvas=document.createElement('canvas');canvas.width=Number(svg.getAttribute('width'));canvas.height=Number(svg.getAttribute('height'));const context=canvas.getContext('2d');context.drawImage(image,0,0);resolve(context)};image.onerror=()=>reject(new Error('SVG rasterization failed'));image.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(new XMLSerializer().serializeToString(svg))});
const alpha=(context,x,y)=>context.getImageData(x,y,1,1).data[3];
(async()=>{const context=await rasterize(stage),a=alpha(context,15,10),l=alpha(context,55,10),mi=alpha(context,95,10),mm=alpha(context,135,10),modes=[alphaBox,luminanceBox,matchImage,matchMask].map(node=>getComputedStyle(node).maskMode).join('/');if(a<250||l>5||mi<250||mm>5||modes!=='alpha/luminance/match-source/match-source')throw new Error('mask-mode interpretation mismatch');result.textContent='alpha='+a+'; luminance='+l+'; match-image='+mi+'; match-mask='+mm+'; modes='+modes})().catch(error=>result.textContent='ERROR:'+error.message);
</script>Resultado
alpha=255; luminance=0; match-image=255; match-mask=0; modes=alpha/luminance/match-source/match-source
O exemplo foi executado localmente numa sessão Chrome isolada e sem rede; o resultado provém da API CSS do navegador.