@zag-js/auto-resize 0.0.0-dev-20220615060231
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/README.md +22 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +79 -0
- package/dist/index.mjs +57 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# @zag-js/auto-resize
|
|
2
|
+
|
|
3
|
+
Autoresize utilities for the web
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
yarn add @zag-js/auto-resize
|
|
9
|
+
# or
|
|
10
|
+
npm i @zag-js/auto-resize
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Contribution
|
|
14
|
+
|
|
15
|
+
Yes please! See the
|
|
16
|
+
[contributing guidelines](https://github.com/chakra-ui/zag/blob/main/CONTRIBUTING.md)
|
|
17
|
+
for details.
|
|
18
|
+
|
|
19
|
+
## Licence
|
|
20
|
+
|
|
21
|
+
This project is licensed under the terms of the
|
|
22
|
+
[MIT license](https://github.com/chakra-ui/zag/blob/main/LICENSE).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function autoResizeInput(input: HTMLInputElement | null): () => void;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
var src_exports = {};
|
|
21
|
+
__export(src_exports, {
|
|
22
|
+
autoResizeInput: () => autoResizeInput
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(src_exports);
|
|
25
|
+
|
|
26
|
+
// ../dom/dist/index.mjs
|
|
27
|
+
function isWindow(value) {
|
|
28
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
29
|
+
}
|
|
30
|
+
function getOwnerDocument(el) {
|
|
31
|
+
var _a;
|
|
32
|
+
if (isWindow(el))
|
|
33
|
+
return el.document;
|
|
34
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
35
|
+
}
|
|
36
|
+
function getOwnerWindow(el) {
|
|
37
|
+
var _a;
|
|
38
|
+
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/index.ts
|
|
42
|
+
function copyVisualStyles(fromEl, toEl) {
|
|
43
|
+
if (!fromEl)
|
|
44
|
+
return;
|
|
45
|
+
const win = getOwnerWindow(fromEl);
|
|
46
|
+
const el = win.getComputedStyle(fromEl);
|
|
47
|
+
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;
|
|
48
|
+
toEl.style.cssText += cssText;
|
|
49
|
+
}
|
|
50
|
+
function createGhostElement(doc) {
|
|
51
|
+
var el = doc.createElement("div");
|
|
52
|
+
el.id = "ghost";
|
|
53
|
+
el.style.cssText = "display:inline-block;height:0;overflow:hidden;position:absolute;top:0;visibility:hidden;white-space:nowrap;";
|
|
54
|
+
doc.body.appendChild(el);
|
|
55
|
+
return el;
|
|
56
|
+
}
|
|
57
|
+
function autoResizeInput(input) {
|
|
58
|
+
if (!input)
|
|
59
|
+
return;
|
|
60
|
+
const doc = getOwnerDocument(input);
|
|
61
|
+
const win = getOwnerWindow(input);
|
|
62
|
+
const ghost = createGhostElement(doc);
|
|
63
|
+
copyVisualStyles(input, ghost);
|
|
64
|
+
function resize() {
|
|
65
|
+
win.requestAnimationFrame(() => {
|
|
66
|
+
ghost.innerHTML = input.value;
|
|
67
|
+
const rect = win.getComputedStyle(ghost);
|
|
68
|
+
input == null ? void 0 : input.style.setProperty("width", rect.width);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
resize();
|
|
72
|
+
input == null ? void 0 : input.addEventListener("input", resize);
|
|
73
|
+
input == null ? void 0 : input.addEventListener("change", resize);
|
|
74
|
+
return () => {
|
|
75
|
+
doc.body.removeChild(ghost);
|
|
76
|
+
input == null ? void 0 : input.removeEventListener("input", resize);
|
|
77
|
+
input == null ? void 0 : input.removeEventListener("change", resize);
|
|
78
|
+
};
|
|
79
|
+
}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// ../dom/dist/index.mjs
|
|
2
|
+
function isWindow(value) {
|
|
3
|
+
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
4
|
+
}
|
|
5
|
+
function getOwnerDocument(el) {
|
|
6
|
+
var _a;
|
|
7
|
+
if (isWindow(el))
|
|
8
|
+
return el.document;
|
|
9
|
+
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
10
|
+
}
|
|
11
|
+
function getOwnerWindow(el) {
|
|
12
|
+
var _a;
|
|
13
|
+
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/index.ts
|
|
17
|
+
function copyVisualStyles(fromEl, toEl) {
|
|
18
|
+
if (!fromEl)
|
|
19
|
+
return;
|
|
20
|
+
const win = getOwnerWindow(fromEl);
|
|
21
|
+
const el = win.getComputedStyle(fromEl);
|
|
22
|
+
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;
|
|
23
|
+
toEl.style.cssText += cssText;
|
|
24
|
+
}
|
|
25
|
+
function createGhostElement(doc) {
|
|
26
|
+
var el = doc.createElement("div");
|
|
27
|
+
el.id = "ghost";
|
|
28
|
+
el.style.cssText = "display:inline-block;height:0;overflow:hidden;position:absolute;top:0;visibility:hidden;white-space:nowrap;";
|
|
29
|
+
doc.body.appendChild(el);
|
|
30
|
+
return el;
|
|
31
|
+
}
|
|
32
|
+
function autoResizeInput(input) {
|
|
33
|
+
if (!input)
|
|
34
|
+
return;
|
|
35
|
+
const doc = getOwnerDocument(input);
|
|
36
|
+
const win = getOwnerWindow(input);
|
|
37
|
+
const ghost = createGhostElement(doc);
|
|
38
|
+
copyVisualStyles(input, ghost);
|
|
39
|
+
function resize() {
|
|
40
|
+
win.requestAnimationFrame(() => {
|
|
41
|
+
ghost.innerHTML = input.value;
|
|
42
|
+
const rect = win.getComputedStyle(ghost);
|
|
43
|
+
input == null ? void 0 : input.style.setProperty("width", rect.width);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
resize();
|
|
47
|
+
input == null ? void 0 : input.addEventListener("input", resize);
|
|
48
|
+
input == null ? void 0 : input.addEventListener("change", resize);
|
|
49
|
+
return () => {
|
|
50
|
+
doc.body.removeChild(ghost);
|
|
51
|
+
input == null ? void 0 : input.removeEventListener("input", resize);
|
|
52
|
+
input == null ? void 0 : input.removeEventListener("change", resize);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
autoResizeInput
|
|
57
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zag-js/auto-resize",
|
|
3
|
+
"version": "0.0.0-dev-20220615060231",
|
|
4
|
+
"description": "Autoresize utilities for the web",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"js",
|
|
7
|
+
"utils",
|
|
8
|
+
"auto-resize"
|
|
9
|
+
],
|
|
10
|
+
"author": "Segun Adebayo <sage@adebayosegun.com>",
|
|
11
|
+
"homepage": "https://github.com/chakra-ui/zag#readme",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"module": "dist/index.mjs",
|
|
15
|
+
"types": "dist/index.d.ts",
|
|
16
|
+
"repository": "https://github.com/chakra-ui/zag/tree/main/packages/utilities/auto-resize",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/**/*"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build:fast": "yarn zag build",
|
|
23
|
+
"start": "yarn zag build --watch",
|
|
24
|
+
"build": "yarn zag build --prod",
|
|
25
|
+
"test": "jest --config ../../../jest.config.js --rootDir tests",
|
|
26
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
27
|
+
"test:ci": "yarn test --ci --runInBand --updateSnapshot",
|
|
28
|
+
"test:watch": "yarn test --watchAll"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/chakra-ui/zag/issues"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@zag-js/dom-utils": "0.0.0-dev-20220615060231"
|
|
38
|
+
}
|
|
39
|
+
}
|