so://phie

outline

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

blob: ff59a357e7fdb37839ea55dd79a83f3f31302606 (967 bytes)[doc][blame][raw]

1function define(args) {

2 let node = {};

3 if(typeof args === 'object') {

4 for(let entry of Object.entries(args)) {

5 let [ key, value ] = entry;

6 if(typeof value === 'string') {

7 node[key] = document.querySelector(value);

8 }

9 if(typeof value === 'object') {

10 let { query, all = false, parent = document } = value;

11 if(typeof query === 'string') {

12 if(typeof parent === 'string') {

13 parent = document.querySelector(parent);

14 }

15 node[key] = all ?

16 Array.from(parent.querySelectorAll(query))

17 : parent.querySelector(query);

18 }

19 }

20 }

21 return node;

22 }

23}

24

25function html(func) {

26 return {

27 build: function(args) {

28 let template = document.createElement('template');

29 template.innerHTML = func(args);

30 let fragment = template.content.cloneNode(true);

31 return {

32 element: fragment.firstElementChild,

33 render: function(parent) {

34 parent.appendChild(fragment);

35 }

36 };

37 }

38 };

39}

40

41export { define, html };