earthnut 0.1.7-alpha.0 → 0.2.0
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/README.md +105 -2
- package/components/image/index.d.ts +12 -0
- package/components/image/types.d.ts +12 -0
- package/components/image/useSrcChange.d.ts +11 -0
- package/components/ripples/LazyRippleEle.d.ts +1 -1
- package/components/ripples/RipplesEle.d.ts +2 -2
- package/components/ripples/types.d.ts +1 -1
- package/components/ripples/useOptionUpdate.d.ts +1 -1
- package/customHooks/useAnimationFrame.d.ts +36 -17
- package/customHooks/useInputIsComposing.d.ts +7 -7
- package/customHooks/useRipples/buildBackground/utils/create-canvas-element.d.ts +1 -1
- package/customHooks/useRipples/index.d.ts +2 -4
- package/customHooks/useRipples/use-lazy-ripple.d.ts +5 -4
- package/customHooks/useTimeId.d.ts +0 -2
- package/index.cjs +1 -1
- package/index.d.ts +17 -3
- package/index.mjs +1 -1
- package/package.json +4 -54
- package/styles/common.css +252 -137
- package/styles/common.scss +26 -106
- package/styles/reset.scss +103 -0
- package/styles/respond.scss +54 -0
- package/styles/root.scss +94 -0
- package/styles/vars.scss +248 -0
- package/705/index.cjs +0 -7
- package/705/index.mjs +0 -7
- package/BackgroundRipple/index.cjs +0 -7
- package/BackgroundRipple/index.mjs +0 -7
- package/Layout/index.cjs +0 -7
- package/Layout/index.mjs +0 -7
- package/LazyBackgroundRipple/index.cjs +0 -7
- package/LazyBackgroundRipple/index.mjs +0 -7
- package/components/index.d.ts +0 -12
- package/customHooks/index.d.ts +0 -12
- package/dog.d.ts +0 -8
- package/useAnimationFrame/index.cjs +0 -7
- package/useAnimationFrame/index.mjs +0 -7
- package/useInputIsComposing/index.cjs +0 -7
- package/useInputIsComposing/index.mjs +0 -7
- package/useLazyRipples/index.cjs +0 -7
- package/useLazyRipples/index.mjs +0 -7
- package/useRipples/index.cjs +0 -7
- package/useRipples/index.mjs +0 -7
- package/useTimeId/index.cjs +0 -7
- package/useTimeId/index.mjs +0 -7
package/README.md
CHANGED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
npm install --save earthnut
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## 文档
|
|
12
|
+
|
|
13
|
+
参阅 [earthnut](https://earthnut.dev/quickUse/)
|
|
14
|
+
|
|
11
15
|
## 涟漪背景
|
|
12
16
|
|
|
13
17
|
由于当前组件的开发进度较缓慢,目前:
|
|
@@ -23,6 +27,105 @@ npm install --save earthnut
|
|
|
23
27
|
|
|
24
28
|
切换背景最好不好通过设置
|
|
25
29
|
|
|
26
|
-
##
|
|
30
|
+
## 自定义钩子
|
|
27
31
|
|
|
28
|
-
|
|
32
|
+
几个简单的自定义钩子,写着玩
|
|
33
|
+
|
|
34
|
+
### useTimeId
|
|
35
|
+
|
|
36
|
+
就是 `useRef` 和 `useEffect` 的简单使用。
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { useTimeId } from 'earthnut';
|
|
40
|
+
|
|
41
|
+
export function Home () {
|
|
42
|
+
|
|
43
|
+
const timeId = useTimeId();
|
|
44
|
+
|
|
45
|
+
return <>
|
|
46
|
+
<button
|
|
47
|
+
onclick = { () => {
|
|
48
|
+
timeId.current = setTimeout(() =>
|
|
49
|
+
console.log('没有感情的按钮 A 打印了一条没有感情的消息'), 2500);
|
|
50
|
+
}
|
|
51
|
+
}>
|
|
52
|
+
没有感情的按钮 A
|
|
53
|
+
</button>
|
|
54
|
+
<button onclick={()=> clearTimeout(timeId.current)}>没有感情的按钮 B</button>
|
|
55
|
+
</>
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### useAnimationFrame
|
|
60
|
+
|
|
61
|
+
使用下一帧动画。
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { useAnimationFrame } from 'earthnut';
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## scss 样式
|
|
68
|
+
|
|
69
|
+
导出了一个 `common.css` 作为样式使用,还可以引用其中的 `scss` 文件使用其中的函数。
|
|
70
|
+
|
|
71
|
+
如果使用 `common.css` 建议仅在跟下进行导入即可,避免在
|
|
72
|
+
|
|
73
|
+
在使用 `webpack` 的应用中可以这样引入
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
// webpack.config.js
|
|
77
|
+
module.exports = {
|
|
78
|
+
module: {
|
|
79
|
+
rules: [
|
|
80
|
+
{
|
|
81
|
+
test: /\.scss$/,
|
|
82
|
+
use: [
|
|
83
|
+
'style-loader',
|
|
84
|
+
'css-loader',
|
|
85
|
+
{
|
|
86
|
+
loader: 'sass-loader',
|
|
87
|
+
options: {
|
|
88
|
+
sassOptions: {
|
|
89
|
+
includePaths: [path.resolve(__dirname, 'node_modules/ui-library-a/src/scss')], // UI 库 SCSS 路径
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
在使用 `vite` 的应用中可以这样引入
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
// vite.config.js
|
|
104
|
+
import { defineConfig } from 'vite';
|
|
105
|
+
import path from 'path';
|
|
106
|
+
|
|
107
|
+
export default defineConfig({
|
|
108
|
+
css: {
|
|
109
|
+
preprocessorOptions: {
|
|
110
|
+
scss: {
|
|
111
|
+
additionalData: `@use "${path.resolve(__dirname, 'node_modules/ui-library-a/src/scss')}" as lib;`,
|
|
112
|
+
includePaths: [path.resolve(__dirname, 'node_modules/ui-library-a/src/scss')],
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
为了防止意外覆盖别人的自定义 css 属性,该样式皆以 `en-` 为前缀。譬如:
|
|
120
|
+
|
|
121
|
+
```tsx
|
|
122
|
+
import { xcn } from 'earthnut';
|
|
123
|
+
|
|
124
|
+
export function Home() {
|
|
125
|
+
return (
|
|
126
|
+
<div>
|
|
127
|
+
<p className={xcn('en-text-in=one-line')}>无论我字数多少,仅会会在同一行就行打印。</p>
|
|
128
|
+
</div>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license MIT
|
|
3
|
+
* earthnut@components/image/index.d.ts
|
|
4
|
+
* Copyright (c) 2025 earthnut.dev
|
|
5
|
+
* 请在项目根参看详细许可证明
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { EnImageProps } from './types';
|
|
9
|
+
/** 简单的图像 */
|
|
10
|
+
declare const Image: React.ForwardRefExoticComponent<Omit<EnImageProps, "ref"> & React.RefAttributes<HTMLImageElement>>;
|
|
11
|
+
export { Image };
|
|
12
|
+
export type { EnImageProps };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license MIT
|
|
3
|
+
* earthnut@components/image/types.d.ts
|
|
4
|
+
* Copyright (c) 2025 earthnut.dev
|
|
5
|
+
* 请在项目根参看详细许可证明
|
|
6
|
+
*/
|
|
7
|
+
export type EnImageProps = {
|
|
8
|
+
/** 下载错误时展示的图像 */
|
|
9
|
+
errorSrc?: string;
|
|
10
|
+
/** 加载中的图像 */
|
|
11
|
+
loadingSrc?: string;
|
|
12
|
+
} & React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license MIT
|
|
3
|
+
* earthnut@components/image/useSrcChange.d.ts
|
|
4
|
+
* Copyright (c) 2025 earthnut.dev
|
|
5
|
+
* 请在项目根参看详细许可证明
|
|
6
|
+
*/
|
|
7
|
+
/** 当地址触发变更 */
|
|
8
|
+
export declare function useSrcChange(src: string, fallbackSrc?: string): {
|
|
9
|
+
resultSrc: string;
|
|
10
|
+
loadComplete: number;
|
|
11
|
+
};
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
* @CreateDate 周四 12/12/2024
|
|
13
13
|
* @Description 涟漪
|
|
14
14
|
****************************************************************************/
|
|
15
|
-
import React from 'react';
|
|
16
15
|
import { RipplesOptions } from '../../customHooks/useRipples/types';
|
|
17
16
|
import { RippleEle } from './types';
|
|
17
|
+
import * as React from 'react';
|
|
18
18
|
/**
|
|
19
19
|
*
|
|
20
20
|
* ### 一个 ripple 背景组件
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* Copyright (c) 2025 earthnut.dev
|
|
5
5
|
* 请在项目根参看详细许可证明
|
|
6
6
|
*/
|
|
7
|
-
import React from 'react';
|
|
8
7
|
import { RipplesOptions } from '../../customHooks/useRipples/types';
|
|
9
8
|
import { RippleEle } from './types';
|
|
9
|
+
import * as React from 'react';
|
|
10
10
|
/**
|
|
11
11
|
*
|
|
12
12
|
* ### 一个 ripple 背景组件
|
|
@@ -25,7 +25,7 @@ import { RippleEle } from './types';
|
|
|
25
25
|
* 使用:
|
|
26
26
|
*
|
|
27
27
|
* ```ts
|
|
28
|
-
* import { BackgroundRipple } from 'earthnut
|
|
28
|
+
* import { BackgroundRipple } from 'earthnut';
|
|
29
29
|
* // 也可以全量导入
|
|
30
30
|
* // import { BackgroundRipple } from 'earthnut';
|
|
31
31
|
* ...
|
|
@@ -13,36 +13,55 @@
|
|
|
13
13
|
* @CreateDate 周二 01/07/2025
|
|
14
14
|
* @Description 使用 animationFrame
|
|
15
15
|
****************************************************************************/
|
|
16
|
+
/** 使用动画结果 */
|
|
17
|
+
export interface UseAnimationFrameResult {
|
|
18
|
+
/** 取消执行动画 */
|
|
19
|
+
cancel(): void;
|
|
20
|
+
/** 当前取消的状态 */
|
|
21
|
+
canceled: boolean;
|
|
22
|
+
/** 再次执行 */
|
|
23
|
+
render(): void;
|
|
24
|
+
}
|
|
25
|
+
export type AnimationFrameOption = boolean | {
|
|
26
|
+
immediately?: boolean;
|
|
27
|
+
once?: boolean;
|
|
28
|
+
};
|
|
16
29
|
/**
|
|
17
30
|
*
|
|
18
|
-
*
|
|
31
|
+
* 该钩子在组件卸载时会自动调用 `window.cancelAnimationFrame` 清理传入的回调方法。
|
|
32
|
+
* 默认是传入即启动调用方法
|
|
19
33
|
*
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
22
|
-
* @
|
|
23
|
-
* @
|
|
24
|
-
* @
|
|
34
|
+
* @description 创建一个会自己关闭(组建卸载时)的 animationFrame。当然,可以通过返回值手动终止
|
|
35
|
+
* @param callback 使用回调函数。回调函数有两个参数,除了默认的时间,还有另一个用于暂停后的记时时间。如果没有主动暂停,两者时间总是趋近于相等的(可能有其他延迟造成时间差越来越大)。如果没有暂停需求,使用第一个默认时间就可以了。
|
|
36
|
+
* @param [option=false] 使用第二参数,可指定是否立即执行及是否仅执行一次
|
|
37
|
+
* @returns 返回值包含执行状态
|
|
38
|
+
* @version 0.2.0
|
|
39
|
+
* @see https://earthnut.dev/custom-hooks/use-animation-frame
|
|
25
40
|
* @example
|
|
26
41
|
* 使用:
|
|
27
42
|
*
|
|
28
43
|
* ```ts
|
|
29
|
-
* import { useAnimationFrame } from 'earthnut/useAnimationFrame';
|
|
30
|
-
* // 也可以全量导入
|
|
31
44
|
* // import { useAnimationFrame } from 'earthnut';
|
|
32
45
|
* ...
|
|
33
|
-
* const animationFrameId = useAnimationFrame();
|
|
34
46
|
*
|
|
35
|
-
* function
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* useEffect(()=>{
|
|
41
|
-
* animationFrameId.current = window.requestAnimationFrame(performAction);
|
|
47
|
+
* export function Home () {
|
|
48
|
+
* // 如果没有主动暂停的需要,直接使用默认的 time 最好。如果中间有使用暂停。那么 time 值是不连贯的,而 runTime 是连贯的
|
|
49
|
+
* const result = useAnimationFrame((time ,runTime) => {
|
|
50
|
+
* ... //
|
|
42
51
|
* });
|
|
52
|
+
*
|
|
53
|
+
*
|
|
54
|
+
* return <>
|
|
55
|
+
*
|
|
56
|
+
* <button onclick={() => result.cancel()}>暂停</button>
|
|
57
|
+
* <button onclick={() => result.render()}>恢复</button>
|
|
58
|
+
* </>
|
|
59
|
+
* }
|
|
43
60
|
* ...
|
|
44
61
|
*
|
|
45
62
|
* ```
|
|
46
63
|
*
|
|
64
|
+
* 当然,可使用第二参数执行立即执行还是仅执行一次(作用不大,不与赘述)
|
|
65
|
+
*
|
|
47
66
|
*/
|
|
48
|
-
export declare function
|
|
67
|
+
export declare function useAnimationFrame(callback: (time: number, runtime: number) => void, option?: AnimationFrameOption): UseAnimationFrameResult;
|
|
@@ -22,30 +22,30 @@
|
|
|
22
22
|
* @param inputRef [React.RefObject<HTMLInputElement | HTMLTextAreaElement>] 输入框的 ref
|
|
23
23
|
* @returns React.RefObject<boolean>
|
|
24
24
|
* @version 0.0.4
|
|
25
|
-
* @see https://earthnut.dev/use-input-is-composing
|
|
25
|
+
* @see https://earthnut.dev/custom-hooks/use-input-is-composing
|
|
26
26
|
* @example
|
|
27
27
|
*
|
|
28
28
|
* 使用:
|
|
29
29
|
*
|
|
30
30
|
* ```ts
|
|
31
|
-
* import { useInputIsComposing } from 'earthnut
|
|
32
|
-
*
|
|
33
|
-
* // import { useInputIsComposing } from 'earthnut';
|
|
31
|
+
* import { useInputIsComposing } from 'earthnut';
|
|
32
|
+
*
|
|
34
33
|
* ...
|
|
35
34
|
* const inputRef = useRef<HTMLInputElement>(null);
|
|
36
35
|
*
|
|
37
36
|
* const inputIsComposing = useInputIsComposing(inputRef);
|
|
38
37
|
* ...
|
|
39
|
-
* function enterDown(
|
|
38
|
+
* function enterDown(e: React.KeyboardEvent<HTMLInputElement>) {
|
|
40
39
|
* if (e.key === 'Enter') {
|
|
41
40
|
* if (isComposing.current) {
|
|
42
41
|
* console.log("此时此景,按回车键说明为了从候选词中挑选");
|
|
43
|
-
* } else
|
|
42
|
+
* } else {
|
|
44
43
|
* console.log("输入完毕,敲回车是为了看一些开发者是否绑定了其他事件");
|
|
44
|
+
* }
|
|
45
45
|
* }
|
|
46
46
|
* }
|
|
47
47
|
* ...
|
|
48
|
-
* <input type="text" onKeyDown={enterDown} />
|
|
48
|
+
* <input type="text" onKeyDown={enterDown} ref={inputRef} />
|
|
49
49
|
* ...
|
|
50
50
|
* ```
|
|
51
51
|
*/
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* Copyright (c) 2025 earthnut.dev
|
|
5
5
|
* 请在项目根参看详细许可证明
|
|
6
6
|
*/
|
|
7
|
-
import { Ripples } from 'components/ripples';
|
|
7
|
+
import { Ripples } from '../../../../components/ripples';
|
|
8
8
|
/** 根据给出的 html 数据构建一个 canvas */
|
|
9
9
|
export declare function createCanvasElement(this: Ripples, img: CanvasImageSource): HTMLCanvasElement;
|
|
@@ -14,16 +14,14 @@ import { Ripples } from './ripplesClass';
|
|
|
14
14
|
* @param canvas `usrRef` 包裹的 `HTMLCanvasElement`,用于绘制图像
|
|
15
15
|
* @param option 初始化的
|
|
16
16
|
* @version 0.0.3
|
|
17
|
-
* @see https://earthnut.dev/use-ripples
|
|
17
|
+
* @see https://earthnut.dev/custom-hooks/use-ripples
|
|
18
18
|
* @see JQuery https://github.com/sirxemic/jquery.ripples
|
|
19
19
|
* @example
|
|
20
20
|
*
|
|
21
21
|
* 下面是在 <BackgroundRipple> 中使用
|
|
22
22
|
*
|
|
23
23
|
* ```ts
|
|
24
|
-
* import { useRipples } from 'earthnut
|
|
25
|
-
* // 也可以使用包全量导入
|
|
26
|
-
* // import { useRipples } from 'earthnut';
|
|
24
|
+
* import { useRipples } from 'earthnut';
|
|
27
25
|
*
|
|
28
26
|
* export function BackgroundRipple(props: BackgroundRipplesProps) {
|
|
29
27
|
*
|
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
* Copyright (c) 2025 earthnut.dev
|
|
5
5
|
* 请在项目根参看详细许可证明
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { Ripples } from './ripplesClass';
|
|
8
|
+
import { RipplesOptions } from './types';
|
|
8
9
|
/** 动态加载包含的自定义的钩子 */
|
|
9
|
-
export declare function useLazyRipples(): {
|
|
10
|
-
|
|
10
|
+
export declare function useLazyRipples(canvas: React.RefObject<HTMLCanvasElement | null>, option?: RipplesOptions): {
|
|
11
|
+
ripples: React.RefObject<Ripples | null>;
|
|
11
12
|
isLoading: boolean;
|
|
12
|
-
error:
|
|
13
|
+
error: unknown;
|
|
13
14
|
};
|