@@ -18865,33 +18865,54 @@ const index$e = /* @__PURE__ */ defineBuiltInComponent({
1886518865 };
1886618866 }
1886718867});
18868- const coefficientMap = {
18869- medium: 1,
18870- thick: 2
18871- };
18868+ class UniVueElement extends HTMLElement {
18869+ }
18870+ class UniLoadingElement extends UniVueElement {
18871+ }
1887218872function useLoadingStyle(targetElement, bold) {
1887318873 const loadingSize = ref("16px");
18874- const loadingBorderWidth = ref("0px");
18874+ const loadingBorderWidth = ref("1px");
18875+ const loadingBorderRadius = ref("8px");
18876+ let observer = null;
1887518877 const calculateLoadingWidth = (element, bold2) => {
18876- if (!element)
18877- return;
18878- const computedStyle = window.getComputedStyle(element);
18879- const width = parseFloat(computedStyle.width);
18880- const height = parseFloat(computedStyle.height);
18881- const coefficient = coefficientMap[bold2 ? "thick" : "medium"];
18878+ const { width, height } = element.getBoundingClientRect();
18879+ const coefficient = bold2 ? 2 : 1;
1888218880 const minSide = Math.min(width, height);
1888318881 const calculatedWidth = minSide / 16 * coefficient;
1888418882 loadingSize.value = `${minSide}px`;
1888518883 loadingBorderWidth.value = `${calculatedWidth}px`;
18884+ loadingBorderRadius.value = `${minSide / 2}px`;
18885+ };
18886+ const setupObserver = (cb) => {
18887+ const el = targetElement.value;
18888+ if (!el)
18889+ return;
18890+ observer = new ResizeObserver((entries2) => {
18891+ cb(el);
18892+ });
18893+ observer.observe(el);
1888618894 };
1888718895 onMounted(() => {
18896+ setupObserver((el) => {
18897+ calculateLoadingWidth(el, bold.value);
18898+ });
1888818899 watchEffect(() => {
18889- calculateLoadingWidth(targetElement.value, bold.value);
18900+ const _bold = bold.value;
18901+ const el = targetElement.value;
18902+ if (el !== null) {
18903+ calculateLoadingWidth(el, _bold);
18904+ }
1889018905 });
1889118906 });
18907+ onUnmounted(() => {
18908+ if (observer) {
18909+ observer.disconnect();
18910+ }
18911+ });
1889218912 return {
1889318913 size: loadingSize,
18894- borderWidth: loadingBorderWidth
18914+ borderWidth: loadingBorderWidth,
18915+ borderRadius: loadingBorderRadius
1889518916 };
1889618917}
1889718918var __defProp2 = Object.defineProperty;
@@ -18914,7 +18935,12 @@ var __spreadValues = (a2, b) => {
1891418935};
1891518936var __spreadProps = (a2, b) => __defProps(a2, __getOwnPropDescs(b));
1891618937const _sfc_main$4 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, {
18917- name: "Loading",
18938+ name: "loading",
18939+ // @ts-ignore
18940+ rootElement: {
18941+ name: "uni-loading-element",
18942+ class: UniLoadingElement
18943+ },
1891818944 __reserved: true,
1891918945 compatConfig: {
1892018946 MODE: 3
0 commit comments