@kazuhi-ra/turnbox-core 0.1.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.
@@ -0,0 +1,156 @@
1
+ // src/normalize.ts
2
+ var MAX_FACE_PCS = 4;
3
+ var DEFAULT_DURATION = 800;
4
+ var DEFAULT_DELAY = 50;
5
+ var DEFAULT_SIZE = 200;
6
+ var normalizeOptions = (options) => {
7
+ const facePcs = Math.min(options.facePcs, MAX_FACE_PCS);
8
+ const axis = options.axis ?? "X";
9
+ const direction = options.direction ?? "positive";
10
+ const duration = options.duration ?? DEFAULT_DURATION;
11
+ const delay = options.delay ?? DEFAULT_DELAY;
12
+ const width = options.width ?? DEFAULT_SIZE;
13
+ const height = options.height ?? DEFAULT_SIZE;
14
+ const even = options.even ?? (axis === "Y" ? width : height);
15
+ const length = axis === "Y" ? width : height;
16
+ const fixed = even === length;
17
+ const rawType = options.type ?? "real";
18
+ const type = !fixed && rawType === "skip" ? "real" : rawType;
19
+ const geometry = fixed ? { kind: "fixed", axis, length } : { kind: "variable", axis, length, even };
20
+ return { facePcs, direction, type, duration, delay, geometry };
21
+ };
22
+
23
+ // src/transform.ts
24
+ var TRANSFORM_ORIGIN_CENTER = "50% 50%";
25
+ var TRANSFORM_ORIGIN_TOP_EDGE = "50% 0px";
26
+ var TRANSFORM_ORIGIN_LEFT_EDGE = "0px 50%";
27
+ var getFaceParity = (faceNum) => faceNum % 2 !== 0 ? "odd" : "even";
28
+ var calcBaseDeg = (currentFace, faceNum) => (currentFace - faceNum) * -90;
29
+ var isSkipWrapEdge = (currentFace, faceNum) => currentFace === MAX_FACE_PCS && faceNum === 1 || currentFace === 1 && faceNum === MAX_FACE_PCS;
30
+ var applyAnimationType = (deg, currentFace, faceNum, type) => {
31
+ if (type === "skip") {
32
+ const clamped = Math.sign(deg) * 90;
33
+ return isSkipWrapEdge(currentFace, faceNum) ? clamped * -1 : clamped;
34
+ }
35
+ if (type === "repeat") {
36
+ if (getFaceParity(currentFace) === "odd" && getFaceParity(faceNum) === "even") return 90;
37
+ if (getFaceParity(currentFace) === "even" && getFaceParity(faceNum) === "odd") return -90;
38
+ }
39
+ return deg;
40
+ };
41
+ var applyDirection = (deg, direction) => {
42
+ if (direction !== "negative") return deg;
43
+ const flipped = deg * -1;
44
+ return Object.is(flipped, -0) ? 0 : flipped;
45
+ };
46
+ var calcDeg = (currentFace, faceNum, options) => {
47
+ const base = calcBaseDeg(currentFace, faceNum);
48
+ const typed = applyAnimationType(base, currentFace, faceNum, options.type);
49
+ return applyDirection(typed, options.direction);
50
+ };
51
+ var faceVisibility = (deg) => {
52
+ const abs = Math.abs(deg);
53
+ if (abs === 0 || abs === 360) return "front";
54
+ if (abs === 90 || abs === 270) return "side";
55
+ return "hidden";
56
+ };
57
+ var Z_INDEX = { front: 20, side: 10, hidden: 0 };
58
+ var calcZIndex = (deg) => Z_INDEX[faceVisibility(deg)];
59
+ var classifyDeg = (deg) => {
60
+ if (deg === 0 || Math.abs(deg) === 360) return "zero";
61
+ if (deg === 90 || deg === -270) return "pos90";
62
+ if (Math.abs(deg) === 180) return "half";
63
+ return "neg90";
64
+ };
65
+ var calcFixedTranslate = (deg, axis, length) => {
66
+ const abs = Math.abs(deg);
67
+ if (abs === 0 || abs === 360) return [0, 0, 0];
68
+ if (abs === 180) return [0, 0, length];
69
+ const changeHalf = (deg < 0 ? -length : length) / 2;
70
+ const half = length / 2;
71
+ if (axis === "Y") return [changeHalf, 0, half];
72
+ return abs === 90 ? [0, -changeHalf, half] : [0, changeHalf, half];
73
+ };
74
+ var variableTranslateTable = {
75
+ Y: {
76
+ odd: {
77
+ zero: () => [0, 0, 0],
78
+ pos90: (_l, e) => [e, 0, 0],
79
+ half: (l, e) => [e * 2 - l, 0, e],
80
+ neg90: (l, e) => [e - l, 0, e]
81
+ },
82
+ even: {
83
+ zero: () => [0, 0, 0],
84
+ pos90: (l, e) => [e, 0, -(e - l)],
85
+ half: (l, e) => [e, 0, l],
86
+ neg90: (_l, e) => [0, 0, e]
87
+ }
88
+ },
89
+ X: {
90
+ odd: {
91
+ zero: () => [0, 0, 0],
92
+ pos90: (l, e) => [0, e - l, e],
93
+ half: (l, e) => [0, e * 2 - l, e],
94
+ neg90: (_l, e) => [0, e, 0]
95
+ },
96
+ even: {
97
+ zero: () => [0, 0, 0],
98
+ pos90: (_l, e) => [0, 0, e],
99
+ half: (l, e) => [0, e, l],
100
+ neg90: (l, e) => [0, e, -(e - l)]
101
+ }
102
+ }
103
+ };
104
+ var adjustTranslateTable = {
105
+ Y: {
106
+ odd: {
107
+ zero: () => [0, 0, 0],
108
+ pos90: (_l, e) => [0, 0, e],
109
+ half: (l, e) => [-l, 0, e],
110
+ neg90: (l, _e) => [-l, 0, 0]
111
+ },
112
+ even: {
113
+ zero: () => [0, 0, 0],
114
+ pos90: (l, _e) => [0, 0, l],
115
+ half: (l, e) => [-e, 0, l],
116
+ neg90: (_l, e) => [-e, 0, 0]
117
+ }
118
+ },
119
+ X: {
120
+ odd: {
121
+ zero: () => [0, 0, 0],
122
+ pos90: (l, _e) => [0, -l, 0],
123
+ half: (l, e) => [0, -l, e],
124
+ neg90: (_l, e) => [0, 0, e]
125
+ },
126
+ even: {
127
+ zero: () => [0, 0, 0],
128
+ pos90: (_l, e) => [0, -e, 0],
129
+ half: (l, e) => [0, -e, l],
130
+ neg90: (l, _e) => [0, 0, l]
131
+ }
132
+ }
133
+ };
134
+ var lookupTranslate = (table, deg, faceNum, geometry) => table[geometry.axis][getFaceParity(faceNum)][classifyDeg(deg)](geometry.length, geometry.even);
135
+ var calcFaceTransform = (currentFace, faceNum, options) => {
136
+ const { geometry } = options;
137
+ const deg = calcDeg(currentFace, faceNum, options);
138
+ const [x, y, z] = geometry.kind === "fixed" ? calcFixedTranslate(deg, geometry.axis, geometry.length) : lookupTranslate(variableTranslateTable, deg, faceNum, geometry);
139
+ const transformOrigin = geometry.kind === "fixed" ? TRANSFORM_ORIGIN_CENTER : geometry.axis === "X" ? `50% ${geometry.even}px` : `${geometry.even}px 50%`;
140
+ return { axis: geometry.axis, deg, x, y, z, zIndex: calcZIndex(deg), transformOrigin };
141
+ };
142
+ var calcAdjustFaceTransform = (currentFace, faceNum, options) => {
143
+ const { geometry } = options;
144
+ const deg = calcDeg(currentFace, faceNum, options);
145
+ const [x, y, z] = geometry.kind === "variable" ? lookupTranslate(adjustTranslateTable, deg, faceNum, geometry) : [0, 0, 0];
146
+ const transformOrigin = geometry.axis === "X" ? TRANSFORM_ORIGIN_TOP_EDGE : TRANSFORM_ORIGIN_LEFT_EDGE;
147
+ return { axis: geometry.axis, deg, x, y, z, zIndex: calcZIndex(deg), transformOrigin };
148
+ };
149
+
150
+ export {
151
+ MAX_FACE_PCS,
152
+ normalizeOptions,
153
+ getFaceParity,
154
+ calcFaceTransform,
155
+ calcAdjustFaceTransform
156
+ };
@@ -0,0 +1,161 @@
1
+ // src/normalize.ts
2
+ var MAX_FACE_PCS = 4;
3
+ var DEFAULT_DURATION = 800;
4
+ var DEFAULT_DELAY = 50;
5
+ var DEFAULT_SIZE = 200;
6
+ var normalizeOptions = (options) => {
7
+ const faces = Math.min(options.faces, MAX_FACE_PCS);
8
+ const axis = options.axis ?? "X";
9
+ const direction = options.direction ?? "positive";
10
+ const duration = options.duration ?? DEFAULT_DURATION;
11
+ const delay = options.delay ?? DEFAULT_DELAY;
12
+ const width = options.width ?? DEFAULT_SIZE;
13
+ const height = options.height ?? DEFAULT_SIZE;
14
+ const even = options.even ?? (axis === "Y" ? width : height);
15
+ const length = axis === "Y" ? width : height;
16
+ const fixed = even === length;
17
+ const rawType = options.type ?? "real";
18
+ const type = !fixed && rawType === "skip" ? "real" : rawType;
19
+ const geometry = fixed ? { kind: "fixed", axis, length } : { kind: "variable", axis, length, even };
20
+ const easing = options.easing ?? "ease";
21
+ const perspective = options.perspective ?? 1e3;
22
+ return { faces, direction, type, duration, delay, easing, perspective, geometry };
23
+ };
24
+
25
+ // src/transform.ts
26
+ var TRANSFORM_ORIGIN_CENTER = "50% 50%";
27
+ var TRANSFORM_ORIGIN_TOP_EDGE = "50% 0px";
28
+ var TRANSFORM_ORIGIN_LEFT_EDGE = "0px 50%";
29
+ var getFaceParity = (faceNum) => faceNum % 2 !== 0 ? "odd" : "even";
30
+ var calcBaseDeg = (currentFace, faceNum) => (currentFace - faceNum) * -90;
31
+ var isSkipWrapEdge = (currentFace, faceNum) => currentFace === MAX_FACE_PCS && faceNum === 1 || currentFace === 1 && faceNum === MAX_FACE_PCS;
32
+ var applyAnimationType = (deg, currentFace, faceNum, type) => {
33
+ if (type === "skip") {
34
+ const clamped = Math.sign(deg) * 90;
35
+ return isSkipWrapEdge(currentFace, faceNum) ? clamped * -1 : clamped;
36
+ }
37
+ if (type === "repeat") {
38
+ if (getFaceParity(currentFace) === "odd" && getFaceParity(faceNum) === "even") return 90;
39
+ if (getFaceParity(currentFace) === "even" && getFaceParity(faceNum) === "odd") return -90;
40
+ }
41
+ return deg;
42
+ };
43
+ var applyDirection = (deg, direction) => {
44
+ if (direction !== "negative") return deg;
45
+ const flipped = deg * -1;
46
+ return Object.is(flipped, -0) ? 0 : flipped;
47
+ };
48
+ var calcDeg = (currentFace, faceNum, options) => {
49
+ const base = calcBaseDeg(currentFace, faceNum);
50
+ const typed = applyAnimationType(base, currentFace, faceNum, options.type);
51
+ return applyDirection(typed, options.direction);
52
+ };
53
+ var faceVisibility = (deg) => {
54
+ const abs = Math.abs(deg);
55
+ if (abs === 0 || abs === 360) return "front";
56
+ if (abs === 90 || abs === 270) return "side";
57
+ return "hidden";
58
+ };
59
+ var Z_INDEX = { front: 20, side: 10, hidden: 0 };
60
+ var calcZIndex = (deg) => Z_INDEX[faceVisibility(deg)];
61
+ var classifyDeg = (deg) => {
62
+ if (deg === 0 || Math.abs(deg) === 360) return "zero";
63
+ if (deg === 90 || deg === -270) return "pos90";
64
+ if (Math.abs(deg) === 180) return "half";
65
+ return "neg90";
66
+ };
67
+ var calcFixedTranslate = (deg, axis, length) => {
68
+ const abs = Math.abs(deg);
69
+ if (abs === 0 || abs === 360) return [0, 0, 0];
70
+ if (abs === 180) return [0, 0, length];
71
+ const changeHalf = (deg < 0 ? -length : length) / 2;
72
+ const half = length / 2;
73
+ if (axis === "Y") return [changeHalf, 0, half];
74
+ return abs === 90 ? [0, -changeHalf, half] : [0, changeHalf, half];
75
+ };
76
+ var variableTranslateTable = {
77
+ Y: {
78
+ odd: {
79
+ zero: () => [0, 0, 0],
80
+ pos90: (_l, e) => [e, 0, 0],
81
+ half: (l, e) => [e * 2 - l, 0, e],
82
+ neg90: (l, e) => [e - l, 0, e]
83
+ },
84
+ even: {
85
+ zero: () => [0, 0, 0],
86
+ pos90: (l, e) => [e, 0, -(e - l)],
87
+ half: (l, e) => [e, 0, l],
88
+ neg90: (_l, e) => [0, 0, e]
89
+ }
90
+ },
91
+ X: {
92
+ odd: {
93
+ zero: () => [0, 0, 0],
94
+ pos90: (l, e) => [0, e - l, e],
95
+ half: (l, e) => [0, e * 2 - l, e],
96
+ neg90: (_l, e) => [0, e, 0]
97
+ },
98
+ even: {
99
+ zero: () => [0, 0, 0],
100
+ pos90: (_l, e) => [0, 0, e],
101
+ half: (l, e) => [0, e, l],
102
+ neg90: (l, e) => [0, e, -(e - l)]
103
+ }
104
+ }
105
+ };
106
+ var adjustTranslateTable = {
107
+ Y: {
108
+ odd: {
109
+ zero: () => [0, 0, 0],
110
+ pos90: (_l, e) => [0, 0, e],
111
+ half: (l, e) => [-l, 0, e],
112
+ neg90: (l, _e) => [-l, 0, 0]
113
+ },
114
+ even: {
115
+ zero: () => [0, 0, 0],
116
+ pos90: (l, _e) => [0, 0, l],
117
+ half: (l, e) => [-e, 0, l],
118
+ neg90: (_l, e) => [-e, 0, 0]
119
+ }
120
+ },
121
+ X: {
122
+ odd: {
123
+ zero: () => [0, 0, 0],
124
+ pos90: (l, _e) => [0, -l, 0],
125
+ half: (l, e) => [0, -l, e],
126
+ neg90: (_l, e) => [0, 0, e]
127
+ },
128
+ even: {
129
+ zero: () => [0, 0, 0],
130
+ pos90: (_l, e) => [0, -e, 0],
131
+ half: (l, e) => [0, -e, l],
132
+ neg90: (l, _e) => [0, 0, l]
133
+ }
134
+ }
135
+ };
136
+ var lookupTranslate = (table, deg, faceNum, geometry) => table[geometry.axis][getFaceParity(faceNum)][classifyDeg(deg)](geometry.length, geometry.even);
137
+ var calcFaceTransform = (currentFace, faceNum, options) => {
138
+ const { geometry } = options;
139
+ const deg = calcDeg(currentFace, faceNum, options);
140
+ const [x, y, z] = geometry.kind === "fixed" ? calcFixedTranslate(deg, geometry.axis, geometry.length) : lookupTranslate(variableTranslateTable, deg, faceNum, geometry);
141
+ const transformOrigin = geometry.kind === "fixed" ? TRANSFORM_ORIGIN_CENTER : geometry.axis === "X" ? `50% ${geometry.even}px` : `${geometry.even}px 50%`;
142
+ return { axis: geometry.axis, deg, x, y, z, zIndex: calcZIndex(deg), transformOrigin };
143
+ };
144
+ var calcAdjustFaceTransform = (currentFace, faceNum, options) => {
145
+ const { geometry } = options;
146
+ const deg = calcDeg(currentFace, faceNum, options);
147
+ const [x, y, z] = geometry.kind === "variable" ? lookupTranslate(adjustTranslateTable, deg, faceNum, geometry) : [0, 0, 0];
148
+ const transformOrigin = geometry.axis === "X" ? TRANSFORM_ORIGIN_TOP_EDGE : TRANSFORM_ORIGIN_LEFT_EDGE;
149
+ return { axis: geometry.axis, deg, x, y, z, zIndex: calcZIndex(deg), transformOrigin };
150
+ };
151
+
152
+ export {
153
+ MAX_FACE_PCS,
154
+ DEFAULT_DURATION,
155
+ DEFAULT_DELAY,
156
+ DEFAULT_SIZE,
157
+ normalizeOptions,
158
+ getFaceParity,
159
+ calcFaceTransform,
160
+ calcAdjustFaceTransform
161
+ };
@@ -0,0 +1,159 @@
1
+ // src/normalize.ts
2
+ var MAX_FACE_PCS = 4;
3
+ var DEFAULT_DURATION = 800;
4
+ var DEFAULT_DELAY = 50;
5
+ var DEFAULT_SIZE = 200;
6
+ var normalizeOptions = (options) => {
7
+ const facePcs = Math.min(options.facePcs, MAX_FACE_PCS);
8
+ const axis = options.axis ?? "X";
9
+ const direction = options.direction ?? "positive";
10
+ const duration = options.duration ?? DEFAULT_DURATION;
11
+ const delay = options.delay ?? DEFAULT_DELAY;
12
+ const width = options.width ?? DEFAULT_SIZE;
13
+ const height = options.height ?? DEFAULT_SIZE;
14
+ const even = options.even ?? (axis === "Y" ? width : height);
15
+ const length = axis === "Y" ? width : height;
16
+ const fixed = even === length;
17
+ const rawType = options.type ?? "real";
18
+ const type = !fixed && rawType === "skip" ? "real" : rawType;
19
+ const geometry = fixed ? { kind: "fixed", axis, length } : { kind: "variable", axis, length, even };
20
+ return { facePcs, direction, type, duration, delay, geometry };
21
+ };
22
+
23
+ // src/transform.ts
24
+ var TRANSFORM_ORIGIN_CENTER = "50% 50%";
25
+ var TRANSFORM_ORIGIN_TOP_EDGE = "50% 0px";
26
+ var TRANSFORM_ORIGIN_LEFT_EDGE = "0px 50%";
27
+ var getFaceParity = (faceNum) => faceNum % 2 !== 0 ? "odd" : "even";
28
+ var calcBaseDeg = (currentFace, faceNum) => (currentFace - faceNum) * -90;
29
+ var isSkipWrapEdge = (currentFace, faceNum) => currentFace === MAX_FACE_PCS && faceNum === 1 || currentFace === 1 && faceNum === MAX_FACE_PCS;
30
+ var applyAnimationType = (deg, currentFace, faceNum, type) => {
31
+ if (type === "skip") {
32
+ const clamped = Math.sign(deg) * 90;
33
+ return isSkipWrapEdge(currentFace, faceNum) ? clamped * -1 : clamped;
34
+ }
35
+ if (type === "repeat") {
36
+ if (getFaceParity(currentFace) === "odd" && getFaceParity(faceNum) === "even") return 90;
37
+ if (getFaceParity(currentFace) === "even" && getFaceParity(faceNum) === "odd") return -90;
38
+ }
39
+ return deg;
40
+ };
41
+ var applyDirection = (deg, direction) => {
42
+ if (direction !== "negative") return deg;
43
+ const flipped = deg * -1;
44
+ return Object.is(flipped, -0) ? 0 : flipped;
45
+ };
46
+ var calcDeg = (currentFace, faceNum, options) => {
47
+ const base = calcBaseDeg(currentFace, faceNum);
48
+ const typed = applyAnimationType(base, currentFace, faceNum, options.type);
49
+ return applyDirection(typed, options.direction);
50
+ };
51
+ var faceVisibility = (deg) => {
52
+ const abs = Math.abs(deg);
53
+ if (abs === 0 || abs === 360) return "front";
54
+ if (abs === 90 || abs === 270) return "side";
55
+ return "hidden";
56
+ };
57
+ var Z_INDEX = { front: 20, side: 10, hidden: 0 };
58
+ var calcZIndex = (deg) => Z_INDEX[faceVisibility(deg)];
59
+ var classifyDeg = (deg) => {
60
+ if (deg === 0 || Math.abs(deg) === 360) return "zero";
61
+ if (deg === 90 || deg === -270) return "pos90";
62
+ if (Math.abs(deg) === 180) return "half";
63
+ return "neg90";
64
+ };
65
+ var calcFixedTranslate = (deg, axis, length) => {
66
+ const abs = Math.abs(deg);
67
+ if (abs === 0 || abs === 360) return [0, 0, 0];
68
+ if (abs === 180) return [0, 0, length];
69
+ const changeHalf = (deg < 0 ? -length : length) / 2;
70
+ const half = length / 2;
71
+ if (axis === "Y") return [changeHalf, 0, half];
72
+ return abs === 90 ? [0, -changeHalf, half] : [0, changeHalf, half];
73
+ };
74
+ var variableTranslateTable = {
75
+ Y: {
76
+ odd: {
77
+ zero: () => [0, 0, 0],
78
+ pos90: (_l, e) => [e, 0, 0],
79
+ half: (l, e) => [e * 2 - l, 0, e],
80
+ neg90: (l, e) => [e - l, 0, e]
81
+ },
82
+ even: {
83
+ zero: () => [0, 0, 0],
84
+ pos90: (l, e) => [e, 0, -(e - l)],
85
+ half: (l, e) => [e, 0, l],
86
+ neg90: (_l, e) => [0, 0, e]
87
+ }
88
+ },
89
+ X: {
90
+ odd: {
91
+ zero: () => [0, 0, 0],
92
+ pos90: (l, e) => [0, e - l, e],
93
+ half: (l, e) => [0, e * 2 - l, e],
94
+ neg90: (_l, e) => [0, e, 0]
95
+ },
96
+ even: {
97
+ zero: () => [0, 0, 0],
98
+ pos90: (_l, e) => [0, 0, e],
99
+ half: (l, e) => [0, e, l],
100
+ neg90: (l, e) => [0, e, -(e - l)]
101
+ }
102
+ }
103
+ };
104
+ var adjustTranslateTable = {
105
+ Y: {
106
+ odd: {
107
+ zero: () => [0, 0, 0],
108
+ pos90: (_l, e) => [0, 0, e],
109
+ half: (l, e) => [-l, 0, e],
110
+ neg90: (l, _e) => [-l, 0, 0]
111
+ },
112
+ even: {
113
+ zero: () => [0, 0, 0],
114
+ pos90: (l, _e) => [0, 0, l],
115
+ half: (l, e) => [-e, 0, l],
116
+ neg90: (_l, e) => [-e, 0, 0]
117
+ }
118
+ },
119
+ X: {
120
+ odd: {
121
+ zero: () => [0, 0, 0],
122
+ pos90: (l, _e) => [0, -l, 0],
123
+ half: (l, e) => [0, -l, e],
124
+ neg90: (_l, e) => [0, 0, e]
125
+ },
126
+ even: {
127
+ zero: () => [0, 0, 0],
128
+ pos90: (_l, e) => [0, -e, 0],
129
+ half: (l, e) => [0, -e, l],
130
+ neg90: (l, _e) => [0, 0, l]
131
+ }
132
+ }
133
+ };
134
+ var lookupTranslate = (table, deg, faceNum, geometry) => table[geometry.axis][getFaceParity(faceNum)][classifyDeg(deg)](geometry.length, geometry.even);
135
+ var calcFaceTransform = (currentFace, faceNum, options) => {
136
+ const { geometry } = options;
137
+ const deg = calcDeg(currentFace, faceNum, options);
138
+ const [x, y, z] = geometry.kind === "fixed" ? calcFixedTranslate(deg, geometry.axis, geometry.length) : lookupTranslate(variableTranslateTable, deg, faceNum, geometry);
139
+ const transformOrigin = geometry.kind === "fixed" ? TRANSFORM_ORIGIN_CENTER : geometry.axis === "X" ? `50% ${geometry.even}px` : `${geometry.even}px 50%`;
140
+ return { axis: geometry.axis, deg, x, y, z, zIndex: calcZIndex(deg), transformOrigin };
141
+ };
142
+ var calcAdjustFaceTransform = (currentFace, faceNum, options) => {
143
+ const { geometry } = options;
144
+ const deg = calcDeg(currentFace, faceNum, options);
145
+ const [x, y, z] = geometry.kind === "variable" ? lookupTranslate(adjustTranslateTable, deg, faceNum, geometry) : [0, 0, 0];
146
+ const transformOrigin = geometry.axis === "X" ? TRANSFORM_ORIGIN_TOP_EDGE : TRANSFORM_ORIGIN_LEFT_EDGE;
147
+ return { axis: geometry.axis, deg, x, y, z, zIndex: calcZIndex(deg), transformOrigin };
148
+ };
149
+
150
+ export {
151
+ MAX_FACE_PCS,
152
+ DEFAULT_DURATION,
153
+ DEFAULT_DELAY,
154
+ DEFAULT_SIZE,
155
+ normalizeOptions,
156
+ getFaceParity,
157
+ calcFaceTransform,
158
+ calcAdjustFaceTransform
159
+ };
@@ -0,0 +1,83 @@
1
+ type Axis = "X" | "Y";
2
+ type Direction = "positive" | "negative";
3
+ type AnimationType = "real" | "repeat" | "skip";
4
+ declare const VIRTUAL_PREV_WRAP: 0;
5
+ declare const VIRTUAL_NEXT_WRAP: 5;
6
+ type VirtualWrapFace = typeof VIRTUAL_PREV_WRAP | typeof VIRTUAL_NEXT_WRAP;
7
+ type Transition = {
8
+ kind: "noop";
9
+ } | {
10
+ kind: "step";
11
+ to: number;
12
+ doAnimate: boolean;
13
+ hasAdjust: boolean;
14
+ } | {
15
+ kind: "virtual-wrap";
16
+ via: VirtualWrapFace;
17
+ landAt: 1 | 4;
18
+ doAnimate: boolean;
19
+ } | {
20
+ kind: "direct-wrap";
21
+ to: number;
22
+ doAnimate: boolean;
23
+ };
24
+ type RotationDeg = -360 | -270 | -180 | -90 | 0 | 90 | 180 | 270 | 360;
25
+ type FaceVisibility = "front" | "side" | "hidden";
26
+ type FaceParity = "odd" | "even";
27
+ type Geometry = {
28
+ kind: "fixed";
29
+ axis: Axis;
30
+ length: number;
31
+ } | {
32
+ kind: "variable";
33
+ axis: Axis;
34
+ length: number;
35
+ even: number;
36
+ };
37
+ type FaceCount = 2 | 3 | 4;
38
+ type TurnBoxOptions = {
39
+ faces: FaceCount;
40
+ axis?: Axis;
41
+ direction?: Direction;
42
+ type?: AnimationType;
43
+ duration?: number;
44
+ delay?: number;
45
+ easing?: string;
46
+ perspective?: number;
47
+ width?: number;
48
+ height?: number;
49
+ even?: number;
50
+ onChange?: (face: number) => void;
51
+ onAnimationEnd?: (face: number) => void;
52
+ };
53
+ type NormalizedOptions = {
54
+ faces: FaceCount;
55
+ direction: Direction;
56
+ type: AnimationType;
57
+ duration: number;
58
+ delay: number;
59
+ easing: string;
60
+ perspective: number;
61
+ geometry: Geometry;
62
+ };
63
+ type FaceTransform = {
64
+ axis: Axis;
65
+ deg: RotationDeg;
66
+ x: number;
67
+ y: number;
68
+ z: number;
69
+ zIndex: number;
70
+ transformOrigin: string;
71
+ };
72
+
73
+ declare const MAX_FACE_PCS = 4;
74
+ declare const DEFAULT_DURATION = 800;
75
+ declare const DEFAULT_DELAY = 50;
76
+ declare const DEFAULT_SIZE = 200;
77
+ declare const normalizeOptions: (options: TurnBoxOptions) => NormalizedOptions;
78
+
79
+ declare const getFaceParity: (faceNum: number) => FaceParity;
80
+ declare const calcFaceTransform: (currentFace: number, faceNum: number, options: NormalizedOptions) => FaceTransform;
81
+ declare const calcAdjustFaceTransform: (currentFace: number, faceNum: number, options: NormalizedOptions) => FaceTransform;
82
+
83
+ 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 RotationDeg as R, type Transition as T, VIRTUAL_NEXT_WRAP as V, type Axis as a, DEFAULT_DURATION as b, DEFAULT_SIZE as c, type Direction as d, type FaceParity as e, type FaceTransform as f, type FaceVisibility as g, type TurnBoxOptions as h, VIRTUAL_PREV_WRAP as i, type VirtualWrapFace as j, calcAdjustFaceTransform as k, calcFaceTransform as l, getFaceParity as m, normalizeOptions as n };
@@ -0,0 +1,86 @@
1
+ type Axis = "X" | "Y";
2
+ type Direction = "positive" | "negative";
3
+ type AnimationType = "real" | "repeat" | "skip";
4
+ declare const VIRTUAL_PREV_WRAP: 0;
5
+ declare const VIRTUAL_NEXT_WRAP: 5;
6
+ type VirtualWrapFace = typeof VIRTUAL_PREV_WRAP | typeof VIRTUAL_NEXT_WRAP;
7
+ type Transition = {
8
+ kind: "noop";
9
+ } | {
10
+ kind: "step";
11
+ to: number;
12
+ doAnimate: boolean;
13
+ hasAdjust: boolean;
14
+ } | {
15
+ kind: "virtual-wrap";
16
+ via: VirtualWrapFace;
17
+ landAt: 1 | 4;
18
+ doAnimate: boolean;
19
+ } | {
20
+ kind: "direct-wrap";
21
+ to: number;
22
+ doAnimate: boolean;
23
+ };
24
+ type RotationDeg = -360 | -270 | -180 | -90 | 0 | 90 | 180 | 270 | 360;
25
+ type FaceVisibility = "front" | "side" | "hidden";
26
+ type FaceParity = "odd" | "even";
27
+ type Geometry = {
28
+ kind: "fixed";
29
+ axis: Axis;
30
+ length: number;
31
+ } | {
32
+ kind: "variable";
33
+ axis: Axis;
34
+ length: number;
35
+ even: number;
36
+ };
37
+ type FaceCount = 2 | 3 | 4;
38
+ type TurnBoxOptions = {
39
+ faces: FaceCount;
40
+ axis?: Axis;
41
+ direction?: Direction;
42
+ type?: AnimationType;
43
+ duration?: number;
44
+ delay?: number;
45
+ easing?: string;
46
+ perspective?: number;
47
+ width?: number;
48
+ height?: number;
49
+ even?: number;
50
+ onChange?: (face: number) => void;
51
+ onAnimationEnd?: (face: number) => void;
52
+ };
53
+ type NormalizedOptions = {
54
+ faces: FaceCount;
55
+ direction: Direction;
56
+ type: AnimationType;
57
+ duration: number;
58
+ delay: number;
59
+ easing: string;
60
+ perspective: number;
61
+ geometry: Geometry;
62
+ };
63
+ type FaceTransform = {
64
+ axis: Axis;
65
+ deg: RotationDeg;
66
+ x: number;
67
+ y: number;
68
+ z: number;
69
+ zIndex: number;
70
+ transformOrigin: string;
71
+ };
72
+
73
+ declare const MAX_FACE_PCS = 4;
74
+ declare const DEFAULT_DURATION = 200;
75
+ declare const DEFAULT_DELAY = 0;
76
+ declare const DEFAULT_EASING = "linear";
77
+ declare const DEFAULT_PERSPECTIVE = 800;
78
+ declare const DEFAULT_SIZE = 200;
79
+ declare const DEFAULT_HEIGHT = 50;
80
+ declare const normalizeOptions: (options: TurnBoxOptions) => NormalizedOptions;
81
+
82
+ declare const getFaceParity: (faceNum: number) => FaceParity;
83
+ declare const calcFaceTransform: (currentFace: number, faceNum: number, options: NormalizedOptions) => FaceTransform;
84
+ declare const calcAdjustFaceTransform: (currentFace: number, faceNum: number, options: NormalizedOptions) => FaceTransform;
85
+
86
+ 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 RotationDeg as R, type Transition as T, VIRTUAL_NEXT_WRAP as V, 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 TurnBoxOptions as k, VIRTUAL_PREV_WRAP as l, type VirtualWrapFace as m, calcAdjustFaceTransform as n, calcFaceTransform as o, getFaceParity as p, normalizeOptions as q };