enigmatic 0.9.20 → 0.10.2
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/components.mjs +17 -0
- package/enigmatic.css +246 -314
- package/enigmatic.js +143 -120
- package/index.html +1 -8
- package/package.json +4 -11
- package/.vscode/launch.json +0 -15
- package/elements/alert-box/alert-box.js +0 -19
- package/elements/alert-box/index.html +0 -6
- package/elements/block-maker/block-maker.js +0 -15
- package/elements/block-maker/index.html +0 -7
- package/elements/chart-progress-bar/chart-progress-bar.js +0 -9
- package/elements/chart-progress-bar/index.html +0 -5
- package/elements/chart-radial-progress/chart-radial-progress.css +0 -39
- package/elements/chart-radial-progress/chart-radial-progress.js +0 -13
- package/elements/chart-radial-progress/index.html +0 -13
- package/elements/chart-statistic/chart-statistic.js +0 -34
- package/elements/chart-statistic/index.html +0 -13
- package/elements/data-grid/data-grid.js +0 -39
- package/elements/data-grid/index.html +0 -13
- package/elements/data-source/data-source.js +0 -36
- package/elements/data-source/index.html +0 -10
- package/elements/data-stream/data-stream.js +0 -28
- package/elements/data-stream/index.html +0 -7
- package/elements/font-awesome/font-awesome.js +0 -11
- package/elements/font-awesome/index.html +0 -7
- package/elements/for-list/for-list.js +0 -25
- package/elements/for-list/index.html +0 -11
- package/elements/hello-world/hello-world.js +0 -16
- package/elements/hello-world/index.html +0 -3
- package/elements/index.mjs +0 -20
- package/elements/map-embed/index.html +0 -4
- package/elements/map-embed/map-embed.js +0 -9
- package/elements/monaco-editor/index.html +0 -11
- package/elements/monaco-editor/monaco-editor.mjs +0 -33
- package/elements/online-indicator/index.html +0 -15
- package/elements/online-indicator/online-indicator.js +0 -20
- package/elements/side-menu/index.html +0 -10
- package/elements/side-menu/side-menu.js +0 -16
- package/elements/tailwind-css/index.html +0 -11
- package/elements/tailwind-css/tailwind-css.js +0 -11
- package/elements/test-runner/index.html +0 -176
- package/elements/test-runner/test-runner.js +0 -59
- package/elements/time-ago/index.html +0 -11
- package/elements/time-ago/time-ago.js +0 -22
- package/elements/toggle-switch/index.html +0 -8
- package/elements/toggle-switch/toggle-switch.js +0 -86
- package/elements/view-panel/index.html +0 -18
- package/elements/view-panel/view-panel.js +0 -22
- package/elements/you-tube/index.html +0 -7
- package/elements/you-tube/you-tube.js +0 -9
- package/readme.md +0 -93
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
<script src='https://unpkg.com/enigmatic'></script>
|
|
2
|
-
<script src='font-awesome.js'></script>
|
|
3
|
-
<link rel='stylesheet' href='https://unpkg.com/enigmatic/index.css'>
|
|
4
|
-
|
|
5
|
-
<font-awesome class='fifty' id='i' icon='fa fa-camera'></font-awesome>
|
|
6
|
-
|
|
7
|
-
<button onclick='i.set("fa fa-comments")'>Fetch</button>
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
class ForList extends EnigmaticElement {
|
|
2
|
-
innerTemplate = ''
|
|
3
|
-
constructor(parent, tag, attrs) {
|
|
4
|
-
super()
|
|
5
|
-
}
|
|
6
|
-
set(array) {
|
|
7
|
-
if(!this.innerTemplate)
|
|
8
|
-
this.innerTemplate = this.innerHTML
|
|
9
|
-
this.innerHTML = ''
|
|
10
|
-
for (const rec of array) {
|
|
11
|
-
let addhtml = this.innerTemplate
|
|
12
|
-
for(const m of addhtml.match(/\{\{(.*?)\}\}/g)) {
|
|
13
|
-
const dest = m.replace(/{{|}}/g,'').split('.')
|
|
14
|
-
let k, val = rec
|
|
15
|
-
while(k = dest.shift()) {
|
|
16
|
-
val = val[k]
|
|
17
|
-
}
|
|
18
|
-
addhtml = addhtml.replace(m, val)
|
|
19
|
-
}
|
|
20
|
-
this.innerHTML += addhtml
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
customElements.define("for-list", ForList)
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
<script src='https://unpkg.com/enigmatic'></script>
|
|
2
|
-
<script src='for-list.js'></script>
|
|
3
|
-
<script src='../data-source/data-source.js'></script>
|
|
4
|
-
|
|
5
|
-
<data-source href='https://randomuser.me/api/?results=5' target='users' cache></data-source>
|
|
6
|
-
|
|
7
|
-
<for-list data='users.results'>
|
|
8
|
-
<div>{{name.title}} {{name.first}} {{name.last}} {{email}}</div>
|
|
9
|
-
</for-list>
|
|
10
|
-
|
|
11
|
-
<button onclick=''>Fetch</button>
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
class HelloWorld extends EnigmaticElement {
|
|
2
|
-
connectedCallback() {
|
|
3
|
-
this.innerHTML = `
|
|
4
|
-
<style>
|
|
5
|
-
hello-world > h1 {
|
|
6
|
-
padding: 1em;
|
|
7
|
-
color: white;
|
|
8
|
-
background: linear-gradient(to left, red, yellow, green, blue, violet)
|
|
9
|
-
}
|
|
10
|
-
</style>
|
|
11
|
-
<h1>${this.getAttribute('message')||'Hello World!'}</h1>
|
|
12
|
-
`;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
customElements.define('hello-world', HelloWorld)
|
package/elements/index.mjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import './block-maker/block-maker.js'
|
|
2
|
-
import './chart-progress-bar/chart-progress-bar.js'
|
|
3
|
-
import './chart-radial-progress/chart-radial-progress.js'
|
|
4
|
-
import './chart-statistic/chart-statistic.js'
|
|
5
|
-
import './data-grid/data-grid.js'
|
|
6
|
-
import './data-source/data-source.js'
|
|
7
|
-
import './data-stream/data-stream.js'
|
|
8
|
-
import './font-awesome/font-awesome.js'
|
|
9
|
-
import './for-list/for-list.js'
|
|
10
|
-
import './hello-world/hello-world.js'
|
|
11
|
-
import './map-embed/map-embed.js'
|
|
12
|
-
//import './monaco-editor.js'
|
|
13
|
-
import './online-indicator/online-indicator.js'
|
|
14
|
-
import './side-menu/side-menu.js'
|
|
15
|
-
import './test-runner/test-runner.js'
|
|
16
|
-
import './toggle-switch/toggle-switch.js'
|
|
17
|
-
import './view-panel/view-panel.js'
|
|
18
|
-
import './you-tube/you-tube.js'
|
|
19
|
-
import './tailwind-css/tailwind-css.js'
|
|
20
|
-
import './alert-box/alert-box.js'
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
class MapEmbed extends EnigmaticElement {
|
|
2
|
-
connectedCallback() {
|
|
3
|
-
const where = this.getAttribute('where')
|
|
4
|
-
const zoom = this.getAttribute('zoom')
|
|
5
|
-
this.innerHTML = `<iframe width="600" height="500" id="gmap_canvas" src="https://maps.google.com/maps?q=${where||'Chicago'}&t=&z=${zoom||14}&ie=UTF8&iwloc=&output=embed" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe><style>.mapouter{position:relative;text-align:right;height:500px;width:600px;}</style>`
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
customElements.define("map-embed", MapEmbed)
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
<script src='//unpkg.com/enigmatic'></script>
|
|
2
|
-
<script type='module' src='monaco-editor.mjs'></script>
|
|
3
|
-
|
|
4
|
-
<monaco-editor id='me1' estyle="width: 600px; height: 400px; border: 1px solid gray"></monaco-editor>
|
|
5
|
-
<code for='me1' hidden>class HelloWorld extends HTMLElement {
|
|
6
|
-
connectedCallback() {
|
|
7
|
-
this.innerHTML = '<div>Hello World!</div>'
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
customElements.define('hello-world', HelloWorld)
|
|
11
|
-
</code>
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import * as monaco from 'https://cdn.skypack.dev/monaco-editor@0.23'
|
|
2
|
-
customElements.define('monaco-editor', class extends EnigmaticElement {
|
|
3
|
-
connectedCallback() {
|
|
4
|
-
const c = document.createElement('div')
|
|
5
|
-
c.style = this.getAttribute('estyle') || "width: 600px; height: 400px; border: 1px solid gray"
|
|
6
|
-
this.appendChild(c)
|
|
7
|
-
const id = 'me1'
|
|
8
|
-
const codewin = $(`code[for=${id}]`)?.innerHTML || ''
|
|
9
|
-
this.editor = monaco.editor.create(c, {
|
|
10
|
-
value: codewin,
|
|
11
|
-
language: 'javascript'
|
|
12
|
-
})
|
|
13
|
-
}
|
|
14
|
-
set(lang = 'javascript', code){
|
|
15
|
-
this.editor.setModel(monaco.editor.createModel(code, lang))
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
/*
|
|
20
|
-
|
|
21
|
-
example..
|
|
22
|
-
|
|
23
|
-
<monaco-editor id='me1' estyle="width: 600px; height: 400px; border: 1px solid gray"></monaco-editor>
|
|
24
|
-
<code for='me1' hidden>
|
|
25
|
-
class HelloWorld extends HTMLElement {
|
|
26
|
-
connectedCallback() {
|
|
27
|
-
this.innerHTML = '<div>Hello World!</div>'
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
customElements.define('hello-world', HelloWorld)
|
|
31
|
-
</code>
|
|
32
|
-
|
|
33
|
-
*/
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
<script src='https://unpkg.com/enigmatic'></script>
|
|
2
|
-
<script src='online-indicator.js'></script>
|
|
3
|
-
|
|
4
|
-
1 <online-indicator></online-indicator>
|
|
5
|
-
2 <online-indicator online='On' offline='Off'></online-indicator>
|
|
6
|
-
|
|
7
|
-
<script>
|
|
8
|
-
main = async () => {
|
|
9
|
-
// Promise based offline detection
|
|
10
|
-
await $('online-indicator').wentOffline()
|
|
11
|
-
console.log('went offline')
|
|
12
|
-
await $('online-indicator').wentOnline()
|
|
13
|
-
console.log('went online')
|
|
14
|
-
}
|
|
15
|
-
</script>
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
class OnlineIndicator extends EnigmaticElement {
|
|
2
|
-
connectedCallback() {
|
|
3
|
-
const o = this.getAttribute('online')
|
|
4
|
-
const f = this.getAttribute('offline')
|
|
5
|
-
this.innerHTML = window.navigator.onLine ? (o || '🟢') : (f || '🔴')
|
|
6
|
-
window.addEventListener('online', this.connectedCallback.bind(this))
|
|
7
|
-
window.addEventListener('offline', this.connectedCallback.bind(this))
|
|
8
|
-
}
|
|
9
|
-
async wentOnline() {
|
|
10
|
-
return new Promise(resolve => {
|
|
11
|
-
window.addEventListener('online', resolve)
|
|
12
|
-
})
|
|
13
|
-
}
|
|
14
|
-
async wentOffline() {
|
|
15
|
-
return new Promise(resolve => {
|
|
16
|
-
window.addEventListener('offline', resolve)
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
customElements.define('online-indicator', OnlineIndicator)
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
class SideMenu extends EnigmaticElement {
|
|
2
|
-
connectedCallback() {
|
|
3
|
-
this.innerHTML = `
|
|
4
|
-
<e-e id='sm1' style='overflow:hidden; background: radial-gradient(circle, #E5E6E4, #FFF); top: 0; height: 98%; padding: 10px; position: absolute; right: 0; width: 300px'>
|
|
5
|
-
${$('side-menu').innerHTML}
|
|
6
|
-
</e-e>
|
|
7
|
-
`
|
|
8
|
-
this.opened = false
|
|
9
|
-
this.toggleclasses = this.getAttribute('toggle-classes')?.split(' ') || ['show', 'hide']
|
|
10
|
-
this.classList.add(this.toggleclasses[1])
|
|
11
|
-
}
|
|
12
|
-
toggle() {
|
|
13
|
-
super.toggle(this.toggleclasses)
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
customElements.define('side-menu', SideMenu)
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
<script src='//unpkg.com/enigmatic'></script>
|
|
2
|
-
<script src='tailwind-css.js'></script>
|
|
3
|
-
<link rel='stylesheet' href='http://localhost:3000/index.css'>
|
|
4
|
-
|
|
5
|
-
<tailwind-css></tailwind-css>
|
|
6
|
-
|
|
7
|
-
<div class='underline red'>tailwind</div>
|
|
8
|
-
|
|
9
|
-
<div class="py-3 px-5 mb-4 bg-blue-100 text-blue-900 text-sm rounded-md border border-blue-200" role="alert">
|
|
10
|
-
A simple <strong>primary</strong> alert—check it out!
|
|
11
|
-
</div>
|
|
@@ -1,176 +0,0 @@
|
|
|
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>
|
|
@@ -1,59 +0,0 @@
|
|
|
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)
|
|
@@ -1,22 +0,0 @@
|
|
|
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)
|
|
@@ -1,8 +0,0 @@
|
|
|
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>
|
|
@@ -1,86 +0,0 @@
|
|
|
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)
|
|
@@ -1,18 +0,0 @@
|
|
|
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>
|
|
@@ -1,22 +0,0 @@
|
|
|
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)
|