@zc-ui/hooks 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ZC UI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("vue"),t=require("@zc-ui/utils");function n(n,i,a,o={}){let{capture:s=!1,passive:c=!1,immediate:l=!1}=o;if(!t.isClient)return()=>{};let u=null,d=e=>{let t={capture:s};c&&(t.passive=c),e.addEventListener(i,a,t),u=()=>e.removeEventListener(i,a,t)},f=()=>{if(!t.isClient)return;let e=r(n)?n.value:n;e&&d(e)},p=(0,e.getCurrentInstance)();return l?(f(),r(n)&&p&&(0,e.onMounted)(f)):p?(0,e.onMounted)(f):console.warn("[zc-ui] useEventListener: called outside of a component setup function without `immediate: true`. The listener will not be attached."),p&&(0,e.onBeforeUnmount)(()=>{u&&u()}),()=>{u&&u()}}function r(e){return typeof e==`object`&&!!e&&`__v_isRef`in e}function i(e,t,i={}){let{ignore:o=[],event:s=`click`}=i;n(document,s,n=>{let i=r(e)?e.value:e;if(!i)return;let s=n.composedPath?n.composedPath():[],c=n.target||s[0];if(!a(i,c)){for(let e of o)if(e&&a(e,c))return;t(n)}})}function a(e,t){return t&&`contains`in e?e.contains(t):!1}function o(n){let r=(0,e.ref)(0),i=(0,e.ref)(0);if(!t.isClient)return{width:r,height:i};let a=null,o=e=>{let t=e.getBoundingClientRect();r.value=t.width,i.value=t.height};return(0,e.onMounted)(()=>{let e=n.value;e&&(o(e),`ResizeObserver`in window&&(a=new ResizeObserver(e=>{for(let t of e){let{width:e,height:n}=t.contentRect;r.value=e,i.value=n}}),a.observe(e)))}),(0,e.onBeforeUnmount)(()=>{a&&(a.disconnect(),a=null)}),{width:r,height:i}}var s=1300,c=(0,e.ref)(s);function l(){return{currentZIndex:(0,e.computed)(()=>c.value),nextZIndex:()=>++c.value,resetZIndex:()=>{c.value=s}}}function u(){return s}var d=0;function f(e=`zc`){return{id:`${e}-${(0,t.guid)()}-${++d}`}}function p(t={}){let{returnFocusOnRelease:n=!0}=t,r=(0,e.ref)(!1),i=null,a=null,o=[`a[href]`,`button:not([disabled])`,`input:not([disabled])`,`textarea:not([disabled])`,`select:not([disabled])`,`[tabindex]:not([tabindex="-1"])`,`[contenteditable="true"]`].join(`, `);function s(){return i?Array.from(i.querySelectorAll(o)).filter(e=>e.offsetParent!==null||e.getClientRects().length>0||e===document.activeElement):[]}function c(e){if(e.key!==`Tab`||!r.value||!i)return;let t=s();if(t.length===0){e.preventDefault();return}let n=t[0],a=t[t.length-1];e.shiftKey?(document.activeElement===n||!i.contains(document.activeElement))&&(e.preventDefault(),a.focus()):(document.activeElement===a||!i.contains(document.activeElement))&&(e.preventDefault(),n.focus())}function l(t){let n=`value`in t?t.value:t;n&&(a=document.activeElement,i=n,r.value=!0,document.addEventListener(`keydown`,c),(0,e.nextTick)(()=>{let e=s();e.length>0?e[0].focus():(n.setAttribute(`tabindex`,`-1`),n.focus())}))}function u(){r.value&&(document.removeEventListener(`keydown`,c),r.value=!1,i=null,n&&a&&(a.focus(),a=null))}return(0,e.onBeforeUnmount)(()=>{u()}),{active:r,activate:l,release:u}}function m(){let t=(0,e.getCurrentInstance)();return(0,e.computed)(()=>{var e;return(e=t==null?void 0:t.appContext.config.globalProperties.$router)==null?null:e})}function h(t=!1){let n=(0,e.ref)(t);return{value:n,toggle:()=>{n.value=!n.value},set:e=>{n.value=e}}}function g(e){let t=()=>`zc-${e}`;return{b:t,e:e=>e?`${t()}__${e}`:``,m:e=>e?`${t()}--${e}`:``,em:(e,n)=>e&&n?`${t()}__${e}--${n}`:``,bm:e=>e?`${t()} ${t()}--${e}`:t(),is:(e,t=!0)=>t?`is-${e}`:``}}exports.getBaseZIndex=u,exports.useClickOutside=i,exports.useEventListener=n,exports.useFocusTrap=p,exports.useId=f,exports.useNamespace=g,exports.useOptionalRouter=m,exports.useSize=o,exports.useToggle=h,exports.useZIndex=l;
package/dist/index.mjs ADDED
@@ -0,0 +1,167 @@
1
+ import { computed as e, getCurrentInstance as t, nextTick as n, onBeforeUnmount as r, onMounted as i, ref as a } from "vue";
2
+ import { guid as o, isClient as s } from "@zc-ui/utils";
3
+ //#region src/useEventListener.ts
4
+ function c(e, n, a, o = {}) {
5
+ let { capture: c = !1, passive: u = !1, immediate: d = !1 } = o;
6
+ if (!s) return () => {};
7
+ let f = null, p = (e) => {
8
+ let t = { capture: c };
9
+ u && (t.passive = u), e.addEventListener(n, a, t), f = () => e.removeEventListener(n, a, t);
10
+ }, m = () => {
11
+ if (!s) return;
12
+ let t = l(e) ? e.value : e;
13
+ t && p(t);
14
+ }, h = t();
15
+ return d ? (m(), l(e) && h && i(m)) : h ? i(m) : console.warn("[zc-ui] useEventListener: called outside of a component setup function without `immediate: true`. The listener will not be attached."), h && r(() => {
16
+ f && f();
17
+ }), () => {
18
+ f && f();
19
+ };
20
+ }
21
+ function l(e) {
22
+ return typeof e == "object" && !!e && "__v_isRef" in e;
23
+ }
24
+ //#endregion
25
+ //#region src/useClickOutside.ts
26
+ function u(e, t, n = {}) {
27
+ let { ignore: r = [], event: i = "click" } = n;
28
+ c(document, i, (n) => {
29
+ let i = l(e) ? e.value : e;
30
+ if (!i) return;
31
+ let a = n.composedPath ? n.composedPath() : [], o = n.target || a[0];
32
+ if (!d(i, o)) {
33
+ for (let e of r) if (e && d(e, o)) return;
34
+ t(n);
35
+ }
36
+ });
37
+ }
38
+ function d(e, t) {
39
+ return t && "contains" in e ? e.contains(t) : !1;
40
+ }
41
+ //#endregion
42
+ //#region src/useSize.ts
43
+ function f(e) {
44
+ let t = a(0), n = a(0);
45
+ if (!s) return {
46
+ width: t,
47
+ height: n
48
+ };
49
+ let o = null, c = (e) => {
50
+ let r = e.getBoundingClientRect();
51
+ t.value = r.width, n.value = r.height;
52
+ };
53
+ return i(() => {
54
+ let r = e.value;
55
+ r && (c(r), "ResizeObserver" in window && (o = new ResizeObserver((e) => {
56
+ for (let r of e) {
57
+ let { width: e, height: i } = r.contentRect;
58
+ t.value = e, n.value = i;
59
+ }
60
+ }), o.observe(r)));
61
+ }), r(() => {
62
+ o && (o.disconnect(), o = null);
63
+ }), {
64
+ width: t,
65
+ height: n
66
+ };
67
+ }
68
+ //#endregion
69
+ //#region src/useZIndex.ts
70
+ var p = 1300, m = a(p);
71
+ function h() {
72
+ return {
73
+ currentZIndex: e(() => m.value),
74
+ nextZIndex: () => ++m.value,
75
+ resetZIndex: () => {
76
+ m.value = p;
77
+ }
78
+ };
79
+ }
80
+ function g() {
81
+ return p;
82
+ }
83
+ //#endregion
84
+ //#region src/useId.ts
85
+ var _ = 0;
86
+ function v(e = "zc") {
87
+ return { id: `${e}-${o()}-${++_}` };
88
+ }
89
+ //#endregion
90
+ //#region src/useFocusTrap.ts
91
+ function y(e = {}) {
92
+ let { returnFocusOnRelease: t = !0 } = e, i = a(!1), o = null, s = null, c = [
93
+ "a[href]",
94
+ "button:not([disabled])",
95
+ "input:not([disabled])",
96
+ "textarea:not([disabled])",
97
+ "select:not([disabled])",
98
+ "[tabindex]:not([tabindex=\"-1\"])",
99
+ "[contenteditable=\"true\"]"
100
+ ].join(", ");
101
+ function l() {
102
+ return o ? Array.from(o.querySelectorAll(c)).filter((e) => e.offsetParent !== null || e.getClientRects().length > 0 || e === document.activeElement) : [];
103
+ }
104
+ function u(e) {
105
+ if (e.key !== "Tab" || !i.value || !o) return;
106
+ let t = l();
107
+ if (t.length === 0) {
108
+ e.preventDefault();
109
+ return;
110
+ }
111
+ let n = t[0], r = t[t.length - 1];
112
+ e.shiftKey ? (document.activeElement === n || !o.contains(document.activeElement)) && (e.preventDefault(), r.focus()) : (document.activeElement === r || !o.contains(document.activeElement)) && (e.preventDefault(), n.focus());
113
+ }
114
+ function d(e) {
115
+ let t = "value" in e ? e.value : e;
116
+ t && (s = document.activeElement, o = t, i.value = !0, document.addEventListener("keydown", u), n(() => {
117
+ let e = l();
118
+ e.length > 0 ? e[0].focus() : (t.setAttribute("tabindex", "-1"), t.focus());
119
+ }));
120
+ }
121
+ function f() {
122
+ i.value && (document.removeEventListener("keydown", u), i.value = !1, o = null, t && s && (s.focus(), s = null));
123
+ }
124
+ return r(() => {
125
+ f();
126
+ }), {
127
+ active: i,
128
+ activate: d,
129
+ release: f
130
+ };
131
+ }
132
+ //#endregion
133
+ //#region src/useOptionalRouter.ts
134
+ function b() {
135
+ let n = t();
136
+ return e(() => {
137
+ var e;
138
+ return (e = n == null ? void 0 : n.appContext.config.globalProperties.$router) == null ? null : e;
139
+ });
140
+ }
141
+ //#endregion
142
+ //#region src/index.ts
143
+ function x(e = !1) {
144
+ let t = a(e);
145
+ return {
146
+ value: t,
147
+ toggle: () => {
148
+ t.value = !t.value;
149
+ },
150
+ set: (e) => {
151
+ t.value = e;
152
+ }
153
+ };
154
+ }
155
+ function S(e) {
156
+ let t = () => `zc-${e}`;
157
+ return {
158
+ b: t,
159
+ e: (e) => e ? `${t()}__${e}` : "",
160
+ m: (e) => e ? `${t()}--${e}` : "",
161
+ em: (e, n) => e && n ? `${t()}__${e}--${n}` : "",
162
+ bm: (e) => e ? `${t()} ${t()}--${e}` : t(),
163
+ is: (e, t = !0) => t ? `is-${e}` : ""
164
+ };
165
+ }
166
+ //#endregion
167
+ export { g as getBaseZIndex, u as useClickOutside, c as useEventListener, y as useFocusTrap, v as useId, S as useNamespace, b as useOptionalRouter, f as useSize, x as useToggle, h as useZIndex };
@@ -0,0 +1,44 @@
1
+ import { Ref } from 'vue';
2
+ export { useEventListener, type EventTargetLike, type UseEventListenerOptions, } from './useEventListener';
3
+ export { useClickOutside, type ClickOutsideOptions } from './useClickOutside';
4
+ export { useSize, type ElementSize, type UseSizeReturn } from './useSize';
5
+ export { useZIndex, getBaseZIndex } from './useZIndex';
6
+ export { useId } from './useId';
7
+ export { useFocusTrap, type FocusTrapOptions } from './useFocusTrap';
8
+ export { useOptionalRouter } from './useOptionalRouter';
9
+ /**
10
+ * useToggle - A simple boolean toggle composable.
11
+ *
12
+ * @example
13
+ * const { value, toggle, set } = useToggle(false)
14
+ * toggle() // value becomes true
15
+ * set(false) // value is now false
16
+ */
17
+ export declare function useToggle(initialValue?: boolean): {
18
+ value: Ref<boolean>;
19
+ toggle: () => void;
20
+ set: (val: boolean) => void;
21
+ };
22
+ /**
23
+ * useNamespace - BEM class name generator for ZC UI components.
24
+ *
25
+ * Follows the convention: zc-{block}__{element}--{modifier}
26
+ *
27
+ * @example
28
+ * const ns = useNamespace('button')
29
+ * ns.b() // 'zc-button'
30
+ * ns.e('icon') // 'zc-button__icon'
31
+ * ns.m('primary') // 'zc-button--primary'
32
+ * ns.em('icon','left') // 'zc-button__icon--left'
33
+ * ns.is('disabled') // 'is-disabled'
34
+ * ns.is('loading', true) // 'is-loading'
35
+ */
36
+ export declare function useNamespace(block: string): {
37
+ b: () => string;
38
+ e: (el: string) => string;
39
+ m: (mod: string) => string;
40
+ em: (el: string, mod: string) => string;
41
+ bm: (mod: string) => string;
42
+ is: (name: string, state?: boolean) => string;
43
+ };
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,GAAG,EAAE,MAAM,KAAK,CAAA;AAGnC,OAAO,EACL,gBAAgB,EAChB,KAAK,eAAe,EACpB,KAAK,uBAAuB,GAC7B,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,eAAe,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAC7E,OAAO,EAAE,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAA;AACzE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAMvD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,YAAY,UAAQ,GAAG;IAC/C,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IACnB,MAAM,EAAE,MAAM,IAAI,CAAA;IAClB,GAAG,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAA;CAC5B,CASA;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM;;YAOzB,MAAM;aAGL,MAAM;aAGN,MAAM,OAAO,MAAM;cAGlB,MAAM;eAGL,MAAM;EAGzB"}
@@ -0,0 +1,25 @@
1
+ import { EventTargetLike } from './useEventListener';
2
+ export type { EventTargetLike, UseEventListenerOptions } from './useEventListener';
3
+ /**
4
+ * Options for useClickOutside.
5
+ */
6
+ export interface ClickOutsideOptions {
7
+ /** Additional elements that should NOT trigger the outside-click. */
8
+ ignore?: Array<EventTargetLike | null | undefined>;
9
+ /** Event type to listen for. Default: 'click' */
10
+ event?: string;
11
+ }
12
+ /**
13
+ * useClickOutside - Invoke a handler when the user clicks outside
14
+ * the referenced element(s).
15
+ *
16
+ * @example
17
+ * const targetRef = ref<HTMLElement | null>(null)
18
+ * useClickOutside(targetRef, () => {
19
+ * console.log('Clicked outside!')
20
+ * })
21
+ */
22
+ export declare function useClickOutside(target: EventTargetLike | {
23
+ value: EventTargetLike | null | undefined;
24
+ }, handler: (e: MouseEvent) => void, options?: ClickOutsideOptions): void;
25
+ //# sourceMappingURL=useClickOutside.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useClickOutside.d.ts","sourceRoot":"","sources":["../../src/useClickOutside.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAExF,YAAY,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AAElF;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,qEAAqE;IACrE,MAAM,CAAC,EAAE,KAAK,CAAC,eAAe,GAAG,IAAI,GAAG,SAAS,CAAC,CAAA;IAClD,iDAAiD;IACjD,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,eAAe,GAAG;IAAE,KAAK,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,CAAA;CAAE,EACvE,OAAO,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,EAChC,OAAO,GAAE,mBAAwB,GAChC,IAAI,CA0BN"}
@@ -0,0 +1,31 @@
1
+ import { Ref } from 'vue';
2
+ /**
3
+ * Type alias for any event target that supports addEventListener.
4
+ */
5
+ export type EventTargetLike = HTMLElement | Window | Document;
6
+ /**
7
+ * Options for useEventListener.
8
+ */
9
+ export interface UseEventListenerOptions {
10
+ /** Whether to use capture phase */
11
+ capture?: boolean;
12
+ /** Whether to use passive listener */
13
+ passive?: boolean;
14
+ /** Register listener immediately (skip onMounted). Default: false */
15
+ immediate?: boolean;
16
+ }
17
+ /**
18
+ * useEventListener - Register an event listener on a target and
19
+ * automatically clean up on component unmount.
20
+ *
21
+ * Supports reactive Ref<HTMLElement | null> targets, static targets,
22
+ * and SSR-safe operation (no-op when window is undefined).
23
+ *
24
+ * @example
25
+ * useEventListener(window, 'resize', () => console.log('resized'))
26
+ * useEventListener(buttonRef, 'click', handler)
27
+ */
28
+ export declare function useEventListener(target: EventTargetLike | Ref<EventTargetLike | null | undefined>, event: string, handler: EventListener, options?: UseEventListenerOptions): () => void;
29
+ /** Type guard: check if value is a Vue Ref — exported for reuse by other composables */
30
+ export declare function isRefTarget(val: unknown): val is Ref<unknown>;
31
+ //# sourceMappingURL=useEventListener.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEventListener.d.ts","sourceRoot":"","sources":["../../src/useEventListener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkD,KAAK,GAAG,EAAE,MAAM,KAAK,CAAA;AAG9E;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,MAAM,GAAG,QAAQ,CAAA;AAE7D;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,mCAAmC;IACnC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,sCAAsC;IACtC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,qEAAqE;IACrE,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,eAAe,GAAG,GAAG,CAAC,eAAe,GAAG,IAAI,GAAG,SAAS,CAAC,EACjE,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,aAAa,EACtB,OAAO,GAAE,uBAA4B,GACpC,MAAM,IAAI,CAoDZ;AAED,wFAAwF;AACxF,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAE7D"}
@@ -0,0 +1,24 @@
1
+ import { Ref } from 'vue';
2
+ export interface FocusTrapOptions {
3
+ /** Whether to return focus to the previously focused element on release */
4
+ returnFocusOnRelease?: boolean;
5
+ }
6
+ /**
7
+ * useFocusTrap — traps keyboard focus within a container element.
8
+ *
9
+ * When `active` is true, Tab/Shift+Tab cycles only through focusable elements
10
+ * inside the container. On release, focus is optionally restored to the element
11
+ * that was focused before activation.
12
+ *
13
+ * @example
14
+ * const trap = useFocusTrap()
15
+ * trap.activate(el)
16
+ * // later...
17
+ * trap.release()
18
+ */
19
+ export declare function useFocusTrap(options?: FocusTrapOptions): {
20
+ active: Ref<boolean, boolean>;
21
+ activate: (el: HTMLElement | Ref<HTMLElement | undefined>) => void;
22
+ release: () => void;
23
+ };
24
+ //# sourceMappingURL=useFocusTrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFocusTrap.d.ts","sourceRoot":"","sources":["../../src/useFocusTrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,GAAG,EAA6B,MAAM,KAAK,CAAA;AAE9D,MAAM,WAAW,gBAAgB;IAC/B,2EAA2E;IAC3E,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,gBAAqB;;mBAmDnC,WAAW,GAAG,GAAG,CAAC,WAAW,GAAG,SAAS,CAAC;;EA6CjE"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * useId - Generate a stable unique ID for use in the DOM.
3
+ * The ID is generated once at setup time and persists across re-renders,
4
+ * making it ideal for ARIA associations and label/input pairings.
5
+ *
6
+ * @example
7
+ * const { id } = useId('input')
8
+ * // id === 'input-xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx-0'
9
+ */
10
+ export declare function useId(prefix?: string): {
11
+ id: string;
12
+ };
13
+ //# sourceMappingURL=useId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useId.d.ts","sourceRoot":"","sources":["../../src/useId.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,MAAM,SAAO,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAGnD"}
@@ -0,0 +1,14 @@
1
+ import { ComputedRef } from 'vue';
2
+ /**
3
+ * useOptionalRouter - Safely access the Vue Router instance.
4
+ *
5
+ * Encapsulates the `getCurrentInstance()` pattern in a composable so
6
+ * individual components don't use it directly. Returns null when
7
+ * vue-router is not installed.
8
+ *
9
+ * @example
10
+ * const router = useOptionalRouter()
11
+ * router.value?.push('/home')
12
+ */
13
+ export declare function useOptionalRouter(): ComputedRef<any | null>;
14
+ //# sourceMappingURL=useOptionalRouter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOptionalRouter.d.ts","sourceRoot":"","sources":["../../src/useOptionalRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,WAAW,EAAE,MAAM,KAAK,CAAA;AAEpE;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,IAAI,WAAW,CAAC,GAAG,GAAG,IAAI,CAAC,CAG3D"}
@@ -0,0 +1,19 @@
1
+ import { Ref } from 'vue';
2
+ export interface ElementSize {
3
+ width: number;
4
+ height: number;
5
+ }
6
+ export interface UseSizeReturn {
7
+ width: Ref<number>;
8
+ height: Ref<number>;
9
+ }
10
+ /**
11
+ * useSize - Track the width and height of a DOM element reactively.
12
+ * Uses ResizeObserver under the hood and cleans up automatically.
13
+ *
14
+ * @example
15
+ * const elRef = ref<HTMLElement | null>(null)
16
+ * const { width, height } = useSize(elRef)
17
+ */
18
+ export declare function useSize(target: Ref<HTMLElement | null | undefined>): UseSizeReturn;
19
+ //# sourceMappingURL=useSize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSize.d.ts","sourceRoot":"","sources":["../../src/useSize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,GAAG,EAAE,MAAM,KAAK,CAAA;AAG/D,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAClB,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CACpB;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,aAAa,CA2ClF"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * useZIndex - Manage z-index values for popup/dropdown/modal layers.
3
+ * Each call to `nextZIndex()` returns a monotonically increasing value,
4
+ * ensuring newly opened layers always appear above previously opened ones.
5
+ *
6
+ * @example
7
+ * const { currentZIndex, nextZIndex } = useZIndex()
8
+ *
9
+ * const dropdownStyle = computed(() => ({
10
+ * zIndex: nextZIndex()
11
+ * }))
12
+ */
13
+ export declare function useZIndex(): {
14
+ currentZIndex: import('vue').ComputedRef<number>;
15
+ nextZIndex: () => number;
16
+ resetZIndex: () => void;
17
+ };
18
+ /**
19
+ * Get the current base z-index constant.
20
+ */
21
+ export declare function getBaseZIndex(): number;
22
+ //# sourceMappingURL=useZIndex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useZIndex.d.ts","sourceRoot":"","sources":["../../src/useZIndex.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS;;sBAMA,MAAM;uBAQL,IAAI;EAS7B;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@zc-ui/hooks",
3
+ "version": "0.0.1",
4
+ "description": "ZC UI Vue 3 composables / hooks",
5
+ "license": "MIT",
6
+ "author": "ZC UI Team",
7
+ "homepage": "https://zc-ui.github.io/zc-ui",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/zc-ui/zc-ui.git",
11
+ "directory": "packages/hooks"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/zc-ui/zc-ui/issues"
15
+ },
16
+ "keywords": [
17
+ "vue",
18
+ "vue3",
19
+ "hooks",
20
+ "composables",
21
+ "zc-ui"
22
+ ],
23
+ "type": "module",
24
+ "main": "./dist/index.cjs",
25
+ "module": "./dist/index.mjs",
26
+ "types": "./dist/types/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/types/index.d.ts",
30
+ "import": "./dist/index.mjs",
31
+ "require": "./dist/index.cjs"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "sideEffects": false,
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "registry": "https://registry.npmjs.org"
41
+ },
42
+ "peerDependencies": {
43
+ "vue": "^3.4.0"
44
+ },
45
+ "dependencies": {
46
+ "@zc-ui/utils": "0.0.1"
47
+ },
48
+ "scripts": {
49
+ "build": "vite build",
50
+ "typecheck": "vue-tsc --noEmit -p tsconfig.json"
51
+ }
52
+ }