@stacksjs/composables 0.70.257 → 0.70.259
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/_shared.js +1 -23
- package/dist/cloneFnJSON.js +1 -3
- package/dist/computedAsync.js +1 -20
- package/dist/computedEager.js +1 -10
- package/dist/createEventHook.js +1 -15
- package/dist/createFetch.js +1 -8
- package/dist/createGlobalState.js +1 -10
- package/dist/createSharedComposable.js +1 -9
- package/dist/extendRef.js +1 -6
- package/dist/formatTimeAgo.js +1 -33
- package/dist/index.js +1 -210
- package/dist/isDefined.js +1 -3
- package/dist/makeDestructurable.js +1 -16
- package/dist/onClickOutside.js +1 -25
- package/dist/onKeyStroke.js +1 -31
- package/dist/onLongPress.js +1 -43
- package/dist/onStartTyping.js +1 -23
- package/dist/refAutoReset.js +1 -15
- package/dist/refDefault.js +1 -8
- package/dist/resolveRef.js +1 -7
- package/dist/ssrHandlers.js +1 -8
- package/dist/syncRef.js +1 -35
- package/dist/tryOnMounted.js +1 -22
- package/dist/unrefElement.js +1 -9
- package/dist/until.js +1 -62
- package/dist/useActiveElement.js +1 -19
- package/dist/useAnimate.js +1 -48
- package/dist/useArrayUtils.js +1 -114
- package/dist/useAsyncQueue.js +1 -22
- package/dist/useAsyncState.js +1 -35
- package/dist/useBase64.js +1 -45
- package/dist/useBattery.js +1 -38
- package/dist/useBreakpoints.js +1 -97
- package/dist/useBroadcastChannel.js +1 -31
- package/dist/useBrowserLocation.js +1 -64
- package/dist/useClipboard.js +1 -32
- package/dist/useClipboardItems.js +1 -15
- package/dist/useCloned.js +1 -16
- package/dist/useColorMode.js +1 -60
- package/dist/useConfirmDialog.js +1 -34
- package/dist/useCounter.js +1 -28
- package/dist/useCssVar.js +1 -23
- package/dist/useCycleList.js +1 -27
- package/dist/useDark.js +1 -38
- package/dist/useDateFormat.js +1 -11
- package/dist/useDebounce.js +1 -16
- package/dist/useDebounceFn.js +1 -18
- package/dist/useDebouncedRef.js +1 -22
- package/dist/useDebouncedRefHistory.js +1 -36
- package/dist/useDeviceMotion.js +1 -53
- package/dist/useDeviceOrientation.js +1 -23
- package/dist/useDevicePixelRatio.js +1 -24
- package/dist/useDocumentVisibility.js +1 -16
- package/dist/useDraggable.js +1 -58
- package/dist/useDropZone.js +1 -52
- package/dist/useElementBounding.js +1 -59
- package/dist/useElementByPoint.js +1 -18
- package/dist/useElementHover.js +1 -28
- package/dist/useElementSize.js +1 -34
- package/dist/useElementVisibility.js +1 -10
- package/dist/useEventBus.js +1 -41
- package/dist/useEventListener.js +1 -29
- package/dist/useEventSource.js +1 -72
- package/dist/useEyeDropper.js +1 -17
- package/dist/useFavicon.js +1 -22
- package/dist/useFetch.js +1 -61
- package/dist/useFileDialog.js +1 -24
- package/dist/useFocus.js +1 -42
- package/dist/useFocusWithin.js +1 -29
- package/dist/useForm.js +1 -182
- package/dist/useFps.js +1 -22
- package/dist/useFullscreen.js +1 -67
- package/dist/useGeolocation.js +1 -55
- package/dist/useIdle.js +1 -46
- package/dist/useImage.js +1 -32
- package/dist/useInfiniteScroll.js +1 -50
- package/dist/useIntersectionObserver.js +1 -27
- package/dist/useInterval.js +1 -32
- package/dist/useIntervalFn.js +1 -24
- package/dist/useKeyModifier.js +1 -22
- package/dist/useLastChanged.js +1 -8
- package/dist/useLocalStorage.js +1 -4
- package/dist/useMagicKeys.js +1 -81
- package/dist/useManualRefHistory.js +1 -64
- package/dist/useMath.js +1 -52
- package/dist/useMediaQuery.js +1 -19
- package/dist/useMemoize.js +1 -24
- package/dist/useMounted.js +1 -8
- package/dist/useMouse.js +1 -67
- package/dist/useMouseInElement.js +1 -31
- package/dist/useMousePressed.js +1 -31
- package/dist/useMutationObserver.js +1 -27
- package/dist/useNavigatorLanguage.js +1 -17
- package/dist/useNetwork.js +1 -58
- package/dist/useNow.js +1 -10
- package/dist/useObjectUrl.js +1 -23
- package/dist/useOffsetPagination.js +1 -45
- package/dist/useOnline.js +1 -20
- package/dist/usePageLeave.js +1 -27
- package/dist/useParallax.js +1 -33
- package/dist/useParentElement.js +1 -8
- package/dist/usePermission.js +1 -21
- package/dist/usePointer.js +1 -32
- package/dist/usePointerLock.js +1 -33
- package/dist/usePointerSwipe.js +1 -52
- package/dist/usePreferredColorScheme.js +1 -25
- package/dist/usePreferredContrast.js +1 -29
- package/dist/usePreferredLanguages.js +1 -16
- package/dist/usePreferredReducedMotion.js +1 -18
- package/dist/usePrevious.js +1 -8
- package/dist/useQuery.js +1 -265
- package/dist/useRafFn.js +1 -37
- package/dist/useRefHistory.js +1 -72
- package/dist/useResizeObserver.js +1 -27
- package/dist/useScreenOrientation.js +1 -27
- package/dist/useScreenSafeArea.js +1 -25
- package/dist/useScriptTag.js +1 -52
- package/dist/useScroll.js +1 -116
- package/dist/useScrollLock.js +1 -39
- package/dist/useSessionStorage.js +1 -4
- package/dist/useShare.js +1 -11
- package/dist/useSorted.js +1 -10
- package/dist/useStepper.js +1 -46
- package/dist/useStorage.js +1 -54
- package/dist/useStyleTag.js +1 -39
- package/dist/useSupported.js +1 -10
- package/dist/useSwipe.js +1 -58
- package/dist/useTextDirection.js +1 -16
- package/dist/useTextSelection.js +1 -27
- package/dist/useTextareaAutosize.js +1 -20
- package/dist/useThrottle.js +1 -23
- package/dist/useThrottleFn.js +1 -36
- package/dist/useThrottledRef.js +1 -30
- package/dist/useThrottledRefHistory.js +1 -43
- package/dist/useTimeAgo.js +1 -58
- package/dist/useTimeout.js +1 -32
- package/dist/useTimeoutFn.js +1 -27
- package/dist/useTimeoutPoll.js +1 -33
- package/dist/useTimestamp.js +1 -43
- package/dist/useTitle.js +1 -12
- package/dist/useToNumber.js +1 -25
- package/dist/useToString.js +1 -10
- package/dist/useToggle.js +1 -12
- package/dist/useTransition.js +1 -89
- package/dist/useUrlSearchParams.js +1 -72
- package/dist/useVibrate.js +1 -14
- package/dist/useVirtualList.js +1 -49
- package/dist/useWakeLock.js +1 -32
- package/dist/useWebNotification.js +1 -39
- package/dist/useWebSocket.js +1 -103
- package/dist/useWebWorker.js +1 -56
- package/dist/useWindowFocus.js +1 -20
- package/dist/useWindowScroll.js +1 -17
- package/dist/useWindowSize.js +1 -28
- package/dist/watchArray.js +1 -9
- package/dist/watchAtMost.js +1 -12
- package/dist/watchDebounced.js +1 -20
- package/dist/watchDeep.js +1 -13
- package/dist/watchIgnorable.js +1 -19
- package/dist/watchImmediate.js +1 -7
- package/dist/watchOnce.js +1 -17
- package/dist/watchPausable.js +1 -23
- package/dist/watchThrottled.js +1 -37
- package/dist/watchTriggerable.js +1 -10
- package/dist/watchWithFilter.js +1 -6
- package/dist/whenever.js +1 -7
- package/package.json +2 -2
package/dist/tryOnMounted.js
CHANGED
|
@@ -1,22 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function tryOnMounted(fn) {
|
|
3
|
-
fn();
|
|
4
|
-
}
|
|
5
|
-
export function tryOnBeforeMount(fn) {
|
|
6
|
-
fn();
|
|
7
|
-
}
|
|
8
|
-
export function tryOnUnmounted(fn) {
|
|
9
|
-
try {
|
|
10
|
-
onUnmounted(fn);
|
|
11
|
-
} catch {}
|
|
12
|
-
}
|
|
13
|
-
export function tryOnBeforeUnmount(fn) {
|
|
14
|
-
try {
|
|
15
|
-
onUnmounted(fn);
|
|
16
|
-
} catch {}
|
|
17
|
-
}
|
|
18
|
-
export function tryOnScopeDispose(fn) {
|
|
19
|
-
try {
|
|
20
|
-
onUnmounted(fn);
|
|
21
|
-
} catch {}
|
|
22
|
-
}
|
|
1
|
+
import{onUnmounted}from"@stacksjs/stx";export function tryOnMounted(fn){fn()}export function tryOnBeforeMount(fn){fn()}export function tryOnUnmounted(fn){try{onUnmounted(fn)}catch{}}export function tryOnBeforeUnmount(fn){try{onUnmounted(fn)}catch{}}export function tryOnScopeDispose(fn){try{onUnmounted(fn)}catch{}}
|
package/dist/unrefElement.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function unrefElement(elRef) {
|
|
3
|
-
const plain = unref(elRef);
|
|
4
|
-
if (!plain)
|
|
5
|
-
return plain;
|
|
6
|
-
if (plain.$el)
|
|
7
|
-
return plain.$el;
|
|
8
|
-
return plain;
|
|
9
|
-
}
|
|
1
|
+
import{unref}from"./_shared";export function unrefElement(elRef){const plain=unref(elRef);if(!plain)return plain;if(plain.$el)return plain.$el;return plain}
|
package/dist/until.js
CHANGED
|
@@ -1,62 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function until(r) {
|
|
3
|
-
function toMatch(condition, options = {}) {
|
|
4
|
-
const { timeout, throwOnTimeout = !1 } = options;
|
|
5
|
-
if (condition(r.value))
|
|
6
|
-
return Promise.resolve(r.value);
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
let timer = null;
|
|
9
|
-
const unwatch = watch(r, (newVal) => {
|
|
10
|
-
if (condition(newVal)) {
|
|
11
|
-
unwatch();
|
|
12
|
-
if (timer !== null)
|
|
13
|
-
clearTimeout(timer);
|
|
14
|
-
resolve(newVal);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
if (timeout !== void 0)
|
|
18
|
-
timer = setTimeout(() => {
|
|
19
|
-
unwatch();
|
|
20
|
-
if (throwOnTimeout)
|
|
21
|
-
reject(Error("Timeout"));
|
|
22
|
-
else
|
|
23
|
-
resolve(r.value);
|
|
24
|
-
}, timeout);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
function toBe(value, options) {
|
|
28
|
-
return toMatch((v) => v === value, options);
|
|
29
|
-
}
|
|
30
|
-
function toBeTruthy(options) {
|
|
31
|
-
return toMatch((v) => Boolean(v), options);
|
|
32
|
-
}
|
|
33
|
-
function toBeNull(options) {
|
|
34
|
-
return toMatch((v) => v === null, options);
|
|
35
|
-
}
|
|
36
|
-
function toBeUndefined(options) {
|
|
37
|
-
return toMatch((v) => v === void 0, options);
|
|
38
|
-
}
|
|
39
|
-
function toBeNaN(options) {
|
|
40
|
-
return toMatch((v) => Number.isNaN(v), options);
|
|
41
|
-
}
|
|
42
|
-
function changed(options) {
|
|
43
|
-
const initial = r.value;
|
|
44
|
-
return toMatch((v) => v !== initial, options);
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
toMatch,
|
|
48
|
-
toBe,
|
|
49
|
-
toBeTruthy,
|
|
50
|
-
toBeNull,
|
|
51
|
-
toBeUndefined,
|
|
52
|
-
toBeNaN,
|
|
53
|
-
changed,
|
|
54
|
-
not: {
|
|
55
|
-
toBe: (value, options) => toMatch((v) => v !== value, options),
|
|
56
|
-
toBeTruthy: (options) => toMatch((v) => !v, options),
|
|
57
|
-
toBeNull: (options) => toMatch((v) => v !== null, options),
|
|
58
|
-
toBeUndefined: (options) => toMatch((v) => v !== void 0, options),
|
|
59
|
-
toBeNaN: (options) => toMatch((v) => !Number.isNaN(v), options)
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
1
|
+
import{watch}from"@stacksjs/stx";export function until(r){function toMatch(condition,options={}){const{timeout,throwOnTimeout=!1}=options;if(condition(r.value))return Promise.resolve(r.value);return new Promise((resolve,reject)=>{let timer=null;const unwatch=watch(r,(newVal)=>{if(condition(newVal)){unwatch();if(timer!==null)clearTimeout(timer);resolve(newVal)}});if(timeout!==void 0)timer=setTimeout(()=>{unwatch();if(throwOnTimeout)reject(Error("Timeout"));else resolve(r.value)},timeout)})}function toBe(value,options){return toMatch((v)=>v===value,options)}function toBeTruthy(options){return toMatch((v)=>Boolean(v),options)}function toBeNull(options){return toMatch((v)=>v===null,options)}function toBeUndefined(options){return toMatch((v)=>v===void 0,options)}function toBeNaN(options){return toMatch((v)=>Number.isNaN(v),options)}function changed(options){const initial=r.value;return toMatch((v)=>v!==initial,options)}return{toMatch,toBe,toBeTruthy,toBeNull,toBeUndefined,toBeNaN,changed,not:{toBe:(value,options)=>toMatch((v)=>v!==value,options),toBeTruthy:(options)=>toMatch((v)=>!v,options),toBeNull:(options)=>toMatch((v)=>v!==null,options),toBeUndefined:(options)=>toMatch((v)=>v!==void 0,options),toBeNaN:(options)=>toMatch((v)=>!Number.isNaN(v),options)}}}
|
package/dist/useActiveElement.js
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function useActiveElement() {
|
|
3
|
-
const activeElement = ref(null);
|
|
4
|
-
if (typeof document > "u")
|
|
5
|
-
return activeElement;
|
|
6
|
-
activeElement.value = document.activeElement;
|
|
7
|
-
const handler = () => {
|
|
8
|
-
activeElement.value = document.activeElement;
|
|
9
|
-
};
|
|
10
|
-
document.addEventListener("focusin", handler, { passive: !0 });
|
|
11
|
-
document.addEventListener("focusout", handler, { passive: !0 });
|
|
12
|
-
try {
|
|
13
|
-
onUnmounted(() => {
|
|
14
|
-
document.removeEventListener("focusin", handler);
|
|
15
|
-
document.removeEventListener("focusout", handler);
|
|
16
|
-
});
|
|
17
|
-
} catch {}
|
|
18
|
-
return activeElement;
|
|
19
|
-
}
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";export function useActiveElement(){const activeElement=ref(null);if(typeof document>"u")return activeElement;activeElement.value=document.activeElement;const handler=()=>{activeElement.value=document.activeElement};document.addEventListener("focusin",handler,{passive:!0});document.addEventListener("focusout",handler,{passive:!0});try{onUnmounted(()=>{document.removeEventListener("focusin",handler);document.removeEventListener("focusout",handler)})}catch{}return activeElement}
|
package/dist/useAnimate.js
CHANGED
|
@@ -1,48 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { unref } from "./_shared";
|
|
3
|
-
export function useAnimate(target, keyframes, options) {
|
|
4
|
-
const isSupported = ref(typeof HTMLElement < "u" && "animate" in HTMLElement.prototype), animate = ref(void 0), pending = ref(!1), playState = ref("idle"), currentTime = ref(null);
|
|
5
|
-
function syncState() {
|
|
6
|
-
if (animate.value) {
|
|
7
|
-
pending.value = animate.value.pending;
|
|
8
|
-
playState.value = animate.value.playState;
|
|
9
|
-
currentTime.value = animate.value.currentTime;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function init() {
|
|
13
|
-
const el = unref(target);
|
|
14
|
-
if (!el || !isSupported.value)
|
|
15
|
-
return;
|
|
16
|
-
animate.value = el.animate(keyframes, options);
|
|
17
|
-
animate.value.addEventListener("finish", syncState);
|
|
18
|
-
animate.value.addEventListener("cancel", syncState);
|
|
19
|
-
syncState();
|
|
20
|
-
}
|
|
21
|
-
function play() {
|
|
22
|
-
animate.value?.play();
|
|
23
|
-
syncState();
|
|
24
|
-
}
|
|
25
|
-
function pause() {
|
|
26
|
-
animate.value?.pause();
|
|
27
|
-
syncState();
|
|
28
|
-
}
|
|
29
|
-
function reverse() {
|
|
30
|
-
animate.value?.reverse();
|
|
31
|
-
syncState();
|
|
32
|
-
}
|
|
33
|
-
function finish() {
|
|
34
|
-
animate.value?.finish();
|
|
35
|
-
syncState();
|
|
36
|
-
}
|
|
37
|
-
function cancel() {
|
|
38
|
-
animate.value?.cancel();
|
|
39
|
-
syncState();
|
|
40
|
-
}
|
|
41
|
-
init();
|
|
42
|
-
try {
|
|
43
|
-
onUnmounted(() => {
|
|
44
|
-
animate.value?.cancel();
|
|
45
|
-
});
|
|
46
|
-
} catch {}
|
|
47
|
-
return { isSupported, animate, play, pause, reverse, finish, cancel, pending, playState, currentTime };
|
|
48
|
-
}
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";import{unref}from"./_shared";export function useAnimate(target,keyframes,options){const isSupported=ref(typeof HTMLElement<"u"&&"animate"in HTMLElement.prototype),animate=ref(void 0),pending=ref(!1),playState=ref("idle"),currentTime=ref(null);function syncState(){if(animate.value){pending.value=animate.value.pending;playState.value=animate.value.playState;currentTime.value=animate.value.currentTime}}function init(){const el=unref(target);if(!el||!isSupported.value)return;animate.value=el.animate(keyframes,options);animate.value.addEventListener("finish",syncState);animate.value.addEventListener("cancel",syncState);syncState()}function play(){animate.value?.play();syncState()}function pause(){animate.value?.pause();syncState()}function reverse(){animate.value?.reverse();syncState()}function finish(){animate.value?.finish();syncState()}function cancel(){animate.value?.cancel();syncState()}init();try{onUnmounted(()=>{animate.value?.cancel()})}catch{}return{isSupported,animate,play,pause,reverse,finish,cancel,pending,playState,currentTime}}
|
package/dist/useArrayUtils.js
CHANGED
|
@@ -1,114 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { isRef, unref } from "./_shared";
|
|
3
|
-
function watchSource(source, cb) {
|
|
4
|
-
if (isRef(source))
|
|
5
|
-
watch(source, cb);
|
|
6
|
-
}
|
|
7
|
-
function getArray(source) {
|
|
8
|
-
return unref(source);
|
|
9
|
-
}
|
|
10
|
-
export function useArrayDifference(list, other, compareFn) {
|
|
11
|
-
const result = ref([]);
|
|
12
|
-
function update() {
|
|
13
|
-
const arr = getArray(list), otherArr = getArray(other);
|
|
14
|
-
if (compareFn)
|
|
15
|
-
result.value = arr.filter((item) => !otherArr.some((o) => compareFn(item, o)));
|
|
16
|
-
else
|
|
17
|
-
result.value = arr.filter((item) => !otherArr.includes(item));
|
|
18
|
-
}
|
|
19
|
-
update();
|
|
20
|
-
watchSource(list, update);
|
|
21
|
-
watchSource(other, update);
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
export function useArrayEvery(list, fn) {
|
|
25
|
-
const result = ref(!1);
|
|
26
|
-
function update() {
|
|
27
|
-
result.value = getArray(list).every(fn);
|
|
28
|
-
}
|
|
29
|
-
update();
|
|
30
|
-
watchSource(list, update);
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
export function useArrayFilter(list, fn) {
|
|
34
|
-
const result = ref([]);
|
|
35
|
-
function update() {
|
|
36
|
-
result.value = getArray(list).filter(fn);
|
|
37
|
-
}
|
|
38
|
-
update();
|
|
39
|
-
watchSource(list, update);
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
export function useArrayFind(list, fn) {
|
|
43
|
-
const result = ref(void 0);
|
|
44
|
-
function update() {
|
|
45
|
-
result.value = getArray(list).find(fn);
|
|
46
|
-
}
|
|
47
|
-
update();
|
|
48
|
-
watchSource(list, update);
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
export function useArrayFindIndex(list, fn) {
|
|
52
|
-
const result = ref(-1);
|
|
53
|
-
function update() {
|
|
54
|
-
result.value = getArray(list).findIndex(fn);
|
|
55
|
-
}
|
|
56
|
-
update();
|
|
57
|
-
watchSource(list, update);
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
export function useArrayIncludes(list, value, compareFn) {
|
|
61
|
-
const result = ref(!1);
|
|
62
|
-
function update() {
|
|
63
|
-
const arr = getArray(list), v = unref(value);
|
|
64
|
-
if (compareFn)
|
|
65
|
-
result.value = arr.some((item) => compareFn(item, v));
|
|
66
|
-
else
|
|
67
|
-
result.value = arr.includes(v);
|
|
68
|
-
}
|
|
69
|
-
update();
|
|
70
|
-
watchSource(list, update);
|
|
71
|
-
if (isRef(value))
|
|
72
|
-
watch(value, update);
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
export function useArrayMap(list, fn) {
|
|
76
|
-
const result = ref([]);
|
|
77
|
-
function update() {
|
|
78
|
-
result.value = getArray(list).map(fn);
|
|
79
|
-
}
|
|
80
|
-
update();
|
|
81
|
-
watchSource(list, update);
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
export function useArrayReduce(list, fn, initialValue) {
|
|
85
|
-
const result = ref(initialValue);
|
|
86
|
-
function update() {
|
|
87
|
-
result.value = getArray(list).reduce(fn, initialValue);
|
|
88
|
-
}
|
|
89
|
-
update();
|
|
90
|
-
watchSource(list, update);
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
|
-
export function useArraySome(list, fn) {
|
|
94
|
-
const result = ref(!1);
|
|
95
|
-
function update() {
|
|
96
|
-
result.value = getArray(list).some(fn);
|
|
97
|
-
}
|
|
98
|
-
update();
|
|
99
|
-
watchSource(list, update);
|
|
100
|
-
return result;
|
|
101
|
-
}
|
|
102
|
-
export function useArrayUnique(list, compareFn) {
|
|
103
|
-
const result = ref([]);
|
|
104
|
-
function update() {
|
|
105
|
-
const arr = getArray(list);
|
|
106
|
-
if (compareFn)
|
|
107
|
-
result.value = arr.filter((item, index) => arr.findIndex((other) => compareFn(item, other)) === index);
|
|
108
|
-
else
|
|
109
|
-
result.value = [...new Set(arr)];
|
|
110
|
-
}
|
|
111
|
-
update();
|
|
112
|
-
watchSource(list, update);
|
|
113
|
-
return result;
|
|
114
|
-
}
|
|
1
|
+
import{computed,ref,watch}from"@stacksjs/stx";import{isRef,unref}from"./_shared";function watchSource(source,cb){if(isRef(source))watch(source,cb)}function getArray(source){return unref(source)}export function useArrayDifference(list,other,compareFn){const result=ref([]);function update(){const arr=getArray(list),otherArr=getArray(other);if(compareFn)result.value=arr.filter((item)=>!otherArr.some((o)=>compareFn(item,o)));else result.value=arr.filter((item)=>!otherArr.includes(item))}update();watchSource(list,update);watchSource(other,update);return result}export function useArrayEvery(list,fn){const result=ref(!1);function update(){result.value=getArray(list).every(fn)}update();watchSource(list,update);return result}export function useArrayFilter(list,fn){const result=ref([]);function update(){result.value=getArray(list).filter(fn)}update();watchSource(list,update);return result}export function useArrayFind(list,fn){const result=ref(void 0);function update(){result.value=getArray(list).find(fn)}update();watchSource(list,update);return result}export function useArrayFindIndex(list,fn){const result=ref(-1);function update(){result.value=getArray(list).findIndex(fn)}update();watchSource(list,update);return result}export function useArrayIncludes(list,value,compareFn){const result=ref(!1);function update(){const arr=getArray(list),v=unref(value);if(compareFn)result.value=arr.some((item)=>compareFn(item,v));else result.value=arr.includes(v)}update();watchSource(list,update);if(isRef(value))watch(value,update);return result}export function useArrayMap(list,fn){const result=ref([]);function update(){result.value=getArray(list).map(fn)}update();watchSource(list,update);return result}export function useArrayReduce(list,fn,initialValue){const result=ref(initialValue);function update(){result.value=getArray(list).reduce(fn,initialValue)}update();watchSource(list,update);return result}export function useArraySome(list,fn){const result=ref(!1);function update(){result.value=getArray(list).some(fn)}update();watchSource(list,update);return result}export function useArrayUnique(list,compareFn){const result=ref([]);function update(){const arr=getArray(list);if(compareFn)result.value=arr.filter((item,index)=>arr.findIndex((other)=>compareFn(item,other))===index);else result.value=[...new Set(arr)]}update();watchSource(list,update);return result}
|
package/dist/useAsyncQueue.js
CHANGED
|
@@ -1,22 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function useAsyncQueue(tasks) {
|
|
3
|
-
const activeIndex = ref(-1), isFinished = ref(!1), result = ref(tasks.map(() => ({ state: "pending" })));
|
|
4
|
-
async function runTasks() {
|
|
5
|
-
for (let i = 0;i < tasks.length; i++) {
|
|
6
|
-
activeIndex.value = i;
|
|
7
|
-
const task = tasks[i];
|
|
8
|
-
if (!task)
|
|
9
|
-
continue;
|
|
10
|
-
try {
|
|
11
|
-
const data = await task();
|
|
12
|
-
result.value = result.value.map((r, idx) => idx === i ? { state: "fulfilled", data } : r);
|
|
13
|
-
} catch (e) {
|
|
14
|
-
result.value = result.value.map((r, idx) => idx === i ? { state: "rejected", data: e } : r);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
activeIndex.value = tasks.length;
|
|
18
|
-
isFinished.value = !0;
|
|
19
|
-
}
|
|
20
|
-
runTasks();
|
|
21
|
-
return { activeIndex, result, isFinished };
|
|
22
|
-
}
|
|
1
|
+
import{ref}from"@stacksjs/stx";export function useAsyncQueue(tasks){const activeIndex=ref(-1),isFinished=ref(!1),result=ref(tasks.map(()=>({state:"pending"})));async function runTasks(){for(let i=0;i<tasks.length;i++){activeIndex.value=i;const task=tasks[i];if(!task)continue;try{const data=await task();result.value=result.value.map((r,idx)=>idx===i?{state:"fulfilled",data}:r)}catch(e){result.value=result.value.map((r,idx)=>idx===i?{state:"rejected",data:e}:r)}}activeIndex.value=tasks.length;isFinished.value=!0}runTasks();return{activeIndex,result,isFinished}}
|
package/dist/useAsyncState.js
CHANGED
|
@@ -1,35 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function useAsyncState(promise, initialState, options = {}) {
|
|
3
|
-
const {
|
|
4
|
-
immediate = !0,
|
|
5
|
-
onError,
|
|
6
|
-
resetOnExecute = !0,
|
|
7
|
-
delay = 0
|
|
8
|
-
} = options, state = ref(initialState), isReady = ref(!1), isLoading = ref(!1), error = ref(void 0);
|
|
9
|
-
async function execute(executeDelay) {
|
|
10
|
-
const delayMs = executeDelay ?? delay;
|
|
11
|
-
if (resetOnExecute)
|
|
12
|
-
state.value = initialState;
|
|
13
|
-
error.value = void 0;
|
|
14
|
-
isReady.value = !1;
|
|
15
|
-
isLoading.value = !0;
|
|
16
|
-
if (delayMs > 0)
|
|
17
|
-
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
18
|
-
try {
|
|
19
|
-
const result = typeof promise === "function" ? await promise() : await promise;
|
|
20
|
-
state.value = result;
|
|
21
|
-
isReady.value = !0;
|
|
22
|
-
return result;
|
|
23
|
-
} catch (e) {
|
|
24
|
-
error.value = e;
|
|
25
|
-
if (onError)
|
|
26
|
-
onError(e);
|
|
27
|
-
return state.value;
|
|
28
|
-
} finally {
|
|
29
|
-
isLoading.value = !1;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (immediate)
|
|
33
|
-
execute();
|
|
34
|
-
return { state, isReady, isLoading, error, execute };
|
|
35
|
-
}
|
|
1
|
+
import{ref}from"@stacksjs/stx";export function useAsyncState(promise,initialState,options={}){const{immediate=!0,onError,resetOnExecute=!0,delay=0}=options,state=ref(initialState),isReady=ref(!1),isLoading=ref(!1),error=ref(void 0);async function execute(executeDelay){const delayMs=executeDelay??delay;if(resetOnExecute)state.value=initialState;error.value=void 0;isReady.value=!1;isLoading.value=!0;if(delayMs>0)await new Promise((resolve)=>setTimeout(resolve,delayMs));try{const result=typeof promise==="function"?await promise():await promise;state.value=result;isReady.value=!0;return result}catch(e){error.value=e;if(onError)onError(e);return state.value}finally{isLoading.value=!1}}if(immediate)execute();return{state,isReady,isLoading,error,execute}}
|
package/dist/useBase64.js
CHANGED
|
@@ -1,45 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { isRef, unref } from "./_shared";
|
|
3
|
-
export function useBase64(source) {
|
|
4
|
-
const base64 = ref("");
|
|
5
|
-
async function encode(input) {
|
|
6
|
-
if (typeof input === "string") {
|
|
7
|
-
if (typeof btoa < "u")
|
|
8
|
-
return btoa(input);
|
|
9
|
-
return Buffer.from(input).toString("base64");
|
|
10
|
-
}
|
|
11
|
-
if (input instanceof ArrayBuffer) {
|
|
12
|
-
const bytes = new Uint8Array(input);
|
|
13
|
-
let binary = "";
|
|
14
|
-
for (const byte of bytes)
|
|
15
|
-
binary += String.fromCharCode(byte);
|
|
16
|
-
if (typeof btoa < "u")
|
|
17
|
-
return btoa(binary);
|
|
18
|
-
return Buffer.from(input).toString("base64");
|
|
19
|
-
}
|
|
20
|
-
if (typeof Blob < "u" && input instanceof Blob)
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
const reader = new FileReader;
|
|
23
|
-
reader.onload = () => {
|
|
24
|
-
const result = reader.result, base64Part = result.split(",")[1] ?? result;
|
|
25
|
-
resolve(base64Part);
|
|
26
|
-
};
|
|
27
|
-
reader.onerror = reject;
|
|
28
|
-
reader.readAsDataURL(input);
|
|
29
|
-
});
|
|
30
|
-
if (typeof HTMLCanvasElement < "u" && input instanceof HTMLCanvasElement)
|
|
31
|
-
return input.toDataURL().split(",")[1] ?? "";
|
|
32
|
-
return "";
|
|
33
|
-
}
|
|
34
|
-
async function execute() {
|
|
35
|
-
const val = unref(source), result = await encode(val);
|
|
36
|
-
base64.value = result;
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
execute().catch(() => {});
|
|
40
|
-
if (isRef(source))
|
|
41
|
-
watch(source, () => {
|
|
42
|
-
execute().catch(() => {});
|
|
43
|
-
});
|
|
44
|
-
return { base64, execute };
|
|
45
|
-
}
|
|
1
|
+
import{ref,watch}from"@stacksjs/stx";import{isRef,unref}from"./_shared";export function useBase64(source){const base64=ref("");async function encode(input){if(typeof input==="string"){if(typeof btoa<"u")return btoa(input);return Buffer.from(input).toString("base64")}if(input instanceof ArrayBuffer){const bytes=new Uint8Array(input);let binary="";for(const byte of bytes)binary+=String.fromCharCode(byte);if(typeof btoa<"u")return btoa(binary);return Buffer.from(input).toString("base64")}if(typeof Blob<"u"&&input instanceof Blob)return new Promise((resolve,reject)=>{const reader=new FileReader;reader.onload=()=>{const result=reader.result,base64Part=result.split(",")[1]??result;resolve(base64Part)};reader.onerror=reject;reader.readAsDataURL(input)});if(typeof HTMLCanvasElement<"u"&&input instanceof HTMLCanvasElement)return input.toDataURL().split(",")[1]??"";return""}async function execute(){const val=unref(source),result=await encode(val);base64.value=result;return result}execute().catch(()=>{});if(isRef(source))watch(source,()=>{execute().catch(()=>{})});return{base64,execute}}
|
package/dist/useBattery.js
CHANGED
|
@@ -1,38 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { noop } from "./_shared";
|
|
3
|
-
export function useBattery() {
|
|
4
|
-
const nav = typeof navigator < "u" ? navigator : void 0, isSupported = ref(!!nav?.getBattery), charging = ref(!1), chargingTime = ref(0), dischargingTime = ref(0), level = ref(1), cleanups = [];
|
|
5
|
-
let cleanup = noop;
|
|
6
|
-
if (isSupported.value && nav?.getBattery)
|
|
7
|
-
nav.getBattery().then((battery) => {
|
|
8
|
-
const updateBatteryInfo = () => {
|
|
9
|
-
charging.value = battery.charging;
|
|
10
|
-
chargingTime.value = battery.chargingTime;
|
|
11
|
-
dischargingTime.value = battery.dischargingTime;
|
|
12
|
-
level.value = battery.level;
|
|
13
|
-
};
|
|
14
|
-
updateBatteryInfo();
|
|
15
|
-
battery.addEventListener("chargingchange", updateBatteryInfo);
|
|
16
|
-
battery.addEventListener("chargingtimechange", updateBatteryInfo);
|
|
17
|
-
battery.addEventListener("dischargingtimechange", updateBatteryInfo);
|
|
18
|
-
battery.addEventListener("levelchange", updateBatteryInfo);
|
|
19
|
-
cleanups.push(() => {
|
|
20
|
-
battery.removeEventListener("chargingchange", updateBatteryInfo);
|
|
21
|
-
battery.removeEventListener("chargingtimechange", updateBatteryInfo);
|
|
22
|
-
battery.removeEventListener("dischargingtimechange", updateBatteryInfo);
|
|
23
|
-
battery.removeEventListener("levelchange", updateBatteryInfo);
|
|
24
|
-
});
|
|
25
|
-
cleanup = () => {
|
|
26
|
-
for (const fn of cleanups)
|
|
27
|
-
fn();
|
|
28
|
-
cleanups.length = 0;
|
|
29
|
-
cleanup = noop;
|
|
30
|
-
};
|
|
31
|
-
}).catch(() => {
|
|
32
|
-
isSupported.value = !1;
|
|
33
|
-
});
|
|
34
|
-
try {
|
|
35
|
-
onUnmounted(() => cleanup());
|
|
36
|
-
} catch {}
|
|
37
|
-
return { charging, chargingTime, dischargingTime, level, isSupported };
|
|
38
|
-
}
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";import{noop}from"./_shared";export function useBattery(){const nav=typeof navigator<"u"?navigator:void 0,isSupported=ref(!!nav?.getBattery),charging=ref(!1),chargingTime=ref(0),dischargingTime=ref(0),level=ref(1),cleanups=[];let cleanup=noop;if(isSupported.value&&nav?.getBattery)nav.getBattery().then((battery)=>{const updateBatteryInfo=()=>{charging.value=battery.charging;chargingTime.value=battery.chargingTime;dischargingTime.value=battery.dischargingTime;level.value=battery.level};updateBatteryInfo();battery.addEventListener("chargingchange",updateBatteryInfo);battery.addEventListener("chargingtimechange",updateBatteryInfo);battery.addEventListener("dischargingtimechange",updateBatteryInfo);battery.addEventListener("levelchange",updateBatteryInfo);cleanups.push(()=>{battery.removeEventListener("chargingchange",updateBatteryInfo);battery.removeEventListener("chargingtimechange",updateBatteryInfo);battery.removeEventListener("dischargingtimechange",updateBatteryInfo);battery.removeEventListener("levelchange",updateBatteryInfo)});cleanup=()=>{for(const fn of cleanups)fn();cleanups.length=0;cleanup=noop}}).catch(()=>{isSupported.value=!1});try{onUnmounted(()=>cleanup())}catch{}return{charging,chargingTime,dischargingTime,level,isSupported}}
|
package/dist/useBreakpoints.js
CHANGED
|
@@ -1,97 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { defaultWindow } from "./_shared";
|
|
3
|
-
export function useBreakpoints(breakpoints) {
|
|
4
|
-
const win = defaultWindow(), width = ref(win ? win.innerWidth : 0);
|
|
5
|
-
function updateWidth() {
|
|
6
|
-
if (win)
|
|
7
|
-
width.value = win.innerWidth;
|
|
8
|
-
}
|
|
9
|
-
if (win) {
|
|
10
|
-
win.addEventListener("resize", updateWidth);
|
|
11
|
-
try {
|
|
12
|
-
onUnmounted(() => {
|
|
13
|
-
win.removeEventListener("resize", updateWidth);
|
|
14
|
-
});
|
|
15
|
-
} catch {}
|
|
16
|
-
}
|
|
17
|
-
function getValue(k) {
|
|
18
|
-
return breakpoints[k];
|
|
19
|
-
}
|
|
20
|
-
function greaterOrEqual(k) {
|
|
21
|
-
return computed(() => width.value >= getValue(k));
|
|
22
|
-
}
|
|
23
|
-
function smallerOrEqual(k) {
|
|
24
|
-
return computed(() => width.value <= getValue(k));
|
|
25
|
-
}
|
|
26
|
-
function between(a, b) {
|
|
27
|
-
return computed(() => width.value >= getValue(a) && width.value < getValue(b));
|
|
28
|
-
}
|
|
29
|
-
function isGreater(k) {
|
|
30
|
-
return computed(() => width.value > getValue(k));
|
|
31
|
-
}
|
|
32
|
-
function isSmaller(k) {
|
|
33
|
-
return computed(() => width.value < getValue(k));
|
|
34
|
-
}
|
|
35
|
-
function current() {
|
|
36
|
-
return computed(() => {
|
|
37
|
-
return Object.keys(breakpoints).sort((a, b) => breakpoints[a] - breakpoints[b]).filter((k) => width.value >= breakpoints[k]);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
greaterOrEqual,
|
|
42
|
-
smallerOrEqual,
|
|
43
|
-
between,
|
|
44
|
-
isGreater,
|
|
45
|
-
isSmaller,
|
|
46
|
-
current
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
export const breakpointsTailwind = {
|
|
50
|
-
sm: 640,
|
|
51
|
-
md: 768,
|
|
52
|
-
lg: 1024,
|
|
53
|
-
xl: 1280,
|
|
54
|
-
"2xl": 1536
|
|
55
|
-
}, breakpointsBootstrap = {
|
|
56
|
-
sm: 576,
|
|
57
|
-
md: 768,
|
|
58
|
-
lg: 992,
|
|
59
|
-
xl: 1200,
|
|
60
|
-
xxl: 1400
|
|
61
|
-
}, breakpointsBootstrapV5 = breakpointsBootstrap, breakpointsAntDesign = {
|
|
62
|
-
xs: 480,
|
|
63
|
-
sm: 576,
|
|
64
|
-
md: 768,
|
|
65
|
-
lg: 992,
|
|
66
|
-
xl: 1200,
|
|
67
|
-
xxl: 1600
|
|
68
|
-
}, breakpointsMaterialDesign = {
|
|
69
|
-
xs: 600,
|
|
70
|
-
sm: 960,
|
|
71
|
-
md: 1264,
|
|
72
|
-
lg: 1904
|
|
73
|
-
}, breakpointsQuasar = {
|
|
74
|
-
xs: 600,
|
|
75
|
-
sm: 1024,
|
|
76
|
-
md: 1440,
|
|
77
|
-
lg: 1920
|
|
78
|
-
}, breakpointsMasterCss = {
|
|
79
|
-
"3xs": 360,
|
|
80
|
-
"2xs": 480,
|
|
81
|
-
xs: 600,
|
|
82
|
-
sm: 768,
|
|
83
|
-
md: 1024,
|
|
84
|
-
lg: 1280,
|
|
85
|
-
xl: 1440,
|
|
86
|
-
"2xl": 1600,
|
|
87
|
-
"3xl": 1920,
|
|
88
|
-
"4xl": 2560
|
|
89
|
-
}, breakpointsSematic = {
|
|
90
|
-
mobileS: 320,
|
|
91
|
-
mobileM: 375,
|
|
92
|
-
mobileL: 425,
|
|
93
|
-
tablet: 768,
|
|
94
|
-
laptop: 1024,
|
|
95
|
-
laptopL: 1440,
|
|
96
|
-
desktop: 2560
|
|
97
|
-
};
|
|
1
|
+
import{computed,ref,onUnmounted}from"@stacksjs/stx";import{defaultWindow}from"./_shared";export function useBreakpoints(breakpoints){const win=defaultWindow(),width=ref(win?win.innerWidth:0);function updateWidth(){if(win)width.value=win.innerWidth}if(win){win.addEventListener("resize",updateWidth);try{onUnmounted(()=>{win.removeEventListener("resize",updateWidth)})}catch{}}function getValue(k){return breakpoints[k]}function greaterOrEqual(k){return computed(()=>width.value>=getValue(k))}function smallerOrEqual(k){return computed(()=>width.value<=getValue(k))}function between(a,b){return computed(()=>width.value>=getValue(a)&&width.value<getValue(b))}function isGreater(k){return computed(()=>width.value>getValue(k))}function isSmaller(k){return computed(()=>width.value<getValue(k))}function current(){return computed(()=>{return Object.keys(breakpoints).sort((a,b)=>breakpoints[a]-breakpoints[b]).filter((k)=>width.value>=breakpoints[k])})}return{greaterOrEqual,smallerOrEqual,between,isGreater,isSmaller,current}}export const breakpointsTailwind={sm:640,md:768,lg:1024,xl:1280,"2xl":1536},breakpointsBootstrap={sm:576,md:768,lg:992,xl:1200,xxl:1400},breakpointsBootstrapV5=breakpointsBootstrap,breakpointsAntDesign={xs:480,sm:576,md:768,lg:992,xl:1200,xxl:1600},breakpointsMaterialDesign={xs:600,sm:960,md:1264,lg:1904},breakpointsQuasar={xs:600,sm:1024,md:1440,lg:1920},breakpointsMasterCss={"3xs":360,"2xs":480,xs:600,sm:768,md:1024,lg:1280,xl:1440,"2xl":1600,"3xl":1920,"4xl":2560},breakpointsSematic={mobileS:320,mobileM:375,mobileL:425,tablet:768,laptop:1024,laptopL:1440,desktop:2560};
|
|
@@ -1,31 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function useBroadcastChannel(name) {
|
|
3
|
-
const isSupported = ref(typeof BroadcastChannel < "u"), channel = ref(void 0), data = ref(null), error = ref(null), isClosed = ref(!1);
|
|
4
|
-
if (isSupported.value) {
|
|
5
|
-
const bc = new BroadcastChannel(name);
|
|
6
|
-
channel.value = bc;
|
|
7
|
-
bc.onmessage = (e) => {
|
|
8
|
-
data.value = e.data;
|
|
9
|
-
};
|
|
10
|
-
bc.onmessageerror = (e) => {
|
|
11
|
-
error.value = e;
|
|
12
|
-
};
|
|
13
|
-
try {
|
|
14
|
-
onUnmounted(() => {
|
|
15
|
-
bc.close();
|
|
16
|
-
isClosed.value = !0;
|
|
17
|
-
});
|
|
18
|
-
} catch {}
|
|
19
|
-
}
|
|
20
|
-
function post(message) {
|
|
21
|
-
if (channel.value && !isClosed.value)
|
|
22
|
-
channel.value.postMessage(message);
|
|
23
|
-
}
|
|
24
|
-
function close() {
|
|
25
|
-
if (channel.value && !isClosed.value) {
|
|
26
|
-
channel.value.close();
|
|
27
|
-
isClosed.value = !0;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return { isSupported, channel, data, error, post, close, isClosed };
|
|
31
|
-
}
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";export function useBroadcastChannel(name){const isSupported=ref(typeof BroadcastChannel<"u"),channel=ref(void 0),data=ref(null),error=ref(null),isClosed=ref(!1);if(isSupported.value){const bc=new BroadcastChannel(name);channel.value=bc;bc.onmessage=(e)=>{data.value=e.data};bc.onmessageerror=(e)=>{error.value=e};try{onUnmounted(()=>{bc.close();isClosed.value=!0})}catch{}}function post(message){if(channel.value&&!isClosed.value)channel.value.postMessage(message)}function close(){if(channel.value&&!isClosed.value){channel.value.close();isClosed.value=!0}}return{isSupported,channel,data,error,post,close,isClosed}}
|
|
@@ -1,64 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { defaultWindow } from "./_shared";
|
|
3
|
-
export function useBrowserLocation() {
|
|
4
|
-
const win = defaultWindow();
|
|
5
|
-
function readLocation() {
|
|
6
|
-
if (!win)
|
|
7
|
-
return {
|
|
8
|
-
href: "",
|
|
9
|
-
protocol: "",
|
|
10
|
-
host: "",
|
|
11
|
-
hostname: "",
|
|
12
|
-
port: "",
|
|
13
|
-
pathname: "",
|
|
14
|
-
search: "",
|
|
15
|
-
hash: "",
|
|
16
|
-
origin: ""
|
|
17
|
-
};
|
|
18
|
-
return {
|
|
19
|
-
href: win.location.href,
|
|
20
|
-
protocol: win.location.protocol,
|
|
21
|
-
host: win.location.host,
|
|
22
|
-
hostname: win.location.hostname,
|
|
23
|
-
port: win.location.port,
|
|
24
|
-
pathname: win.location.pathname,
|
|
25
|
-
search: win.location.search,
|
|
26
|
-
hash: win.location.hash,
|
|
27
|
-
origin: win.location.origin
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const initial = readLocation(), href = ref(initial.href), protocol = ref(initial.protocol), host = ref(initial.host), hostname = ref(initial.hostname), port = ref(initial.port), pathname = ref(initial.pathname), search = ref(initial.search), hash = ref(initial.hash), origin = ref(initial.origin);
|
|
31
|
-
function update() {
|
|
32
|
-
const loc = readLocation();
|
|
33
|
-
href.value = loc.href;
|
|
34
|
-
protocol.value = loc.protocol;
|
|
35
|
-
host.value = loc.host;
|
|
36
|
-
hostname.value = loc.hostname;
|
|
37
|
-
port.value = loc.port;
|
|
38
|
-
pathname.value = loc.pathname;
|
|
39
|
-
search.value = loc.search;
|
|
40
|
-
hash.value = loc.hash;
|
|
41
|
-
origin.value = loc.origin;
|
|
42
|
-
}
|
|
43
|
-
if (win) {
|
|
44
|
-
win.addEventListener("popstate", update);
|
|
45
|
-
win.addEventListener("hashchange", update);
|
|
46
|
-
try {
|
|
47
|
-
onUnmounted(() => {
|
|
48
|
-
win.removeEventListener("popstate", update);
|
|
49
|
-
win.removeEventListener("hashchange", update);
|
|
50
|
-
});
|
|
51
|
-
} catch {}
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
href,
|
|
55
|
-
protocol,
|
|
56
|
-
host,
|
|
57
|
-
hostname,
|
|
58
|
-
port,
|
|
59
|
-
pathname,
|
|
60
|
-
search,
|
|
61
|
-
hash,
|
|
62
|
-
origin
|
|
63
|
-
};
|
|
64
|
-
}
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";import{defaultWindow}from"./_shared";export function useBrowserLocation(){const win=defaultWindow();function readLocation(){if(!win)return{href:"",protocol:"",host:"",hostname:"",port:"",pathname:"",search:"",hash:"",origin:""};return{href:win.location.href,protocol:win.location.protocol,host:win.location.host,hostname:win.location.hostname,port:win.location.port,pathname:win.location.pathname,search:win.location.search,hash:win.location.hash,origin:win.location.origin}}const initial=readLocation(),href=ref(initial.href),protocol=ref(initial.protocol),host=ref(initial.host),hostname=ref(initial.hostname),port=ref(initial.port),pathname=ref(initial.pathname),search=ref(initial.search),hash=ref(initial.hash),origin=ref(initial.origin);function update(){const loc=readLocation();href.value=loc.href;protocol.value=loc.protocol;host.value=loc.host;hostname.value=loc.hostname;port.value=loc.port;pathname.value=loc.pathname;search.value=loc.search;hash.value=loc.hash;origin.value=loc.origin}if(win){win.addEventListener("popstate",update);win.addEventListener("hashchange",update);try{onUnmounted(()=>{win.removeEventListener("popstate",update);win.removeEventListener("hashchange",update)})}catch{}}return{href,protocol,host,hostname,port,pathname,search,hash,origin}}
|