vue-peel-card 0.2.0 → 0.2.3
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 +5 -0
- package/dist/vue-peel-card.js +222 -214
- package/dist/vue-peel-card.umd.cjs +14 -14
- package/package.json +5 -1
- package/src/PeelCard.vue +15 -1
- package/types/index.d.ts +1 -0
package/README.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
Vue 3 component: a card you can peel off by its edge. Rendered with WebGL; the card content is plain HTML.
|
|
4
4
|
The curl follows your finger and rotates if you drag up or down. Includes shadows, a highlight on the fold and the back side of the paper.
|
|
5
5
|
|
|
6
|
+
## Demo
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+
|
|
6
10
|
## Installation
|
|
7
11
|
|
|
8
12
|
```bash
|
|
@@ -86,6 +90,7 @@ a fallback is drawn: the `bg` color and plain text.
|
|
|
86
90
|
| `padding` | `number` | `16` | gap between the card and the component edges |
|
|
87
91
|
| `maxScale` | `number` | `1.35` | maximum zoom |
|
|
88
92
|
| `hint` | `boolean` | `true` | edge wiggle on start |
|
|
93
|
+
| `clickPeel` | `boolean` | `false` | a click or tap (without dragging) peels the card from the pressed edge; use `click-peel` in templates |
|
|
89
94
|
| `label` | `string` | — | `aria-label` of the canvas |
|
|
90
95
|
|
|
91
96
|
## Events
|
package/dist/vue-peel-card.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { openBlock as
|
|
2
|
-
const
|
|
3
|
-
const l =
|
|
4
|
-
for (const [d,
|
|
5
|
-
l[d] =
|
|
1
|
+
import { openBlock as ke, createElementBlock as Fe, normalizeStyle as le, createElementVNode as tt, renderSlot as nt, createTextVNode as at, createCommentVNode as ot, ref as O, computed as rt, onMounted as it, onBeforeUnmount as st, watch as lt } from "vue";
|
|
2
|
+
const ct = (o, s) => {
|
|
3
|
+
const l = o.__vccOpts || o;
|
|
4
|
+
for (const [d, x] of s)
|
|
5
|
+
l[d] = x;
|
|
6
6
|
return l;
|
|
7
|
-
},
|
|
8
|
-
function
|
|
9
|
-
return
|
|
7
|
+
}, K = 18, dt = 75, W = 1, Le = 12;
|
|
8
|
+
function Be(o, s, l, d) {
|
|
9
|
+
return o <= l * s ? o - s * Math.sin(o / s) : o - s * Math.sin(d) + (o - l * s) * Math.cos(d);
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
let
|
|
13
|
-
for (let
|
|
14
|
-
const L = (
|
|
15
|
-
|
|
11
|
+
function ft(o, s, l, d) {
|
|
12
|
+
let x = 0, T = 4e3;
|
|
13
|
+
for (let E = 0; E < 48; E++) {
|
|
14
|
+
const L = (x + T) / 2;
|
|
15
|
+
Be(L, s, l, d) < o ? x = L : T = L;
|
|
16
16
|
}
|
|
17
|
-
return (
|
|
17
|
+
return (x + T) / 2;
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
const
|
|
21
|
-
return { R:
|
|
19
|
+
function ut(o) {
|
|
20
|
+
const s = K + (dt - K) * Math.exp(-o / 70), l = 0.12 + 0.55 * Math.exp(-o / 140), d = Math.PI - l;
|
|
21
|
+
return { R: s, phi: l, Th: d, tf: ft(o, s, d, l), sp: Math.sin(l), cp: Math.cos(l) };
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
const l = Math.atan2(
|
|
23
|
+
const S = (o, s) => {
|
|
24
|
+
const l = Math.atan2(o[1], o[0]) + s;
|
|
25
25
|
return [Math.cos(l), Math.sin(l)];
|
|
26
26
|
};
|
|
27
|
-
function
|
|
28
|
-
return l = Math.min(1, Math.max(0, (l -
|
|
27
|
+
function j(o, s, l) {
|
|
28
|
+
return l = Math.min(1, Math.max(0, (l - o) / (s - o))), l * l * (3 - 2 * l);
|
|
29
29
|
}
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
return [(
|
|
33
|
-
},
|
|
34
|
-
<foreignObject width="${
|
|
30
|
+
const ht = (o) => {
|
|
31
|
+
const s = parseInt(String(o).replace("#", "").padEnd(6, "0").slice(0, 6), 16);
|
|
32
|
+
return [(s >> 16) / 255, (s >> 8 & 255) / 255, (s & 255) / 255];
|
|
33
|
+
}, mt = (o, s, l) => `<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${l}">
|
|
34
|
+
<foreignObject width="${s}" height="${l}"><div xmlns="http://www.w3.org/1999/xhtml" style="width:${s}px;height:${l}px;background:${o.bg || "#ffffff"}">${o.html || ""}</div></foreignObject></svg>`, Ie = `
|
|
35
35
|
uniform vec2 uG, uU, uHalf;
|
|
36
36
|
uniform float uTf, uR, uTheta, uSinPhi, uCosPhi;
|
|
37
|
-
`,
|
|
37
|
+
`, gt = `
|
|
38
38
|
attribute vec2 aPos;
|
|
39
|
-
${
|
|
39
|
+
${Ie}
|
|
40
40
|
uniform vec2 uView; uniform float uScale;
|
|
41
41
|
varying vec2 vOrig, vXY; varying float vZ, vTh, vS;
|
|
42
42
|
void main(){
|
|
@@ -53,12 +53,12 @@ void main(){
|
|
|
53
53
|
float k = 1.0/(1.0 - min(z,1500.0)/3200.0);
|
|
54
54
|
vec2 xy = pos*uScale*k;
|
|
55
55
|
gl_Position = vec4(xy*2.0/uView, -0.1 - min(z,600.0)*0.0015, 1.0);
|
|
56
|
-
}`,
|
|
56
|
+
}`, Ue = (o) => `
|
|
57
57
|
precision highp float;
|
|
58
|
-
${
|
|
58
|
+
${Ie}
|
|
59
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; }
|
|
60
60
|
float hash(vec2 p){ return fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453); }
|
|
61
|
-
float rectMask(vec2 p, float soft){ return smoothstep(-soft*0.5, soft, -sdRR(p, uHalf, ${
|
|
61
|
+
float rectMask(vec2 p, float soft){ return smoothstep(-soft*0.5, soft, -sdRR(p, uHalf, ${o.toFixed(1)})); }
|
|
62
62
|
// Shadow of the folded part: which point of the original card hangs above point q.
|
|
63
63
|
float flapShadow(vec2 q){
|
|
64
64
|
float tq = dot(q-uG, uU);
|
|
@@ -69,11 +69,11 @@ float flapShadow(vec2 q){
|
|
|
69
69
|
else{ float e = (tq-tA)/uCosPhi; s = uTheta*uR + e; z = uR*(1.0+uCosPhi) + e*uSinPhi; }
|
|
70
70
|
vec2 po = q + uU*((uTf - s) - tq);
|
|
71
71
|
return rectMask(po, 3.0 + 0.3*z) * decay * exp(-z/110.0);
|
|
72
|
-
}`,
|
|
72
|
+
}`, pt = (o) => `${Ue(o)}
|
|
73
73
|
uniform sampler2D uFront; uniform vec3 uBack; uniform float uScale, uAlpha;
|
|
74
74
|
varying vec2 vOrig, vXY; varying float vZ, vTh, vS;
|
|
75
75
|
void main(){
|
|
76
|
-
float sd = sdRR(vOrig, uHalf, ${
|
|
76
|
+
float sd = sdRR(vOrig, uHalf, ${o.toFixed(1)});
|
|
77
77
|
float a = clamp(0.5 - sd*uScale, 0.0, 1.0);
|
|
78
78
|
if(a <= 0.0) discard;
|
|
79
79
|
float c = cos(vTh);
|
|
@@ -93,23 +93,23 @@ void main(){
|
|
|
93
93
|
col += max(pow(max(dot(N,Hh),0.0),48.0) - pow(Hh.z,48.0), 0.0)*0.2;
|
|
94
94
|
if(front && vTh < 1.5707963) col *= 1.0 - 0.55*flapShadow(vXY)*exp(-vZ/16.0);
|
|
95
95
|
gl_FragColor = vec4(col*a*uAlpha, a*uAlpha);
|
|
96
|
-
}`,
|
|
96
|
+
}`, vt = "attribute vec2 aPos; void main(){ gl_Position = vec4(aPos,0.0,1.0); }", Tt = (o) => `${Ue(o)}
|
|
97
97
|
uniform sampler2D uBase; uniform vec2 uView; uniform float uScale, uAlpha; uniform vec3 uBg;
|
|
98
98
|
void main(){
|
|
99
99
|
vec2 q = (gl_FragCoord.xy - 0.5*uView)/uScale;
|
|
100
100
|
vec2 sc = gl_FragCoord.xy/uView - 0.5;
|
|
101
101
|
vec3 col = uBg*(1.0 - 0.22*dot(sc,sc)*2.0) + (hash(gl_FragCoord.xy)-0.5)*0.012;
|
|
102
|
-
float dsh = sdRR(q - vec2(0.0,-14.0), uHalf, ${
|
|
102
|
+
float dsh = sdRR(q - vec2(0.0,-14.0), uHalf, ${o.toFixed(1)});
|
|
103
103
|
col *= 1.0 - 0.30*(1.0 - smoothstep(-20.0, 34.0, dsh));
|
|
104
|
-
float dc = sdRR(q - vec2(0.0,-2.0), uHalf, ${
|
|
104
|
+
float dc = sdRR(q - vec2(0.0,-2.0), uHalf, ${o.toFixed(1)});
|
|
105
105
|
col *= 1.0 - 0.18*(1.0 - smoothstep(-2.0, 8.0, dc));
|
|
106
|
-
float sd = sdRR(q, uHalf, ${
|
|
106
|
+
float sd = sdRR(q, uHalf, ${o.toFixed(1)});
|
|
107
107
|
float a = clamp(0.5 - sd*uScale, 0.0, 1.0);
|
|
108
108
|
vec3 tex = texture2D(uBase, q/(2.0*uHalf)+0.5).rgb*0.97;
|
|
109
109
|
col = mix(col, tex, a);
|
|
110
110
|
col *= 1.0 - 0.55*flapShadow(q)*uAlpha;
|
|
111
111
|
gl_FragColor = vec4(col,1.0);
|
|
112
|
-
}`,
|
|
112
|
+
}`, Et = {
|
|
113
113
|
name: "PeelCard",
|
|
114
114
|
props: {
|
|
115
115
|
cards: { type: Array, required: !0 },
|
|
@@ -121,11 +121,12 @@ void main(){
|
|
|
121
121
|
padding: { type: Number, default: 16 },
|
|
122
122
|
maxScale: { type: Number, default: 1.35 },
|
|
123
123
|
hint: { type: Boolean, default: !0 },
|
|
124
|
+
clickPeel: { type: Boolean, default: !1 },
|
|
124
125
|
label: { type: String, default: "Card: drag the edge to peel it off" }
|
|
125
126
|
},
|
|
126
127
|
emits: ["grab", "peel", "change", "toggle"],
|
|
127
|
-
setup(
|
|
128
|
-
const d =
|
|
128
|
+
setup(o, { emit: s, expose: l }) {
|
|
129
|
+
const d = O(null), x = O(null), T = O(!1), E = O(!1), L = O(!1), Ce = { position: "relative", width: "100%", height: "100%", minHeight: "200px" }, Ne = { position: "absolute", inset: "0", display: "grid", placeItems: "center", padding: "24px", textAlign: "center", opacity: ".7" }, De = rt(() => ({
|
|
129
130
|
position: "absolute",
|
|
130
131
|
inset: "0",
|
|
131
132
|
width: "100%",
|
|
@@ -134,111 +135,111 @@ void main(){
|
|
|
134
135
|
touchAction: "none",
|
|
135
136
|
userSelect: "none",
|
|
136
137
|
WebkitUserSelect: "none",
|
|
137
|
-
cursor:
|
|
138
|
-
outline:
|
|
138
|
+
cursor: T.value ? "grabbing" : "grab",
|
|
139
|
+
outline: E.value ? "2px solid currentColor" : "none",
|
|
139
140
|
outlineOffset: "-4px"
|
|
140
|
-
})),
|
|
141
|
+
})), Oe = (h) => {
|
|
141
142
|
try {
|
|
142
|
-
|
|
143
|
+
E.value = h.target.matches(":focus-visible");
|
|
143
144
|
} catch {
|
|
144
|
-
|
|
145
|
+
E.value = !1;
|
|
145
146
|
}
|
|
146
147
|
};
|
|
147
|
-
let
|
|
148
|
+
let ce = () => {
|
|
148
149
|
};
|
|
149
|
-
const
|
|
150
|
+
const de = { peel() {
|
|
150
151
|
} };
|
|
151
|
-
function
|
|
152
|
-
const h =
|
|
152
|
+
function Ge() {
|
|
153
|
+
const h = x.value, f = o.width, g = o.height, Z = o.radius, b = o.toggle, t = h.getContext("webgl2", { antialias: !0, alpha: !1 }) || h.getContext("webgl", { antialias: !0, alpha: !1 });
|
|
153
154
|
if (!t) {
|
|
154
155
|
L.value = !0;
|
|
155
156
|
return;
|
|
156
157
|
}
|
|
157
|
-
const
|
|
158
|
-
let
|
|
159
|
-
const
|
|
160
|
-
let
|
|
161
|
-
const
|
|
162
|
-
const
|
|
158
|
+
const Xe = typeof WebGL2RenderingContext < "u" && t instanceof WebGL2RenderingContext, M = () => b ? 2 : o.cards.length;
|
|
159
|
+
let G = !0;
|
|
160
|
+
const fe = [];
|
|
161
|
+
let Q = 0;
|
|
162
|
+
const ue = (n, a) => {
|
|
163
|
+
const r = (u, m) => {
|
|
163
164
|
const p = t.createShader(u);
|
|
164
165
|
return t.shaderSource(p, m), t.compileShader(p), t.getShaderParameter(p, t.COMPILE_STATUS) || console.error(t.getShaderInfoLog(p)), p;
|
|
165
|
-
},
|
|
166
|
-
t.attachShader(
|
|
167
|
-
const c = t.getProgramParameter(
|
|
166
|
+
}, i = t.createProgram();
|
|
167
|
+
t.attachShader(i, r(t.VERTEX_SHADER, n)), t.attachShader(i, r(t.FRAGMENT_SHADER, a)), t.linkProgram(i), t.getProgramParameter(i, t.LINK_STATUS) || console.error(t.getProgramInfoLog(i)), i.loc = {};
|
|
168
|
+
const c = t.getProgramParameter(i, t.ACTIVE_UNIFORMS);
|
|
168
169
|
for (let u = 0; u < c; u++) {
|
|
169
|
-
const m = t.getActiveUniform(
|
|
170
|
-
|
|
170
|
+
const m = t.getActiveUniform(i, u).name;
|
|
171
|
+
i.loc[m] = t.getUniformLocation(i, m);
|
|
171
172
|
}
|
|
172
|
-
return
|
|
173
|
-
},
|
|
174
|
-
for (let n = 0, a = 0; n <= I; n++) for (let
|
|
175
|
-
|
|
176
|
-
const A = new Uint16Array(
|
|
177
|
-
for (let n = 0, a = 0; n < I; n++) for (let
|
|
178
|
-
const
|
|
179
|
-
A[a++] =
|
|
173
|
+
return i.aPos = t.getAttribLocation(i, "aPos"), i;
|
|
174
|
+
}, _ = ue(gt, pt(Z)), P = ue(vt, Tt(Z)), he = Math.max(2.5, Math.sqrt((f + 4) * (g + 4) / 6e4)), y = Math.round((f + 4) / he), I = Math.round((g + 4) / he), me = f / 2 + 2, ge = g / 2 + 2, J = new Float32Array((y + 1) * (I + 1) * 2);
|
|
175
|
+
for (let n = 0, a = 0; n <= I; n++) for (let r = 0; r <= y; r++)
|
|
176
|
+
J[a++] = -me + 2 * me * r / y, J[a++] = -ge + 2 * ge * n / I;
|
|
177
|
+
const A = new Uint16Array(y * I * 6);
|
|
178
|
+
for (let n = 0, a = 0; n < I; n++) for (let r = 0; r < y; r++) {
|
|
179
|
+
const i = n * (y + 1) + r, c = i + 1, u = i + y + 1, m = u + 1;
|
|
180
|
+
A[a++] = i, A[a++] = c, A[a++] = u, A[a++] = c, A[a++] = m, A[a++] = u;
|
|
180
181
|
}
|
|
181
|
-
const Q = t.createBuffer();
|
|
182
|
-
t.bindBuffer(t.ARRAY_BUFFER, Q), t.bufferData(t.ARRAY_BUFFER, Z, t.STATIC_DRAW);
|
|
183
|
-
const J = t.createBuffer();
|
|
184
|
-
t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, J), t.bufferData(t.ELEMENT_ARRAY_BUFFER, A, t.STATIC_DRAW);
|
|
185
182
|
const ee = t.createBuffer();
|
|
186
|
-
t.bindBuffer(t.ARRAY_BUFFER, ee), t.bufferData(t.ARRAY_BUFFER,
|
|
183
|
+
t.bindBuffer(t.ARRAY_BUFFER, ee), t.bufferData(t.ARRAY_BUFFER, J, t.STATIC_DRAW);
|
|
184
|
+
const te = t.createBuffer();
|
|
185
|
+
t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, te), t.bufferData(t.ELEMENT_ARRAY_BUFFER, A, t.STATIC_DRAW);
|
|
186
|
+
const ne = t.createBuffer();
|
|
187
|
+
t.bindBuffer(t.ARRAY_BUFFER, ne), t.bufferData(t.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), t.STATIC_DRAW);
|
|
187
188
|
let U = 2, v = 0;
|
|
188
|
-
const
|
|
189
|
-
async function
|
|
190
|
-
const a = Math.round(f * U),
|
|
191
|
-
|
|
192
|
-
const c =
|
|
189
|
+
const w = /* @__PURE__ */ new Map();
|
|
190
|
+
async function qe(n) {
|
|
191
|
+
const a = Math.round(f * U), r = Math.round(g * U), i = document.createElement("canvas");
|
|
192
|
+
i.width = a, i.height = r;
|
|
193
|
+
const c = i.getContext("2d");
|
|
193
194
|
let u = !1;
|
|
194
195
|
try {
|
|
195
196
|
const m = new Image(), p = new Promise((F, B) => {
|
|
196
197
|
m.onload = F, m.onerror = B;
|
|
197
198
|
});
|
|
198
|
-
m.src = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(
|
|
199
|
+
m.src = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(mt(n, f, g)), await p, c.drawImage(m, 0, 0, a, r), c.getImageData(0, 0, 1, 1), u = !0;
|
|
199
200
|
} catch (m) {
|
|
200
201
|
console.warn("[PeelCard] foreignObject unavailable, drawing fallback", m);
|
|
201
202
|
}
|
|
202
203
|
if (!u) {
|
|
203
|
-
c.setTransform(1, 0, 0, 1, 0, 0), c.fillStyle = n.bg || "#ffffff", c.fillRect(0, 0, a,
|
|
204
|
+
c.setTransform(1, 0, 0, 1, 0, 0), c.fillStyle = n.bg || "#ffffff", c.fillRect(0, 0, a, r);
|
|
204
205
|
const p = (new DOMParser().parseFromString(n.html || "", "text/html").body.textContent || "").split(/\n+/).map((F) => F.trim()).filter(Boolean).slice(0, 6);
|
|
205
206
|
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));
|
|
206
207
|
}
|
|
207
|
-
return
|
|
208
|
+
return i;
|
|
208
209
|
}
|
|
209
|
-
function
|
|
210
|
-
if (!
|
|
211
|
-
if (n = (n %
|
|
212
|
-
const a =
|
|
213
|
-
return
|
|
214
|
-
if (!
|
|
210
|
+
function X(n) {
|
|
211
|
+
if (!M() || !o.cards.length) return Promise.resolve();
|
|
212
|
+
if (n = (n % M() + M()) % M(), w.has(n)) return w.get(n).promise;
|
|
213
|
+
const a = o.cards[n % o.cards.length], r = { tex: null, back: ht(a.back || "#f2efe6") };
|
|
214
|
+
return r.promise = qe(a).then((i) => {
|
|
215
|
+
if (!G || w.get(n) !== r) return;
|
|
215
216
|
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,
|
|
217
|
-
}),
|
|
217
|
+
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, 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), Xe ? (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), r.tex = c;
|
|
218
|
+
}), w.set(n, r), r.promise;
|
|
218
219
|
}
|
|
219
|
-
function
|
|
220
|
-
const a = n ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([v, (v + 1) %
|
|
221
|
-
for (const [
|
|
220
|
+
function ae(n) {
|
|
221
|
+
const a = n ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([v, (v + 1) % M(), (v + 2) % M()]);
|
|
222
|
+
for (const [r, i] of w) a.has(r) || (i.tex && t.deleteTexture(i.tex), w.delete(r));
|
|
222
223
|
}
|
|
223
|
-
const
|
|
224
|
-
let
|
|
225
|
-
function
|
|
224
|
+
const pe = () => Promise.all([X(0), X(1), X(2)]);
|
|
225
|
+
let C = 1, N = 1, oe = 1, re = 1, q = 1, H = 1;
|
|
226
|
+
function ve() {
|
|
226
227
|
const n = d.value.getBoundingClientRect();
|
|
227
|
-
|
|
228
|
+
oe = Math.max(1, n.width), re = Math.max(1, n.height), C = Math.min(window.devicePixelRatio || 1, 2), q = Math.round(oe * C), H = Math.round(re * C), h.width = q, h.height = H, N = Math.max(0.3, Math.min(o.maxScale, (oe - 2 * o.padding) / f, (re - 2 * o.padding) / g));
|
|
228
229
|
}
|
|
229
|
-
let
|
|
230
|
-
function
|
|
231
|
-
let n =
|
|
230
|
+
let k = [0.9, 0.89, 0.85];
|
|
231
|
+
function Y() {
|
|
232
|
+
let n = o.background;
|
|
232
233
|
if (!n)
|
|
233
|
-
for (let
|
|
234
|
-
const
|
|
235
|
-
if (
|
|
236
|
-
n =
|
|
234
|
+
for (let r = d.value; r; r = r.parentElement) {
|
|
235
|
+
const i = getComputedStyle(r).backgroundColor;
|
|
236
|
+
if (i && !/rgba?\(.*,\s*0\)$/.test(i) && i !== "transparent") {
|
|
237
|
+
n = i;
|
|
237
238
|
break;
|
|
238
239
|
}
|
|
239
240
|
}
|
|
240
241
|
const a = (n || "").match(/[\d.]+/g);
|
|
241
|
-
a && a.length >= 3 && (
|
|
242
|
+
a && a.length >= 3 && (k = [a[0] / 255, a[1] / 255, a[2] / 255]);
|
|
242
243
|
}
|
|
243
244
|
const e = {
|
|
244
245
|
mode: "idle",
|
|
@@ -262,108 +263,115 @@ void main(){
|
|
|
262
263
|
restick: !1,
|
|
263
264
|
pending: !1,
|
|
264
265
|
prog: !1
|
|
265
|
-
},
|
|
266
|
+
}, He = matchMedia("(prefers-reduced-motion: reduce)").matches, R = { ok: !1, x: 0, y: 0 }, Ye = [[-f / 2, -g / 2], [f / 2, -g / 2], [-f / 2, g / 2], [f / 2, g / 2]], ze = (n, a) => Ye.map((r) => (r[0] - n[0]) * a[0] + (r[1] - n[1]) * a[1]), Te = (n, a) => Math.max(...ze(n, a)), D = (n, a) => Be(Te(n, a) + 2.2 * K + 20, K, Math.PI - 0.12, 0.12), Ee = (n) => {
|
|
266
267
|
const a = h.getBoundingClientRect();
|
|
267
|
-
return [(n.clientX - a.left - a.width / 2) /
|
|
268
|
+
return [(n.clientX - a.left - a.width / 2) / N, -(n.clientY - a.top - a.height / 2) / N];
|
|
268
269
|
};
|
|
269
|
-
function
|
|
270
|
-
const
|
|
271
|
-
e.nIn = n, e.g = n[0] ? [-n[0] * f / 2,
|
|
272
|
-
}
|
|
273
|
-
function ze(n) {
|
|
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();
|
|
270
|
+
function xe(n, a) {
|
|
271
|
+
const r = Z * 0.8, i = (c, u) => Math.max(-u + r, Math.min(u - r, c));
|
|
272
|
+
e.nIn = n, e.g = n[0] ? [-n[0] * f / 2, i(a[1], g / 2)] : [i(a[0], f / 2), -n[1] * g / 2];
|
|
276
273
|
}
|
|
277
274
|
function $e(n) {
|
|
278
|
-
const a = n[0] -
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
function xe(n) {
|
|
282
|
-
const a = performance.now(), o = Math.max(1, a - e.lastTime);
|
|
283
|
-
e.velU += ((n - e.lastDT) / o * 1e3 - e.velU) * 0.35, e.lastDT = n, e.lastTime = a;
|
|
275
|
+
const a = n[0] + f / 2, r = f / 2 - n[0], i = n[1] + g / 2, c = g / 2 - n[1], u = Math.min(a, r, i, c);
|
|
276
|
+
xe(u === a ? [1, 0] : u === r ? [-1, 0] : u === 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();
|
|
284
277
|
}
|
|
285
278
|
function Ve(n) {
|
|
286
|
-
const a =
|
|
279
|
+
const a = n[0] - e.p0[0], r = n[1] - e.p0[1];
|
|
280
|
+
return Math.hypot(a, r) < 10 ? !1 : (xe(Math.abs(a) >= Math.abs(r) ? [-Math.sign(a), 0] : [0, -Math.sign(r)], e.p0), e.pending = !1, e.ang = 0, e.angBase = 0, e.angT = 0, e.dEnd = D(e.g, e.nIn), e.d = e.dEnd, e.dT = 0, e.velU = 0, e.lastDT = 0, e.lastTime = performance.now(), !0);
|
|
281
|
+
}
|
|
282
|
+
function Re(n) {
|
|
283
|
+
const a = performance.now(), r = Math.max(1, a - e.lastTime);
|
|
284
|
+
e.velU += ((n - e.lastDT) / r * 1e3 - e.velU) * 0.35, e.lastDT = n, e.lastTime = a;
|
|
285
|
+
}
|
|
286
|
+
function We(n) {
|
|
287
|
+
const a = [n[0] - e.p0[0], n[1] - e.p0[1]], r = Math.hypot(a[0], a[1]);
|
|
287
288
|
if (e.restick) {
|
|
288
|
-
const p =
|
|
289
|
-
e.angT = e.angBase + F *
|
|
290
|
-
const B =
|
|
291
|
-
e.dT = Math.max(0, -(a[0] * B[0] + a[1] * B[1])),
|
|
289
|
+
const p = S(e.nIn, e.angBase).map((et) => -et), 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])));
|
|
290
|
+
e.angT = e.angBase + F * j(6, 70, r);
|
|
291
|
+
const B = S(e.nIn, e.angT);
|
|
292
|
+
e.dT = Math.max(0, -(a[0] * B[0] + a[1] * B[1])), Re(e.dT);
|
|
292
293
|
return;
|
|
293
294
|
}
|
|
294
|
-
const
|
|
295
|
-
e.angT = u *
|
|
296
|
-
const m =
|
|
297
|
-
e.dT = Math.max(0, a[0] * m[0] + a[1] * m[1]),
|
|
295
|
+
const i = a[0] * e.nIn[0] + a[1] * e.nIn[1], c = e.nIn[0] * a[1] - e.nIn[1] * a[0], u = Math.max(-W, Math.min(W, Math.atan2(c, i)));
|
|
296
|
+
e.angT = u * j(6, 70, r);
|
|
297
|
+
const m = S(e.nIn, e.angT);
|
|
298
|
+
e.dT = Math.max(0, a[0] * m[0] + a[1] * m[1]), Re(e.dT);
|
|
298
299
|
}
|
|
299
|
-
function
|
|
300
|
-
const n =
|
|
301
|
-
e.dEnd =
|
|
300
|
+
function z() {
|
|
301
|
+
const n = S(e.nIn, e.prog ? e.angT : e.ang);
|
|
302
|
+
e.dEnd = D(e.g, n), e.alpha = 1, e.mode = "complete";
|
|
302
303
|
}
|
|
303
|
-
function
|
|
304
|
+
function je() {
|
|
304
305
|
if (e.mode !== "drag") return;
|
|
305
|
-
if (
|
|
306
|
-
e.pending = !1, e.restick = !1, e.mode = "rest",
|
|
306
|
+
if (T.value = !1, e.pending) {
|
|
307
|
+
e.pending = !1, e.restick = !1, e.mode = "rest", ie();
|
|
307
308
|
return;
|
|
308
309
|
}
|
|
309
|
-
const n =
|
|
310
|
+
const n = S(e.nIn, e.ang);
|
|
310
311
|
if (e.restick) {
|
|
311
|
-
const
|
|
312
|
-
|
|
312
|
+
const r = e.d / D(e.g, n);
|
|
313
|
+
r < 0.6 || e.velU > 700 && r < 0.9 ? e.mode = "settle" : z();
|
|
313
314
|
return;
|
|
314
315
|
}
|
|
315
|
-
const a = e.d /
|
|
316
|
-
a > 0.32 || e.velU > 700 && a > 0.1 ?
|
|
316
|
+
const a = e.d / Te(e.g, n);
|
|
317
|
+
a > 0.32 || e.velU > 700 && a > 0.1 ? z() : e.mode = "settle";
|
|
317
318
|
}
|
|
318
|
-
function
|
|
319
|
-
const a = Math.max(-
|
|
320
|
-
if (
|
|
321
|
-
e.nIn = [1, 0], e.g = [-f / 2, 0], e.ang = e.angT = a, e.prog = !0, e.dEnd =
|
|
319
|
+
function ie(n) {
|
|
320
|
+
const a = Math.max(-W, Math.min(W, (typeof n == "number" ? n : Le) * Math.PI / 180));
|
|
321
|
+
if (b && e.peeled && e.mode === "rest") {
|
|
322
|
+
e.nIn = [1, 0], e.g = [-f / 2, 0], e.ang = e.angT = a, e.prog = !0, e.dEnd = D(e.g, S(e.nIn, a)), e.d = e.dEnd, e.t = 0, e.mode = "unfade";
|
|
322
323
|
return;
|
|
323
324
|
}
|
|
324
|
-
if (
|
|
325
|
+
if (b && e.peeled && e.mode === "drag") {
|
|
325
326
|
e.restick = !1, e.mode = "settle";
|
|
326
327
|
return;
|
|
327
328
|
}
|
|
328
|
-
e.mode !== "idle" && e.mode !== "hint" && e.mode !== "settle" ||
|
|
329
|
+
e.mode !== "idle" && e.mode !== "hint" && e.mode !== "settle" || b && e.peeled || (e.interacted = !0, e.nIn = [1, 0], e.g = [-f / 2, 0], e.ang = 0, e.angT = a, e.prog = !0, z());
|
|
329
330
|
}
|
|
330
|
-
|
|
331
|
-
function
|
|
332
|
-
!
|
|
331
|
+
de.peel = ie;
|
|
332
|
+
function be() {
|
|
333
|
+
!o.hint || e.mode !== "idle" || e.interacted || He || (e.nIn = [1, 0], e.g = [-f / 2, 0], e.ang = 0, e.mode = "hint", e.t = 0);
|
|
333
334
|
}
|
|
334
|
-
const
|
|
335
|
+
const Me = (n) => {
|
|
335
336
|
if (e.mode === "complete" || e.mode === "fade" || e.mode === "unfade" || e.mode === "unpeel") return;
|
|
336
|
-
const a =
|
|
337
|
-
if (e.prog = !1,
|
|
337
|
+
const a = Ee(n);
|
|
338
|
+
if (e.prog = !1, b && e.peeled) {
|
|
338
339
|
if (e.mode !== "rest") return;
|
|
339
|
-
h.setPointerCapture(n.pointerId),
|
|
340
|
+
h.setPointerCapture(n.pointerId), T.value = !0, e.restick = !0, e.pending = !0, e.p0 = a, e.mode = "drag";
|
|
340
341
|
return;
|
|
341
342
|
}
|
|
342
|
-
Math.abs(a[0]) > f / 2 + 30 || Math.abs(a[1]) > g / 2 + 30 || (h.setPointerCapture(n.pointerId),
|
|
343
|
-
},
|
|
343
|
+
Math.abs(a[0]) > f / 2 + 30 || Math.abs(a[1]) > g / 2 + 30 || (h.setPointerCapture(n.pointerId), T.value = !0, e.interacted || s("grab"), e.interacted = !0, e.restick = !1, R.ok = !0, R.x = n.clientX, R.y = n.clientY, $e(a), e.mode = "drag");
|
|
344
|
+
}, _e = (n) => {
|
|
344
345
|
if (e.mode !== "drag") return;
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
346
|
+
R.ok && Math.hypot(n.clientX - R.x, n.clientY - R.y) > 8 && (R.ok = !1);
|
|
347
|
+
const a = Ee(n);
|
|
348
|
+
e.pending && !Ve(a) || We(a);
|
|
349
|
+
}, $ = (n) => {
|
|
350
|
+
if (o.clickPeel && n.type === "pointerup" && R.ok && e.mode === "drag" && !e.restick) {
|
|
351
|
+
R.ok = !1, T.value = !1, e.d = 0, e.ang = 0, e.angT = Le * Math.PI / 180, e.prog = !0, z();
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
je();
|
|
355
|
+
}, Pe = (n) => {
|
|
356
|
+
(n.key === "ArrowRight" || n.key === "Enter" || n.key === " ") && (n.preventDefault(), ie());
|
|
349
357
|
};
|
|
350
|
-
h.addEventListener("pointerdown",
|
|
351
|
-
function
|
|
358
|
+
h.addEventListener("pointerdown", Me), h.addEventListener("pointermove", _e), h.addEventListener("pointerup", $), h.addEventListener("pointercancel", $), h.addEventListener("keydown", Pe);
|
|
359
|
+
function Ke() {
|
|
352
360
|
const n = v;
|
|
353
|
-
v = (v + 1) %
|
|
361
|
+
v = (v + 1) % M(), e.d = 0, e.ang = 0, e.alpha = 1, e.mode = "idle", X(v + 2), ae(!1), s("peel", n), s("change", v);
|
|
354
362
|
}
|
|
355
|
-
function
|
|
363
|
+
function Ze(n) {
|
|
356
364
|
switch (e.mode) {
|
|
357
365
|
case "drag":
|
|
358
366
|
if (e.pending) break;
|
|
359
367
|
if (e.restick) {
|
|
360
|
-
const a =
|
|
368
|
+
const a = D(e.g, S(e.nIn, e.ang));
|
|
361
369
|
e.d += (Math.max(0, a - e.dT) - e.d) * (1 - Math.exp(-n * 30));
|
|
362
370
|
} else e.d += (Math.min(e.dT, 1500) - e.d) * (1 - Math.exp(-n * 30));
|
|
363
371
|
e.ang += (e.angT - e.ang) * (1 - Math.exp(-n * 16));
|
|
364
372
|
break;
|
|
365
373
|
case "settle":
|
|
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",
|
|
374
|
+
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", b && e.peeled && (e.peeled = !1, s("toggle", !1)));
|
|
367
375
|
break;
|
|
368
376
|
case "hint": {
|
|
369
377
|
e.t += n;
|
|
@@ -372,91 +380,91 @@ void main(){
|
|
|
372
380
|
break;
|
|
373
381
|
}
|
|
374
382
|
case "complete":
|
|
375
|
-
e.d += Math.max((e.dEnd - e.d) * (1 - Math.exp(-n * 6)), 380 * n), e.prog && (e.ang = e.angT *
|
|
383
|
+
e.d += Math.max((e.dEnd - e.d) * (1 - Math.exp(-n * 6)), 380 * n), e.prog && (e.ang = e.angT * j(6, 70, e.d)), e.d >= e.dEnd && (e.d = e.dEnd, e.mode = "fade", e.t = 0);
|
|
376
384
|
break;
|
|
377
385
|
case "rest":
|
|
378
386
|
break;
|
|
379
387
|
case "fade":
|
|
380
|
-
e.t += n, e.alpha = Math.max(0, 1 - e.t / 0.28), e.t >= 0.28 && (
|
|
388
|
+
e.t += n, e.alpha = Math.max(0, 1 - e.t / 0.28), e.t >= 0.28 && (b ? (e.mode = "rest", e.peeled || (e.peeled = !0, s("toggle", !0))) : Ke());
|
|
381
389
|
break;
|
|
382
390
|
case "unfade":
|
|
383
391
|
e.t += n, e.alpha = Math.min(1, e.alpha + n / 0.28), e.alpha >= 1 && (e.mode = "unpeel");
|
|
384
392
|
break;
|
|
385
393
|
case "unpeel":
|
|
386
|
-
e.d -= Math.max((e.dEnd - e.d) * (1 - Math.exp(-n * 6)), 380 * n), e.ang = e.angT *
|
|
394
|
+
e.d -= Math.max((e.dEnd - e.d) * (1 - Math.exp(-n * 6)), 380 * n), e.ang = e.angT * j(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));
|
|
387
395
|
break;
|
|
388
396
|
}
|
|
389
|
-
|
|
397
|
+
b && !e.pending && (e.mode === "drag" || e.mode === "settle") && (e.alpha += (1 - e.alpha) * (1 - Math.exp(-n * 12)));
|
|
390
398
|
}
|
|
391
|
-
function Ae(n, a,
|
|
392
|
-
const
|
|
393
|
-
t.uniform2f(
|
|
399
|
+
function Ae(n, a, r) {
|
|
400
|
+
const i = n.loc;
|
|
401
|
+
t.uniform2f(i.uG, e.g[0], e.g[1]), t.uniform2f(i.uU, r[0], r[1]), t.uniform2f(i.uHalf, f / 2, g / 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, q, H), t.uniform1f(i.uScale, N * C);
|
|
394
402
|
}
|
|
395
|
-
function
|
|
396
|
-
const n =
|
|
397
|
-
if (t.viewport(0, 0, q,
|
|
398
|
-
const
|
|
399
|
-
t.disable(t.DEPTH_TEST), t.disable(t.BLEND), t.useProgram(
|
|
403
|
+
function Qe() {
|
|
404
|
+
const n = w.get(v), a = w.get((v + 1) % M());
|
|
405
|
+
if (t.viewport(0, 0, q, H), t.clearColor(k[0], k[1], k[2], 1), t.clear(t.COLOR_BUFFER_BIT | t.DEPTH_BUFFER_BIT), !n || !n.tex || !a || !a.tex) return;
|
|
406
|
+
const r = S(e.nIn, e.ang), i = ut(e.d);
|
|
407
|
+
t.disable(t.DEPTH_TEST), t.disable(t.BLEND), t.useProgram(P), Ae(P, i, r), t.uniform3f(P.loc.uBg, k[0], k[1], k[2]), t.uniform1f(P.loc.uAlpha, e.alpha), t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, a.tex), t.uniform1i(P.loc.uBase, 0), t.bindBuffer(t.ARRAY_BUFFER, ne), t.enableVertexAttribArray(P.aPos), t.vertexAttribPointer(P.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(_), Ae(_, i, r), t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, n.tex), t.uniform1i(_.loc.uFront, 0), t.uniform3f(_.loc.uBack, n.back[0], n.back[1], n.back[2]), t.uniform1f(_.loc.uAlpha, e.alpha), t.bindBuffer(t.ARRAY_BUFFER, ee), t.enableVertexAttribArray(_.aPos), t.vertexAttribPointer(_.aPos, 2, t.FLOAT, !1, 0, 0), t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, te), t.drawElements(t.TRIANGLES, A.length, t.UNSIGNED_SHORT, 0);
|
|
400
408
|
}
|
|
401
409
|
let se = performance.now();
|
|
402
|
-
function
|
|
403
|
-
if (!
|
|
410
|
+
function we(n) {
|
|
411
|
+
if (!G) return;
|
|
404
412
|
const a = Math.min(0.05, (n - se) / 1e3);
|
|
405
|
-
se = n,
|
|
413
|
+
se = n, Ze(a), Qe(), Q = requestAnimationFrame(we);
|
|
406
414
|
}
|
|
407
|
-
const
|
|
408
|
-
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
+
const Se = new ResizeObserver(ve);
|
|
416
|
+
Se.observe(d.value);
|
|
417
|
+
const V = matchMedia("(prefers-color-scheme: dark)");
|
|
418
|
+
V.addEventListener && V.addEventListener("change", Y);
|
|
419
|
+
const ye = new MutationObserver(Y);
|
|
420
|
+
ye.observe(document.documentElement, { attributes: !0 }), ve(), Y(), U = Math.min(3, Math.max(2, N * C));
|
|
421
|
+
const Je = lt(() => o.cards.map((n) => `${n.bg}\0${n.back}\0${n.html}`).join(""), () => {
|
|
422
|
+
ae(!0), v = 0, e.d = 0, e.mode = "idle", e.alpha = 1, e.peeled = !1, pe();
|
|
415
423
|
});
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
se = n,
|
|
419
|
-
}),
|
|
420
|
-
}),
|
|
421
|
-
|
|
424
|
+
pe().then(() => {
|
|
425
|
+
G && (Q = requestAnimationFrame((n) => {
|
|
426
|
+
se = n, we(n);
|
|
427
|
+
}), fe.push(setTimeout(be, 900), setTimeout(be, 8e3)));
|
|
428
|
+
}), ce = () => {
|
|
429
|
+
G = !1, cancelAnimationFrame(Q), fe.forEach(clearTimeout), Je(), Se.disconnect(), ye.disconnect(), V.removeEventListener && V.removeEventListener("change", Y), h.removeEventListener("pointerdown", Me), h.removeEventListener("pointermove", _e), h.removeEventListener("pointerup", $), h.removeEventListener("pointercancel", $), h.removeEventListener("keydown", Pe), ae(!0), t.deleteBuffer(ee), t.deleteBuffer(te), t.deleteBuffer(ne), t.deleteProgram(_), t.deleteProgram(P);
|
|
422
430
|
const n = t.getExtension("WEBGL_lose_context");
|
|
423
431
|
n && n.loseContext();
|
|
424
432
|
}, typeof window < "u" && window.__PEEL_DEBUG__ && (window.__peelDebug = e);
|
|
425
433
|
}
|
|
426
|
-
return
|
|
434
|
+
return it(Ge), st(() => ce()), l({ peel: () => de.peel() }), { root: d, canvas: x, noGL: L, focused: E, rootStyle: Ce, noGLStyle: Ne, canvasStyle: De, onFocus: Oe };
|
|
427
435
|
}
|
|
428
|
-
},
|
|
429
|
-
function
|
|
430
|
-
return
|
|
436
|
+
}, xt = ["aria-label"];
|
|
437
|
+
function Rt(o, s, l, d, x, T) {
|
|
438
|
+
return ke(), Fe("div", {
|
|
431
439
|
ref: "root",
|
|
432
|
-
style:
|
|
440
|
+
style: le(d.rootStyle)
|
|
433
441
|
}, [
|
|
434
|
-
|
|
442
|
+
tt("canvas", {
|
|
435
443
|
ref: "canvas",
|
|
436
444
|
tabindex: "0",
|
|
437
445
|
role: "img",
|
|
438
446
|
"aria-label": l.label,
|
|
439
|
-
style:
|
|
440
|
-
onFocus:
|
|
441
|
-
onBlur:
|
|
442
|
-
}, null, 44,
|
|
443
|
-
d.noGL ? (
|
|
447
|
+
style: le(d.canvasStyle),
|
|
448
|
+
onFocus: s[0] || (s[0] = (...E) => d.onFocus && d.onFocus(...E)),
|
|
449
|
+
onBlur: s[1] || (s[1] = (E) => d.focused = !1)
|
|
450
|
+
}, null, 44, xt),
|
|
451
|
+
d.noGL ? (ke(), Fe("div", {
|
|
444
452
|
key: 0,
|
|
445
|
-
style:
|
|
453
|
+
style: le(d.noGLStyle)
|
|
446
454
|
}, [
|
|
447
|
-
|
|
448
|
-
|
|
455
|
+
nt(o.$slots, "fallback", {}, () => [
|
|
456
|
+
s[2] || (s[2] = at("WebGL is not available in this browser.", -1))
|
|
449
457
|
])
|
|
450
|
-
], 4)) :
|
|
458
|
+
], 4)) : ot("", !0)
|
|
451
459
|
], 4);
|
|
452
460
|
}
|
|
453
|
-
const
|
|
454
|
-
install(
|
|
455
|
-
|
|
461
|
+
const bt = /* @__PURE__ */ ct(Et, [["render", Rt]]), Pt = {
|
|
462
|
+
install(o) {
|
|
463
|
+
o.component("PeelCard", bt);
|
|
456
464
|
}
|
|
457
465
|
};
|
|
458
466
|
export {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
467
|
+
bt as PeelCard,
|
|
468
|
+
Pt as PeelCardPlugin,
|
|
469
|
+
bt as default
|
|
462
470
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
<foreignObject width="${s}" height="${l}"><div xmlns="http://www.w3.org/1999/xhtml" style="width:${s}px;height:${l}px;background:${
|
|
1
|
+
(function(x,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],c):(x=typeof globalThis<"u"?globalThis:x||self,c(x.VuePeelCard={},x.Vue))})(this,function(x,c){"use strict";const Ie=(o,s)=>{const l=o.__vccOpts||o;for(const[f,M]of s)l[f]=M;return l};function le(o,s,l,f){return o<=l*s?o-s*Math.sin(o/s):o-s*Math.sin(f)+(o-l*s)*Math.cos(f)}function Be(o,s,l,f){let M=0,E=4e3;for(let R=0;R<48;R++){const F=(M+E)/2;le(F,s,l,f)<o?M=F:E=F}return(M+E)/2}function Fe(o){const s=18+57*Math.exp(-o/70),l=.12+.55*Math.exp(-o/140),f=Math.PI-l;return{R:s,phi:l,Th:f,tf:Be(o,s,f,l),sp:Math.sin(l),cp:Math.cos(l)}}const A=(o,s)=>{const l=Math.atan2(o[1],o[0])+s;return[Math.cos(l),Math.sin(l)]};function X(o,s,l){return l=Math.min(1,Math.max(0,(l-o)/(s-o))),l*l*(3-2*l)}const Ue=o=>{const s=parseInt(String(o).replace("#","").padEnd(6,"0").slice(0,6),16);return[(s>>16)/255,(s>>8&255)/255,(s&255)/255]},Ce=(o,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:${o.bg||"#ffffff"}">${o.html||""}</div></foreignObject></svg>`,ce=`
|
|
3
3
|
uniform vec2 uG, uU, uHalf;
|
|
4
4
|
uniform float uTf, uR, uTheta, uSinPhi, uCosPhi;
|
|
5
|
-
`,
|
|
5
|
+
`,Ne=`
|
|
6
6
|
attribute vec2 aPos;
|
|
7
|
-
${
|
|
7
|
+
${ce}
|
|
8
8
|
uniform vec2 uView; uniform float uScale;
|
|
9
9
|
varying vec2 vOrig, vXY; varying float vZ, vTh, vS;
|
|
10
10
|
void main(){
|
|
@@ -21,12 +21,12 @@ void main(){
|
|
|
21
21
|
float k = 1.0/(1.0 - min(z,1500.0)/3200.0);
|
|
22
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
|
+
}`,de=o=>`
|
|
25
25
|
precision highp float;
|
|
26
|
-
${
|
|
26
|
+
${ce}
|
|
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){ return smoothstep(-soft*0.5, soft, -sdRR(p, uHalf, ${
|
|
29
|
+
float rectMask(vec2 p, float soft){ return smoothstep(-soft*0.5, soft, -sdRR(p, uHalf, ${o.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
|
-
}`,
|
|
40
|
+
}`,De=o=>`${de(o)}
|
|
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, ${o.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
|
-
}`,
|
|
64
|
+
}`,Ge="attribute vec2 aPos; void main(){ gl_Position = vec4(aPos,0.0,1.0); }",Oe=o=>`${de(o)}
|
|
65
65
|
uniform sampler2D uBase; uniform vec2 uView; uniform float uScale, uAlpha; uniform vec3 uBg;
|
|
66
66
|
void main(){
|
|
67
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, ${o.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, ${o.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, ${o.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
78
|
col *= 1.0 - 0.55*flapShadow(q)*uAlpha;
|
|
79
79
|
gl_FragColor = vec4(col,1.0);
|
|
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"}})});
|
|
80
|
+
}`,Xe={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},clickPeel:{type:Boolean,default:!1},label:{type:String,default:"Card: drag the edge to peel it off"}},emits:["grab","peel","change","toggle"],setup(o,{emit:s,expose:l}){const f=c.ref(null),M=c.ref(null),E=c.ref(!1),R=c.ref(!1),F=c.ref(!1),Ve={position:"relative",width:"100%",height:"100%",minHeight:"200px"},Ye={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:E.value?"grabbing":"grab",outline:R.value?"2px solid currentColor":"none",outlineOffset:"-4px"})),We=m=>{try{R.value=m.target.matches(":focus-visible")}catch{R.value=!1}};let fe=()=>{};const ue={peel(){}};function je(){const m=M.value,u=o.width,p=o.height,Z=o.radius,P=o.toggle,t=m.getContext("webgl2",{antialias:!0,alpha:!1})||m.getContext("webgl",{antialias:!0,alpha:!1});if(!t){F.value=!0;return}const Ke=typeof WebGL2RenderingContext<"u"&&t instanceof WebGL2RenderingContext,_=()=>P?2:o.cards.length;let q=!0;const he=[];let Q=0;const me=(n,a)=>{const r=(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,r(t.VERTEX_SHADER,n)),t.attachShader(i,r(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},S=me(Ne,De(Z)),w=me(Ge,Oe(Z)),ge=Math.max(2.5,Math.sqrt((u+4)*(p+4)/6e4)),k=Math.round((u+4)/ge),C=Math.round((p+4)/ge),pe=u/2+2,Te=p/2+2,J=new Float32Array((k+1)*(C+1)*2);for(let n=0,a=0;n<=C;n++)for(let r=0;r<=k;r++)J[a++]=-pe+2*pe*r/k,J[a++]=-Te+2*Te*n/C;const y=new Uint16Array(k*C*6);for(let n=0,a=0;n<C;n++)for(let r=0;r<k;r++){const i=n*(k+1)+r,d=i+1,h=i+k+1,g=h+1;y[a++]=i,y[a++]=d,y[a++]=h,y[a++]=d,y[a++]=g,y[a++]=h}const ee=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,ee),t.bufferData(t.ARRAY_BUFFER,J,t.STATIC_DRAW);const te=t.createBuffer();t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,te),t.bufferData(t.ELEMENT_ARRAY_BUFFER,y,t.STATIC_DRAW);const ne=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,ne),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW);let N=2,v=0;const L=new Map;async function Ze(n){const a=Math.round(u*N),r=Math.round(p*N),i=document.createElement("canvas");i.width=a,i.height=r;const d=i.getContext("2d");let h=!1;try{const g=new Image,T=new Promise((B,U)=>{g.onload=B,g.onerror=U});g.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(Ce(n,u,p)),await T,d.drawImage(g,0,0,a,r),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,r);const T=(new DOMParser().parseFromString(n.html||"","text/html").body.textContent||"").split(/\n+/).map(B=>B.trim()).filter(Boolean).slice(0,6);d.scale(N,N),d.fillStyle="#222",d.font="600 22px system-ui,sans-serif",T.forEach((B,U)=>d.fillText(B,28,50+U*34))}return i}function z(n){if(!_()||!o.cards.length)return Promise.resolve();if(n=(n%_()+_())%_(),L.has(n))return L.get(n).promise;const a=o.cards[n%o.cards.length],r={tex:null,back:Ue(a.back||"#f2efe6")};return r.promise=Ze(a).then(i=>{if(!q||L.get(n)!==r)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),Ke?(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),r.tex=d}),L.set(n,r),r.promise}function ae(n){const a=n?new Set:new Set([v,(v+1)%_(),(v+2)%_()]);for(const[r,i]of L)a.has(r)||(i.tex&&t.deleteTexture(i.tex),L.delete(r))}const ve=()=>Promise.all([z(0),z(1),z(2)]);let D=1,G=1,oe=1,re=1,H=1,V=1;function Ee(){const n=f.value.getBoundingClientRect();oe=Math.max(1,n.width),re=Math.max(1,n.height),D=Math.min(window.devicePixelRatio||1,2),H=Math.round(oe*D),V=Math.round(re*D),m.width=H,m.height=V,G=Math.max(.3,Math.min(o.maxScale,(oe-2*o.padding)/u,(re-2*o.padding)/p))}let I=[.9,.89,.85];function Y(){let n=o.background;if(!n)for(let r=f.value;r;r=r.parentElement){const i=getComputedStyle(r).backgroundColor;if(i&&!/rgba?\(.*,\s*0\)$/.test(i)&&i!=="transparent"){n=i;break}}const a=(n||"").match(/[\d.]+/g);a&&a.length>=3&&(I=[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},Qe=matchMedia("(prefers-reduced-motion: reduce)").matches,b={ok:!1,x:0,y:0},Je=[[-u/2,-p/2],[u/2,-p/2],[-u/2,p/2],[u/2,p/2]],et=(n,a)=>Je.map(r=>(r[0]-n[0])*a[0]+(r[1]-n[1])*a[1]),Re=(n,a)=>Math.max(...et(n,a)),O=(n,a)=>le(Re(n,a)+2.2*18+20,18,Math.PI-.12,.12),xe=n=>{const a=m.getBoundingClientRect();return[(n.clientX-a.left-a.width/2)/G,-(n.clientY-a.top-a.height/2)/G]};function Me(n,a){const r=Z*.8,i=(d,h)=>Math.max(-h+r,Math.min(h-r,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 tt(n){const a=n[0]+u/2,r=u/2-n[0],i=n[1]+p/2,d=p/2-n[1],h=Math.min(a,r,i,d);Me(h===a?[1,0]:h===r?[-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 nt(n){const a=n[0]-e.p0[0],r=n[1]-e.p0[1];return Math.hypot(a,r)<10?!1:(Me(Math.abs(a)>=Math.abs(r)?[-Math.sign(a),0]:[0,-Math.sign(r)],e.p0),e.pending=!1,e.ang=0,e.angBase=0,e.angT=0,e.dEnd=O(e.g,e.nIn),e.d=e.dEnd,e.dT=0,e.velU=0,e.lastDT=0,e.lastTime=performance.now(),!0)}function be(n){const a=performance.now(),r=Math.max(1,a-e.lastTime);e.velU+=((n-e.lastDT)/r*1e3-e.velU)*.35,e.lastDT=n,e.lastTime=a}function at(n){const a=[n[0]-e.p0[0],n[1]-e.p0[1]],r=Math.hypot(a[0],a[1]);if(e.restick){const T=A(e.nIn,e.angBase).map(dt=>-dt),B=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+B*X(6,70,r);const U=A(e.nIn,e.angT);e.dT=Math.max(0,-(a[0]*U[0]+a[1]*U[1])),be(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*X(6,70,r);const g=A(e.nIn,e.angT);e.dT=Math.max(0,a[0]*g[0]+a[1]*g[1]),be(e.dT)}function $(){const n=A(e.nIn,e.prog?e.angT:e.ang);e.dEnd=O(e.g,n),e.alpha=1,e.mode="complete"}function ot(){if(e.mode!=="drag")return;if(E.value=!1,e.pending){e.pending=!1,e.restick=!1,e.mode="rest",ie();return}const n=A(e.nIn,e.ang);if(e.restick){const r=e.d/O(e.g,n);r<.6||e.velU>700&&r<.9?e.mode="settle":$();return}const a=e.d/Re(e.g,n);a>.32||e.velU>700&&a>.1?$():e.mode="settle"}function ie(n){const a=Math.max(-1,Math.min(1,(typeof n=="number"?n:12)*Math.PI/180));if(P&&e.peeled&&e.mode==="rest"){e.nIn=[1,0],e.g=[-u/2,0],e.ang=e.angT=a,e.prog=!0,e.dEnd=O(e.g,A(e.nIn,a)),e.d=e.dEnd,e.t=0,e.mode="unfade";return}if(P&&e.peeled&&e.mode==="drag"){e.restick=!1,e.mode="settle";return}e.mode!=="idle"&&e.mode!=="hint"&&e.mode!=="settle"||P&&e.peeled||(e.interacted=!0,e.nIn=[1,0],e.g=[-u/2,0],e.ang=0,e.angT=a,e.prog=!0,$())}ue.peel=ie;function Ae(){!o.hint||e.mode!=="idle"||e.interacted||Qe||(e.nIn=[1,0],e.g=[-u/2,0],e.ang=0,e.mode="hint",e.t=0)}const Pe=n=>{if(e.mode==="complete"||e.mode==="fade"||e.mode==="unfade"||e.mode==="unpeel")return;const a=xe(n);if(e.prog=!1,P&&e.peeled){if(e.mode!=="rest")return;m.setPointerCapture(n.pointerId),E.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),E.value=!0,e.interacted||s("grab"),e.interacted=!0,e.restick=!1,b.ok=!0,b.x=n.clientX,b.y=n.clientY,tt(a),e.mode="drag")},_e=n=>{if(e.mode!=="drag")return;b.ok&&Math.hypot(n.clientX-b.x,n.clientY-b.y)>8&&(b.ok=!1);const a=xe(n);e.pending&&!nt(a)||at(a)},W=n=>{if(o.clickPeel&&n.type==="pointerup"&&b.ok&&e.mode==="drag"&&!e.restick){b.ok=!1,E.value=!1,e.d=0,e.ang=0,e.angT=12*Math.PI/180,e.prog=!0,$();return}ot()},Se=n=>{(n.key==="ArrowRight"||n.key==="Enter"||n.key===" ")&&(n.preventDefault(),ie())};m.addEventListener("pointerdown",Pe),m.addEventListener("pointermove",_e),m.addEventListener("pointerup",W),m.addEventListener("pointercancel",W),m.addEventListener("keydown",Se);function rt(){const n=v;v=(v+1)%_(),e.d=0,e.ang=0,e.alpha=1,e.mode="idle",z(v+2),ae(!1),s("peel",n),s("change",v)}function it(n){switch(e.mode){case"drag":if(e.pending)break;if(e.restick){const a=O(e.g,A(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",P&&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*X(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&&(P?(e.mode="rest",e.peeled||(e.peeled=!0,s("toggle",!0))):rt());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*X(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}P&&!e.pending&&(e.mode==="drag"||e.mode==="settle")&&(e.alpha+=(1-e.alpha)*(1-Math.exp(-n*12)))}function we(n,a,r){const i=n.loc;t.uniform2f(i.uG,e.g[0],e.g[1]),t.uniform2f(i.uU,r[0],r[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,H,V),t.uniform1f(i.uScale,G*D)}function st(){const n=L.get(v),a=L.get((v+1)%_());if(t.viewport(0,0,H,V),t.clearColor(I[0],I[1],I[2],1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT),!n||!n.tex||!a||!a.tex)return;const r=A(e.nIn,e.ang),i=Fe(e.d);t.disable(t.DEPTH_TEST),t.disable(t.BLEND),t.useProgram(w),we(w,i,r),t.uniform3f(w.loc.uBg,I[0],I[1],I[2]),t.uniform1f(w.loc.uAlpha,e.alpha),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,a.tex),t.uniform1i(w.loc.uBase,0),t.bindBuffer(t.ARRAY_BUFFER,ne),t.enableVertexAttribArray(w.aPos),t.vertexAttribPointer(w.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(S),we(S,i,r),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,n.tex),t.uniform1i(S.loc.uFront,0),t.uniform3f(S.loc.uBack,n.back[0],n.back[1],n.back[2]),t.uniform1f(S.loc.uAlpha,e.alpha),t.bindBuffer(t.ARRAY_BUFFER,ee),t.enableVertexAttribArray(S.aPos),t.vertexAttribPointer(S.aPos,2,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,te),t.drawElements(t.TRIANGLES,y.length,t.UNSIGNED_SHORT,0)}let se=performance.now();function ye(n){if(!q)return;const a=Math.min(.05,(n-se)/1e3);se=n,it(a),st(),Q=requestAnimationFrame(ye)}const Le=new ResizeObserver(Ee);Le.observe(f.value);const j=matchMedia("(prefers-color-scheme: dark)");j.addEventListener&&j.addEventListener("change",Y);const ke=new MutationObserver(Y);ke.observe(document.documentElement,{attributes:!0}),Ee(),Y(),N=Math.min(3,Math.max(2,G*D));const lt=()=>o.cards.map(n=>`${n.bg}\0${n.back}\0${n.html}`).join(""),ct=c.watch(lt,()=>{ae(!0),v=0,e.d=0,e.mode="idle",e.alpha=1,e.peeled=!1,ve()});ve().then(()=>{q&&(Q=requestAnimationFrame(n=>{se=n,ye(n)}),he.push(setTimeout(Ae,900),setTimeout(Ae,8e3)))}),fe=()=>{q=!1,cancelAnimationFrame(Q),he.forEach(clearTimeout),ct(),Le.disconnect(),ke.disconnect(),j.removeEventListener&&j.removeEventListener("change",Y),m.removeEventListener("pointerdown",Pe),m.removeEventListener("pointermove",_e),m.removeEventListener("pointerup",W),m.removeEventListener("pointercancel",W),m.removeEventListener("keydown",Se),ae(!0),t.deleteBuffer(ee),t.deleteBuffer(te),t.deleteBuffer(ne),t.deleteProgram(S),t.deleteProgram(w);const n=t.getExtension("WEBGL_lose_context");n&&n.loseContext()},typeof window<"u"&&window.__PEEL_DEBUG__&&(window.__peelDebug=e)}return c.onMounted(je),c.onBeforeUnmount(()=>fe()),l({peel:()=>ue.peel()}),{root:f,canvas:M,noGL:F,focused:R,rootStyle:Ve,noGLStyle:Ye,canvasStyle:$e,onFocus:We}}},qe=["aria-label"];function ze(o,s,l,f,M,E){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]=(...R)=>f.onFocus&&f.onFocus(...R)),onBlur:s[1]||(s[1]=R=>f.focused=!1)},null,44,qe),f.noGL?(c.openBlock(),c.createElementBlock("div",{key:0,style:c.normalizeStyle(f.noGLStyle)},[c.renderSlot(o.$slots,"fallback",{},()=>[s[2]||(s[2]=c.createTextVNode("WebGL is not available in this browser.",-1))])],4)):c.createCommentVNode("",!0)],4)}const K=Ie(Xe,[["render",ze]]),He={install(o){o.component("PeelCard",K)}};x.PeelCard=K,x.PeelCardPlugin=He,x.default=K,Object.defineProperties(x,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-peel-card",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
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",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/Alick09/vue-peel-card.git"
|
|
10
|
+
},
|
|
7
11
|
"type": "module",
|
|
8
12
|
"main": "./dist/vue-peel-card.umd.cjs",
|
|
9
13
|
"module": "./dist/vue-peel-card.js",
|
package/src/PeelCard.vue
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
padding Number gap between the card and the component edges (16)
|
|
20
20
|
maxScale Number maximum zoom (1.35)
|
|
21
21
|
hint Boolean show a wiggle hint on start (true)
|
|
22
|
+
clickPeel Boolean a click or tap peels the card from the pressed edge (false)
|
|
22
23
|
label String aria-label of the canvas
|
|
23
24
|
Events
|
|
24
25
|
grab first touch of the card
|
|
@@ -178,6 +179,7 @@ export default {
|
|
|
178
179
|
padding: { type: Number, default: 16 },
|
|
179
180
|
maxScale: { type: Number, default: 1.35 },
|
|
180
181
|
hint: { type: Boolean, default: true },
|
|
182
|
+
clickPeel: { type: Boolean, default: false },
|
|
181
183
|
label: { type: String, default: 'Card: drag the edge to peel it off' },
|
|
182
184
|
},
|
|
183
185
|
emits: ['grab', 'peel', 'change', 'toggle'],
|
|
@@ -329,6 +331,7 @@ export default {
|
|
|
329
331
|
peeled: false, restick: false, pending: false, prog: false,
|
|
330
332
|
}
|
|
331
333
|
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
334
|
+
const tap = { ok: false, x: 0, y: 0 }
|
|
332
335
|
const CORNERS = [[-W / 2, -H / 2], [W / 2, -H / 2], [-W / 2, H / 2], [W / 2, H / 2]]
|
|
333
336
|
const proj = (g, u) => CORNERS.map(c => (c[0] - g[0]) * u[0] + (c[1] - g[1]) * u[1])
|
|
334
337
|
const tmaxOf = (g, u) => Math.max(...proj(g, u))
|
|
@@ -436,15 +439,26 @@ export default {
|
|
|
436
439
|
if (!st.interacted) emit('grab')
|
|
437
440
|
st.interacted = true
|
|
438
441
|
st.restick = false
|
|
442
|
+
tap.ok = true; tap.x = e.clientX; tap.y = e.clientY
|
|
439
443
|
beginDrag(p); st.mode = 'drag'
|
|
440
444
|
}
|
|
441
445
|
const onMove = e => {
|
|
442
446
|
if (st.mode !== 'drag') return
|
|
447
|
+
if (tap.ok && Math.hypot(e.clientX - tap.x, e.clientY - tap.y) > 8) tap.ok = false
|
|
443
448
|
const p = toUnits(e)
|
|
444
449
|
if (st.pending && !resolvePending(p)) return
|
|
445
450
|
updateTargets(p)
|
|
446
451
|
}
|
|
447
|
-
|
|
452
|
+
// clickPeel: a press that barely moved peels from the pressed edge
|
|
453
|
+
const onUp = e => {
|
|
454
|
+
if (props.clickPeel && e.type === 'pointerup' && tap.ok && st.mode === 'drag' && !st.restick) {
|
|
455
|
+
tap.ok = false; grabbing.value = false
|
|
456
|
+
st.d = 0; st.ang = 0; st.angT = PEEL_ANGLE * Math.PI / 180; st.prog = true
|
|
457
|
+
startComplete()
|
|
458
|
+
return
|
|
459
|
+
}
|
|
460
|
+
endDrag()
|
|
461
|
+
}
|
|
448
462
|
const onKey = e => { if (e.key === 'ArrowRight' || e.key === 'Enter' || e.key === ' ') { e.preventDefault(); peel() } }
|
|
449
463
|
cv.addEventListener('pointerdown', onDown)
|
|
450
464
|
cv.addEventListener('pointermove', onMove)
|