nanime 0.0.7 → 0.0.10

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/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.13.5 <5.0.0"
6
6
  },
7
- "version": "0.0.7",
7
+ "version": "0.0.10",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -1,21 +1,32 @@
1
1
  import { createAnimatable } from "animejs/animatable";
2
- import { tryOnScopeDispose, useMounted } from "@vueuse/core";
3
- import { shallowReactive, toValue, watchEffect } from "vue";
2
+ import { toReactive, tryOnScopeDispose, useMounted } from "@vueuse/core";
3
+ import { shallowRef, toValue, watchEffect, nextTick } from "vue";
4
4
  import { normalizeAnimeTarget } from "../utils/normalize-targets.js";
5
+ import { AnimationComponentFlags, getAnimationComponentFlag } from "../utils/normalizers/instance-management.js";
5
6
  export function useAnimatable(target, options) {
7
+ const flag = getAnimationComponentFlag();
8
+ const animatable = shallowRef(createAnimatable({}, {}));
6
9
  const mounted = useMounted();
7
- const animatable = shallowReactive(createAnimatable({}, {}));
8
- let oldTarget;
9
- watchEffect(() => {
10
- if (!mounted.value) return;
11
- const targets = normalizeAnimeTarget(target);
12
- if (oldTarget === targets) return;
13
- oldTarget = targets;
14
- const newAnimatable = createAnimatable(targets, toValue(options) || {});
15
- Object.assign(animatable, newAnimatable);
16
- });
17
- tryOnScopeDispose(() => {
18
- animatable.revert();
19
- });
20
- return animatable;
10
+ if (flag === AnimationComponentFlags.Watchable) {
11
+ let oldTarget;
12
+ watchEffect(() => {
13
+ if (!mounted.value) return;
14
+ const targets = normalizeAnimeTarget(target);
15
+ if (oldTarget === targets) return;
16
+ oldTarget = targets;
17
+ const newAnimatable = createAnimatable(targets, toValue(options) || {});
18
+ animatable.value = newAnimatable;
19
+ });
20
+ tryOnScopeDispose(() => {
21
+ animatable.value.revert();
22
+ });
23
+ } else {
24
+ nextTick(() => {
25
+ const targets = normalizeAnimeTarget(target);
26
+ if (!targets) return;
27
+ const newAnimatable = createAnimatable(targets, toValue(options) || {});
28
+ animatable.value = newAnimatable;
29
+ });
30
+ }
31
+ return toReactive(animatable);
21
32
  }
@@ -2,4 +2,4 @@ import { type MaybeRefOrGetter } from 'vue';
2
2
  import { normalizeAnimeTarget } from '../utils/normalize-targets.js';
3
3
  import type { AnimationParams } from 'animejs';
4
4
  import { type JSAnimation } from 'animejs/animation';
5
- export declare function useAnimate(target: Parameters<typeof normalizeAnimeTarget>[0], options?: MaybeRefOrGetter<AnimationParams>): JSAnimation;
5
+ export declare function useAnimate(target: Parameters<typeof normalizeAnimeTarget>[0], parameters?: MaybeRefOrGetter<AnimationParams>): JSAnimation;
@@ -1,22 +1,33 @@
1
1
  import { toReactive, tryOnScopeDispose, useMounted } from "@vueuse/core";
2
- import { shallowRef, toValue, watchEffect } from "vue";
2
+ import { shallowRef, toValue, watchEffect, nextTick } from "vue";
3
3
  import { normalizeAnimeTarget } from "../utils/normalize-targets.js";
4
4
  import { animate } from "animejs/animation";
5
- export function useAnimate(target, options) {
6
- const mounted = useMounted();
5
+ import { AnimationComponentFlags, getAnimationComponentFlag } from "../utils/normalizers/instance-management.js";
6
+ export function useAnimate(target, parameters) {
7
+ const flag = getAnimationComponentFlag();
7
8
  const animation = shallowRef(animate({}, {}));
8
- let oldTarget;
9
- watchEffect(() => {
10
- if (!mounted.value) return;
11
- const targets = normalizeAnimeTarget(target);
12
- if (oldTarget === targets) return;
13
- if (animation.value) animation.value.revert();
14
- oldTarget = targets;
15
- const newAnimation = animate(targets, toValue(options) || {});
16
- animation.value = newAnimation;
17
- });
18
- tryOnScopeDispose(() => {
19
- animation.value?.revert();
20
- });
9
+ const mounted = useMounted();
10
+ if (flag === AnimationComponentFlags.Watchable) {
11
+ let oldTarget;
12
+ watchEffect(() => {
13
+ if (!mounted.value) return;
14
+ const targets = normalizeAnimeTarget(target);
15
+ if (oldTarget === targets) return;
16
+ if (animation.value) animation.value.revert();
17
+ oldTarget = targets;
18
+ const newAnimation = animate(targets, toValue(parameters) || {});
19
+ animation.value = newAnimation;
20
+ });
21
+ tryOnScopeDispose(() => {
22
+ animation.value?.revert();
23
+ });
24
+ } else {
25
+ nextTick(() => {
26
+ const targets = normalizeAnimeTarget(target);
27
+ if (!targets) return;
28
+ const newAnimation = animate(targets, toValue(parameters) || {});
29
+ animation.value = newAnimation;
30
+ });
31
+ }
21
32
  return toReactive(animation);
22
33
  }
@@ -56,7 +56,6 @@ export function useDraggable(target, options) {
56
56
  x: resolveAxis(options?.x),
57
57
  y: resolveAxis(options?.y)
58
58
  });
59
- console.log("initializing");
60
59
  dragController.value = dragEngine;
61
60
  },
62
61
  {
@@ -0,0 +1,5 @@
1
+ import { type MaybeRefOrGetter } from 'vue';
2
+ import { normalizeAnimeTarget } from '../utils/normalize-targets.js';
3
+ import type { AnimationParams, ScrambleTextParams } from 'animejs';
4
+ import { type JSAnimation } from 'animejs/animation';
5
+ export declare function useScrambleText(target: Parameters<typeof normalizeAnimeTarget>[0], animationOptions?: MaybeRefOrGetter<AnimationParams>, scrambleOptions?: MaybeRefOrGetter<ScrambleTextParams>): JSAnimation;
@@ -0,0 +1,38 @@
1
+ import { toReactive, tryOnScopeDispose, useMounted } from "@vueuse/core";
2
+ import { shallowRef, toValue, watchEffect, nextTick } from "vue";
3
+ import { normalizeAnimeTarget } from "../utils/normalize-targets.js";
4
+ import { animate } from "animejs/animation";
5
+ import { scrambleText } from "animejs/text";
6
+ import { AnimationComponentFlags, getAnimationComponentFlag } from "../utils/normalizers/instance-management.js";
7
+ export function useScrambleText(target, animationOptions, scrambleOptions) {
8
+ const flag = getAnimationComponentFlag();
9
+ const animation = shallowRef(animate({}, {}));
10
+ const mounted = useMounted();
11
+ function buildParams() {
12
+ const anim = toValue(animationOptions) || {};
13
+ const scramble = toValue(scrambleOptions) || {};
14
+ return {
15
+ ...anim,
16
+ innerHTML: scrambleText(scramble)
17
+ };
18
+ }
19
+ if (flag === AnimationComponentFlags.Watchable) {
20
+ watchEffect(() => {
21
+ if (!mounted.value) return;
22
+ const targets = normalizeAnimeTarget(target);
23
+ if (!targets) return;
24
+ if (animation.value) animation.value.revert();
25
+ animation.value = animate(targets, buildParams());
26
+ });
27
+ tryOnScopeDispose(() => {
28
+ animation.value?.revert();
29
+ });
30
+ } else {
31
+ nextTick(() => {
32
+ const targets = normalizeAnimeTarget(target);
33
+ if (!targets) return;
34
+ animation.value = animate(targets, buildParams());
35
+ });
36
+ }
37
+ return toReactive(animation);
38
+ }
@@ -1,41 +1,12 @@
1
- import { type MaybeRef, type MaybeRefOrGetter } from 'vue';
1
+ import { type ComputedRef, type MaybeRef, type MaybeRefOrGetter, type Ref } from 'vue';
2
2
  import { splitText, type TextSplitter } from 'animejs/text';
3
3
  import { normalizeSplitTextTarget } from '../utils/normalize-targets.js';
4
- export declare function useSplitText(target: MaybeRef<Parameters<typeof normalizeSplitTextTarget>[0]>, parameters?: MaybeRefOrGetter<Parameters<typeof splitText>[1]>): {
5
- lines: import("vue").ShallowRef<HTMLElement[], HTMLElement[]>;
6
- words: import("vue").ShallowRef<HTMLElement[], HTMLElement[]>;
7
- chars: import("vue").ShallowRef<HTMLElement[], HTMLElement[]>;
8
- properties: import("vue").ComputedRef<import("../utils/extract-props.js").NonFunctionProperties<{
9
- debug: boolean;
10
- includeSpaces: boolean;
11
- accessible: boolean;
12
- linesOnly: boolean;
13
- lineTemplate: string | false | import("animejs").SplitFunctionValue;
14
- wordTemplate: string | false | import("animejs").SplitFunctionValue;
15
- charTemplate: string | false | import("animejs").SplitFunctionValue;
16
- $target: HTMLElement;
17
- html: string;
18
- lines: any[];
19
- words: any[];
20
- chars: any[];
21
- effects: any[];
22
- effectsCleanups: any[];
23
- cache: string;
24
- ready: boolean;
25
- width: number;
26
- resizeTimeout: NodeJS.Timeout;
27
- resizeObserver: {
28
- disconnect: () => void;
29
- observe: (target: Element, options?: ResizeObserverOptions) => void;
30
- unobserve: (target: Element) => void;
31
- };
32
- addEffect: (effect: (...args: any[]) => import("animejs").Tickable | (() => void)) => void | TextSplitter;
33
- revert: () => TextSplitter;
34
- splitNode: (node: Node) => void;
35
- split: (clearCache?: boolean) => TextSplitter;
36
- refresh: () => void;
37
- }> | undefined>;
38
- revert: () => TextSplitter | undefined;
39
- split: () => TextSplitter | undefined;
40
- refresh: () => void | undefined;
4
+ import { type NonFunctionProperties, type OnlyFunctionProperties } from '../utils/extract-props.js';
5
+ type SplitText = {
6
+ [x in 'lines' | 'words' | 'chars']: Ref<HTMLElement[]>;
7
+ } & {
8
+ properties: ComputedRef<NonFunctionProperties<TextSplitter> | undefined>;
9
+ methods: ComputedRef<OnlyFunctionProperties<TextSplitter> | undefined>;
41
10
  };
11
+ export declare function useSplitText(target: MaybeRef<Parameters<typeof normalizeSplitTextTarget>[0]>, parameters?: MaybeRefOrGetter<Parameters<typeof splitText>[1]>): SplitText;
12
+ export {};
@@ -1,7 +1,7 @@
1
1
  import { computed, nextTick, ref, shallowRef, toValue, watchEffect } from "vue";
2
2
  import { splitText } from "animejs/text";
3
3
  import { normalizeSplitTextTarget } from "../utils/normalize-targets.js";
4
- import { extractNonFunctionProperties } from "../utils/extract-props.js";
4
+ import { extractNonFunctionProperties, extractOnlyFunctionProperties } from "../utils/extract-props.js";
5
5
  import { tryOnScopeDispose, useMounted } from "@vueuse/core";
6
6
  export function useSplitText(target, parameters) {
7
7
  const mounted = useMounted();
@@ -41,8 +41,6 @@ export function useSplitText(target, parameters) {
41
41
  words,
42
42
  chars,
43
43
  properties: computed(() => splitter.value ? extractNonFunctionProperties(splitter.value) : void 0),
44
- revert: () => splitter.value?.revert(),
45
- split: () => splitter.value?.split(),
46
- refresh: () => splitter.value?.refresh()
44
+ methods: computed(() => splitter.value ? extractOnlyFunctionProperties(splitter.value) : void 0)
47
45
  };
48
46
  }
@@ -2,4 +2,4 @@ import { type MaybeRefOrGetter } from 'vue';
2
2
  import type { WAAPIAnimationParams } from 'animejs';
3
3
  import { normalizeWaapiAnimeTarget } from '../utils/normalize-targets.js';
4
4
  import { type WAAPIAnimation } from 'animejs/waapi';
5
- export declare function useWaapiAnimate(target: Parameters<typeof normalizeWaapiAnimeTarget>[0], options?: MaybeRefOrGetter<WAAPIAnimationParams>): WAAPIAnimation;
5
+ export declare function useWaapiAnimate(target: Parameters<typeof normalizeWaapiAnimeTarget>[0], parameters?: MaybeRefOrGetter<WAAPIAnimationParams>): WAAPIAnimation;
@@ -1,19 +1,31 @@
1
1
  import { toReactive, tryOnScopeDispose, useMounted } from "@vueuse/core";
2
- import { shallowRef, toValue, watchEffect } from "vue";
2
+ import { shallowRef, toValue, watchEffect, nextTick } from "vue";
3
3
  import { normalizeWaapiAnimeTarget } from "../utils/normalize-targets.js";
4
4
  import { waapi } from "animejs/waapi";
5
- export function useWaapiAnimate(target, options) {
6
- const mounted = useMounted();
5
+ import { AnimationComponentFlags, getAnimationComponentFlag } from "../utils/normalizers/instance-management.js";
6
+ export function useWaapiAnimate(target, parameters) {
7
+ const flag = getAnimationComponentFlag();
7
8
  const animation = shallowRef(waapi.animate([], {}));
8
- watchEffect(() => {
9
- const targets = normalizeWaapiAnimeTarget(target);
10
- if (!mounted.value || !targets) return;
11
- if (animation.value) animation.value.revert();
12
- const newAnimation = waapi.animate(targets, toValue(options) || {});
13
- animation.value = newAnimation;
14
- });
15
- tryOnScopeDispose(() => {
16
- animation.value?.revert();
17
- });
9
+ const mounted = useMounted();
10
+ if (flag === AnimationComponentFlags.Watchable) {
11
+ watchEffect(() => {
12
+ const targets = normalizeWaapiAnimeTarget(target);
13
+ if (!mounted.value || !targets) return;
14
+ if (animation.value) animation.value.revert();
15
+ const newAnimation = waapi.animate(targets, toValue(parameters) || {});
16
+ animation.value = newAnimation;
17
+ });
18
+ tryOnScopeDispose(() => {
19
+ animation.value?.revert();
20
+ });
21
+ } else {
22
+ nextTick(() => {
23
+ const targets = normalizeWaapiAnimeTarget(target);
24
+ if (!targets) return;
25
+ if (animation.value) animation.value.revert();
26
+ const newAnimation = waapi.animate(targets, toValue(parameters) || {});
27
+ animation.value = newAnimation;
28
+ });
29
+ }
18
30
  return toReactive(animation);
19
31
  }
@@ -3,4 +3,9 @@ type NonFunctionKeys<T> = {
3
3
  }[keyof T];
4
4
  export type NonFunctionProperties<T> = Pick<T, NonFunctionKeys<T>>;
5
5
  export declare function extractNonFunctionProperties<T extends object>(obj: T): NonFunctionProperties<T>;
6
+ type FunctionKeys<T> = {
7
+ [K in keyof T]: T[K] extends Function ? K : never;
8
+ }[keyof T];
9
+ export type OnlyFunctionProperties<T> = Pick<T, FunctionKeys<T>>;
10
+ export declare function extractOnlyFunctionProperties<T extends object>(obj: T): OnlyFunctionProperties<T>;
6
11
  export {};
@@ -11,3 +11,16 @@ export function extractNonFunctionProperties(obj) {
11
11
  }
12
12
  return result;
13
13
  }
14
+ export function extractOnlyFunctionProperties(obj) {
15
+ if (!obj || typeof obj !== "object") return {};
16
+ const result = {};
17
+ for (const key in obj) {
18
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
19
+ const value = obj[key];
20
+ if (typeof value === "function") {
21
+ result[key] = value;
22
+ }
23
+ }
24
+ }
25
+ return result;
26
+ }
@@ -0,0 +1,5 @@
1
+ export declare enum AnimationComponentFlags {
2
+ Watchable = 0,
3
+ Instant = 1
4
+ }
5
+ export declare function getAnimationComponentFlag(): AnimationComponentFlags;
@@ -0,0 +1,10 @@
1
+ import { getCurrentInstance } from "vue";
2
+ export var AnimationComponentFlags = /* @__PURE__ */ ((AnimationComponentFlags2) => {
3
+ AnimationComponentFlags2[AnimationComponentFlags2["Watchable"] = 0] = "Watchable";
4
+ AnimationComponentFlags2[AnimationComponentFlags2["Instant"] = 1] = "Instant";
5
+ return AnimationComponentFlags2;
6
+ })(AnimationComponentFlags || {});
7
+ export function getAnimationComponentFlag() {
8
+ return getCurrentInstance() ? 0 /* Watchable */ : 1 /* Instant */;
9
+ }
10
+ ;
@@ -1 +1 @@
1
- export type { AnimationParams, TargetsParam, AutoLayoutParams, EasingParam, LayoutAnimationParams, WAAPIEasingParam, Draggable, DraggableAxisParam, DraggableParams, WAAPIAnimationParams, DOMTargetsParam, DOMTargetSelector, AnimatableObject, AnimatableParams, } from 'animejs';
1
+ export type { AnimationParams, TargetsParam, EasingParam, WAAPIEasingParam, Draggable, DraggableAxisParam, DraggableParams, WAAPIAnimationParams, DOMTargetsParam, DOMTargetSelector, AnimatableObject, AnimatableParams, ScrambleTextParams, } from 'animejs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanime",
3
- "version": "0.0.7",
3
+ "version": "0.0.10",
4
4
  "description": "Nuxt module for animejs integration and transitions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,40 +32,48 @@
32
32
  "playground",
33
33
  "docs"
34
34
  ],
35
+ "scripts": {
36
+ "prepack": "nuxt-module-build build",
37
+ "dev": "npm run dev:prepare && nuxt dev playground",
38
+ "dev:build": "nuxt build playground",
39
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground",
40
+ "release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
41
+ "lint": "eslint .",
42
+ "test": "vitest run",
43
+ "test:watch": "vitest watch",
44
+ "test:types": "nuxt typecheck",
45
+ "clean": "rm -rf playground/.nuxt docs/.nuxt playground/.output docs/.output .nuxt"
46
+ },
35
47
  "dependencies": {
36
- "@vueuse/core": "^14.1.0",
37
- "animejs": "^4.3.5",
48
+ "@vueuse/core": "^14.3.0",
49
+ "animejs": "^4.4.1",
50
+ "defu": "^6.1.7",
51
+ "vue": "^3.5.34"
52
+ },
53
+ "peerDependencies": {
54
+ "@vueuse/core": ">=13.0.0",
55
+ "animejs": "^4.4.0",
38
56
  "defu": "^6.1.4",
39
- "vue": "^3.5.27"
57
+ "vue": "^3.5.0"
40
58
  },
41
59
  "devDependencies": {
42
- "@nuxt/devtools": "^3.1.1",
43
- "@nuxt/eslint-config": "^1.13.0",
44
- "@nuxt/kit": "^4.3.0",
60
+ "@nuxt/devtools": "^3.2.4",
61
+ "@nuxt/eslint-config": "^1.15.2",
62
+ "@nuxt/kit": "^4.4.6",
45
63
  "@nuxt/module-builder": "^1.0.2",
46
- "@nuxt/schema": "^4.3.0",
64
+ "@nuxt/schema": "^4.4.6",
47
65
  "@nuxt/test-utils": "^3.23.0",
48
66
  "@types/node": "latest",
49
- "@vue/test-utils": "^2.4.6",
67
+ "@vue/test-utils": "^2.4.10",
50
68
  "@vueuse/nuxt": "14.1.0",
51
69
  "changelogen": "^0.6.2",
52
- "eslint": "^9.39.2",
53
- "happy-dom": "^20.4.0",
54
- "lefthook": "^2.0.16",
55
- "nuxt": "^4.3.0",
70
+ "eslint": "^9.39.4",
71
+ "happy-dom": "^20.9.0",
72
+ "lefthook": "^2.1.8",
73
+ "nuxt": "^4.4.6",
56
74
  "typescript": "~5.9.3",
57
- "vitest": "^4.0.18",
58
- "vue-tsc": "^3.2.4"
75
+ "vitest": "^3.2.4",
76
+ "vue-tsc": "^3.3.1"
59
77
  },
60
- "scripts": {
61
- "dev": "npm run dev:prepare && nuxt dev playground",
62
- "dev:build": "nuxt build playground",
63
- "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground",
64
- "release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
65
- "lint": "eslint .",
66
- "test": "vitest run",
67
- "test:watch": "vitest watch",
68
- "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
69
- "clean": "rm -rf playground/.nuxt docs/.nuxt playground/.output docs/.output .nuxt"
70
- }
71
- }
78
+ "packageManager": "pnpm@10.15.0+sha512.486ebc259d3e999a4e8691ce03b5cac4a71cbeca39372a9b762cb500cfdf0873e2cb16abe3d951b1ee2cf012503f027b98b6584e4df22524e0c7450d9ec7aa7b"
79
+ }