perspective-layered-ui 1.0.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/README.md +65 -0
- package/dist/index.es.js +361 -0
- package/dist/index.js +6 -0
- package/dist/perspective-layered-ui.css +1 -0
- package/dist/vite.svg +1 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# perspective-layered-ui
|
|
2
|
+
|
|
3
|
+
A React component library for creating interactive layered UI scenes with 3D perspective effects. Stack full-screen layers and navigate between them with smooth transitions.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install perspective-layered-ui
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
First, import the component and the required CSS:
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { LayeredScene } from 'perspective-layered-ui';
|
|
17
|
+
import 'perspective-layered-ui/dist/perspective-layered-ui.css';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Then use it in your React app:
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { LayeredScene } from 'perspective-layered-ui';
|
|
24
|
+
import 'perspective-layered-ui/dist/perspective-layered-ui.css';
|
|
25
|
+
|
|
26
|
+
function App() {
|
|
27
|
+
return (
|
|
28
|
+
<LayeredScene>
|
|
29
|
+
<div style={{ background: 'red', height: '100vh' }}>Layer 1</div>
|
|
30
|
+
<div style={{ background: 'green', height: '100vh' }}>Layer 2</div>
|
|
31
|
+
<div style={{ background: 'blue', height: '100vh' }}>Layer 3</div>
|
|
32
|
+
</LayeredScene>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Props
|
|
38
|
+
|
|
39
|
+
The `LayeredScene` component accepts the following props:
|
|
40
|
+
|
|
41
|
+
- `children`: `ReactNode` - The layers to display (each child is a layer).
|
|
42
|
+
- `className?`: `string` - Additional CSS class for the container.
|
|
43
|
+
- `style?`: `CSSProperties` - Inline styles for the container.
|
|
44
|
+
- `transitionMs?`: `number` - Transition duration in milliseconds (default: 250).
|
|
45
|
+
- `easing?`: `string` - CSS easing function (default: 'ease-out').
|
|
46
|
+
- `depthSpacingPx?`: `number` - Z-axis spacing between layers (default: 200).
|
|
47
|
+
- `perspectivePx?`: `number` - Perspective value for the 3D effect (default: 3000).
|
|
48
|
+
- `blurAt1Px?`: `number` - Blur amount for layers at distance 1 (default: 6).
|
|
49
|
+
- `blurAt2Px?`: `number` - Blur amount for layers at distance 2 (default: 10).
|
|
50
|
+
- `opacityAt1?`: `number` - Opacity for layers at distance 1 (default: 0.7).
|
|
51
|
+
- `opacityAt2?`: `number` - Opacity for layers at distance 2 (default: 0.45).
|
|
52
|
+
- `minVisibleOpacity?`: `number` - Minimum opacity for visible layers (default: 0.2).
|
|
53
|
+
- `initialIndex?`: `number` - Initial active layer index (default: 0).
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
57
|
+
- Smooth 3D transitions between layers
|
|
58
|
+
- Customizable perspective and depth
|
|
59
|
+
- Blur and opacity effects for depth perception
|
|
60
|
+
- Keyboard and programmatic navigation
|
|
61
|
+
- Lightweight and dependency-free (requires React)
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
MIT
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import ue, { useMemo as fe, Children as me, useState as O, useRef as Q, useCallback as de, useEffect as K, isValidElement as ee } from "react";
|
|
2
|
+
var Z = { exports: {} }, F = {};
|
|
3
|
+
var re;
|
|
4
|
+
function ge() {
|
|
5
|
+
if (re) return F;
|
|
6
|
+
re = 1;
|
|
7
|
+
var f = /* @__PURE__ */ Symbol.for("react.transitional.element"), _ = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
8
|
+
function b(d, c, l) {
|
|
9
|
+
var y = null;
|
|
10
|
+
if (l !== void 0 && (y = "" + l), c.key !== void 0 && (y = "" + c.key), "key" in c) {
|
|
11
|
+
l = {};
|
|
12
|
+
for (var R in c)
|
|
13
|
+
R !== "key" && (l[R] = c[R]);
|
|
14
|
+
} else l = c;
|
|
15
|
+
return c = l.ref, {
|
|
16
|
+
$$typeof: f,
|
|
17
|
+
type: d,
|
|
18
|
+
key: y,
|
|
19
|
+
ref: c !== void 0 ? c : null,
|
|
20
|
+
props: l
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return F.Fragment = _, F.jsx = b, F.jsxs = b, F;
|
|
24
|
+
}
|
|
25
|
+
var L = {};
|
|
26
|
+
var te;
|
|
27
|
+
function Ee() {
|
|
28
|
+
return te || (te = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
29
|
+
function f(e) {
|
|
30
|
+
if (e == null) return null;
|
|
31
|
+
if (typeof e == "function")
|
|
32
|
+
return e.$$typeof === u ? null : e.displayName || e.name || null;
|
|
33
|
+
if (typeof e == "string") return e;
|
|
34
|
+
switch (e) {
|
|
35
|
+
case P:
|
|
36
|
+
return "Fragment";
|
|
37
|
+
case I:
|
|
38
|
+
return "Profiler";
|
|
39
|
+
case s:
|
|
40
|
+
return "StrictMode";
|
|
41
|
+
case j:
|
|
42
|
+
return "Suspense";
|
|
43
|
+
case J:
|
|
44
|
+
return "SuspenseList";
|
|
45
|
+
case x:
|
|
46
|
+
return "Activity";
|
|
47
|
+
}
|
|
48
|
+
if (typeof e == "object")
|
|
49
|
+
switch (typeof e.tag == "number" && console.error(
|
|
50
|
+
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
51
|
+
), e.$$typeof) {
|
|
52
|
+
case U:
|
|
53
|
+
return "Portal";
|
|
54
|
+
case M:
|
|
55
|
+
return e.displayName || "Context";
|
|
56
|
+
case q:
|
|
57
|
+
return (e._context.displayName || "Context") + ".Consumer";
|
|
58
|
+
case z:
|
|
59
|
+
var r = e.render;
|
|
60
|
+
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
61
|
+
case T:
|
|
62
|
+
return r = e.displayName || null, r !== null ? r : f(e.type) || "Memo";
|
|
63
|
+
case S:
|
|
64
|
+
r = e._payload, e = e._init;
|
|
65
|
+
try {
|
|
66
|
+
return f(e(r));
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
function _(e) {
|
|
73
|
+
return "" + e;
|
|
74
|
+
}
|
|
75
|
+
function b(e) {
|
|
76
|
+
try {
|
|
77
|
+
_(e);
|
|
78
|
+
var r = !1;
|
|
79
|
+
} catch {
|
|
80
|
+
r = !0;
|
|
81
|
+
}
|
|
82
|
+
if (r) {
|
|
83
|
+
r = console;
|
|
84
|
+
var n = r.error, o = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
85
|
+
return n.call(
|
|
86
|
+
r,
|
|
87
|
+
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
88
|
+
o
|
|
89
|
+
), _(e);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function d(e) {
|
|
93
|
+
if (e === P) return "<>";
|
|
94
|
+
if (typeof e == "object" && e !== null && e.$$typeof === S)
|
|
95
|
+
return "<...>";
|
|
96
|
+
try {
|
|
97
|
+
var r = f(e);
|
|
98
|
+
return r ? "<" + r + ">" : "<...>";
|
|
99
|
+
} catch {
|
|
100
|
+
return "<...>";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function c() {
|
|
104
|
+
var e = h.A;
|
|
105
|
+
return e === null ? null : e.getOwner();
|
|
106
|
+
}
|
|
107
|
+
function l() {
|
|
108
|
+
return Error("react-stack-top-frame");
|
|
109
|
+
}
|
|
110
|
+
function y(e) {
|
|
111
|
+
if (E.call(e, "key")) {
|
|
112
|
+
var r = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
113
|
+
if (r && r.isReactWarning) return !1;
|
|
114
|
+
}
|
|
115
|
+
return e.key !== void 0;
|
|
116
|
+
}
|
|
117
|
+
function R(e, r) {
|
|
118
|
+
function n() {
|
|
119
|
+
g || (g = !0, console.error(
|
|
120
|
+
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
121
|
+
r
|
|
122
|
+
));
|
|
123
|
+
}
|
|
124
|
+
n.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
125
|
+
get: n,
|
|
126
|
+
configurable: !0
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function W() {
|
|
130
|
+
var e = f(this.type);
|
|
131
|
+
return p[e] || (p[e] = !0, console.error(
|
|
132
|
+
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
133
|
+
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
134
|
+
}
|
|
135
|
+
function X(e, r, n, o, k, N) {
|
|
136
|
+
var a = n.ref;
|
|
137
|
+
return e = {
|
|
138
|
+
$$typeof: $,
|
|
139
|
+
type: e,
|
|
140
|
+
key: r,
|
|
141
|
+
props: n,
|
|
142
|
+
_owner: o
|
|
143
|
+
}, (a !== void 0 ? a : null) !== null ? Object.defineProperty(e, "ref", {
|
|
144
|
+
enumerable: !1,
|
|
145
|
+
get: W
|
|
146
|
+
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
147
|
+
configurable: !1,
|
|
148
|
+
enumerable: !1,
|
|
149
|
+
writable: !0,
|
|
150
|
+
value: 0
|
|
151
|
+
}), Object.defineProperty(e, "_debugInfo", {
|
|
152
|
+
configurable: !1,
|
|
153
|
+
enumerable: !1,
|
|
154
|
+
writable: !0,
|
|
155
|
+
value: null
|
|
156
|
+
}), Object.defineProperty(e, "_debugStack", {
|
|
157
|
+
configurable: !1,
|
|
158
|
+
enumerable: !1,
|
|
159
|
+
writable: !0,
|
|
160
|
+
value: k
|
|
161
|
+
}), Object.defineProperty(e, "_debugTask", {
|
|
162
|
+
configurable: !1,
|
|
163
|
+
enumerable: !1,
|
|
164
|
+
writable: !0,
|
|
165
|
+
value: N
|
|
166
|
+
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
167
|
+
}
|
|
168
|
+
function B(e, r, n, o, k, N) {
|
|
169
|
+
var a = r.children;
|
|
170
|
+
if (a !== void 0)
|
|
171
|
+
if (o)
|
|
172
|
+
if (Y(a)) {
|
|
173
|
+
for (o = 0; o < a.length; o++)
|
|
174
|
+
A(a[o]);
|
|
175
|
+
Object.freeze && Object.freeze(a);
|
|
176
|
+
} else
|
|
177
|
+
console.error(
|
|
178
|
+
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
179
|
+
);
|
|
180
|
+
else A(a);
|
|
181
|
+
if (E.call(r, "key")) {
|
|
182
|
+
a = f(e);
|
|
183
|
+
var w = Object.keys(r).filter(function(H) {
|
|
184
|
+
return H !== "key";
|
|
185
|
+
});
|
|
186
|
+
o = 0 < w.length ? "{key: someKey, " + w.join(": ..., ") + ": ...}" : "{key: someKey}", t[a + o] || (w = 0 < w.length ? "{" + w.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
187
|
+
`A props object containing a "key" prop is being spread into JSX:
|
|
188
|
+
let props = %s;
|
|
189
|
+
<%s {...props} />
|
|
190
|
+
React keys must be passed directly to JSX without using spread:
|
|
191
|
+
let props = %s;
|
|
192
|
+
<%s key={someKey} {...props} />`,
|
|
193
|
+
o,
|
|
194
|
+
a,
|
|
195
|
+
w,
|
|
196
|
+
a
|
|
197
|
+
), t[a + o] = !0);
|
|
198
|
+
}
|
|
199
|
+
if (a = null, n !== void 0 && (b(n), a = "" + n), y(r) && (b(r.key), a = "" + r.key), "key" in r) {
|
|
200
|
+
n = {};
|
|
201
|
+
for (var G in r)
|
|
202
|
+
G !== "key" && (n[G] = r[G]);
|
|
203
|
+
} else n = r;
|
|
204
|
+
return a && R(
|
|
205
|
+
n,
|
|
206
|
+
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
207
|
+
), X(
|
|
208
|
+
e,
|
|
209
|
+
a,
|
|
210
|
+
n,
|
|
211
|
+
c(),
|
|
212
|
+
k,
|
|
213
|
+
N
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
function A(e) {
|
|
217
|
+
C(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === S && (e._payload.status === "fulfilled" ? C(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
218
|
+
}
|
|
219
|
+
function C(e) {
|
|
220
|
+
return typeof e == "object" && e !== null && e.$$typeof === $;
|
|
221
|
+
}
|
|
222
|
+
var i = ue, $ = /* @__PURE__ */ Symbol.for("react.transitional.element"), U = /* @__PURE__ */ Symbol.for("react.portal"), P = /* @__PURE__ */ Symbol.for("react.fragment"), s = /* @__PURE__ */ Symbol.for("react.strict_mode"), I = /* @__PURE__ */ Symbol.for("react.profiler"), q = /* @__PURE__ */ Symbol.for("react.consumer"), M = /* @__PURE__ */ Symbol.for("react.context"), z = /* @__PURE__ */ Symbol.for("react.forward_ref"), j = /* @__PURE__ */ Symbol.for("react.suspense"), J = /* @__PURE__ */ Symbol.for("react.suspense_list"), T = /* @__PURE__ */ Symbol.for("react.memo"), S = /* @__PURE__ */ Symbol.for("react.lazy"), x = /* @__PURE__ */ Symbol.for("react.activity"), u = /* @__PURE__ */ Symbol.for("react.client.reference"), h = i.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, E = Object.prototype.hasOwnProperty, Y = Array.isArray, m = console.createTask ? console.createTask : function() {
|
|
223
|
+
return null;
|
|
224
|
+
};
|
|
225
|
+
i = {
|
|
226
|
+
react_stack_bottom_frame: function(e) {
|
|
227
|
+
return e();
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var g, p = {}, V = i.react_stack_bottom_frame.bind(
|
|
231
|
+
i,
|
|
232
|
+
l
|
|
233
|
+
)(), D = m(d(l)), t = {};
|
|
234
|
+
L.Fragment = P, L.jsx = function(e, r, n) {
|
|
235
|
+
var o = 1e4 > h.recentlyCreatedOwnerStacks++;
|
|
236
|
+
return B(
|
|
237
|
+
e,
|
|
238
|
+
r,
|
|
239
|
+
n,
|
|
240
|
+
!1,
|
|
241
|
+
o ? Error("react-stack-top-frame") : V,
|
|
242
|
+
o ? m(d(e)) : D
|
|
243
|
+
);
|
|
244
|
+
}, L.jsxs = function(e, r, n) {
|
|
245
|
+
var o = 1e4 > h.recentlyCreatedOwnerStacks++;
|
|
246
|
+
return B(
|
|
247
|
+
e,
|
|
248
|
+
r,
|
|
249
|
+
n,
|
|
250
|
+
!0,
|
|
251
|
+
o ? Error("react-stack-top-frame") : V,
|
|
252
|
+
o ? m(d(e)) : D
|
|
253
|
+
);
|
|
254
|
+
};
|
|
255
|
+
})()), L;
|
|
256
|
+
}
|
|
257
|
+
var ne;
|
|
258
|
+
function pe() {
|
|
259
|
+
return ne || (ne = 1, process.env.NODE_ENV === "production" ? Z.exports = ge() : Z.exports = Ee()), Z.exports;
|
|
260
|
+
}
|
|
261
|
+
var v = pe();
|
|
262
|
+
function he({
|
|
263
|
+
children: f,
|
|
264
|
+
className: _,
|
|
265
|
+
style: b,
|
|
266
|
+
transitionMs: d = 250,
|
|
267
|
+
easing: c = "ease-out",
|
|
268
|
+
depthSpacingPx: l = 200,
|
|
269
|
+
perspectivePx: y = 3e3,
|
|
270
|
+
blurAt1Px: R = 6,
|
|
271
|
+
blurAt2Px: W = 10,
|
|
272
|
+
opacityAt1: X = 0.7,
|
|
273
|
+
opacityAt2: B = 0.45,
|
|
274
|
+
minVisibleOpacity: A = 0.2,
|
|
275
|
+
initialIndex: C = 0
|
|
276
|
+
}) {
|
|
277
|
+
const i = fe(() => me.toArray(f), [f]), $ = (t) => Math.max(0, Math.min(1, t)), U = (t, e, r) => t + (e - t) * r, P = (t, e, r, n) => t <= 0 ? e : t >= 2 ? n : t <= 1 ? U(e, r, $(t)) : U(r, n, $(t - 1)), [s, I] = O(() => Number.isNaN(C) ? 0 : Math.max(0, Math.min(i.length - 1, C))), [q, M] = O(null), [z, j] = O(null), [J, T] = O(1), [S, x] = O(1), [u, h] = O(!1), [E, Y] = O(1), m = Q(null), g = Q(null), p = de((t) => {
|
|
278
|
+
if (u || t < 0 || t >= i.length || t === s) return;
|
|
279
|
+
const e = t > s ? 1 : -1;
|
|
280
|
+
h(!0), M(s), x(0), Y(e), e === -1 ? (j(t), T(0)) : (j(null), T(1)), I(t), g.current !== null && window.cancelAnimationFrame(g.current), g.current = window.requestAnimationFrame(() => {
|
|
281
|
+
x(1), e === -1 && T(1), g.current = null;
|
|
282
|
+
}), m.current !== null && window.clearTimeout(m.current), m.current = window.setTimeout(() => {
|
|
283
|
+
h(!1), M(null), j(null), T(1), x(1), Y(1), m.current = null;
|
|
284
|
+
}, d + 60);
|
|
285
|
+
}, [u, s, i.length, d, h, M, x, Y, j, T, I]);
|
|
286
|
+
K(() => () => {
|
|
287
|
+
m.current !== null && window.clearTimeout(m.current), g.current !== null && window.cancelAnimationFrame(g.current);
|
|
288
|
+
}, []), K(() => {
|
|
289
|
+
I((t) => Math.max(0, Math.min(i.length - 1, t)));
|
|
290
|
+
}, [i.length]), K(() => {
|
|
291
|
+
const t = (e) => {
|
|
292
|
+
e.key === "PageUp" ? p(s - 1) : e.key === "PageDown" && p(s + 1);
|
|
293
|
+
};
|
|
294
|
+
return window.addEventListener("keydown", t), () => {
|
|
295
|
+
window.removeEventListener("keydown", t);
|
|
296
|
+
};
|
|
297
|
+
}, [s, p]);
|
|
298
|
+
const V = u, D = l * s;
|
|
299
|
+
return /* @__PURE__ */ v.jsx(
|
|
300
|
+
"div",
|
|
301
|
+
{
|
|
302
|
+
className: `layeredScene ${V ? "is-transitioning" : ""}${_ ? ` ${_}` : ""}`,
|
|
303
|
+
"aria-label": "3D layered scene",
|
|
304
|
+
style: {
|
|
305
|
+
"--camera-z": `${D}px`,
|
|
306
|
+
"--transition-ms": `${d}ms`,
|
|
307
|
+
"--transition-easing": c,
|
|
308
|
+
"--perspective": `${y}px`,
|
|
309
|
+
...b
|
|
310
|
+
},
|
|
311
|
+
children: i.map((t, e) => {
|
|
312
|
+
const r = Math.abs(e - s), n = q !== null && e === q, o = z !== null && e === z, k = -l * e, N = n && E === 1 ? l * 2 : 0;
|
|
313
|
+
if (k + N + D > 0 && !n && !(o && u && E === -1))
|
|
314
|
+
return null;
|
|
315
|
+
const H = P(r, 1, X, B), oe = n && u ? E === -1 ? S === 0 ? 1 : A : S === 0 ? 1 : A : o && u && E === -1 ? J === 0 ? 0 : 1 : e === s ? 1 : H, ae = P(r, 0, R, W), se = o && u && E === -1 ? J === 0 ? W : 0 : ae, le = 1e4 - Math.round(r * 10) + (n ? 1e3 : 0), ce = ee(t) ? t : /* @__PURE__ */ v.jsx(v.Fragment, { children: t }), ie = (ee(t) ? t.key : null) ?? e;
|
|
316
|
+
return /* @__PURE__ */ v.jsx(
|
|
317
|
+
"div",
|
|
318
|
+
{
|
|
319
|
+
className: `layeredLayer ${r === 0 ? "is-focused" : ""} ${e === s ? "is-active" : ""} ${n ? "is-outgoing" : ""}`,
|
|
320
|
+
style: {
|
|
321
|
+
"--z": `${k}px`,
|
|
322
|
+
"--outgoing-offset": `${N}px`,
|
|
323
|
+
"--stack": le,
|
|
324
|
+
"--layer-blur": `${se}px`,
|
|
325
|
+
opacity: Math.max(A, oe)
|
|
326
|
+
},
|
|
327
|
+
children: /* @__PURE__ */ v.jsxs("div", { className: "layeredLayerInner", children: [
|
|
328
|
+
ce,
|
|
329
|
+
/* @__PURE__ */ v.jsxs("div", { className: "layeredControls", children: [
|
|
330
|
+
e !== 0 ? /* @__PURE__ */ v.jsx(
|
|
331
|
+
"button",
|
|
332
|
+
{
|
|
333
|
+
type: "button",
|
|
334
|
+
className: "layeredBtn",
|
|
335
|
+
onClick: () => p(s - 1),
|
|
336
|
+
disabled: u || e !== s,
|
|
337
|
+
children: "Previous"
|
|
338
|
+
}
|
|
339
|
+
) : null,
|
|
340
|
+
e !== i.length - 1 ? /* @__PURE__ */ v.jsx(
|
|
341
|
+
"button",
|
|
342
|
+
{
|
|
343
|
+
type: "button",
|
|
344
|
+
className: "layeredBtn",
|
|
345
|
+
onClick: () => p(s + 1),
|
|
346
|
+
disabled: u || e !== s,
|
|
347
|
+
children: "Next"
|
|
348
|
+
}
|
|
349
|
+
) : null
|
|
350
|
+
] })
|
|
351
|
+
] })
|
|
352
|
+
},
|
|
353
|
+
ie
|
|
354
|
+
);
|
|
355
|
+
})
|
|
356
|
+
}
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
export {
|
|
360
|
+
he as LayeredScene
|
|
361
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react");var Z={exports:{}},F={};var K;function le(){if(K)return F;K=1;var m=Symbol.for("react.transitional.element"),_=Symbol.for("react.fragment");function y(g,c,u){var R=null;if(u!==void 0&&(R=""+u),c.key!==void 0&&(R=""+c.key),"key"in c){u={};for(var T in c)T!=="key"&&(u[T]=c[T])}else u=c;return c=u.ref,{$$typeof:m,type:g,key:R,ref:c!==void 0?c:null,props:u}}return F.Fragment=_,F.jsx=y,F.jsxs=y,F}var L={};var Q;function ue(){return Q||(Q=1,process.env.NODE_ENV!=="production"&&(function(){function m(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===f?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case P:return"Fragment";case I:return"Profiler";case l:return"StrictMode";case A:return"Suspense";case J:return"SuspenseList";case x:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case U:return"Portal";case M:return e.displayName||"Context";case q:return(e._context.displayName||"Context")+".Consumer";case z:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case h:return r=e.displayName||null,r!==null?r:m(e.type)||"Memo";case j:r=e._payload,e=e._init;try{return m(e(r))}catch{}}return null}function _(e){return""+e}function y(e){try{_(e);var r=!1}catch{r=!0}if(r){r=console;var n=r.error,a=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",a),_(e)}}function g(e){if(e===P)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===j)return"<...>";try{var r=m(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function c(){var e=k.A;return e===null?null:e.getOwner()}function u(){return Error("react-stack-top-frame")}function R(e){if(v.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function T(e,r){function n(){E||(E=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}function W(){var e=m(this.type);return p[e]||(p[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function X(e,r,n,a,w,N){var o=n.ref;return e={$$typeof:$,type:e,key:r,props:n,_owner:a},(o!==void 0?o:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:W}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:w}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:N}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function B(e,r,n,a,w,N){var o=r.children;if(o!==void 0)if(a)if(Y(o)){for(a=0;a<o.length;a++)S(o[a]);Object.freeze&&Object.freeze(o)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else S(o);if(v.call(r,"key")){o=m(e);var O=Object.keys(r).filter(function(H){return H!=="key"});a=0<O.length?"{key: someKey, "+O.join(": ..., ")+": ...}":"{key: someKey}",t[o+a]||(O=0<O.length?"{"+O.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
|
+
let props = %s;
|
|
3
|
+
<%s {...props} />
|
|
4
|
+
React keys must be passed directly to JSX without using spread:
|
|
5
|
+
let props = %s;
|
|
6
|
+
<%s key={someKey} {...props} />`,a,o,O,o),t[o+a]=!0)}if(o=null,n!==void 0&&(y(n),o=""+n),R(r)&&(y(r.key),o=""+r.key),"key"in r){n={};for(var G in r)G!=="key"&&(n[G]=r[G])}else n=r;return o&&T(n,typeof e=="function"?e.displayName||e.name||"Unknown":e),X(e,o,n,c(),w,N)}function S(e){C(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===j&&(e._payload.status==="fulfilled"?C(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function C(e){return typeof e=="object"&&e!==null&&e.$$typeof===$}var i=s,$=Symbol.for("react.transitional.element"),U=Symbol.for("react.portal"),P=Symbol.for("react.fragment"),l=Symbol.for("react.strict_mode"),I=Symbol.for("react.profiler"),q=Symbol.for("react.consumer"),M=Symbol.for("react.context"),z=Symbol.for("react.forward_ref"),A=Symbol.for("react.suspense"),J=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),j=Symbol.for("react.lazy"),x=Symbol.for("react.activity"),f=Symbol.for("react.client.reference"),k=i.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,v=Object.prototype.hasOwnProperty,Y=Array.isArray,d=console.createTask?console.createTask:function(){return null};i={react_stack_bottom_frame:function(e){return e()}};var E,p={},V=i.react_stack_bottom_frame.bind(i,u)(),D=d(g(u)),t={};L.Fragment=P,L.jsx=function(e,r,n){var a=1e4>k.recentlyCreatedOwnerStacks++;return B(e,r,n,!1,a?Error("react-stack-top-frame"):V,a?d(g(e)):D)},L.jsxs=function(e,r,n){var a=1e4>k.recentlyCreatedOwnerStacks++;return B(e,r,n,!0,a?Error("react-stack-top-frame"):V,a?d(g(e)):D)}})()),L}var ee;function ce(){return ee||(ee=1,process.env.NODE_ENV==="production"?Z.exports=le():Z.exports=ue()),Z.exports}var b=ce();function ie({children:m,className:_,style:y,transitionMs:g=250,easing:c="ease-out",depthSpacingPx:u=200,perspectivePx:R=3e3,blurAt1Px:T=6,blurAt2Px:W=10,opacityAt1:X=.7,opacityAt2:B=.45,minVisibleOpacity:S=.2,initialIndex:C=0}){const i=s.useMemo(()=>s.Children.toArray(m),[m]),$=t=>Math.max(0,Math.min(1,t)),U=(t,e,r)=>t+(e-t)*r,P=(t,e,r,n)=>t<=0?e:t>=2?n:t<=1?U(e,r,$(t)):U(r,n,$(t-1)),[l,I]=s.useState(()=>Number.isNaN(C)?0:Math.max(0,Math.min(i.length-1,C))),[q,M]=s.useState(null),[z,A]=s.useState(null),[J,h]=s.useState(1),[j,x]=s.useState(1),[f,k]=s.useState(!1),[v,Y]=s.useState(1),d=s.useRef(null),E=s.useRef(null),p=s.useCallback(t=>{if(f||t<0||t>=i.length||t===l)return;const e=t>l?1:-1;k(!0),M(l),x(0),Y(e),e===-1?(A(t),h(0)):(A(null),h(1)),I(t),E.current!==null&&window.cancelAnimationFrame(E.current),E.current=window.requestAnimationFrame(()=>{x(1),e===-1&&h(1),E.current=null}),d.current!==null&&window.clearTimeout(d.current),d.current=window.setTimeout(()=>{k(!1),M(null),A(null),h(1),x(1),Y(1),d.current=null},g+60)},[f,l,i.length,g,k,M,x,Y,A,h,I]);s.useEffect(()=>()=>{d.current!==null&&window.clearTimeout(d.current),E.current!==null&&window.cancelAnimationFrame(E.current)},[]),s.useEffect(()=>{I(t=>Math.max(0,Math.min(i.length-1,t)))},[i.length]),s.useEffect(()=>{const t=e=>{e.key==="PageUp"?p(l-1):e.key==="PageDown"&&p(l+1)};return window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}},[l,p]);const V=f,D=u*l;return b.jsx("div",{className:`layeredScene ${V?"is-transitioning":""}${_?` ${_}`:""}`,"aria-label":"3D layered scene",style:{"--camera-z":`${D}px`,"--transition-ms":`${g}ms`,"--transition-easing":c,"--perspective":`${R}px`,...y},children:i.map((t,e)=>{const r=Math.abs(e-l),n=q!==null&&e===q,a=z!==null&&e===z,w=-u*e,N=n&&v===1?u*2:0;if(w+N+D>0&&!n&&!(a&&f&&v===-1))return null;const H=P(r,1,X,B),re=n&&f?v===-1?j===0?1:S:j===0?1:S:a&&f&&v===-1?J===0?0:1:e===l?1:H,te=P(r,0,T,W),ne=a&&f&&v===-1?J===0?W:0:te,ae=1e4-Math.round(r*10)+(n?1e3:0),oe=s.isValidElement(t)?t:b.jsx(b.Fragment,{children:t}),se=(s.isValidElement(t)?t.key:null)??e;return b.jsx("div",{className:`layeredLayer ${r===0?"is-focused":""} ${e===l?"is-active":""} ${n?"is-outgoing":""}`,style:{"--z":`${w}px`,"--outgoing-offset":`${N}px`,"--stack":ae,"--layer-blur":`${ne}px`,opacity:Math.max(S,re)},children:b.jsxs("div",{className:"layeredLayerInner",children:[oe,b.jsxs("div",{className:"layeredControls",children:[e!==0?b.jsx("button",{type:"button",className:"layeredBtn",onClick:()=>p(l-1),disabled:f||e!==l,children:"Previous"}):null,e!==i.length-1?b.jsx("button",{type:"button",className:"layeredBtn",onClick:()=>p(l+1),disabled:f||e!==l,children:"Next"}):null]})]})},se)})})}exports.LayeredScene=ie;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.layeredScene{width:100%;height:100%;position:relative;perspective:var(--perspective, 3000px);perspective-origin:50% 50%;overflow:hidden}.layeredLayer{position:absolute;inset:0;width:100%;height:100%;z-index:var(--stack, 0);border:0;padding:0;text-align:left;color:inherit;background:none;transform-style:preserve-3d;transform:translateZ(calc(var(--z, 0px) + var(--camera-z, 0px) + var(--outgoing-offset, 0px)));transform-origin:50% 50%;filter:blur(var(--layer-blur, 0px));transition:none;will-change:transform,filter,opacity}.layeredLayer.is-outgoing{pointer-events:none}.layeredScene.is-transitioning .layeredLayer{transition:transform var(--transition-ms, .25s) var(--transition-easing, ease-out),filter var(--transition-ms, .25s) var(--transition-easing, ease-out),opacity calc(var(--transition-ms, .25s) * .9) linear}.layeredLayerInner{height:100%;width:100%;border-radius:14px;box-shadow:0 24px 60px #0009,0 10px 24px #0006;padding:14px 16px;box-sizing:border-box;display:grid;gap:10px;align-content:start;transform:translateZ(0);position:relative;overflow:hidden;background:#090c1278;border:1px solid rgba(190,200,220,.05);-webkit-backdrop-filter:blur(3px);backdrop-filter:blur(3px)}.layeredLayerInner:before{content:"";position:absolute;inset:0;border-radius:inherit;pointer-events:none;z-index:0;background-image:linear-gradient(to right,#a0aabe0f 1px,#a0aabe00 1px),linear-gradient(to bottom,#a0aabe0f 1px,#a0aabe00 1px);background-size:120px 60px;background-position:0 0}.layeredLayerInner>*{position:relative;z-index:1}.layeredControls{margin-top:auto;display:flex;gap:8px}.layeredBtn{appearance:none;border:1px solid rgba(170,180,200,.35);background:#0c0e1499;color:#c7ccd8;padding:6px 10px;border-radius:8px;cursor:pointer;font:inherit;font-weight:600;font-size:11px;text-transform:uppercase;letter-spacing:.08em}.layeredBtn:disabled{cursor:not-allowed;opacity:.6}
|
package/dist/vite.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "perspective-layered-ui",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A React component for creating layered UI scenes with perspective effects",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.es.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.es.js",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"keywords": [
|
|
19
|
+
"react",
|
|
20
|
+
"ui",
|
|
21
|
+
"perspective",
|
|
22
|
+
"layered",
|
|
23
|
+
"component"
|
|
24
|
+
],
|
|
25
|
+
"author": "Your Name",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"scripts": {
|
|
28
|
+
"dev": "vite",
|
|
29
|
+
"build": "tsc -b && vite build && tsc --project tsconfig.lib.json",
|
|
30
|
+
"lint": "eslint .",
|
|
31
|
+
"preview": "vite preview"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"react": "^19.2.0",
|
|
35
|
+
"react-dom": "^19.2.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@eslint/js": "^9.39.1",
|
|
39
|
+
"@types/node": "^24.10.1",
|
|
40
|
+
"@types/react": "^19.2.5",
|
|
41
|
+
"@types/react-dom": "^19.2.3",
|
|
42
|
+
"@vitejs/plugin-react": "^5.1.1",
|
|
43
|
+
"eslint": "^9.39.1",
|
|
44
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
45
|
+
"eslint-plugin-react-refresh": "^0.4.24",
|
|
46
|
+
"globals": "^16.5.0",
|
|
47
|
+
"typescript": "~5.9.3",
|
|
48
|
+
"typescript-eslint": "^8.46.4",
|
|
49
|
+
"vite": "^7.2.4"
|
|
50
|
+
}
|
|
51
|
+
}
|