@surdeddd/bottom-sheet 0.14.0 → 0.20.1

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.
Files changed (56) hide show
  1. package/README.md +13 -0
  2. package/dist/{BottomSheetCore-DJYwWOqt.d.ts → BottomSheetCore-Cgn8b_6A.d.ts} +11 -2
  3. package/dist/{BottomSheetCore-Cp7dWy91.d.cts → BottomSheetCore-VPJZcKcg.d.cts} +11 -2
  4. package/dist/{BottomSheetEngine-Lm7HIVHv.d.cts → BottomSheetEngine-B8C2CwF9.d.cts} +1 -1
  5. package/dist/{BottomSheetEngine-O5PbeKfe.d.ts → BottomSheetEngine-DwYR_ygJ.d.ts} +1 -1
  6. package/dist/core.cjs +100 -9
  7. package/dist/core.d.cts +2 -2
  8. package/dist/core.d.ts +2 -2
  9. package/dist/core.js +100 -9
  10. package/dist/debug.d.cts +1 -1
  11. package/dist/debug.d.ts +1 -1
  12. package/dist/element.cjs +107 -9
  13. package/dist/element.d.cts +2 -2
  14. package/dist/element.d.ts +2 -2
  15. package/dist/element.iife.global.js +2 -2
  16. package/dist/element.js +107 -9
  17. package/dist/features.d.cts +4 -4
  18. package/dist/features.d.ts +4 -4
  19. package/dist/{index-Bb5TRmyg.d.cts → index-CnfbOKx0.d.cts} +1 -1
  20. package/dist/{index-Cl9ebCP2.d.ts → index-DcMkhXAy.d.ts} +1 -1
  21. package/dist/index.cjs +100 -9
  22. package/dist/index.d.cts +8 -8
  23. package/dist/index.d.ts +8 -8
  24. package/dist/index.js +100 -9
  25. package/dist/integrations/formik.d.cts +1 -1
  26. package/dist/integrations/formik.d.ts +1 -1
  27. package/dist/integrations/react-hook-form.d.cts +1 -1
  28. package/dist/integrations/react-hook-form.d.ts +1 -1
  29. package/dist/preact.d.cts +2 -2
  30. package/dist/preact.d.ts +2 -2
  31. package/dist/qwik-lib/index.qwik.cjs +98 -9
  32. package/dist/qwik-lib/index.qwik.mjs +98 -9
  33. package/dist/qwik.cjs +100 -9
  34. package/dist/qwik.d.cts +2 -2
  35. package/dist/qwik.d.ts +2 -2
  36. package/dist/qwik.js +100 -9
  37. package/dist/react.cjs +100 -9
  38. package/dist/react.d.cts +3 -3
  39. package/dist/react.d.ts +3 -3
  40. package/dist/react.js +100 -9
  41. package/dist/solid.cjs +100 -9
  42. package/dist/solid.d.cts +10 -1
  43. package/dist/solid.d.ts +10 -1
  44. package/dist/solid.js +100 -9
  45. package/dist/solid.source.jsx +100 -9
  46. package/dist/svelte-core.cjs +100 -9
  47. package/dist/svelte-core.js +100 -9
  48. package/dist/svelte.cjs +100 -9
  49. package/dist/svelte.js +100 -9
  50. package/dist/vue.cjs +101 -10
  51. package/dist/vue.js +101 -10
  52. package/dist/webgl.cjs +154 -34
  53. package/dist/webgl.d.cts +1 -1
  54. package/dist/webgl.d.ts +1 -1
  55. package/dist/webgl.js +154 -34
  56. package/package.json +39 -39
package/dist/webgl.cjs CHANGED
@@ -1,12 +1,22 @@
1
1
  'use strict';
2
2
 
3
3
  // src/webgl/gl-context.ts
4
+ var supportsHighpFragment = (gl) => {
5
+ try {
6
+ const fmt = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT);
7
+ return !!fmt && fmt.precision > 0;
8
+ } catch {
9
+ return false;
10
+ }
11
+ };
4
12
  var hasWebGL = () => {
5
13
  if (typeof document === "undefined") return false;
6
- if (typeof WebGLRenderingContext === "undefined") return false;
14
+ if (typeof WebGLRenderingContext === "undefined" && typeof WebGL2RenderingContext === "undefined") {
15
+ return false;
16
+ }
7
17
  try {
8
18
  const probe = document.createElement("canvas");
9
- const gl = probe.getContext("webgl", { alpha: true }) ?? probe.getContext("experimental-webgl");
19
+ const gl = probe.getContext("webgl2", { alpha: true }) ?? probe.getContext("webgl", { alpha: true }) ?? probe.getContext("experimental-webgl");
10
20
  if (!gl) return false;
11
21
  const lose = gl.getExtension(
12
22
  "WEBGL_lose_context"
@@ -25,18 +35,26 @@ var createGLHandle = (onLost) => {
25
35
  canvas.style.left = "0";
26
36
  canvas.style.top = "0";
27
37
  canvas.style.pointerEvents = "none";
38
+ const attrs = {
39
+ alpha: true,
40
+ premultipliedAlpha: true,
41
+ antialias: true,
42
+ depth: false,
43
+ stencil: false,
44
+ preserveDrawingBuffer: false
45
+ };
28
46
  let gl = null;
29
- try {
30
- gl = canvas.getContext("webgl", {
31
- alpha: true,
32
- premultipliedAlpha: true,
33
- antialias: true,
34
- depth: false,
35
- stencil: false,
36
- preserveDrawingBuffer: false
37
- });
38
- } catch {
39
- gl = null;
47
+ let isWebGL2 = false;
48
+ for (const id of ["webgl2", "webgl", "experimental-webgl"]) {
49
+ try {
50
+ const ctx = canvas.getContext(id, attrs);
51
+ if (ctx) {
52
+ gl = ctx;
53
+ isWebGL2 = id === "webgl2";
54
+ break;
55
+ }
56
+ } catch {
57
+ }
40
58
  }
41
59
  if (!gl) return null;
42
60
  const handleLost = (e) => {
@@ -47,6 +65,8 @@ var createGLHandle = (onLost) => {
47
65
  return {
48
66
  canvas,
49
67
  gl,
68
+ isWebGL2,
69
+ highp: isWebGL2 || supportsHighpFragment(gl),
50
70
  destroy: () => {
51
71
  canvas.removeEventListener("webglcontextlost", handleLost);
52
72
  const lose = gl?.getExtension("WEBGL_lose_context");
@@ -77,8 +97,8 @@ void main() {
77
97
  gl_Position = vec4(a_pos, 0.0, 1.0);
78
98
  }
79
99
  `;
80
- var FRAGMENT_SRC = `
81
- precision mediump float;
100
+ var FRAGMENT_SRC = (precision) => `
101
+ precision ${precision} float;
82
102
 
83
103
  uniform vec2 u_resolution;
84
104
  uniform vec4 u_rect;
@@ -155,9 +175,16 @@ var compile = (gl, type, src) => {
155
175
  }
156
176
  return shader;
157
177
  };
158
- var createSurfaceProgram = (gl) => {
178
+ var createSurfaceProgram = (gl, highp = true) => {
159
179
  const vs = compile(gl, gl.VERTEX_SHADER, VERTEX_SRC);
160
- const fs = compile(gl, gl.FRAGMENT_SHADER, FRAGMENT_SRC);
180
+ let fs = compile(
181
+ gl,
182
+ gl.FRAGMENT_SHADER,
183
+ FRAGMENT_SRC(highp ? "highp" : "mediump")
184
+ );
185
+ if (!fs && highp) {
186
+ fs = compile(gl, gl.FRAGMENT_SHADER, FRAGMENT_SRC("mediump"));
187
+ }
161
188
  if (!vs || !fs) return null;
162
189
  const program = gl.createProgram();
163
190
  if (!program) return null;
@@ -273,6 +300,59 @@ var wrapLines = (ctx, text, maxWidth) => {
273
300
  lines.push(line);
274
301
  return lines;
275
302
  };
303
+ var isPaintedColor = (value) => !!value && value !== "transparent" && !/rgba\(\s*0,\s*0,\s*0,\s*0\s*\)/.test(value);
304
+ var roundedPath = (ctx, x, y, w, h, r) => {
305
+ const rad = Math.min(r, w / 2, h / 2);
306
+ ctx.beginPath();
307
+ if (rad <= 0) {
308
+ ctx.rect(x, y, w, h);
309
+ return;
310
+ }
311
+ ctx.moveTo(x + rad, y);
312
+ ctx.arcTo(x + w, y, x + w, y + h, rad);
313
+ ctx.arcTo(x + w, y + h, x, y + h, rad);
314
+ ctx.arcTo(x, y + h, x, y, rad);
315
+ ctx.arcTo(x, y, x + w, y, rad);
316
+ ctx.closePath();
317
+ };
318
+ var drawBox = (ctx, cs, rect, rootRect) => {
319
+ const bg = cs.backgroundColor;
320
+ const borderWidth = parseFloat(cs.borderTopWidth) || 0;
321
+ const hasBorder = borderWidth > 0 && isPaintedColor(cs.borderTopColor);
322
+ if (!isPaintedColor(bg) && !hasBorder) return false;
323
+ const x = rect.left - rootRect.left;
324
+ const y = rect.top - rootRect.top;
325
+ const radius = parseFloat(cs.borderTopLeftRadius) || 0;
326
+ if (isPaintedColor(bg)) {
327
+ roundedPath(ctx, x, y, rect.width, rect.height, radius);
328
+ ctx.fillStyle = bg;
329
+ ctx.fill();
330
+ }
331
+ if (hasBorder) {
332
+ roundedPath(ctx, x, y, rect.width, rect.height, radius);
333
+ ctx.strokeStyle = cs.borderTopColor;
334
+ ctx.lineWidth = borderWidth;
335
+ ctx.stroke();
336
+ }
337
+ return true;
338
+ };
339
+ var drawImage = (ctx, img, rootRect) => {
340
+ if (!img.complete || img.naturalWidth === 0) return false;
341
+ const rect = img.getBoundingClientRect();
342
+ if (rect.width < 1 || rect.height < 1) return false;
343
+ try {
344
+ ctx.drawImage(
345
+ img,
346
+ rect.left - rootRect.left,
347
+ rect.top - rootRect.top,
348
+ rect.width,
349
+ rect.height
350
+ );
351
+ return true;
352
+ } catch {
353
+ return false;
354
+ }
355
+ };
276
356
  var captureContent = (gl, root, dpr) => {
277
357
  const rootRect = root.getBoundingClientRect();
278
358
  const w = Math.max(1, Math.round(rootRect.width * dpr));
@@ -289,12 +369,24 @@ var captureContent = (gl, root, dpr) => {
289
369
  let painted = 0;
290
370
  while (walker.nextNode()) {
291
371
  const el = walker.currentNode;
372
+ if (el.tagName === "IMG") {
373
+ if (drawImage(ctx, el, rootRect)) {
374
+ painted++;
375
+ hiddenNodes.push(el);
376
+ }
377
+ continue;
378
+ }
292
379
  if (!isRenderable(el)) continue;
293
- const text = directText(el);
294
- if (!text) continue;
295
380
  const rect = el.getBoundingClientRect();
296
381
  if (rect.width < 1 || rect.height < 1) continue;
297
382
  const cs = getComputedStyle(el);
383
+ const boxed = drawBox(ctx, cs, rect, rootRect);
384
+ if (boxed) {
385
+ painted++;
386
+ hiddenNodes.push(el);
387
+ }
388
+ const text = directText(el);
389
+ if (!text) continue;
298
390
  ctx.font = `${cs.fontStyle} ${cs.fontWeight} ${cs.fontSize} ${cs.fontFamily}`;
299
391
  ctx.fillStyle = cs.color;
300
392
  ctx.textBaseline = "top";
@@ -321,7 +413,7 @@ var captureContent = (gl, root, dpr) => {
321
413
  });
322
414
  if (lines.length) {
323
415
  painted++;
324
- hiddenNodes.push(el);
416
+ if (!boxed) hiddenNodes.push(el);
325
417
  }
326
418
  }
327
419
  if (!painted) return null;
@@ -329,14 +421,19 @@ var captureContent = (gl, root, dpr) => {
329
421
  if (!texture) return null;
330
422
  gl.bindTexture(gl.TEXTURE_2D, texture);
331
423
  gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
332
- gl.texImage2D(
333
- gl.TEXTURE_2D,
334
- 0,
335
- gl.RGBA,
336
- gl.RGBA,
337
- gl.UNSIGNED_BYTE,
338
- surface
339
- );
424
+ try {
425
+ gl.texImage2D(
426
+ gl.TEXTURE_2D,
427
+ 0,
428
+ gl.RGBA,
429
+ gl.RGBA,
430
+ gl.UNSIGNED_BYTE,
431
+ surface
432
+ );
433
+ } catch {
434
+ gl.deleteTexture(texture);
435
+ return null;
436
+ }
340
437
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
341
438
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
342
439
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
@@ -344,10 +441,30 @@ var captureContent = (gl, root, dpr) => {
344
441
  return { texture, width: w, height: h, hiddenNodes };
345
442
  };
346
443
  var hideCapturedText = (nodes) => {
347
- const restore = nodes.map((el) => ({ el, prev: el.style.color }));
348
- for (const { el } of restore) el.style.color = "transparent";
444
+ const restore = nodes.map((el) => ({
445
+ el,
446
+ color: el.style.color,
447
+ background: el.style.background,
448
+ borderColor: el.style.borderColor,
449
+ opacity: el.style.opacity,
450
+ isImage: el.tagName === "IMG"
451
+ }));
452
+ for (const entry of restore) {
453
+ if (entry.isImage) {
454
+ entry.el.style.opacity = "0";
455
+ continue;
456
+ }
457
+ entry.el.style.color = "transparent";
458
+ entry.el.style.background = "transparent";
459
+ entry.el.style.borderColor = "transparent";
460
+ }
349
461
  return () => {
350
- for (const { el, prev } of restore) el.style.color = prev;
462
+ for (const entry of restore) {
463
+ entry.el.style.color = entry.color;
464
+ entry.el.style.background = entry.background;
465
+ entry.el.style.borderColor = entry.borderColor;
466
+ entry.el.style.opacity = entry.opacity;
467
+ }
351
468
  };
352
469
  };
353
470
 
@@ -448,7 +565,7 @@ var webglRenderer = (options = {}) => ({
448
565
  bail("no-webgl");
449
566
  return;
450
567
  }
451
- program = createSurfaceProgram(handle.gl);
568
+ program = createSurfaceProgram(handle.gl, handle.highp);
452
569
  if (!program) {
453
570
  handle.destroy();
454
571
  handle = null;
@@ -508,10 +625,13 @@ var webglRenderer = (options = {}) => ({
508
625
  paint();
509
626
  const held = ctx.isDragging();
510
627
  bend *= held ? BEND_DECAY_HELD : BEND_DECAY_FREE;
511
- const settled = !held && !ctx.isAnimating() && Math.abs(bend) < BEND_REST;
512
- if (settled) {
628
+ const flat = Math.abs(bend) < BEND_REST;
629
+ if (!held && flat && capture) {
513
630
  bend = 0;
514
631
  releaseCapture();
632
+ }
633
+ if (!held && flat && !ctx.isAnimating()) {
634
+ bend = 0;
515
635
  paint();
516
636
  running = false;
517
637
  frameId = null;
package/dist/webgl.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { f as EngineFeature } from './BottomSheetCore-Cp7dWy91.cjs';
1
+ import { f as EngineFeature } from './BottomSheetCore-VPJZcKcg.cjs';
2
2
  import './transform-jVfAikE9.cjs';
3
3
 
4
4
  type WebGLRendererOptions = {
package/dist/webgl.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { f as EngineFeature } from './BottomSheetCore-DJYwWOqt.js';
1
+ import { f as EngineFeature } from './BottomSheetCore-Cgn8b_6A.js';
2
2
  import './transform-jVfAikE9.js';
3
3
 
4
4
  type WebGLRendererOptions = {
package/dist/webgl.js CHANGED
@@ -1,10 +1,20 @@
1
1
  // src/webgl/gl-context.ts
2
+ var supportsHighpFragment = (gl) => {
3
+ try {
4
+ const fmt = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT);
5
+ return !!fmt && fmt.precision > 0;
6
+ } catch {
7
+ return false;
8
+ }
9
+ };
2
10
  var hasWebGL = () => {
3
11
  if (typeof document === "undefined") return false;
4
- if (typeof WebGLRenderingContext === "undefined") return false;
12
+ if (typeof WebGLRenderingContext === "undefined" && typeof WebGL2RenderingContext === "undefined") {
13
+ return false;
14
+ }
5
15
  try {
6
16
  const probe = document.createElement("canvas");
7
- const gl = probe.getContext("webgl", { alpha: true }) ?? probe.getContext("experimental-webgl");
17
+ const gl = probe.getContext("webgl2", { alpha: true }) ?? probe.getContext("webgl", { alpha: true }) ?? probe.getContext("experimental-webgl");
8
18
  if (!gl) return false;
9
19
  const lose = gl.getExtension(
10
20
  "WEBGL_lose_context"
@@ -23,18 +33,26 @@ var createGLHandle = (onLost) => {
23
33
  canvas.style.left = "0";
24
34
  canvas.style.top = "0";
25
35
  canvas.style.pointerEvents = "none";
36
+ const attrs = {
37
+ alpha: true,
38
+ premultipliedAlpha: true,
39
+ antialias: true,
40
+ depth: false,
41
+ stencil: false,
42
+ preserveDrawingBuffer: false
43
+ };
26
44
  let gl = null;
27
- try {
28
- gl = canvas.getContext("webgl", {
29
- alpha: true,
30
- premultipliedAlpha: true,
31
- antialias: true,
32
- depth: false,
33
- stencil: false,
34
- preserveDrawingBuffer: false
35
- });
36
- } catch {
37
- gl = null;
45
+ let isWebGL2 = false;
46
+ for (const id of ["webgl2", "webgl", "experimental-webgl"]) {
47
+ try {
48
+ const ctx = canvas.getContext(id, attrs);
49
+ if (ctx) {
50
+ gl = ctx;
51
+ isWebGL2 = id === "webgl2";
52
+ break;
53
+ }
54
+ } catch {
55
+ }
38
56
  }
39
57
  if (!gl) return null;
40
58
  const handleLost = (e) => {
@@ -45,6 +63,8 @@ var createGLHandle = (onLost) => {
45
63
  return {
46
64
  canvas,
47
65
  gl,
66
+ isWebGL2,
67
+ highp: isWebGL2 || supportsHighpFragment(gl),
48
68
  destroy: () => {
49
69
  canvas.removeEventListener("webglcontextlost", handleLost);
50
70
  const lose = gl?.getExtension("WEBGL_lose_context");
@@ -75,8 +95,8 @@ void main() {
75
95
  gl_Position = vec4(a_pos, 0.0, 1.0);
76
96
  }
77
97
  `;
78
- var FRAGMENT_SRC = `
79
- precision mediump float;
98
+ var FRAGMENT_SRC = (precision) => `
99
+ precision ${precision} float;
80
100
 
81
101
  uniform vec2 u_resolution;
82
102
  uniform vec4 u_rect;
@@ -153,9 +173,16 @@ var compile = (gl, type, src) => {
153
173
  }
154
174
  return shader;
155
175
  };
156
- var createSurfaceProgram = (gl) => {
176
+ var createSurfaceProgram = (gl, highp = true) => {
157
177
  const vs = compile(gl, gl.VERTEX_SHADER, VERTEX_SRC);
158
- const fs = compile(gl, gl.FRAGMENT_SHADER, FRAGMENT_SRC);
178
+ let fs = compile(
179
+ gl,
180
+ gl.FRAGMENT_SHADER,
181
+ FRAGMENT_SRC(highp ? "highp" : "mediump")
182
+ );
183
+ if (!fs && highp) {
184
+ fs = compile(gl, gl.FRAGMENT_SHADER, FRAGMENT_SRC("mediump"));
185
+ }
159
186
  if (!vs || !fs) return null;
160
187
  const program = gl.createProgram();
161
188
  if (!program) return null;
@@ -271,6 +298,59 @@ var wrapLines = (ctx, text, maxWidth) => {
271
298
  lines.push(line);
272
299
  return lines;
273
300
  };
301
+ var isPaintedColor = (value) => !!value && value !== "transparent" && !/rgba\(\s*0,\s*0,\s*0,\s*0\s*\)/.test(value);
302
+ var roundedPath = (ctx, x, y, w, h, r) => {
303
+ const rad = Math.min(r, w / 2, h / 2);
304
+ ctx.beginPath();
305
+ if (rad <= 0) {
306
+ ctx.rect(x, y, w, h);
307
+ return;
308
+ }
309
+ ctx.moveTo(x + rad, y);
310
+ ctx.arcTo(x + w, y, x + w, y + h, rad);
311
+ ctx.arcTo(x + w, y + h, x, y + h, rad);
312
+ ctx.arcTo(x, y + h, x, y, rad);
313
+ ctx.arcTo(x, y, x + w, y, rad);
314
+ ctx.closePath();
315
+ };
316
+ var drawBox = (ctx, cs, rect, rootRect) => {
317
+ const bg = cs.backgroundColor;
318
+ const borderWidth = parseFloat(cs.borderTopWidth) || 0;
319
+ const hasBorder = borderWidth > 0 && isPaintedColor(cs.borderTopColor);
320
+ if (!isPaintedColor(bg) && !hasBorder) return false;
321
+ const x = rect.left - rootRect.left;
322
+ const y = rect.top - rootRect.top;
323
+ const radius = parseFloat(cs.borderTopLeftRadius) || 0;
324
+ if (isPaintedColor(bg)) {
325
+ roundedPath(ctx, x, y, rect.width, rect.height, radius);
326
+ ctx.fillStyle = bg;
327
+ ctx.fill();
328
+ }
329
+ if (hasBorder) {
330
+ roundedPath(ctx, x, y, rect.width, rect.height, radius);
331
+ ctx.strokeStyle = cs.borderTopColor;
332
+ ctx.lineWidth = borderWidth;
333
+ ctx.stroke();
334
+ }
335
+ return true;
336
+ };
337
+ var drawImage = (ctx, img, rootRect) => {
338
+ if (!img.complete || img.naturalWidth === 0) return false;
339
+ const rect = img.getBoundingClientRect();
340
+ if (rect.width < 1 || rect.height < 1) return false;
341
+ try {
342
+ ctx.drawImage(
343
+ img,
344
+ rect.left - rootRect.left,
345
+ rect.top - rootRect.top,
346
+ rect.width,
347
+ rect.height
348
+ );
349
+ return true;
350
+ } catch {
351
+ return false;
352
+ }
353
+ };
274
354
  var captureContent = (gl, root, dpr) => {
275
355
  const rootRect = root.getBoundingClientRect();
276
356
  const w = Math.max(1, Math.round(rootRect.width * dpr));
@@ -287,12 +367,24 @@ var captureContent = (gl, root, dpr) => {
287
367
  let painted = 0;
288
368
  while (walker.nextNode()) {
289
369
  const el = walker.currentNode;
370
+ if (el.tagName === "IMG") {
371
+ if (drawImage(ctx, el, rootRect)) {
372
+ painted++;
373
+ hiddenNodes.push(el);
374
+ }
375
+ continue;
376
+ }
290
377
  if (!isRenderable(el)) continue;
291
- const text = directText(el);
292
- if (!text) continue;
293
378
  const rect = el.getBoundingClientRect();
294
379
  if (rect.width < 1 || rect.height < 1) continue;
295
380
  const cs = getComputedStyle(el);
381
+ const boxed = drawBox(ctx, cs, rect, rootRect);
382
+ if (boxed) {
383
+ painted++;
384
+ hiddenNodes.push(el);
385
+ }
386
+ const text = directText(el);
387
+ if (!text) continue;
296
388
  ctx.font = `${cs.fontStyle} ${cs.fontWeight} ${cs.fontSize} ${cs.fontFamily}`;
297
389
  ctx.fillStyle = cs.color;
298
390
  ctx.textBaseline = "top";
@@ -319,7 +411,7 @@ var captureContent = (gl, root, dpr) => {
319
411
  });
320
412
  if (lines.length) {
321
413
  painted++;
322
- hiddenNodes.push(el);
414
+ if (!boxed) hiddenNodes.push(el);
323
415
  }
324
416
  }
325
417
  if (!painted) return null;
@@ -327,14 +419,19 @@ var captureContent = (gl, root, dpr) => {
327
419
  if (!texture) return null;
328
420
  gl.bindTexture(gl.TEXTURE_2D, texture);
329
421
  gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
330
- gl.texImage2D(
331
- gl.TEXTURE_2D,
332
- 0,
333
- gl.RGBA,
334
- gl.RGBA,
335
- gl.UNSIGNED_BYTE,
336
- surface
337
- );
422
+ try {
423
+ gl.texImage2D(
424
+ gl.TEXTURE_2D,
425
+ 0,
426
+ gl.RGBA,
427
+ gl.RGBA,
428
+ gl.UNSIGNED_BYTE,
429
+ surface
430
+ );
431
+ } catch {
432
+ gl.deleteTexture(texture);
433
+ return null;
434
+ }
338
435
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
339
436
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
340
437
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
@@ -342,10 +439,30 @@ var captureContent = (gl, root, dpr) => {
342
439
  return { texture, width: w, height: h, hiddenNodes };
343
440
  };
344
441
  var hideCapturedText = (nodes) => {
345
- const restore = nodes.map((el) => ({ el, prev: el.style.color }));
346
- for (const { el } of restore) el.style.color = "transparent";
442
+ const restore = nodes.map((el) => ({
443
+ el,
444
+ color: el.style.color,
445
+ background: el.style.background,
446
+ borderColor: el.style.borderColor,
447
+ opacity: el.style.opacity,
448
+ isImage: el.tagName === "IMG"
449
+ }));
450
+ for (const entry of restore) {
451
+ if (entry.isImage) {
452
+ entry.el.style.opacity = "0";
453
+ continue;
454
+ }
455
+ entry.el.style.color = "transparent";
456
+ entry.el.style.background = "transparent";
457
+ entry.el.style.borderColor = "transparent";
458
+ }
347
459
  return () => {
348
- for (const { el, prev } of restore) el.style.color = prev;
460
+ for (const entry of restore) {
461
+ entry.el.style.color = entry.color;
462
+ entry.el.style.background = entry.background;
463
+ entry.el.style.borderColor = entry.borderColor;
464
+ entry.el.style.opacity = entry.opacity;
465
+ }
349
466
  };
350
467
  };
351
468
 
@@ -446,7 +563,7 @@ var webglRenderer = (options = {}) => ({
446
563
  bail("no-webgl");
447
564
  return;
448
565
  }
449
- program = createSurfaceProgram(handle.gl);
566
+ program = createSurfaceProgram(handle.gl, handle.highp);
450
567
  if (!program) {
451
568
  handle.destroy();
452
569
  handle = null;
@@ -506,10 +623,13 @@ var webglRenderer = (options = {}) => ({
506
623
  paint();
507
624
  const held = ctx.isDragging();
508
625
  bend *= held ? BEND_DECAY_HELD : BEND_DECAY_FREE;
509
- const settled = !held && !ctx.isAnimating() && Math.abs(bend) < BEND_REST;
510
- if (settled) {
626
+ const flat = Math.abs(bend) < BEND_REST;
627
+ if (!held && flat && capture) {
511
628
  bend = 0;
512
629
  releaseCapture();
630
+ }
631
+ if (!held && flat && !ctx.isAnimating()) {
632
+ bend = 0;
513
633
  paint();
514
634
  running = false;
515
635
  frameId = null;