@@ -469,18 +469,32 @@ if (typeof HTMLElement !== 'undefined') {
469469 const set_shader_prop = v => {
470470 element . style . setProperty ( 'background' , 'url("' + v + '") no-repeat 50%/cover' ) ;
471471 }
472-
473472 const tick = ( [ v , animated ] ) => {
474- if ( animated ) {
475- this . animations . push ( create_animation ( t => {
476- set_shader_prop ( v ( t , width , height , images ) ) ;
477- } ) ) ;
473+ if ( target . type === 'content' ) {
474+ let canvas = v ( 0 , width , height , images ) ;
475+ element . replaceChildren ( canvas ) ;
476+ if ( animated ) {
477+ this . animations . push ( create_animation ( t => {
478+ v ( t , width , height , images ) ;
479+ } ) ) ;
480+ } else {
481+ let render = this . shader_renders . get ( target . selector ) ;
482+ if ( ! this . shader_renders . has ( target . selector ) ) {
483+ this . shader_renders . set ( target . selector , v ) ;
484+ }
485+ }
478486 } else {
479- let render = this . shader_renders . get ( target . selector ) ;
480- if ( ! this . shader_renders . has ( target . selector ) ) {
481- this . shader_renders . set ( target . selector , v ) ;
487+ if ( animated ) {
488+ this . animations . push ( create_animation ( t => {
489+ set_shader_prop ( v ( t , width , height , images ) . toDataURL ( ) ) ;
490+ } ) ) ;
491+ } else {
492+ let render = this . shader_renders . get ( target . selector ) ;
493+ if ( ! this . shader_renders . has ( target . selector ) ) {
494+ this . shader_renders . set ( target . selector , v ) ;
495+ }
496+ set_shader_prop ( v ( 0 , width , height , images ) . toDataURL ( ) ) ;
482497 }
483- set_shader_prop ( v ( 0 , width , height , images ) ) ;
484498 }
485499 }
486500
@@ -498,7 +512,7 @@ if (typeof HTMLElement !== 'undefined') {
498512 } ) ) . then ( fn ) ;
499513 }
500514
501- if ( ! this . observers . has ( target ) ) {
515+ if ( ! this . observers . has ( target . selector ) ) {
502516 let observer = new ResizeObserver ( ( ) => {
503517 let rect = element . getBoundingClientRect ( ) ;
504518 width = rect . width ;
@@ -511,7 +525,7 @@ if (typeof HTMLElement !== 'undefined') {
511525 images = result ;
512526 let render = this . shader_renders . get ( target . selector ) ;
513527 if ( render ) {
514- set_shader_prop ( render ( 0 , width , height , images ) ) ;
528+ set_shader_prop ( render ( 0 , width , height , images ) . toDataURL ( ) ) ;
515529 }
516530 } ) ;
517531 } ) ;
@@ -640,11 +654,12 @@ if (typeof HTMLElement !== 'undefined') {
640654
641655 build_grid ( compiled , grid ) {
642656 const { has_transition, has_animation } = compiled . props ;
643- let has_delay = ( has_transition || has_animation ) ;
644657 const { uniforms, content, styles } = compiled ;
658+ let has_delay = ( has_transition || has_animation ) ;
659+ let has_content = Object . keys ( content ) . length ;
645660 this . doodle . innerHTML = `
646661 <style>${ get_basic_styles ( grid ) + styles . main } </style>
647- ${ ( styles . cells || styles . container || Object . keys ( content ) . length ) ? create_grid ( grid , compiled ) : '' }
662+ ${ ( styles . cells || styles . container || has_content ) ? create_grid ( grid , compiled ) : '' }
648663 ` ;
649664 if ( has_delay ) {
650665 this . reflow ( ) ;
@@ -654,7 +669,9 @@ if (typeof HTMLElement !== 'undefined') {
654669 get_basic_styles ( grid ) +
655670 styles . all
656671 ) ) ;
657-
672+ if ( has_content ) {
673+ replace ( Object . values ( compiled . content ) . join ( ' ' ) ) ;
674+ }
658675 this . bind_uniforms ( uniforms ) ;
659676 }
660677
@@ -789,7 +806,7 @@ function get_basic_styles(grid) {
789806 svg {
790807 position: absolute;
791808 }
792- grid, svg {
809+ grid, svg, canvas {
793810 width: 100%;
794811 height: 100%
795812 }
@@ -798,8 +815,11 @@ function get_basic_styles(grid) {
798815
799816function create_cell ( x , y , z , content , child = '' ) {
800817 let id = cell_id ( x , y , z ) ;
801- let head = content [ '#' + id ] ?? '' ;
802818 let tail = child ?? '' ;
819+ let head = content [ '#' + id ] ?? '' ;
820+ if ( head . startsWith ( '${shader' ) ) {
821+ head = '' ;
822+ }
803823 return `<cell id="${ id } " part="cell">${ head } ${ tail } </cell>` ;
804824}
805825
0 commit comments