@zinejs/core 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ //#region src/geometry/curls/types.ts
2
+ var e = [
3
+ "roll",
4
+ "cone",
5
+ "leaf",
6
+ "flick",
7
+ "silk",
8
+ "simple"
9
+ ], t = "cone";
10
+ //#endregion
11
+ export { t as n, e as t };
12
+
13
+ //# sourceMappingURL=types-CcPVyhOJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-CcPVyhOJ.js","names":[],"sources":["../src/geometry/curls/types.ts"],"sourcesContent":["/**\n * Curl type identifiers and the deform contract. Kept free of the deform\n * implementations so the engine (and CSS-only builds) can reference the union and the\n * validation list without pulling the WebGL-only curl math into the eager bundle.\n */\nimport type { PageMesh } from './mesh';\n\n/** Where a corner-anchored curl folds from: y in [0,1], 0 = top edge, 1 = bottom edge. */\nexport interface CurlAnchor {\n y: number;\n /**\n * Full-width lone page (single-page mode). The leaf hinges at the container edge and\n * has no facing half to land on — deforms may soften and delay the flop so the curl\n * reads naturally before the renderer dissolves the sheet.\n */\n fill?: boolean;\n}\n\nexport type CurlDeform = (mesh: PageMesh, W: number, H: number, t: number, anchor: CurlAnchor) => void;\n\nexport interface CurlModel {\n readonly deform: CurlDeform;\n /** True when the fold originates at a corner (`anchor.y`) rather than the whole edge. */\n readonly anchored: boolean;\n}\n\nexport type CurlType = 'roll' | 'cone' | 'leaf' | 'flick' | 'silk' | 'simple';\n\nexport const CURL_TYPES: CurlType[] = ['roll', 'cone', 'leaf', 'flick', 'silk', 'simple'];\n\nexport const DEFAULT_CURL: CurlType = 'cone';\n"],"mappings":";AA4BA,IAAa,IAAyB;CAAC;CAAQ;CAAQ;CAAQ;CAAS;CAAQ;AAAQ,GAE3E,IAAyB"}
@@ -1,4 +1,4 @@
1
- import { n as e } from "./types-Bz64qLvE.js";
1
+ import { n as e } from "./types-CcPVyhOJ.js";
2
2
  //#region src/geometry/curls/mesh.ts
3
3
  function t(e, t) {
4
4
  let n = e + 1, r = t + 1, i = n * r, a = new Float32Array(i * 2);
@@ -37,95 +37,186 @@ function r(e, t, r, i) {
37
37
  n(e);
38
38
  }
39
39
  //#endregion
40
- //#region src/geometry/curls/simple.ts
41
- function i(e, t, r, i) {
42
- let a = e.cols + 1, o = e.rows + 1, s = e.positions, c = i * Math.PI, l = Math.cos(c), u = Math.sin(c);
43
- for (let n = 0; n < a; n++) {
44
- let i = n / e.cols * t, c = i * l, d = i * u;
45
- for (let t = 0; t < o; t++) {
46
- let i = (t * a + n) * 3;
47
- s[i] = c, s[i + 1] = t / e.rows * r, s[i + 2] = d;
40
+ //#region src/geometry/curls/cone.ts
41
+ var i = 30 * Math.PI / 180, a = 44 * Math.PI / 180, o = 1.35, s = .7, c = 1.85, l = 1.15, u = .42, d = 1.08;
42
+ function f(e, t, r, f, p) {
43
+ let m = e.cols + 1, h = e.rows + 1, g = e.positions, _ = !!p.fill, v = Math.sin(Math.PI * f) ** .85, y = _ ? a : i, b = Math.PI / 2 - v * (Math.PI / 2 - y), x = Math.sin(b), S = Math.cos(b), C = 1 / Math.max(x, 1e-6), w = _ ? c : o, T = r * (w + ((_ ? l : s) - w) * v), E = (p.y - .5) * 2, D = E >= 0, O = Math.min(1, Math.abs(E) / u), k = 1 - O, A = D ? r + T : -T, j = Math.hypot(t, .5 * r - A), M = Math.max(j * x, t / Math.PI), N = _ ? f ** +d : f, P = -Math.PI * N, F = Math.cos(P), I = Math.sin(P);
44
+ if (v < 1e-4) {
45
+ for (let n = 0; n < h; n++) {
46
+ let i = n / e.rows * r;
47
+ for (let r = 0; r < m; r++) {
48
+ let a = r / e.cols * t, o = (n * m + r) * 3;
49
+ g[o] = a * F, g[o + 1] = i, g[o + 2] = -a * I;
50
+ }
48
51
  }
52
+ n(e);
53
+ return;
49
54
  }
50
- n(e);
51
- }
52
- function a(e, t, r, i) {
53
- let a = e.cols + 1, o = e.rows + 1, s = e.positions, c = i * Math.PI, l = Math.max(.001, 1.6 * Math.sin(Math.PI * i)), u = t / l, d = Math.sin(c), f = Math.cos(c);
54
- for (let n = 0; n < a; n++) {
55
- let i = c + l * (n / e.cols * t / t), p = u * (Math.sin(i) - d), m = u * (f - Math.cos(i));
56
- for (let t = 0; t < o; t++) {
57
- let i = (t * a + n) * 3;
58
- s[i] = p, s[i + 1] = t / e.rows * r, s[i + 2] = m;
55
+ for (let n = 0; n < h; n++) {
56
+ let i = n / e.rows * r;
57
+ for (let a = 0; a < m; a++) {
58
+ let o = a / e.cols * t, s = o, c = i, l = 0;
59
+ if (O > 1e-5) {
60
+ let e = D ? r - i : i, t = -T, n = Math.hypot(o, e - t);
61
+ if (n > 1e-8) {
62
+ let e = n * x, i = Math.asin(Math.min(1, Math.max(0, o / n))) * C, a = 1 - Math.cos(i), u = n + t - e * a * x;
63
+ s = e * Math.sin(i), c = D ? r - u : u, l = e * a * S;
64
+ }
65
+ }
66
+ let u = s, d = c, f = l;
67
+ if (k > 1e-5) {
68
+ let e = o / M, t = M * Math.sin(e), n = M * (1 - Math.cos(e));
69
+ u = O * s + k * t, d = O * c + k * i, f = O * l + k * n;
70
+ }
71
+ let p = (n * m + a) * 3;
72
+ g[p] = u * F + f * I, g[p + 1] = d, g[p + 2] = -u * I + f * F;
59
73
  }
60
74
  }
61
75
  n(e);
62
76
  }
63
77
  //#endregion
64
- //#region src/geometry/curls/fold.ts
65
- var o = .04, s = .6;
66
- function c(e, t, r, i, a) {
67
- let c = e.cols + 1, l = e.rows + 1, u = e.positions, d = Math.max(1e-4, o * t), f = a.y * r, p = t - 2 * t * i, m = f + (.5 * r - f) * s * Math.sin(Math.PI * i), h = t - p, g = f - m, _ = Math.hypot(h, g);
68
- if (_ < 1e-4) {
69
- for (let n = 0; n < l; n++) for (let i = 0; i < c; i++) {
70
- let a = (n * c + i) * 3;
71
- u[a] = i / e.cols * t, u[a + 1] = n / e.rows * r, u[a + 2] = 0;
78
+ //#region src/geometry/curls/leaf.ts
79
+ var p = .34, m = 11 * Math.PI / 180, h = 128;
80
+ function g() {
81
+ let e = /* @__PURE__ */ new Float64Array(129), t = /* @__PURE__ */ new Float64Array(129), n = 1 / h, r = (e) => Math.PI * e - .5 * Math.sin(2 * Math.PI * e);
82
+ for (let i = 1; i <= h; i++) {
83
+ let a = r((i - 1) * n), o = r(i * n);
84
+ e[i] = e[i - 1] + .5 * (Math.cos(a) + Math.cos(o)) * n, t[i] = t[i - 1] + .5 * (Math.sin(a) + Math.sin(o)) * n;
85
+ }
86
+ return e[h] = 0, {
87
+ x: e,
88
+ z: t
89
+ };
90
+ }
91
+ var _ = g(), v = _.z[h];
92
+ function y(e) {
93
+ let t = Math.max(0, Math.min(1, e)) * h, n = Math.min(h - 1, Math.floor(t)), r = t - n;
94
+ return [_.x[n] + (_.x[n + 1] - _.x[n]) * r, _.z[n] + (_.z[n + 1] - _.z[n]) * r];
95
+ }
96
+ function b(e, t, r, i, a) {
97
+ let o = e.cols + 1, s = e.rows + 1, c = e.positions;
98
+ if (i <= 1e-7 || i >= .9999999) {
99
+ let a = i < .5 ? 1 : -1;
100
+ for (let n = 0; n < s; n++) {
101
+ let i = n / e.rows * r;
102
+ for (let r = 0; r < o; r++) {
103
+ let s = (n * o + r) * 3;
104
+ c[s] = a * (r / e.cols) * t, c[s + 1] = i, c[s + 2] = 0;
105
+ }
72
106
  }
73
107
  n(e);
74
108
  return;
75
109
  }
76
- let v = h / _, y = g / _, b = -y, x = v, S = (t + p) / 2, C = (f + m) / 2;
77
- for (let n = 0; n < l; n++) {
110
+ let l = Math.sin(Math.PI * i) ** .72, u = Math.max(1e-6, t * p * l), d = Math.max(-1, Math.min(1, (a.y - .5) * 2)) * m * Math.sin(Math.PI * i) ** 1.15, f = Math.cos(d), h = Math.sin(d), g = -h, _ = f, b = Math.abs(h) * r * .5, x = t + b / f, S = x + (-(u + b) / f - x) * i, C = r * .5;
111
+ for (let n = 0; n < s; n++) {
78
112
  let i = n / e.rows * r;
79
- for (let r = 0; r < c; r++) {
80
- let a = r / e.cols * t, o = a - S, s = i - C, l = o * v + s * y, f = o * b + s * x, p = (n * c + r) * 3;
81
- if (l <= 0) {
82
- u[p] = a, u[p + 1] = i, u[p + 2] = 0;
113
+ for (let r = 0; r < o; r++) {
114
+ let a = r / e.cols * t, s = a - S, l = i - C, d = s * f + l * h, p = s * g + l * _, m = (n * o + r) * 3;
115
+ if (d <= 0) {
116
+ c[m] = a, c[m + 1] = i, c[m + 2] = 0;
83
117
  continue;
84
118
  }
85
- let m = Math.min(l / d, Math.PI), h = Math.max(0, l - d * Math.PI), g = d * Math.sin(m) - h;
86
- u[p] = S + b * f + v * g, u[p + 1] = C + x * f + y * g, u[p + 2] = d * (1 - Math.cos(m));
119
+ let b, x;
120
+ if (d < u) {
121
+ let [e, t] = y(d / u);
122
+ b = u * e, x = u * t;
123
+ } else b = -(d - u), x = u * v;
124
+ c[m] = S + g * p + f * b, c[m + 1] = C + _ * p + h * b, c[m + 2] = x;
87
125
  }
88
126
  }
89
127
  n(e);
90
128
  }
91
129
  //#endregion
92
- //#region src/geometry/curls/peel.ts
93
- var l = .7;
94
- function u(e, t, r, i, a) {
95
- let o = e.cols + 1, s = e.rows + 1, c = e.positions;
96
- for (let n = 0; n < s; n++) {
97
- let s = n / e.rows, u = Math.abs(s - a.y), d = Math.min(1, Math.max(0, i * 1.7 - l * u)), f = Math.max(1e-6, d < .5 ? d * 2 * Math.PI : (1 - (d - .5) * 2) * Math.PI), p = t / f, m = d < .5 ? 0 : -(d - .5) * 2 * Math.PI, h = Math.cos(m), g = Math.sin(m), _ = s * r;
130
+ //#region src/geometry/curls/flick.ts
131
+ var x = .45;
132
+ function S(e, t, r, i, a) {
133
+ let o = e.cols + 1, s = e.rows + 1, c = e.cols, l = e.positions, u = t / c, d = Math.PI * i, f = -.52 * Math.sin(2 * Math.PI * i);
134
+ for (let t = 0; t < s; t++) {
135
+ let n = t / e.rows, i = f * (1 + x * Math.abs(n - a.y)), s = n * r, p = 0, m = 0, h = Math.cos(d), g = Math.sin(d);
136
+ l[t * o * 3] = 0, l[t * o * 3 + 1] = s, l[t * o * 3 + 2] = 0;
137
+ for (let e = 1; e < o; e++) {
138
+ let n = e / c, r = d + i * n * n, a = Math.cos(r), f = Math.sin(r);
139
+ p += .5 * (h + a) * u, m += .5 * (g + f) * u, h = a, g = f;
140
+ let _ = (t * o + e) * 3;
141
+ l[_] = p, l[_ + 1] = s, l[_ + 2] = m;
142
+ }
143
+ }
144
+ n(e);
145
+ }
146
+ //#endregion
147
+ //#region src/geometry/curls/silk.ts
148
+ var C = .52, w = .62, T = .5, E = 1.12;
149
+ function D(e, t, r, i, a) {
150
+ let o = e.cols + 1, s = e.rows + 1, c = e.cols, l = e.positions, u = t / c, d = !!a.fill;
151
+ if (i <= 1e-7 || i >= .9999999) {
152
+ let a = i < .5 ? 1 : -1;
153
+ for (let n = 0; n < s; n++) {
154
+ let i = n / e.rows * r;
155
+ for (let r = 0; r < o; r++) {
156
+ let s = (n * o + r) * 3;
157
+ l[s] = a * (r / e.cols) * t, l[s + 1] = i, l[s + 2] = 0;
158
+ }
159
+ }
160
+ n(e);
161
+ return;
162
+ }
163
+ let f = Math.PI * (d ? i ** +E : i), p = C * Math.sin(Math.PI * i) ** .8, m = w * Math.sin(Math.PI * i) * (1 - i);
164
+ for (let t = 0; t < s; t++) {
165
+ let n = t / e.rows, i = n * r, s = 1 - T * Math.abs(n - a.y), d = p * (.75 + .25 * s), h = m * s, g = 0, _ = 0, v = Math.cos(f), y = Math.sin(f);
166
+ l[t * o * 3] = 0, l[t * o * 3 + 1] = i, l[t * o * 3 + 2] = 0;
167
+ for (let e = 1; e < o; e++) {
168
+ let n = e / c, r = f + d * Math.sin(2 * Math.PI * n) + h * n * n, a = Math.cos(r), s = Math.sin(r);
169
+ g += .5 * (v + a) * u, _ += .5 * (y + s) * u, v = a, y = s;
170
+ let p = (t * o + e) * 3;
171
+ l[p] = g, l[p + 1] = i, l[p + 2] = _;
172
+ }
173
+ }
174
+ n(e);
175
+ }
176
+ //#endregion
177
+ //#region src/geometry/curls/simple.ts
178
+ function O(e, t, r, i) {
179
+ let a = e.cols + 1, o = e.rows + 1, s = e.positions, c = i * Math.PI, l = Math.cos(c), u = Math.sin(c);
180
+ for (let n = 0; n < a; n++) {
181
+ let i = n / e.cols * t, c = i * l, d = i * u;
98
182
  for (let t = 0; t < o; t++) {
99
- let r = t / e.cols * f, i = Math.sin(r) * p, a = (1 - Math.cos(r)) * p, s = (n * o + t) * 3;
100
- c[s] = i * h + a * g, c[s + 1] = _, c[s + 2] = -i * g + a * h;
183
+ let i = (t * a + n) * 3;
184
+ s[i] = c, s[i + 1] = t / e.rows * r, s[i + 2] = d;
101
185
  }
102
186
  }
103
187
  n(e);
104
188
  }
105
189
  //#endregion
106
190
  //#region src/geometry/curls/index.ts
107
- var d = {
191
+ var k = {
108
192
  roll: {
109
193
  deform: r,
110
- deformFill: a,
111
194
  anchored: !1
112
195
  },
113
- simple: {
114
- deform: i,
115
- anchored: !1
196
+ cone: {
197
+ deform: f,
198
+ anchored: !0
199
+ },
200
+ leaf: {
201
+ deform: b,
202
+ anchored: !0
116
203
  },
117
- fold: {
118
- deform: c,
204
+ flick: {
205
+ deform: S,
119
206
  anchored: !0
120
207
  },
121
- peel: {
122
- deform: u,
208
+ silk: {
209
+ deform: D,
123
210
  anchored: !0
211
+ },
212
+ simple: {
213
+ deform: O,
214
+ anchored: !1
124
215
  }
125
216
  };
126
217
  //#endregion
127
218
  //#region src/renderer/gl/context.ts
128
- function f(e) {
219
+ function A(e) {
129
220
  let t = e.getContext("webgl2", {
130
221
  alpha: !0,
131
222
  premultipliedAlpha: !0,
@@ -139,17 +230,17 @@ function f(e) {
139
230
  }
140
231
  //#endregion
141
232
  //#region src/renderer/gl/program.ts
142
- function p(e, t, n) {
233
+ function j(e, t, n) {
143
234
  let r = e.createProgram();
144
235
  if (r === null) throw Error("WebglRenderer: could not create a program.");
145
- let i = m(e, e.VERTEX_SHADER, t), a = m(e, e.FRAGMENT_SHADER, n);
236
+ let i = M(e, e.VERTEX_SHADER, t), a = M(e, e.FRAGMENT_SHADER, n);
146
237
  if (e.attachShader(r, i), e.attachShader(r, a), e.linkProgram(r), e.deleteShader(i), e.deleteShader(a), !e.getProgramParameter(r, e.LINK_STATUS)) {
147
238
  let t = e.getProgramInfoLog(r);
148
239
  throw e.deleteProgram(r), Error(`WebglRenderer: program link failed: ${t ?? "unknown error"}`);
149
240
  }
150
241
  return r;
151
242
  }
152
- function m(e, t, n) {
243
+ function M(e, t, n) {
153
244
  let r = e.createShader(t);
154
245
  if (r === null) throw Error("WebglRenderer: could not create a shader.");
155
246
  if (e.shaderSource(r, n), e.compileShader(r), !e.getShaderParameter(r, e.COMPILE_STATUS)) {
@@ -160,21 +251,21 @@ function m(e, t, n) {
160
251
  }
161
252
  //#endregion
162
253
  //#region src/renderer/gl/texture.ts
163
- function h(e) {
254
+ function N(e) {
164
255
  let t = e.createTexture();
165
256
  if (t === null) throw Error("WebglRenderer: could not create a texture.");
166
257
  return e.bindTexture(e.TEXTURE_2D, t), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_S, e.CLAMP_TO_EDGE), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_T, e.CLAMP_TO_EDGE), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MIN_FILTER, e.LINEAR), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MAG_FILTER, e.LINEAR), t;
167
258
  }
168
- function g(e, t, n) {
259
+ function P(e, t, n) {
169
260
  e.bindTexture(e.TEXTURE_2D, t), e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL, !1), e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !0), e.texImage2D(e.TEXTURE_2D, 0, e.RGBA, e.RGBA, e.UNSIGNED_BYTE, n);
170
261
  }
171
262
  //#endregion
172
263
  //#region src/renderer/webglRenderer.ts
173
- var _ = "#version 300 es\nin vec2 aUnit;\nuniform vec2 uViewport;\nuniform vec4 uRect;\nuniform vec3 uView;\nout vec2 vUv;\nvoid main() {\n vec2 px = uRect.xy + aUnit * uRect.zw;\n px = px * uView.x + uView.yz;\n vec2 clip = px / uViewport * 2.0 - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n vUv = aUnit;\n}", v = "#version 300 es\nprecision mediump float;\nin vec2 vUv;\nuniform sampler2D uTex;\nuniform float uGutterSide; // +1 = spine at right edge, -1 = at left edge, 0 = none\nout vec4 outColor;\nvoid main() {\n vec4 c = texture(uTex, vUv);\n if (uGutterSide != 0.0) {\n float d = uGutterSide > 0.0 ? (1.0 - vUv.x) : vUv.x;\n c.rgb *= mix(0.72, 1.0, smoothstep(0.0, 0.10, d));\n }\n outColor = c;\n}", y = "#version 300 es\nin vec3 aPos; // leaf-local device px: x = bent offset from spine, y 0..H, z depth\nin vec3 aNormal;\nin vec2 aUv;\nuniform vec2 uViewport;\nuniform vec3 uView; // scale, tx, ty\nuniform float uOriginX; // spine x in device px\nuniform float uDir; // +1 leaf to the right of spine, -1 to the left\nuniform float uLeafW; // leaf width in device px (perspective scale)\nout vec2 vUv;\nout float vFacing;\nout float vU;\nvoid main() {\n float bookX = uOriginX + uDir * aPos.x;\n float bookY = aPos.y;\n float Z = aPos.z;\n float D = uLeafW * 3.0;\n float persp = D / max(D - Z, 1.0);\n float cx = uViewport.x * 0.5;\n float cy = uViewport.y * 0.5;\n float px = cx + (bookX - cx) * persp;\n float py = cy + (bookY - cy) * min(persp, 1.0); // Y only shrinks (top-safe)\n vec2 p = vec2(px, py) * uView.x + uView.yz;\n vec2 clip = p / uViewport * 2.0 - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n vUv = aUv;\n vFacing = aNormal.z;\n vU = aUv.x;\n}", b = "#version 300 es\nprecision mediump float;\nin vec2 vUv;\nin float vFacing;\nin float vU;\nuniform sampler2D uFront;\nuniform sampler2D uBack;\nuniform highp float uDir;\nuniform float uGloss; // 0 disables the specular highlight (e.g. the flat 'simple' curl)\nout vec4 outColor;\nvoid main() {\n // The turn mesh carries its own facing in the normal; the front points at the viewer\n // (normal.z > 0) until the leaf passes vertical, for both flip directions. u->x still\n // flips with uDir so a left-hand leaf reads spine-inward.\n bool showFront = vFacing > 0.0;\n float fx = uDir > 0.0 ? vUv.x : 1.0 - vUv.x;\n vec4 c = showFront ? texture(uFront, vec2(fx, vUv.y)) : texture(uBack, vec2(1.0 - fx, vUv.y));\n\n // Fold shading: the sheet darkens sharply where it curves away from the viewer, so the\n // rolled edge reads as a deep crease with a soft highlight riding the ridge.\n float diff = clamp(abs(vFacing), 0.0, 1.0);\n float lit = mix(0.42, 1.0, diff);\n lit *= mix(0.7, 1.0, smoothstep(0.0, 0.12, vU)); // spine crease matches the gutter shadow\n\n // Glossy specular: brightest where the surface tilts ~30 deg from facing the viewer,\n // so a thin glossy highlight rides across the sheet as it rolls.\n float spec = pow(max(cos(acos(diff) - 0.52), 0.0), 220.0) * 0.22 * uGloss;\n\n c.rgb = clamp(c.rgb * lit + spec, 0.0, 1.0);\n outColor = c;\n}", x = 28, S = 36, C = 4e3, w = 256 * 1024 * 1024;
174
- function T(e) {
264
+ var F = "#version 300 es\nin vec2 aUnit;\nuniform vec2 uViewport;\nuniform vec4 uRect;\nuniform vec3 uView;\nout vec2 vUv;\nvoid main() {\n vec2 px = uRect.xy + aUnit * uRect.zw;\n px = px * uView.x + uView.yz;\n vec2 clip = px / uViewport * 2.0 - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n vUv = aUnit;\n}", I = "#version 300 es\nprecision mediump float;\nin vec2 vUv;\nuniform sampler2D uTex;\nuniform float uGutterSide; // +1 = spine at right edge, -1 = at left edge, 0 = none\nout vec4 outColor;\nvoid main() {\n vec4 c = texture(uTex, vUv);\n if (uGutterSide != 0.0) {\n float d = uGutterSide > 0.0 ? (1.0 - vUv.x) : vUv.x;\n c.rgb *= mix(0.72, 1.0, smoothstep(0.0, 0.10, d));\n }\n outColor = c;\n}", L = "#version 300 es\nin vec3 aPos; // leaf-local device px: x = bent offset from spine, y 0..H, z depth\nin vec3 aNormal;\nin vec2 aUv;\nuniform vec2 uViewport;\nuniform vec3 uView; // scale, tx, ty\nuniform float uOriginX; // spine x in device px\nuniform float uDir; // +1 leaf to the right of spine, -1 to the left\nuniform float uLeafW; // leaf width in device px (perspective scale)\nout vec2 vUv;\nout float vFacing;\nout float vU;\nvoid main() {\n float bookX = uOriginX + uDir * aPos.x;\n float bookY = aPos.y;\n float Z = aPos.z;\n // Eye distance, in leaf widths. Keeps the perspective resolution-independent. 5.3 puts the\n // roll's deepest point ~14% larger than flat; stronger than that (a nearer eye) balloons the\n // turning sheet and reads more like a fisheye than a page lifting.\n float D = uLeafW * 5.3;\n float persp = D / max(D - Z, 1.0);\n float cx = uViewport.x * 0.5;\n float cy = uViewport.y * 0.5;\n float px = cx + (bookX - cx) * persp;\n float py = cy + (bookY - cy) * min(persp, 1.0); // Y only shrinks (top-safe)\n vec2 p = vec2(px, py) * uView.x + uView.yz;\n vec2 clip = p / uViewport * 2.0 - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n vUv = aUv;\n vFacing = aNormal.z;\n vU = aUv.x;\n}", R = "#version 300 es\nprecision mediump float;\nin vec2 vUv;\nin float vFacing;\nin float vU;\nuniform sampler2D uFront;\nuniform sampler2D uBack;\nuniform highp float uDir;\nuniform float uGloss; // 0 disables the specular highlight (e.g. the flat 'simple' curl)\nuniform float uAlpha; // leaf opacity; a lone page dissolves into the page landing beneath it\nout vec4 outColor;\nvoid main() {\n // The turn mesh carries its own facing in the normal; the front points at the viewer\n // (normal.z > 0) until the leaf passes vertical, for both flip directions. u->x still\n // flips with uDir so a left-hand leaf reads spine-inward.\n bool showFront = vFacing > 0.0;\n float fx = uDir > 0.0 ? vUv.x : 1.0 - vUv.x;\n vec4 c = showFront ? texture(uFront, vec2(fx, vUv.y)) : texture(uBack, vec2(1.0 - fx, vUv.y));\n\n // Fold shading: the sheet darkens sharply where it curves away from the viewer, so the\n // rolled edge reads as a deep crease with a soft highlight riding the ridge.\n float diff = clamp(abs(vFacing), 0.0, 1.0);\n float lit = mix(0.42, 1.0, diff);\n lit *= mix(0.7, 1.0, smoothstep(0.0, 0.12, vU)); // spine crease matches the gutter shadow\n\n // Glossy specular: brightest where the surface tilts ~30 deg from facing the viewer,\n // so a thin glossy highlight rides across the sheet as it rolls.\n float spec = pow(max(cos(acos(diff) - 0.52), 0.0), 220.0) * 0.22 * uGloss;\n\n c.rgb = clamp(c.rgb * lit + spec, 0.0, 1.0);\n // Premultiplied alpha (blendFunc ONE, ONE_MINUS_SRC_ALPHA): scale colour as well as alpha,\n // or fading would brighten the sheet additively instead of dissolving it.\n outColor = vec4(c.rgb * uAlpha, c.a * uAlpha);\n}", z = 28, B = 36, V = .7, H = .8, U = 4e3, W = 256 * 1024 * 1024;
265
+ function G(e) {
175
266
  return e.left === null == (e.right === null) ? 0 : e.right === null ? 1 : -1;
176
267
  }
177
- var E = class {
268
+ var K = class {
178
269
  #e = null;
179
270
  #t = null;
180
271
  #n = null;
@@ -185,7 +276,7 @@ var E = class {
185
276
  #s = null;
186
277
  #c = null;
187
278
  #l = 0;
188
- #u = t(x, S);
279
+ #u = t(z, B);
189
280
  #d = /* @__PURE__ */ new Map();
190
281
  #f = 0;
191
282
  #p = null;
@@ -216,7 +307,7 @@ var E = class {
216
307
  mount(e) {
217
308
  this.#e = e;
218
309
  let t = e.ownerDocument, n = t.createElement("canvas");
219
- return n.style.cssText = "display:block;width:100%;height:100%;", e.append(n), this.#t = n, n.addEventListener("webglcontextlost", this.#L), n.addEventListener("webglcontextrestored", this.#R), t.addEventListener("visibilitychange", this.#z), this.#n = f(n), this.#H(), Promise.resolve();
310
+ return n.style.cssText = "display:block;width:100%;height:100%;", e.append(n), this.#t = n, n.addEventListener("webglcontextlost", this.#L), n.addEventListener("webglcontextrestored", this.#R), t.addEventListener("visibilitychange", this.#z), this.#n = A(n), this.#H(), Promise.resolve();
220
311
  }
221
312
  destroy() {
222
313
  this.#V();
@@ -241,7 +332,7 @@ var E = class {
241
332
  }
242
333
  beginFlip(e, t, n, r) {
243
334
  let i = r?.fill ?? !1;
244
- this.#x = 0, r?.curl && (this.#S = r.curl), r?.anchor && (this.#C = r.anchor), this.#T = i ? 0 : T(e), this.#E = i ? 0 : T(t), this.#P(t), i ? this.#b = {
335
+ this.#x = 0, r?.curl && (this.#S = r.curl), r?.anchor && (this.#C = r.anchor), this.#T = i ? 0 : G(e), this.#E = i ? 0 : G(t), this.#P(t), i ? this.#b = {
245
336
  underLeft: null,
246
337
  underRight: null,
247
338
  underFull: t.right ?? t.left,
@@ -306,7 +397,7 @@ var E = class {
306
397
  }
307
398
  #I() {
308
399
  let e = this.#F();
309
- return !this.#y && this.#v !== null && T(this.#v) !== 0 ? {
400
+ return !this.#y && this.#v !== null && G(this.#v) !== 0 ? {
310
401
  x: e.x + e.width / 4,
311
402
  y: e.y,
312
403
  width: e.width / 2,
@@ -314,7 +405,7 @@ var E = class {
314
405
  } : e;
315
406
  }
316
407
  #L = (e) => {
317
- e.preventDefault(), this.#A = !0, this.#M === null && (this.#M = setTimeout(() => this.#B(), C));
408
+ e.preventDefault(), this.#A = !0, this.#M === null && (this.#M = setTimeout(() => this.#B(), U));
318
409
  };
319
410
  #R = () => {
320
411
  this.#V(), this.#A = !1, this.#H(), this.#G();
@@ -331,7 +422,7 @@ var E = class {
331
422
  #H() {
332
423
  let e = this.#n;
333
424
  if (e !== null) {
334
- this.#r = p(e, _, v), this.#i = p(e, y, b);
425
+ this.#r = j(e, F, I), this.#i = j(e, L, R);
335
426
  for (let t of [
336
427
  "uViewport",
337
428
  "uRect",
@@ -347,9 +438,10 @@ var E = class {
347
438
  "uLeafW",
348
439
  "uFront",
349
440
  "uBack",
350
- "uGloss"
441
+ "uGloss",
442
+ "uAlpha"
351
443
  ]) this.#h[t] = e.getUniformLocation(this.#i, t);
352
- this.#a = this.#U(e, this.#r), this.#W(e, this.#i), this.#d.clear(), this.#f = 0, this.#p = this.#ee(e), e.useProgram(this.#r), e.uniform1i(this.#m.uTex ?? null, 0), e.useProgram(this.#i), e.uniform1i(this.#h.uFront ?? null, 0), e.uniform1i(this.#h.uBack ?? null, 1), e.clearColor(0, 0, 0, 0), e.enable(e.BLEND), e.blendFunc(e.ONE, e.ONE_MINUS_SRC_ALPHA);
444
+ this.#a = this.#U(e, this.#r), this.#W(e, this.#i), this.#d.clear(), this.#f = 0, this.#p = this.#te(e), e.useProgram(this.#r), e.uniform1i(this.#m.uTex ?? null, 0), e.useProgram(this.#i), e.uniform1i(this.#h.uFront ?? null, 0), e.uniform1i(this.#h.uBack ?? null, 1), e.clearColor(0, 0, 0, 0), e.enable(e.BLEND), e.blendFunc(e.ONE, e.ONE_MINUS_SRC_ALPHA);
353
445
  }
354
446
  }
355
447
  #U(e, t) {
@@ -370,7 +462,7 @@ var E = class {
370
462
  }
371
463
  #W(e, t) {
372
464
  let n = [];
373
- for (let e = 0; e < S; e++) for (let t = 0; t < x; t++) {
465
+ for (let e = 0; e < B; e++) for (let t = 0; t < z; t++) {
374
466
  let r = e * 29 + t, i = r + 1, a = r + 29, o = a + 1;
375
467
  n.push(r, a, i, i, a, o);
376
468
  }
@@ -389,7 +481,7 @@ var E = class {
389
481
  }
390
482
  #G() {
391
483
  let e = this.#n, t = this.#t;
392
- e === null || t === null || this.#A || e.isContextLost() || (this.#te(), e.clear(e.COLOR_BUFFER_BIT), this.#K(), this.#b === null ? this.#v !== null && this.#q() : this.#J());
484
+ e === null || t === null || this.#A || e.isContextLost() || (this.#ne(), e.clear(e.COLOR_BUFFER_BIT), this.#K(), this.#b === null ? this.#v !== null && this.#q() : this.#J());
393
485
  }
394
486
  #K() {
395
487
  let e = this.#n, t = this.#t, n = t.width, r = t.height;
@@ -402,17 +494,17 @@ var E = class {
402
494
  }
403
495
  #q() {
404
496
  let e = this.#O, t = this.#k, n = this.#v;
405
- this.#w = this.#y ? 0 : T(n) * (e / 4), this.#Y(), this.#y ? this.#X({
497
+ this.#w = this.#y ? 0 : G(n) * (e / 4), this.#X(), this.#y ? this.#Z({
406
498
  x: 0,
407
499
  y: 0,
408
500
  w: e,
409
501
  h: t
410
- }, n.right ?? n.left) : (this.#X({
502
+ }, n.right ?? n.left) : (this.#Z({
411
503
  x: 0,
412
504
  y: 0,
413
505
  w: e / 2,
414
506
  h: t
415
- }, n.left, +!!n.right), this.#X({
507
+ }, n.left, +!!n.right), this.#Z({
416
508
  x: e / 2,
417
509
  y: 0,
418
510
  w: e / 2,
@@ -421,57 +513,64 @@ var E = class {
421
513
  }
422
514
  #J() {
423
515
  let e = this.#n, t = this.#O, n = this.#k, r = this.#b;
424
- if (this.#w = r.fill ? 0 : (this.#T + (this.#E - this.#T) * this.#x) * (t / 4), this.#Y(), r.fill ? this.#X({
516
+ if (this.#w = r.fill ? 0 : (this.#T + (this.#E - this.#T) * this.#x) * (t / 4), this.#X(), r.fill ? this.#Z({
425
517
  x: 0,
426
518
  y: 0,
427
519
  w: t,
428
520
  h: n
429
- }, r.underFull) : (this.#X({
521
+ }, r.underFull) : (this.#Z({
430
522
  x: 0,
431
523
  y: 0,
432
524
  w: t / 2,
433
525
  h: n
434
- }, r.underLeft, 1), this.#X({
526
+ }, r.underLeft, 1), this.#Z({
435
527
  x: t / 2,
436
528
  y: 0,
437
529
  w: t / 2,
438
530
  h: n
439
531
  }, r.underRight, -1)), r.front === null && r.back === null) return;
440
- let i = r.fill ? t : t / 2, a = r.fill ? r.dir > 0 ? 0 : t : t / 2, o = d[this.#S];
441
- (r.fill && o.deformFill ? o.deformFill : o.deform)(this.#u, i, n, this.#x, this.#C), e.bindBuffer(e.ARRAY_BUFFER, this.#s), e.bufferSubData(e.ARRAY_BUFFER, 0, this.#u.positions), e.bindBuffer(e.ARRAY_BUFFER, this.#c), e.bufferSubData(e.ARRAY_BUFFER, 0, this.#u.normals), this.#Z(e.TEXTURE0, r.front), this.#Z(e.TEXTURE1, r.back), e.activeTexture(e.TEXTURE0), e.useProgram(this.#i), e.bindVertexArray(this.#o), e.uniform2f(this.#h.uViewport ?? null, t, n), e.uniform3f(this.#h.uView ?? null, this.#g.scale, this.#g.tx * this.#_ + this.#w, this.#g.ty * this.#_), e.uniform1f(this.#h.uOriginX ?? null, a), e.uniform1f(this.#h.uDir ?? null, r.dir), e.uniform1f(this.#h.uLeafW ?? null, i), e.uniform1f(this.#h.uGloss ?? null, this.#S === "simple" ? 0 : 1), e.drawElements(e.TRIANGLES, this.#l, e.UNSIGNED_SHORT, 0);
532
+ let i = r.fill ? t : t / 2, a = r.fill ? r.dir > 0 ? 0 : t : t / 2;
533
+ k[this.#S].deform(this.#u, i, n, this.#x, {
534
+ y: this.#C.y,
535
+ fill: r.fill
536
+ }), e.bindBuffer(e.ARRAY_BUFFER, this.#s), e.bufferSubData(e.ARRAY_BUFFER, 0, this.#u.positions), e.bindBuffer(e.ARRAY_BUFFER, this.#c), e.bufferSubData(e.ARRAY_BUFFER, 0, this.#u.normals), this.#Q(e.TEXTURE0, r.front), this.#Q(e.TEXTURE1, r.back), e.activeTexture(e.TEXTURE0), e.useProgram(this.#i), e.bindVertexArray(this.#o), e.uniform2f(this.#h.uViewport ?? null, t, n), e.uniform3f(this.#h.uView ?? null, this.#g.scale, this.#g.tx * this.#_ + this.#w, this.#g.ty * this.#_), e.uniform1f(this.#h.uOriginX ?? null, a), e.uniform1f(this.#h.uDir ?? null, r.dir), e.uniform1f(this.#h.uLeafW ?? null, i), e.uniform1f(this.#h.uGloss ?? null, this.#S === "simple" ? 0 : 1), e.uniform1f(this.#h.uAlpha ?? null, r.fill ? this.#Y() : 1), e.drawElements(e.TRIANGLES, this.#l, e.UNSIGNED_SHORT, 0);
442
537
  }
443
538
  #Y() {
539
+ let e = this.#S === "roll" || this.#S === "simple" ? V : H, t = (this.#x - e) / (1 - e);
540
+ return t <= 0 ? 1 : t >= 1 ? 0 : (1 - t) ** 1.5;
541
+ }
542
+ #X() {
444
543
  let e = this.#n;
445
544
  e.useProgram(this.#r), e.bindVertexArray(this.#a), e.activeTexture(e.TEXTURE0), e.uniform2f(this.#m.uViewport ?? null, this.#O, this.#k), e.uniform3f(this.#m.uView ?? null, this.#g.scale, this.#g.tx * this.#_ + this.#w, this.#g.ty * this.#_);
446
545
  }
447
- #X(e, t, n = 0) {
546
+ #Z(e, t, n = 0) {
448
547
  let r = this.#n;
449
- t !== null && (this.#Z(r.TEXTURE0, t), r.uniform4f(this.#m.uRect ?? null, e.x, e.y, e.w, e.h), r.uniform1f(this.#m.uGutterSide ?? null, n), r.drawArrays(r.TRIANGLE_STRIP, 0, 4));
548
+ t !== null && (this.#Q(r.TEXTURE0, t), r.uniform4f(this.#m.uRect ?? null, e.x, e.y, e.w, e.h), r.uniform1f(this.#m.uGutterSide ?? null, n), r.drawArrays(r.TRIANGLE_STRIP, 0, 4));
450
549
  }
451
- #Z(e, t) {
550
+ #Q(e, t) {
452
551
  let n = this.#n;
453
- n.activeTexture(e), n.bindTexture(n.TEXTURE_2D, t === null ? this.#p : this.#Q(t));
552
+ n.activeTexture(e), n.bindTexture(n.TEXTURE_2D, t === null ? this.#p : this.#$(t));
454
553
  }
455
- #Q(e) {
554
+ #$(e) {
456
555
  let t = this.#n, n = this.#d.get(e);
457
556
  if (n !== void 0) return this.#d.delete(e), this.#d.set(e, n), n.tex;
458
- let r = h(t);
459
- g(t, r, e);
557
+ let r = N(t);
558
+ P(t, r, e);
460
559
  let i = e, a = i.width * i.height * 4;
461
560
  return this.#d.set(e, {
462
561
  tex: r,
463
562
  bytes: a
464
- }), this.#f += a, this.#$(), r;
563
+ }), this.#f += a, this.#ee(), r;
465
564
  }
466
- #$() {
565
+ #ee() {
467
566
  let e = this.#n;
468
567
  for (let [t, n] of this.#d) {
469
- if (this.#f <= w || this.#d.size <= 4) break;
568
+ if (this.#f <= W || this.#d.size <= 4) break;
470
569
  this.#d.delete(t), this.#f -= n.bytes, e.deleteTexture(n.tex);
471
570
  }
472
571
  }
473
- #ee(e) {
474
- let t = h(e);
572
+ #te(e) {
573
+ let t = N(e);
475
574
  return e.bindTexture(e.TEXTURE_2D, t), e.texImage2D(e.TEXTURE_2D, 0, e.RGBA, 1, 1, 0, e.RGBA, e.UNSIGNED_BYTE, new Uint8Array([
476
575
  0,
477
576
  0,
@@ -479,7 +578,7 @@ var E = class {
479
578
  0
480
579
  ])), t;
481
580
  }
482
- #te() {
581
+ #ne() {
483
582
  let e = this.#n, t = this.#t, n = this.#e;
484
583
  if (e === null || t === null || n === null) return;
485
584
  this.#_ = typeof devicePixelRatio == "number" ? devicePixelRatio : 1;
@@ -488,6 +587,6 @@ var E = class {
488
587
  }
489
588
  };
490
589
  //#endregion
491
- export { E as WebglRenderer };
590
+ export { K as WebglRenderer };
492
591
 
493
- //# sourceMappingURL=webglRenderer-m-lr412M.js.map
592
+ //# sourceMappingURL=webglRenderer-BK-ArG1G.js.map