so://phie

outline

A web-based drawing app
git clone git://soophie.de/outline

blob: 3fa699b096d664f62d355941e9df0617a8086c05 (23144 bytes)[doc][blame][raw]

1import { FIREBASE, COLORS, PRIORITY_MODAL, LOCALES } from './constant.js';

2import { uuid, query, prevent } from './util.js';

3

4import locale from './mod/locale.js';

5import canvas from './mod/canvas.js';

6import cookie from './mod/cookie.js';

7

8let node;

9let 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: false

23 },

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: false

38 },

39 history: [],

40 redo_history: []

41};

42

43export async function init() {

44

45 locale.init();

46 await locale.load('./asset/lang', LOCALES);

47 canvas.init();

48

49 node = query({

50 wrapper: '.wrapper',

51 controls: '.controls',

52 modal_list: { query: '.modal', all: true },

53 tab_list: { query: '.tab', all: true },

54 header: '.header-list',

55 hotbar: '.hotbar',

56 hotbar_list: { query: '.hotbar .color', all: true },

57 modal_color_list: { query: '.colors-modal .color', all: true },

58 language_list: { query: '.more-modal .language-tab .item[data-event="change.language"]', all: true },

59 device_list: { query: '.more-modal .device-tab .item[data-event="change.device"]', all: true },

60 pencil_list: { query: '.pencil-modal .item[data-event="change.pencil"]', all: true },

61 modal_event_list: { query: '[data-event*=".modal"]', all: true },

62 tab_event_list: { query: '[data-event*=".tab"]', all: true },

63 capture_event_list: { query: '[data-event*=".capture"]', all: true },

64 tool_list: { query: '.tool', all: true },

65 action_list: { query: '.action', all: true },

66 notification: '.notification',

67 scale_input: 'input.scale[type="range"]',

68 clear: 'button.btn-apply[data-event="clear"]',

69 pencil_tool: '.tool-item[data-code="pencil"]',

70 option_event_fullscreen: '[data-event="toggle.fullscreen"]',

71 option_event_view_mode: '[data-event="toggle.view-mode"]',

72 option_event_dark_mode: '[data-event="toggle.dark-mode"]',

73 undo_tool: '[data-lang="action.undo"]',

74 redo_tool: '[data-lang="action.redo"]',

75 colors_modal: '.colors-modal',

76 mainbar: '.mainbar',

77 sidebar: '.sidebar',

78 edit_mode: '[data-event="close.view-mode"]',

79 content: '.modal .content',

80 caption_list: { query: '[data-event="open.content"]' , all: true },

81 content_list: { query: '.content-item' , all: true },

82 download: '#download',

83 cookie: '.cookie',

84 accept: '.button.accept'

85 });

86

87 update_language_list();

88

89 fill_hotbar_list();

90 fill_modal_color_list();

91

92 bind_events(locale);

93

94 node.wrapper.animate([

95 { opacity: 1 },

96 { opacity: 0, pointerEvents: 'none' }

97 ], {

98 delay: 100,

99 duration: 500,

100 fill: 'both'

101 });

102 node.hotbar.animate([

103 { opacity: 0, bottom: '-10px' },

104 { opacity: 1 }

105 ], {

106 delay: 600,

107 easing: 'ease-out',

108 duration: 250,

109 fill: 'both'

110 });

111

112 if(!cookie.hasAccepted()) {

113 node.cookie.classList.remove('hidden');

114 cookie.requestPermission(node.accept)

115 .then(function() {

116 node.cookie.classList.add('hidden');

117 load_resources();

118 });

119 }

120 else {

121 load_resources();

122 }

123}

124

125function load_resources() {

126 let dark_mode = localStorage.getItem('outline.custom.dark-mode');

127 if(dark_mode && dark_mode === 'true') {

128 document.body.classList.add('theme-dark');

129 state.option.dark_mode = true;

130 update_dark_mode_option({ passive: true });

131 }

132 try {

133 firebase.initializeApp(FIREBASE);

134 firebase.analytics();

135 }

136 catch(error) {

137 console.warn('Unable to load Google Analytics!');

138 }

139}

140

141function bind_events(locale) {

142 document.addEventListener('dragstart', prevent);

143 document.addEventListener('contextmenu', prevent);

144 document.addEventListener('pointerdown', on_pointerdown);

145 document.addEventListener('pointermove', on_pointermove);

146 document.addEventListener('pointerup', on_pointerup);

147 document.addEventListener('pointerout', on_pointerout);

148 document.addEventListener('keydown', on_keydown);

149 document.addEventListener('wheel', on_wheel);

150 document.addEventListener('wheel', function(event) {

151 if(event.ctrlKey) {

152 prevent(event);

153 }

154 }, { passive: false });

155 document.addEventListener('touchmove', function(event) {

156 if(event.target !== node.scale_input && event.target !== node.colors_modal && !node.modal_color_list.includes(event.target) && event.target !== node.content) {

157 event.preventDefault();

158 }

159 }, { passive: false });

160

161 for(let item of node.language_list) {

162 item.addEventListener('click', function(event) {

163 let code = item.dataset.code;

164 locale.change(code);

165 update_language_list();

166 });

167 }

168 for(let item of node.device_list) {

169 item.addEventListener('click', function(event) {

170 let code = item.dataset.code;

171 if(state.device_list[code]) {

172 state.device = code;

173 update_device_list();

174 }

175 });

176 }

177 for(let item of node.pencil_list) {

178 item.addEventListener('click', function(event) {

179 state.pencil = item.dataset.code;

180 update_pencil_list();

181 state.modal = null;

182 update_modal_list();

183 });

184 }

185 for(let item of node.modal_event_list) {

186 item.addEventListener('click', function(event) {

187 let code = item.dataset.code;

188 let match = /^(toggle|open|close).modal$/.exec(item.dataset.event);

189 if(match) {

190 if(!item.classList.contains('inactive')) {

191 switch(match[1]) {

192 case 'toggle':

193 if(code) {

194 state.modal = state.modal !== code ? code : null;

195 update_modal_list();

196 }

197 break;

198 case 'open':

199 if(code && state.modal !== code) {

200 state.modal = code;

201 update_modal_list();

202 }

203 break;

204 case 'close':

205 if(state.modal !== null) {

206 state.modal = null;

207 update_modal_list();

208 }

209 break;

210 default:

211 break;

212 }

213 }

214 }

215 });

216 }

217 for(let item of node.tab_event_list) {

218 item.addEventListener('click', function(event) {

219 let code = item.dataset.code;

220 let match = /^(open|close).tab/.exec(item.dataset.event);

221 if(match) {

222 switch(match[1]) {

223 case 'open':

224 if(code && state.tab !== code) {

225 state.tab = code;

226 update_tab_list();

227 }

228 break;

229 case 'close':

230 if(state.tab !== null) {

231 state.tab = null;

232 update_tab_list();

233 }

234 break;

235 default:

236 break;

237 }

238 }

239 });

240 }

241 for(let item of node.capture_event_list) {

242 item.addEventListener('click', function(event) {

243 let code = item.dataset.code;

244 if(code === 'download') {

245 if(state.option.crop_mode) {

246 state.option.crop_mode = false;

247 canvas.draw_crop(state);

248 canvas.get_canvas().style.cursor = 'default';

249 }

250 let data = canvas.create_capture(0, 0, window.innerWidth, window.innerHeight, 60);

251 if(data) {

252 node.download.download = `outline-${uuid()}.png`;

253 node.download.href = data;

254 node.download.click();

255 }

256 else {

257 console.warn('Unable to create capture from current state!');

258 }

259 }

260 if(code === 'crop') {

261 state.option.crop_mode = true;

262 state.region = [];

263 canvas.draw_crop(state);

264 canvas.get_canvas().style.cursor = 'crosshair';

265 }

266 state.modal = null;

267 state.tab = null;

268 update_modal_list();

269 })

270 }

271 node.scale_input.addEventListener('input', function(event) {

272 state.radius = parseInt(node.scale_input.value);

273 state.point = {

274 x: parseInt(window.innerWidth / 2),

275 y: parseInt(window.innerHeight / 2)

276 };

277 canvas.draw_cursor(state);

278 });

279 node.clear.addEventListener('click', function(event) {

280 canvas.clear(state);

281 update_undo_and_redo();

282 show_notification('notification.clear');

283 state.modal = null;

284 update_modal_list();

285 });

286 node.option_event_fullscreen.addEventListener('click', function(event) {

287 if(!document.fullscreenElement) {

288 document.documentElement.requestFullscreen();

289 }

290 else if(document.exitFullscreen) {

291 document.exitFullscreen();

292 }

293 });

294 window.addEventListener('fullscreenchange', on_fullscreenchange);

295 node.option_event_view_mode.addEventListener('click', function(event) {

296 state.option.view_mode = !state.option.view_mode;

297 update_view_mode_option();

298 });

299 node.option_event_dark_mode.addEventListener('click', function(event) {

300 state.option.dark_mode = !state.option.dark_mode;

301 update_dark_mode_option();

302 });

303 node.undo_tool.addEventListener('click', function(event) {

304 canvas.undo(state);

305 update_undo_and_redo();

306 });

307 node.redo_tool.addEventListener('click', function(event) {

308 canvas.redo(state);

309 update_undo_and_redo();

310 });

311 node.edit_mode.addEventListener('click', function(event) {

312 state.option.view_mode = false;

313 update_view_mode_option();

314 });

315 for(let item of node.caption_list) {

316 item.addEventListener('click', function(event) {

317 state.caption = item.dataset.code;

318 update_caption_list();

319 });

320 }

321

322 window.addEventListener('beforeunload', function(event) {

323 // ...

324 });

325}

326

327function update_language_list() {

328 let lang = locale.get_current();

329 for(let item of node.language_list) {

330 let code = item.dataset.code;

331 item.classList[code === lang ? 'add' : 'remove']('active');

332 }

333}

334

335function update_device_list() {

336 if(!state.option.view_mode && !state.option.crop_mode) {

337 canvas.get_canvas().style.cursor = state.device === 'mouse' ? 'none' : '';

338 }

339 for(let item of node.device_list) {

340 let code = item.dataset.code;

341 item.classList[code === state.device ? 'add' : 'remove']('active');

342 item.classList[state.device_list[code] ? 'remove' : 'add']('inactive');

343 }

344}

345

346function update_pencil_list() {

347 for(let item of node.pencil_list) {

348 let code = item.dataset.code;

349 item.classList[code === state.pencil ? 'add' : 'remove']('active');

350 if(code === state.pencil) {

351 node.pencil_tool.querySelector('i.ico').innerHTML = item.querySelector('i.ico').innerHTML;

352 }

353 }

354}

355

356function update_hotbar() {

357 for(let item of node.hotbar_list) {

358 item.classList[node.hotbar_list[state.index] === item ? 'add' : 'remove']('active');

359 }

360}

361

362function update_focus(bool) {

363 for(let item of node.hotbar_list) {

364 item.style.pointerEvents = bool ? '' : 'none';

365 }

366 for(let item of node.tool_list) {

367 item.style.pointerEvents = bool ? '' : 'none';

368 }

369 for(let item of node.action_list) {

370 item.style.pointerEvents = bool ? '' : 'none';

371 }

372}

373

374function update_modal_list() {

375 for(let item of node.modal_list) {

376 item.classList.add('hidden');

377 }

378 for(let item of node.modal_event_list) {

379 item.classList.remove('active');

380 }

381 state.tab = null;

382 update_tab_list();

383 state.caption = 'controls';

384 update_caption_list();

385 if(state.modal) {

386 canvas.on_release(event, state, true);

387 let modal = document.querySelector(`.modal.${state.modal}-modal`);

388 let button = document.querySelector(`[data-event*=".modal"][data-code="${state.modal}"]`);

389 if(modal) {

390 modal.classList.remove('hidden');

391 modal.animate([

392 { opacity: 0, marginTop: '-6px' },

393 { opacity: 1, marginTop: '0' }

394 ], {

395 duration: 100,

396 fill: 'both'

397 });

398 }

399 if(button) {

400 button.classList.add('active');

401 }

402 }

403}

404

405function update_tab_list() {

406 for(let item of node.modal_list) {

407 let main = item.querySelector('.main');

408 if(main) {

409 main.classList.remove('hidden');

410 main.style.marginLeft = '0';

411 }

412 }

413 for(let item of node.tab_list) {

414 item.classList.add('hidden');

415 }

416 if(state.modal && state.tab) {

417 let modal = document.querySelector(`.modal.${state.modal}-modal`);

418 let tab = document.querySelector(`.${state.tab}-tab`);

419 let main = modal.querySelector('.main');

420 if(modal && tab && main) {

421 tab.classList.remove('hidden');

422 main.style.marginLeft = '-100%';

423 main.classList.add('hidden');

424 }

425 }

426}

427

428function update_fullscreen_option() {

429 let fullscreen = document.fullscreenElement;

430 node.option_event_fullscreen.classList[fullscreen ? 'add' : 'remove']('active');

431 node.option_event_fullscreen.querySelector('.ico').textContent = fullscreen ? 'toggle_on' : 'toggle_off';

432}

433

434function update_view_mode_option() {

435 let view_mode = state.option.view_mode;

436 show_notification(`notification.view-mode.${view_mode ? 'on' : 'off'}`);

437 node.option_event_view_mode.classList[view_mode ? 'add' : 'remove']('active');

438 node.option_event_view_mode.querySelector('.ico').textContent = view_mode ? 'toggle_on' : 'toggle_off';

439 state.modal = null;

440 state.tab = null;

441 update_modal_list();

442 if(view_mode) {

443 canvas.on_release(null, state);

444 canvas.clear_cursor();

445 canvas.get_canvas().style.cursor = 'default';

446 node.hotbar.classList.add('inactive');

447 node.header.classList.add('inactive');

448 node.hotbar.animate([

449 { opacity: 1 },

450 { opacity: 0, bottom: '-10px', pointerEvents: 'none' }

451 ], {

452 easing: 'ease-out',

453 duration: 250,

454 fill: 'both'

455 });

456 node.mainbar.animate([

457 { opacity: 1, marginTop: 0 },

458 { opacity: 0, marginTop: '-60px' }

459 ], {

460 easing: 'ease-out',

461 duration: 250,

462 fill: 'both'

463 });

464 node.sidebar.classList.remove('hidden');

465 node.sidebar.animate([

466 { opacity: 0 },

467 { opacity: 1 }

468 ], {

469 delay: 250,

470 easing: 'ease-out',

471 duration: 250,

472 fill: 'both'

473 });

474 }

475 else {

476 state.option.crop_mode = false;

477 canvas.draw_crop(state);

478 canvas.on_release(null, state, true);

479 canvas.get_canvas().style.cursor = 'none';

480 node.hotbar.classList.remove('inactive');

481 node.header.classList.remove('inactive');

482 node.hotbar.animate([

483 { opacity: 0, bottom: '-10px' },

484 { opacity: 1, bottom: '30px' }

485 ], {

486 easing: 'ease-out',

487 duration: 250,

488 fill: 'both'

489 });

490 node.mainbar.animate([

491 { opacity: 0, marginTop: '-60px' },

492 { opacity: 1, marginTop: 0 }

493 ], {

494 easing: 'ease-out',

495 duration: 250,

496 fill: 'both'

497 });

498 node.sidebar.classList.add('hidden');

499 }

500}

501

502const CONFIG_COOKIE_PROPERTY = 'outline.custom.accepted';

503

504function update_dark_mode_option(args) {

505 let { passive = false } = args || {};

506 let dark_mode = state.option.dark_mode;

507 if(!passive) {

508 show_notification(`notification.dark-mode.${dark_mode ? 'on' : 'off'}`);

509 }

510 node.option_event_dark_mode.classList[dark_mode ? 'add' : 'remove']('active');

511 node.option_event_dark_mode.querySelector('.ico').textContent = dark_mode ? 'toggle_on' : 'toggle_off';

512 document.body.classList[dark_mode ? 'add' : 'remove']('theme-dark');

513 if(cookie.hasAccepted()) {

514 localStorage.setItem('outline.custom.dark-mode', dark_mode);

515 }

516}

517

518function update_undo_and_redo() {

519 node.undo_tool.classList[state.history.length > 0 ? 'remove' : 'add']('inactive');

520 node.redo_tool.classList[state.redo_history.length > 0 ? 'remove' : 'add']('inactive');

521}

522

523function update_caption_list() {

524 for(let item of node.caption_list) {

525 let code = item.dataset.code;

526 item.classList[code === state.caption ? 'add' : 'remove']('active');

527 }

528 for(let item of node.content_list) {

529 let code = item.dataset.code;

530 item.classList[code === state.caption ? 'remove' : 'add']('hidden');

531 }

532}

533

534function on_pointerdown(event) {

535 // detect touch

536 if(!state.device_list.touch && event.pointerType === 'touch') {

537 state.device_list.touch = true;

538 if(state.device) {

539 show_notification('notification.input-device.touch.add');

540 }

541 else {

542 state.device = 'touch';

543 state.device_fallback = 'touch';

544 }

545 update_device_list();

546 }

547 // detect pen

548 if(!state.device_list.pen && event.pointerType === 'pen') {

549 state.device_list.pen = true;

550 show_notification('notification.input-device.pencil.add');

551 if(!state.device) {

552 state.device = 'pen';

553 state.device_fallback = 'pen';

554 }

555 update_device_list();

556 }

557 // drawing

558 if(!state.option.view_mode && state.device === event.pointerType) {

559 if(event.target === canvas.get_canvas()) {

560 if(!PRIORITY_MODAL.includes(state.modal)) {

561 update_focus(false);

562 canvas.on_press(event, state);

563 update_undo_and_redo();

564 state.point = {

565 x: event.layerX,

566 y: event.layerY

567 };

568 canvas.draw_cursor(state);

569 }

570 }

571 }

572 if(state.option.view_mode && state.option.crop_mode) {

573 if(event.target === canvas.get_canvas()) {

574 state.crop = true;

575 state.region = [];

576 state.region[0] = { x: event.layerX, y: event.layerY };

577 canvas.draw_crop(state);

578 }

579 }

580}

581

582function on_pointermove(event) {

583 // detect mouse

584 if(!state.device_list.mouse && event.pointerType === 'mouse') {

585 state.device_list.mouse = true;

586 if(state.device) {

587 show_notification('notification.input-device.mouse.add');

588 }

589 else {

590 state.device = 'mouse';

591 state.device_fallback = 'mouse';

592 }

593 update_device_list();

594 }

595 // drawing

596 if(!state.option.view_mode && state.device === event.pointerType) {

597 if(event.target === canvas.get_canvas()) {

598 if(!PRIORITY_MODAL.includes(state.modal)) {

599 canvas.on_move(event, state);

600 }

601 state.point = {

602 x: event.layerX,

603 y: event.layerY

604 };

605 }

606 canvas.draw_cursor(state);

607 }

608 if(state.option.view_mode && state.option.crop_mode) {

609 if(state.crop && event.target === canvas.get_canvas()) {

610 state.region[1] = { x: event.layerX, y: event.layerY };

611 canvas.draw_crop(state);

612 }

613 }

614}

615

616function on_pointerup(event) {

617 if(!state.option.view_mode && state.device === event.pointerType) {

618 canvas.on_release(event, state);

619 update_undo_and_redo();

620 update_focus(true);

621 }

622 if(state.option.view_mode && state.option.crop_mode) {

623 if(state.crop && event.target === canvas.get_canvas()) {

624 state.crop = false;

625 state.region[1] = { x: event.layerX, y: event.layerY };

626 canvas.draw_crop(state);

627 let [ begin, end ] = state.region;

628 let delta = {

629 x: end.x - begin.x,

630 y: end.y - begin.y

631 };

632 let x = begin.x < end.x ? begin.x : end.x;

633 let y = begin.y < end.y ? begin.y : end.y;

634 if(delta.x < 0) {

635 delta.x *= -1;

636 }

637 if(delta.y < 0) {

638 delta.y *= -1;

639 }

640 if(delta.x != 0 && delta.y != 0) {

641 let data = canvas.create_capture(x, y, delta.x, delta.y);

642 if(data) {

643 node.download.download = `outline-${uuid()}.png`;

644 node.download.href = data;

645 node.download.click();

646 state.option.crop_mode = false;

647 canvas.draw_crop(state);

648 canvas.get_canvas().style.cursor = 'default';

649 }

650 else {

651 console.warn('Unable to create capture from current state!');

652 }

653 }

654 }

655 }

656}

657

658function on_pointerout(event) {

659 if(!state.option.view_mode && state.device === event.pointerType) {

660 canvas.on_release(event, state);

661 update_undo_and_redo();

662 state.point = null;

663 canvas.draw_cursor(state);

664 }

665 if(state.option.view_mode && state.option.crop_mode) {

666 if(state.crop && event.target === canvas.get_canvas()) {

667 state.crop = false;

668 state.region = [];

669 canvas.draw_crop(state);

670 }

671 }

672}

673

674function on_keydown(event) {

675 if(event.code === 'Escape') {

676 if(state.tab) {

677 state.tab = null;

678 update_tab_list();

679 return;

680 }

681 if(state.modal) {

682 state.modal = null;

683 update_modal_list();

684 return;

685 }

686 if(state.option.view_mode && state.option.crop_mode) {

687 state.option.crop_mode = false;

688 canvas.draw_crop(state);

689 canvas.get_canvas().style.cursor = 'default';

690 }

691 }

692 if(!event.ctrlKey && !event.shiftKey && !event.altKey) {

693 if(!state.option.view_mode) {

694 if(event.code.startsWith('Digit')) {

695 let i = parseInt(event.code.substr(5)) - 1;

696 if(state.index !== i) {

697 if(i >= 0 && i < state.color_list.length) {

698 canvas.on_release(event, state);

699 state.color = state.color_list[i];

700 state.index = i;

701 canvas.draw_cursor(state);

702 update_hotbar();

703 }

704 }

705 }

706 if(event.code === 'KeyZ') {

707 state.modal = state.modal !== 'colors' ? 'colors' : null;

708 update_modal_list();

709 }

710 if(event.code === 'KeyX') {

711 state.modal = state.modal !== 'scale' ? 'scale' : null;

712 update_modal_list();

713 }

714 if(event.code === 'KeyC') {

715 state.modal = state.modal !== 'pencil' ? 'pencil' : null;

716 update_modal_list();

717 }

718 if(event.code === 'KeyV') {

719 state.modal = state.modal !== 'clear' ? 'clear' : null;

720 update_modal_list();

721 }

722 /*

723 if(event.code === 'KeyB') {

724 state.modal = state.modal !== 'multiplayer' ? 'multiplayer' : null;

725 update_modal_list();

726 }

727 if(event.code === 'KeyN') {

728 state.modal = state.modal !== 'account' ? 'account' : null;

729 update_modal_list();

730 }

731 */

732 if(event.code === 'KeyM') {

733 state.modal = state.modal !== 'more' ? 'more' : null;

734 update_modal_list();

735 }

736 if(event.code === 'KeyQ') {

737 canvas.on_release(event, state);

738 state.pencil = state.pencil_list[0];

739 canvas.draw_cursor(state);

740 update_pencil_list();

741 }

742 if(event.code === 'KeyW') {

743 canvas.on_release(event, state);

744 state.pencil = state.pencil_list[1];

745 canvas.draw_cursor(state);

746 update_pencil_list();

747 }

748 if(event.code === 'KeyE') {

749 canvas.on_release(event, state);

750 state.pencil = state.pencil_list[2];

751 canvas.draw_cursor(state);

752 update_pencil_list();

753 }

754 if(event.code === 'KeyF') {

755 if(!document.fullscreenElement) {

756 document.documentElement.requestFullscreen();

757 }

758 else if(document.exitFullscreen) {

759 document.exitFullscreen();

760 }

761 }

762 }

763 if(event.code === 'Space') {

764 state.option.view_mode = !state.option.view_mode;

765 update_view_mode_option();

766 }

767 }

768 if(event.ctrlKey && !event.shiftKey && !event.altKey) {

769 if(event.code === 'KeyY') {

770 canvas.undo(state);

771 update_undo_and_redo();

772 }

773 if(event.code === 'KeyZ') {

774 canvas.redo(state);

775 update_undo_and_redo();

776 }

777 }

778 if(event.code === 'Enter') {

779 if(state.modal === 'clear') {

780 node.clear.click();

781 }

782 }

783}

784

785function on_wheel(event) {

786 if(!state.option.view_mode && state.device === 'mouse') {

787 if(event.target === canvas.get_canvas()) {

788 let y = event.deltaY < 0 ? 1 : -1;

789 if(state.radius + y > 2 - 1 && state.radius + y < 50 + 1) {

790 canvas.on_release(event, state);

791 state.radius += y;

792 node.scale_input.value = state.radius;

793 canvas.draw_cursor(state);

794 }

795 }

796 }

797}

798

799function on_fullscreenchange(event) {

800 update_fullscreen_option();

801}

802

803function fill_hotbar_list() {

804 for(let [ i, item ] of Object.entries(node.hotbar_list)) {

805 if(state.color_list.length > i) {

806 item.style.background = COLORS[state.color_list[i]];

807 item.addEventListener('click', function(event) {

808 canvas.on_release(event, state);

809 state.color = state.color_list[i];

810 state.index = i;

811 canvas.draw_cursor(state);

812 update_hotbar();

813 });

814 if(state.index == i) {

815 item.classList.add('active');

816 }

817 }

818 }

819}

820

821function fill_modal_color_list() {

822 for(let [ i, item ] of Object.entries(node.modal_color_list)) {

823 if(COLORS.length > i) {

824 item.style.background = COLORS[i];

825 item.addEventListener('click', function(event) {

826 canvas.on_release(event, state);

827 state.color = i;

828 state.modal = null;

829 update_modal_list();

830 canvas.draw_cursor(state);

831 state.index = null;

832 update_hotbar();

833 });

834 }

835 }

836}

837

838function show_notification(message) {

839 let code = uuid();

840 state.timestamp = code;

841 let content = node.notification.querySelector('.content');

842 content.textContent = locale.get()[message];

843 node.notification.animate([

844 { opacity: 0 },

845 { opacity: 1 }

846 ], {

847 duration: 200,

848 fill: 'both'

849 });

850 setTimeout(function() {

851 if(state.timestamp === code) {

852 node.notification.animate([

853 { opacity: 1 },

854 { opacity: 0 }

855 ], {

856 duration: 200,

857 fill: 'both'

858 });

859 }

860 }, 1000);

861}