@sprite-motion/react 0.1.2 → 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/README.md CHANGED
@@ -1,84 +1,23 @@
1
1
  # @sprite-motion/react
2
2
 
3
- React component and hook for sprite sheet animation.
3
+ > **Deprecated** use [`mason-sprite/react`](https://www.npmjs.com/package/mason-sprite) instead.
4
+ > This package is a compatibility shim. See [MIGRATION.md](https://github.com/FE-HyunSu/sprite-motion/blob/main/MIGRATION.md).
4
5
 
5
- Part of [Sprite Motion](https://github.com/FE-HyunSu/sprite-motion) — play PNG/WebP sprite sheets with `rows`, `cols`, and `fps`. No Lottie required.
6
-
7
- ## Install
6
+ ## Migrate
8
7
 
9
8
  ```bash
10
- npm install @sprite-motion/react
9
+ npm install mason-sprite
11
10
  ```
12
11
 
13
- ## Usage
14
-
15
12
  ```tsx
13
+ // Before
16
14
  import { SpriteAnimation } from '@sprite-motion/react';
17
15
 
18
- <SpriteAnimation
19
- src="/sprite.png"
20
- rows={4}
21
- cols={4}
22
- fps={12}
23
- loop
24
- width={128}
25
- height={128}
26
- />
27
- ```
28
-
29
- ## Playback Controls
30
-
31
- ```tsx
32
- import { useRef } from 'react';
33
- import { SpriteAnimation, type SpriteAnimationHandle } from '@sprite-motion/react';
34
-
35
- const ref = useRef<SpriteAnimationHandle>(null);
36
-
37
- ref.current?.play();
38
- ref.current?.pause();
39
- ref.current?.stop();
40
- ref.current?.goToFrame(3);
41
- ```
42
-
43
- ## Hook
44
-
45
- ```tsx
46
- import { useSpriteAnimation } from '@sprite-motion/react';
47
-
48
- const { ref, state, play, pause, stop, goToFrame } = useSpriteAnimation({
49
- src: '/sprite.png',
50
- rows: 4,
51
- cols: 4,
52
- fps: 12,
53
- });
16
+ // After
17
+ import { Sprite } from 'mason-sprite/react';
54
18
  ```
55
19
 
56
- ## Props
57
-
58
- | Prop | Type | Default | Description |
59
- |------|------|---------|-------------|
60
- | `src` | `string` | — | Sprite sheet image URL |
61
- | `rows` | `number` | — | Number of rows |
62
- | `cols` | `number` | — | Number of columns |
63
- | `fps` | `number` | `12` | Frames per second |
64
- | `loop` | `boolean` | `true` | Loop animation |
65
- | `width` | `number` | `128` | Display width (px) |
66
- | `height` | `number` | `128` | Display height (px) |
67
- | `autoPlay` | `boolean` | `true` | Start on mount |
68
- | `renderer` | `'css' \| 'canvas'` | `'css'` | Rendering mode |
69
- | `onComplete` | `() => void` | — | Called when a non-looping animation finishes |
70
- | `onFrameChange` | `(frame: number) => void` | — | Called on each frame change |
71
-
72
- ## Renderers
73
-
74
- - **CSS (default)** — lightweight, uses `background-position`
75
- - **Canvas** — uses `drawImage`, good for custom drawing
76
-
77
- ## Related Packages
78
-
79
- - [`@sprite-motion/core`](https://www.npmjs.com/package/@sprite-motion/core) — framework-agnostic engine
80
- - [`@sprite-motion/vue`](https://www.npmjs.com/package/@sprite-motion/vue)
81
- - [`@sprite-motion/svelte`](https://www.npmjs.com/package/@sprite-motion/svelte)
20
+ Existing code on v0.2.0 still works — `SpriteAnimation` is aliased to `Sprite`.
82
21
 
83
22
  ## License
84
23
 
package/dist/index.cjs CHANGED
@@ -20,101 +20,32 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ Sprite: () => import_react.Sprite,
23
24
  SpriteAnimation: () => SpriteAnimation,
24
- useSpriteAnimation: () => useSpriteAnimation
25
+ useSpriteAnimation: () => import_react.useSprite
25
26
  });
26
27
  module.exports = __toCommonJS(index_exports);
28
+ var import_react = require("mason-sprite/react");
27
29
 
28
- // src/SpriteAnimation.tsx
29
- var import_react2 = require("react");
30
-
31
- // src/useSpriteAnimation.ts
32
- var import_core = require("@sprite-motion/core");
33
- var import_react = require("react");
34
- function useSpriteAnimation(options) {
35
- const ref = (0, import_react.useRef)(null);
36
- const animatorRef = (0, import_react.useRef)(null);
37
- const [state, setState] = (0, import_react.useState)({
38
- currentFrame: 0,
39
- totalFrames: options.rows * options.cols,
40
- isPlaying: false,
41
- isLoaded: false
42
- });
43
- const { enabled = true, ...animatorOptions } = options;
44
- (0, import_react.useEffect)(() => {
45
- if (!enabled) return;
46
- const animator = new import_core.SpriteAnimator(animatorOptions);
47
- animatorRef.current = animator;
48
- const unsubscribe = animator.subscribe(setState);
49
- queueMicrotask(() => {
50
- if (ref.current) {
51
- animator.attach(ref.current);
52
- }
53
- });
54
- return () => {
55
- unsubscribe();
56
- animator.destroy();
57
- animatorRef.current = null;
58
- };
59
- }, [enabled]);
60
- (0, import_react.useEffect)(() => {
61
- animatorRef.current?.updateOptions(animatorOptions);
62
- }, [
63
- animatorOptions.src,
64
- animatorOptions.rows,
65
- animatorOptions.cols,
66
- animatorOptions.fps,
67
- animatorOptions.loop,
68
- animatorOptions.width,
69
- animatorOptions.height,
70
- animatorOptions.autoPlay,
71
- animatorOptions.renderer
72
- ]);
73
- return {
74
- ref,
75
- state,
76
- play: () => animatorRef.current?.play(),
77
- pause: () => animatorRef.current?.pause(),
78
- stop: () => animatorRef.current?.stop(),
79
- goToFrame: (frame) => animatorRef.current?.goToFrame(frame)
80
- };
30
+ // src/warn.ts
31
+ var MIGRATION_URL = "https://github.com/FE-HyunSu/sprite-motion/blob/main/MIGRATION.md";
32
+ var warned = false;
33
+ function warnDeprecation(packageName) {
34
+ if (warned || typeof console === "undefined") return;
35
+ warned = true;
36
+ console.warn(
37
+ `[${packageName}] This package is deprecated and will receive no further updates.
38
+ Please migrate to mason-sprite: npm install mason-sprite
39
+ Migration guide: ${MIGRATION_URL}`
40
+ );
81
41
  }
82
42
 
83
- // src/SpriteAnimation.tsx
84
- var import_jsx_runtime = require("react/jsx-runtime");
85
- var SpriteAnimation = (0, import_react2.forwardRef)(
86
- function SpriteAnimation2({ className, style, ...options }, ref) {
87
- const { ref: targetRef, play, pause, stop, goToFrame } = useSpriteAnimation(options);
88
- (0, import_react2.useImperativeHandle)(ref, () => ({ play, pause, stop, goToFrame }), [
89
- play,
90
- pause,
91
- stop,
92
- goToFrame
93
- ]);
94
- if (options.renderer === "canvas") {
95
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
96
- "canvas",
97
- {
98
- ref: targetRef,
99
- className,
100
- style
101
- }
102
- );
103
- }
104
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
105
- "div",
106
- {
107
- ref: targetRef,
108
- className,
109
- style,
110
- role: "img",
111
- "aria-label": "Sprite animation"
112
- }
113
- );
114
- }
115
- );
43
+ // src/index.ts
44
+ warnDeprecation("@sprite-motion/react");
45
+ var SpriteAnimation = import_react.Sprite;
116
46
  // Annotate the CommonJS export names for ESM import in node:
117
47
  0 && (module.exports = {
48
+ Sprite,
118
49
  SpriteAnimation,
119
50
  useSpriteAnimation
120
51
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/SpriteAnimation.tsx","../src/useSpriteAnimation.ts"],"sourcesContent":["export { SpriteAnimation } from './SpriteAnimation.js';\nexport type { SpriteAnimationHandle, SpriteAnimationProps } from './SpriteAnimation.js';\nexport { useSpriteAnimation } from './useSpriteAnimation.js';\nexport type { UseSpriteAnimationOptions, UseSpriteAnimationReturn } from './useSpriteAnimation.js';\n","import type { SpriteAnimationOptions } from '@sprite-motion/core';\nimport { forwardRef, useImperativeHandle } from 'react';\nimport { useSpriteAnimation } from './useSpriteAnimation.js';\n\nexport interface SpriteAnimationProps extends SpriteAnimationOptions {\n className?: string;\n style?: React.CSSProperties;\n}\n\nexport interface SpriteAnimationHandle {\n play: () => void;\n pause: () => void;\n stop: () => void;\n goToFrame: (frame: number) => void;\n}\n\nexport const SpriteAnimation = forwardRef<SpriteAnimationHandle, SpriteAnimationProps>(\n function SpriteAnimation({ className, style, ...options }, ref) {\n const { ref: targetRef, play, pause, stop, goToFrame } = useSpriteAnimation(options);\n\n useImperativeHandle(ref, () => ({ play, pause, stop, goToFrame }), [\n play,\n pause,\n stop,\n goToFrame,\n ]);\n\n if (options.renderer === 'canvas') {\n return (\n <canvas\n ref={targetRef as React.RefObject<HTMLCanvasElement>}\n className={className}\n style={style}\n />\n );\n }\n\n return (\n <div\n ref={targetRef as React.RefObject<HTMLDivElement>}\n className={className}\n style={style}\n role=\"img\"\n aria-label=\"Sprite animation\"\n />\n );\n },\n);\n","import { SpriteAnimator, type SpriteAnimationOptions, type SpriteAnimationState } from '@sprite-motion/core';\nimport { useEffect, useRef, useState } from 'react';\n\nexport interface UseSpriteAnimationOptions extends SpriteAnimationOptions {\n /** Skip auto-attach; useful when controlling the target manually */\n enabled?: boolean;\n}\n\nexport interface UseSpriteAnimationReturn {\n ref: React.RefObject<HTMLElement | HTMLCanvasElement | null>;\n state: SpriteAnimationState;\n play: () => void;\n pause: () => void;\n stop: () => void;\n goToFrame: (frame: number) => void;\n}\n\nexport function useSpriteAnimation(options: UseSpriteAnimationOptions): UseSpriteAnimationReturn {\n const ref = useRef<HTMLElement | HTMLCanvasElement | null>(null);\n const animatorRef = useRef<SpriteAnimator | null>(null);\n const [state, setState] = useState<SpriteAnimationState>({\n currentFrame: 0,\n totalFrames: options.rows * options.cols,\n isPlaying: false,\n isLoaded: false,\n });\n\n const { enabled = true, ...animatorOptions } = options;\n\n useEffect(() => {\n if (!enabled) return;\n\n const animator = new SpriteAnimator(animatorOptions);\n animatorRef.current = animator;\n\n const unsubscribe = animator.subscribe(setState);\n\n queueMicrotask(() => {\n if (ref.current) {\n animator.attach(ref.current);\n }\n });\n\n return () => {\n unsubscribe();\n animator.destroy();\n animatorRef.current = null;\n };\n }, [enabled]);\n\n useEffect(() => {\n animatorRef.current?.updateOptions(animatorOptions);\n }, [\n animatorOptions.src,\n animatorOptions.rows,\n animatorOptions.cols,\n animatorOptions.fps,\n animatorOptions.loop,\n animatorOptions.width,\n animatorOptions.height,\n animatorOptions.autoPlay,\n animatorOptions.renderer,\n ]);\n\n return {\n ref,\n state,\n play: () => animatorRef.current?.play(),\n pause: () => animatorRef.current?.pause(),\n stop: () => animatorRef.current?.stop(),\n goToFrame: (frame) => animatorRef.current?.goToFrame(frame),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAAA,gBAAgD;;;ACDhD,kBAAuF;AACvF,mBAA4C;AAgBrC,SAAS,mBAAmB,SAA8D;AAC/F,QAAM,UAAM,qBAA+C,IAAI;AAC/D,QAAM,kBAAc,qBAA8B,IAAI;AACtD,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAA+B;AAAA,IACvD,cAAc;AAAA,IACd,aAAa,QAAQ,OAAO,QAAQ;AAAA,IACpC,WAAW;AAAA,IACX,UAAU;AAAA,EACZ,CAAC;AAED,QAAM,EAAE,UAAU,MAAM,GAAG,gBAAgB,IAAI;AAE/C,8BAAU,MAAM;AACd,QAAI,CAAC,QAAS;AAEd,UAAM,WAAW,IAAI,2BAAe,eAAe;AACnD,gBAAY,UAAU;AAEtB,UAAM,cAAc,SAAS,UAAU,QAAQ;AAE/C,mBAAe,MAAM;AACnB,UAAI,IAAI,SAAS;AACf,iBAAS,OAAO,IAAI,OAAO;AAAA,MAC7B;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AACX,kBAAY;AACZ,eAAS,QAAQ;AACjB,kBAAY,UAAU;AAAA,IACxB;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,8BAAU,MAAM;AACd,gBAAY,SAAS,cAAc,eAAe;AAAA,EACpD,GAAG;AAAA,IACD,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,EAClB,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,MAAM,MAAM,YAAY,SAAS,KAAK;AAAA,IACtC,OAAO,MAAM,YAAY,SAAS,MAAM;AAAA,IACxC,MAAM,MAAM,YAAY,SAAS,KAAK;AAAA,IACtC,WAAW,CAAC,UAAU,YAAY,SAAS,UAAU,KAAK;AAAA,EAC5D;AACF;;;AD3CQ;AAbD,IAAM,sBAAkB;AAAA,EAC7B,SAASC,iBAAgB,EAAE,WAAW,OAAO,GAAG,QAAQ,GAAG,KAAK;AAC9D,UAAM,EAAE,KAAK,WAAW,MAAM,OAAO,MAAM,UAAU,IAAI,mBAAmB,OAAO;AAEnF,2CAAoB,KAAK,OAAO,EAAE,MAAM,OAAO,MAAM,UAAU,IAAI;AAAA,MACjE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,QAAI,QAAQ,aAAa,UAAU;AACjC,aACE;AAAA,QAAC;AAAA;AAAA,UACC,KAAK;AAAA,UACL;AAAA,UACA;AAAA;AAAA,MACF;AAAA,IAEJ;AAEA,WACE;AAAA,MAAC;AAAA;AAAA,QACC,KAAK;AAAA,QACL;AAAA,QACA;AAAA,QACA,MAAK;AAAA,QACL,cAAW;AAAA;AAAA,IACb;AAAA,EAEJ;AACF;","names":["import_react","SpriteAnimation"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/warn.ts"],"sourcesContent":["import { Sprite, useSprite } from 'mason-sprite/react';\nimport type {\n SpriteHandle,\n SpriteProps,\n UseSpriteOptions,\n UseSpriteReturn,\n} from 'mason-sprite/react';\nimport { warnDeprecation } from './warn.js';\n\nwarnDeprecation('@sprite-motion/react');\n\n/** @deprecated Use `Sprite` from `mason-sprite/react` */\nexport const SpriteAnimation = Sprite;\n\nexport { Sprite, useSprite as useSpriteAnimation };\n\nexport type {\n SpriteHandle as SpriteAnimationHandle,\n SpriteProps as SpriteAnimationProps,\n UseSpriteOptions as UseSpriteAnimationOptions,\n UseSpriteReturn as UseSpriteAnimationReturn,\n};\n","const MIGRATION_URL =\n 'https://github.com/FE-HyunSu/sprite-motion/blob/main/MIGRATION.md';\n\nlet warned = false;\n\nexport function warnDeprecation(packageName: string): void {\n if (warned || typeof console === 'undefined') return;\n warned = true;\n console.warn(\n `[${packageName}] This package is deprecated and will receive no further updates.\\n` +\n `Please migrate to mason-sprite: npm install mason-sprite\\n` +\n `Migration guide: ${MIGRATION_URL}`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkC;;;ACAlC,IAAM,gBACJ;AAEF,IAAI,SAAS;AAEN,SAAS,gBAAgB,aAA2B;AACzD,MAAI,UAAU,OAAO,YAAY,YAAa;AAC9C,WAAS;AACT,UAAQ;AAAA,IACN,IAAI,WAAW;AAAA;AAAA,mBAEO,aAAa;AAAA,EACrC;AACF;;;ADJA,gBAAgB,sBAAsB;AAG/B,IAAM,kBAAkB;","names":[]}
package/dist/index.d.cts CHANGED
@@ -1,30 +1,8 @@
1
1
  import * as react from 'react';
2
- import { SpriteAnimationOptions, SpriteAnimationState } from '@sprite-motion/core';
2
+ import { SpriteProps, SpriteHandle } from 'mason-sprite/react';
3
+ export { Sprite, SpriteHandle as SpriteAnimationHandle, SpriteProps as SpriteAnimationProps, UseSpriteOptions as UseSpriteAnimationOptions, UseSpriteReturn as UseSpriteAnimationReturn, useSprite as useSpriteAnimation } from 'mason-sprite/react';
3
4
 
4
- interface SpriteAnimationProps extends SpriteAnimationOptions {
5
- className?: string;
6
- style?: React.CSSProperties;
7
- }
8
- interface SpriteAnimationHandle {
9
- play: () => void;
10
- pause: () => void;
11
- stop: () => void;
12
- goToFrame: (frame: number) => void;
13
- }
14
- declare const SpriteAnimation: react.ForwardRefExoticComponent<SpriteAnimationProps & react.RefAttributes<SpriteAnimationHandle>>;
5
+ /** @deprecated Use `Sprite` from `mason-sprite/react` */
6
+ declare const SpriteAnimation: react.ForwardRefExoticComponent<SpriteProps & react.RefAttributes<SpriteHandle>>;
15
7
 
16
- interface UseSpriteAnimationOptions extends SpriteAnimationOptions {
17
- /** Skip auto-attach; useful when controlling the target manually */
18
- enabled?: boolean;
19
- }
20
- interface UseSpriteAnimationReturn {
21
- ref: React.RefObject<HTMLElement | HTMLCanvasElement | null>;
22
- state: SpriteAnimationState;
23
- play: () => void;
24
- pause: () => void;
25
- stop: () => void;
26
- goToFrame: (frame: number) => void;
27
- }
28
- declare function useSpriteAnimation(options: UseSpriteAnimationOptions): UseSpriteAnimationReturn;
29
-
30
- export { SpriteAnimation, type SpriteAnimationHandle, type SpriteAnimationProps, type UseSpriteAnimationOptions, type UseSpriteAnimationReturn, useSpriteAnimation };
8
+ export { SpriteAnimation };
package/dist/index.d.ts CHANGED
@@ -1,30 +1,8 @@
1
1
  import * as react from 'react';
2
- import { SpriteAnimationOptions, SpriteAnimationState } from '@sprite-motion/core';
2
+ import { SpriteProps, SpriteHandle } from 'mason-sprite/react';
3
+ export { Sprite, SpriteHandle as SpriteAnimationHandle, SpriteProps as SpriteAnimationProps, UseSpriteOptions as UseSpriteAnimationOptions, UseSpriteReturn as UseSpriteAnimationReturn, useSprite as useSpriteAnimation } from 'mason-sprite/react';
3
4
 
4
- interface SpriteAnimationProps extends SpriteAnimationOptions {
5
- className?: string;
6
- style?: React.CSSProperties;
7
- }
8
- interface SpriteAnimationHandle {
9
- play: () => void;
10
- pause: () => void;
11
- stop: () => void;
12
- goToFrame: (frame: number) => void;
13
- }
14
- declare const SpriteAnimation: react.ForwardRefExoticComponent<SpriteAnimationProps & react.RefAttributes<SpriteAnimationHandle>>;
5
+ /** @deprecated Use `Sprite` from `mason-sprite/react` */
6
+ declare const SpriteAnimation: react.ForwardRefExoticComponent<SpriteProps & react.RefAttributes<SpriteHandle>>;
15
7
 
16
- interface UseSpriteAnimationOptions extends SpriteAnimationOptions {
17
- /** Skip auto-attach; useful when controlling the target manually */
18
- enabled?: boolean;
19
- }
20
- interface UseSpriteAnimationReturn {
21
- ref: React.RefObject<HTMLElement | HTMLCanvasElement | null>;
22
- state: SpriteAnimationState;
23
- play: () => void;
24
- pause: () => void;
25
- stop: () => void;
26
- goToFrame: (frame: number) => void;
27
- }
28
- declare function useSpriteAnimation(options: UseSpriteAnimationOptions): UseSpriteAnimationReturn;
29
-
30
- export { SpriteAnimation, type SpriteAnimationHandle, type SpriteAnimationProps, type UseSpriteAnimationOptions, type UseSpriteAnimationReturn, useSpriteAnimation };
8
+ export { SpriteAnimation };
package/dist/index.js CHANGED
@@ -1,93 +1,25 @@
1
- // src/SpriteAnimation.tsx
2
- import { forwardRef, useImperativeHandle } from "react";
1
+ // src/index.ts
2
+ import { Sprite, useSprite } from "mason-sprite/react";
3
3
 
4
- // src/useSpriteAnimation.ts
5
- import { SpriteAnimator } from "@sprite-motion/core";
6
- import { useEffect, useRef, useState } from "react";
7
- function useSpriteAnimation(options) {
8
- const ref = useRef(null);
9
- const animatorRef = useRef(null);
10
- const [state, setState] = useState({
11
- currentFrame: 0,
12
- totalFrames: options.rows * options.cols,
13
- isPlaying: false,
14
- isLoaded: false
15
- });
16
- const { enabled = true, ...animatorOptions } = options;
17
- useEffect(() => {
18
- if (!enabled) return;
19
- const animator = new SpriteAnimator(animatorOptions);
20
- animatorRef.current = animator;
21
- const unsubscribe = animator.subscribe(setState);
22
- queueMicrotask(() => {
23
- if (ref.current) {
24
- animator.attach(ref.current);
25
- }
26
- });
27
- return () => {
28
- unsubscribe();
29
- animator.destroy();
30
- animatorRef.current = null;
31
- };
32
- }, [enabled]);
33
- useEffect(() => {
34
- animatorRef.current?.updateOptions(animatorOptions);
35
- }, [
36
- animatorOptions.src,
37
- animatorOptions.rows,
38
- animatorOptions.cols,
39
- animatorOptions.fps,
40
- animatorOptions.loop,
41
- animatorOptions.width,
42
- animatorOptions.height,
43
- animatorOptions.autoPlay,
44
- animatorOptions.renderer
45
- ]);
46
- return {
47
- ref,
48
- state,
49
- play: () => animatorRef.current?.play(),
50
- pause: () => animatorRef.current?.pause(),
51
- stop: () => animatorRef.current?.stop(),
52
- goToFrame: (frame) => animatorRef.current?.goToFrame(frame)
53
- };
4
+ // src/warn.ts
5
+ var MIGRATION_URL = "https://github.com/FE-HyunSu/sprite-motion/blob/main/MIGRATION.md";
6
+ var warned = false;
7
+ function warnDeprecation(packageName) {
8
+ if (warned || typeof console === "undefined") return;
9
+ warned = true;
10
+ console.warn(
11
+ `[${packageName}] This package is deprecated and will receive no further updates.
12
+ Please migrate to mason-sprite: npm install mason-sprite
13
+ Migration guide: ${MIGRATION_URL}`
14
+ );
54
15
  }
55
16
 
56
- // src/SpriteAnimation.tsx
57
- import { jsx } from "react/jsx-runtime";
58
- var SpriteAnimation = forwardRef(
59
- function SpriteAnimation2({ className, style, ...options }, ref) {
60
- const { ref: targetRef, play, pause, stop, goToFrame } = useSpriteAnimation(options);
61
- useImperativeHandle(ref, () => ({ play, pause, stop, goToFrame }), [
62
- play,
63
- pause,
64
- stop,
65
- goToFrame
66
- ]);
67
- if (options.renderer === "canvas") {
68
- return /* @__PURE__ */ jsx(
69
- "canvas",
70
- {
71
- ref: targetRef,
72
- className,
73
- style
74
- }
75
- );
76
- }
77
- return /* @__PURE__ */ jsx(
78
- "div",
79
- {
80
- ref: targetRef,
81
- className,
82
- style,
83
- role: "img",
84
- "aria-label": "Sprite animation"
85
- }
86
- );
87
- }
88
- );
17
+ // src/index.ts
18
+ warnDeprecation("@sprite-motion/react");
19
+ var SpriteAnimation = Sprite;
89
20
  export {
21
+ Sprite,
90
22
  SpriteAnimation,
91
- useSpriteAnimation
23
+ useSprite as useSpriteAnimation
92
24
  };
93
25
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/SpriteAnimation.tsx","../src/useSpriteAnimation.ts"],"sourcesContent":["import type { SpriteAnimationOptions } from '@sprite-motion/core';\nimport { forwardRef, useImperativeHandle } from 'react';\nimport { useSpriteAnimation } from './useSpriteAnimation.js';\n\nexport interface SpriteAnimationProps extends SpriteAnimationOptions {\n className?: string;\n style?: React.CSSProperties;\n}\n\nexport interface SpriteAnimationHandle {\n play: () => void;\n pause: () => void;\n stop: () => void;\n goToFrame: (frame: number) => void;\n}\n\nexport const SpriteAnimation = forwardRef<SpriteAnimationHandle, SpriteAnimationProps>(\n function SpriteAnimation({ className, style, ...options }, ref) {\n const { ref: targetRef, play, pause, stop, goToFrame } = useSpriteAnimation(options);\n\n useImperativeHandle(ref, () => ({ play, pause, stop, goToFrame }), [\n play,\n pause,\n stop,\n goToFrame,\n ]);\n\n if (options.renderer === 'canvas') {\n return (\n <canvas\n ref={targetRef as React.RefObject<HTMLCanvasElement>}\n className={className}\n style={style}\n />\n );\n }\n\n return (\n <div\n ref={targetRef as React.RefObject<HTMLDivElement>}\n className={className}\n style={style}\n role=\"img\"\n aria-label=\"Sprite animation\"\n />\n );\n },\n);\n","import { SpriteAnimator, type SpriteAnimationOptions, type SpriteAnimationState } from '@sprite-motion/core';\nimport { useEffect, useRef, useState } from 'react';\n\nexport interface UseSpriteAnimationOptions extends SpriteAnimationOptions {\n /** Skip auto-attach; useful when controlling the target manually */\n enabled?: boolean;\n}\n\nexport interface UseSpriteAnimationReturn {\n ref: React.RefObject<HTMLElement | HTMLCanvasElement | null>;\n state: SpriteAnimationState;\n play: () => void;\n pause: () => void;\n stop: () => void;\n goToFrame: (frame: number) => void;\n}\n\nexport function useSpriteAnimation(options: UseSpriteAnimationOptions): UseSpriteAnimationReturn {\n const ref = useRef<HTMLElement | HTMLCanvasElement | null>(null);\n const animatorRef = useRef<SpriteAnimator | null>(null);\n const [state, setState] = useState<SpriteAnimationState>({\n currentFrame: 0,\n totalFrames: options.rows * options.cols,\n isPlaying: false,\n isLoaded: false,\n });\n\n const { enabled = true, ...animatorOptions } = options;\n\n useEffect(() => {\n if (!enabled) return;\n\n const animator = new SpriteAnimator(animatorOptions);\n animatorRef.current = animator;\n\n const unsubscribe = animator.subscribe(setState);\n\n queueMicrotask(() => {\n if (ref.current) {\n animator.attach(ref.current);\n }\n });\n\n return () => {\n unsubscribe();\n animator.destroy();\n animatorRef.current = null;\n };\n }, [enabled]);\n\n useEffect(() => {\n animatorRef.current?.updateOptions(animatorOptions);\n }, [\n animatorOptions.src,\n animatorOptions.rows,\n animatorOptions.cols,\n animatorOptions.fps,\n animatorOptions.loop,\n animatorOptions.width,\n animatorOptions.height,\n animatorOptions.autoPlay,\n animatorOptions.renderer,\n ]);\n\n return {\n ref,\n state,\n play: () => animatorRef.current?.play(),\n pause: () => animatorRef.current?.pause(),\n stop: () => animatorRef.current?.stop(),\n goToFrame: (frame) => animatorRef.current?.goToFrame(frame),\n };\n}\n"],"mappings":";AACA,SAAS,YAAY,2BAA2B;;;ACDhD,SAAS,sBAA8E;AACvF,SAAS,WAAW,QAAQ,gBAAgB;AAgBrC,SAAS,mBAAmB,SAA8D;AAC/F,QAAM,MAAM,OAA+C,IAAI;AAC/D,QAAM,cAAc,OAA8B,IAAI;AACtD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAA+B;AAAA,IACvD,cAAc;AAAA,IACd,aAAa,QAAQ,OAAO,QAAQ;AAAA,IACpC,WAAW;AAAA,IACX,UAAU;AAAA,EACZ,CAAC;AAED,QAAM,EAAE,UAAU,MAAM,GAAG,gBAAgB,IAAI;AAE/C,YAAU,MAAM;AACd,QAAI,CAAC,QAAS;AAEd,UAAM,WAAW,IAAI,eAAe,eAAe;AACnD,gBAAY,UAAU;AAEtB,UAAM,cAAc,SAAS,UAAU,QAAQ;AAE/C,mBAAe,MAAM;AACnB,UAAI,IAAI,SAAS;AACf,iBAAS,OAAO,IAAI,OAAO;AAAA,MAC7B;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AACX,kBAAY;AACZ,eAAS,QAAQ;AACjB,kBAAY,UAAU;AAAA,IACxB;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,YAAU,MAAM;AACd,gBAAY,SAAS,cAAc,eAAe;AAAA,EACpD,GAAG;AAAA,IACD,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,EAClB,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,MAAM,MAAM,YAAY,SAAS,KAAK;AAAA,IACtC,OAAO,MAAM,YAAY,SAAS,MAAM;AAAA,IACxC,MAAM,MAAM,YAAY,SAAS,KAAK;AAAA,IACtC,WAAW,CAAC,UAAU,YAAY,SAAS,UAAU,KAAK;AAAA,EAC5D;AACF;;;AD3CQ;AAbD,IAAM,kBAAkB;AAAA,EAC7B,SAASA,iBAAgB,EAAE,WAAW,OAAO,GAAG,QAAQ,GAAG,KAAK;AAC9D,UAAM,EAAE,KAAK,WAAW,MAAM,OAAO,MAAM,UAAU,IAAI,mBAAmB,OAAO;AAEnF,wBAAoB,KAAK,OAAO,EAAE,MAAM,OAAO,MAAM,UAAU,IAAI;AAAA,MACjE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,QAAI,QAAQ,aAAa,UAAU;AACjC,aACE;AAAA,QAAC;AAAA;AAAA,UACC,KAAK;AAAA,UACL;AAAA,UACA;AAAA;AAAA,MACF;AAAA,IAEJ;AAEA,WACE;AAAA,MAAC;AAAA;AAAA,QACC,KAAK;AAAA,QACL;AAAA,QACA;AAAA,QACA,MAAK;AAAA,QACL,cAAW;AAAA;AAAA,IACb;AAAA,EAEJ;AACF;","names":["SpriteAnimation"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/warn.ts"],"sourcesContent":["import { Sprite, useSprite } from 'mason-sprite/react';\nimport type {\n SpriteHandle,\n SpriteProps,\n UseSpriteOptions,\n UseSpriteReturn,\n} from 'mason-sprite/react';\nimport { warnDeprecation } from './warn.js';\n\nwarnDeprecation('@sprite-motion/react');\n\n/** @deprecated Use `Sprite` from `mason-sprite/react` */\nexport const SpriteAnimation = Sprite;\n\nexport { Sprite, useSprite as useSpriteAnimation };\n\nexport type {\n SpriteHandle as SpriteAnimationHandle,\n SpriteProps as SpriteAnimationProps,\n UseSpriteOptions as UseSpriteAnimationOptions,\n UseSpriteReturn as UseSpriteAnimationReturn,\n};\n","const MIGRATION_URL =\n 'https://github.com/FE-HyunSu/sprite-motion/blob/main/MIGRATION.md';\n\nlet warned = false;\n\nexport function warnDeprecation(packageName: string): void {\n if (warned || typeof console === 'undefined') return;\n warned = true;\n console.warn(\n `[${packageName}] This package is deprecated and will receive no further updates.\\n` +\n `Please migrate to mason-sprite: npm install mason-sprite\\n` +\n `Migration guide: ${MIGRATION_URL}`,\n );\n}\n"],"mappings":";AAAA,SAAS,QAAQ,iBAAiB;;;ACAlC,IAAM,gBACJ;AAEF,IAAI,SAAS;AAEN,SAAS,gBAAgB,aAA2B;AACzD,MAAI,UAAU,OAAO,YAAY,YAAa;AAC9C,WAAS;AACT,UAAQ;AAAA,IACN,IAAI,WAAW;AAAA;AAAA,mBAEO,aAAa;AAAA,EACrC;AACF;;;ADJA,gBAAgB,sBAAsB;AAG/B,IAAM,kBAAkB;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprite-motion/react",
3
- "version": "0.1.2",
4
- "description": "React component for sprite sheet animation",
3
+ "version": "0.2.0",
4
+ "description": "[DEPRECATED] Use mason-sprite/react instead — compatibility shim for @sprite-motion/react",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
@@ -31,17 +31,12 @@
31
31
  "bugs": {
32
32
  "url": "https://github.com/FE-HyunSu/sprite-motion/issues"
33
33
  },
34
- "scripts": {
35
- "build": "tsup",
36
- "typecheck": "tsc --noEmit",
37
- "dev": "tsup --watch"
38
- },
39
34
  "peerDependencies": {
40
35
  "react": ">=17",
41
36
  "react-dom": ">=17"
42
37
  },
43
38
  "dependencies": {
44
- "@sprite-motion/core": "workspace:*"
39
+ "mason-sprite": "0.1.1"
45
40
  },
46
41
  "devDependencies": {
47
42
  "@types/react": "^19.1.6",
@@ -59,5 +54,10 @@
59
54
  "react",
60
55
  "spritesheet"
61
56
  ],
62
- "license": "MIT"
63
- }
57
+ "license": "MIT",
58
+ "scripts": {
59
+ "build": "tsup",
60
+ "typecheck": "tsc --noEmit",
61
+ "dev": "tsup --watch"
62
+ }
63
+ }