Skip to content

Commit d07d41c

Browse files
committed
refactor: remove image to simplify demo
1 parent e70488c commit d07d41c

File tree

10 files changed

+93
-234
lines changed

10 files changed

+93
-234
lines changed

src/assets/gaara.jpg

-263 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
11
.wrap {
22
height: 100vh;
3-
background: linear-gradient(to right,#ccf 0%,#bbf 100%);
4-
}
5-
6-
.panel {
7-
padding-top: 2rem;
8-
padding-left: 6rem;
9-
label {
10-
display: block;
11-
}
123
}

src/pages/index/components/masked-image/index.js

-69
This file was deleted.

src/pages/index/components/masked-image/style.module.css

-17
This file was deleted.

src/pages/index/components/playground/index.js

+27-20
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,57 @@
11
import React, { useState, useRef, useEffect } from 'react';
2-
import imageUrl from '#/assets/gaara.jpg';
3-
import MaskedImage from '../masked-image';
42
import Result from '../result';
53
import styles from './style.module.css';
64

5+
const messages = [
6+
'hello, world',
7+
'Every day is Friday',
8+
'Today, I don\'t feel like doing anything',
9+
'I just wanna lay in my bed',
10+
'Don\'t feel like picking up my phone',
11+
'So leave a message at the tone',
12+
'\'Cause today, I swear, I\'m not doing anything',
13+
];
14+
const getMessage = () => messages[Math.floor(Math.random() * messages.length)];
15+
716
const data = [
817
{
9-
text: '这是一只眼睛',
10-
bbox: [450, 350, 600, 450],
18+
text: getMessage(),
19+
bbox: [0.3, 0.3, 0.4, 0.4],
1120
},
1221
{
13-
text: '这是另一只眼睛',
14-
bbox: [680, 400, 830, 500],
22+
text: getMessage(),
23+
bbox: [0.4, 0.4, 0.6, 0.6],
1524
},
1625
{
17-
text: '爱',
18-
bbox: [720, 300, 810, 400],
26+
text: getMessage(),
27+
bbox: [0.3, 0.5, 0.4, 0.6],
1928
},
2029
{
21-
text: '这是一只大手',
22-
bbox: [280, 1170, 820, 1570],
30+
text: getMessage(),
31+
bbox: [0.2, 0.6, 0.8, 0.8],
2332
},
2433
];
2534

2635
export default function Playground() {
2736
const [wrapProps, setWrapProps] = useState(null);
28-
const [imageProps, setImageProps] = useState(null);
2937
const ref = useRef();
3038

3139
useEffect(() => {
3240
const rect = ref.current.getBoundingClientRect();
33-
setWrapProps(rect);
41+
setWrapProps({
42+
top: rect.top,
43+
left: rect.left,
44+
width: rect.width,
45+
height: rect.height,
46+
scale: rect.width / 750,
47+
});
3448
}, []);
3549

3650
return (
3751
<div className={styles.wrap} ref={ref}>
38-
<MaskedImage
39-
url={imageUrl}
40-
wrapProps={wrapProps}
41-
imageProps={imageProps}
42-
onLoad={setImageProps}
43-
/>
44-
{imageProps && (
52+
{wrapProps && (
4553
<Result
4654
wrapProps={wrapProps}
47-
imageProps={imageProps}
4855
data={data}
4956
/>
5057
)}

src/pages/index/components/playground/style.module.css

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
top: 0;
66
left: 0;
77
overflow: auto;
8+
background: #ccf;
89
}
910

1011
@media (min-width: 450px) {

src/pages/index/components/result-text/index.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default React.forwardRef((props, ref) => {
88
const [showText, setShowText] = useState(false);
99
const {
1010
data: {
11-
text, style, align, animated,
11+
text, style, animated,
1212
},
1313
} = props;
1414

@@ -35,12 +35,8 @@ export default React.forwardRef((props, ref) => {
3535
}, [animated]);
3636

3737
if (!text) return null;
38-
const className = [
39-
styles.wrap,
40-
styles[`align-${align || 'left'}`],
41-
].join(' ');
4238
return (
43-
<div className={className} style={style} ref={ref}>
39+
<div className={styles.wrap} style={style} ref={ref}>
4440
<div className={styles.bar} style={{ transform: `scaleX(${scale})` }} />
4541
<div className={`${styles.text} ${showText ? '' : styles.hidden}`}>{text}</div>
4642
</div>

src/pages/index/components/result-text/style.module.css

+2-14
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,8 @@
88
left: 0;
99
right: 0;
1010
bottom: 0;
11-
}
12-
13-
.align-left {
14-
.bar {
15-
transform-origin: left center;
16-
background: linear-gradient(to right, rgba(0,94,240,.6) 0%, rgba(107,196,255,.6) 100%);
17-
}
18-
}
19-
20-
.align-right {
21-
.bar {
22-
transform-origin: right center;
23-
background: linear-gradient(to left, rgba(0,94,240,.6) 0%, rgba(107,196,255,.6) 100%);
24-
}
11+
transform-origin: left center;
12+
background: linear-gradient(to right, rgba(0,94,240,.6) 0%, rgba(107,196,255,.6) 100%);
2513
}
2614

2715
.text {

0 commit comments

Comments
 (0)