avances en plantillas

This commit is contained in:
JACS 2026-05-01 18:15:40 -05:00
parent 0f84beacf1
commit da0530d79b
2062 changed files with 598814 additions and 22 deletions

View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 Jack Moore
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,122 @@
## Changelog
##### v.6.0.1 - 2023-02-13
* Improved performance when appending text onto previous textarea value
##### v.6.0.0 - 2023-02-10
* Reworked to remove use of cached (potentially stale) style values. Fixes #404
* Dropped support for Internet Explorer
##### v.5.0.2 - 2022-11-20
* Avoid issue caused by using 'smooth' scroll-behavior
##### v.5.0.1 - 2021-06-30
* Changed module field to point to new ESM bundle. Fixes #391, closes #393
##### v.5.0.0 - 2021-05-17
* Add module field to package.json so autosize can be imported as an ES Module
##### v.4.0.4 - 2021-05-17
* Revert module field to package.json, will release as major version bump
##### v.4.0.3 - 2021-05-15
* Add module field to package.json so autosize can be imported as an ES Module
##### v.4.0.2 - 2018-04-30
* More specific detection of when to change overflow. Merges #361.
##### v.4.0.1 - 2018-03-23
* Minor refactor & updated build dependencies
##### v.4.0.0 - 2017-07-12
* Changed how Autosize determines the initial height. Fixes #336.
##### v.3.0.21 - 2017-05-19
* Fixed bug with overflow detection which degraded performance of textareas that exceed their max-width. Fixes #333.
##### v.3.0.20 - 2016-12-04
* Fixed minor bug where the `resized` event would not fire under specific conditions when changing the overflow.
##### v.3.0.19 - 2016-11-23
* Bubble dispatched events. Merged #319.
##### v.3.0.18 - 2016-10-26
* Fixed Firefox issue where calling dispatchEvent on a detached element throws an error. Fixes #317.
##### v.3.0.17 - 2016-7-25
* Fixed Chromium issue where getComputedStyle pixel value did not exactly match the style pixel value. Fixes #306.
* Removed undocumented argument, minor refactoring, more comments.
##### v.3.0.16 - 2016-7-13
* Fixed issue with overflowing parent elements. Fixes #298.
##### v.3.0.15 - 2016-1-26
* Used newer Event constructor, when available. Fixes #280.
##### v.3.0.14 - 2015-11-11
* Fixed memory leak on destroy. Merged #271, fixes #270.
* Fixed bug in old versions of Firefox (1-5), fixes #246.
##### v.3.0.13 - 2015-09-26
* Fixed scroll-bar jumpiness in iOS. Merged #261, fixes #207.
* Fixed reflowing of initial text in Chrome and Safari.
##### v.3.0.12 - 2015-09-14
* Merged changes were discarded when building new dist files. Merged #255, Fixes #257 for real this time.
##### v.3.0.11 - 2015-09-14
* Fixed regression from 3.0.10 that caused an error with ES5 browsers. Merged #255, Fixes #257.
##### v.3.0.10 - 2015-09-10
* Removed data attribute as a way of tracking which elements autosize has been assigned to. fixes #254, fixes #200.
##### v.3.0.9 - 2015-09-02
* Fixed issue with assigning autosize to detached nodes. Merged #253, Fixes #234.
##### v.3.0.8 - 2015-06-29
* Fixed the `autosize:resized` event not being triggered when the overflow changes. Fixes #244.
##### v.3.0.7 - 2015-06-29
* Fixed jumpy behavior in Windows 8.1 mobile. Fixes #239.
##### v.3.0.6 - 2015-05-19
* Renamed 'dest' folder to 'dist' to follow common conventions.
##### v.3.0.5 - 2015-05-18
* Do nothing in Node.js environment.
##### v.3.0.4 - 2015-05-05
* Added options object for indicating if the script should set the overflowX and overflowY. The default behavior lets the script control the overflows, which will normalize the appearance between browsers. Fixes #220.
##### v.3.0.3 - 2015-04-23
* Avoided adjusting the height for hidden textarea elements. Fixes #155.
##### v.3.0.2 - 2015-04-23
* Reworked to respect max-height of any unit-type. Fixes #191.
##### v.3.0.1 - 2015-04-23
* Fixed the destroy event so that it removes its own event handler. Fixes #218.
##### v.3.0.0 - 2015-04-15
* Added new methods for updating and destroying:
* autosize.update(elements)
* autosize.destroy(elements)
* Renamed custom events as to not use jQuery's custom events namespace:
* autosize.resized renamed to autosize:resized
* autosize.update renamed to autosize:update
* autosize.destroy renamed to autosize:destroy
##### v.2.0.1 - 2015-04-15
* Version bump for NPM publishing purposes
##### v.2.0.0 - 2015-02-25
* Smaller, simpler code-base
* New API. Example usage: `autosize(document.querySelectorAll(textarea));`
* Dropped jQuery dependency
* Dropped IE7-IE8 support
* Dropped optional parameters
* Closes #98, closes #106, closes #123, fixes #129, fixes #132, fixes #139, closes #140, closes #166, closes #168, closes #192, closes #193, closes #197

View file

@ -0,0 +1 @@
var e=new Map;function t(t){var o=e.get(t);o&&o.destroy()}function o(t){var o=e.get(t);o&&o.update()}var r=null;"undefined"==typeof window?((r=function(e){return e}).destroy=function(e){return e},r.update=function(e){return e}):((r=function(t,o){return t&&Array.prototype.forEach.call(t.length?t:[t],function(t){return function(t){if(t&&t.nodeName&&"TEXTAREA"===t.nodeName&&!e.has(t)){var o,r=null,n=window.getComputedStyle(t),i=(o=t.value,function(){a({testForHeightReduction:""===o||!t.value.startsWith(o),restoreTextAlign:null}),o=t.value}),l=function(o){t.removeEventListener("autosize:destroy",l),t.removeEventListener("autosize:update",s),t.removeEventListener("input",i),window.removeEventListener("resize",s),Object.keys(o).forEach(function(e){return t.style[e]=o[e]}),e.delete(t)}.bind(t,{height:t.style.height,resize:t.style.resize,textAlign:t.style.textAlign,overflowY:t.style.overflowY,overflowX:t.style.overflowX,wordWrap:t.style.wordWrap});t.addEventListener("autosize:destroy",l),t.addEventListener("autosize:update",s),t.addEventListener("input",i),window.addEventListener("resize",s),t.style.overflowX="hidden",t.style.wordWrap="break-word",e.set(t,{destroy:l,update:s}),s()}function a(e){var o,i,l=e.restoreTextAlign,s=void 0===l?null:l,d=e.testForHeightReduction,u=void 0===d||d,c=n.overflowY;if(0!==t.scrollHeight&&("vertical"===n.resize?t.style.resize="none":"both"===n.resize&&(t.style.resize="horizontal"),u&&(o=function(e){for(var t=[];e&&e.parentNode&&e.parentNode instanceof Element;)e.parentNode.scrollTop&&t.push([e.parentNode,e.parentNode.scrollTop]),e=e.parentNode;return function(){return t.forEach(function(e){var t=e[0],o=e[1];t.style.scrollBehavior="auto",t.scrollTop=o,t.style.scrollBehavior=null})}}(t),t.style.height=""),i="content-box"===n.boxSizing?t.scrollHeight-(parseFloat(n.paddingTop)+parseFloat(n.paddingBottom)):t.scrollHeight+parseFloat(n.borderTopWidth)+parseFloat(n.borderBottomWidth),"none"!==n.maxHeight&&i>parseFloat(n.maxHeight)?("hidden"===n.overflowY&&(t.style.overflow="scroll"),i=parseFloat(n.maxHeight)):"hidden"!==n.overflowY&&(t.style.overflow="hidden"),t.style.height=i+"px",s&&(t.style.textAlign=s),o&&o(),r!==i&&(t.dispatchEvent(new Event("autosize:resized",{bubbles:!0})),r=i),c!==n.overflow&&!s)){var v=n.textAlign;"hidden"===n.overflow&&(t.style.textAlign="start"===v?"end":"start"),a({restoreTextAlign:v,testForHeightReduction:!0})}}function s(){a({testForHeightReduction:!0,restoreTextAlign:null})}}(t)}),t}).destroy=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],t),e},r.update=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],o),e});var n=r;export default n;

View file

@ -0,0 +1,231 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.autosize = factory());
}(this, (function () {
var assignedElements = new Map();
function assign(ta) {
if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || assignedElements.has(ta)) return;
var previousHeight = null;
function cacheScrollTops(el) {
var arr = [];
while (el && el.parentNode && el.parentNode instanceof Element) {
if (el.parentNode.scrollTop) {
arr.push([el.parentNode, el.parentNode.scrollTop]);
}
el = el.parentNode;
}
return function () {
return arr.forEach(function (_ref) {
var node = _ref[0],
scrollTop = _ref[1];
node.style.scrollBehavior = 'auto';
node.scrollTop = scrollTop;
node.style.scrollBehavior = null;
});
};
}
var computed = window.getComputedStyle(ta);
function setHeight(_ref2) {
var _ref2$restoreTextAlig = _ref2.restoreTextAlign,
restoreTextAlign = _ref2$restoreTextAlig === void 0 ? null : _ref2$restoreTextAlig,
_ref2$testForHeightRe = _ref2.testForHeightReduction,
testForHeightReduction = _ref2$testForHeightRe === void 0 ? true : _ref2$testForHeightRe;
var initialOverflowY = computed.overflowY;
if (ta.scrollHeight === 0) {
// If the scrollHeight is 0, then the element probably has display:none or is detached from the DOM.
return;
} // disallow vertical resizing
if (computed.resize === 'vertical') {
ta.style.resize = 'none';
} else if (computed.resize === 'both') {
ta.style.resize = 'horizontal';
}
var restoreScrollTops; // remove inline height style to accurately measure situations where the textarea should shrink
// however, skip this step if the new value appends to the previous value, as textarea height should only have grown
if (testForHeightReduction) {
// ensure the scrollTop values of parent elements are not modified as a consequence of shrinking the textarea height
restoreScrollTops = cacheScrollTops(ta);
ta.style.height = '';
}
var newHeight;
if (computed.boxSizing === 'content-box') {
newHeight = ta.scrollHeight - (parseFloat(computed.paddingTop) + parseFloat(computed.paddingBottom));
} else {
newHeight = ta.scrollHeight + parseFloat(computed.borderTopWidth) + parseFloat(computed.borderBottomWidth);
}
if (computed.maxHeight !== 'none' && newHeight > parseFloat(computed.maxHeight)) {
if (computed.overflowY === 'hidden') {
ta.style.overflow = 'scroll';
}
newHeight = parseFloat(computed.maxHeight);
} else if (computed.overflowY !== 'hidden') {
ta.style.overflow = 'hidden';
}
ta.style.height = newHeight + 'px';
if (restoreTextAlign) {
ta.style.textAlign = restoreTextAlign;
}
if (restoreScrollTops) {
restoreScrollTops();
}
if (previousHeight !== newHeight) {
ta.dispatchEvent(new Event('autosize:resized', {
bubbles: true
}));
previousHeight = newHeight;
}
if (initialOverflowY !== computed.overflow && !restoreTextAlign) {
var textAlign = computed.textAlign;
if (computed.overflow === 'hidden') {
// Webkit fails to reflow text after overflow is hidden,
// even if hiding overflow would allow text to fit more compactly.
// The following is intended to force the necessary text reflow.
ta.style.textAlign = textAlign === 'start' ? 'end' : 'start';
}
setHeight({
restoreTextAlign: textAlign,
testForHeightReduction: true
});
}
}
function fullSetHeight() {
setHeight({
testForHeightReduction: true,
restoreTextAlign: null
});
}
var handleInput = function () {
var previousValue = ta.value;
return function () {
setHeight({
// if previousValue is '', check for height shrinkage because the placeholder may be taking up space instead
// if new value is merely appending to previous value, skip checking for height deduction
testForHeightReduction: previousValue === '' || !ta.value.startsWith(previousValue),
restoreTextAlign: null
});
previousValue = ta.value;
};
}();
var destroy = function (style) {
ta.removeEventListener('autosize:destroy', destroy);
ta.removeEventListener('autosize:update', fullSetHeight);
ta.removeEventListener('input', handleInput);
window.removeEventListener('resize', fullSetHeight); // future todo: consider replacing with ResizeObserver
Object.keys(style).forEach(function (key) {
return ta.style[key] = style[key];
});
assignedElements["delete"](ta);
}.bind(ta, {
height: ta.style.height,
resize: ta.style.resize,
textAlign: ta.style.textAlign,
overflowY: ta.style.overflowY,
overflowX: ta.style.overflowX,
wordWrap: ta.style.wordWrap
});
ta.addEventListener('autosize:destroy', destroy);
ta.addEventListener('autosize:update', fullSetHeight);
ta.addEventListener('input', handleInput);
window.addEventListener('resize', fullSetHeight); // future todo: consider replacing with ResizeObserver
ta.style.overflowX = 'hidden';
ta.style.wordWrap = 'break-word';
assignedElements.set(ta, {
destroy: destroy,
update: fullSetHeight
});
fullSetHeight();
}
function destroy(ta) {
var methods = assignedElements.get(ta);
if (methods) {
methods.destroy();
}
}
function update(ta) {
var methods = assignedElements.get(ta);
if (methods) {
methods.update();
}
}
var autosize = null; // Do nothing in Node.js environment
if (typeof window === 'undefined') {
autosize = function autosize(el) {
return el;
};
autosize.destroy = function (el) {
return el;
};
autosize.update = function (el) {
return el;
};
} else {
autosize = function autosize(el, options) {
if (el) {
Array.prototype.forEach.call(el.length ? el : [el], function (x) {
return assign(x);
});
}
return el;
};
autosize.destroy = function (el) {
if (el) {
Array.prototype.forEach.call(el.length ? el : [el], destroy);
}
return el;
};
autosize.update = function (el) {
if (el) {
Array.prototype.forEach.call(el.length ? el : [el], update);
}
return el;
};
}
var autosize$1 = autosize;
return autosize$1;
})));

View file

@ -0,0 +1 @@
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self).autosize=t()}(this,function(){var e=new Map;function t(t){var o=e.get(t);o&&o.destroy()}function o(t){var o=e.get(t);o&&o.update()}var r=null;return"undefined"==typeof window?((r=function(e){return e}).destroy=function(e){return e},r.update=function(e){return e}):((r=function(t,o){return t&&Array.prototype.forEach.call(t.length?t:[t],function(t){return function(t){if(t&&t.nodeName&&"TEXTAREA"===t.nodeName&&!e.has(t)){var o,r=null,n=window.getComputedStyle(t),i=(o=t.value,function(){s({testForHeightReduction:""===o||!t.value.startsWith(o),restoreTextAlign:null}),o=t.value}),l=function(o){t.removeEventListener("autosize:destroy",l),t.removeEventListener("autosize:update",a),t.removeEventListener("input",i),window.removeEventListener("resize",a),Object.keys(o).forEach(function(e){return t.style[e]=o[e]}),e.delete(t)}.bind(t,{height:t.style.height,resize:t.style.resize,textAlign:t.style.textAlign,overflowY:t.style.overflowY,overflowX:t.style.overflowX,wordWrap:t.style.wordWrap});t.addEventListener("autosize:destroy",l),t.addEventListener("autosize:update",a),t.addEventListener("input",i),window.addEventListener("resize",a),t.style.overflowX="hidden",t.style.wordWrap="break-word",e.set(t,{destroy:l,update:a}),a()}function s(e){var o,i,l=e.restoreTextAlign,a=void 0===l?null:l,d=e.testForHeightReduction,u=void 0===d||d,f=n.overflowY;if(0!==t.scrollHeight&&("vertical"===n.resize?t.style.resize="none":"both"===n.resize&&(t.style.resize="horizontal"),u&&(o=function(e){for(var t=[];e&&e.parentNode&&e.parentNode instanceof Element;)e.parentNode.scrollTop&&t.push([e.parentNode,e.parentNode.scrollTop]),e=e.parentNode;return function(){return t.forEach(function(e){var t=e[0],o=e[1];t.style.scrollBehavior="auto",t.scrollTop=o,t.style.scrollBehavior=null})}}(t),t.style.height=""),i="content-box"===n.boxSizing?t.scrollHeight-(parseFloat(n.paddingTop)+parseFloat(n.paddingBottom)):t.scrollHeight+parseFloat(n.borderTopWidth)+parseFloat(n.borderBottomWidth),"none"!==n.maxHeight&&i>parseFloat(n.maxHeight)?("hidden"===n.overflowY&&(t.style.overflow="scroll"),i=parseFloat(n.maxHeight)):"hidden"!==n.overflowY&&(t.style.overflow="hidden"),t.style.height=i+"px",a&&(t.style.textAlign=a),o&&o(),r!==i&&(t.dispatchEvent(new Event("autosize:resized",{bubbles:!0})),r=i),f!==n.overflow&&!a)){var c=n.textAlign;"hidden"===n.overflow&&(t.style.textAlign="start"===c?"end":"start"),s({restoreTextAlign:c,testForHeightReduction:!0})}}function a(){s({testForHeightReduction:!0,restoreTextAlign:null})}}(t)}),t}).destroy=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],t),e},r.update=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],o),e}),r});

View file

@ -0,0 +1,37 @@
{
"name": "autosize",
"description": "Autosize is a small, stand-alone script to automatically adjust textarea height to fit text.",
"version": "6.0.1",
"keywords": [
"textarea",
"form",
"ui"
],
"files": [
"dist",
"src"
],
"author": {
"name": "Jack Moore",
"url": "http://www.jacklmoore.com",
"email": "hello@jacklmoore.com"
},
"source": "src/autosize.js",
"module": "dist/autosize.esm.js",
"unpkg": "dist/autosize.min.js",
"main": "dist/autosize.js",
"license": "MIT",
"homepage": "http://www.jacklmoore.com/autosize",
"demo": "http://www.jacklmoore.com/autosize",
"repository": {
"type": "git",
"url": "http://github.com/jackmoore/autosize.git"
},
"devDependencies": {
"microbundle": "^0.13.3"
},
"scripts": {
"build": "npx microbundle --no-sourcemap --no-pkg-main --no-compress -f umd -o dist/autosize.js && npx microbundle --no-sourcemap -f esm,umd",
"dev": "npx microbundle --no-sourcemap --no-pkg-main --no-compress -f umd -o dist/autosize.js watch"
}
}

View file

@ -0,0 +1,29 @@
## Summary
Autosize is a small, stand-alone script to automatically adjust textarea height to fit text.
#### Demo
Full documentation and a demo can be found at [jacklmoore.com/autosize](http://jacklmoore.com/autosize)
#### Install via NPM
```bash
npm install autosize
```
#### Usage
The autosize function accepts a single textarea element, or an array or array-like object (such as a NodeList or jQuery collection) of textarea elements.
```javascript
// from a NodeList
autosize(document.querySelectorAll('textarea'));
// from a single Node
autosize(document.querySelector('textarea'));
// from a jQuery collection
autosize($('textarea'));
```
Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php)

View file

@ -0,0 +1,199 @@
const assignedElements = new Map();
function assign(ta) {
if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || assignedElements.has(ta)) return;
let previousHeight = null;
function cacheScrollTops(el) {
const arr = [];
while (el && el.parentNode && el.parentNode instanceof Element) {
if (el.parentNode.scrollTop) {
arr.push([el.parentNode, el.parentNode.scrollTop]);
}
el = el.parentNode;
}
return ()=> arr.forEach(([node, scrollTop]) => {
node.style.scrollBehavior = 'auto';
node.scrollTop = scrollTop;
node.style.scrollBehavior = null;
});
}
const computed = window.getComputedStyle(ta);
function setHeight({
restoreTextAlign = null,
testForHeightReduction = true,
}) {
let initialOverflowY = computed.overflowY;
if (ta.scrollHeight === 0) {
// If the scrollHeight is 0, then the element probably has display:none or is detached from the DOM.
return;
}
// disallow vertical resizing
if (computed.resize === 'vertical') {
ta.style.resize = 'none';
} else if (computed.resize === 'both') {
ta.style.resize = 'horizontal';
}
let restoreScrollTops
// remove inline height style to accurately measure situations where the textarea should shrink
// however, skip this step if the new value appends to the previous value, as textarea height should only have grown
if (testForHeightReduction) {
// ensure the scrollTop values of parent elements are not modified as a consequence of shrinking the textarea height
restoreScrollTops = cacheScrollTops(ta);
ta.style.height = '';
}
let newHeight;
if (computed.boxSizing === 'content-box') {
newHeight = ta.scrollHeight - (parseFloat(computed.paddingTop)+parseFloat(computed.paddingBottom));
} else {
newHeight = ta.scrollHeight + parseFloat(computed.borderTopWidth)+parseFloat(computed.borderBottomWidth);
}
if (computed.maxHeight !== 'none' && newHeight > parseFloat(computed.maxHeight)) {
if (computed.overflowY === 'hidden') {
ta.style.overflow = 'scroll';
}
newHeight = parseFloat(computed.maxHeight);
} else if (computed.overflowY !== 'hidden') {
ta.style.overflow = 'hidden';
}
ta.style.height = newHeight+'px';
if (restoreTextAlign) {
ta.style.textAlign = restoreTextAlign;
}
if (restoreScrollTops) {
restoreScrollTops();
}
if (previousHeight !== newHeight) {
ta.dispatchEvent(new Event('autosize:resized', {bubbles: true}));
previousHeight = newHeight;
}
if (initialOverflowY !== computed.overflow && !restoreTextAlign) {
const textAlign = computed.textAlign;
if (computed.overflow === 'hidden') {
// Webkit fails to reflow text after overflow is hidden,
// even if hiding overflow would allow text to fit more compactly.
// The following is intended to force the necessary text reflow.
ta.style.textAlign = textAlign === 'start' ? 'end' : 'start';
}
setHeight({
restoreTextAlign: textAlign,
testForHeightReduction: true,
});
}
}
function fullSetHeight() {
setHeight({
testForHeightReduction: true,
restoreTextAlign: null,
});
}
const handleInput = (function(){
let previousValue = ta.value;
return ()=> {
setHeight({
// if previousValue is '', check for height shrinkage because the placeholder may be taking up space instead
// if new value is merely appending to previous value, skip checking for height deduction
testForHeightReduction: previousValue === '' || !ta.value.startsWith(previousValue),
restoreTextAlign: null,
});
previousValue = ta.value;
}
}())
const destroy = (style => {
ta.removeEventListener('autosize:destroy', destroy);
ta.removeEventListener('autosize:update', fullSetHeight);
ta.removeEventListener('input', handleInput);
window.removeEventListener('resize', fullSetHeight); // future todo: consider replacing with ResizeObserver
Object.keys(style).forEach(key => ta.style[key] = style[key]);
assignedElements.delete(ta);
}).bind(ta, {
height: ta.style.height,
resize: ta.style.resize,
textAlign: ta.style.textAlign,
overflowY: ta.style.overflowY,
overflowX: ta.style.overflowX,
wordWrap: ta.style.wordWrap,
});
ta.addEventListener('autosize:destroy', destroy);
ta.addEventListener('autosize:update', fullSetHeight);
ta.addEventListener('input', handleInput);
window.addEventListener('resize', fullSetHeight); // future todo: consider replacing with ResizeObserver
ta.style.overflowX = 'hidden';
ta.style.wordWrap = 'break-word';
assignedElements.set(ta, {
destroy,
update: fullSetHeight,
});
fullSetHeight();
}
function destroy(ta) {
const methods = assignedElements.get(ta);
if (methods) {
methods.destroy();
}
}
function update(ta) {
const methods = assignedElements.get(ta);
if (methods) {
methods.update();
}
}
let autosize = null;
// Do nothing in Node.js environment
if (typeof window === 'undefined') {
autosize = el => el;
autosize.destroy = el => el;
autosize.update = el => el;
} else {
autosize = (el, options) => {
if (el) {
Array.prototype.forEach.call(el.length ? el : [el], x => assign(x, options));
}
return el;
};
autosize.destroy = el => {
if (el) {
Array.prototype.forEach.call(el.length ? el : [el], destroy);
}
return el;
};
autosize.update = el => {
if (el) {
Array.prototype.forEach.call(el.length ? el : [el], update);
}
return el;
};
}
export default autosize;