-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgen.html
More file actions
269 lines (238 loc) · 7.74 KB
/
gen.html
File metadata and controls
269 lines (238 loc) · 7.74 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dialouge Generator</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" rel="stylesheet" />
<style>
textarea, #output, #jsonOutput { width: 90%; height: 150px; margin: 10px; }
#output { padding: 10px; border: 1px solid #ccc; cursor: pointer; }
form { margin: 10px; }
#modal {
display: none;
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
padding: 20px;
background: white;
border: 1px solid #ccc;
z-index: 1001;
}
#output { background: black }
#overlay {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,0.5);
z-index: 1000;
}
body {
background-color: #121212;
color: white;
}
input[type=text], select, textarea {
background-color: #333;
color: white;
border: 1px solid #666;
}
input[type=range], input[type=color] {
background-color: #333;
}
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple {
background-color: #333;
color: white;
border: 1px solid #666;
}
.select2-dropdown {
background-color: #333;
color: white;
border-color: #666;
}
.select2-container--default .select2-results>.select2-results__options {
background-color: #333;
color: white;
}
.select2-container--default .select2-search--dropdown .select2-search__field {
color: white;
background-color: #333;
border: 1px solid #666;
}
.select2-container--default .select2-results__option--highlighted[aria-selected] {
background-color: #565656;
color: white;
}
.select2-container--default .select2-selection__choice {
background-color: #565656;
color: white;
border: 1px solid #666;
}
.select2-container--default .select2-selection__choice__remove:hover {
color: #c00;
}
</style>
</head>
<body>
<form id="textForm">
Text: <input type="text" id="textValue" placeholder="Enter text">
Font: <select id="fontFamily">
<option>Arial</option>
<option>Verdana</option>
<option>Helvetica</option>
<option>Times New Roman</option>
<option>Courier New</option>
</select>
<label for="fontSize">Size:</label>
<input type="range" id="fontSize" min="10" max="100" value="14" oninput="sizeValue.value = this.value">
<output id="sizeValue">14</output>
Color: <input type="color" id="fontColor" value="#FFFFFF">
CSS: <input type="text" id="additionalCSS" placeholder="Additional CSS">
<button type="button" onclick="addText()">Add Text</button>
</form>
<div id="output"></div>
<textarea id="jsonOutput"></textarea>
<div id="overlay"></div>
<div id="modal">
<form id="editForm">
Text: <input type="text" id="modalText" />
Font: <select id="modalFont">
<option>Arial</option>
<option>Verdana</option>
<option>Helvetica</option>
<option>Times New Roman</option>
<option>Courier New</option>
</select>
Size: <input type="text" id="modalSize" />
Color: <input type="text" id="modalColor" />
CSS: <input type="text" id="modalCSS" />
<button type="button" onclick="saveChanges()">Save Changes</button>
<button type="button" onclick="closeModal()">Close</button>
</form>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.full.min.js"></script>
<script>
let jsonData = { line: [] };
let currentEditingIndex = null;
const fonts = ["Arial", "Verdana", "Helvetica", "Times New Roman", "Courier New", "Comic Sans MS", "Impact", "Georgia", "Palatino Linotype", "Book Antiqua", "Lucida Sans Unicode", "Trebuchet MS", "Tahoma", "Lucida Console", "Garamond", "Calibri", "Cambria", "Consolas", "Franklin Gothic Medium", "Segoe UI"];
populateFonts();
document.addEventListener('DOMContentLoaded', function () {
$('#fontFamily, #modalFont').select2();
});
function detectFont(font) {
let canvas = document.createElement("canvas");
let context = canvas.getContext("2d");
context.font = "72px monospace";
let baselineSize = context.measureText("A").width;
context.font = "72px '" + font + "', monospace";
let newSize = context.measureText("A").width;
return newSize !== baselineSize;
}
function populateFonts() {
let select = document.getElementById('fontFamily');
fonts.forEach(font => {
if (detectFont(font)) {
let option = document.createElement('option');
option.textContent = font;
option.value = font;
option.style.fontFamily = font; // Apply the font directly to the option
select.appendChild(option);
}
});
}
populateFonts();
function addText() {
const textValue = document.getElementById('textValue').value;
const fontFamily = $('#fontFamily').val();
const fontSize = document.getElementById('fontSize').value + 'px';
const fontColor = document.getElementById('fontColor').value;
const additionalCSS = document.getElementById('additionalCSS').value;
const newText = {
text: textValue,
style: {
font: fontFamily,
size: fontSize,
color: fontColor,
css: additionalCSS
}
};
jsonData.line.push(newText);
updateOutput();
updateJSONOutput();
}
function updateOutput() {
const output = document.getElementById('output');
output.innerHTML = '';
jsonData.line.forEach((item, index) => {
const span = document.createElement('span');
span.textContent = item.text;
span.style.fontFamily = item.style.font;
span.style.fontSize = item.style.size;
span.style.color = item.style.color;
if (item.style.css) {
span.style.cssText += item.style.css;
}
span.addEventListener('contextmenu', function(event) {
event.preventDefault();
showEditModal(index);
});
output.appendChild(span);
});
}
function formatFontOption(state) {
if (!state.id) {
return state.text;
}
var $state = $('<span style="font-family:' + state.element.value + '">' + state.text + '</span>');
return $state;
}
function updateJSONOutput() {
document.getElementById('jsonOutput').value = JSON.stringify(jsonData, null, 2);
}
function showEditModal(index) {
const item = jsonData.line[index];
document.getElementById('modalText').value = item.text;
$('#modalFont').val(item.style.font).trigger('change');
document.getElementById('modalSize').value = item.style.size;
document.getElementById('modalColor').value = item.style.color;
document.getElementById('modalCSS').value = item.style.css;
currentEditingIndex = index;
document.getElementById('modal').style.display = 'block';
document.getElementById('overlay').style.display = 'block';
}
function saveChanges() {
const text = document.getElementById('modalText').value;
const font = $('#modalFont').val();
const size = document.getElementById('modalSize').value + 'px';
const color = document.getElementById('modalColor').value;
const css = document.getElementById('modalCSS').value;
if (currentEditingIndex !== null) {
const item = jsonData.line[currentEditingIndex];
item.text = text;
item.style.font = font;
item.style.size = size;
item.style.color = color;
item.style.css = css;
updateOutput();
updateJSONOutput();
closeModal();
}
}
function closeModal() {
document.getElementById('modal').style.display = 'none';
document.getElementById('overlay').style.display = 'none';
}
$(document).ready(function() {
$('#fontFamily').select2({
templateResult: formatFontOption, // Use the format function for dropdown items
templateSelection: formatFontOption // Also use it for the selected item display
});
});
updateJSONOutput();
</script>
</body>
</html>