mirror of
https://github.com/paricafe/misskey.git
synced 2024-12-02 12:56:44 -06:00
21 lines
455 B
TypeScript
21 lines
455 B
TypeScript
import { Directive } from 'vue';
|
|
|
|
const map = new WeakMap<HTMLElement, ResizeObserver>();
|
|
|
|
export default {
|
|
mounted(el: HTMLElement, binding, vn) {
|
|
const ro = new ResizeObserver((entries, observer) => {
|
|
el.style.setProperty('--containerHeight', el.offsetHeight + 'px');
|
|
});
|
|
ro.observe(el);
|
|
map.set(el, ro);
|
|
},
|
|
|
|
unmounted(el, binding, vn) {
|
|
const ro = map.get(el);
|
|
if (ro) {
|
|
ro.disconnect();
|
|
map.delete(el);
|
|
}
|
|
},
|
|
} as Directive;
|