laymur 0.13.1 → 0.13.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.
@@ -1,3 +1,4 @@
1
+ import type { UICanvasRenderingContext2D } from "../../miscellaneous/canvas";
1
2
  import type { UITextSpan } from "../../miscellaneous/text-span/UITextSpan";
2
3
  import { UITextStyle } from "../../miscellaneous/text-style/UITextStyle";
3
4
  import type { UITextStyleConfig } from "../../miscellaneous/text-style/UITextStyle.Internal";
@@ -15,7 +16,7 @@ export declare function splitTextIntoChunks(text: string): string[];
15
16
  * @param textStyle Resolved text style
16
17
  * @returns Chunk metrics
17
18
  */
18
- export declare function measureTextChunk(context: OffscreenCanvasRenderingContext2D, text: string, textStyle: UITextStyleConfig): UIChunkMetrics;
19
+ export declare function measureTextChunk(context: UICanvasRenderingContext2D, text: string, textStyle: UITextStyleConfig): UIChunkMetrics;
19
20
  /**
20
21
  * Builds text lines with word wrapping.
21
22
  * @param maxWidth Maximum line width in pixels
@@ -36,7 +37,7 @@ export declare function calculateTextSize(lines: UITextLine[]): UITextSize;
36
37
  * @param commonStyle Fallback style
37
38
  * @returns Measured text chunks
38
39
  */
39
- export declare function buildTextChunks(context: OffscreenCanvasRenderingContext2D, textSpans: UITextSpan[], commonStyle: UITextStyle): UITextChunk[];
40
+ export declare function buildTextChunks(context: UICanvasRenderingContext2D, textSpans: UITextSpan[], commonStyle: UITextStyle): UITextChunk[];
40
41
  /**
41
42
  * Calculates text layout parameters.
42
43
  * @param textChunks Measured text chunks
@@ -1,3 +1,4 @@
1
+ import type { UICanvasRenderingContext2D } from "../../miscellaneous/canvas";
1
2
  import type { UITextStyleConfig } from "../../miscellaneous/text-style/UITextStyle.Internal";
2
3
  import type { UITextLine } from "./UIText.Interfaces";
3
4
  /**
@@ -8,7 +9,7 @@ import type { UITextLine } from "./UIText.Interfaces";
8
9
  * @param style Resolved text style
9
10
  * @param context Canvas rendering context
10
11
  */
11
- export declare function renderTextChunk(x: number, y: number, text: string, style: UITextStyleConfig, context: OffscreenCanvasRenderingContext2D): void;
12
+ export declare function renderTextChunk(x: number, y: number, text: string, style: UITextStyleConfig, context: UICanvasRenderingContext2D): void;
12
13
  /**
13
14
  * Renders text lines to canvas.
14
15
  * @param paddingTop Top padding in pixels
@@ -16,4 +17,4 @@ export declare function renderTextChunk(x: number, y: number, text: string, styl
16
17
  * @param lines Text lines to render
17
18
  * @param context Canvas rendering context
18
19
  */
19
- export declare function renderTextLines(paddingTop: number, paddingLeft: number, lines: UITextLine[], context: OffscreenCanvasRenderingContext2D): void;
20
+ export declare function renderTextLines(paddingTop: number, paddingLeft: number, lines: UITextLine[], context: UICanvasRenderingContext2D): void;
package/dist/index.js CHANGED
@@ -6463,6 +6463,24 @@ class UIAnimatedImage extends UIElement {
6463
6463
  }
6464
6464
  }
6465
6465
 
6466
+ /**
6467
+ * Creates a canvas with OffscreenCanvas fallback to HTMLCanvasElement.
6468
+ * Uses OffscreenCanvas when available, falls back to HTMLCanvasElement otherwise.
6469
+ *
6470
+ * @param width - Canvas width in pixels
6471
+ * @param height - Canvas height in pixels
6472
+ * @returns Canvas instance
6473
+ */
6474
+ function createCanvas(width, height) {
6475
+ if (typeof OffscreenCanvas !== "undefined") {
6476
+ return new OffscreenCanvas(width, height);
6477
+ }
6478
+ const canvas = document.createElement("canvas");
6479
+ canvas.width = width;
6480
+ canvas.height = height;
6481
+ return canvas;
6482
+ }
6483
+
6466
6484
  const GRAPHICS_DEFAULT_WIDTH = 2;
6467
6485
  const GRAPHICS_DEFAULT_HEIGHT = 2;
6468
6486
  const GRAPHICS_TEMP_COLOR = new UIColor();
@@ -6479,10 +6497,10 @@ class UIGraphics extends UIElement {
6479
6497
  const w = options?.width ?? GRAPHICS_DEFAULT_WIDTH;
6480
6498
  const h = options?.height ?? GRAPHICS_DEFAULT_HEIGHT;
6481
6499
  const color = new UIColor(options?.color);
6482
- const canvas = new OffscreenCanvas(w, h);
6500
+ const canvas = createCanvas(w, h);
6483
6501
  const context = canvas.getContext("2d");
6484
6502
  if (!context) {
6485
- throw new Error("UIGraphics.constructor: failed to get 2D context from OffscreenCanvas");
6503
+ throw new Error("UIGraphics.constructor: failed to get 2D context from canvas");
6486
6504
  }
6487
6505
  const texture = new CanvasTexture(canvas);
6488
6506
  texture.colorSpace = SRGBColorSpace;
@@ -6491,7 +6509,7 @@ class UIGraphics extends UIElement {
6491
6509
  texture.needsUpdate = true;
6492
6510
  super(layer, source$4, {
6493
6511
  texture: texture,
6494
- textureTransform: new Matrix4(),
6512
+ textureTransform: new Matrix3(),
6495
6513
  color,
6496
6514
  }, options);
6497
6515
  this._private_canvas = canvas;
@@ -8124,7 +8142,7 @@ class UIText extends UIElement {
8124
8142
  * @param options - Configuration options
8125
8143
  */
8126
8144
  constructor(layer, content, options = {}) {
8127
- const canvas = new OffscreenCanvas(2, 2);
8145
+ const canvas = createCanvas(2, 2);
8128
8146
  const context = canvas.getContext("2d");
8129
8147
  if (!context) {
8130
8148
  throw new Error("UIText.constructor: failed to create canvas context");