38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
import { ref, watchEffect, watch, getCurrentInstance, onBeforeUnmount, onDeactivated, onActivated } from 'vue';
|
|
import { i as injectHead, r as resolveUnrefHeadInput } from './vue.ziyDaVMR.mjs';
|
|
|
|
function useHead(input, options = {}) {
|
|
const head = options.head || injectHead();
|
|
if (head) {
|
|
if (!head.ssr)
|
|
return clientUseHead(head, input, options);
|
|
return head.push(input, options);
|
|
}
|
|
}
|
|
function clientUseHead(head, input, options = {}) {
|
|
const deactivated = ref(false);
|
|
const resolvedInput = ref({});
|
|
watchEffect(() => {
|
|
resolvedInput.value = deactivated.value ? {} : resolveUnrefHeadInput(input);
|
|
});
|
|
const entry = head.push(resolvedInput.value, options);
|
|
watch(resolvedInput, (e) => {
|
|
entry.patch(e);
|
|
});
|
|
const vm = getCurrentInstance();
|
|
if (vm) {
|
|
onBeforeUnmount(() => {
|
|
entry.dispose();
|
|
});
|
|
onDeactivated(() => {
|
|
deactivated.value = true;
|
|
});
|
|
onActivated(() => {
|
|
deactivated.value = false;
|
|
});
|
|
}
|
|
return entry;
|
|
}
|
|
|
|
export { useHead as u };
|