enigmatic 0.11.5 → 0.21.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/README.md +81 -0
- package/authn.mjs +123 -0
- package/enigmatic.css +8 -0
- package/enigmatic.js +40 -28
- package/index.html +33 -0
- package/package.json +1 -1
- package/tests/test-authn.html +0 -0
- package/tests/test-element-classic.html +14 -0
- package/tests/test-error.html +5 -0
- package/tests/test-fetch.html +26 -0
- package/tests/test-flatten.html +38 -0
- package/tests/test-icons.html +3 -0
- package/tests/test-layout.html +32 -0
- package/{test-schema.html → tests/test-schema.html} +1 -3
- package/tests/test-state.html +4 -0
- package/theme.css +9 -0
- package/server.mjs +0 -9
- package/test-components.html +0 -16
- package/test-flatten.html +0 -33
- package/test-js.html +0 -24
- package/test-layout.html +0 -13
- /package/{test.mjs → tests/test.mjs} +0 -0
package/README.md
CHANGED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
**Enigmatic.js - Documentation**
|
|
2
|
+
|
|
3
|
+
*Note: The code provided is a self-contained JavaScript file that defines a library named Enigmatic.js. The documentation below explains the functions and features available in the library.*
|
|
4
|
+
|
|
5
|
+
**1. Introduction**
|
|
6
|
+
|
|
7
|
+
Enigmatic.js is a JavaScript library designed to provide utility functions and tools to simplify common tasks such as loading resources, working with custom elements, managing state, and handling data reactivity. The library aims to enhance web development productivity and offers the following features:
|
|
8
|
+
|
|
9
|
+
- Resource Loading: Load JavaScript and CSS files dynamically.
|
|
10
|
+
- Custom Element: Define custom web components with ease.
|
|
11
|
+
- State Management: Easily manage and react to changes in application state.
|
|
12
|
+
- Data Handling: Fetch data from remote sources and stream real-time data.
|
|
13
|
+
|
|
14
|
+
**2. Helpers**
|
|
15
|
+
|
|
16
|
+
Enigmatic.js provides several helper functions to simplify common tasks:
|
|
17
|
+
|
|
18
|
+
- `w.$(selector)`: Returns the first element matching the given CSS selector within the document.
|
|
19
|
+
- `w.$$(selector)`: Returns a list of all elements matching the given CSS selector within the document.
|
|
20
|
+
- `w.loadJS(src)`: Loads a JavaScript file dynamically by creating a script element in the document's head.
|
|
21
|
+
- `w.loadCSS(src)`: Loads a CSS file dynamically by creating a link element in the document's head.
|
|
22
|
+
- `w.wait(ms)`: Returns a Promise that resolves after the specified number of milliseconds.
|
|
23
|
+
- `w.ready()`: Returns a Promise that resolves when the DOM is ready and the document has completed loading.
|
|
24
|
+
|
|
25
|
+
**3. Template Flattening**
|
|
26
|
+
|
|
27
|
+
Enigmatic.js provides the `w.flatten(obj, text)` function to template a string using placeholders. The placeholders can be in the form of `{$key}`, `{_key_}`, or `{_val_}`. The function recursively replaces the placeholders with the corresponding keys and values from the provided object.
|
|
28
|
+
|
|
29
|
+
**4. Custom Element**
|
|
30
|
+
|
|
31
|
+
Enigmatic.js simplifies the process of defining custom elements with the `w.element(name, options)` function. It takes the following parameters:
|
|
32
|
+
|
|
33
|
+
- `name` (string): The name of the custom element.
|
|
34
|
+
- `options` (object): An object containing configuration options for the custom element.
|
|
35
|
+
- `onMount`: A function to be executed when the custom element is connected to the DOM.
|
|
36
|
+
- `beforeData`: A function to preprocess the data before rendering the template.
|
|
37
|
+
- `style`: A string containing CSS rules specific to the custom element.
|
|
38
|
+
- `template`: A string representing the HTML template for the custom element.
|
|
39
|
+
|
|
40
|
+
**5. State, Data, and Reactivity**
|
|
41
|
+
|
|
42
|
+
Enigmatic.js introduces reactive state management with the `w.state` object. It is implemented using a Proxy to reactively update DOM elements when state changes. DOM elements with `data` attributes that match state keys will be automatically updated when the corresponding state changes.
|
|
43
|
+
|
|
44
|
+
- `w.state`: An object acting as reactive state storage. Changes to this object trigger updates in associated DOM elements with matching `data` attributes.
|
|
45
|
+
|
|
46
|
+
- `w.save(obj, name)`: Saves a JavaScript object to the local storage under the specified name.
|
|
47
|
+
- `w.load(name)`: Loads a JavaScript object from local storage using the given name.
|
|
48
|
+
- `w.get(url, options, transform, key)`: Fetches data from a remote URL using the `fetch` API. Transforms the fetched data using the optional `transform` function and updates the state with the specified `key`.
|
|
49
|
+
- `w.stream(url, key)`: Sets up an EventSource to stream real-time data from the specified URL and updates the state with the specified `key`.
|
|
50
|
+
|
|
51
|
+
**6. Startup**
|
|
52
|
+
|
|
53
|
+
Enigmatic.js provides the `w.start()` function to kickstart the library and process elements on the page with special attributes like `fetch`, `immediate`, and `stream`.
|
|
54
|
+
|
|
55
|
+
**7. Global Object**
|
|
56
|
+
|
|
57
|
+
The code creates a global object `w` that holds all the utility functions and state management features.
|
|
58
|
+
|
|
59
|
+
**8. Usage Example**
|
|
60
|
+
|
|
61
|
+
To use Enigmatic.js, include the script in your HTML file and call its functions as needed. For example:
|
|
62
|
+
|
|
63
|
+
```html
|
|
64
|
+
<script src="path/to/enigmatic.js"></script>
|
|
65
|
+
<script>
|
|
66
|
+
// Perform custom element registration
|
|
67
|
+
w.element('custom-element', {
|
|
68
|
+
template: '<div>{_key_}: {_val_}</div>',
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Initialize Enigmatic.js
|
|
72
|
+
(async () => {
|
|
73
|
+
await w.start();
|
|
74
|
+
w.state.exampleData = { key1: 'value1', key2: 'value2' };
|
|
75
|
+
})();
|
|
76
|
+
</script>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**9. Support**
|
|
80
|
+
|
|
81
|
+
For bug reports, feature requests, or general inquiries, please visit the GitHub repository of Enigmatic.js.
|
package/authn.mjs
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
ArrayBuffer.from = (string) => Uint8Array.from(string.split('').map(e => e.charCodeAt(0))).buffer
|
|
2
|
+
|
|
3
|
+
const webauthn = async () => {
|
|
4
|
+
const op = {}
|
|
5
|
+
op.attestation = 'direct'
|
|
6
|
+
op.authenticatorSelection = {
|
|
7
|
+
authenticatorAttachment: 'platform',
|
|
8
|
+
requireResidentKey: false,
|
|
9
|
+
userVerification: 'discouraged'
|
|
10
|
+
}
|
|
11
|
+
op.challenge = ArrayBuffer.from('challenge')
|
|
12
|
+
op.pubKeyCredParams = []
|
|
13
|
+
op.rp = { id: location.hostname, name: location.hostname }
|
|
14
|
+
op.timeout = 60000,
|
|
15
|
+
op.user = { name: 'cb', displayName: 'cb', id: ArrayBuffer.from('cb') }
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
async makeCredential() {
|
|
19
|
+
return await navigator.credentials.create({ publicKey: op })
|
|
20
|
+
},
|
|
21
|
+
async getAssertion() {
|
|
22
|
+
return await navigator.credentials.get({ publicKey: op })
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const w = await webauthn()
|
|
28
|
+
const credential = await w.makeCredential()
|
|
29
|
+
const decodedClientData = JSON.parse(new TextDecoder('utf-8').decode(credential.response.clientDataJSON))
|
|
30
|
+
console.log(decodedClientData)
|
|
31
|
+
// decode credential.response.attestationObject
|
|
32
|
+
|
|
33
|
+
//
|
|
34
|
+
// w.getAssertion()
|
|
35
|
+
//
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
const credential = await navigator.credentials.create({
|
|
39
|
+
publicKey: {
|
|
40
|
+
challenge: Uint8Array.from(
|
|
41
|
+
'xxxxxx', c => c.charCodeAt(0)),
|
|
42
|
+
rp: {
|
|
43
|
+
name: "Test",
|
|
44
|
+
id: "localhost",
|
|
45
|
+
},
|
|
46
|
+
user: {
|
|
47
|
+
id: Uint8Array.from(
|
|
48
|
+
"UZSL85T9AFC", c => c.charCodeAt(0)),
|
|
49
|
+
name: "lee@webauthn.guide",
|
|
50
|
+
displayName: "Lee",
|
|
51
|
+
},
|
|
52
|
+
pubKeyCredParams: [{ alg: -7, type: "public-key" }],
|
|
53
|
+
authenticatorSelection: {
|
|
54
|
+
authenticatorAttachment: "cross-platform",
|
|
55
|
+
},
|
|
56
|
+
timeout: 60000,
|
|
57
|
+
attestation: "direct"
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
console.log(credential)
|
|
62
|
+
|
|
63
|
+
// Auth
|
|
64
|
+
const publicKeyCredentialRequestOptions = {
|
|
65
|
+
challenge: Uint8Array.from(
|
|
66
|
+
randomStringFromServer, c => c.charCodeAt(0)),
|
|
67
|
+
allowCredentials: [{
|
|
68
|
+
id: Uint8Array.from(
|
|
69
|
+
credentialId, c => c.charCodeAt(0)),
|
|
70
|
+
type: 'public-key',
|
|
71
|
+
transports: ['usb', 'ble', 'nfc'],
|
|
72
|
+
}],
|
|
73
|
+
timeout: 60000,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const assertion = await navigator.credentials.get({
|
|
77
|
+
publicKey: publicKeyCredentialRequestOptions
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
ArrayBuffer.from = (string) => Uint8Array.from(string.split('').map(e => e.charCodeAt(0))).buffer
|
|
82
|
+
|
|
83
|
+
const webauthn = async () => {
|
|
84
|
+
//if(!await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable())
|
|
85
|
+
// return false
|
|
86
|
+
const op = {}
|
|
87
|
+
op.attestation = 'direct'
|
|
88
|
+
op.authenticatorSelection = {
|
|
89
|
+
authenticatorAttachment: 'platform',
|
|
90
|
+
requireResidentKey: false,
|
|
91
|
+
userVerification: 'discouraged'
|
|
92
|
+
}
|
|
93
|
+
op.challenge = ArrayBuffer.from('challenge')
|
|
94
|
+
op.pubKeyCredParams = [{ alg: -7, type: 'public-key' }]
|
|
95
|
+
op.rp = { id: 'localhost', name: 'localhost' }
|
|
96
|
+
op.timeout = 60000,
|
|
97
|
+
op.user = { name: 'cb', displayName: 'cb', id: ArrayBuffer.from('cb') }
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
async makeCredential() {
|
|
101
|
+
const cred = await navigator.credentials.create({ publicKey: op })
|
|
102
|
+
return cred
|
|
103
|
+
},
|
|
104
|
+
async getAssertion() {
|
|
105
|
+
const cred = await navigator.credentials.get({ publicKey: op })
|
|
106
|
+
return cred
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const w = await webauthn()
|
|
112
|
+
w.makeCredential().then(e => console.log(e))
|
|
113
|
+
//w.getAssertion().then(e => console.log(e))
|
|
114
|
+
|
|
115
|
+
/*
|
|
116
|
+
send to server
|
|
117
|
+
{
|
|
118
|
+
credential: {type: 'FIDO', id: attestation.id},
|
|
119
|
+
clientData: attestation.signature.clientData,
|
|
120
|
+
authnrData: attestation.signature.authnrData,
|
|
121
|
+
signature: attestation.signature.signature
|
|
122
|
+
}
|
|
123
|
+
*/
|
package/enigmatic.css
CHANGED
package/enigmatic.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const w = {}, d = document
|
|
2
|
-
w.enigmatic = { version: '
|
|
2
|
+
w.enigmatic = { version: '2023-07-29 0.21.2' }
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
window.onerror = (err, l, n) => {
|
|
5
|
+
document.write(`<h2 style="border:8px solid Tomato;">${[l, 'line: ' + n, err].join('<br>')}</h2>`)
|
|
6
|
+
}
|
|
5
7
|
|
|
6
8
|
w.$ = d.querySelector.bind(d)
|
|
7
9
|
w.$$ = d.querySelectorAll.bind(d)
|
|
@@ -14,6 +16,7 @@ w.loadJS = (src) => {
|
|
|
14
16
|
d.head.appendChild(s)
|
|
15
17
|
})
|
|
16
18
|
}
|
|
19
|
+
|
|
17
20
|
w.loadCSS = (src) => {
|
|
18
21
|
return new Promise((r, j) => {
|
|
19
22
|
const s = document.createElement('link')
|
|
@@ -23,7 +26,9 @@ w.loadCSS = (src) => {
|
|
|
23
26
|
d.head.appendChild(s)
|
|
24
27
|
})
|
|
25
28
|
}
|
|
29
|
+
|
|
26
30
|
w.wait = (ms) => new Promise((r) => setTimeout(r, ms))
|
|
31
|
+
|
|
27
32
|
w.ready = async () => {
|
|
28
33
|
return new Promise((r) => {
|
|
29
34
|
if (document.readyState === 'complete') r(true)
|
|
@@ -33,16 +38,31 @@ w.ready = async () => {
|
|
|
33
38
|
})
|
|
34
39
|
}
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
w.flattenMap = (obj, text) => {
|
|
42
|
+
let template = ''
|
|
43
|
+
if (text.match(/\$key|\$val/i)) {
|
|
44
|
+
for (let k in obj) {
|
|
45
|
+
template += text.replaceAll('{$key}', k).replaceAll('{$val}', obj[k])
|
|
46
|
+
}
|
|
47
|
+
return template
|
|
48
|
+
}
|
|
49
|
+
for (let k in obj) {
|
|
50
|
+
text = text.replaceAll(`{${k}}`, obj[k])
|
|
51
|
+
}
|
|
52
|
+
return text
|
|
53
|
+
}
|
|
54
|
+
|
|
38
55
|
w.flatten = (obj, text) => {
|
|
56
|
+
if (!(obj instanceof Array) && typeof Object.values(obj)[0] === 'string') {
|
|
57
|
+
return w.flattenMap(obj, text)
|
|
58
|
+
}
|
|
39
59
|
let htmls = ''
|
|
40
60
|
if (obj instanceof Array) obj = { ...obj }
|
|
41
61
|
for (let k in obj) {
|
|
42
62
|
let html = text.replaceAll('{$key}', k)
|
|
43
63
|
for (let j in obj[k]) {
|
|
44
64
|
const val = typeof obj[k] === 'object' ? obj[k][j] : obj[k]
|
|
45
|
-
html = html.replaceAll('{_key_}', j).replaceAll('{
|
|
65
|
+
html = html.replaceAll('{_key_}', j).replaceAll('{$val}', val)
|
|
46
66
|
html = html.replaceAll(`{${j}}`, val)
|
|
47
67
|
}
|
|
48
68
|
htmls += html
|
|
@@ -50,7 +70,6 @@ w.flatten = (obj, text) => {
|
|
|
50
70
|
return htmls
|
|
51
71
|
}
|
|
52
72
|
|
|
53
|
-
/////// Custom element
|
|
54
73
|
w.element = (
|
|
55
74
|
name,
|
|
56
75
|
{ onMount = x => x, beforeData = (x) => x, style, template = '' }
|
|
@@ -81,10 +100,9 @@ if (window.components) {
|
|
|
81
100
|
for (let name in window.components) w.element(name, window.components[name])
|
|
82
101
|
}
|
|
83
102
|
|
|
84
|
-
/////// State, data, and reactivity
|
|
85
103
|
w.state = new Proxy({}, {
|
|
86
104
|
set: (obj, prop, value) => {
|
|
87
|
-
console.log(prop, value)
|
|
105
|
+
console.log('state change:', prop, value)
|
|
88
106
|
if (this[prop] === value) {
|
|
89
107
|
return true
|
|
90
108
|
}
|
|
@@ -101,17 +119,13 @@ w.state = new Proxy({}, {
|
|
|
101
119
|
}
|
|
102
120
|
)
|
|
103
121
|
|
|
104
|
-
w.save = (obj, name) => {
|
|
105
|
-
return localStorage.setItem(name, JSON.stringify(obj))
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
w.load = (name) => {
|
|
109
|
-
return localStorage.getItem(name)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
122
|
w.get = async (url, options = {}, transform, key) => {
|
|
113
|
-
|
|
114
|
-
|
|
123
|
+
console.log(`fetching ${url}`)
|
|
124
|
+
let data = await (await fetch(url, options)).json()
|
|
125
|
+
if (transform) {
|
|
126
|
+
console.log('transforming ' + data)
|
|
127
|
+
data = transform(data)
|
|
128
|
+
}
|
|
115
129
|
if (key) w.state[key] = data
|
|
116
130
|
return data
|
|
117
131
|
}
|
|
@@ -125,38 +139,36 @@ w.stream = async (url, key) => {
|
|
|
125
139
|
}
|
|
126
140
|
}
|
|
127
141
|
|
|
128
|
-
/////// Startup
|
|
129
142
|
w.start = async () => {
|
|
130
143
|
await w.ready();
|
|
131
144
|
[...$$('*')].map(e => {
|
|
132
145
|
e.attr = {};
|
|
133
146
|
[...e.attributes].map((a) => (e.attr[a.name] = a.value))
|
|
134
|
-
if (e.attr
|
|
147
|
+
if (e.attr.fetch) {
|
|
135
148
|
e.fetch = async () => {
|
|
136
|
-
return w.get(e.attr
|
|
149
|
+
return w.get(e.attr.fetch, {}, null, e.attr.data)
|
|
137
150
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
e.fetch()
|
|
151
|
+
if (!e.hasAttribute('defer'))
|
|
152
|
+
e.fetch()
|
|
141
153
|
}
|
|
142
154
|
if (e.attr?.stream) {
|
|
143
155
|
e.stream = w.stream.bind(null, e.pr.stream, null, window[e.pr.transform], e.id)
|
|
144
156
|
}
|
|
145
157
|
let dta = e.attr?.data
|
|
146
158
|
if (dta) {
|
|
147
|
-
console.log(`
|
|
159
|
+
console.log(`reactive ${e} ${dta}`)
|
|
148
160
|
if (!e.set) {
|
|
149
161
|
if (e.innerHTML) {
|
|
150
162
|
e.template = e.innerHTML
|
|
151
|
-
if (e.innerHTML.match('{')) {
|
|
163
|
+
if (e.innerHTML.match('{') && !e.attr.preserve) {
|
|
152
164
|
e.innerHTML = ''
|
|
153
165
|
}
|
|
154
166
|
}
|
|
155
167
|
e.set = (o) => {
|
|
156
|
-
e.innerHTML = w.flatten(o, e.template)
|
|
168
|
+
e.innerHTML = w.flatten(o, e.template) || o
|
|
157
169
|
}
|
|
158
170
|
}
|
|
159
|
-
if (e.attr
|
|
171
|
+
if (e.attr.value) {
|
|
160
172
|
let o = e.attr.value
|
|
161
173
|
try { o = JSON.parse(o) } catch (e) { }
|
|
162
174
|
w.state[dta] = o
|
package/index.html
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script src=components.js></script>
|
|
2
|
+
<script src=enigmatic.js></script>
|
|
3
|
+
<link rel=stylesheet href=enigmatic.css>
|
|
4
|
+
|
|
5
|
+
<body style="--cols:3fr 10fr 3fr; --rows:3fr 11fr 2fr">
|
|
6
|
+
|
|
7
|
+
<div class="bg-white"></div>
|
|
8
|
+
<div class="bg-white">
|
|
9
|
+
<img height='62' style='filter:invert(50%)'
|
|
10
|
+
src='https://unpkg.com/simple-icons@v7/icons/apple.svg'>
|
|
11
|
+
|
|
12
|
+
</div>
|
|
13
|
+
<div class="bg-white"></div>
|
|
14
|
+
|
|
15
|
+
<div class="bg-white"></div>
|
|
16
|
+
<section class="bg-white" style="--cols: 1fr 1fr 1fr; --rows: 1fr 1fr 1fr">
|
|
17
|
+
<div class="bg-green"></div>
|
|
18
|
+
<div class="bg-white"><hello-world></hello-world></div>
|
|
19
|
+
<div class="bg-white"></div>
|
|
20
|
+
<div class="bg-white"></div>
|
|
21
|
+
<div class="bg-white"></div>
|
|
22
|
+
<div class="bg-white"></div>
|
|
23
|
+
<div class="bg-white"></div>
|
|
24
|
+
<div class="bg-white"></div>
|
|
25
|
+
<div class="bg-green"></div>
|
|
26
|
+
</section>
|
|
27
|
+
<div class="bg-white"></div>
|
|
28
|
+
|
|
29
|
+
<div class="bg-yellow"></div>
|
|
30
|
+
<div class="bg-yellow"></div>
|
|
31
|
+
<div class="bg-yellow"></div>
|
|
32
|
+
|
|
33
|
+
</body>
|
package/package.json
CHANGED
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script src='../enigmatic.js'></script>
|
|
2
|
+
|
|
3
|
+
<script type="module">
|
|
4
|
+
|
|
5
|
+
customElements.define('classic-syntax', class CS extends HTMLElement {
|
|
6
|
+
set(data) {
|
|
7
|
+
this.innerHTML = flatten(data, this.innerHTML)
|
|
8
|
+
}
|
|
9
|
+
})
|
|
10
|
+
state.mykey = {message: 'somedata'}
|
|
11
|
+
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<classic-syntax data="mykey">{message}</classic-syntax>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script src='../enigmatic.js'></script>
|
|
2
|
+
|
|
3
|
+
<!-- HTML declarative -->
|
|
4
|
+
<div data='users_declare' fetch='toydb-687z3zxxqk0r.runkit.sh/'>{test_message}</div>
|
|
5
|
+
|
|
6
|
+
<!-- Not immediate -->
|
|
7
|
+
<div id='f' data='users_declare2' fetch='toydb-687z3zxxqk0r.runkit.sh/' defer>Delayed: {test_message}</div>
|
|
8
|
+
<button onclick='f.fetch()'>Fetch</button>
|
|
9
|
+
|
|
10
|
+
<!-- Transform results -->
|
|
11
|
+
<script>
|
|
12
|
+
get('randomuser.me/api', null, x=>x.results, 'users')
|
|
13
|
+
</script>
|
|
14
|
+
<div data="users">
|
|
15
|
+
<div>{gender} {picture}</div>
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
<!-- Component -->
|
|
19
|
+
<script>
|
|
20
|
+
element('my-c', {
|
|
21
|
+
onmount: e=>e.style.border='1px solid black',
|
|
22
|
+
template: 'is: {gender}',
|
|
23
|
+
style: 'color:red'})
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<my-c data='users_component'></my-c>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script src='../enigmatic.js'></script>
|
|
2
|
+
<link rel=stylesheet href='../enigmatic.css'>
|
|
3
|
+
|
|
4
|
+
<body style='--rows: 1fr 1fr 1fr 1fr 10fr; --cols: 1fr 10fr 1fr'>
|
|
5
|
+
<h1 style='--span: 3'>Text templating (Flatten)</h1>
|
|
6
|
+
|
|
7
|
+
<div data="testobj" style='--span: 4' preserve='true'>
|
|
8
|
+
{k1} {k2}
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<div data="testobjkv" style='--span: 4' preserve='true'>
|
|
12
|
+
{$key} {$val}
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
<div data="testarray" style='--span: 4' preserve='true'>
|
|
16
|
+
{$key}: {name}={value}
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div data="testobjobj" style='--span: 4' preserve='true'>
|
|
20
|
+
{$key}: {name}={value}
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
<div></div>
|
|
24
|
+
|
|
25
|
+
<section style='--cols: 1fr 1fr 1fr 1fr'>
|
|
26
|
+
<button onclick='state.testobj={"k1": "val1", "k2": "val2"}'>{k1: 'val1', k2: 'val2'}</button>
|
|
27
|
+
<button onclick='state.testobjkv={"k1": "val1", "k2": "val2"}'>{k1: 'val1', k2: 'val2'}</button>
|
|
28
|
+
<button onclick='state.testarray=[{ name: "myname", value: "myvalue" },{ name: "myname2", value: "myvalue2" }]'>[
|
|
29
|
+
{ name: 'myname', value: 'myvalue' },
|
|
30
|
+
{ name: 'myname2', value: 'myvalue2' },
|
|
31
|
+
]</button>
|
|
32
|
+
<button onclick='state.testobjobj={ "k1": {name: "myname3", value: "myvalue3"}, "k2": {name: "myname4", value: "myvalue4"} }'>{
|
|
33
|
+
"k1": { name: 'myname3', value: 'myvalue3' },
|
|
34
|
+
"k2": { name: 'myname4', value: 'myvalue4' },
|
|
35
|
+
}</button>
|
|
36
|
+
</section>
|
|
37
|
+
|
|
38
|
+
</body>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<script src=components.js></script>
|
|
2
|
+
<script src=enigmatic.js></script>
|
|
3
|
+
<link rel=stylesheet href=enigmatic.css>
|
|
4
|
+
|
|
5
|
+
<body style="--cols:3fr 10fr 3fr; --rows:3fr 11fr 2fr">
|
|
6
|
+
|
|
7
|
+
<div class="bg-white"></div>
|
|
8
|
+
<div class="bg-white">
|
|
9
|
+
<img height='62' style='filter:invert(50%)' src='https://unpkg.com/simple-icons@v7/icons/apple.svg'>
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
<div class="bg-white"></div>
|
|
13
|
+
|
|
14
|
+
<div class="bg-white"></div>
|
|
15
|
+
<section class="bg-white" style="--cols: 1fr 1fr 1fr; --rows: 1fr 1fr 1fr">
|
|
16
|
+
<div class="bg-green"></div>
|
|
17
|
+
<div class="bg-white"><hello-world></hello-world></div>
|
|
18
|
+
<div class="bg-white"></div>
|
|
19
|
+
<div class="bg-white"></div>
|
|
20
|
+
<div class="bg-white"></div>
|
|
21
|
+
<div class="bg-white"></div>
|
|
22
|
+
<div class="bg-white"></div>
|
|
23
|
+
<div class="bg-white"></div>
|
|
24
|
+
<div class="bg-green"></div>
|
|
25
|
+
</section>
|
|
26
|
+
<div class="bg-white"></div>
|
|
27
|
+
|
|
28
|
+
<div class="bg-yellow"></div>
|
|
29
|
+
<div class="bg-yellow"></div>
|
|
30
|
+
<div class="bg-yellow"></div>
|
|
31
|
+
|
|
32
|
+
</body>
|
package/theme.css
ADDED
package/server.mjs
DELETED
package/test-components.html
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
customElements.define('is-online', class IsOnline extends HTMLElement {
|
|
3
|
-
connectedCallback() {
|
|
4
|
-
this.setAttribute('rel', 'icon')
|
|
5
|
-
this.setAttribute('href', "data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🎯</text></svg>")
|
|
6
|
-
}
|
|
7
|
-
})
|
|
8
|
-
</script>
|
|
9
|
-
|
|
10
|
-
<link rel="stylesheet" href="enigmatic.css">
|
|
11
|
-
<body style="--cols:1fr 6fr 1fr; --rows:1fr 10fr">
|
|
12
|
-
<my-e>hey</my-e>
|
|
13
|
-
<my-e>hey</my-e>
|
|
14
|
-
<my-e>hey</my-e>
|
|
15
|
-
<my-e>hey</my-e>
|
|
16
|
-
<my-e>hey</my-e>
|
package/test-flatten.html
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
<script src='enigmatic.js'></script>
|
|
2
|
-
|
|
3
|
-
<div id='templ' data="akey">
|
|
4
|
-
{$key}: {_key_} : {_val_}, name = {name}, value = {value} <br>
|
|
5
|
-
</div>
|
|
6
|
-
|
|
7
|
-
<button onclick='window.testone()'>Test one</button>
|
|
8
|
-
<button onclick='window.testtwo()'>Test two</button>
|
|
9
|
-
<button onclick='window.testthree()'>Test three</button>
|
|
10
|
-
|
|
11
|
-
<script type="module">
|
|
12
|
-
window.testone = () => {
|
|
13
|
-
const testone = [
|
|
14
|
-
{ name: 'myname', value: 'myvalue' },
|
|
15
|
-
{ name: 'myname2', value: 'myvalue2' },
|
|
16
|
-
]
|
|
17
|
-
state.akey = testone
|
|
18
|
-
}
|
|
19
|
-
window.testtwo = () => {
|
|
20
|
-
const testt = {
|
|
21
|
-
"k1": { name: 'myname3', value: 'myvalue3' },
|
|
22
|
-
"k2": { name: 'myname4', value: 'myvalue4' },
|
|
23
|
-
}
|
|
24
|
-
state.akey = testt
|
|
25
|
-
}
|
|
26
|
-
window.testthree = () => {
|
|
27
|
-
const testt = {
|
|
28
|
-
"k1": 'val1',
|
|
29
|
-
"k2": 'val2',
|
|
30
|
-
}
|
|
31
|
-
state.akey = testt
|
|
32
|
-
}
|
|
33
|
-
</script>
|
package/test-js.html
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<script src='components.js'></script>
|
|
3
|
-
<script src='enigmatic.js'></script>
|
|
4
|
-
|
|
5
|
-
<div id="counter" data="count" value="0">{value}</div>
|
|
6
|
-
<button onclick="state.count++">Incr</button>
|
|
7
|
-
|
|
8
|
-
<div id='div1' data="users" fetch="randomuser.me/api" value='{"results": [ {"name": {"first": "set", "last": "me"}} ]}'>
|
|
9
|
-
{results[0].name.first} {results[0].name.last}
|
|
10
|
-
</div>
|
|
11
|
-
|
|
12
|
-
<button onclick='state.users = {"results": [ {"name": {"first": "first", "last": "last"} }]}'>Set user</button>
|
|
13
|
-
<button onclick="div1.fetch()">Fetch user</button>
|
|
14
|
-
|
|
15
|
-
<div id='div2' data="users2" fetch="randomuser.me/api" immediate>
|
|
16
|
-
<div>{results[0].name.first} {results[0].name.last}</div>
|
|
17
|
-
</div>
|
|
18
|
-
|
|
19
|
-
<div id='div3' data="users2">
|
|
20
|
-
<div>{results[0].name.first} {results[0].name.last}</div>
|
|
21
|
-
</div>
|
|
22
|
-
|
|
23
|
-
<random-users data="users"></random-users>
|
|
24
|
-
<tailwind-example></tailwind-example>
|
package/test-layout.html
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<link rel=stylesheet href=enigmatic.css>
|
|
2
|
-
|
|
3
|
-
<body style="--cols:1fr 1fr 1fr 10fr; --rows:1fr 10fr">
|
|
4
|
-
<div class="bg-red" style="--span:2">Hello</div>
|
|
5
|
-
<div class="bg-green"></div>
|
|
6
|
-
<div class="bg-yellow"></div>
|
|
7
|
-
<div class="bg-blue"></div>
|
|
8
|
-
<div class="bg-red"></div>
|
|
9
|
-
<div class="bg-green"></div>
|
|
10
|
-
<div class="bg-yellow"></div>
|
|
11
|
-
<div class="bg-blue"></div>
|
|
12
|
-
<div class="bg-red"></div>
|
|
13
|
-
</body>
|
|
File without changes
|