From 6713807498d46b51477a6fa130d7097d5a06df73 Mon Sep 17 00:00:00 2001 From: vrugtehagel Date: Sun, 20 Mar 2022 13:18:16 +0000 Subject: [PATCH] Update minified file and dependency versions --- index.js | 4 ++-- index.min.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 2253667..a84e43f 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,8 @@ import { define, secret } from './define.js' export { define } from './define.js' export { default as register } from './register.js' -export { reversible, until } from 'https://deno.land/x/reversibles@v1.0.0/index.js' -export { default as when } from 'https://deno.land/x/reversibles@v1.0.0/library/when/index.js' +export { reversible, until } from 'https://deno.land/x/reversibles@v1.1.1/index.js' +export { default as when } from 'https://deno.land/x/reversibles@v1.1.1/library/when/index.js' export { default as stateify } from 'https://deno.land/x/stateify@v1.0.0/index.js' diff --git a/index.min.js b/index.min.js index 317fc31..91ef67b 100644 --- a/index.min.js +++ b/index.min.js @@ -1,5 +1,5 @@ -let g=null;const U=(e,t)=>{const n=t?async function(...r){return e.apply(this,r).result}:function(...r){return e.apply(this,r).result};return n.do=function(...r){const s=this==n?e(...r):e.apply(this,r),{result:o}=s;let i=!1;return{result:o,undo:()=>{i||(i=!0,s.undo())},get undone(){return i}}},n},B=e=>function(...t){const n=g,r=[];g=r;const s=e.apply(this,t);g=n;const o=s.then(l=>(n?.unshift(i),g=n,l)),i=()=>s.then(()=>r.forEach(l=>l()));return{result:o,undo:i}},T=e=>function(...t){const n=g,r=[];g=r;const s=e.apply(this,t),o=()=>r.forEach(i=>i());return n?.unshift(o),g=n,{result:s,undo:o}};x.define=e=>U(function(...t){const n=e.apply(this,t),{result:r,undo:s}=n;return g?.unshift(s),{result:r,undo:s}});function x(e){const t=e.constructor.name=="AsyncFunction";return U(t?B(e):T(e),t)}async function N(e){const t=g;return g=null,{then:r=>e.then(s=>(g=t,r(s)))}}const L=e=>(...t)=>e.forEach(n=>n(...t));function R(e){const t=x.define((s,o)=>{const i=[];let l;const f=y=>{if(i.push(y),!(i.length>1))return l=L(i),e.addEventListener(s,l,o),{then:f}};return{undo:()=>e.removeEventListener(s,l,o),result:{then:f,after:y=>(queueMicrotask(()=>queueMicrotask(y)),{then:f})}}}),n=x.define((s,o={})=>{const i=s[0].toUpperCase()+s.slice(1).toLowerCase(),l=window[i+"Observer"];if(!l)return;let f;const b=[],v=m=>{if(b.push(m),!(b.length>1))return f=new l(L(b)),f.observe(e,o),{then:v}};return{undo:()=>f.disconnect(),result:{then:v}}}),r=(s,o)=>{if(o=="does")return t;if(o=="observes"&&e instanceof Node)return n;const i=o.replace(/s$/,"");return l=>t(i,l)};return new Proxy({does:()=>{},observes:()=>{}},{get:r})}const A=Symbol("is-state-variable");function W(e){e!=null&&e[A]&&(e=e.get());const t={thing:e};return new d(t,"thing").proxy}class d extends EventTarget{static map=new WeakMap;static parentMap=new WeakMap;static proxyActions=["apply","construct","defineProperty","deleteProperty","get","getOwnPropertyDescriptor","getPrototypeOf","has","isExtensible","ownKeys","preventExtensions","set","setPrototypeOf"];object;key;callback;specials={valueOf:()=>this.value,toString:()=>this.value.toString(),get:()=>this.value,set:t=>{t!=null&&t[A]&&(t=t.get()),this.change(()=>this.object[this.key]=t)},delete:()=>this.change(()=>delete this.object[this.key]),typeof:()=>typeof this.value,addEventListener:(...t)=>this.addEventListener(...t),removeEventListener:(...t)=>this.removeEventListener(...t),dispatchEvent:(...t)=>this.dispatchEvent(...t)};constructor(t,n,r=null){d.map.has(t)||d.map.set(t,{});const s=d.map.get(t);if(s[n])return s[n];super();Object.assign(this,{object:t,key:n,callback:r}),s[n]=this,this.initialize(),this.changeValue(this.value)}get value(){return this.object[this.key]}get isObject(){return typeof this.value=="object"&&this.value!=null}get isArray(){return Array.isArray(this.value)}change(t){const n=this.value;t();const{value:r,key:s}=this;this.changeValue(r,n),this.dispatchValueChange(r,n),d.parentMap.get(this.object)?.forEach(o=>o.dispatchPropertyChange(s))}dispatchValueChange(t,n){if(t===n)return;const r={oldValue:n,value:t};this.dispatchEvent(new CustomEvent("valuechange",{detail:r})),this.dispatchEvent(new CustomEvent("change",{detail:r}))}dispatchPropertyChange(t){const n=t==null?{unknown:!0}:{property:t};this.dispatchEvent(new CustomEvent("propertychange",{detail:n})),this.dispatchEvent(new CustomEvent("change",{detail:n}))}changeValue(t,n){d.parentMap.get(n)?.delete(this),this.isObject&&(typeof t!="object"||t==null||(d.parentMap.has(t)||d.parentMap.set(t,new Set),d.parentMap.get(t).add(this)))}isPropertyReference(t){return this.isObject?this.isArray?typeof t=="symbol"?!1:!!(Number.isInteger(+t)&&t>=0):!0:!1}initialize(){const t=this.callback?function(){}:{},n={};n.get=(r,s)=>this.get(s),n.set=(r,s,o)=>(this.isPropertyReference(s)&&this.proxy[s].set(o),!0),n.deleteProperty=(r,s)=>{!this.isPropertyReference(s)||this.proxy[s].delete()},n.apply=(r,s,...o)=>this.callback.apply(s,...o);for(const r of d.proxyActions)n[r]??=(s,...o)=>Reflect[r](this.value,...o);this.proxy=new Proxy(t,n)}get(t){if(t==A)return!0;if(!this.isObject&&t==Symbol.toPrimitive)return()=>this.value;const n=this.specials[t];if((!this.isObject||this.isArray)&&n)return n;const r=this.getFlattenedValue(t);if(!this.isPropertyReference(t))return r;const s=this.value;return new d(s,t,n).proxy}getFlattenedValue(t){const n=this.value[t];return typeof n!="function"?n:this.isArray?(...r)=>this.callArrayMethod(this.value,t,...r):n.bind(this.value)}callArrayMethod(t,n,...r){const s=[...t],o=t,i=t[n](...r);if(!(s.length!=o.length||o.some((c,y)=>c!==s[y])))return i;const f=Math.max(s.length,o.length),b=[];for(let c=0;cc.dispatchPropertyChange()),i}}const H=import.meta,K=new Set,w=Symbol("secret"),a=e=>h.name=e,C=new Set,M=new Map;let h=null;a[w]={},a[w].getByUUID=e=>{const t=M.get(e);return M.delete(e),t},a[w].newContext=()=>({name:"",observed:[],properties:[],methods:[],form:!1,exposed:{internals:Symbol("internals"),attributes:Symbol("attributes"),any:Symbol("any"),elements:Symbol("elements")}}),a.context=e=>h?console.log({uuid:e}):(C.add(e),queueMicrotask(()=>{if(C.has(e))throw Error("Yozo: top level await not allowed in custom element definitions")}),h=a[w].newContext(),h.exposed),a.attribute=(e,t={})=>{if(h.observed.push(e),!t.type)return;const n=t.as??e.replace(/-+\w/g,s=>s.slice(-1).toUpperCase()),r=Array.isArray(n)?n:[n];for(const s of r)G(e,{...t,as:s})},a.form=()=>{h.form=!0},a.property=(e,t)=>{typeof t=="function"&&(t={get:t}),h.properties.push({name:e,descriptor:t})},a.method=(e,t)=>{h.methods.push({name:e,method:t})},a.construct=e=>{h.construct=e},a.connect=e=>{h.connect=x(e)},a.disconnect=e=>{h.disconnect=e},a.done=(e,t)=>{if(!!h&&(C.delete(e),M.set(e,h),h=null,t))throw t};export{a as define};async function Y(e,{as:t}={}){if(K.has(e.toString()))return;const r=await(await fetch(e)).text(),o=new DOMParser().parseFromString(r,"text/html"),i=o.querySelector("template"),l=o.querySelector("script"),f=o.querySelector("style"),b=i.getAttribute("mode")??"open",v=i.hasAttribute("delegates-focus"),c=f?new CSSStyleSheet:null,y=new Map,m=await J(l.textContent),{exposed:P,observed:q,form:D}=m,{internals:S,attributes:F,any:X,elements:$}=P;c?.replace(f.textContent),i.removeAttribute("mode"),i.removeAttribute("delegates-focus");const E=class extends HTMLElement{#t=null;[F]=(...u)=>{const p=new EventTarget;return y.set(u,p),p};[$]=Object.assign(u=>this[S].shadowRoot.querySelector(u),{all:u=>[...this[S].shadowRoot.querySelectorAll(u)]});constructor(){super();const u=this.attachShadow({mode:b,delegatesFocus:v});u.append(i.content.cloneNode(!0)),c&&(u.adoptedStyleSheets=[c]),this[S]=this.attachInternals(),m.construct?.call(this,this)}connectedCallback(){this.#t?.undo(),m.connect&&(this.#t=m.connect.do.call(this,this))}disconnectedCallback(){this.#t.undo(),m.disconnect?.()}attributeChangedCallback(u,p,O){if(p===O)return;const I={attribute:u,oldValue:p,value:O},V=()=>new CustomEvent("change",{detail:I});for(const[k,z]of y)(k.includes("*")||k.includes(u))&&z.dispatchEvent(V())}},j=(u,p)=>Object.defineProperty(E.prototype,u,p);for(const{name:u,method:p}of m.methods)j(u,{writable:!0,configurable:!0,value:p});for(const{name:u,descriptor:p}of m.properties)j(u,p);Object.defineProperty(E,"formAssociated",{get:()=>D}),Object.defineProperty(E,"observedAttributes",{get:()=>q}),customElements.define(t??m.name,E)}export{Y as register};export{x as reversible,N as until};export{R as when};export{W as stateify};a[w].url=H.url;function G(e,t){const{type:n,as:r}=t;n==Boolean?a.property(r,{get(){return this.hasAttribute(e)},set(s){this.toggleAttribute(e,s)}}):a.property(r,{get(){const s=this.getAttribute(e);return s==null?t.default??null:n(s)},set(s){if(s==null)return this.removeAttribute(e);this.setAttribute(e,s)}})}async function J(e){const t=crypto.randomUUID(),n="application/javascript",r=new Blob([Q(e,t)],{type:n}),s=URL.createObjectURL(r);return await import(s),URL.revokeObjectURL(s),a[w].getByUUID(t)}const Q=(e,t)=>` -import { define, when } from "${a[w].url}"; +let b=null;const D=(e,t)=>{const s=t?async function(...r){return e.apply(this,r).result}:function(...r){return e.apply(this,r).result};return s.do=function(...r){const n=this==s?e(...r):e.apply(this,r),{result:o}=n;let c=!1;return{result:o,undo:()=>{c||(c=!0,n.undo())},get undone(){return c}}},s},B=e=>function(...t){const s=b,r=[];b=r;const n=e.apply(this,t);b=s;const o=n.then(l=>(s?.unshift(c),b=s,l)),c=()=>n.then(()=>r.forEach(l=>l()));return{result:o,undo:c}},N=e=>function(...t){const s=b,r=[];b=r;const n=e.apply(this,t),o=()=>r.forEach(c=>c());return s?.unshift(o),b=s,{result:n,undo:o}};S.define=e=>D(function(...t){const s=e.apply(this,t),{result:r,undo:n}=s;return b?.unshift(n),{result:r,undo:n}});function S(e){const t=e.constructor.name=="AsyncFunction";return D(t?B(e):N(e),t)}async function R(e){const t=b;return b=null,{then:r=>e.then(n=>(b=t,r(n)))}}const F=e=>(...t)=>e.forEach(s=>s(...t));function W(e){const t=S.define((n,o)=>{const c=[];let l,p=!1;const f=v=>(queueMicrotask(()=>queueMicrotask(v)),{then:i,timeout:y}),y=async v=>({then:C=>{const w=U=>{clearTimeout(M),e.removeEventListener(n,w,o),C(U)},M=setTimeout(()=>w(null),v);e.addEventListener(n,w,o)}}),i=v=>{if(c.push(v),p&&v(null),!(c.length>1))return l=F(c),e.addEventListener(n,l,o),{then:i}};return{undo:()=>e.removeEventListener(n,l,o),result:{now:()=>(p=!0,{then:i,after:f}),then:i,after:f,timeout:y}}}),s=S.define((n,o={})=>{const c=n[0].toUpperCase()+n.slice(1).toLowerCase(),l=globalThis[c+"Observer"];if(!l)return;let p;const f=[],y=g=>{if(f.push(g),!(f.length>1))return p=new l(F(f)),p.observe(e,o),{then:y}};return{undo:()=>p.disconnect(),result:{then:y}}}),r=(n,o)=>{if(o=="does")return t;if(o=="observes"&&e instanceof Node)return s;const c=o.replace(/s$/,"");return l=>t(c,l)};return new Proxy({does:()=>{},observes:()=>{}},{get:r})}const j=Symbol("is-state-variable");function H(e){e!=null&&e[j]&&(e=e.get());const t={thing:e};return new d(t,"thing").proxy}class d extends EventTarget{static map=new WeakMap;static parentMap=new WeakMap;static proxyActions=["apply","construct","defineProperty","deleteProperty","get","getOwnPropertyDescriptor","getPrototypeOf","has","isExtensible","ownKeys","preventExtensions","set","setPrototypeOf"];object;key;callback;specials={valueOf:()=>this.value,toString:()=>this.value.toString(),get:()=>this.value,set:t=>{t!=null&&t[j]&&(t=t.get()),this.change(()=>this.object[this.key]=t)},delete:()=>this.change(()=>delete this.object[this.key]),typeof:()=>typeof this.value,addEventListener:(...t)=>this.addEventListener(...t),removeEventListener:(...t)=>this.removeEventListener(...t),dispatchEvent:(...t)=>this.dispatchEvent(...t)};constructor(t,s,r=null){d.map.has(t)||d.map.set(t,{});const n=d.map.get(t);if(n[s])return n[s];super();Object.assign(this,{object:t,key:s,callback:r}),n[s]=this,this.initialize(),this.changeValue(this.value)}get value(){return this.object[this.key]}get isObject(){return typeof this.value=="object"&&this.value!=null}get isArray(){return Array.isArray(this.value)}change(t){const s=this.value;t();const{value:r,key:n}=this;this.changeValue(r,s),this.dispatchValueChange(r,s),d.parentMap.get(this.object)?.forEach(o=>o.dispatchPropertyChange(n))}dispatchValueChange(t,s){if(t===s)return;const r={oldValue:s,value:t};this.dispatchEvent(new CustomEvent("valuechange",{detail:r})),this.dispatchEvent(new CustomEvent("change",{detail:r}))}dispatchPropertyChange(t){const s=t==null?{unknown:!0}:{property:t};this.dispatchEvent(new CustomEvent("propertychange",{detail:s})),this.dispatchEvent(new CustomEvent("change",{detail:s}))}changeValue(t,s){d.parentMap.get(s)?.delete(this),this.isObject&&(typeof t!="object"||t==null||(d.parentMap.has(t)||d.parentMap.set(t,new Set),d.parentMap.get(t).add(this)))}isPropertyReference(t){return this.isObject?this.isArray?typeof t=="symbol"?!1:!!(Number.isInteger(+t)&&t>=0):!0:!1}initialize(){const t=this.callback?function(){}:{},s={};s.get=(r,n)=>this.get(n),s.set=(r,n,o)=>(this.isPropertyReference(n)&&this.proxy[n].set(o),!0),s.deleteProperty=(r,n)=>{!this.isPropertyReference(n)||this.proxy[n].delete()},s.apply=(r,n,...o)=>this.callback.apply(n,...o);for(const r of d.proxyActions)s[r]??=(n,...o)=>Reflect[r](this.value,...o);this.proxy=new Proxy(t,s)}get(t){if(t==j)return!0;if(!this.isObject&&t==Symbol.toPrimitive)return()=>this.value;const s=this.specials[t];if((!this.isObject||this.isArray)&&s)return s;const r=this.getFlattenedValue(t);if(!this.isPropertyReference(t))return r;const n=this.value;return new d(n,t,s).proxy}getFlattenedValue(t){const s=this.value[t];return typeof s!="function"?s:this.isArray?(...r)=>this.callArrayMethod(this.value,t,...r):s.bind(this.value)}callArrayMethod(t,s,...r){const n=[...t],o=t,c=t[s](...r);if(!(n.length!=o.length||o.some((i,E)=>i!==n[E])))return c;const p=Math.max(n.length,o.length),f=[];for(let i=0;ii.dispatchPropertyChange()),c}}const K=import.meta,Y=new Set,x=Symbol("secret"),a=e=>h.name=e,O=new Set,k=new Map;let h=null;a[x]={},a[x].getByUUID=e=>{const t=k.get(e);return k.delete(e),t},a[x].newContext=()=>({name:"",observed:[],properties:[],methods:[],form:!1,exposed:{internals:Symbol("internals"),attributes:Symbol("attributes"),any:Symbol("any"),elements:Symbol("elements")}}),a.context=e=>h?console.log({uuid:e}):(O.add(e),queueMicrotask(()=>{if(O.has(e))throw Error("Yozo: top level await not allowed in custom element definitions")}),h=a[x].newContext(),h.exposed),a.attribute=(e,t={})=>{if(h.observed.push(e),!t.type)return;const s=t.as??e.replace(/-+\w/g,n=>n.slice(-1).toUpperCase()),r=Array.isArray(s)?s:[s];for(const n of r)J(e,{...t,as:n})},a.form=()=>{h.form=!0},a.property=(e,t)=>{typeof t=="function"&&(t={get:t}),h.properties.push({name:e,descriptor:t})},a.method=(e,t)=>{h.methods.push({name:e,method:t})},a.construct=e=>{h.construct=e},a.connect=e=>{h.connect=S(e)},a.disconnect=e=>{h.disconnect=e},a.done=(e,t)=>{if(!!h&&(O.delete(e),k.set(e,h),h=null,t))throw t};export{a as define};async function G(e,{as:t}={}){if(Y.has(e.toString()))return;const r=await(await fetch(e)).text(),o=new DOMParser().parseFromString(r,"text/html"),c=o.querySelector("template"),l=o.querySelector("script"),p=o.querySelector("style"),f=c.getAttribute("mode")??"open",y=c.hasAttribute("delegates-focus"),i=p?new CSSStyleSheet:null,E=new Map,g=await Q(l.textContent),{exposed:L,observed:v,form:C}=g,{internals:w,attributes:M,any:U,elements:I}=L;i?.replace(p.textContent),c.removeAttribute("mode"),c.removeAttribute("delegates-focus");const A=class extends HTMLElement{#t=null;[M]=(...u)=>{const m=new EventTarget;return E.set(u,m),m};[I]=Object.assign(u=>this[w].shadowRoot.querySelector(u),{all:u=>[...this[w].shadowRoot.querySelectorAll(u)]});constructor(){super();const u=this.attachShadow({mode:f,delegatesFocus:y});u.append(c.content.cloneNode(!0)),i&&(u.adoptedStyleSheets=[i]),this[w]=this.attachInternals(),g.construct?.call(this,this)}connectedCallback(){this.#t?.undo(),g.connect&&(this.#t=g.connect.do.call(this,this))}disconnectedCallback(){this.#t.undo(),g.disconnect?.()}attributeChangedCallback(u,m,q){if(m===q)return;const $={attribute:u,oldValue:m,value:q},V=()=>new CustomEvent("change",{detail:$});for(const[T,z]of E)(T.includes("*")||T.includes(u))&&z.dispatchEvent(V())}},P=(u,m)=>Object.defineProperty(A.prototype,u,m);for(const{name:u,method:m}of g.methods)P(u,{writable:!0,configurable:!0,value:m});for(const{name:u,descriptor:m}of g.properties)P(u,m);Object.defineProperty(A,"formAssociated",{get:()=>C}),Object.defineProperty(A,"observedAttributes",{get:()=>v}),customElements.define(t??g.name,A)}export{G as register};export{S as reversible,R as until};export{W as when};export{H as stateify};a[x].url=K.url;function J(e,t){const{type:s,as:r}=t;s==Boolean?a.property(r,{get(){return this.hasAttribute(e)},set(n){this.toggleAttribute(e,n)}}):a.property(r,{get(){const n=this.getAttribute(e);return n==null?t.default??null:s(n)},set(n){if(n==null)return this.removeAttribute(e);this.setAttribute(e,n)}})}async function Q(e){const t=crypto.randomUUID(),s="application/javascript",r=new Blob([X(e,t)],{type:s}),n=URL.createObjectURL(r);return await import(n),URL.revokeObjectURL(n),a[x].getByUUID(t)}const X=(e,t)=>` +import { define, when } from "${a[x].url}"; const { internals, attributes, any, elements } = define.context('${t}'); const { construct, connect, disconnect } = define; try {