@vnejs/uis.react.smooth-text 0.1.3 → 0.1.4
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/SmoothText.d.ts +0 -1
- package/dist/SmoothText.d.ts.map +1 -1
- package/dist/SmoothText.js +2 -3
- package/dist/SmoothText.js.map +1 -1
- package/dist/SmoothText.styles.d.ts +2 -0
- package/dist/SmoothText.styles.d.ts.map +1 -0
- package/dist/SmoothText.styles.js +18 -0
- package/dist/SmoothText.styles.js.map +1 -0
- package/package.json +12 -18
- package/src/SmoothText.stories.tsx +54 -0
- package/src/SmoothText.styles.ts +20 -0
- package/src/SmoothText.tsx +94 -0
- package/src/hooks/chars.hook.ts +23 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +18 -0
- package/dist/SmoothText.styl +0 -10
package/dist/SmoothText.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "./SmoothText.styl";
|
|
2
1
|
export declare const SmoothText: ({ tokens, color, size, className, width, height, opacity, font, transition, charDelay, tokensVisibleForce, isForce, isCentered, isNotRender, isNoScrollBar, scrollBarTextSize, }: {
|
|
3
2
|
tokens?: any[];
|
|
4
3
|
color?: string;
|
package/dist/SmoothText.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmoothText.d.ts","sourceRoot":"","sources":["../src/SmoothText.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SmoothText.d.ts","sourceRoot":"","sources":["../src/SmoothText.tsx"],"names":[],"mappings":"AAYA,eAAO,MAAM,UAAU,GAAI;;;;;;;;;;;;;;;;;CAiB1B,4CAgEA,CAAC"}
|
package/dist/SmoothText.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useMemo } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { getVneLength } from "@vnejs/uis.utils";
|
|
4
4
|
import { Char, Scrollbar } from "@vnejs/uis.react";
|
|
5
5
|
import { useSmoothTextCharsVisibleHook } from "./hooks/chars.hook";
|
|
6
|
-
import "./SmoothText.
|
|
7
|
-
const b = cn("SmoothText");
|
|
6
|
+
import { b } from "./SmoothText.styles.js";
|
|
8
7
|
const EMPTY_ARRAY = [];
|
|
9
8
|
export const SmoothText = ({ tokens = [], color = "", size = 60, className = "", width = 0, height = 0, opacity = null, font = "", transition = null, charDelay = 20, tokensVisibleForce = null, isForce = false, isCentered = false, isNotRender = false, isNoScrollBar = false, scrollBarTextSize = null, }) => {
|
|
10
9
|
const style = useMemo(() => {
|
package/dist/SmoothText.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmoothText.js","sourceRoot":"","sources":["../src/SmoothText.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAa,OAAO,EAAY,MAAM,OAAO,CAAC;AAElE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"SmoothText.js","sourceRoot":"","sources":["../src/SmoothText.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAa,OAAO,EAAY,MAAM,OAAO,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AAEnE,OAAO,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AAE3C,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EACzB,MAAM,GAAG,EAAE,EACX,KAAK,GAAG,EAAE,EACV,IAAI,GAAG,EAAE,EACT,SAAS,GAAG,EAAE,EACd,KAAK,GAAG,CAAC,EACT,MAAM,GAAG,CAAC,EACV,OAAO,GAAG,IAAI,EACd,IAAI,GAAG,EAAE,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,SAAS,EAAE,CAAC,GAAG,aAAa,EAC5B,OAAO,EAAE,OAAO,IAAI,aAAa,KAAK,CAAC,IAJlC,GAAG,SAAS,CAAC,KAAK,IAAI,CAAC,EAAE,CAK9B,CACH,EACD,CAAC,aAAa,CAAC,CAChB,CAAC;IAEF,IAAI,WAAW;QAAE,OAAO,IAAI,CAAC;IAE7B,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,CACL,cAAK,SAAS,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,YACrD,cACE,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,EACrB,KAAK,EAAE,KAAK,YAEX,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,GACnB,GACF,CACP,CAAC;IACJ,CAAC;IAED,OAAO,CACL,KAAC,SAAS,IACR,SAAS,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,EACzC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,iBAAiB,YAE3B,cACE,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,EACrB,KAAK,EAAE,KAAK,YAEX,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,GACnB,GACI,CACb,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SmoothText.styles.d.ts","sourceRoot":"","sources":["../src/SmoothText.styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,CAAC,4BAAmB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { cn, injectStyles, sel } from "@vnejs/uis.utils";
|
|
2
|
+
export const b = cn("SmoothText");
|
|
3
|
+
const CSS = `
|
|
4
|
+
${sel(b("chars"))} {
|
|
5
|
+
width: 100%;
|
|
6
|
+
height: 100%;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
${sel(b({ isCentered: true }))} ${sel(b("chars"))} {
|
|
10
|
+
text-align: center;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
${sel(b({ isNoScrollBar: true }))} {
|
|
14
|
+
display: inline-block;
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
injectStyles(CSS);
|
|
18
|
+
//# sourceMappingURL=SmoothText.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SmoothText.styles.js","sourceRoot":"","sources":["../src/SmoothText.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAEzD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC;AAElC,MAAM,GAAG,GAAG;EACV,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;;;;;EAKf,GAAG,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;;;;EAI/C,GAAG,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;;;CAGhC,CAAC;AAEF,YAAY,CAAC,GAAG,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,32 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/uis.react.smooth-text",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"build": "
|
|
8
|
-
"publish:major:
|
|
9
|
-
"publish:minor:
|
|
10
|
-
"publish:patch:
|
|
11
|
-
"publish:major": "
|
|
12
|
-
"publish:minor": "
|
|
13
|
-
"publish:patch": "
|
|
7
|
+
"build": "npx @vnejs/monorepo package",
|
|
8
|
+
"publish:major:uis:react": "npm run publish:major",
|
|
9
|
+
"publish:minor:uis:react": "npm run publish:minor",
|
|
10
|
+
"publish:patch:uis:react": "npm run publish:patch",
|
|
11
|
+
"publish:major": "npx @vnejs/monorepo publish major --access public",
|
|
12
|
+
"publish:minor": "npx @vnejs/monorepo publish minor --access public",
|
|
13
|
+
"publish:patch": "npx @vnejs/monorepo publish patch --access public"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"@
|
|
17
|
-
"@vnejs/uis.utils": "~0.1.0",
|
|
18
|
-
"react": "19.2.4",
|
|
19
|
-
"react-dom": "19.2.4",
|
|
20
|
-
"@vnejs/uis.react": "~0.1.0"
|
|
16
|
+
"@vnejs/uis.utils": "~0.1.0"
|
|
21
17
|
},
|
|
22
18
|
"devDependencies": {
|
|
23
|
-
"@vnejs/uis.react": "~0.1.0"
|
|
24
|
-
"typescript": "^6.0.3",
|
|
25
|
-
"@types/react": "^19.0.10",
|
|
26
|
-
"@types/react-dom": "^19.0.4"
|
|
19
|
+
"@vnejs/uis.react": "~0.1.0"
|
|
27
20
|
},
|
|
28
21
|
"files": [
|
|
29
22
|
"dist",
|
|
30
|
-
"
|
|
23
|
+
"src",
|
|
24
|
+
"tsconfig.json"
|
|
31
25
|
]
|
|
32
26
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { renderWithVneWrap, DEFAULT_ARGS, ARGS } from "@vnejs/uis.react";
|
|
4
|
+
|
|
5
|
+
import { SmoothText } from "./SmoothText";
|
|
6
|
+
|
|
7
|
+
export const Common = {
|
|
8
|
+
args: {
|
|
9
|
+
...DEFAULT_ARGS,
|
|
10
|
+
|
|
11
|
+
text: "In a loose sense the edge of the criterion the general features and possibilities of the existing network the final phase and cannot be developed under such circumstances.",
|
|
12
|
+
|
|
13
|
+
size: 48,
|
|
14
|
+
|
|
15
|
+
charDelay: 10,
|
|
16
|
+
|
|
17
|
+
width: 900,
|
|
18
|
+
height: 180,
|
|
19
|
+
|
|
20
|
+
isForce: false,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const onTextFinished = () => console.log("finish");
|
|
25
|
+
const onTextStarted = () => console.log("start");
|
|
26
|
+
|
|
27
|
+
export default {
|
|
28
|
+
title: "Base/SmoothText",
|
|
29
|
+
render: renderWithVneWrap(({ text, ...args }) => {
|
|
30
|
+
const tokens = useMemo(() => [...text].map((char) => ({ token: char })), [text]);
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<SmoothText
|
|
34
|
+
{...args}
|
|
35
|
+
color="white"
|
|
36
|
+
tokens={tokens}
|
|
37
|
+
onTextFinished={onTextFinished}
|
|
38
|
+
onTextStarted={onTextStarted}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}),
|
|
42
|
+
argTypes: {
|
|
43
|
+
// engine
|
|
44
|
+
...ARGS,
|
|
45
|
+
|
|
46
|
+
// Text
|
|
47
|
+
size: { control: { type: "number", min: 24, max: 180, step: 6 } },
|
|
48
|
+
|
|
49
|
+
// SmoothText
|
|
50
|
+
charDelay: { control: { type: "number", min: 0, max: 64, step: 2 } },
|
|
51
|
+
width: { control: { type: "number", min: 1200, max: 2400, step: 30 } },
|
|
52
|
+
height: { control: { type: "number", min: 120, max: 600, step: 30 } },
|
|
53
|
+
},
|
|
54
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { cn, injectStyles, sel } from "@vnejs/uis.utils";
|
|
2
|
+
|
|
3
|
+
export const b = cn("SmoothText");
|
|
4
|
+
|
|
5
|
+
const CSS = `
|
|
6
|
+
${sel(b("chars"))} {
|
|
7
|
+
width: 100%;
|
|
8
|
+
height: 100%;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
${sel(b({ isCentered: true }))} ${sel(b("chars"))} {
|
|
12
|
+
text-align: center;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
${sel(b({ isNoScrollBar: true }))} {
|
|
16
|
+
display: inline-block;
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
injectStyles(CSS);
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { getVneLength } from "@vnejs/uis.utils";
|
|
4
|
+
|
|
5
|
+
import { Char, Scrollbar } from "@vnejs/uis.react";
|
|
6
|
+
|
|
7
|
+
import { useSmoothTextCharsVisibleHook } from "./hooks/chars.hook";
|
|
8
|
+
|
|
9
|
+
import { b } from "./SmoothText.styles.js";
|
|
10
|
+
|
|
11
|
+
const EMPTY_ARRAY = [];
|
|
12
|
+
|
|
13
|
+
export const SmoothText = ({
|
|
14
|
+
tokens = [],
|
|
15
|
+
color = "",
|
|
16
|
+
size = 60,
|
|
17
|
+
className = "",
|
|
18
|
+
width = 0,
|
|
19
|
+
height = 0,
|
|
20
|
+
opacity = null,
|
|
21
|
+
font = "",
|
|
22
|
+
transition = null,
|
|
23
|
+
charDelay = 20,
|
|
24
|
+
tokensVisibleForce = null,
|
|
25
|
+
isForce = false,
|
|
26
|
+
isCentered = false,
|
|
27
|
+
isNotRender = false,
|
|
28
|
+
isNoScrollBar = false,
|
|
29
|
+
scrollBarTextSize = null,
|
|
30
|
+
}) => {
|
|
31
|
+
const style = useMemo(() => {
|
|
32
|
+
const result: Record<string, any> = {};
|
|
33
|
+
|
|
34
|
+
if (font) result.fontFamily = font;
|
|
35
|
+
if (color) result.color = color;
|
|
36
|
+
|
|
37
|
+
if (size) {
|
|
38
|
+
result.fontSize = `round(down, calc(${getVneLength(size)} * var(--vne-text-size-multiplicator, 1)), 1px)`;
|
|
39
|
+
result.lineHeight = `round(down, calc(${getVneLength(1.25 * size)} * var(--vne-text-size-multiplicator, 1)), 1px)`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (transition !== null) result.transition = transition && !isForce ? `${transition}ms` : "none";
|
|
43
|
+
|
|
44
|
+
if (opacity) result.opacity = opacity;
|
|
45
|
+
|
|
46
|
+
return result;
|
|
47
|
+
}, [font, color, size, transition, opacity, isForce]);
|
|
48
|
+
|
|
49
|
+
const tokensVisible = useSmoothTextCharsVisibleHook(tokens, charDelay, tokensVisibleForce);
|
|
50
|
+
|
|
51
|
+
const renderChar = useCallback(
|
|
52
|
+
(tokenInfo, i) => (
|
|
53
|
+
<Char
|
|
54
|
+
key={`${tokenInfo.token}:${i}`}
|
|
55
|
+
token={tokenInfo.token}
|
|
56
|
+
marks={tokenInfo.marks}
|
|
57
|
+
isVisible={i < tokensVisible}
|
|
58
|
+
isForce={isForce || tokensVisible === 0}
|
|
59
|
+
/>
|
|
60
|
+
),
|
|
61
|
+
[tokensVisible],
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
if (isNotRender) return null;
|
|
65
|
+
|
|
66
|
+
if (isNoScrollBar) {
|
|
67
|
+
return (
|
|
68
|
+
<div className={b({ isNoScrollBar: true }, [className])}>
|
|
69
|
+
<div
|
|
70
|
+
className={b("chars")}
|
|
71
|
+
style={style}
|
|
72
|
+
>
|
|
73
|
+
{tokens.map(renderChar)}
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<Scrollbar
|
|
81
|
+
className={b({ isCentered }, [className])}
|
|
82
|
+
width={width}
|
|
83
|
+
height={height}
|
|
84
|
+
textSize={scrollBarTextSize}
|
|
85
|
+
>
|
|
86
|
+
<div
|
|
87
|
+
className={b("chars")}
|
|
88
|
+
style={style}
|
|
89
|
+
>
|
|
90
|
+
{tokens.map(renderChar)}
|
|
91
|
+
</div>
|
|
92
|
+
</Scrollbar>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
export const useSmoothTextCharsVisibleHook = (tokens, charDelay, tokensVisibleForce) => {
|
|
4
|
+
const [tokensVisible, setTokensVisible] = useState(0);
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (tokensVisibleForce === null) setTokensVisible(0);
|
|
8
|
+
}, [tokens, charDelay]);
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (tokensVisibleForce !== null) setTokensVisible(tokensVisibleForce);
|
|
12
|
+
}, [tokensVisibleForce]);
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (tokensVisibleForce !== null || tokensVisible >= tokens.length) return;
|
|
16
|
+
|
|
17
|
+
const tm = setTimeout(() => setTokensVisible(tokensVisible + 1), charDelay);
|
|
18
|
+
|
|
19
|
+
return () => clearTimeout(tm);
|
|
20
|
+
}, [tokens, tokensVisible, charDelay, tokensVisibleForce]);
|
|
21
|
+
|
|
22
|
+
return tokensVisible;
|
|
23
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./SmoothText";
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.react.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "dist",
|
|
5
|
+
"rootDir": "src"
|
|
6
|
+
},
|
|
7
|
+
"include": [
|
|
8
|
+
"src/**/*.ts",
|
|
9
|
+
"src/**/*.tsx",
|
|
10
|
+
"../../../globals.d.ts",
|
|
11
|
+
"../../../peer-modules.d.ts"
|
|
12
|
+
],
|
|
13
|
+
"exclude": [
|
|
14
|
+
"dist",
|
|
15
|
+
"node_modules",
|
|
16
|
+
"src/**/*.stories.tsx"
|
|
17
|
+
]
|
|
18
|
+
}
|