enigmatic 0.9.11 → 0.9.15
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/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/enigmatic.css +315 -0
- package/enigmatic.js +132 -0
- package/package.json +3 -3
- package/readme.md +99 -0
- package/test.html +173 -37
- package/elements/hello-world.mjs +0 -6
- package/elements/monaco-editor.mjs +0 -32
- package/main.css +0 -372
- package/main.js +0 -78
- package/maker.html +0 -16
|
@@ -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)
|
package/enigmatic.css
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/* layout */
|
|
2
|
+
|
|
3
|
+
body {
|
|
4
|
+
display: grid;
|
|
5
|
+
font-family: Roboto, Helvetica, sans-serif;
|
|
6
|
+
margin: 0;
|
|
7
|
+
grid-template-columns: var(--cols, 1fr 4fr 1fr);
|
|
8
|
+
grid-template-rows: var(--rows, 1fr 9fr 1fr);
|
|
9
|
+
height: 100vh;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.span {
|
|
13
|
+
grid-column: span var(--span, 3);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.span-rows {
|
|
17
|
+
grid-row: span var(--span-rows, 3);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.flex {
|
|
21
|
+
display: flex;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** positioning **/
|
|
25
|
+
|
|
26
|
+
.center {
|
|
27
|
+
position: fixed;
|
|
28
|
+
top: 50%;
|
|
29
|
+
left: 50%;
|
|
30
|
+
margin-top: -50px;
|
|
31
|
+
margin-left: -100px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.center-h {
|
|
35
|
+
position: fixed;
|
|
36
|
+
left: 50%;
|
|
37
|
+
margin-left: -100px;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.right {
|
|
41
|
+
float: right;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.left {
|
|
45
|
+
float: left;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.fixed {
|
|
49
|
+
position: fixed;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.top {
|
|
53
|
+
top: 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.bottom {
|
|
57
|
+
bottom: 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.fill {
|
|
61
|
+
height: 100vh;
|
|
62
|
+
width: 100wh;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.roboto {
|
|
66
|
+
font-family: 'Roboto', sans-serif;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** font **/
|
|
70
|
+
|
|
71
|
+
@font-face {
|
|
72
|
+
font-family: 'Roboto';
|
|
73
|
+
font-style: normal;
|
|
74
|
+
font-weight: 400;
|
|
75
|
+
src: local('Roboto Regular'), local('Roboto-Regular'), url(//themes.googleusercontent.com/static/fonts/roboto/v10/2UX7WLTfW3W8TclTUvlFyQ.woff) format('woff');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** elements **/
|
|
79
|
+
|
|
80
|
+
.hide {
|
|
81
|
+
opacity: 0;
|
|
82
|
+
transition: opacity .25s linear;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.show {
|
|
86
|
+
opacity: 1;
|
|
87
|
+
transition: opacity .25s linear;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.slide-in {
|
|
91
|
+
animation: slide-in 0.1s forwards;
|
|
92
|
+
-webkit-animation: slide-in 0.1s forwards;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.slide-out {
|
|
96
|
+
animation: slide-out 0.1s forwards;
|
|
97
|
+
-webkit-animation: slide-out 0.1s forwards;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@keyframes slide-in {
|
|
101
|
+
100% {
|
|
102
|
+
transform: translateX(0%);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@-webkit-keyframes slide-in {
|
|
107
|
+
100% {
|
|
108
|
+
-webkit-transform: translateX(0%);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@keyframes slide-out {
|
|
113
|
+
0% {
|
|
114
|
+
transform: translateX(0%);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
100% {
|
|
118
|
+
transform: translateX(-100%);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@-webkit-keyframes slide-out {
|
|
123
|
+
0% {
|
|
124
|
+
-webkit-transform: translateX(0%);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
100% {
|
|
128
|
+
-webkit-transform: translateX(-100%);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
a {
|
|
134
|
+
text-decoration: none;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.shadow {
|
|
138
|
+
box-shadow: 6px 6px 6px #dbdbdb
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.cursor {
|
|
142
|
+
cursor: default;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.bg-blue, .hover\:bg-blue:hover {
|
|
146
|
+
background-color: #0074d9
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.bg-green {
|
|
150
|
+
background-color: #1a8d1e;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.bg-yellow {
|
|
154
|
+
background-color: #ffdc00
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.bg-orange {
|
|
158
|
+
background-color: #ff851b
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.bg-red {
|
|
162
|
+
background-color: #ff4136
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.bg-white {
|
|
166
|
+
background-color: #fff
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.bg-gray {
|
|
170
|
+
background-color: #aaa
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.bg-black {
|
|
174
|
+
background-color: #111
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.blue {
|
|
178
|
+
color: #0074d9
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.green {
|
|
182
|
+
color: #1a8d1e;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.yellow {
|
|
186
|
+
color: #ffdc00
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.orange {
|
|
190
|
+
color: #ff851b
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.red {
|
|
194
|
+
color: #ff4136
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.white {
|
|
198
|
+
color: #fff;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.gray {
|
|
202
|
+
color: #aaa
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.black {
|
|
206
|
+
color: #111
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.margins {
|
|
210
|
+
margin: var(--margins, 15px)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.padding {
|
|
214
|
+
padding: var(--padding, 15px)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.rem {
|
|
218
|
+
font-size: var(--rem, 2rem);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.faded {
|
|
222
|
+
opacity: 0.5;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.fade {
|
|
226
|
+
opacity: 1;
|
|
227
|
+
transition: opacity .25s ease-in-out;
|
|
228
|
+
-moz-transition: opacity .25s ease-in-out;
|
|
229
|
+
-webkit-transition: opacity .25s ease-in-out;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.fade:hover {
|
|
233
|
+
opacity: 0.5
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.unfade {
|
|
237
|
+
opacity: 0.5;
|
|
238
|
+
transition: opacity .25s ease-in-out;
|
|
239
|
+
-moz-transition: opacity .25s ease-in-out;
|
|
240
|
+
-webkit-transition: opacity .25s ease-in-out;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.unfade:hover {
|
|
244
|
+
opacity: 1
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.rounded {
|
|
248
|
+
-moz-border-radius: 10px;
|
|
249
|
+
-webkit-border-radius: 10px;
|
|
250
|
+
border-radius: 10px;
|
|
251
|
+
-khtml-border-radius: 10px;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.round {
|
|
255
|
+
vertical-align: middle;
|
|
256
|
+
width: 50px;
|
|
257
|
+
height: 50px;
|
|
258
|
+
border-radius: 50%;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** html elements **/
|
|
262
|
+
|
|
263
|
+
button {
|
|
264
|
+
border-radius: 0.5rem;
|
|
265
|
+
background-color: #787978;
|
|
266
|
+
/* Green */
|
|
267
|
+
border: none;
|
|
268
|
+
color: white;
|
|
269
|
+
padding: 15px 32px;
|
|
270
|
+
text-align: center;
|
|
271
|
+
text-decoration: none;
|
|
272
|
+
display: inline-block;
|
|
273
|
+
opacity: .85;
|
|
274
|
+
transition: opacity .25s ease-in-out;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
button:hover {
|
|
278
|
+
opacity: 1;
|
|
279
|
+
transition: opacity .25s ease-in-out;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
ul {
|
|
283
|
+
list-style-type: none;
|
|
284
|
+
border: 20px;
|
|
285
|
+
padding: 20px;
|
|
286
|
+
width: 50%;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
li {
|
|
290
|
+
list-style-type: none;
|
|
291
|
+
border: 10px;
|
|
292
|
+
padding: 10px;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
li:hover {
|
|
296
|
+
background-color: rgb(243, 241, 241);
|
|
297
|
+
cursor: pointer;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** Opacity **/
|
|
301
|
+
.opacity-100 {
|
|
302
|
+
opacity: 1;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
.opacity-25 {
|
|
306
|
+
opacity: .25;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
.opacity-50 {
|
|
310
|
+
opacity: .5;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
.opacity-75 {
|
|
314
|
+
opacity: .75;
|
|
315
|
+
}
|
package/enigmatic.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// e-e
|
|
2
|
+
window.$ = document.querySelector.bind(document)
|
|
3
|
+
window.$$ = document.querySelectorAll.bind(document)
|
|
4
|
+
window.body = document.body
|
|
5
|
+
|
|
6
|
+
window.loadJS = src => {
|
|
7
|
+
return new Promise((r, j) => {
|
|
8
|
+
if ($(`script[src="${src}"]`))
|
|
9
|
+
return r(true)
|
|
10
|
+
const s = document.createElement('script')
|
|
11
|
+
s.src = src
|
|
12
|
+
s.addEventListener('load', r)
|
|
13
|
+
document.head.appendChild(s)
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
window.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
|
+
document.head.appendChild(s)
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class Data {
|
|
28
|
+
_ = {}
|
|
29
|
+
set (name= new Error('data.set() needs a name'), value) {
|
|
30
|
+
this._[name] = value
|
|
31
|
+
for(const e of $$(`[data*=${name}]`)) {
|
|
32
|
+
let v = this._
|
|
33
|
+
for(const k of e.getAttribute('data').split('.')) {
|
|
34
|
+
v = v[k]
|
|
35
|
+
}
|
|
36
|
+
e.set ? e.set(v) : e.textContent = v
|
|
37
|
+
}
|
|
38
|
+
const ret = {}
|
|
39
|
+
ret[name] = value
|
|
40
|
+
return ret
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
window.data = new Data ()
|
|
45
|
+
window.wait = ms => new Promise(r => setTimeout(r, ms))
|
|
46
|
+
|
|
47
|
+
class EnigmaticElement extends HTMLElement {
|
|
48
|
+
constructor () {
|
|
49
|
+
super ()
|
|
50
|
+
}
|
|
51
|
+
connectedCallback () {
|
|
52
|
+
if (!this.id)
|
|
53
|
+
this.id = Math.floor(Math.random() * 5000)
|
|
54
|
+
for (let attr of this.attributes) {
|
|
55
|
+
this[attr.name] = attr.value
|
|
56
|
+
}
|
|
57
|
+
this.innerTemplate = this.innerHTML
|
|
58
|
+
}
|
|
59
|
+
async show () {
|
|
60
|
+
return new Promise(r => {
|
|
61
|
+
this.hidden = false
|
|
62
|
+
this.classList.remove('hide')
|
|
63
|
+
this.classList.add('show')
|
|
64
|
+
for (const child of this.children) {
|
|
65
|
+
child.classList.remove('hide')
|
|
66
|
+
child.classList.add('show')
|
|
67
|
+
}
|
|
68
|
+
r(true)
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
async hide () {
|
|
72
|
+
return new Promise(r => {
|
|
73
|
+
this.classList.remove('show')
|
|
74
|
+
this.classList.add('hide')
|
|
75
|
+
for(const child of this.children) {
|
|
76
|
+
child.classList.remove('show')
|
|
77
|
+
child.classList.add('hide')
|
|
78
|
+
}
|
|
79
|
+
r(true)
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
async toggle (classes = ['show', 'hide']) {
|
|
83
|
+
const c = this.classList
|
|
84
|
+
if(!c.contains(classes[0]) && !c.contains(classes[1]))
|
|
85
|
+
c.add(classes[0])
|
|
86
|
+
for(const cls of classes) {
|
|
87
|
+
this.classList.toggle(cls)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
set (s) {
|
|
91
|
+
if(typeof s === 'object') {
|
|
92
|
+
s = JSON.stringify(s)
|
|
93
|
+
}
|
|
94
|
+
this.innerHTML = s
|
|
95
|
+
}
|
|
96
|
+
child (type = 'e-e', id = Math.random()) {
|
|
97
|
+
const child = document.createElement(type)
|
|
98
|
+
child.id = id
|
|
99
|
+
this.appendChild(child)
|
|
100
|
+
return child
|
|
101
|
+
}
|
|
102
|
+
childHTML (html, type = 'e-e', id = Math.random()) {
|
|
103
|
+
const e = this.child(type, id)
|
|
104
|
+
e.innerHTML = html
|
|
105
|
+
return e
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
customElements.define ('e-e', EnigmaticElement)
|
|
110
|
+
|
|
111
|
+
window.addEventListener('DOMContentLoaded', (event) => {
|
|
112
|
+
window.body = document.body
|
|
113
|
+
body.child = (type, id) => {
|
|
114
|
+
const child = document.createElement(type)
|
|
115
|
+
if(id) child.id = id
|
|
116
|
+
body.appendChild(child)
|
|
117
|
+
return child
|
|
118
|
+
}
|
|
119
|
+
if(main) main(document)
|
|
120
|
+
if(window.main) window.main(document)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
window.ready = async () => {
|
|
124
|
+
return new Promise(r => {
|
|
125
|
+
if(document.readyState === 'complete')
|
|
126
|
+
r(true)
|
|
127
|
+
document.onreadystatechange = () => {
|
|
128
|
+
if (document.readyState === 'complete')
|
|
129
|
+
r()
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
}
|
package/package.json
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"name": "enigmatic",
|
|
3
3
|
"description": "Simple web controls",
|
|
4
4
|
"url": "http://github.com/digplan/enigmatic",
|
|
5
|
-
"author": "
|
|
6
|
-
"main": "
|
|
5
|
+
"author": "",
|
|
6
|
+
"main": "enigmatic.js",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git://github.com/digplan/enigmatic.git"
|
|
10
10
|
},
|
|
11
|
-
"version": "0.9.
|
|
11
|
+
"version": "0.9.15"
|
|
12
12
|
}
|