A web-based drawing app
git clone git://soophie.de/outline
blob: 048b278f5497b351bacb88e028c3e6ed7ecf7f6f (23833 bytes)[doc][blame][raw]
1
import { FIREBASE, COLORS, PRIORITY_MODAL, LOCALES } from './constant.js';2
import { uuid, query, prevent } from './util.js';4
import locale from './mod/locale.js';5
import canvas from './mod/canvas.js';6
import cookie from './mod/cookie.js';8
let node;9
let state = {10
color: 54,11
color_list: [54, 2, 17, 27, 37, 12],12
radius: 14,13
region: [],14
crop: false,15
index: 0,16
device: null,17
device_fallback: null,18
device_list: {19
mouse: false,20
touch: false,21
pen: false,22
gamepad: false23
},24
pencil_list: [25
'pen',26
'marker',27
'eraser'28
],29
pencil: 'pen',30
timestamp: null,31
modal: null,32
tab: null,33
caption: null,34
option: {35
view_mode: false,36
crop_mode: false,37
dark_mode: false38
},39
history: [],40
redo_history: [],41
key: {}42
};44
export async function init() {46
locale.init();47
await locale.load('./asset/lang', LOCALES);48
canvas.init();50
node = query({51
wrapper: '.wrapper',52
controls: '.controls',53
modal_list: { query: '.modal', all: true },54
tab_list: { query: '.tab', all: true },55
header: '.header-list',56
hotbar: '.hotbar',57
hotbar_list: { query: '.hotbar .color', all: true },58
modal_color_list: { query: '.colors-modal .color', all: true },59
language_list: { query: '.more-modal .language-tab .item[data-event="change.language"]', all: true },60
device_list: { query: '.more-modal .device-tab .item[data-event="change.device"]', all: true },61
pencil_list: { query: '.pencil-modal .item[data-event="change.pencil"]', all: true },62
modal_event_list: { query: '[data-event*=".modal"]', all: true },63
tab_event_list: { query: '[data-event*=".tab"]', all: true },64
capture_event_list: { query: '[data-event*=".capture"]', all: true },65
tool_list: { query: '.tool', all: true },66
action_list: { query: '.action', all: true },67
notification: '.notification',68
scale_input: 'input.scale[type="range"]',69
clear: 'button.btn-apply[data-event="clear"]',70
pencil_tool: '.tool-item[data-code="pencil"]',71
option_event_fullscreen: '[data-event="toggle.fullscreen"]',72
option_event_view_mode: '[data-event="toggle.view-mode"]',73
option_event_dark_mode: '[data-event="toggle.dark-mode"]',74
undo_tool: '[data-lang="action.undo"]',75
redo_tool: '[data-lang="action.redo"]',76
colors_modal: '.colors-modal',77
mainbar: '.mainbar',78
sidebar: '.sidebar',79
edit_mode: '[data-event="close.view-mode"]',80
content: '.modal .content',81
caption_list: { query: '[data-event="open.content"]' , all: true },82
content_list: { query: '.content-item' , all: true },83
download: '#download',84
cookie: '.cookie',85
accept: '.button.accept'86
});88
update_language_list();90
fill_hotbar_list();91
fill_modal_color_list();93
bind_events(locale);95
node.wrapper.animate([96
{ opacity: 1 },97
{ opacity: 0, pointerEvents: 'none' }98
], {99
delay: 100,100
duration: 500,101
fill: 'both'102
});103
node.hotbar.animate([104
{ opacity: 0, bottom: '-10px' },105
{ opacity: 1 }106
], {107
delay: 600,108
easing: 'ease-out',109
duration: 250,110
fill: 'both'111
});113
if(!cookie.hasAccepted()) {114
node.cookie.classList.remove('hidden');115
cookie.requestPermission(node.accept)116
.then(function() {117
node.cookie.classList.add('hidden');118
load_resources();119
});120
}121
else {122
load_resources();123
}124
}126
function load_resources() {127
let dark_mode = localStorage.getItem('outline.custom.dark-mode');128
if(dark_mode && dark_mode === 'true') {129
document.body.classList.add('theme-dark');130
state.option.dark_mode = true;131
update_dark_mode_option({ passive: true });132
}133
let lang = localStorage.getItem('outline.custom.lang');134
if(lang && LOCALES.includes(lang)) {135
locale.change(lang);136
update_language_list();137
}138
try {139
firebase.initializeApp(FIREBASE);140
firebase.analytics();141
}142
catch(error) {143
console.warn('Unable to load Google Analytics!');144
}145
}147
function bind_events(locale) {148
document.addEventListener('dragstart', prevent);149
document.addEventListener('contextmenu', prevent);150
document.addEventListener('pointerdown', on_pointerdown);151
document.addEventListener('pointermove', on_pointermove);152
document.addEventListener('pointerup', on_pointerup);153
document.addEventListener('pointerout', on_pointerout);154
document.addEventListener('keydown', on_keydown);155
document.addEventListener('keyup', on_keyup);156
document.addEventListener('wheel', on_wheel);157
document.addEventListener('wheel', function(event) {158
if(event.ctrlKey) {159
prevent(event);160
}161
}, { passive: false });162
document.addEventListener('touchmove', function(event) {163
if(event.target !== node.scale_input && event.target !== node.colors_modal && !node.modal_color_list.includes(event.target) && event.target !== node.content) {164
event.preventDefault();165
}166
}, { passive: false });168
for(let item of node.language_list) {169
item.addEventListener('click', function() {170
let code = item.dataset.code;171
locale.change(code);172
update_language_list();173
});174
}175
for(let item of node.device_list) {176
item.addEventListener('click', function() {177
let code = item.dataset.code;178
if(state.device_list[code]) {179
state.device = code;180
update_device_list();181
}182
});183
}184
for(let item of node.pencil_list) {185
item.addEventListener('click', function() {186
state.pencil = item.dataset.code;187
update_pencil_list();188
state.modal = null;189
update_modal_list();190
});191
}192
for(let item of node.modal_event_list) {193
item.addEventListener('click', function() {194
let code = item.dataset.code;195
let match = /^(toggle|open|close).modal$/.exec(item.dataset.event);196
if(match) {197
if(!item.classList.contains('inactive')) {198
switch(match[1]) {199
case 'toggle':200
if(code) {201
state.modal = state.modal !== code ? code : null;202
update_modal_list();203
}204
break;205
case 'open':206
if(code && state.modal !== code) {207
state.modal = code;208
update_modal_list();209
}210
break;211
case 'close':212
if(state.modal !== null) {213
state.modal = null;214
update_modal_list();215
}216
break;217
default:218
break;219
}220
}221
}222
});223
}224
for(let item of node.tab_event_list) {225
item.addEventListener('click', function() {226
let code = item.dataset.code;227
let match = /^(open|close).tab/.exec(item.dataset.event);228
if(match) {229
switch(match[1]) {230
case 'open':231
if(code && state.tab !== code) {232
state.tab = code;233
update_tab_list();234
}235
break;236
case 'close':237
if(state.tab !== null) {238
state.tab = null;239
update_tab_list();240
}241
break;242
default:243
break;244
}245
}246
});247
}248
for(let item of node.capture_event_list) {249
item.addEventListener('click', function() {250
let code = item.dataset.code;251
if(code === 'download') {252
if(state.option.crop_mode) {253
state.option.crop_mode = false;254
canvas.draw_crop(state);255
canvas.get_canvas().style.cursor = 'default';256
}257
let data = canvas.create_capture(0, 0, window.innerWidth, window.innerHeight, 60);258
if(data) {259
node.download.download = `outline-${uuid()}.png`;260
node.download.href = data;261
node.download.click();262
}263
else {264
console.warn('Unable to create capture from current state!');265
}266
}267
if(code === 'crop') {268
state.option.crop_mode = true;269
state.region = [];270
canvas.draw_crop(state);271
canvas.get_canvas().style.cursor = 'crosshair';272
}273
state.modal = null;274
state.tab = null;275
update_modal_list();276
})277
}278
node.scale_input.addEventListener('input', function() {279
state.radius = parseInt(node.scale_input.value);280
state.point = {281
x: parseInt(window.innerWidth / 2),282
y: parseInt(window.innerHeight / 2)283
};284
canvas.draw_cursor(state);285
});286
node.clear.addEventListener('click', function() {287
canvas.clear(state);288
update_undo_and_redo();289
show_notification('notification.clear');290
state.modal = null;291
update_modal_list();292
});293
node.option_event_fullscreen.addEventListener('click', function() {294
if(!document.fullscreenElement) {295
document.documentElement.requestFullscreen();296
}297
else if(document.exitFullscreen) {298
document.exitFullscreen();299
}300
});301
window.addEventListener('fullscreenchange', on_fullscreenchange);302
node.option_event_view_mode.addEventListener('click', function() {303
state.option.view_mode = !state.option.view_mode;304
update_view_mode_option();305
});306
node.option_event_dark_mode.addEventListener('click', function() {307
state.option.dark_mode = !state.option.dark_mode;308
update_dark_mode_option();309
});310
node.undo_tool.addEventListener('click', function() {311
canvas.undo(state);312
update_undo_and_redo();313
});314
node.redo_tool.addEventListener('click', function() {315
canvas.redo(state);316
update_undo_and_redo();317
});318
node.edit_mode.addEventListener('click', function() {319
state.option.view_mode = false;320
update_view_mode_option();321
});322
for(let item of node.caption_list) {323
item.addEventListener('click', function() {324
state.caption = item.dataset.code;325
update_caption_list();326
});327
}329
window.addEventListener('beforeunload', function() {330
// ...331
});332
}334
function update_language_list() {335
let lang = locale.get_current();336
for(let item of node.language_list) {337
let code = item.dataset.code;338
item.classList[code === lang ? 'add' : 'remove']('active');339
}340
if(cookie.hasAccepted()) {341
localStorage.setItem('outline.custom.lang', lang);342
}343
}345
function update_device_list() {346
if(!state.option.view_mode && !state.option.crop_mode) {347
canvas.get_canvas().style.cursor = state.device === 'mouse' ? 'none' : '';348
}349
for(let item of node.device_list) {350
let code = item.dataset.code;351
item.classList[code === state.device ? 'add' : 'remove']('active');352
item.classList[state.device_list[code] ? 'remove' : 'add']('inactive');353
}354
}356
function update_pencil_list() {357
for(let item of node.pencil_list) {358
let code = item.dataset.code;359
item.classList[code === state.pencil ? 'add' : 'remove']('active');360
if(code === state.pencil) {361
node.pencil_tool.querySelector('i.ico').innerHTML = item.querySelector('i.ico').innerHTML;362
}363
}364
}366
function update_hotbar() {367
for(let item of node.hotbar_list) {368
item.classList[node.hotbar_list[state.index] === item ? 'add' : 'remove']('active');369
}370
}372
function update_focus(bool) {373
for(let item of node.hotbar_list) {374
item.style.pointerEvents = bool ? '' : 'none';375
}376
for(let item of node.tool_list) {377
item.style.pointerEvents = bool ? '' : 'none';378
}379
for(let item of node.action_list) {380
item.style.pointerEvents = bool ? '' : 'none';381
}382
}384
function update_modal_list() {385
for(let item of node.modal_list) {386
item.classList.add('hidden');387
}388
for(let item of node.modal_event_list) {389
item.classList.remove('active');390
}391
state.tab = null;392
update_tab_list();393
state.caption = 'controls';394
update_caption_list();395
if(state.modal) {396
canvas.on_release(event, state, true);397
let modal = document.querySelector(`.modal.${state.modal}-modal`);398
let button = document.querySelector(`[data-event*=".modal"][data-code="${state.modal}"]`);399
if(modal) {400
modal.classList.remove('hidden');401
modal.animate([402
{ opacity: 0, marginTop: '-6px' },403
{ opacity: 1, marginTop: '0' }404
], {405
duration: 100,406
fill: 'both'407
});408
}409
if(button) {410
button.classList.add('active');411
}412
}413
}415
function update_tab_list() {416
for(let item of node.modal_list) {417
let main = item.querySelector('.main');418
if(main) {419
main.classList.remove('hidden');420
main.style.marginLeft = '0';421
}422
}423
for(let item of node.tab_list) {424
item.classList.add('hidden');425
}426
if(state.modal && state.tab) {427
let modal = document.querySelector(`.modal.${state.modal}-modal`);428
let tab = document.querySelector(`.${state.tab}-tab`);429
let main = modal.querySelector('.main');430
if(modal && tab && main) {431
tab.classList.remove('hidden');432
main.style.marginLeft = '-100%';433
main.classList.add('hidden');434
}435
}436
}438
function update_fullscreen_option() {439
let fullscreen = document.fullscreenElement;440
node.option_event_fullscreen.classList[fullscreen ? 'add' : 'remove']('active');441
node.option_event_fullscreen.querySelector('.ico').textContent = fullscreen ? 'toggle_on' : 'toggle_off';442
}444
function update_view_mode_option() {445
let view_mode = state.option.view_mode;446
show_notification(`notification.view-mode.${view_mode ? 'on' : 'off'}`);447
node.option_event_view_mode.classList[view_mode ? 'add' : 'remove']('active');448
node.option_event_view_mode.querySelector('.ico').textContent = view_mode ? 'toggle_on' : 'toggle_off';449
state.modal = null;450
state.tab = null;451
update_modal_list();452
if(view_mode) {453
canvas.on_release(null, state);454
canvas.clear_cursor();455
canvas.get_canvas().style.cursor = 'default';456
node.hotbar.classList.add('inactive');457
node.header.classList.add('inactive');458
node.hotbar.animate([459
{ opacity: 1 },460
{ opacity: 0, bottom: '-10px', pointerEvents: 'none' }461
], {462
easing: 'ease-out',463
duration: 250,464
fill: 'both'465
});466
node.mainbar.animate([467
{ opacity: 1, marginTop: 0 },468
{ opacity: 0, marginTop: '-60px' }469
], {470
easing: 'ease-out',471
duration: 250,472
fill: 'both'473
});474
node.sidebar.classList.remove('hidden');475
node.sidebar.animate([476
{ opacity: 0 },477
{ opacity: 1 }478
], {479
delay: 250,480
easing: 'ease-out',481
duration: 250,482
fill: 'both'483
});484
}485
else {486
state.option.crop_mode = false;487
canvas.draw_crop(state);488
canvas.on_release(null, state, true);489
canvas.get_canvas().style.cursor = 'none';490
node.hotbar.classList.remove('inactive');491
node.header.classList.remove('inactive');492
node.hotbar.animate([493
{ opacity: 0, bottom: '-10px' },494
{ opacity: 1, bottom: '30px' }495
], {496
easing: 'ease-out',497
duration: 250,498
fill: 'both'499
});500
node.mainbar.animate([501
{ opacity: 0, marginTop: '-60px' },502
{ opacity: 1, marginTop: 0 }503
], {504
easing: 'ease-out',505
duration: 250,506
fill: 'both'507
});508
node.sidebar.classList.add('hidden');509
}510
}512
function update_dark_mode_option(args) {513
let { passive = false } = args || {};514
let dark_mode = state.option.dark_mode;515
if(!passive) {516
show_notification(`notification.dark-mode.${dark_mode ? 'on' : 'off'}`);517
}518
node.option_event_dark_mode.classList[dark_mode ? 'add' : 'remove']('active');519
node.option_event_dark_mode.querySelector('.ico').textContent = dark_mode ? 'toggle_on' : 'toggle_off';520
document.body.classList[dark_mode ? 'add' : 'remove']('theme-dark');521
if(cookie.hasAccepted()) {522
localStorage.setItem('outline.custom.dark-mode', dark_mode);523
}524
}526
function update_undo_and_redo() {527
node.undo_tool.classList[state.history.length > 0 ? 'remove' : 'add']('inactive');528
node.redo_tool.classList[state.redo_history.length > 0 ? 'remove' : 'add']('inactive');529
}531
function update_caption_list() {532
for(let item of node.caption_list) {533
let code = item.dataset.code;534
item.classList[code === state.caption ? 'add' : 'remove']('active');535
}536
for(let item of node.content_list) {537
let code = item.dataset.code;538
item.classList[code === state.caption ? 'remove' : 'add']('hidden');539
}540
}542
function on_pointerdown(event) {543
// detect touch544
if(!state.device_list.touch && event.pointerType === 'touch') {545
state.device_list.touch = true;546
if(state.device) {547
show_notification('notification.input-device.touch.add');548
}549
else {550
state.device = 'touch';551
state.device_fallback = 'touch';552
}553
update_device_list();554
}555
// detect pen556
if(!state.device_list.pen && event.pointerType === 'pen') {557
state.device_list.pen = true;558
show_notification('notification.input-device.pencil.add');559
if(!state.device) {560
state.device = 'pen';561
state.device_fallback = 'pen';562
}563
update_device_list();564
}565
// drawing566
if(event.button == 0) {567
if(!state.option.view_mode && state.device === event.pointerType) {568
if(event.target === canvas.get_canvas()) {569
if(!PRIORITY_MODAL.includes(state.modal)) {570
update_focus(false);571
canvas.on_press(event, state);572
update_undo_and_redo();573
state.point = {574
x: event.layerX,575
y: event.layerY576
};577
canvas.draw_cursor(state);578
}579
}580
}581
if(state.option.view_mode && state.option.crop_mode) {582
if(event.target === canvas.get_canvas()) {583
state.crop = true;584
state.region = [];585
state.region[0] = { x: event.layerX, y: event.layerY };586
canvas.draw_crop(state);587
}588
}589
}590
}592
function on_pointermove(event) {593
// detect mouse594
if(!state.device_list.mouse && event.pointerType === 'mouse') {595
state.device_list.mouse = true;596
if(state.device) {597
show_notification('notification.input-device.mouse.add');598
}599
else {600
state.device = 'mouse';601
state.device_fallback = 'mouse';602
}603
update_device_list();604
}605
// drawing606
if(!state.option.view_mode && state.device === event.pointerType) {607
if(event.target === canvas.get_canvas()) {608
if(!PRIORITY_MODAL.includes(state.modal)) {609
canvas.on_move(event, state);610
}611
state.point = {612
x: event.layerX,613
y: event.layerY614
};615
}616
canvas.draw_cursor(state);617
}618
if(state.option.view_mode && state.option.crop_mode) {619
if(state.crop && event.target === canvas.get_canvas()) {620
state.region[1] = { x: event.layerX, y: event.layerY };621
canvas.draw_crop(state);622
}623
}624
}626
function on_pointerup(event) {627
if(event.button == 0) {628
if(!state.option.view_mode && state.device === event.pointerType) {629
canvas.on_release(event, state);630
update_undo_and_redo();631
update_focus(true);632
}633
if(state.option.view_mode && state.option.crop_mode) {634
if(state.crop && event.target === canvas.get_canvas()) {635
state.crop = false;636
state.region[1] = { x: event.layerX, y: event.layerY };637
canvas.draw_crop(state);638
let [ begin, end ] = state.region;639
let delta = {640
x: end.x - begin.x,641
y: end.y - begin.y642
};643
let x = begin.x < end.x ? begin.x : end.x;644
let y = begin.y < end.y ? begin.y : end.y;645
if(delta.x < 0) {646
delta.x *= -1;647
}648
if(delta.y < 0) {649
delta.y *= -1;650
}651
if(delta.x != 0 && delta.y != 0) {652
let data = canvas.create_capture(x, y, delta.x, delta.y);653
if(data) {654
node.download.download = `outline-${uuid()}.png`;655
node.download.href = data;656
node.download.click();657
state.option.crop_mode = false;658
canvas.draw_crop(state);659
canvas.get_canvas().style.cursor = 'default';660
}661
else {662
console.warn('Unable to create capture from current state!');663
}664
}665
}666
}667
}668
}670
function on_pointerout(event) {671
if(!state.option.view_mode && state.device === event.pointerType) {672
canvas.on_release(event, state);673
update_undo_and_redo();674
state.point = null;675
canvas.draw_cursor(state);676
}677
if(state.option.view_mode && state.option.crop_mode) {678
if(state.crop && event.target === canvas.get_canvas()) {679
state.crop = false;680
state.region = [];681
canvas.draw_crop(state);682
}683
}684
}686
function on_keydown(event) {687
if(!state.key[event.code]) {688
if(event.code === 'Escape') {689
if(state.tab) {690
state.tab = null;691
update_tab_list();692
return;693
}694
if(state.modal) {695
state.modal = null;696
update_modal_list();697
return;698
}699
if(state.option.view_mode && state.option.crop_mode) {700
state.option.crop_mode = false;701
canvas.draw_crop(state);702
canvas.get_canvas().style.cursor = 'default';703
}704
}705
if(!event.ctrlKey && !event.shiftKey && !event.altKey) {706
if(!state.option.view_mode) {707
if(event.code.startsWith('Digit')) {708
let i = parseInt(event.code.substr(5)) - 1;709
if(state.index !== i) {710
if(i >= 0 && i < state.color_list.length) {711
canvas.on_release(event, state);712
state.color = state.color_list[i];713
state.index = i;714
canvas.draw_cursor(state);715
update_hotbar();716
}717
}718
}719
if(event.code === 'KeyZ') {720
state.modal = state.modal !== 'colors' ? 'colors' : null;721
update_modal_list();722
}723
if(event.code === 'KeyX') {724
state.modal = state.modal !== 'scale' ? 'scale' : null;725
update_modal_list();726
}727
if(event.code === 'KeyC') {728
state.modal = state.modal !== 'pencil' ? 'pencil' : null;729
update_modal_list();730
}731
if(event.code === 'KeyV') {732
state.modal = state.modal !== 'clear' ? 'clear' : null;733
update_modal_list();734
}735
/*736
if(event.code === 'KeyB') {737
state.modal = state.modal !== 'multiplayer' ? 'multiplayer' : null;738
update_modal_list();739
}740
if(event.code === 'KeyN') {741
state.modal = state.modal !== 'account' ? 'account' : null;742
update_modal_list();743
}744
*/745
if(event.code === 'KeyM') {746
state.modal = state.modal !== 'more' ? 'more' : null;747
update_modal_list();748
}749
if(event.code === 'KeyQ') {750
canvas.on_release(event, state);751
state.pencil = state.pencil_list[0];752
canvas.draw_cursor(state);753
update_pencil_list();754
}755
if(event.code === 'KeyW') {756
canvas.on_release(event, state);757
state.pencil = state.pencil_list[1];758
canvas.draw_cursor(state);759
update_pencil_list();760
}761
if(event.code === 'KeyE') {762
canvas.on_release(event, state);763
state.pencil = state.pencil_list[2];764
canvas.draw_cursor(state);765
update_pencil_list();766
}767
if(event.code === 'KeyF') {768
if(!document.fullscreenElement) {769
document.documentElement.requestFullscreen();770
}771
else if(document.exitFullscreen) {772
document.exitFullscreen();773
}774
}775
}776
if(state.option.view_mode && !state.option.crop_mode) {777
if(event.code === 'KeyZ') {778
state.modal = state.modal !== 'capture' ? 'capture' : null;779
update_modal_list();780
}781
}782
if(event.code === 'Space') {783
state.option.view_mode = !state.option.view_mode;784
update_view_mode_option();785
}786
}787
if(event.ctrlKey && !event.shiftKey && !event.altKey) {788
if(event.code === 'KeyY') {789
canvas.undo(state);790
update_undo_and_redo();791
}792
if(event.code === 'KeyZ') {793
canvas.redo(state);794
update_undo_and_redo();795
}796
}797
if(event.code === 'Enter') {798
if(state.modal === 'clear') {799
node.clear.click();800
}801
}802
state.key[event.code] = true;803
}804
}806
function on_keyup(event) {807
state.key[event.code] = false;808
}810
function on_wheel(event) {811
if(!state.option.view_mode && state.device === 'mouse') {812
if(event.target === canvas.get_canvas()) {813
let y = event.deltaY < 0 ? 1 : -1;814
if(state.radius + y > 2 - 1 && state.radius + y < 50 + 1) {815
canvas.on_release(event, state);816
state.radius += y;817
node.scale_input.value = state.radius;818
canvas.draw_cursor(state);819
}820
}821
}822
}824
function on_fullscreenchange() {825
update_fullscreen_option();826
}828
function fill_hotbar_list() {829
for(let [ i, item ] of Object.entries(node.hotbar_list)) {830
if(state.color_list.length > i) {831
item.style.background = COLORS[state.color_list[i]];832
item.addEventListener('click', function(event) {833
canvas.on_release(event, state);834
state.color = state.color_list[i];835
state.index = i;836
canvas.draw_cursor(state);837
update_hotbar();838
});839
if(state.index == i) {840
item.classList.add('active');841
}842
}843
}844
}846
function fill_modal_color_list() {847
for(let [ i, item ] of Object.entries(node.modal_color_list)) {848
if(COLORS.length > i) {849
item.style.background = COLORS[i];850
item.addEventListener('click', function(event) {851
canvas.on_release(event, state);852
state.color = i;853
state.modal = null;854
update_modal_list();855
canvas.draw_cursor(state);856
state.index = null;857
update_hotbar();858
});859
}860
}861
}863
function show_notification(message) {864
let code = uuid();865
state.timestamp = code;866
let content = node.notification.querySelector('.content');867
content.textContent = locale.get()[message];868
node.notification.animate([869
{ opacity: 0 },870
{ opacity: 1 }871
], {872
duration: 200,873
fill: 'both'874
});875
setTimeout(function() {876
if(state.timestamp === code) {877
node.notification.animate([878
{ opacity: 1 },879
{ opacity: 0 }880
], {881
duration: 200,882
fill: 'both'883
});884
}885
}, 1000);886
}