This repository was archived by the owner on Aug 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathSVGInput.html
More file actions
317 lines (265 loc) · 6.8 KB
/
SVGInput.html
File metadata and controls
317 lines (265 loc) · 6.8 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<div class='step-1' style='display: {{step === 1 ? "block" : "none"}}'>
<h2>Import SVG</h2>
<label for="file-upload" class="custom-file-upload">
Select File
</label>
<input id="file-upload" type="file" on:change="handleFiles(this.files)" />
<div style='stroke: {{errorMessage ? "#EB1E32" : "#F037A5" }}' ref:svgHolder id='svg-holder'>
{{{svgPreview}}}
</div>
<!-- New Code -->
<h2>Convert Text</h2>
<p><strong>Font URL:</strong>
<input bind:value='font' placeholder="If not interested just press load" id='font' type=text>
</p>
<button id='loadb'>Load</button>
<div id='loads'></div>
<p><strong>Text Input:</strong>
<input bind:value='text' placeholder="Type the text you wish" id='text' type=text>
</p>
<!-- Above you can see some extra options for the user
if you wish to add them -->
<!--<h4>Parameters</h4>
X<input bind:value='x' id='x' type=text>
Y<input bind:value='y' id='y' type=text>
Font Size<input bind:value='fontsize' id='fontsize' type=text>
Kerning<input bind:value='kerning' id='kerning' type=checkbox>
Anchor<input bind:value='anchor' id='anchor' placeholder="top">-->
<!--Debug<input bind:value='debug' id='debug' type=checkbox>-->
<button id='getsvg' type='button'>GetSVGPath</button>
<p><textarea id='result'></textarea></p>
<script>
$('#getsvg').click(function(){
var temp = $("#result").val();
$("#result").text(temp);
});
</script>
<!-- New Code ends here -->
<h5>paste the SVG path below:</h5>
{{#if errorMessage}}
<p class='nestpas'>Error: Ceci n'est pas une SVG</p>
{{/if}}
<div class='cm-input' id='cm-input' ref:cmInput>
{{#if svgTextError }}
<div class='svg-text-error'>
<p>Yikes! There is a problem with your SVG text file. Try again.</p>
</div>
{{/if}}
</div>
<h3>...or try an example</h3>
<div class='example-container'>
{{#each Object.keys(examples) as example }}
<button on:click='setNewSVG(examples[example], true, example)' class='dot-button {{selectedExample === example ? "selected-dot-button" : ""}}'>{{{examples[example]}}}</button>
{{/each}}
</div>
<p>Find more SVGs at the <a target='_blank' href="https://thenounproject.com">Noun Project
<img class='icon' alt='link out' src='../src/static/images/link-out.svg' /></a></p>
</div>
<style>
input[type="file"] {
display: none;
}
.custom-file-upload {
border: 2px solid #F037A5;
color: #F037A5;
border-radius: 500px;
display: inline-block;
padding: 10px 29px;
cursor: pointer;
font-size: 12px;
text-transform: uppercase;
height: 35px;
font-weight: 900;
line-height: 1;
letter-spacing: 2px;
}
.custom-file-upload:hover {
background-color: #F037A5;
color: #FAE62D;
}
.smaller-paste {
font-size: 12px;
margin-top: 0px;
padding-left: 5px;
}
#result {
margin-bottom: 2px;
position: relative;
width: 271.11px;
height: 120px;
font-family: monospace;
line-height: 1.5;
}
#svg-holder {
fill: none;
stroke: black;
stroke-width: 2px;
width: 100px;
height: 100px;
position: absolute;
top: 60px;
right: 30px;
}
#svg-holder > svg {
width: 100px;
height: 100px;
}
.nestpas {
font-family: 'Pacifico', cursive;
font-size: 14px;
position: absolute;
top: 130px;
right: 16px;
width: 109px;
color: #EB1E32;
line-height: 1;
}
.CodeMirror {
height: 300px;
}
.cm-input {
margin-bottom: 20px;
position: relative;
}
.svg-text-error {
width: calc(100% - 30px);
left: 30px;
padding-left: 20px;
height: 60px;
background-color: #F037A5;
position: absolute;
bottom: 0;
z-index: 10;
border: 2px solid #FAE62D;
font-size: 14px;
color: white;
}
.example-container {
display: flex;
width: 100%;
justify-content: space-between;
flex-wrap: wrap;
}
.dot-button > svg {
fill: none;
stroke: #F037A5;
stroke-width: 2px;
width: 32px;
margin: 0;
vertical-align: middle;
}
.dot-button {
background-color: transparent;
width: 66px;
height: 66px;
border-radius: 66px;
border: #F037A5 2px solid;
font-size: 14px;
color: #F037A5;
margin-bottom: 20px;
}
.dot-button:hover {
background-color: #F037A5;
color: #FAE62D;
}
.selected-dot-button {
background-color: #F037A5;
color: #FAE62D;
}
.selected-dot-button > svg {
fill: none;
stroke: #FAE62D;
stroke-width: 2px;
width: 32px;
margin: 0;
}
.dot-button:hover > svg {
fill: none;
stroke: #FAE62D;
stroke-width: 2px;
width: 32px;
margin: 0;
}
.icon {
width: 16px;
display: inline-block;
}
</style>
<script>
import pathologize from '../js/pathologize';
import CodeMirror from 'codemirror';
import 'codemirror/mode/xml/xml';
import beautify from 'xml-beautifier';
export default {
data () {
return {
cmInput: null,
selectedExample: 'bunny'
};
},
oncreate () {
const cmInput = CodeMirror(this.refs.cmInput, {
value: '//raw SVG will go here',
mode: 'xml',
lineNumbers: true,
lineWrapping: true,
htmlMode: true
});
this.set({cmInput});
//sets the initial example
const selectedExample = this.get('selectedExample');
const examples = this.get('examples');
//listens for new SVG input from direct pasting or editing into the code mirror
cmInput.on('change', (cm, change) => {
if ( change.origin != 'setValue' ) {
const changedValue = cm.getValue();
this.setNewSVG( changedValue, false, null );
}
});
this.setNewSVG( examples[selectedExample], true, selectedExample );
this.observe( 'secretSVG', secretSVG => {
if (secretSVG) {
const hiddenExamples = this.get('hiddenExamples');
this.setNewSVG( hiddenExamples[secretSVG], true, null );
this.set({secretSVG: null});
}
});
},
methods: {
handleFiles( e ) {
const file = e[0];
const hiddenExamples = this.get('hiddenExamples');
const context = this;
if (file.type === 'image/svg+xml') {
const reader = new FileReader();
reader.onload = function() {
context.setNewSVG(reader.result, true, null);
};
reader.readAsText(file);
} else {
this.setNewSVG(hiddenExamples.pipe, true, null );
this.set({errorMessage: true});
}
},
setNewSVG( rawSVG, updateCodeMirror, example ) {
const pathsOnly = pathologize(rawSVG);
//first update preview image and svg reference in DOM
//and handle error message information and example selection if necessary
this.set({
svgPreview: pathsOnly,
selectedExample: example,
errorMessage: false
});
//updates code mirror if svg isn't coming from a paste
if ( updateCodeMirror ) {
const cmInput = this.get('cmInput');
cmInput.setValue(beautify(rawSVG));
}
//then fires an event telling the app it's time to coordinate
this.fire( 'readySVG', {
ready: true
});
},
}
};
</script>