so://phie

outline

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

blob: bfafa72dfba7559b910089989aa8d0cf12c9f925 (1373 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 item.dataset.title = that.state.dark ? 'Light Theme' : 'Dark Theme';

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

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

33 }

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

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

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

37 }

38}

39

40function isMobile() {

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

42}

43

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