@tltdsh/mx 1.3.2 → 1.4.1
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 +2 -2
- package/CLAUDE.md +2 -2
- package/README.md +2 -2
- package/mx.d.ts +48 -41
- package/mx.min.js +1 -1
- package/mx.mjs +1 -1
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -251,11 +251,11 @@ this.$attrs({ disabled, class: 'my-component' });
|
|
|
251
251
|
|
|
252
252
|
Caveats vs `render()`: `$attrs` cannot clear event handlers (it calls `removeAttribute`, which is a no-op for handlers) and does not reset `value`/`checked`/`selected` properties on null. For full cleanup semantics, use `render()` with fresh descriptions. See [mxjs.dev/reference](https://mxjs.dev/reference).
|
|
253
253
|
|
|
254
|
-
**
|
|
254
|
+
**Handler cleanup**: `render()` keeps a per-element cache of what it last applied; a handler or `.prop` present in render N but absent in render N+1 is nulled from that cache before the children reconcile. You never manually remove handlers.
|
|
255
255
|
|
|
256
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
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
|
|
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; a child reading a parent attribute during `$()` sees the previous render's value if it changed, `null` if the new description dropped it (removals are undone before children reconcile) or added it. Pass data via `$state`, dispatch after mount.
|
|
259
259
|
|
|
260
260
|
---
|
|
261
261
|
|
package/CLAUDE.md
CHANGED
|
@@ -251,11 +251,11 @@ this.$attrs({ disabled, class: 'my-component' });
|
|
|
251
251
|
|
|
252
252
|
Caveats vs `render()`: `$attrs` cannot clear event handlers (it calls `removeAttribute`, which is a no-op for handlers) and does not reset `value`/`checked`/`selected` properties on null. For full cleanup semantics, use `render()` with fresh descriptions. See [mxjs.dev/reference](https://mxjs.dev/reference).
|
|
253
253
|
|
|
254
|
-
**
|
|
254
|
+
**Handler cleanup**: `render()` keeps a per-element cache of what it last applied; a handler or `.prop` present in render N but absent in render N+1 is nulled from that cache before the children reconcile. You never manually remove handlers.
|
|
255
255
|
|
|
256
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
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
|
|
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; a child reading a parent attribute during `$()` sees the previous render's value if it changed, `null` if the new description dropped it (removals are undone before children reconcile) or added it. Pass data via `$state`, dispatch after mount.
|
|
259
259
|
|
|
260
260
|
---
|
|
261
261
|
|
package/README.md
CHANGED
|
@@ -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.1/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,12 +114,16 @@ 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;
|
|
@@ -132,6 +136,21 @@ interface MxHTMLAttrs {
|
|
|
132
136
|
'aria-busy'?: boolean | 'true' | 'false';
|
|
133
137
|
'aria-current'?: boolean | 'true' | 'false' | 'page' | 'step' | 'location' | 'date' | 'time';
|
|
134
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
|
+
|
|
147
|
+
// ARIA form validation cluster (accessibility)
|
|
148
|
+
// Absent IS the default ("not required", "valid", "editable") for these three,
|
|
149
|
+
// so plain booleans are fine: `false` removes the attribute, which reads the same.
|
|
150
|
+
'aria-required'?: boolean | 'true' | 'false';
|
|
151
|
+
'aria-invalid'?: boolean | 'true' | 'false' | 'grammar' | 'spelling';
|
|
152
|
+
'aria-readonly'?: boolean | 'true' | 'false';
|
|
153
|
+
|
|
135
154
|
// Loading
|
|
136
155
|
fetchpriority?: 'high' | 'low' | 'auto';
|
|
137
156
|
|
|
@@ -327,9 +346,6 @@ interface MxElement extends HTMLElement {
|
|
|
327
346
|
* reconciles DOM. Returns this element.
|
|
328
347
|
*/
|
|
329
348
|
$(props?: Record<string, any>): this;
|
|
330
|
-
|
|
331
|
-
/** Internal tracking object (stamp system) */
|
|
332
|
-
_$: any;
|
|
333
349
|
}
|
|
334
350
|
|
|
335
351
|
// ---------------------------------------------------------------------------
|
|
@@ -441,6 +457,21 @@ interface MxHTMLTags {
|
|
|
441
457
|
embed: MxTagFn;
|
|
442
458
|
|
|
443
459
|
// SVG
|
|
460
|
+
//
|
|
461
|
+
// Only all-lowercase SVG tags are listed. Tag names are kebab-cased
|
|
462
|
+
// unconditionally, so a camelCase SVG tag cannot be produced by the proxy:
|
|
463
|
+
// `mx.clipPath()` emits `<clip-path>`, `mx.linearGradient()` emits
|
|
464
|
+
// `<linear-gradient>` - invalid elements that parse fine and paint nothing.
|
|
465
|
+
// Affected: clipPath, foreignObject, linearGradient, radialGradient, textPath,
|
|
466
|
+
// animateTransform and every fe* filter primitive (feGaussianBlur, feOffset,
|
|
467
|
+
// feMerge, feMergeNode, feBlend, feColorMatrix, ...).
|
|
468
|
+
//
|
|
469
|
+
// Workaround - build the node yourself and pass it in as a child; render()
|
|
470
|
+
// matches real DOM nodes by identity:
|
|
471
|
+
// let clip = document.createElementNS('http://www.w3.org/2000/svg', 'clipPath')
|
|
472
|
+
// clip.id = 'c'
|
|
473
|
+
// clip.append(document.createElementNS('http://www.w3.org/2000/svg', 'rect'))
|
|
474
|
+
// mx.svg(mx.defs(clip), mx.rect({ 'clip-path': 'url(#c)' }))
|
|
444
475
|
svg: MxTagFn;
|
|
445
476
|
path: MxTagFn;
|
|
446
477
|
circle: MxTagFn;
|
|
@@ -455,23 +486,12 @@ interface MxHTMLTags {
|
|
|
455
486
|
defs: MxTagFn;
|
|
456
487
|
use: MxTagFn;
|
|
457
488
|
symbol: MxTagFn;
|
|
458
|
-
clipPath: MxTagFn;
|
|
459
489
|
mask: MxTagFn;
|
|
460
490
|
pattern: MxTagFn;
|
|
461
491
|
image: MxTagFn;
|
|
462
|
-
foreignObject: MxTagFn;
|
|
463
|
-
linearGradient: MxTagFn;
|
|
464
|
-
radialGradient: MxTagFn;
|
|
465
492
|
stop: MxTagFn;
|
|
466
493
|
filter: MxTagFn;
|
|
467
|
-
feGaussianBlur: MxTagFn;
|
|
468
|
-
feOffset: MxTagFn;
|
|
469
|
-
feMerge: MxTagFn;
|
|
470
|
-
feMergeNode: MxTagFn;
|
|
471
|
-
feBlend: MxTagFn;
|
|
472
|
-
feColorMatrix: MxTagFn;
|
|
473
494
|
animate: MxTagFn;
|
|
474
|
-
animateTransform: MxTagFn;
|
|
475
495
|
|
|
476
496
|
// Interactive
|
|
477
497
|
details: MxTagFn;
|
|
@@ -592,27 +612,17 @@ interface DomHTMLTags {
|
|
|
592
612
|
iframe: DomTagFn<HTMLIFrameElement>;
|
|
593
613
|
|
|
594
614
|
// SVG
|
|
615
|
+
//
|
|
616
|
+
// `svg` is the only SVG tag dom() can build: createElement special-cases the
|
|
617
|
+
// tag name 'svg' and switches to the SVG namespace. Every other SVG tag goes
|
|
618
|
+
// through createElement and lands in the HTML namespace, so `dom.path()` is an
|
|
619
|
+
// HTMLUnknownElement - it serializes as `<path d="...">` and looks correct in
|
|
620
|
+
// DevTools, but has no geometry API and never renders. Those tags are therefore
|
|
621
|
+
// not declared here; they fall through to the index signature as plain Element.
|
|
622
|
+
//
|
|
623
|
+
// Build SVG subtrees with mx.*() inside an mx-rendered `svg` (render() namespaces
|
|
624
|
+
// children of an svg correctly), or with document.createElementNS by hand.
|
|
595
625
|
svg: DomTagFn<SVGSVGElement>;
|
|
596
|
-
path: DomTagFn<SVGPathElement>;
|
|
597
|
-
circle: DomTagFn<SVGCircleElement>;
|
|
598
|
-
ellipse: DomTagFn<SVGEllipseElement>;
|
|
599
|
-
line: DomTagFn<SVGLineElement>;
|
|
600
|
-
polyline: DomTagFn<SVGPolylineElement>;
|
|
601
|
-
polygon: DomTagFn<SVGPolygonElement>;
|
|
602
|
-
rect: DomTagFn<SVGRectElement>;
|
|
603
|
-
text: DomTagFn<SVGTextElement>;
|
|
604
|
-
g: DomTagFn<SVGGElement>;
|
|
605
|
-
defs: DomTagFn<SVGDefsElement>;
|
|
606
|
-
use: DomTagFn<SVGUseElement>;
|
|
607
|
-
symbol: DomTagFn<SVGSymbolElement>;
|
|
608
|
-
clipPath: DomTagFn<SVGClipPathElement>;
|
|
609
|
-
image: DomTagFn<SVGImageElement>;
|
|
610
|
-
foreignObject: DomTagFn<SVGForeignObjectElement>;
|
|
611
|
-
linearGradient: DomTagFn<SVGLinearGradientElement>;
|
|
612
|
-
radialGradient: DomTagFn<SVGRadialGradientElement>;
|
|
613
|
-
stop: DomTagFn<SVGStopElement>;
|
|
614
|
-
filter: DomTagFn<SVGFilterElement>;
|
|
615
|
-
animate: DomTagFn<SVGAnimateElement>;
|
|
616
626
|
|
|
617
627
|
// Interactive
|
|
618
628
|
details: DomTagFn<HTMLDetailsElement>;
|
|
@@ -698,9 +708,6 @@ declare global {
|
|
|
698
708
|
* Only available on elements created from defined components.
|
|
699
709
|
*/
|
|
700
710
|
$(props?: Record<string, any>): this;
|
|
701
|
-
|
|
702
|
-
/** Internal stamp tracking (do not use directly) */
|
|
703
|
-
_$: any;
|
|
704
711
|
}
|
|
705
712
|
|
|
706
713
|
/** mx - virtual description proxy */
|
package/mx.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(
|
|
1
|
+
!function(l,i){let _='http://www.w3.org/2000/svg',w=l=>s[l]||=l.replace(/[A-Z]/g,'-$&').toLowerCase(),A=Symbol(),f=Object.assign,R=components={},$=(l,n={})=>new Proxy(l,{get:(_,i)=>n[i]||=l.bind(0,i)}),g=Symbol(),s={},n=(i,d)=>'svg'!=i&!d?f(l.createElement(i),R[i]):l.createElementNS(_,i),d={__proto__:null,value:1,selected:1,checked:1};define=(i,l={})=>{R[w(i)]=l;if(l.$)l.$$||=l.$,l.$=function(i){let _=l.$$.call(this,f(this.$state||={},i));return this.render(..._?._?[_]:_||[])}},dom=$((l,i,..._)=>(l=n(w(l)),i?.__proto__==Object.prototype&&!i?.nodeType?l.$?l.$(i):l.render(..._).$attrs(i):l.render(i,..._),l)),i.render=function(...f){let i=this,R=_==i.namespaceURI&'foreignObject'!=i.localName,l=i.firstChild,e;for(let _ of f){let $,w,m;if(_==null|!1===_)continue;if(_._)[$,w,m]=_;else if(_.nodeType){if(!e){for(let _ of f)_?.nodeType&&(_[g]=f);e=1}for(;l&&l!=_&&l[g]!=f;l=$)$=l.nextSibling,i.removeChild(l);l!=_&&(l?.nextSibling==_?i.removeChild(l):i.insertBefore(_,l)),l=_.nextSibling;continue}if(l)!$?l.splitText?l.data!=''+_&&(l.data=''+_):l.replaceWith(l=new Text(_)):$!=l.localName&&l.replaceWith(l=n($,R));else i.append(l=$?n($,R):new Text(_));if($)if(l.$)l[A]=0,l.$(w);else{let R=l[A]||={__proto__:null};for(let i in R)w&&Object.hasOwn(w,i)||(i[0]=='.'?(delete R[i],d[i=i.slice(1)]||w&&Object.hasOwn(w,i)&&w[i]||(l[i]=null,l.R(i))):(d[i]?l[i]='':R[i]?.call&&(l[i]=null),l.R(i),delete R[i]));l.render(...m);for(let i in w)_=w[i],i[0]=='.'?(R[i]=_,l[i=i.slice(1)]===_||(l[i]=_)):i in R&&R[i]===_?d[i]&&(l[i]===_||(l[i]=_)):_!=null&!1!==_?(_.call?l[i]=_:(d[i]&&(l[i]===_||(l[i]=_)),l.setAttribute(i,_)),R[i]=_):(d[i]?l[i]==''||(l[i]=''):R[i]?.call&&(l[i]=null),l.R(i),delete R[i])}l=l.nextSibling}for(let $;l;l=$)$=l.nextSibling,i.removeChild(l);return this},i.$attrs=function(l,i,_){for(i in l)_=l[i],i[0]=='.'?this[i.slice(1)]=_:_!=null&!1!==_?(_.call?this[i]=_:this.setAttribute(i,_)):this.R(i);return this},i.R=i.removeAttribute,mx=$((l,i,..._)=>(l=w(l),_=i?.__proto__==Object.prototype&&!i?.nodeType?[l,i,_]:[l,null,[i,..._]],_._=1,_))}(document,Element.prototype)
|
package/mx.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
let mx, dom, define, components;
|
|
2
|
-
!function(
|
|
2
|
+
!function(l,i){let _='http://www.w3.org/2000/svg',w=l=>s[l]||=l.replace(/[A-Z]/g,'-$&').toLowerCase(),A=Symbol(),f=Object.assign,R=components={},$=(l,n={})=>new Proxy(l,{get:(_,i)=>n[i]||=l.bind(0,i)}),g=Symbol(),s={},n=(i,d)=>'svg'!=i&!d?f(l.createElement(i),R[i]):l.createElementNS(_,i),d={__proto__:null,value:1,selected:1,checked:1};define=(i,l={})=>{R[w(i)]=l;if(l.$)l.$$||=l.$,l.$=function(i){let _=l.$$.call(this,f(this.$state||={},i));return this.render(..._?._?[_]:_||[])}},dom=$((l,i,..._)=>(l=n(w(l)),i?.__proto__==Object.prototype&&!i?.nodeType?l.$?l.$(i):l.render(..._).$attrs(i):l.render(i,..._),l)),i.render=function(...f){let i=this,R=_==i.namespaceURI&'foreignObject'!=i.localName,l=i.firstChild,e;for(let _ of f){let $,w,m;if(_==null|!1===_)continue;if(_._)[$,w,m]=_;else if(_.nodeType){if(!e){for(let _ of f)_?.nodeType&&(_[g]=f);e=1}for(;l&&l!=_&&l[g]!=f;l=$)$=l.nextSibling,i.removeChild(l);l!=_&&(l?.nextSibling==_?i.removeChild(l):i.insertBefore(_,l)),l=_.nextSibling;continue}if(l)!$?l.splitText?l.data!=''+_&&(l.data=''+_):l.replaceWith(l=new Text(_)):$!=l.localName&&l.replaceWith(l=n($,R));else i.append(l=$?n($,R):new Text(_));if($)if(l.$)l[A]=0,l.$(w);else{let R=l[A]||={__proto__:null};for(let i in R)w&&Object.hasOwn(w,i)||(i[0]=='.'?(delete R[i],d[i=i.slice(1)]||w&&Object.hasOwn(w,i)&&w[i]||(l[i]=null,l.R(i))):(d[i]?l[i]='':R[i]?.call&&(l[i]=null),l.R(i),delete R[i]));l.render(...m);for(let i in w)_=w[i],i[0]=='.'?(R[i]=_,l[i=i.slice(1)]===_||(l[i]=_)):i in R&&R[i]===_?d[i]&&(l[i]===_||(l[i]=_)):_!=null&!1!==_?(_.call?l[i]=_:(d[i]&&(l[i]===_||(l[i]=_)),l.setAttribute(i,_)),R[i]=_):(d[i]?l[i]==''||(l[i]=''):R[i]?.call&&(l[i]=null),l.R(i),delete R[i])}l=l.nextSibling}for(let $;l;l=$)$=l.nextSibling,i.removeChild(l);return this},i.$attrs=function(l,i,_){for(i in l)_=l[i],i[0]=='.'?this[i.slice(1)]=_:_!=null&!1!==_?(_.call?this[i]=_:this.setAttribute(i,_)):this.R(i);return this},i.R=i.removeAttribute,mx=$((l,i,..._)=>(l=w(l),_=i?.__proto__==Object.prototype&&!i?.nodeType?[l,i,_]:[l,null,[i,..._]],_._=1,_))}(document,Element.prototype)
|
|
3
3
|
export { mx, dom, define, components };
|