@sprite-motion/react 0.1.1 → 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 ADDED
@@ -0,0 +1,24 @@
1
+ # @sprite-motion/react
2
+
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).
5
+
6
+ ## Migrate
7
+
8
+ ```bash
9
+ npm install mason-sprite
10
+ ```
11
+
12
+ ```tsx
13
+ // Before
14
+ import { SpriteAnimation } from '@sprite-motion/react';
15
+
16
+ // After
17
+ import { Sprite } from 'mason-sprite/react';
18
+ ```
19
+
20
+ Existing code on v0.2.0 still works — `SpriteAnimation` is aliased to `Sprite`.
21
+
22
+ ## License
23
+
24
+ MIT
package/dist/index.cjs CHANGED
@@ -20,127 +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({
87
- src,
88
- rows,
89
- cols,
90
- fps = 12,
91
- loop = true,
92
- width = 128,
93
- height = 128,
94
- autoPlay = true,
95
- renderer = "css",
96
- onComplete,
97
- onFrameChange,
98
- className,
99
- style
100
- }, ref) {
101
- const { ref: targetRef, play, pause, stop, goToFrame } = useSpriteAnimation({
102
- src,
103
- rows,
104
- cols,
105
- fps,
106
- loop,
107
- width,
108
- height,
109
- autoPlay,
110
- renderer,
111
- onComplete,
112
- onFrameChange
113
- });
114
- (0, import_react2.useImperativeHandle)(ref, () => ({ play, pause, stop, goToFrame }), [
115
- play,
116
- pause,
117
- stop,
118
- goToFrame
119
- ]);
120
- if (renderer === "canvas") {
121
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
122
- "canvas",
123
- {
124
- ref: targetRef,
125
- className,
126
- style
127
- }
128
- );
129
- }
130
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
131
- "div",
132
- {
133
- ref: targetRef,
134
- className,
135
- style,
136
- role: "img",
137
- "aria-label": "Sprite animation"
138
- }
139
- );
140
- }
141
- );
43
+ // src/index.ts
44
+ warnDeprecation("@sprite-motion/react");
45
+ var SpriteAnimation = import_react.Sprite;
142
46
  // Annotate the CommonJS export names for ESM import in node:
143
47
  0 && (module.exports = {
48
+ Sprite,
144
49
  SpriteAnimation,
145
50
  useSpriteAnimation
146
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(\n {\n src,\n rows,\n cols,\n fps = 12,\n loop = true,\n width = 128,\n height = 128,\n autoPlay = true,\n renderer = 'css',\n onComplete,\n onFrameChange,\n className,\n style,\n },\n ref,\n ) {\n const { ref: targetRef, play, pause, stop, goToFrame } = useSpriteAnimation({\n src,\n rows,\n cols,\n fps,\n loop,\n width,\n height,\n autoPlay,\n renderer,\n onComplete,\n onFrameChange,\n });\n\n useImperativeHandle(ref, () => ({ play, pause, stop, goToFrame }), [\n play,\n pause,\n stop,\n goToFrame,\n ]);\n\n if (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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riteAnimation"]}
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,119 +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({
60
- src,
61
- rows,
62
- cols,
63
- fps = 12,
64
- loop = true,
65
- width = 128,
66
- height = 128,
67
- autoPlay = true,
68
- renderer = "css",
69
- onComplete,
70
- onFrameChange,
71
- className,
72
- style
73
- }, ref) {
74
- const { ref: targetRef, play, pause, stop, goToFrame } = useSpriteAnimation({
75
- src,
76
- rows,
77
- cols,
78
- fps,
79
- loop,
80
- width,
81
- height,
82
- autoPlay,
83
- renderer,
84
- onComplete,
85
- onFrameChange
86
- });
87
- useImperativeHandle(ref, () => ({ play, pause, stop, goToFrame }), [
88
- play,
89
- pause,
90
- stop,
91
- goToFrame
92
- ]);
93
- if (renderer === "canvas") {
94
- return /* @__PURE__ */ jsx(
95
- "canvas",
96
- {
97
- ref: targetRef,
98
- className,
99
- style
100
- }
101
- );
102
- }
103
- return /* @__PURE__ */ jsx(
104
- "div",
105
- {
106
- ref: targetRef,
107
- className,
108
- style,
109
- role: "img",
110
- "aria-label": "Sprite animation"
111
- }
112
- );
113
- }
114
- );
17
+ // src/index.ts
18
+ warnDeprecation("@sprite-motion/react");
19
+ var SpriteAnimation = Sprite;
115
20
  export {
21
+ Sprite,
116
22
  SpriteAnimation,
117
- useSpriteAnimation
23
+ useSprite as useSpriteAnimation
118
24
  };
119
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(\n {\n src,\n rows,\n cols,\n fps = 12,\n loop = true,\n width = 128,\n height = 128,\n autoPlay = true,\n renderer = 'css',\n onComplete,\n onFrameChange,\n className,\n style,\n },\n ref,\n ) {\n const { ref: targetRef, play, pause, stop, goToFrame } = useSpriteAnimation({\n src,\n rows,\n cols,\n fps,\n loop,\n width,\n height,\n autoPlay,\n renderer,\n onComplete,\n onFrameChange,\n });\n\n useImperativeHandle(ref, () => ({ play, pause, stop, goToFrame }), [\n play,\n pause,\n stop,\n goToFrame,\n ]);\n\n if (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?.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,UAAU,KAAK;AAAA,EAC5D;AACF;;;ADdQ;AA1CD,IAAM,kBAAkB;AAAA,EAC7B,SAASA,iBACP;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,WAAW;AAAA,IACX,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GACA,KACA;AACA,UAAM,EAAE,KAAK,WAAW,MAAM,OAAO,MAAM,UAAU,IAAI,mBAAmB;AAAA,MAC1E;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,wBAAoB,KAAK,OAAO,EAAE,MAAM,OAAO,MAAM,UAAU,IAAI;AAAA,MACjE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,QAAI,aAAa,UAAU;AACzB,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.1",
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",
@@ -19,19 +19,24 @@
19
19
  }
20
20
  },
21
21
  "files": [
22
- "dist"
22
+ "dist",
23
+ "README.md"
23
24
  ],
24
- "scripts": {
25
- "build": "tsup",
26
- "typecheck": "tsc --noEmit",
27
- "dev": "tsup --watch"
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/FE-HyunSu/sprite-motion.git",
28
+ "directory": "packages/react"
29
+ },
30
+ "homepage": "https://github.com/FE-HyunSu/sprite-motion#readme",
31
+ "bugs": {
32
+ "url": "https://github.com/FE-HyunSu/sprite-motion/issues"
28
33
  },
29
34
  "peerDependencies": {
30
35
  "react": ">=17",
31
36
  "react-dom": ">=17"
32
37
  },
33
38
  "dependencies": {
34
- "@sprite-motion/core": "workspace:*"
39
+ "mason-sprite": "0.1.1"
35
40
  },
36
41
  "devDependencies": {
37
42
  "@types/react": "^19.1.6",
@@ -49,5 +54,10 @@
49
54
  "react",
50
55
  "spritesheet"
51
56
  ],
52
- "license": "MIT"
53
- }
57
+ "license": "MIT",
58
+ "scripts": {
59
+ "build": "tsup",
60
+ "typecheck": "tsc --noEmit",
61
+ "dev": "tsup --watch"
62
+ }
63
+ }