@tltdsh/mx 1.0.0 → 1.0.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 +197 -0
- package/mx.d.ts +687 -0
- package/mx.mjs +3 -0
- package/package.json +80 -8
package/README.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# mx.js
|
|
2
|
+
|
|
3
|
+
Expressive UI library in **890 bytes** (brotli) for building high-end, enterprise-level applications. 4 globals, zero dependencies, no build step.
|
|
4
|
+
|
|
5
|
+
[**Documentation**](https://mxjs.dev)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm i @tltdsh/mx
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Script tag (globals)
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<script src="https://unpkg.com/@tltdsh/mx"></script>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### ESM
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import { mx, dom, define, components } from '@tltdsh/mx'
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 4 Globals
|
|
26
|
+
|
|
27
|
+
| Global | Returns | Use for |
|
|
28
|
+
|--------|---------|---------|
|
|
29
|
+
| `mx.tag(attrs?, ...children)` | Description array | Inside `render()` — efficient reconciliation |
|
|
30
|
+
| `dom.tag(attrs?, ...children)` | HTMLElement | Persistent references, calling `.$()` later |
|
|
31
|
+
| `define(name, { $() {} })` | void | Register a component |
|
|
32
|
+
| `components` | object | Component registry |
|
|
33
|
+
|
|
34
|
+
CamelCase auto-converts to kebab-case: `mx.priceChart()` → `<price-chart>`.
|
|
35
|
+
|
|
36
|
+
## Quick start
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
define('counter', {
|
|
40
|
+
$({ count = 0 }) {
|
|
41
|
+
return [
|
|
42
|
+
mx.button({ onclick: _ => this.$({ count: count + 1 }) }, '+'),
|
|
43
|
+
mx.span(count),
|
|
44
|
+
mx.button({ onclick: _ => this.$({ count: count - 1 }) }, '-')
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
document.body.render(mx.counter({ count: 10 }))
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Examples
|
|
53
|
+
|
|
54
|
+
### SVG sparkline
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
define('sparkline', {
|
|
58
|
+
$({ history = [], width = 80, height = 24 }) {
|
|
59
|
+
if (!history.length) return []
|
|
60
|
+
let min = Math.min(...history), max = Math.max(...history)
|
|
61
|
+
let range = max - min || 1
|
|
62
|
+
let points = history.map((v, i) =>
|
|
63
|
+
(i / (history.length - 1) * width).toFixed(1) + ',' +
|
|
64
|
+
(height - ((v - min) / range * (height - 2) + 1)).toFixed(1)
|
|
65
|
+
).join(' ')
|
|
66
|
+
return mx.svg({ viewBox: '0 0 ' + width + ' ' + height, width, height, fill: 'none' },
|
|
67
|
+
mx.polyline({ points, stroke: '#0071e3', 'stroke-width': '1.5', 'stroke-linecap': 'round' })
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Sortable table
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
define('data-table', {
|
|
77
|
+
$({ rows = [], sortKey = 'name', sortDir = 1 }) {
|
|
78
|
+
let sorted = [...rows].sort((a, b) => {
|
|
79
|
+
let va = a[sortKey], vb = b[sortKey]
|
|
80
|
+
return sortDir * (typeof va === 'string' ? va.localeCompare(vb) : va - vb)
|
|
81
|
+
})
|
|
82
|
+
let header = (label, key) =>
|
|
83
|
+
mx.th({ onclick: _ => this.$({ sortKey: key, sortDir: sortKey === key ? -sortDir : 1 }) },
|
|
84
|
+
label, sortKey === key ? (sortDir > 0 ? ' ▲' : ' ▼') : null
|
|
85
|
+
)
|
|
86
|
+
return mx.table(
|
|
87
|
+
mx.thead(mx.tr(header('Name', 'name'), header('Value', 'value'))),
|
|
88
|
+
mx.tbody(...sorted.map(r => mx.tr(mx.td(r.name), mx.td(r.value))))
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Keyed list with persistent DOM
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
define('drink-builder', {
|
|
98
|
+
$({ drinks = [], onadd, onremove }) {
|
|
99
|
+
this._rowMap ||= new Map
|
|
100
|
+
for (let [id] of this._rowMap)
|
|
101
|
+
if (!drinks.find(d => d.id === id)) this._rowMap.delete(id)
|
|
102
|
+
for (let d of drinks) {
|
|
103
|
+
let el = this._rowMap.get(d.id)
|
|
104
|
+
if (!el) { el = dom.drinkRow(); this._rowMap.set(d.id, el) }
|
|
105
|
+
el.$({ drink: d, onremove })
|
|
106
|
+
}
|
|
107
|
+
return [
|
|
108
|
+
!!drinks.length && mx.div({ class: 'list' },
|
|
109
|
+
...drinks.map(d => this._rowMap.get(d.id))
|
|
110
|
+
),
|
|
111
|
+
mx.button({ onclick: _ => onadd?.() }, '+ Add drink')
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Toast notifications
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
let toastContainer = null
|
|
121
|
+
|
|
122
|
+
function toast(message, type = 'info') {
|
|
123
|
+
if (!toastContainer) {
|
|
124
|
+
toastContainer = dom.div({ class: 'toast-container' })
|
|
125
|
+
document.body.append(toastContainer)
|
|
126
|
+
}
|
|
127
|
+
let el = dom.div({ class: 'toast toast-' + type },
|
|
128
|
+
mx.span(message),
|
|
129
|
+
mx.button({ onclick() { el.remove() } }, '×')
|
|
130
|
+
)
|
|
131
|
+
toastContainer.append(el)
|
|
132
|
+
setTimeout(_ => el.remove(), 4000)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
toast.success = msg => toast(msg, 'success')
|
|
136
|
+
toast.error = msg => toast(msg, 'error')
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## How it works
|
|
140
|
+
|
|
141
|
+
**`render(...children)`** reconciles children left-to-right against existing DOM:
|
|
142
|
+
|
|
143
|
+
- `mx.*()` descriptions → create/reuse elements by tag, apply attrs, recurse
|
|
144
|
+
- Real DOM nodes → identity-match by reference (keyed lists)
|
|
145
|
+
- Strings / numbers → text nodes (auto-cast, no `String()` needed)
|
|
146
|
+
- `null` / `false` → skipped (conditional rendering)
|
|
147
|
+
|
|
148
|
+
Excess old nodes are removed. That's it.
|
|
149
|
+
|
|
150
|
+
## Attributes
|
|
151
|
+
|
|
152
|
+
```js
|
|
153
|
+
mx.div({ class: 'active' }) // setAttribute
|
|
154
|
+
mx.input({ '.value': text }) // el.value = text (property)
|
|
155
|
+
mx.button({ disabled: true }) // setAttribute(name, '')
|
|
156
|
+
mx.button({ disabled: null }) // removeAttribute
|
|
157
|
+
mx.button({ onclick: handler }) // el.onclick = handler (auto-cleaned)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
`value`, `checked`, `selected` set both attribute and property automatically.
|
|
161
|
+
|
|
162
|
+
## Keyed lists
|
|
163
|
+
|
|
164
|
+
Create persistent elements with `dom()`, store in a Map, render by reference:
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
let rowMap = new Map(
|
|
168
|
+
data.map(d => [d.id, dom.tableRow({ data: d })])
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
// Nodes move by identity — internal state preserved on reorder
|
|
172
|
+
container.render(...data.map(d => rowMap.get(d.id)))
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Tips
|
|
176
|
+
|
|
177
|
+
- `mx.*` = descriptions (arrays) for inside `render()`
|
|
178
|
+
- `dom.*` = real HTMLElements for persistent references
|
|
179
|
+
- `$()` always returns array of children
|
|
180
|
+
- `??=` protects `$state` from parent prop overwrites
|
|
181
|
+
- Never `addEventListener` inside `$()` — use direct property assignment
|
|
182
|
+
- Numbers auto-cast — no `String()` needed
|
|
183
|
+
- Use `_ =>` for unused arrow params
|
|
184
|
+
- `clearInterval(this._interval)` at top of `$()` for timers
|
|
185
|
+
- `this._cache ||= new Map` for persistent Maps
|
|
186
|
+
|
|
187
|
+
## TypeScript
|
|
188
|
+
|
|
189
|
+
Full type definitions included. Provides autocomplete for all HTML/SVG elements and attributes.
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { mx, dom, define, type MxChild, type MxAttrs } from '@tltdsh/mx'
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
0BSD — do whatever you want.
|
package/mx.d.ts
ADDED
|
@@ -0,0 +1,687 @@
|
|
|
1
|
+
// Type definitions for @tltdsh/mx
|
|
2
|
+
// https://mxjs.dev
|
|
3
|
+
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// Children — everything render() and mx/dom accept as child nodes
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
/** A description array returned by mx.*() calls */
|
|
9
|
+
interface MxDescription extends Array<any> {
|
|
10
|
+
/** Internal marker — distinguishes descriptions from plain arrays */
|
|
11
|
+
_: 1 | true;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Anything that can appear as a child in render(), mx.*(), or dom.*() */
|
|
15
|
+
type MxChild =
|
|
16
|
+
| MxDescription
|
|
17
|
+
| Node
|
|
18
|
+
| string
|
|
19
|
+
| number
|
|
20
|
+
| false
|
|
21
|
+
| null
|
|
22
|
+
| undefined;
|
|
23
|
+
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Attributes
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
/** Common HTML attributes with autocomplete support */
|
|
29
|
+
interface MxHTMLAttrs {
|
|
30
|
+
// Core
|
|
31
|
+
class?: string;
|
|
32
|
+
id?: string;
|
|
33
|
+
style?: string;
|
|
34
|
+
title?: string;
|
|
35
|
+
tabindex?: number | string;
|
|
36
|
+
role?: string;
|
|
37
|
+
slot?: string;
|
|
38
|
+
hidden?: boolean;
|
|
39
|
+
|
|
40
|
+
// Data / aria (string-indexed below covers data-* and aria-*)
|
|
41
|
+
|
|
42
|
+
// Links / navigation
|
|
43
|
+
href?: string;
|
|
44
|
+
target?: string;
|
|
45
|
+
rel?: string;
|
|
46
|
+
download?: string | boolean;
|
|
47
|
+
|
|
48
|
+
// Media
|
|
49
|
+
src?: string;
|
|
50
|
+
alt?: string;
|
|
51
|
+
width?: number | string;
|
|
52
|
+
height?: number | string;
|
|
53
|
+
loading?: 'lazy' | 'eager';
|
|
54
|
+
|
|
55
|
+
// Forms
|
|
56
|
+
type?: string;
|
|
57
|
+
name?: string;
|
|
58
|
+
value?: string | number;
|
|
59
|
+
checked?: boolean;
|
|
60
|
+
selected?: boolean;
|
|
61
|
+
disabled?: boolean | null;
|
|
62
|
+
readonly?: boolean;
|
|
63
|
+
required?: boolean;
|
|
64
|
+
placeholder?: string;
|
|
65
|
+
maxlength?: number | string;
|
|
66
|
+
minlength?: number | string;
|
|
67
|
+
min?: number | string;
|
|
68
|
+
max?: number | string;
|
|
69
|
+
step?: number | string;
|
|
70
|
+
pattern?: string;
|
|
71
|
+
autocomplete?: string;
|
|
72
|
+
autofocus?: boolean;
|
|
73
|
+
multiple?: boolean;
|
|
74
|
+
accept?: string;
|
|
75
|
+
for?: string;
|
|
76
|
+
action?: string;
|
|
77
|
+
method?: string;
|
|
78
|
+
enctype?: string;
|
|
79
|
+
novalidate?: boolean;
|
|
80
|
+
form?: string;
|
|
81
|
+
|
|
82
|
+
// Table
|
|
83
|
+
colspan?: number | string;
|
|
84
|
+
rowspan?: number | string;
|
|
85
|
+
scope?: string;
|
|
86
|
+
|
|
87
|
+
// Content
|
|
88
|
+
contenteditable?: boolean | string;
|
|
89
|
+
draggable?: boolean | string;
|
|
90
|
+
spellcheck?: boolean | string;
|
|
91
|
+
lang?: string;
|
|
92
|
+
dir?: string;
|
|
93
|
+
translate?: string;
|
|
94
|
+
|
|
95
|
+
// Meta / script
|
|
96
|
+
charset?: string;
|
|
97
|
+
content?: string;
|
|
98
|
+
'http-equiv'?: string;
|
|
99
|
+
defer?: boolean;
|
|
100
|
+
async?: boolean;
|
|
101
|
+
crossorigin?: string;
|
|
102
|
+
integrity?: string;
|
|
103
|
+
|
|
104
|
+
// Mouse events
|
|
105
|
+
onclick?: ((e: MouseEvent) => void) | null;
|
|
106
|
+
ondblclick?: ((e: MouseEvent) => void) | null;
|
|
107
|
+
onmousedown?: ((e: MouseEvent) => void) | null;
|
|
108
|
+
onmouseup?: ((e: MouseEvent) => void) | null;
|
|
109
|
+
onmousemove?: ((e: MouseEvent) => void) | null;
|
|
110
|
+
onmouseenter?: ((e: MouseEvent) => void) | null;
|
|
111
|
+
onmouseleave?: ((e: MouseEvent) => void) | null;
|
|
112
|
+
onmouseover?: ((e: MouseEvent) => void) | null;
|
|
113
|
+
onmouseout?: ((e: MouseEvent) => void) | null;
|
|
114
|
+
oncontextmenu?: ((e: MouseEvent) => void) | null;
|
|
115
|
+
|
|
116
|
+
// Pointer events
|
|
117
|
+
onpointerdown?: ((e: PointerEvent) => void) | null;
|
|
118
|
+
onpointerup?: ((e: PointerEvent) => void) | null;
|
|
119
|
+
onpointermove?: ((e: PointerEvent) => void) | null;
|
|
120
|
+
onpointerenter?: ((e: PointerEvent) => void) | null;
|
|
121
|
+
onpointerleave?: ((e: PointerEvent) => void) | null;
|
|
122
|
+
onpointerover?: ((e: PointerEvent) => void) | null;
|
|
123
|
+
onpointerout?: ((e: PointerEvent) => void) | null;
|
|
124
|
+
onpointercancel?: ((e: PointerEvent) => void) | null;
|
|
125
|
+
|
|
126
|
+
// Touch events
|
|
127
|
+
ontouchstart?: ((e: TouchEvent) => void) | null;
|
|
128
|
+
ontouchmove?: ((e: TouchEvent) => void) | null;
|
|
129
|
+
ontouchend?: ((e: TouchEvent) => void) | null;
|
|
130
|
+
ontouchcancel?: ((e: TouchEvent) => void) | null;
|
|
131
|
+
|
|
132
|
+
// Keyboard events
|
|
133
|
+
onkeydown?: ((e: KeyboardEvent) => void) | null;
|
|
134
|
+
onkeyup?: ((e: KeyboardEvent) => void) | null;
|
|
135
|
+
|
|
136
|
+
// Focus events
|
|
137
|
+
onfocus?: ((e: FocusEvent) => void) | null;
|
|
138
|
+
onblur?: ((e: FocusEvent) => void) | null;
|
|
139
|
+
onfocusin?: ((e: FocusEvent) => void) | null;
|
|
140
|
+
onfocusout?: ((e: FocusEvent) => void) | null;
|
|
141
|
+
|
|
142
|
+
// Input events
|
|
143
|
+
oninput?: ((e: Event) => void) | null;
|
|
144
|
+
onchange?: ((e: Event) => void) | null;
|
|
145
|
+
onsubmit?: ((e: Event) => void) | null;
|
|
146
|
+
onreset?: ((e: Event) => void) | null;
|
|
147
|
+
oninvalid?: ((e: Event) => void) | null;
|
|
148
|
+
onselect?: ((e: Event) => void) | null;
|
|
149
|
+
|
|
150
|
+
// Drag events
|
|
151
|
+
ondrag?: ((e: DragEvent) => void) | null;
|
|
152
|
+
ondragstart?: ((e: DragEvent) => void) | null;
|
|
153
|
+
ondragend?: ((e: DragEvent) => void) | null;
|
|
154
|
+
ondragover?: ((e: DragEvent) => void) | null;
|
|
155
|
+
ondragenter?: ((e: DragEvent) => void) | null;
|
|
156
|
+
ondragleave?: ((e: DragEvent) => void) | null;
|
|
157
|
+
ondrop?: ((e: DragEvent) => void) | null;
|
|
158
|
+
|
|
159
|
+
// Scroll / resize
|
|
160
|
+
onscroll?: ((e: Event) => void) | null;
|
|
161
|
+
onresize?: ((e: Event) => void) | null;
|
|
162
|
+
onwheel?: ((e: WheelEvent) => void) | null;
|
|
163
|
+
|
|
164
|
+
// Media events
|
|
165
|
+
onplay?: ((e: Event) => void) | null;
|
|
166
|
+
onpause?: ((e: Event) => void) | null;
|
|
167
|
+
onended?: ((e: Event) => void) | null;
|
|
168
|
+
onloadeddata?: ((e: Event) => void) | null;
|
|
169
|
+
ontimeupdate?: ((e: Event) => void) | null;
|
|
170
|
+
onvolumechange?: ((e: Event) => void) | null;
|
|
171
|
+
onerror?: ((e: Event) => void) | null;
|
|
172
|
+
onload?: ((e: Event) => void) | null;
|
|
173
|
+
onabort?: ((e: Event) => void) | null;
|
|
174
|
+
|
|
175
|
+
// Animation / transition
|
|
176
|
+
onanimationstart?: ((e: AnimationEvent) => void) | null;
|
|
177
|
+
onanimationend?: ((e: AnimationEvent) => void) | null;
|
|
178
|
+
onanimationiteration?: ((e: AnimationEvent) => void) | null;
|
|
179
|
+
ontransitionend?: ((e: TransitionEvent) => void) | null;
|
|
180
|
+
ontransitionstart?: ((e: TransitionEvent) => void) | null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** SVG-specific attributes */
|
|
184
|
+
interface MxSVGAttrs {
|
|
185
|
+
viewBox?: string;
|
|
186
|
+
xmlns?: string;
|
|
187
|
+
fill?: string;
|
|
188
|
+
stroke?: string;
|
|
189
|
+
'stroke-width'?: string | number;
|
|
190
|
+
'stroke-linecap'?: 'butt' | 'round' | 'square';
|
|
191
|
+
'stroke-linejoin'?: 'miter' | 'round' | 'bevel';
|
|
192
|
+
'stroke-dasharray'?: string;
|
|
193
|
+
'stroke-dashoffset'?: string | number;
|
|
194
|
+
'stroke-opacity'?: string | number;
|
|
195
|
+
'fill-opacity'?: string | number;
|
|
196
|
+
'fill-rule'?: 'nonzero' | 'evenodd';
|
|
197
|
+
opacity?: string | number;
|
|
198
|
+
transform?: string;
|
|
199
|
+
d?: string;
|
|
200
|
+
points?: string;
|
|
201
|
+
cx?: string | number;
|
|
202
|
+
cy?: string | number;
|
|
203
|
+
r?: string | number;
|
|
204
|
+
rx?: string | number;
|
|
205
|
+
ry?: string | number;
|
|
206
|
+
x?: string | number;
|
|
207
|
+
y?: string | number;
|
|
208
|
+
x1?: string | number;
|
|
209
|
+
y1?: string | number;
|
|
210
|
+
x2?: string | number;
|
|
211
|
+
y2?: string | number;
|
|
212
|
+
dx?: string | number;
|
|
213
|
+
dy?: string | number;
|
|
214
|
+
'text-anchor'?: string;
|
|
215
|
+
'dominant-baseline'?: string;
|
|
216
|
+
'font-size'?: string | number;
|
|
217
|
+
'font-family'?: string;
|
|
218
|
+
'font-weight'?: string | number;
|
|
219
|
+
preserveAspectRatio?: string;
|
|
220
|
+
'clip-path'?: string;
|
|
221
|
+
mask?: string;
|
|
222
|
+
filter?: string;
|
|
223
|
+
'marker-start'?: string;
|
|
224
|
+
'marker-mid'?: string;
|
|
225
|
+
'marker-end'?: string;
|
|
226
|
+
gradientUnits?: string;
|
|
227
|
+
patternUnits?: string;
|
|
228
|
+
offset?: string | number;
|
|
229
|
+
'stop-color'?: string;
|
|
230
|
+
'stop-opacity'?: string | number;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Full attribute type. Supports:
|
|
235
|
+
* - Standard HTML/SVG attributes (autocomplete)
|
|
236
|
+
* - `'.prop': value` — sets element property directly
|
|
237
|
+
* - `onclick: fn` — event handler as property (auto-cleaned)
|
|
238
|
+
* - `name: null | false` — removes attribute
|
|
239
|
+
* - `name: true` — sets empty attribute
|
|
240
|
+
* - `[key: string]: any` — custom attributes, data-*, aria-*
|
|
241
|
+
*/
|
|
242
|
+
type MxAttrs = MxHTMLAttrs & MxSVGAttrs & {
|
|
243
|
+
[key: string]: any;
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
// ---------------------------------------------------------------------------
|
|
247
|
+
// Component definition
|
|
248
|
+
// ---------------------------------------------------------------------------
|
|
249
|
+
|
|
250
|
+
/** Object passed to define() to register a component */
|
|
251
|
+
interface MxComponentDefinition {
|
|
252
|
+
/**
|
|
253
|
+
* Render function. Called with merged $state + incoming props.
|
|
254
|
+
* `this` is the component element.
|
|
255
|
+
* Return a single MxDescription or an array of MxChild.
|
|
256
|
+
*/
|
|
257
|
+
$?(this: MxElement, props: Record<string, any>): MxChild | MxChild[];
|
|
258
|
+
|
|
259
|
+
/** Any other properties are mixed into the created element */
|
|
260
|
+
[key: string]: any;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// ---------------------------------------------------------------------------
|
|
264
|
+
// Component element — an HTMLElement created by define()
|
|
265
|
+
// ---------------------------------------------------------------------------
|
|
266
|
+
|
|
267
|
+
interface MxElement extends HTMLElement {
|
|
268
|
+
/** Merged state object. Props passed to $() are Object.assign'd here. */
|
|
269
|
+
$state: Record<string, any>;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Update component: merges props into $state, calls render function,
|
|
273
|
+
* reconciles DOM. Returns this element.
|
|
274
|
+
*/
|
|
275
|
+
$(props?: Record<string, any>): this;
|
|
276
|
+
|
|
277
|
+
/** Internal tracking object (stamp system) */
|
|
278
|
+
_$: any;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// ---------------------------------------------------------------------------
|
|
282
|
+
// mx proxy — creates virtual descriptions for reconciliation
|
|
283
|
+
// ---------------------------------------------------------------------------
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Tag function signature: first arg is optional attrs object, rest are children.
|
|
287
|
+
* If first arg is not a plain Object (or is a DOM node), it's treated as a child.
|
|
288
|
+
*/
|
|
289
|
+
type MxTagFn = (attrs?: MxAttrs | MxChild, ...children: MxChild[]) => MxDescription;
|
|
290
|
+
|
|
291
|
+
/** Tag functions for known HTML elements */
|
|
292
|
+
interface MxHTMLTags {
|
|
293
|
+
// Document structure
|
|
294
|
+
html: MxTagFn;
|
|
295
|
+
head: MxTagFn;
|
|
296
|
+
body: MxTagFn;
|
|
297
|
+
|
|
298
|
+
// Sections
|
|
299
|
+
div: MxTagFn;
|
|
300
|
+
span: MxTagFn;
|
|
301
|
+
p: MxTagFn;
|
|
302
|
+
section: MxTagFn;
|
|
303
|
+
article: MxTagFn;
|
|
304
|
+
aside: MxTagFn;
|
|
305
|
+
header: MxTagFn;
|
|
306
|
+
footer: MxTagFn;
|
|
307
|
+
main: MxTagFn;
|
|
308
|
+
nav: MxTagFn;
|
|
309
|
+
|
|
310
|
+
// Headings
|
|
311
|
+
h1: MxTagFn;
|
|
312
|
+
h2: MxTagFn;
|
|
313
|
+
h3: MxTagFn;
|
|
314
|
+
h4: MxTagFn;
|
|
315
|
+
h5: MxTagFn;
|
|
316
|
+
h6: MxTagFn;
|
|
317
|
+
|
|
318
|
+
// Text / inline
|
|
319
|
+
a: MxTagFn;
|
|
320
|
+
strong: MxTagFn;
|
|
321
|
+
em: MxTagFn;
|
|
322
|
+
b: MxTagFn;
|
|
323
|
+
i: MxTagFn;
|
|
324
|
+
u: MxTagFn;
|
|
325
|
+
s: MxTagFn;
|
|
326
|
+
small: MxTagFn;
|
|
327
|
+
sub: MxTagFn;
|
|
328
|
+
sup: MxTagFn;
|
|
329
|
+
mark: MxTagFn;
|
|
330
|
+
code: MxTagFn;
|
|
331
|
+
pre: MxTagFn;
|
|
332
|
+
kbd: MxTagFn;
|
|
333
|
+
abbr: MxTagFn;
|
|
334
|
+
cite: MxTagFn;
|
|
335
|
+
q: MxTagFn;
|
|
336
|
+
time: MxTagFn;
|
|
337
|
+
br: MxTagFn;
|
|
338
|
+
hr: MxTagFn;
|
|
339
|
+
wbr: MxTagFn;
|
|
340
|
+
|
|
341
|
+
// Lists
|
|
342
|
+
ul: MxTagFn;
|
|
343
|
+
ol: MxTagFn;
|
|
344
|
+
li: MxTagFn;
|
|
345
|
+
dl: MxTagFn;
|
|
346
|
+
dt: MxTagFn;
|
|
347
|
+
dd: MxTagFn;
|
|
348
|
+
|
|
349
|
+
// Table
|
|
350
|
+
table: MxTagFn;
|
|
351
|
+
thead: MxTagFn;
|
|
352
|
+
tbody: MxTagFn;
|
|
353
|
+
tfoot: MxTagFn;
|
|
354
|
+
tr: MxTagFn;
|
|
355
|
+
th: MxTagFn;
|
|
356
|
+
td: MxTagFn;
|
|
357
|
+
caption: MxTagFn;
|
|
358
|
+
colgroup: MxTagFn;
|
|
359
|
+
col: MxTagFn;
|
|
360
|
+
|
|
361
|
+
// Forms
|
|
362
|
+
form: MxTagFn;
|
|
363
|
+
input: MxTagFn;
|
|
364
|
+
textarea: MxTagFn;
|
|
365
|
+
select: MxTagFn;
|
|
366
|
+
option: MxTagFn;
|
|
367
|
+
optgroup: MxTagFn;
|
|
368
|
+
button: MxTagFn;
|
|
369
|
+
label: MxTagFn;
|
|
370
|
+
fieldset: MxTagFn;
|
|
371
|
+
legend: MxTagFn;
|
|
372
|
+
datalist: MxTagFn;
|
|
373
|
+
output: MxTagFn;
|
|
374
|
+
progress: MxTagFn;
|
|
375
|
+
meter: MxTagFn;
|
|
376
|
+
|
|
377
|
+
// Media
|
|
378
|
+
img: MxTagFn;
|
|
379
|
+
picture: MxTagFn;
|
|
380
|
+
source: MxTagFn;
|
|
381
|
+
video: MxTagFn;
|
|
382
|
+
audio: MxTagFn;
|
|
383
|
+
track: MxTagFn;
|
|
384
|
+
canvas: MxTagFn;
|
|
385
|
+
iframe: MxTagFn;
|
|
386
|
+
object: MxTagFn;
|
|
387
|
+
embed: MxTagFn;
|
|
388
|
+
|
|
389
|
+
// SVG
|
|
390
|
+
svg: MxTagFn;
|
|
391
|
+
path: MxTagFn;
|
|
392
|
+
circle: MxTagFn;
|
|
393
|
+
ellipse: MxTagFn;
|
|
394
|
+
line: MxTagFn;
|
|
395
|
+
polyline: MxTagFn;
|
|
396
|
+
polygon: MxTagFn;
|
|
397
|
+
rect: MxTagFn;
|
|
398
|
+
text: MxTagFn;
|
|
399
|
+
tspan: MxTagFn;
|
|
400
|
+
g: MxTagFn;
|
|
401
|
+
defs: MxTagFn;
|
|
402
|
+
use: MxTagFn;
|
|
403
|
+
symbol: MxTagFn;
|
|
404
|
+
clipPath: MxTagFn;
|
|
405
|
+
mask: MxTagFn;
|
|
406
|
+
pattern: MxTagFn;
|
|
407
|
+
image: MxTagFn;
|
|
408
|
+
foreignObject: MxTagFn;
|
|
409
|
+
linearGradient: MxTagFn;
|
|
410
|
+
radialGradient: MxTagFn;
|
|
411
|
+
stop: MxTagFn;
|
|
412
|
+
filter: MxTagFn;
|
|
413
|
+
feGaussianBlur: MxTagFn;
|
|
414
|
+
feOffset: MxTagFn;
|
|
415
|
+
feMerge: MxTagFn;
|
|
416
|
+
feMergeNode: MxTagFn;
|
|
417
|
+
feBlend: MxTagFn;
|
|
418
|
+
feColorMatrix: MxTagFn;
|
|
419
|
+
animate: MxTagFn;
|
|
420
|
+
animateTransform: MxTagFn;
|
|
421
|
+
|
|
422
|
+
// Interactive
|
|
423
|
+
details: MxTagFn;
|
|
424
|
+
summary: MxTagFn;
|
|
425
|
+
dialog: MxTagFn;
|
|
426
|
+
menu: MxTagFn;
|
|
427
|
+
|
|
428
|
+
// Misc
|
|
429
|
+
template: MxTagFn;
|
|
430
|
+
script: MxTagFn;
|
|
431
|
+
style: MxTagFn;
|
|
432
|
+
link: MxTagFn;
|
|
433
|
+
meta: MxTagFn;
|
|
434
|
+
noscript: MxTagFn;
|
|
435
|
+
slot: MxTagFn;
|
|
436
|
+
blockquote: MxTagFn;
|
|
437
|
+
figure: MxTagFn;
|
|
438
|
+
figcaption: MxTagFn;
|
|
439
|
+
address: MxTagFn;
|
|
440
|
+
data: MxTagFn;
|
|
441
|
+
map: MxTagFn;
|
|
442
|
+
area: MxTagFn;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* `mx` — creates virtual descriptions for render reconciliation.
|
|
447
|
+
*
|
|
448
|
+
* CamelCase auto-converts to kebab-case:
|
|
449
|
+
* `mx.priceChart()` → `<price-chart>`
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* mx.div({ class: 'card' }, mx.h2('Title'), mx.p('Body'))
|
|
453
|
+
* mx.input({ type: 'text', oninput: e => console.log(e.target.value) })
|
|
454
|
+
* mx.myComponent({ count: 5 })
|
|
455
|
+
*/
|
|
456
|
+
interface MxProxy extends MxHTMLTags {
|
|
457
|
+
/** Any tag name — CamelCase converts to kebab-case */
|
|
458
|
+
[tag: string]: MxTagFn;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// ---------------------------------------------------------------------------
|
|
462
|
+
// dom proxy — creates real HTMLElements
|
|
463
|
+
// ---------------------------------------------------------------------------
|
|
464
|
+
|
|
465
|
+
type DomTagFn<T extends Element = Element> = (attrs?: MxAttrs | MxChild, ...children: MxChild[]) => T;
|
|
466
|
+
|
|
467
|
+
/** Tag functions for known HTML elements returning proper element types */
|
|
468
|
+
interface DomHTMLTags {
|
|
469
|
+
// Sections
|
|
470
|
+
div: DomTagFn<HTMLDivElement>;
|
|
471
|
+
span: DomTagFn<HTMLSpanElement>;
|
|
472
|
+
p: DomTagFn<HTMLParagraphElement>;
|
|
473
|
+
section: DomTagFn<HTMLElement>;
|
|
474
|
+
article: DomTagFn<HTMLElement>;
|
|
475
|
+
aside: DomTagFn<HTMLElement>;
|
|
476
|
+
header: DomTagFn<HTMLElement>;
|
|
477
|
+
footer: DomTagFn<HTMLElement>;
|
|
478
|
+
main: DomTagFn<HTMLElement>;
|
|
479
|
+
nav: DomTagFn<HTMLElement>;
|
|
480
|
+
|
|
481
|
+
// Headings
|
|
482
|
+
h1: DomTagFn<HTMLHeadingElement>;
|
|
483
|
+
h2: DomTagFn<HTMLHeadingElement>;
|
|
484
|
+
h3: DomTagFn<HTMLHeadingElement>;
|
|
485
|
+
h4: DomTagFn<HTMLHeadingElement>;
|
|
486
|
+
h5: DomTagFn<HTMLHeadingElement>;
|
|
487
|
+
h6: DomTagFn<HTMLHeadingElement>;
|
|
488
|
+
|
|
489
|
+
// Text / inline
|
|
490
|
+
a: DomTagFn<HTMLAnchorElement>;
|
|
491
|
+
strong: DomTagFn<HTMLElement>;
|
|
492
|
+
em: DomTagFn<HTMLElement>;
|
|
493
|
+
b: DomTagFn<HTMLElement>;
|
|
494
|
+
i: DomTagFn<HTMLElement>;
|
|
495
|
+
code: DomTagFn<HTMLElement>;
|
|
496
|
+
pre: DomTagFn<HTMLPreElement>;
|
|
497
|
+
br: DomTagFn<HTMLBRElement>;
|
|
498
|
+
hr: DomTagFn<HTMLHRElement>;
|
|
499
|
+
|
|
500
|
+
// Lists
|
|
501
|
+
ul: DomTagFn<HTMLUListElement>;
|
|
502
|
+
ol: DomTagFn<HTMLOListElement>;
|
|
503
|
+
li: DomTagFn<HTMLLIElement>;
|
|
504
|
+
dl: DomTagFn<HTMLDListElement>;
|
|
505
|
+
|
|
506
|
+
// Table
|
|
507
|
+
table: DomTagFn<HTMLTableElement>;
|
|
508
|
+
thead: DomTagFn<HTMLTableSectionElement>;
|
|
509
|
+
tbody: DomTagFn<HTMLTableSectionElement>;
|
|
510
|
+
tfoot: DomTagFn<HTMLTableSectionElement>;
|
|
511
|
+
tr: DomTagFn<HTMLTableRowElement>;
|
|
512
|
+
th: DomTagFn<HTMLTableCellElement>;
|
|
513
|
+
td: DomTagFn<HTMLTableCellElement>;
|
|
514
|
+
caption: DomTagFn<HTMLTableCaptionElement>;
|
|
515
|
+
|
|
516
|
+
// Forms
|
|
517
|
+
form: DomTagFn<HTMLFormElement>;
|
|
518
|
+
input: DomTagFn<HTMLInputElement>;
|
|
519
|
+
textarea: DomTagFn<HTMLTextAreaElement>;
|
|
520
|
+
select: DomTagFn<HTMLSelectElement>;
|
|
521
|
+
option: DomTagFn<HTMLOptionElement>;
|
|
522
|
+
optgroup: DomTagFn<HTMLOptGroupElement>;
|
|
523
|
+
button: DomTagFn<HTMLButtonElement>;
|
|
524
|
+
label: DomTagFn<HTMLLabelElement>;
|
|
525
|
+
fieldset: DomTagFn<HTMLFieldSetElement>;
|
|
526
|
+
legend: DomTagFn<HTMLLegendElement>;
|
|
527
|
+
output: DomTagFn<HTMLOutputElement>;
|
|
528
|
+
progress: DomTagFn<HTMLProgressElement>;
|
|
529
|
+
meter: DomTagFn<HTMLMeterElement>;
|
|
530
|
+
|
|
531
|
+
// Media
|
|
532
|
+
img: DomTagFn<HTMLImageElement>;
|
|
533
|
+
picture: DomTagFn<HTMLPictureElement>;
|
|
534
|
+
source: DomTagFn<HTMLSourceElement>;
|
|
535
|
+
video: DomTagFn<HTMLVideoElement>;
|
|
536
|
+
audio: DomTagFn<HTMLAudioElement>;
|
|
537
|
+
canvas: DomTagFn<HTMLCanvasElement>;
|
|
538
|
+
iframe: DomTagFn<HTMLIFrameElement>;
|
|
539
|
+
|
|
540
|
+
// SVG
|
|
541
|
+
svg: DomTagFn<SVGSVGElement>;
|
|
542
|
+
path: DomTagFn<SVGPathElement>;
|
|
543
|
+
circle: DomTagFn<SVGCircleElement>;
|
|
544
|
+
ellipse: DomTagFn<SVGEllipseElement>;
|
|
545
|
+
line: DomTagFn<SVGLineElement>;
|
|
546
|
+
polyline: DomTagFn<SVGPolylineElement>;
|
|
547
|
+
polygon: DomTagFn<SVGPolygonElement>;
|
|
548
|
+
rect: DomTagFn<SVGRectElement>;
|
|
549
|
+
text: DomTagFn<SVGTextElement>;
|
|
550
|
+
g: DomTagFn<SVGGElement>;
|
|
551
|
+
defs: DomTagFn<SVGDefsElement>;
|
|
552
|
+
use: DomTagFn<SVGUseElement>;
|
|
553
|
+
symbol: DomTagFn<SVGSymbolElement>;
|
|
554
|
+
clipPath: DomTagFn<SVGClipPathElement>;
|
|
555
|
+
image: DomTagFn<SVGImageElement>;
|
|
556
|
+
foreignObject: DomTagFn<SVGForeignObjectElement>;
|
|
557
|
+
linearGradient: DomTagFn<SVGLinearGradientElement>;
|
|
558
|
+
radialGradient: DomTagFn<SVGRadialGradientElement>;
|
|
559
|
+
stop: DomTagFn<SVGStopElement>;
|
|
560
|
+
filter: DomTagFn<SVGFilterElement>;
|
|
561
|
+
animate: DomTagFn<SVGAnimateElement>;
|
|
562
|
+
|
|
563
|
+
// Interactive
|
|
564
|
+
details: DomTagFn<HTMLDetailsElement>;
|
|
565
|
+
dialog: DomTagFn<HTMLDialogElement>;
|
|
566
|
+
menu: DomTagFn<HTMLMenuElement>;
|
|
567
|
+
|
|
568
|
+
// Misc
|
|
569
|
+
template: DomTagFn<HTMLTemplateElement>;
|
|
570
|
+
script: DomTagFn<HTMLScriptElement>;
|
|
571
|
+
style: DomTagFn<HTMLStyleElement>;
|
|
572
|
+
link: DomTagFn<HTMLLinkElement>;
|
|
573
|
+
slot: DomTagFn<HTMLSlotElement>;
|
|
574
|
+
blockquote: DomTagFn<HTMLQuoteElement>;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* `dom` — creates real HTMLElements with attributes and children applied.
|
|
579
|
+
*
|
|
580
|
+
* CamelCase auto-converts to kebab-case:
|
|
581
|
+
* `dom.priceChart()` → `<price-chart>` HTMLElement
|
|
582
|
+
*
|
|
583
|
+
* For defined components, `dom.name({ props })` calls `$()` and returns the element.
|
|
584
|
+
*
|
|
585
|
+
* @example
|
|
586
|
+
* let el = dom.div({ class: 'card' }, dom.h2('Title'))
|
|
587
|
+
* document.body.append(el)
|
|
588
|
+
*
|
|
589
|
+
* let chart = dom.priceChart({ asset }) // component
|
|
590
|
+
* chart.$({ asset: newAsset }) // update later
|
|
591
|
+
*/
|
|
592
|
+
interface DomProxy extends DomHTMLTags {
|
|
593
|
+
/** Any tag name — CamelCase converts to kebab-case. Returns Element (or MxElement for components). */
|
|
594
|
+
[tag: string]: DomTagFn<Element>;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// ---------------------------------------------------------------------------
|
|
598
|
+
// define() — register a component
|
|
599
|
+
// ---------------------------------------------------------------------------
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Register a component by name. The `$` function becomes the render function.
|
|
603
|
+
* Name is lowercased — CamelCase in mx/dom auto-converts to kebab-case.
|
|
604
|
+
*
|
|
605
|
+
* @example
|
|
606
|
+
* define('counter', {
|
|
607
|
+
* $({ count = 0 }) {
|
|
608
|
+
* return [
|
|
609
|
+
* mx.button({ onclick: _ => this.$({ count: count + 1 }) }, '+'),
|
|
610
|
+
* mx.span(count)
|
|
611
|
+
* ]
|
|
612
|
+
* }
|
|
613
|
+
* })
|
|
614
|
+
*/
|
|
615
|
+
type MxDefine = (name: string, definition: MxComponentDefinition) => void;
|
|
616
|
+
|
|
617
|
+
// ---------------------------------------------------------------------------
|
|
618
|
+
// Element.prototype augmentations
|
|
619
|
+
// ---------------------------------------------------------------------------
|
|
620
|
+
|
|
621
|
+
declare global {
|
|
622
|
+
interface Element {
|
|
623
|
+
/**
|
|
624
|
+
* Reconcile children left-to-right against existing DOM.
|
|
625
|
+
* Accepts mx descriptions, real DOM nodes, strings, numbers, null, false.
|
|
626
|
+
* Excess old nodes are removed. Returns `this`.
|
|
627
|
+
*/
|
|
628
|
+
render(...children: MxChild[]): this;
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Apply an attributes object to this element.
|
|
632
|
+
* Supports `.prop`, event handlers, null/false removal, boolean attrs.
|
|
633
|
+
*/
|
|
634
|
+
$attrs(attrs: MxAttrs): this;
|
|
635
|
+
|
|
636
|
+
/** Alias for removeAttribute (used internally) */
|
|
637
|
+
R(name: string): void;
|
|
638
|
+
|
|
639
|
+
/** Component state — merged via Object.assign on each $() call */
|
|
640
|
+
$state: Record<string, any>;
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Update component: merge props into $state, re-render.
|
|
644
|
+
* Only available on elements created from defined components.
|
|
645
|
+
*/
|
|
646
|
+
$(props?: Record<string, any>): this;
|
|
647
|
+
|
|
648
|
+
/** Internal stamp tracking (do not use directly) */
|
|
649
|
+
_$: any;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/** mx — virtual description proxy */
|
|
653
|
+
var mx: MxProxy;
|
|
654
|
+
|
|
655
|
+
/** dom — real element proxy */
|
|
656
|
+
var dom: DomProxy;
|
|
657
|
+
|
|
658
|
+
/** Register a component */
|
|
659
|
+
var define: MxDefine;
|
|
660
|
+
|
|
661
|
+
/** Component registry — maps lowercase names to definitions */
|
|
662
|
+
var components: Record<string, MxComponentDefinition>;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// ---------------------------------------------------------------------------
|
|
666
|
+
// ESM exports (for import { mx, dom, define, components } from '@tltdsh/mx')
|
|
667
|
+
// ---------------------------------------------------------------------------
|
|
668
|
+
|
|
669
|
+
export declare const mx: MxProxy;
|
|
670
|
+
export declare const dom: DomProxy;
|
|
671
|
+
export declare const define: MxDefine;
|
|
672
|
+
export declare const components: Record<string, MxComponentDefinition>;
|
|
673
|
+
|
|
674
|
+
export type {
|
|
675
|
+
MxDescription,
|
|
676
|
+
MxChild,
|
|
677
|
+
MxAttrs,
|
|
678
|
+
MxHTMLAttrs,
|
|
679
|
+
MxSVGAttrs,
|
|
680
|
+
MxComponentDefinition,
|
|
681
|
+
MxElement,
|
|
682
|
+
MxTagFn,
|
|
683
|
+
DomTagFn,
|
|
684
|
+
MxProxy,
|
|
685
|
+
DomProxy,
|
|
686
|
+
MxDefine,
|
|
687
|
+
};
|
package/mx.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var mx, dom, define, components;
|
|
2
|
+
!function(e,t,n){n=components={},define=(e,t={})=>{if(t.$){let e=t.$;t.$=function(t){let n=e.call(this,i(this.$state||={},t));return n._?this.render(n):this.render(...n)}}n[e=e.toLowerCase()]=t};let s={value:1,checked:1,selected:1},i=Object.assign,a="http://www.w3.org/2000/svg",o=(t,s)=>{if(t=="svg"|s)return e.createElementNS(a,t);let o=e.createElement(t),r=n[t];return r&&i(o,r),o};t.R=t.removeAttribute,t.$attrs=function(e,t,n){for(t in e)n=e[t],t[0]=="."?this[t.slice(1)]=n:n?.call?this[t]=n:n==null|n===!1?this.R(t):this.setAttribute(t,n==!0?"":n);return this},t.render=function(...i){let t=this,e=t.firstChild,n=t.namespaceURI==a;for(let a of i){if(a==null|a===!1)continue;let r,c,l;if(a._)[r,c,l]=a;else if(a.nodeType){e!=a&&(e?e.replaceWith(a):t.append(a)),e=a.nextSibling;continue}if(e)r?e.localName!=r&&e.replaceWith(e=o(r,n)):e.localName?e.replaceWith(e=new Text(a)):e.nodeValue!=""+a&&(e.nodeValue=""+a);else if(r)t.append(e=o(r,n));else{t.append(a);continue}if(r){let t=c;if(e.$)e._$=0;else{let n=e._$||={},o=n.__||={},i=n._=-~n._;for(let o in n){if(o[0]=="_")continue;(!t||!(o in c))&&(o[0]!="."&&(e.R(o),s[o]&&(e[o]="")),delete n[o])}if(t)for(let t in c){let a=c[t];if(a==n[t]){a?.call||s[t]?o[t]=i:t[0]=="."&&(o[t.slice(1)]=i);continue}t[0]=="."?(e[t.slice(1)]=a,o[t.slice(1)]=i,n[t]=a):a!=null&a!==!1?(a?.call?(e[t]=a,o[t]=i):(e.setAttribute(t,a),s[t]&&(e[t]=a,o[t]=i)),n[t]=a):(e.R(t),s[t]&&(e[t]=""),delete n[t])}for(let t in o)o[t]!=i&&(e[t]=null,delete o[t])}e.$?e.$.call(e,c):e.render(...l)}e=e.nextSibling}for(;e;){let t=e.nextSibling;e.remove(),e=t}return this};let l={},r=e=>new Proxy(e,{get:(t,n)=>e.bind(0,n)}),c=e=>(l[e]||=e.replace(/[A-Z]/g,"-$&").toLowerCase());mx=r((e,t,...n)=>{e=c(e);let s=t?.constructor==Object&&!t.nodeType?[e,t,n]:[e,null,[t,...n]];return s._=1,s}),dom=r((e,t,...n)=>{let s=o(c(e));if(t?.constructor==Object&&!t.nodeType){if(s.$)return s.$(t);s.$attrs(t)}else n=[t,...n];return s.render(...n),s})}(document,Element.prototype);
|
|
3
|
+
export { mx, dom, define, components };
|
package/package.json
CHANGED
|
@@ -1,27 +1,99 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tltdsh/mx",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Expressive UI library in 890 bytes for building high-end, enterprise-level applications. 4 globals, zero dependencies, no build step.",
|
|
5
5
|
"license": "0BSD",
|
|
6
6
|
"author": "tltdsh",
|
|
7
|
+
"homepage": "https://mxjs.dev",
|
|
7
8
|
|
|
8
9
|
"main": "mx.min.js",
|
|
9
|
-
"module": "mx.
|
|
10
|
+
"module": "mx.mjs",
|
|
11
|
+
"types": "mx.d.ts",
|
|
10
12
|
"exports": {
|
|
11
|
-
".":
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./mx.mjs",
|
|
15
|
+
"require": "./mx.min.js",
|
|
16
|
+
"types": "./mx.d.ts",
|
|
17
|
+
"default": "./mx.min.js"
|
|
18
|
+
}
|
|
12
19
|
},
|
|
13
20
|
"files": [
|
|
14
|
-
"mx.min.js"
|
|
21
|
+
"mx.min.js",
|
|
22
|
+
"mx.mjs",
|
|
23
|
+
"mx.d.ts",
|
|
24
|
+
"LICENSE"
|
|
15
25
|
],
|
|
26
|
+
"sideEffects": true,
|
|
16
27
|
"keywords": [
|
|
17
28
|
"ui",
|
|
18
29
|
"dom",
|
|
19
30
|
"framework",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
31
|
+
"library",
|
|
32
|
+
"engine",
|
|
33
|
+
"protocol",
|
|
34
|
+
"reactive",
|
|
35
|
+
"expressive",
|
|
36
|
+
"render",
|
|
37
|
+
"rendering",
|
|
38
|
+
"reconciliation",
|
|
39
|
+
"virtual-dom",
|
|
22
40
|
"components",
|
|
41
|
+
"component-library",
|
|
23
42
|
"custom-elements",
|
|
43
|
+
"web-components",
|
|
44
|
+
"enterprise",
|
|
45
|
+
"production",
|
|
46
|
+
"tiny",
|
|
47
|
+
"lightweight",
|
|
48
|
+
"minimal",
|
|
49
|
+
"small",
|
|
50
|
+
"micro",
|
|
51
|
+
"fast",
|
|
52
|
+
"performant",
|
|
53
|
+
"efficient",
|
|
54
|
+
"high-performance",
|
|
24
55
|
"no-dependencies",
|
|
25
|
-
"
|
|
56
|
+
"zero-dependencies",
|
|
57
|
+
"no-build",
|
|
58
|
+
"no-bundler",
|
|
59
|
+
"no-compile",
|
|
60
|
+
"no-jsx",
|
|
61
|
+
"no-virtual-dom",
|
|
62
|
+
"dom-first",
|
|
63
|
+
"dom-manipulation",
|
|
64
|
+
"svg",
|
|
65
|
+
"frontend",
|
|
66
|
+
"front-end",
|
|
67
|
+
"view",
|
|
68
|
+
"view-layer",
|
|
69
|
+
"template",
|
|
70
|
+
"templating",
|
|
71
|
+
"declarative",
|
|
72
|
+
"state-management",
|
|
73
|
+
"state",
|
|
74
|
+
"vanilla",
|
|
75
|
+
"vanilla-js",
|
|
76
|
+
"plain-js",
|
|
77
|
+
"browser",
|
|
78
|
+
"client-side",
|
|
79
|
+
"spa",
|
|
80
|
+
"single-page-app",
|
|
81
|
+
"web",
|
|
82
|
+
"webapp",
|
|
83
|
+
"web-app",
|
|
84
|
+
"html",
|
|
85
|
+
"javascript",
|
|
86
|
+
"js",
|
|
87
|
+
"ui-library",
|
|
88
|
+
"ui-framework",
|
|
89
|
+
"ui-engine",
|
|
90
|
+
"element",
|
|
91
|
+
"node",
|
|
92
|
+
"tree",
|
|
93
|
+
"diff",
|
|
94
|
+
"patch",
|
|
95
|
+
"proxy",
|
|
96
|
+
"keyed",
|
|
97
|
+
"keyed-list"
|
|
26
98
|
]
|
|
27
99
|
}
|