vue-peel-card 0.1.1 → 0.2.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 +6 -3
- package/dist/vue-peel-card.js +236 -229
- package/dist/vue-peel-card.umd.cjs +18 -18
- package/package.json +2 -1
- package/src/PeelCard.vue +89 -63
- package/types/index.d.ts +1 -1
package/README.md
CHANGED
|
@@ -50,8 +50,9 @@ Exactly two cards. The first swipe peels the top card, the second (back) sticks
|
|
|
50
50
|
<button @click="card.peel()">Toggle</button>
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
The peel looks exactly like in normal mode, and the card then disappears completely; the second card stays underneath.
|
|
54
|
+
To bring it back, drag in any direction (the card returns from the opposite side and lays down), or tap / call `peel()`
|
|
55
|
+
for the same animation in reverse from the right side.
|
|
55
56
|
|
|
56
57
|
## Card format
|
|
57
58
|
|
|
@@ -98,7 +99,8 @@ a fallback is drawn: the `bg` color and plain text.
|
|
|
98
99
|
|
|
99
100
|
## Methods
|
|
100
101
|
|
|
101
|
-
`peel()` via `ref`: peels the card; in toggle mode switches the state.
|
|
102
|
+
`peel(angle?)` via `ref`: peels the card; in toggle mode switches the state. `angle` is the tilt of the peel direction in degrees
|
|
103
|
+
(positive tilts upward, default `12`, `0` is straight).
|
|
102
104
|
|
|
103
105
|
## Accessibility
|
|
104
106
|
|
|
@@ -109,6 +111,7 @@ The canvas is keyboard-focusable: Right Arrow, Space or Enter peels the card. Th
|
|
|
109
111
|
|
|
110
112
|
```bash
|
|
111
113
|
npm install
|
|
114
|
+
npm run dev # playground at http://localhost:5173
|
|
112
115
|
npm run build # dist/vue-peel-card.js (ESM) and dist/vue-peel-card.umd.cjs
|
|
113
116
|
```
|
|
114
117
|
|
package/dist/vue-peel-card.js
CHANGED
|
@@ -1,49 +1,43 @@
|
|
|
1
|
-
import { openBlock as ye, createElementBlock as
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
for (const [
|
|
5
|
-
|
|
6
|
-
return
|
|
7
|
-
},
|
|
8
|
-
function
|
|
9
|
-
return
|
|
1
|
+
import { openBlock as ye, createElementBlock as Fe, normalizeStyle as ie, createElementVNode as Je, renderSlot as et, createTextVNode as tt, createCommentVNode as nt, ref as D, computed as at, onMounted as ot, onBeforeUnmount as rt, watch as st } from "vue";
|
|
2
|
+
const it = (r, i) => {
|
|
3
|
+
const l = r.__vccOpts || r;
|
|
4
|
+
for (const [d, E] of i)
|
|
5
|
+
l[d] = E;
|
|
6
|
+
return l;
|
|
7
|
+
}, W = 18, lt = 75, V = 1, ct = 12;
|
|
8
|
+
function Le(r, i, l, d) {
|
|
9
|
+
return r <= l * i ? r - i * Math.sin(r / i) : r - i * Math.sin(d) + (r - l * i) * Math.cos(d);
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
let
|
|
13
|
-
for (let
|
|
14
|
-
const L = (
|
|
15
|
-
|
|
11
|
+
function dt(r, i, l, d) {
|
|
12
|
+
let E = 0, x = 4e3;
|
|
13
|
+
for (let T = 0; T < 48; T++) {
|
|
14
|
+
const L = (E + x) / 2;
|
|
15
|
+
Le(L, i, l, d) < r ? E = L : x = L;
|
|
16
16
|
}
|
|
17
|
-
return (
|
|
17
|
+
return (E + x) / 2;
|
|
18
18
|
}
|
|
19
|
-
function ft(
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
if (s > 0) {
|
|
23
|
-
const T = ce(0.45, 1, i / s);
|
|
24
|
-
l = l * (1 - T) + $ * T;
|
|
25
|
-
}
|
|
26
|
-
const v = Math.PI - l;
|
|
27
|
-
return { R: c, phi: l, Th: v, tf: lt(i, c, v, l), sp: Math.sin(l), cp: Math.cos(l) };
|
|
19
|
+
function ft(r) {
|
|
20
|
+
const i = W + (lt - W) * Math.exp(-r / 70), l = 0.12 + 0.55 * Math.exp(-r / 140), d = Math.PI - l;
|
|
21
|
+
return { R: i, phi: l, Th: d, tf: dt(r, i, d, l), sp: Math.sin(l), cp: Math.cos(l) };
|
|
28
22
|
}
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
return [Math.cos(
|
|
23
|
+
const w = (r, i) => {
|
|
24
|
+
const l = Math.atan2(r[1], r[0]) + i;
|
|
25
|
+
return [Math.cos(l), Math.sin(l)];
|
|
32
26
|
};
|
|
33
|
-
function
|
|
34
|
-
return
|
|
27
|
+
function Y(r, i, l) {
|
|
28
|
+
return l = Math.min(1, Math.max(0, (l - r) / (i - r))), l * l * (3 - 2 * l);
|
|
35
29
|
}
|
|
36
|
-
const ut = (
|
|
37
|
-
const
|
|
38
|
-
return [(
|
|
39
|
-
},
|
|
40
|
-
<foreignObject width="${
|
|
30
|
+
const ut = (r) => {
|
|
31
|
+
const i = parseInt(String(r).replace("#", "").padEnd(6, "0").slice(0, 6), 16);
|
|
32
|
+
return [(i >> 16) / 255, (i >> 8 & 255) / 255, (i & 255) / 255];
|
|
33
|
+
}, ht = (r, i, l) => `<svg xmlns="http://www.w3.org/2000/svg" width="${i}" height="${l}">
|
|
34
|
+
<foreignObject width="${i}" height="${l}"><div xmlns="http://www.w3.org/1999/xhtml" style="width:${i}px;height:${l}px;background:${r.bg || "#ffffff"}">${r.html || ""}</div></foreignObject></svg>`, Be = `
|
|
41
35
|
uniform vec2 uG, uU, uHalf;
|
|
42
36
|
uniform float uTf, uR, uTheta, uSinPhi, uCosPhi;
|
|
43
|
-
`,
|
|
37
|
+
`, mt = `
|
|
44
38
|
attribute vec2 aPos;
|
|
45
39
|
${Be}
|
|
46
|
-
uniform vec2 uView
|
|
40
|
+
uniform vec2 uView; uniform float uScale;
|
|
47
41
|
varying vec2 vOrig, vXY; varying float vZ, vTh, vS;
|
|
48
42
|
void main(){
|
|
49
43
|
float t = dot(aPos-uG, uU);
|
|
@@ -57,14 +51,14 @@ void main(){
|
|
|
57
51
|
vec2 pos = aPos + uU*(tp-t);
|
|
58
52
|
vOrig = aPos; vXY = pos; vZ = z; vTh = th; vS = s;
|
|
59
53
|
float k = 1.0/(1.0 - min(z,1500.0)/3200.0);
|
|
60
|
-
vec2 xy =
|
|
54
|
+
vec2 xy = pos*uScale*k;
|
|
61
55
|
gl_Position = vec4(xy*2.0/uView, -0.1 - min(z,600.0)*0.0015, 1.0);
|
|
62
|
-
}`,
|
|
56
|
+
}`, Ie = (r) => `
|
|
63
57
|
precision highp float;
|
|
64
58
|
${Be}
|
|
65
59
|
float sdRR(vec2 p, vec2 b, float r){ vec2 q = abs(p)-b+r; return length(max(q,0.0)) + min(max(q.x,q.y),0.0) - r; }
|
|
66
60
|
float hash(vec2 p){ return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453); }
|
|
67
|
-
float rectMask(vec2 p, float soft){
|
|
61
|
+
float rectMask(vec2 p, float soft){ return smoothstep(-soft*0.5, soft, -sdRR(p, uHalf, ${r.toFixed(1)})); }
|
|
68
62
|
// Shadow of the folded part: which point of the original card hangs above point q.
|
|
69
63
|
float flapShadow(vec2 q){
|
|
70
64
|
float tq = dot(q-uG, uU);
|
|
@@ -75,11 +69,11 @@ float flapShadow(vec2 q){
|
|
|
75
69
|
else{ float e = (tq-tA)/uCosPhi; s = uTheta*uR + e; z = uR*(1.0+uCosPhi) + e*uSinPhi; }
|
|
76
70
|
vec2 po = q + uU*((uTf - s) - tq);
|
|
77
71
|
return rectMask(po, 3.0 + 0.3*z) * decay * exp(-z/110.0);
|
|
78
|
-
}`,
|
|
72
|
+
}`, gt = (r) => `${Ie(r)}
|
|
79
73
|
uniform sampler2D uFront; uniform vec3 uBack; uniform float uScale, uAlpha;
|
|
80
74
|
varying vec2 vOrig, vXY; varying float vZ, vTh, vS;
|
|
81
75
|
void main(){
|
|
82
|
-
float sd = sdRR(vOrig, uHalf, ${
|
|
76
|
+
float sd = sdRR(vOrig, uHalf, ${r.toFixed(1)});
|
|
83
77
|
float a = clamp(0.5 - sd*uScale, 0.0, 1.0);
|
|
84
78
|
if(a <= 0.0) discard;
|
|
85
79
|
float c = cos(vTh);
|
|
@@ -99,23 +93,23 @@ void main(){
|
|
|
99
93
|
col += max(pow(max(dot(N,Hh),0.0),48.0) - pow(Hh.z,48.0), 0.0)*0.2;
|
|
100
94
|
if(front && vTh < 1.5707963) col *= 1.0 - 0.55*flapShadow(vXY)*exp(-vZ/16.0);
|
|
101
95
|
gl_FragColor = vec4(col*a*uAlpha, a*uAlpha);
|
|
102
|
-
}`,
|
|
103
|
-
uniform sampler2D uBase; uniform vec2 uView
|
|
96
|
+
}`, pt = "attribute vec2 aPos; void main(){ gl_Position = vec4(aPos,0.0,1.0); }", vt = (r) => `${Ie(r)}
|
|
97
|
+
uniform sampler2D uBase; uniform vec2 uView; uniform float uScale, uAlpha; uniform vec3 uBg;
|
|
104
98
|
void main(){
|
|
105
|
-
vec2 q = (gl_FragCoord.xy - 0.5*uView)/uScale
|
|
99
|
+
vec2 q = (gl_FragCoord.xy - 0.5*uView)/uScale;
|
|
106
100
|
vec2 sc = gl_FragCoord.xy/uView - 0.5;
|
|
107
101
|
vec3 col = uBg*(1.0 - 0.22*dot(sc,sc)*2.0) + (hash(gl_FragCoord.xy)-0.5)*0.012;
|
|
108
|
-
float dsh = sdRR(q - vec2(0.0,-14.0), uHalf, ${
|
|
102
|
+
float dsh = sdRR(q - vec2(0.0,-14.0), uHalf, ${r.toFixed(1)});
|
|
109
103
|
col *= 1.0 - 0.30*(1.0 - smoothstep(-20.0, 34.0, dsh));
|
|
110
|
-
float dc = sdRR(q - vec2(0.0,-2.0), uHalf, ${
|
|
104
|
+
float dc = sdRR(q - vec2(0.0,-2.0), uHalf, ${r.toFixed(1)});
|
|
111
105
|
col *= 1.0 - 0.18*(1.0 - smoothstep(-2.0, 8.0, dc));
|
|
112
|
-
float sd = sdRR(q, uHalf, ${
|
|
106
|
+
float sd = sdRR(q, uHalf, ${r.toFixed(1)});
|
|
113
107
|
float a = clamp(0.5 - sd*uScale, 0.0, 1.0);
|
|
114
108
|
vec3 tex = texture2D(uBase, q/(2.0*uHalf)+0.5).rgb*0.97;
|
|
115
109
|
col = mix(col, tex, a);
|
|
116
|
-
col *= 1.0 - 0.55*flapShadow(q);
|
|
110
|
+
col *= 1.0 - 0.55*flapShadow(q)*uAlpha;
|
|
117
111
|
gl_FragColor = vec4(col,1.0);
|
|
118
|
-
}`,
|
|
112
|
+
}`, Tt = {
|
|
119
113
|
name: "PeelCard",
|
|
120
114
|
props: {
|
|
121
115
|
cards: { type: Array, required: !0 },
|
|
@@ -130,8 +124,8 @@ void main(){
|
|
|
130
124
|
label: { type: String, default: "Card: drag the edge to peel it off" }
|
|
131
125
|
},
|
|
132
126
|
emits: ["grab", "peel", "change", "toggle"],
|
|
133
|
-
setup(
|
|
134
|
-
const
|
|
127
|
+
setup(r, { emit: i, expose: l }) {
|
|
128
|
+
const d = D(null), E = D(null), x = D(!1), T = D(!1), L = D(!1), Ue = { position: "relative", width: "100%", height: "100%", minHeight: "200px" }, ke = { position: "absolute", inset: "0", display: "grid", placeItems: "center", padding: "24px", textAlign: "center", opacity: ".7" }, Ce = at(() => ({
|
|
135
129
|
position: "absolute",
|
|
136
130
|
inset: "0",
|
|
137
131
|
width: "100%",
|
|
@@ -140,113 +134,111 @@ void main(){
|
|
|
140
134
|
touchAction: "none",
|
|
141
135
|
userSelect: "none",
|
|
142
136
|
WebkitUserSelect: "none",
|
|
143
|
-
cursor:
|
|
144
|
-
outline:
|
|
137
|
+
cursor: x.value ? "grabbing" : "grab",
|
|
138
|
+
outline: T.value ? "2px solid currentColor" : "none",
|
|
145
139
|
outlineOffset: "-4px"
|
|
146
140
|
})), Ne = (h) => {
|
|
147
141
|
try {
|
|
148
|
-
|
|
142
|
+
T.value = h.target.matches(":focus-visible");
|
|
149
143
|
} catch {
|
|
150
|
-
|
|
144
|
+
T.value = !1;
|
|
151
145
|
}
|
|
152
146
|
};
|
|
153
147
|
let le = () => {
|
|
154
148
|
};
|
|
155
|
-
const
|
|
149
|
+
const ce = { peel() {
|
|
156
150
|
} };
|
|
157
|
-
function
|
|
158
|
-
const h =
|
|
151
|
+
function De() {
|
|
152
|
+
const h = E.value, f = r.width, g = r.height, j = r.radius, R = r.toggle, t = h.getContext("webgl2", { antialias: !0, alpha: !1 }) || h.getContext("webgl", { antialias: !0, alpha: !1 });
|
|
159
153
|
if (!t) {
|
|
160
154
|
L.value = !0;
|
|
161
155
|
return;
|
|
162
156
|
}
|
|
163
|
-
const
|
|
164
|
-
let
|
|
165
|
-
const
|
|
166
|
-
let
|
|
167
|
-
const
|
|
168
|
-
const o = (
|
|
169
|
-
const
|
|
170
|
-
return t.shaderSource(
|
|
171
|
-
},
|
|
172
|
-
t.attachShader(
|
|
173
|
-
const
|
|
174
|
-
for (let
|
|
175
|
-
const
|
|
176
|
-
|
|
157
|
+
const Oe = typeof WebGL2RenderingContext < "u" && t instanceof WebGL2RenderingContext, b = () => R ? 2 : r.cards.length;
|
|
158
|
+
let O = !0;
|
|
159
|
+
const de = [];
|
|
160
|
+
let K = 0;
|
|
161
|
+
const fe = (n, a) => {
|
|
162
|
+
const o = (u, m) => {
|
|
163
|
+
const p = t.createShader(u);
|
|
164
|
+
return t.shaderSource(p, m), t.compileShader(p), t.getShaderParameter(p, t.COMPILE_STATUS) || console.error(t.getShaderInfoLog(p)), p;
|
|
165
|
+
}, s = t.createProgram();
|
|
166
|
+
t.attachShader(s, o(t.VERTEX_SHADER, n)), t.attachShader(s, o(t.FRAGMENT_SHADER, a)), t.linkProgram(s), t.getProgramParameter(s, t.LINK_STATUS) || console.error(t.getProgramInfoLog(s)), s.loc = {};
|
|
167
|
+
const c = t.getProgramParameter(s, t.ACTIVE_UNIFORMS);
|
|
168
|
+
for (let u = 0; u < c; u++) {
|
|
169
|
+
const m = t.getActiveUniform(s, u).name;
|
|
170
|
+
s.loc[m] = t.getUniformLocation(s, m);
|
|
177
171
|
}
|
|
178
|
-
return
|
|
179
|
-
},
|
|
180
|
-
for (let n = 0, a = 0; n <=
|
|
181
|
-
Z[a++] = -
|
|
182
|
-
const
|
|
183
|
-
for (let n = 0, a = 0; n <
|
|
184
|
-
const
|
|
185
|
-
|
|
172
|
+
return s.aPos = t.getAttribLocation(s, "aPos"), s;
|
|
173
|
+
}, M = fe(mt, gt(j)), _ = fe(pt, vt(j)), ue = Math.max(2.5, Math.sqrt((f + 4) * (g + 4) / 6e4)), S = Math.round((f + 4) / ue), I = Math.round((g + 4) / ue), he = f / 2 + 2, me = g / 2 + 2, Z = new Float32Array((S + 1) * (I + 1) * 2);
|
|
174
|
+
for (let n = 0, a = 0; n <= I; n++) for (let o = 0; o <= S; o++)
|
|
175
|
+
Z[a++] = -he + 2 * he * o / S, Z[a++] = -me + 2 * me * n / I;
|
|
176
|
+
const A = new Uint16Array(S * I * 6);
|
|
177
|
+
for (let n = 0, a = 0; n < I; n++) for (let o = 0; o < S; o++) {
|
|
178
|
+
const s = n * (S + 1) + o, c = s + 1, u = s + S + 1, m = u + 1;
|
|
179
|
+
A[a++] = s, A[a++] = c, A[a++] = u, A[a++] = c, A[a++] = m, A[a++] = u;
|
|
186
180
|
}
|
|
187
|
-
const K = t.createBuffer();
|
|
188
|
-
t.bindBuffer(t.ARRAY_BUFFER, K), t.bufferData(t.ARRAY_BUFFER, Z, t.STATIC_DRAW);
|
|
189
181
|
const Q = t.createBuffer();
|
|
190
|
-
t.bindBuffer(t.
|
|
182
|
+
t.bindBuffer(t.ARRAY_BUFFER, Q), t.bufferData(t.ARRAY_BUFFER, Z, t.STATIC_DRAW);
|
|
191
183
|
const J = t.createBuffer();
|
|
192
|
-
t.bindBuffer(t.
|
|
193
|
-
|
|
184
|
+
t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, J), t.bufferData(t.ELEMENT_ARRAY_BUFFER, A, t.STATIC_DRAW);
|
|
185
|
+
const ee = t.createBuffer();
|
|
186
|
+
t.bindBuffer(t.ARRAY_BUFFER, ee), t.bufferData(t.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), t.STATIC_DRAW);
|
|
187
|
+
let U = 2, v = 0;
|
|
194
188
|
const P = /* @__PURE__ */ new Map();
|
|
195
|
-
async function
|
|
196
|
-
const a = Math.round(f *
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
let
|
|
189
|
+
async function Ge(n) {
|
|
190
|
+
const a = Math.round(f * U), o = Math.round(g * U), s = document.createElement("canvas");
|
|
191
|
+
s.width = a, s.height = o;
|
|
192
|
+
const c = s.getContext("2d");
|
|
193
|
+
let u = !1;
|
|
200
194
|
try {
|
|
201
|
-
const
|
|
202
|
-
|
|
195
|
+
const m = new Image(), p = new Promise((F, B) => {
|
|
196
|
+
m.onload = F, m.onerror = B;
|
|
203
197
|
});
|
|
204
|
-
|
|
205
|
-
} catch (
|
|
206
|
-
console.warn("[PeelCard] foreignObject unavailable, drawing fallback",
|
|
198
|
+
m.src = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(ht(n, f, g)), await p, c.drawImage(m, 0, 0, a, o), c.getImageData(0, 0, 1, 1), u = !0;
|
|
199
|
+
} catch (m) {
|
|
200
|
+
console.warn("[PeelCard] foreignObject unavailable, drawing fallback", m);
|
|
207
201
|
}
|
|
208
|
-
if (!
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
|
|
202
|
+
if (!u) {
|
|
203
|
+
c.setTransform(1, 0, 0, 1, 0, 0), c.fillStyle = n.bg || "#ffffff", c.fillRect(0, 0, a, o);
|
|
204
|
+
const p = (new DOMParser().parseFromString(n.html || "", "text/html").body.textContent || "").split(/\n+/).map((F) => F.trim()).filter(Boolean).slice(0, 6);
|
|
205
|
+
c.scale(U, U), c.fillStyle = "#222", c.font = "600 22px system-ui,sans-serif", p.forEach((F, B) => c.fillText(F, 28, 50 + B * 34));
|
|
212
206
|
}
|
|
213
|
-
return
|
|
207
|
+
return s;
|
|
214
208
|
}
|
|
215
|
-
function
|
|
216
|
-
if (!
|
|
217
|
-
if (n = (n %
|
|
218
|
-
const a =
|
|
219
|
-
return o.promise =
|
|
220
|
-
if (!
|
|
221
|
-
const
|
|
222
|
-
t.bindTexture(t.TEXTURE_2D,
|
|
209
|
+
function G(n) {
|
|
210
|
+
if (!b() || !r.cards.length) return Promise.resolve();
|
|
211
|
+
if (n = (n % b() + b()) % b(), P.has(n)) return P.get(n).promise;
|
|
212
|
+
const a = r.cards[n % r.cards.length], o = { tex: null, back: ut(a.back || "#f2efe6") };
|
|
213
|
+
return o.promise = Ge(a).then((s) => {
|
|
214
|
+
if (!O || P.get(n) !== o) return;
|
|
215
|
+
const c = t.createTexture();
|
|
216
|
+
t.bindTexture(t.TEXTURE_2D, c), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, !0), t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, t.RGBA, t.UNSIGNED_BYTE, s), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_S, t.CLAMP_TO_EDGE), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_T, t.CLAMP_TO_EDGE), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MAG_FILTER, t.LINEAR), Oe ? (t.generateMipmap(t.TEXTURE_2D), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MIN_FILTER, t.LINEAR_MIPMAP_LINEAR)) : t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MIN_FILTER, t.LINEAR), o.tex = c;
|
|
223
217
|
}), P.set(n, o), o.promise;
|
|
224
218
|
}
|
|
225
|
-
function
|
|
226
|
-
const a = n ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([
|
|
227
|
-
for (const [o,
|
|
219
|
+
function te(n) {
|
|
220
|
+
const a = n ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([v, (v + 1) % b(), (v + 2) % b()]);
|
|
221
|
+
for (const [o, s] of P) a.has(o) || (s.tex && t.deleteTexture(s.tex), P.delete(o));
|
|
228
222
|
}
|
|
229
|
-
const
|
|
230
|
-
let
|
|
231
|
-
function
|
|
232
|
-
const n =
|
|
233
|
-
|
|
234
|
-
const a = x ? 1.5 : 1;
|
|
235
|
-
D = Math.max(0.3, Math.min(i.maxScale, (te - 2 * i.padding) / (f * a), (ne - 2 * i.padding) / (g * a)));
|
|
223
|
+
const ge = () => Promise.all([G(0), G(1), G(2)]);
|
|
224
|
+
let k = 1, C = 1, ne = 1, ae = 1, q = 1, X = 1;
|
|
225
|
+
function pe() {
|
|
226
|
+
const n = d.value.getBoundingClientRect();
|
|
227
|
+
ne = Math.max(1, n.width), ae = Math.max(1, n.height), k = Math.min(window.devicePixelRatio || 1, 2), q = Math.round(ne * k), X = Math.round(ae * k), h.width = q, h.height = X, C = Math.max(0.3, Math.min(r.maxScale, (ne - 2 * r.padding) / f, (ae - 2 * r.padding) / g));
|
|
236
228
|
}
|
|
237
|
-
let
|
|
238
|
-
function
|
|
239
|
-
let n =
|
|
229
|
+
let y = [0.9, 0.89, 0.85];
|
|
230
|
+
function H() {
|
|
231
|
+
let n = r.background;
|
|
240
232
|
if (!n)
|
|
241
|
-
for (let o =
|
|
242
|
-
const
|
|
243
|
-
if (
|
|
244
|
-
n =
|
|
233
|
+
for (let o = d.value; o; o = o.parentElement) {
|
|
234
|
+
const s = getComputedStyle(o).backgroundColor;
|
|
235
|
+
if (s && !/rgba?\(.*,\s*0\)$/.test(s) && s !== "transparent") {
|
|
236
|
+
n = s;
|
|
245
237
|
break;
|
|
246
238
|
}
|
|
247
239
|
}
|
|
248
240
|
const a = (n || "").match(/[\d.]+/g);
|
|
249
|
-
a && a.length >= 3 && (
|
|
241
|
+
a && a.length >= 3 && (y = [a[0] / 255, a[1] / 255, a[2] / 255]);
|
|
250
242
|
}
|
|
251
243
|
const e = {
|
|
252
244
|
mode: "idle",
|
|
@@ -268,188 +260,203 @@ void main(){
|
|
|
268
260
|
interacted: !1,
|
|
269
261
|
peeled: !1,
|
|
270
262
|
restick: !1,
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
},
|
|
274
|
-
const o = Te(n, a);
|
|
275
|
-
return Math.cos($) * (Math.max(...o) - Math.min(...o)) + B + 8;
|
|
276
|
-
}, Ee = (n) => {
|
|
263
|
+
pending: !1,
|
|
264
|
+
prog: !1
|
|
265
|
+
}, qe = matchMedia("(prefers-reduced-motion: reduce)").matches, Xe = [[-f / 2, -g / 2], [f / 2, -g / 2], [-f / 2, g / 2], [f / 2, g / 2]], He = (n, a) => Xe.map((o) => (o[0] - n[0]) * a[0] + (o[1] - n[1]) * a[1]), ve = (n, a) => Math.max(...He(n, a)), N = (n, a) => Le(ve(n, a) + 2.2 * W + 20, W, Math.PI - 0.12, 0.12), Te = (n) => {
|
|
277
266
|
const a = h.getBoundingClientRect();
|
|
278
|
-
return [(n.clientX - a.left - a.width / 2) /
|
|
267
|
+
return [(n.clientX - a.left - a.width / 2) / C, -(n.clientY - a.top - a.height / 2) / C];
|
|
279
268
|
};
|
|
269
|
+
function Ee(n, a) {
|
|
270
|
+
const o = j * 0.8, s = (c, u) => Math.max(-u + o, Math.min(u - o, c));
|
|
271
|
+
e.nIn = n, e.g = n[0] ? [-n[0] * f / 2, s(a[1], g / 2)] : [s(a[0], f / 2), -n[1] * g / 2];
|
|
272
|
+
}
|
|
280
273
|
function ze(n) {
|
|
281
|
-
const a = n[0] + f / 2, o = f / 2 - n[0],
|
|
282
|
-
|
|
274
|
+
const a = n[0] + f / 2, o = f / 2 - n[0], s = n[1] + g / 2, c = g / 2 - n[1], u = Math.min(a, o, s, c);
|
|
275
|
+
Ee(u === a ? [1, 0] : u === o ? [-1, 0] : u === s ? [0, 1] : [0, -1], n), e.p0 = n, e.dT = 0, e.angT = 0, e.velU = 0, e.lastDT = 0, e.lastTime = performance.now();
|
|
283
276
|
}
|
|
284
|
-
function
|
|
277
|
+
function $e(n) {
|
|
278
|
+
const a = n[0] - e.p0[0], o = n[1] - e.p0[1];
|
|
279
|
+
return Math.hypot(a, o) < 10 ? !1 : (Ee(Math.abs(a) >= Math.abs(o) ? [-Math.sign(a), 0] : [0, -Math.sign(o)], e.p0), e.pending = !1, e.ang = 0, e.angBase = 0, e.angT = 0, e.dEnd = N(e.g, e.nIn), e.d = e.dEnd, e.dT = 0, e.velU = 0, e.lastDT = 0, e.lastTime = performance.now(), !0);
|
|
280
|
+
}
|
|
281
|
+
function xe(n) {
|
|
285
282
|
const a = performance.now(), o = Math.max(1, a - e.lastTime);
|
|
286
283
|
e.velU += ((n - e.lastDT) / o * 1e3 - e.velU) * 0.35, e.lastDT = n, e.lastTime = a;
|
|
287
284
|
}
|
|
288
|
-
function
|
|
285
|
+
function Ve(n) {
|
|
289
286
|
const a = [n[0] - e.p0[0], n[1] - e.p0[1]], o = Math.hypot(a[0], a[1]);
|
|
290
287
|
if (e.restick) {
|
|
291
|
-
const
|
|
292
|
-
e.angT = e.angBase +
|
|
293
|
-
const
|
|
294
|
-
e.dT = Math.max(0, -(a[0] *
|
|
288
|
+
const p = w(e.nIn, e.angBase).map((Qe) => -Qe), F = Math.max(-0.6, Math.min(0.6, Math.atan2(p[0] * a[1] - p[1] * a[0], a[0] * p[0] + a[1] * p[1])));
|
|
289
|
+
e.angT = e.angBase + F * Y(6, 70, o);
|
|
290
|
+
const B = w(e.nIn, e.angT);
|
|
291
|
+
e.dT = Math.max(0, -(a[0] * B[0] + a[1] * B[1])), xe(e.dT);
|
|
295
292
|
return;
|
|
296
293
|
}
|
|
297
|
-
const
|
|
298
|
-
e.angT =
|
|
299
|
-
const
|
|
300
|
-
e.dT = Math.max(0, a[0] *
|
|
294
|
+
const s = a[0] * e.nIn[0] + a[1] * e.nIn[1], c = e.nIn[0] * a[1] - e.nIn[1] * a[0], u = Math.max(-V, Math.min(V, Math.atan2(c, s)));
|
|
295
|
+
e.angT = u * Y(6, 70, o);
|
|
296
|
+
const m = w(e.nIn, e.angT);
|
|
297
|
+
e.dT = Math.max(0, a[0] * m[0] + a[1] * m[1]), xe(e.dT);
|
|
301
298
|
}
|
|
302
299
|
function oe() {
|
|
303
|
-
const n =
|
|
304
|
-
|
|
305
|
-
e.dEnd = N(e.g, n);
|
|
306
|
-
const a = Ve(e.g, n) / 2;
|
|
307
|
-
e.shiftVec = [n[0] * a, n[1] * a];
|
|
308
|
-
} else
|
|
309
|
-
e.dEnd = se(ae(e.g, n) + 2.2 * B + 20, B, Math.PI - 0.12, 0.12);
|
|
310
|
-
e.mode = "complete";
|
|
300
|
+
const n = w(e.nIn, e.prog ? e.angT : e.ang);
|
|
301
|
+
e.dEnd = N(e.g, n), e.alpha = 1, e.mode = "complete";
|
|
311
302
|
}
|
|
312
|
-
function
|
|
303
|
+
function Ye() {
|
|
313
304
|
if (e.mode !== "drag") return;
|
|
314
|
-
|
|
315
|
-
|
|
305
|
+
if (x.value = !1, e.pending) {
|
|
306
|
+
e.pending = !1, e.restick = !1, e.mode = "rest", re();
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const n = w(e.nIn, e.ang);
|
|
316
310
|
if (e.restick) {
|
|
317
311
|
const o = e.d / N(e.g, n);
|
|
318
312
|
o < 0.6 || e.velU > 700 && o < 0.9 ? e.mode = "settle" : oe();
|
|
319
313
|
return;
|
|
320
314
|
}
|
|
321
|
-
const a = e.d /
|
|
315
|
+
const a = e.d / ve(e.g, n);
|
|
322
316
|
a > 0.32 || e.velU > 700 && a > 0.1 ? oe() : e.mode = "settle";
|
|
323
317
|
}
|
|
324
|
-
function
|
|
325
|
-
|
|
318
|
+
function re(n) {
|
|
319
|
+
const a = Math.max(-V, Math.min(V, (typeof n == "number" ? n : ct) * Math.PI / 180));
|
|
320
|
+
if (R && e.peeled && e.mode === "rest") {
|
|
321
|
+
e.nIn = [1, 0], e.g = [-f / 2, 0], e.ang = e.angT = a, e.prog = !0, e.dEnd = N(e.g, w(e.nIn, a)), e.d = e.dEnd, e.t = 0, e.mode = "unfade";
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (R && e.peeled && e.mode === "drag") {
|
|
326
325
|
e.restick = !1, e.mode = "settle";
|
|
327
326
|
return;
|
|
328
327
|
}
|
|
329
|
-
e.mode !== "idle" && e.mode !== "hint" && e.mode !== "settle" ||
|
|
328
|
+
e.mode !== "idle" && e.mode !== "hint" && e.mode !== "settle" || R && e.peeled || (e.interacted = !0, e.nIn = [1, 0], e.g = [-f / 2, 0], e.ang = 0, e.angT = a, e.prog = !0, oe());
|
|
330
329
|
}
|
|
331
|
-
|
|
332
|
-
function
|
|
333
|
-
!
|
|
330
|
+
ce.peel = re;
|
|
331
|
+
function Re() {
|
|
332
|
+
!r.hint || e.mode !== "idle" || e.interacted || qe || (e.nIn = [1, 0], e.g = [-f / 2, 0], e.ang = 0, e.mode = "hint", e.t = 0);
|
|
334
333
|
}
|
|
335
|
-
const
|
|
336
|
-
if (e.mode === "complete" || e.mode === "fade") return;
|
|
337
|
-
const a =
|
|
338
|
-
if (
|
|
339
|
-
|
|
334
|
+
const be = (n) => {
|
|
335
|
+
if (e.mode === "complete" || e.mode === "fade" || e.mode === "unfade" || e.mode === "unpeel") return;
|
|
336
|
+
const a = Te(n);
|
|
337
|
+
if (e.prog = !1, R && e.peeled) {
|
|
338
|
+
if (e.mode !== "rest") return;
|
|
339
|
+
h.setPointerCapture(n.pointerId), x.value = !0, e.restick = !0, e.pending = !0, e.p0 = a, e.mode = "drag";
|
|
340
340
|
return;
|
|
341
341
|
}
|
|
342
|
-
Math.abs(a[0]) > f / 2 + 30 || Math.abs(a[1]) > g / 2 + 30 || (h.setPointerCapture(n.pointerId),
|
|
343
|
-
},
|
|
344
|
-
e.mode
|
|
345
|
-
|
|
346
|
-
|
|
342
|
+
Math.abs(a[0]) > f / 2 + 30 || Math.abs(a[1]) > g / 2 + 30 || (h.setPointerCapture(n.pointerId), x.value = !0, e.interacted || i("grab"), e.interacted = !0, e.restick = !1, ze(a), e.mode = "drag");
|
|
343
|
+
}, Me = (n) => {
|
|
344
|
+
if (e.mode !== "drag") return;
|
|
345
|
+
const a = Te(n);
|
|
346
|
+
e.pending && !$e(a) || Ve(a);
|
|
347
|
+
}, z = () => Ye(), _e = (n) => {
|
|
348
|
+
(n.key === "ArrowRight" || n.key === "Enter" || n.key === " ") && (n.preventDefault(), re());
|
|
347
349
|
};
|
|
348
|
-
h.addEventListener("pointerdown",
|
|
350
|
+
h.addEventListener("pointerdown", be), h.addEventListener("pointermove", Me), h.addEventListener("pointerup", z), h.addEventListener("pointercancel", z), h.addEventListener("keydown", _e);
|
|
349
351
|
function We() {
|
|
350
|
-
const n =
|
|
351
|
-
|
|
352
|
+
const n = v;
|
|
353
|
+
v = (v + 1) % b(), e.d = 0, e.ang = 0, e.alpha = 1, e.mode = "idle", G(v + 2), te(!1), i("peel", n), i("change", v);
|
|
352
354
|
}
|
|
353
355
|
function je(n) {
|
|
354
356
|
switch (e.mode) {
|
|
355
357
|
case "drag":
|
|
358
|
+
if (e.pending) break;
|
|
356
359
|
if (e.restick) {
|
|
357
|
-
const
|
|
358
|
-
e.d += (Math.max(0,
|
|
360
|
+
const a = N(e.g, w(e.nIn, e.ang));
|
|
361
|
+
e.d += (Math.max(0, a - e.dT) - e.d) * (1 - Math.exp(-n * 30));
|
|
359
362
|
} else e.d += (Math.min(e.dT, 1500) - e.d) * (1 - Math.exp(-n * 30));
|
|
360
363
|
e.ang += (e.angT - e.ang) * (1 - Math.exp(-n * 16));
|
|
361
364
|
break;
|
|
362
365
|
case "settle":
|
|
363
|
-
e.d += (0 - e.d) * (1 - Math.exp(-n * 9)), e.d < 0.05 && (e.d = 0, e.mode = "idle",
|
|
366
|
+
e.d += (0 - e.d) * (1 - Math.exp(-n * 9)), e.ang += (0 - e.ang) * (1 - Math.exp(-n * 14)), e.d < 0.05 && Math.abs(e.ang) < 2e-3 && (e.d = 0, e.ang = 0, e.mode = "idle", R && e.peeled && (e.peeled = !1, i("toggle", !1)));
|
|
364
367
|
break;
|
|
365
368
|
case "hint": {
|
|
366
369
|
e.t += n;
|
|
367
|
-
const
|
|
368
|
-
|
|
370
|
+
const a = e.t / 1.5;
|
|
371
|
+
a >= 1 ? (e.d = 0, e.ang = 0, e.mode = "idle") : (e.d = 70 * Math.pow(Math.sin(Math.PI * a), 2), e.ang = 0.22 * Math.sin(2 * Math.PI * a));
|
|
369
372
|
break;
|
|
370
373
|
}
|
|
371
374
|
case "complete":
|
|
372
|
-
e.d += Math.max((e.dEnd - e.d) * (1 - Math.exp(-n * 6)), 380 * n), e.
|
|
375
|
+
e.d += Math.max((e.dEnd - e.d) * (1 - Math.exp(-n * 6)), 380 * n), e.prog && (e.ang = e.angT * Y(6, 70, e.d)), e.d >= e.dEnd && (e.d = e.dEnd, e.mode = "fade", e.t = 0);
|
|
373
376
|
break;
|
|
374
377
|
case "rest":
|
|
375
|
-
e.d = N(e.g, A(e.nIn, e.ang));
|
|
376
378
|
break;
|
|
377
379
|
case "fade":
|
|
378
|
-
e.t += n, e.alpha = Math.max(0, 1 - e.t / 0.28), e.t >= 0.28 && We();
|
|
380
|
+
e.t += n, e.alpha = Math.max(0, 1 - e.t / 0.28), e.t >= 0.28 && (R ? (e.mode = "rest", e.peeled || (e.peeled = !0, i("toggle", !0))) : We());
|
|
381
|
+
break;
|
|
382
|
+
case "unfade":
|
|
383
|
+
e.t += n, e.alpha = Math.min(1, e.alpha + n / 0.28), e.alpha >= 1 && (e.mode = "unpeel");
|
|
384
|
+
break;
|
|
385
|
+
case "unpeel":
|
|
386
|
+
e.d -= Math.max((e.dEnd - e.d) * (1 - Math.exp(-n * 6)), 380 * n), e.ang = e.angT * Y(6, 70, e.d), e.d <= 0 && (e.d = 0, e.ang = 0, e.prog = !1, e.mode = "idle", e.peeled = !1, i("toggle", !1));
|
|
379
387
|
break;
|
|
380
388
|
}
|
|
381
|
-
|
|
382
|
-
e.shiftF += (a - e.shiftF) * (1 - Math.exp(-n * 6));
|
|
389
|
+
R && !e.pending && (e.mode === "drag" || e.mode === "settle") && (e.alpha += (1 - e.alpha) * (1 - Math.exp(-n * 12)));
|
|
383
390
|
}
|
|
384
|
-
function
|
|
385
|
-
const
|
|
386
|
-
t.uniform2f(
|
|
391
|
+
function Ae(n, a, o) {
|
|
392
|
+
const s = n.loc;
|
|
393
|
+
t.uniform2f(s.uG, e.g[0], e.g[1]), t.uniform2f(s.uU, o[0], o[1]), t.uniform2f(s.uHalf, f / 2, g / 2), t.uniform1f(s.uTf, a.tf), t.uniform1f(s.uR, a.R), t.uniform1f(s.uTheta, a.Th), t.uniform1f(s.uSinPhi, a.sp), t.uniform1f(s.uCosPhi, a.cp), t.uniform2f(s.uView, q, X), t.uniform1f(s.uScale, C * k);
|
|
387
394
|
}
|
|
388
|
-
function
|
|
389
|
-
const n = P.get(
|
|
390
|
-
if (t.viewport(0, 0,
|
|
391
|
-
const o =
|
|
392
|
-
t.disable(t.DEPTH_TEST), t.disable(t.BLEND), t.useProgram(
|
|
395
|
+
function Ke() {
|
|
396
|
+
const n = P.get(v), a = P.get((v + 1) % b());
|
|
397
|
+
if (t.viewport(0, 0, q, X), t.clearColor(y[0], y[1], y[2], 1), t.clear(t.COLOR_BUFFER_BIT | t.DEPTH_BUFFER_BIT), !n || !n.tex || !a || !a.tex) return;
|
|
398
|
+
const o = w(e.nIn, e.ang), s = ft(e.d);
|
|
399
|
+
t.disable(t.DEPTH_TEST), t.disable(t.BLEND), t.useProgram(_), Ae(_, s, o), t.uniform3f(_.loc.uBg, y[0], y[1], y[2]), t.uniform1f(_.loc.uAlpha, e.alpha), t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, a.tex), t.uniform1i(_.loc.uBase, 0), t.bindBuffer(t.ARRAY_BUFFER, ee), t.enableVertexAttribArray(_.aPos), t.vertexAttribPointer(_.aPos, 2, t.FLOAT, !1, 0, 0), t.drawArrays(t.TRIANGLE_STRIP, 0, 4), t.enable(t.DEPTH_TEST), t.depthFunc(t.LEQUAL), t.enable(t.BLEND), t.blendFunc(t.ONE, t.ONE_MINUS_SRC_ALPHA), t.useProgram(M), Ae(M, s, o), t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, n.tex), t.uniform1i(M.loc.uFront, 0), t.uniform3f(M.loc.uBack, n.back[0], n.back[1], n.back[2]), t.uniform1f(M.loc.uAlpha, e.alpha), t.bindBuffer(t.ARRAY_BUFFER, Q), t.enableVertexAttribArray(M.aPos), t.vertexAttribPointer(M.aPos, 2, t.FLOAT, !1, 0, 0), t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, J), t.drawElements(t.TRIANGLES, A.length, t.UNSIGNED_SHORT, 0);
|
|
393
400
|
}
|
|
394
|
-
let
|
|
401
|
+
let se = performance.now();
|
|
395
402
|
function Pe(n) {
|
|
396
|
-
if (!
|
|
397
|
-
const a = Math.min(0.05, (n -
|
|
398
|
-
|
|
403
|
+
if (!O) return;
|
|
404
|
+
const a = Math.min(0.05, (n - se) / 1e3);
|
|
405
|
+
se = n, je(a), Ke(), K = requestAnimationFrame(Pe);
|
|
399
406
|
}
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
const
|
|
407
|
-
|
|
407
|
+
const we = new ResizeObserver(pe);
|
|
408
|
+
we.observe(d.value);
|
|
409
|
+
const $ = matchMedia("(prefers-color-scheme: dark)");
|
|
410
|
+
$.addEventListener && $.addEventListener("change", H);
|
|
411
|
+
const Se = new MutationObserver(H);
|
|
412
|
+
Se.observe(document.documentElement, { attributes: !0 }), pe(), H(), U = Math.min(3, Math.max(2, C * k));
|
|
413
|
+
const Ze = st(() => r.cards.map((n) => `${n.bg}\0${n.back}\0${n.html}`).join(""), () => {
|
|
414
|
+
te(!0), v = 0, e.d = 0, e.mode = "idle", e.alpha = 1, e.peeled = !1, ge();
|
|
408
415
|
});
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}),
|
|
416
|
+
ge().then(() => {
|
|
417
|
+
O && (K = requestAnimationFrame((n) => {
|
|
418
|
+
se = n, Pe(n);
|
|
419
|
+
}), de.push(setTimeout(Re, 900), setTimeout(Re, 8e3)));
|
|
413
420
|
}), le = () => {
|
|
414
|
-
|
|
421
|
+
O = !1, cancelAnimationFrame(K), de.forEach(clearTimeout), Ze(), we.disconnect(), Se.disconnect(), $.removeEventListener && $.removeEventListener("change", H), h.removeEventListener("pointerdown", be), h.removeEventListener("pointermove", Me), h.removeEventListener("pointerup", z), h.removeEventListener("pointercancel", z), h.removeEventListener("keydown", _e), te(!0), t.deleteBuffer(Q), t.deleteBuffer(J), t.deleteBuffer(ee), t.deleteProgram(M), t.deleteProgram(_);
|
|
415
422
|
const n = t.getExtension("WEBGL_lose_context");
|
|
416
423
|
n && n.loseContext();
|
|
417
424
|
}, typeof window < "u" && window.__PEEL_DEBUG__ && (window.__peelDebug = e);
|
|
418
425
|
}
|
|
419
|
-
return ot(
|
|
426
|
+
return ot(De), rt(() => le()), l({ peel: () => ce.peel() }), { root: d, canvas: E, noGL: L, focused: T, rootStyle: Ue, noGLStyle: ke, canvasStyle: Ce, onFocus: Ne };
|
|
420
427
|
}
|
|
421
|
-
},
|
|
422
|
-
function
|
|
423
|
-
return ye(),
|
|
428
|
+
}, Et = ["aria-label"];
|
|
429
|
+
function xt(r, i, l, d, E, x) {
|
|
430
|
+
return ye(), Fe("div", {
|
|
424
431
|
ref: "root",
|
|
425
|
-
style: ie(
|
|
432
|
+
style: ie(d.rootStyle)
|
|
426
433
|
}, [
|
|
427
434
|
Je("canvas", {
|
|
428
435
|
ref: "canvas",
|
|
429
436
|
tabindex: "0",
|
|
430
437
|
role: "img",
|
|
431
|
-
"aria-label":
|
|
432
|
-
style: ie(
|
|
433
|
-
onFocus:
|
|
434
|
-
onBlur:
|
|
435
|
-
}, null, 44,
|
|
436
|
-
|
|
438
|
+
"aria-label": l.label,
|
|
439
|
+
style: ie(d.canvasStyle),
|
|
440
|
+
onFocus: i[0] || (i[0] = (...T) => d.onFocus && d.onFocus(...T)),
|
|
441
|
+
onBlur: i[1] || (i[1] = (T) => d.focused = !1)
|
|
442
|
+
}, null, 44, Et),
|
|
443
|
+
d.noGL ? (ye(), Fe("div", {
|
|
437
444
|
key: 0,
|
|
438
|
-
style: ie(
|
|
445
|
+
style: ie(d.noGLStyle)
|
|
439
446
|
}, [
|
|
440
|
-
et(
|
|
441
|
-
|
|
447
|
+
et(r.$slots, "fallback", {}, () => [
|
|
448
|
+
i[2] || (i[2] = tt("WebGL is not available in this browser.", -1))
|
|
442
449
|
])
|
|
443
450
|
], 4)) : nt("", !0)
|
|
444
451
|
], 4);
|
|
445
452
|
}
|
|
446
|
-
const Rt = /* @__PURE__ */
|
|
447
|
-
install(
|
|
448
|
-
|
|
453
|
+
const Rt = /* @__PURE__ */ it(Tt, [["render", xt]]), _t = {
|
|
454
|
+
install(r) {
|
|
455
|
+
r.component("PeelCard", Rt);
|
|
449
456
|
}
|
|
450
457
|
};
|
|
451
458
|
export {
|
|
452
459
|
Rt as PeelCard,
|
|
453
|
-
|
|
460
|
+
_t as PeelCardPlugin,
|
|
454
461
|
Rt as default
|
|
455
462
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
<foreignObject width="${s}" height="${
|
|
1
|
+
(function(R,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],c):(R=typeof globalThis<"u"?globalThis:R||self,c(R.VuePeelCard={},R.Vue))})(this,function(R,c){"use strict";const Fe=(r,s)=>{const l=r.__vccOpts||r;for(const[f,x]of s)l[f]=x;return l};function se(r,s,l,f){return r<=l*s?r-s*Math.sin(r/s):r-s*Math.sin(f)+(r-l*s)*Math.cos(f)}function Ie(r,s,l,f){let x=0,M=4e3;for(let E=0;E<48;E++){const B=(x+M)/2;se(B,s,l,f)<r?x=B:M=B}return(x+M)/2}function Be(r){const s=18+57*Math.exp(-r/70),l=.12+.55*Math.exp(-r/140),f=Math.PI-l;return{R:s,phi:l,Th:f,tf:Ie(r,s,f,l),sp:Math.sin(l),cp:Math.cos(l)}}const b=(r,s)=>{const l=Math.atan2(r[1],r[0])+s;return[Math.cos(l),Math.sin(l)]};function O(r,s,l){return l=Math.min(1,Math.max(0,(l-r)/(s-r))),l*l*(3-2*l)}const Ue=r=>{const s=parseInt(String(r).replace("#","").padEnd(6,"0").slice(0,6),16);return[(s>>16)/255,(s>>8&255)/255,(s&255)/255]},ke=(r,s,l)=>`<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${l}">
|
|
2
|
+
<foreignObject width="${s}" height="${l}"><div xmlns="http://www.w3.org/1999/xhtml" style="width:${s}px;height:${l}px;background:${r.bg||"#ffffff"}">${r.html||""}</div></foreignObject></svg>`,le=`
|
|
3
3
|
uniform vec2 uG, uU, uHalf;
|
|
4
4
|
uniform float uTf, uR, uTheta, uSinPhi, uCosPhi;
|
|
5
5
|
`,Ce=`
|
|
6
6
|
attribute vec2 aPos;
|
|
7
|
-
${
|
|
8
|
-
uniform vec2 uView
|
|
7
|
+
${le}
|
|
8
|
+
uniform vec2 uView; uniform float uScale;
|
|
9
9
|
varying vec2 vOrig, vXY; varying float vZ, vTh, vS;
|
|
10
10
|
void main(){
|
|
11
11
|
float t = dot(aPos-uG, uU);
|
|
@@ -19,14 +19,14 @@ void main(){
|
|
|
19
19
|
vec2 pos = aPos + uU*(tp-t);
|
|
20
20
|
vOrig = aPos; vXY = pos; vZ = z; vTh = th; vS = s;
|
|
21
21
|
float k = 1.0/(1.0 - min(z,1500.0)/3200.0);
|
|
22
|
-
vec2 xy =
|
|
22
|
+
vec2 xy = pos*uScale*k;
|
|
23
23
|
gl_Position = vec4(xy*2.0/uView, -0.1 - min(z,600.0)*0.0015, 1.0);
|
|
24
|
-
}`,
|
|
24
|
+
}`,ce=r=>`
|
|
25
25
|
precision highp float;
|
|
26
|
-
${
|
|
26
|
+
${le}
|
|
27
27
|
float sdRR(vec2 p, vec2 b, float r){ vec2 q = abs(p)-b+r; return length(max(q,0.0)) + min(max(q.x,q.y),0.0) - r; }
|
|
28
28
|
float hash(vec2 p){ return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453); }
|
|
29
|
-
float rectMask(vec2 p, float soft){
|
|
29
|
+
float rectMask(vec2 p, float soft){ return smoothstep(-soft*0.5, soft, -sdRR(p, uHalf, ${r.toFixed(1)})); }
|
|
30
30
|
// Shadow of the folded part: which point of the original card hangs above point q.
|
|
31
31
|
float flapShadow(vec2 q){
|
|
32
32
|
float tq = dot(q-uG, uU);
|
|
@@ -37,11 +37,11 @@ float flapShadow(vec2 q){
|
|
|
37
37
|
else{ float e = (tq-tA)/uCosPhi; s = uTheta*uR + e; z = uR*(1.0+uCosPhi) + e*uSinPhi; }
|
|
38
38
|
vec2 po = q + uU*((uTf - s) - tq);
|
|
39
39
|
return rectMask(po, 3.0 + 0.3*z) * decay * exp(-z/110.0);
|
|
40
|
-
}`,Ne=
|
|
40
|
+
}`,Ne=r=>`${ce(r)}
|
|
41
41
|
uniform sampler2D uFront; uniform vec3 uBack; uniform float uScale, uAlpha;
|
|
42
42
|
varying vec2 vOrig, vXY; varying float vZ, vTh, vS;
|
|
43
43
|
void main(){
|
|
44
|
-
float sd = sdRR(vOrig, uHalf, ${
|
|
44
|
+
float sd = sdRR(vOrig, uHalf, ${r.toFixed(1)});
|
|
45
45
|
float a = clamp(0.5 - sd*uScale, 0.0, 1.0);
|
|
46
46
|
if(a <= 0.0) discard;
|
|
47
47
|
float c = cos(vTh);
|
|
@@ -61,20 +61,20 @@ void main(){
|
|
|
61
61
|
col += max(pow(max(dot(N,Hh),0.0),48.0) - pow(Hh.z,48.0), 0.0)*0.2;
|
|
62
62
|
if(front && vTh < 1.5707963) col *= 1.0 - 0.55*flapShadow(vXY)*exp(-vZ/16.0);
|
|
63
63
|
gl_FragColor = vec4(col*a*uAlpha, a*uAlpha);
|
|
64
|
-
}`,De="attribute vec2 aPos; void main(){ gl_Position = vec4(aPos,0.0,1.0); }",
|
|
65
|
-
uniform sampler2D uBase; uniform vec2 uView
|
|
64
|
+
}`,De="attribute vec2 aPos; void main(){ gl_Position = vec4(aPos,0.0,1.0); }",Ge=r=>`${ce(r)}
|
|
65
|
+
uniform sampler2D uBase; uniform vec2 uView; uniform float uScale, uAlpha; uniform vec3 uBg;
|
|
66
66
|
void main(){
|
|
67
|
-
vec2 q = (gl_FragCoord.xy - 0.5*uView)/uScale
|
|
67
|
+
vec2 q = (gl_FragCoord.xy - 0.5*uView)/uScale;
|
|
68
68
|
vec2 sc = gl_FragCoord.xy/uView - 0.5;
|
|
69
69
|
vec3 col = uBg*(1.0 - 0.22*dot(sc,sc)*2.0) + (hash(gl_FragCoord.xy)-0.5)*0.012;
|
|
70
|
-
float dsh = sdRR(q - vec2(0.0,-14.0), uHalf, ${
|
|
70
|
+
float dsh = sdRR(q - vec2(0.0,-14.0), uHalf, ${r.toFixed(1)});
|
|
71
71
|
col *= 1.0 - 0.30*(1.0 - smoothstep(-20.0, 34.0, dsh));
|
|
72
|
-
float dc = sdRR(q - vec2(0.0,-2.0), uHalf, ${
|
|
72
|
+
float dc = sdRR(q - vec2(0.0,-2.0), uHalf, ${r.toFixed(1)});
|
|
73
73
|
col *= 1.0 - 0.18*(1.0 - smoothstep(-2.0, 8.0, dc));
|
|
74
|
-
float sd = sdRR(q, uHalf, ${
|
|
74
|
+
float sd = sdRR(q, uHalf, ${r.toFixed(1)});
|
|
75
75
|
float a = clamp(0.5 - sd*uScale, 0.0, 1.0);
|
|
76
76
|
vec3 tex = texture2D(uBase, q/(2.0*uHalf)+0.5).rgb*0.97;
|
|
77
77
|
col = mix(col, tex, a);
|
|
78
|
-
col *= 1.0 - 0.55*flapShadow(q);
|
|
78
|
+
col *= 1.0 - 0.55*flapShadow(q)*uAlpha;
|
|
79
79
|
gl_FragColor = vec4(col,1.0);
|
|
80
|
-
}`,Ge={name:"PeelCard",props:{cards:{type:Array,required:!0},toggle:{type:Boolean,default:!1},width:{type:Number,default:420},height:{type:Number,default:280},radius:{type:Number,default:18},background:{type:String,default:""},padding:{type:Number,default:16},maxScale:{type:Number,default:1.35},hint:{type:Boolean,default:!0},label:{type:String,default:"Card: drag the edge to peel it off"}},emits:["grab","peel","change","toggle"],setup(i,{emit:s,expose:c}){const l=f.ref(null),v=f.ref(null),E=f.ref(!1),x=f.ref(!1),U=f.ref(!1),Ve={position:"relative",width:"100%",height:"100%",minHeight:"200px"},ze={position:"absolute",inset:"0",display:"grid",placeItems:"center",padding:"24px",textAlign:"center",opacity:".7"},Ye=f.computed(()=>({position:"absolute",inset:"0",width:"100%",height:"100%",display:"block",touchAction:"none",userSelect:"none",WebkitUserSelect:"none",cursor:E.value?"grabbing":"grab",outline:x.value?"2px solid currentColor":"none",outlineOffset:"-4px"})),$e=m=>{try{x.value=m.target.matches(":focus-visible")}catch{x.value=!1}};let fe=()=>{};const de={peel(){}};function We(){const m=v.value,d=i.width,p=i.height,Z=i.radius,b=i.toggle,t=m.getContext("webgl2",{antialias:!0,alpha:!1})||m.getContext("webgl",{antialias:!0,alpha:!1});if(!t){U.value=!0;return}const je=typeof WebGL2RenderingContext<"u"&&t instanceof WebGL2RenderingContext,A=()=>b?2:i.cards.length;let G=!0;const ue=[];let K=0;const he=(n,a)=>{const o=(T,h)=>{const g=t.createShader(T);return t.shaderSource(g,h),t.compileShader(g),t.getShaderParameter(g,t.COMPILE_STATUS)||console.error(t.getShaderInfoLog(g)),g},r=t.createProgram();t.attachShader(r,o(t.VERTEX_SHADER,n)),t.attachShader(r,o(t.FRAGMENT_SHADER,a)),t.linkProgram(r),t.getProgramParameter(r,t.LINK_STATUS)||console.error(t.getProgramInfoLog(r)),r.loc={};const u=t.getProgramParameter(r,t.ACTIVE_UNIFORMS);for(let T=0;T<u;T++){const h=t.getActiveUniform(r,T).name;r.loc[h]=t.getUniformLocation(r,h)}return r.aPos=t.getAttribLocation(r,"aPos"),r},w=he(Ce,Ne(Z)),F=he(De,Oe(Z)),me=Math.max(2.5,Math.sqrt((d+4)*(p+4)/6e4)),B=Math.round((d+4)/me),k=Math.round((p+4)/me),ge=d/2+2,pe=p/2+2,Q=new Float32Array((B+1)*(k+1)*2);for(let n=0,a=0;n<=k;n++)for(let o=0;o<=B;o++)Q[a++]=-ge+2*ge*o/B,Q[a++]=-pe+2*pe*n/k;const I=new Uint16Array(B*k*6);for(let n=0,a=0;n<k;n++)for(let o=0;o<B;o++){const r=n*(B+1)+o,u=r+1,T=r+B+1,h=T+1;I[a++]=r,I[a++]=u,I[a++]=T,I[a++]=u,I[a++]=h,I[a++]=T}const J=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,J),t.bufferData(t.ARRAY_BUFFER,Q,t.STATIC_DRAW);const ee=t.createBuffer();t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,ee),t.bufferData(t.ELEMENT_ARRAY_BUFFER,I,t.STATIC_DRAW);const te=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,te),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW);let C=2,R=0;const y=new Map;async function Ze(n){const a=Math.round(d*C),o=Math.round(p*C),r=document.createElement("canvas");r.width=a,r.height=o;const u=r.getContext("2d");let T=!1;try{const h=new Image,g=new Promise((S,_)=>{h.onload=S,h.onerror=_});h.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(ke(n,d,p)),await g,u.drawImage(h,0,0,a,o),u.getImageData(0,0,1,1),T=!0}catch(h){console.warn("[PeelCard] foreignObject unavailable, drawing fallback",h)}if(!T){u.setTransform(1,0,0,1,0,0),u.fillStyle=n.bg||"#ffffff",u.fillRect(0,0,a,o);const g=(new DOMParser().parseFromString(n.html||"","text/html").body.textContent||"").split(/\n+/).map(S=>S.trim()).filter(Boolean).slice(0,6);u.scale(C,C),u.fillStyle="#222",u.font="600 22px system-ui,sans-serif",g.forEach((S,_)=>u.fillText(S,28,50+_*34))}return r}function q(n){if(!A()||!i.cards.length)return Promise.resolve();if(n=(n%A()+A())%A(),y.has(n))return y.get(n).promise;const a=i.cards[n%i.cards.length],o={tex:null,back:Ue(a.back||"#f2efe6")};return o.promise=Ze(a).then(r=>{if(!G||y.get(n)!==o)return;const u=t.createTexture();t.bindTexture(t.TEXTURE_2D,u),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,!0),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),je?(t.generateMipmap(t.TEXTURE_2D),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR_MIPMAP_LINEAR)):t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),o.tex=u}),y.set(n,o),o.promise}function ne(n){const a=n?new Set:new Set([R,(R+1)%A(),(R+2)%A()]);for(const[o,r]of y)a.has(o)||(r.tex&&t.deleteTexture(r.tex),y.delete(o))}const Te=()=>Promise.all([q(0),q(1),q(2)]);let N=1,D=1,ae=1,oe=1,X=1,H=1;function ve(){const n=l.value.getBoundingClientRect();ae=Math.max(1,n.width),oe=Math.max(1,n.height),N=Math.min(window.devicePixelRatio||1,2),X=Math.round(ae*N),H=Math.round(oe*N),m.width=X,m.height=H;const a=b?1.5:1;D=Math.max(.3,Math.min(i.maxScale,(ae-2*i.padding)/(d*a),(oe-2*i.padding)/(p*a)))}let L=[.9,.89,.85];function V(){let n=i.background;if(!n)for(let o=l.value;o;o=o.parentElement){const r=getComputedStyle(o).backgroundColor;if(r&&!/rgba?\(.*,\s*0\)$/.test(r)&&r!=="transparent"){n=r;break}}const a=(n||"").match(/[\d.]+/g);a&&a.length>=3&&(L=[a[0]/255,a[1]/255,a[2]/255])}const e={mode:"idle",d:0,ang:0,g:[-d/2,0],nIn:[1,0],p0:[0,0],dT:0,angT:0,angBase:0,alpha:1,t:0,dEnd:0,velU:0,lastDT:0,lastTime:0,interacted:!1,peeled:!1,restick:!1,shiftF:0,shiftVec:[0,0]},Ke=matchMedia("(prefers-reduced-motion: reduce)").matches,Qe=[[-d/2,-p/2],[d/2,-p/2],[-d/2,p/2],[d/2,p/2]],Ee=(n,a)=>Qe.map(o=>(o[0]-n[0])*a[0]+(o[1]-n[1])*a[1]),re=(n,a)=>Math.max(...Ee(n,a)),O=(n,a)=>$(re(n,a)+4,18,Math.PI-1.15,1.15),Je=(n,a)=>{const o=Ee(n,a);return Math.cos(1.15)*(Math.max(...o)-Math.min(...o))+18+8},Re=n=>{const a=m.getBoundingClientRect();return[(n.clientX-a.left-a.width/2)/D,-(n.clientY-a.top-a.height/2)/D]};function et(n){const a=n[0]+d/2,o=d/2-n[0],r=n[1]+p/2,u=p/2-n[1],T=Math.min(a,o,r,u),h=Z*.8,g=(S,_)=>Math.max(-_+h,Math.min(_-h,S));T===a?(e.nIn=[1,0],e.g=[-d/2,g(n[1],p/2)]):T===o?(e.nIn=[-1,0],e.g=[d/2,g(n[1],p/2)]):T===r?(e.nIn=[0,1],e.g=[g(n[0],d/2),-p/2]):(e.nIn=[0,-1],e.g=[g(n[0],d/2),p/2]),e.p0=n,e.dT=0,e.angT=0,e.velU=0,e.lastDT=0,e.lastTime=performance.now()}function xe(n){const a=performance.now(),o=Math.max(1,a-e.lastTime);e.velU+=((n-e.lastDT)/o*1e3-e.velU)*.35,e.lastDT=n,e.lastTime=a}function tt(n){const a=[n[0]-e.p0[0],n[1]-e.p0[1]],o=Math.hypot(a[0],a[1]);if(e.restick){const g=P(e.nIn,e.angBase).map(st=>-st),S=Math.max(-.6,Math.min(.6,Math.atan2(g[0]*a[1]-g[1]*a[0],a[0]*g[0]+a[1]*g[1])));e.angT=e.angBase+S*W(6,70,o);const _=P(e.nIn,e.angT);e.dT=Math.max(0,-(a[0]*_[0]+a[1]*_[1])),xe(e.dT);return}const r=a[0]*e.nIn[0]+a[1]*e.nIn[1],u=e.nIn[0]*a[1]-e.nIn[1]*a[0],T=Math.max(-1,Math.min(1,Math.atan2(u,r)));e.angT=T*W(6,70,o);const h=P(e.nIn,e.angT);e.dT=Math.max(0,a[0]*h[0]+a[1]*h[1]),xe(e.dT)}function ie(){const n=P(e.nIn,e.ang);if(b){e.dEnd=O(e.g,n);const a=Je(e.g,n)/2;e.shiftVec=[n[0]*a,n[1]*a]}else e.dEnd=$(re(e.g,n)+2.2*18+20,18,Math.PI-.12,.12);e.mode="complete"}function nt(){if(e.mode!=="drag")return;E.value=!1;const n=P(e.nIn,e.ang);if(e.restick){const o=e.d/O(e.g,n);o<.6||e.velU>700&&o<.9?e.mode="settle":ie();return}const a=e.d/re(e.g,n);a>.32||e.velU>700&&a>.1?ie():e.mode="settle"}function be(){if(b&&e.peeled&&(e.mode==="rest"||e.mode==="drag")){e.restick=!1,e.mode="settle";return}e.mode!=="idle"&&e.mode!=="hint"&&e.mode!=="settle"||b&&e.peeled||(e.interacted=!0,e.nIn=[1,0],e.g=[-d/2,0],e.ang=0,ie())}de.peel=be;function Me(){!i.hint||e.mode!=="idle"||e.interacted||Ke||(e.nIn=[1,0],e.g=[-d/2,0],e.ang=0,e.mode="hint",e.t=0)}const Se=n=>{if(e.mode==="complete"||e.mode==="fade")return;const a=Re(n);if(b&&e.peeled){m.setPointerCapture(n.pointerId),E.value=!0,e.restick=!0,e.angBase=e.ang,e.p0=a,e.dT=0,e.velU=0,e.lastDT=0,e.lastTime=performance.now(),e.mode="drag";return}Math.abs(a[0])>d/2+30||Math.abs(a[1])>p/2+30||(m.setPointerCapture(n.pointerId),E.value=!0,e.interacted||s("grab"),e.interacted=!0,e.restick=!1,et(a),e.mode="drag")},_e=n=>{e.mode==="drag"&&tt(Re(n))},z=()=>nt(),Pe=n=>{(n.key==="ArrowRight"||n.key==="Enter"||n.key===" ")&&(n.preventDefault(),be())};m.addEventListener("pointerdown",Se),m.addEventListener("pointermove",_e),m.addEventListener("pointerup",z),m.addEventListener("pointercancel",z),m.addEventListener("keydown",Pe);function at(){const n=R;R=(R+1)%A(),e.d=0,e.ang=0,e.alpha=1,e.mode="idle",q(R+2),ne(!1),s("peel",n),s("change",R)}function ot(n){switch(e.mode){case"drag":if(e.restick){const o=O(e.g,P(e.nIn,e.ang));e.d+=(Math.max(0,o-e.dT)-e.d)*(1-Math.exp(-n*30))}else e.d+=(Math.min(e.dT,1500)-e.d)*(1-Math.exp(-n*30));e.ang+=(e.angT-e.ang)*(1-Math.exp(-n*16));break;case"settle":e.d+=(0-e.d)*(1-Math.exp(-n*9)),e.d<.05&&(e.d=0,e.mode="idle",b&&e.peeled&&(e.peeled=!1,s("toggle",!1)));break;case"hint":{e.t+=n;const o=e.t/1.5;o>=1?(e.d=0,e.mode="idle"):(e.d=70*Math.pow(Math.sin(Math.PI*o),2),e.ang=.22*Math.sin(2*Math.PI*o));break}case"complete":e.d+=Math.max((e.dEnd-e.d)*(1-Math.exp(-n*6)),380*n),e.d>=e.dEnd&&(e.d=e.dEnd,b?(e.mode="rest",e.peeled||(e.peeled=!0,s("toggle",!0))):(e.mode="fade",e.t=0));break;case"rest":e.d=O(e.g,P(e.nIn,e.ang));break;case"fade":e.t+=n,e.alpha=Math.max(0,1-e.t/.28),e.t>=.28&&at();break}const a=b&&(e.peeled&&(e.mode==="rest"||e.mode==="drag"&&e.restick)||e.mode==="complete")?1:0;e.shiftF+=(a-e.shiftF)*(1-Math.exp(-n*6))}function Ae(n,a,o){const r=n.loc;t.uniform2f(r.uG,e.g[0],e.g[1]),t.uniform2f(r.uU,o[0],o[1]),t.uniform2f(r.uHalf,d/2,p/2),t.uniform1f(r.uTf,a.tf),t.uniform1f(r.uR,a.R),t.uniform1f(r.uTheta,a.Th),t.uniform1f(r.uSinPhi,a.sp),t.uniform1f(r.uCosPhi,a.cp),t.uniform2f(r.uView,X,H),t.uniform1f(r.uScale,D*N),t.uniform2f(r.uShift,e.shiftVec[0]*e.shiftF,e.shiftVec[1]*e.shiftF)}function rt(){const n=y.get(R),a=y.get((R+1)%A());if(t.viewport(0,0,X,H),t.clearColor(L[0],L[1],L[2],1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT),!n||!n.tex||!a||!a.tex)return;const o=P(e.nIn,e.ang),r=Le(e.d,b?O(e.g,o):0);t.disable(t.DEPTH_TEST),t.disable(t.BLEND),t.useProgram(F),Ae(F,r,o),t.uniform3f(F.loc.uBg,L[0],L[1],L[2]),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,a.tex),t.uniform1i(F.loc.uBase,0),t.bindBuffer(t.ARRAY_BUFFER,te),t.enableVertexAttribArray(F.aPos),t.vertexAttribPointer(F.aPos,2,t.FLOAT,!1,0,0),t.drawArrays(t.TRIANGLE_STRIP,0,4),t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.useProgram(w),Ae(w,r,o),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,n.tex),t.uniform1i(w.loc.uFront,0),t.uniform3f(w.loc.uBack,n.back[0],n.back[1],n.back[2]),t.uniform1f(w.loc.uAlpha,e.alpha),t.bindBuffer(t.ARRAY_BUFFER,J),t.enableVertexAttribArray(w.aPos),t.vertexAttribPointer(w.aPos,2,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,ee),t.drawElements(t.TRIANGLES,I.length,t.UNSIGNED_SHORT,0)}let se=performance.now();function we(n){if(!G)return;const a=Math.min(.05,(n-se)/1e3);se=n,ot(a),rt(),K=requestAnimationFrame(we)}const Ie=new ResizeObserver(ve);Ie.observe(l.value);const Y=matchMedia("(prefers-color-scheme: dark)");Y.addEventListener&&Y.addEventListener("change",V);const ye=new MutationObserver(V);ye.observe(document.documentElement,{attributes:!0}),ve(),V(),C=Math.min(3,Math.max(2,D*N));const it=f.watch(()=>i.cards,()=>{ne(!0),R=0,e.d=0,e.mode="idle",e.alpha=1,e.peeled=!1,e.shiftF=0,Te()});Te().then(()=>{G&&(K=requestAnimationFrame(n=>{se=n,we(n)}),ue.push(setTimeout(Me,900),setTimeout(Me,8e3)))}),fe=()=>{G=!1,cancelAnimationFrame(K),ue.forEach(clearTimeout),it(),Ie.disconnect(),ye.disconnect(),Y.removeEventListener&&Y.removeEventListener("change",V),m.removeEventListener("pointerdown",Se),m.removeEventListener("pointermove",_e),m.removeEventListener("pointerup",z),m.removeEventListener("pointercancel",z),m.removeEventListener("keydown",Pe),ne(!0),t.deleteBuffer(J),t.deleteBuffer(ee),t.deleteBuffer(te),t.deleteProgram(w),t.deleteProgram(F);const n=t.getExtension("WEBGL_lose_context");n&&n.loseContext()},typeof window<"u"&&window.__PEEL_DEBUG__&&(window.__peelDebug=e)}return f.onMounted(We),f.onBeforeUnmount(()=>fe()),c({peel:()=>de.peel()}),{root:l,canvas:v,noGL:U,focused:x,rootStyle:Ve,noGLStyle:ze,canvasStyle:Ye,onFocus:$e}}},qe=["aria-label"];function Xe(i,s,c,l,v,E){return f.openBlock(),f.createElementBlock("div",{ref:"root",style:f.normalizeStyle(l.rootStyle)},[f.createElementVNode("canvas",{ref:"canvas",tabindex:"0",role:"img","aria-label":c.label,style:f.normalizeStyle(l.canvasStyle),onFocus:s[0]||(s[0]=(...x)=>l.onFocus&&l.onFocus(...x)),onBlur:s[1]||(s[1]=x=>l.focused=!1)},null,44,qe),l.noGL?(f.openBlock(),f.createElementBlock("div",{key:0,style:f.normalizeStyle(l.noGLStyle)},[f.renderSlot(i.$slots,"fallback",{},()=>[s[2]||(s[2]=f.createTextVNode("WebGL is not available in this browser.",-1))])],4)):f.createCommentVNode("",!0)],4)}const j=Fe(Ge,[["render",Xe]]),He={install(i){i.component("PeelCard",j)}};M.PeelCard=j,M.PeelCardPlugin=He,M.default=j,Object.defineProperties(M,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
80
|
+
}`,Oe={name:"PeelCard",props:{cards:{type:Array,required:!0},toggle:{type:Boolean,default:!1},width:{type:Number,default:420},height:{type:Number,default:280},radius:{type:Number,default:18},background:{type:String,default:""},padding:{type:Number,default:16},maxScale:{type:Number,default:1.35},hint:{type:Boolean,default:!0},label:{type:String,default:"Card: drag the edge to peel it off"}},emits:["grab","peel","change","toggle"],setup(r,{emit:s,expose:l}){const f=c.ref(null),x=c.ref(null),M=c.ref(!1),E=c.ref(!1),B=c.ref(!1),He={position:"relative",width:"100%",height:"100%",minHeight:"200px"},Ve={position:"absolute",inset:"0",display:"grid",placeItems:"center",padding:"24px",textAlign:"center",opacity:".7"},$e=c.computed(()=>({position:"absolute",inset:"0",width:"100%",height:"100%",display:"block",touchAction:"none",userSelect:"none",WebkitUserSelect:"none",cursor:M.value?"grabbing":"grab",outline:E.value?"2px solid currentColor":"none",outlineOffset:"-4px"})),Ye=m=>{try{E.value=m.target.matches(":focus-visible")}catch{E.value=!1}};let de=()=>{};const fe={peel(){}};function We(){const m=x.value,u=r.width,p=r.height,j=r.radius,A=r.toggle,t=m.getContext("webgl2",{antialias:!0,alpha:!1})||m.getContext("webgl",{antialias:!0,alpha:!1});if(!t){B.value=!0;return}const je=typeof WebGL2RenderingContext<"u"&&t instanceof WebGL2RenderingContext,_=()=>A?2:r.cards.length;let X=!0;const ue=[];let K=0;const he=(n,a)=>{const o=(h,g)=>{const T=t.createShader(h);return t.shaderSource(T,g),t.compileShader(T),t.getShaderParameter(T,t.COMPILE_STATUS)||console.error(t.getShaderInfoLog(T)),T},i=t.createProgram();t.attachShader(i,o(t.VERTEX_SHADER,n)),t.attachShader(i,o(t.FRAGMENT_SHADER,a)),t.linkProgram(i),t.getProgramParameter(i,t.LINK_STATUS)||console.error(t.getProgramInfoLog(i)),i.loc={};const d=t.getProgramParameter(i,t.ACTIVE_UNIFORMS);for(let h=0;h<d;h++){const g=t.getActiveUniform(i,h).name;i.loc[g]=t.getUniformLocation(i,g)}return i.aPos=t.getAttribLocation(i,"aPos"),i},P=he(Ce,Ne(j)),S=he(De,Ge(j)),me=Math.max(2.5,Math.sqrt((u+4)*(p+4)/6e4)),L=Math.round((u+4)/me),k=Math.round((p+4)/me),ge=u/2+2,pe=p/2+2,Z=new Float32Array((L+1)*(k+1)*2);for(let n=0,a=0;n<=k;n++)for(let o=0;o<=L;o++)Z[a++]=-ge+2*ge*o/L,Z[a++]=-pe+2*pe*n/k;const w=new Uint16Array(L*k*6);for(let n=0,a=0;n<k;n++)for(let o=0;o<L;o++){const i=n*(L+1)+o,d=i+1,h=i+L+1,g=h+1;w[a++]=i,w[a++]=d,w[a++]=h,w[a++]=d,w[a++]=g,w[a++]=h}const Q=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,Q),t.bufferData(t.ARRAY_BUFFER,Z,t.STATIC_DRAW);const J=t.createBuffer();t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,J),t.bufferData(t.ELEMENT_ARRAY_BUFFER,w,t.STATIC_DRAW);const ee=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,ee),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW);let C=2,v=0;const y=new Map;async function Ke(n){const a=Math.round(u*C),o=Math.round(p*C),i=document.createElement("canvas");i.width=a,i.height=o;const d=i.getContext("2d");let h=!1;try{const g=new Image,T=new Promise((I,U)=>{g.onload=I,g.onerror=U});g.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(ke(n,u,p)),await T,d.drawImage(g,0,0,a,o),d.getImageData(0,0,1,1),h=!0}catch(g){console.warn("[PeelCard] foreignObject unavailable, drawing fallback",g)}if(!h){d.setTransform(1,0,0,1,0,0),d.fillStyle=n.bg||"#ffffff",d.fillRect(0,0,a,o);const T=(new DOMParser().parseFromString(n.html||"","text/html").body.textContent||"").split(/\n+/).map(I=>I.trim()).filter(Boolean).slice(0,6);d.scale(C,C),d.fillStyle="#222",d.font="600 22px system-ui,sans-serif",T.forEach((I,U)=>d.fillText(I,28,50+U*34))}return i}function q(n){if(!_()||!r.cards.length)return Promise.resolve();if(n=(n%_()+_())%_(),y.has(n))return y.get(n).promise;const a=r.cards[n%r.cards.length],o={tex:null,back:Ue(a.back||"#f2efe6")};return o.promise=Ke(a).then(i=>{if(!X||y.get(n)!==o)return;const d=t.createTexture();t.bindTexture(t.TEXTURE_2D,d),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,!0),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),je?(t.generateMipmap(t.TEXTURE_2D),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR_MIPMAP_LINEAR)):t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),o.tex=d}),y.set(n,o),o.promise}function te(n){const a=n?new Set:new Set([v,(v+1)%_(),(v+2)%_()]);for(const[o,i]of y)a.has(o)||(i.tex&&t.deleteTexture(i.tex),y.delete(o))}const Te=()=>Promise.all([q(0),q(1),q(2)]);let N=1,D=1,ne=1,ae=1,z=1,H=1;function ve(){const n=f.value.getBoundingClientRect();ne=Math.max(1,n.width),ae=Math.max(1,n.height),N=Math.min(window.devicePixelRatio||1,2),z=Math.round(ne*N),H=Math.round(ae*N),m.width=z,m.height=H,D=Math.max(.3,Math.min(r.maxScale,(ne-2*r.padding)/u,(ae-2*r.padding)/p))}let F=[.9,.89,.85];function V(){let n=r.background;if(!n)for(let o=f.value;o;o=o.parentElement){const i=getComputedStyle(o).backgroundColor;if(i&&!/rgba?\(.*,\s*0\)$/.test(i)&&i!=="transparent"){n=i;break}}const a=(n||"").match(/[\d.]+/g);a&&a.length>=3&&(F=[a[0]/255,a[1]/255,a[2]/255])}const e={mode:"idle",d:0,ang:0,g:[-u/2,0],nIn:[1,0],p0:[0,0],dT:0,angT:0,angBase:0,alpha:1,t:0,dEnd:0,velU:0,lastDT:0,lastTime:0,interacted:!1,peeled:!1,restick:!1,pending:!1,prog:!1},Ze=matchMedia("(prefers-reduced-motion: reduce)").matches,Qe=[[-u/2,-p/2],[u/2,-p/2],[-u/2,p/2],[u/2,p/2]],Je=(n,a)=>Qe.map(o=>(o[0]-n[0])*a[0]+(o[1]-n[1])*a[1]),Ee=(n,a)=>Math.max(...Je(n,a)),G=(n,a)=>se(Ee(n,a)+2.2*18+20,18,Math.PI-.12,.12),Re=n=>{const a=m.getBoundingClientRect();return[(n.clientX-a.left-a.width/2)/D,-(n.clientY-a.top-a.height/2)/D]};function xe(n,a){const o=j*.8,i=(d,h)=>Math.max(-h+o,Math.min(h-o,d));e.nIn=n,e.g=n[0]?[-n[0]*u/2,i(a[1],p/2)]:[i(a[0],u/2),-n[1]*p/2]}function et(n){const a=n[0]+u/2,o=u/2-n[0],i=n[1]+p/2,d=p/2-n[1],h=Math.min(a,o,i,d);xe(h===a?[1,0]:h===o?[-1,0]:h===i?[0,1]:[0,-1],n),e.p0=n,e.dT=0,e.angT=0,e.velU=0,e.lastDT=0,e.lastTime=performance.now()}function tt(n){const a=n[0]-e.p0[0],o=n[1]-e.p0[1];return Math.hypot(a,o)<10?!1:(xe(Math.abs(a)>=Math.abs(o)?[-Math.sign(a),0]:[0,-Math.sign(o)],e.p0),e.pending=!1,e.ang=0,e.angBase=0,e.angT=0,e.dEnd=G(e.g,e.nIn),e.d=e.dEnd,e.dT=0,e.velU=0,e.lastDT=0,e.lastTime=performance.now(),!0)}function Me(n){const a=performance.now(),o=Math.max(1,a-e.lastTime);e.velU+=((n-e.lastDT)/o*1e3-e.velU)*.35,e.lastDT=n,e.lastTime=a}function nt(n){const a=[n[0]-e.p0[0],n[1]-e.p0[1]],o=Math.hypot(a[0],a[1]);if(e.restick){const T=b(e.nIn,e.angBase).map(ct=>-ct),I=Math.max(-.6,Math.min(.6,Math.atan2(T[0]*a[1]-T[1]*a[0],a[0]*T[0]+a[1]*T[1])));e.angT=e.angBase+I*O(6,70,o);const U=b(e.nIn,e.angT);e.dT=Math.max(0,-(a[0]*U[0]+a[1]*U[1])),Me(e.dT);return}const i=a[0]*e.nIn[0]+a[1]*e.nIn[1],d=e.nIn[0]*a[1]-e.nIn[1]*a[0],h=Math.max(-1,Math.min(1,Math.atan2(d,i)));e.angT=h*O(6,70,o);const g=b(e.nIn,e.angT);e.dT=Math.max(0,a[0]*g[0]+a[1]*g[1]),Me(e.dT)}function oe(){const n=b(e.nIn,e.prog?e.angT:e.ang);e.dEnd=G(e.g,n),e.alpha=1,e.mode="complete"}function at(){if(e.mode!=="drag")return;if(M.value=!1,e.pending){e.pending=!1,e.restick=!1,e.mode="rest",re();return}const n=b(e.nIn,e.ang);if(e.restick){const o=e.d/G(e.g,n);o<.6||e.velU>700&&o<.9?e.mode="settle":oe();return}const a=e.d/Ee(e.g,n);a>.32||e.velU>700&&a>.1?oe():e.mode="settle"}function re(n){const a=Math.max(-1,Math.min(1,(typeof n=="number"?n:12)*Math.PI/180));if(A&&e.peeled&&e.mode==="rest"){e.nIn=[1,0],e.g=[-u/2,0],e.ang=e.angT=a,e.prog=!0,e.dEnd=G(e.g,b(e.nIn,a)),e.d=e.dEnd,e.t=0,e.mode="unfade";return}if(A&&e.peeled&&e.mode==="drag"){e.restick=!1,e.mode="settle";return}e.mode!=="idle"&&e.mode!=="hint"&&e.mode!=="settle"||A&&e.peeled||(e.interacted=!0,e.nIn=[1,0],e.g=[-u/2,0],e.ang=0,e.angT=a,e.prog=!0,oe())}fe.peel=re;function be(){!r.hint||e.mode!=="idle"||e.interacted||Ze||(e.nIn=[1,0],e.g=[-u/2,0],e.ang=0,e.mode="hint",e.t=0)}const Ae=n=>{if(e.mode==="complete"||e.mode==="fade"||e.mode==="unfade"||e.mode==="unpeel")return;const a=Re(n);if(e.prog=!1,A&&e.peeled){if(e.mode!=="rest")return;m.setPointerCapture(n.pointerId),M.value=!0,e.restick=!0,e.pending=!0,e.p0=a,e.mode="drag";return}Math.abs(a[0])>u/2+30||Math.abs(a[1])>p/2+30||(m.setPointerCapture(n.pointerId),M.value=!0,e.interacted||s("grab"),e.interacted=!0,e.restick=!1,et(a),e.mode="drag")},_e=n=>{if(e.mode!=="drag")return;const a=Re(n);e.pending&&!tt(a)||nt(a)},$=()=>at(),Pe=n=>{(n.key==="ArrowRight"||n.key==="Enter"||n.key===" ")&&(n.preventDefault(),re())};m.addEventListener("pointerdown",Ae),m.addEventListener("pointermove",_e),m.addEventListener("pointerup",$),m.addEventListener("pointercancel",$),m.addEventListener("keydown",Pe);function ot(){const n=v;v=(v+1)%_(),e.d=0,e.ang=0,e.alpha=1,e.mode="idle",q(v+2),te(!1),s("peel",n),s("change",v)}function rt(n){switch(e.mode){case"drag":if(e.pending)break;if(e.restick){const a=G(e.g,b(e.nIn,e.ang));e.d+=(Math.max(0,a-e.dT)-e.d)*(1-Math.exp(-n*30))}else e.d+=(Math.min(e.dT,1500)-e.d)*(1-Math.exp(-n*30));e.ang+=(e.angT-e.ang)*(1-Math.exp(-n*16));break;case"settle":e.d+=(0-e.d)*(1-Math.exp(-n*9)),e.ang+=(0-e.ang)*(1-Math.exp(-n*14)),e.d<.05&&Math.abs(e.ang)<.002&&(e.d=0,e.ang=0,e.mode="idle",A&&e.peeled&&(e.peeled=!1,s("toggle",!1)));break;case"hint":{e.t+=n;const a=e.t/1.5;a>=1?(e.d=0,e.ang=0,e.mode="idle"):(e.d=70*Math.pow(Math.sin(Math.PI*a),2),e.ang=.22*Math.sin(2*Math.PI*a));break}case"complete":e.d+=Math.max((e.dEnd-e.d)*(1-Math.exp(-n*6)),380*n),e.prog&&(e.ang=e.angT*O(6,70,e.d)),e.d>=e.dEnd&&(e.d=e.dEnd,e.mode="fade",e.t=0);break;case"rest":break;case"fade":e.t+=n,e.alpha=Math.max(0,1-e.t/.28),e.t>=.28&&(A?(e.mode="rest",e.peeled||(e.peeled=!0,s("toggle",!0))):ot());break;case"unfade":e.t+=n,e.alpha=Math.min(1,e.alpha+n/.28),e.alpha>=1&&(e.mode="unpeel");break;case"unpeel":e.d-=Math.max((e.dEnd-e.d)*(1-Math.exp(-n*6)),380*n),e.ang=e.angT*O(6,70,e.d),e.d<=0&&(e.d=0,e.ang=0,e.prog=!1,e.mode="idle",e.peeled=!1,s("toggle",!1));break}A&&!e.pending&&(e.mode==="drag"||e.mode==="settle")&&(e.alpha+=(1-e.alpha)*(1-Math.exp(-n*12)))}function Se(n,a,o){const i=n.loc;t.uniform2f(i.uG,e.g[0],e.g[1]),t.uniform2f(i.uU,o[0],o[1]),t.uniform2f(i.uHalf,u/2,p/2),t.uniform1f(i.uTf,a.tf),t.uniform1f(i.uR,a.R),t.uniform1f(i.uTheta,a.Th),t.uniform1f(i.uSinPhi,a.sp),t.uniform1f(i.uCosPhi,a.cp),t.uniform2f(i.uView,z,H),t.uniform1f(i.uScale,D*N)}function it(){const n=y.get(v),a=y.get((v+1)%_());if(t.viewport(0,0,z,H),t.clearColor(F[0],F[1],F[2],1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT),!n||!n.tex||!a||!a.tex)return;const o=b(e.nIn,e.ang),i=Be(e.d);t.disable(t.DEPTH_TEST),t.disable(t.BLEND),t.useProgram(S),Se(S,i,o),t.uniform3f(S.loc.uBg,F[0],F[1],F[2]),t.uniform1f(S.loc.uAlpha,e.alpha),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,a.tex),t.uniform1i(S.loc.uBase,0),t.bindBuffer(t.ARRAY_BUFFER,ee),t.enableVertexAttribArray(S.aPos),t.vertexAttribPointer(S.aPos,2,t.FLOAT,!1,0,0),t.drawArrays(t.TRIANGLE_STRIP,0,4),t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.useProgram(P),Se(P,i,o),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,n.tex),t.uniform1i(P.loc.uFront,0),t.uniform3f(P.loc.uBack,n.back[0],n.back[1],n.back[2]),t.uniform1f(P.loc.uAlpha,e.alpha),t.bindBuffer(t.ARRAY_BUFFER,Q),t.enableVertexAttribArray(P.aPos),t.vertexAttribPointer(P.aPos,2,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,J),t.drawElements(t.TRIANGLES,w.length,t.UNSIGNED_SHORT,0)}let ie=performance.now();function we(n){if(!X)return;const a=Math.min(.05,(n-ie)/1e3);ie=n,rt(a),it(),K=requestAnimationFrame(we)}const ye=new ResizeObserver(ve);ye.observe(f.value);const Y=matchMedia("(prefers-color-scheme: dark)");Y.addEventListener&&Y.addEventListener("change",V);const Le=new MutationObserver(V);Le.observe(document.documentElement,{attributes:!0}),ve(),V(),C=Math.min(3,Math.max(2,D*N));const st=()=>r.cards.map(n=>`${n.bg}\0${n.back}\0${n.html}`).join(""),lt=c.watch(st,()=>{te(!0),v=0,e.d=0,e.mode="idle",e.alpha=1,e.peeled=!1,Te()});Te().then(()=>{X&&(K=requestAnimationFrame(n=>{ie=n,we(n)}),ue.push(setTimeout(be,900),setTimeout(be,8e3)))}),de=()=>{X=!1,cancelAnimationFrame(K),ue.forEach(clearTimeout),lt(),ye.disconnect(),Le.disconnect(),Y.removeEventListener&&Y.removeEventListener("change",V),m.removeEventListener("pointerdown",Ae),m.removeEventListener("pointermove",_e),m.removeEventListener("pointerup",$),m.removeEventListener("pointercancel",$),m.removeEventListener("keydown",Pe),te(!0),t.deleteBuffer(Q),t.deleteBuffer(J),t.deleteBuffer(ee),t.deleteProgram(P),t.deleteProgram(S);const n=t.getExtension("WEBGL_lose_context");n&&n.loseContext()},typeof window<"u"&&window.__PEEL_DEBUG__&&(window.__peelDebug=e)}return c.onMounted(We),c.onBeforeUnmount(()=>de()),l({peel:()=>fe.peel()}),{root:f,canvas:x,noGL:B,focused:E,rootStyle:He,noGLStyle:Ve,canvasStyle:$e,onFocus:Ye}}},Xe=["aria-label"];function qe(r,s,l,f,x,M){return c.openBlock(),c.createElementBlock("div",{ref:"root",style:c.normalizeStyle(f.rootStyle)},[c.createElementVNode("canvas",{ref:"canvas",tabindex:"0",role:"img","aria-label":l.label,style:c.normalizeStyle(f.canvasStyle),onFocus:s[0]||(s[0]=(...E)=>f.onFocus&&f.onFocus(...E)),onBlur:s[1]||(s[1]=E=>f.focused=!1)},null,44,Xe),f.noGL?(c.openBlock(),c.createElementBlock("div",{key:0,style:c.normalizeStyle(f.noGLStyle)},[c.renderSlot(r.$slots,"fallback",{},()=>[s[2]||(s[2]=c.createTextVNode("WebGL is not available in this browser.",-1))])],4)):c.createCommentVNode("",!0)],4)}const W=Fe(Oe,[["render",qe]]),ze={install(r){r.component("PeelCard",W)}};R.PeelCard=W,R.PeelCardPlugin=ze,R.default=W,Object.defineProperties(R,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-peel-card",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Vue 3 component: a WebGL card you can peel off by its edge. HTML card content, realistic curl that follows your finger, toggle mode.",
|
|
5
5
|
"keywords": ["vue", "vue3", "webgl", "card", "peel", "page-curl", "flashcards", "animation"],
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"files": ["dist", "src", "types"],
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"scripts": {
|
|
22
|
+
"dev": "vite --open",
|
|
22
23
|
"build": "vite build",
|
|
23
24
|
"prepublishOnly": "npm run build"
|
|
24
25
|
},
|
package/src/PeelCard.vue
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
change(i) (normal mode) card i became the top card
|
|
27
27
|
toggle(b) (toggle mode) b = true — peeled, false — stuck back
|
|
28
28
|
Methods (via ref)
|
|
29
|
-
peel()
|
|
29
|
+
peel(angle) peel off; in toggle mode switches the state. angle: tilt in degrees, positive = upward (default 12, 0 = straight)
|
|
30
30
|
-->
|
|
31
31
|
<template>
|
|
32
32
|
<div ref="root" :style="rootStyle">
|
|
@@ -50,7 +50,7 @@ import { ref, computed, onMounted, onBeforeUnmount, watch } from 'vue'
|
|
|
50
50
|
Everything behind the fold line (t < Tf, where t is the coordinate along the pull direction U from the grab point G)
|
|
51
51
|
wraps around a cylinder of radius R through angle Theta, then continues as a straight segment at angle Phi to the plane. */
|
|
52
52
|
const RMIN = 18, RBIG = 75, MAXANG = 1.0
|
|
53
|
-
const
|
|
53
|
+
const PEEL_ANGLE = 12 // default tilt of peel(), degrees
|
|
54
54
|
|
|
55
55
|
// How far the grab point moves when the fold is at distance s from it.
|
|
56
56
|
function Gfun(s, R, Th, phi) {
|
|
@@ -62,11 +62,9 @@ function solveS(d, R, Th, phi) {
|
|
|
62
62
|
for (let i = 0; i < 48; i++) { const m = (lo + hi) / 2; if (Gfun(m, R, Th, phi) < d) lo = m; else hi = m }
|
|
63
63
|
return (lo + hi) / 2
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
function geom(d, dRest) {
|
|
65
|
+
function geom(d) {
|
|
67
66
|
const R = RMIN + (RBIG - RMIN) * Math.exp(-d / 70) // the curl starts gentle, then tightens
|
|
68
|
-
|
|
69
|
-
if (dRest > 0) { const b = smooth(0.45, 1, d / dRest); phi = phi * (1 - b) + PHI_REST * b }
|
|
67
|
+
const phi = 0.12 + 0.55 * Math.exp(-d / 140) // edge lift angle
|
|
70
68
|
const Th = Math.PI - phi
|
|
71
69
|
return { R, phi, Th, tf: solveS(d, R, Th, phi), sp: Math.sin(phi), cp: Math.cos(phi) }
|
|
72
70
|
}
|
|
@@ -86,7 +84,7 @@ uniform float uTf, uR, uTheta, uSinPhi, uCosPhi;
|
|
|
86
84
|
const VS = `
|
|
87
85
|
attribute vec2 aPos;
|
|
88
86
|
${FLAP_UNIFORMS}
|
|
89
|
-
uniform vec2 uView
|
|
87
|
+
uniform vec2 uView; uniform float uScale;
|
|
90
88
|
varying vec2 vOrig, vXY; varying float vZ, vTh, vS;
|
|
91
89
|
void main(){
|
|
92
90
|
float t = dot(aPos-uG, uU);
|
|
@@ -100,16 +98,16 @@ void main(){
|
|
|
100
98
|
vec2 pos = aPos + uU*(tp-t);
|
|
101
99
|
vOrig = aPos; vXY = pos; vZ = z; vTh = th; vS = s;
|
|
102
100
|
float k = 1.0/(1.0 - min(z,1500.0)/3200.0);
|
|
103
|
-
vec2 xy =
|
|
101
|
+
vec2 xy = pos*uScale*k;
|
|
104
102
|
gl_Position = vec4(xy*2.0/uView, -0.1 - min(z,600.0)*0.0015, 1.0);
|
|
105
103
|
}`
|
|
106
104
|
|
|
107
|
-
const common =
|
|
105
|
+
const common = RAD => `
|
|
108
106
|
precision highp float;
|
|
109
107
|
${FLAP_UNIFORMS}
|
|
110
108
|
float sdRR(vec2 p, vec2 b, float r){ vec2 q = abs(p)-b+r; return length(max(q,0.0)) + min(max(q.x,q.y),0.0) - r; }
|
|
111
109
|
float hash(vec2 p){ return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453); }
|
|
112
|
-
float rectMask(vec2 p, float soft){
|
|
110
|
+
float rectMask(vec2 p, float soft){ return smoothstep(-soft*0.5, soft, -sdRR(p, uHalf, ${RAD.toFixed(1)})); }
|
|
113
111
|
// Shadow of the folded part: which point of the original card hangs above point q.
|
|
114
112
|
float flapShadow(vec2 q){
|
|
115
113
|
float tq = dot(q-uG, uU);
|
|
@@ -122,7 +120,7 @@ float flapShadow(vec2 q){
|
|
|
122
120
|
return rectMask(po, 3.0 + 0.3*z) * decay * exp(-z/110.0);
|
|
123
121
|
}`
|
|
124
122
|
|
|
125
|
-
const fsCard = RAD => `${common()}
|
|
123
|
+
const fsCard = RAD => `${common(RAD)}
|
|
126
124
|
uniform sampler2D uFront; uniform vec3 uBack; uniform float uScale, uAlpha;
|
|
127
125
|
varying vec2 vOrig, vXY; varying float vZ, vTh, vS;
|
|
128
126
|
void main(){
|
|
@@ -149,10 +147,10 @@ void main(){
|
|
|
149
147
|
}`
|
|
150
148
|
|
|
151
149
|
const VS_FLOOR = `attribute vec2 aPos; void main(){ gl_Position = vec4(aPos,0.0,1.0); }`
|
|
152
|
-
const fsFloor = RAD => `${common()}
|
|
153
|
-
uniform sampler2D uBase; uniform vec2 uView
|
|
150
|
+
const fsFloor = RAD => `${common(RAD)}
|
|
151
|
+
uniform sampler2D uBase; uniform vec2 uView; uniform float uScale, uAlpha; uniform vec3 uBg;
|
|
154
152
|
void main(){
|
|
155
|
-
vec2 q = (gl_FragCoord.xy - 0.5*uView)/uScale
|
|
153
|
+
vec2 q = (gl_FragCoord.xy - 0.5*uView)/uScale;
|
|
156
154
|
vec2 sc = gl_FragCoord.xy/uView - 0.5;
|
|
157
155
|
vec3 col = uBg*(1.0 - 0.22*dot(sc,sc)*2.0) + (hash(gl_FragCoord.xy)-0.5)*0.012;
|
|
158
156
|
float dsh = sdRR(q - vec2(0.0,-14.0), uHalf, ${RAD.toFixed(1)});
|
|
@@ -163,7 +161,7 @@ void main(){
|
|
|
163
161
|
float a = clamp(0.5 - sd*uScale, 0.0, 1.0);
|
|
164
162
|
vec3 tex = texture2D(uBase, q/(2.0*uHalf)+0.5).rgb*0.97;
|
|
165
163
|
col = mix(col, tex, a);
|
|
166
|
-
col *= 1.0 - 0.55*flapShadow(q);
|
|
164
|
+
col *= 1.0 - 0.55*flapShadow(q)*uAlpha;
|
|
167
165
|
gl_FragColor = vec4(col,1.0);
|
|
168
166
|
}`
|
|
169
167
|
|
|
@@ -308,8 +306,7 @@ export default {
|
|
|
308
306
|
dpr = Math.min(window.devicePixelRatio || 1, 2)
|
|
309
307
|
cw = Math.round(cssW * dpr); ch = Math.round(cssH * dpr)
|
|
310
308
|
cv.width = cw; cv.height = ch
|
|
311
|
-
|
|
312
|
-
S = Math.max(0.3, Math.min(props.maxScale, (cssW - 2 * props.padding) / (W * fit), (cssH - 2 * props.padding) / (H * fit)))
|
|
309
|
+
S = Math.max(0.3, Math.min(props.maxScale, (cssW - 2 * props.padding) / W, (cssH - 2 * props.padding) / H))
|
|
313
310
|
}
|
|
314
311
|
let bg = [0.9, 0.89, 0.85]
|
|
315
312
|
function readBg() {
|
|
@@ -329,27 +326,38 @@ export default {
|
|
|
329
326
|
mode: 'idle', // idle | drag | settle | hint | complete | fade | rest
|
|
330
327
|
d: 0, ang: 0, g: [-W / 2, 0], nIn: [1, 0], p0: [0, 0], dT: 0, angT: 0, angBase: 0,
|
|
331
328
|
alpha: 1, t: 0, dEnd: 0, velU: 0, lastDT: 0, lastTime: 0, interacted: false,
|
|
332
|
-
peeled: false, restick: false,
|
|
329
|
+
peeled: false, restick: false, pending: false, prog: false,
|
|
333
330
|
}
|
|
334
331
|
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
335
332
|
const CORNERS = [[-W / 2, -H / 2], [W / 2, -H / 2], [-W / 2, H / 2], [W / 2, H / 2]]
|
|
336
333
|
const proj = (g, u) => CORNERS.map(c => (c[0] - g[0]) * u[0] + (c[1] - g[1]) * u[1])
|
|
337
334
|
const tmaxOf = (g, u) => Math.max(...proj(g, u))
|
|
338
|
-
//
|
|
339
|
-
const
|
|
340
|
-
const overhangFor = (g, u) => { const p = proj(g, u); return Math.cos(PHI_REST) * (Math.max(...p) - Math.min(...p)) + RMIN + 8 }
|
|
335
|
+
// pull distance at which the card is completely peeled away
|
|
336
|
+
const dFullFor = (g, u) => Gfun(tmaxOf(g, u) + 2.2 * RMIN + 20, RMIN, Math.PI - 0.12, 0.12)
|
|
341
337
|
const toUnits = e => { const r = cv.getBoundingClientRect(); return [(e.clientX - r.left - r.width / 2) / S, -(e.clientY - r.top - r.height / 2) / S] }
|
|
342
338
|
|
|
339
|
+
// grab point on the edge whose inward normal is nIn, as close to p as possible
|
|
340
|
+
function placeAt(nIn, p) {
|
|
341
|
+
const pad = RAD * 0.8, cl = (v, lim) => Math.max(-lim + pad, Math.min(lim - pad, v))
|
|
342
|
+
st.nIn = nIn
|
|
343
|
+
st.g = nIn[0] ? [-nIn[0] * W / 2, cl(p[1], H / 2)] : [cl(p[0], W / 2), -nIn[1] * H / 2]
|
|
344
|
+
}
|
|
343
345
|
function beginDrag(p) { // nearest edge and the grab point on it
|
|
344
346
|
const dl = p[0] + W / 2, dr = W / 2 - p[0], db = p[1] + H / 2, dt = H / 2 - p[1]
|
|
345
|
-
const m = Math.min(dl, dr, db, dt)
|
|
346
|
-
|
|
347
|
-
if (m === dl) { st.nIn = [1, 0]; st.g = [-W / 2, cl(p[1], H / 2)] }
|
|
348
|
-
else if (m === dr) { st.nIn = [-1, 0]; st.g = [W / 2, cl(p[1], H / 2)] }
|
|
349
|
-
else if (m === db) { st.nIn = [0, 1]; st.g = [cl(p[0], W / 2), -H / 2] }
|
|
350
|
-
else { st.nIn = [0, -1]; st.g = [cl(p[0], W / 2), H / 2] }
|
|
347
|
+
const m = Math.min(dl, dr, db, dt)
|
|
348
|
+
placeAt(m === dl ? [1, 0] : m === dr ? [-1, 0] : m === db ? [0, 1] : [0, -1], p)
|
|
351
349
|
st.p0 = p; st.dT = 0; st.angT = 0; st.velU = 0; st.lastDT = 0; st.lastTime = performance.now()
|
|
352
350
|
}
|
|
351
|
+
// A returning card has no remembered side: it comes in from the side the finger pulls away from.
|
|
352
|
+
function resolvePending(p) {
|
|
353
|
+
const vx = p[0] - st.p0[0], vy = p[1] - st.p0[1]
|
|
354
|
+
if (Math.hypot(vx, vy) < 10) return false
|
|
355
|
+
placeAt(Math.abs(vx) >= Math.abs(vy) ? [-Math.sign(vx), 0] : [0, -Math.sign(vy)], st.p0)
|
|
356
|
+
st.pending = false; st.ang = 0; st.angBase = 0; st.angT = 0
|
|
357
|
+
st.dEnd = dFullFor(st.g, st.nIn); st.d = st.dEnd
|
|
358
|
+
st.dT = 0; st.velU = 0; st.lastDT = 0; st.lastTime = performance.now()
|
|
359
|
+
return true
|
|
360
|
+
}
|
|
353
361
|
function trackVel(x) {
|
|
354
362
|
const now = performance.now(), dtm = Math.max(1, now - st.lastTime)
|
|
355
363
|
st.velU += ((x - st.lastDT) / dtm * 1000 - st.velU) * 0.35
|
|
@@ -374,22 +382,18 @@ export default {
|
|
|
374
382
|
trackVel(st.dT)
|
|
375
383
|
}
|
|
376
384
|
function startComplete() {
|
|
377
|
-
const u = dirOf(st.nIn, st.ang)
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
const k = overhangFor(st.g, u) / 2
|
|
381
|
-
st.shiftVec = [u[0] * k, u[1] * k]
|
|
382
|
-
} else {
|
|
383
|
-
st.dEnd = Gfun(tmaxOf(st.g, u) + 2.2 * RMIN + 20, RMIN, Math.PI - 0.12, 0.12)
|
|
384
|
-
}
|
|
385
|
+
const u = dirOf(st.nIn, st.prog ? st.angT : st.ang)
|
|
386
|
+
st.dEnd = dFullFor(st.g, u)
|
|
387
|
+
st.alpha = 1
|
|
385
388
|
st.mode = 'complete'
|
|
386
389
|
}
|
|
387
390
|
function endDrag() {
|
|
388
391
|
if (st.mode !== 'drag') return
|
|
389
392
|
grabbing.value = false
|
|
393
|
+
if (st.pending) { st.pending = false; st.restick = false; st.mode = 'rest'; peel(); return } // a tap brings it back too
|
|
390
394
|
const u = dirOf(st.nIn, st.ang)
|
|
391
395
|
if (st.restick) {
|
|
392
|
-
const f = st.d /
|
|
396
|
+
const f = st.d / dFullFor(st.g, u)
|
|
393
397
|
if (f < 0.6 || (st.velU > 700 && f < 0.9)) st.mode = 'settle' // stick back
|
|
394
398
|
else startComplete() // return to the peeled position
|
|
395
399
|
return
|
|
@@ -397,12 +401,18 @@ export default {
|
|
|
397
401
|
const ratio = st.d / tmaxOf(st.g, u)
|
|
398
402
|
if (ratio > 0.32 || (st.velU > 700 && ratio > 0.1)) startComplete(); else st.mode = 'settle'
|
|
399
403
|
}
|
|
400
|
-
|
|
401
|
-
|
|
404
|
+
// angle: tilt of the peel direction in degrees (positive = upward), 0 = straight
|
|
405
|
+
function peel(angle) {
|
|
406
|
+
const a = Math.max(-MAXANG, Math.min(MAXANG, (typeof angle === 'number' ? angle : PEEL_ANGLE) * Math.PI / 180))
|
|
407
|
+
if (TOG && st.peeled && st.mode === 'rest') { // reverse of the peel: fade in, then curl back down
|
|
408
|
+
st.nIn = [1, 0]; st.g = [-W / 2, 0]; st.ang = st.angT = a; st.prog = true
|
|
409
|
+
st.dEnd = dFullFor(st.g, dirOf(st.nIn, a)); st.d = st.dEnd; st.t = 0; st.mode = 'unfade'; return
|
|
410
|
+
}
|
|
411
|
+
if (TOG && st.peeled && st.mode === 'drag') { st.restick = false; st.mode = 'settle'; return }
|
|
402
412
|
if (st.mode !== 'idle' && st.mode !== 'hint' && st.mode !== 'settle') return
|
|
403
413
|
if (TOG && st.peeled) return
|
|
404
414
|
st.interacted = true
|
|
405
|
-
st.nIn = [1, 0]; st.g = [-W / 2, 0]; st.ang = 0; startComplete()
|
|
415
|
+
st.nIn = [1, 0]; st.g = [-W / 2, 0]; st.ang = 0; st.angT = a; st.prog = true; startComplete()
|
|
406
416
|
}
|
|
407
417
|
api.peel = peel
|
|
408
418
|
function startHint() {
|
|
@@ -411,12 +421,13 @@ export default {
|
|
|
411
421
|
}
|
|
412
422
|
|
|
413
423
|
const onDown = e => {
|
|
414
|
-
if (st.mode === 'complete' || st.mode === 'fade') return
|
|
424
|
+
if (st.mode === 'complete' || st.mode === 'fade' || st.mode === 'unfade' || st.mode === 'unpeel') return
|
|
415
425
|
const p = toUnits(e)
|
|
416
|
-
|
|
426
|
+
st.prog = false
|
|
427
|
+
if (TOG && st.peeled) { // peeled: any touch starts bringing the card back
|
|
428
|
+
if (st.mode !== 'rest') return
|
|
417
429
|
cv.setPointerCapture(e.pointerId); grabbing.value = true
|
|
418
|
-
st.restick = true; st.
|
|
419
|
-
st.mode = 'drag'
|
|
430
|
+
st.restick = true; st.pending = true; st.p0 = p; st.mode = 'drag'
|
|
420
431
|
return
|
|
421
432
|
}
|
|
422
433
|
if (Math.abs(p[0]) > W / 2 + 30 || Math.abs(p[1]) > H / 2 + 30) return
|
|
@@ -427,7 +438,12 @@ export default {
|
|
|
427
438
|
st.restick = false
|
|
428
439
|
beginDrag(p); st.mode = 'drag'
|
|
429
440
|
}
|
|
430
|
-
const onMove = e => {
|
|
441
|
+
const onMove = e => {
|
|
442
|
+
if (st.mode !== 'drag') return
|
|
443
|
+
const p = toUnits(e)
|
|
444
|
+
if (st.pending && !resolvePending(p)) return
|
|
445
|
+
updateTargets(p)
|
|
446
|
+
}
|
|
431
447
|
const onUp = () => endDrag()
|
|
432
448
|
const onKey = e => { if (e.key === 'ArrowRight' || e.key === 'Enter' || e.key === ' ') { e.preventDefault(); peel() } }
|
|
433
449
|
cv.addEventListener('pointerdown', onDown)
|
|
@@ -446,44 +462,53 @@ export default {
|
|
|
446
462
|
function stepState(dt) {
|
|
447
463
|
switch (st.mode) {
|
|
448
464
|
case 'drag':
|
|
465
|
+
if (st.pending) break
|
|
449
466
|
if (st.restick) {
|
|
450
|
-
const dR =
|
|
467
|
+
const dR = dFullFor(st.g, dirOf(st.nIn, st.ang))
|
|
451
468
|
st.d += (Math.max(0, dR - st.dT) - st.d) * (1 - Math.exp(-dt * 30))
|
|
452
469
|
} else st.d += (Math.min(st.dT, 1500) - st.d) * (1 - Math.exp(-dt * 30))
|
|
453
470
|
st.ang += (st.angT - st.ang) * (1 - Math.exp(-dt * 16))
|
|
454
471
|
break
|
|
455
472
|
case 'settle':
|
|
456
473
|
st.d += (0 - st.d) * (1 - Math.exp(-dt * 9))
|
|
457
|
-
|
|
458
|
-
|
|
474
|
+
st.ang += (0 - st.ang) * (1 - Math.exp(-dt * 14)) // a rotated fold line curls a corner even at d = 0
|
|
475
|
+
if (st.d < 0.05 && Math.abs(st.ang) < 0.002) {
|
|
476
|
+
st.d = 0; st.ang = 0; st.mode = 'idle'
|
|
459
477
|
if (TOG && st.peeled) { st.peeled = false; emit('toggle', false) }
|
|
460
478
|
}
|
|
461
479
|
break
|
|
462
480
|
case 'hint': {
|
|
463
481
|
st.t += dt; const k = st.t / 1.5
|
|
464
|
-
if (k >= 1) { st.d = 0; st.mode = 'idle' }
|
|
482
|
+
if (k >= 1) { st.d = 0; st.ang = 0; st.mode = 'idle' }
|
|
465
483
|
else { st.d = 70 * Math.pow(Math.sin(Math.PI * k), 2); st.ang = 0.22 * Math.sin(2 * Math.PI * k) }
|
|
466
484
|
break
|
|
467
485
|
}
|
|
468
486
|
case 'complete':
|
|
469
487
|
st.d += Math.max((st.dEnd - st.d) * (1 - Math.exp(-dt * 6)), 380 * dt)
|
|
470
|
-
if (st.
|
|
471
|
-
|
|
472
|
-
if (TOG) { st.mode = 'rest'; if (!st.peeled) { st.peeled = true; emit('toggle', true) } }
|
|
473
|
-
else { st.mode = 'fade'; st.t = 0 }
|
|
474
|
-
}
|
|
488
|
+
if (st.prog) st.ang = st.angT * smooth(6, 70, st.d) // a tilted fold line curls a corner at small d, so ramp the tilt in
|
|
489
|
+
if (st.d >= st.dEnd) { st.d = st.dEnd; st.mode = 'fade'; st.t = 0 }
|
|
475
490
|
break
|
|
476
491
|
case 'rest':
|
|
477
|
-
st.d = dRestFor(st.g, dirOf(st.nIn, st.ang))
|
|
478
492
|
break
|
|
479
493
|
case 'fade':
|
|
480
494
|
st.t += dt; st.alpha = Math.max(0, 1 - st.t / 0.28)
|
|
481
|
-
if (st.t >= 0.28)
|
|
495
|
+
if (st.t >= 0.28) {
|
|
496
|
+
if (!TOG) swapCards()
|
|
497
|
+
else { st.mode = 'rest'; if (!st.peeled) { st.peeled = true; emit('toggle', true) } }
|
|
498
|
+
}
|
|
499
|
+
break
|
|
500
|
+
case 'unfade':
|
|
501
|
+
st.t += dt; st.alpha = Math.min(1, st.alpha + dt / 0.28)
|
|
502
|
+
if (st.alpha >= 1) st.mode = 'unpeel'
|
|
503
|
+
break
|
|
504
|
+
case 'unpeel':
|
|
505
|
+
st.d -= Math.max((st.dEnd - st.d) * (1 - Math.exp(-dt * 6)), 380 * dt)
|
|
506
|
+
st.ang = st.angT * smooth(6, 70, st.d)
|
|
507
|
+
if (st.d <= 0) { st.d = 0; st.ang = 0; st.prog = false; st.mode = 'idle'; st.peeled = false; emit('toggle', false) }
|
|
482
508
|
break
|
|
483
509
|
}
|
|
484
|
-
//
|
|
485
|
-
|
|
486
|
-
st.shiftF += (want - st.shiftF) * (1 - Math.exp(-dt * 6))
|
|
510
|
+
// dragging a peeled card back: it becomes visible again
|
|
511
|
+
if (TOG && !st.pending && (st.mode === 'drag' || st.mode === 'settle')) st.alpha += (1 - st.alpha) * (1 - Math.exp(-dt * 12))
|
|
487
512
|
}
|
|
488
513
|
|
|
489
514
|
/* — rendering — */
|
|
@@ -493,7 +518,6 @@ export default {
|
|
|
493
518
|
gl.uniform1f(L.uTf, gm.tf); gl.uniform1f(L.uR, gm.R); gl.uniform1f(L.uTheta, gm.Th)
|
|
494
519
|
gl.uniform1f(L.uSinPhi, gm.sp); gl.uniform1f(L.uCosPhi, gm.cp)
|
|
495
520
|
gl.uniform2f(L.uView, cw, ch); gl.uniform1f(L.uScale, S * dpr)
|
|
496
|
-
gl.uniform2f(L.uShift, st.shiftVec[0] * st.shiftF, st.shiftVec[1] * st.shiftF)
|
|
497
521
|
}
|
|
498
522
|
function draw() {
|
|
499
523
|
const A = texCache.get(topIdx), B = texCache.get((topIdx + 1) % N())
|
|
@@ -501,12 +525,12 @@ export default {
|
|
|
501
525
|
gl.clearColor(bg[0], bg[1], bg[2], 1); gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
|
|
502
526
|
if (!A || !A.tex || !B || !B.tex) return
|
|
503
527
|
const u = dirOf(st.nIn, st.ang)
|
|
504
|
-
const gm = geom(st.d
|
|
528
|
+
const gm = geom(st.d)
|
|
505
529
|
|
|
506
530
|
// 1) table + bottom card + shadows
|
|
507
531
|
gl.disable(gl.DEPTH_TEST); gl.disable(gl.BLEND)
|
|
508
532
|
gl.useProgram(pFloor); setCommon(pFloor, gm, u)
|
|
509
|
-
gl.uniform3f(pFloor.loc.uBg, bg[0], bg[1], bg[2])
|
|
533
|
+
gl.uniform3f(pFloor.loc.uBg, bg[0], bg[1], bg[2]); gl.uniform1f(pFloor.loc.uAlpha, st.alpha)
|
|
510
534
|
gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, B.tex); gl.uniform1i(pFloor.loc.uBase, 0)
|
|
511
535
|
gl.bindBuffer(gl.ARRAY_BUFFER, quadVB)
|
|
512
536
|
gl.enableVertexAttribArray(pFloor.aPos); gl.vertexAttribPointer(pFloor.aPos, 2, gl.FLOAT, false, 0, 0)
|
|
@@ -539,8 +563,10 @@ export default {
|
|
|
539
563
|
resize(); readBg()
|
|
540
564
|
texScale = Math.min(3, Math.max(2, S * dpr))
|
|
541
565
|
|
|
542
|
-
|
|
543
|
-
|
|
566
|
+
// Watch content, not array identity: inline `:cards="[a, b]"` is a new array on every parent render.
|
|
567
|
+
const cardsKey = () => props.cards.map(c => `${c.bg}\u0000${c.back}\u0000${c.html}`).join('\u0001')
|
|
568
|
+
const stopWatch = watch(cardsKey, () => { // cards replaced: re-render textures
|
|
569
|
+
freeTextures(true); topIdx = 0; st.d = 0; st.mode = 'idle'; st.alpha = 1; st.peeled = false; warm()
|
|
544
570
|
})
|
|
545
571
|
warm().then(() => {
|
|
546
572
|
if (!alive) return
|
package/types/index.d.ts
CHANGED