@cos-design/true-focus 3.7.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT LICENSE
2
+
3
+ Copyright (c) 2021-present jiaxiantao
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});require('./index.css');var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("react");c=s(c,1);let l=require("react/jsx-runtime");var u={trueFocus:`cos-trueFocus-GX7IP`,stage:`cos-stage-epay6`,word:`cos-word-5pfV3`,focusFrame:`cos-focusFrame-o7brV`,corner:`cos-corner-PThvn`,tl:`cos-tl-maoq6`,tr:`cos-tr-KTph3`,bl:`cos-bl-JAm8m`,br:`cos-br-s9hq-`},d=({sentence:e=`True Focus`,separator:t=` `,manualMode:n=!1,blurAmount:r=5,borderColor:i=`#22c55e`,glowColor:a=`rgb(34 197 94 / 60%)`,animationDuration:o=.5,pauseBetweenAnimations:s=1,fontSize:d=48,color:f=`#f8fafc`})=>{let p=e.split(t).filter(Boolean),[m,h]=(0,c.useState)(0),[g,_]=(0,c.useState)(0),v=(0,c.useRef)(null),y=(0,c.useRef)([]),[b,x]=(0,c.useState)({x:0,y:0,width:0,height:0});(0,c.useEffect)(()=>{if(n||p.length===0)return;let e=window.setInterval(()=>{h(e=>(e+1)%p.length)},(o+s)*1e3);return()=>window.clearInterval(e)},[o,n,s,p.length]),(0,c.useEffect)(()=>{let e=v.current,t=y.current[m];if(!e||!t)return;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();x({x:r.left-n.left,y:r.top-n.top,width:r.width,height:r.height})},[m,d,e,p.length]);let S=e=>{n&&(_(e),h(e))},C=()=>{n&&h(g)};return(0,l.jsx)(`div`,{className:u.trueFocus,children:(0,l.jsxs)(`div`,{className:u.stage,ref:v,style:{fontSize:d,"--focus-color":f,"--border-color":i,"--glow-color":a,"--focus-duration":`${o}s`},children:[p.map((e,t)=>{let i=t===m;return(0,l.jsx)(`span`,{ref:e=>{y.current[t]=e},className:u.word,style:{filter:i?`blur(0px)`:`blur(${r}px)`,cursor:n?`pointer`:`default`},onMouseEnter:()=>S(t),onMouseLeave:C,children:e},`${e}-${t}`)}),(0,l.jsxs)(`div`,{className:u.focusFrame,style:{transform:`translate(${b.x}px, ${b.y}px)`,width:b.width,height:b.height,opacity:+(m>=0)},children:[(0,l.jsx)(`span`,{className:`${u.corner} ${u.tl}`}),(0,l.jsx)(`span`,{className:`${u.corner} ${u.tr}`}),(0,l.jsx)(`span`,{className:`${u.corner} ${u.bl}`}),(0,l.jsx)(`span`,{className:`${u.corner} ${u.br}`})]})]})})};exports.TrueFocus=d,exports.default=d;
package/dist/index.css ADDED
@@ -0,0 +1 @@
1
+ .cos-trueFocus-GX7IP{background:radial-gradient(circle at 40% 40%,#22c55e1a,#0000 36%),linear-gradient(#0a0a0a,#0f172a);border-radius:18px;justify-content:center;align-items:center;min-height:220px;padding:40px;display:flex;overflow:hidden}.cos-stage-epay6{color:var(--focus-color,#f8fafc);letter-spacing:.02em;-webkit-user-select:none;user-select:none;flex-wrap:wrap;justify-content:center;align-items:center;gap:16px;font-weight:900;display:flex;position:relative}.cos-word-5pfV3{transition:filter var(--focus-duration,.5s) ease;position:relative}.cos-focusFrame-o7brV{pointer-events:none;box-sizing:border-box;transition:transform var(--focus-duration,.5s) ease, width var(--focus-duration,.5s) ease, height var(--focus-duration,.5s) ease, opacity var(--focus-duration,.5s) ease;position:absolute;top:0;left:0}.cos-corner-PThvn{border:3px solid var(--border-color,#22c55e);width:14px;height:14px;filter:drop-shadow(0 0 4px var(--glow-color,#22c55e99));border-radius:3px;position:absolute}.cos-tl-maoq6{border-bottom:0;border-right:0;top:-10px;left:-10px}.cos-tr-KTph3{border-bottom:0;border-left:0;top:-10px;right:-10px}.cos-bl-JAm8m{border-top:0;border-right:0;bottom:-10px;left:-10px}.cos-br-s9hq-{border-top:0;border-left:0;bottom:-10px;right:-10px}
@@ -0,0 +1,3 @@
1
+ export { default } from './src/components/trueFocus/index';
2
+ export { default as TrueFocus } from './src/components/trueFocus/index';
3
+ export type * from './src/components/trueFocus/index';
package/dist/index.js ADDED
@@ -0,0 +1,98 @@
1
+ import { useEffect as e, useRef as t, useState as n } from "react";
2
+ import { jsx as r, jsxs as i } from "react/jsx-runtime";
3
+ import './index.css';var a = {
4
+ trueFocus: "cos-trueFocus-GX7IP",
5
+ stage: "cos-stage-epay6",
6
+ word: "cos-word-5pfV3",
7
+ focusFrame: "cos-focusFrame-o7brV",
8
+ corner: "cos-corner-PThvn",
9
+ tl: "cos-tl-maoq6",
10
+ tr: "cos-tr-KTph3",
11
+ bl: "cos-bl-JAm8m",
12
+ br: "cos-br-s9hq-"
13
+ }, o = ({ sentence: o = "True Focus", separator: s = " ", manualMode: c = !1, blurAmount: l = 5, borderColor: u = "#22c55e", glowColor: d = "rgb(34 197 94 / 60%)", animationDuration: f = .5, pauseBetweenAnimations: p = 1, fontSize: m = 48, color: h = "#f8fafc" }) => {
14
+ let g = o.split(s).filter(Boolean), [_, v] = n(0), [y, b] = n(0), x = t(null), S = t([]), [C, w] = n({
15
+ x: 0,
16
+ y: 0,
17
+ width: 0,
18
+ height: 0
19
+ });
20
+ e(() => {
21
+ if (c || g.length === 0) return;
22
+ let e = window.setInterval(() => {
23
+ v((e) => (e + 1) % g.length);
24
+ }, (f + p) * 1e3);
25
+ return () => window.clearInterval(e);
26
+ }, [
27
+ f,
28
+ c,
29
+ p,
30
+ g.length
31
+ ]), e(() => {
32
+ let e = x.current, t = S.current[_];
33
+ if (!e || !t) return;
34
+ let n = e.getBoundingClientRect(), r = t.getBoundingClientRect();
35
+ w({
36
+ x: r.left - n.left,
37
+ y: r.top - n.top,
38
+ width: r.width,
39
+ height: r.height
40
+ });
41
+ }, [
42
+ _,
43
+ m,
44
+ o,
45
+ g.length
46
+ ]);
47
+ let T = (e) => {
48
+ c && (b(e), v(e));
49
+ }, E = () => {
50
+ c && v(y);
51
+ };
52
+ return /* @__PURE__ */ r("div", {
53
+ className: a.trueFocus,
54
+ children: /* @__PURE__ */ i("div", {
55
+ className: a.stage,
56
+ ref: x,
57
+ style: {
58
+ fontSize: m,
59
+ "--focus-color": h,
60
+ "--border-color": u,
61
+ "--glow-color": d,
62
+ "--focus-duration": `${f}s`
63
+ },
64
+ children: [g.map((e, t) => {
65
+ let n = t === _;
66
+ return /* @__PURE__ */ r("span", {
67
+ ref: (e) => {
68
+ S.current[t] = e;
69
+ },
70
+ className: a.word,
71
+ style: {
72
+ filter: n ? "blur(0px)" : `blur(${l}px)`,
73
+ cursor: c ? "pointer" : "default"
74
+ },
75
+ onMouseEnter: () => T(t),
76
+ onMouseLeave: E,
77
+ children: e
78
+ }, `${e}-${t}`);
79
+ }), /* @__PURE__ */ i("div", {
80
+ className: a.focusFrame,
81
+ style: {
82
+ transform: `translate(${C.x}px, ${C.y}px)`,
83
+ width: C.width,
84
+ height: C.height,
85
+ opacity: +(_ >= 0)
86
+ },
87
+ children: [
88
+ /* @__PURE__ */ r("span", { className: `${a.corner} ${a.tl}` }),
89
+ /* @__PURE__ */ r("span", { className: `${a.corner} ${a.tr}` }),
90
+ /* @__PURE__ */ r("span", { className: `${a.corner} ${a.bl}` }),
91
+ /* @__PURE__ */ r("span", { className: `${a.corner} ${a.br}` })
92
+ ]
93
+ })]
94
+ })
95
+ });
96
+ };
97
+ //#endregion
98
+ export { o as TrueFocus, o as default };
@@ -0,0 +1,3 @@
1
+ export { default } from '../../../src/components/trueFocus';
2
+ export { default as TrueFocus } from '../../../src/components/trueFocus';
3
+ export type * from '../../../src/components/trueFocus';
@@ -0,0 +1,25 @@
1
+ import { default as React } from 'react';
2
+ export interface TrueFocusProps {
3
+ /** 句子文案 */
4
+ sentence?: string;
5
+ /** 分词分隔符 */
6
+ separator?: string;
7
+ /** 是否仅 hover 聚焦 */
8
+ manualMode?: boolean;
9
+ /** 非聚焦词模糊强度(px) */
10
+ blurAmount?: number;
11
+ /** 焦点框颜色 */
12
+ borderColor?: string;
13
+ /** 焦点光晕颜色 */
14
+ glowColor?: string;
15
+ /** 切换动画时长(秒) */
16
+ animationDuration?: number;
17
+ /** 自动切换间歇(秒) */
18
+ pauseBetweenAnimations?: number;
19
+ /** 字号 */
20
+ fontSize?: number;
21
+ /** 文字颜色 */
22
+ color?: string;
23
+ }
24
+ declare const TrueFocus: React.FC<TrueFocusProps>;
25
+ export default TrueFocus;
@@ -0,0 +1,39 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ declare module '*.module.less' {
4
+ const classes: { readonly [key: string]: string };
5
+ export default classes;
6
+ }
7
+
8
+ declare module '*.less' {
9
+ const classes: { readonly [key: string]: string };
10
+ export default classes;
11
+ }
12
+
13
+ declare module '*.png' {
14
+ const src: string;
15
+ export default src;
16
+ }
17
+
18
+ declare module '*.jpg' {
19
+ const src: string;
20
+ export default src;
21
+ }
22
+
23
+ declare module '*.mp4' {
24
+ const src: string;
25
+ export default src;
26
+ }
27
+
28
+ declare module '*.mp3' {
29
+ const src: string;
30
+ export default src;
31
+ }
32
+
33
+ declare module '*.svg' {
34
+ import type { FC, SVGProps } from 'react';
35
+
36
+ export const ReactComponent: FC<SVGProps<SVGSVGElement>>;
37
+ const src: string;
38
+ export default src;
39
+ }
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@cos-design/true-focus",
3
+ "version": "3.7.0",
4
+ "description": "TrueFocus component from cos-design",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "LICENSE"
24
+ ],
25
+ "sideEffects": [
26
+ "**/*.css",
27
+ "**/*.less"
28
+ ],
29
+ "keywords": [
30
+ "cos-design",
31
+ "react",
32
+ "trueFocus",
33
+ "TrueFocus"
34
+ ],
35
+ "homepage": "https://jiaxiantao.github.io/cos-design/",
36
+ "bugs": {
37
+ "url": "https://github.com/jiaxiantao/cos-design/issues"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/jiaxiantao/cos-design.git",
42
+ "directory": "packages/trueFocus"
43
+ },
44
+ "author": "jiaxiantao <jiaxiantao@souche.com>",
45
+ "license": "MIT",
46
+ "peerDependencies": {
47
+ "react": ">=18.0.0",
48
+ "react-dom": ">=18.0.0"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public",
52
+ "registry": "https://registry.npmjs.org"
53
+ }
54
+ }