text: !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).VueClamp=t()}(this,function(){"use strict";var e=null;var t=null;function i(e,t){void 0===t&&(t={});var i=document.createElement(e);return Object.keys(t).forEach(function(e){i[e]=t[e]}),i}function s(e,t,i){return(window.getComputedStyle(e,i||null)||{display:"none"})[t]}function r(e){if(!document.documentElement.contains(e))return{detached:!0,rendered:!1};for(var t=e;t!==document;){if("none"===s(t,"display"))return{detached:!1,rendered:!1};t=t.parentNode}return{detached:!1,rendered:!0}}var n='.resize-triggers{visibility:hidden;opacity:0}.resize-contract-trigger,.resize-contract-trigger:before,.resize-expand-trigger,.resize-triggers{content:"";position:absolute;top:0;left:0;height:100%;width:100%;overflow:hidden}.resize-contract-trigger,.resize-expand-trigger{background:#eee;overflow:auto}.resize-contract-trigger:before{width:200%;height:200%}',o=0,a=null;function _(e,t){if(e.__resize_mutation_handler__||(e.__resize_mutation_handler__=function(){var e=r(this),t=e.rendered,i=e.detached;t!==this.__resize_rendered__&&(!i&&this.__resize_triggers__&&(h(this),this.addEventListener("scroll",l,!0)),this.__resize_rendered__=t,d(this))}.bind(e)),!e.__resize_listeners__)if(e.__resize_listeners__=[],window.ResizeObserver){var _=e.offsetWidth,c=e.offsetHeight,f=new ResizeObserver(function(){(e.__resize_observer_triggered__||(e.__resize_observer_triggered__=!0,e.offsetWidth!==_||e.offsetHeight!==c))&&d(e)}),u=r(e),p=u.detached,g=u.rendered;e.__resize_observer_triggered__=!1===p&&!1===g,e.__resize_observer__=f,f.observe(e)}else if(e.attachEvent&&e.addEventListener)e.__resize_legacy_resize_handler__=function(){d(e)},e.attachEvent("onresize",e.__resize_legacy_resize_handler__),document.addEventListener("DOMSubtreeModified",e.__resize_mutation_handler__);else if(o||(a=function(e){var t=document.createElement("style");return t.type="text/css",t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e)),(document.querySelector("head")||document.body).appendChild(t),t}(n)),function(e){var t=s(e,"position");t&&"static"!==t||(e.style.position="relative");e.__resize_old_position__=t,e.__resize_last__={};var r=i("div",{className:"resize-triggers"}),n=i("div",{className:"resize-expand-trigger"}),o=i("div"),a=i("div",{className:"resize-contract-trigger"});n.appendChild(o),r.appendChild(n),r.appendChild(a),e.appendChild(r),e.__resize_triggers__={triggers:r,expand:n,expandChild:o,contract:a},h(e),e.addEventListener("scroll",l,!0),e.__resize_last__={width:e.offsetWidth,height:e.offsetHeight}}(e),e.__resize_rendered__=r(e).rendered,window.MutationObserver){var m=new MutationObserver(e.__resize_mutation_handler__);m.observe(document,{attributes:!0,childList:!0,characterData:!0,subtree:!0}),e.__resize_mutation_observer__=m}e.__resize_listeners__.push(t),o++}function l(){var i,s,r=this;h(this),this.__resize_raf__&&(i=this.__resize_raf__,t||(t=(window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||function(e){clearTimeout(e)}).bind(window)),t(i)),this.__resize_raf__=(s=function(){var e,t,i,s,n,o,a=(t=(e=r).__resize_last__,i=t.width,s=t.height,n=e.offsetWidth,o=e.offsetHeight,n!==i||o!==s?{width:n,height:o}:null);a&&(r.__resize_last__=a,d(r))},e||(e=(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(e){return setTimeout(e,16)}).bind(window)),e(s))}function d(e){e&&e.__resize_listeners__&&e.__resize_listeners__.forEach(function(t){t.call(e)})}function h(e){var t=e.__resize_triggers__,i=t.expand,s=t.expandChild,r=t.contract,n=r.scrollWidth,o=r.scrollHeight,a=i.offsetWidth,_=i.offsetHeight,l=i.scrollWidth,d=i.scrollHeight;r.scrollLeft=n,r.scrollTop=o,s.style.width=a+1+"px",s.style.height=_+1+"px",i.scrollLeft=l,i.scrollTop=d}var c=["maxLines","maxHeight","ellipsis","isClamped"],f=["tag","text","autoresize"];return{name:"vue-clamp",props:{tag:{type:String,default:"div"},autoresize:{type:Boolean,default:!1},maxLines:Number,maxHeight:[String,Number],ellipsis:{type:String,default:"…"},expanded:Boolean},data:function(){return{offset:null,text:this.getText(),localExpanded:!!this.expanded}},computed:{clampedText:function(){return this.text.slice(0,this.offset)+this.ellipsis},isClamped:function(){return!!this.text&&this.offset!==this.text.length},realText:function(){return this.isClamped?this.clampedText:this.text},realMaxHeight:function(){if(this.localExpanded)return null;var e=this.maxHeight;return e?"number"==typeof e?e+"px":e:null}},watch:{expanded:function(e){this.localExpanded=e},isClamped:function(e){var t=this;this.$nextTick().then(function(){return t.$emit("change",e)})},localExpanded:function(e){e?this.clampAt(this.text.length):this.update(),this.expanded!==e&&this.$emit("update:expanded",e)}},mounted:function(){var e=this;this.init(),f.forEach(function(t){e.$watch(t,e.init)}),c.forEach(function(t){e.$watch(t,e.update)})},updated:function(){this.text=this.getText(),this.applyChange()},beforeDestroy:function(){this.cleanUp()},methods:{init:function(){var e=this;if(this.$slots.default){if(this.offset=this.text.length,this.cleanUp(),this.autoresize){var t=function(){e.update()};_(this.$el,t),this.unregisterResizeCallback=function(){!function(e,t){if(e.detachEvent&&e.removeEventListener)return e.detachEvent("onresize",e.__resize_legacy_resize_handler__),void document.removeEventListener("DOMSubtreeModified",e.__resize_mutation_handler__);var i=e.__resize_listeners__;i&&(i.splice(i.indexOf(t),1),i.length||(e.__resize_observer__?(e.__resize_observer__.unobserve(e),e.__resize_observer__.disconnect(),e.__resize_observer__=null):(e.__resize_mutation_observer__&&(e.__resize_mutation_observer__.disconnect(),e.__resize_mutation_observer__=null),e.removeEventListener("scroll",l),e.removeChild(e.__resize_triggers__.triggers),e.__resize_triggers__=null),e.__resize_listeners__=null),!--o&&a&&a.parentNode.removeChild(a))}(e.$el,t)}}this.update()}},update:function(){this.localExpanded||(this.applyChange(),(this.isOverflow()||this.isClamped)&&this.search())},expand:function(){this.localExpanded=!0},collapse:function(){this.localExpanded=!1},toggle:function(){this.localExpanded=!this.localExpanded},getLines:function(){return this.$refs.content.getClientRects().length},isOverflow:function(){return!(!this.maxLines&&!this.maxHeight)&&(!!(this.maxLines&&this.getLines()>this.maxLines)||!!(this.maxHeight&&this.$el.scrollHeight>this.$el.offsetHeight))},getText:function(){var e=(this.$slots.default||[]).filter(function(e){return!e.tag&&!e.isComment})[0];return e?e.text:""},moveEdge:function(e){this.clampAt(this.offset+e)},clampAt:function(e){this.offset=e,this.applyChange()},applyChange:function(){this.$refs.text.textContent=this.realText},stepToFit:function(){this.fill(),this.clamp()},fill:function(){for(;(!this.isOverflow()||this.getLines()<2)&&this.offset<this.text.length;)this.moveEdge(1)},clamp:function(){for(;this.isOverflow()&&this.getLines()>1&&this.offset>0;)this.moveEdge(-1)},search:function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var i=e[0];void 0===i&&(i=0);var s=e[1];if(void 0===s&&(s=this.offset),s-i<=3)this.stepToFit();else{var r=Math.floor((s+i)/2);this.clampAt(r),this.isOverflow()?this.search(i,r):this.search(r,s)}},cleanUp:function(){this.unregisterResizeCallback&&this.unregisterResizeCallback()}},render:function(e){var t=[e("span",{ref:"text",attrs:{"aria-label":this.text.trim()}},this.realText)],i={expand:this.expand,collapse:this.collapse,toggle:this.toggle,clamped:this.isClamped,expanded:this.localExpanded},s=this.$scopedSlots.before?this.$scopedSlots.before(i):this.$slots.before;s&&t.unshift.apply(t,Array.isArray(s)?s:[s]);var r=this.$scopedSlots.after?this.$scopedSlots.after(i):this.$slots.after;r&&t.push.apply(t,Array.isArray(r)?r:[r]);var n=[e("span",{style:{boxShadow:"transparent 0 0"},ref:"content"},t)];return e(this.tag,{style:{maxHeight:this.realMaxHeight,overflow:"hidden"}},n)}}});
  