enigmatic 0.10.0 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,18 @@
1
- window.components = {
2
- 'hello-world': {
3
- style: 'color: red',
4
- template: 'Hello World'
5
- },
6
- 'random-users': {
7
- template: 'Hello Random user: {results[0].name.first} {results[0].name.last}',
8
- onMount: e => console.log('Mounted', e.tagName, e.props),
9
- beforeData: x => x.results[0].name.first = 'John'
10
- },
11
- 'tailwind-example': {
12
- template: '<div class="bg-blue-500 text-white font-bold py-2 px-4 rounded">Hello World</div>',
13
- onMount: e => loadCSS('https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css')
14
- }
15
- }
16
-
1
+ window.components = {
2
+ 'hello-world': {
3
+ style: 'color: red',
4
+ onMount: async x => console.log('mounted h-w'),
5
+ template: 'Hello World'
6
+ },
7
+ 'random-users': {
8
+ template: 'Hello Random user: {results[0].name.first} {results[0].name.last}',
9
+ onMount: e => console.log('Mounted', e.tagName, e.props),
10
+ beforeData: x => x.results[0].name.first = 'John'
11
+ },
12
+ 'tailwind-example': {
13
+ template: '<div class="bg-blue-300 text-white font-bold py-2 px-4 rounded">I am Tailwind</div>',
14
+ onMount: async e => await loadCSS('https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css')
15
+ }
16
+ }
17
+
17
18
  console.log('components.mjs', components)
package/enigmatic.css CHANGED
@@ -1,247 +1,247 @@
1
- body {
2
- font-family: var(--font-primary, -apple-system, BlinkMacSystemFont, sans-serif);
3
- height: 100vh;
4
- background-color: var(--bg-color, #fff);
5
- padding: .5rem;
6
- }
7
-
8
- body,
9
- section {
10
- display: grid;
11
- margin: 0;
12
- grid-template-columns: var(--cols, 1fr 4fr 1fr);
13
- grid-template-rows: var(--rows, 1fr 9fr 1fr);
14
- }
15
-
16
- * {
17
- grid-column: span var(--span, 1);
18
- grid-row: span var(--span-rows, 1);
19
- }
20
-
21
- .flex {
22
- display: flex;
23
- }
24
-
25
- /** positioning ***/
26
-
27
- .center {
28
- position: fixed;
29
- top: 50%;
30
- left: 50%;
31
- margin-top: -50px;
32
- margin-left: -100px;
33
- }
34
-
35
- .right {
36
- float: right;
37
- }
38
-
39
- .left {
40
- float: left;
41
- }
42
-
43
- .fixed {
44
- position: fixed;
45
- }
46
-
47
- .top {
48
- top: 0;
49
- }
50
-
51
- .bottom { bottom: 0 }
52
-
53
- .fill { height: 100vh; width: 100wh }
54
-
55
- .hide {
56
- opacity: 0;
57
- transition: opacity 0.25s linear;
58
- }
59
-
60
- .show {
61
- opacity: 1;
62
- transition: opacity 0.25s linear;
63
- }
64
-
65
- .slide-in {
66
- animation: slide-in 0.1s forwards;
67
- -webkit-animation: slide-in 0.1s forwards;
68
- }
69
-
70
- .slide-out {
71
- animation: slide-out 0.1s forwards;
72
- -webkit-animation: slide-out 0.1s forwards;
73
- }
74
-
75
- @keyframes slide-in {
76
- 100% {
77
- transform: translateX(0%);
78
- }
79
- }
80
-
81
- @-webkit-keyframes slide-in {
82
- 100% {
83
- -webkit-transform: translateX(0%);
84
- }
85
- }
86
-
87
- @keyframes slide-out {
88
- 0% {
89
- transform: translateX(0%);
90
- }
91
-
92
- 100% {
93
- transform: translateX(-100%);
94
- }
95
- }
96
-
97
- @-webkit-keyframes slide-out {
98
- 0% {
99
- -webkit-transform: translateX(0%);
100
- }
101
-
102
- 100% {
103
- -webkit-transform: translateX(-100%);
104
- }
105
- }
106
-
107
- a {
108
- text-decoration: none;
109
- }
110
-
111
- .shadow {
112
- box-shadow: 6px 6px 6px #dbdbdb;
113
- }
114
-
115
- .cursor {
116
- cursor: default;
117
- }
118
-
119
- .margins {
120
- margin: var(--margins, 15px);
121
- }
122
-
123
- .padding {
124
- padding: var(--padding, 15px);
125
- }
126
-
127
- .rem {
128
- font-size: var(--rem, 2rem);
129
- }
130
-
131
- .faded {
132
- opacity: 0.5;
133
- }
134
-
135
- .fade {
136
- opacity: 1;
137
- transition: opacity 0.25s ease-in-out;
138
- -moz-transition: opacity 0.25s ease-in-out;
139
- -webkit-transition: opacity 0.25s ease-in-out;
140
- }
141
-
142
- .fade:hover {
143
- opacity: 0.5;
144
- }
145
-
146
- .unfade {
147
- opacity: 0.5;
148
- transition: opacity 0.25s ease-in-out;
149
- -moz-transition: opacity 0.25s ease-in-out;
150
- -webkit-transition: opacity 0.25s ease-in-out;
151
- }
152
-
153
- .unfade:hover {
154
- opacity: 1;
155
- }
156
-
157
- .rounded {
158
- -moz-border-radius: 10px;
159
- -webkit-border-radius: 10px;
160
- border-radius: 10px;
161
- -khtml-border-radius: 10px;
162
- }
163
-
164
- .round {
165
- vertical-align: middle;
166
- width: 50px;
167
- height: 50px;
168
- border-radius: 50%;
169
- }
170
-
171
- /** html elements **/
172
-
173
- canvas {
174
- position: fixed;
175
- top: 0;
176
- left: 0;
177
- }
178
-
179
- ul {
180
- list-style-type: none;
181
- border: 20px;
182
- padding: 20px;
183
- width: 50%;
184
- }
185
-
186
- li {
187
- list-style-type: none;
188
- border: 10px;
189
- padding: 10px;
190
- }
191
-
192
- li:hover {
193
- background-color: rgb(243, 241, 241);
194
- cursor: pointer;
195
- }
196
-
197
- .opacity1 {
198
- opacity: .1
199
- }
200
-
201
- .opacity2 {
202
- opacity: .2
203
- }
204
-
205
- .opacity3 {
206
- opacity: .3
207
- }
208
-
209
- .opacity4 {
210
- opacity: .4
211
- }
212
-
213
- .opacity5 {
214
- opacity: .5
215
- }
216
-
217
- .opacity6 {
218
- opacity: .6
219
- }
220
-
221
- .opacity7 {
222
- opacity: .7
223
- }
224
-
225
- .opacity8 {
226
- opacity: .8
227
- }
228
-
229
- .opacity9 {
230
- opacity: .9
231
- }
232
-
233
- .bg-red {
234
- background-color: red;
235
- }
236
-
237
- .bg-blue {
238
- background-color: blue;
239
- }
240
-
241
- .bg-yellow {
242
- background-color: yellow;
243
- }
244
-
245
- .bg-green {
246
- background-color: green;
1
+ body {
2
+ font-family: var(--font-primary, -apple-system, BlinkMacSystemFont, sans-serif);
3
+ height: 100vh;
4
+ background-color: var(--bg-color, #fff);
5
+ padding: .5rem;
6
+ }
7
+
8
+ body,
9
+ section {
10
+ display: grid;
11
+ margin: 0;
12
+ grid-template-columns: var(--cols, 1fr 4fr 1fr);
13
+ grid-template-rows: var(--rows, 1fr 9fr 1fr);
14
+ }
15
+
16
+ * {
17
+ grid-column: span var(--span, 1);
18
+ grid-row: span var(--span-rows, 1);
19
+ }
20
+
21
+ .flex {
22
+ display: flex;
23
+ }
24
+
25
+ /** positioning ***/
26
+
27
+ .center {
28
+ position: fixed;
29
+ top: 50%;
30
+ left: 50%;
31
+ margin-top: -50px;
32
+ margin-left: -100px;
33
+ }
34
+
35
+ .right {
36
+ float: right;
37
+ }
38
+
39
+ .left {
40
+ float: left;
41
+ }
42
+
43
+ .fixed {
44
+ position: fixed;
45
+ }
46
+
47
+ .top {
48
+ top: 0;
49
+ }
50
+
51
+ .bottom { bottom: 0 }
52
+
53
+ .fill { height: 100vh; width: 100wh }
54
+
55
+ .hide {
56
+ opacity: 0;
57
+ transition: opacity 0.25s linear;
58
+ }
59
+
60
+ .show {
61
+ opacity: 1;
62
+ transition: opacity 0.25s linear;
63
+ }
64
+
65
+ .slide-in {
66
+ animation: slide-in 0.1s forwards;
67
+ -webkit-animation: slide-in 0.1s forwards;
68
+ }
69
+
70
+ .slide-out {
71
+ animation: slide-out 0.1s forwards;
72
+ -webkit-animation: slide-out 0.1s forwards;
73
+ }
74
+
75
+ @keyframes slide-in {
76
+ 100% {
77
+ transform: translateX(0%);
78
+ }
79
+ }
80
+
81
+ @-webkit-keyframes slide-in {
82
+ 100% {
83
+ -webkit-transform: translateX(0%);
84
+ }
85
+ }
86
+
87
+ @keyframes slide-out {
88
+ 0% {
89
+ transform: translateX(0%);
90
+ }
91
+
92
+ 100% {
93
+ transform: translateX(-100%);
94
+ }
95
+ }
96
+
97
+ @-webkit-keyframes slide-out {
98
+ 0% {
99
+ -webkit-transform: translateX(0%);
100
+ }
101
+
102
+ 100% {
103
+ -webkit-transform: translateX(-100%);
104
+ }
105
+ }
106
+
107
+ a {
108
+ text-decoration: none;
109
+ }
110
+
111
+ .shadow {
112
+ box-shadow: 6px 6px 6px #dbdbdb;
113
+ }
114
+
115
+ .cursor {
116
+ cursor: default;
117
+ }
118
+
119
+ .margins {
120
+ margin: var(--margins, 15px);
121
+ }
122
+
123
+ .padding {
124
+ padding: var(--padding, 15px);
125
+ }
126
+
127
+ .rem {
128
+ font-size: var(--rem, 2rem);
129
+ }
130
+
131
+ .faded {
132
+ opacity: 0.5;
133
+ }
134
+
135
+ .fade {
136
+ opacity: 1;
137
+ transition: opacity 0.25s ease-in-out;
138
+ -moz-transition: opacity 0.25s ease-in-out;
139
+ -webkit-transition: opacity 0.25s ease-in-out;
140
+ }
141
+
142
+ .fade:hover {
143
+ opacity: 0.5;
144
+ }
145
+
146
+ .unfade {
147
+ opacity: 0.5;
148
+ transition: opacity 0.25s ease-in-out;
149
+ -moz-transition: opacity 0.25s ease-in-out;
150
+ -webkit-transition: opacity 0.25s ease-in-out;
151
+ }
152
+
153
+ .unfade:hover {
154
+ opacity: 1;
155
+ }
156
+
157
+ .rounded {
158
+ -moz-border-radius: 10px;
159
+ -webkit-border-radius: 10px;
160
+ border-radius: 10px;
161
+ -khtml-border-radius: 10px;
162
+ }
163
+
164
+ .round {
165
+ vertical-align: middle;
166
+ width: 50px;
167
+ height: 50px;
168
+ border-radius: 50%;
169
+ }
170
+
171
+ /** html elements **/
172
+
173
+ canvas {
174
+ position: fixed;
175
+ top: 0;
176
+ left: 0;
177
+ }
178
+
179
+ ul {
180
+ list-style-type: none;
181
+ border: 20px;
182
+ padding: 20px;
183
+ width: 50%;
184
+ }
185
+
186
+ li {
187
+ list-style-type: none;
188
+ border: 10px;
189
+ padding: 10px;
190
+ }
191
+
192
+ li:hover {
193
+ background-color: rgb(243, 241, 241);
194
+ cursor: pointer;
195
+ }
196
+
197
+ .opacity1 {
198
+ opacity: .1
199
+ }
200
+
201
+ .opacity2 {
202
+ opacity: .2
203
+ }
204
+
205
+ .opacity3 {
206
+ opacity: .3
207
+ }
208
+
209
+ .opacity4 {
210
+ opacity: .4
211
+ }
212
+
213
+ .opacity5 {
214
+ opacity: .5
215
+ }
216
+
217
+ .opacity6 {
218
+ opacity: .6
219
+ }
220
+
221
+ .opacity7 {
222
+ opacity: .7
223
+ }
224
+
225
+ .opacity8 {
226
+ opacity: .8
227
+ }
228
+
229
+ .opacity9 {
230
+ opacity: .9
231
+ }
232
+
233
+ .bg-red {
234
+ background-color: red;
235
+ }
236
+
237
+ .bg-blue {
238
+ background-color: blue;
239
+ }
240
+
241
+ .bg-yellow {
242
+ background-color: yellow;
243
+ }
244
+
245
+ .bg-green {
246
+ background-color: green;
247
247
  }
package/enigmatic.js CHANGED
@@ -1,157 +1,150 @@
1
- const w = {},
2
- d = document;
3
-
4
- // helpers
5
-
6
- w.$ = d.querySelector.bind(d);
7
- w.$$ = d.querySelectorAll.bind(d);
8
- w.loadJS = (src) => {
9
- return new Promise((r, j) => {
10
- if ($(`script[src="${src}"]`)) return r(true);
11
- const s = d.createElement('script');
12
- s.src = src;
13
- s.addEventListener('load', r);
14
- d.head.appendChild(s);
15
- });
16
- };
17
- w.loadCSS = (src) => {
18
- return new Promise((r, j) => {
19
- const s = document.createElement('link');
20
- s.rel = 'stylesheet';
21
- s.href = src;
22
- s.addEventListener('load', r);
23
- d.head.appendChild(s);
24
- });
25
- };
26
- w.wait = (ms) => new Promise((r) => setTimeout(r, ms));
27
- w.ready = async () => {
28
- return new Promise((r) => {
29
- if (document.readyState === 'complete') r(true);
30
- document.onreadystatechange = () => {
31
- if (document.readyState === 'complete') r();
32
- };
33
- });
34
- };
35
- w.child = (type, html) => {
36
- const e = d.createElement(type);
37
- e.innerHTML = html;
38
- d.body.appendChild(e);
39
- return e;
40
- };
41
-
42
- // Custom element
43
-
44
- w.element = (s, style, onMount = () => { }) => {
45
- let [name, html] = s[0].split(', ');
46
- customElements.define(
47
- name,
48
- class extends HTMLElement {
49
- connectedCallback(props) {
50
- const om = onMount;
51
- om();
52
- if (style) this.innerHTML += `<style>${name} { ${style} }</style>`;
53
- this.innerHTML += html;
54
- }
55
- }
56
- );
57
- };
58
-
59
- // Data
60
-
61
- w.state = new Proxy(
62
- {},
63
- {
64
- set: (obj, prop, value) => {
65
- for (const e of $$(`[data*=${prop}]`)) {
66
- console.log('setting e', e.tagName, e.id, value);
67
- if (!e.set) {
68
- e.set = new Function(
69
- 'o',
70
- 'return this.innerHTML = `' +
71
- e.innerHTML.replaceAll('{', '${o.') +
72
- '`'
73
- );
74
- console.log(e, 'defaulting set', e.set);
75
- }
76
- console.log(value);
77
- e.set(value);
78
- }
79
- obj[prop] = value;
80
- return value;
81
- },
82
- get: (obj, prop, receiver) => {
83
- if (prop == '_state') return obj;
84
- return obj[prop];
85
- },
86
- }
87
- );
88
-
89
- w.dataEvent = (x) => console.log(`dataevent: ${x}`);
90
-
91
- w.fetchJSON = async (url, key) => {
92
- const j = await (await fetch(url)).json();
93
- if (key) state[key] = j;
94
- dataEvent(j);
95
- return j;
96
- };
97
-
98
- w.streamJSON = async (url, key) => {
99
- const ev = new EventSource(url);
100
- ev.onmessage = (ev) => {
101
- const j = JSON.parse(ev.data);
102
- if (key) state[key] = j;
103
- dataEvent(j);
104
- return j;
105
- };
106
- };
107
-
108
- // State changes
109
-
110
- w.trackStateChanges = () =>
111
- (w.dataEvent = (o) =>
112
- localStorage.set(new Date().toISOString(), JSON.stringify(o)));
113
- w.untrackStateChanges = () =>
114
- (w.dataEvent = (o) => console.log('dataevent:', o));
115
-
116
- // Startup
117
-
118
- w.start = async () => {
119
- await w.ready();
120
- [...$$('div')].map((e) => {
121
- if (!e.id)
122
- e.id = (Math.random() + 1).toString(36).substring(7).toUpperCase();
123
- e.pr = {};
124
- [...e.attributes].map((a) => (e.pr[a.name] = a.value));
125
- if (!e.fetch && e.pr.fetch)
126
- e.fetch = fetchJSON.bind(null, e.pr.fetch, e.id);
127
- if ('immediate' in e.pr) e.fetch();
128
- if (!e.stream && e.pr.stream)
129
- e.stream = streamJSON.bind(null, e.pr.stream, e.id);
130
- if (e.pr.data) {
131
- if (this.innerHTML.contains('{')) {
132
- this.template = this.innerHTML.replaceAll('{', '${');
133
- this.innerHTML = '';
134
- }
135
- this.set = (o) => {
136
- if (!Array.isArray(o)) o = [o];
137
- const m = new Function('o', 'return `' + this.template + '`');
138
- o.map((i) => (this.innerHTML += m(o)));
139
- };
140
- }
141
- });
142
- d.body.child = (html, parent = document.body) => {
143
- const ch = document.createElement('div');
144
- ch.id = 'testchild';
145
- ch.html = html;
146
- parent.appendChild(ch);
147
- return ch;
148
- };
149
- };
150
-
151
- w.enigmatic = { version: '2022-03-01T17:12:33.046Z' };
152
- Object.assign(window, w);
153
-
154
- (async() => {
155
- await w.start()
156
- if(w.main) w.main()
1
+ const w = {}, d = document;
2
+
3
+ // helpers
4
+
5
+ w.$ = d.querySelector.bind(d);
6
+ w.$$ = d.querySelectorAll.bind(d);
7
+ w.loadJS = (src) => {
8
+ return new Promise((r, j) => {
9
+ if ($(`script[src="${src}"]`)) return r(true);
10
+ const s = d.createElement('script');
11
+ s.src = src;
12
+ s.addEventListener('load', r);
13
+ d.head.appendChild(s);
14
+ });
15
+ };
16
+ w.loadCSS = (src) => {
17
+ return new Promise((r, j) => {
18
+ const s = document.createElement('link');
19
+ s.rel = 'stylesheet';
20
+ s.href = src;
21
+ s.addEventListener('load', r);
22
+ d.head.appendChild(s);
23
+ });
24
+ };
25
+ w.wait = (ms) => new Promise((r) => setTimeout(r, ms));
26
+ w.ready = async () => {
27
+ return new Promise((r) => {
28
+ if (document.readyState === 'complete') r(true);
29
+ document.onreadystatechange = () => {
30
+ if (document.readyState === 'complete') r();
31
+ };
32
+ });
33
+ };
34
+ w.child = (type = 'div', html = '') => {
35
+ const e = d.createElement(type);
36
+ e.innerHTML = html;
37
+ d.body.appendChild(e);
38
+ return e;
39
+ };
40
+
41
+ // Custom element
42
+
43
+ w.element = (name, {onMount = x=>x, beforeData = x=>x, style, template = ''}) => {
44
+ customElements.define(name, class extends HTMLElement {
45
+ async connectedCallback(props) {
46
+ await onMount()
47
+ if (style) {
48
+ const s = document.createElement('style')
49
+ s.innerHTML = `${name} {${style}}`
50
+ d.body.appendChild(s);
51
+ }
52
+ this.template = template;
53
+ if(!this.template.match('{'))
54
+ this.innerHTML = this.template
55
+ }
56
+ set(o) {
57
+ this.innerHTML = ''
58
+ o = beforeData(o)
59
+ if(!Array.isArray(o)) o = [o];
60
+ const m = new Function('o', 'return `' + this.template + '`');
61
+ o.map((i) => (this.innerHTML += m(o)));
62
+ }
63
+ })
64
+ }
65
+
66
+ if (window.components) {
67
+ for (let name in window.components)
68
+ w.element(name, window.components[name])
69
+ }
70
+
71
+ // Data
72
+
73
+ w.state = new Proxy(
74
+ {}, {
75
+ set: (obj, prop, value) => {
76
+ let ret = []
77
+ for (const e of $$(`[data*=${prop}]`)) {
78
+ console.log(['setting e', e.tagName, e.id, value])
79
+ e.set(value);
80
+ }
81
+ obj[prop] = value;
82
+ },
83
+ get: (obj, prop, receiver) => {
84
+ if (prop == '_state') return obj;
85
+ return obj[prop];
86
+ },
87
+ }
88
+ )
89
+
90
+ w.dataEvent = (x) => console.log(`dataevent: ${x}`);
91
+
92
+ w.fetchJSON = async (url, key) => {
93
+ const j = await (await fetch(url)).json();
94
+ if (key) state[key] = j;
95
+ dataEvent(j);
96
+ return j;
97
+ };
98
+
99
+ w.streamJSON = async (url, key) => {
100
+ const ev = new EventSource(url);
101
+ ev.onmessage = (ev) => {
102
+ const j = JSON.parse(ev.data);
103
+ if (key) state[key] = j;
104
+ dataEvent(j);
105
+ return j;
106
+ };
107
+ };
108
+
109
+ // State changes
110
+
111
+ w.trackStateChanges = () =>
112
+ (w.dataEvent = (o) =>
113
+ localStorage.set(new Date().toISOString(), JSON.stringify(o)));
114
+ w.untrackStateChanges = () =>
115
+ (w.dataEvent = (o) => console.log('dataevent:', o));
116
+
117
+ // Startup
118
+
119
+ w.start = async () => {
120
+ await w.ready();
121
+ [...$$('div')].map((e) => {
122
+ if (!e.id)
123
+ e.id = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 3)
124
+ e.pr = {};
125
+ [...e.attributes].map((a) => (e.pr[a.name] = a.value));
126
+ if (e.pr.fetch) e.fetch = fetchJSON.bind(null, e.pr.fetch, e.id);
127
+ if ('immediate' in e.pr) e.fetch();
128
+ if (e.pr.stream) e.stream = streamJSON.bind(null, e.pr.stream, e.id);
129
+ if (e.pr.data) {
130
+ if (e.innerHTML && e.innerHTML.includes('{')) {
131
+ e.template = e.innerHTML.replaceAll('{', '${');
132
+ e.innerHTML = '';
133
+ }
134
+ e.set = (o) => {
135
+ e.innerHTML = ''
136
+ if (!Array.isArray(o)) o = [o];
137
+ const m = new Function('o', 'return `' + e.template + '`');
138
+ o.map((i) => (e.innerHTML += m(i)));
139
+ };
140
+ }
141
+ })
142
+ }
143
+
144
+ w.enigmatic = { version: '2022-03-05 0.10.2' };
145
+ Object.assign(window, w);
146
+
147
+ (async() => {
148
+ await w.start()
149
+ if(window.main) window.main()
157
150
  })();
package/index.html ADDED
@@ -0,0 +1,10 @@
1
+ <script src='components.js'></script>
2
+ <script src='enigmatic.js'></script>
3
+
4
+ <div data='key'>This is data: {o.a}</div>
5
+ <hello-world></hello-world>
6
+ <tailwind-example></tailwind-example>
7
+
8
+ <script>
9
+ main = x => state.key = [{a: 'one'}, { a: 'two' }]
10
+ </script>
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
- {
2
- "name": "enigmatic",
3
- "main": "enigmatic.js",
4
- "version": "0.10.0"
1
+ {
2
+ "name": "enigmatic",
3
+ "main": "enigmatic.js",
4
+ "version": "0.10.3"
5
5
  }