-
-
Notifications
You must be signed in to change notification settings - Fork 175
/
index.html
executable file
·206 lines (142 loc) · 5.14 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>frame.js / editor</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link rel="manifest" href="manifest.json">
</head>
<body ontouchstart="">
<link href="./css/main.css" rel="stylesheet" />
<link id="theme" href="./css/dark.css" rel="stylesheet" />
<link rel="stylesheet" href="./js/libs/codemirror/codemirror.css">
<link rel="stylesheet" href="./js/libs/codemirror/theme/monokai.css">
<script src="./js/libs/codemirror/codemirror.js"></script>
<script src="./js/libs/codemirror/mode/javascript.js"></script>
<link rel="stylesheet" href="./js/libs/codemirror/addon/dialog/dialog.css">
<link rel="stylesheet" href="./js/libs/codemirror/addon/search/matchesonscrollbar.css">
<script src="./js/libs/codemirror/addon/dialog/dialog.js"></script>
<script src="./js/libs/codemirror/addon/search/searchcursor.js"></script>
<script src="./js/libs/codemirror/addon/search/search.js"></script>
<script src="./js/libs/codemirror/addon/scroll/annotatescrollbar.js"></script>
<script src="./js/libs/codemirror/addon/search/matchesonscrollbar.js"></script>
<script src="./js/libs/codemirror/addon/search/jump-to-line.js"></script>
<script src="./js/libs/signals.min.js"></script>
<script src="https://unpkg.com/@ffmpeg/[email protected]/dist/ffmpeg.min.js" defer></script>
<script type="module">
import { Editor } from './js/Editor.js';
import { Viewport } from './js/Viewport.js';
import { Code } from './js/Code.js';
import { Sidebar } from './js/Sidebar.js';
import { Controls } from './js/Controls.js';
import { Timeline } from './js/Timeline.js';
import { Menubar } from './js/Menubar.js';
var editor = new Editor();
var viewport = new Viewport( editor );
document.body.appendChild( viewport.dom );
var code = new Code( editor );
document.body.appendChild( code.dom );
var sidebar = new Sidebar( editor );
document.body.appendChild( sidebar.dom );
var controls = new Controls( editor );
document.body.appendChild( controls.dom );
var timeline = new Timeline( editor );
document.body.appendChild( timeline.dom );
var menubar = new Menubar( editor );
document.body.appendChild( menubar.dom );
// LocalStorage
editor.signals.animationAdded.add( saveState );
editor.signals.animationModified.add( saveState );
editor.signals.animationRemoved.add( saveState );
editor.signals.animationRenamed.add( saveState );
editor.signals.effectCompiled.add( saveState );
editor.signals.effectRenamed.add( saveState );
editor.signals.scriptChanged.add( saveState );
editor.signals.scriptRemoved.add( saveState );
editor.signals.editorCleared.add( saveState );
var timeout;
function saveState() {
clearTimeout( timeout );
timeout = setTimeout( function () {
editor.config.setKey( 'state', JSON.stringify( editor.toJSON() ) );
}, 1000 );
}
//
var state = editor.config.getKey( 'state' );
if ( state !== undefined ) {
editor.fromJSON( JSON.parse( state ) );
}
// Short-cuts
document.addEventListener( 'keydown', function ( event ) {
if ( event.metaKey || event.ctrlKey ) {
switch ( event.keyCode ) {
case 83: // prevent CMD + S
event.preventDefault();
break;
case 69: // CMD + E to export
event.preventDefault();
editor.signals.exportState.dispatch();
break;
}
return;
}
switch ( event.keyCode ) {
case 8: // prevent browser back
event.preventDefault();
break;
case 32:
editor.player.isPlaying ? editor.stop() : editor.play();
break;
case 37:
event.preventDefault();
editor.setTime( editor.player.currentTime - editor.player.playbackRate );
break;
case 39:
event.preventDefault();
editor.setTime( editor.player.currentTime + editor.player.playbackRate );
break;
case 38:
event.preventDefault();
editor.speedUp();
break;
case 40:
event.preventDefault();
editor.speedDown();
break;
case 83:
break;
}
} );
// Drop
document.addEventListener( 'dragover', function ( event ) {
event.preventDefault();
event.dataTransfer.dropEffect = 'copy';
}, false );
document.addEventListener( 'drop', function ( event ) {
event.preventDefault();
if ( event.dataTransfer.files.length > 0 ) {
var reader = new FileReader();
reader.addEventListener( 'load', function ( event ) {
if ( confirm( 'Any unsaved data will be lost. Are you sure?' ) ) {
editor.clear();
editor.fromJSON( JSON.parse( event.target.result ) );
}
}, false );
reader.readAsText( event.dataTransfer.files[ 0 ] );
}
}, false );
//
window.addEventListener( 'resize', function () {
editor.signals.windowResized.dispatch();
} );
editor.signals.windowResized.dispatch();
// ServiceWorker
if ( 'serviceWorker' in navigator ) {
try {
navigator.serviceWorker.register( 'sw.js' );
} catch ( error ) {
}
}
</script>
</body>
</html>