-
Notifications
You must be signed in to change notification settings - Fork 1
/
draw.js
149 lines (131 loc) · 5.09 KB
/
draw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/// function gives html draw info
function draw(objectProps) {
var { objectShape, width, height, backgroundColor, fontColor, labels } = objectProps;
switch (objectShape) {
case "cube":
return {
"styles": `
.cube {
width: ${width || "200px"};
height: ${height || "200px"};
/* position: relative; */
transform-style: preserve-3d;
animation: rotate 5s infinite linear;
}
.cube .face {
position: absolute;
width: 200px;
height: 200px;
display: flex;
justify-content: center;
align-items: center;
color: ${fontColor || "white"} !important;
font-size: 24px;
/* background-color: rgba(0, 0, 0, 0.5) */
${backgroundColor ? `background-color: ${backgroundColor};` : "background-color: darkred;"}
}
.cube .front {
transform: translateZ(100px);
}
.cube .back {
transform: rotateY(180deg) translateZ(100px);
}
.cube .right {
transform: rotateY(90deg) translateZ(100px);
}
.cube .left {
transform: rotateY(-90deg) translateZ(100px);
}
.cube .top {
transform: rotateX(90deg) translateZ(100px);
}
.cube .bottom {
transform: rotateX(-90deg) translateZ(100px);
}
@keyframes rotate {
from {
transform: rotateY(0deg);
}
to {
transform: rotateY(360deg);
}
}
`,
"HTML": `
<div class="cube">
<div class="face front">${labels?.front || "Front"}</div>
<div class="face back">${labels?.back || "Back"}</div>
<div class="face right">${labels?.right || "Right"}</div>
<div class="face left">${labels?.left || "Left"}</div>
<div class="face top">${labels?.top || "Top"}</div>
<div class="face bottom">${labels?.bottom || "Bottom"}</div>
</div>
`,
};
case "rectangle":
return {
"styles": `
.rectangle {
width: ${width || "300px"};
height: ${height || "200px"};
position: relative;
perspective: 1000px;
}
.rectangle .side {
position: absolute;
width: 300px;
height: 200px;
display: flex;
justify-content: center;
align-items: center;
color: ${fontColor || "white"} !important;
font-size: 24px;
/* background-color: rgba(0, 0, 0, 0.5); */
${backgroundColor ? `background-color: ${backgroundColor} !important;` : "background-color: darkred !important;"}
transition: transform 0.5s;
}
.rectangle.front {
transform: translateZ(100px);
}
.rectangle.back {
transform: translateZ(-100px);
}
.rectangle.right {
transform: rotateY(90deg) translateX(150px);
}
.rectangle.left {
transform: rotateY(-90deg) translateX(-150px);
}
.rectangle.top {
transform: rotateX(90deg) translateY(-100px);
}
.rectangle.bottom {
transform: rotateX(-90deg) translateY(100px);
}
.rectangle: hover.rectangle.side {
transform: rotateX(0deg) rotateY(0deg);
}
`,
"HTML": `
<div class="rectangle">
<div class="side front">${labels?.front || "Front"}</div>
<div class="side back">${labels?.back || "Back"}</div>
<div class="side right">${labels?.right || "Right"}</div>
<div class="side left">${labels?.left || "Left"}</div>
<div class="side top">${labels?.top || "Top"}</div>
<div class="side bottom">${labels?.bottom || "Bottom"}</div>
</div>
`,
};
default:
return {
"styles": ``,
"HTML": `
< script >
console.log("Object shape ${objectShape} invalid or currently unsupported. Sorry if unsupported!")
</script >
`
}
}
}
module.exports = { draw };