@interaxjs/vue 0.0.0-stage → 0.4.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/README.md CHANGED
@@ -1,3 +1,91 @@
1
- # Temporary Holding Version
1
+ # @interaxjs/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 bindings for the animation engine. Core stays framework-free; this package only connects template refs and players to the existing runtime and DOM handles.
4
+
5
+ ## `useTarget`
6
+
7
+ ```vue
8
+ <script setup lang="ts">
9
+ import { ref } from 'vue';
10
+ import { DOMTargetRegistry } from '@interaxjs/dom';
11
+ import { useTarget } from '@interaxjs/vue';
12
+
13
+ const registry = new DOMTargetRegistry();
14
+ const element = ref<Element | null>(null);
15
+
16
+ useTarget(element, {
17
+ registry,
18
+ targetId: 'hero',
19
+ });
20
+ </script>
21
+
22
+ <template>
23
+ <div ref="element">Hero</div>
24
+ </template>
25
+ ```
26
+
27
+ The handle is created on mount, registered in the registry, and destroyed on unmount. If the element is replaced, the old handle is unregistered and a new one is created.
28
+
29
+ ## `usePlayer`
30
+
31
+ ```vue
32
+ <script setup lang="ts">
33
+ import { createRuntime } from '@interaxjs/runtime';
34
+ import { usePlayer } from '@interaxjs/vue';
35
+
36
+ const runtime = createRuntime({ project, registry, renderer: render });
37
+ const player = usePlayer({
38
+ runtime,
39
+ compositionId: 'intro',
40
+ autoplay: true,
41
+ loop: true,
42
+ });
43
+ </script>
44
+
45
+ <template>
46
+ <button @click="player.toggle()">
47
+ {{ player.playing.value ? 'Pause' : 'Play' }}
48
+ </button>
49
+ <span>{{ player.time.value }}</span>
50
+ </template>
51
+ ```
52
+
53
+ `time`, `playing`, `direction`, `speed`, `loop` and `context` are Vue refs. The player is destroyed on unmount.
54
+
55
+ Pass `context` in options or call `player.setContext()` to change the
56
+ breakpoint/reduced-motion context; playback time is preserved.
57
+
58
+ ```ts
59
+ const player = usePlayer({
60
+ runtime,
61
+ compositionId: 'intro',
62
+ context: { breakpoint: 'mobile' },
63
+ });
64
+ ```
65
+
66
+ ## `Animated`
67
+
68
+ ```vue
69
+ <script setup lang="ts">
70
+ import { DOMTargetRegistry } from '@interaxjs/dom';
71
+ import { Animated } from '@interaxjs/vue';
72
+
73
+ const registry = new DOMTargetRegistry();
74
+ </script>
75
+
76
+ <template>
77
+ <Animated target-id="hero" :registry="registry">
78
+ <Card />
79
+ </Animated>
80
+ </template>
81
+ ```
82
+
83
+ `Animated` renders a wrapper element (`as="div"` by default), registers it as a target, and removes it on unmount. Use `kind="svg"` or `as="span"` when needed.
84
+
85
+ ## Tests
86
+
87
+ The package test runs with `happy-dom` and `@vue/test-utils`:
88
+
89
+ ```bash
90
+ bun run --filter '@interaxjs/vue' test
91
+ ```
@@ -0,0 +1,125 @@
1
+ import { type PropType } from 'vue';
2
+ import type { ID, TargetRegistry } from '@interaxjs/core';
3
+ /**
4
+ * Vue component that registers its root element as an animation target and
5
+ * forwards slots. `as` selects the element tag; SVG elements are detected
6
+ * automatically.
7
+ */
8
+ export declare const Animated: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
9
+ targetId: {
10
+ type: PropType<ID>;
11
+ required: true;
12
+ };
13
+ registry: {
14
+ type: PropType<TargetRegistry>;
15
+ required: true;
16
+ };
17
+ scopePath: {
18
+ type: PropType<readonly string[]>;
19
+ default: () => never[];
20
+ };
21
+ as: {
22
+ type: StringConstructor;
23
+ default: string;
24
+ };
25
+ kind: {
26
+ type: PropType<"auto" | "html" | "svg">;
27
+ default: string;
28
+ };
29
+ restoreOnDestroy: {
30
+ type: BooleanConstructor;
31
+ default: boolean;
32
+ };
33
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
34
+ [key: string]: any;
35
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
36
+ targetId: {
37
+ type: PropType<ID>;
38
+ required: true;
39
+ };
40
+ registry: {
41
+ type: PropType<TargetRegistry>;
42
+ required: true;
43
+ };
44
+ scopePath: {
45
+ type: PropType<readonly string[]>;
46
+ default: () => never[];
47
+ };
48
+ as: {
49
+ type: StringConstructor;
50
+ default: string;
51
+ };
52
+ kind: {
53
+ type: PropType<"auto" | "html" | "svg">;
54
+ default: string;
55
+ };
56
+ restoreOnDestroy: {
57
+ type: BooleanConstructor;
58
+ default: boolean;
59
+ };
60
+ }>> & Readonly<{}>, {
61
+ restoreOnDestroy: boolean;
62
+ scopePath: readonly string[];
63
+ as: string;
64
+ kind: "auto" | "html" | "svg";
65
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
66
+ /** Backwards-compatible alias for `Animated`. */
67
+ export declare const AnimationTarget: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
68
+ targetId: {
69
+ type: PropType<ID>;
70
+ required: true;
71
+ };
72
+ registry: {
73
+ type: PropType<TargetRegistry>;
74
+ required: true;
75
+ };
76
+ scopePath: {
77
+ type: PropType<readonly string[]>;
78
+ default: () => never[];
79
+ };
80
+ as: {
81
+ type: StringConstructor;
82
+ default: string;
83
+ };
84
+ kind: {
85
+ type: PropType<"auto" | "html" | "svg">;
86
+ default: string;
87
+ };
88
+ restoreOnDestroy: {
89
+ type: BooleanConstructor;
90
+ default: boolean;
91
+ };
92
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
93
+ [key: string]: any;
94
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
95
+ targetId: {
96
+ type: PropType<ID>;
97
+ required: true;
98
+ };
99
+ registry: {
100
+ type: PropType<TargetRegistry>;
101
+ required: true;
102
+ };
103
+ scopePath: {
104
+ type: PropType<readonly string[]>;
105
+ default: () => never[];
106
+ };
107
+ as: {
108
+ type: StringConstructor;
109
+ default: string;
110
+ };
111
+ kind: {
112
+ type: PropType<"auto" | "html" | "svg">;
113
+ default: string;
114
+ };
115
+ restoreOnDestroy: {
116
+ type: BooleanConstructor;
117
+ default: boolean;
118
+ };
119
+ }>> & Readonly<{}>, {
120
+ restoreOnDestroy: boolean;
121
+ scopePath: readonly string[];
122
+ as: string;
123
+ kind: "auto" | "html" | "svg";
124
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
125
+ //# sourceMappingURL=animated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animated.d.ts","sourceRoot":"","sources":["../src/animated.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC7D,OAAO,KAAK,EAAE,EAAE,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAG1D;;;;GAIG;AACH,eAAO,MAAM,QAAQ;;cAGS,QAAQ,CAAC,EAAE,CAAC;;;;cACZ,QAAQ,CAAC,cAAc,CAAC;;;;cAEpC,QAAQ,CAAC,SAAS,MAAM,EAAE,CAAC;;;;;;;;cAK1B,QAAQ,CAAC,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;;;;;;;;;;;cARtB,QAAQ,CAAC,EAAE,CAAC;;;;cACZ,QAAQ,CAAC,cAAc,CAAC;;;;cAEpC,QAAQ,CAAC,SAAS,MAAM,EAAE,CAAC;;;;;;;;cAK1B,QAAQ,CAAC,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;;;;;;;;;;;;4EAgBlD,CAAC;AAEH,iDAAiD;AACjD,eAAO,MAAM,eAAe;;cA3BE,QAAQ,CAAC,EAAE,CAAC;;;;cACZ,QAAQ,CAAC,cAAc,CAAC;;;;cAEpC,QAAQ,CAAC,SAAS,MAAM,EAAE,CAAC;;;;;;;;cAK1B,QAAQ,CAAC,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;;;;;;;;;;;cARtB,QAAQ,CAAC,EAAE,CAAC;;;;cACZ,QAAQ,CAAC,cAAc,CAAC;;;;cAEpC,QAAQ,CAAC,SAAS,MAAM,EAAE,CAAC;;;;;;;;cAK1B,QAAQ,CAAC,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;;;;;;;;;;;;4EAmBb,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { defineComponent, h, ref } from 'vue';
2
+ import { useTarget } from "./use-target.js";
3
+ /**
4
+ * Vue component that registers its root element as an animation target and
5
+ * forwards slots. `as` selects the element tag; SVG elements are detected
6
+ * automatically.
7
+ */
8
+ export const Animated = defineComponent({
9
+ name: 'Animated',
10
+ props: {
11
+ targetId: { type: String, required: true },
12
+ registry: { type: Object, required: true },
13
+ scopePath: {
14
+ type: Array,
15
+ default: () => [],
16
+ },
17
+ as: { type: String, default: 'div' },
18
+ kind: {
19
+ type: String,
20
+ default: 'auto',
21
+ },
22
+ restoreOnDestroy: { type: Boolean, default: true },
23
+ },
24
+ setup(props, { slots }) {
25
+ const element = ref(null);
26
+ useTarget(element, {
27
+ registry: props.registry,
28
+ targetId: props.targetId,
29
+ scopePath: props.scopePath,
30
+ kind: props.kind,
31
+ restoreOnDestroy: props.restoreOnDestroy,
32
+ });
33
+ return () => h(props.as, { ref: element }, slots.default?.());
34
+ },
35
+ });
36
+ /** Backwards-compatible alias for `Animated`. */
37
+ export const AnimationTarget = Animated;
38
+ //# sourceMappingURL=animated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animated.js","sourceRoot":"","sources":["../src/animated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,GAAG,EAAiB,MAAM,KAAK,CAAC;AAE7D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,eAAe,CAAC;IACvC,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE;QACN,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAsB,EAAE,QAAQ,EAAE,IAAI,EAAE;QAC1D,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAkC,EAAE,QAAQ,EAAE,IAAI,EAAE;QACtE,SAAS,EAAE;YACV,IAAI,EAAE,KAAoC;YAC1C,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;SACjB;QACD,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE;QACpC,IAAI,EAAE;YACL,IAAI,EAAE,MAA2C;YACjD,OAAO,EAAE,MAAM;SACf;QACD,gBAAgB,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE;KAClD;IACD,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE;QACrB,MAAM,OAAO,GAAG,GAAG,CAAiB,IAAI,CAAC,CAAC;QAC1C,SAAS,CAAC,OAAO,EAAE;YAClB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;SACxC,CAAC,CAAC;QACH,OAAO,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC/D,CAAC;CACD,CAAC,CAAC;AAEH,iDAAiD;AACjD,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './use-target.js';
2
+ export * from './use-player.js';
3
+ export * from './animated.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./use-target.js";
2
+ export * from "./use-player.js";
3
+ export * from "./animated.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { type Ref } from 'vue';
2
+ import type { EvaluationContext, ID, Time } from '@interaxjs/core';
3
+ import type { AnimationPlayer, AnimationRuntime } from '@interaxjs/runtime';
4
+ /** `usePlayer` options. */
5
+ export interface UsePlayerOptions {
6
+ runtime: AnimationRuntime;
7
+ compositionId: ID;
8
+ autoplay?: boolean;
9
+ loop?: boolean | {
10
+ start?: Time;
11
+ end?: Time;
12
+ };
13
+ speed?: number;
14
+ direction?: 1 | -1;
15
+ context?: EvaluationContext;
16
+ onEnd?: () => void;
17
+ }
18
+ /** Reactive player state and controls returned by `usePlayer`. */
19
+ export interface UsePlayerReturn {
20
+ player: AnimationPlayer;
21
+ time: Ref<Time>;
22
+ playing: Ref<boolean>;
23
+ direction: Ref<1 | -1>;
24
+ speed: Ref<number>;
25
+ loop: Ref<{
26
+ start: Time;
27
+ end: Time;
28
+ } | null>;
29
+ context: Ref<EvaluationContext | undefined>;
30
+ play: () => void;
31
+ pause: () => void;
32
+ toggle: () => void;
33
+ seek: (time: Time) => void;
34
+ stop: () => void;
35
+ reverse: () => void;
36
+ setSpeed: (speed: number) => void;
37
+ setLoop: (range?: {
38
+ start?: Time;
39
+ end?: Time;
40
+ }) => void;
41
+ clearLoop: () => void;
42
+ setContext: (context?: EvaluationContext) => void;
43
+ refresh: () => void;
44
+ }
45
+ /**
46
+ * Creates a player scoped to the current Vue component and mirrors its state
47
+ * into refs. The player is destroyed on unmount; call `refresh()` after
48
+ * project edits so the duration/context stay current.
49
+ */
50
+ export declare function usePlayer(options: UsePlayerOptions): UsePlayerReturn;
51
+ //# sourceMappingURL=use-player.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-player.d.ts","sourceRoot":"","sources":["../src/use-player.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAChE,OAAO,KAAK,EAAE,iBAAiB,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAmB,MAAM,oBAAoB,CAAC;AAE7F,2BAA2B;AAC3B,MAAM,WAAW,gBAAgB;IAChC,OAAO,EAAE,gBAAgB,CAAC;IAC1B,aAAa,EAAE,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,GAAG;QAAE,KAAK,CAAC,EAAE,IAAI,CAAC;QAAC,GAAG,CAAC,EAAE,IAAI,CAAA;KAAE,CAAC;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACnB,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,kEAAkE;AAClE,MAAM,WAAW,eAAe;IAC/B,MAAM,EAAE,eAAe,CAAC;IACxB,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAChB,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACtB,SAAS,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvB,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACnB,IAAI,EAAE,GAAG,CAAC;QAAE,KAAK,EAAE,IAAI,CAAC;QAAC,GAAG,EAAE,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;IAC7C,OAAO,EAAE,GAAG,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAAC;IAC5C,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAC3B,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,IAAI,CAAC;QAAC,GAAG,CAAC,EAAE,IAAI,CAAA;KAAE,KAAK,IAAI,CAAC;IACxD,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAClD,OAAO,EAAE,MAAM,IAAI,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CA2GpE"}
@@ -0,0 +1,115 @@
1
+ import { onBeforeUnmount, onMounted, ref } from 'vue';
2
+ /**
3
+ * Creates a player scoped to the current Vue component and mirrors its state
4
+ * into refs. The player is destroyed on unmount; call `refresh()` after
5
+ * project edits so the duration/context stay current.
6
+ */
7
+ export function usePlayer(options) {
8
+ const player = options.runtime.createPlayer(options.compositionId);
9
+ const time = ref(player.time);
10
+ const playing = ref(player.playing);
11
+ const direction = ref(player.direction);
12
+ const speed = ref(player.speed);
13
+ const loop = ref(player.loop);
14
+ const context = ref(player.context);
15
+ const sync = () => {
16
+ time.value = player.time;
17
+ playing.value = player.playing;
18
+ direction.value = player.direction;
19
+ speed.value = player.speed;
20
+ loop.value = player.loop;
21
+ context.value = player.context;
22
+ };
23
+ const events = [
24
+ 'play',
25
+ 'pause',
26
+ 'seek',
27
+ 'time',
28
+ 'loop',
29
+ 'reverse',
30
+ 'speed',
31
+ ];
32
+ const offs = events.map((type) => player.on(type, sync));
33
+ offs.push(player.on('end', () => {
34
+ sync();
35
+ options.onEnd?.();
36
+ }));
37
+ if (options.loop !== undefined) {
38
+ if (options.loop === true)
39
+ player.setLoop();
40
+ else if (options.loop === false)
41
+ player.clearLoop();
42
+ else
43
+ player.setLoop(options.loop);
44
+ }
45
+ if (options.speed !== undefined)
46
+ player.setSpeed(options.speed);
47
+ if (options.direction === -1)
48
+ player.reverse();
49
+ if (options.context !== undefined)
50
+ player.setContext(options.context);
51
+ sync();
52
+ onMounted(() => {
53
+ if (options.autoplay)
54
+ player.play();
55
+ });
56
+ onBeforeUnmount(() => {
57
+ for (const off of offs)
58
+ off();
59
+ player.destroy();
60
+ });
61
+ return {
62
+ player,
63
+ time,
64
+ playing,
65
+ direction,
66
+ speed,
67
+ loop,
68
+ context,
69
+ play: () => {
70
+ player.play();
71
+ sync();
72
+ },
73
+ pause: () => {
74
+ player.pause();
75
+ sync();
76
+ },
77
+ toggle: () => {
78
+ player.toggle();
79
+ sync();
80
+ },
81
+ seek: (value) => {
82
+ player.seek(value);
83
+ sync();
84
+ },
85
+ stop: () => {
86
+ player.stop();
87
+ sync();
88
+ },
89
+ reverse: () => {
90
+ player.reverse();
91
+ sync();
92
+ },
93
+ setSpeed: (value) => {
94
+ player.setSpeed(value);
95
+ sync();
96
+ },
97
+ setLoop: (range) => {
98
+ player.setLoop(range);
99
+ sync();
100
+ },
101
+ clearLoop: () => {
102
+ player.clearLoop();
103
+ sync();
104
+ },
105
+ setContext: (value) => {
106
+ player.setContext(value);
107
+ sync();
108
+ },
109
+ refresh: () => {
110
+ player.refresh();
111
+ sync();
112
+ },
113
+ };
114
+ }
115
+ //# sourceMappingURL=use-player.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-player.js","sourceRoot":"","sources":["../src/use-player.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,GAAG,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MAAM,CAAC,KAAK,EAAE,CAAC;YACf,IAAI,EAAE,CAAC;QACR,CAAC;QACD,MAAM,EAAE,GAAG,EAAE;YACZ,MAAM,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,EAAE,CAAC;QACR,CAAC;QACD,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;YACf,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,IAAI,EAAE,CAAC;QACR,CAAC;QACD,IAAI,EAAE,GAAG,EAAE;YACV,MAAM,CAAC,IAAI,EAAE,CAAC;YACd,IAAI,EAAE,CAAC;QACR,CAAC;QACD,OAAO,EAAE,GAAG,EAAE;YACb,MAAM,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,EAAE,CAAC;QACR,CAAC;QACD,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;YACnB,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACvB,IAAI,EAAE,CAAC;QACR,CAAC;QACD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YAClB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACtB,IAAI,EAAE,CAAC;QACR,CAAC;QACD,SAAS,EAAE,GAAG,EAAE;YACf,MAAM,CAAC,SAAS,EAAE,CAAC;YACnB,IAAI,EAAE,CAAC;QACR,CAAC;QACD,UAAU,EAAE,CAAC,KAAK,EAAE,EAAE;YACrB,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YACzB,IAAI,EAAE,CAAC;QACR,CAAC;QACD,OAAO,EAAE,GAAG,EAAE;YACb,MAAM,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,EAAE,CAAC;QACR,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type Ref } from 'vue';
2
+ import type { ID, TargetHandle, TargetRegistry } from '@interaxjs/core';
3
+ /** `useTarget` options: registry, target id, scope and handle behavior. */
4
+ export interface UseTargetOptions {
5
+ registry: TargetRegistry;
6
+ targetId: ID;
7
+ scopePath?: readonly string[];
8
+ kind?: 'auto' | 'html' | 'svg';
9
+ restoreOnDestroy?: boolean;
10
+ sceneRoot?: Element | null;
11
+ }
12
+ /** Current handle and a manual unregister function. */
13
+ export interface UseTargetReturn {
14
+ handle: Ref<TargetHandle | null>;
15
+ unregister: () => void;
16
+ }
17
+ /**
18
+ * Registers an element with a target registry and returns the handle plus an
19
+ * unregister function. The handle is destroyed on unmount; `restoreOnDestroy`
20
+ * controls whether written styles/attributes are rolled back.
21
+ */
22
+ export declare function useTarget(element: Ref<Element | null | undefined>, options: UseTargetOptions): UseTargetReturn;
23
+ //# sourceMappingURL=use-target.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-target.d.ts","sourceRoot":"","sources":["../src/use-target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAC9E,OAAO,KAAK,EAAE,EAAE,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGxE,2EAA2E;AAC3E,MAAM,WAAW,gBAAgB;IAChC,QAAQ,EAAE,cAAc,CAAC;IACzB,QAAQ,EAAE,EAAE,CAAC;IACb,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC3B;AAED,uDAAuD;AACvD,MAAM,WAAW,eAAe;IAC/B,MAAM,EAAE,GAAG,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IACjC,UAAU,EAAE,MAAM,IAAI,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACxB,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,EACxC,OAAO,EAAE,gBAAgB,GACvB,eAAe,CA6DjB"}
@@ -0,0 +1,57 @@
1
+ import { onBeforeUnmount, onMounted, shallowRef, watch } from 'vue';
2
+ import { DOMTargetHandle, SVGTargetHandle } from '@interaxjs/dom';
3
+ /**
4
+ * Registers an element with a target registry and returns the handle plus an
5
+ * unregister function. The handle is destroyed on unmount; `restoreOnDestroy`
6
+ * controls whether written styles/attributes are rolled back.
7
+ */
8
+ export function useTarget(element, options) {
9
+ const handle = shallowRef(null);
10
+ let unregister;
11
+ let mounted = false;
12
+ let stopWatch;
13
+ const detach = () => {
14
+ unregister?.();
15
+ unregister = undefined;
16
+ handle.value?.destroy();
17
+ handle.value = null;
18
+ };
19
+ const attach = () => {
20
+ const current = element.value;
21
+ if (current === null || current === undefined)
22
+ return;
23
+ const isSvg = options.kind === 'svg' ||
24
+ (options.kind !== 'html' &&
25
+ typeof SVGElement !== 'undefined' &&
26
+ current instanceof SVGElement);
27
+ const target = isSvg
28
+ ? new SVGTargetHandle(current, options.targetId, options.scopePath ?? [], {
29
+ restoreOnDestroy: options.restoreOnDestroy,
30
+ sceneRoot: options.sceneRoot,
31
+ })
32
+ : new DOMTargetHandle(current, options.targetId, options.scopePath ?? [], {
33
+ restoreOnDestroy: options.restoreOnDestroy,
34
+ sceneRoot: options.sceneRoot,
35
+ });
36
+ handle.value = target;
37
+ unregister = options.registry.register(target);
38
+ };
39
+ onMounted(() => {
40
+ mounted = true;
41
+ attach();
42
+ stopWatch = watch(element, () => {
43
+ if (!mounted)
44
+ return;
45
+ detach();
46
+ attach();
47
+ }, { flush: 'post' });
48
+ });
49
+ onBeforeUnmount(() => {
50
+ mounted = false;
51
+ stopWatch?.();
52
+ stopWatch = undefined;
53
+ detach();
54
+ });
55
+ return { handle, unregister: detach };
56
+ }
57
+ //# sourceMappingURL=use-target.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-target.js","sourceRoot":"","sources":["../src/use-target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS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,SAAS,EAAE,OAAO,CAAC,SAAS;aAC5B,CAAC,CAAC;QACL,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC;QACtB,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACd,OAAO,GAAG,IAAI,CAAC;QACf,MAAM,EAAE,CAAC;QACT,SAAS,GAAG,KAAK,CAChB,OAAO,EACP,GAAG,EAAE;YACJ,IAAI,CAAC,OAAO;gBAAE,OAAO;YACrB,MAAM,EAAE,CAAC;YACT,MAAM,EAAE,CAAC;QACV,CAAC,EACD,EAAE,KAAK,EAAE,MAAM,EAAE,CACjB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,eAAe,CAAC,GAAG,EAAE;QACpB,OAAO,GAAG,KAAK,CAAC;QAChB,SAAS,EAAE,EAAE,CAAC;QACd,SAAS,GAAG,SAAS,CAAC;QACtB,MAAM,EAAE,CAAC;IACV,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;AACvC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@interaxjs/vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.4.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "import": "./dist/index.js",
9
+ "default": "./dist/index.js"
10
+ }
11
+ },
12
+ "scripts": {
13
+ "typecheck": "tsc --noEmit -p tsconfig.json",
14
+ "test": "bun test --preload ./test/setup.ts",
15
+ "build": "tsc -p tsconfig.build.json"
16
+ },
17
+ "dependencies": {
18
+ "@interaxjs/core": "0.4.0",
19
+ "@interaxjs/dom": "0.4.0",
20
+ "@interaxjs/runtime": "0.4.0"
21
+ },
22
+ "peerDependencies": {
23
+ "interax": "0.4.0",
24
+ "vue": "^3.5.0"
25
+ },
26
+ "devDependencies": {
27
+ "@interaxjs/builder": "0.4.0",
28
+ "@happy-dom/global-registrator": "^20.0.8",
29
+ "@vue/test-utils": "^2.4.6",
30
+ "happy-dom": "^20.0.8",
31
+ "vue": "^3.5.45"
32
+ },
33
+ "sideEffects": false,
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "publishConfig": {
38
+ "access": "public"
39
+ }
40
+ }