@zag-js/auto-resize 0.1.1 → 0.1.3
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 +3 -30
- package/package.json +5 -5
- package/dist/index.mjs +0 -60
package/dist/index.js
CHANGED
|
@@ -1,30 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
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);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
autoResizeInput: () => autoResizeInput
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(src_exports);
|
|
26
|
-
|
|
27
|
-
// ../dom/dist/index.mjs
|
|
1
|
+
// ../dom/dist/index.js
|
|
28
2
|
function isDocument(el) {
|
|
29
3
|
return el.nodeType === Node.DOCUMENT_NODE;
|
|
30
4
|
}
|
|
@@ -81,7 +55,6 @@ function autoResizeInput(input) {
|
|
|
81
55
|
input == null ? void 0 : input.removeEventListener("change", resize);
|
|
82
56
|
};
|
|
83
57
|
}
|
|
84
|
-
|
|
85
|
-
0 && (module.exports = {
|
|
58
|
+
export {
|
|
86
59
|
autoResizeInput
|
|
87
|
-
}
|
|
60
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
+
"type": "module",
|
|
2
3
|
"name": "@zag-js/auto-resize",
|
|
3
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.3",
|
|
4
5
|
"description": "Autoresize utilities for the web",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"js",
|
|
@@ -11,7 +12,6 @@
|
|
|
11
12
|
"homepage": "https://github.com/chakra-ui/zag#readme",
|
|
12
13
|
"license": "MIT",
|
|
13
14
|
"main": "dist/index.js",
|
|
14
|
-
"module": "dist/index.mjs",
|
|
15
15
|
"types": "dist/index.d.ts",
|
|
16
16
|
"repository": "https://github.com/chakra-ui/zag/tree/main/packages/utilities/auto-resize",
|
|
17
17
|
"sideEffects": false,
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@zag-js/dom-utils": "0.1.
|
|
28
|
+
"@zag-js/dom-utils": "0.1.12"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
|
-
"build-fast": "tsup src/index.ts --format=esm
|
|
31
|
+
"build-fast": "tsup src/index.ts --format=esm",
|
|
32
32
|
"start": "pnpm build --watch",
|
|
33
|
-
"build": "tsup src/index.ts --format=esm
|
|
33
|
+
"build": "tsup src/index.ts --format=esm --dts",
|
|
34
34
|
"test": "jest --config ../../../jest.config.js --rootDir tests",
|
|
35
35
|
"lint": "eslint src --ext .ts,.tsx",
|
|
36
36
|
"test-ci": "pnpm test --ci --runInBand -u",
|
package/dist/index.mjs
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// ../dom/dist/index.mjs
|
|
2
|
-
function isDocument(el) {
|
|
3
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
4
|
-
}
|
|
5
|
-
function isWindow(value) {
|
|
6
|
-
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
7
|
-
}
|
|
8
|
-
function getDocument(el) {
|
|
9
|
-
if (isWindow(el))
|
|
10
|
-
return el.document;
|
|
11
|
-
if (isDocument(el))
|
|
12
|
-
return el;
|
|
13
|
-
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
14
|
-
}
|
|
15
|
-
function getWindow(el) {
|
|
16
|
-
return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// src/index.ts
|
|
20
|
-
function copyVisualStyles(fromEl, toEl) {
|
|
21
|
-
if (!fromEl)
|
|
22
|
-
return;
|
|
23
|
-
const win = getWindow(fromEl);
|
|
24
|
-
const el = win.getComputedStyle(fromEl);
|
|
25
|
-
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;
|
|
26
|
-
toEl.style.cssText += cssText;
|
|
27
|
-
}
|
|
28
|
-
function createGhostElement(doc) {
|
|
29
|
-
var el = doc.createElement("div");
|
|
30
|
-
el.id = "ghost";
|
|
31
|
-
el.style.cssText = "display:inline-block;height:0;overflow:hidden;position:absolute;top:0;visibility:hidden;white-space:nowrap;";
|
|
32
|
-
doc.body.appendChild(el);
|
|
33
|
-
return el;
|
|
34
|
-
}
|
|
35
|
-
function autoResizeInput(input) {
|
|
36
|
-
if (!input)
|
|
37
|
-
return;
|
|
38
|
-
const doc = getDocument(input);
|
|
39
|
-
const win = getWindow(input);
|
|
40
|
-
const ghost = createGhostElement(doc);
|
|
41
|
-
copyVisualStyles(input, ghost);
|
|
42
|
-
function resize() {
|
|
43
|
-
win.requestAnimationFrame(() => {
|
|
44
|
-
ghost.innerHTML = input.value;
|
|
45
|
-
const rect = win.getComputedStyle(ghost);
|
|
46
|
-
input == null ? void 0 : input.style.setProperty("width", rect.width);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
resize();
|
|
50
|
-
input == null ? void 0 : input.addEventListener("input", resize);
|
|
51
|
-
input == null ? void 0 : input.addEventListener("change", resize);
|
|
52
|
-
return () => {
|
|
53
|
-
doc.body.removeChild(ghost);
|
|
54
|
-
input == null ? void 0 : input.removeEventListener("input", resize);
|
|
55
|
-
input == null ? void 0 : input.removeEventListener("change", resize);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
export {
|
|
59
|
-
autoResizeInput
|
|
60
|
-
};
|