CKTIS / CSS
Propriedade CSS `mask-clip`
`mask-clip` restringe a área de pintura de cada máscara de imagem a uma caixa geométrica escolhida, ou remove essa restrição com `no-clip`.
Versão: CSS modules; captured CSSWG editor index includes draft and obsolete features requiring review
Sintaxe
[ <coord-box> | no-clip ]#mask-clip restringe a área de pintura de cada máscara de imagem a uma caixa geométrica escolhida, ou remove essa restrição com no-clip.
O exemplo aplica uma máscara opaca a dois retângulos SVG com traço: fill-box produz alfa 0 na região só do traço e 255 dentro do preenchimento, enquanto stroke-box mantém também o ponto do traço com alfa 255.
Gramática: [ <coord-box> | no-clip ]#.
As caixas CSS incluem content-box, padding-box e border-box; em SVG, fill-box, stroke-box e view-box referem os limites correspondentes. mask-clip não controla uma referência a um elemento SVG <mask> — os atributos da máscara definem a área. O valor é uma lista por camadas, começa em border-box e no-clip deixa a pintura sem recorte.
Exemplos
<!doctype html><meta charset="utf-8"><svg id="stage" xmlns="http://www.w3.org/2000/svg" width="110" height="50"><rect id="fill" x="10" y="10" width="30" height="30" fill="blue" stroke="blue" stroke-width="10" style="mask-image:linear-gradient(black,black);mask-clip:fill-box"/><rect id="stroke" x="70" y="10" width="30" height="30" fill="blue" stroke="blue" stroke-width="10" style="mask-image:linear-gradient(black,black);mask-clip:stroke-box"/></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),fillStroke=alpha(context,6,25),fillCenter=alpha(context,20,25),strokeStroke=alpha(context,66,25),a=getComputedStyle(fill).maskClip,b=getComputedStyle(stroke).maskClip;if(fillStroke>5||fillCenter<250||strokeStroke<250||a!=='fill-box'||b!=='stroke-box')throw new Error('mask-clip geometry mismatch');result.textContent='fill-stroke='+fillStroke+'; fill-center='+fillCenter+'; stroke-stroke='+strokeStroke+'; computed='+a+'/'+b})().catch(error=>result.textContent='ERROR:'+error.message);
</script>Resultado
fill-stroke=0; fill-center=255; stroke-stroke=255; computed=fill-box/stroke-box
O exemplo foi executado localmente numa sessão Chrome isolada e sem rede; o resultado provém da API CSS do navegador.