enigmatic 0.9.13 → 0.9.17
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.
- package/.vscode/launch.json +15 -0
- package/elements/alert-box/alert-box.js +19 -0
- package/elements/alert-box/index.html +6 -0
- package/elements/block-maker/block-maker.js +15 -0
- package/elements/block-maker/index.html +7 -0
- package/elements/chart-progress-bar/chart-progress-bar.js +9 -0
- package/elements/chart-progress-bar/index.html +5 -0
- package/elements/chart-radial-progress/chart-radial-progress.css +39 -0
- package/elements/chart-radial-progress/chart-radial-progress.js +13 -0
- package/elements/chart-radial-progress/index.html +13 -0
- package/elements/chart-statistic/chart-statistic.js +34 -0
- package/elements/chart-statistic/index.html +13 -0
- package/elements/data-grid/data-grid.js +39 -0
- package/elements/data-grid/index.html +13 -0
- package/elements/data-source/data-source.js +36 -0
- package/elements/data-source/index.html +10 -0
- package/elements/data-stream/data-stream.js +28 -0
- package/elements/data-stream/index.html +7 -0
- package/elements/font-awesome/font-awesome.js +11 -0
- package/elements/font-awesome/index.html +7 -0
- package/elements/for-list/for-list.js +25 -0
- package/elements/for-list/index.html +11 -0
- package/elements/hello-world/hello-world.js +16 -0
- package/elements/hello-world/index.html +3 -0
- package/elements/index.mjs +20 -0
- package/elements/map-embed/index.html +4 -0
- package/elements/map-embed/map-embed.js +9 -0
- package/elements/monaco-editor/index.html +11 -0
- package/elements/monaco-editor/monaco-editor.mjs +33 -0
- package/elements/online-indicator/index.html +15 -0
- package/elements/online-indicator/online-indicator.js +20 -0
- package/elements/side-menu/index.html +10 -0
- package/elements/side-menu/side-menu.js +16 -0
- package/elements/tailwind-css/index.html +11 -0
- package/elements/tailwind-css/tailwind-css.js +11 -0
- package/elements/test-runner/index.html +176 -0
- package/elements/test-runner/test-runner.js +59 -0
- package/elements/time-ago/index.html +11 -0
- package/elements/time-ago/time-ago.js +22 -0
- package/elements/toggle-switch/index.html +8 -0
- package/elements/toggle-switch/toggle-switch.js +86 -0
- package/elements/view-panel/index.html +18 -0
- package/elements/view-panel/view-panel.js +22 -0
- package/elements/you-tube/index.html +7 -0
- package/elements/you-tube/you-tube.js +9 -0
- package/{index.css → enigmatic.css} +110 -241
- package/{index.js → enigmatic.js} +29 -40
- package/index.html +17 -0
- package/package.json +3 -3
- package/readme.md +99 -0
- package/sw.js +0 -22
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
<script src='index.js'></script>
|
|
2
|
+
<script type='module' src='elements/index.mjs'></script>
|
|
3
|
+
<link rel='stylesheet' href='index.css'>
|
|
4
|
+
|
|
5
|
+
<body style='display: grid; place-items: center;'>
|
|
6
|
+
<test-runner></test-runner>
|
|
7
|
+
</body>
|
|
8
|
+
|
|
9
|
+
<script>
|
|
10
|
+
main = async () => {
|
|
11
|
+
const runner = $('test-runner')
|
|
12
|
+
const display = $('tr-display')
|
|
13
|
+
runner.createTests({
|
|
14
|
+
// dom
|
|
15
|
+
'Window exists': () => typeof window !== 'undefined',
|
|
16
|
+
'Document exists': () => typeof document !== 'undefined',
|
|
17
|
+
'Body exists': () => typeof document.body !== 'undefined',
|
|
18
|
+
// core js
|
|
19
|
+
'fetch exists': () => { return fetch },
|
|
20
|
+
'localStorage exists': () => { return localStorage },
|
|
21
|
+
// enigmatic core
|
|
22
|
+
'$ selector': () => { return $.name == 'bound querySelector' },
|
|
23
|
+
'$$ selector': () => { return $$.name == 'bound querySelectorAll' },
|
|
24
|
+
'window.loadJS': () => { return window.loadJS },
|
|
25
|
+
'window.loadCSS': () => { return window.loadCSS },
|
|
26
|
+
'window.data': () => { return window.data },
|
|
27
|
+
'window.data object': () => { return window.data._ },
|
|
28
|
+
'window.data set': () => { return window.data.set },
|
|
29
|
+
'window.wait': async () => {
|
|
30
|
+
return new Promise(async (r, j) => {
|
|
31
|
+
const time = +new Date()
|
|
32
|
+
await wait(100)
|
|
33
|
+
const timetaken = +new Date() - time
|
|
34
|
+
timetaken > 99 ? r(timetaken) : j(`Wait took ${timetaken}ms`)
|
|
35
|
+
})
|
|
36
|
+
},
|
|
37
|
+
'window.ready': () => { return window.ready },
|
|
38
|
+
// EE
|
|
39
|
+
'EnigmaticElement': () => { return EnigmaticElement },
|
|
40
|
+
'EnigmaticElement create': async () => {
|
|
41
|
+
return new Promise(async (r, j) => {
|
|
42
|
+
const e = $('#trdisplay').child('e-e')
|
|
43
|
+
e.id = 'testelement'
|
|
44
|
+
e.innerHTML = '<h1>Hello e-e element</h1>'
|
|
45
|
+
e.hide()
|
|
46
|
+
e.show()
|
|
47
|
+
e.setAttribute('data', 'mykey')
|
|
48
|
+
r(e)
|
|
49
|
+
})
|
|
50
|
+
},
|
|
51
|
+
'EE-childHTML': () => {
|
|
52
|
+
const e = $('#trdisplay').childHTML('<span>Im a test</span>')
|
|
53
|
+
const ret = (e.innerHTML === '<span>Im a test</span>')
|
|
54
|
+
e.remove()
|
|
55
|
+
return ret
|
|
56
|
+
},
|
|
57
|
+
// Data
|
|
58
|
+
'window.data set': () => { return window.data.set },
|
|
59
|
+
'window.data.set(val)': () => { return window.data.set('mykey', 'myval') },
|
|
60
|
+
'Element data subscribe': () => { return $('#testelement').innerHTML === 'myval' },
|
|
61
|
+
// Custom elements
|
|
62
|
+
'Hello World element': async () => {
|
|
63
|
+
$('#testelement').remove()
|
|
64
|
+
return new Promise(async (r, j) => {
|
|
65
|
+
const hw = $('#trdisplay').child('hello-world')
|
|
66
|
+
await wait(500)
|
|
67
|
+
$('hello-world').hide()
|
|
68
|
+
await wait(500)
|
|
69
|
+
$('hello-world').show()
|
|
70
|
+
await wait(500)
|
|
71
|
+
$('hello-world').hide()
|
|
72
|
+
$('hello-world').remove()
|
|
73
|
+
r(true)
|
|
74
|
+
})
|
|
75
|
+
},
|
|
76
|
+
'you-tube': async () => {
|
|
77
|
+
const r = $('#trdisplay').child('you-tube')
|
|
78
|
+
await wait(1500)
|
|
79
|
+
r.hide()
|
|
80
|
+
r.remove()
|
|
81
|
+
return r
|
|
82
|
+
},
|
|
83
|
+
'monaco-editor': async () => {
|
|
84
|
+
const r = $('#trdisplay').child('monaco-editor')
|
|
85
|
+
r.set('javascript', 'console.log(1)')
|
|
86
|
+
await wait(500)
|
|
87
|
+
await r.hide()
|
|
88
|
+
r.remove()
|
|
89
|
+
return r
|
|
90
|
+
},
|
|
91
|
+
'online-indicator': async () => {
|
|
92
|
+
const r = $('#trdisplay').child('online-indicator')
|
|
93
|
+
await wait(500)
|
|
94
|
+
if (navigator.onLine && r.innerHTML !== '🟢')
|
|
95
|
+
throw Error('online-indicator not online')
|
|
96
|
+
runner.set('Disconnect your network connection to continue')
|
|
97
|
+
//await r.wentOffline()
|
|
98
|
+
if (!navigator.onLine && r.innerHTML !== '🔴')
|
|
99
|
+
throw Error('online-indicator not offline')
|
|
100
|
+
runner.set('Connect your network connection to continue')
|
|
101
|
+
//await r.wentOnline()
|
|
102
|
+
await r.hide()
|
|
103
|
+
r.remove()
|
|
104
|
+
return true
|
|
105
|
+
},
|
|
106
|
+
'font-awesome': async () => {
|
|
107
|
+
const r = $('#trdisplay').child('font-awesome')
|
|
108
|
+
r.set('fas fa-heart')
|
|
109
|
+
await wait(500)
|
|
110
|
+
r.set('fas fa-check')
|
|
111
|
+
await wait(1000)
|
|
112
|
+
const ret = getComputedStyle($('font-awesome')).fontFamily.match(/Font/i)
|
|
113
|
+
r.remove()
|
|
114
|
+
return ret
|
|
115
|
+
},
|
|
116
|
+
'view-panel': async () => {
|
|
117
|
+
const display = $('#trdisplay')
|
|
118
|
+
const vp = display.child('view-panel')
|
|
119
|
+
vp.classList.add('show')
|
|
120
|
+
vp.style.display = 'grid'
|
|
121
|
+
vp.style.gridTemplate = '1fr / 1fr'
|
|
122
|
+
const x = vp.child('e-e', 'one')
|
|
123
|
+
x.style.backgroundColor = 'red'
|
|
124
|
+
x.innerHTML = '!'
|
|
125
|
+
const xx = vp.child('div', 'two')
|
|
126
|
+
xx.style.backgroundColor = 'green'
|
|
127
|
+
xx.innerHTML = '!'
|
|
128
|
+
const xxx = vp.child('div', 'three')
|
|
129
|
+
xxx.style.backgroundColor = 'blue'
|
|
130
|
+
xxx.innerHTML = '!'
|
|
131
|
+
const b = display.child('button', 'four')
|
|
132
|
+
b.textContent = 'Show only one'
|
|
133
|
+
b.onclick = () => {
|
|
134
|
+
vp.showOnly('#one')
|
|
135
|
+
}
|
|
136
|
+
const c = display.child('button', 'five')
|
|
137
|
+
c.textContent = 'Show all'
|
|
138
|
+
c.onclick = () => {
|
|
139
|
+
vp.showAll()
|
|
140
|
+
$('#one').hide()
|
|
141
|
+
}
|
|
142
|
+
await wait(500)
|
|
143
|
+
b.click()
|
|
144
|
+
await wait(500)
|
|
145
|
+
c.click()
|
|
146
|
+
await wait(500)
|
|
147
|
+
b.remove()
|
|
148
|
+
c.remove()
|
|
149
|
+
vp.remove()
|
|
150
|
+
return true
|
|
151
|
+
},
|
|
152
|
+
'side-menu': async () => {
|
|
153
|
+
$('#trdisplay').childHTML(`
|
|
154
|
+
<button id='opener' onclick="$('#me').toggle()" style='position: absolute; left: 400px'>Open</button>
|
|
155
|
+
<side-menu id='me' toggle-classes='slide-in slide-out'>
|
|
156
|
+
<li class=''>
|
|
157
|
+
<font-awesome class='fa fa-check'></font-awesome> one
|
|
158
|
+
</li>
|
|
159
|
+
<li class=''>
|
|
160
|
+
<font-awesome class='fa fa-check'></font-awesome> one
|
|
161
|
+
</li>
|
|
162
|
+
<li class=''>
|
|
163
|
+
<font-awesome class='fa fa-check'></font-awesome> one
|
|
164
|
+
</li>
|
|
165
|
+
<li class=''>
|
|
166
|
+
<font-awesome class='fa fa-check'></font-awesome> one
|
|
167
|
+
</li>
|
|
168
|
+
<li class=''>
|
|
169
|
+
<font-awesome class='fa fa-check'></font-awesome> one
|
|
170
|
+
</li>
|
|
171
|
+
</side-menu>`)
|
|
172
|
+
return true
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
</script>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
class TestRunner extends EnigmaticElement {
|
|
2
|
+
|
|
3
|
+
tests = {}
|
|
4
|
+
|
|
5
|
+
connectedCallback() {
|
|
6
|
+
window.testrunner = this
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
createTests(tests) {
|
|
10
|
+
this.tests = tests
|
|
11
|
+
this.innerHTML = `
|
|
12
|
+
<div style="display:grid; grid-template: 4fr 1fr / 4fr 1fr">
|
|
13
|
+
<e-e id='trdisplay'></e-e>
|
|
14
|
+
<div></div>
|
|
15
|
+
<div>
|
|
16
|
+
<span id='trstatus'>${this.count()} tests loaded</span>
|
|
17
|
+
<button style='margin-top: 5px; float: right' onclick='testrunner.run()'>Run</button>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
count() {
|
|
24
|
+
return Object.keys(this.tests).length
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async run() {
|
|
28
|
+
console.clear()
|
|
29
|
+
let pass = true, ret = [], time = +new Date(), func
|
|
30
|
+
for (const test in this.tests) {
|
|
31
|
+
let success, message
|
|
32
|
+
$('#trstatus').innerHTML = `<i>${test}</i>`
|
|
33
|
+
try {
|
|
34
|
+
func = this.tests[test]
|
|
35
|
+
const isAsyncTest = (func.constructor.name === 'AsyncFunction')
|
|
36
|
+
success = isAsyncTest ? await func() : func()
|
|
37
|
+
} catch (e) {
|
|
38
|
+
success = false
|
|
39
|
+
message = e
|
|
40
|
+
console.error(e)
|
|
41
|
+
}
|
|
42
|
+
if (!success) {
|
|
43
|
+
this.innerHTML = `Failed on test: ${test} ${message}`
|
|
44
|
+
pass = false
|
|
45
|
+
}
|
|
46
|
+
ret = [...ret, { test, func, success }]
|
|
47
|
+
}
|
|
48
|
+
const status = $('#trstatus'), count = this.count()
|
|
49
|
+
status.innerHTML = `${pass ? '<green>Passed</green>' : '<red>Failed</red>'}`
|
|
50
|
+
status.innerHTML += ` ${count} tests in ${+new Date() - time}ms`
|
|
51
|
+
console[!!console.table ? 'table' : 'log'](ret)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
set(s) {
|
|
55
|
+
$('#trstatus').innerHTML = s
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
customElements.define('test-runner', TestRunner)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
class TimeAgo extends EnigmaticElement {
|
|
3
|
+
set(v) {
|
|
4
|
+
const d = new Date(v)
|
|
5
|
+
const now = new Date()
|
|
6
|
+
const diff = (now - d) / 1000
|
|
7
|
+
const day_diff = Math.floor(diff / 86400)
|
|
8
|
+
this.textContent =
|
|
9
|
+
diff < 60 && 'just now' ||
|
|
10
|
+
diff < 120 && '1 minute ago' ||
|
|
11
|
+
diff < 3600 && Math.floor( diff / 60 ) + ' minutes ago' ||
|
|
12
|
+
diff < 7200 && '1 hour ago' ||
|
|
13
|
+
diff < 86400 && Math.floor( diff / 3600 ) + ' hours ago' ||
|
|
14
|
+
day_diff == 1 && 'Yesterday' ||
|
|
15
|
+
day_diff < 7 && day_diff + ' days ago' ||
|
|
16
|
+
day_diff < 31 && Math.ceil( day_diff / 7 ) + ' weeks ago' ||
|
|
17
|
+
day_diff < 365 && Math.ceil(day_diff / 30) + ' months ago' ||
|
|
18
|
+
Math.ceil(day_diff / 365) + ' years ago'
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
customElements.define('time-ago', TimeAgo)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<script src='https://unpkg.com/enigmatic'></script>
|
|
2
|
+
<script src='toggle-switch.js'></script>
|
|
3
|
+
|
|
4
|
+
<toggle-switch id='ts'></toggle-switch>
|
|
5
|
+
<button onclick='ts.toggle()'>Toggle</button>
|
|
6
|
+
<button onclick='ts.toggle(true)'>On</button>
|
|
7
|
+
<button onclick='ts.toggle(false)'>Off</button>
|
|
8
|
+
<button onclick='ts.set("")'>Set</button>
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
|
|
2
|
+
class ToggleSwitch extends EnigmaticElement {
|
|
3
|
+
|
|
4
|
+
async connectedCallback() {
|
|
5
|
+
this.innerHTML = `
|
|
6
|
+
<style>
|
|
7
|
+
.switch {
|
|
8
|
+
position: relative;
|
|
9
|
+
display: inline-block;
|
|
10
|
+
width: 60px;
|
|
11
|
+
height: 34px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.switch input {
|
|
15
|
+
opacity: 0;
|
|
16
|
+
width: 0;
|
|
17
|
+
height: 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.slider {
|
|
21
|
+
position: absolute;
|
|
22
|
+
cursor: pointer;
|
|
23
|
+
top: 0;
|
|
24
|
+
left: 0;
|
|
25
|
+
right: 0;
|
|
26
|
+
bottom: 0;
|
|
27
|
+
background-color: #ccc;
|
|
28
|
+
-webkit-transition: .4s;
|
|
29
|
+
transition: .4s;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.slider:before {
|
|
33
|
+
position: absolute;
|
|
34
|
+
content: "";
|
|
35
|
+
height: 26px;
|
|
36
|
+
width: 26px;
|
|
37
|
+
left: 4px;
|
|
38
|
+
bottom: 4px;
|
|
39
|
+
background-color: white;
|
|
40
|
+
-webkit-transition: .4s;
|
|
41
|
+
transition: .4s;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
input:checked + .slider {
|
|
45
|
+
background-color: #2196F3;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
input:focus + .slider {
|
|
49
|
+
box-shadow: 0 0 1px #2196F3;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
input:checked + .slider:before {
|
|
53
|
+
-webkit-transform: translateX(26px);
|
|
54
|
+
-ms-transform: translateX(26px);
|
|
55
|
+
transform: translateX(26px);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* Rounded sliders */
|
|
59
|
+
.slider.round {
|
|
60
|
+
border-radius: 34px;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.slider.round:before {
|
|
64
|
+
border-radius: 50%;
|
|
65
|
+
}
|
|
66
|
+
</style>
|
|
67
|
+
|
|
68
|
+
<label class="switch">
|
|
69
|
+
<input type="checkbox" checked>
|
|
70
|
+
<span class="slider round"></span>
|
|
71
|
+
</label>
|
|
72
|
+
`
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
toggle(onoff) {
|
|
76
|
+
if (onoff !== undefined)
|
|
77
|
+
return this.querySelector('input').checked = onoff
|
|
78
|
+
this.querySelector('input').checked = !this.querySelector('input').checked;
|
|
79
|
+
}
|
|
80
|
+
set(v) {
|
|
81
|
+
const tf = !!v
|
|
82
|
+
this.querySelector('input').checked = tf
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
customElements.define('toggle-switch', ToggleSwitch)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<script src='//unpkg.com/enigmatic'></script>
|
|
2
|
+
<script src='view-panel.js'></script>
|
|
3
|
+
<link rel='stylesheet' href='//unpkg.com/enigmatic/index.css'>
|
|
4
|
+
|
|
5
|
+
<body>
|
|
6
|
+
<view-panel id='mypanel' agent='chromex'>
|
|
7
|
+
Hidden, not a valid agent
|
|
8
|
+
</view-panel>
|
|
9
|
+
|
|
10
|
+
<view-panel id='mypanel2'>
|
|
11
|
+
<div>One</div>
|
|
12
|
+
<div id='two'>Two</div>
|
|
13
|
+
<div>Three</div>
|
|
14
|
+
</view-panel>
|
|
15
|
+
<button onclick='mypanel2.hide()'>Hide</button>
|
|
16
|
+
<button onclick='mypanel2.show()'>Show</button>
|
|
17
|
+
<button onclick='mypanel2.showOnly("#two")'>Show only Two</button>
|
|
18
|
+
</body>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
class ViewPanel extends EnigmaticElement {
|
|
2
|
+
constructor() {
|
|
3
|
+
super()
|
|
4
|
+
}
|
|
5
|
+
connectedCallback() {
|
|
6
|
+
const browser = navigator.userAgent.toLowerCase()
|
|
7
|
+
const agent = this.attributes['agent']?.value
|
|
8
|
+
if (agent && !browser.match(agent))
|
|
9
|
+
this.remove()
|
|
10
|
+
}
|
|
11
|
+
showOnly(qs) {
|
|
12
|
+
for (const child of this.children) {
|
|
13
|
+
if (child instanceof EnigmaticElement) {
|
|
14
|
+
child[child.matches(qs) ? 'show' : 'hide']()
|
|
15
|
+
} else {
|
|
16
|
+
child.classList.add(child.matches(qs) ? 'show' : 'hide')
|
|
17
|
+
child.classList.remove(child.matches(qs) ? 'hide' : 'show')
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
customElements.define('view-panel', ViewPanel)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
class YouTube extends EnigmaticElement {
|
|
2
|
+
connectedCallback() {
|
|
3
|
+
this.uid = this.getAttribute('uid') || 'Fku7hi5kI-c'
|
|
4
|
+
this.innerHTML = `<iframe width="560" height="315" src="https://www.youtube.com/embed/${this.uid}"
|
|
5
|
+
title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write;
|
|
6
|
+
encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>`
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
customElements.define('you-tube', YouTube)
|