@stacksjs/composables 0.70.258 → 0.70.260
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/useMagicKeys.js
CHANGED
|
@@ -1,81 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function useMagicKeys() {
|
|
3
|
-
const current = ref(new Set), refs = new Map;
|
|
4
|
-
function getRef(key) {
|
|
5
|
-
const lower = key.toLowerCase();
|
|
6
|
-
if (!refs.has(lower))
|
|
7
|
-
refs.set(lower, ref(!1));
|
|
8
|
-
return refs.get(lower);
|
|
9
|
-
}
|
|
10
|
-
function updateCombos() {
|
|
11
|
-
for (const [key, r] of refs)
|
|
12
|
-
if (key.includes("+")) {
|
|
13
|
-
const parts = key.split("+").map((p) => p.trim().toLowerCase());
|
|
14
|
-
r.value = parts.every((p) => current.value.has(p));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if (typeof window < "u") {
|
|
18
|
-
const onKeyDown = (e) => {
|
|
19
|
-
const key = e.key.toLowerCase();
|
|
20
|
-
current.value.add(key);
|
|
21
|
-
current.value = new Set(current.value);
|
|
22
|
-
const r = getRef(key);
|
|
23
|
-
r.value = !0;
|
|
24
|
-
if (e.ctrlKey) {
|
|
25
|
-
getRef("ctrl").value = !0;
|
|
26
|
-
current.value.add("ctrl");
|
|
27
|
-
}
|
|
28
|
-
if (e.shiftKey) {
|
|
29
|
-
getRef("shift").value = !0;
|
|
30
|
-
current.value.add("shift");
|
|
31
|
-
}
|
|
32
|
-
if (e.altKey) {
|
|
33
|
-
getRef("alt").value = !0;
|
|
34
|
-
current.value.add("alt");
|
|
35
|
-
}
|
|
36
|
-
if (e.metaKey) {
|
|
37
|
-
getRef("meta").value = !0;
|
|
38
|
-
current.value.add("meta");
|
|
39
|
-
}
|
|
40
|
-
updateCombos();
|
|
41
|
-
}, onKeyUp = (e) => {
|
|
42
|
-
const key = e.key.toLowerCase();
|
|
43
|
-
current.value.delete(key);
|
|
44
|
-
current.value = new Set(current.value);
|
|
45
|
-
const r = getRef(key);
|
|
46
|
-
r.value = !1;
|
|
47
|
-
if (!e.ctrlKey) {
|
|
48
|
-
getRef("ctrl").value = !1;
|
|
49
|
-
current.value.delete("ctrl");
|
|
50
|
-
}
|
|
51
|
-
if (!e.shiftKey) {
|
|
52
|
-
getRef("shift").value = !1;
|
|
53
|
-
current.value.delete("shift");
|
|
54
|
-
}
|
|
55
|
-
if (!e.altKey) {
|
|
56
|
-
getRef("alt").value = !1;
|
|
57
|
-
current.value.delete("alt");
|
|
58
|
-
}
|
|
59
|
-
if (!e.metaKey) {
|
|
60
|
-
getRef("meta").value = !1;
|
|
61
|
-
current.value.delete("meta");
|
|
62
|
-
}
|
|
63
|
-
updateCombos();
|
|
64
|
-
};
|
|
65
|
-
window.addEventListener("keydown", onKeyDown, { passive: !0 });
|
|
66
|
-
window.addEventListener("keyup", onKeyUp, { passive: !0 });
|
|
67
|
-
try {
|
|
68
|
-
onUnmounted(() => {
|
|
69
|
-
window.removeEventListener("keydown", onKeyDown);
|
|
70
|
-
window.removeEventListener("keyup", onKeyUp);
|
|
71
|
-
});
|
|
72
|
-
} catch {}
|
|
73
|
-
}
|
|
74
|
-
return new Proxy({ current }, {
|
|
75
|
-
get(target, prop) {
|
|
76
|
-
if (prop === "current")
|
|
77
|
-
return current;
|
|
78
|
-
return getRef(prop);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";export function useMagicKeys(){const current=ref(new Set),refs=new Map;function getRef(key){const lower=key.toLowerCase();if(!refs.has(lower))refs.set(lower,ref(!1));return refs.get(lower)}function updateCombos(){for(const[key,r]of refs)if(key.includes("+")){const parts=key.split("+").map((p)=>p.trim().toLowerCase());r.value=parts.every((p)=>current.value.has(p))}}if(typeof window<"u"){const onKeyDown=(e)=>{const key=e.key.toLowerCase();current.value.add(key);current.value=new Set(current.value);const r=getRef(key);r.value=!0;if(e.ctrlKey){getRef("ctrl").value=!0;current.value.add("ctrl")}if(e.shiftKey){getRef("shift").value=!0;current.value.add("shift")}if(e.altKey){getRef("alt").value=!0;current.value.add("alt")}if(e.metaKey){getRef("meta").value=!0;current.value.add("meta")}updateCombos()},onKeyUp=(e)=>{const key=e.key.toLowerCase();current.value.delete(key);current.value=new Set(current.value);const r=getRef(key);r.value=!1;if(!e.ctrlKey){getRef("ctrl").value=!1;current.value.delete("ctrl")}if(!e.shiftKey){getRef("shift").value=!1;current.value.delete("shift")}if(!e.altKey){getRef("alt").value=!1;current.value.delete("alt")}if(!e.metaKey){getRef("meta").value=!1;current.value.delete("meta")}updateCombos()};window.addEventListener("keydown",onKeyDown,{passive:!0});window.addEventListener("keyup",onKeyUp,{passive:!0});try{onUnmounted(()=>{window.removeEventListener("keydown",onKeyDown);window.removeEventListener("keyup",onKeyUp)})}catch{}}return new Proxy({current},{get(target,prop){if(prop==="current")return current;return getRef(prop)}})}
|
|
@@ -1,64 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
function cloneValue(val, shouldClone) {
|
|
3
|
-
if (!shouldClone)
|
|
4
|
-
return val;
|
|
5
|
-
if (typeof structuredClone === "function")
|
|
6
|
-
return structuredClone(val);
|
|
7
|
-
return JSON.parse(JSON.stringify(val));
|
|
8
|
-
}
|
|
9
|
-
export function useManualRefHistory(source, options = {}) {
|
|
10
|
-
const { capacity = 1 / 0, clone = !1 } = options, undoStack = ref([
|
|
11
|
-
{ snapshot: cloneValue(source.value, clone), timestamp: Date.now() }
|
|
12
|
-
]), redoStack = ref([]), canUndo = computed(() => undoStack.value.length > 1), canRedo = computed(() => redoStack.value.length > 0), last = computed(() => {
|
|
13
|
-
return undoStack.value[undoStack.value.length - 1];
|
|
14
|
-
});
|
|
15
|
-
function commit() {
|
|
16
|
-
const record = {
|
|
17
|
-
snapshot: cloneValue(source.value, clone),
|
|
18
|
-
timestamp: Date.now()
|
|
19
|
-
};
|
|
20
|
-
undoStack.value = [...undoStack.value, record];
|
|
21
|
-
if (capacity !== 1 / 0 && undoStack.value.length > capacity)
|
|
22
|
-
undoStack.value = undoStack.value.slice(undoStack.value.length - capacity);
|
|
23
|
-
redoStack.value = [];
|
|
24
|
-
}
|
|
25
|
-
function undo() {
|
|
26
|
-
if (undoStack.value.length <= 1)
|
|
27
|
-
return;
|
|
28
|
-
const current = undoStack.value[undoStack.value.length - 1], newUndoStack = undoStack.value.slice(0, -1);
|
|
29
|
-
undoStack.value = newUndoStack;
|
|
30
|
-
if (current)
|
|
31
|
-
redoStack.value = [...redoStack.value, current];
|
|
32
|
-
const previous = newUndoStack[newUndoStack.length - 1];
|
|
33
|
-
if (!previous)
|
|
34
|
-
return;
|
|
35
|
-
source.value = cloneValue(previous.snapshot, clone);
|
|
36
|
-
}
|
|
37
|
-
function redo() {
|
|
38
|
-
if (redoStack.value.length === 0)
|
|
39
|
-
return;
|
|
40
|
-
const next = redoStack.value[redoStack.value.length - 1];
|
|
41
|
-
redoStack.value = redoStack.value.slice(0, -1);
|
|
42
|
-
if (next)
|
|
43
|
-
undoStack.value = [...undoStack.value, next];
|
|
44
|
-
if (!next)
|
|
45
|
-
return;
|
|
46
|
-
source.value = cloneValue(next.snapshot, clone);
|
|
47
|
-
}
|
|
48
|
-
function clear() {
|
|
49
|
-
undoStack.value = [
|
|
50
|
-
{ snapshot: cloneValue(source.value, clone), timestamp: Date.now() }
|
|
51
|
-
];
|
|
52
|
-
redoStack.value = [];
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
history: undoStack,
|
|
56
|
-
commit,
|
|
57
|
-
undo,
|
|
58
|
-
redo,
|
|
59
|
-
canUndo,
|
|
60
|
-
canRedo,
|
|
61
|
-
clear,
|
|
62
|
-
last
|
|
63
|
-
};
|
|
64
|
-
}
|
|
1
|
+
import{computed,ref}from"@stacksjs/stx";function cloneValue(val,shouldClone){if(!shouldClone)return val;if(typeof structuredClone==="function")return structuredClone(val);return JSON.parse(JSON.stringify(val))}export function useManualRefHistory(source,options={}){const{capacity=1/0,clone=!1}=options,undoStack=ref([{snapshot:cloneValue(source.value,clone),timestamp:Date.now()}]),redoStack=ref([]),canUndo=computed(()=>undoStack.value.length>1),canRedo=computed(()=>redoStack.value.length>0),last=computed(()=>{return undoStack.value[undoStack.value.length-1]});function commit(){const record={snapshot:cloneValue(source.value,clone),timestamp:Date.now()};undoStack.value=[...undoStack.value,record];if(capacity!==1/0&&undoStack.value.length>capacity)undoStack.value=undoStack.value.slice(undoStack.value.length-capacity);redoStack.value=[]}function undo(){if(undoStack.value.length<=1)return;const current=undoStack.value[undoStack.value.length-1],newUndoStack=undoStack.value.slice(0,-1);undoStack.value=newUndoStack;if(current)redoStack.value=[...redoStack.value,current];const previous=newUndoStack[newUndoStack.length-1];if(!previous)return;source.value=cloneValue(previous.snapshot,clone)}function redo(){if(redoStack.value.length===0)return;const next=redoStack.value[redoStack.value.length-1];redoStack.value=redoStack.value.slice(0,-1);if(next)undoStack.value=[...undoStack.value,next];if(!next)return;source.value=cloneValue(next.snapshot,clone)}function clear(){undoStack.value=[{snapshot:cloneValue(source.value,clone),timestamp:Date.now()}];redoStack.value=[]}return{history:undoStack,commit,undo,redo,canUndo,canRedo,clear,last}}
|
package/dist/useMath.js
CHANGED
|
@@ -1,52 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
function unref(val) {
|
|
3
|
-
if (val && typeof val === "object" && "value" in val && "subscribe" in val)
|
|
4
|
-
return val.value;
|
|
5
|
-
return val;
|
|
6
|
-
}
|
|
7
|
-
export function useAbs(value) {
|
|
8
|
-
return computed(() => Math.abs(unref(value)));
|
|
9
|
-
}
|
|
10
|
-
export function useAverage(...args) {
|
|
11
|
-
return computed(() => {
|
|
12
|
-
const values = args.map(unref);
|
|
13
|
-
return values.length ? values.reduce((a, b) => a + b, 0) / values.length : 0;
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
export function useCeil(value) {
|
|
17
|
-
return computed(() => Math.ceil(unref(value)));
|
|
18
|
-
}
|
|
19
|
-
export function useClamp(value, min, max) {
|
|
20
|
-
return computed(() => Math.min(unref(max), Math.max(unref(min), unref(value))));
|
|
21
|
-
}
|
|
22
|
-
export function useFloor(value) {
|
|
23
|
-
return computed(() => Math.floor(unref(value)));
|
|
24
|
-
}
|
|
25
|
-
export function useMax(...args) {
|
|
26
|
-
return computed(() => Math.max(...args.map(unref)));
|
|
27
|
-
}
|
|
28
|
-
export function useMin(...args) {
|
|
29
|
-
return computed(() => Math.min(...args.map(unref)));
|
|
30
|
-
}
|
|
31
|
-
export function usePrecision(value, digits = 0) {
|
|
32
|
-
return computed(() => Number(unref(value).toFixed(Math.max(0, Math.min(100, unref(digits))))));
|
|
33
|
-
}
|
|
34
|
-
export function useRound(value) {
|
|
35
|
-
return computed(() => Math.round(unref(value)));
|
|
36
|
-
}
|
|
37
|
-
export function useSum(...args) {
|
|
38
|
-
return computed(() => args.map(unref).reduce((a, b) => a + b, 0));
|
|
39
|
-
}
|
|
40
|
-
export function useTrunc(value) {
|
|
41
|
-
return computed(() => Math.trunc(unref(value)));
|
|
42
|
-
}
|
|
43
|
-
export function logicNot(value) {
|
|
44
|
-
return computed(() => !unref(value));
|
|
45
|
-
}
|
|
46
|
-
export function logicOr(...args) {
|
|
47
|
-
return computed(() => args.some((a) => unref(a)));
|
|
48
|
-
}
|
|
49
|
-
export const or = logicOr;
|
|
50
|
-
export function and(...args) {
|
|
51
|
-
return computed(() => args.every((a) => unref(a)));
|
|
52
|
-
}
|
|
1
|
+
import{computed,ref}from"@stacksjs/stx";function unref(val){if(val&&typeof val==="object"&&"value"in val&&"subscribe"in val)return val.value;return val}export function useAbs(value){return computed(()=>Math.abs(unref(value)))}export function useAverage(...args){return computed(()=>{const values=args.map(unref);return values.length?values.reduce((a,b)=>a+b,0)/values.length:0})}export function useCeil(value){return computed(()=>Math.ceil(unref(value)))}export function useClamp(value,min,max){return computed(()=>Math.min(unref(max),Math.max(unref(min),unref(value))))}export function useFloor(value){return computed(()=>Math.floor(unref(value)))}export function useMax(...args){return computed(()=>Math.max(...args.map(unref)))}export function useMin(...args){return computed(()=>Math.min(...args.map(unref)))}export function usePrecision(value,digits=0){return computed(()=>Number(unref(value).toFixed(Math.max(0,Math.min(100,unref(digits))))))}export function useRound(value){return computed(()=>Math.round(unref(value)))}export function useSum(...args){return computed(()=>args.map(unref).reduce((a,b)=>a+b,0))}export function useTrunc(value){return computed(()=>Math.trunc(unref(value)))}export function logicNot(value){return computed(()=>!unref(value))}export function logicOr(...args){return computed(()=>args.some((a)=>unref(a)))}export const or=logicOr;export function and(...args){return computed(()=>args.every((a)=>unref(a)))}
|
package/dist/useMediaQuery.js
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { defaultWindow, toValue } from "./_shared";
|
|
3
|
-
export function useMediaQuery(query) {
|
|
4
|
-
const win = defaultWindow(), matches = ref(!1);
|
|
5
|
-
if (!win || !win.matchMedia)
|
|
6
|
-
return matches;
|
|
7
|
-
const queryStr = toValue(query), mediaQuery = win.matchMedia(queryStr);
|
|
8
|
-
matches.value = mediaQuery.matches;
|
|
9
|
-
const handler = (e) => {
|
|
10
|
-
matches.value = e.matches;
|
|
11
|
-
};
|
|
12
|
-
mediaQuery.addEventListener("change", handler);
|
|
13
|
-
try {
|
|
14
|
-
onUnmounted(() => {
|
|
15
|
-
mediaQuery.removeEventListener("change", handler);
|
|
16
|
-
});
|
|
17
|
-
} catch {}
|
|
18
|
-
return matches;
|
|
19
|
-
}
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";import{defaultWindow,toValue}from"./_shared";export function useMediaQuery(query){const win=defaultWindow(),matches=ref(!1);if(!win||!win.matchMedia)return matches;const queryStr=toValue(query),mediaQuery=win.matchMedia(queryStr);matches.value=mediaQuery.matches;const handler=(e)=>{matches.value=e.matches};mediaQuery.addEventListener("change",handler);try{onUnmounted(()=>{mediaQuery.removeEventListener("change",handler)})}catch{}return matches}
|
package/dist/useMemoize.js
CHANGED
|
@@ -1,24 +1 @@
|
|
|
1
|
-
export function useMemoize(_fn, getKey) {
|
|
2
|
-
const cache = new Map, keyFn = getKey ?? ((...args) => JSON.stringify(args)), memoized = function(...args) {
|
|
3
|
-
const key = keyFn(...args);
|
|
4
|
-
if (cache.has(key))
|
|
5
|
-
return cache.get(key);
|
|
6
|
-
const result = _fn(...args);
|
|
7
|
-
cache.set(key, result);
|
|
8
|
-
return result;
|
|
9
|
-
};
|
|
10
|
-
memoized.load = (...args) => {
|
|
11
|
-
const key = keyFn(...args), result = _fn(...args);
|
|
12
|
-
cache.set(key, result);
|
|
13
|
-
return result;
|
|
14
|
-
};
|
|
15
|
-
memoized.delete = (...args) => {
|
|
16
|
-
const key = keyFn(...args);
|
|
17
|
-
cache.delete(key);
|
|
18
|
-
};
|
|
19
|
-
memoized.clear = () => {
|
|
20
|
-
cache.clear();
|
|
21
|
-
};
|
|
22
|
-
memoized.cache = cache;
|
|
23
|
-
return memoized;
|
|
24
|
-
}
|
|
1
|
+
export function useMemoize(_fn,getKey){const cache=new Map,keyFn=getKey??((...args)=>JSON.stringify(args)),memoized=function(...args){const key=keyFn(...args);if(cache.has(key))return cache.get(key);const result=_fn(...args);cache.set(key,result);return result};memoized.load=(...args)=>{const key=keyFn(...args),result=_fn(...args);cache.set(key,result);return result};memoized.delete=(...args)=>{const key=keyFn(...args);cache.delete(key)};memoized.clear=()=>{cache.clear()};memoized.cache=cache;return memoized}
|
package/dist/useMounted.js
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function useMounted() {
|
|
3
|
-
const isMounted = ref(!1);
|
|
4
|
-
Promise.resolve().then(() => {
|
|
5
|
-
isMounted.value = !0;
|
|
6
|
-
});
|
|
7
|
-
return isMounted;
|
|
8
|
-
}
|
|
1
|
+
import{ref}from"@stacksjs/stx";export function useMounted(){const isMounted=ref(!1);Promise.resolve().then(()=>{isMounted.value=!0});return isMounted}
|
package/dist/useMouse.js
CHANGED
|
@@ -1,67 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { noop } from "./_shared";
|
|
3
|
-
export function useMouse(options) {
|
|
4
|
-
const type = options?.type ?? "page", touch = options?.touch ?? !0, initialValue = options?.initialValue ?? { x: 0, y: 0 }, x = ref(initialValue.x), y = ref(initialValue.y), sourceType = ref(null);
|
|
5
|
-
let cleanup = noop;
|
|
6
|
-
if (typeof window < "u") {
|
|
7
|
-
const cleanups = [], getMouseCoords = (event) => {
|
|
8
|
-
switch (type) {
|
|
9
|
-
case "page":
|
|
10
|
-
return { x: event.pageX, y: event.pageY };
|
|
11
|
-
case "client":
|
|
12
|
-
return { x: event.clientX, y: event.clientY };
|
|
13
|
-
case "screen":
|
|
14
|
-
return { x: event.screenX, y: event.screenY };
|
|
15
|
-
default:
|
|
16
|
-
return { x: event.pageX, y: event.pageY };
|
|
17
|
-
}
|
|
18
|
-
}, mouseHandler = (event) => {
|
|
19
|
-
const coords = getMouseCoords(event);
|
|
20
|
-
x.value = coords.x;
|
|
21
|
-
y.value = coords.y;
|
|
22
|
-
sourceType.value = "mouse";
|
|
23
|
-
};
|
|
24
|
-
window.addEventListener("mousemove", mouseHandler, { passive: !0 });
|
|
25
|
-
cleanups.push(() => window.removeEventListener("mousemove", mouseHandler));
|
|
26
|
-
if (touch) {
|
|
27
|
-
const touchHandler = (event) => {
|
|
28
|
-
if (event.touches.length > 0) {
|
|
29
|
-
const touchEvent = event.touches[0];
|
|
30
|
-
if (!touchEvent)
|
|
31
|
-
return;
|
|
32
|
-
switch (type) {
|
|
33
|
-
case "page":
|
|
34
|
-
x.value = touchEvent.pageX;
|
|
35
|
-
y.value = touchEvent.pageY;
|
|
36
|
-
break;
|
|
37
|
-
case "client":
|
|
38
|
-
x.value = touchEvent.clientX;
|
|
39
|
-
y.value = touchEvent.clientY;
|
|
40
|
-
break;
|
|
41
|
-
case "screen":
|
|
42
|
-
x.value = touchEvent.screenX;
|
|
43
|
-
y.value = touchEvent.screenY;
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
sourceType.value = "touch";
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
window.addEventListener("touchstart", touchHandler, { passive: !0 });
|
|
50
|
-
window.addEventListener("touchmove", touchHandler, { passive: !0 });
|
|
51
|
-
cleanups.push(() => {
|
|
52
|
-
window.removeEventListener("touchstart", touchHandler);
|
|
53
|
-
window.removeEventListener("touchmove", touchHandler);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
cleanup = () => {
|
|
57
|
-
for (const fn of cleanups)
|
|
58
|
-
fn();
|
|
59
|
-
cleanups.length = 0;
|
|
60
|
-
cleanup = noop;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
onUnmounted(() => cleanup());
|
|
65
|
-
} catch {}
|
|
66
|
-
return { x, y, sourceType };
|
|
67
|
-
}
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";import{noop}from"./_shared";export function useMouse(options){const type=options?.type??"page",touch=options?.touch??!0,initialValue=options?.initialValue??{x:0,y:0},x=ref(initialValue.x),y=ref(initialValue.y),sourceType=ref(null);let cleanup=noop;if(typeof window<"u"){const cleanups=[],getMouseCoords=(event)=>{switch(type){case"page":return{x:event.pageX,y:event.pageY};case"client":return{x:event.clientX,y:event.clientY};case"screen":return{x:event.screenX,y:event.screenY};default:return{x:event.pageX,y:event.pageY}}},mouseHandler=(event)=>{const coords=getMouseCoords(event);x.value=coords.x;y.value=coords.y;sourceType.value="mouse"};window.addEventListener("mousemove",mouseHandler,{passive:!0});cleanups.push(()=>window.removeEventListener("mousemove",mouseHandler));if(touch){const touchHandler=(event)=>{if(event.touches.length>0){const touchEvent=event.touches[0];if(!touchEvent)return;switch(type){case"page":x.value=touchEvent.pageX;y.value=touchEvent.pageY;break;case"client":x.value=touchEvent.clientX;y.value=touchEvent.clientY;break;case"screen":x.value=touchEvent.screenX;y.value=touchEvent.screenY;break}sourceType.value="touch"}};window.addEventListener("touchstart",touchHandler,{passive:!0});window.addEventListener("touchmove",touchHandler,{passive:!0});cleanups.push(()=>{window.removeEventListener("touchstart",touchHandler);window.removeEventListener("touchmove",touchHandler)})}cleanup=()=>{for(const fn of cleanups)fn();cleanups.length=0;cleanup=noop}}try{onUnmounted(()=>cleanup())}catch{}return{x,y,sourceType}}
|
|
@@ -1,31 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { unref } from "./_shared";
|
|
3
|
-
export function useMouseInElement(target) {
|
|
4
|
-
const x = ref(0), y = ref(0), elementX = ref(0), elementY = ref(0), elementPositionX = ref(0), elementPositionY = ref(0), elementHeight = ref(0), elementWidth = ref(0), isOutside = ref(!0);
|
|
5
|
-
if (typeof window > "u")
|
|
6
|
-
return { x, y, elementX, elementY, elementPositionX, elementPositionY, elementHeight, elementWidth, isOutside };
|
|
7
|
-
const handler = (event) => {
|
|
8
|
-
x.value = event.pageX;
|
|
9
|
-
y.value = event.pageY;
|
|
10
|
-
const el = unref(target);
|
|
11
|
-
if (!el) {
|
|
12
|
-
isOutside.value = !0;
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const rect = el.getBoundingClientRect();
|
|
16
|
-
elementPositionX.value = rect.left + window.scrollX;
|
|
17
|
-
elementPositionY.value = rect.top + window.scrollY;
|
|
18
|
-
elementHeight.value = rect.height;
|
|
19
|
-
elementWidth.value = rect.width;
|
|
20
|
-
elementX.value = event.pageX - elementPositionX.value;
|
|
21
|
-
elementY.value = event.pageY - elementPositionY.value;
|
|
22
|
-
isOutside.value = elementX.value < 0 || elementY.value < 0 || elementX.value > elementWidth.value || elementY.value > elementHeight.value;
|
|
23
|
-
};
|
|
24
|
-
window.addEventListener("mousemove", handler, { passive: !0 });
|
|
25
|
-
try {
|
|
26
|
-
onUnmounted(() => {
|
|
27
|
-
window.removeEventListener("mousemove", handler);
|
|
28
|
-
});
|
|
29
|
-
} catch {}
|
|
30
|
-
return { x, y, elementX, elementY, elementPositionX, elementPositionY, elementHeight, elementWidth, isOutside };
|
|
31
|
-
}
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";import{unref}from"./_shared";export function useMouseInElement(target){const x=ref(0),y=ref(0),elementX=ref(0),elementY=ref(0),elementPositionX=ref(0),elementPositionY=ref(0),elementHeight=ref(0),elementWidth=ref(0),isOutside=ref(!0);if(typeof window>"u")return{x,y,elementX,elementY,elementPositionX,elementPositionY,elementHeight,elementWidth,isOutside};const handler=(event)=>{x.value=event.pageX;y.value=event.pageY;const el=unref(target);if(!el){isOutside.value=!0;return}const rect=el.getBoundingClientRect();elementPositionX.value=rect.left+window.scrollX;elementPositionY.value=rect.top+window.scrollY;elementHeight.value=rect.height;elementWidth.value=rect.width;elementX.value=event.pageX-elementPositionX.value;elementY.value=event.pageY-elementPositionY.value;isOutside.value=elementX.value<0||elementY.value<0||elementX.value>elementWidth.value||elementY.value>elementHeight.value};window.addEventListener("mousemove",handler,{passive:!0});try{onUnmounted(()=>{window.removeEventListener("mousemove",handler)})}catch{}return{x,y,elementX,elementY,elementPositionX,elementPositionY,elementHeight,elementWidth,isOutside}}
|
package/dist/useMousePressed.js
CHANGED
|
@@ -1,31 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { unref } from "./_shared";
|
|
3
|
-
export function useMousePressed(target) {
|
|
4
|
-
const pressed = ref(!1), sourceType = ref(null);
|
|
5
|
-
if (typeof window > "u")
|
|
6
|
-
return { pressed, sourceType };
|
|
7
|
-
const el = unref(target) ?? window, onMouseDown = () => {
|
|
8
|
-
pressed.value = !0;
|
|
9
|
-
sourceType.value = "mouse";
|
|
10
|
-
}, onTouchStart = () => {
|
|
11
|
-
pressed.value = !0;
|
|
12
|
-
sourceType.value = "touch";
|
|
13
|
-
}, onUp = () => {
|
|
14
|
-
pressed.value = !1;
|
|
15
|
-
};
|
|
16
|
-
el.addEventListener("mousedown", onMouseDown, { passive: !0 });
|
|
17
|
-
el.addEventListener("touchstart", onTouchStart, { passive: !0 });
|
|
18
|
-
window.addEventListener("mouseup", onUp, { passive: !0 });
|
|
19
|
-
window.addEventListener("touchend", onUp, { passive: !0 });
|
|
20
|
-
window.addEventListener("touchcancel", onUp, { passive: !0 });
|
|
21
|
-
try {
|
|
22
|
-
onUnmounted(() => {
|
|
23
|
-
el.removeEventListener("mousedown", onMouseDown);
|
|
24
|
-
el.removeEventListener("touchstart", onTouchStart);
|
|
25
|
-
window.removeEventListener("mouseup", onUp);
|
|
26
|
-
window.removeEventListener("touchend", onUp);
|
|
27
|
-
window.removeEventListener("touchcancel", onUp);
|
|
28
|
-
});
|
|
29
|
-
} catch {}
|
|
30
|
-
return { pressed, sourceType };
|
|
31
|
-
}
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";import{unref}from"./_shared";export function useMousePressed(target){const pressed=ref(!1),sourceType=ref(null);if(typeof window>"u")return{pressed,sourceType};const el=unref(target)??window,onMouseDown=()=>{pressed.value=!0;sourceType.value="mouse"},onTouchStart=()=>{pressed.value=!0;sourceType.value="touch"},onUp=()=>{pressed.value=!1};el.addEventListener("mousedown",onMouseDown,{passive:!0});el.addEventListener("touchstart",onTouchStart,{passive:!0});window.addEventListener("mouseup",onUp,{passive:!0});window.addEventListener("touchend",onUp,{passive:!0});window.addEventListener("touchcancel",onUp,{passive:!0});try{onUnmounted(()=>{el.removeEventListener("mousedown",onMouseDown);el.removeEventListener("touchstart",onTouchStart);window.removeEventListener("mouseup",onUp);window.removeEventListener("touchend",onUp);window.removeEventListener("touchcancel",onUp)})}catch{}return{pressed,sourceType}}
|
|
@@ -1,27 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { unref, noop } from "./_shared";
|
|
3
|
-
export function useMutationObserver(target, callback, options) {
|
|
4
|
-
const isSupported = ref(typeof window < "u" && "MutationObserver" in window);
|
|
5
|
-
let cleanup = noop;
|
|
6
|
-
(() => {
|
|
7
|
-
cleanup();
|
|
8
|
-
if (!isSupported.value)
|
|
9
|
-
return;
|
|
10
|
-
const el = unref(target);
|
|
11
|
-
if (!el)
|
|
12
|
-
return;
|
|
13
|
-
const observer = new MutationObserver(callback);
|
|
14
|
-
observer.observe(el, options ?? { childList: !0, subtree: !0 });
|
|
15
|
-
cleanup = () => {
|
|
16
|
-
observer.disconnect();
|
|
17
|
-
cleanup = noop;
|
|
18
|
-
};
|
|
19
|
-
})();
|
|
20
|
-
const stop = () => {
|
|
21
|
-
cleanup();
|
|
22
|
-
};
|
|
23
|
-
try {
|
|
24
|
-
onUnmounted(stop);
|
|
25
|
-
} catch {}
|
|
26
|
-
return { isSupported, stop };
|
|
27
|
-
}
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";import{unref,noop}from"./_shared";export function useMutationObserver(target,callback,options){const isSupported=ref(typeof window<"u"&&"MutationObserver"in window);let cleanup=noop;(()=>{cleanup();if(!isSupported.value)return;const el=unref(target);if(!el)return;const observer=new MutationObserver(callback);observer.observe(el,options??{childList:!0,subtree:!0});cleanup=()=>{observer.disconnect();cleanup=noop}})();const stop=()=>{cleanup()};try{onUnmounted(stop)}catch{}return{isSupported,stop}}
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function useNavigatorLanguage() {
|
|
3
|
-
const isSupported = ref(typeof navigator < "u" && "language" in navigator), language = ref(isSupported.value ? navigator.language : "");
|
|
4
|
-
if (typeof window < "u") {
|
|
5
|
-
const handler = () => {
|
|
6
|
-
if (isSupported.value)
|
|
7
|
-
language.value = navigator.language;
|
|
8
|
-
};
|
|
9
|
-
window.addEventListener("languagechange", handler, { passive: !0 });
|
|
10
|
-
try {
|
|
11
|
-
onUnmounted(() => {
|
|
12
|
-
window.removeEventListener("languagechange", handler);
|
|
13
|
-
});
|
|
14
|
-
} catch {}
|
|
15
|
-
}
|
|
16
|
-
return { language, isSupported };
|
|
17
|
-
}
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";export function useNavigatorLanguage(){const isSupported=ref(typeof navigator<"u"&&"language"in navigator),language=ref(isSupported.value?navigator.language:"");if(typeof window<"u"){const handler=()=>{if(isSupported.value)language.value=navigator.language};window.addEventListener("languagechange",handler,{passive:!0});try{onUnmounted(()=>{window.removeEventListener("languagechange",handler)})}catch{}}return{language,isSupported}}
|
package/dist/useNetwork.js
CHANGED
|
@@ -1,58 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function useNetwork() {
|
|
3
|
-
const isSupported = ref(typeof navigator < "u" && "connection" in navigator), isOnline = ref(typeof navigator < "u" ? navigator.onLine : !0), offlineAt = ref(void 0), onlineAt = ref(void 0), downlink = ref(void 0), downlinkMax = ref(void 0), effectiveType = ref(void 0), rtt = ref(void 0), saveData = ref(void 0), type = ref(void 0);
|
|
4
|
-
function updateNetworkInfo() {
|
|
5
|
-
if (!isSupported.value)
|
|
6
|
-
return;
|
|
7
|
-
const conn = navigator.connection;
|
|
8
|
-
if (conn) {
|
|
9
|
-
downlink.value = conn.downlink;
|
|
10
|
-
downlinkMax.value = conn.downlinkMax;
|
|
11
|
-
effectiveType.value = conn.effectiveType;
|
|
12
|
-
rtt.value = conn.rtt;
|
|
13
|
-
saveData.value = conn.saveData;
|
|
14
|
-
type.value = conn.type;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
updateNetworkInfo();
|
|
18
|
-
if (typeof window < "u") {
|
|
19
|
-
const onOnline = () => {
|
|
20
|
-
isOnline.value = !0;
|
|
21
|
-
onlineAt.value = Date.now();
|
|
22
|
-
}, onOffline = () => {
|
|
23
|
-
isOnline.value = !1;
|
|
24
|
-
offlineAt.value = Date.now();
|
|
25
|
-
};
|
|
26
|
-
window.addEventListener("online", onOnline);
|
|
27
|
-
window.addEventListener("offline", onOffline);
|
|
28
|
-
try {
|
|
29
|
-
onUnmounted(() => {
|
|
30
|
-
window.removeEventListener("online", onOnline);
|
|
31
|
-
window.removeEventListener("offline", onOffline);
|
|
32
|
-
});
|
|
33
|
-
} catch {}
|
|
34
|
-
if (isSupported.value) {
|
|
35
|
-
const conn = navigator.connection;
|
|
36
|
-
if (conn?.addEventListener) {
|
|
37
|
-
conn.addEventListener("change", updateNetworkInfo);
|
|
38
|
-
try {
|
|
39
|
-
onUnmounted(() => {
|
|
40
|
-
conn.removeEventListener("change", updateNetworkInfo);
|
|
41
|
-
});
|
|
42
|
-
} catch {}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
isSupported,
|
|
48
|
-
isOnline,
|
|
49
|
-
offlineAt,
|
|
50
|
-
onlineAt,
|
|
51
|
-
downlink,
|
|
52
|
-
downlinkMax,
|
|
53
|
-
effectiveType,
|
|
54
|
-
rtt,
|
|
55
|
-
saveData,
|
|
56
|
-
type
|
|
57
|
-
};
|
|
58
|
-
}
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";export function useNetwork(){const isSupported=ref(typeof navigator<"u"&&"connection"in navigator),isOnline=ref(typeof navigator<"u"?navigator.onLine:!0),offlineAt=ref(void 0),onlineAt=ref(void 0),downlink=ref(void 0),downlinkMax=ref(void 0),effectiveType=ref(void 0),rtt=ref(void 0),saveData=ref(void 0),type=ref(void 0);function updateNetworkInfo(){if(!isSupported.value)return;const conn=navigator.connection;if(conn){downlink.value=conn.downlink;downlinkMax.value=conn.downlinkMax;effectiveType.value=conn.effectiveType;rtt.value=conn.rtt;saveData.value=conn.saveData;type.value=conn.type}}updateNetworkInfo();if(typeof window<"u"){const onOnline=()=>{isOnline.value=!0;onlineAt.value=Date.now()},onOffline=()=>{isOnline.value=!1;offlineAt.value=Date.now()};window.addEventListener("online",onOnline);window.addEventListener("offline",onOffline);try{onUnmounted(()=>{window.removeEventListener("online",onOnline);window.removeEventListener("offline",onOffline)})}catch{}if(isSupported.value){const conn=navigator.connection;if(conn?.addEventListener){conn.addEventListener("change",updateNetworkInfo);try{onUnmounted(()=>{conn.removeEventListener("change",updateNetworkInfo)})}catch{}}}}return{isSupported,isOnline,offlineAt,onlineAt,downlink,downlinkMax,effectiveType,rtt,saveData,type}}
|
package/dist/useNow.js
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function useNow(options) {
|
|
3
|
-
const interval = options?.interval ?? 1000, now = ref(new Date), timer = setInterval(() => {
|
|
4
|
-
now.value = new Date;
|
|
5
|
-
}, interval);
|
|
6
|
-
try {
|
|
7
|
-
onUnmounted(() => clearInterval(timer));
|
|
8
|
-
} catch {}
|
|
9
|
-
return now;
|
|
10
|
-
}
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";export function useNow(options){const interval=options?.interval??1000,now=ref(new Date),timer=setInterval(()=>{now.value=new Date},interval);try{onUnmounted(()=>clearInterval(timer))}catch{}return now}
|
package/dist/useObjectUrl.js
CHANGED
|
@@ -1,23 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function useObjectUrl(source) {
|
|
3
|
-
const url = ref(void 0);
|
|
4
|
-
function release() {
|
|
5
|
-
if (url.value) {
|
|
6
|
-
URL.revokeObjectURL(url.value);
|
|
7
|
-
url.value = void 0;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
function update(val) {
|
|
11
|
-
release();
|
|
12
|
-
if (val)
|
|
13
|
-
url.value = URL.createObjectURL(val);
|
|
14
|
-
}
|
|
15
|
-
update(source.value);
|
|
16
|
-
watch(source, (val) => {
|
|
17
|
-
update(val);
|
|
18
|
-
});
|
|
19
|
-
try {
|
|
20
|
-
onUnmounted(() => release());
|
|
21
|
-
} catch {}
|
|
22
|
-
return url;
|
|
23
|
-
}
|
|
1
|
+
import{onUnmounted,ref,watch}from"@stacksjs/stx";export function useObjectUrl(source){const url=ref(void 0);function release(){if(url.value){URL.revokeObjectURL(url.value);url.value=void 0}}function update(val){release();if(val)url.value=URL.createObjectURL(val)}update(source.value);watch(source,(val)=>{update(val)});try{onUnmounted(()=>release())}catch{}return url}
|
|
@@ -1,45 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function useOffsetPagination(options = {}) {
|
|
3
|
-
const {
|
|
4
|
-
total: totalOption,
|
|
5
|
-
pageSize = 10,
|
|
6
|
-
page = 1,
|
|
7
|
-
onPageChange,
|
|
8
|
-
onPageSizeChange
|
|
9
|
-
} = options, currentPage = ref(page), currentPageSize = ref(pageSize), totalItems = typeof totalOption === "object" && totalOption && "value" in totalOption ? totalOption : ref(typeof totalOption === "number" ? totalOption : 0), pageCount = ref(Math.max(1, Math.ceil(totalItems.value / currentPageSize.value))), isFirstPage = ref(currentPage.value <= 1), isLastPage = ref(currentPage.value >= pageCount.value);
|
|
10
|
-
function updateComputed() {
|
|
11
|
-
pageCount.value = Math.max(1, Math.ceil(totalItems.value / currentPageSize.value));
|
|
12
|
-
isFirstPage.value = currentPage.value <= 1;
|
|
13
|
-
isLastPage.value = currentPage.value >= pageCount.value;
|
|
14
|
-
}
|
|
15
|
-
watch(currentPage, () => {
|
|
16
|
-
updateComputed();
|
|
17
|
-
onPageChange?.({ currentPage: currentPage.value, currentPageSize: currentPageSize.value });
|
|
18
|
-
});
|
|
19
|
-
watch(currentPageSize, () => {
|
|
20
|
-
currentPage.value = 1;
|
|
21
|
-
updateComputed();
|
|
22
|
-
onPageSizeChange?.({ currentPage: currentPage.value, currentPageSize: currentPageSize.value });
|
|
23
|
-
});
|
|
24
|
-
watch(totalItems, () => {
|
|
25
|
-
updateComputed();
|
|
26
|
-
});
|
|
27
|
-
function prev() {
|
|
28
|
-
if (currentPage.value > 1)
|
|
29
|
-
currentPage.value--;
|
|
30
|
-
}
|
|
31
|
-
function next() {
|
|
32
|
-
if (currentPage.value < pageCount.value)
|
|
33
|
-
currentPage.value++;
|
|
34
|
-
}
|
|
35
|
-
updateComputed();
|
|
36
|
-
return {
|
|
37
|
-
currentPage,
|
|
38
|
-
currentPageSize,
|
|
39
|
-
pageCount,
|
|
40
|
-
isFirstPage,
|
|
41
|
-
isLastPage,
|
|
42
|
-
prev,
|
|
43
|
-
next
|
|
44
|
-
};
|
|
45
|
-
}
|
|
1
|
+
import{computed,ref,watch}from"@stacksjs/stx";export function useOffsetPagination(options={}){const{total:totalOption,pageSize=10,page=1,onPageChange,onPageSizeChange}=options,currentPage=ref(page),currentPageSize=ref(pageSize),totalItems=typeof totalOption==="object"&&totalOption&&"value"in totalOption?totalOption:ref(typeof totalOption==="number"?totalOption:0),pageCount=ref(Math.max(1,Math.ceil(totalItems.value/currentPageSize.value))),isFirstPage=ref(currentPage.value<=1),isLastPage=ref(currentPage.value>=pageCount.value);function updateComputed(){pageCount.value=Math.max(1,Math.ceil(totalItems.value/currentPageSize.value));isFirstPage.value=currentPage.value<=1;isLastPage.value=currentPage.value>=pageCount.value}watch(currentPage,()=>{updateComputed();onPageChange?.({currentPage:currentPage.value,currentPageSize:currentPageSize.value})});watch(currentPageSize,()=>{currentPage.value=1;updateComputed();onPageSizeChange?.({currentPage:currentPage.value,currentPageSize:currentPageSize.value})});watch(totalItems,()=>{updateComputed()});function prev(){if(currentPage.value>1)currentPage.value--}function next(){if(currentPage.value<pageCount.value)currentPage.value++}updateComputed();return{currentPage,currentPageSize,pageCount,isFirstPage,isLastPage,prev,next}}
|
package/dist/useOnline.js
CHANGED
|
@@ -1,20 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function useOnline() {
|
|
3
|
-
const isOnline = ref(typeof navigator < "u" ? navigator.onLine : !0);
|
|
4
|
-
if (typeof window < "u") {
|
|
5
|
-
const onOnline = () => {
|
|
6
|
-
isOnline.value = !0;
|
|
7
|
-
}, onOffline = () => {
|
|
8
|
-
isOnline.value = !1;
|
|
9
|
-
};
|
|
10
|
-
window.addEventListener("online", onOnline);
|
|
11
|
-
window.addEventListener("offline", onOffline);
|
|
12
|
-
try {
|
|
13
|
-
onUnmounted(() => {
|
|
14
|
-
window.removeEventListener("online", onOnline);
|
|
15
|
-
window.removeEventListener("offline", onOffline);
|
|
16
|
-
});
|
|
17
|
-
} catch {}
|
|
18
|
-
}
|
|
19
|
-
return isOnline;
|
|
20
|
-
}
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";export function useOnline(){const isOnline=ref(typeof navigator<"u"?navigator.onLine:!0);if(typeof window<"u"){const onOnline=()=>{isOnline.value=!0},onOffline=()=>{isOnline.value=!1};window.addEventListener("online",onOnline);window.addEventListener("offline",onOffline);try{onUnmounted(()=>{window.removeEventListener("online",onOnline);window.removeEventListener("offline",onOffline)})}catch{}}return isOnline}
|
package/dist/usePageLeave.js
CHANGED
|
@@ -1,27 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { noop } from "./_shared";
|
|
3
|
-
export function usePageLeave() {
|
|
4
|
-
const isLeft = ref(!1);
|
|
5
|
-
let cleanup = noop;
|
|
6
|
-
if (typeof document < "u") {
|
|
7
|
-
const cleanups = [], onLeave = (event) => {
|
|
8
|
-
if (event.clientY <= 0 || event.clientX <= 0 || event.clientX >= (typeof window < "u" ? window.innerWidth : 0) || event.clientY >= (typeof window < "u" ? window.innerHeight : 0))
|
|
9
|
-
isLeft.value = !0;
|
|
10
|
-
}, onEnter = () => {
|
|
11
|
-
isLeft.value = !1;
|
|
12
|
-
};
|
|
13
|
-
document.documentElement.addEventListener("mouseleave", onLeave);
|
|
14
|
-
document.documentElement.addEventListener("mouseenter", onEnter);
|
|
15
|
-
cleanups.push(() => document.documentElement.removeEventListener("mouseleave", onLeave), () => document.documentElement.removeEventListener("mouseenter", onEnter));
|
|
16
|
-
cleanup = () => {
|
|
17
|
-
for (const fn of cleanups)
|
|
18
|
-
fn();
|
|
19
|
-
cleanups.length = 0;
|
|
20
|
-
cleanup = noop;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
try {
|
|
24
|
-
onUnmounted(() => cleanup());
|
|
25
|
-
} catch {}
|
|
26
|
-
return isLeft;
|
|
27
|
-
}
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";import{noop}from"./_shared";export function usePageLeave(){const isLeft=ref(!1);let cleanup=noop;if(typeof document<"u"){const cleanups=[],onLeave=(event)=>{if(event.clientY<=0||event.clientX<=0||event.clientX>=(typeof window<"u"?window.innerWidth:0)||event.clientY>=(typeof window<"u"?window.innerHeight:0))isLeft.value=!0},onEnter=()=>{isLeft.value=!1};document.documentElement.addEventListener("mouseleave",onLeave);document.documentElement.addEventListener("mouseenter",onEnter);cleanups.push(()=>document.documentElement.removeEventListener("mouseleave",onLeave),()=>document.documentElement.removeEventListener("mouseenter",onEnter));cleanup=()=>{for(const fn of cleanups)fn();cleanups.length=0;cleanup=noop}}try{onUnmounted(()=>cleanup())}catch{}return isLeft}
|