@futaba-soft/turnbox-core 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 +22 -0
- package/README.md +113 -2
- package/dist/chunk-MQKESMYJ.js +116 -0
- package/dist/index-DM7U8n8C.d.ts +77 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +20 -0
- package/dist/internal.d.ts +107 -0
- package/dist/internal.js +193 -0
- package/package.json +46 -3
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,114 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @futaba-soft/turnbox-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Pure geometry and navigation functions for TURNBOX.js. No DOM dependency.
|
|
4
|
+
|
|
5
|
+
For most use cases, prefer `@futaba-soft/turnbox-dom`, `@futaba-soft/turnbox-react`, or `@futaba-soft/turnbox-vue`.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @futaba-soft/turnbox-core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
|
|
15
|
+
### normalizeOptions(options)
|
|
16
|
+
|
|
17
|
+
Fills in defaults and returns a `NormalizedOptions` object.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { normalizeOptions } from "@futaba-soft/turnbox-core";
|
|
21
|
+
|
|
22
|
+
const opts = normalizeOptions({ faces: 4, duration: 400 });
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### calcFaceTransform(currentFace, faceNum, opts)
|
|
26
|
+
|
|
27
|
+
Returns the CSS transform values for `faceNum` relative to `currentFace`.
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { normalizeOptions, calcFaceTransform } from "@futaba-soft/turnbox-core";
|
|
31
|
+
|
|
32
|
+
const opts = normalizeOptions({ faces: 4 });
|
|
33
|
+
const t = calcFaceTransform(1, 2, opts);
|
|
34
|
+
// { axis: "X", deg: 90, x: 0, y: -25, z: 25, zIndex: 10, transformOrigin: "50% 50%" }
|
|
35
|
+
|
|
36
|
+
const css = `rotate${t.axis}(${t.deg}deg) translate3d(${t.x}px, ${t.y}px, ${t.z}px)`;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### DEFAULT_SIZE / DEFAULT_HEIGHT
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { DEFAULT_SIZE, DEFAULT_HEIGHT } from "@futaba-soft/turnbox-core";
|
|
43
|
+
// DEFAULT_SIZE = 200
|
|
44
|
+
// DEFAULT_HEIGHT = 50
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Internal API
|
|
48
|
+
|
|
49
|
+
`@futaba-soft/turnbox-core/internal` is used across the `@futaba-soft/turnbox-*` packages and may have breaking changes in minor releases. Direct use from outside the monorepo is not recommended.
|
|
50
|
+
|
|
51
|
+
### State machine
|
|
52
|
+
|
|
53
|
+
Shared reducer for `@futaba-soft/turnbox-dom`, `-react`, and `-vue`.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import {
|
|
57
|
+
INITIAL_STATE,
|
|
58
|
+
reducer,
|
|
59
|
+
toPhase,
|
|
60
|
+
buildGoStepAction,
|
|
61
|
+
buildGoInstantAction,
|
|
62
|
+
type TurnBoxState,
|
|
63
|
+
type TurnBoxAction,
|
|
64
|
+
type AnimationPhase,
|
|
65
|
+
type PendingNav,
|
|
66
|
+
} from "@futaba-soft/turnbox-core/internal";
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
| Export | Kind | Description |
|
|
70
|
+
| --- | --- | --- |
|
|
71
|
+
| `TurnBoxState` | type | Union of `IdleState \| SettlingState \| AnimatingState` |
|
|
72
|
+
| `TurnBoxAction` | type | Union of all dispatchable action types |
|
|
73
|
+
| `AnimationPhase` | type | `{ kind: "idle" } \| { kind: "animating" }` — coarser view of state for `isAnimating` |
|
|
74
|
+
| `PendingNav` | type | `{ face: number; animation: boolean }` — item stored in the queue |
|
|
75
|
+
| `INITIAL_STATE` | const | Initial `TurnBoxState` (face 1, idle) |
|
|
76
|
+
| `reducer` | function | `(state, action) => TurnBoxState` |
|
|
77
|
+
| `toPhase` | function | `(state) => AnimationPhase` — collapses `settling` into `idle` |
|
|
78
|
+
| `buildGoStepAction` | function | `(to, from) => TurnBoxAction` — animated step |
|
|
79
|
+
| `buildGoInstantAction` | function | `(displayFace, from) => TurnBoxAction` — no-animation jump |
|
|
80
|
+
|
|
81
|
+
### Navigation orchestration
|
|
82
|
+
|
|
83
|
+
Decision layer that sits above the state machine, shared by all adapters.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import {
|
|
87
|
+
resolveNavigation,
|
|
88
|
+
buildDrainResult,
|
|
89
|
+
type NavigationDecision,
|
|
90
|
+
type DrainResult,
|
|
91
|
+
} from "@futaba-soft/turnbox-core/internal";
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
| Export | Kind | Description |
|
|
95
|
+
| --- | --- | --- |
|
|
96
|
+
| `NavigationDecision` | type | `"noop" \| "enqueue" \| "abort" \| "go"` — what the caller should do |
|
|
97
|
+
| `DrainResult` | type | `"empty" \| { navigate, enqueue }` — result of draining the queue after settle |
|
|
98
|
+
| `resolveNavigation` | function | `(state, rawTarget, opts, animation) => NavigationDecision` |
|
|
99
|
+
| `buildDrainResult` | function | `(settledFace, queue, opts) => DrainResult` |
|
|
100
|
+
|
|
101
|
+
### Other internal exports
|
|
102
|
+
|
|
103
|
+
| Export | Description |
|
|
104
|
+
| --- | --- |
|
|
105
|
+
| `shouldAnimate` | Whether a transition should run with animation |
|
|
106
|
+
| `resolveTransition` | Resolves `rawTarget` to a canonical face + `doAnimate` flag |
|
|
107
|
+
| `getFaceParity` | Returns `"odd" \| "even"` for a face number |
|
|
108
|
+
| `MAX_FACE_PCS` | Maximum supported face count (`4`) |
|
|
109
|
+
| `FOCUSABLE` | CSS selector string for focusable elements inside a face |
|
|
110
|
+
| `Transition`, `RotationDeg`, `FaceVisibility`, `FaceParity` | Shared geometry/navigation types |
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
MIT
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// src/normalize.ts
|
|
2
|
+
var MAX_FACE_PCS = 4;
|
|
3
|
+
var DEFAULT_DURATION = 200;
|
|
4
|
+
var DEFAULT_DELAY = 0;
|
|
5
|
+
var DEFAULT_EASING = "linear";
|
|
6
|
+
var DEFAULT_PERSPECTIVE = 800;
|
|
7
|
+
var DEFAULT_SIZE = 200;
|
|
8
|
+
var DEFAULT_HEIGHT = 50;
|
|
9
|
+
var normalizeOptions = (options) => {
|
|
10
|
+
const faces = Math.min(options.faces, MAX_FACE_PCS);
|
|
11
|
+
const axis = options.axis ?? "X";
|
|
12
|
+
const direction = options.direction ?? "positive";
|
|
13
|
+
const duration = options.duration ?? DEFAULT_DURATION;
|
|
14
|
+
const delay = options.delay ?? DEFAULT_DELAY;
|
|
15
|
+
const easing = options.easing ?? DEFAULT_EASING;
|
|
16
|
+
const perspective = options.perspective ?? DEFAULT_PERSPECTIVE;
|
|
17
|
+
const width = options.width ?? DEFAULT_SIZE;
|
|
18
|
+
const height = options.height ?? DEFAULT_HEIGHT;
|
|
19
|
+
const even = options.even ?? (axis === "Y" ? width : height);
|
|
20
|
+
const length = axis === "Y" ? width : height;
|
|
21
|
+
const fixed = even === length;
|
|
22
|
+
const rawType = options.type ?? "real";
|
|
23
|
+
const type = !fixed && rawType === "skip" ? "real" : rawType;
|
|
24
|
+
const geometry = fixed ? { kind: "fixed", axis, length } : { kind: "variable", axis, length, even };
|
|
25
|
+
return { faces, direction, type, duration, delay, easing, perspective, geometry };
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// src/transform.ts
|
|
29
|
+
var getFaceParity = (faceNum) => faceNum % 2 !== 0 ? "odd" : "even";
|
|
30
|
+
var calcBaseDeg = (currentFace, faceNum) => (currentFace - faceNum) * -90;
|
|
31
|
+
var isWrapEdge = (currentFace, faceNum) => currentFace === MAX_FACE_PCS && faceNum === 1 || currentFace === 1 && faceNum === MAX_FACE_PCS;
|
|
32
|
+
var calcDegSkip = (base, currentFace, faceNum) => {
|
|
33
|
+
const clamped = Math.sign(base) * 90;
|
|
34
|
+
return isWrapEdge(currentFace, faceNum) ? -clamped : clamped;
|
|
35
|
+
};
|
|
36
|
+
var calcDegReal = (base, currentFace, faceNum) => {
|
|
37
|
+
if (!isWrapEdge(currentFace, faceNum)) return base;
|
|
38
|
+
return Math.sign(base) * -90;
|
|
39
|
+
};
|
|
40
|
+
var calcDegRepeat = (base, currentFace, faceNum) => {
|
|
41
|
+
if (getFaceParity(currentFace) === "odd" && getFaceParity(faceNum) === "even") return 90;
|
|
42
|
+
if (getFaceParity(currentFace) === "even" && getFaceParity(faceNum) === "odd") return -90;
|
|
43
|
+
return base;
|
|
44
|
+
};
|
|
45
|
+
var applyDirection = (deg, direction) => {
|
|
46
|
+
if (direction !== "negative") return deg;
|
|
47
|
+
const flipped = deg * -1;
|
|
48
|
+
return Object.is(flipped, -0) ? 0 : flipped;
|
|
49
|
+
};
|
|
50
|
+
var calcDeg = (currentFace, faceNum, options) => {
|
|
51
|
+
const base = calcBaseDeg(currentFace, faceNum);
|
|
52
|
+
const typed = options.type === "skip" ? calcDegSkip(base, currentFace, faceNum) : options.type === "repeat" ? calcDegRepeat(base, currentFace, faceNum) : calcDegReal(base, currentFace, faceNum);
|
|
53
|
+
return applyDirection(typed, options.direction);
|
|
54
|
+
};
|
|
55
|
+
var faceVisibility = (deg) => {
|
|
56
|
+
const abs = Math.abs(deg);
|
|
57
|
+
if (abs === 0 || abs === 360) return "front";
|
|
58
|
+
if (abs === 90 || abs === 270) return "side";
|
|
59
|
+
return "hidden";
|
|
60
|
+
};
|
|
61
|
+
var Z_INDEX = { front: 20, side: 10, hidden: 0 };
|
|
62
|
+
var calcZIndex = (deg) => Z_INDEX[faceVisibility(deg)];
|
|
63
|
+
var calcTranslate = (deg, faceNum, axis, length, pivot, evenSize) => {
|
|
64
|
+
const abs = Math.abs(deg);
|
|
65
|
+
if (abs === 0 || abs === 360) return [0, 0, 0];
|
|
66
|
+
const parity = getFaceParity(faceNum);
|
|
67
|
+
if (abs === 180) {
|
|
68
|
+
const lateral2 = parity === "odd" ? 2 * pivot - length : 2 * pivot - evenSize;
|
|
69
|
+
const tz2 = parity === "odd" ? evenSize : length;
|
|
70
|
+
return axis === "Y" ? [lateral2, 0, tz2] : [0, lateral2, tz2];
|
|
71
|
+
}
|
|
72
|
+
const isPos = deg > 0;
|
|
73
|
+
const isY = axis === "Y";
|
|
74
|
+
let lateral;
|
|
75
|
+
let tz;
|
|
76
|
+
if (parity === "odd") {
|
|
77
|
+
if (isPos === isY) {
|
|
78
|
+
lateral = pivot;
|
|
79
|
+
tz = evenSize - pivot;
|
|
80
|
+
} else {
|
|
81
|
+
lateral = pivot - length;
|
|
82
|
+
tz = pivot;
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
if (isPos === isY) {
|
|
86
|
+
lateral = pivot;
|
|
87
|
+
tz = length - pivot;
|
|
88
|
+
} else {
|
|
89
|
+
lateral = pivot - evenSize;
|
|
90
|
+
tz = pivot;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return axis === "Y" ? [lateral, 0, tz] : [0, lateral, tz];
|
|
94
|
+
};
|
|
95
|
+
var calcFaceTransform = (currentFace, faceNum, options) => {
|
|
96
|
+
const { geometry } = options;
|
|
97
|
+
const deg = calcDeg(currentFace, faceNum, options);
|
|
98
|
+
const pivot = geometry.kind === "fixed" ? geometry.length / 2 : geometry.even;
|
|
99
|
+
const evenSize = geometry.kind === "fixed" ? geometry.length : geometry.even;
|
|
100
|
+
const [x, y, z] = calcTranslate(deg, faceNum, geometry.axis, geometry.length, pivot, evenSize);
|
|
101
|
+
const transformOrigin = geometry.axis === "X" ? `50% ${pivot}px` : `${pivot}px 50%`;
|
|
102
|
+
return { axis: geometry.axis, deg, x, y, z, zIndex: calcZIndex(deg), transformOrigin };
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export {
|
|
106
|
+
MAX_FACE_PCS,
|
|
107
|
+
DEFAULT_DURATION,
|
|
108
|
+
DEFAULT_DELAY,
|
|
109
|
+
DEFAULT_EASING,
|
|
110
|
+
DEFAULT_PERSPECTIVE,
|
|
111
|
+
DEFAULT_SIZE,
|
|
112
|
+
DEFAULT_HEIGHT,
|
|
113
|
+
normalizeOptions,
|
|
114
|
+
getFaceParity,
|
|
115
|
+
calcFaceTransform
|
|
116
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
type Axis = "X" | "Y";
|
|
2
|
+
type Direction = "positive" | "negative";
|
|
3
|
+
type AnimationType = "real" | "repeat" | "skip";
|
|
4
|
+
type Transition = {
|
|
5
|
+
kind: "noop";
|
|
6
|
+
} | {
|
|
7
|
+
kind: "step";
|
|
8
|
+
to: number;
|
|
9
|
+
doAnimate: boolean;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "direct-wrap";
|
|
12
|
+
to: number;
|
|
13
|
+
doAnimate: boolean;
|
|
14
|
+
};
|
|
15
|
+
type RotationDeg = -360 | -180 | -90 | 0 | 90 | 180 | 360;
|
|
16
|
+
type FaceVisibility = "front" | "side" | "hidden";
|
|
17
|
+
type FaceParity = "odd" | "even";
|
|
18
|
+
type Geometry = {
|
|
19
|
+
kind: "fixed";
|
|
20
|
+
axis: Axis;
|
|
21
|
+
length: number;
|
|
22
|
+
} | {
|
|
23
|
+
kind: "variable";
|
|
24
|
+
axis: Axis;
|
|
25
|
+
length: number;
|
|
26
|
+
even: number;
|
|
27
|
+
};
|
|
28
|
+
type FaceCount = 2 | 3 | 4;
|
|
29
|
+
type ReduceAnimation = "system setting" | "never";
|
|
30
|
+
type TurnBoxOptions = {
|
|
31
|
+
faces: FaceCount;
|
|
32
|
+
axis?: Axis;
|
|
33
|
+
direction?: Direction;
|
|
34
|
+
type?: AnimationType;
|
|
35
|
+
duration?: number;
|
|
36
|
+
delay?: number;
|
|
37
|
+
easing?: string;
|
|
38
|
+
perspective?: number;
|
|
39
|
+
width?: number;
|
|
40
|
+
height?: number;
|
|
41
|
+
even?: number;
|
|
42
|
+
onChange?: (face: number) => void;
|
|
43
|
+
onAnimationEnd?: (face: number) => void;
|
|
44
|
+
};
|
|
45
|
+
type NormalizedOptions = {
|
|
46
|
+
faces: FaceCount;
|
|
47
|
+
direction: Direction;
|
|
48
|
+
type: AnimationType;
|
|
49
|
+
duration: number;
|
|
50
|
+
delay: number;
|
|
51
|
+
easing: string;
|
|
52
|
+
perspective: number;
|
|
53
|
+
geometry: Geometry;
|
|
54
|
+
};
|
|
55
|
+
type FaceTransform = {
|
|
56
|
+
axis: Axis;
|
|
57
|
+
deg: RotationDeg;
|
|
58
|
+
x: number;
|
|
59
|
+
y: number;
|
|
60
|
+
z: number;
|
|
61
|
+
zIndex: number;
|
|
62
|
+
transformOrigin: string;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
declare const MAX_FACE_PCS = 4;
|
|
66
|
+
declare const DEFAULT_DURATION = 200;
|
|
67
|
+
declare const DEFAULT_DELAY = 0;
|
|
68
|
+
declare const DEFAULT_EASING = "linear";
|
|
69
|
+
declare const DEFAULT_PERSPECTIVE = 800;
|
|
70
|
+
declare const DEFAULT_SIZE = 200;
|
|
71
|
+
declare const DEFAULT_HEIGHT = 50;
|
|
72
|
+
declare const normalizeOptions: (options: TurnBoxOptions) => NormalizedOptions;
|
|
73
|
+
|
|
74
|
+
declare const getFaceParity: (faceNum: number) => FaceParity;
|
|
75
|
+
declare const calcFaceTransform: (currentFace: number, faceNum: number, options: NormalizedOptions) => FaceTransform;
|
|
76
|
+
|
|
77
|
+
export { type AnimationType as A, DEFAULT_DELAY as D, type FaceCount as F, type Geometry as G, MAX_FACE_PCS as M, type NormalizedOptions as N, type ReduceAnimation as R, type Transition as T, type Axis as a, DEFAULT_DURATION as b, DEFAULT_EASING as c, DEFAULT_HEIGHT as d, DEFAULT_PERSPECTIVE as e, DEFAULT_SIZE as f, type Direction as g, type FaceParity as h, type FaceTransform as i, type FaceVisibility as j, type RotationDeg as k, type TurnBoxOptions as l, calcFaceTransform as m, getFaceParity as n, normalizeOptions as o };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { A as AnimationType, a as Axis, D as DEFAULT_DELAY, b as DEFAULT_DURATION, c as DEFAULT_EASING, d as DEFAULT_HEIGHT, e as DEFAULT_PERSPECTIVE, f as DEFAULT_SIZE, g as Direction, F as FaceCount, i as FaceTransform, G as Geometry, N as NormalizedOptions, R as ReduceAnimation, l as TurnBoxOptions, m as calcFaceTransform, o as normalizeOptions } from './index-DM7U8n8C.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_DELAY,
|
|
3
|
+
DEFAULT_DURATION,
|
|
4
|
+
DEFAULT_EASING,
|
|
5
|
+
DEFAULT_HEIGHT,
|
|
6
|
+
DEFAULT_PERSPECTIVE,
|
|
7
|
+
DEFAULT_SIZE,
|
|
8
|
+
calcFaceTransform,
|
|
9
|
+
normalizeOptions
|
|
10
|
+
} from "./chunk-MQKESMYJ.js";
|
|
11
|
+
export {
|
|
12
|
+
DEFAULT_DELAY,
|
|
13
|
+
DEFAULT_DURATION,
|
|
14
|
+
DEFAULT_EASING,
|
|
15
|
+
DEFAULT_HEIGHT,
|
|
16
|
+
DEFAULT_PERSPECTIVE,
|
|
17
|
+
DEFAULT_SIZE,
|
|
18
|
+
calcFaceTransform,
|
|
19
|
+
normalizeOptions
|
|
20
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { N as NormalizedOptions, T as Transition } from './index-DM7U8n8C.js';
|
|
2
|
+
export { A as AnimationType, a as Axis, D as DEFAULT_DELAY, b as DEFAULT_DURATION, c as DEFAULT_EASING, d as DEFAULT_HEIGHT, e as DEFAULT_PERSPECTIVE, f as DEFAULT_SIZE, g as Direction, F as FaceCount, h as FaceParity, i as FaceTransform, j as FaceVisibility, G as Geometry, M as MAX_FACE_PCS, R as ReduceAnimation, k as RotationDeg, l as TurnBoxOptions, m as calcFaceTransform, n as getFaceParity, o as normalizeOptions } from './index-DM7U8n8C.js';
|
|
3
|
+
|
|
4
|
+
declare const FOCUSABLE = "a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])";
|
|
5
|
+
|
|
6
|
+
declare const shouldAnimate: (currentFace: number, targetFace: number, options: NormalizedOptions, animationFlag?: boolean) => boolean;
|
|
7
|
+
declare const resolveTransition: (from: number, rawTarget: number, opts: NormalizedOptions, animationFlag: boolean) => Transition;
|
|
8
|
+
|
|
9
|
+
type AnimationPhase = {
|
|
10
|
+
kind: "idle";
|
|
11
|
+
} | {
|
|
12
|
+
kind: "animating";
|
|
13
|
+
};
|
|
14
|
+
type PendingNav = {
|
|
15
|
+
face: number;
|
|
16
|
+
animation: boolean;
|
|
17
|
+
};
|
|
18
|
+
type IdleState = {
|
|
19
|
+
kind: "idle";
|
|
20
|
+
displayFace: number;
|
|
21
|
+
shownFaces: ReadonlySet<number>;
|
|
22
|
+
};
|
|
23
|
+
type SettlingState = {
|
|
24
|
+
kind: "settling";
|
|
25
|
+
displayFace: number;
|
|
26
|
+
from: number;
|
|
27
|
+
shownFaces: ReadonlySet<number>;
|
|
28
|
+
queue: PendingNav[];
|
|
29
|
+
};
|
|
30
|
+
type AnimatingState = {
|
|
31
|
+
kind: "animating";
|
|
32
|
+
displayFace: number;
|
|
33
|
+
from: number;
|
|
34
|
+
shownFaces: ReadonlySet<number>;
|
|
35
|
+
queue: PendingNav[];
|
|
36
|
+
};
|
|
37
|
+
type TurnBoxState = IdleState | SettlingState | AnimatingState;
|
|
38
|
+
type TurnBoxAction = {
|
|
39
|
+
type: "GO_STEP";
|
|
40
|
+
to: number;
|
|
41
|
+
from: number;
|
|
42
|
+
shownFaces: ReadonlySet<number>;
|
|
43
|
+
} | {
|
|
44
|
+
type: "GO_INSTANT";
|
|
45
|
+
displayFace: number;
|
|
46
|
+
from: number;
|
|
47
|
+
} | {
|
|
48
|
+
type: "COMPLETE";
|
|
49
|
+
displayFace: number;
|
|
50
|
+
} | {
|
|
51
|
+
type: "SETTLE";
|
|
52
|
+
} | {
|
|
53
|
+
type: "ENQUEUE";
|
|
54
|
+
nav: PendingNav;
|
|
55
|
+
} | {
|
|
56
|
+
type: "ABORT";
|
|
57
|
+
displayFace: number;
|
|
58
|
+
};
|
|
59
|
+
declare const INITIAL_STATE: TurnBoxState;
|
|
60
|
+
declare const reducer: (state: TurnBoxState, action: TurnBoxAction) => TurnBoxState;
|
|
61
|
+
declare const buildGoInstantAction: (displayFace: number, from: number) => TurnBoxAction;
|
|
62
|
+
declare const buildGoStepAction: (to: number, from: number) => TurnBoxAction;
|
|
63
|
+
declare const toPhase: (state: TurnBoxState) => AnimationPhase;
|
|
64
|
+
|
|
65
|
+
type NavigationDecision = {
|
|
66
|
+
kind: "noop";
|
|
67
|
+
} | {
|
|
68
|
+
kind: "enqueue";
|
|
69
|
+
nav: PendingNav;
|
|
70
|
+
} | {
|
|
71
|
+
kind: "abort";
|
|
72
|
+
} | {
|
|
73
|
+
kind: "go";
|
|
74
|
+
from: number;
|
|
75
|
+
to: number;
|
|
76
|
+
doAnimate: boolean;
|
|
77
|
+
};
|
|
78
|
+
declare const resolveNavigation: (state: TurnBoxState, rawTarget: number, opts: NormalizedOptions, animation: boolean) => NavigationDecision;
|
|
79
|
+
type NavigationPlan = {
|
|
80
|
+
effect: "noop";
|
|
81
|
+
} | {
|
|
82
|
+
effect: "enqueue";
|
|
83
|
+
action: TurnBoxAction;
|
|
84
|
+
} | {
|
|
85
|
+
effect: "abort";
|
|
86
|
+
} | {
|
|
87
|
+
effect: "animate";
|
|
88
|
+
from: number;
|
|
89
|
+
to: number;
|
|
90
|
+
action: TurnBoxAction;
|
|
91
|
+
} | {
|
|
92
|
+
effect: "instant";
|
|
93
|
+
from: number;
|
|
94
|
+
to: number;
|
|
95
|
+
action: TurnBoxAction;
|
|
96
|
+
};
|
|
97
|
+
declare const planNavigation: (state: TurnBoxState, rawTarget: number, opts: NormalizedOptions, animation: boolean) => NavigationPlan;
|
|
98
|
+
type DrainResult = {
|
|
99
|
+
kind: "empty";
|
|
100
|
+
} | {
|
|
101
|
+
kind: "navigate";
|
|
102
|
+
nav: PendingNav;
|
|
103
|
+
enqueue: PendingNav[];
|
|
104
|
+
};
|
|
105
|
+
declare const buildDrainResult: (settledFace: number, queue: PendingNav[], opts: NormalizedOptions) => DrainResult;
|
|
106
|
+
|
|
107
|
+
export { type AnimatingState, type AnimationPhase, type DrainResult, FOCUSABLE, INITIAL_STATE, type IdleState, type NavigationDecision, type NavigationPlan, NormalizedOptions, type PendingNav, type SettlingState, Transition, type TurnBoxAction, type TurnBoxState, buildDrainResult, buildGoInstantAction, buildGoStepAction, planNavigation, reducer, resolveNavigation, resolveTransition, shouldAnimate, toPhase };
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_DELAY,
|
|
3
|
+
DEFAULT_DURATION,
|
|
4
|
+
DEFAULT_EASING,
|
|
5
|
+
DEFAULT_HEIGHT,
|
|
6
|
+
DEFAULT_PERSPECTIVE,
|
|
7
|
+
DEFAULT_SIZE,
|
|
8
|
+
MAX_FACE_PCS,
|
|
9
|
+
calcFaceTransform,
|
|
10
|
+
getFaceParity,
|
|
11
|
+
normalizeOptions
|
|
12
|
+
} from "./chunk-MQKESMYJ.js";
|
|
13
|
+
|
|
14
|
+
// src/focus.ts
|
|
15
|
+
var FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
16
|
+
|
|
17
|
+
// src/navigation.ts
|
|
18
|
+
var shouldAnimate = (currentFace, targetFace, options, animationFlag = true) => {
|
|
19
|
+
if (!animationFlag) return false;
|
|
20
|
+
if (currentFace === targetFace) return false;
|
|
21
|
+
const diff = Math.abs(targetFace - currentFace);
|
|
22
|
+
if (options.type !== "skip" && diff > 1) {
|
|
23
|
+
const isBoundaryWrap = options.faces === MAX_FACE_PCS && (options.type === "real" || options.type === "repeat") && (currentFace === 1 && targetFace === options.faces || currentFace === options.faces && targetFace === 1);
|
|
24
|
+
if (!isBoundaryWrap) return false;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
};
|
|
28
|
+
var resolveBoundary = (rawTarget, opts) => {
|
|
29
|
+
if (opts.faces === MAX_FACE_PCS) {
|
|
30
|
+
if (rawTarget === opts.faces + 1) return { kind: "resolved", to: 1, isDirectWrap: true };
|
|
31
|
+
if (rawTarget === 0) return { kind: "resolved", to: opts.faces, isDirectWrap: true };
|
|
32
|
+
if (rawTarget > opts.faces + 1) return { kind: "resolved", to: opts.faces, isDirectWrap: false };
|
|
33
|
+
if (rawTarget < 0) return { kind: "noop" };
|
|
34
|
+
return { kind: "resolved", to: rawTarget, isDirectWrap: false };
|
|
35
|
+
}
|
|
36
|
+
if (rawTarget < 1) return { kind: "noop" };
|
|
37
|
+
return { kind: "resolved", to: Math.min(rawTarget, opts.faces), isDirectWrap: false };
|
|
38
|
+
};
|
|
39
|
+
var resolveTransition = (from, rawTarget, opts, animationFlag) => {
|
|
40
|
+
const boundary = resolveBoundary(rawTarget, opts);
|
|
41
|
+
if (boundary.kind === "noop" || from === boundary.to) return { kind: "noop" };
|
|
42
|
+
const { to, isDirectWrap } = boundary;
|
|
43
|
+
if (isDirectWrap) {
|
|
44
|
+
return { kind: "direct-wrap", to, doAnimate: animationFlag };
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
kind: "step",
|
|
48
|
+
to,
|
|
49
|
+
doAnimate: shouldAnimate(from, to, opts, animationFlag)
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/state-machine.ts
|
|
54
|
+
var INITIAL_STATE = {
|
|
55
|
+
kind: "idle",
|
|
56
|
+
displayFace: 1,
|
|
57
|
+
shownFaces: /* @__PURE__ */ new Set([1])
|
|
58
|
+
};
|
|
59
|
+
var reducer = (state, action) => {
|
|
60
|
+
switch (action.type) {
|
|
61
|
+
case "GO_STEP":
|
|
62
|
+
return {
|
|
63
|
+
kind: "animating",
|
|
64
|
+
displayFace: action.to,
|
|
65
|
+
from: action.from,
|
|
66
|
+
shownFaces: action.shownFaces,
|
|
67
|
+
// Preserve queue if transitioning from a non-idle state (e.g. abort → immediate re-go).
|
|
68
|
+
// In the abort path, ABORT resets to idle first, so queue is always [] here.
|
|
69
|
+
queue: state.kind !== "idle" ? [...state.queue] : []
|
|
70
|
+
};
|
|
71
|
+
case "GO_INSTANT":
|
|
72
|
+
return {
|
|
73
|
+
kind: "settling",
|
|
74
|
+
displayFace: action.displayFace,
|
|
75
|
+
from: action.from,
|
|
76
|
+
shownFaces: /* @__PURE__ */ new Set([action.displayFace]),
|
|
77
|
+
queue: []
|
|
78
|
+
};
|
|
79
|
+
case "SETTLE":
|
|
80
|
+
if (state.kind !== "settling") return state;
|
|
81
|
+
return {
|
|
82
|
+
kind: "idle",
|
|
83
|
+
displayFace: state.displayFace,
|
|
84
|
+
shownFaces: state.shownFaces
|
|
85
|
+
};
|
|
86
|
+
case "COMPLETE":
|
|
87
|
+
return {
|
|
88
|
+
kind: "idle",
|
|
89
|
+
displayFace: action.displayFace,
|
|
90
|
+
shownFaces: /* @__PURE__ */ new Set([action.displayFace])
|
|
91
|
+
};
|
|
92
|
+
case "ENQUEUE":
|
|
93
|
+
if (state.kind === "idle") return state;
|
|
94
|
+
return { ...state, queue: [...state.queue, action.nav] };
|
|
95
|
+
case "ABORT":
|
|
96
|
+
return {
|
|
97
|
+
kind: "idle",
|
|
98
|
+
displayFace: action.displayFace,
|
|
99
|
+
shownFaces: /* @__PURE__ */ new Set([action.displayFace])
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var buildGoInstantAction = (displayFace, from) => ({
|
|
104
|
+
type: "GO_INSTANT",
|
|
105
|
+
displayFace,
|
|
106
|
+
from
|
|
107
|
+
});
|
|
108
|
+
var buildGoStepAction = (to, from) => ({
|
|
109
|
+
type: "GO_STEP",
|
|
110
|
+
to,
|
|
111
|
+
from,
|
|
112
|
+
shownFaces: /* @__PURE__ */ new Set([from, to])
|
|
113
|
+
});
|
|
114
|
+
var toPhase = (state) => {
|
|
115
|
+
switch (state.kind) {
|
|
116
|
+
case "idle":
|
|
117
|
+
case "settling":
|
|
118
|
+
return { kind: "idle" };
|
|
119
|
+
case "animating":
|
|
120
|
+
return { kind: "animating" };
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// src/orchestration.ts
|
|
125
|
+
var resolveNavigation = (state, rawTarget, opts, animation) => {
|
|
126
|
+
if (state.kind !== "idle") {
|
|
127
|
+
const t2 = resolveTransition(state.displayFace, rawTarget, opts, animation);
|
|
128
|
+
if (t2.kind === "noop") return { kind: "noop" };
|
|
129
|
+
const isImmediate = !animation || t2.to === state.from;
|
|
130
|
+
if (!isImmediate) return { kind: "enqueue", nav: { face: t2.to, animation } };
|
|
131
|
+
return { kind: "abort" };
|
|
132
|
+
}
|
|
133
|
+
const from = state.displayFace;
|
|
134
|
+
const t = resolveTransition(from, rawTarget, opts, animation);
|
|
135
|
+
if (t.kind === "noop") return { kind: "noop" };
|
|
136
|
+
return { kind: "go", from, to: t.to, doAnimate: t.doAnimate };
|
|
137
|
+
};
|
|
138
|
+
var planNavigation = (state, rawTarget, opts, animation) => {
|
|
139
|
+
const decision = resolveNavigation(state, rawTarget, opts, animation);
|
|
140
|
+
switch (decision.kind) {
|
|
141
|
+
case "noop":
|
|
142
|
+
return { effect: "noop" };
|
|
143
|
+
case "enqueue":
|
|
144
|
+
return { effect: "enqueue", action: { type: "ENQUEUE", nav: decision.nav } };
|
|
145
|
+
case "abort":
|
|
146
|
+
return { effect: "abort" };
|
|
147
|
+
case "go":
|
|
148
|
+
return decision.doAnimate ? {
|
|
149
|
+
effect: "animate",
|
|
150
|
+
from: decision.from,
|
|
151
|
+
to: decision.to,
|
|
152
|
+
action: buildGoStepAction(decision.to, decision.from)
|
|
153
|
+
} : {
|
|
154
|
+
effect: "instant",
|
|
155
|
+
from: decision.from,
|
|
156
|
+
to: decision.to,
|
|
157
|
+
action: buildGoInstantAction(decision.to, decision.from)
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
var buildDrainResult = (settledFace, queue, opts) => {
|
|
162
|
+
for (let i = 0; i < queue.length; i++) {
|
|
163
|
+
const pending = queue[i];
|
|
164
|
+
const t = resolveTransition(settledFace, pending.face, opts, pending.animation);
|
|
165
|
+
if (t.kind !== "noop") {
|
|
166
|
+
return { kind: "navigate", nav: pending, enqueue: queue.slice(i + 1) };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return { kind: "empty" };
|
|
170
|
+
};
|
|
171
|
+
export {
|
|
172
|
+
DEFAULT_DELAY,
|
|
173
|
+
DEFAULT_DURATION,
|
|
174
|
+
DEFAULT_EASING,
|
|
175
|
+
DEFAULT_HEIGHT,
|
|
176
|
+
DEFAULT_PERSPECTIVE,
|
|
177
|
+
DEFAULT_SIZE,
|
|
178
|
+
FOCUSABLE,
|
|
179
|
+
INITIAL_STATE,
|
|
180
|
+
MAX_FACE_PCS,
|
|
181
|
+
buildDrainResult,
|
|
182
|
+
buildGoInstantAction,
|
|
183
|
+
buildGoStepAction,
|
|
184
|
+
calcFaceTransform,
|
|
185
|
+
getFaceParity,
|
|
186
|
+
normalizeOptions,
|
|
187
|
+
planNavigation,
|
|
188
|
+
reducer,
|
|
189
|
+
resolveNavigation,
|
|
190
|
+
resolveTransition,
|
|
191
|
+
shouldAnimate,
|
|
192
|
+
toPhase
|
|
193
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@futaba-soft/turnbox-core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Core logic for TurnBox — pure functions for 3D box animation geometry, state, and transitions (no DOM dependency)",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"3d",
|
|
7
|
+
"animation",
|
|
8
|
+
"css3",
|
|
9
|
+
"transform",
|
|
10
|
+
"turnbox",
|
|
11
|
+
"pure"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "futaba-soft",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/futaba-soft/turnbox_js.git",
|
|
18
|
+
"directory": "packages/core"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/futaba-soft/turnbox_js#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/futaba-soft/turnbox_js/issues"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"import": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts"
|
|
29
|
+
},
|
|
30
|
+
"./internal": {
|
|
31
|
+
"import": "./dist/internal.js",
|
|
32
|
+
"types": "./dist/internal.d.ts"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"main": "./dist/index.js",
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"LICENSE"
|
|
41
|
+
],
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsup src/index.ts src/internal.ts --format esm --dts --out-dir dist",
|
|
47
|
+
"test": "vitest run"
|
|
48
|
+
}
|
|
6
49
|
}
|