@zag-js/auto-resize 0.50.0 → 0.51.1

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,69 +1,2 @@
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
- var import_dom_query = require("@zag-js/dom-query");
27
- function copyVisualStyles(fromEl, toEl) {
28
- if (!fromEl)
29
- return;
30
- const win = (0, import_dom_query.getWindow)(fromEl);
31
- const el = win.getComputedStyle(fromEl);
32
- 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;
33
- toEl.style.cssText += cssText;
34
- }
35
- function createGhostElement(doc) {
36
- var el = doc.createElement("div");
37
- el.id = "ghost";
38
- el.style.cssText = "display:inline-block;height:0;overflow:hidden;position:absolute;top:0;visibility:hidden;white-space:nowrap;";
39
- doc.body.appendChild(el);
40
- return el;
41
- }
42
- function autoResizeInput(input) {
43
- if (!input)
44
- return;
45
- const doc = (0, import_dom_query.getDocument)(input);
46
- const win = (0, import_dom_query.getWindow)(input);
47
- const ghost = createGhostElement(doc);
48
- copyVisualStyles(input, ghost);
49
- function resize() {
50
- win.requestAnimationFrame(() => {
51
- ghost.innerHTML = input.value;
52
- const rect = win.getComputedStyle(ghost);
53
- input?.style.setProperty("width", rect.width);
54
- });
55
- }
56
- resize();
57
- input?.addEventListener("input", resize);
58
- input?.addEventListener("change", resize);
59
- return () => {
60
- doc.body.removeChild(ghost);
61
- input?.removeEventListener("input", resize);
62
- input?.removeEventListener("change", resize);
63
- };
64
- }
65
- // Annotate the CommonJS export names for ESM import in node:
66
- 0 && (module.exports = {
67
- autoResizeInput
68
- });
1
+ "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var src_exports={};__export(src_exports,{autoResizeInput:()=>autoResizeInput});module.exports=__toCommonJS(src_exports);var import_dom_query=require("@zag-js/dom-query");function copyVisualStyles(fromEl,toEl){if(!fromEl)return;const win=(0,import_dom_query.getWindow)(fromEl);const el=win.getComputedStyle(fromEl);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;toEl.style.cssText+=cssText}function createGhostElement(doc){var el=doc.createElement("div");el.id="ghost";el.style.cssText="display:inline-block;height:0;overflow:hidden;position:absolute;top:0;visibility:hidden;white-space:nowrap;";doc.body.appendChild(el);return el}function autoResizeInput(input){if(!input)return;const doc=(0,import_dom_query.getDocument)(input);const win=(0,import_dom_query.getWindow)(input);const ghost=createGhostElement(doc);copyVisualStyles(input,ghost);function resize(){win.requestAnimationFrame(()=>{ghost.innerHTML=input.value;const rect=win.getComputedStyle(ghost);input?.style.setProperty("width",rect.width)})}resize();input?.addEventListener("input",resize);input?.addEventListener("change",resize);return()=>{doc.body.removeChild(ghost);input?.removeEventListener("input",resize);input?.removeEventListener("change",resize)}}0&&(module.exports={autoResizeInput});
69
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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;AAAQ;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;AAAO;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":[]}
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":"qqBAAA,6IAAuC,6BAEvC,SAAS,iBAAiB,OAA4B,KAAmB,CACvE,GAAI,CAAC,OAAQ,OAEb,MAAM,OAAM,4BAAU,MAAM,EAC5B,MAAM,GAAK,IAAI,iBAAiB,MAAM,EAGtC,MAAM,QAAU,cAAgB,GAAG,UACf,gBAAkB,GAAG,gBAAkB,2BACpB,GAAG,iBAAmB,0BACvB,GAAG,WACrB,0BAA4B,GAAG,oBAC/B,iBAAmB,GAAG,YACtB,cAAgB,GAAG,SACnB,iBAAmB,GAAG,YACtB,eAAiB,GAAG,UACpB,iBAAmB,GAAG,YACtB,sBAAwB,GAAG,gBAC3B,2BAA6B,GAAG,qBAChC,yBAA2B,GAAG,mBAC9B,gBAAkB,GAAG,WACrB,mBAAqB,GAAG,cACxB,gBAAkB,GAAG,WACrB,iBAAmB,GAAG,YACtB,iBAAmB,GAAG,YACtB,kBAAoB,GAAG,aACvB,gBAAkB,GAAG,WACrB,mBAAqB,GAAG,cAE5C,KAAK,MAAM,SAAW,OACxB,CAEA,SAAS,mBAAmB,IAAe,CACzC,IAAI,GAAK,IAAI,cAAc,KAAK,EAChC,GAAG,GAAK,QACR,GAAG,MAAM,QACP,8GACF,IAAI,KAAK,YAAY,EAAE,EACvB,OAAO,EACT,CAEO,SAAS,gBAAgB,MAAgC,CAC9D,GAAI,CAAC,MAAO,OACZ,MAAM,OAAM,8BAAY,KAAK,EAC7B,MAAM,OAAM,4BAAU,KAAK,EAE3B,MAAM,MAAQ,mBAAmB,GAAG,EAEpC,iBAAiB,MAAO,KAAK,EAE7B,SAAS,QAAS,CAChB,IAAI,sBAAsB,IAAM,CAC9B,MAAM,UAAY,MAAO,MACzB,MAAM,KAAO,IAAI,iBAAiB,KAAK,EACvC,OAAO,MAAM,YAAY,QAAS,KAAK,KAAK,CAC9C,CAAC,CACH,CAEA,OAAO,EAEP,OAAO,iBAAiB,QAAS,MAAM,EACvC,OAAO,iBAAiB,SAAU,MAAM,EAExC,MAAO,IAAM,CACX,IAAI,KAAK,YAAY,KAAK,EAC1B,OAAO,oBAAoB,QAAS,MAAM,EAC1C,OAAO,oBAAoB,SAAU,MAAM,CAC7C,CACF","names":[]}
package/dist/index.mjs CHANGED
@@ -1,44 +1,2 @@
1
- // src/index.ts
2
- import { getDocument, getWindow } from "@zag-js/dom-query";
3
- function copyVisualStyles(fromEl, toEl) {
4
- if (!fromEl)
5
- return;
6
- const win = getWindow(fromEl);
7
- const el = win.getComputedStyle(fromEl);
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;
10
- }
11
- function createGhostElement(doc) {
12
- var el = doc.createElement("div");
13
- el.id = "ghost";
14
- el.style.cssText = "display:inline-block;height:0;overflow:hidden;position:absolute;top:0;visibility:hidden;white-space:nowrap;";
15
- doc.body.appendChild(el);
16
- return el;
17
- }
18
- function autoResizeInput(input) {
19
- if (!input)
20
- return;
21
- const doc = getDocument(input);
22
- const win = getWindow(input);
23
- const ghost = createGhostElement(doc);
24
- copyVisualStyles(input, ghost);
25
- function resize() {
26
- win.requestAnimationFrame(() => {
27
- ghost.innerHTML = input.value;
28
- const rect = win.getComputedStyle(ghost);
29
- input?.style.setProperty("width", rect.width);
30
- });
31
- }
32
- resize();
33
- input?.addEventListener("input", resize);
34
- input?.addEventListener("change", resize);
35
- return () => {
36
- doc.body.removeChild(ghost);
37
- input?.removeEventListener("input", resize);
38
- input?.removeEventListener("change", resize);
39
- };
40
- }
41
- export {
42
- autoResizeInput
43
- };
1
+ import{getDocument,getWindow}from"@zag-js/dom-query";function copyVisualStyles(fromEl,toEl){if(!fromEl)return;const win=getWindow(fromEl);const el=win.getComputedStyle(fromEl);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;toEl.style.cssText+=cssText}function createGhostElement(doc){var el=doc.createElement("div");el.id="ghost";el.style.cssText="display:inline-block;height:0;overflow:hidden;position:absolute;top:0;visibility:hidden;white-space:nowrap;";doc.body.appendChild(el);return el}function autoResizeInput(input){if(!input)return;const doc=getDocument(input);const win=getWindow(input);const ghost=createGhostElement(doc);copyVisualStyles(input,ghost);function resize(){win.requestAnimationFrame(()=>{ghost.innerHTML=input.value;const rect=win.getComputedStyle(ghost);input?.style.setProperty("width",rect.width)})}resize();input?.addEventListener("input",resize);input?.addEventListener("change",resize);return()=>{doc.body.removeChild(ghost);input?.removeEventListener("input",resize);input?.removeEventListener("change",resize)}}export{autoResizeInput};
44
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
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;AAAQ;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;AAAO;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":[]}
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,OAAS,YAAa,cAAiB,oBAEvC,SAAS,iBAAiB,OAA4B,KAAmB,CACvE,GAAI,CAAC,OAAQ,OAEb,MAAM,IAAM,UAAU,MAAM,EAC5B,MAAM,GAAK,IAAI,iBAAiB,MAAM,EAGtC,MAAM,QAAU,cAAgB,GAAG,UACf,gBAAkB,GAAG,gBAAkB,2BACpB,GAAG,iBAAmB,0BACvB,GAAG,WACrB,0BAA4B,GAAG,oBAC/B,iBAAmB,GAAG,YACtB,cAAgB,GAAG,SACnB,iBAAmB,GAAG,YACtB,eAAiB,GAAG,UACpB,iBAAmB,GAAG,YACtB,sBAAwB,GAAG,gBAC3B,2BAA6B,GAAG,qBAChC,yBAA2B,GAAG,mBAC9B,gBAAkB,GAAG,WACrB,mBAAqB,GAAG,cACxB,gBAAkB,GAAG,WACrB,iBAAmB,GAAG,YACtB,iBAAmB,GAAG,YACtB,kBAAoB,GAAG,aACvB,gBAAkB,GAAG,WACrB,mBAAqB,GAAG,cAE5C,KAAK,MAAM,SAAW,OACxB,CAEA,SAAS,mBAAmB,IAAe,CACzC,IAAI,GAAK,IAAI,cAAc,KAAK,EAChC,GAAG,GAAK,QACR,GAAG,MAAM,QACP,8GACF,IAAI,KAAK,YAAY,EAAE,EACvB,OAAO,EACT,CAEO,SAAS,gBAAgB,MAAgC,CAC9D,GAAI,CAAC,MAAO,OACZ,MAAM,IAAM,YAAY,KAAK,EAC7B,MAAM,IAAM,UAAU,KAAK,EAE3B,MAAM,MAAQ,mBAAmB,GAAG,EAEpC,iBAAiB,MAAO,KAAK,EAE7B,SAAS,QAAS,CAChB,IAAI,sBAAsB,IAAM,CAC9B,MAAM,UAAY,MAAO,MACzB,MAAM,KAAO,IAAI,iBAAiB,KAAK,EACvC,OAAO,MAAM,YAAY,QAAS,KAAK,KAAK,CAC9C,CAAC,CACH,CAEA,OAAO,EAEP,OAAO,iBAAiB,QAAS,MAAM,EACvC,OAAO,iBAAiB,SAAU,MAAM,EAExC,MAAO,IAAM,CACX,IAAI,KAAK,YAAY,KAAK,EAC1B,OAAO,oBAAoB,QAAS,MAAM,EAC1C,OAAO,oBAAoB,SAAU,MAAM,CAC7C,CACF","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/auto-resize",
3
- "version": "0.50.0",
3
+ "version": "0.51.1",
4
4
  "description": "Autoresize utilities for the web",
5
5
  "keywords": [
6
6
  "js",
@@ -23,7 +23,7 @@
23
23
  "url": "https://github.com/chakra-ui/zag/issues"
24
24
  },
25
25
  "dependencies": {
26
- "@zag-js/dom-query": "0.50.0"
26
+ "@zag-js/dom-query": "0.51.1"
27
27
  },
28
28
  "devDependencies": {
29
29
  "clean-package": "2.2.0"