Skip to content

Commit 151275e

Browse files
committed
fix font cache issue in text block
1 parent 6817185 commit 151275e

File tree

1 file changed

+2
-37
lines changed

1 file changed

+2
-37
lines changed

src/blocks/text/index.js

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -97,28 +97,6 @@ const text = function (el, config) {
9797
</div>`)
9898
el.appendChild(child)
9999

100-
// if there are images, let's exploit the alt attribute if contains a number
101-
// as a scale multiplier
102-
// let images = child.querySelectorAll('img')
103-
// if (images) {
104-
// images = [...images].forEach(img => {
105-
// const a = img.getAttribute('alt')
106-
// if (a) {
107-
// const val = +a
108-
// if (val > 0) img.style.height = 4 * val + 'em'
109-
// }
110-
// })
111-
// }
112-
113-
// let isObserved = false
114-
// let isComputing = false
115-
// const resizeObserver = new ResizeObserver(() => {
116-
// if (!isComputing) {
117-
// resizeObserver.disconnect()
118-
// compute()
119-
// }
120-
// })
121-
122100
// this is the iterative scale routine
123101
const compute = () => {
124102
child.style.setProperty('--textSize', `${fsize}${funit}`)
@@ -134,12 +112,6 @@ const text = function (el, config) {
134112
return false
135113
}
136114

137-
// isComputing = true
138-
// if (!isObserved) {
139-
// resizeObserver.observe(el)
140-
// isObserved = true
141-
// }
142-
143115
const mbox = mel.getBoundingClientRect()
144116
const bbox = el.getBoundingClientRect()
145117

@@ -152,25 +124,18 @@ const text = function (el, config) {
152124
setTimeout(() => {
153125
child.classList.remove(css.promise)
154126
resolve(that)
155-
// isComputing = false
156127
})
157128
}
158129
}
159130

160131
if (config.font) {
161-
fetch(config.font).then(res => {
162-
setTimeout(compute)
163-
}).catch(err => {
164-
console.log('error on preload font', err)
132+
document.fonts.ready.then(() => {
165133
setTimeout(compute)
166134
})
167135
} else {
168136
setTimeout(compute)
169137
}
170-
171-
that.destroy = () => {
172-
// resizeObserver.disconnect()
173-
}
138+
setTimeout(compute)
174139
})
175140
}
176141

0 commit comments

Comments
 (0)