microtags 0.0.12 → 0.0.14

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 CHANGED
@@ -262,11 +262,11 @@ export const myCounter = define('my-counter')
262
262
  There are two separate things people call "validation":
263
263
 
264
264
  1. **Prop validation** checks the attributes passed into a component.
265
- Pass a [Standard Schema](https://standardschema.dev) (Zod, Valibot,
266
- ArkType) to [`p.schema`](#withprops); it coerces the attribute value
267
- and falls back to `undefined` when the value doesn't coerce.
268
- 2. **Form input validation** -- client-side validation -- checks live user input
269
- in a form, for example a value that changes on every keystroke.
265
+ Pass a [Standard Schema](https://standardschema.dev)
266
+ (Zod, Valibot, ArkType) to [`p.schema`](#withprops), and it coerces the
267
+ attribute value and falls back to `undefined` when the value doesn't coerce.
268
+ 2. **Form input validation** -- aka client-side validation -- checks live user
269
+ input in a form, for example a value that changes on every keystroke.
270
270
  There is no dedicated API for this. Validate the schema directly
271
271
  inside `.setup()` and hold the result as a signal.
272
272
 
@@ -413,19 +413,13 @@ and the submit button is disabled until valid. See `example/subscribe-form.ts`.
413
413
 
414
414
  ## Serverside Example
415
415
 
416
- See [./example/ssr.ts](./example/ssr.ts).
416
+ See [./example/ssr.ts](./example/ssr.ts) for an example of rendering an HTML
417
+ string and then "hydrating" the page on the client.
417
418
 
418
419
  ### `.TAG`
419
420
 
420
- Each tag name that you pass to `define` is exposed as a property `.TAG`
421
- on the return value. It is possible to import your web components in Node,
422
- even though Node does not have browser APIs.
423
-
424
- The `data-ref` attribute is a fallback. It's used when you don't pass a
425
- selector to `r.one()`. If you pass explicit CSS selectors to `withRefs`,
426
- e.g. `{ copy: r.one('button') }`, then the HTML does not require a `data-ref`
427
- attribute.
428
-
421
+ Each tag name is exposed as a property `.TAG`. You can import the web
422
+ components in Node, even though Node does not have browser APIs.
429
423
 
430
424
  ```ts
431
425
  import { MyCounter, CountBtn, CopyBtn } from './index.js'
@@ -469,9 +463,8 @@ export function render ():string {
469
463
 
470
464
  ### `.refs`
471
465
 
472
- Web components created with `microtags` have a property `.refs` that is an
473
- object of the ref names you created the coponent with. Use it to create
474
- `data-ref` attributes.
466
+ Web components created with `microtags` have a property `.refs`. It is an
467
+ object of ref names you passed in. Use it to create `data-ref` attributes.
475
468
 
476
469
  ```ts
477
470
  import { MyCounter } from '../example.js'
@@ -494,12 +487,12 @@ export function render () {
494
487
 
495
488
  ### `define`
496
489
 
490
+ Function `define(tagName)` returns a [`ComponentBuilder`](#componentbuilder).
491
+
497
492
  ```js
498
493
  function define (tagName:string):ComponentBuilder
499
494
  ```
500
495
 
501
- Function `define(tagName)` returns a [`ComponentBuilder`](#componentbuilder).
502
-
503
496
 
504
497
  #### `ComponentBuilder`
505
498
 
package/dist/index.min.js CHANGED
@@ -1,2 +1,2 @@
1
- var Z=Object.defineProperty;var r=(e,n)=>Z(e,"name",{value:n,configurable:!0});function j({update:e,notify:n,unwatched:t}){return{link:i,unlink:c,propagate:a,checkDirty:g,shallowPropagate:h};function i(s,f,o){let d=f.depsTail;if(d!==void 0&&d.dep===s)return;let u=d!==void 0?d.nextDep:f.deps;if(u!==void 0&&u.dep===s){u.version=o,f.depsTail=u;return}let l=s.subsTail;if(l!==void 0&&l.version===o&&l.sub===f)return;let p=f.depsTail=s.subsTail={version:o,dep:s,sub:f,prevDep:d,nextDep:u,prevSub:l,nextSub:void 0};u!==void 0&&(u.prevDep=p),d!==void 0?d.nextDep=p:f.deps=p,l!==void 0?l.nextSub=p:s.subs=p}function c(s,f=s.sub){let{dep:o,prevDep:d,nextDep:u,nextSub:l,prevSub:p}=s;return u!==void 0?u.prevDep=d:f.depsTail=d,d!==void 0?d.nextDep=u:f.deps=u,l!==void 0?l.prevSub=p:o.subsTail=p,p!==void 0?p.nextSub=l:(o.subs=l)===void 0&&t(o),u}function a(s,f){let o=s.nextSub,d;e:do{let u=s.sub,l=u.flags;if(l&60?l&12?l&4?!(l&48)&&x(s,u)?(u.flags=l|40,l&=1):l=0:u.flags=l&-9|32:l=0:(u.flags=l|32,f&&(u.flags|=8)),l&2&&n(u),l&1){let p=u.subs;if(p!==void 0){let m=(s=p).nextSub;m!==void 0&&(d={value:o,prev:d},o=m);continue}}if((s=o)!==void 0){o=s.nextSub;continue}for(;d!==void 0;)if(s=d.value,d=d.prev,s!==void 0){o=s.nextSub;continue e}break}while(!0)}function g(s,f){let o,d=0,u=!1;e:do{let l=s.dep,p=l.flags;if(f.flags&16)u=!0;else if((p&17)===17){let m=l.subs;e(l)&&(m.nextSub!==void 0&&h(m),u=!0)}else if((p&33)===33){o={value:s,prev:o},s=l.deps,f=l,++d;continue}if(!u){let m=s.nextDep;if(m!==void 0){s=m;continue}}for(;d--;){if(s=o.value,o=o.prev,u){let b=f.subs;if(e(f)){b.nextSub!==void 0&&h(b),f=s.sub;continue}u=!1}else f.flags&=-33;f=s.sub;let m=s.nextDep;if(m!==void 0){s=m;continue e}}return u&&!!f.flags}while(!0)}function h(s){do{let f=s.sub,o=f.flags;(o&48)===32&&(f.flags=o|16,(o&6)===2&&n(f))}while((s=s.nextSub)!==void 0)}function x(s,f){let o=f.depsTail;for(;o!==void 0;){if(o===s)return!0;o=o.prevDep}return!1}}r(j,"createReactiveSystem");var k=64,E=0,C=0,ee=0,S=0,R=0,v,y=[],{link:O,unlink:w,propagate:ne,checkDirty:te,shallowPropagate:re}=j({update(e){return"getter"in e?se(e):"currentValue"in e?V(e):(e.flags=1,!0)},notify(e){let n=R,t=n;do if(y[n++]=e,e.flags&=-3,e=e.subs?.sub,e===void 0||!(e.flags&2))break;while(!0);for(R=n;t<--n;){let i=y[t];y[t++]=y[n],y[n]=i}},unwatched(e){"getter"in e?e.depsTail!==void 0&&(e.flags=17,F(e)):"currentValue"in e||("fn"in e?B.call(e):$.call(e))}});function T(e){let n=v;return v=e,n}r(T,"setActiveSub");function L(e){return fe.bind({currentValue:e,pendingValue:e,subs:void 0,subsTail:void 0,flags:1})}r(L,"signal");function P(e){let n={fn:e,cleanup:void 0,subs:void 0,subsTail:void 0,deps:void 0,depsTail:void 0,flags:6},t=T(n);t!==void 0&&(O(n,t,0),t.flags|=k);try{++C,n.cleanup=n.fn()}finally{--C,v=t,n.flags&=-5}return B.bind(n)}r(P,"effect");function se(e){if(e.flags&k){let t=e.depsTail;for(;t!==void 0;){let i=t.prevDep,c=t.dep;!("getter"in c)&&!("currentValue"in c)&&w(t,e),t=i}}e.depsTail=void 0,e.flags=5;let n=T(e);try{++E;let t=e.value;return t!==(e.value=e.getter(t))}finally{v=n,e.flags&=-5,I(e)}}r(se,"updateComputed");function V(e){return e.flags=1,e.currentValue!==(e.currentValue=e.pendingValue)}r(V,"updateSignal");function oe(e){let n=e.flags;if(n&16||n&32&&te(e.deps,e)){if(n&k){let i=e.depsTail;for(;i!==void 0;){let c=i.prevDep,a=i.dep;!("getter"in a)&&!("currentValue"in a)&&w(i,e),i=c}}if(e.cleanup&&(H(e),!e.flags))return;e.depsTail=void 0,e.flags=6;let t=T(e);try{++E,++C,e.cleanup=e.fn()}finally{--C,v=t,e.flags&=-5,I(e)}}else e.deps!==void 0&&(e.flags=2|n&k)}r(oe,"run");function ie(){try{for(;S<R;){let e=y[S];y[S++]=void 0,oe(e)}}finally{for(;S<R;){let e=y[S];y[S++]=void 0,e.flags|=10}S=0,R=0}}r(ie,"flush");function fe(...e){if(e.length){if(this.pendingValue!==(this.pendingValue=e[0])){this.flags=17;let n=this.subs;n!==void 0&&(ne(n,!!C),ee||ie())}}else{if(this.flags&16&&V(this)){let t=this.subs;t!==void 0&&re(t)}let n=v;return n!==void 0&&O(this,n,E),this.currentValue}}r(fe,"signalOper");function H(e){let n=e.cleanup;e.cleanup=void 0;let t=v;v=void 0;try{n()}finally{v=t}}r(H,"runCleanup");function B(){$.call(this),this.cleanup&&H(this)}r(B,"effectOper");function $(){this.flags=0,F(this);let e=this.subs;e!==void 0&&w(e)}r($,"effectScopeOper");function F(e){let n=e.depsTail;for(;n!==void 0;){let t=n.prevDep;w(n,e),n=t}}r(F,"disposeAllDepsInReverse");function I(e){let n=e.depsTail,t=n!==void 0?n.nextDep:e.deps;for(;t!==void 0;)t=w(t,e)}r(I,"purgeDeps");function K(e){let n=T(void 0);try{return e()}finally{T(n)}}r(K,"untracked");function _(e){return K(()=>e())}r(_,"peek");function q(e){return e===null?NaN:Number(e)}r(q,"coerceNumber");function z(e){return e??""}r(z,"coerceString");function G(e){return e!==null}r(G,"coerceBoolean");function J(e){if(e!==null)try{return JSON.parse(e)}catch{return}}r(J,"coerceJson");function W(e){let n,t=!1;for(let i of e)try{i()}catch(c){t||(n=c,t=!0)}if(t)throw n}r(W,"runAll");var ue=new WeakMap,M=new Map;function D(e,n){let t=e.parentElement;for(;t;){let i=ue.get(t);if(i&&i.has(n.id))return i.get(n.id);t=t.parentElement}}r(D,"resolveContextSignal");function Q(e,n){let t=M.get(e);return t||(t=new Set,M.set(e,t)),t.add(n),()=>{M.get(e)?.delete(n)}}r(Q,"onContextAvailable");function U(e,n,t,i,c){return{host:e,props:n,refs:t,contexts:i,peek:_,on(a,g,h,x){a.addEventListener(g,h,x),c.push(()=>{a.removeEventListener(g,h,x)})},emit(a,g,h){let x=a instanceof Event?a:new CustomEvent(a,{bubbles:!0,...h,detail:g});return e.dispatchEvent(x)},effect(a){let g=P(a);c.push(g)},bind(a,g,h){let x=g instanceof HTMLInputElement?g:void 0,s="value",f="change";x?.type==="checkbox"?s="checked":x?.type==="number"||x?.type==="range"?(s="valueAsNumber",f="input"):(x||g instanceof HTMLTextAreaElement)&&(f="input");let o=h?.prop??s,d=h?h.event:f,u=g;if(d){let p=r(()=>{a(u[o])},"handler");g.addEventListener(d,p),c.push(()=>{g.removeEventListener(d,p)})}let l=P(()=>{u[o]=a()});c.push(l)},onCleanup(a){c.push(a)},consume(a){let g=D(e,a);return g?g():void 0}}}r(U,"makeSetupContext");var ae=typeof HTMLElement<"u"?HTMLElement:class{};function le(e,n){let t={},i=[];for(let[c,a]of Object.entries(n)){let g=a.selector??`[data-ref="${c}"]`;if(a._microtag==="ref:all")t[c]=Array.from(e.querySelectorAll(g));else{let h=e.querySelector(g);h?t[c]=h:i.push(c)}}if(i.length>0)throw new Error(`${e.tagName}: missing refs: ${i.join(", ")}`);return t}r(le,"collectRefs");function X(e){let{props:n,observedAttrNames:t,setup:i,refs:c={},contexts:a={}}=e;class g extends ae{static{r(this,"MicrotagElement")}static get observedAttributes(){return t}_props={};_cleanups=[];constructor(){super();for(let[x,s]of Object.entries(n))this._props[x]=L(s(null))}connectedCallback(){this._cleanups=[];for(let[p,m]of Object.entries(n)){let b=this.getAttribute(p);b!==null&&this._props[p](m(b))}let x=this._cleanups,s=this._props,f=new Proxy({},{get:r((p,m)=>{if(typeof m!="string")return;let b=a[m];if(!b)return;let A=D(this,b);return A?A():void 0},"get"),has:r((p,m)=>typeof m!="string"?!1:m in a,"has")}),o=!1,d=[],u=r(()=>{if(o)return;for(let b of Object.values(a))if(!D(this,b))return;o=!0;for(let b of d)b();d.length=0;let p=le(this,c),m=U(this,s,p,f,x);i(m)},"tryRunSetup"),l=r(()=>{this.isConnected&&u()},"tryRunSetupIfConnected");for(let p of Object.values(a))if(!D(this,p)){let m=Q(p.id,l);d.push(m),x.push(m)}u()}attributeChangedCallback(x,s,f){let o=n[x];o!==void 0&&this._props[x]!==void 0&&this._props[x](o(f))}disconnectedCallback(){let x=this._cleanups;this._cleanups=[],W(x)}}return g}r(X,"factory");var ce={number:r(()=>q,"number"),string:r(()=>z,"string"),boolean:r(()=>G,"boolean"),json:r(()=>J,"json"),schema:r(e=>e,"schema"),prop:r(e=>({_microtag:"prop",initial:e}),"prop")},de={one:r((e=>({_microtag:"ref:one",selector:e})),"one"),all:r((e=>({_microtag:"ref:all",selector:e})),"all")},pe={},N=class e{constructor(n,t={},i=[],c={},a={}){this.tagName=n;this._coercers=t,this._observed=i,this._refDefs=c,this._ctxDefs=a}tagName;static{r(this,"ComponentBuilder")}_coercers;_observed;_refDefs;_ctxDefs;get TAG(){return this.tagName}withProps(n){let t=n(ce),i={},c=[];for(let[a,g]of Object.entries(t))i[a]=xe(a,g),Y(g)||c.push(a);return new e(this.tagName,i,c,this._refDefs,this._ctxDefs)}withRefs(n){let t=n(de);return new e(this.tagName,this._coercers,this._observed,t,this._ctxDefs)}withContexts(n){let t=n(pe);return new e(this.tagName,this._coercers,this._observed,this._refDefs,t)}setup(n){let t=X({props:this._coercers,observedAttrNames:this._observed,refs:this._refDefs,contexts:this._ctxDefs,setup:n});Object.defineProperty(t,"TAG",{value:this.tagName,enumerable:!0});let i={};for(let c of Object.keys(this._refDefs))i[c]=c;return Object.defineProperty(t,"refs",{value:Object.freeze(i),enumerable:!0}),typeof customElements<"u"&&customElements.define(this.tagName,t),t}};function ge(e){return new N(e)}r(ge,"define");function Y(e){return typeof e=="object"&&e!==null&&"_microtag"in e&&e._microtag==="prop"}r(Y,"isPropOnly");function me(e){return typeof e=="object"&&e!==null&&"~standard"in e}r(me,"isStandardSchema");function xe(e,n){if(Y(n))return t=>n.initial;if(me(n)){let t=n;return i=>{let c=t["~standard"].validate(i);if(c instanceof Promise)throw new TypeError(`withProps: async schemas are not supported (prop "${e}")`);if(!c.issues)return c.value}}return n}r(xe,"normalizePropDef");export{ge as define,_ as peek,K as untracked};
1
+ var Z=Object.defineProperty;var r=(e,n)=>Z(e,"name",{value:n,configurable:!0});function j({update:e,notify:n,unwatched:t}){return{link:i,unlink:c,propagate:a,checkDirty:g,shallowPropagate:h};function i(s,f,o){let d=f.depsTail;if(d!==void 0&&d.dep===s)return;let u=d!==void 0?d.nextDep:f.deps;if(u!==void 0&&u.dep===s){u.version=o,f.depsTail=u;return}let l=s.subsTail;if(l!==void 0&&l.version===o&&l.sub===f)return;let p=f.depsTail=s.subsTail={version:o,dep:s,sub:f,prevDep:d,nextDep:u,prevSub:l,nextSub:void 0};u!==void 0&&(u.prevDep=p),d!==void 0?d.nextDep=p:f.deps=p,l!==void 0?l.nextSub=p:s.subs=p}function c(s,f=s.sub){let{dep:o,prevDep:d,nextDep:u,nextSub:l,prevSub:p}=s;return u!==void 0?u.prevDep=d:f.depsTail=d,d!==void 0?d.nextDep=u:f.deps=u,l!==void 0?l.prevSub=p:o.subsTail=p,p!==void 0?p.nextSub=l:(o.subs=l)===void 0&&t(o),u}function a(s,f){let o=s.nextSub,d;e:do{let u=s.sub,l=u.flags;if(l&60?l&12?l&4?!(l&48)&&x(s,u)?(u.flags=l|40,l&=1):l=0:u.flags=l&-9|32:l=0:(u.flags=l|32,f&&(u.flags|=8)),l&2&&n(u),l&1){let p=u.subs;if(p!==void 0){let m=(s=p).nextSub;m!==void 0&&(d={value:o,prev:d},o=m);continue}}if((s=o)!==void 0){o=s.nextSub;continue}for(;d!==void 0;)if(s=d.value,d=d.prev,s!==void 0){o=s.nextSub;continue e}break}while(!0)}function g(s,f){let o,d=0,u=!1;e:do{let l=s.dep,p=l.flags;if(f.flags&16)u=!0;else if((p&17)===17){let m=l.subs;e(l)&&(m.nextSub!==void 0&&h(m),u=!0)}else if((p&33)===33){o={value:s,prev:o},s=l.deps,f=l,++d;continue}if(!u){let m=s.nextDep;if(m!==void 0){s=m;continue}}for(;d--;){if(s=o.value,o=o.prev,u){let b=f.subs;if(e(f)){b.nextSub!==void 0&&h(b),f=s.sub;continue}u=!1}else f.flags&=-33;f=s.sub;let m=s.nextDep;if(m!==void 0){s=m;continue e}}return u&&!!f.flags}while(!0)}function h(s){do{let f=s.sub,o=f.flags;(o&48)===32&&(f.flags=o|16,(o&6)===2&&n(f))}while((s=s.nextSub)!==void 0)}function x(s,f){let o=f.depsTail;for(;o!==void 0;){if(o===s)return!0;o=o.prevDep}return!1}}r(j,"createReactiveSystem");var k=64,L=0,C=0,ee=0,S=0,R=0,v,y=[],{link:O,unlink:w,propagate:ne,checkDirty:te,shallowPropagate:re}=j({update(e){return"getter"in e?se(e):"currentValue"in e?V(e):(e.flags=1,!0)},notify(e){let n=R,t=n;do if(y[n++]=e,e.flags&=-3,e=e.subs?.sub,e===void 0||!(e.flags&2))break;while(!0);for(R=n;t<--n;){let i=y[t];y[t++]=y[n],y[n]=i}},unwatched(e){"getter"in e?e.depsTail!==void 0&&(e.flags=17,F(e)):"currentValue"in e||("fn"in e?B.call(e):$.call(e))}});function T(e){let n=v;return v=e,n}r(T,"setActiveSub");function P(e){return fe.bind({currentValue:e,pendingValue:e,subs:void 0,subsTail:void 0,flags:1})}r(P,"signal");function E(e){let n={fn:e,cleanup:void 0,subs:void 0,subsTail:void 0,deps:void 0,depsTail:void 0,flags:6},t=T(n);t!==void 0&&(O(n,t,0),t.flags|=k);try{++C,n.cleanup=n.fn()}finally{--C,v=t,n.flags&=-5}return B.bind(n)}r(E,"effect");function se(e){if(e.flags&k){let t=e.depsTail;for(;t!==void 0;){let i=t.prevDep,c=t.dep;!("getter"in c)&&!("currentValue"in c)&&w(t,e),t=i}}e.depsTail=void 0,e.flags=5;let n=T(e);try{++L;let t=e.value;return t!==(e.value=e.getter(t))}finally{v=n,e.flags&=-5,I(e)}}r(se,"updateComputed");function V(e){return e.flags=1,e.currentValue!==(e.currentValue=e.pendingValue)}r(V,"updateSignal");function oe(e){let n=e.flags;if(n&16||n&32&&te(e.deps,e)){if(n&k){let i=e.depsTail;for(;i!==void 0;){let c=i.prevDep,a=i.dep;!("getter"in a)&&!("currentValue"in a)&&w(i,e),i=c}}if(e.cleanup&&(H(e),!e.flags))return;e.depsTail=void 0,e.flags=6;let t=T(e);try{++L,++C,e.cleanup=e.fn()}finally{--C,v=t,e.flags&=-5,I(e)}}else e.deps!==void 0&&(e.flags=2|n&k)}r(oe,"run");function ie(){try{for(;S<R;){let e=y[S];y[S++]=void 0,oe(e)}}finally{for(;S<R;){let e=y[S];y[S++]=void 0,e.flags|=10}S=0,R=0}}r(ie,"flush");function fe(...e){if(e.length){if(this.pendingValue!==(this.pendingValue=e[0])){this.flags=17;let n=this.subs;n!==void 0&&(ne(n,!!C),ee||ie())}}else{if(this.flags&16&&V(this)){let t=this.subs;t!==void 0&&re(t)}let n=v;return n!==void 0&&O(this,n,L),this.currentValue}}r(fe,"signalOper");function H(e){let n=e.cleanup;e.cleanup=void 0;let t=v;v=void 0;try{n()}finally{v=t}}r(H,"runCleanup");function B(){$.call(this),this.cleanup&&H(this)}r(B,"effectOper");function $(){this.flags=0,F(this);let e=this.subs;e!==void 0&&w(e)}r($,"effectScopeOper");function F(e){let n=e.depsTail;for(;n!==void 0;){let t=n.prevDep;w(n,e),n=t}}r(F,"disposeAllDepsInReverse");function I(e){let n=e.depsTail,t=n!==void 0?n.nextDep:e.deps;for(;t!==void 0;)t=w(t,e)}r(I,"purgeDeps");function K(e){let n=T(void 0);try{return e()}finally{T(n)}}r(K,"untracked");function _(e){return K(()=>e())}r(_,"peek");function q(e){return e===null?NaN:Number(e)}r(q,"coerceNumber");function z(e){return e??""}r(z,"coerceString");function G(e){return e!==null}r(G,"coerceBoolean");function J(e){if(e!==null)try{return JSON.parse(e)}catch{return}}r(J,"coerceJson");function W(e){let n,t=!1;for(let i of e)try{i()}catch(c){t||(n=c,t=!0)}if(t)throw n}r(W,"runAll");var ue=new WeakMap,M=new Map;function D(e,n){let t=e.parentElement;for(;t;){let i=ue.get(t);if(i&&i.has(n.id))return i.get(n.id);t=t.parentElement}}r(D,"resolveContextSignal");function Q(e,n){let t=M.get(e);return t||(t=new Set,M.set(e,t)),t.add(n),()=>{M.get(e)?.delete(n)}}r(Q,"onContextAvailable");function U(e,n,t,i,c){return{host:e,props:n,refs:t,contexts:i,peek:_,on(a,g,h,x){a.addEventListener(g,h,x),c.push(()=>{a.removeEventListener(g,h,x)})},emit(a,g,h){let x=a instanceof Event?a:new CustomEvent(a,{bubbles:!0,...h,detail:g});return e.dispatchEvent(x)},effect(a){let g=E(a);c.push(g)},bind(a,g,h){let x=g instanceof HTMLInputElement?g:void 0,s="value",f="change";x?.type==="checkbox"?s="checked":x?.type==="number"||x?.type==="range"?(s="valueAsNumber",f="input"):(x||g instanceof HTMLTextAreaElement)&&(f="input");let o=h?.prop??s,d=h?h.event:f,u=g;if(d){let p=r(()=>{a(u[o])},"handler");g.addEventListener(d,p),c.push(()=>{g.removeEventListener(d,p)})}let l=E(()=>{u[o]=a()});c.push(l)},onCleanup(a){c.push(a)},consume(a){let g=D(e,a);return g?g():void 0}}}r(U,"makeSetupContext");var ae=typeof HTMLElement<"u"?HTMLElement:class{};function le(e,n){let t={},i=[];for(let[c,a]of Object.entries(n)){let g=a.selector??`[data-ref="${c}"]`;if(a._microtag==="ref:all")t[c]=Array.from(e.querySelectorAll(g));else{let h=e.querySelector(g);h?t[c]=h:i.push(c)}}if(i.length>0)throw new Error(`${e.tagName}: missing refs: ${i.join(", ")}`);return t}r(le,"collectRefs");function X(e){let{props:n,observedAttrNames:t,setup:i,refs:c={},contexts:a={}}=e;class g extends ae{static{r(this,"MicrotagElement")}static get observedAttributes(){return t}_props={};_cleanups=[];constructor(){super();for(let[x,s]of Object.entries(n))this._props[x]=P(s(null))}connectedCallback(){this._cleanups=[];for(let[p,m]of Object.entries(n)){let b=this.getAttribute(p);b!==null&&this._props[p](m(b))}let x=this._cleanups,s=this._props,f=new Proxy({},{get:r((p,m)=>{if(typeof m!="string")return;let b=a[m];if(!b)return;let A=D(this,b);return A?A():void 0},"get"),has:r((p,m)=>typeof m!="string"?!1:m in a,"has")}),o=!1,d=[],u=r(()=>{if(o)return;for(let b of Object.values(a))if(!D(this,b))return;o=!0;for(let b of d)b();d.length=0;let p=le(this,c),m=U(this,s,p,f,x);i(m)},"tryRunSetup"),l=r(()=>{this.isConnected&&u()},"tryRunSetupIfConnected");for(let p of Object.values(a))if(!D(this,p)){let m=Q(p.id,l);d.push(m),x.push(m)}u()}attributeChangedCallback(x,s,f){let o=n[x];o!==void 0&&this._props[x]!==void 0&&this._props[x](o(f))}disconnectedCallback(){let x=this._cleanups;this._cleanups=[],W(x)}}return g}r(X,"factory");var ce={number:r(()=>q,"number"),string:r(()=>z,"string"),boolean:r(()=>G,"boolean"),json:r(()=>J,"json"),schema:r(e=>e,"schema"),prop:r(e=>({_microtag:"prop",initial:e}),"prop")},de={one:r((e=>({_microtag:"ref:one",selector:e})),"one"),all:r((e=>({_microtag:"ref:all",selector:e})),"all")},pe={},N=class e{constructor(n,t={},i=[],c={},a={}){this.tagName=n;this._coercers=t,this._observed=i,this._refDefs=c,this._ctxDefs=a}tagName;static{r(this,"ComponentBuilder")}_coercers;_observed;_refDefs;_ctxDefs;get TAG(){return this.tagName}withProps(n){let t=n(ce),i={},c=[];for(let[a,g]of Object.entries(t))i[a]=xe(a,g),Y(g)||c.push(a);return new e(this.tagName,i,c,this._refDefs,this._ctxDefs)}withRefs(n){let t=n(de);return new e(this.tagName,this._coercers,this._observed,t,this._ctxDefs)}withContexts(n){let t=n(pe);return new e(this.tagName,this._coercers,this._observed,this._refDefs,t)}setup(n){let t=X({props:this._coercers,observedAttrNames:this._observed,refs:this._refDefs,contexts:this._ctxDefs,setup:n});Object.defineProperty(t,"TAG",{value:this.tagName,enumerable:!0});let i={};for(let c of Object.keys(this._refDefs))i[c]=c;return Object.defineProperty(t,"refs",{value:Object.freeze(i),enumerable:!0}),typeof customElements<"u"&&customElements.define(this.tagName,t),t}};function ge(e){return new N(e)}r(ge,"define");function Y(e){return typeof e=="object"&&e!==null&&"_microtag"in e&&e._microtag==="prop"}r(Y,"isPropOnly");function me(e){return typeof e=="object"&&e!==null&&"~standard"in e}r(me,"isStandardSchema");function xe(e,n){if(Y(n))return t=>n.initial;if(me(n)){let t=n;return i=>{let c=t["~standard"].validate(i);if(c instanceof Promise)throw new TypeError(`withProps: async schemas are not supported (prop "${e}")`);if(!c.issues)return c.value}}return n}r(xe,"normalizePropDef");export{ge as define,_ as peek,K as untracked};
2
2
  //# sourceMappingURL=index.min.js.map
package/package.json CHANGED
@@ -1,11 +1,40 @@
1
1
  {
2
2
  "name": "microtags",
3
+ "version": "0.0.14",
4
+ "description": "Web component helper",
3
5
  "type": "module",
4
- "version": "0.0.12",
5
- "sideEffects": [
6
- "./example/**"
7
- ],
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js",
10
+ "require": "./dist/index.cjs"
11
+ },
12
+ "./min": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.min.js"
15
+ },
16
+ "./render": {
17
+ "types": "./dist/render.d.ts",
18
+ "import": "./dist/render.js",
19
+ "require": "./dist/render.cjs"
20
+ },
21
+ "./context": {
22
+ "types": "./dist/context.d.ts",
23
+ "import": "./dist/context.js",
24
+ "require": "./dist/context.cjs"
25
+ },
26
+ "./util": {
27
+ "types": "./dist/util.d.ts",
28
+ "import": "./dist/util.js",
29
+ "require": "./dist/util.cjs"
30
+ }
31
+ },
8
32
  "main": "dist/index.js",
33
+ "types": "./dist/index.d.ts",
34
+ "directories": {
35
+ "example": "example",
36
+ "test": "test"
37
+ },
9
38
  "files": [
10
39
  "./dist/*"
11
40
  ],
@@ -32,38 +61,13 @@
32
61
  "postversion": "git push --follow-tags && npm publish",
33
62
  "prepublishOnly": "npm run build"
34
63
  },
35
- "exports": {
36
- ".": {
37
- "types": "./dist/index.d.ts",
38
- "import": "./dist/index.js",
39
- "require": "./dist/index.cjs"
40
- },
41
- "./min": {
42
- "types": "./dist/index.d.ts",
43
- "import": "./dist/index.min.js"
44
- },
45
- "./render": {
46
- "types": "./dist/render.d.ts",
47
- "import": "./dist/render.js",
48
- "require": "./dist/render.cjs"
49
- },
50
- "./context": {
51
- "types": "./dist/context.d.ts",
52
- "import": "./dist/context.js",
53
- "require": "./dist/context.cjs"
54
- },
55
- "./util": {
56
- "types": "./dist/util.d.ts",
57
- "import": "./dist/util.js",
58
- "require": "./dist/util.cjs"
59
- }
60
- },
61
64
  "dependencies": {
62
65
  "@standard-schema/spec": "^1.1.0",
63
66
  "alien-signals": "^3.2.1"
64
67
  },
65
68
  "devDependencies": {
66
69
  "@size-limit/preset-small-lib": "^12.1.0",
70
+ "@stylistic/eslint-plugin": "^5.10.0",
67
71
  "@substrate-system/debug": "^0.9.64",
68
72
  "@substrate-system/dom": "^0.1.13",
69
73
  "@substrate-system/tapout": "^0.0.38",
@@ -84,6 +88,20 @@
84
88
  "vite": "^8.0.5",
85
89
  "zod": "^4.4.3"
86
90
  },
87
- "author": "nichoth <nichoth@nichoth.com> (https://nichoth.com)",
88
- "license": "SEE LICENSE IN LICENSE"
91
+ "keywords": [
92
+ "web",
93
+ "component",
94
+ "custom",
95
+ "elements"
96
+ ],
97
+ "homepage": "https://github.com/nichoth/microtags",
98
+ "bugs": {
99
+ "url": "https://github.com/nichoth/microtags/issues"
100
+ },
101
+ "repository": {
102
+ "type": "git",
103
+ "url": "git+https://github.com/nichoth/microtags.git"
104
+ },
105
+ "license": "SEE LICENSE IN LICENSE",
106
+ "author": "nichoth <nichoth@nichoth.com> (https://nichoth.com)"
89
107
  }