@tltdsh/mx 1.0.3 → 1.0.5
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 +22 -10
- package/mx.d.ts +20 -20
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
# mx.js
|
|
2
2
|
|
|
3
|
-
Expressive UI library in **
|
|
3
|
+
Expressive UI library in **862 bytes** (brotli) for building high-end, enterprise-level applications. 4 globals, zero dependencies, no build step.
|
|
4
4
|
|
|
5
5
|
[**Documentation**](https://mxjs.dev)
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
### CDN (recommended)
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<!-- jsDelivr (multi-CDN, recommended) -->
|
|
13
|
+
<script src="https://cdn.jsdelivr.net/npm/@tltdsh/mx"></script>
|
|
14
|
+
|
|
15
|
+
<!-- unpkg -->
|
|
16
|
+
<script src="https://unpkg.com/@tltdsh/mx"></script>
|
|
11
17
|
```
|
|
12
18
|
|
|
13
|
-
###
|
|
19
|
+
### Pinned version
|
|
14
20
|
|
|
15
21
|
```html
|
|
16
|
-
<script src="https://
|
|
22
|
+
<script src="https://cdn.jsdelivr.net/npm/@tltdsh/mx@1.0.3/mx.min.js"></script>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### npm / yarn / bun
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
npm i @tltdsh/mx
|
|
17
29
|
```
|
|
18
30
|
|
|
19
31
|
### ESM
|
|
@@ -26,7 +38,7 @@ import { mx, dom, define, components } from '@tltdsh/mx'
|
|
|
26
38
|
|
|
27
39
|
| Global | Returns | Use for |
|
|
28
40
|
|--------|---------|---------|
|
|
29
|
-
| `mx.tag(attrs?, ...children)` | Description array | Inside `render()`
|
|
41
|
+
| `mx.tag(attrs?, ...children)` | Description array | Inside `render()` - efficient reconciliation |
|
|
30
42
|
| `dom.tag(attrs?, ...children)` | HTMLElement | Persistent references, calling `.$()` later |
|
|
31
43
|
| `define(name, { $() {} })` | void | Register a component |
|
|
32
44
|
| `components` | object | Component registry |
|
|
@@ -168,7 +180,7 @@ let rowMap = new Map(
|
|
|
168
180
|
data.map(d => [d.id, dom.tableRow({ data: d })])
|
|
169
181
|
)
|
|
170
182
|
|
|
171
|
-
// Nodes move by identity
|
|
183
|
+
// Nodes move by identity - internal state preserved on reorder
|
|
172
184
|
container.render(...data.map(d => rowMap.get(d.id)))
|
|
173
185
|
```
|
|
174
186
|
|
|
@@ -178,8 +190,8 @@ container.render(...data.map(d => rowMap.get(d.id)))
|
|
|
178
190
|
- `dom.*` = real HTMLElements for persistent references
|
|
179
191
|
- `$()` always returns array of children
|
|
180
192
|
- `??=` protects `$state` from parent prop overwrites
|
|
181
|
-
- Never `addEventListener` inside `$()`
|
|
182
|
-
- Numbers auto-cast
|
|
193
|
+
- Never `addEventListener` inside `$()` - use direct property assignment
|
|
194
|
+
- Numbers auto-cast - no `String()` needed
|
|
183
195
|
- Use `_ =>` for unused arrow params
|
|
184
196
|
- `clearInterval(this._interval)` at top of `$()` for timers
|
|
185
197
|
- `this._cache ||= new Map` for persistent Maps
|
|
@@ -194,4 +206,4 @@ import { mx, dom, define, type MxChild, type MxAttrs } from '@tltdsh/mx'
|
|
|
194
206
|
|
|
195
207
|
## License
|
|
196
208
|
|
|
197
|
-
0BSD
|
|
209
|
+
0BSD - do whatever you want.
|
package/mx.d.ts
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// https://mxjs.dev
|
|
3
3
|
|
|
4
4
|
// ---------------------------------------------------------------------------
|
|
5
|
-
// Children
|
|
5
|
+
// Children - everything render() and mx/dom accept as child nodes
|
|
6
6
|
// ---------------------------------------------------------------------------
|
|
7
7
|
|
|
8
8
|
/** A description array returned by mx.*() calls */
|
|
9
9
|
interface MxDescription extends Array<any> {
|
|
10
|
-
/** Internal marker
|
|
10
|
+
/** Internal marker - distinguishes descriptions from plain arrays */
|
|
11
11
|
_: 1 | true;
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -233,11 +233,11 @@ interface MxSVGAttrs {
|
|
|
233
233
|
/**
|
|
234
234
|
* Full attribute type. Supports:
|
|
235
235
|
* - Standard HTML/SVG attributes (autocomplete)
|
|
236
|
-
* - `'.prop': value`
|
|
237
|
-
* - `onclick: fn`
|
|
238
|
-
* - `name: null | false`
|
|
239
|
-
* - `name: true`
|
|
240
|
-
* - `[key: string]: any`
|
|
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
241
|
*/
|
|
242
242
|
type MxAttrs = MxHTMLAttrs & MxSVGAttrs & {
|
|
243
243
|
[key: string]: any;
|
|
@@ -261,7 +261,7 @@ interface MxComponentDefinition {
|
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
// ---------------------------------------------------------------------------
|
|
264
|
-
// Component element
|
|
264
|
+
// Component element - an HTMLElement created by define()
|
|
265
265
|
// ---------------------------------------------------------------------------
|
|
266
266
|
|
|
267
267
|
interface MxElement extends HTMLElement {
|
|
@@ -279,7 +279,7 @@ interface MxElement extends HTMLElement {
|
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
// ---------------------------------------------------------------------------
|
|
282
|
-
// mx proxy
|
|
282
|
+
// mx proxy - creates virtual descriptions for reconciliation
|
|
283
283
|
// ---------------------------------------------------------------------------
|
|
284
284
|
|
|
285
285
|
/**
|
|
@@ -443,7 +443,7 @@ interface MxHTMLTags {
|
|
|
443
443
|
}
|
|
444
444
|
|
|
445
445
|
/**
|
|
446
|
-
* `mx`
|
|
446
|
+
* `mx` - creates virtual descriptions for render reconciliation.
|
|
447
447
|
*
|
|
448
448
|
* CamelCase auto-converts to kebab-case:
|
|
449
449
|
* `mx.priceChart()` → `<price-chart>`
|
|
@@ -454,12 +454,12 @@ interface MxHTMLTags {
|
|
|
454
454
|
* mx.myComponent({ count: 5 })
|
|
455
455
|
*/
|
|
456
456
|
interface MxProxy extends MxHTMLTags {
|
|
457
|
-
/** Any tag name
|
|
457
|
+
/** Any tag name - CamelCase converts to kebab-case */
|
|
458
458
|
[tag: string]: MxTagFn;
|
|
459
459
|
}
|
|
460
460
|
|
|
461
461
|
// ---------------------------------------------------------------------------
|
|
462
|
-
// dom proxy
|
|
462
|
+
// dom proxy - creates real HTMLElements
|
|
463
463
|
// ---------------------------------------------------------------------------
|
|
464
464
|
|
|
465
465
|
type DomTagFn<T extends Element = Element> = (attrs?: MxAttrs | MxChild, ...children: MxChild[]) => T;
|
|
@@ -575,7 +575,7 @@ interface DomHTMLTags {
|
|
|
575
575
|
}
|
|
576
576
|
|
|
577
577
|
/**
|
|
578
|
-
* `dom`
|
|
578
|
+
* `dom` - creates real HTMLElements with attributes and children applied.
|
|
579
579
|
*
|
|
580
580
|
* CamelCase auto-converts to kebab-case:
|
|
581
581
|
* `dom.priceChart()` → `<price-chart>` HTMLElement
|
|
@@ -590,17 +590,17 @@ interface DomHTMLTags {
|
|
|
590
590
|
* chart.$({ asset: newAsset }) // update later
|
|
591
591
|
*/
|
|
592
592
|
interface DomProxy extends DomHTMLTags {
|
|
593
|
-
/** Any tag name
|
|
593
|
+
/** Any tag name - CamelCase converts to kebab-case. Returns Element (or MxElement for components). */
|
|
594
594
|
[tag: string]: DomTagFn<Element>;
|
|
595
595
|
}
|
|
596
596
|
|
|
597
597
|
// ---------------------------------------------------------------------------
|
|
598
|
-
// define()
|
|
598
|
+
// define() - register a component
|
|
599
599
|
// ---------------------------------------------------------------------------
|
|
600
600
|
|
|
601
601
|
/**
|
|
602
602
|
* Register a component by name. The `$` function becomes the render function.
|
|
603
|
-
* Name is lowercased
|
|
603
|
+
* Name is lowercased - CamelCase in mx/dom auto-converts to kebab-case.
|
|
604
604
|
*
|
|
605
605
|
* @example
|
|
606
606
|
* define('counter', {
|
|
@@ -636,7 +636,7 @@ declare global {
|
|
|
636
636
|
/** Alias for removeAttribute (used internally) */
|
|
637
637
|
R(name: string): void;
|
|
638
638
|
|
|
639
|
-
/** Component state
|
|
639
|
+
/** Component state - merged via Object.assign on each $() call */
|
|
640
640
|
$state: Record<string, any>;
|
|
641
641
|
|
|
642
642
|
/**
|
|
@@ -649,16 +649,16 @@ declare global {
|
|
|
649
649
|
_$: any;
|
|
650
650
|
}
|
|
651
651
|
|
|
652
|
-
/** mx
|
|
652
|
+
/** mx - virtual description proxy */
|
|
653
653
|
var mx: MxProxy;
|
|
654
654
|
|
|
655
|
-
/** dom
|
|
655
|
+
/** dom - real element proxy */
|
|
656
656
|
var dom: DomProxy;
|
|
657
657
|
|
|
658
658
|
/** Register a component */
|
|
659
659
|
var define: MxDefine;
|
|
660
660
|
|
|
661
|
-
/** Component registry
|
|
661
|
+
/** Component registry - maps lowercase names to definitions */
|
|
662
662
|
var components: Record<string, MxComponentDefinition>;
|
|
663
663
|
}
|
|
664
664
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tltdsh/mx",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Expressive UI library in
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "Expressive UI library in 862 bytes for building high-end, enterprise-level applications. 4 globals, zero dependencies, no build step.",
|
|
5
5
|
"license": "0BSD",
|
|
6
6
|
"author": "tltdsh",
|
|
7
7
|
"homepage": "https://mxjs.dev",
|