1
+ const preview = document . getElementById ( "preview" ) ;
2
+ const styles = document . getElementById ( "styles" ) ;
3
+ const ranges = document . querySelectorAll ( ".settings input" ) ;
4
+ const copyButton = document . getElementById ( "copy-styles" ) ;
5
+
6
+ // Add event listener to each range input
7
+ ranges . forEach ( ( slider ) => {
8
+ slider . addEventListener ( "input" , generateStyles ) ;
9
+ } ) ;
10
+
11
+ // Function to generate and update styles
12
+ function generateStyles ( ) {
13
+ const xShadow = getValue ( "x-shadow" ) ;
14
+ const yShadow = getValue ( "y-shadow" ) ;
15
+ const blurRadius = getValue ( "blur-r" ) ;
16
+ const spreadRadius = getValue ( "spread-r" ) ;
17
+ const shadowColor = getValue ( "shadow-color" ) ;
18
+ const shadowOpacity = getValue ( "shadow-opacity" ) ;
19
+ const shadowInset = getValue ( "inset-shadow" ) === "true" ;
20
+ const borderRadius = getValue ( "border-r" ) ;
21
+
22
+ // Create the box shadow CSS property value
23
+ const boxShadow = `${
24
+ shadowInset ? "inset " : ""
25
+ } ${ xShadow } px ${ yShadow } px ${ blurRadius } px ${ spreadRadius } px ${ hexToRgba (
26
+ shadowColor ,
27
+ shadowOpacity
28
+ ) } `;
29
+
30
+ // Update the preview element styles
31
+ preview . style . boxShadow = boxShadow ;
32
+ preview . style . borderRadius = `${ borderRadius } px` ;
33
+
34
+ // Update textarea with generated styles
35
+ styles . textContent = `box-shadow: ${ boxShadow } ;\nborder-radius: ${ borderRadius } px;` ;
36
+ }
37
+
38
+ // Function to get the value of an input element
39
+ function getValue ( id ) {
40
+ return document . getElementById ( id ) . value ;
41
+ }
42
+
43
+ // Function to convert hex color and opacity to rgba format
44
+ function hexToRgba ( shadowColor , shadowOpacity ) {
45
+ const r = parseInt ( shadowColor . substr ( 1 , 2 ) , 16 ) ;
46
+ const g = parseInt ( shadowColor . substr ( 3 , 2 ) , 16 ) ;
47
+ const b = parseInt ( shadowColor . substr ( 5 , 2 ) , 16 ) ;
48
+
49
+ return `rgba(${ r } , ${ g } , ${ b } , ${ shadowOpacity } )` ;
50
+ }
51
+
52
+ // Function to copy the generated styles
53
+ function copyStyles ( ) {
54
+ styles . select ( ) ;
55
+ document . execCommand ( "copy" ) ;
56
+ copyButton . innerText = "Copied!" ;
57
+ setTimeout ( ( ) => {
58
+ copyButton . innerText = "Copy" ;
59
+ } , 500 ) ;
60
+ }
61
+
62
+ copyButton . addEventListener ( "click" , copyStyles ) ;
63
+
64
+ generateStyles ( ) ;
0 commit comments