@futaba-soft/turnbox-vue 0.0.0-stage → 0.5.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 futaba-soft
4
+ Based on turnBox.js (https://github.com/nohtcoltd/turnbox_js) by NOHT CO.,LTD., MIT licensed.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,120 @@
1
- # Temporary Holding Version
1
+ # @futaba-soft/turnbox-vue
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
+ Vue adapter for TURNBOX.js. Compound component and `useTurnBox` composable.
4
+
5
+ Requires Vue 3 or later.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @futaba-soft/turnbox-vue
11
+ ```
12
+
13
+ ## Compound Component
14
+
15
+ ```vue
16
+ <template>
17
+ <TurnBox.Root :faces="2" :duration="400">
18
+ <TurnBox.Face>
19
+ Front<TurnBox.Button>Flip</TurnBox.Button>
20
+ </TurnBox.Face>
21
+ <TurnBox.Face>
22
+ <TurnBox.Button direction="prev">Flip back</TurnBox.Button>Back
23
+ </TurnBox.Face>
24
+ </TurnBox.Root>
25
+ </template>
26
+
27
+ <script setup>
28
+ import { TurnBox } from "@futaba-soft/turnbox-vue";
29
+ </script>
30
+ ```
31
+
32
+ ### External control via ref
33
+
34
+ ```vue
35
+ <template>
36
+ <TurnBox.Root :faces="4" :duration="400" :ref="handle">
37
+ <TurnBox.Face>Face 1</TurnBox.Face>
38
+ <TurnBox.Face>Face 2</TurnBox.Face>
39
+ <TurnBox.Face>Face 3</TurnBox.Face>
40
+ <TurnBox.Face>Face 4</TurnBox.Face>
41
+ </TurnBox.Root>
42
+ <button @click="handle?.next()">Next</button>
43
+ <button @click="handle?.prev()">Back</button>
44
+ </template>
45
+
46
+ <script setup>
47
+ import { ref } from "vue";
48
+ import { TurnBox, type TurnBoxRootHandle } from "@futaba-soft/turnbox-vue";
49
+
50
+ const handle = ref<TurnBoxRootHandle | null>(null);
51
+ </script>
52
+ ```
53
+
54
+ ### TurnBoxRootHandle
55
+
56
+ | Method | Description |
57
+ | --- | --- |
58
+ | `next()` | Go to the next face |
59
+ | `prev()` | Go to the previous face |
60
+ | `goTo(face, animation?)` | Go to the specified face (`animation` defaults to `true`) |
61
+ | `getCurrentFace()` | Current face number (1-based) |
62
+ | `isAnimating()` | Whether an animation is in progress |
63
+
64
+ ### TurnBox.Button props
65
+
66
+ | Prop | Type | Default | Description |
67
+ | --- | --- | --- | --- |
68
+ | `direction` | `"next" \| "prev"` | `"next"` | Go to the next or previous face |
69
+ | `to` | `number` | | Jump to a specific face (takes priority over `direction`) |
70
+
71
+ Forwards standard attrs (`class`, `style`, etc.) to the native `<button>`.
72
+
73
+ ## useTurnBox composable
74
+
75
+ ```vue
76
+ <script setup>
77
+ import { useTurnBox } from "@futaba-soft/turnbox-vue";
78
+
79
+ const { containerRef, currentFace, isAnimating, next, prev, goTo } = useTurnBox({
80
+ faces: 2,
81
+ duration: 400,
82
+ });
83
+ </script>
84
+
85
+ <template>
86
+ <div ref="containerRef">
87
+ <div>Front</div>
88
+ <div>Back</div>
89
+ </div>
90
+ </template>
91
+ ```
92
+
93
+ ### UseTurnBoxReturn
94
+
95
+ | Field | Type | Description |
96
+ | --- | --- | --- |
97
+ | `containerRef` | `Ref<HTMLElement \| null>` | Attach to the container element |
98
+ | `currentFace` | `Ref<number>` | Current face number (1-based) |
99
+ | `isAnimating` | `Ref<boolean>` | Whether an animation is in progress |
100
+ | `next()` | `() => void` | Go to the next face |
101
+ | `prev()` | `() => void` | Go to the previous face |
102
+ | `goTo(face, animation?)` | `(face: number, animation?: boolean) => void` | Go to the specified face |
103
+
104
+ ## TurnBox.Provider
105
+
106
+ Use `TurnBox.Provider` to override [`reduceAnimation`](../../README.md#reduceanimation--accessibility-setting) for a subtree. Without a Provider the default is `"system setting"`.
107
+
108
+ ```vue
109
+ <TurnBox.Provider reduce-animation="never">
110
+ <App />
111
+ </TurnBox.Provider>
112
+ ```
113
+
114
+ ## Options
115
+
116
+ See [shared options](../../README.md#options).
117
+
118
+ ## License
119
+
120
+ MIT
@@ -0,0 +1,180 @@
1
+ import * as vue from 'vue';
2
+ import { Ref, CSSProperties } from 'vue';
3
+ import * as _futaba_soft_turnbox_core from '@futaba-soft/turnbox-core';
4
+ import { TurnBoxOptions } from '@futaba-soft/turnbox-core';
5
+ export { TurnBoxOptions } from '@futaba-soft/turnbox-core';
6
+
7
+ type UseTurnBoxReturn = {
8
+ containerRef: Ref<HTMLElement | null>;
9
+ currentFace: Ref<number>;
10
+ isAnimating: Ref<boolean>;
11
+ goTo(face: number, animation?: boolean): void;
12
+ next(): void;
13
+ prev(): void;
14
+ };
15
+ declare const useTurnBox: (options: TurnBoxOptions) => UseTurnBoxReturn;
16
+
17
+ type FaceProps = {
18
+ style?: CSSProperties;
19
+ class?: string;
20
+ };
21
+
22
+ type ButtonProps = {
23
+ direction?: "next" | "prev";
24
+ to?: number;
25
+ };
26
+
27
+ type TurnBoxRootHandle = {
28
+ goTo(face: number, animation?: boolean): void;
29
+ getCurrentFace(): number;
30
+ isAnimating(): boolean;
31
+ next(): void;
32
+ prev(): void;
33
+ };
34
+
35
+ declare const TurnBox: {
36
+ Root: vue.DefineComponent<vue.ExtractPropTypes<{
37
+ faces: {
38
+ type: vue.PropType<2 | 3 | 4>;
39
+ required: true;
40
+ };
41
+ axis: {
42
+ type: vue.PropType<"X" | "Y">;
43
+ };
44
+ direction: {
45
+ type: vue.PropType<"positive" | "negative">;
46
+ };
47
+ type: {
48
+ type: vue.PropType<"real" | "repeat" | "skip">;
49
+ };
50
+ duration: {
51
+ type: NumberConstructor;
52
+ };
53
+ delay: {
54
+ type: NumberConstructor;
55
+ };
56
+ easing: {
57
+ type: StringConstructor;
58
+ };
59
+ perspective: {
60
+ type: NumberConstructor;
61
+ };
62
+ width: {
63
+ type: NumberConstructor;
64
+ };
65
+ height: {
66
+ type: NumberConstructor;
67
+ };
68
+ even: {
69
+ type: NumberConstructor;
70
+ };
71
+ onChange: {
72
+ type: vue.PropType<(face: number) => void>;
73
+ };
74
+ onAnimationEnd: {
75
+ type: vue.PropType<(face: number) => void>;
76
+ };
77
+ ariaLabel: {
78
+ type: StringConstructor;
79
+ };
80
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
81
+ [key: string]: any;
82
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
83
+ faces: {
84
+ type: vue.PropType<2 | 3 | 4>;
85
+ required: true;
86
+ };
87
+ axis: {
88
+ type: vue.PropType<"X" | "Y">;
89
+ };
90
+ direction: {
91
+ type: vue.PropType<"positive" | "negative">;
92
+ };
93
+ type: {
94
+ type: vue.PropType<"real" | "repeat" | "skip">;
95
+ };
96
+ duration: {
97
+ type: NumberConstructor;
98
+ };
99
+ delay: {
100
+ type: NumberConstructor;
101
+ };
102
+ easing: {
103
+ type: StringConstructor;
104
+ };
105
+ perspective: {
106
+ type: NumberConstructor;
107
+ };
108
+ width: {
109
+ type: NumberConstructor;
110
+ };
111
+ height: {
112
+ type: NumberConstructor;
113
+ };
114
+ even: {
115
+ type: NumberConstructor;
116
+ };
117
+ onChange: {
118
+ type: vue.PropType<(face: number) => void>;
119
+ };
120
+ onAnimationEnd: {
121
+ type: vue.PropType<(face: number) => void>;
122
+ };
123
+ ariaLabel: {
124
+ type: StringConstructor;
125
+ };
126
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
127
+ Face: vue.DefineComponent<vue.ExtractPropTypes<{
128
+ _faceIndex: {
129
+ type: vue.PropType<number>;
130
+ default: number;
131
+ };
132
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
133
+ [key: string]: any;
134
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
135
+ _faceIndex: {
136
+ type: vue.PropType<number>;
137
+ default: number;
138
+ };
139
+ }>> & Readonly<{}>, {
140
+ _faceIndex: number;
141
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
142
+ Button: vue.DefineComponent<vue.ExtractPropTypes<{
143
+ direction: {
144
+ type: vue.PropType<"next" | "prev">;
145
+ default: string;
146
+ };
147
+ to: {
148
+ type: NumberConstructor;
149
+ };
150
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
151
+ [key: string]: any;
152
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
153
+ direction: {
154
+ type: vue.PropType<"next" | "prev">;
155
+ default: string;
156
+ };
157
+ to: {
158
+ type: NumberConstructor;
159
+ };
160
+ }>> & Readonly<{}>, {
161
+ direction: "next" | "prev";
162
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
163
+ Provider: vue.DefineComponent<vue.ExtractPropTypes<{
164
+ reduceAnimation: {
165
+ type: vue.PropType<_futaba_soft_turnbox_core.ReduceAnimation>;
166
+ default: string;
167
+ };
168
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
169
+ [key: string]: any;
170
+ }>[] | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
171
+ reduceAnimation: {
172
+ type: vue.PropType<_futaba_soft_turnbox_core.ReduceAnimation>;
173
+ default: string;
174
+ };
175
+ }>> & Readonly<{}>, {
176
+ reduceAnimation: _futaba_soft_turnbox_core.ReduceAnimation;
177
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
178
+ };
179
+
180
+ export { type ButtonProps, type FaceProps, TurnBox, type TurnBoxRootHandle, type UseTurnBoxReturn, useTurnBox };
package/dist/index.js ADDED
@@ -0,0 +1,438 @@
1
+ // src/useTurnBox.ts
2
+ import { onMounted, onUnmounted, ref, watch } from "vue";
3
+ import { createTurnBox } from "@futaba-soft/turnbox-dom";
4
+
5
+ // src/TurnBox/configContext.ts
6
+ import { inject } from "vue";
7
+ var TurnBoxConfigKey = /* @__PURE__ */ Symbol("TurnBoxConfig");
8
+ var DEFAULT_CONFIG = { reduceAnimation: "system setting" };
9
+ var injectTurnBoxConfig = () => inject(TurnBoxConfigKey, DEFAULT_CONFIG);
10
+
11
+ // src/useTurnBox.ts
12
+ var useTurnBox = (options) => {
13
+ const config = injectTurnBoxConfig();
14
+ const containerRef = ref(null);
15
+ const currentFace = ref(1);
16
+ const isAnimating = ref(false);
17
+ let instance = null;
18
+ const init = () => {
19
+ const el = containerRef.value;
20
+ if (!el) return;
21
+ instance = createTurnBox(el, {
22
+ ...options,
23
+ reduceAnimation: config.reduceAnimation,
24
+ onChange: (face) => {
25
+ currentFace.value = face;
26
+ isAnimating.value = true;
27
+ options.onChange?.(face);
28
+ },
29
+ onAnimationEnd: (face) => {
30
+ isAnimating.value = false;
31
+ options.onAnimationEnd?.(face);
32
+ }
33
+ });
34
+ currentFace.value = instance.getCurrentFace();
35
+ };
36
+ const cleanup = () => {
37
+ instance?.destroy();
38
+ instance = null;
39
+ };
40
+ onMounted(init);
41
+ onUnmounted(cleanup);
42
+ watch(
43
+ () => [
44
+ options.faces,
45
+ options.axis,
46
+ options.direction,
47
+ options.type,
48
+ options.duration,
49
+ options.delay,
50
+ options.easing,
51
+ options.perspective,
52
+ options.width,
53
+ options.height,
54
+ options.even,
55
+ config.reduceAnimation
56
+ ],
57
+ () => {
58
+ cleanup();
59
+ init();
60
+ }
61
+ );
62
+ return {
63
+ containerRef,
64
+ currentFace,
65
+ isAnimating,
66
+ goTo: (face, animation = true) => instance?.goTo(face, animation),
67
+ next: () => instance?.next(),
68
+ prev: () => instance?.prev()
69
+ };
70
+ };
71
+
72
+ // src/TurnBox/Root.ts
73
+ import {
74
+ defineComponent as defineComponent2,
75
+ ref as ref2,
76
+ shallowRef,
77
+ computed,
78
+ provide,
79
+ h as h2,
80
+ onUnmounted as onUnmounted2,
81
+ cloneVNode,
82
+ nextTick,
83
+ Fragment
84
+ } from "vue";
85
+ import { normalizeOptions, DEFAULT_SIZE, DEFAULT_HEIGHT } from "@futaba-soft/turnbox-core";
86
+ import {
87
+ FOCUSABLE,
88
+ INITIAL_STATE,
89
+ reducer,
90
+ toPhase,
91
+ planNavigation,
92
+ buildDrainResult
93
+ } from "@futaba-soft/turnbox-core/internal";
94
+
95
+ // src/TurnBox/context.ts
96
+ import { inject as inject2 } from "vue";
97
+ var TurnBoxContextKey = /* @__PURE__ */ Symbol("TurnBoxContext");
98
+ var useTurnBoxContext = () => {
99
+ const ctx = inject2(TurnBoxContextKey);
100
+ if (!ctx) throw new Error("TurnBox components must be used within <TurnBox.Root>");
101
+ return ctx;
102
+ };
103
+
104
+ // src/TurnBox/Face.ts
105
+ import { defineComponent, h } from "vue";
106
+ import { calcFaceTransform } from "@futaba-soft/turnbox-core";
107
+
108
+ // src/TurnBox/utils.ts
109
+ var toTransformString = (ft) => `rotate${ft.axis}(${ft.deg}deg) translate3d(${ft.x}px, ${ft.y}px, ${ft.z}px)`;
110
+
111
+ // src/TurnBox/Face.ts
112
+ var hasTransition = (phase) => phase.kind === "animating";
113
+ var faceDimStyle = (faceIndex, opts) => {
114
+ const { geometry } = opts;
115
+ if (geometry.kind !== "variable") return { inset: "0" };
116
+ const isEven = faceIndex % 2 === 0;
117
+ if (geometry.axis === "X") {
118
+ return { width: "100%", height: `${isEven ? geometry.even : geometry.length}px` };
119
+ }
120
+ return { width: `${isEven ? geometry.even : geometry.length}px`, height: "100%" };
121
+ };
122
+ var Face = defineComponent({
123
+ name: "TurnBoxFace",
124
+ inheritAttrs: false,
125
+ props: {
126
+ _faceIndex: { type: Number, default: 0 }
127
+ },
128
+ setup(props, { slots, attrs }) {
129
+ const { opts, displayFace, phase, shownFaces } = useTurnBoxContext();
130
+ return () => {
131
+ const faceIndex = props._faceIndex;
132
+ const currentPhase = phase.value;
133
+ const currentOpts = opts.value;
134
+ const ft = calcFaceTransform(displayFace.value, faceIndex, currentOpts);
135
+ const transformStr = toTransformString(ft);
136
+ const isShown = shownFaces.value.has(faceIndex);
137
+ const userStyle = attrs.style ?? {};
138
+ const faceStyle = {
139
+ ...userStyle,
140
+ position: "absolute",
141
+ ...faceDimStyle(faceIndex, currentOpts),
142
+ transform: transformStr,
143
+ transformOrigin: ft?.transformOrigin ?? "center",
144
+ zIndex: ft?.zIndex ?? 0,
145
+ opacity: isShown ? 1 : 0,
146
+ backfaceVisibility: "hidden",
147
+ transition: hasTransition(currentPhase) ? `transform ${currentOpts.duration}ms ${currentOpts.easing} ${currentOpts.delay}ms` : void 0
148
+ };
149
+ return h(
150
+ "div",
151
+ {
152
+ ...attrs,
153
+ "data-face-index": faceIndex,
154
+ style: faceStyle,
155
+ "aria-hidden": isShown ? void 0 : true,
156
+ inert: isShown ? void 0 : true
157
+ },
158
+ slots.default?.()
159
+ );
160
+ };
161
+ }
162
+ });
163
+
164
+ // src/TurnBox/Root.ts
165
+ var flattenVNodes = (nodes) => nodes.flatMap(
166
+ (node) => node.type === Fragment && Array.isArray(node.children) ? flattenVNodes(node.children) : [node]
167
+ );
168
+ var calcContainerDynStyle = (displayFace, phaseKind, opts) => {
169
+ const { geometry } = opts;
170
+ if (geometry.kind !== "variable") return {};
171
+ const isEven = displayFace % 2 === 0;
172
+ const isAnimating = phaseKind === "animating";
173
+ const transition = isAnimating ? `${geometry.axis === "X" ? "height" : "left"} ${opts.duration}ms ${opts.easing} ${opts.delay}ms` : void 0;
174
+ return geometry.axis === "X" ? { height: `${isEven ? geometry.even : geometry.length}px`, transition } : { left: `${isEven ? (geometry.length - geometry.even) / 2 : 0}px`, transition };
175
+ };
176
+ var Root = defineComponent2({
177
+ name: "TurnBoxRoot",
178
+ props: {
179
+ faces: { type: Number, required: true },
180
+ axis: { type: String },
181
+ direction: { type: String },
182
+ type: { type: String },
183
+ duration: { type: Number },
184
+ delay: { type: Number },
185
+ easing: { type: String },
186
+ perspective: { type: Number },
187
+ width: { type: Number },
188
+ height: { type: Number },
189
+ even: { type: Number },
190
+ onChange: { type: Function },
191
+ onAnimationEnd: { type: Function },
192
+ ariaLabel: { type: String }
193
+ },
194
+ setup(props, { slots, expose }) {
195
+ const config = injectTurnBoxConfig();
196
+ const machineState = shallowRef(INITIAL_STATE);
197
+ const rafPendingFrom = shallowRef(null);
198
+ const dispatch = (action) => {
199
+ machineState.value = reducer(machineState.value, action);
200
+ };
201
+ const displayFace = computed(() => rafPendingFrom.value ?? machineState.value.displayFace);
202
+ const phase = computed(() => toPhase(machineState.value));
203
+ const shownFaces = computed(() => machineState.value.shownFaces);
204
+ const pendingTimers = [];
205
+ let pendingRaf = null;
206
+ const boxRef = ref2(null);
207
+ const cancelFaceAnimations = () => {
208
+ const box = boxRef.value;
209
+ if (!box) return;
210
+ for (const el of box.querySelectorAll("[data-face-index]")) {
211
+ for (const anim of el.getAnimations?.() ?? []) anim.cancel();
212
+ }
213
+ };
214
+ const focusFace = (faceIndex) => {
215
+ const box = boxRef.value;
216
+ if (!box) return;
217
+ box.querySelector(`[data-face-index="${faceIndex}"]`)?.querySelector(FOCUSABLE)?.focus({ preventScroll: true });
218
+ };
219
+ const opts = computed(() => {
220
+ const base = normalizeOptions({
221
+ faces: props.faces,
222
+ axis: props.axis,
223
+ direction: props.direction,
224
+ type: props.type,
225
+ duration: props.duration,
226
+ delay: props.delay,
227
+ easing: props.easing,
228
+ perspective: props.perspective,
229
+ width: props.width,
230
+ height: props.height,
231
+ even: props.even
232
+ });
233
+ const prefersReducedMotion = config.reduceAnimation !== "never" && typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
234
+ if (prefersReducedMotion) {
235
+ return { ...base, duration: 0, delay: 0 };
236
+ }
237
+ return base;
238
+ });
239
+ const addTimeout = (fn, ms) => {
240
+ const id = setTimeout(fn, ms);
241
+ pendingTimers.push(id);
242
+ };
243
+ const scheduleRaf = typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : (fn) => setTimeout(fn, 0);
244
+ const cancelRaf = typeof cancelAnimationFrame !== "undefined" ? cancelAnimationFrame : clearTimeout;
245
+ onUnmounted2(() => {
246
+ for (const id of pendingTimers) clearTimeout(id);
247
+ if (pendingRaf !== null) cancelRaf(pendingRaf);
248
+ });
249
+ const abortAnimation = () => {
250
+ for (const id of pendingTimers) clearTimeout(id);
251
+ pendingTimers.length = 0;
252
+ if (pendingRaf !== null) {
253
+ cancelRaf(pendingRaf);
254
+ pendingRaf = null;
255
+ }
256
+ rafPendingFrom.value = null;
257
+ const settleFace = machineState.value.displayFace;
258
+ dispatch({ type: "ABORT", displayFace: settleFace });
259
+ };
260
+ const goTo = (rawTarget, animation = true, fromQueue = false) => {
261
+ const drainQueue = (settledFace, queue) => {
262
+ const result = buildDrainResult(settledFace, queue, opts.value);
263
+ if (result.kind === "empty") return;
264
+ goTo(result.nav.face, result.nav.animation, true);
265
+ if (machineState.value.kind !== "idle") {
266
+ for (const item of result.enqueue) dispatch({ type: "ENQUEUE", nav: item });
267
+ }
268
+ };
269
+ let plan = planNavigation(machineState.value, rawTarget, opts.value, animation);
270
+ if (plan.effect === "noop") return;
271
+ if (plan.effect === "enqueue") {
272
+ dispatch(plan.action);
273
+ return;
274
+ }
275
+ if (plan.effect === "abort") {
276
+ abortAnimation();
277
+ plan = planNavigation(machineState.value, rawTarget, opts.value, animation);
278
+ if (plan.effect !== "animate" && plan.effect !== "instant") return;
279
+ }
280
+ const { from, to } = plan;
281
+ const time = opts.value.duration + opts.value.delay;
282
+ props.onChange?.(to);
283
+ if (plan.effect === "instant") {
284
+ dispatch(plan.action);
285
+ addTimeout(() => {
286
+ const pendingQueue = machineState.value.kind === "settling" ? [...machineState.value.queue] : [];
287
+ dispatch({ type: "SETTLE" });
288
+ props.onAnimationEnd?.(to);
289
+ focusFace(to);
290
+ drainQueue(to, pendingQueue);
291
+ }, time);
292
+ return;
293
+ }
294
+ dispatch(plan.action);
295
+ if (fromQueue) {
296
+ addTimeout(() => {
297
+ cancelFaceAnimations();
298
+ const pendingQueue = machineState.value.kind === "animating" ? [...machineState.value.queue] : [];
299
+ dispatch({ type: "COMPLETE", displayFace: to });
300
+ props.onAnimationEnd?.(to);
301
+ nextTick(() => focusFace(to));
302
+ drainQueue(to, pendingQueue);
303
+ }, time);
304
+ return;
305
+ }
306
+ rafPendingFrom.value = from;
307
+ pendingRaf = scheduleRaf(() => {
308
+ pendingRaf = null;
309
+ rafPendingFrom.value = null;
310
+ addTimeout(() => {
311
+ cancelFaceAnimations();
312
+ const pendingQueue = machineState.value.kind === "animating" ? [...machineState.value.queue] : [];
313
+ dispatch({ type: "COMPLETE", displayFace: to });
314
+ props.onAnimationEnd?.(to);
315
+ nextTick(() => focusFace(to));
316
+ drainQueue(to, pendingQueue);
317
+ }, time);
318
+ });
319
+ };
320
+ const resolveCurrentFace = () => machineState.value.displayFace;
321
+ const next = () => goTo(resolveCurrentFace() + 1, true);
322
+ const prev = () => goTo(resolveCurrentFace() - 1, true);
323
+ provide(TurnBoxContextKey, {
324
+ opts,
325
+ displayFace,
326
+ phase,
327
+ shownFaces,
328
+ goTo,
329
+ next,
330
+ prev
331
+ });
332
+ expose({
333
+ goTo,
334
+ // Logical target, not the rAF-held displayFace (which reads "from" for one frame) —
335
+ // consistent with next()/prev() stepping from machineState.displayFace.
336
+ getCurrentFace: () => machineState.value.displayFace,
337
+ isAnimating: () => machineState.value.kind !== "idle",
338
+ next,
339
+ prev
340
+ });
341
+ return () => {
342
+ const boxWidth = props.width ?? DEFAULT_SIZE;
343
+ const boxHeight = props.height ?? DEFAULT_HEIGHT;
344
+ const children = flattenVNodes(slots.default?.() ?? []);
345
+ let faceCount = 0;
346
+ const indexedChildren = children.flatMap((child) => {
347
+ if (child.type === Face) {
348
+ faceCount++;
349
+ if (faceCount > opts.value.faces) return [];
350
+ return [cloneVNode(child, { _faceIndex: faceCount })];
351
+ }
352
+ return [child];
353
+ });
354
+ const containerDynStyle = calcContainerDynStyle(displayFace.value, phase.value.kind, opts.value);
355
+ return h2(
356
+ "div",
357
+ {
358
+ // role="region" makes TurnBox a landmark for screen reader navigation (e.g. "R" key jump).
359
+ // Only set when aria-label is provided — an unlabelled landmark is worse than no landmark.
360
+ role: props.ariaLabel ? "region" : void 0,
361
+ "aria-label": props.ariaLabel,
362
+ style: {
363
+ perspective: `${opts.value.perspective}px`,
364
+ width: `${boxWidth}px`,
365
+ height: `${boxHeight}px`,
366
+ position: "relative"
367
+ }
368
+ },
369
+ [
370
+ h2(
371
+ "div",
372
+ {
373
+ ref: boxRef,
374
+ "data-turnbox-box": "",
375
+ style: {
376
+ width: `${boxWidth}px`,
377
+ position: "absolute",
378
+ top: 0,
379
+ bottom: 0,
380
+ transformStyle: "preserve-3d",
381
+ ...containerDynStyle
382
+ }
383
+ },
384
+ indexedChildren
385
+ )
386
+ ]
387
+ );
388
+ };
389
+ }
390
+ });
391
+
392
+ // src/TurnBox/Button.ts
393
+ import { defineComponent as defineComponent3, h as h3 } from "vue";
394
+ var Button = defineComponent3({
395
+ name: "TurnBoxButton",
396
+ inheritAttrs: false,
397
+ props: {
398
+ direction: { type: String, default: "next" },
399
+ to: { type: Number }
400
+ },
401
+ setup(props, { slots, attrs }) {
402
+ const { goTo, next, prev } = useTurnBoxContext();
403
+ const handleClick = () => {
404
+ if (props.to !== void 0) {
405
+ goTo(props.to);
406
+ } else if (props.direction === "prev") {
407
+ prev();
408
+ } else {
409
+ next();
410
+ }
411
+ };
412
+ return () => h3("button", { type: "button", ...attrs, onClick: handleClick }, slots.default?.());
413
+ }
414
+ });
415
+
416
+ // src/TurnBox/Provider.ts
417
+ import { defineComponent as defineComponent4, provide as provide2, reactive, watchEffect } from "vue";
418
+ var Provider = defineComponent4({
419
+ name: "TurnBoxProvider",
420
+ props: {
421
+ reduceAnimation: { type: String, default: "system setting" }
422
+ },
423
+ setup(props, { slots }) {
424
+ const config = reactive({ reduceAnimation: props.reduceAnimation });
425
+ watchEffect(() => {
426
+ config.reduceAnimation = props.reduceAnimation;
427
+ });
428
+ provide2(TurnBoxConfigKey, config);
429
+ return () => slots.default?.();
430
+ }
431
+ });
432
+
433
+ // src/TurnBox/index.ts
434
+ var TurnBox = { Root, Face, Button, Provider };
435
+ export {
436
+ TurnBox,
437
+ useTurnBox
438
+ };
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@futaba-soft/turnbox-vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.5.0",
4
+ "description": "Vue TurnBox — CSS3 3D box flip animation compound component and composable for Vue 3",
5
+ "keywords": [
6
+ "3d",
7
+ "animation",
8
+ "css3",
9
+ "transform",
10
+ "turnbox",
11
+ "vue",
12
+ "composable",
13
+ "component"
14
+ ],
15
+ "license": "MIT",
16
+ "author": "futaba-soft",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/futaba-soft/turnbox_js.git",
20
+ "directory": "packages/vue"
21
+ },
22
+ "homepage": "https://github.com/futaba-soft/turnbox_js#readme",
23
+ "bugs": {
24
+ "url": "https://github.com/futaba-soft/turnbox_js/issues"
25
+ },
26
+ "type": "module",
27
+ "exports": {
28
+ ".": {
29
+ "import": "./dist/index.js",
30
+ "types": "./dist/index.d.ts"
31
+ }
32
+ },
33
+ "main": "./dist/index.js",
34
+ "types": "./dist/index.d.ts",
35
+ "sideEffects": false,
36
+ "files": [
37
+ "dist",
38
+ "LICENSE"
39
+ ],
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "peerDependencies": {
44
+ "vue": ">=3"
45
+ },
46
+ "dependencies": {
47
+ "@futaba-soft/turnbox-core": "^0.5.0",
48
+ "@futaba-soft/turnbox-dom": "0.5.0"
49
+ },
50
+ "devDependencies": {
51
+ "@vue/server-renderer": "^3.5.39",
52
+ "@vue/test-utils": "^2.4.11",
53
+ "vue": "^3.5.39"
54
+ },
55
+ "scripts": {
56
+ "build": "tsup src/index.ts --format esm --dts --out-dir dist",
57
+ "test": "vitest run"
58
+ }
6
59
  }