@zag-js/auto-resize 0.1.3 → 0.1.4

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 CHANGED
@@ -1,4 +1,30 @@
1
- // ../dom/dist/index.js
1
+ "use strict";
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
2
28
  function isDocument(el) {
3
29
  return el.nodeType === Node.DOCUMENT_NODE;
4
30
  }
@@ -55,6 +81,7 @@ function autoResizeInput(input) {
55
81
  input == null ? void 0 : input.removeEventListener("change", resize);
56
82
  };
57
83
  }
58
- export {
84
+ // Annotate the CommonJS export names for ESM import in node:
85
+ 0 && (module.exports = {
59
86
  autoResizeInput
60
- };
87
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,60 @@
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
+ };
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
- "type": "module",
3
2
  "name": "@zag-js/auto-resize",
4
- "version": "0.1.3",
3
+ "version": "0.1.4",
5
4
  "description": "Autoresize utilities for the web",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
6
8
  "keywords": [
7
9
  "js",
8
10
  "utils",
@@ -11,8 +13,6 @@
11
13
  "author": "Segun Adebayo <sage@adebayosegun.com>",
12
14
  "homepage": "https://github.com/chakra-ui/zag#readme",
13
15
  "license": "MIT",
14
- "main": "dist/index.js",
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,
18
18
  "files": [
@@ -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.12"
28
+ "@zag-js/dom-utils": "0.1.13"
29
29
  },
30
30
  "scripts": {
31
- "build-fast": "tsup src/index.ts --format=esm",
31
+ "build-fast": "tsup src/index.ts --format=esm,cjs",
32
32
  "start": "pnpm build --watch",
33
- "build": "tsup src/index.ts --format=esm --dts",
33
+ "build": "tsup src/index.ts --format=esm,cjs --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",