react-native-spritestudio-ui 0.0.0-stage → 7.0.0-beta.1

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/LICENSE.ja.md ADDED
@@ -0,0 +1,12 @@
1
+ これは BSD 3-Clause License の参考訳です。正文は英語版の [LICENSE.md](./LICENSE.md) であり、解釈に相違が生じた場合は英語版が優先します。
2
+
3
+ Copyright (c) CRI Middleware Co., Ltd.
4
+ All rights reserved.
5
+
6
+ ソースコード形式かバイナリ形式か、変更するかしないかを問わず、以下の条件を満たす場合に限り、再頒布および使用が許可されます。
7
+
8
+ 1. ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、および下記免責条項を含めること。
9
+ 2. バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の資料に、上記の著作権表示、本条件一覧、および下記免責条項を含めること。
10
+ 3. 書面による特別の許可なしに、本ソフトウェアから派生した製品の宣伝または販売促進に、CRI Middleware Co., Ltd. の名前またはコントリビューターの名前を使用してはならない。
11
+
12
+ 本ソフトウェアは、著作権者およびコントリビューターによって「現状のまま」提供されており、明示黙示を問わず、商業的な使用可能性、および特定の目的に対する適合性に関する暗黙の保証も含め、またそれに限定されない、いかなる保証もありません。著作権者もコントリビューターも、事由のいかんを問わず、損害発生の原因いかんを問わず、かつ責任の根拠が契約であるか厳格責任であるか(過失その他の)不法行為であるかを問わず、仮にそのような損害が発生する可能性を知らされていたとしても、本ソフトウェアの使用によって発生した(代替品または代用サービスの調達、使用の喪失、データの喪失、利益の喪失、業務の中断も含め、またそれに限定されない)直接損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害について、一切責任を負わないものとします。
package/LICENSE.md ADDED
@@ -0,0 +1,25 @@
1
+ Copyright (c) CRI Middleware Co., Ltd.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ 3. Neither the name of the CRI Middleware Co., Ltd. nor the names of its contributors
13
+ may be used to endorse or promote products derived from this software
14
+ without specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.ja.md ADDED
@@ -0,0 +1,41 @@
1
+ [**English**](./README.md) | [**日本語**](./README.ja.md)
2
+
3
+ # react-native-spritestudio-ui
4
+
5
+ **SpriteStudio のアニメーションを React Native アプリのボタンにします。**
6
+
7
+ `<SpriteStudioButton>` はボタンになった [`react-native-spritestudio`](https://www.npmjs.com/package/react-native-spritestudio) のビューです。押下・ホバー・キーボードのフォーカス・`disabled` のそれぞれで 1 つのアニメーションの区間を再生し、押下を一部のパーツの上だけに絞れ、reduced motion では各状態が止まります。
8
+
9
+ - 📖 **[UI ボタン](https://cri-middleware.github.io/SSPlayerForReactNative/ja/usage/ui)** — ガイド
10
+ - 📦 **[リポジトリ](https://github.com/cri-middleware/SSPlayerForReactNative)** — プレイヤー本体、ロードマップ、サンプルアプリ
11
+
12
+ ## インストール
13
+
14
+ ```bash
15
+ npx expo install react-native-spritestudio-ui
16
+ ```
17
+
18
+ `react-native-spritestudio` を同じバージョンの peer として受け取ります。先にそちらを入れて設定してください([インストール](https://cri-middleware.github.io/SSPlayerForReactNative/ja/setup/install))。
19
+
20
+ ## 使い方
21
+
22
+ 1. **状態を作ります。** 1 つのアニメーションに、状態と同じ名前のラベル(`normal`・`hover`・`pressed`・`disabled`・`focused`)を、その状態のループが始まるフレームに置きます。各状態は次のラベルの 1 フレーム手前までです。ラベルの無い状態は落とし先を再生し(`pressed` は `hover`、ほかは `normal`)、ラベルが 1 つも無ければアニメーション全体を再生します。
23
+ 2. **ボタンを作ります。**
24
+
25
+ ```tsx
26
+ import { SpriteStudioButton } from 'react-native-spritestudio-ui'
27
+
28
+ <SpriteStudioButton
29
+ source="ss/ui/start.ssab"
30
+ accessibilityLabel="Start"
31
+ hitParts={['face']}
32
+ onPress={start}
33
+ style={{ width: 240, height: 96 }}
34
+ />
35
+ ```
36
+
37
+ OS の動きを減らす設定(iOS の「視差効果を減らす」、Android の「アニメーションを削除」)が有効なら、各状態は先頭フレームで止まります。ただしアニメーションに `reduced_motion` ラベルがあれば、`normal` と `normal` に落ちてくる状態は代わりにその区間を再生します。`accessibilityLabel` が無ければ、ボタンはスクリーンリーダーにとって装飾です。
38
+
39
+ ## ライセンス
40
+
41
+ BSD-3-Clause — [LICENSE.md](./LICENSE.md)(参考訳: [LICENSE.ja.md](./LICENSE.ja.md))を参照してください。
package/README.md CHANGED
@@ -1,3 +1,41 @@
1
- # Temporary Holding Version
1
+ [**English**](./README.md) | [**日本語**](./README.ja.md)
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
+ # react-native-spritestudio-ui
4
+
5
+ **A SpriteStudio animation as a button in a React Native app.**
6
+
7
+ `<SpriteStudioButton>` is a [`react-native-spritestudio`](https://www.npmjs.com/package/react-native-spritestudio) view that is a button: press, hover, keyboard focus and `disabled` each play a section of one animation, a press can be made to count only on some of its parts, and under reduced motion each state holds still.
8
+
9
+ - 📖 **[UI buttons](https://cri-middleware.github.io/SSPlayerForReactNative/usage/ui)** — the guide
10
+ - 📦 **[Repository](https://github.com/cri-middleware/SSPlayerForReactNative)** — the player, the roadmap and the example app
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npx expo install react-native-spritestudio-ui
16
+ ```
17
+
18
+ It takes `react-native-spritestudio` as a peer at the same version — install and set that up first ([Installation](https://cri-middleware.github.io/SSPlayerForReactNative/setup/install)).
19
+
20
+ ## Use
21
+
22
+ 1. **Author the states** in one animation: a label named after each state — `normal`, `hover`, `pressed`, `disabled`, `focused` — where that state's loop starts. Each runs to the frame before the next label. A state without a label falls back (`pressed` to `hover`, the rest to `normal`), and with no labels at all the whole animation plays.
23
+ 2. **Make the button:**
24
+
25
+ ```tsx
26
+ import { SpriteStudioButton } from 'react-native-spritestudio-ui'
27
+
28
+ <SpriteStudioButton
29
+ source="ss/ui/start.ssab"
30
+ accessibilityLabel="Start"
31
+ hitParts={['face']}
32
+ onPress={start}
33
+ style={{ width: 240, height: 96 }}
34
+ />
35
+ ```
36
+
37
+ Under the system's reduce motion setting (Reduce Motion on iOS, Remove animations on Android) each state holds its first frame; `normal`, and the states that fall back to it, play a `reduced_motion` label instead when the animation has one. Without `accessibilityLabel` the button is decoration to a screen reader.
38
+
39
+ ## License
40
+
41
+ BSD-3-Clause — see [LICENSE.md](./LICENSE.md).
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+
3
+ import { forwardRef, useEffect, useMemo, useRef, useState } from 'react';
4
+ import { AccessibilityInfo, Pressable, StyleSheet, View } from 'react-native';
5
+ import { SpriteStudioView, useSsViewPlayer } from 'react-native-spritestudio';
6
+ import { SsUiStateDriver, ssUiStateOf } from "./uiState.js";
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ const VIEW_PROPS = {
9
+ source: true,
10
+ textures: true,
11
+ animation: true,
12
+ speed: true,
13
+ fit: true,
14
+ frame: true,
15
+ frameScope: true,
16
+ measureFrames: true,
17
+ parts: true,
18
+ onUserData: true,
19
+ onAudio: true,
20
+ onSignal: true,
21
+ onLoad: true,
22
+ onError: true,
23
+ onAnimationFinished: true,
24
+ onAnimationLooped: true,
25
+ onAnimationStarted: true,
26
+ onAnimationChanged: true,
27
+ align: true,
28
+ flipX: true,
29
+ flipY: true,
30
+ offset: true,
31
+ scale: true,
32
+ style: true,
33
+ placeholder: true
34
+ };
35
+
36
+ /**
37
+ * The props of a `<SpriteStudioView>` that still mean something on a button —
38
+ * `animation` is where the states' labels are read from — and those of a
39
+ * `<Pressable>`, which the button is. The playback props are the button's.
40
+ */
41
+
42
+ function ownViewProps(props) {
43
+ const view = {};
44
+ const rest = {};
45
+ for (const [key, value] of Object.entries(props)) {
46
+ if (key in VIEW_PROPS) view[key] = value;else rest[key] = value;
47
+ }
48
+ return {
49
+ view: view,
50
+ rest
51
+ };
52
+ }
53
+ function useSystemReducedMotion(active) {
54
+ const [enabled, setEnabled] = useState(null);
55
+ useEffect(() => {
56
+ if (!active) return;
57
+ let live = true;
58
+ AccessibilityInfo.isReduceMotionEnabled().then(value => {
59
+ if (live) setEnabled(value);
60
+ }, () => {
61
+ if (live) setEnabled(false);
62
+ });
63
+ const subscription = AccessibilityInfo.addEventListener('reduceMotionChanged', setEnabled);
64
+ return () => {
65
+ live = false;
66
+ subscription.remove();
67
+ };
68
+ }, [active]);
69
+ return enabled;
70
+ }
71
+ function ButtonSurface(props) {
72
+ const {
73
+ animation,
74
+ clips,
75
+ hitParts,
76
+ hitOnArtwork = false,
77
+ reducedMotion,
78
+ disabled,
79
+ onPressIn,
80
+ onPressOut,
81
+ onHoverIn,
82
+ onHoverOut,
83
+ onFocus,
84
+ onBlur,
85
+ ...pressable
86
+ } = props;
87
+ const player = useSsViewPlayer();
88
+ const [pressed, setPressed] = useState(false);
89
+ const [hovered, setHovered] = useState(false);
90
+ const [focused, setFocused] = useState(false);
91
+ const system = useSystemReducedMotion(reducedMotion == null);
92
+ const reduced = reducedMotion ?? system;
93
+ useEffect(() => {
94
+ if (disabled) setPressed(false);
95
+ }, [disabled]);
96
+ const clipsKey = clips == null ? '' : JSON.stringify(clips);
97
+ const driver = useMemo(() => player == null ? null : new SsUiStateDriver(player, {
98
+ animation,
99
+ clips
100
+ }),
101
+ // eslint-disable-next-line react-hooks/exhaustive-deps
102
+ [player, animation, clipsKey]);
103
+ const state = ssUiStateOf({
104
+ disabled: disabled ?? false,
105
+ pressed,
106
+ hovered,
107
+ focused
108
+ });
109
+ const shown = useRef({
110
+ driver,
111
+ state,
112
+ reduced
113
+ });
114
+ shown.current = {
115
+ driver,
116
+ state,
117
+ reduced
118
+ };
119
+ useEffect(() => {
120
+ if (driver == null || reduced == null) return;
121
+ driver.show(state, reduced);
122
+ }, [driver, state, reduced]);
123
+ useEffect(() => {
124
+ if (player == null) return;
125
+ return player.addListener(() => {
126
+ const {
127
+ driver: current,
128
+ state: now,
129
+ reduced: still
130
+ } = shown.current;
131
+ if (current != null && still != null) current.show(now, still);
132
+ });
133
+ }, [player]);
134
+ const narrows = hitParts != null || hitOnArtwork;
135
+ const refuse = event => {
136
+ if (player == null) return false;
137
+ const {
138
+ locationX,
139
+ locationY
140
+ } = event.nativeEvent;
141
+ return player.hitTestPart(locationX, locationY, hitParts) < 0;
142
+ };
143
+ const labelled = pressable.accessibilityLabel != null || pressable['aria-label'] != null;
144
+ const accessibility = labelled ? {
145
+ accessibilityRole: 'button'
146
+ } : {
147
+ accessible: false,
148
+ importantForAccessibility: 'no-hide-descendants'
149
+ };
150
+ return /*#__PURE__*/_jsx(View, {
151
+ style: StyleSheet.absoluteFill,
152
+ onStartShouldSetResponderCapture: narrows ? refuse : undefined,
153
+ children: /*#__PURE__*/_jsx(Pressable, {
154
+ ...accessibility,
155
+ ...pressable,
156
+ style: StyleSheet.absoluteFill,
157
+ disabled: disabled,
158
+ onPressIn: event => {
159
+ setPressed(true);
160
+ onPressIn?.(event);
161
+ },
162
+ onPressOut: event => {
163
+ setPressed(false);
164
+ onPressOut?.(event);
165
+ },
166
+ onHoverIn: event => {
167
+ setHovered(true);
168
+ onHoverIn?.(event);
169
+ },
170
+ onHoverOut: event => {
171
+ setHovered(false);
172
+ onHoverOut?.(event);
173
+ },
174
+ onFocus: event => {
175
+ setFocused(true);
176
+ onFocus?.(event);
177
+ },
178
+ onBlur: event => {
179
+ setFocused(false);
180
+ onBlur?.(event);
181
+ }
182
+ })
183
+ });
184
+ }
185
+
186
+ /**
187
+ * A `<SpriteStudioView>` that is a button: a `<Pressable>` over the view's box
188
+ * whose states each play a section of one animation.
189
+ *
190
+ * Pressed, hovered, focused and `disabled` map to `pressed`, `hover`, `focused`
191
+ * and `disabled`, one at a time in that order of precedence, and none of them
192
+ * to `normal`. Each state plays, looping, from the label of its name to the
193
+ * frame before the next label; a state without a label falls back — `pressed`
194
+ * to `hover`, the rest to `normal` — and with no labels the whole animation
195
+ * plays. Under reduced motion each state holds its first frame, and `normal`
196
+ * plays a `reduced_motion` label instead when the animation has one.
197
+ *
198
+ * Without an `accessibilityLabel` it is decoration to a screen reader; with
199
+ * one it is read as a button.
200
+ *
201
+ * It takes its player's playback over: `playing`, `loop` and `transitionMs`
202
+ * are not props here, and the player from the ref is not one to play or stop.
203
+ */
204
+ export const SpriteStudioButton = /*#__PURE__*/forwardRef(function SpriteStudioButton(props, ref) {
205
+ const {
206
+ view,
207
+ rest
208
+ } = ownViewProps(props);
209
+ return /*#__PURE__*/_jsx(SpriteStudioView, {
210
+ ...view,
211
+ ref: ref,
212
+ playing: false,
213
+ children: /*#__PURE__*/_jsx(ButtonSurface, {
214
+ ...rest,
215
+ animation: view.animation
216
+ })
217
+ });
218
+ });
219
+ //# sourceMappingURL=SpriteStudioButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["forwardRef","useEffect","useMemo","useRef","useState","AccessibilityInfo","Pressable","StyleSheet","View","SpriteStudioView","useSsViewPlayer","SsUiStateDriver","ssUiStateOf","jsx","_jsx","VIEW_PROPS","source","textures","animation","speed","fit","frame","frameScope","measureFrames","parts","onUserData","onAudio","onSignal","onLoad","onError","onAnimationFinished","onAnimationLooped","onAnimationStarted","onAnimationChanged","align","flipX","flipY","offset","scale","style","placeholder","ownViewProps","props","view","rest","key","value","Object","entries","useSystemReducedMotion","active","enabled","setEnabled","live","isReduceMotionEnabled","then","subscription","addEventListener","remove","ButtonSurface","clips","hitParts","hitOnArtwork","reducedMotion","disabled","onPressIn","onPressOut","onHoverIn","onHoverOut","onFocus","onBlur","pressable","player","pressed","setPressed","hovered","setHovered","focused","setFocused","system","reduced","clipsKey","JSON","stringify","driver","state","shown","current","show","addListener","now","still","narrows","refuse","event","locationX","locationY","nativeEvent","hitTestPart","labelled","accessibilityLabel","accessibility","accessibilityRole","accessible","importantForAccessibility","absoluteFill","onStartShouldSetResponderCapture","undefined","children","SpriteStudioButton","ref","playing"],"sourceRoot":"../../src","sources":["SpriteStudioButton.tsx"],"mappings":";;AAAA,SAASA,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAA2B,OAAO;AAC3F,SACEC,iBAAiB,EACjBC,SAAS,EACTC,UAAU,EACVC,IAAI,QAGC,cAAc;AACrB,SACEC,gBAAgB,EAChBC,eAAe,QAGV,2BAA2B;AAElC,SAASC,eAAe,EAAEC,WAAW,QAAwB,cAAW;AAAA,SAAAC,GAAA,IAAAC,IAAA;AA+BxE,MAAMC,UAAiD,GAAG;EACxDC,MAAM,EAAE,IAAI;EACZC,QAAQ,EAAE,IAAI;EACdC,SAAS,EAAE,IAAI;EACfC,KAAK,EAAE,IAAI;EACXC,GAAG,EAAE,IAAI;EACTC,KAAK,EAAE,IAAI;EACXC,UAAU,EAAE,IAAI;EACh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B,KAAK,IAAK;QAClBhB,UAAU,CAAC,IAAI,CAAC;QAChBT,OAAO,GAAGyB,KAAK,CAAC;MAClB,CAAE;MACFxB,MAAM,EAAGwB,KAAK,IAAK;QACjBhB,UAAU,CAAC,KAAK,CAAC;QACjBR,MAAM,GAAGwB,KAAK,CAAC;MACjB;IAAE,CACH;EAAC,CACE,CAAC;AAEX;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMe,kBAAkB,gBAAG7G,UAAU,CAC1C,SAAS6G,kBAAkBA,CAACnE,KAAK,EAAEoE,GAAG,EAAE;EACtC,MAAM;IAAEnE,IAAI;IAAEC;EAAK,CAAC,GAAGH,YAAY,CAACC,KAAK,CAAC;EAC1C,oBACE5B,IAAA,CAACL,gBAAgB;IAAA,GAAKkC,IAAI;IAAEmE,GAAG,EAAEA,GAAI;IAACC,OAAO,EAAE,KAAM;IAAAH,QAAA,eACnD9F,IAAA,CAAC6C,aAAa;MAAA,GAAMf,IAAI;MAAmB1B,SAAS,EAAEyB,IAAI,CAACzB;IAAU,CAAE;EAAC,CACxD,CAAC;AAEvB,CACF,CAAC","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ export { SpriteStudioButton } from "./SpriteStudioButton.js";
4
+ export { SsUiStateDriver, ssUiStateOf } from "./uiState.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["SpriteStudioButton","SsUiStateDriver","ssUiStateOf"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,kBAAkB,QAAsC,yBAAsB;AACvF,SACEC,eAAe,EACfC,WAAW,QAKN,cAAW","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * A state a SpriteStudio button shows. By default each plays from the label of
5
+ * the same name in one animation, up to the frame before the next label.
6
+ */
7
+
8
+ /**
9
+ * The one state to show when several hold at once: `disabled` over `pressed`
10
+ * over `hover` over `focused`, and `normal` when none does.
11
+ */
12
+ export function ssUiStateOf(flags) {
13
+ if (flags.disabled) return 'disabled';
14
+ if (flags.pressed) return 'pressed';
15
+ if (flags.hovered) return 'hover';
16
+ if (flags.focused) return 'focused';
17
+ return 'normal';
18
+ }
19
+ const CHAINS = {
20
+ normal: ['normal'],
21
+ hover: ['hover', 'normal'],
22
+ pressed: ['pressed', 'hover', 'normal'],
23
+ disabled: ['disabled', 'normal'],
24
+ focused: ['focused', 'normal']
25
+ };
26
+
27
+ /**
28
+ * What a state plays instead of the label named after it: the section of
29
+ * `animation` that starts at `label`.
30
+ *
31
+ * With only `animation`, the whole of it. With only `label`, that label in the
32
+ * animation the states are read from. A section runs to the frame before the
33
+ * next label, or to the end of the animation.
34
+ */
35
+
36
+ /** Per-state replacements for the labels named after the states. */
37
+
38
+ export const SS_REDUCED_MOTION_LABEL = 'reduced_motion';
39
+
40
+ /** A section a state plays, and whether to hold its first frame rather than play it. */
41
+
42
+ function labelFrameOf(table, label) {
43
+ for (const entry of table.labels) {
44
+ if (entry.name === label) return entry.frame;
45
+ }
46
+ if (label === '_start') return table.startFrame;
47
+ if (label === '_end') return table.endFrame;
48
+ return null;
49
+ }
50
+
51
+ /**
52
+ * The section starting at `label` in `table`: to the frame before the next
53
+ * label — any label, the state names or not — or to the end of the animation.
54
+ * Null when the table has no `label`.
55
+ */
56
+ export function labelSectionOf(table, label) {
57
+ const start = labelFrameOf(table, label);
58
+ if (start == null) return null;
59
+ for (const entry of table.labels) {
60
+ if (entry.frame > start) return {
61
+ startFrame: start,
62
+ endFrame: entry.frame - 1
63
+ };
64
+ }
65
+ return {
66
+ startFrame: start,
67
+ endFrame: table.endFrame
68
+ };
69
+ }
70
+
71
+ /**
72
+ * The section `state` plays in `animation`: the first of its chain that has a
73
+ * clip in `clips` or a label of its own name, or else the whole animation.
74
+ * Null when `tableOf` knows no `animation`.
75
+ *
76
+ * Under `reducedMotion` the section is held, except where it came from
77
+ * `normal` (or the whole animation `normal` falls back to) and `animation` has a
78
+ * `reduced_motion` label: that label's section plays instead.
79
+ *
80
+ * A clip that names an animation or a label the pack does not have is handed
81
+ * to `onMissingClip`, and the state goes on as if it had none.
82
+ */
83
+ export function resolveUiSection(state, options) {
84
+ const {
85
+ animation,
86
+ tableOf,
87
+ clips = {},
88
+ reducedMotion = false,
89
+ onMissingClip
90
+ } = options;
91
+ const base = tableOf(animation);
92
+ if (base == null) return null;
93
+ let name = animation;
94
+ let range = null;
95
+ let source = null;
96
+ for (const s of CHAINS[state]) {
97
+ const clip = clips[s];
98
+ if (clip != null) {
99
+ const clipName = clip.animation ?? animation;
100
+ const table = clipName === animation ? base : tableOf(clipName);
101
+ range = table == null ? null : clip.label == null ? {
102
+ startFrame: table.startFrame,
103
+ endFrame: table.endFrame
104
+ } : labelSectionOf(table, clip.label);
105
+ if (range != null) {
106
+ name = clipName;
107
+ source = s;
108
+ break;
109
+ }
110
+ onMissingClip?.(s, clip);
111
+ }
112
+ range = labelSectionOf(base, s);
113
+ if (range != null) {
114
+ source = s;
115
+ break;
116
+ }
117
+ }
118
+ range ??= {
119
+ startFrame: base.startFrame,
120
+ endFrame: base.endFrame
121
+ };
122
+ if (reducedMotion && (source === 'normal' || source === null)) {
123
+ const calm = labelSectionOf(base, SS_REDUCED_MOTION_LABEL);
124
+ if (calm != null) return {
125
+ animation,
126
+ ...calm,
127
+ hold: false
128
+ };
129
+ }
130
+ return {
131
+ animation: name,
132
+ ...range,
133
+ hold: reducedMotion
134
+ };
135
+ }
136
+
137
+ /**
138
+ * Plays the section an {@link SsUiState} calls for on a `player` the host owns.
139
+ *
140
+ * {@link show} switches at once and plays the new section from its first
141
+ * frame, looping; the section that was playing is dropped. Under reduced
142
+ * motion it holds the section's first frame instead, stopped, so no event
143
+ * fires — except that `normal`, and the states that fall back to it, play the
144
+ * `reduced_motion` label's section when the animation has one.
145
+ *
146
+ * It takes the player's playback over: it selects animations, sets sections
147
+ * and the loop count, and plays and stops.
148
+ */
149
+ export class SsUiStateDriver {
150
+ /**
151
+ * The animation the states' labels are read from. When omitted, the one the
152
+ * player has selected the first time a state is shown, or else the pack's
153
+ * first.
154
+ */
155
+
156
+ base = null;
157
+ shownOn = null;
158
+ shownAnimation = null;
159
+ current = null;
160
+ reduced = false;
161
+ reported = new Set();
162
+ constructor(player, options = {}) {
163
+ this.player = player;
164
+ this.animation = options.animation;
165
+ this.clips = options.clips ?? {};
166
+ }
167
+
168
+ /** The state last shown, or null before one has been. */
169
+ get state() {
170
+ return this.current;
171
+ }
172
+
173
+ /**
174
+ * Shows `state` — or nothing before the player has loaded a pack.
175
+ *
176
+ * Showing the state already shown, with the same `reducedMotion`, does
177
+ * nothing while the player still has the pack and the animation it was
178
+ * given, so it can be called on every change the player announces. After
179
+ * another load, or a switch made elsewhere, it shows the state again.
180
+ */
181
+ show(state, reducedMotion = false) {
182
+ const player = this.player;
183
+ const internal = player.internal;
184
+ if (internal == null) return;
185
+ if (internal === this.shownOn && state === this.current && reducedMotion === this.reduced && player.currentAnimation === this.shownAnimation) {
186
+ return;
187
+ }
188
+ this.shownOn = internal;
189
+ this.current = state;
190
+ this.reduced = reducedMotion;
191
+ const names = player.getAnimationNames();
192
+ const base = this.base != null && names.includes(this.base) ? this.base : this.animation ?? player.currentAnimation ?? names[0];
193
+ if (base == null) return;
194
+ this.base = base;
195
+ const section = resolveUiSection(state, {
196
+ animation: base,
197
+ tableOf: name => player.getLabelTable(name),
198
+ clips: this.clips,
199
+ reducedMotion,
200
+ onMissingClip: (s, clip) => this.reportMissingClip(s, clip)
201
+ });
202
+ if (section == null) {
203
+ player.setAnimation(base);
204
+ return;
205
+ }
206
+ this.shownAnimation = section.animation;
207
+ if (!player.setAnimation(section.animation)) {
208
+ this.shownAnimation = null;
209
+ return;
210
+ }
211
+ player.setAnimationSection(section.startFrame, section.endFrame);
212
+ if (section.hold) {
213
+ player.stop();
214
+ } else {
215
+ player.setLoopCount(0);
216
+ player.play();
217
+ }
218
+ }
219
+ reportMissingClip(state, clip) {
220
+ const key = `${state}|${clip.animation ?? ''}|${clip.label ?? ''}`;
221
+ if (this.reported.has(key)) return;
222
+ this.reported.add(key);
223
+ const what = [clip.animation != null ? `animation '${clip.animation}'` : null, clip.label != null ? `label '${clip.label}'` : null].filter(part => part != null).join(' with ');
224
+ console.warn(`react-native-spritestudio-ui: the clip for ${state} names ${what}, which the loaded ` + `pack does not have, so ${state} plays as if it had none.`);
225
+ }
226
+ }
227
+ //# sourceMappingURL=uiState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ssUiStateOf","flags","disabled","pressed","hovered","focused","CHAINS","normal","hover","SS_REDUCED_MOTION_LABEL","labelFrameOf","table","label","entry","labels","name","frame","startFrame","endFrame","labelSectionOf","start","resolveUiSection","state","options","animation","tableOf","clips","reducedMotion","onMissingClip","base","range","source","s","clip","clipName","calm","hold","SsUiStateDriver","shownOn","shownAnimation","current","reduced","reported","Set","constructor","player","show","internal","currentAnimation","names","getAnimationNames","includes","section","getLabelTable","reportMissingClip","setAnimation","setAnimationSection","stop","setLoopCount","play","key","has","add","what","filter","part","join","console","warn"],"sourceRoot":"../../src","sources":["uiState.ts"],"mappings":";;AAEA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA,OAAO,SAASA,WAAWA,CAACC,KAK3B,EAAa;EACZ,IAAIA,KAAK,CAACC,QAAQ,EAAE,OAAO,UAAU;EACrC,IAAID,KAAK,CAACE,OAAO,EAAE,OAAO,SAAS;EACnC,IAAIF,KAAK,CAACG,OAAO,EAAE,OAAO,OAAO;EACjC,IAAIH,KAAK,CAACI,OAAO,EAAE,OAAO,SAAS;EACnC,OAAO,QAAQ;AACjB;AAEA,MAAMC,MAAyD,GAAG;EAChEC,MAAM,EAAE,CAAC,QAAQ,CAAC;EAClBC,KAAK,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;EAC1BL,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cAAc,GAAG,IAAI;MAC1B;IACF;IACAM,MAAM,CAACW,mBAAmB,CAACJ,OAAO,CAACnC,UAAU,EAAEmC,OAAO,CAAClC,QAAQ,CAAC;IAChE,IAAIkC,OAAO,CAAChB,IAAI,EAAE;MAChBS,MAAM,CAACY,IAAI,CAAC,CAAC;IACf,CAAC,MAAM;MACLZ,MAAM,CAACa,YAAY,CAAC,CAAC,CAAC;MACtBb,MAAM,CAACc,IAAI,CAAC,CAAC;IACf;EACF;EAEQL,iBAAiBA,CAAChC,KAAgB,EAAEW,IAAc,EAAQ;IAChE,MAAM2B,GAAG,GAAG,GAAGtC,KAAK,IAAIW,IAAI,CAACT,SAAS,IAAI,EAAE,IAAIS,IAAI,CAACrB,KAAK,IAAI,EAAE,EAAE;IAClE,IAAI,IAAI,CAAC8B,QAAQ,CAACmB,GAAG,CAACD,GAAG,CAAC,EAAE;IAC5B,IAAI,CAAClB,QAAQ,CAACoB,GAAG,CAACF,GAAG,CAAC;IACtB,MAAMG,IAAI,GAAG,CACX9B,IAAI,CAACT,SAAS,IAAI,IAAI,GAAG,cAAcS,IAAI,CAACT,SAAS,GAAG,GAAG,IAAI,EAC/DS,IAAI,CAACrB,KAAK,IAAI,IAAI,GAAG,UAAUqB,IAAI,CAACrB,KAAK,GAAG,GAAG,IAAI,CACpD,CACEoD,MAAM,CAAEC,IAAI,IAAKA,IAAI,IAAI,IAAI,CAAC,CAC9BC,IAAI,CAAC,QAAQ,CAAC;IACjBC,OAAO,CAACC,IAAI,CACV,8CAA8C9C,KAAK,UAAUyC,IAAI,qBAAqB,GACpF,0BAA0BzC,KAAK,2BACnC,CAAC;EACH;AACF","ignoreList":[]}
@@ -0,0 +1,45 @@
1
+ import { type PressableProps } from 'react-native';
2
+ import { type SpriteStudioViewProps, type SpriteStudioViewRef } from 'react-native-spritestudio';
3
+ import { type SsUiClips } from './uiState.js';
4
+ type SsButtonViewProps = Pick<SpriteStudioViewProps, 'source' | 'textures' | 'animation' | 'speed' | 'fit' | 'frame' | 'frameScope' | 'measureFrames' | 'parts' | 'onUserData' | 'onAudio' | 'onSignal' | 'onLoad' | 'onError' | 'onAnimationFinished' | 'onAnimationLooped' | 'onAnimationStarted' | 'onAnimationChanged' | 'align' | 'flipX' | 'flipY' | 'offset' | 'scale' | 'style' | 'placeholder'>;
5
+ /**
6
+ * The props of a `<SpriteStudioView>` that still mean something on a button —
7
+ * `animation` is where the states' labels are read from — and those of a
8
+ * `<Pressable>`, which the button is. The playback props are the button's.
9
+ */
10
+ export interface SpriteStudioButtonProps extends SsButtonViewProps, Omit<PressableProps, 'style' | 'children'> {
11
+ /** Per-state replacements for the labels named after the states. */
12
+ clips?: SsUiClips;
13
+ /**
14
+ * The parts a press counts on, by name or index: a touch that starts on
15
+ * none of their outlines is not a press. Omitted, the whole box takes one.
16
+ * Only touches are narrowed — keyboard focus and a screen reader's
17
+ * activation reach the button as before.
18
+ */
19
+ hitParts?: ReadonlyArray<string | number>;
20
+ /** With no `hitParts`, whether a press counts on any part with an outline rather than on the whole box. */
21
+ hitOnArtwork?: boolean;
22
+ /** Whether to hold still. Omitted, it follows the system's reduce motion setting. */
23
+ reducedMotion?: boolean;
24
+ }
25
+ /**
26
+ * A `<SpriteStudioView>` that is a button: a `<Pressable>` over the view's box
27
+ * whose states each play a section of one animation.
28
+ *
29
+ * Pressed, hovered, focused and `disabled` map to `pressed`, `hover`, `focused`
30
+ * and `disabled`, one at a time in that order of precedence, and none of them
31
+ * to `normal`. Each state plays, looping, from the label of its name to the
32
+ * frame before the next label; a state without a label falls back — `pressed`
33
+ * to `hover`, the rest to `normal` — and with no labels the whole animation
34
+ * plays. Under reduced motion each state holds its first frame, and `normal`
35
+ * plays a `reduced_motion` label instead when the animation has one.
36
+ *
37
+ * Without an `accessibilityLabel` it is decoration to a screen reader; with
38
+ * one it is read as a button.
39
+ *
40
+ * It takes its player's playback over: `playing`, `loop` and `transitionMs`
41
+ * are not props here, and the player from the ref is not one to play or stop.
42
+ */
43
+ export declare const SpriteStudioButton: import("react").ForwardRefExoticComponent<SpriteStudioButtonProps & import("react").RefAttributes<SpriteStudioViewRef>>;
44
+ export {};
45
+ //# sourceMappingURL=SpriteStudioButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpriteStudioButton.d.ts","sourceRoot":"","sources":["../../src/SpriteStudioButton.tsx"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,cAAc,EACpB,MAAM,cAAc,CAAA;AACrB,OAAO,EAGL,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACzB,MAAM,2BAA2B,CAAA;AAElC,OAAO,EAAgC,KAAK,SAAS,EAAE,MAAM,cAAW,CAAA;AAExE,KAAK,iBAAiB,GAAG,IAAI,CAC3B,qBAAqB,EACnB,QAAQ,GACR,UAAU,GACV,WAAW,GACX,OAAO,GACP,KAAK,GACL,OAAO,GACP,YAAY,GACZ,eAAe,GACf,OAAO,GACP,YAAY,GACZ,SAAS,GACT,UAAU,GACV,QAAQ,GACR,SAAS,GACT,qBAAqB,GACrB,mBAAmB,GACnB,oBAAoB,GACpB,oBAAoB,GACpB,OAAO,GACP,OAAO,GACP,OAAO,GACP,QAAQ,GACR,OAAO,GACP,OAAO,GACP,aAAa,CAChB,CAAA;AA8BD;;;;GAIG;AACH,MAAM,WAAW,uBACf,SAAQ,iBAAiB,EACvB,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,UAAU,CAAC;IAC5C,oEAAoE;IACpE,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;IACzC,2GAA2G;IAC3G,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,qFAAqF;IACrF,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAoJD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,kBAAkB,yHAS9B,CAAA"}