so://phie

outline

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

blob: bdd323fbe0ba17248c698c3f505c581f0efcbf75 (1303 bytes)[doc][blame][raw]

1function uuid() {

2 return 'xxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {

3 let r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);

4 return v.toString(16);

5 });

6}

7

8function luma(color) {

9 color = color.substr(1);

10 let r = parseInt(color.substr(0, 2), 16);

11 let g = parseInt(color.substr(2, 4), 16);

12 let b = parseInt(color.substr(4, 6), 16);

13 return ((r * 0.299) + (g * 0.587) + (b * 0.114)) > 50;

14}

15

16function download(file, data) {

17 let link = document.createElement('a');

18 link.classList.add('hidden');

19 link.download = file;

20 link.href = data;

21 document.body.appendChild(link);

22 link.click();

23}

24

25function switchTheme(item, that, isChanged) {

26 if(isChanged) {

27 that.state.dark = !that.state.dark;

28 }

29 item.querySelector('.ico').textContent = that.state.dark ? 'wb_sunny' : 'brightness_2';

30 for(let modal of that.node.modal) {

31 modal.classList[that.state.dark ? 'add' : 'remove']('theme-dark');

32 }

33 that.node.spinner.classList[that.state.dark ? 'add' : 'remove']('theme-dark');

34 if(typeof localStorage !== 'undefined') {

35 localStorage.setItem('outline.theme.dark', that.state.dark);

36 }

37}

38

39function isMobile() {

40 return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent.toLowerCase());

41}

42

43export { uuid, luma, download, switchTheme, isMobile };