Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Extending CSS using Houdini

Extending CSS using Houdini

CSS Houdini is a group of low-level browser APIs that allows developers to hook into the browser's rendering engine, allowing for custom paint, layout, and other styling capabilities. In this deck, we will learn about the various CSS Houdini APIs and how to use them.

Arnelle Balane

February 27, 2021
Tweet

More Decks by Arnelle Balane

Other Decks in Technology

Transcript

  1. Arnelle Balane Tech Lead @ Newlogic Google Developers Expert for

    Web Technologies @arnellebalane UncaughtException @uncaughtxcptn Subscribe to our channel! /UncaughtException
  2. Houdini • a collection of JavaScript APIs • allows us

    to hook into the browser’s rendering engine
  3. Houdini • a collection of JavaScript APIs • allows us

    to hook into the browser’s rendering engine • extends CSS, at CSS speed!
  4. class MyWorklet { paint() { </ magic ✨ } }

    registerPaint('my-worklet', MyWorklet); worklet.js
  5. class MyWorklet { paint(ctx, geometry) { </ magic ✨ }

    } registerPaint('my-worklet', MyWorklet); worklet.js
  6. class MyWorklet { static get inputProperties() { return ['<-line-width', '<-line-color'];

    } paint(ctx, geom, props) { const width = props.get('<-line-width'); const color = props.get('<-line-color'); </ magic ✨ } } worklet.js
  7. CSS.registerProperty({ name: '<-line-width', syntax: '<length>', inherits: false, initialValue: 3px });

    index.js <length> <number> <percentage> <color> <image> <url> <angle> <<. https://www.w3.org/TR/css-propertie s-values-api-1/#syntax-string
  8. <-line-width: 3rem; <-line-color: #ff0000; CSSUnitValue { value: 48, unit: 'px'

    } CSSStyleValue { 'rgb(255, 0, 0)' } ✨ Houdini TypedOM
  9. class MyWorklet { static get inputProperties() {✨} paint(ctx, geom, props)

    { ctx.lineWidth = props.get('<-line-width').value; ctx.strokeStyle = props.get('<-line-color').toString(); </ magic ✨ } } worklet.js
  10. class MyWorklet { static get inputProperties() {✨} paint(ctx, geom, props)

    { ctx.lineWidth = props.get('<-line-width').value; ctx.strokeStyle = props.get('<-line-color').toString(); </ magic ✨ } } worklet.js
  11. class MyWorklet { static get inputArguments() { return ['<length>', '<color>'];

    } paint(ctx, geom, props, args) { const width = args[0].value; const color = args[0].toString(); </ magic ✨ } } worklet.js