@lark-apaas/client-toolkit 1.2.11 → 1.2.13
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/lib/apis/hooks/useScrollReveal.d.ts +1 -0
- package/lib/apis/hooks/useScrollReveal.js +1 -0
- package/lib/apis/utils/scopedStorage.d.ts +1 -0
- package/lib/apis/utils/scopedStorage.js +2 -0
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/useScrollReveal.d.ts +61 -0
- package/lib/hooks/useScrollReveal.js +37 -0
- package/lib/utils/scopedStorage.d.ts +5 -0
- package/lib/utils/scopedStorage.js +46 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../hooks/useScrollReveal';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../hooks/useScrollReveal.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { scopedStorage } from '../../utils/scopedStorage';
|
package/lib/hooks/index.d.ts
CHANGED
package/lib/hooks/index.js
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Options for useScrollReveal hook
|
|
4
|
+
*/
|
|
5
|
+
export interface UseScrollRevealOptions<T extends HTMLElement = HTMLElement> {
|
|
6
|
+
/** Ref to the container element to scope the query (default: document.body) */
|
|
7
|
+
containerRef?: RefObject<T | null>;
|
|
8
|
+
/** IntersectionObserver threshold - element visibility percentage to trigger (default: 0.1) */
|
|
9
|
+
threshold?: number;
|
|
10
|
+
/** IntersectionObserver rootMargin - margin around root (default: '0px 0px -50px 0px') */
|
|
11
|
+
rootMargin?: string;
|
|
12
|
+
/** CSS class to add when element becomes visible (default: 'visible') */
|
|
13
|
+
visibleClass?: string;
|
|
14
|
+
/** CSS selector for elements to observe (default: '.scroll-reveal') */
|
|
15
|
+
selector?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Hook to enable scroll reveal animations using IntersectionObserver.
|
|
19
|
+
*
|
|
20
|
+
* Observes elements with the specified selector and adds a visibility class
|
|
21
|
+
* when they enter the viewport.
|
|
22
|
+
*
|
|
23
|
+
* @param options - Configuration options
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* // Usage without parameters (queries entire document.body)
|
|
28
|
+
* import { useScrollReveal } from '@lark-apaas/client-toolkit/hooks/useScrollReveal';
|
|
29
|
+
*
|
|
30
|
+
* function MyComponent() {
|
|
31
|
+
* useScrollReveal();
|
|
32
|
+
*
|
|
33
|
+
* return <div className="scroll-reveal">I will fade in on scroll!</div>;
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```tsx
|
|
39
|
+
* // Usage with container ref
|
|
40
|
+
* import { useRef } from 'react';
|
|
41
|
+
* import { useScrollReveal } from '@lark-apaas/client-toolkit/hooks/useScrollReveal';
|
|
42
|
+
*
|
|
43
|
+
* function MyComponent() {
|
|
44
|
+
* const containerRef = useRef<HTMLDivElement>(null);
|
|
45
|
+
* useScrollReveal({ containerRef });
|
|
46
|
+
*
|
|
47
|
+
* return (
|
|
48
|
+
* <div ref={containerRef}>
|
|
49
|
+
* <div className="scroll-reveal">I will fade in on scroll!</div>
|
|
50
|
+
* </div>
|
|
51
|
+
* );
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* // Usage with custom options
|
|
58
|
+
* useScrollReveal({ threshold: 0.2, visibleClass: 'animate-in' });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function useScrollReveal<T extends HTMLElement = HTMLElement>(options?: UseScrollRevealOptions<T>): void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
const DEFAULT_OPTIONS = {
|
|
3
|
+
threshold: 0.1,
|
|
4
|
+
rootMargin: '0px 0px -50px 0px',
|
|
5
|
+
visibleClass: 'visible',
|
|
6
|
+
selector: '.scroll-reveal'
|
|
7
|
+
};
|
|
8
|
+
function useScrollReveal(options) {
|
|
9
|
+
const { containerRef, threshold, rootMargin, visibleClass, selector } = {
|
|
10
|
+
...DEFAULT_OPTIONS,
|
|
11
|
+
...options
|
|
12
|
+
};
|
|
13
|
+
useEffect(()=>{
|
|
14
|
+
const container = containerRef?.current ?? document.body;
|
|
15
|
+
if (!container) return;
|
|
16
|
+
const observer = new IntersectionObserver((entries)=>{
|
|
17
|
+
entries.forEach((entry)=>{
|
|
18
|
+
if (entry.isIntersecting) entry.target.classList.add(visibleClass);
|
|
19
|
+
});
|
|
20
|
+
}, {
|
|
21
|
+
threshold,
|
|
22
|
+
rootMargin
|
|
23
|
+
});
|
|
24
|
+
const elements = container.querySelectorAll(selector);
|
|
25
|
+
elements.forEach((el)=>observer.observe(el));
|
|
26
|
+
return ()=>{
|
|
27
|
+
observer.disconnect();
|
|
28
|
+
};
|
|
29
|
+
}, [
|
|
30
|
+
containerRef,
|
|
31
|
+
threshold,
|
|
32
|
+
rootMargin,
|
|
33
|
+
visibleClass,
|
|
34
|
+
selector
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
export { useScrollReveal };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { getAppId } from "./getAppId.js";
|
|
2
|
+
function getPrefix() {
|
|
3
|
+
const appId = getAppId(window.location.pathname);
|
|
4
|
+
const namespace = appId || '__global__';
|
|
5
|
+
return `__miaoda_${namespace}__:`;
|
|
6
|
+
}
|
|
7
|
+
function getScopedKeys() {
|
|
8
|
+
const prefix = getPrefix();
|
|
9
|
+
const keys = [];
|
|
10
|
+
for(let i = 0; i < localStorage.length; i++){
|
|
11
|
+
const key = localStorage.key(i);
|
|
12
|
+
if (key && key.startsWith(prefix)) keys.push(key.substring(prefix.length));
|
|
13
|
+
}
|
|
14
|
+
return keys;
|
|
15
|
+
}
|
|
16
|
+
const scopedStorage = {
|
|
17
|
+
getItem (key) {
|
|
18
|
+
const prefixedKey = getPrefix() + key;
|
|
19
|
+
return localStorage.getItem(prefixedKey);
|
|
20
|
+
},
|
|
21
|
+
setItem (key, value) {
|
|
22
|
+
const prefixedKey = getPrefix() + key;
|
|
23
|
+
localStorage.setItem(prefixedKey, value);
|
|
24
|
+
},
|
|
25
|
+
removeItem (key) {
|
|
26
|
+
const prefixedKey = getPrefix() + key;
|
|
27
|
+
localStorage.removeItem(prefixedKey);
|
|
28
|
+
},
|
|
29
|
+
clear () {
|
|
30
|
+
const prefix = getPrefix();
|
|
31
|
+
const keysToRemove = [];
|
|
32
|
+
for(let i = 0; i < localStorage.length; i++){
|
|
33
|
+
const key = localStorage.key(i);
|
|
34
|
+
if (key && key.startsWith(prefix)) keysToRemove.push(key);
|
|
35
|
+
}
|
|
36
|
+
keysToRemove.forEach((key)=>localStorage.removeItem(key));
|
|
37
|
+
},
|
|
38
|
+
key (index) {
|
|
39
|
+
const keys = getScopedKeys();
|
|
40
|
+
return keys[index] || null;
|
|
41
|
+
},
|
|
42
|
+
get length () {
|
|
43
|
+
return getScopedKeys().length;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
export { scopedStorage };
|