laymur 0.14.0 → 0.14.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.
package/dist/index.js CHANGED
@@ -2556,28 +2556,27 @@ class UIColor {
2556
2556
  }
2557
2557
  }
2558
2558
 
2559
- /**
2560
- * Checks if WebGL2 is available.
2561
- */
2562
- function checkWebGL2Support() {
2563
- const canvas = document.createElement("canvas");
2564
- return canvas.getContext("webgl2") !== null;
2565
- }
2566
2559
  /**
2567
2560
  * Checks real OffscreenCanvas support as a texture source
2568
2561
  */
2569
- function checkOffscreenCanvasSupport() {
2562
+ function checkOffscreenCanvasSupportInternal() {
2570
2563
  var _a;
2571
- if (typeof OffscreenCanvas === "undefined") return false;
2564
+ if (typeof OffscreenCanvas === "undefined") {
2565
+ return false;
2566
+ }
2572
2567
  const testCanvasElement = document.createElement("canvas");
2573
2568
  testCanvasElement.width = 4;
2574
2569
  testCanvasElement.height = 4;
2575
2570
  const gl = (_a = testCanvasElement.getContext("webgl")) !== null && _a !== void 0 ? _a : testCanvasElement.getContext("webgl2");
2576
- if (!gl) return false;
2571
+ if (!gl) {
2572
+ return false;
2573
+ }
2577
2574
  try {
2578
2575
  const offscreenCanvas = new OffscreenCanvas(4, 4);
2579
2576
  const offscreenContext = offscreenCanvas.getContext("2d");
2580
- if (!offscreenContext) return false;
2577
+ if (!offscreenContext) {
2578
+ return false;
2579
+ }
2581
2580
  offscreenContext.fillStyle = "#ff0000";
2582
2581
  offscreenContext.fillRect(0, 0, 4, 4);
2583
2582
  const texture = gl.createTexture();
@@ -2602,7 +2601,9 @@ function checkOffscreenCanvasSupport() {
2602
2601
  gl.deleteTexture(texture);
2603
2602
  // Check that the read pixel is red (with tolerance)
2604
2603
  const isRedPixel = pixelData[0] > 200 && pixelData[1] < 50 && pixelData[2] < 50 && pixelData[3] > 200;
2605
- if (!isRedPixel) return false;
2604
+ if (!isRedPixel) {
2605
+ return false;
2606
+ }
2606
2607
  return true;
2607
2608
  } catch (error) {
2608
2609
  return false;
@@ -2611,11 +2612,13 @@ function checkOffscreenCanvasSupport() {
2611
2612
  /**
2612
2613
  * Checks sRGB support
2613
2614
  */
2614
- function checkSRGBSupport() {
2615
+ function checkSRGBSupportInternal() {
2615
2616
  var _a;
2616
2617
  const canvasElement = document.createElement("canvas");
2617
2618
  const gl = (_a = canvasElement.getContext("webgl2")) !== null && _a !== void 0 ? _a : canvasElement.getContext("webgl");
2618
- if (!gl) return false;
2619
+ if (!gl) {
2620
+ return false;
2621
+ }
2619
2622
  if (gl instanceof WebGL2RenderingContext) {
2620
2623
  try {
2621
2624
  const texture = gl.createTexture();
@@ -2629,7 +2632,9 @@ function checkSRGBSupport() {
2629
2632
  }
2630
2633
  }
2631
2634
  const extension = gl.getExtension("EXT_sRGB");
2632
- if (!extension) return false;
2635
+ if (!extension) {
2636
+ return false;
2637
+ }
2633
2638
  try {
2634
2639
  const texture = gl.createTexture();
2635
2640
  gl.bindTexture(gl.TEXTURE_2D, texture);
@@ -2641,14 +2646,16 @@ function checkSRGBSupport() {
2641
2646
  return false;
2642
2647
  }
2643
2648
  }
2644
- const WEBGL2_SUPPORTED = checkWebGL2Support();
2645
- const OFFSCREEN_CANVAS_SUPPORTED = checkOffscreenCanvasSupport();
2646
- const SRGB_SUPPORTED = checkSRGBSupport();
2647
- console.log("[WebGL] Capabilities:", {
2648
- webgl2: WEBGL2_SUPPORTED,
2649
- offscreenCanvas: OFFSCREEN_CANVAS_SUPPORTED,
2650
- srgb: SRGB_SUPPORTED
2651
- });
2649
+ let OFFSCREEN_CANVAS_SUPPORTED_INTERNAL;
2650
+ let SRGB_SUPPORTED_INTERNAL;
2651
+ const checkOffscreenCanvasSupport = () => {
2652
+ OFFSCREEN_CANVAS_SUPPORTED_INTERNAL !== null && OFFSCREEN_CANVAS_SUPPORTED_INTERNAL !== void 0 ? OFFSCREEN_CANVAS_SUPPORTED_INTERNAL : OFFSCREEN_CANVAS_SUPPORTED_INTERNAL = checkOffscreenCanvasSupportInternal();
2653
+ return OFFSCREEN_CANVAS_SUPPORTED_INTERNAL;
2654
+ };
2655
+ const checkSRGBSupport = () => {
2656
+ SRGB_SUPPORTED_INTERNAL !== null && SRGB_SUPPORTED_INTERNAL !== void 0 ? SRGB_SUPPORTED_INTERNAL : SRGB_SUPPORTED_INTERNAL = checkSRGBSupportInternal();
2657
+ return SRGB_SUPPORTED_INTERNAL;
2658
+ };
2652
2659
 
2653
2660
  const DEFAULT_ALPHA_TEST = 0.5;
2654
2661
  const GLSL_TYPE_INFO_FLOAT = Object.freeze({
@@ -2814,7 +2821,7 @@ function buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclaration
2814
2821
  return `
2815
2822
  // Defines
2816
2823
  #define PI 3.14159265359
2817
- #define SRGB_SUPPORTED ${SRGB_SUPPORTED ? '1' : '0'}
2824
+ #define SRGB_SUPPORTED ${checkSRGBSupport() ? '1' : '0'}
2818
2825
 
2819
2826
  // Uniforms
2820
2827
  ${uniformDeclarations.join("\n")}
@@ -6656,7 +6663,7 @@ class UIAnimatedImage extends UIElement {
6656
6663
  * @returns Canvas instance
6657
6664
  */
6658
6665
  function createCanvas(width, height) {
6659
- if (OFFSCREEN_CANVAS_SUPPORTED) {
6666
+ if (checkOffscreenCanvasSupport()) {
6660
6667
  return new OffscreenCanvas(width, height);
6661
6668
  }
6662
6669
  const canvasElement = document.createElement("canvas");
@@ -6676,7 +6683,7 @@ function createCanvas(width, height) {
6676
6683
  */
6677
6684
  function createCanvasTexture(canvas) {
6678
6685
  const texture = new CanvasTexture(canvas, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearFilter, RGBAFormat, UnsignedByteType, 1);
6679
- texture.colorSpace = SRGB_SUPPORTED ? SRGBColorSpace : NoColorSpace;
6686
+ texture.colorSpace = checkSRGBSupport() ? SRGBColorSpace : NoColorSpace;
6680
6687
  texture.generateMipmaps = false;
6681
6688
  return texture;
6682
6689
  }