nanime 0.0.4 → 0.0.5

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
@@ -4,13 +4,14 @@
4
4
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
5
  [![License][license-src]][license-href]
6
6
  [![Nuxt][nuxt-src]][nuxt-href]
7
+ [![release nanime][release-src]][release-href]
7
8
 
8
9
  This module provides a set of SSR safe composables and components to make it easier
9
10
  to use [AnimeJS](https://animejs.com/) in your Nuxt application.
10
11
 
11
12
  - [✨  Release Notes](/CHANGELOG.md)
13
+ - [📖  Documentation](https://nanimejs.netlify.app)
12
14
  <!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/my-module?file=playground%2Fapp.vue) -->
13
- <!-- - [📖 &nbsp;Documentation](https://example.com) -->
14
15
 
15
16
  ## Features
16
17
 
@@ -81,14 +82,17 @@ That's it! You can now use the module in your application
81
82
 
82
83
 
83
84
  <!-- Badges -->
84
- [npm-version-src]: https://img.shields.io/npm/v/my-module/latest.svg?style=flat&colorA=020420&colorB=00DC82
85
- [npm-version-href]: https://npmjs.com/package/my-module
85
+ [npm-version-src]: https://img.shields.io/npm/v/nanime/latest.svg?style=flat&colorA=020420&colorB=00DC82
86
+ [npm-version-href]: https://npmjs.com/package/nanime
86
87
 
87
- [npm-downloads-src]: https://img.shields.io/npm/dm/my-module.svg?style=flat&colorA=020420&colorB=00DC82
88
- [npm-downloads-href]: https://npm.chart.dev/my-module
88
+ [npm-downloads-src]: https://img.shields.io/npm/dm/nanime.svg?style=flat&colorA=020420&colorB=00DC82
89
+ [npm-downloads-href]: https://npm.chart.dev/nanime
89
90
 
90
- [license-src]: https://img.shields.io/npm/l/my-module.svg?style=flat&colorA=020420&colorB=00DC82
91
- [license-href]: https://npmjs.com/package/my-module
91
+ [license-src]: https://img.shields.io/npm/l/nanime.svg?style=flat&colorA=020420&colorB=00DC82
92
+ [license-href]: https://npmjs.com/package/nanime
92
93
 
93
94
  [nuxt-src]: https://img.shields.io/badge/Nuxt-020420?logo=nuxt
94
95
  [nuxt-href]: https://nuxt.com
96
+
97
+ [release-src]: https://github.com/astraldev/nanime/actions/workflows/npm-publish.yml/badge.svg
98
+ [release-href]: https://github.com/astraldev/nanime/actions/workflows/npm-publish.yml
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.4",
7
+ "version": "0.0.5",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -46,11 +46,10 @@ const module$1 = defineNuxtModule({
46
46
  if (_options.composables) {
47
47
  addImportsDir(resolver.resolve("./runtime/app/composables"));
48
48
  }
49
- _nuxt.options.alias[`#${__configKey}`] = resolver.resolve("./runtime/app/composables");
49
+ _nuxt.options.alias[`#${__configKey}/composables`] = resolver.resolve("./runtime/app/composables");
50
50
  _nuxt.options.alias[`#${__configKey}/components`] = resolver.resolve("./runtime/app/components");
51
51
  _nuxt.options.alias[`#${__configKey}/utils`] = resolver.resolve("./runtime/app/utils");
52
52
  _nuxt.options.alias[`#${__configKey}/easings`] = resolver.resolve("./runtime/app/utils/easings");
53
- console.log(_nuxt.options.alias);
54
53
  }
55
54
  });
56
55
 
@@ -2,9 +2,7 @@ import type { AutoLayoutParams, EasingParam, LayoutAnimationParams, WAAPIEasingP
2
2
  import type { VueInstance } from '@vueuse/core';
3
3
  import type { BaseTransitionProps } from 'vue';
4
4
  import type { TransitionDurationInput } from '../../utils/transitions/types.js';
5
- type Prettify<T> = {
6
- [K in keyof T]: T[K];
7
- } & {};
5
+ import type { Prettify } from '../../utils/normalizers/prettify.js';
8
6
  export type SharedTransitionProps = {
9
7
  duration?: TransitionDurationInput;
10
8
  delay?: TransitionDurationInput;
@@ -41,4 +39,3 @@ export declare const isWaapiEase: (properties: SharedTransitionProps) => propert
41
39
  export declare const isStandardEase: (properties: SharedTransitionProps) => properties is SharedTransitionProps & {
42
40
  ease?: EasingParam;
43
41
  };
44
- export {};
@@ -1,4 +1,15 @@
1
- import { type MaybeRefOrGetter } from '#imports';
2
- import { normalizeAnimeTarget } from '../utils/normalize-targets.js';
3
- import type { Draggable, DraggableParams } from 'animejs';
4
- export declare function useDraggable(target: Parameters<typeof normalizeAnimeTarget>[0], options?: MaybeRefOrGetter<DraggableParams>): Draggable;
1
+ import { type DraggableTypes } from '../utils/normalize-targets.js';
2
+ import type { Draggable, DraggableAxisParam, DraggableParams } from 'animejs';
3
+ import { type ProxyReturns } from '../utils/create-proxy.js';
4
+ import { type MakeRefable } from '../utils/normalizers/make-reffable.js';
5
+ import type { Prettify } from '../utils/normalizers/prettify.js';
6
+ declare const REFFABLE_PROPS: readonly ["containerPadding", "containerFriction", "dragSpeed", "scrollSpeed", "scrollThreshold", "minVelocity", "maxVelocity", "velocityMultiplier", "snap"];
7
+ type RefableProps = typeof REFFABLE_PROPS[number];
8
+ type DraggableOptions = MakeRefable<Omit<DraggableParams, 'trigger' | 'container' | 'x' | 'y'> & {
9
+ trigger?: DraggableTypes['trigger'];
10
+ container?: DraggableTypes['container'];
11
+ x?: boolean | Prettify<MakeRefable<DraggableAxisParam, 'snap', Draggable>>;
12
+ y?: boolean | Prettify<MakeRefable<DraggableAxisParam, 'snap', Draggable>>;
13
+ }, RefableProps, Draggable>;
14
+ export declare function useDraggable(target: DraggableTypes['target'], options?: DraggableOptions): ProxyReturns<Draggable>;
15
+ export {};
@@ -1,22 +1,83 @@
1
- import { toReactive, tryOnScopeDispose, useMounted } from "@vueuse/core";
2
- import { shallowRef, toValue, watchEffect } from "#imports";
3
- import { normalizeAnimeTarget } from "../utils/normalize-targets.js";
1
+ import { tryOnScopeDispose, useMounted } from "@vueuse/core";
2
+ import { nextTick, shallowRef, toValue, watch, watchPostEffect } from "#imports";
3
+ import { normalizeAnimeTarget, normalizeDraggableContainer, normalizeLayoutTarget } from "../utils/normalize-targets.js";
4
4
  import { createDraggable } from "animejs/draggable";
5
+ import { createProxy } from "../utils/create-proxy.js";
6
+ import { normalizeReffable } from "../utils/normalizers/make-reffable.js";
7
+ import defu from "defu";
8
+ const REFFABLE_PROPS = [
9
+ "containerPadding",
10
+ "containerFriction",
11
+ "dragSpeed",
12
+ "scrollSpeed",
13
+ "scrollThreshold",
14
+ "minVelocity",
15
+ "maxVelocity",
16
+ "velocityMultiplier",
17
+ "snap"
18
+ ];
5
19
  export function useDraggable(target, options) {
6
20
  const mounted = useMounted();
7
- const dragController = shallowRef(createDraggable({}, {}));
21
+ const dragController = shallowRef(null);
8
22
  let oldTarget;
9
- watchEffect(() => {
10
- if (!mounted.value) return;
11
- const targets = normalizeAnimeTarget(target);
12
- if (oldTarget === targets) return;
13
- if (dragController.value) dragController.value.revert();
14
- oldTarget = targets;
15
- const newAnimation = createDraggable(targets, toValue(options) || {});
16
- dragController.value = newAnimation;
23
+ watch(
24
+ [
25
+ () => target,
26
+ () => options?.trigger,
27
+ () => options?.container,
28
+ () => mounted.value
29
+ ],
30
+ () => {
31
+ if (!mounted.value) return;
32
+ const targets = normalizeAnimeTarget(target);
33
+ if (oldTarget === targets) return;
34
+ if (dragController.value) dragController.value.revert();
35
+ oldTarget = targets;
36
+ const trigger = normalizeLayoutTarget(toValue(options)?.trigger);
37
+ const container = normalizeDraggableContainer(toValue(options)?.container);
38
+ const resolveAxis = (axis) => {
39
+ if (!axis || typeof axis !== "object") return axis;
40
+ return defu(axis, {
41
+ snap: (d) => normalizeReffable(axis.snap, d)
42
+ });
43
+ };
44
+ const dragEngine = createDraggable(targets, {
45
+ ...options,
46
+ trigger: trigger || void 0,
47
+ container: container || void 0,
48
+ ...(() => {
49
+ const acc = {};
50
+ REFFABLE_PROPS.forEach((key) => {
51
+ if (!options || !(key in options)) return;
52
+ acc[key] = (d) => normalizeReffable(options[key], d);
53
+ });
54
+ return acc;
55
+ })(),
56
+ x: resolveAxis(options?.x),
57
+ y: resolveAxis(options?.y)
58
+ });
59
+ console.log("initializing");
60
+ dragController.value = dragEngine;
61
+ },
62
+ {
63
+ flush: "post"
64
+ }
65
+ );
66
+ watchPostEffect(() => {
67
+ if (!options || !dragController.value) return;
68
+ REFFABLE_PROPS.forEach((key) => {
69
+ if (key in options) toValue(options[key]);
70
+ });
71
+ if (typeof options.x === "object" && options.x !== null) {
72
+ toValue(options.x.snap);
73
+ }
74
+ if (typeof options.y === "object" && options.y !== null) {
75
+ toValue(options.y.snap);
76
+ }
77
+ nextTick(() => dragController.value?.refresh());
17
78
  });
18
79
  tryOnScopeDispose(() => {
19
80
  dragController.value?.revert();
20
81
  });
21
- return toReactive(dragController);
82
+ return createProxy(dragController);
22
83
  }
@@ -0,0 +1,9 @@
1
+ import type { Ref, UnwrapNestedRefs } from 'vue';
2
+ export type SafeFunctions<T> = {
3
+ [K in keyof T]: T[K] extends (...args: any[]) => any ? ((...args: Parameters<T[K]>) => ReturnType<T[K]>) | undefined : T[K];
4
+ };
5
+ export type ProxyReturns<T> = SafeFunctions<Exclude<UnwrapNestedRefs<T>, null | undefined>>;
6
+ /**
7
+ * Converts the object to a reactive version, and stubs null / undefined values
8
+ */
9
+ export declare function createProxy<T = object | null>(objectRef: Ref<T>): ProxyReturns<T>;
@@ -0,0 +1,37 @@
1
+ import { unref, isRef, reactive } from "#imports";
2
+ export function createProxy(objectRef) {
3
+ const proxy = new Proxy({}, {
4
+ get(_, p, receiver) {
5
+ if (!objectRef.value) return void 0;
6
+ return unref(Reflect.get(objectRef.value, p, receiver));
7
+ },
8
+ set(_, p, value) {
9
+ if (!objectRef.value) return true;
10
+ if (isRef(objectRef.value[p]) && !isRef(value))
11
+ objectRef.value[p].value = value;
12
+ else
13
+ objectRef.value[p] = value;
14
+ return true;
15
+ },
16
+ deleteProperty(_, p) {
17
+ if (!objectRef.value) return true;
18
+ return Reflect.deleteProperty(objectRef.value, p);
19
+ },
20
+ has(_, p) {
21
+ if (!objectRef.value) return true;
22
+ return Reflect.has(objectRef.value, p);
23
+ },
24
+ ownKeys() {
25
+ if (!objectRef.value) return [];
26
+ return Object.keys(objectRef.value);
27
+ },
28
+ getOwnPropertyDescriptor() {
29
+ if (!objectRef.value) return void 0;
30
+ return {
31
+ enumerable: true,
32
+ configurable: true
33
+ };
34
+ }
35
+ });
36
+ return reactive(proxy);
37
+ }
@@ -1,14 +1,26 @@
1
1
  import { type MaybeRef } from '#imports';
2
2
  import type { MaybeElementRef, VueInstance } from '@vueuse/core';
3
- import type { TargetsParam, DOMTargetsParam, DOMTargetSelector } from 'animejs';
3
+ import type { TargetsParam, DOMTargetsParam, DOMTargetSelector, DraggableParams } from 'animejs';
4
4
  type WaapiElementTargets = VueInstance | HTMLElement | HTMLElement[] | SVGElement | SVGElement[] | NodeList | string | null;
5
5
  type WaapiTargets = MaybeRef<WaapiElementTargets> | MaybeRef<WaapiElementTargets>[];
6
6
  export declare function normalizeWaapiAnimeTarget(target: WaapiTargets): DOMTargetsParam | null;
7
7
  type AnimeTargets = TargetsParam | MaybeElementRef | MaybeElementRef[];
8
8
  export declare function normalizeAnimeTarget(target: AnimeTargets): TargetsParam;
9
- type AnimeLayoutTargets = DOMTargetSelector | MaybeElementRef<HTMLElement | VueInstance> | null | undefined;
9
+ type AnimeLayoutTargets = DOMTargetSelector | MaybeElementRef<HTMLElement | SVGElement | VueInstance | null> | null | undefined;
10
10
  export declare function normalizeLayoutTarget(target: AnimeLayoutTargets): DOMTargetSelector | null;
11
11
  type SplitTargets = HTMLElement | string;
12
12
  type SplitTextTargets = SplitTargets | MaybeElementRef<HTMLElement> | null | undefined | MaybeElementRef<VueInstance>;
13
+ export type SplitTextTypes = {
14
+ targets: SplitTextTargets;
15
+ };
13
16
  export declare function normalizeSplitTextTarget(target: SplitTextTargets): SplitTargets | null;
17
+ type DraggableTargets = AnimeLayoutTargets | null;
18
+ type DraggableTargetContainer = DraggableParams['container'] | MaybeElementRef<HTMLElement | VueInstance | null> | null | undefined;
19
+ type DraggableTargetTrigger = DraggableParams['trigger'] | AnimeLayoutTargets;
20
+ export type DraggableTypes = {
21
+ target: DraggableTargets;
22
+ trigger: DraggableTargetTrigger;
23
+ container: DraggableTargetContainer;
24
+ };
25
+ export declare function normalizeDraggableContainer(target: DraggableTargetContainer): DraggableParams['container'] | null | undefined;
14
26
  export {};
@@ -42,3 +42,14 @@ export function normalizeSplitTextTarget(target) {
42
42
  }
43
43
  return resolved;
44
44
  }
45
+ export function normalizeDraggableContainer(target) {
46
+ if (typeof target === "function") {
47
+ return target;
48
+ }
49
+ const resolved = toValue(target);
50
+ if (!resolved) return null;
51
+ if (isVueInstance(resolved)) {
52
+ return resolved.$el;
53
+ }
54
+ return resolved;
55
+ }
@@ -0,0 +1,6 @@
1
+ import { type MaybeRefOrGetter } from '#imports';
2
+ export type MaybeRefOrArgsGetter<T, Args> = MaybeRefOrGetter<T> | ((data: Args) => T);
3
+ export type MakeRefable<T, K extends keyof T, Args> = {
4
+ [P in keyof T]?: P extends K ? MaybeRefOrArgsGetter<T[P], Args> : T[P];
5
+ };
6
+ export declare function normalizeReffable<T, Args>(value: MaybeRefOrArgsGetter<T, Args>, args?: Args): T;
@@ -0,0 +1,7 @@
1
+ import { toValue } from "#imports";
2
+ export function normalizeReffable(value, args) {
3
+ if (typeof value === "function") {
4
+ return value(args);
5
+ }
6
+ return toValue(value);
7
+ }
@@ -0,0 +1,3 @@
1
+ export type Prettify<T> = {
2
+ [K in keyof T]: T[K];
3
+ } & {};
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanime",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Nuxt module for animejs integration and transitions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,22 +22,16 @@
22
22
  ]
23
23
  }
24
24
  },
25
+ "publishConfig": {
26
+ "provenance": true
27
+ },
25
28
  "files": [
26
29
  "dist"
27
30
  ],
28
- "scripts": {
29
- "postinstall": "lefthook install",
30
- "prepack": "nuxt-module-build build",
31
- "dev": "npm run dev:prepare && nuxt dev playground",
32
- "dev:build": "nuxt build playground",
33
- "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground",
34
- "release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
35
- "lint": "eslint .",
36
- "test": "vitest run",
37
- "test:watch": "vitest watch",
38
- "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
39
- "clean": "rm -rf playground/.nuxt docs/.nuxt playground/.output docs/.output .nuxt"
40
- },
31
+ "workspaces": [
32
+ "playground",
33
+ "docs"
34
+ ],
41
35
  "dependencies": {
42
36
  "@vueuse/core": "^14.1.0",
43
37
  "animejs": "^4.3.5",
@@ -63,5 +57,16 @@
63
57
  "vitest": "^4.0.18",
64
58
  "vue-tsc": "^3.2.4"
65
59
  },
66
- "packageManager": "pnpm@10.15.0+sha512.486ebc259d3e999a4e8691ce03b5cac4a71cbeca39372a9b762cb500cfdf0873e2cb16abe3d951b1ee2cf012503f027b98b6584e4df22524e0c7450d9ec7aa7b"
67
- }
60
+ "scripts": {
61
+ "postinstall": "lefthook install",
62
+ "dev": "npm run dev:prepare && nuxt dev playground",
63
+ "dev:build": "nuxt build playground",
64
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground",
65
+ "release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
66
+ "lint": "eslint .",
67
+ "test": "vitest run",
68
+ "test:watch": "vitest watch",
69
+ "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
70
+ "clean": "rm -rf playground/.nuxt docs/.nuxt playground/.output docs/.output .nuxt"
71
+ }
72
+ }