fastdom: more batch

This commit is contained in:
jean-emmanuel 2022-01-20 20:23:55 +01:00
parent e33d7263ee
commit 3e06e52948
3 changed files with 43 additions and 27 deletions

View file

@ -1,8 +1,9 @@
var chroma = require('chroma-js')
var chroma = require('chroma-js'),
fastdom = require('fastdom')
module.exports = (container)=>{
setTimeout(()=>{
fastdom.measure(()=>{
var computedStyle = window.getComputedStyle(container),
alpha = parseFloat(computedStyle.getPropertyValue('--alpha-scrollbar')),
@ -18,10 +19,12 @@ module.exports = (container)=>{
}
if (color) {
try {
container.style.setProperty('--color-scrollbar', chroma(color).alpha(alpha).css())
container.style.setProperty('--color-scrollbar-on', chroma(color).alpha(alphaOn).css())
} catch(e) {}
fastdom.mutate(()=>{
try {
container.style.setProperty('--color-scrollbar', chroma(color).alpha(alpha).css())
container.style.setProperty('--color-scrollbar-on', chroma(color).alpha(alphaOn).css())
} catch(e) {}
})
}
})

View file

@ -70,12 +70,6 @@ class Canvas extends Widget {
this.height = height
this.width = width
// fastdom.mutate(()=>{
this.canvas.setAttribute('width', width * ratio)
this.canvas.setAttribute('height', height * ratio)
this.container.style.setProperty('--widget-height', this.height + 'rem')
this.container.style.setProperty('--widget-width', this.width + 'rem')
// })
this.parsersLocalScope.height = this.height
this.parsersLocalScope.width = this.width
@ -86,14 +80,24 @@ class Canvas extends Widget {
this.ctx.scale(ratio, ratio)
}
this.cacheCanvasStyle(style)
fastdom.measure(()=>{
this.cacheCanvasStyle(style)
fastdom.mutate(()=>{
if (!this.hasSize) {
this.hasSize = true
this.setVisibility()
}
this.canvas.setAttribute('width', width * ratio)
this.canvas.setAttribute('height', height * ratio)
this.container.style.setProperty('--widget-height', this.height + 'rem')
this.container.style.setProperty('--widget-width', this.width + 'rem')
if (!this.hasSize) {
this.hasSize = true
this.setVisibility()
}
this.batchDraw()
})
})
this.batchDraw()
}
@ -109,7 +113,6 @@ class Canvas extends Widget {
style = style || window.getComputedStyle(this.canvas)
for (var data of this.constructor.cssVariables) {
var val = style.getPropertyValue(data.css).trim()
@ -138,6 +141,7 @@ class Canvas extends Widget {
this.ctx.textBaseline = 'middle'
this.ctx.textAlign = this.textAlign
}
clear() {
@ -184,19 +188,27 @@ class Canvas extends Widget {
case 'alphaFillOff':
case 'alphaFillOn':
case 'colorBg':
setTimeout(()=>{
fastdom.measure(()=>{
this.cacheCanvasStyle()
this.batchDraw()
},10)
fastdom.mutate(()=>{
this.batchDraw()
})
})
// setTimeout(()=>{
// this.cacheCanvasStyle()
// this.batchDraw()
// },10)
return
case 'css':
case 'lineWidth':
case 'padding':
resize.check(this.canvas, true)
setTimeout(()=>{
fastdom.measure(()=>{
this.cacheCanvasStyle()
this.batchDraw()
},10)
fastdom.mutate(()=>{
this.batchDraw()
})
})
return
}

View file

@ -6,7 +6,8 @@ var Container = require('../common/container'),
setScrollbarColor = require('../../ui/scrollbar-color'),
iOS13 = require('../../ui/ios') === 13,
Fader = require('../sliders/fader'), faderDefaults,
resize = require('../../events/resize')
resize = require('../../events/resize'),
fastdom = require('fastdom')
class Panel extends Container() {
@ -140,7 +141,7 @@ class Panel extends Container() {
this.scroll = [0, 0]
this.scrollWidth = 1
this.scrollHeight = 1
setTimeout(()=>{
fastdom.measure(()=>{
this.scrollWidth = this.widget.scrollWidth - this.widget.clientWidth
this.scrollHeight = this.widget.scrollHeight - this.widget.clientHeight
})