@tltdsh/mx 1.3.1 → 1.4.0
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/AGENTS.md +6 -0
- package/CLAUDE.md +6 -0
- package/README.md +3 -3
- package/mx.d.ts +47 -41
- package/mx.min.js +1 -1
- package/mx.mjs +1 -1
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -124,6 +124,8 @@ __defineSetter__, __lookupGetter__, __lookupSetter__, __proto__
|
|
|
124
124
|
|
|
125
125
|
`mx.toString()` produces a broken description that throws `InvalidCharacterError` at `createElement` time. Also applies to `define('toString', ...)`.
|
|
126
126
|
|
|
127
|
+
Tag/component names only - **attribute** names are safe: the reconciler tracks attrs by own-key checks (`Object.hasOwn`), so `{ toString: 'x' }` sets and removes cleanly, and attrs objects with an own `constructor` key are still recognized as attrs.
|
|
128
|
+
|
|
127
129
|
---
|
|
128
130
|
|
|
129
131
|
## Checklist for New Components
|
|
@@ -251,6 +253,10 @@ Caveats vs `render()`: `$attrs` cannot clear event handlers (it calls `removeAtt
|
|
|
251
253
|
|
|
252
254
|
**Stamp system**: Event handlers set via `render()` attrs in render N but absent in render N+1 are auto-nullified. You never manually remove handlers.
|
|
253
255
|
|
|
256
|
+
**Custom events**: `on*` attrs only register listeners for spec-known handler properties (`onclick`, `oninput`, ...). A custom event type (`onping: fn`) is a silent expando - use `addEventListener` once (guarded) for custom events.
|
|
257
|
+
|
|
258
|
+
**Children-first ordering**: `render()` reconciles an element's children before applying its own attributes (load-bearing for `select.value`). Consequences: a child that dispatches an event synchronously during mount is missed by the parent's not-yet-attached handler, and a child reading a parent attribute during `$()` sees the previous render's value. Pass data via `$state`, dispatch after mount.
|
|
259
|
+
|
|
254
260
|
---
|
|
255
261
|
|
|
256
262
|
## Conditional Rendering
|
package/CLAUDE.md
CHANGED
|
@@ -124,6 +124,8 @@ __defineSetter__, __lookupGetter__, __lookupSetter__, __proto__
|
|
|
124
124
|
|
|
125
125
|
`mx.toString()` produces a broken description that throws `InvalidCharacterError` at `createElement` time. Also applies to `define('toString', ...)`.
|
|
126
126
|
|
|
127
|
+
Tag/component names only - **attribute** names are safe: the reconciler tracks attrs by own-key checks (`Object.hasOwn`), so `{ toString: 'x' }` sets and removes cleanly, and attrs objects with an own `constructor` key are still recognized as attrs.
|
|
128
|
+
|
|
127
129
|
---
|
|
128
130
|
|
|
129
131
|
## Checklist for New Components
|
|
@@ -251,6 +253,10 @@ Caveats vs `render()`: `$attrs` cannot clear event handlers (it calls `removeAtt
|
|
|
251
253
|
|
|
252
254
|
**Stamp system**: Event handlers set via `render()` attrs in render N but absent in render N+1 are auto-nullified. You never manually remove handlers.
|
|
253
255
|
|
|
256
|
+
**Custom events**: `on*` attrs only register listeners for spec-known handler properties (`onclick`, `oninput`, ...). A custom event type (`onping: fn`) is a silent expando - use `addEventListener` once (guarded) for custom events.
|
|
257
|
+
|
|
258
|
+
**Children-first ordering**: `render()` reconciles an element's children before applying its own attributes (load-bearing for `select.value`). Consequences: a child that dispatches an event synchronously during mount is missed by the parent's not-yet-attached handler, and a child reading a parent attribute during `$()` sees the previous render's value. Pass data via `$state`, dispatch after mount.
|
|
259
|
+
|
|
254
260
|
---
|
|
255
261
|
|
|
256
262
|
## Conditional Rendering
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# mx.js
|
|
2
2
|
|
|
3
|
-
Sub-1KB reactive DOM reconciliation engine for building massive platforms and user interfaces at scale. **
|
|
3
|
+
Sub-1KB reactive DOM reconciliation engine for building massive platforms and user interfaces at scale. **Under 1KB** brotli. 4 globals, zero dependencies, no virtual DOM, no build step. Small enough to fit in an AI context window.
|
|
4
4
|
|
|
5
5
|
**Full documentation & live playground: [mxjs.dev](https://mxjs.dev)**
|
|
6
6
|
|
|
@@ -21,7 +21,7 @@ Sub-1KB reactive DOM reconciliation engine for building massive platforms and us
|
|
|
21
21
|
### Pinned version
|
|
22
22
|
|
|
23
23
|
```html
|
|
24
|
-
<script src="https://cdn.jsdelivr.net/npm/@tltdsh/mx@1.
|
|
24
|
+
<script src="https://cdn.jsdelivr.net/npm/@tltdsh/mx@1.4.0/mx.min.js"></script>
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
### npm / yarn / bun
|
|
@@ -42,7 +42,7 @@ import { mx, dom, define, components } from '@tltdsh/mx'
|
|
|
42
42
|
const { mx, dom, define, components } = await import('https://cdn.jsdelivr.net/npm/@tltdsh/mx/mx.mjs')
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
Works in any modern browser,
|
|
45
|
+
Works in any modern browser, with or without a bundler - no install, one line. Browser runtimes only: the module reads `document` at evaluation time, so importing it under Node, Deno, or Bun throws `ReferenceError: document is not defined`.
|
|
46
46
|
|
|
47
47
|
## 4 Globals
|
|
48
48
|
|
package/mx.d.ts
CHANGED
|
@@ -114,18 +114,36 @@ interface MxHTMLAttrs {
|
|
|
114
114
|
'aria-errormessage'?: string;
|
|
115
115
|
|
|
116
116
|
// ARIA states cluster (accessibility)
|
|
117
|
+
// NOTE: `false` REMOVES an attribute (`removeAttribute`), it does not write "false".
|
|
118
|
+
// For the four states below, absent is NOT the same as "false" to a screen reader
|
|
119
|
+
// (absent aria-expanded means "not expandable", absent aria-pressed means "not a
|
|
120
|
+
// toggle button"), so they only accept the explicit strings. Pass String(flag).
|
|
117
121
|
'aria-hidden'?: boolean | 'true' | 'false';
|
|
118
|
-
'aria-expanded'?:
|
|
122
|
+
'aria-expanded'?: 'true' | 'false';
|
|
119
123
|
'aria-disabled'?: boolean | 'true' | 'false';
|
|
120
|
-
'aria-selected'?:
|
|
121
|
-
'aria-checked'?:
|
|
122
|
-
'aria-pressed'?:
|
|
124
|
+
'aria-selected'?: 'true' | 'false';
|
|
125
|
+
'aria-checked'?: 'true' | 'false' | 'mixed';
|
|
126
|
+
'aria-pressed'?: 'true' | 'false' | 'mixed';
|
|
123
127
|
|
|
124
128
|
// ARIA relations cluster (accessibility)
|
|
125
129
|
'aria-controls'?: string;
|
|
126
130
|
'aria-owns'?: string;
|
|
127
131
|
'aria-haspopup'?: boolean | 'true' | 'false' | 'menu' | 'listbox' | 'tree' | 'grid' | 'dialog';
|
|
128
132
|
|
|
133
|
+
// ARIA live region cluster (accessibility)
|
|
134
|
+
'aria-live'?: 'off' | 'polite' | 'assertive';
|
|
135
|
+
'aria-atomic'?: boolean | 'true' | 'false';
|
|
136
|
+
'aria-busy'?: boolean | 'true' | 'false';
|
|
137
|
+
'aria-current'?: boolean | 'true' | 'false' | 'page' | 'step' | 'location' | 'date' | 'time';
|
|
138
|
+
|
|
139
|
+
// ARIA values cluster (accessibility)
|
|
140
|
+
'aria-valuemin'?: number;
|
|
141
|
+
'aria-valuemax'?: number;
|
|
142
|
+
'aria-valuenow'?: number;
|
|
143
|
+
'aria-valuetext'?: string;
|
|
144
|
+
'aria-orientation'?: 'horizontal' | 'vertical';
|
|
145
|
+
'aria-sort'?: 'none' | 'ascending' | 'descending' | 'other';
|
|
146
|
+
|
|
129
147
|
// Loading
|
|
130
148
|
fetchpriority?: 'high' | 'low' | 'auto';
|
|
131
149
|
|
|
@@ -321,9 +339,6 @@ interface MxElement extends HTMLElement {
|
|
|
321
339
|
* reconciles DOM. Returns this element.
|
|
322
340
|
*/
|
|
323
341
|
$(props?: Record<string, any>): this;
|
|
324
|
-
|
|
325
|
-
/** Internal tracking object (stamp system) */
|
|
326
|
-
_$: any;
|
|
327
342
|
}
|
|
328
343
|
|
|
329
344
|
// ---------------------------------------------------------------------------
|
|
@@ -435,6 +450,21 @@ interface MxHTMLTags {
|
|
|
435
450
|
embed: MxTagFn;
|
|
436
451
|
|
|
437
452
|
// SVG
|
|
453
|
+
//
|
|
454
|
+
// Only all-lowercase SVG tags are listed. Tag names are kebab-cased
|
|
455
|
+
// unconditionally, so a camelCase SVG tag cannot be produced by the proxy:
|
|
456
|
+
// `mx.clipPath()` emits `<clip-path>`, `mx.linearGradient()` emits
|
|
457
|
+
// `<linear-gradient>` - invalid elements that parse fine and paint nothing.
|
|
458
|
+
// Affected: clipPath, foreignObject, linearGradient, radialGradient, textPath,
|
|
459
|
+
// animateTransform and every fe* filter primitive (feGaussianBlur, feOffset,
|
|
460
|
+
// feMerge, feMergeNode, feBlend, feColorMatrix, ...).
|
|
461
|
+
//
|
|
462
|
+
// Workaround - build the node yourself and pass it in as a child; render()
|
|
463
|
+
// matches real DOM nodes by identity:
|
|
464
|
+
// let clip = document.createElementNS('http://www.w3.org/2000/svg', 'clipPath')
|
|
465
|
+
// clip.id = 'c'
|
|
466
|
+
// clip.append(document.createElementNS('http://www.w3.org/2000/svg', 'rect'))
|
|
467
|
+
// mx.svg(mx.defs(clip), mx.rect({ 'clip-path': 'url(#c)' }))
|
|
438
468
|
svg: MxTagFn;
|
|
439
469
|
path: MxTagFn;
|
|
440
470
|
circle: MxTagFn;
|
|
@@ -449,23 +479,12 @@ interface MxHTMLTags {
|
|
|
449
479
|
defs: MxTagFn;
|
|
450
480
|
use: MxTagFn;
|
|
451
481
|
symbol: MxTagFn;
|
|
452
|
-
clipPath: MxTagFn;
|
|
453
482
|
mask: MxTagFn;
|
|
454
483
|
pattern: MxTagFn;
|
|
455
484
|
image: MxTagFn;
|
|
456
|
-
foreignObject: MxTagFn;
|
|
457
|
-
linearGradient: MxTagFn;
|
|
458
|
-
radialGradient: MxTagFn;
|
|
459
485
|
stop: MxTagFn;
|
|
460
486
|
filter: MxTagFn;
|
|
461
|
-
feGaussianBlur: MxTagFn;
|
|
462
|
-
feOffset: MxTagFn;
|
|
463
|
-
feMerge: MxTagFn;
|
|
464
|
-
feMergeNode: MxTagFn;
|
|
465
|
-
feBlend: MxTagFn;
|
|
466
|
-
feColorMatrix: MxTagFn;
|
|
467
487
|
animate: MxTagFn;
|
|
468
|
-
animateTransform: MxTagFn;
|
|
469
488
|
|
|
470
489
|
// Interactive
|
|
471
490
|
details: MxTagFn;
|
|
@@ -586,27 +605,17 @@ interface DomHTMLTags {
|
|
|
586
605
|
iframe: DomTagFn<HTMLIFrameElement>;
|
|
587
606
|
|
|
588
607
|
// SVG
|
|
608
|
+
//
|
|
609
|
+
// `svg` is the only SVG tag dom() can build: createElement special-cases the
|
|
610
|
+
// tag name 'svg' and switches to the SVG namespace. Every other SVG tag goes
|
|
611
|
+
// through createElement and lands in the HTML namespace, so `dom.path()` is an
|
|
612
|
+
// HTMLUnknownElement - it serializes as `<path d="...">` and looks correct in
|
|
613
|
+
// DevTools, but has no geometry API and never renders. Those tags are therefore
|
|
614
|
+
// not declared here; they fall through to the index signature as plain Element.
|
|
615
|
+
//
|
|
616
|
+
// Build SVG subtrees with mx.*() inside an mx-rendered `svg` (render() namespaces
|
|
617
|
+
// children of an svg correctly), or with document.createElementNS by hand.
|
|
589
618
|
svg: DomTagFn<SVGSVGElement>;
|
|
590
|
-
path: DomTagFn<SVGPathElement>;
|
|
591
|
-
circle: DomTagFn<SVGCircleElement>;
|
|
592
|
-
ellipse: DomTagFn<SVGEllipseElement>;
|
|
593
|
-
line: DomTagFn<SVGLineElement>;
|
|
594
|
-
polyline: DomTagFn<SVGPolylineElement>;
|
|
595
|
-
polygon: DomTagFn<SVGPolygonElement>;
|
|
596
|
-
rect: DomTagFn<SVGRectElement>;
|
|
597
|
-
text: DomTagFn<SVGTextElement>;
|
|
598
|
-
g: DomTagFn<SVGGElement>;
|
|
599
|
-
defs: DomTagFn<SVGDefsElement>;
|
|
600
|
-
use: DomTagFn<SVGUseElement>;
|
|
601
|
-
symbol: DomTagFn<SVGSymbolElement>;
|
|
602
|
-
clipPath: DomTagFn<SVGClipPathElement>;
|
|
603
|
-
image: DomTagFn<SVGImageElement>;
|
|
604
|
-
foreignObject: DomTagFn<SVGForeignObjectElement>;
|
|
605
|
-
linearGradient: DomTagFn<SVGLinearGradientElement>;
|
|
606
|
-
radialGradient: DomTagFn<SVGRadialGradientElement>;
|
|
607
|
-
stop: DomTagFn<SVGStopElement>;
|
|
608
|
-
filter: DomTagFn<SVGFilterElement>;
|
|
609
|
-
animate: DomTagFn<SVGAnimateElement>;
|
|
610
619
|
|
|
611
620
|
// Interactive
|
|
612
621
|
details: DomTagFn<HTMLDetailsElement>;
|
|
@@ -692,9 +701,6 @@ declare global {
|
|
|
692
701
|
* Only available on elements created from defined components.
|
|
693
702
|
*/
|
|
694
703
|
$(props?: Record<string, any>): this;
|
|
695
|
-
|
|
696
|
-
/** Internal stamp tracking (do not use directly) */
|
|
697
|
-
_$: any;
|
|
698
704
|
}
|
|
699
705
|
|
|
700
706
|
/** mx - virtual description proxy */
|
package/mx.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(i,
|
|
1
|
+
!function(m,i,_,u){let $='http://www.w3.org/2000/svg',t={__proto__:null,value:1,checked:1,selected:1},x=Symbol(),n=(i,t)=>!t&'svg'!=i?l(m.createElement(i),_[i]):m.createElementNS($,i),R=m=>h[m]||=m.replace(/[A-Z]/g,'-$&').toLowerCase(),h={},l=Object.assign,w=(m,n={})=>new Proxy(m,{get:(i,_)=>n[_]||=m.bind(0,_)});define=(i,m={})=>{if(m.$)m.$$||=m.$,m.$=function(i){let _=m.$$.call(this,l(this.$state||={},i));return this.render(..._?._?[_]:_||[])};_[R(i)]=m};i.render=function(...l){let i=this,_=i.namespaceURI==$&'foreignObject'!=i.localName,m=i.firstChild;for(let $ of l){let w,R,g;if($==null|!1===$)continue;if($._)[w,R,g]=$;else if($.nodeType){$!=m&&(m?m.replaceWith($):i.append($)),m=$.nextSibling;continue}if(m)!w?m.splitText?m.data!=$+''&&(m.data=$+''):m.replaceWith(m=new Text($)):w!=m.localName&&m.replaceWith(m=n(w,_));else if(w)i.append(m=n(w,_));else{i.append($);continue}if(w)if(m.$)m[x]=0,m.$(R);else{m.render(...g);let[_,n]=m[x]||=[{},{}],l=u=-~u;for(let i in _){R&&Object.hasOwn(R,i)||(('.'==i[0]?t[i.slice(1)]&&delete n[i.slice(1)]:(t[i]&&(delete n[i],m[i]=''),m.R(i))),delete _[i])}for(let i in R){let $=R[i],k=i.slice(1);_[i]===$?'.'==i[0]?(m[k]===$||(m[k]=$),n[k]=l):t[i]?(m[i]===$||(m[i]=$),n[i]=l):$?.call&&(n[i]=l):'.'==i[0]?(m[k]===$||(m[k]=$),n[k]=l,_[i]=$):$!=null&!1!==$?($.call?(m[i]=$,n[i]=l):(t[i]?(m[i]===$||(m[i]=$),n[i]=l):delete n[i],m.setAttribute(i,$)),_[i]=$):(t[i]&&(delete n[i],m[i]=''),m.R(i),delete _[i])}for(let i in n)l-n[i]&&(delete n[i],m[i]=null,m.R(i))}m=m.nextSibling}for(let $;m;m=$)$=m.nextSibling,i.removeChild(m);return this},i.R=i.removeAttribute,_=components={},i.$attrs=function(m,i,$){for(i in m)$=m[i],'.'==i[0]?this[i.slice(1)]=$:$!=null&!1!==$?($.call?this[i]=$:this.setAttribute(i,$)):this.R(i);return this},mx=w((m,i,..._)=>(m=R(m),_=i?.__proto__==Object.prototype&&!i?.nodeType?[m,i,_]:[m,null,[i,..._]],_._=1,_)),dom=w((m,i,..._)=>(m=n(R(m)),i?.__proto__==Object.prototype&&!i?.nodeType?m.$?m.$(i):m.render(..._).$attrs(i):m.render(i,..._),m))}(document,Element.prototype)
|
package/mx.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
let mx, dom, define, components;
|
|
2
|
-
!function(i,
|
|
2
|
+
!function(m,i,_,u){let $='http://www.w3.org/2000/svg',t={__proto__:null,value:1,checked:1,selected:1},x=Symbol(),n=(i,t)=>!t&'svg'!=i?l(m.createElement(i),_[i]):m.createElementNS($,i),R=m=>h[m]||=m.replace(/[A-Z]/g,'-$&').toLowerCase(),h={},l=Object.assign,w=(m,n={})=>new Proxy(m,{get:(i,_)=>n[_]||=m.bind(0,_)});define=(i,m={})=>{if(m.$)m.$$||=m.$,m.$=function(i){let _=m.$$.call(this,l(this.$state||={},i));return this.render(..._?._?[_]:_||[])};_[R(i)]=m};i.render=function(...l){let i=this,_=i.namespaceURI==$&'foreignObject'!=i.localName,m=i.firstChild;for(let $ of l){let w,R,g;if($==null|!1===$)continue;if($._)[w,R,g]=$;else if($.nodeType){$!=m&&(m?m.replaceWith($):i.append($)),m=$.nextSibling;continue}if(m)!w?m.splitText?m.data!=$+''&&(m.data=$+''):m.replaceWith(m=new Text($)):w!=m.localName&&m.replaceWith(m=n(w,_));else if(w)i.append(m=n(w,_));else{i.append($);continue}if(w)if(m.$)m[x]=0,m.$(R);else{m.render(...g);let[_,n]=m[x]||=[{},{}],l=u=-~u;for(let i in _){R&&Object.hasOwn(R,i)||(('.'==i[0]?t[i.slice(1)]&&delete n[i.slice(1)]:(t[i]&&(delete n[i],m[i]=''),m.R(i))),delete _[i])}for(let i in R){let $=R[i],k=i.slice(1);_[i]===$?'.'==i[0]?(m[k]===$||(m[k]=$),n[k]=l):t[i]?(m[i]===$||(m[i]=$),n[i]=l):$?.call&&(n[i]=l):'.'==i[0]?(m[k]===$||(m[k]=$),n[k]=l,_[i]=$):$!=null&!1!==$?($.call?(m[i]=$,n[i]=l):(t[i]?(m[i]===$||(m[i]=$),n[i]=l):delete n[i],m.setAttribute(i,$)),_[i]=$):(t[i]&&(delete n[i],m[i]=''),m.R(i),delete _[i])}for(let i in n)l-n[i]&&(delete n[i],m[i]=null,m.R(i))}m=m.nextSibling}for(let $;m;m=$)$=m.nextSibling,i.removeChild(m);return this},i.R=i.removeAttribute,_=components={},i.$attrs=function(m,i,$){for(i in m)$=m[i],'.'==i[0]?this[i.slice(1)]=$:$!=null&!1!==$?($.call?this[i]=$:this.setAttribute(i,$)):this.R(i);return this},mx=w((m,i,..._)=>(m=R(m),_=i?.__proto__==Object.prototype&&!i?.nodeType?[m,i,_]:[m,null,[i,..._]],_._=1,_)),dom=w((m,i,..._)=>(m=n(R(m)),i?.__proto__==Object.prototype&&!i?.nodeType?m.$?m.$(i):m.render(..._).$attrs(i):m.render(i,..._),m))}(document,Element.prototype)
|
|
3
3
|
export { mx, dom, define, components };
|