UNPKG

nodality

Version:

A lightweight library for declarative UI elements.

2 lines 5.95 kB
/*! For license information please see transformanim.esm.js.LICENSE.txt */ var t={d:(e,a)=>{for(var i in a)t.o(a,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:a[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function a(t){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},a(t)}function i(t,e){for(var a=0;a<e.length;a++){var i=e[a];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,n(i.key),i)}}function n(t){var e=function(t){if("object"!=a(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,"string");if("object"!=a(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==a(e)?e:e+""}t.d(e,{A:()=>r});var r=function(){return t=function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.data=e,this.targetHeight=this.data.targetHeight,void 0===this.data.type?this.type="default":this.type=this.data.type,this.layout="flex",this.setup()},(e=[{key:"toCode",value:function(){return[""]}},{key:"set",value:function(t){return console.log("WHY NOT 900"),t.arrayPadding&&(this.wrdiv.style.marginTop=t.arrayPadding.value),t.height&&(this.wrdiv.style.height=t.height),this}},{key:"setup",value:function(){var t=this,e=document.createElement("div");this.wrdiv=e,e.style.display="flex",e.style.flexDirection="column",this.data.overflow&&(e.style.overflow="hidden"),e.style.display="flex",e.style.justifyContent="center",e.style.alignItems="center",e.style.background="orange",e.style.height="900px",this.data.sticky||(e.style.position="fixed"),e.style.marginTop="0px";var a=document.createElement("img");a.style.gridArea="1/1",a.style.display="none",a.style.width="50%",a.setAttribute("class","m2"),e.appendChild(a),this.data.view&&(this.m2img=this.data.view.render(),e.appendChild(this.m2img)),this.data.paragraph&&(this.paragraph=this.data.paragraph.render(),e.appendChild(this.paragraph)),this.data.view&&(a.style.display="none");var i=document.createElement("h2");i.style.fontFamily="Arial",i.style.fontSize="2.4rem",i.style.background="linear-gradient(#3498db, #1abc9c)",i.style.webkitBackgroundClip="text",i.style.webkitTextFillColor="transparent";var n=document.createTextNode("Supercharged");i.appendChild(n),!0!==this.data.showTitle&&void 0!==this.data.showTitle||(this.data.content&&this.data.content.render?e.appendChild(this.data.content.render()):e.appendChild(i));var r=document.createElement("p");document.createTextNode("Hello"),e.appendChild(r),this.res=e,window.addEventListener("scroll",(function(n){return t.resize(e,a,i)})),this.resize(e,a,i)}},{key:"setStickyData",value:function(t){return this.data.stickyData=t,this}},{key:"toAuto",value:function(){return this.res.style.height="auto",this}},{key:"stick",value:function(t){return t?(t.offset&&(null!=this.data.stickyData?this.data.stickyData.top=t.offset:(this.data.stickyData={top:t.offset},this.fixedToRelative(!0))),t.value?this.makeSticky():this.noSticky(),this):(this.makeSticky(),this)}},{key:"makeSticky",value:function(){return this.wrdiv.style.position="sticky",this.wrdiv.style.top=0,this}},{key:"setProps",value:function(t){return t.targetHeight&&(this.data.targetHeight=t.targetHeight),t.flagValue&&(this.data.flagValue=t.flagValue),this}},{key:"noSticky",value:function(){return this.wrdiv.style.position="",this}},{key:"toSticky",value:function(){return this.wrdiv.style.position="sticky",this.wrdiv.style.top="0",this}},{key:"toOpacity",value:function(t){this.res.style.opacity="".concat(t)}},{key:"setUncomment",value:function(t){this.data.uncomment=t}},{key:"fixedToRelative",value:function(t){return this.data.uncomment=t,this}},{key:"mask",value:function(t){var e=this;return window.addEventListener("scroll",(function(){e.innerMask(t)})),this}},{key:"innerMask",value:function(t){if(t){var e=s(window.scrollY,{min:t.start,max:t.end},{min:7,max:0});console.warn(e),console.warn(window.scrollY),s(window.scrollY,{min:t.start,max:t.end},{min:37,max:37})}return this}},{key:"setScale",value:function(t){var e=this;return this.data.range=t,this.m2img.style.transform="scale(".concat(this.data.range.scaleMax,")"),window.addEventListener("scroll",(function(){var t=s(window.scrollY,{min:e.data.range.min,max:e.data.range.max},{min:e.data.range.scaleMax,max:e.data.range.scaleMin});null!=e.m2img&&(e.m2img.style.transform="scale(".concat(t,")"))})),this}},{key:"resize",value:function(t,e,a){var i=window.scrollY||document.documentElement.scrollTop;if(i>this.lastScrollTop?this.isUp=!1:this.isUp=!0,this.data.sticky)t.style.background="#fafafa";else if(this.data.stickyData){var n=this.data.stickyData.top;this.data.uncomment&&(window.scrollY>n?(t.style.background="pink",t.style.position="relative",t.style.top=n):(t.style.background="orange",t.style.top=0,t.style.position="fixed"))}this.lastScrollTop=i<=0?0:i;var r=e;this.m2img=e,this.data.view&&(r=this.m2img);var o=s(window.scrollY,{min:3150,max:3300},{min:0,max:100}),l=s(window.scrollY,{min:3150,max:3300},{min:60,max:80}),c=s(window.scrollY,{min:3150,max:3300},{min:0,max:40});this.data.operation&&"translate"===this.data.operation.type&&(r.style.transform="translate3d(".concat(o,"%, ").concat(o/2,"%, 0px) scale(").concat(l/100,") rotate(").concat(c,"deg)"))}},{key:"render",value:function(t){if(!t)return this.res;document.querySelector(t).appendChild(this.res)}}])&&i(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function s(t,e,a){t<e.min&&(t=e.min),t>e.max&&(t=e.max);var i=(t-e.min)/(e.max-e.min);e.min>e.max&&(i=(t-e.max)/(e.min-e.max));var n=(a.min-a.max)*i-a.min;if(n=Math.abs(n),a.min<a.max){var r=(a.max+Math.abs(a.min))*i;n=a.min+r}return n}var o=e.A;export{o as TransformAnim};