laymur 0.13.2 → 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.
- package/dist/elements/UIText/UIText.Measuring.d.ts +3 -2
- package/dist/elements/UIText/UIText.Rendering.d.ts +3 -2
- package/dist/index.js +21 -3
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/miscellaneous/canvas.d.ts +13 -0
- package/package.json +1 -1
|
@@ -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:
|
|
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:
|
|
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:
|
|
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:
|
|
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 =
|
|
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
|
|
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;
|
|
@@ -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 =
|
|
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");
|