Comparing version
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.VueSnip=t():e.VueSnip=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);var r={directiveName:"snip",snipMethod:"css",maxLines:3,resizeObserverPolyfill:null},i=function(e,t){var n=parseInt(t);if(!Number.isNaN(n))return n;var i=e.options.maxLines,o=parseInt(i);return Number.isNaN(o)?r.maxLines:o},o=function(e,t){if("css"===t||"js"===t)return t;var n=e.options.snipMethod;return"css"===n||"js"===n?n:r.snipMethod};function s(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var n=[],r=!0,i=!1,o=void 0;try{for(var s,u=e[Symbol.iterator]();!(r=(s=u.next()).done)&&(n.push(s.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw o}}return n}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return u(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return u(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var c=function(e,t){return function(n,r){var u=r.value,c=r.arg,a=e.elementMap,l=new(function(e){return window.ResizeObserver||e.resizeObserverPolyfill}(e.options))((function(e){s(e,1)[0].contentRect.width!==a.get(n).prevWidth&&(t(n),a.get(n).prevWidth=n.clientWidth)}));l.observe(n),a.set(n,{observer:l,fullText:n.textContent,maxLines:i(e,u),snipMethod:o(e,c)})}};function a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var l=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.el=t,this.state=n,this.unprocessed=null,this.processed=null,this.optout=!1}var t,n,r;return t=e,(n=[{key:"_snipChunks",value:function(e){var t=this;if(!this.unprocessed||this.optout)return this;var n=this.unprocessed.split(e);return this.unprocessed=n.find((function(n){if(t.el.textContent="".concat(t.processed).concat(n).concat("..."),!t._isWithinRange())return!0;t.processed="".concat(t.processed).concat(n).concat(e)})),this}},{key:"_isWithinRange",value:function(){return e=this.el,t=window.getComputedStyle(e),n=parseInt(t.height),r="normal"===t.lineHeight?1.2*parseInt(t.fontSize):parseInt(t.lineHeight),(0===n&&0===r?0:Math.ceil(n/r))<=this.state.elementMap.get(this.el).maxLines;var e,t,n,r}},{key:"initText",value:function(){var e=this.state.elementMap.get(this.el),t=e.fullText;return e.maxLines<=0?(this.optout=!0,this):(this.optout=this._isWithinRange(),this.unprocessed=t,this.processed="",this)}},{key:"snipSentences",value:function(){return this._snipChunks(". ")}},{key:"snipSubsentences",value:function(){return this._snipChunks(", ")}},{key:"snipWords",value:function(){return this._snipChunks(" ")}},{key:"addEllipsis",value:function(){if(!this.optout){for(;[" ",".",","].includes(this.processed[this.processed.length-1]);)this.processed=this.processed.substring(0,this.processed.length-1);this.el.textContent="".concat(this.processed).concat("...")}}}])&&a(t.prototype,n),r&&a(t,r),e}(),p=function(e){var t={elementMap:new WeakMap,options:e},n=function(e){return function(t){var n=e.elementMap.get(t),r=n.fullText,i=n.maxLines,o=n.snipMethod;if(t.textContent=r,"css"!==o)return"js"===o?(t.style="",new l(t,e).initText().snipSentences().snipSubsentences().snipWords().addEllipsis()):void 0;t.style="display: -webkit-box; -webkit-line-clamp: ".concat(i,"; -webkit-box-orient: vertical; overflow: hidden;")}}(t);return{directiveName:function(e){return e.options.directiveName}(t),inserted:c(t,n),update:function(e,t){return function(n,r){var s=r.value,u=r.arg,c=e.elementMap;c.get(n).maxLines=i(e,s),c.get(n).snipMethod=o(e,u),t(n)}}(t,n),unbind:function(e){return function(t){var n=e.elementMap;n.delete(t),n.get(t).observer.disconnect()}}(t)}};function f(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function d(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?f(Object(n),!0).forEach((function(t){h(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):f(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function h(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}t.default={install:function(e,t){t=d(d({},r),{},{options:t});var n=p(t),i=n.directiveName,o=n.inserted,s=n.update,u=n.unbind;e.directive(i,{inserted:o,update:s,unbind:u})}}}])})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.VueSnip=t():e.VueSnip=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);var r={directiveName:"snip",snipMethod:"css",maxLines:3,resizeObserverPolyfill:null},i=function(e,t){var n=parseInt(t);if(!Number.isNaN(n))return n;var i=e.options.maxLines,o=parseInt(i);return Number.isNaN(o)?r.maxLines:o},o=function(e,t){if(!(CSS&&CSS.supports("display","-webkit-box")&&CSS.supports("-webkit-line-clamp","3")&&CSS.supports("-webkit-box-orient","vertical")))return"js";if("css"===t||"js"===t)return t;var n=e.options.snipMethod;return"css"===n||"js"===n?n:r.snipMethod};function s(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var n=[],r=!0,i=!1,o=void 0;try{for(var s,u=e[Symbol.iterator]();!(r=(s=u.next()).done)&&(n.push(s.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw o}}return n}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return u(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return u(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var c=function(e,t){return function(n,r){var u=r.value,c=r.arg,a=e.elementMap,l=new(function(e){return window.ResizeObserver||e.resizeObserverPolyfill}(e.options))((function(e){s(e,1)[0].contentRect.width!==a.get(n).prevWidth&&(t(n),a.get(n).prevWidth=n.clientWidth)}));l.observe(n),a.set(n,{observer:l,fullText:n.textContent,maxLines:i(e,u),snipMethod:o(e,c)})}};function a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var l=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.el=t,this.state=n,this.unprocessed=null,this.processed=null,this.optout=!1}var t,n,r;return t=e,(n=[{key:"_snipChunks",value:function(e){var t=this;if(!this.unprocessed||this.optout)return this;var n=this.unprocessed.split(e);return this.unprocessed=n.find((function(n){if(t.el.textContent="".concat(t.processed).concat(n).concat("..."),!t._isWithinRange())return!0;t.processed="".concat(t.processed).concat(n).concat(e)})),this}},{key:"_isWithinRange",value:function(){return e=this.el,t=window.getComputedStyle(e),n=parseInt(t.height),r="normal"===t.lineHeight?1.2*parseInt(t.fontSize):parseInt(t.lineHeight),(0===n&&0===r?0:Math.ceil(n/r))<=this.state.elementMap.get(this.el).maxLines;var e,t,n,r}},{key:"initText",value:function(){var e=this.state.elementMap.get(this.el),t=e.fullText;return e.maxLines<=0?(this.optout=!0,this):(this.optout=this._isWithinRange(),this.unprocessed=t,this.processed="",this)}},{key:"snipSentences",value:function(){return this._snipChunks(". ")}},{key:"snipSubsentences",value:function(){return this._snipChunks(", ")}},{key:"snipWords",value:function(){return this._snipChunks(" ")}},{key:"addEllipsis",value:function(){if(!this.optout){for(;[" ",".",","].includes(this.processed[this.processed.length-1]);)this.processed=this.processed.substring(0,this.processed.length-1);this.el.textContent="".concat(this.processed).concat("...")}}}])&&a(t.prototype,n),r&&a(t,r),e}(),p=function(e){var t={elementMap:new WeakMap,options:e},n=function(e){return function(t){var n=e.elementMap.get(t),r=n.fullText,i=n.maxLines,o=n.snipMethod;if(t.textContent=r,"css"!==o)return"js"===o?(t.style="",new l(t,e).initText().snipSentences().snipSubsentences().snipWords().addEllipsis()):void 0;t.style="display: -webkit-box; -webkit-line-clamp: ".concat(i,"; -webkit-box-orient: vertical; overflow: hidden;")}}(t);return{directiveName:function(e){return e.options.directiveName}(t),inserted:c(t,n),update:function(e,t){return function(n,r){var s=r.value,u=r.arg,c=e.elementMap;c.get(n).maxLines=i(e,s),c.get(n).snipMethod=o(e,u),t(n)}}(t,n),unbind:function(e){return function(t){var n=e.elementMap;n.delete(t),n.get(t).observer.disconnect()}}(t)}};function f(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function d(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?f(Object(n),!0).forEach((function(t){h(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):f(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function h(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}t.default={install:function(e,t){t=d(d({},r),{},{options:t});var n=p(t),i=n.directiveName,o=n.inserted,s=n.update,u=n.unbind;e.directive(i,{inserted:o,update:s,unbind:u})}}}])})); |
{ | ||
"name": "vue-snip", | ||
"version": "1.0.0-alpha.2", | ||
"version": "1.0.0-alpha.3", | ||
"author": "Andrej Bilec <andrej.bilec@gmail.com>", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -7,2 +7,4 @@ # vue-snip | ||
 | ||
 | ||
 | ||
@@ -9,0 +11,0 @@ Vue.js directive that clamps the content of a text element if it exceeds specified number of lines. |
9902
2.87%25
8.7%