@@ -102,51 +102,114 @@ function pauseEvent(e) {
102
102
return false ;
103
103
}
104
104
105
- function customAlert ( polylines ) {
105
+ const dialogstyle = `
106
+ z-index: 999999999999;
107
+ width: 550px;
108
+ min-height: 100px;
109
+ position: absolute;
110
+ left: 50%;
111
+ top: 100px;
112
+ transform: translate(-50%, 0%);
113
+ background: #f4f4f4;
114
+ border-radius: 10px;
115
+ border: 1px solid black;
116
+ padding: 8px;
117
+ `
118
+
119
+ const polylinesStyle = `
120
+ overflow-x: auto;
121
+ background: #e2e2e2;
122
+ border-radius: 5px;
123
+ margin: auto;
124
+ margin-top: 1em;
125
+ margin-bottom: 1em;
126
+ padding: .25rem;
127
+ `
128
+
129
+ const buttonClasses = `class="mx-auto my-1 text-white p-2 rounded cursor-pointer bg-gray-700 hover:bg-gray-500"`
106
130
131
+ function customAlert ( polylines ) {
107
132
const el = document . createElement ( "div" ) ;
108
- const style = `
109
- z-index: 999999999999;
110
- width: 550px;
111
- min-height: 100px;
112
- position: absolute;
113
- left: 50%;
114
- top: 100px;
115
- transform: translate(-50%, 0%);
116
- background: #f4f4f4;
117
- border-radius: 10px;
118
- border: 1px solid black;
119
- padding: 8px;
120
- `
121
-
122
- const polylinesStyle = `
123
- overflow-x: auto;
124
- background: #e2e2e2;
125
- border-radius: 5px;
126
- margin: auto;
127
- margin-top: 1em;
128
- margin-bottom: 1em;
129
- padding: .25rem;
130
- `
131
-
133
+
132
134
el . innerHTML = `
133
- <div style="${ style } ">
135
+ <div style="${ dialogstyle } ">
134
136
<div>
135
137
<div>Here are the polylines of your SVG. Copy and paste it into the editor.</div>
136
138
<pre style="${ polylinesStyle } ">${ polylines } </pre>
137
139
</div>
138
140
139
141
<span style="width: 100%; display: flex;">
140
- <button class="mx-auto my-1 text-white p-2 rounded cursor-pointer bg-gray-700 hover:bg-gray-500" >
142
+ <button id="closeButton"" ${ buttonClasses } >
141
143
close
142
144
</button>
145
+ <button id="scaleButton" ${ buttonClasses } >
146
+ scale
147
+ </button>
143
148
</span>
144
149
</div>
145
150
`
146
151
147
- el . querySelector ( "button " ) . addEventListener ( "click" , ( ) => {
152
+ el . querySelector ( "#closeButton " ) . addEventListener ( "click" , ( ) => {
148
153
el . remove ( ) ;
149
154
} )
155
+
156
+ el . querySelector ( "#scaleButton" ) . addEventListener ( "click" , ( ) => {
157
+ el . remove ( ) ;
158
+ scaleAlert ( polylines ) ;
159
+ } )
160
+
161
+ document . body . append ( el ) ;
162
+ }
163
+
164
+ function scaleAlert ( polylines ) {
165
+ const el = document . createElement ( "div" ) ;
166
+
167
+ el . innerHTML = `
168
+ <div style="${ dialogstyle } ">
169
+ <div>
170
+ <div>Scale your polylines to specific dimensions.</div>
171
+ <pre style="${ polylinesStyle } ">${ polylines } </pre>
172
+ </div>
173
+
174
+ <div style="width: 100%; display: flex;">
175
+ <input type="number" id="newWidth" placeholder="Width" style="${ polylinesStyle } width: 50%; margin: 5px; ">
176
+ <input type="number" id="newHeight" placeholder="Height" style="${ polylinesStyle } width: 50%; margin: 5px; ">
177
+ </div>
150
178
179
+ <div style="width: 100%; text-align: center;">
180
+ <input type="checkbox" id="paddingCheckbox" name="paddingCheckbox">
181
+ <label for="paddingCheckbox"> Add Padding</label><br>
182
+ </div>
183
+
184
+ <span style="width: 100%; display: flex;">
185
+ <button id="scaleButton"" ${ buttonClasses } >
186
+ scale (keep aspect ratio)
187
+ </button>
188
+ <button id="cancelButton"" ${ buttonClasses } >
189
+ cancel
190
+ </button>
191
+ </span>
192
+ </div>
193
+ `
194
+
195
+ el . querySelector ( "#scaleButton" ) . addEventListener ( "click" , ( ) => {
196
+ const newWidth = el . querySelector ( "#newWidth" ) . value ;
197
+ const newHeight = el . querySelector ( "#newHeight" ) . value ;
198
+ const addPadding = el . querySelector ( "#paddingCheckbox" ) . checked ;
199
+
200
+ if ( Number . isNaN ( newWidth ) || Number . isNaN ( newHeight ) || newWidth == "" || newHeight == "" ) {
201
+ alert ( "Invalid width/height provided " ) ;
202
+ } else {
203
+ const newPolyLines = tk . scalePolylinesToDimension ( polylines , newWidth , newHeight , addPadding ) ;
204
+ el . remove ( ) ;
205
+ customAlert ( newPolyLines ) ;
206
+ }
207
+ } )
208
+
209
+ el . querySelector ( "#cancelButton" ) . addEventListener ( "click" , ( ) => {
210
+ el . remove ( ) ;
211
+ customAlert ( polylines ) ;
212
+ } )
213
+
151
214
document . body . append ( el ) ;
152
215
}
0 commit comments