@zag-js/auto-resize 0.74.2 → 0.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +36 -8
- package/dist/index.mjs +37 -10
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
declare function autoResizeInput(input: HTMLInputElement | null): (() => void) | undefined;
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
declare const autoresizeTextarea: (el: HTMLTextAreaElement | null) => (() => void) | undefined;
|
|
4
|
+
|
|
5
|
+
export { autoResizeInput, autoresizeTextarea };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
declare function autoResizeInput(input: HTMLInputElement | null): (() => void) | undefined;
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
declare const autoresizeTextarea: (el: HTMLTextAreaElement | null) => (() => void) | undefined;
|
|
4
|
+
|
|
5
|
+
export { autoResizeInput, autoresizeTextarea };
|
package/dist/index.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
var domQuery = require('@zag-js/dom-query');
|
|
4
4
|
|
|
5
|
-
// src/
|
|
6
|
-
function
|
|
7
|
-
if (!
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const cssText = "box-sizing:" + el.boxSizing + ";border-left:" + el.borderLeftWidth + " solid red;border-right:" + el.borderRightWidth + " solid red;font-family:" + el.fontFamily + ";font-feature-settings:" + el.fontFeatureSettings + ";font-kerning:" + el.fontKerning + ";font-size:" + el.fontSize + ";font-stretch:" + el.fontStretch + ";font-style:" + el.fontStyle + ";font-variant:" + el.fontVariant + ";font-variant-caps:" + el.fontVariantCaps + ";font-variant-ligatures:" + el.fontVariantLigatures + ";font-variant-numeric:" + el.fontVariantNumeric + ";font-weight:" + el.fontWeight + ";letter-spacing:" + el.letterSpacing + ";margin-left:" + el.marginLeft + ";margin-right:" + el.marginRight + ";padding-left:" + el.paddingLeft + ";padding-right:" + el.paddingRight + ";text-indent:" + el.textIndent + ";text-transform:" + el.textTransform;
|
|
11
|
-
toEl.style.cssText += cssText;
|
|
5
|
+
// src/autoresize-input.ts
|
|
6
|
+
function getVisualStyles(node) {
|
|
7
|
+
if (!node) return;
|
|
8
|
+
const style = domQuery.getComputedStyle(node);
|
|
9
|
+
return "box-sizing:" + style.boxSizing + ";border-left:" + style.borderLeftWidth + " solid red;border-right:" + style.borderRightWidth + " solid red;font-family:" + style.fontFamily + ";font-feature-settings:" + style.fontFeatureSettings + ";font-kerning:" + style.fontKerning + ";font-size:" + style.fontSize + ";font-stretch:" + style.fontStretch + ";font-style:" + style.fontStyle + ";font-variant:" + style.fontVariant + ";font-variant-caps:" + style.fontVariantCaps + ";font-variant-ligatures:" + style.fontVariantLigatures + ";font-variant-numeric:" + style.fontVariantNumeric + ";font-weight:" + style.fontWeight + ";letter-spacing:" + style.letterSpacing + ";margin-left:" + style.marginLeft + ";margin-right:" + style.marginRight + ";padding-left:" + style.paddingLeft + ";padding-right:" + style.paddingRight + ";text-indent:" + style.textIndent + ";text-transform:" + style.textTransform;
|
|
12
10
|
}
|
|
11
|
+
|
|
12
|
+
// src/autoresize-input.ts
|
|
13
13
|
function createGhostElement(doc) {
|
|
14
14
|
var el = doc.createElement("div");
|
|
15
15
|
el.id = "ghost";
|
|
@@ -22,7 +22,8 @@ function autoResizeInput(input) {
|
|
|
22
22
|
const doc = domQuery.getDocument(input);
|
|
23
23
|
const win = domQuery.getWindow(input);
|
|
24
24
|
const ghost = createGhostElement(doc);
|
|
25
|
-
|
|
25
|
+
const cssText = getVisualStyles(input);
|
|
26
|
+
if (cssText) ghost.style.cssText += cssText;
|
|
26
27
|
function resize() {
|
|
27
28
|
win.requestAnimationFrame(() => {
|
|
28
29
|
ghost.innerHTML = input.value;
|
|
@@ -39,5 +40,32 @@ function autoResizeInput(input) {
|
|
|
39
40
|
input?.removeEventListener("change", resize);
|
|
40
41
|
};
|
|
41
42
|
}
|
|
43
|
+
var autoresizeTextarea = (el) => {
|
|
44
|
+
if (!el) return;
|
|
45
|
+
const style = domQuery.getComputedStyle(el);
|
|
46
|
+
const win = el.ownerDocument.defaultView || window;
|
|
47
|
+
const onInput = () => {
|
|
48
|
+
el.style.height = "auto";
|
|
49
|
+
const borderTopWidth = parseInt(style.borderTopWidth, 10);
|
|
50
|
+
const borderBottomWidth = parseInt(style.borderBottomWidth, 10);
|
|
51
|
+
el.style.height = `${el.scrollHeight + borderTopWidth + borderBottomWidth}px`;
|
|
52
|
+
};
|
|
53
|
+
el.addEventListener("input", onInput);
|
|
54
|
+
const elementPrototype = Object.getPrototypeOf(el);
|
|
55
|
+
const descriptor = Object.getOwnPropertyDescriptor(elementPrototype, "value");
|
|
56
|
+
Object.defineProperty(el, "value", {
|
|
57
|
+
...descriptor,
|
|
58
|
+
set() {
|
|
59
|
+
descriptor?.set?.apply(this, arguments);
|
|
60
|
+
onInput();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
const resizeObserver = new win.ResizeObserver(() => onInput());
|
|
64
|
+
resizeObserver.observe(el);
|
|
65
|
+
return () => {
|
|
66
|
+
el.removeEventListener("input", onInput);
|
|
67
|
+
};
|
|
68
|
+
};
|
|
42
69
|
|
|
43
70
|
exports.autoResizeInput = autoResizeInput;
|
|
71
|
+
exports.autoresizeTextarea = autoresizeTextarea;
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { getDocument, getWindow } from '@zag-js/dom-query';
|
|
1
|
+
import { getDocument, getWindow, getComputedStyle } from '@zag-js/dom-query';
|
|
2
2
|
|
|
3
|
-
// src/
|
|
4
|
-
function
|
|
5
|
-
if (!
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const cssText = "box-sizing:" + el.boxSizing + ";border-left:" + el.borderLeftWidth + " solid red;border-right:" + el.borderRightWidth + " solid red;font-family:" + el.fontFamily + ";font-feature-settings:" + el.fontFeatureSettings + ";font-kerning:" + el.fontKerning + ";font-size:" + el.fontSize + ";font-stretch:" + el.fontStretch + ";font-style:" + el.fontStyle + ";font-variant:" + el.fontVariant + ";font-variant-caps:" + el.fontVariantCaps + ";font-variant-ligatures:" + el.fontVariantLigatures + ";font-variant-numeric:" + el.fontVariantNumeric + ";font-weight:" + el.fontWeight + ";letter-spacing:" + el.letterSpacing + ";margin-left:" + el.marginLeft + ";margin-right:" + el.marginRight + ";padding-left:" + el.paddingLeft + ";padding-right:" + el.paddingRight + ";text-indent:" + el.textIndent + ";text-transform:" + el.textTransform;
|
|
9
|
-
toEl.style.cssText += cssText;
|
|
3
|
+
// src/autoresize-input.ts
|
|
4
|
+
function getVisualStyles(node) {
|
|
5
|
+
if (!node) return;
|
|
6
|
+
const style = getComputedStyle(node);
|
|
7
|
+
return "box-sizing:" + style.boxSizing + ";border-left:" + style.borderLeftWidth + " solid red;border-right:" + style.borderRightWidth + " solid red;font-family:" + style.fontFamily + ";font-feature-settings:" + style.fontFeatureSettings + ";font-kerning:" + style.fontKerning + ";font-size:" + style.fontSize + ";font-stretch:" + style.fontStretch + ";font-style:" + style.fontStyle + ";font-variant:" + style.fontVariant + ";font-variant-caps:" + style.fontVariantCaps + ";font-variant-ligatures:" + style.fontVariantLigatures + ";font-variant-numeric:" + style.fontVariantNumeric + ";font-weight:" + style.fontWeight + ";letter-spacing:" + style.letterSpacing + ";margin-left:" + style.marginLeft + ";margin-right:" + style.marginRight + ";padding-left:" + style.paddingLeft + ";padding-right:" + style.paddingRight + ";text-indent:" + style.textIndent + ";text-transform:" + style.textTransform;
|
|
10
8
|
}
|
|
9
|
+
|
|
10
|
+
// src/autoresize-input.ts
|
|
11
11
|
function createGhostElement(doc) {
|
|
12
12
|
var el = doc.createElement("div");
|
|
13
13
|
el.id = "ghost";
|
|
@@ -20,7 +20,8 @@ function autoResizeInput(input) {
|
|
|
20
20
|
const doc = getDocument(input);
|
|
21
21
|
const win = getWindow(input);
|
|
22
22
|
const ghost = createGhostElement(doc);
|
|
23
|
-
|
|
23
|
+
const cssText = getVisualStyles(input);
|
|
24
|
+
if (cssText) ghost.style.cssText += cssText;
|
|
24
25
|
function resize() {
|
|
25
26
|
win.requestAnimationFrame(() => {
|
|
26
27
|
ghost.innerHTML = input.value;
|
|
@@ -37,5 +38,31 @@ function autoResizeInput(input) {
|
|
|
37
38
|
input?.removeEventListener("change", resize);
|
|
38
39
|
};
|
|
39
40
|
}
|
|
41
|
+
var autoresizeTextarea = (el) => {
|
|
42
|
+
if (!el) return;
|
|
43
|
+
const style = getComputedStyle(el);
|
|
44
|
+
const win = el.ownerDocument.defaultView || window;
|
|
45
|
+
const onInput = () => {
|
|
46
|
+
el.style.height = "auto";
|
|
47
|
+
const borderTopWidth = parseInt(style.borderTopWidth, 10);
|
|
48
|
+
const borderBottomWidth = parseInt(style.borderBottomWidth, 10);
|
|
49
|
+
el.style.height = `${el.scrollHeight + borderTopWidth + borderBottomWidth}px`;
|
|
50
|
+
};
|
|
51
|
+
el.addEventListener("input", onInput);
|
|
52
|
+
const elementPrototype = Object.getPrototypeOf(el);
|
|
53
|
+
const descriptor = Object.getOwnPropertyDescriptor(elementPrototype, "value");
|
|
54
|
+
Object.defineProperty(el, "value", {
|
|
55
|
+
...descriptor,
|
|
56
|
+
set() {
|
|
57
|
+
descriptor?.set?.apply(this, arguments);
|
|
58
|
+
onInput();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
const resizeObserver = new win.ResizeObserver(() => onInput());
|
|
62
|
+
resizeObserver.observe(el);
|
|
63
|
+
return () => {
|
|
64
|
+
el.removeEventListener("input", onInput);
|
|
65
|
+
};
|
|
66
|
+
};
|
|
40
67
|
|
|
41
|
-
export { autoResizeInput };
|
|
68
|
+
export { autoResizeInput, autoresizeTextarea };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/auto-resize",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.76.0",
|
|
4
4
|
"description": "Autoresize utilities for the web",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@zag-js/dom-query": "0.
|
|
25
|
+
"@zag-js/dom-query": "0.76.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"clean-package": "2.2.0"
|