bb-react-pose-text
Version:
Easily animate characters and words with React Pose
2 lines (1 loc) • 2.53 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("bb-react-pose"),require("hey-listen")):"function"==typeof define&&define.amd?define(["exports","react","bb-react-pose","hey-listen"],e):e(t.splitText={},t.React,null,null)}(this,function(t,e,r,n){"use strict";var o="default"in e?e.default:e;r=r&&r.hasOwnProperty("default")?r.default:r;var i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};var s=function(){return(s=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};var a={display:"inline-block"},u=function(t){return n.invariant("string"==typeof t,"Child of SplitText must be a string"),{text:t,numChars:t.length,splitText:t.split(" ").map(function(t){return t.split("")})}},c=function(t){t.wordPoses,t.charPoses,t.children;return function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&(r[n[o]]=t[n[o]])}return r}(t,["wordPoses","charPoses","children"])},l=function(t){function e(e){var n=t.call(this,e)||this;n.state={};var o=e.wordPoses,i=e.charPoses,s=e.children;return u(s),o&&(n.Word=r.div(o)),i&&(n.Char=r.div(i)),n}return function(t,e){function r(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}(e,t),e.getDerivedStateFromProps=function(t,e){var r=t.children;return e&&r===e.text?null:u(r)},e.prototype.renderChars=function(t,e,r,n){var i=this,u=this.state.numChars,l=t.length,p=this.state.text;return t.map(function(t,d){return i.Char?o.createElement(i.Char,s({key:p+d,style:a,wordIndex:e,numWords:r,charIndex:n+d,charInWordIndex:d,numChars:u,numCharsInWord:l},c(i.props)),t):t})},e.prototype.renderWords=function(){var t=this,e=this.state,r=e.text,n=e.splitText,i=n.length,u=0;return n.map(function(e,n){var l=t.renderChars(e,n,i,u).concat([n!==i-1?" ":null]);return u+=e.length,t.Word?o.createElement(t.Word,s({key:r+n,style:a,wordIndex:n,numWords:i},c(t.props)),l):o.createElement("div",{style:a,key:r+n},l)})},e.prototype.render=function(){return this.renderWords()},e}(e.PureComponent);t.default=l,Object.defineProperty(t,"__esModule",{value:!0})});