-
Notifications
You must be signed in to change notification settings - Fork 129
/
index.js.map
1 lines (1 loc) · 5.73 KB
/
index.js.map
1
{"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["/**\n * @name setProps\n * @description Set the ityped properties configuration\n * @param {Object} config The configuration properties\n * @return {Promise}\n */\nconst setProps = ({\n strings = ['Put your strings here...', 'and Enjoy!'],\n typeSpeed = 100,\n backSpeed = 50,\n backDelay = 500,\n startDelay = 500,\n cursorChar = '|',\n placeholder = false,\n showCursor = true,\n disableBackTyping = false,\n onFinished = function () { },\n loop = true\n}) => ({\n strings,\n typeSpeed,\n backSpeed,\n cursorChar,\n backDelay,\n placeholder,\n startDelay,\n showCursor,\n loop,\n disableBackTyping,\n onFinished\n})\n\nexport const init = (element, properties) => {\n let i = 0, l, STRINGS_TO_ITERATE;\n\n const typewrite = (strings, props) => {\n if (i === l)\n if (props.loop) i = 0;\n setTimeout(() => { typeString(strings[i], props); }, props.startDelay);\n }\n\n const typeString = (str, props) => {\n let index = 0,\n strLen = str.length;\n let intervalID = setInterval(() => {\n props.placeholder ? element.placeholder += str[index] : element.textContent += str[index];\n if (++index === strLen) return onStringTyped(intervalID, props);\n }, props.typeSpeed);\n }\n\n const onStringTyped = (id, props) => {\n clearInterval(id);\n if (props.disableBackTyping && i === l - 1) {\n return props.onFinished()\n }\n if (!props.loop && i === l - 1) {\n return props.onFinished();\n }\n setTimeout(() => eraseString(props), props.backDelay);\n }\n\n const eraseString = (props) => {\n let str = props.placeholder ? element.placeholder : element.textContent,\n strLen = str.length;\n let intervalID = setInterval(() => {\n props.placeholder\n ? element.placeholder = element.placeholder.substr(0, --strLen)\n : element.textContent = str.substr(0, --strLen);\n if (strLen === 0) return onStringErased(intervalID, props);\n }, props.backSpeed);\n }\n\n const onStringErased = (id, props) => {\n clearInterval(id);\n ++i;\n typewrite(STRINGS_TO_ITERATE, props);\n }\n\n const setCursor = (element, props) => {\n let cursorSpan = document.createElement('span');\n cursorSpan.classList.add('ityped-cursor');\n cursorSpan.textContent = '|';\n cursorSpan.textContent = props.cursorChar;\n element.insertAdjacentElement('afterend', cursorSpan);\n }\n\n\n const startTyping = (prop) => {\n let props = setProps(prop || {})\n let strings = props.strings\n STRINGS_TO_ITERATE = strings\n l = strings.length\n if (typeof element === \"string\") element = document.querySelector(element)\n if (props.showCursor) setCursor(element, props)\n typewrite(strings, props)\n }\n\n return startTyping(properties)\n}"],"names":["setProps","strings","typeSpeed","backSpeed","backDelay","startDelay","cursorChar","placeholder","showCursor","disableBackTyping","onFinished","loop","init","element","properties","i","l","STRINGS_TO_ITERATE","typewrite","props","typeString","str","index","strLen","length","intervalID","setInterval","textContent","onStringTyped","id","eraseString","substr","onStringErased","setCursor","cursorSpan","document","createElement","classList","add","insertAdjacentElement","startTyping","prop","querySelector"],"mappings":";;;;;;;;;;;;AAAA;;;;;;AAMA,IAAMA,WAAW,SAAXA,QAAW;0BACfC,OADe;MACfA,OADe,gCACL,CAAC,0BAAD,EAA6B,YAA7B,CADK;4BAEfC,SAFe;MAEfA,SAFe,kCAEH,GAFG;4BAGfC,SAHe;MAGfA,SAHe,kCAGH,EAHG;4BAIfC,SAJe;MAIfA,SAJe,kCAIH,GAJG;6BAKfC,UALe;MAKfA,UALe,mCAKF,GALE;6BAMfC,UANe;MAMfA,UANe,mCAMF,GANE;8BAOfC,WAPe;MAOfA,WAPe,oCAOD,KAPC;6BAQfC,UARe;MAQfA,UARe,mCAQF,IARE;mCASfC,iBATe;MASfA,iBATe,yCASK,KATL;6BAUfC,UAVe;MAUfA,UAVe,mCAUF,YAAY,EAVV;uBAWfC,IAXe;MAWfA,IAXe,6BAWR,IAXQ;SAYV;oBAAA;wBAAA;wBAAA;0BAAA;wBAAA;4BAAA;0BAAA;0BAAA;cAAA;wCAAA;;GAZU;CAAjB;;AA0BA,AAAO,IAAMC,OAAO,SAAPA,IAAO,CAACC,OAAD,EAAUC,UAAV,EAAyB;MACvCC,IAAI,CAAR;MAAWC,UAAX;MAAcC,2BAAd;;M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