@zag-js/auto-resize 0.69.0 → 0.71.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.js +8 -32
- package/dist/index.mjs +4 -5
- package/package.json +4 -5
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/src/index.ts +0 -71
package/dist/index.js
CHANGED
|
@@ -1,32 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var domQuery = require('@zag-js/dom-query');
|
|
19
4
|
|
|
20
5
|
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
autoResizeInput: () => autoResizeInput
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(src_exports);
|
|
26
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
27
6
|
function copyVisualStyles(fromEl, toEl) {
|
|
28
7
|
if (!fromEl) return;
|
|
29
|
-
const win =
|
|
8
|
+
const win = domQuery.getWindow(fromEl);
|
|
30
9
|
const el = win.getComputedStyle(fromEl);
|
|
31
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;
|
|
32
11
|
toEl.style.cssText += cssText;
|
|
@@ -40,8 +19,8 @@ function createGhostElement(doc) {
|
|
|
40
19
|
}
|
|
41
20
|
function autoResizeInput(input) {
|
|
42
21
|
if (!input) return;
|
|
43
|
-
const doc =
|
|
44
|
-
const win =
|
|
22
|
+
const doc = domQuery.getDocument(input);
|
|
23
|
+
const win = domQuery.getWindow(input);
|
|
45
24
|
const ghost = createGhostElement(doc);
|
|
46
25
|
copyVisualStyles(input, ghost);
|
|
47
26
|
function resize() {
|
|
@@ -60,8 +39,5 @@ function autoResizeInput(input) {
|
|
|
60
39
|
input?.removeEventListener("change", resize);
|
|
61
40
|
};
|
|
62
41
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
autoResizeInput
|
|
66
|
-
});
|
|
67
|
-
//# sourceMappingURL=index.js.map
|
|
42
|
+
|
|
43
|
+
exports.autoResizeInput = autoResizeInput;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { getDocument, getWindow } from '@zag-js/dom-query';
|
|
2
|
+
|
|
1
3
|
// src/index.ts
|
|
2
|
-
import { getDocument, getWindow } from "@zag-js/dom-query";
|
|
3
4
|
function copyVisualStyles(fromEl, toEl) {
|
|
4
5
|
if (!fromEl) return;
|
|
5
6
|
const win = getWindow(fromEl);
|
|
@@ -36,7 +37,5 @@ function autoResizeInput(input) {
|
|
|
36
37
|
input?.removeEventListener("change", resize);
|
|
37
38
|
};
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
//# sourceMappingURL=index.mjs.map
|
|
40
|
+
|
|
41
|
+
export { autoResizeInput };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/auto-resize",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.71.0",
|
|
4
4
|
"description": "Autoresize utilities for the web",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
"repository": "https://github.com/chakra-ui/zag/tree/main/packages/utilities/auto-resize",
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"files": [
|
|
16
|
-
"dist"
|
|
17
|
-
"src"
|
|
16
|
+
"dist"
|
|
18
17
|
],
|
|
19
18
|
"publishConfig": {
|
|
20
19
|
"access": "public"
|
|
@@ -23,7 +22,7 @@
|
|
|
23
22
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
24
23
|
},
|
|
25
24
|
"dependencies": {
|
|
26
|
-
"@zag-js/dom-query": "0.
|
|
25
|
+
"@zag-js/dom-query": "0.71.0"
|
|
27
26
|
},
|
|
28
27
|
"devDependencies": {
|
|
29
28
|
"clean-package": "2.2.0"
|
|
@@ -42,7 +41,7 @@
|
|
|
42
41
|
},
|
|
43
42
|
"scripts": {
|
|
44
43
|
"build": "tsup",
|
|
45
|
-
"test": "
|
|
44
|
+
"test": "vitest",
|
|
46
45
|
"lint": "eslint src",
|
|
47
46
|
"test-ci": "pnpm test --ci --runInBand -u",
|
|
48
47
|
"test-watch": "pnpm test --watchAll"
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { getDocument, getWindow } from \"@zag-js/dom-query\"\n\nfunction copyVisualStyles(fromEl: HTMLElement | null, toEl: HTMLElement) {\n if (!fromEl) return\n\n const win = getWindow(fromEl)\n const el = win.getComputedStyle(fromEl)\n\n // prettier-ignore\n const cssText = 'box-sizing:' + el.boxSizing +\n ';border-left:' + el.borderLeftWidth + ' solid red' +\n ';border-right:' + el.borderRightWidth + ' solid red' +\n ';font-family:' + el.fontFamily +\n ';font-feature-settings:' + el.fontFeatureSettings +\n ';font-kerning:' + el.fontKerning +\n ';font-size:' + el.fontSize +\n ';font-stretch:' + el.fontStretch +\n ';font-style:' + el.fontStyle +\n ';font-variant:' + el.fontVariant +\n ';font-variant-caps:' + el.fontVariantCaps +\n ';font-variant-ligatures:' + el.fontVariantLigatures +\n ';font-variant-numeric:' + el.fontVariantNumeric +\n ';font-weight:' + el.fontWeight +\n ';letter-spacing:' + el.letterSpacing +\n ';margin-left:' + el.marginLeft +\n ';margin-right:' + el.marginRight +\n ';padding-left:' + el.paddingLeft +\n ';padding-right:' + el.paddingRight +\n ';text-indent:' + el.textIndent +\n ';text-transform:' + el.textTransform\n\n toEl.style.cssText += cssText\n}\n\nfunction createGhostElement(doc: Document) {\n var el = doc.createElement(\"div\")\n el.id = \"ghost\"\n el.style.cssText =\n \"display:inline-block;height:0;overflow:hidden;position:absolute;top:0;visibility:hidden;white-space:nowrap;\"\n doc.body.appendChild(el)\n return el\n}\n\nexport function autoResizeInput(input: HTMLInputElement | null) {\n if (!input) return\n const doc = getDocument(input)\n const win = getWindow(input)\n\n const ghost = createGhostElement(doc)\n\n copyVisualStyles(input, ghost)\n\n function resize() {\n win.requestAnimationFrame(() => {\n ghost.innerHTML = input!.value\n const rect = win.getComputedStyle(ghost)\n input?.style.setProperty(\"width\", rect.width)\n })\n }\n\n resize()\n\n input?.addEventListener(\"input\", resize)\n input?.addEventListener(\"change\", resize)\n\n return () => {\n doc.body.removeChild(ghost)\n input?.removeEventListener(\"input\", resize)\n input?.removeEventListener(\"change\", resize)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAuC;AAEvC,SAAS,iBAAiB,QAA4B,MAAmB;AACvE,MAAI,CAAC,OAAQ;AAEb,QAAM,UAAM,4BAAU,MAAM;AAC5B,QAAM,KAAK,IAAI,iBAAiB,MAAM;AAGtC,QAAM,UAAU,gBAAgB,GAAG,YACf,kBAAkB,GAAG,kBAAkB,6BACpB,GAAG,mBAAmB,4BACvB,GAAG,aACrB,4BAA4B,GAAG,sBAC/B,mBAAmB,GAAG,cACtB,gBAAgB,GAAG,WACnB,mBAAmB,GAAG,cACtB,iBAAiB,GAAG,YACpB,mBAAmB,GAAG,cACtB,wBAAwB,GAAG,kBAC3B,6BAA6B,GAAG,uBAChC,2BAA2B,GAAG,qBAC9B,kBAAkB,GAAG,aACrB,qBAAqB,GAAG,gBACxB,kBAAkB,GAAG,aACrB,mBAAmB,GAAG,cACtB,mBAAmB,GAAG,cACtB,oBAAoB,GAAG,eACvB,kBAAkB,GAAG,aACrB,qBAAqB,GAAG;AAE5C,OAAK,MAAM,WAAW;AACxB;AAEA,SAAS,mBAAmB,KAAe;AACzC,MAAI,KAAK,IAAI,cAAc,KAAK;AAChC,KAAG,KAAK;AACR,KAAG,MAAM,UACP;AACF,MAAI,KAAK,YAAY,EAAE;AACvB,SAAO;AACT;AAEO,SAAS,gBAAgB,OAAgC;AAC9D,MAAI,CAAC,MAAO;AACZ,QAAM,UAAM,8BAAY,KAAK;AAC7B,QAAM,UAAM,4BAAU,KAAK;AAE3B,QAAM,QAAQ,mBAAmB,GAAG;AAEpC,mBAAiB,OAAO,KAAK;AAE7B,WAAS,SAAS;AAChB,QAAI,sBAAsB,MAAM;AAC9B,YAAM,YAAY,MAAO;AACzB,YAAM,OAAO,IAAI,iBAAiB,KAAK;AACvC,aAAO,MAAM,YAAY,SAAS,KAAK,KAAK;AAAA,IAC9C,CAAC;AAAA,EACH;AAEA,SAAO;AAEP,SAAO,iBAAiB,SAAS,MAAM;AACvC,SAAO,iBAAiB,UAAU,MAAM;AAExC,SAAO,MAAM;AACX,QAAI,KAAK,YAAY,KAAK;AAC1B,WAAO,oBAAoB,SAAS,MAAM;AAC1C,WAAO,oBAAoB,UAAU,MAAM;AAAA,EAC7C;AACF;","names":[]}
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { getDocument, getWindow } from \"@zag-js/dom-query\"\n\nfunction copyVisualStyles(fromEl: HTMLElement | null, toEl: HTMLElement) {\n if (!fromEl) return\n\n const win = getWindow(fromEl)\n const el = win.getComputedStyle(fromEl)\n\n // prettier-ignore\n const cssText = 'box-sizing:' + el.boxSizing +\n ';border-left:' + el.borderLeftWidth + ' solid red' +\n ';border-right:' + el.borderRightWidth + ' solid red' +\n ';font-family:' + el.fontFamily +\n ';font-feature-settings:' + el.fontFeatureSettings +\n ';font-kerning:' + el.fontKerning +\n ';font-size:' + el.fontSize +\n ';font-stretch:' + el.fontStretch +\n ';font-style:' + el.fontStyle +\n ';font-variant:' + el.fontVariant +\n ';font-variant-caps:' + el.fontVariantCaps +\n ';font-variant-ligatures:' + el.fontVariantLigatures +\n ';font-variant-numeric:' + el.fontVariantNumeric +\n ';font-weight:' + el.fontWeight +\n ';letter-spacing:' + el.letterSpacing +\n ';margin-left:' + el.marginLeft +\n ';margin-right:' + el.marginRight +\n ';padding-left:' + el.paddingLeft +\n ';padding-right:' + el.paddingRight +\n ';text-indent:' + el.textIndent +\n ';text-transform:' + el.textTransform\n\n toEl.style.cssText += cssText\n}\n\nfunction createGhostElement(doc: Document) {\n var el = doc.createElement(\"div\")\n el.id = \"ghost\"\n el.style.cssText =\n \"display:inline-block;height:0;overflow:hidden;position:absolute;top:0;visibility:hidden;white-space:nowrap;\"\n doc.body.appendChild(el)\n return el\n}\n\nexport function autoResizeInput(input: HTMLInputElement | null) {\n if (!input) return\n const doc = getDocument(input)\n const win = getWindow(input)\n\n const ghost = createGhostElement(doc)\n\n copyVisualStyles(input, ghost)\n\n function resize() {\n win.requestAnimationFrame(() => {\n ghost.innerHTML = input!.value\n const rect = win.getComputedStyle(ghost)\n input?.style.setProperty(\"width\", rect.width)\n })\n }\n\n resize()\n\n input?.addEventListener(\"input\", resize)\n input?.addEventListener(\"change\", resize)\n\n return () => {\n doc.body.removeChild(ghost)\n input?.removeEventListener(\"input\", resize)\n input?.removeEventListener(\"change\", resize)\n }\n}\n"],"mappings":";AAAA,SAAS,aAAa,iBAAiB;AAEvC,SAAS,iBAAiB,QAA4B,MAAmB;AACvE,MAAI,CAAC,OAAQ;AAEb,QAAM,MAAM,UAAU,MAAM;AAC5B,QAAM,KAAK,IAAI,iBAAiB,MAAM;AAGtC,QAAM,UAAU,gBAAgB,GAAG,YACf,kBAAkB,GAAG,kBAAkB,6BACpB,GAAG,mBAAmB,4BACvB,GAAG,aACrB,4BAA4B,GAAG,sBAC/B,mBAAmB,GAAG,cACtB,gBAAgB,GAAG,WACnB,mBAAmB,GAAG,cACtB,iBAAiB,GAAG,YACpB,mBAAmB,GAAG,cACtB,wBAAwB,GAAG,kBAC3B,6BAA6B,GAAG,uBAChC,2BAA2B,GAAG,qBAC9B,kBAAkB,GAAG,aACrB,qBAAqB,GAAG,gBACxB,kBAAkB,GAAG,aACrB,mBAAmB,GAAG,cACtB,mBAAmB,GAAG,cACtB,oBAAoB,GAAG,eACvB,kBAAkB,GAAG,aACrB,qBAAqB,GAAG;AAE5C,OAAK,MAAM,WAAW;AACxB;AAEA,SAAS,mBAAmB,KAAe;AACzC,MAAI,KAAK,IAAI,cAAc,KAAK;AAChC,KAAG,KAAK;AACR,KAAG,MAAM,UACP;AACF,MAAI,KAAK,YAAY,EAAE;AACvB,SAAO;AACT;AAEO,SAAS,gBAAgB,OAAgC;AAC9D,MAAI,CAAC,MAAO;AACZ,QAAM,MAAM,YAAY,KAAK;AAC7B,QAAM,MAAM,UAAU,KAAK;AAE3B,QAAM,QAAQ,mBAAmB,GAAG;AAEpC,mBAAiB,OAAO,KAAK;AAE7B,WAAS,SAAS;AAChB,QAAI,sBAAsB,MAAM;AAC9B,YAAM,YAAY,MAAO;AACzB,YAAM,OAAO,IAAI,iBAAiB,KAAK;AACvC,aAAO,MAAM,YAAY,SAAS,KAAK,KAAK;AAAA,IAC9C,CAAC;AAAA,EACH;AAEA,SAAO;AAEP,SAAO,iBAAiB,SAAS,MAAM;AACvC,SAAO,iBAAiB,UAAU,MAAM;AAExC,SAAO,MAAM;AACX,QAAI,KAAK,YAAY,KAAK;AAC1B,WAAO,oBAAoB,SAAS,MAAM;AAC1C,WAAO,oBAAoB,UAAU,MAAM;AAAA,EAC7C;AACF;","names":[]}
|
package/src/index.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { getDocument, getWindow } from "@zag-js/dom-query"
|
|
2
|
-
|
|
3
|
-
function copyVisualStyles(fromEl: HTMLElement | null, toEl: HTMLElement) {
|
|
4
|
-
if (!fromEl) return
|
|
5
|
-
|
|
6
|
-
const win = getWindow(fromEl)
|
|
7
|
-
const el = win.getComputedStyle(fromEl)
|
|
8
|
-
|
|
9
|
-
// prettier-ignore
|
|
10
|
-
const cssText = 'box-sizing:' + el.boxSizing +
|
|
11
|
-
';border-left:' + el.borderLeftWidth + ' solid red' +
|
|
12
|
-
';border-right:' + el.borderRightWidth + ' solid red' +
|
|
13
|
-
';font-family:' + el.fontFamily +
|
|
14
|
-
';font-feature-settings:' + el.fontFeatureSettings +
|
|
15
|
-
';font-kerning:' + el.fontKerning +
|
|
16
|
-
';font-size:' + el.fontSize +
|
|
17
|
-
';font-stretch:' + el.fontStretch +
|
|
18
|
-
';font-style:' + el.fontStyle +
|
|
19
|
-
';font-variant:' + el.fontVariant +
|
|
20
|
-
';font-variant-caps:' + el.fontVariantCaps +
|
|
21
|
-
';font-variant-ligatures:' + el.fontVariantLigatures +
|
|
22
|
-
';font-variant-numeric:' + el.fontVariantNumeric +
|
|
23
|
-
';font-weight:' + el.fontWeight +
|
|
24
|
-
';letter-spacing:' + el.letterSpacing +
|
|
25
|
-
';margin-left:' + el.marginLeft +
|
|
26
|
-
';margin-right:' + el.marginRight +
|
|
27
|
-
';padding-left:' + el.paddingLeft +
|
|
28
|
-
';padding-right:' + el.paddingRight +
|
|
29
|
-
';text-indent:' + el.textIndent +
|
|
30
|
-
';text-transform:' + el.textTransform
|
|
31
|
-
|
|
32
|
-
toEl.style.cssText += cssText
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function createGhostElement(doc: Document) {
|
|
36
|
-
var el = doc.createElement("div")
|
|
37
|
-
el.id = "ghost"
|
|
38
|
-
el.style.cssText =
|
|
39
|
-
"display:inline-block;height:0;overflow:hidden;position:absolute;top:0;visibility:hidden;white-space:nowrap;"
|
|
40
|
-
doc.body.appendChild(el)
|
|
41
|
-
return el
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function autoResizeInput(input: HTMLInputElement | null) {
|
|
45
|
-
if (!input) return
|
|
46
|
-
const doc = getDocument(input)
|
|
47
|
-
const win = getWindow(input)
|
|
48
|
-
|
|
49
|
-
const ghost = createGhostElement(doc)
|
|
50
|
-
|
|
51
|
-
copyVisualStyles(input, ghost)
|
|
52
|
-
|
|
53
|
-
function resize() {
|
|
54
|
-
win.requestAnimationFrame(() => {
|
|
55
|
-
ghost.innerHTML = input!.value
|
|
56
|
-
const rect = win.getComputedStyle(ghost)
|
|
57
|
-
input?.style.setProperty("width", rect.width)
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
resize()
|
|
62
|
-
|
|
63
|
-
input?.addEventListener("input", resize)
|
|
64
|
-
input?.addEventListener("change", resize)
|
|
65
|
-
|
|
66
|
-
return () => {
|
|
67
|
-
doc.body.removeChild(ghost)
|
|
68
|
-
input?.removeEventListener("input", resize)
|
|
69
|
-
input?.removeEventListener("change", resize)
|
|
70
|
-
}
|
|
71
|
-
}
|