-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
267 lines (233 loc) · 11.1 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/default.min.css">
<link rel="stylesheet" href="./css/splitting.css" />
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<meta charset="utf-8" />
<script src="./js/splitting.js"></script>
<link href="./css/main.css" rel="stylesheet" >
<title>Kapsas</title>
</head>
<body>
<div>
<!-- Setting autocomplete off on input tags makes the values reset on soft refresh in FF -->
<div autocomplete="off" class="directChildrenInheritMarginTop" style="padding: 8px; background-color: #f5f5d4; text-align: center;">
<div class="directChildrenInheritMarginTop" style="margin-top: 4px;">
<div>
<p style="margin: 0 0 0 0;">Presets</p>
<button id="preset-breathing" class="button" style="padding: .75rem 1.25rem;">Breathing</button>
<button id="preset-diagonal-stripes" class="button" style="padding: .75rem 1.25rem;">Diagonal stripes</button>
<button id="preset-multi-expand-opacity" class="button" style="padding: .75rem 1.25rem;">Multi expand opacity</button>
</div>
<p style="margin: 1em 0 0 0;">Settings</p>
<details>
<summary class="button" style="padding: .75rem 1.25rem; width: 100%">
Style
</summary>
<div class="css-contenteditable-wrapper" style="text-align: left;">
<style id="animation-style-input" contenteditable="" spellcheck="false" class="input-textinput" style="display: block;"></style>
<pre id="animation-style-textoutput" class="input-textoutput" aria-hidden="true"></pre>
</div>
</details>
<details>
<summary class="button" style="padding: .75rem 1.25rem; width: 100%">
<span>Keyframes
<span>
<a title="Animatable CSS properties" tabindex="-1" target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties">
<img style="color: #ffffff;" src="svg/question-circle-solid.svg" alt="question-circle-solid.svg" height="16px"></img>
</a>
</span>
</span>
</summary>
<div class="css-contenteditable-wrapper">
<style contenteditable spellcheck="false" class="input-textinput" id="input-keyframes-textinput" style="display: block;"></style>
<pre id="input-keyframes-textoutput" class="input-textoutput" aria-hidden="true"></pre>
</div>
</details>
<details>
<summary class="button" style="padding: .75rem 1.25rem; width: 100%">
Text
</summary>
<div class="css-contenteditable-wrapper">
<div id="input-text-textarea" contenteditable spellcheck="false" class="main-font" style="outline: none; font-size: 40px;"></div>
</div>
</details>
<details>
<summary class="button" style="padding: .75rem 1.25rem; width: 100%">
Script
</summary>
<div class="css-contenteditable-wrapper" style="text-align: left;">
<style id="script-input" contenteditable="" spellcheck="false" class="input-textinput" style="display: block;"></style>
<pre id="script-textoutput" class="input-textoutput" aria-hidden="true"></pre>
</div>
</details>
<p style="margin: 1em 0 0 0;">Actions</p>
<div class="center">
<button class="button" type="button" tabindex="0" style="width: 140px; height: 40px;" id="input-font-btn">
<img style="color: #ffffff;" src="svg/upload-solid.svg" alt="upload-solid.svg" height="16px">Upload font</img>
</button>
</div>
<div>
<button class="button" type="button" tabindex="0" style="width: 140px; height: 40px;" id="input-button-animation-state-toggle">State: running</button>
<button class="button" type="button" tabindex="0" style="width: 140px; height: 40px;" id="btn-start">Restart</button>
</div>
</div>
</div>
<div class="main-font set-keyframes-target" id="input-to-output-text-render" style="margin: 40px 0; text-align: center;">
<div data-splitting>
Content will be rendered here
</div>
</div>
</div>
</div>
</body>
</html>
<script type="module">
import hljs from 'https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/es/highlight.min.js';
import Template from './js/template.js';
import Breating from './js/templates/breathing.js';
import DiagonalStripes from './js/templates/diagonalStripes.js';
import MultiExpandOpacity from './js/templates/multiExpandOpacity.js';
let breathingTemplate = new Template(
new Breating().GetStyle,
new Breating().GetKeyframes,
new Breating().GetScript,
new Breating().GetText()
);
let diagonalStripesTemplate = new Template(
new DiagonalStripes().GetStyle,
new DiagonalStripes().GetKeyframes,
new DiagonalStripes().GetScript,
new DiagonalStripes().GetText()
);
let multiExpandOpacityTemplate = new Template(
new MultiExpandOpacity().GetStyle,
new MultiExpandOpacity().GetKeyframes,
new MultiExpandOpacity().GetScript,
new MultiExpandOpacity().GetText()
);
let templates = [breathingTemplate, diagonalStripesTemplate, multiExpandOpacityTemplate];
main();
function main() {
SetHtmlValues(templates[0]);
HandleEvents();
}
function HandleEvents() {
KeyframeChangeEvent();
SettingsChangeEvent();
ScriptChangeEvent();
HandleAnimationStateEvent();
HandleFontFileUploadEvent();
HandleStartEvent();
ContentEditableNoDivHackEvent();
HandlePresets();
}
function KeyframeChangeEvent() {
let elementKeyframes = document.querySelector('#input-keyframes-textinput');
elementKeyframes.addEventListener('input', (e) => ChangeContenteditableHighlight('#input-keyframes-textinput', '#input-keyframes-textoutput', null, 'css'));
}
function SettingsChangeEvent() {
let animationSettings = document.querySelector('#animation-style-input');
animationSettings.addEventListener('input', (e) => ChangeContenteditableHighlight('#animation-style-input', '#animation-style-textoutput', null, 'css'));
}
function ScriptChangeEvent() {
let elementSettingsInput = document.querySelector('#script-input');
elementSettingsInput.addEventListener('input', (e) => ChangeContenteditableHighlight('#script-input', '#script-textoutput', null, 'javascript'));
}
function HandleStartEvent() {
let startBtn = document.querySelector('#btn-start');
startBtn.addEventListener('click', (e) => {
let x = document.querySelector('#script-input').innerText;
eval(x);
});
}
function ContentEditableNoDivHackEvent() {
/*
Replaces default enter <div> to enter <br> for pressing enter inside contenteditable element.
Line break element <br> is easier to manipulate to match the #input-keyframes-textinput and #input-keyframes-textoutput elements.
*/
document.addEventListener('keydown', event => {
if (event.key === 'Enter' && event.target.id === "input-keyframes-textinput") {
console.log("blocked");
document.execCommand('insertLineBreak')
event.preventDefault()
}
});
}
function HandlePresets() {
$('#preset-breathing').first().on('click', () => {
SetHtmlValues(templates[0]);
});
$('#preset-diagonal-stripes').first().on('click', () => {
SetHtmlValues(templates[1]);
});
$('#preset-multi-expand-opacity').first().on('click', () => {
SetHtmlValues(templates[2]);
});
}
function SetHtmlValues(template) {
// Set values annoying to set using html to html elements
// Newline can be set in html using (the linefeed character literal), but using \n or string templates is more elegant
let elementInputText = document.querySelector("#input-text-textarea");
elementInputText.innerHTML = template.textArr.join('<br>');
let elementKeyframes = document.querySelector('#input-keyframes-textinput');
elementKeyframes.innerHTML = template.getKeyframes();
let elementKeyframesHighlighting = document.querySelector('#input-keyframes-textoutput');
elementKeyframesHighlighting.innerHTML = hljs.highlight(elementKeyframes.innerHTML, {language: 'css'}).value;
let elementSettingsInput = document.querySelector('#animation-style-input');
elementSettingsInput.innerHTML = template.getSettings();
let elementSettingsHighlighting = document.querySelector('#animation-style-textoutput');
elementSettingsHighlighting.innerHTML = hljs.highlight(elementSettingsInput.innerHTML, {language: 'css'}).value;
let elementScript = document.querySelector('#script-input');
elementScript.innerHTML = template.getScript();
let elementScriptHighighting = document.querySelector('#script-textoutput');
elementScriptHighighting.innerHTML = hljs.highlight(elementScript.innerHTML, {language: 'javascript'}).value;
eval(template.getScript());
}
function ChangeContenteditableHighlight(inputSelector, outputSelector, text = null, language) {
if (text === null) {
let animationSettings = document.querySelector(inputSelector);
text = animationSettings.innerText;
}
let animationSettingsHighLight = document.querySelector(outputSelector);
animationSettingsHighLight.innerHTML = hljs.highlight(text, {language: language}).value;
}
function HandleAnimationStateEvent() {
let root = document.documentElement;
root.style.setProperty('--animation-play-state', `running`)
const toggle = document.getElementById('input-button-animation-state-toggle');
toggle.addEventListener('click', () => {
let newState = root.style.getPropertyValue('--animation-play-state') === 'running' ? 'paused' : 'running';
root.style.setProperty('--animation-play-state', newState);
toggle.innerHTML = 'State: ' + newState;
});
}
function HandleFontFileUploadEvent() {
let reader = new FileReader();
reader.onload = function(event) {
let file = event.target.result;
// document.head.append('<style type="text/css">@font-face { font-family:"MYFONT2"; src: url("'+file+'"); }</style>');
SetFont(file)
}
let startReadingFile = (thisElement) => {
let inputFile = thisElement.files[0];
reader.readAsDataURL(inputFile);
}
let input = document.createElement('input');
input.type = 'file';
input.accept = '.ttf, .woff, .woff2';
document.querySelector('#input-font-btn').addEventListener("click", () => {
input.click();
});
input.addEventListener("change", () => startReadingFile(input));
}
function SetFont(fontFile) {
/* Font name has to match the one in the css to target a nonexisting font-family to override */
let font = new FontFace('ClientAwesomeUploadedFont', `url(${fontFile})`);
font.load().then((loaded_face) => {
document.fonts.add(loaded_face);
});
}
</script>