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

O mágico mundo de Houdini

O mágico mundo de Houdini

Muitas pessoas acham o CSS totalmente mágico, tanto quando ele funciona, mas principalmente quando ele não funciona! Já imaginou se conseguíssemos ter as nossas próprias mágicas? Nessa talk falarei sobre as mágicas que vieram com o Houdini e o mundo que está se abrindo com essa nova forma de desenvolver CSS.

Fernanda Bernardo

July 10, 2019
Tweet

More Decks by Fernanda Bernardo

Other Decks in Technology

Transcript

  1. Javascript CSS Suporte de browsers Polyfill / Use! Mata polyfill

    Reclama dos browsers Perda de interesse Suporte de alguns browsers
  2. body { background-color: red; font-size: 1em; } Abstract Syntax Tree

    AST https://astexplorer.net/ background-color: red;
  3. body { background-color: red; font-size: 1em; } Abstract Syntax Tree

    AST https://astexplorer.net/ font-size: 1em;
  4. .bla { width: calc(random * 100%); } .bla { width:

    calc(0.35746 * 100%); } https://philipwalton.com/articles/the-dark-side-of-polyfilling-css/
  5. PARSER CASCADE LAYOUT COMPOSITE PAINT DOM CSSOM Parser Typed OM

    Font Metrics Worklets Box Tree Properties and Values Layout Paint Animation Scroll Custom.
  6. PARSER CASCADE LAYOUT COMPOSITE PAINT DOM CSSOM Parser Typed OM

    Font Metrics Worklets Box Tree Properties and Values Layout Paint Animation Scroll Custom.
  7. Houdini CSS Força tarefa da W3C para definir APIs de

    baixo nível para nós, desenvolvedores, podermos criar, controlar e extender nossas propriedades CSS
  8. element.style.width = ‘100px’; element.style.height = num + ‘px’; Hoje em

    dia… element.style.width element.style.height Estilo inline
  9. PARSER CASCADE LAYOUT COMPOSITE PAINT DOM CSSOM Typed OM Worklets

    Properties and Values Layout Paint Animation
  10. CSS.number CSS.percent // <time> CSS.s CSS.ms // <frequency> CSS.Hz CSS.kHz

    // <resolution> CSS.dpi CSS.dpcm CSS.dppx // <angle> CSS.deg CSS.grad CSS.rad CSS.turn // <length> CSS.em CSS.ex CSS.ch CSS.ic CSS.rem CSS.lh CSS.rlh CSS.vw CSS.vh CSS.vi CSS.vb CSS.vmin CSS.vmax CSS.cm CSS.mm CSS.Q CSS.in CSS.pt CSS.pc CSS.px // <flex> CSS.fr
  11. PARSER CASCADE LAYOUT COMPOSITE PAINT DOM CSSOM Typed OM Worklets

    Properties and Values Layout Paint Animation
  12. CSS custom properties body { --theme-color: cornflowerblue; background-color: var(—theme-color); }

    body.dark-theme { --theme-color: midnightblue; } transition: --theme-color 1s ease-in-out;
  13. CSS custom properties body { --theme-color: background-color: var(—theme-color); transition: --theme-color

    1s ease-in-out; } body.dark-theme { --theme-color: midnightblue; } url(‘oi.png');
  14. window.CSS.registerProperty({ name: '--theme-color', syntax: '<color>', inherits: false, initialValue: ‘tomato' });

    syntax: '<color>', <length> <number> <percentage> <url> <angle> … Properties and Values API
  15. body { --theme-color: background-color: var(—theme-color); transition: --theme-color 1s ease-in-out; }

    body.dark-theme { --theme-color: midnightblue; } url(‘oi.png'); Properties and Values API
  16. PARSER CASCADE LAYOUT COMPOSITE PAINT DOM CSSOM Typed OM Worklets

    Properties and Values Layout Paint Animation
  17. Worklets Workers pequenos, bem específicos e leves. Eles ajudam o

    dev a ter acesso ao processo de renderização do navegador. “mini web workers”
  18. PARSER CASCADE LAYOUT COMPOSITE PAINT DOM CSSOM Typed OM Worklets

    Properties and Values Layout Paint Animation
  19. if ('paintWorklet' in CSS) { CSS.paintWorklet.addModule('worklet.js'); } *.js registerPaint('circle', class

    { static get inputProperties() {} paint(ctx, geom, properties) {} }); worklet.js .circle { background-image: paint(circle); } *.css
  20. registerPaint('circle', class { static get inputProperties() {} paint(ctx, geom, properties)

    { const x = size.width / 2, y = size.height / 2, radius = Math.min(x, y); ctx.fillStyle = ‘pink'; ctx.beginPath(); ctx.arc(x, y, radius, 0, 2 * Math.PI); ctx.fill(); } }); const x = size.width / 2, y = size.height / 2, radius = Math.min(x, y); ctx.fillStyle = ‘pink'; ctx.beginPath(); ctx.arc(x, y, radius, 0, 2 * Math.PI); ctx.fill();
  21. PARSER CASCADE LAYOUT COMPOSITE PAINT DOM CSSOM Typed OM Worklets

    Properties and Values Layout Paint Animation
  22. if ('layoutWorklet' in CSS) { CSS.layoutWorklet.addModule('worklet.js'); } *.js registerLayout(‘masonry', class

    { static get inputProperties() {} layout(children, edges, constraints, properties) {} }); worklet.js .container { display: layout(masonry); } *.css
  23. PARSER CASCADE LAYOUT COMPOSITE PAINT DOM CSSOM Typed OM Worklets

    Properties and Values Layout Paint Animation
  24. if ('animationWorklet' in CSS) { CSS.animationWorklet.addModule('worklet.js'); } *.js registerAnimator(‘parallax', class

    { constructor(options) {} animate(currentTime, effect) { effect.localTime = currentTime; } }); worklet.js
  25. new WorkletAnimation( 'parallax', effectKeyframes, scrollTimeline, {}, ).play(); *.js effectKeyframes, const

    effectKeyframes = new KeyframeEffect( elem, [ {transform: 'scale(1)'}, {transform: 'scale(.25)'}, {transform: 'scale(1)'} ], { duration: timeRange } );
  26. new WorkletAnimation( 'parallax', effectKeyframes, scrollTimeline, {}, ).play(); *.js effectKeyframes, const

    effectKeyframes = new KeyframeEffect( elem, [ {transform: 'scale(1)'}, {transform: 'scale(.25)'}, {transform: 'scale(1)'} ], { duration: timeRange } ); elemento que queremos animar elem,
  27. new WorkletAnimation( 'parallax', effectKeyframes, scrollTimeline, {}, ).play(); *.js effectKeyframes, const

    effectKeyframes = new KeyframeEffect( elem, [ {transform: 'scale(1)'}, {transform: 'scale(.25)'}, {transform: 'scale(1)'} ], { duration: timeRange } ); Animação por Keyframe que queremos aplicar [ {transform: 'scale(1)'}, {transform: 'scale(.25)'}, {transform: 'scale(1)'} ],
  28. new WorkletAnimation( 'parallax', effectKeyframes, scrollTimeline, {}, ).play(); *.js effectKeyframes, const

    effectKeyframes = new KeyframeEffect( elem, [ {transform: 'scale(1)'}, {transform: 'scale(.25)'}, {transform: 'scale(1)'} ], { duration: timeRange } ); duração da animação { duration: timeRange }
  29. new WorkletAnimation( 'parallax', effectKeyframes, scrollTimeline, {}, ).play(); *.js scrollTimeline, const

    scrollTimeline = new ScrollTimeline( scrollSource, timeRange ); scrollSource, Elemento que queremos ver o scroll
  30. new WorkletAnimation( 'parallax', effectKeyframes, scrollTimeline, {}, ).play(); *.js scrollTimeline, const

    scrollTimeline = new ScrollTimeline( scrollSource, timeRange ); timeRange Passos da nossa animação
  31. Links * Exemplos https://css-houdini.rocks/ https://houdini.glitch.me/ https://extra-css.netlify.com/ https://github.com/nucliweb/awesome-css-houdini https://github.com/w3c/css-houdini-drafts * Talks

    State of Houdini - Surma - https://www.youtube.com/watch?v=lK3OiJvwgSc How to Be #Extra with CSS Houdini - Una Kravetz - https://www.youtube.com/watch?v=qY0UF7jaqfs Extendendo o CSS com JavaScript e magia - Mario Souto - https://www.youtube.com/watch?v=qFYHOkuy35A * Slides https://ibevanmeenen.me/houdini/ https://jef.binomed.fr/binomed_docs/Prezs/HoudiniCss