comic-plus
Version:
<p align="center"> <img width="200px" src="./logo.png"/> </p>
86 lines (85 loc) • 3.02 kB
JavaScript
import { defineComponent, ref, computed, watch, onMounted, nextTick, openBlock, createBlock, Transition, withCtx, withDirectives, createElementVNode, normalizeClass, normalizeStyle, resolveDynamicComponent, createElementBlock, toDisplayString, createCommentVNode, vShow, isVNode } from "vue";
import "../style/loading.css";
import { useGlobal, getNextZIndex, getMaxZIndex } from "../../../utils/config.mjs";
import { useLookScroll } from "../../../utils/look-scroll.mjs";
import { isVueComponent } from "../../../utils/typescript.mjs";
import "@vueuse/core";
import { loadingProps } from "./main.props.mjs";
const _hoisted_1 = {
key: 0,
style: { "margin-top": "4px" }
};
const _sfc_main = /* @__PURE__ */ defineComponent({
...{
name: "CuLoading"
},
__name: "main",
props: loadingProps,
setup(__props, { expose: __expose }) {
const props = __props;
const zIndex = ref(0);
const visible = ref(false);
const lookScroll = ref(false);
const { globalLoadingRender } = useGlobal();
if (props.global) {
useLookScroll(lookScroll);
}
const style = computed(() => {
return {
"z-index": zIndex.value,
background: props.background,
color: props.color
};
});
const isCanRender = (value) => {
return isVueComponent(value) || isVNode(value);
};
const iconRender = computed(() => {
return isCanRender(props.icon) ? props.icon : isCanRender(globalLoadingRender.value) ? globalLoadingRender.value : null;
});
function updateVisible(val) {
visible.value = val;
}
watch(visible, (val) => {
if (val) {
zIndex.value = props.global ? getNextZIndex() : getMaxZIndex(props.target);
}
});
onMounted(() => {
const position = window.getComputedStyle(props.target).position;
if (position === "static") {
props.target.style.setProperty("position", "relative");
}
nextTick(() => {
visible.value = props.defaultVisible;
});
});
__expose({
visible,
updateVisible
});
return (_ctx, _cache) => {
return openBlock(), createBlock(Transition, {
name: "cu-fade",
onBeforeEnter: _cache[0] || (_cache[0] = ($event) => lookScroll.value = true),
onAfterLeave: _cache[1] || (_cache[1] = ($event) => lookScroll.value = false)
}, {
default: withCtx(() => [
withDirectives(createElementVNode("div", {
class: normalizeClass(["cu-loading", { blur: _ctx.blur, global: _ctx.global }]),
style: normalizeStyle(style.value)
}, [
(openBlock(), createBlock(resolveDynamicComponent(iconRender.value), { class: "is-loading cu-loading__icon" })),
_ctx.text ? (openBlock(), createElementBlock("span", _hoisted_1, toDisplayString(_ctx.text), 1)) : createCommentVNode("", true)
], 6), [
[vShow, visible.value]
])
]),
_: 1
});
};
}
});
export {
_sfc_main as default
};