@dative-gpi/foundation-shared-components 1.0.180-utils-composable → 1.0.181
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/composables/index.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
export * from "./useAccessibilityPreferences";
|
|
2
1
|
export * from "./useAddress";
|
|
3
2
|
export * from "./useAutocomplete";
|
|
4
3
|
export * from "./useBreakpoints";
|
|
5
4
|
export * from "./useColors";
|
|
6
|
-
export * from "./useCountUp";
|
|
7
5
|
export * from "./useDebounce";
|
|
8
|
-
export * from "./useElementVisibility"
|
|
9
6
|
export * from "./useMapLayers";
|
|
10
7
|
export * from "./useRules";
|
|
11
8
|
export * from "./useSlots";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dative-gpi/foundation-shared-components",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.181",
|
|
5
5
|
"description": "",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"author": "",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@dative-gpi/foundation-shared-domain": "1.0.
|
|
14
|
-
"@dative-gpi/foundation-shared-services": "1.0.
|
|
13
|
+
"@dative-gpi/foundation-shared-domain": "1.0.181",
|
|
14
|
+
"@dative-gpi/foundation-shared-services": "1.0.181"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"@dative-gpi/bones-ui": "^1.0.0",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"sass": "1.71.1",
|
|
36
36
|
"sass-loader": "13.3.2"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "a6836b28ce33081e2a05e2088a41df6d8083629e"
|
|
39
39
|
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { ref, computed, onBeforeUnmount, watch } from 'vue';
|
|
2
|
-
import { useAccessibilityPreferences } from './useAccessibilityPreferences';
|
|
3
|
-
|
|
4
|
-
export function useCountUp(options: {
|
|
5
|
-
value: number | string,
|
|
6
|
-
duration?: number,
|
|
7
|
-
countUp?: boolean,
|
|
8
|
-
pad?: number,
|
|
9
|
-
startOnVisible?: boolean,
|
|
10
|
-
easing?: (t: number) => number
|
|
11
|
-
}) {
|
|
12
|
-
const {
|
|
13
|
-
value,
|
|
14
|
-
duration = 800,
|
|
15
|
-
countUp = true,
|
|
16
|
-
pad = 2,
|
|
17
|
-
startOnVisible = true,
|
|
18
|
-
easing = easeOutCubic
|
|
19
|
-
} = options;
|
|
20
|
-
|
|
21
|
-
const { prefersReducedMotion } = useAccessibilityPreferences();
|
|
22
|
-
const current = ref(0);
|
|
23
|
-
const rafId = ref(0);
|
|
24
|
-
const hasAnimated = ref(false);
|
|
25
|
-
|
|
26
|
-
// Easing function
|
|
27
|
-
function easeOutCubic(t: number) {
|
|
28
|
-
return 1 - Math.pow(1 - t, 3);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Target value computation
|
|
32
|
-
const target = computed(() => {
|
|
33
|
-
const n = Number(value);
|
|
34
|
-
return Number.isFinite(n) ? Math.trunc(n) : 0;
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// Formatted display value
|
|
38
|
-
const displayText = computed(() => {
|
|
39
|
-
const s = String(countUp ? current.value : target.value);
|
|
40
|
-
return pad > 0 ? s.padStart(pad, "0") : s;
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// Animation function
|
|
44
|
-
function animate(from: number, to: number, animDuration: number) {
|
|
45
|
-
cancelAnimationFrame(rafId.value);
|
|
46
|
-
const start = performance.now();
|
|
47
|
-
|
|
48
|
-
const step = (now: number) => {
|
|
49
|
-
const t = Math.min(1, (now - start) / animDuration);
|
|
50
|
-
const v = from + (to - from) * easing(t);
|
|
51
|
-
current.value = Math.round(v);
|
|
52
|
-
if (t < 1) {
|
|
53
|
-
rafId.value = requestAnimationFrame(step);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
rafId.value = requestAnimationFrame(step);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Start animation
|
|
61
|
-
function start() {
|
|
62
|
-
if (!countUp) {
|
|
63
|
-
current.value = target.value;
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (prefersReducedMotion) {
|
|
68
|
-
current.value = target.value;
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
animate(current.value, target.value, duration);
|
|
73
|
-
hasAnimated.value = true;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Clean up
|
|
77
|
-
onBeforeUnmount(() => {
|
|
78
|
-
cancelAnimationFrame(rafId.value);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// The restart method can be useful when the value changes.
|
|
82
|
-
function restart() {
|
|
83
|
-
if (hasAnimated.value || !startOnVisible) {
|
|
84
|
-
start();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Monitor changes in value
|
|
89
|
-
watch(() => value, () => {
|
|
90
|
-
restart();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
current,
|
|
95
|
-
target,
|
|
96
|
-
displayText,
|
|
97
|
-
start,
|
|
98
|
-
restart,
|
|
99
|
-
hasAnimated
|
|
100
|
-
};
|
|
101
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { ref, onMounted, onBeforeUnmount } from 'vue';
|
|
2
|
-
|
|
3
|
-
export function useElementVisibility(element: HTMLElement | null, options: {
|
|
4
|
-
threshold?: number,
|
|
5
|
-
onVisible?: () => void
|
|
6
|
-
}) {
|
|
7
|
-
const {
|
|
8
|
-
threshold = 0.3,
|
|
9
|
-
onVisible
|
|
10
|
-
} = options;
|
|
11
|
-
|
|
12
|
-
const isVisible = ref(false);
|
|
13
|
-
const observer = ref<IntersectionObserver | null>(null);
|
|
14
|
-
|
|
15
|
-
onMounted(() => {
|
|
16
|
-
if (!element) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
observer.value = new IntersectionObserver((entries) => {
|
|
21
|
-
entries.forEach((entry) => {
|
|
22
|
-
isVisible.value = entry.isIntersecting;
|
|
23
|
-
if (entry.isIntersecting && onVisible) {
|
|
24
|
-
onVisible();
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}, { threshold });
|
|
28
|
-
|
|
29
|
-
observer.value.observe(element);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
onBeforeUnmount(() => {
|
|
33
|
-
observer.value?.disconnect();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
isVisible
|
|
38
|
-
};
|
|
39
|
-
}
|