From 90e97e96e5f531492f9aac3efd6b611ffbe259ac Mon Sep 17 00:00:00 2001 From: Pierre DARRIEUTORT Date: Mon, 4 May 2020 22:05:15 +0200 Subject: [PATCH] updated module call behavior --- README.md | 11 +++++------ lib/fitext.min.js | 1 + package.json | 4 ++-- src/app.js | 12 +++++------- src/fitext.js | 2 +- 5 files changed, 14 insertions(+), 16 deletions(-) create mode 100644 lib/fitext.min.js diff --git a/README.md b/README.md index a0deaf5..c072e37 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@

fitext

Fitext is a module which adapts the textual elements so that they are always contained in their parents without ever exceeding whatever the parent height and width. This [lightweight](#performance-tips) library using no-one dependency. **You can find a playable demo [here](https://pierredarrieutort.github.io/fitext/).** -___
Logo fitext @@ -32,7 +31,7 @@ $ yarn add fitext ES6 Modules : ```js -import fitext from 'fitext/lib/fitext.min' +import fitext from 'fitext' const fittables = document.getElementsByClassName('fit-this-text'); fitext(fittables, true); @@ -51,7 +50,7 @@ No-module : ## Example ```js -import fitext from 'fitext/lib/fitext.min' +import fitext from 'fitext' ['DOMContentLoaded', 'resize'].forEach( e => window.addEventListener( e, adjustHeight ) ) @@ -101,9 +100,9 @@ The support is checked on [this range of browsers](https://browserl.ist/?q=defau Type|Value|Why this weight ? :----:|:-----:|--- -**Original**|1.81 kB| As developed, without any browser support and not as a module. [It's here](src/fitext.js, "Get the file"). -**Minified**|2.79 kB| With all [Browser Support](#browser-suport), as a module and of course minified ! -**Gzipped**|1.20 kB| Same as the minified version but you support gzip 🎉 ! +**Original**|2.16 kB| As developed, without any browser support and not as a module. [It's here](src/fitext.js, "Get the file"). +**Minified**|2.83 kB| With all [Browser Support](#browser-suport), as a module and of course minified ! +**Gzipped**|1.23 kB| Same as the minified version but you support gzip 🎉 ! - Try to use relative font-size wherever possible. - If you targeting a parent element all child are already taken in account, don't execute a `fitext` function on them. diff --git a/lib/fitext.min.js b/lib/fitext.min.js new file mode 100644 index 0000000..fdf2ca0 --- /dev/null +++ b/lib/fitext.min.js @@ -0,0 +1 @@ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.fitext=e():t.fitext=e()}(window,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";function n(t){return function(t){if(Array.isArray(t))return o(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return o(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r").concat(t.innerHTML,"
"));var r=t.firstElementChild,o=n(t.getElementsByTagName("*"));r.style.display="inline-block";var i,f;i=function(){var e=parseFloat(getComputedStyle(t).paddingTop),n=parseFloat(getComputedStyle(t).paddingBottom),o=t.offsetHeight-(e+n);return r.offsetHeight>o},f=function(t,e){return t.style.fontSize="".concat(parseFloat(getComputedStyle(t).fontSize)*e,"px")},o.forEach((function(t){t.dataset.size||(t.dataset.size=getComputedStyle(t).fontSize)})),function t(){if(i())for(;i();)o.forEach((function(t){return f(t,.99)}));else if(e)for(;!i();)o.forEach((function(t){return f(t,1.01)}));else o.forEach((function(t){return 1.01*parseFloat(t.style.fontSize) { const WRAPPER_CLASSNAME = 'fitter'