anim-3d-obj 2.0.9 → 2.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -29
- package/dist/index.cjs +673 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +57 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.mts +91 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +646 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -41
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,673 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
|
|
8
|
+
function _interopNamespace(e) {
|
|
9
|
+
if (e && e.__esModule) return e;
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
27
|
+
|
|
28
|
+
// src/components/Obj.tsx
|
|
29
|
+
|
|
30
|
+
// src/keyframes.ts
|
|
31
|
+
function ensureStyleTag() {
|
|
32
|
+
let tag = document.getElementById(
|
|
33
|
+
"anim3d-keyframes"
|
|
34
|
+
);
|
|
35
|
+
if (!tag) {
|
|
36
|
+
tag = document.createElement("style");
|
|
37
|
+
tag.id = "anim3d-keyframes";
|
|
38
|
+
document.head.appendChild(tag);
|
|
39
|
+
}
|
|
40
|
+
return tag;
|
|
41
|
+
}
|
|
42
|
+
function inject(css) {
|
|
43
|
+
if (typeof document === "undefined") return;
|
|
44
|
+
const tag = ensureStyleTag();
|
|
45
|
+
tag.appendChild(document.createTextNode(css));
|
|
46
|
+
}
|
|
47
|
+
function builtInKeyframes(name, cfg) {
|
|
48
|
+
const hi = cfg.degreesHi ?? 15;
|
|
49
|
+
const lo = cfg.degreesLow ?? -15;
|
|
50
|
+
switch (name) {
|
|
51
|
+
case "Y360":
|
|
52
|
+
return `@keyframes Y360 { from { transform: rotateY(0deg) } to { transform: rotateY(360deg) } }`;
|
|
53
|
+
case "X360":
|
|
54
|
+
return `@keyframes X360 { from { transform: rotateX(0deg) } to { transform: rotateX(360deg) } }`;
|
|
55
|
+
case "Z360":
|
|
56
|
+
return `@keyframes Z360 { from { transform: rotateZ(0deg) } to { transform: rotateZ(360deg) } }`;
|
|
57
|
+
case "rockY":
|
|
58
|
+
return `@keyframes rockY { 0%{ transform: rotateY(${lo}deg) } 50%{ transform: rotateY(${hi}deg) } 100%{ transform: rotateY(${lo}deg) } }`;
|
|
59
|
+
case "rockX":
|
|
60
|
+
return `@keyframes rockX { 0%{ transform: rotateX(${lo}deg) } 50%{ transform: rotateX(${hi}deg) } 100%{ transform: rotateX(${lo}deg) } }`;
|
|
61
|
+
default:
|
|
62
|
+
return "";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function resolveAnimation(cfg) {
|
|
66
|
+
if (!cfg) return null;
|
|
67
|
+
const name = cfg.name;
|
|
68
|
+
const builtIn = builtInKeyframes(name, cfg);
|
|
69
|
+
if (builtIn) {
|
|
70
|
+
const marker = `/*kf-${name}*/`;
|
|
71
|
+
if (typeof document !== "undefined") {
|
|
72
|
+
const tag = ensureStyleTag();
|
|
73
|
+
if (!tag.innerHTML.includes(marker)) {
|
|
74
|
+
inject(`${builtIn}
|
|
75
|
+
${marker}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return name;
|
|
79
|
+
}
|
|
80
|
+
return name;
|
|
81
|
+
}
|
|
82
|
+
function toAnimationShorthand(cfg) {
|
|
83
|
+
const name = resolveAnimation(cfg);
|
|
84
|
+
if (!cfg || !name) return null;
|
|
85
|
+
const dur = (cfg.duration ?? 10) + "s";
|
|
86
|
+
const delay = (cfg.delay ?? 0) + "s";
|
|
87
|
+
const iter = cfg.iterationCount ?? "infinite";
|
|
88
|
+
const dir = cfg.direction ?? "normal";
|
|
89
|
+
const timing = cfg.timing ?? "linear";
|
|
90
|
+
const fill = cfg.fillMode ?? "forwards";
|
|
91
|
+
const play = cfg.animationPlayState ?? "running";
|
|
92
|
+
return `${name} ${dur} ${timing} ${delay} ${iter} ${dir} ${fill} ${play}`;
|
|
93
|
+
}
|
|
94
|
+
function faceTransform3D(name, w, h, d) {
|
|
95
|
+
const hw = w / 2;
|
|
96
|
+
const hh = h / 2;
|
|
97
|
+
const hd = d / 2;
|
|
98
|
+
switch (name) {
|
|
99
|
+
case "front":
|
|
100
|
+
return `translate(-50%, -50%) translateZ(${hd}px)`;
|
|
101
|
+
case "back":
|
|
102
|
+
return `translate(-50%, -50%) rotateY(180deg) translateZ(${hd}px)`;
|
|
103
|
+
case "left":
|
|
104
|
+
return `translate(-50%, -50%) rotateY(-90deg) translateZ(${hw}px)`;
|
|
105
|
+
case "right":
|
|
106
|
+
return `translate(-50%, -50%) rotateY(90deg) translateZ(${hw}px)`;
|
|
107
|
+
case "top":
|
|
108
|
+
return `translate(-50%, -50%) rotateX(90deg) translateZ(${hh}px)`;
|
|
109
|
+
case "bottom":
|
|
110
|
+
return `translate(-50%, -50%) rotateX(-90deg) translateZ(${hh}px)`;
|
|
111
|
+
case "top_front":
|
|
112
|
+
return `translate(-50%, -50%) rotateX(45deg) translateZ(${hh}px)`;
|
|
113
|
+
case "top_rear":
|
|
114
|
+
return `translate(-50%, -50%) rotateX(135deg) translateZ(${hh}px)`;
|
|
115
|
+
case "bottom_front":
|
|
116
|
+
return `translate(-50%, -50%) rotateX(-45deg) translateZ(${hh}px)`;
|
|
117
|
+
case "bottom_rear":
|
|
118
|
+
return `translate(-50%, -50%) rotateX(-135deg) translateZ(${hh}px)`;
|
|
119
|
+
default:
|
|
120
|
+
return `translate(-50%, -50%) translateZ(${hd}px)`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function faceTransformFlat(name, w, h, d) {
|
|
124
|
+
const total = 2 * w + 2 * d;
|
|
125
|
+
const half = total / 2;
|
|
126
|
+
let cx;
|
|
127
|
+
switch (name) {
|
|
128
|
+
case "front":
|
|
129
|
+
cx = w / 2;
|
|
130
|
+
break;
|
|
131
|
+
case "right":
|
|
132
|
+
cx = w + d / 2;
|
|
133
|
+
break;
|
|
134
|
+
case "back":
|
|
135
|
+
cx = w + d + w / 2;
|
|
136
|
+
break;
|
|
137
|
+
case "left":
|
|
138
|
+
cx = w + d + w + d / 2;
|
|
139
|
+
break;
|
|
140
|
+
case "top":
|
|
141
|
+
case "top_front":
|
|
142
|
+
case "top_rear":
|
|
143
|
+
cx = w / 2;
|
|
144
|
+
return `translate(-50%, -50%) translateX(${cx - half}px) translateY(-${h}px)`;
|
|
145
|
+
case "bottom":
|
|
146
|
+
case "bottom_front":
|
|
147
|
+
case "bottom_rear":
|
|
148
|
+
cx = w / 2;
|
|
149
|
+
return `translate(-50%, -50%) translateX(${cx - half}px) translateY(${h}px)`;
|
|
150
|
+
default:
|
|
151
|
+
cx = w / 2;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
return `translate(-50%, -50%) translateX(${cx - half}px)`;
|
|
155
|
+
}
|
|
156
|
+
function parseCssText(css) {
|
|
157
|
+
if (!css) return {};
|
|
158
|
+
const style = {};
|
|
159
|
+
css.split(";").forEach((rule) => {
|
|
160
|
+
const [prop, ...rest] = rule.split(":");
|
|
161
|
+
if (!prop || rest.length === 0) return;
|
|
162
|
+
const key = prop.trim().replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
163
|
+
style[key] = rest.join(":").trim();
|
|
164
|
+
});
|
|
165
|
+
return style;
|
|
166
|
+
}
|
|
167
|
+
function faceDimensions(name, w, h, d) {
|
|
168
|
+
switch (name) {
|
|
169
|
+
case "left":
|
|
170
|
+
case "right":
|
|
171
|
+
return { width: d, height: h };
|
|
172
|
+
case "top":
|
|
173
|
+
case "bottom":
|
|
174
|
+
case "top_front":
|
|
175
|
+
case "top_rear":
|
|
176
|
+
case "bottom_front":
|
|
177
|
+
case "bottom_rear":
|
|
178
|
+
return { width: w, height: d };
|
|
179
|
+
default:
|
|
180
|
+
return { width: w, height: h };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function faceAppearance(face, globalDef) {
|
|
184
|
+
const globalStyle = parseCssText(globalDef?.css);
|
|
185
|
+
const faceInlineStyle = parseCssText(face.css);
|
|
186
|
+
const style = {
|
|
187
|
+
...globalStyle,
|
|
188
|
+
...globalDef?.style ?? {},
|
|
189
|
+
...faceInlineStyle,
|
|
190
|
+
...face.style ?? {}
|
|
191
|
+
};
|
|
192
|
+
const className = ["anim3d-face", face.className].filter(Boolean).join(" ");
|
|
193
|
+
const body = face.body ?? globalDef?.body ?? null;
|
|
194
|
+
return { style, className, body };
|
|
195
|
+
}
|
|
196
|
+
var DEFAULT_FACE_NAMES = [
|
|
197
|
+
"front",
|
|
198
|
+
"back",
|
|
199
|
+
"left",
|
|
200
|
+
"right",
|
|
201
|
+
"top",
|
|
202
|
+
"bottom"
|
|
203
|
+
];
|
|
204
|
+
var STAGGER_ORDER = [
|
|
205
|
+
"front",
|
|
206
|
+
"right",
|
|
207
|
+
"back",
|
|
208
|
+
"left",
|
|
209
|
+
"top",
|
|
210
|
+
"bottom",
|
|
211
|
+
"top_front",
|
|
212
|
+
"top_rear",
|
|
213
|
+
"bottom_front",
|
|
214
|
+
"bottom_rear"
|
|
215
|
+
];
|
|
216
|
+
var Obj = React__namespace.memo(
|
|
217
|
+
({
|
|
218
|
+
width = 160,
|
|
219
|
+
height = 160,
|
|
220
|
+
depth = 150,
|
|
221
|
+
perspective = 600,
|
|
222
|
+
perspectiveOrigin = "50% 50%",
|
|
223
|
+
faces,
|
|
224
|
+
global: globalDef,
|
|
225
|
+
anim1,
|
|
226
|
+
anim2,
|
|
227
|
+
showCenterDiv = false,
|
|
228
|
+
flat = false,
|
|
229
|
+
transitionDuration = 1,
|
|
230
|
+
oneAtATime = false,
|
|
231
|
+
remainJoined = false,
|
|
232
|
+
ytilt = false,
|
|
233
|
+
backfaceHidden = false,
|
|
234
|
+
chainEffects,
|
|
235
|
+
onChainComplete,
|
|
236
|
+
onChainReverseComplete,
|
|
237
|
+
className,
|
|
238
|
+
style
|
|
239
|
+
}) => {
|
|
240
|
+
const w = typeof width === "number" ? width : parseFloat(String(width));
|
|
241
|
+
const h = typeof height === "number" ? height : parseFloat(String(height));
|
|
242
|
+
const d = typeof depth === "number" ? depth : parseFloat(String(depth));
|
|
243
|
+
const animation1 = toAnimationShorthand(anim1) ?? void 0;
|
|
244
|
+
const animation2 = toAnimationShorthand(anim2) ?? void 0;
|
|
245
|
+
const [phase, setPhase] = React__namespace.useState(
|
|
246
|
+
flat ? "chained" : "folded"
|
|
247
|
+
);
|
|
248
|
+
const hasChain = Array.isArray(chainEffects) && chainEffects.length > 0;
|
|
249
|
+
const sideCountRef = React__namespace.useRef(0);
|
|
250
|
+
const chainDur = React__namespace.useMemo(() => {
|
|
251
|
+
if (!hasChain) return 0;
|
|
252
|
+
return Math.max(
|
|
253
|
+
0,
|
|
254
|
+
...chainEffects.map(
|
|
255
|
+
(e) => (e.duration ?? 0.5) + (e.delay ?? 0)
|
|
256
|
+
)
|
|
257
|
+
);
|
|
258
|
+
}, [chainEffects, hasChain]);
|
|
259
|
+
const prevFlatForChain = React__namespace.useRef(flat);
|
|
260
|
+
React__namespace.useEffect(() => {
|
|
261
|
+
if (flat === prevFlatForChain.current) return;
|
|
262
|
+
prevFlatForChain.current = flat;
|
|
263
|
+
if (flat) {
|
|
264
|
+
setPhase("unfolding");
|
|
265
|
+
} else {
|
|
266
|
+
if (hasChain && (phase === "chained" || phase === "chaining")) {
|
|
267
|
+
setPhase("unchaining");
|
|
268
|
+
} else {
|
|
269
|
+
setPhase("folding");
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}, [flat]);
|
|
273
|
+
React__namespace.useEffect(() => {
|
|
274
|
+
let timer;
|
|
275
|
+
if (phase === "unfolding") {
|
|
276
|
+
const sideCount = sideCountRef.current;
|
|
277
|
+
const unfoldDur = oneAtATime ? transitionDuration * sideCount : transitionDuration;
|
|
278
|
+
timer = setTimeout(() => {
|
|
279
|
+
if (hasChain) {
|
|
280
|
+
setPhase("chaining");
|
|
281
|
+
} else {
|
|
282
|
+
setPhase("chained");
|
|
283
|
+
onChainComplete?.();
|
|
284
|
+
}
|
|
285
|
+
}, unfoldDur * 1e3 + 60);
|
|
286
|
+
}
|
|
287
|
+
if (phase === "chaining") {
|
|
288
|
+
timer = setTimeout(() => {
|
|
289
|
+
setPhase("chained");
|
|
290
|
+
onChainComplete?.();
|
|
291
|
+
}, chainDur * 1e3 + 60);
|
|
292
|
+
}
|
|
293
|
+
if (phase === "unchaining") {
|
|
294
|
+
timer = setTimeout(() => {
|
|
295
|
+
setPhase("folding");
|
|
296
|
+
}, chainDur * 1e3 + 60);
|
|
297
|
+
}
|
|
298
|
+
if (phase === "folding") {
|
|
299
|
+
const sideCount = sideCountRef.current;
|
|
300
|
+
const foldDur = oneAtATime ? transitionDuration * sideCount : transitionDuration;
|
|
301
|
+
timer = setTimeout(() => {
|
|
302
|
+
setPhase("folded");
|
|
303
|
+
onChainReverseComplete?.();
|
|
304
|
+
}, foldDur * 1e3 + 60);
|
|
305
|
+
}
|
|
306
|
+
return () => {
|
|
307
|
+
if (timer) clearTimeout(timer);
|
|
308
|
+
};
|
|
309
|
+
}, [
|
|
310
|
+
phase,
|
|
311
|
+
hasChain,
|
|
312
|
+
chainDur,
|
|
313
|
+
transitionDuration,
|
|
314
|
+
oneAtATime,
|
|
315
|
+
onChainComplete,
|
|
316
|
+
onChainReverseComplete
|
|
317
|
+
]);
|
|
318
|
+
const isFlatNow = phase === "unfolding" || phase === "chaining" || phase === "chained" || phase === "unchaining";
|
|
319
|
+
const chainActive = phase === "chaining" || phase === "chained";
|
|
320
|
+
const chainMap = React__namespace.useMemo(() => {
|
|
321
|
+
const map = /* @__PURE__ */ new Map();
|
|
322
|
+
if (chainEffects) {
|
|
323
|
+
for (const e of chainEffects) {
|
|
324
|
+
map.set(e.faceName, e);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return map;
|
|
328
|
+
}, [chainEffects]);
|
|
329
|
+
function chainStyle(faceName) {
|
|
330
|
+
const eff = chainMap.get(faceName);
|
|
331
|
+
if (!eff) return {};
|
|
332
|
+
const dur = (eff.duration ?? 0.5) + "s";
|
|
333
|
+
const delay = (eff.delay ?? 0) + "s";
|
|
334
|
+
const timing = eff.timing ?? "ease-in-out";
|
|
335
|
+
const props = [];
|
|
336
|
+
const styles = {};
|
|
337
|
+
if (eff.scaleX !== void 0 || eff.scaleY !== void 0) {
|
|
338
|
+
const sx = eff.scaleX ?? 1;
|
|
339
|
+
const sy = eff.scaleY ?? 1;
|
|
340
|
+
if (chainActive) {
|
|
341
|
+
styles.transform = (styles.transform ?? "") + ` scaleX(${sx}) scaleY(${sy})`;
|
|
342
|
+
}
|
|
343
|
+
props.push("transform");
|
|
344
|
+
}
|
|
345
|
+
if (eff.background !== void 0) {
|
|
346
|
+
if (chainActive) {
|
|
347
|
+
styles.background = eff.background;
|
|
348
|
+
}
|
|
349
|
+
props.push("background");
|
|
350
|
+
}
|
|
351
|
+
if (eff.opacity !== void 0) {
|
|
352
|
+
if (chainActive) {
|
|
353
|
+
styles.opacity = eff.opacity;
|
|
354
|
+
}
|
|
355
|
+
props.push("opacity");
|
|
356
|
+
}
|
|
357
|
+
if (props.length > 0) {
|
|
358
|
+
const transitionParts = props.map(
|
|
359
|
+
(p) => `${p} ${dur} ${timing} ${delay}`
|
|
360
|
+
);
|
|
361
|
+
styles.transition = transitionParts.join(", ");
|
|
362
|
+
}
|
|
363
|
+
return styles;
|
|
364
|
+
}
|
|
365
|
+
const faceList = faces && faces.length > 0 ? faces : DEFAULT_FACE_NAMES.map((name) => ({ name }));
|
|
366
|
+
sideCountRef.current = faceList.filter(
|
|
367
|
+
(f) => ["front", "right", "back", "left"].includes(f.name)
|
|
368
|
+
).length;
|
|
369
|
+
const bfv = backfaceHidden ? "hidden" : "visible";
|
|
370
|
+
const transitionCss = (delay = 0) => `transform ${transitionDuration}s ease-in-out ${delay}s`;
|
|
371
|
+
const tiltCount = React__namespace.useRef(0);
|
|
372
|
+
const prevFlat = React__namespace.useRef(flat);
|
|
373
|
+
const [tiltAnim, setTiltAnim] = React__namespace.useState(void 0);
|
|
374
|
+
React__namespace.useEffect(() => {
|
|
375
|
+
if (flat !== prevFlat.current) {
|
|
376
|
+
prevFlat.current = flat;
|
|
377
|
+
if (ytilt) {
|
|
378
|
+
tiltCount.current += 1;
|
|
379
|
+
const sideCount = faceList.filter(
|
|
380
|
+
(f) => ["front", "right", "back", "left"].includes(
|
|
381
|
+
f.name
|
|
382
|
+
)
|
|
383
|
+
).length;
|
|
384
|
+
const totalDur = oneAtATime ? transitionDuration * sideCount : transitionDuration;
|
|
385
|
+
const name = tiltCount.current % 2 === 0 ? "anim3d-ytilt-a" : "anim3d-ytilt-b";
|
|
386
|
+
setTiltAnim(
|
|
387
|
+
`${name} ${totalDur}s ease-in-out 1 forwards`
|
|
388
|
+
);
|
|
389
|
+
const timer = setTimeout(
|
|
390
|
+
() => setTiltAnim(void 0),
|
|
391
|
+
totalDur * 1e3 + 50
|
|
392
|
+
);
|
|
393
|
+
return () => clearTimeout(timer);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}, [flat, ytilt, transitionDuration, oneAtATime, faceList]);
|
|
397
|
+
const renderStandard = () => faceList.map((face, i) => {
|
|
398
|
+
const dims = faceDimensions(face.name, w, h, d);
|
|
399
|
+
const baseTransform = isFlatNow ? faceTransformFlat(face.name, w, h, d) : faceTransform3D(face.name, w, h, d);
|
|
400
|
+
const {
|
|
401
|
+
style: fStyle,
|
|
402
|
+
className: fCls,
|
|
403
|
+
body
|
|
404
|
+
} = faceAppearance(face, globalDef);
|
|
405
|
+
const idx = STAGGER_ORDER.indexOf(face.name);
|
|
406
|
+
const delay = oneAtATime ? (idx >= 0 ? idx : i) * transitionDuration : 0;
|
|
407
|
+
const cStyle = chainStyle(face.name);
|
|
408
|
+
const scaleAppend = cStyle.transform ? ` ${cStyle.transform}` : "";
|
|
409
|
+
const transform = baseTransform + scaleAppend;
|
|
410
|
+
const foldTransition = transitionCss(delay);
|
|
411
|
+
const combinedTransition = cStyle.transition ? `${foldTransition}, ${cStyle.transition}` : foldTransition;
|
|
412
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
413
|
+
"div",
|
|
414
|
+
{
|
|
415
|
+
className: fCls,
|
|
416
|
+
style: {
|
|
417
|
+
...fStyle,
|
|
418
|
+
...cStyle,
|
|
419
|
+
width: dims.width,
|
|
420
|
+
height: dims.height,
|
|
421
|
+
transform,
|
|
422
|
+
transition: combinedTransition,
|
|
423
|
+
backfaceVisibility: bfv
|
|
424
|
+
},
|
|
425
|
+
children: body
|
|
426
|
+
},
|
|
427
|
+
face.name + "-" + i
|
|
428
|
+
);
|
|
429
|
+
});
|
|
430
|
+
const renderJoined = () => {
|
|
431
|
+
const findFace = (n) => faceList.find((f) => f.name === n);
|
|
432
|
+
const frontFace = findFace("front");
|
|
433
|
+
const rightFace = findFace("right");
|
|
434
|
+
const backFace = findFace("back");
|
|
435
|
+
const leftFace = findFace("left");
|
|
436
|
+
const sideNames = /* @__PURE__ */ new Set([
|
|
437
|
+
"front",
|
|
438
|
+
"right",
|
|
439
|
+
"back",
|
|
440
|
+
"left"
|
|
441
|
+
]);
|
|
442
|
+
const otherFaces = faceList.filter(
|
|
443
|
+
(f) => !sideNames.has(f.name)
|
|
444
|
+
);
|
|
445
|
+
const step = oneAtATime ? transitionDuration : 0;
|
|
446
|
+
const renderFaceEl = (face, dims, extra, key) => {
|
|
447
|
+
if (!face) return null;
|
|
448
|
+
const {
|
|
449
|
+
style: fStyle,
|
|
450
|
+
className: fCls,
|
|
451
|
+
body
|
|
452
|
+
} = faceAppearance(face, globalDef);
|
|
453
|
+
const cStyle = chainStyle(face.name);
|
|
454
|
+
const baseTransform = extra.transform ?? "";
|
|
455
|
+
const scaleAppend = cStyle.transform ? ` ${cStyle.transform}` : "";
|
|
456
|
+
const mergedTransform = baseTransform ? `${baseTransform}${scaleAppend}` : scaleAppend || void 0;
|
|
457
|
+
const foldTransition = extra.transition ?? "";
|
|
458
|
+
const combinedTransition = cStyle.transition ? `${foldTransition}, ${cStyle.transition}` : foldTransition;
|
|
459
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
460
|
+
"div",
|
|
461
|
+
{
|
|
462
|
+
className: fCls,
|
|
463
|
+
style: {
|
|
464
|
+
...fStyle,
|
|
465
|
+
...cStyle,
|
|
466
|
+
width: dims.width,
|
|
467
|
+
height: dims.height,
|
|
468
|
+
display: "flex",
|
|
469
|
+
alignItems: "center",
|
|
470
|
+
justifyContent: "center",
|
|
471
|
+
boxSizing: "border-box",
|
|
472
|
+
backfaceVisibility: bfv,
|
|
473
|
+
...extra,
|
|
474
|
+
transform: mergedTransform ?? extra.transform,
|
|
475
|
+
transition: combinedTransition || extra.transition
|
|
476
|
+
},
|
|
477
|
+
children: body
|
|
478
|
+
},
|
|
479
|
+
key
|
|
480
|
+
);
|
|
481
|
+
};
|
|
482
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
483
|
+
renderFaceEl(
|
|
484
|
+
frontFace,
|
|
485
|
+
{ width: w, height: h },
|
|
486
|
+
{
|
|
487
|
+
position: "absolute",
|
|
488
|
+
left: "50%",
|
|
489
|
+
top: "50%",
|
|
490
|
+
transform: isFlatNow ? "translate(-50%, -50%)" : `translate(-50%, -50%) translateZ(${d / 2}px)`,
|
|
491
|
+
transition: transitionCss(0)
|
|
492
|
+
},
|
|
493
|
+
"front-j"
|
|
494
|
+
),
|
|
495
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
496
|
+
"div",
|
|
497
|
+
{
|
|
498
|
+
style: {
|
|
499
|
+
position: "absolute",
|
|
500
|
+
left: `calc(50% + ${w / 2}px)`,
|
|
501
|
+
top: "50%",
|
|
502
|
+
width: 0,
|
|
503
|
+
height: 0,
|
|
504
|
+
transformOrigin: "0 0",
|
|
505
|
+
transformStyle: "preserve-3d",
|
|
506
|
+
transform: isFlatNow ? "none" : `translateZ(${d / 2}px) rotateY(90deg)`,
|
|
507
|
+
transition: transitionCss(step)
|
|
508
|
+
},
|
|
509
|
+
children: [
|
|
510
|
+
renderFaceEl(
|
|
511
|
+
rightFace,
|
|
512
|
+
{ width: d, height: h },
|
|
513
|
+
{
|
|
514
|
+
position: "absolute",
|
|
515
|
+
left: 0,
|
|
516
|
+
top: 0,
|
|
517
|
+
transform: "translateY(-50%)"
|
|
518
|
+
},
|
|
519
|
+
"right-j"
|
|
520
|
+
),
|
|
521
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
522
|
+
"div",
|
|
523
|
+
{
|
|
524
|
+
style: {
|
|
525
|
+
position: "absolute",
|
|
526
|
+
left: d,
|
|
527
|
+
top: 0,
|
|
528
|
+
width: 0,
|
|
529
|
+
height: 0,
|
|
530
|
+
transformOrigin: "0 0",
|
|
531
|
+
transformStyle: "preserve-3d",
|
|
532
|
+
transform: isFlatNow ? "none" : "rotateY(90deg)",
|
|
533
|
+
transition: transitionCss(step * 2)
|
|
534
|
+
},
|
|
535
|
+
children: [
|
|
536
|
+
renderFaceEl(
|
|
537
|
+
backFace,
|
|
538
|
+
{ width: w, height: h },
|
|
539
|
+
{
|
|
540
|
+
position: "absolute",
|
|
541
|
+
left: 0,
|
|
542
|
+
top: 0,
|
|
543
|
+
transform: "translateY(-50%)"
|
|
544
|
+
},
|
|
545
|
+
"back-j"
|
|
546
|
+
),
|
|
547
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
548
|
+
"div",
|
|
549
|
+
{
|
|
550
|
+
style: {
|
|
551
|
+
position: "absolute",
|
|
552
|
+
left: w,
|
|
553
|
+
top: 0,
|
|
554
|
+
width: 0,
|
|
555
|
+
height: 0,
|
|
556
|
+
transformOrigin: "0 0",
|
|
557
|
+
transformStyle: "preserve-3d",
|
|
558
|
+
transform: isFlatNow ? "none" : "rotateY(90deg)",
|
|
559
|
+
transition: transitionCss(step * 3)
|
|
560
|
+
},
|
|
561
|
+
children: renderFaceEl(
|
|
562
|
+
leftFace,
|
|
563
|
+
{ width: d, height: h },
|
|
564
|
+
{
|
|
565
|
+
position: "absolute",
|
|
566
|
+
left: 0,
|
|
567
|
+
top: 0,
|
|
568
|
+
transform: "translateY(-50%)"
|
|
569
|
+
},
|
|
570
|
+
"left-j"
|
|
571
|
+
)
|
|
572
|
+
}
|
|
573
|
+
)
|
|
574
|
+
]
|
|
575
|
+
}
|
|
576
|
+
)
|
|
577
|
+
]
|
|
578
|
+
}
|
|
579
|
+
),
|
|
580
|
+
otherFaces.map((face, i) => {
|
|
581
|
+
const dims = faceDimensions(face.name, w, h, d);
|
|
582
|
+
const xform = isFlatNow ? faceTransformFlat(face.name, w, h, d) : faceTransform3D(face.name, w, h, d);
|
|
583
|
+
const {
|
|
584
|
+
style: fStyle,
|
|
585
|
+
className: fCls,
|
|
586
|
+
body
|
|
587
|
+
} = faceAppearance(face, globalDef);
|
|
588
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
589
|
+
"div",
|
|
590
|
+
{
|
|
591
|
+
className: fCls,
|
|
592
|
+
style: {
|
|
593
|
+
...fStyle,
|
|
594
|
+
width: dims.width,
|
|
595
|
+
height: dims.height,
|
|
596
|
+
transform: xform,
|
|
597
|
+
transition: transitionCss(0),
|
|
598
|
+
backfaceVisibility: bfv
|
|
599
|
+
},
|
|
600
|
+
children: body
|
|
601
|
+
},
|
|
602
|
+
face.name + "-o-" + i
|
|
603
|
+
);
|
|
604
|
+
})
|
|
605
|
+
] });
|
|
606
|
+
};
|
|
607
|
+
const cssVars = {
|
|
608
|
+
"--obj-w": w + "px",
|
|
609
|
+
"--obj-h": h + "px",
|
|
610
|
+
"--obj-d": d + "px"
|
|
611
|
+
};
|
|
612
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
613
|
+
"div",
|
|
614
|
+
{
|
|
615
|
+
className: ["anim3d-stage", className].filter(Boolean).join(" "),
|
|
616
|
+
style: {
|
|
617
|
+
perspective,
|
|
618
|
+
perspectiveOrigin,
|
|
619
|
+
...cssVars,
|
|
620
|
+
...style
|
|
621
|
+
},
|
|
622
|
+
"data-anim-3d-obj": true,
|
|
623
|
+
role: "img",
|
|
624
|
+
"aria-label": "3D object",
|
|
625
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
626
|
+
"div",
|
|
627
|
+
{
|
|
628
|
+
style: {
|
|
629
|
+
transformStyle: "preserve-3d",
|
|
630
|
+
animation: tiltAnim
|
|
631
|
+
},
|
|
632
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
633
|
+
"div",
|
|
634
|
+
{
|
|
635
|
+
className: "anim3d-wrapper",
|
|
636
|
+
style: {
|
|
637
|
+
...cssVars,
|
|
638
|
+
animation: isFlatNow ? "none" : animation1,
|
|
639
|
+
transformStyle: "preserve-3d",
|
|
640
|
+
transition: transitionCss()
|
|
641
|
+
},
|
|
642
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
643
|
+
"div",
|
|
644
|
+
{
|
|
645
|
+
className: "anim3d-wrapper",
|
|
646
|
+
style: {
|
|
647
|
+
...cssVars,
|
|
648
|
+
animation: isFlatNow ? "none" : animation2,
|
|
649
|
+
transformStyle: "preserve-3d",
|
|
650
|
+
transition: transitionCss()
|
|
651
|
+
},
|
|
652
|
+
children: [
|
|
653
|
+
showCenterDiv && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "anim3d-center" }),
|
|
654
|
+
remainJoined ? renderJoined() : renderStandard()
|
|
655
|
+
]
|
|
656
|
+
}
|
|
657
|
+
)
|
|
658
|
+
}
|
|
659
|
+
)
|
|
660
|
+
}
|
|
661
|
+
)
|
|
662
|
+
}
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
);
|
|
666
|
+
Obj.displayName = "Obj";
|
|
667
|
+
|
|
668
|
+
exports.Obj = Obj;
|
|
669
|
+
exports.default = Obj;
|
|
670
|
+
exports.resolveAnimation = resolveAnimation;
|
|
671
|
+
exports.toAnimationShorthand = toAnimationShorthand;
|
|
672
|
+
//# sourceMappingURL=index.cjs.map
|
|
673
|
+
//# sourceMappingURL=index.cjs.map
|