maz-ui 4.7.5 → 4.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/MazAccordion.CKnz73h4.js +1 -0
- package/dist/chunks/MazAlert.B8hE7wet.js +1 -0
- package/dist/chunks/MazAnimatedCounter.GLLYbZAz.js +1 -0
- package/dist/chunks/MazAnimatedElement._8NY8WgC.js +1 -0
- package/dist/chunks/MazAnimatedText.BSZ8FNf-.js +1 -0
- package/dist/chunks/MazAvatar.vO5VNPi8.js +1 -0
- package/dist/chunks/MazBackdrop.Cjbwi8-V.js +1 -0
- package/dist/chunks/MazBadge.BBZJgHXm.js +1 -0
- package/dist/chunks/MazBottomSheet.WgZ6qobx.js +1 -0
- package/dist/chunks/MazBtn.Cc9C1v2l.js +1 -0
- package/dist/chunks/MazBtnGroup.3B1XcqWM.js +1 -0
- package/dist/chunks/MazCard.YYC0LaHY.js +1 -0
- package/dist/chunks/MazCardSpotlight.SpZF61hl.js +1 -0
- package/dist/chunks/MazCarousel.1NT4jcvR.js +1 -0
- package/dist/chunks/MazChart.CDZ2PBTC.js +1 -0
- package/dist/chunks/MazCheckbox.DurIbKdf.js +1 -0
- package/dist/chunks/MazChecklist.D9ezwGpQ.js +1 -0
- package/dist/chunks/MazCircularProgressBar.rATx_hD9.js +1 -0
- package/dist/chunks/MazContainer.zXcfMOs-.js +1 -0
- package/dist/chunks/MazDatePicker.KUP34cbV.js +1 -0
- package/dist/chunks/MazDialog.CtKF3Xzo.js +1 -0
- package/dist/chunks/MazDialogConfirm.CAAHeBPE.js +1 -0
- package/dist/chunks/MazDrawer.Dc_RGG8a.js +1 -0
- package/dist/chunks/MazDropdown.2DUcivzO.js +1 -0
- package/dist/chunks/MazDropzone.CiWiPcFM.js +1 -0
- package/dist/chunks/MazExpandAnimation.CMMwtuQA.js +1 -0
- package/dist/chunks/MazFullscreenLoader.BIVRcZJ8.js +1 -0
- package/dist/chunks/MazGallery.CEmGy0K9.js +1 -0
- package/dist/chunks/MazIcon.ZWAk25ZX.js +1 -0
- package/dist/chunks/MazInput.DJjWLaKg.js +1 -0
- package/dist/chunks/MazInputCode.DKnl3i-X.js +1 -0
- package/dist/chunks/MazInputNumber.B42Mn-9h.js +1 -0
- package/dist/chunks/MazInputPhoneNumber.CLivThtK.js +1 -0
- package/dist/chunks/MazInputPrice.BeL-M944.js +1 -0
- package/dist/chunks/MazInputTags.CIVT9F6Q.js +1 -0
- package/dist/chunks/MazLazyImg.-EMwandx.js +1 -0
- package/dist/chunks/MazLink.BOpxMATj.js +1 -0
- package/dist/chunks/MazLoadingBar.C86AX2Tk.js +1 -0
- package/dist/chunks/MazPagination.CNNKXBsg.js +1 -0
- package/dist/chunks/MazPickerCalendarDays.CSZZbk5Z.js +1 -0
- package/dist/chunks/MazPickerCalendarGrid.DrUHBH6-.js +1 -0
- package/dist/chunks/MazPickerContainer.BZ74M74V.js +1 -0
- package/dist/chunks/MazPopover.Co8BEopX.js +1 -0
- package/dist/chunks/MazPullToRefresh.DMtb6Oa3.js +1 -0
- package/dist/chunks/MazRadio.75ipjTw2.js +1 -0
- package/dist/chunks/MazRadioButtons.DenHCgB3.js +1 -0
- package/dist/chunks/MazReadMore.CDXacQIw.js +1 -0
- package/dist/chunks/MazReadingProgressBar.828Y0mxA.js +1 -0
- package/dist/chunks/MazSelect.yYFAbBb5.js +1 -0
- package/dist/chunks/MazSelectCountry.DvVgk2es.js +1 -0
- package/dist/chunks/MazSkeleton.BewTYJC2.js +1 -0
- package/dist/chunks/MazSlider.BS5QHWK6.js +1 -0
- package/dist/chunks/MazSpinner.D3NN2pow.js +1 -0
- package/dist/chunks/MazStepper.DTu8HG9T.js +1 -0
- package/dist/chunks/MazSwitch.Dvmj-rTW.js +1 -0
- package/dist/chunks/MazTable.DnOehvN6.js +1 -0
- package/dist/chunks/MazTableCell.xbm2NGWL.js +1 -0
- package/dist/chunks/MazTableRow.B5dJiXk1.js +1 -0
- package/dist/chunks/MazTableTitle.DNA_1mCy.js +1 -0
- package/dist/chunks/MazTabs.-0-YP3QQ.js +1 -0
- package/dist/chunks/MazTabsBar.D2JVKMS7.js +1 -0
- package/dist/chunks/MazTabsContent.C9omK25X.js +1 -0
- package/dist/chunks/MazTabsContentItem.mJEAS5R8.js +1 -0
- package/dist/chunks/MazTextarea.BliEP5G5.js +1 -0
- package/dist/chunks/MazUiProvider.BgN8V0lD.js +1 -0
- package/dist/chunks/_plugin-vue_export-helper.ChmETRGw.js +1 -0
- package/dist/chunks/dialog.DexeIC3K.js +1 -0
- package/dist/chunks/dom-events.BPrKJiCz.js +1 -0
- package/dist/chunks/resolveLinkComponent.DAc3sqGH.js +1 -0
- package/dist/chunks/toast.UQ8RRuT9.js +1 -0
- package/dist/chunks/types.DDbvTVqf.js +1 -0
- package/dist/chunks/useMazInputPhoneNumber.B_qQ0ldP.js +1 -0
- package/dist/chunks/utils.B8bfGQxN.js +1 -0
- package/dist/chunks/vFullscreenImg.CZeRh3mw.js +1 -0
- package/dist/chunks/vLazyImg.CXmd3Lp0.js +1 -0
- package/dist/chunks/vZoomImg.CaAHb98S.js +124 -0
- package/dist/components/MazAccordion.js +1 -86
- package/dist/components/MazAlert.js +1 -85
- package/dist/components/MazAnimatedCounter.js +1 -73
- package/dist/components/MazAnimatedElement.js +1 -44
- package/dist/components/MazAnimatedText.js +1 -103
- package/dist/components/MazAvatar.js +1 -125
- package/dist/components/MazBackdrop.js +1 -163
- package/dist/components/MazBadge.js +1 -29
- package/dist/components/MazBottomSheet.js +1 -55
- package/dist/components/MazBtn.js +1 -109
- package/dist/components/MazBtnGroup.js +1 -44
- package/dist/components/MazCard.js +1 -184
- package/dist/components/MazCardSpotlight.js +1 -81
- package/dist/components/MazCarousel.js +1 -104
- package/dist/components/MazChart.js +1 -4
- package/dist/components/MazCheckbox.js +1 -128
- package/dist/components/MazChecklist.js +1 -133
- package/dist/components/MazCircularProgressBar.js +1 -131
- package/dist/components/MazContainer.js +1 -71
- package/dist/components/MazDatePicker/MazPickerCalendar.js +1 -113
- package/dist/components/MazDatePicker/MazPickerCalendarMonth/MazPickerCalendarDays.js +1 -19
- package/dist/components/MazDatePicker/MazPickerCalendarMonth/MazPickerCalendarGrid.js +1 -181
- package/dist/components/MazDatePicker/MazPickerCalendarMonth/MazPickerCalendarMonth.js +1 -75
- package/dist/components/MazDatePicker/MazPickerCalendarSwitcher.js +1 -90
- package/dist/components/MazDatePicker/MazPickerContainer.js +1 -116
- package/dist/components/MazDatePicker/MazPickerHeader.js +1 -126
- package/dist/components/MazDatePicker/MazPickerMonthSwitcher.js +1 -82
- package/dist/components/MazDatePicker/MazPickerShortcuts.js +1 -55
- package/dist/components/MazDatePicker/MazPickerTime.js +1 -178
- package/dist/components/MazDatePicker/MazPickerYearSwitcher.js +1 -95
- package/dist/components/MazDatePicker.js +1 -466
- package/dist/components/MazDatePicker.vue.d.ts +2 -6
- package/dist/components/MazDialog.js +1 -115
- package/dist/components/MazDialog.vue.d.ts +2 -6
- package/dist/components/MazDialogConfirm.js +1 -6
- package/dist/components/MazDialogConfirm.vue.d.ts +2 -6
- package/dist/components/MazDrawer.js +1 -70
- package/dist/components/MazDropdown.js +1 -277
- package/dist/components/MazDropdown.vue.d.ts +2 -6
- package/dist/components/MazDropzone.js +1 -533
- package/dist/components/MazExpandAnimation.js +1 -46
- package/dist/components/MazFullscreenLoader.js +1 -38
- package/dist/components/MazGallery.js +1 -105
- package/dist/components/MazIcon.js +1 -114
- package/dist/components/MazInput.js +1 -256
- package/dist/components/MazInputCode.js +1 -152
- package/dist/components/MazInputNumber.js +1 -152
- package/dist/components/MazInputPhoneNumber/PhoneInput.js +1 -114
- package/dist/components/MazInputPhoneNumber.js +1 -253
- package/dist/components/MazInputPrice.js +1 -4
- package/dist/components/MazInputTags.js +1 -145
- package/dist/components/MazLazyImg.js +1 -62
- package/dist/components/MazLink.js +1 -80
- package/dist/components/MazLoadingBar.js +1 -24
- package/dist/components/MazPagination.js +1 -184
- package/dist/components/MazPopover.js +1 -326
- package/dist/components/MazPullToRefresh.js +1 -145
- package/dist/components/MazRadio.js +1 -103
- package/dist/components/MazRadioButtons.js +1 -135
- package/dist/components/MazReadMore.js +1 -110
- package/dist/components/MazReadingProgressBar.js +1 -68
- package/dist/components/MazSelect.js +1 -413
- package/dist/components/MazSelectCountry.js +1 -192
- package/dist/components/MazSkeleton.js +1 -50
- package/dist/components/MazSlider.js +1 -205
- package/dist/components/MazSpinner.js +1 -27
- package/dist/components/MazStepper.js +1 -170
- package/dist/components/MazSwitch.js +1 -4
- package/dist/components/MazTable.js +1 -8
- package/dist/components/MazTableCell.js +1 -18
- package/dist/components/MazTableRow.js +1 -26
- package/dist/components/MazTableTitle.js +1 -18
- package/dist/components/MazTabs.js +1 -4
- package/dist/components/MazTabsBar.js +1 -138
- package/dist/components/MazTabsContent.js +1 -4
- package/dist/components/MazTabsContentItem.js +1 -37
- package/dist/components/MazTextarea.js +1 -147
- package/dist/components/MazUiProvider.js +1 -4
- package/dist/components/index.js +1 -127
- package/dist/composables/index.js +1 -44
- package/dist/composables/useAos.js +1 -7
- package/dist/composables/useBreakpoints.js +1 -34
- package/dist/composables/useDialog.js +1 -7
- package/dist/composables/useDisplayNames.js +1 -111
- package/dist/composables/useDropzone.js +1 -66
- package/dist/composables/useFormField.js +1 -101
- package/dist/composables/useFormValidator.js +1 -163
- package/dist/composables/useFreezeValue.js +1 -8
- package/dist/composables/useIdleTimeout.js +1 -10
- package/dist/composables/useInjectStrict.js +1 -10
- package/dist/composables/useInstanceUniqId.js +1 -12
- package/dist/composables/useMountComponent.js +1 -16
- package/dist/composables/useMutationObserver.js +1 -37
- package/dist/composables/useReadingTime.js +1 -33
- package/dist/composables/useStringMatching.js +1 -42
- package/dist/composables/useSwipe.js +1 -26
- package/dist/composables/useTimer.js +1 -36
- package/dist/composables/useToast.js +1 -14
- package/dist/composables/useUserVisibility.js +1 -10
- package/dist/composables/useWait.js +1 -7
- package/dist/composables/useWindowSize.js +1 -21
- package/dist/directives/index.js +1 -19
- package/dist/directives/vClickOutside.js +1 -104
- package/dist/directives/vFullscreenImg.js +1 -10
- package/dist/directives/vLazyImg.js +1 -23
- package/dist/directives/vTooltip.js +1 -161
- package/dist/directives/vZoomImg.js +1 -286
- package/dist/index.js +1 -1
- package/dist/plugins/aos.js +1 -89
- package/dist/plugins/dialog.js +1 -61
- package/dist/plugins/index.js +1 -17
- package/dist/plugins/maz-ui.js +1 -11
- package/dist/plugins/toast.js +1 -261
- package/dist/plugins/wait.js +1 -43
- package/dist/resolvers/MazComponentsResolver.js +1 -18
- package/dist/resolvers/MazDirectivesResolver.js +1 -14
- package/dist/resolvers/MazModulesResolver.js +1 -76
- package/dist/resolvers/index.js +1 -8
- package/dist/tailwindcss/index.js +1 -20
- package/dist/tailwindcss/tailwind.config.js +1 -35
- package/dist/tailwindcss/utils/colors.js +1 -25
- package/dist/tailwindcss/variables/breakpoints.js +1 -29
- package/dist/tailwindcss/variables/colors.js +1 -33
- package/dist/tailwindcss/variables/design-tokens.js +1 -42
- package/dist/tailwindcss/variables/utilities.js +1 -20
- package/dist/tailwindcss/variables/z-indexes.js +1 -17
- package/package.json +12 -13
- package/dist/chunks/MazChart.vue_vue_type_script_setup_true_lang.DpG9UYdm.js +0 -50
- package/dist/chunks/MazDialogConfirm.vue_vue_type_script_setup_true_lang.BB2rYkwY.js +0 -215
- package/dist/chunks/MazInputPrice.vue_vue_type_script_setup_true_lang.DcNkyw1C.js +0 -77
- package/dist/chunks/MazSwitch.vue_vue_type_style_index_0_lang.lYfYsI0R.js +0 -84
- package/dist/chunks/MazTable.vue_vue_type_script_setup_true_lang.ycpSYFvJ.js +0 -517
- package/dist/chunks/MazTabs.vue_vue_type_script_setup_true_lang.CiIFxs7J.js +0 -28
- package/dist/chunks/MazTabsContent.vue_vue_type_script_setup_true_lang.MO7zA8LZ.js +0 -26
- package/dist/chunks/MazUiProvider.vue_vue_type_script_setup_true_lang.DtnM1DOn.js +0 -34
- package/dist/chunks/_plugin-vue_export-helper.B--vMWp3.js +0 -9
- package/dist/chunks/dom-events.DTx6Kblx.js +0 -368
- package/dist/chunks/fullscreen-img.directive.BJieSSIt.js +0 -321
- package/dist/chunks/lazy-img.directive.GRfYbidn.js +0 -174
- package/dist/chunks/resolveLinkComponent.CKR2McYy.js +0 -8
- package/dist/chunks/types.D0Bp_UhS.js +0 -6
- package/dist/chunks/useMazInputPhoneNumber.Os-2y9bz.js +0 -157
- package/dist/chunks/utils.D89Q5cCP.js +0 -207
- /package/dist/assets/{fullscreen-img.DFp1SMPU.css → vFullscreenImg.DFp1SMPU.css} +0 -0
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
import { useMountComponent } from "../composables/useMountComponent.js";
|
|
2
|
-
import { defineComponent, ref, reactive, computed, watch, onMounted, onBeforeUnmount, openBlock, createElementBlock, withKeys, withModifiers, createVNode, unref, createCommentVNode, createElementVNode, normalizeClass, withDirectives, vShow } from "vue";
|
|
3
|
-
import { MazChevronLeft, MazXMark } from "@maz-ui/icons/lazy";
|
|
4
|
-
import { checkAvailability } from "@maz-ui/utils/helpers/checkAvailability";
|
|
5
|
-
import MazSpinner from "../components/MazSpinner.js";
|
|
6
|
-
import { _ as _export_sfc } from "./_plugin-vue_export-helper.B--vMWp3.js";
|
|
7
|
-
import '../assets/fullscreen-img.DFp1SMPU.css';const _hoisted_1 = ["onKeypress"], _hoisted_2 = { class: "m-fullscreen-img-scroller" }, _hoisted_3 = ["src", "alt"], _sfc_main = /* @__PURE__ */ defineComponent({
|
|
8
|
-
__name: "MazFullscreenImg",
|
|
9
|
-
props: {
|
|
10
|
-
src: {},
|
|
11
|
-
clickedElementBounds: { default: void 0 },
|
|
12
|
-
offset: { default: void 0 },
|
|
13
|
-
animation: { default: () => ({
|
|
14
|
-
duration: 300,
|
|
15
|
-
easing: "ease-in-out"
|
|
16
|
-
}) },
|
|
17
|
-
openInstanceClass: { default: "m-fullscreen-img-instance" },
|
|
18
|
-
clickedElement: {},
|
|
19
|
-
destroy: { type: Function, default: void 0 },
|
|
20
|
-
alt: { default: void 0 },
|
|
21
|
-
zoom: { type: Boolean, default: !0 }
|
|
22
|
-
},
|
|
23
|
-
emits: ["close", "previous", "next", "before-close"],
|
|
24
|
-
setup(__props, { emit: __emit }) {
|
|
25
|
-
const props = __props, emits = __emit, imageLoaded = ref(!1), showLoader = ref(!1), loadedOnce = ref(!1), hasMultipleInstances = ref(!1), isZoomed = ref(!1), animationState = reactive({
|
|
26
|
-
running: !1,
|
|
27
|
-
ended: !1
|
|
28
|
-
}), currentClickedElement = ref(props.clickedElement), currentClickedElementBounds = computed(() => props.clickedElement.getBoundingClientRect()), isLandscapeImage = ref(), currentSrc = ref(props.src), currentAlt = ref(props.alt), FullscreenImgElement = ref(), ImgElement = ref(), hideImage = ref(!0), imageZoomClasses = computed(() => ({
|
|
29
|
-
"--is-zoomed": isZoomed.value,
|
|
30
|
-
"--invisible": hideImage.value,
|
|
31
|
-
"--absolute": !isZoomed.value
|
|
32
|
-
}));
|
|
33
|
-
function onImageLoaded() {
|
|
34
|
-
ImgElement.value && (isLandscapeImage.value = ImgElement.value?.naturalWidth > ImgElement.value?.naturalHeight), imageLoaded.value = !0, showLoader.value = !1, loadedOnce.value = !0;
|
|
35
|
-
}
|
|
36
|
-
watch(
|
|
37
|
-
loadedOnce,
|
|
38
|
-
(value) => {
|
|
39
|
-
value && openFullscreen();
|
|
40
|
-
},
|
|
41
|
-
{ immediate: !0 }
|
|
42
|
-
);
|
|
43
|
-
function close() {
|
|
44
|
-
emits("before-close"), closeFullscreen();
|
|
45
|
-
}
|
|
46
|
-
function keydownLister(e) {
|
|
47
|
-
e.key === "Escape" && (e.preventDefault(), close()), (e.key === "ArrowLeft" || e.key === "ArrowRight") && (e.preventDefault(), nextPreviousImage(e.key === "ArrowRight" ? "next" : "previous"));
|
|
48
|
-
}
|
|
49
|
-
function addClassToDocument() {
|
|
50
|
-
document.documentElement.classList.add("--m-fullscreen-open");
|
|
51
|
-
}
|
|
52
|
-
function removeClassFromDocument() {
|
|
53
|
-
document.documentElement.classList.remove("--m-fullscreen-open");
|
|
54
|
-
}
|
|
55
|
-
function getAllInstances() {
|
|
56
|
-
return [...document.querySelectorAll(".m-fullscreen-img-instance")];
|
|
57
|
-
}
|
|
58
|
-
function getNewInstanceIndex(allInstances, newInstanceIndex) {
|
|
59
|
-
return newInstanceIndex < 0 ? allInstances.length - 1 : newInstanceIndex >= allInstances.length ? 0 : newInstanceIndex;
|
|
60
|
-
}
|
|
61
|
-
function useNextInstance(currentInstance, nextInstance) {
|
|
62
|
-
currentInstance.classList.remove(props.openInstanceClass), nextInstance.classList.add(props.openInstanceClass);
|
|
63
|
-
const src = nextInstance.getAttribute("data-src"), alt = nextInstance.getAttribute("data-alt");
|
|
64
|
-
currentAlt.value = alt, currentSrc.value = src ?? currentSrc.value;
|
|
65
|
-
}
|
|
66
|
-
function nextPreviousImage(which) {
|
|
67
|
-
hideImage.value = !0;
|
|
68
|
-
const currentInstance = document.querySelector(
|
|
69
|
-
`.m-fullscreen-img-instance.${props.openInstanceClass}`
|
|
70
|
-
);
|
|
71
|
-
if (currentInstance) {
|
|
72
|
-
const allInstances = getAllInstances(), currentInstanceIndex = allInstances.indexOf(currentInstance), newInstanceIndex = which === "next" ? currentInstanceIndex + 1 : currentInstanceIndex - 1, nextInstance = allInstances[getNewInstanceIndex(allInstances, newInstanceIndex)];
|
|
73
|
-
currentClickedElement.value = nextInstance, nextInstance && useNextInstance(currentInstance, nextInstance), emits(which), imageLoaded.value = !1, showLoader.value = !0, checkAvailability(() => imageLoaded.value === !0, () => {
|
|
74
|
-
hideImage.value = !1, isZoomed.value ? setZoomStyles() : setEndAnimationStyles();
|
|
75
|
-
}, {
|
|
76
|
-
expectedValue: !0,
|
|
77
|
-
interval: 100,
|
|
78
|
-
maxAttempts: 50
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
function setZoomStyles() {
|
|
83
|
-
const imgElement = ImgElement.value;
|
|
84
|
-
if (!imgElement) {
|
|
85
|
-
console.error("[maz-ui](vFullscreenImg) ImgElement is not defined");
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
imgElement.style.removeProperty("max-width"), imgElement.style.removeProperty("max-height"), imgElement?.style.removeProperty("top"), imgElement?.style.removeProperty("left"), isLandscapeImage.value ? (imgElement.style.height = "100vh", imgElement.style.removeProperty("width")) : (imgElement.style.width = "100vw", imgElement.style.removeProperty("height"));
|
|
89
|
-
}
|
|
90
|
-
function toggleZoom() {
|
|
91
|
-
isZoomed.value ? (isZoomed.value = !isZoomed.value, setEndAnimationStyles()) : (isZoomed.value = !isZoomed.value, setZoomStyles());
|
|
92
|
-
}
|
|
93
|
-
function runAnimation(frames) {
|
|
94
|
-
animationState.running = !0, hideImage.value = !1;
|
|
95
|
-
const animation = ImgElement.value?.animate(frames, {
|
|
96
|
-
duration: props.animation.duration,
|
|
97
|
-
easing: props.animation.easing
|
|
98
|
-
});
|
|
99
|
-
if (!animation) {
|
|
100
|
-
console.error("[maz-ui](vFullscreenImg) animation is not defined"), animationState.running = !1, animationState.ended = !0;
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
return animation;
|
|
104
|
-
}
|
|
105
|
-
function getPositionsOfClikedElement(offset = props.offset ?? 0) {
|
|
106
|
-
const width = currentClickedElement.value.clientWidth || 1, height = currentClickedElement.value.clientHeight || 1, windowWidth = window.innerWidth, windowHeight = window.innerHeight, scale = Math.min(
|
|
107
|
-
(windowWidth - 2 * offset) / width,
|
|
108
|
-
(windowHeight - 2 * offset) / height
|
|
109
|
-
), centerX = (windowWidth - width * scale) / 2, centerY = (windowHeight - height * scale) / 2;
|
|
110
|
-
return {
|
|
111
|
-
centerX,
|
|
112
|
-
centerY,
|
|
113
|
-
width,
|
|
114
|
-
height,
|
|
115
|
-
scale
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
function getAnimationFrames({ trigger }) {
|
|
119
|
-
const { width, height, scale, centerX, centerY } = getPositionsOfClikedElement(), { top, left, width: clickedElementWidth, height: clickedElementHeight } = currentClickedElementBounds.value, frames = [
|
|
120
|
-
{
|
|
121
|
-
top: `${top}px`,
|
|
122
|
-
left: `${left}px`,
|
|
123
|
-
width: `${clickedElementWidth}px`,
|
|
124
|
-
height: `${clickedElementHeight}px`,
|
|
125
|
-
opacity: 0
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
top: `${centerY}px`,
|
|
129
|
-
left: `${centerX}px`,
|
|
130
|
-
width: `${width * scale}px`,
|
|
131
|
-
height: `${height * scale}px`,
|
|
132
|
-
opacity: 1
|
|
133
|
-
}
|
|
134
|
-
];
|
|
135
|
-
return {
|
|
136
|
-
frames: trigger === "open" ? frames : frames.reverse()
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
function setEndAnimationStyles() {
|
|
140
|
-
const { height, width, scale } = getPositionsOfClikedElement(), finalStyles = isLandscapeImage.value ? {
|
|
141
|
-
width: `${width * scale}px`,
|
|
142
|
-
maxHeight: `${height * scale}px`
|
|
143
|
-
} : {
|
|
144
|
-
height: `${height * scale}px`,
|
|
145
|
-
maxWidth: `${width * scale}px`
|
|
146
|
-
};
|
|
147
|
-
if (!ImgElement.value) {
|
|
148
|
-
console.error("[maz-ui](vFullscreenImg) ImgElement is not defined");
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
isLandscapeImage.value ? (ImgElement.value.style.removeProperty("height"), ImgElement.value.style.removeProperty("maxHeight")) : (ImgElement.value.style.removeProperty("width"), ImgElement.value.style.removeProperty("maxWidth")), Object.assign(ImgElement.value.style, finalStyles);
|
|
152
|
-
}
|
|
153
|
-
function openFullscreen() {
|
|
154
|
-
const { frames } = getAnimationFrames({
|
|
155
|
-
trigger: "open"
|
|
156
|
-
}), openAnimation = runAnimation(frames);
|
|
157
|
-
if (!openAnimation) {
|
|
158
|
-
console.error("[maz-ui](vFullscreenImg) open animation is not defined"), setEndAnimationStyles();
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
openAnimation.onfinish = () => {
|
|
162
|
-
setEndAnimationStyles(), animationState.running = !1, animationState.ended = !0;
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
function closeFullscreen() {
|
|
166
|
-
const { frames } = getAnimationFrames({
|
|
167
|
-
trigger: "close"
|
|
168
|
-
}), closeAnimation = runAnimation(frames);
|
|
169
|
-
function onFinish() {
|
|
170
|
-
emits("close"), FullscreenImgElement.value?.remove(), props.destroy?.(), animationState.running = !1, animationState.ended = !0;
|
|
171
|
-
}
|
|
172
|
-
if (!closeAnimation) {
|
|
173
|
-
console.error("[maz-ui](vFullscreenImg) close animation is not defined"), onFinish();
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
closeAnimation.onfinish = onFinish;
|
|
177
|
-
}
|
|
178
|
-
function onResizeWindow() {
|
|
179
|
-
isZoomed.value || setEndAnimationStyles();
|
|
180
|
-
}
|
|
181
|
-
return onMounted(() => {
|
|
182
|
-
showLoader.value = !0, document.addEventListener("keydown", keydownLister), window.addEventListener("resize", onResizeWindow), addClassToDocument(), hasMultipleInstances.value = getAllInstances().length > 1;
|
|
183
|
-
}), onBeforeUnmount(() => {
|
|
184
|
-
document.removeEventListener("keydown", keydownLister), window.removeEventListener("resize", onResizeWindow), removeClassFromDocument();
|
|
185
|
-
}), (_ctx, _cache) => (openBlock(), createElementBlock("div", {
|
|
186
|
-
ref_key: "FullscreenImgElement",
|
|
187
|
-
ref: FullscreenImgElement,
|
|
188
|
-
role: "button",
|
|
189
|
-
class: "m-fullscreen-img m-reset-css",
|
|
190
|
-
tabindex: "0",
|
|
191
|
-
onClick: withModifiers(close, ["stop"]),
|
|
192
|
-
onKeypress: withKeys(withModifiers(close, ["prevent"]), ["esc"])
|
|
193
|
-
}, [
|
|
194
|
-
loadedOnce.value && hasMultipleInstances.value ? (openBlock(), createElementBlock("button", {
|
|
195
|
-
key: 0,
|
|
196
|
-
type: "button",
|
|
197
|
-
class: "m-fullscreen-btn --next",
|
|
198
|
-
onClick: _cache[0] || (_cache[0] = withModifiers(($event) => nextPreviousImage("next"), ["stop"]))
|
|
199
|
-
}, [
|
|
200
|
-
createVNode(unref(MazChevronLeft), { class: "maz-rotate-180" })
|
|
201
|
-
])) : createCommentVNode("", !0),
|
|
202
|
-
loadedOnce.value && hasMultipleInstances.value ? (openBlock(), createElementBlock("button", {
|
|
203
|
-
key: 1,
|
|
204
|
-
type: "button",
|
|
205
|
-
class: "m-fullscreen-btn --previous",
|
|
206
|
-
onClick: _cache[1] || (_cache[1] = withModifiers(($event) => nextPreviousImage("previous"), ["stop"]))
|
|
207
|
-
}, [
|
|
208
|
-
createVNode(unref(MazChevronLeft))
|
|
209
|
-
])) : createCommentVNode("", !0),
|
|
210
|
-
createElementVNode("button", {
|
|
211
|
-
type: "button",
|
|
212
|
-
class: "m-fullscreen-btn --close",
|
|
213
|
-
onClick: close
|
|
214
|
-
}, [
|
|
215
|
-
createVNode(unref(MazXMark))
|
|
216
|
-
]),
|
|
217
|
-
createElementVNode("div", _hoisted_2, [
|
|
218
|
-
createElementVNode("img", {
|
|
219
|
-
ref_key: "ImgElement",
|
|
220
|
-
ref: ImgElement,
|
|
221
|
-
src: currentSrc.value,
|
|
222
|
-
alt: currentAlt.value ?? void 0,
|
|
223
|
-
tabindex: "0",
|
|
224
|
-
class: normalizeClass([imageZoomClasses.value]),
|
|
225
|
-
onLoad: onImageLoaded,
|
|
226
|
-
onClick: _cache[2] || (_cache[2] = withModifiers(($event) => __props.zoom && toggleZoom(), ["stop"]))
|
|
227
|
-
}, null, 42, _hoisted_3),
|
|
228
|
-
withDirectives(createVNode(MazSpinner, { class: "m-fullscreen-img-loader" }, null, 512), [
|
|
229
|
-
[vShow, showLoader.value]
|
|
230
|
-
])
|
|
231
|
-
])
|
|
232
|
-
], 40, _hoisted_1));
|
|
233
|
-
}
|
|
234
|
-
}), MazFullscreenImg = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-92a410ce"]]), STATE_OPEN_CLASS = "m-fullscreen-is-open";
|
|
235
|
-
class FullscreenImgHandler {
|
|
236
|
-
options = void 0;
|
|
237
|
-
defaultOptions = {
|
|
238
|
-
scaleOnHover: !1,
|
|
239
|
-
blurOnHover: !1,
|
|
240
|
-
disabled: !1,
|
|
241
|
-
zoom: !0,
|
|
242
|
-
offset: 80,
|
|
243
|
-
animation: {
|
|
244
|
-
duration: 300,
|
|
245
|
-
easing: "ease-in-out"
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
mouseEnterListener = void 0;
|
|
249
|
-
mouseLeaveListener = void 0;
|
|
250
|
-
renderPreviewListener = void 0;
|
|
251
|
-
buildOptions(el, binding) {
|
|
252
|
-
const options = typeof binding.value == "object" ? binding.value : { src: binding.value, alt: void 0 }, src = options?.src ?? this.getImgSrc(el), alt = options?.alt ?? this.getImgAlt(el);
|
|
253
|
-
return {
|
|
254
|
-
...this.defaultOptions,
|
|
255
|
-
...options,
|
|
256
|
-
src,
|
|
257
|
-
alt
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
get allInstances() {
|
|
261
|
-
return [...document.querySelectorAll(".m-fullscreen-img-instance")];
|
|
262
|
-
}
|
|
263
|
-
getImgSrc(el) {
|
|
264
|
-
const imgSrc = this.options?.src || el.getAttribute("src") || el.getAttribute("data-src");
|
|
265
|
-
if (!imgSrc)
|
|
266
|
-
throw new Error(
|
|
267
|
-
'[maz-ui](fullscreen-img) src of image must be provided by `v-fullscreen=""`, `v-fullscreen="{ src: "" }"`, `src=""` or `data-src=""` atributes'
|
|
268
|
-
);
|
|
269
|
-
return imgSrc;
|
|
270
|
-
}
|
|
271
|
-
getImgAlt(el) {
|
|
272
|
-
return this.options?.alt || el.getAttribute("alt") || el.getAttribute("data-alt");
|
|
273
|
-
}
|
|
274
|
-
create(el, binding) {
|
|
275
|
-
if (this.options = this.buildOptions(el, binding), this.options.disabled)
|
|
276
|
-
return;
|
|
277
|
-
el.style.cursor = "move", (this.options.scaleOnHover || this.options.blurOnHover) && (el.style.transition = "all 200ms ease-in-out"), el.classList.add("m-fullscreen-img-instance"), el.setAttribute("data-src", this.getImgSrc(el));
|
|
278
|
-
const alt = this.getImgAlt(el);
|
|
279
|
-
alt && el.setAttribute("data-alt", alt), this.mouseEnterListener = () => this.mouseEnter(el), this.mouseLeaveListener = () => this.mouseLeave(el), this.renderPreviewListener = () => this.renderPreview(el), el.addEventListener("mouseenter", this.mouseEnterListener), el.addEventListener("mouseleave", this.mouseLeaveListener), el.addEventListener("click", this.renderPreviewListener);
|
|
280
|
-
}
|
|
281
|
-
update(el, binding) {
|
|
282
|
-
this.options = this.buildOptions(el, binding);
|
|
283
|
-
}
|
|
284
|
-
remove(el) {
|
|
285
|
-
this.mouseEnterListener && el.removeEventListener("mouseenter", this.mouseEnterListener), this.mouseLeaveListener && el.removeEventListener("mouseleave", this.mouseLeaveListener), this.renderPreviewListener && el.removeEventListener("click", this.renderPreviewListener), el.classList.remove("m-fullscreen-img-instance"), el.style.cursor = "";
|
|
286
|
-
}
|
|
287
|
-
renderPreview(el) {
|
|
288
|
-
return el.classList.add(STATE_OPEN_CLASS), useMountComponent(MazFullscreenImg, {
|
|
289
|
-
props: {
|
|
290
|
-
...this.options,
|
|
291
|
-
src: this.options?.src || this.getImgSrc(el),
|
|
292
|
-
alt: this.options?.alt || this.getImgAlt(el),
|
|
293
|
-
openInstanceClass: STATE_OPEN_CLASS,
|
|
294
|
-
clickedElement: el,
|
|
295
|
-
clickedElementBounds: el.getBoundingClientRect()
|
|
296
|
-
},
|
|
297
|
-
element: document.body
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
mouseLeave(el) {
|
|
301
|
-
this.options?.scaleOnHover && (el.style.transform = ""), this.options?.blurOnHover && (el.style.filter = ""), el.style.zIndex = "";
|
|
302
|
-
}
|
|
303
|
-
mouseEnter(el) {
|
|
304
|
-
el.style.zIndex = "1", this.options?.scaleOnHover && (el.style.transform = "scale(1.04)"), this.options?.blurOnHover && (el.style.filter = "blur(3px)");
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
let instance;
|
|
308
|
-
const directive = {
|
|
309
|
-
mounted(el, binding) {
|
|
310
|
-
return instance = new FullscreenImgHandler(), instance.create(el, binding);
|
|
311
|
-
},
|
|
312
|
-
updated(el, binding) {
|
|
313
|
-
return instance.update(el, binding);
|
|
314
|
-
},
|
|
315
|
-
unmounted(el) {
|
|
316
|
-
return instance.remove(el);
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
export {
|
|
320
|
-
directive as d
|
|
321
|
-
};
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
const EMPTY_PHOTO = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7", DEFAULT_OPTIONS = {
|
|
2
|
-
baseClass: "m-lazy-img",
|
|
3
|
-
loadedClass: "m-lazy-loaded",
|
|
4
|
-
loadingClass: "m-lazy-loading",
|
|
5
|
-
errorClass: "m-lazy-error",
|
|
6
|
-
fallbackClass: "m-lazy-fallback",
|
|
7
|
-
observerOnce: !0,
|
|
8
|
-
loadOnce: !1,
|
|
9
|
-
observerOptions: {
|
|
10
|
-
threshold: 0.1
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
class LazyImg {
|
|
14
|
-
observers = [];
|
|
15
|
-
defaultOptions = DEFAULT_OPTIONS;
|
|
16
|
-
options;
|
|
17
|
-
onImgLoadedCallback;
|
|
18
|
-
onImgErrorCallback;
|
|
19
|
-
hasImgLoaded = !1;
|
|
20
|
-
constructor(opts = {}) {
|
|
21
|
-
this.options = this.buildOptions(opts), this.onImgLoadedCallback = this.imageIsLoaded.bind(this), this.onImgErrorCallback = this.imageHasError.bind(this);
|
|
22
|
-
}
|
|
23
|
-
async loadErrorPhoto() {
|
|
24
|
-
const { default: photo } = await import("@maz-ui/icons/svg/no-image.svg?url");
|
|
25
|
-
return photo;
|
|
26
|
-
}
|
|
27
|
-
buildOptions(opts) {
|
|
28
|
-
return {
|
|
29
|
-
...this.defaultOptions,
|
|
30
|
-
...opts,
|
|
31
|
-
observerOptions: {
|
|
32
|
-
...this.defaultOptions.observerOptions,
|
|
33
|
-
...opts.observerOptions
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
removeClass(el, className) {
|
|
38
|
-
el.classList.remove(className);
|
|
39
|
-
}
|
|
40
|
-
addClass(el, className) {
|
|
41
|
-
el.classList.add(className);
|
|
42
|
-
}
|
|
43
|
-
removeAllStateClasses(el) {
|
|
44
|
-
this.removeClass(el, this.options.loadedClass), this.removeClass(el, this.options.loadingClass), this.removeClass(el, this.options.errorClass), this.removeClass(el, this.options.fallbackClass);
|
|
45
|
-
}
|
|
46
|
-
setBaseClass(el) {
|
|
47
|
-
this.addClass(el, this.options.baseClass);
|
|
48
|
-
}
|
|
49
|
-
imageIsLoading(el) {
|
|
50
|
-
this.addClass(el, this.options.loadingClass), this.options.onLoading?.(el);
|
|
51
|
-
}
|
|
52
|
-
imageIsLoaded(el) {
|
|
53
|
-
this.hasImgLoaded = !0, this.removeClass(el, this.options.loadingClass), this.addClass(el, this.options.loadedClass), this.options.onLoaded?.(el);
|
|
54
|
-
}
|
|
55
|
-
imageHasError(el) {
|
|
56
|
-
this.removeClass(el, this.options.loadingClass), this.addClass(el, this.options.errorClass), this.options.onError?.(el), this.setDefaultPhoto(el);
|
|
57
|
-
}
|
|
58
|
-
getSrc(binding) {
|
|
59
|
-
return typeof binding.value == "object" ? binding.value.src : binding.value;
|
|
60
|
-
}
|
|
61
|
-
getImageUrl(el, binding) {
|
|
62
|
-
const dataSrc = this.getImgElement(el).getAttribute("data-lazy-src");
|
|
63
|
-
return dataSrc || this.getSrc(binding);
|
|
64
|
-
}
|
|
65
|
-
async setPictureSourceUrls(el) {
|
|
66
|
-
const sourceElements = el.querySelectorAll("source");
|
|
67
|
-
if (sourceElements.length > 0)
|
|
68
|
-
for await (const source of sourceElements) {
|
|
69
|
-
const srcSet = source.getAttribute("data-lazy-srcset");
|
|
70
|
-
if (srcSet)
|
|
71
|
-
source.srcset = srcSet;
|
|
72
|
-
else
|
|
73
|
-
return this.imageHasError(el);
|
|
74
|
-
}
|
|
75
|
-
else
|
|
76
|
-
this.imageHasError(el);
|
|
77
|
-
}
|
|
78
|
-
hasBgImgMode(binding) {
|
|
79
|
-
return binding.arg === "bg-image";
|
|
80
|
-
}
|
|
81
|
-
isPictureElement(el) {
|
|
82
|
-
return el instanceof HTMLPictureElement;
|
|
83
|
-
}
|
|
84
|
-
getImgElement(el) {
|
|
85
|
-
return this.isPictureElement(el) ? el.querySelector("img") : el;
|
|
86
|
-
}
|
|
87
|
-
async setDefaultPhoto(el) {
|
|
88
|
-
if (this.options.fallbackSrc === !1)
|
|
89
|
-
return;
|
|
90
|
-
const fallbackSrc = this.options.fallbackSrc;
|
|
91
|
-
typeof fallbackSrc == "string" && this.addClass(el, this.options.fallbackClass);
|
|
92
|
-
const errorPhoto = fallbackSrc ?? await this.loadErrorPhoto(), sourceElements = el.querySelectorAll("source");
|
|
93
|
-
if (sourceElements.length > 0)
|
|
94
|
-
for await (const source of sourceElements)
|
|
95
|
-
source.srcset = errorPhoto;
|
|
96
|
-
else
|
|
97
|
-
this.setImgSrc(el, errorPhoto);
|
|
98
|
-
}
|
|
99
|
-
addEventListenerToImg(el) {
|
|
100
|
-
const imgElement = this.getImgElement(el);
|
|
101
|
-
imgElement.addEventListener("load", () => this.onImgLoadedCallback(el), {
|
|
102
|
-
once: !0
|
|
103
|
-
}), imgElement.addEventListener("error", (err) => this.onImgErrorCallback(el, err), { once: !0 });
|
|
104
|
-
}
|
|
105
|
-
async loadImage(el, binding) {
|
|
106
|
-
if (this.imageIsLoading(el), this.isPictureElement(el))
|
|
107
|
-
this.addEventListenerToImg(el), await this.setPictureSourceUrls(el);
|
|
108
|
-
else {
|
|
109
|
-
const imageUrl = this.getImageUrl(el, binding);
|
|
110
|
-
if (!imageUrl)
|
|
111
|
-
return this.imageHasError(el);
|
|
112
|
-
this.hasBgImgMode(binding) ? (el.style.backgroundImage = `url('${imageUrl}')`, this.imageIsLoaded(el)) : (this.addEventListenerToImg(el), this.setImgSrc(el, imageUrl));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
setImgSrc(el, src) {
|
|
116
|
-
const imgElement = this.getImgElement(el);
|
|
117
|
-
imgElement.src = src;
|
|
118
|
-
}
|
|
119
|
-
handleIntersectionObserver(el, binding, entries, observer) {
|
|
120
|
-
this.observers.push(observer);
|
|
121
|
-
for (const entry of entries)
|
|
122
|
-
if (entry.isIntersecting) {
|
|
123
|
-
if (this.options.onIntersecting?.(entry.target), this.options.observerOnce && observer.unobserve(el), this.options.loadOnce && this.hasImgLoaded)
|
|
124
|
-
return;
|
|
125
|
-
this.loadImage(el, binding);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
createObserver(el, binding) {
|
|
129
|
-
const observerCallback = (entries, intersectionObserver) => {
|
|
130
|
-
this.handleIntersectionObserver(el, binding, entries, intersectionObserver);
|
|
131
|
-
}, observerOptions = this.options.observerOptions;
|
|
132
|
-
new IntersectionObserver(observerCallback, observerOptions).observe(el);
|
|
133
|
-
}
|
|
134
|
-
async imageHandler(el, binding, type) {
|
|
135
|
-
if (type === "update")
|
|
136
|
-
for await (const observer of this.observers) observer.unobserve(el);
|
|
137
|
-
globalThis.IntersectionObserver ? this.createObserver(el, binding) : this.loadImage(el, binding);
|
|
138
|
-
}
|
|
139
|
-
async bindUpdateHandler(el, binding, type) {
|
|
140
|
-
await this.imageHandler(el, binding, type);
|
|
141
|
-
}
|
|
142
|
-
async add(el, binding) {
|
|
143
|
-
if (this.hasBgImgMode(binding) && this.isPictureElement(el))
|
|
144
|
-
throw new Error(`[MazLazyImg] You can't use the "bg-image" mode with "<picture />" element`);
|
|
145
|
-
setTimeout(() => this.setBaseClass(el), 0), el.getAttribute("src") || this.setImgSrc(el, EMPTY_PHOTO), await this.bindUpdateHandler(el, binding, "bind");
|
|
146
|
-
}
|
|
147
|
-
async update(el, binding) {
|
|
148
|
-
binding.value !== binding.oldValue && (this.hasImgLoaded = !1, this.removeAllStateClasses(el), await this.bindUpdateHandler(el, binding, "update"));
|
|
149
|
-
}
|
|
150
|
-
remove(el, binding) {
|
|
151
|
-
this.hasImgLoaded = !1, this.hasBgImgMode(binding) && (el.style.backgroundImage = ""), this.removeAllStateClasses(el);
|
|
152
|
-
for (const observer of this.observers)
|
|
153
|
-
observer.unobserve(el);
|
|
154
|
-
this.observers = [];
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
let instance;
|
|
158
|
-
const directive = {
|
|
159
|
-
created(el, binding) {
|
|
160
|
-
const options = typeof binding.value == "object" ? binding.value : {};
|
|
161
|
-
instance = new LazyImg(options), instance.add(el, binding);
|
|
162
|
-
},
|
|
163
|
-
updated(el, binding) {
|
|
164
|
-
instance.update(el, binding);
|
|
165
|
-
},
|
|
166
|
-
unmounted(el, binding) {
|
|
167
|
-
instance.remove(el, binding);
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
export {
|
|
171
|
-
DEFAULT_OPTIONS as D,
|
|
172
|
-
LazyImg as L,
|
|
173
|
-
directive as d
|
|
174
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { getCurrentInstance } from "vue";
|
|
2
|
-
function resolveLinkComponent() {
|
|
3
|
-
const app = getCurrentInstance()?.appContext.app;
|
|
4
|
-
return app?.component("NuxtLink") ? "NuxtLink" : app?.component("RouterLink") ? "RouterLink" : (console.warn('Your are using "to" property but no router component found (NuxtLink or RouterLink), falling back to anchor ("<a />" - HTMLAnchorElement) tag'), "a");
|
|
5
|
-
}
|
|
6
|
-
export {
|
|
7
|
-
resolveLinkComponent as r
|
|
8
|
-
};
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { getCountryCallingCode, getCountries, isSupportedCountry, getExampleNumber, parsePhoneNumberFromString, AsYouType } from "libphonenumber-js";
|
|
2
|
-
import { ref } from "vue";
|
|
3
|
-
import { fetchLocaleIp } from "@maz-ui/utils/helpers/fetchLocaleIp";
|
|
4
|
-
const examples = ref();
|
|
5
|
-
function isCountryAvailable(locale) {
|
|
6
|
-
try {
|
|
7
|
-
const response = isSupportedCountry(locale);
|
|
8
|
-
return response || (console.error(`[maz-ui](MazInputPhoneNumber) The code country "${locale}" is not available`), !1);
|
|
9
|
-
} catch (error) {
|
|
10
|
-
return console.error(`[maz-ui](MazInputPhoneNumber) ${error}`), !1;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
function getPhoneNumberResults({
|
|
14
|
-
phoneNumber,
|
|
15
|
-
countryCode,
|
|
16
|
-
checkCountryCode = !1
|
|
17
|
-
}) {
|
|
18
|
-
try {
|
|
19
|
-
if (!phoneNumber)
|
|
20
|
-
return {
|
|
21
|
-
isValid: !1,
|
|
22
|
-
countryCode
|
|
23
|
-
};
|
|
24
|
-
const parsedNumber = parsePhoneNumberFromString(phoneNumber, countryCode ?? void 0), isValid = parsedNumber?.isValid() ?? !1, isSameCountryCode = countryCode && checkCountryCode ? parsedNumber?.country && countryCode === parsedNumber.country : !0;
|
|
25
|
-
return {
|
|
26
|
-
isValid: isValid && !!isSameCountryCode,
|
|
27
|
-
countryCode,
|
|
28
|
-
parsedCountryCode: parsedNumber?.country,
|
|
29
|
-
isPossible: parsedNumber?.isPossible(),
|
|
30
|
-
countryCallingCode: parsedNumber?.countryCallingCode,
|
|
31
|
-
nationalNumber: parsedNumber?.nationalNumber,
|
|
32
|
-
type: parsedNumber?.getType(),
|
|
33
|
-
formatInternational: parsedNumber?.formatInternational(),
|
|
34
|
-
formatNational: parsedNumber?.formatNational(),
|
|
35
|
-
uri: parsedNumber?.getURI(),
|
|
36
|
-
e164: parsedNumber?.format("E.164"),
|
|
37
|
-
rfc3966: parsedNumber?.format("RFC3966"),
|
|
38
|
-
possibleCountries: parsedNumber?.getPossibleCountries(),
|
|
39
|
-
phoneNumber
|
|
40
|
-
};
|
|
41
|
-
} catch (error) {
|
|
42
|
-
throw new Error(`[MazInputPhoneNumber](getResultsFromPhoneNumber) ${error}`, { cause: error });
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
async function getPhoneNumberExamplesFile() {
|
|
46
|
-
const { default: data } = await import("libphonenumber-js/examples.mobile.json");
|
|
47
|
-
return data;
|
|
48
|
-
}
|
|
49
|
-
function getPhoneNumberExample(countryCode) {
|
|
50
|
-
try {
|
|
51
|
-
return examples.value && countryCode ? getExampleNumber(countryCode, examples.value)?.formatNational() : void 0;
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.error(`[maz-ui](MazInputPhoneNumber) ${error}`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
function getAsYouTypeFormat(countryCode, phoneNumber) {
|
|
57
|
-
try {
|
|
58
|
-
return !phoneNumber || !countryCode || typeof countryCode != "string" || countryCode.length !== 2 ? phoneNumber : new AsYouType(countryCode).input(phoneNumber);
|
|
59
|
-
} catch (error) {
|
|
60
|
-
return console.error(`[MazInputPhoneNumber](getAsYouTypeFormat) Error with countryCode: "${countryCode}", phoneNumber: "${phoneNumber}"`, error), phoneNumber;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function isSameCountryCallingCode(countryCode, countryCode2) {
|
|
64
|
-
return getCountryCallingCode(countryCode) === getCountryCallingCode(countryCode2);
|
|
65
|
-
}
|
|
66
|
-
async function loadExamples() {
|
|
67
|
-
try {
|
|
68
|
-
if (examples.value)
|
|
69
|
-
return;
|
|
70
|
-
examples.value = await getPhoneNumberExamplesFile();
|
|
71
|
-
} catch (error) {
|
|
72
|
-
console.error("[maz-ui](MazInputPhoneNumber) while loading phone number examples file", error);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function useLibphonenumber() {
|
|
76
|
-
return {
|
|
77
|
-
examples,
|
|
78
|
-
getAsYouTypeFormat,
|
|
79
|
-
getPhoneNumberResults,
|
|
80
|
-
getPhoneNumberExamplesFile,
|
|
81
|
-
getPhoneNumberExample,
|
|
82
|
-
isSameCountryCallingCode,
|
|
83
|
-
isCountryAvailable,
|
|
84
|
-
getCountries,
|
|
85
|
-
getCountryCallingCode,
|
|
86
|
-
loadExamples
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function getBrowserLocale() {
|
|
90
|
-
if (typeof globalThis.window > "u")
|
|
91
|
-
return;
|
|
92
|
-
const browserLocale = globalThis.navigator.language;
|
|
93
|
-
if (!browserLocale)
|
|
94
|
-
return;
|
|
95
|
-
const parts = browserLocale.split("-");
|
|
96
|
-
let locale = parts.length > 1 ? parts[1].slice(0, 2).toUpperCase() : parts[0].slice(0, 2).toUpperCase();
|
|
97
|
-
return locale === "EN" && (locale = "US"), locale === "JA" && (locale = "JP"), {
|
|
98
|
-
locale,
|
|
99
|
-
browserLocale
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
let displayNamesInstance, displayNamesLocale;
|
|
103
|
-
function getCountryName(locale, code, customCountriesNameListByIsoCode) {
|
|
104
|
-
return customCountriesNameListByIsoCode?.[code] ? customCountriesNameListByIsoCode[code] : ((displayNamesLocale !== locale || !displayNamesInstance) && (displayNamesLocale = locale, displayNamesInstance = new Intl.DisplayNames([locale], { type: "region" })), displayNamesInstance.of(code));
|
|
105
|
-
}
|
|
106
|
-
function getCountryList(locale, customCountriesNameListByIsoCode) {
|
|
107
|
-
const countriesList = [], isoList = getCountries();
|
|
108
|
-
locale = locale ?? getBrowserLocale()?.browserLocale ?? "en-US";
|
|
109
|
-
for (const code of isoList) {
|
|
110
|
-
const name = getCountryName(locale, code, customCountriesNameListByIsoCode);
|
|
111
|
-
if (name)
|
|
112
|
-
try {
|
|
113
|
-
const dialCode = getCountryCallingCode(code);
|
|
114
|
-
countriesList.push({
|
|
115
|
-
code,
|
|
116
|
-
dialCode,
|
|
117
|
-
name
|
|
118
|
-
});
|
|
119
|
-
} catch (error) {
|
|
120
|
-
console.error(`[MazInputPhoneNumber](getCountryCallingCode) ${error}`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return countriesList;
|
|
124
|
-
}
|
|
125
|
-
async function fetchCountryCode() {
|
|
126
|
-
try {
|
|
127
|
-
const countryCode = await fetchLocaleIp();
|
|
128
|
-
return countryCode ? {
|
|
129
|
-
data: countryCode,
|
|
130
|
-
error: void 0
|
|
131
|
-
} : {
|
|
132
|
-
data: void 0,
|
|
133
|
-
error: new Error("[MazInputPhoneNumber](fetchCountryCode) No country code found")
|
|
134
|
-
};
|
|
135
|
-
} catch (error) {
|
|
136
|
-
return {
|
|
137
|
-
data: void 0,
|
|
138
|
-
error: new Error(`[MazInputPhoneNumber](fetchCountryCode) ${error}`)
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
const isLetterOrNumberRegex = /[^\d ()+-]/g;
|
|
143
|
-
function sanitizePhoneNumber(input) {
|
|
144
|
-
return input ? input.replaceAll(isLetterOrNumberRegex, "").trim() : "";
|
|
145
|
-
}
|
|
146
|
-
function useMazInputPhoneNumber() {
|
|
147
|
-
return {
|
|
148
|
-
fetchCountryCode,
|
|
149
|
-
getBrowserLocale,
|
|
150
|
-
getCountryList,
|
|
151
|
-
sanitizePhoneNumber
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
export {
|
|
155
|
-
useLibphonenumber as a,
|
|
156
|
-
useMazInputPhoneNumber as u
|
|
157
|
-
};
|