Slide 1

Slide 1 text

Extending CSS using Houdini Arnelle Balane @arnellebalane

Slide 2

Slide 2 text

Arnelle Balane Tech Lead @ Newlogic Google Developers Expert for Web Technologies @arnellebalane UncaughtException @uncaughtxcptn Subscribe to our channel! /UncaughtException

Slide 3

Slide 3 text

bit.ly/cds-cebu-houdini

Slide 4

Slide 4 text

what is Houdini

Slide 5

Slide 5 text

Houdini ● a collection of JavaScript APIs

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Houdini ● a collection of JavaScript APIs ● allows us to hook into the browser’s rendering engine ● extends CSS, at CSS speed!

Slide 8

Slide 8 text

ishoudinireadyyet.com

Slide 9

Slide 9 text

How browsers render pages

Slide 10

Slide 10 text

Houdini Paint API

Slide 11

Slide 11 text

Paint API Draw an image as background using JavaScript

Slide 12

Slide 12 text

paint()

Slide 13

Slide 13 text

paint(worklet)

Slide 14

Slide 14 text

background-image: paint(worklet);

Slide 15

Slide 15 text

background-image: paint(worklet, red);

Slide 16

Slide 16 text

background-image: paint(worklet, red); <-custom-prop: 12px;

Slide 17

Slide 17 text

CSS.paintWorklet .addModule('worklet.js'); Load the paint worklet

Slide 18

Slide 18 text

houdini.how

Slide 19

Slide 19 text

paintlets.herokuapp.com

Slide 20

Slide 20 text

npm: houdini paint worklet

Slide 21

Slide 21 text

import worklet from "url-loader!/worklet.js"; CSS.paintWorklet.addModule(worklet); Usage with bundlers

Slide 22

Slide 22 text

Demo time! ✨

Slide 23

Slide 23 text

Creating our own Paint Worklet

Slide 24

Slide 24 text

class MyWorklet { paint() {

Slide 25

Slide 25 text

class MyWorklet { paint() {

Slide 26

Slide 26 text

class MyWorklet { paint(ctx, geometry) {

Slide 27

Slide 27 text

class MyWorklet { paint(ctx, geom) { ctx.beginPath(); ctx.moveTo(0, 0); ctx.lineTo(geom.width, geom.height); ctx.stroke(); } } worklet.js

Slide 28

Slide 28 text

class MyWorklet { paint(ctx, geom) { ctx.beginPath(); ctx.moveTo(0, 0); ctx.lineTo(geom.width, geom.height); ctx.stroke(); } } worklet.js

Slide 29

Slide 29 text

class MyWorklet { static get inputProperties() { return ['<-line-width', '<-line-color']; } paint(ctx, geom, props) {

Slide 30

Slide 30 text

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');

Slide 31

Slide 31 text

<-line-width: 3px; <-line-color: red; CSSUnparsedValue { ' 3px' } CSSUnparsedValue { ' red' }

Slide 32

Slide 32 text

<-line-width: 3rem; <-line-color: red; CSSUnparsedValue { ' 3rem' } CSSUnparsedValue { ' red' }

Slide 33

Slide 33 text

CSS.registerProperty({ name: '<-line-width', syntax: '', inherits: false, initialValue: 3px }); index.js Houdini Properties & Values API

Slide 34

Slide 34 text

CSS.registerProperty({ name: '<-line-width', syntax: '', inherits: false, initialValue: 3px }); index.js <<. https://www.w3.org/TR/css-propertie s-values-api-1/#syntax-string

Slide 35

Slide 35 text

@property <-line-width { syntax: ''; inherits: false; initial-value: 3px; }

Slide 36

Slide 36 text

<-line-width: 3px; <-line-color: red; CSSUnitValue { value: 3, unit: 'px' } CSSStyleValue { 'rgb(255, 0, 0)' }

Slide 37

Slide 37 text

<-line-width: 3rem; <-line-color: #ff0000; CSSUnitValue { value: 48, unit: 'px' } CSSStyleValue { 'rgb(255, 0, 0)' }

Slide 38

Slide 38 text

<-line-width: 3rem; <-line-color: #ff0000; CSSUnitValue { value: 48, unit: 'px' } CSSStyleValue { 'rgb(255, 0, 0)' } ✨ Houdini TypedOM

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

class MyWorklet { static get inputArguments() { return ['', '']; } paint(ctx, geom, props, args) { const width = args[0].value; const color = args[0].toString();

Slide 42

Slide 42 text

Demo time! ✨

Slide 43

Slide 43 text

css-paint-polyfill

Slide 44

Slide 44 text

import 'css-paint-polyfill'; Using the polyfill

Slide 45

Slide 45 text

What’s so exciting about Houdini?

Slide 46

Slide 46 text

Houdini ● Fancy backgrounds ● Reduce number of DOM nodes ● CSS polyfills

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

css-houdini.rocks

Slide 51

Slide 51 text

Thank you! Extending CSS using Houdini Arnelle Balane @arnellebalane