-
Notifications
You must be signed in to change notification settings - Fork 3
/
cardts.min.js
2 lines (2 loc) · 6.53 KB
/
cardts.min.js
1
2
//2019-05-03 11:13
((e,t,n,s,a="CARDTS",i="License:CC-BY-SA - Danny Engelman - 2019-05-03 11:13")=>{class o extends HTMLElement{S(e,t){throw new Error("Method not implemented.")}constructor(a){super();let i,o,r,y,C,b=this,_=[];n.defineProperties(b,{E:{value:()=>{},writable:!1,enumerable:!1}}),n.assign(b,{D:0,O(){C=b.getRootNode().host,b.D||(y=!b.Q("*")&&b[h]),C?(o=C.G(ee).indexOf(b)+1,b.id||(b.id=(C.id||"noid")+"_"+o),b.S(q,o)):b[E]==te&&b.parentNode[E]==U&&b.parentNode.$zone_appendChild(b),b.C&&b.C(),b.on(G,e=>{}),b.say(X),b.Q("STYLE[disabled]").map(e=>e.disabled=1),b.D=1},get:b.G=(e=>[...b[R].children].filter(t=>t[E][f](e||O))),find:(n,s=((a,i=a&&a.closest(n))=>a&&a!==e&&a!==t?i||s(a.getRootNode().host):null))=>s(b),query:b.Q=((e,t=0)=>[...b[R].querySelectorAll(e)]),free:e=>b.G().filter(t=>0==t.children[m]&&(!e||t.id==e)),cardt:e=>b.Q(te)[e||0],show:(e=1)=>b[$].visibility=e?"visible":"hidden",flip:e=>b[k]=e||(b[k]==F?Y:F),css:b.S=((e,t)=>t?b[$].setProperty("--"+e,s(t)):getComputedStyle(b).getPropertyValue("--"+e)),to:e=>e.free().map(e=>{let t=b.cardt();t&&t.toid(e.id)}),fill:e=>e.map(e=>Array.isArray(e)?e.map(t=>b.P(e[0],t,1)):b.P(e)),A(e,t,n={}){let s=e=>{d(e.detail)&&e.type,t(e)};return b.addEventListener(e,s,n),[e,()=>b.removeEventListener(e,s)]},on(){let e=[...arguments],t=b;e[0]instanceof HTMLElement&&(t=e.shift()),e[0]=W(e[0])||e[0],_.push(t.A(...e))},mute(e,t){let n=W(e)||e;_=_.reduce((s,a)=>{let[i,o]=s;return!e||a[0]===n&&!t||a[0]===n&&a[1]===t?a[1]():s.push(a),s},[])},say(e,t,n={detail:t,bubbles:!0,composed:!0}){b.dispatchEvent(new CustomEvent(W(e)||e,n))},do(e,t,n){b.say(e,t,n)},watch(e,t){r&&(r.takeRecords(),r.disconnect()),(e||t)&&(r=new MutationObserver(n=>[...n].map(n=>{let{type:s,addedNodes:a,removedNodes:i}=n;"childList"===s&&[...a||i].filter(e=>!["#text","#comment"][f](e[E])).map(n=>{(a?e:t)(n)})})).observe(b[R],{childList:!0,subtree:!0}))},toslot(e){let n,s,a;(n=l(b))[k]=b[k],n.id=b.id+P,s=c(b),b.show(0),e[x](b),a=c(b),n[$].position="absolute",t.body[x](n),b.show(),n.bye()},bye(){b.parentNode.removeChild(b)}}),n.assign(b,a),b.constructor.observedAttributes.map(e=>{n.defineProperty(b,e,{get:()=>b[p](e),set(t){t?b[u](e,t):b.removeAttribute(e)}})}),(i=t.getElementById(b[E]))?(b[R]=b.attachShadow({mode:"open"}),b[R][x](l(i.content))):b[R]=b}attributeChangedCallback(e,t,n){this.T&&this.T(e,t,n),Z[f](e)&&this.S(e,n)}connectedCallback(){this.O()}disconnectedCallback(){this.mute(),this.watch(),this.say(G)}}let r=e=>Array.isArray(e)?e[r(e[m])]:0|e*Math.random(),l=e=>e.cloneNode(1),d=e=>"function"==typeof e,c=(n,s=n.getBoundingClientRect(),a=t.documentElement)=>({[v]:s[v]+(e.pageYOffset||a[T]),[L]:s[L]+(e.pageXOffset||a[N]),[_]:n[_],[S]:n[S],[g]:n[g],[A]:n[A]}),m="length",p="getAttribute",u="setAttribute",E="nodeName",h="innerHTML",$="style",f="includes",y="offset",C="transform",b="duration",_=y+"Left",S=y+"Top",g=y+"Height",A=y+"Width",v="top",L="left",T="scrollTop",N="scrollLeft",x="appendChild",w="none",R="$Element_Root",O=a+"-",k="state",D="cardsize",M="facetype",q="index",P="animation",B="layout",z="rotate",H="translatex",I="translatey",Y="face",F="back",V="match",Z=[B,k,y+"y",y+"x",z,I,H],j="transform",K=a+"_",W=e=>[K+"ALLELEMENTS",K+"ALL",K+"SELECT",K+"REMEMBER",K+"PEEKCARDTS",K+"OPENCARDTS",K+"CLOSE",K+"FINDSLOT",K+"CONNECT",K+"DISCONNECT"][e],X=8,G=9,J="Slot",Q=O+"AREA",U=O+"ZONE",ee=O+"SLOT",te=O+"CARDT",ne=e=>e.toLowerCase(),se=e[a]=e[a]||{};se.Elements=se.Elements||{},se.extend=((e,t,n,s=O)=>{try{customElements.define(ne(s+t),se.Elements[ne(t)]=n(se.Elements[ne(e)]))}catch(e){}}),[["AREA",class extends o{static get observedAttributes(){return["cards",D]}constructor(e){super({C(){(e=this).on(2,t=>{let n=t.path[0].id;(()=>{let t,s=[];e.say(n,(a,i)=>{s.push(i),clearTimeout(t),t=setTimeout(()=>{if(s.every(e=>e[k]===Y))e.say(5,V);else{let a=s[m],i=[];e.say(5,(s,o)=>{i.push(o),clearTimeout(t),t=setTimeout(()=>{1==i[m]?e.say(n,4):a==i[m]&&(e.say(5,3),i.forEach(e=>e.mute(5)))},2)})}},2)})})()})},T(t,n,s){t===D?this.S(D,s+"px"):e&&e.D}})}}],["ZONE",class extends o{static get observedAttributes(){return[...Z,"max"]}constructor(e,n){super({C(){e=(n=this).find(Q),n.on(e,7,e=>e.detail()),n.watch(e=>{},e=>{n.G().map((e,t)=>{e.S(q)!=t&&(c(e),c(e),e.S(q,t))})}),[B].map(e=>n.Q(`STYLE[${e}]`).map(t=>t.disabled=t[p](e)!=n[e]));for(let e=n.max;e--;)n.$zone_appendChild(t.createElement(ee))},$zone_appendChild(e=0,n=this[p]("slotsto")||J,s=e){return n!=w&&e[E]!=ee&&(s=t.createElement(O+n.replace(O,"")),e&&s[x](e)),this[R][x](s)},P(e,s=e,a=2,i,o=t.createDocumentFragment()){if(Array.isArray(e))e.map(n.P);else for((i=t.createElement(te)).id=e,i[h]=`<div slot=face>${s}</div>`,i.S("Fbgd",`rgb(${r(150)},${r(150)},${r(150)})`);a--;)n.$zone_appendChild(l(i),ee)}})}}],[J,class extends o{static get observedAttributes(){return Z}}],["CARDT",class extends o{static get observedAttributes(){return[...Z,M,P]}constructor(e,t,n,a){let i,o,l,c=(e,t)=>i[$].setProperty("--"+e,t);super({C(){if(e=(a=this).find(Q),n=a.find(ee),t=a.find(U),i=a.Q(".card")[0],o=i.classList,a[u]("data-"+J,n?n.id:w),a[M]=a.id[f]("/")?"img":(e=>1===e[m]||2===e[m]&&e.codePointAt(0)>255)(a.id)?"char":"word",a[k]=t&&t[k]?t[k]:Y,a.D);else{if(!a.id[f](P)){let e=()=>r([-2,-1,0,1,2])+"px";c(H,e()),c(I,e()),c(z,r([-1.5,-1,-.5,.5,1,1.5])),o.add(j),t&&(a[B]=t[p](B))}i[u](k,a[k]),i[u](M,a[M])}t&&"memory"==t[p]("listen")&&(a.mute(),a.on("click",t=>{a[k]=Y,a.on(e,5,e=>{d(e.detail)?e.detail(e,a):(a[P]=e.detail,e.detail===V?(o.remove(j),a[k]=V):l=setTimeout(()=>{a[k]=F,c("Bcntnt","'!'"),c("Bclr","#050")},1e3))},{}),a.say(2,t.type)}),a.on(e,a.id,e=>{let t=e.detail;d(t)&&t(e,a),a[k]==F&&(a[P]=W(4))}),a.on(e,1,e=>{a[k]==Y&&3==a[P]&&(a[k]=F,clearTimeout(l),a[P]=w)}))},toid:e=>a[P]=["move:"+e],to:e=>{let t=e.free();t&&a.toid(t[0].id)},T(e,n,o){if(a=this,i&&[k].map(e=>i[u](e,a[e])),e===P){let e,n,i,r={[b]:500},l=()=>{},d="easing",c="ease",p="opacity",u=e=>`scale(${s(e)})`,E=(e,t,n)=>`translate3d(${e}px,${t}px,${n}px)`;if(o==w)i&&i.cancel();else if(o==W(4))e=[[0,0],[-1,1],[1,2],[-1,3],[1,4],[-1,5],[1,6],[-1,7],[1,8],[-1,8],[1,10]],n=(e=>({[C]:E(10*e[0],0,0),[y]:e[1]/10,[d]:[c]}));else if(o==V)e=[[1,0,w],[0,1,E(20,0,0)+"rotate3d(0,0,1,120deg)"]],n=(e=>({[p]:e[0],[y]:e[1],[d]:[c],[C]:e[2]})),l=a.bye;else if(3==o)e=[[1,0],[1.3,.8],[1,1]],n=(e=>({[C]:u(e[0]),[y]:e[1]})),r={[b]:999,[d]:"ease-in-out",fill:"forwards"};else if(o[f]("move")){let e=o.split(":")[1];e&&a.say(7,n=>{let s=t.free(e);s[m]&&a.toslot(s[0])})}e&&((i=a.animate(e.map(n),r)).onfinish=l)}}})}}]].map(e=>{let t=ne(e[0]),n=ne(O+t);se.Elements[t]=e[1],customElements.define(n,e[1])})})(window,document,Object,String);//# sourceMappingURL=./cardts.min.beautify.js.map