@zwire/vue 0.0.0-stage → 0.2.0

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) 2026 kjmin-dev
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/README.md CHANGED
@@ -1,3 +1,23 @@
1
- # Temporary Holding Version
1
+ # `@zwire/vue`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Vue 3.5+ read-through `customRef` and `v-model` adapter for [`@zwire/core`](https://www.npmjs.com/package/@zwire/core).
4
+
5
+ Values always read through to `signal.get()` (snapshots are never copied or deeply proxied), and subscriptions are released by Vue's effect scope, including after SSR.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @zwire/core @zwire/vue
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { ScopeProvider, useAtom, useSelector, useSignal } from '@zwire/vue';
17
+
18
+ const value = useSignal(count); // Readonly<Ref<number>>
19
+ const draft = useAtom(title); // Ref<string>, works with v-model
20
+ const name = useSelector(user, (u) => u.name); // ComputedRef<string> with early cutoff
21
+ ```
22
+
23
+ See the [API reference](https://github.com/kjmin-dev/zwire/blob/main/docs/API.md#72-zwirevue) for full documentation.
@@ -0,0 +1,12 @@
1
+ import { type DefineSetupFnComponent, type InjectionKey, type MaybeRefOrGetter } from 'vue';
2
+ import { type ReactiveScope } from '@zwire/core';
3
+ export interface ScopeProviderProps {
4
+ scope: ReactiveScope;
5
+ }
6
+ /** Injection key carrying the active `ReactiveScope`; usable with `app.provide(ScopeKey, scope)`. */
7
+ export declare const ScopeKey: InjectionKey<ReactiveScope>;
8
+ /** Provides `scope` to every descendant of the current component (call inside `setup()`). */
9
+ export declare function provideScope(scope: ReactiveScope): void;
10
+ export declare const ScopeProvider: DefineSetupFnComponent<ScopeProviderProps>;
11
+ export declare function scopeSource(override?: ReactiveScope): MaybeRefOrGetter<ReactiveScope>;
12
+ export declare function useStoreScope(override?: ReactiveScope): ReactiveScope;
@@ -0,0 +1,26 @@
1
+ import { defineComponent, hasInjectionContext, inject, provide, toValue, } from 'vue';
2
+ import { defaultScope } from '@zwire/core';
3
+ /** Injection key carrying the active `ReactiveScope`; usable with `app.provide(ScopeKey, scope)`. */
4
+ export const ScopeKey = /* @__PURE__ */ Symbol('zwire.scope');
5
+ const SCOPE_GET = /* @__PURE__ */ Symbol();
6
+ /** Provides `scope` to every descendant of the current component (call inside `setup()`). */
7
+ export function provideScope(scope) {
8
+ provide(ScopeKey, scope);
9
+ provide(SCOPE_GET, undefined);
10
+ }
11
+ export const ScopeProvider =
12
+ /* @__PURE__ */ defineComponent((props, { slots }) => {
13
+ provide(ScopeKey, props.scope);
14
+ provide(SCOPE_GET, () => props.scope);
15
+ return () => slots.default?.();
16
+ }, { name: 'ScopeProvider', props: ['scope'] });
17
+ export function scopeSource(override) {
18
+ return (override ??
19
+ (hasInjectionContext()
20
+ ? (inject(SCOPE_GET, undefined) ?? inject(ScopeKey, defaultScope))
21
+ : defaultScope));
22
+ }
23
+ export function useStoreScope(override) {
24
+ return toValue(scopeSource(override));
25
+ }
26
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,MAAM,EACN,OAAO,EACP,OAAO,GAIR,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,YAAY,EAAsB,MAAM,aAAa,CAAC;AAM/D,qGAAqG;AACrG,MAAM,CAAC,MAAM,QAAQ,GAAgC,eAAe,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;AAE3F,MAAM,SAAS,GAAoD,eAAe,CAAC,MAAM,EAAE,CAAC;AAE5F,6FAA6F;AAC7F,MAAM,UAAU,YAAY,CAAC,KAAoB;IAC/C,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACzB,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,CAAC,MAAM,aAAa;AACxB,eAAe,CAAC,eAAe,CAC7B,CAAC,KAAyB,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;IACvC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IAC/B,OAAO,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACtC,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;AACjC,CAAC,EACD,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,CAC5C,CAAC;AAEJ,MAAM,UAAU,WAAW,CAAC,QAAwB;IAClD,OAAO,CACL,QAAQ;QACR,CAAC,mBAAmB,EAAE;YACpB,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;YAClE,CAAC,CAAC,YAAY,CAAC,CAClB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,QAAwB;IACpD,OAAO,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import {\n defineComponent,\n hasInjectionContext,\n inject,\n provide,\n toValue,\n type DefineSetupFnComponent,\n type InjectionKey,\n type MaybeRefOrGetter,\n} from 'vue';\nimport { defaultScope, type ReactiveScope } from '@zwire/core';\n\nexport interface ScopeProviderProps {\n scope: ReactiveScope;\n}\n\n/** Injection key carrying the active `ReactiveScope`; usable with `app.provide(ScopeKey, scope)`. */\nexport const ScopeKey: InjectionKey<ReactiveScope> = /* @__PURE__ */ Symbol('zwire.scope');\n\nconst SCOPE_GET: InjectionKey<(() => ReactiveScope) | undefined> = /* @__PURE__ */ Symbol();\n\n/** Provides `scope` to every descendant of the current component (call inside `setup()`). */\nexport function provideScope(scope: ReactiveScope): void {\n provide(ScopeKey, scope);\n provide(SCOPE_GET, undefined);\n}\n\nexport const ScopeProvider: DefineSetupFnComponent<ScopeProviderProps> =\n /* @__PURE__ */ defineComponent(\n (props: ScopeProviderProps, { slots }) => {\n provide(ScopeKey, props.scope);\n provide(SCOPE_GET, () => props.scope);\n return () => slots.default?.();\n },\n { name: 'ScopeProvider', props: ['scope'] },\n );\n\nexport function scopeSource(override?: ReactiveScope): MaybeRefOrGetter<ReactiveScope> {\n return (\n override ??\n (hasInjectionContext()\n ? (inject(SCOPE_GET, undefined) ?? inject(ScopeKey, defaultScope))\n : defaultScope)\n );\n}\n\nexport function useStoreScope(override?: ReactiveScope): ReactiveScope {\n return toValue(scopeSource(override));\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import { type MaybeRefOrGetter, type Ref } from 'vue';
2
+ import type { ReactiveScope, ReadableSignal } from '@zwire/core';
3
+ /** Lazily open a layer for this component. Unmount reverts an open layer. */
4
+ export declare function useOptimistic<H extends {
5
+ readonly active: boolean;
6
+ revert(): void;
7
+ }>(create: (scope: ReactiveScope) => H, scope?: ReactiveScope): () => H;
8
+ /** Lazily open a draft for this component. Unmount discards an open draft. */
9
+ export declare function useDraft<H extends {
10
+ readonly closed: boolean;
11
+ discard(): void;
12
+ }>(create: (scope: ReactiveScope) => H, scope?: ReactiveScope): () => H;
13
+ export declare function useCollectionTopK<T>(collection: MaybeRefOrGetter<{
14
+ topK(k: number): ReadableSignal<readonly T[]>;
15
+ }>, k: MaybeRefOrGetter<number>, scope?: ReactiveScope): Readonly<Ref<readonly T[]>>;
package/dist/hooks.js ADDED
@@ -0,0 +1,41 @@
1
+ import { onScopeDispose, watch, toValue } from 'vue';
2
+ import { useSignal } from './index.js';
3
+ import { scopeSource } from './context.js';
4
+ function useTransactionHandle(create, scope) {
5
+ const source = scopeSource(scope);
6
+ let current;
7
+ let disposed = false;
8
+ const close = () => {
9
+ const previous = current;
10
+ current = undefined;
11
+ if (previous && 'revert' in previous)
12
+ previous.revert();
13
+ else
14
+ previous?.discard();
15
+ };
16
+ if (typeof source === 'function')
17
+ watch(source, close, { flush: 'sync' });
18
+ onScopeDispose(() => {
19
+ disposed = true;
20
+ close();
21
+ });
22
+ return () => {
23
+ if (disposed)
24
+ throw new Error('Transaction owner disposed');
25
+ if (!current || ('active' in current ? !current.active : current.closed))
26
+ current = create(toValue(source));
27
+ return current;
28
+ };
29
+ }
30
+ /** Lazily open a layer for this component. Unmount reverts an open layer. */
31
+ export function useOptimistic(create, scope) {
32
+ return useTransactionHandle(create, scope);
33
+ }
34
+ /** Lazily open a draft for this component. Unmount discards an open draft. */
35
+ export function useDraft(create, scope) {
36
+ return useTransactionHandle(create, scope);
37
+ }
38
+ export function useCollectionTopK(collection, k, scope) {
39
+ return useSignal(() => toValue(collection).topK(toValue(k)), scope);
40
+ }
41
+ //# sourceMappingURL=h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AACJ,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,aAAa,CAC3B,MAAmC,EACnC,KAAqB;IAErB,OAAO,oBAAoB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC7C,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,QAAQ,CACtB,MAAmC,EACnC,KAAqB;IAErB,OAAO,oBAAoB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,UAA+E,EAC/E,CAA2B,EAC3B,KAAqB;IAErB,OAAO,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACtE,CAAC","sourcesContent":["import { onScopeDispose, watch, toValue, type MaybeRefOrGetter, type Ref } from 'vue';\nimport type { ReactiveScope, ReadableSignal } from '@zwire/core';\nimport { useSignal } from './index.ts';\nimport { scopeSource } from './context.ts';\n\ntype TransactionHandle =\n | { readonly active: boolean; revert(): void }\n | { readonly closed: boolean; discard(): void };\n\nfunction useTransactionHandle<H extends TransactionHandle>(\n create: (scope: ReactiveScope) => H,\n scope?: ReactiveScope,\n): () => H {\n const source = scopeSource(scope);\n let current: H | undefined;\n let disposed = false;\n const close = (): void => {\n const previous = current;\n current = undefined;\n if (previous && 'revert' in previous) previous.revert();\n else previous?.discard();\n };\n if (typeof source === 'function') watch(source, close, { flush: 'sync' });\n onScopeDispose(() => {\n disposed = true;\n close();\n });\n return () => {\n if (disposed) throw new Error('Transaction owner disposed');\n if (!current || ('active' in current ? !current.active : current.closed))\n current = create(toValue(source));\n return current;\n };\n}\n\n/** Lazily open a layer for this component. Unmount reverts an open layer. */\nexport function useOptimistic<H extends { readonly active: boolean; revert(): void }>(\n create: (scope: ReactiveScope) => H,\n scope?: ReactiveScope,\n): () => H {\n return useTransactionHandle(create, scope);\n}\n\n/** Lazily open a draft for this component. Unmount discards an open draft. */\nexport function useDraft<H extends { readonly closed: boolean; discard(): void }>(\n create: (scope: ReactiveScope) => H,\n scope?: ReactiveScope,\n): () => H {\n return useTransactionHandle(create, scope);\n}\n\nexport function useCollectionTopK<T>(\n collection: MaybeRefOrGetter<{ topK(k: number): ReadableSignal<readonly T[]> }>,\n k: MaybeRefOrGetter<number>,\n scope?: ReactiveScope,\n): Readonly<Ref<readonly T[]>> {\n return useSignal(() => toValue(collection).topK(toValue(k)), scope);\n}\n"]}
@@ -0,0 +1,16 @@
1
+ import { type ComputedRef, type MaybeRefOrGetter, type Ref } from 'vue';
2
+ import { type EqualityFn, type ReactiveScope, type ReadableSignal, type WritableSignal } from '@zwire/core';
3
+ export { ScopeKey, ScopeProvider, provideScope, useStoreScope, type ScopeProviderProps, } from './context.js';
4
+ /**
5
+ * Tracks a zwire signal as a Vue ref. The ref reads through to `signal.get()`, so snapshots are
6
+ * never copied or deeply proxied. `signal` may be a ref or getter to switch sources reactively.
7
+ */
8
+ export declare function useSignal<T>(signal: MaybeRefOrGetter<ReadableSignal<T>>, scope?: ReactiveScope): Readonly<Ref<T>>;
9
+ export declare const useAtomValue: typeof useSignal;
10
+ /** Two-way ref over a writable zwire signal, suitable for `v-model`. */
11
+ export declare function useAtom<T>(signal: MaybeRefOrGetter<WritableSignal<T>>, scope?: ReactiveScope): Ref<T>;
12
+ /**
13
+ * Derives a slice of `source`. Dependents re-run only when `equals` reports a changed slice, and
14
+ * an equal slice keeps its previous reference.
15
+ */
16
+ export declare function useSelector<T, S>(source: MaybeRefOrGetter<ReadableSignal<T>>, selector: (value: T) => S, equals?: EqualityFn<S>, scope?: ReactiveScope): ComputedRef<S>;
package/dist/index.js ADDED
@@ -0,0 +1,60 @@
1
+ import { computed, customRef, getCurrentScope, toRaw, toValue, watchEffect, } from 'vue';
2
+ import {} from '@zwire/core';
3
+ import { scopeSource } from './context.js';
4
+ export { ScopeKey, ScopeProvider, provideScope, useStoreScope, } from './context.js';
5
+ /** Resolves a possibly reactive source and strips any Vue proxy wrapped around the signal. */
6
+ function resolve(signal) {
7
+ return toRaw(toValue(signal));
8
+ }
9
+ function bridge(signal, scope, write) {
10
+ const sc = scopeSource(scope);
11
+ return customRef((track, trigger) => {
12
+ if (getCurrentScope()) {
13
+ watchEffect((onCleanup) => onCleanup(toValue(sc).subscribe(resolve(signal), trigger)), {
14
+ flush: 'sync',
15
+ });
16
+ }
17
+ return {
18
+ get() {
19
+ track();
20
+ return resolve(signal).get();
21
+ },
22
+ set(value) {
23
+ write?.(value);
24
+ },
25
+ };
26
+ });
27
+ }
28
+ /**
29
+ * Tracks a zwire signal as a Vue ref. The ref reads through to `signal.get()`, so snapshots are
30
+ * never copied or deeply proxied. `signal` may be a ref or getter to switch sources reactively.
31
+ */
32
+ export function useSignal(signal, scope) {
33
+ return bridge(signal, scope);
34
+ }
35
+ export const useAtomValue = useSignal;
36
+ /** Two-way ref over a writable zwire signal, suitable for `v-model`. */
37
+ export function useAtom(signal, scope) {
38
+ return bridge(signal, scope, (value) => {
39
+ resolve(signal).set(() => value);
40
+ });
41
+ }
42
+ /**
43
+ * Derives a slice of `source`. Dependents re-run only when `equals` reports a changed slice, and
44
+ * an equal slice keeps its previous reference.
45
+ */
46
+ export function useSelector(source, selector, equals, scope) {
47
+ const input = useSignal(source, scope);
48
+ const eq = equals ?? Object.is;
49
+ let has = false;
50
+ let last;
51
+ return computed(() => {
52
+ const next = selector(input.value);
53
+ if (has && eq(last, next))
54
+ return last;
55
+ has = true;
56
+ last = next;
57
+ return next;
58
+ });
59
+ }
60
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EACT,eAAe,EACf,KAAK,EACL,OAAO,EACP,WAAW,GAIZ,MAAM,KAAK,CAAC;AACb,OAAO,EAKN,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,WAAW,EAAE,M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AAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CACzB,MAA2C,EAC3C,QAAyB,EACzB,MAAsB,EACtB,KAAqB;IAErB,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACvC,MAAM,EAAE,GAAG,MAAM,IAAI,MAAM,CAAC,EAAE,CAAC;IAC/B,IAAI,GAAG,GAAG,KAAK,CAAC;IAChB,IAAI,IAAO,CAAC;IACZ,OAAO,QAAQ,CAAI,GAAG,EAAE;QACtB,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,GAAG,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QACvC,GAAG,GAAG,IAAI,CAAC;QACX,IAAI,GAAG,IAAI,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n computed,\n customRef,\n getCurrentScope,\n toRaw,\n toValue,\n watchEffect,\n type ComputedRef,\n type MaybeRefOrGetter,\n type Ref,\n} from 'vue';\nimport {\n type EqualityFn,\n type ReactiveScope,\n type ReadableSignal,\n type WritableSignal,\n} from '@zwire/core';\n\nimport { scopeSource } from './context.ts';\nexport {\n ScopeKey,\n ScopeProvider,\n provideScope,\n useStoreScope,\n type ScopeProviderProps,\n} from './context.ts';\n\n/** Resolves a possibly reactive source and strips any Vue proxy wrapped around the signal. */\nfunction resolve<Sig extends object>(signal: MaybeRefOrGetter<Sig>): Sig {\n return toRaw(toValue(signal));\n}\n\nfunction bridge<T>(\n signal: MaybeRefOrGetter<ReadableSignal<T>>,\n scope: ReactiveScope | undefined,\n write?: (value: T) => void,\n): Ref<T> {\n const sc = scopeSource(scope);\n return customRef<T>((track, trigger) => {\n if (getCurrentScope()) {\n watchEffect((onCleanup) => onCleanup(toValue(sc).subscribe(resolve(signal), trigger)), {\n flush: 'sync',\n });\n }\n return {\n get(): T {\n track();\n return resolve(signal).get();\n },\n set(value: T): void {\n write?.(value);\n },\n };\n });\n}\n\n/**\n * Tracks a zwire signal as a Vue ref. The ref reads through to `signal.get()`, so snapshots are\n * never copied or deeply proxied. `signal` may be a ref or getter to switch sources reactively.\n */\nexport function useSignal<T>(\n signal: MaybeRefOrGetter<ReadableSignal<T>>,\n scope?: ReactiveScope,\n): Readonly<Ref<T>> {\n return bridge(signal, scope);\n}\n\nexport const useAtomValue: typeof useSignal = useSignal;\n\n/** Two-way ref over a writable zwire signal, suitable for `v-model`. */\nexport function useAtom<T>(\n signal: MaybeRefOrGetter<WritableSignal<T>>,\n scope?: ReactiveScope,\n): Ref<T> {\n return bridge(signal, scope, (value) => {\n resolve(signal).set(() => value);\n });\n}\n\n/**\n * Derives a slice of `source`. Dependents re-run only when `equals` reports a changed slice, and\n * an equal slice keeps its previous reference.\n */\nexport function useSelector<T, S>(\n source: MaybeRefOrGetter<ReadableSignal<T>>,\n selector: (value: T) => S,\n equals?: EqualityFn<S>,\n scope?: ReactiveScope,\n): ComputedRef<S> {\n const input = useSignal(source, scope);\n const eq = equals ?? Object.is;\n let has = false;\n let last: S;\n return computed<S>(() => {\n const next = selector(input.value);\n if (has && eq(last, next)) return last;\n has = true;\n last = next;\n return next;\n });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "@zwire/vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Vue 3.5+ read-through customRef and v-model adapter for @zwire/core",
5
+ "keywords": [
6
+ "reactive",
7
+ "signals",
8
+ "state-management",
9
+ "store",
10
+ "typescript",
11
+ "vue",
12
+ "zwire"
13
+ ],
14
+ "homepage": "https://github.com/kjmin-dev/zwire#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/kjmin-dev/zwire/issues"
17
+ },
18
+ "license": "MIT",
19
+ "author": "Kyoungjun Min",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/kjmin-dev/zwire.git",
23
+ "directory": "ts/packages/adapters/vue"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "README.md",
28
+ "LICENSE"
29
+ ],
30
+ "type": "module",
31
+ "sideEffects": false,
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "default": "./dist/index.js"
36
+ },
37
+ "./hooks": {
38
+ "types": "./dist/hooks.d.ts",
39
+ "default": "./dist/hooks.js"
40
+ },
41
+ "./package.json": "./package.json"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "peerDependencies": {
47
+ "@zwire/core": "^0.2.0",
48
+ "vue": ">=3.5.0"
49
+ },
50
+ "engines": {
51
+ "node": ">=20.0.0"
52
+ }
53
+ }