laymur 0.27.1 → 0.29.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.
Files changed (138) hide show
  1. package/README.md +99 -5
  2. package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.d.ts +14 -3
  3. package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.js +40 -6
  4. package/dist/core/constraints/UICustomConstraint.js +2 -2
  5. package/dist/core/constraints/UIHeightConstraint/UIHeightConstraint.js +3 -2
  6. package/dist/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.js +3 -2
  7. package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +3 -2
  8. package/dist/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.js +3 -2
  9. package/dist/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.d.ts +6 -0
  10. package/dist/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.js +8 -0
  11. package/dist/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.js +3 -2
  12. package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +3 -2
  13. package/dist/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.js +3 -2
  14. package/dist/core/constraints/UIWidthConstraint/UIWidthConstraint.js +3 -2
  15. package/dist/core/constraints/constraintAsserts.d.ts +41 -0
  16. package/dist/core/constraints/constraintAsserts.js +171 -0
  17. package/dist/core/elements/UICanvasElement/UICanvasElement.d.ts +54 -0
  18. package/dist/core/elements/UICanvasElement/UICanvasElement.js +70 -0
  19. package/dist/core/elements/UIDummy/UIDummy.Internal.d.ts +2 -0
  20. package/dist/core/elements/UIDummy/UIDummy.d.ts +8 -5
  21. package/dist/core/elements/UIDummy/UIDummy.js +24 -11
  22. package/dist/core/elements/UIElement/UIElement.Internal.d.ts +6 -5
  23. package/dist/core/elements/UIElement/UIElement.Internal.js +0 -4
  24. package/dist/core/elements/UIElement/UIElement.d.ts +12 -6
  25. package/dist/core/elements/UIElement/UIElement.js +14 -7
  26. package/dist/core/elements/UIGraphics/UIGraphics.Internal.d.ts +42 -2
  27. package/dist/core/elements/UIGraphics/UIGraphics.Internal.js +2 -2
  28. package/dist/core/elements/UIGraphics/UIGraphics.d.ts +48 -34
  29. package/dist/core/elements/UIGraphics/UIGraphics.js +196 -93
  30. package/dist/core/elements/UIImage/UIImage.d.ts +11 -1
  31. package/dist/core/elements/UIImage/UIImage.js +14 -0
  32. package/dist/core/elements/UIScene/UIScene.Internal.d.ts +10 -1
  33. package/dist/core/elements/UIScene/UIScene.Internal.js +1 -0
  34. package/dist/core/elements/UIScene/UIScene.d.ts +11 -1
  35. package/dist/core/elements/UIScene/UIScene.js +29 -5
  36. package/dist/core/elements/UIText/UIText.Interfaces.d.ts +2 -2
  37. package/dist/core/elements/UIText/UIText.Internal.d.ts +14 -1
  38. package/dist/core/elements/UIText/UIText.Internal.js +12 -0
  39. package/dist/core/elements/UIText/UIText.Measuring.d.ts +9 -4
  40. package/dist/core/elements/UIText/UIText.Measuring.js +17 -6
  41. package/dist/core/elements/UIText/UIText.Rendering.d.ts +7 -16
  42. package/dist/core/elements/UIText/UIText.Rendering.js +212 -46
  43. package/dist/core/elements/UIText/UIText.d.ts +64 -29
  44. package/dist/core/elements/UIText/UIText.js +134 -149
  45. package/dist/core/index.d.ts +10 -4
  46. package/dist/core/index.js +5 -1
  47. package/dist/core/layers/UILayer/UILayer.d.ts +17 -3
  48. package/dist/core/layers/UILayer/UILayer.js +35 -4
  49. package/dist/core/layers/UIViewportLayer/UIViewportLayer.d.ts +2 -0
  50. package/dist/core/layers/UIViewportLayer/UIViewportLayer.js +4 -1
  51. package/dist/core/miscellaneous/UIBlendMode.d.ts +5 -0
  52. package/dist/core/miscellaneous/UIBlendMode.js +7 -0
  53. package/dist/core/miscellaneous/asserts.d.ts +0 -41
  54. package/dist/core/miscellaneous/asserts.js +0 -170
  55. package/dist/core/miscellaneous/canvas-surface/UICanvasSurface.d.ts +46 -0
  56. package/dist/core/miscellaneous/canvas-surface/UICanvasSurface.js +86 -0
  57. package/dist/core/miscellaneous/color/UIColor.d.ts +17 -0
  58. package/dist/core/miscellaneous/color/UIColor.js +22 -0
  59. package/dist/core/miscellaneous/color/canvasColor.d.ts +9 -0
  60. package/dist/core/miscellaneous/color/canvasColor.js +15 -0
  61. package/dist/core/miscellaneous/insets/UIInsets.d.ts +3 -0
  62. package/dist/core/miscellaneous/insets/UIInsets.js +15 -0
  63. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +10 -7
  64. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.js +11 -8
  65. package/dist/core/miscellaneous/paint/UIGradient.Internal.d.ts +37 -0
  66. package/dist/core/miscellaneous/paint/UIGradient.Internal.js +14 -0
  67. package/dist/core/miscellaneous/paint/UIGradient.d.ts +18 -0
  68. package/dist/core/miscellaneous/paint/UIGradient.js +35 -0
  69. package/dist/core/miscellaneous/paint/UILinearGradient.d.ts +14 -0
  70. package/dist/core/miscellaneous/paint/UILinearGradient.js +22 -0
  71. package/dist/core/miscellaneous/paint/UIPaint.Internal.d.ts +21 -0
  72. package/dist/core/miscellaneous/paint/UIPaint.Internal.js +1 -0
  73. package/dist/core/miscellaneous/paint/UIPaint.d.ts +17 -0
  74. package/dist/core/miscellaneous/paint/UIPaint.js +21 -0
  75. package/dist/core/miscellaneous/paint/UIRadialGradient.d.ts +18 -0
  76. package/dist/core/miscellaneous/paint/UIRadialGradient.js +33 -0
  77. package/dist/core/miscellaneous/shared.d.ts +14 -0
  78. package/dist/core/miscellaneous/shared.js +11 -0
  79. package/dist/core/miscellaneous/text-style/UITextStyle.Internal.d.ts +91 -30
  80. package/dist/core/miscellaneous/text-style/UITextStyle.Internal.js +12 -8
  81. package/dist/core/miscellaneous/text-style/UITextStyle.d.ts +41 -63
  82. package/dist/core/miscellaneous/text-style/UITextStyle.js +165 -291
  83. package/dist/core/miscellaneous/texture/UITextureView.Internal.d.ts +2 -1
  84. package/dist/core/miscellaneous/texture/UITextureView.Internal.js +12 -3
  85. package/dist/core/shaders/UIProgressMaskFunctionCircular.js +1 -2
  86. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +7 -3
  87. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +2 -1
  88. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +19 -10
  89. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +6 -2
  90. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.d.ts +41 -9
  91. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.js +97 -35
  92. package/dist/particles/behaviorModules/UIBehaviorAlignToVelocity.d.ts +44 -0
  93. package/dist/particles/behaviorModules/UIBehaviorAlignToVelocity.js +75 -0
  94. package/dist/particles/behaviorModules/UIBehaviorBounce.d.ts +51 -0
  95. package/dist/particles/behaviorModules/UIBehaviorBounce.js +107 -0
  96. package/dist/particles/behaviorModules/UIBehaviorOrbit.d.ts +39 -0
  97. package/dist/particles/behaviorModules/UIBehaviorOrbit.js +73 -0
  98. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.d.ts +7 -2
  99. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.js +9 -5
  100. package/dist/particles/behaviorModules/UIBehaviorSeek.d.ts +38 -0
  101. package/dist/particles/behaviorModules/UIBehaviorSeek.js +75 -0
  102. package/dist/particles/elements/UIEmitter.Internal.d.ts +48 -1
  103. package/dist/particles/elements/UIEmitter.Internal.js +26 -1
  104. package/dist/particles/elements/UIEmitter.Schedule.d.ts +31 -0
  105. package/dist/particles/elements/UIEmitter.Schedule.js +81 -0
  106. package/dist/particles/elements/UIEmitter.d.ts +79 -9
  107. package/dist/particles/elements/UIEmitter.js +241 -83
  108. package/dist/particles/index.d.ts +13 -1
  109. package/dist/particles/index.js +11 -1
  110. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.d.ts +6 -0
  111. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.js +27 -0
  112. package/dist/particles/instancedParticle/UIInstancedParticle.d.ts +7 -1
  113. package/dist/particles/instancedParticle/UIInstancedParticle.js +12 -1
  114. package/dist/particles/miscellaneous/miscellaneous.d.ts +22 -0
  115. package/dist/particles/miscellaneous/miscellaneous.js +38 -0
  116. package/dist/particles/renderingModules/UIRenderingFlipbook.d.ts +41 -0
  117. package/dist/particles/renderingModules/UIRenderingFlipbook.js +70 -0
  118. package/dist/particles/renderingModules/UIRenderingModule.d.ts +2 -1
  119. package/dist/particles/renderingModules/UIRenderingModule.js +2 -1
  120. package/dist/particles/renderingModules/UIRenderingRandomColor.d.ts +19 -0
  121. package/dist/particles/renderingModules/UIRenderingRandomColor.js +28 -0
  122. package/dist/particles/renderingModules/UIRenderingShape.d.ts +31 -0
  123. package/dist/particles/renderingModules/UIRenderingShape.js +54 -0
  124. package/dist/particles/renderingModules/UIRenderingTexture.d.ts +1 -1
  125. package/dist/particles/renderingModules/UIRenderingTexture.js +4 -28
  126. package/dist/particles/shaders/UIRenderingFlipbook.d.ts +5 -0
  127. package/dist/particles/shaders/UIRenderingFlipbook.js +19 -0
  128. package/dist/particles/shaders/UIRenderingRandomColor.d.ts +2 -0
  129. package/dist/particles/shaders/UIRenderingRandomColor.js +10 -0
  130. package/dist/particles/shaders/UIRenderingShape.d.ts +6 -0
  131. package/dist/particles/shaders/UIRenderingShape.js +15 -0
  132. package/dist/particles/shaders/UIRenderingTexture.d.ts +4 -2
  133. package/dist/particles/shaders/UIRenderingTexture.js +27 -2
  134. package/dist/particles/spawnModules/UISpawnCircle.d.ts +44 -0
  135. package/dist/particles/spawnModules/UISpawnCircle.js +81 -0
  136. package/dist/particles/spawnModules/UISpawnRadialVelocity.d.ts +37 -0
  137. package/dist/particles/spawnModules/UISpawnRadialVelocity.js +75 -0
  138. package/package.json +1 -1
@@ -1,13 +1,16 @@
1
1
  import source from "../../shaders/UIProgressMaskFunctionCircular.js";
2
2
  import { assertValidNumber } from "../asserts.js";
3
3
  import { UIProgressMaskFunction } from "./UIProgressMaskFunction.js";
4
- /** Circular radial progress fill */
4
+ /**
5
+ * Circular radial progress fill. Angles are in radians, measured counter-clockwise from the
6
+ * positive x axis, so 0 is the right edge and PI / 2 is the top.
7
+ */
5
8
  export class UIProgressMaskFunctionCircular extends UIProgressMaskFunction {
6
9
  /**
7
10
  * Creates circular mask function.
8
11
  *
9
- * @param startAngle - Starting angle in radians
10
- * @param inverseDirection - Whether to fill counter-clockwise
12
+ * @param startAngle - Angle the fill starts from, in radians
13
+ * @param inverseDirection - Whether to fill clockwise instead of counter-clockwise
11
14
  */
12
15
  constructor(startAngle = 0, inverseDirection = false) {
13
16
  assertValidNumber(startAngle, "UIProgressMaskFunctionCircular.constructor.startAngle");
@@ -15,15 +18,15 @@ export class UIProgressMaskFunctionCircular extends UIProgressMaskFunction {
15
18
  this.startAngleInternal = startAngle;
16
19
  this.inverseDirectionInternal = inverseDirection;
17
20
  }
18
- /** Starting angle in radians */
21
+ /** Angle the fill starts from, in radians */
19
22
  get startAngle() {
20
23
  return this.startAngleInternal;
21
24
  }
22
- /** Whether fill is counter-clockwise */
25
+ /** Whether the fill goes clockwise instead of counter-clockwise */
23
26
  get inverseDirection() {
24
27
  return this.inverseDirectionInternal;
25
28
  }
26
- /** Starting angle in radians */
29
+ /** Angle the fill starts from, in radians */
27
30
  set startAngle(value) {
28
31
  assertValidNumber(value, "UIProgressMaskFunctionCircular.startAngle");
29
32
  if (this.startAngleInternal !== value) {
@@ -31,7 +34,7 @@ export class UIProgressMaskFunctionCircular extends UIProgressMaskFunction {
31
34
  this.dirtyInternal = true;
32
35
  }
33
36
  }
34
- /** Whether fill is counter-clockwise */
37
+ /** Whether the fill goes clockwise instead of counter-clockwise */
35
38
  set inverseDirection(value) {
36
39
  if (this.inverseDirectionInternal !== value) {
37
40
  this.inverseDirectionInternal = value;
@@ -41,7 +44,7 @@ export class UIProgressMaskFunctionCircular extends UIProgressMaskFunction {
41
44
  enumerateProperties() {
42
45
  return {
43
46
  direction: this.inverseDirectionInternal ? -1 : 1,
44
- startAngle: this.startAngleInternal,
47
+ startAngle: this.startAngleInternal / (2 * Math.PI),
45
48
  };
46
49
  }
47
50
  }
@@ -0,0 +1,37 @@
1
+ import type { UIColorConfig } from "../color/UIColor.Internal.js";
2
+ /** Color stop of a gradient */
3
+ export interface UIGradientStop {
4
+ /** Position along the gradient, from 0 to 1 */
5
+ offset: number;
6
+ /** Color at the position. A string is a `UIColor` name or a CSS color. */
7
+ color: UIColorConfig;
8
+ }
9
+ /** Geometry of a linear gradient, in fractions of the filled box from its top left corner */
10
+ export interface UILinearGradientOptions {
11
+ /** Horizontal position of the start */
12
+ startX: number;
13
+ /** Vertical position of the start */
14
+ startY: number;
15
+ /** Horizontal position of the end */
16
+ endX: number;
17
+ /** Vertical position of the end */
18
+ endY: number;
19
+ }
20
+ /**
21
+ * Geometry of a radial gradient. The center is in fractions of the filled box from its top left
22
+ * corner, the radii in fractions of its longer side.
23
+ */
24
+ export interface UIRadialGradientOptions {
25
+ /** Horizontal position of the center */
26
+ centerX: number;
27
+ /** Vertical position of the center */
28
+ centerY: number;
29
+ /** Radius where offset 0 is */
30
+ innerRadius: number;
31
+ /** Radius where offset 1 is */
32
+ outerRadius: number;
33
+ }
34
+ /** From the top edge to the bottom one */
35
+ export declare const LINEAR_GRADIENT_DEFAULT_OPTIONS: UILinearGradientOptions;
36
+ /** From the center to the ends of the longer axis, the middles of the shorter sides */
37
+ export declare const RADIAL_GRADIENT_DEFAULT_OPTIONS: UIRadialGradientOptions;
@@ -0,0 +1,14 @@
1
+ /** From the top edge to the bottom one */
2
+ export const LINEAR_GRADIENT_DEFAULT_OPTIONS = {
3
+ startX: 0.5,
4
+ startY: 0,
5
+ endX: 0.5,
6
+ endY: 1,
7
+ };
8
+ /** From the center to the ends of the longer axis, the middles of the shorter sides */
9
+ export const RADIAL_GRADIENT_DEFAULT_OPTIONS = {
10
+ centerX: 0.5,
11
+ centerY: 0.5,
12
+ innerRadius: 0,
13
+ outerRadius: 0.5,
14
+ };
@@ -0,0 +1,18 @@
1
+ import type { UICanvasRenderingContext2D } from "../canvas.js";
2
+ import type { UIGradientStop } from "./UIGradient.Internal.js";
3
+ import type { UIPaintBox } from "./UIPaint.Internal.js";
4
+ /**
5
+ * Base class for gradients that fill text, its strokes and the shapes of `UIGraphics`. A gradient
6
+ * is laid over the box of what it fills, so its geometry is given in fractions of that box, from
7
+ * the top left corner, y pointing down. A gradient does not change after it is created.
8
+ */
9
+ export declare abstract class UIGradient {
10
+ private readonly stops;
11
+ /**
12
+ * @param stops Color stops, at least one. Their order does not matter.
13
+ * @throws If there are no stops or an offset is outside 0 to 1
14
+ */
15
+ constructor(stops: readonly UIGradientStop[]);
16
+ /** Creates the canvas gradient of this geometry over the box, without stops */
17
+ protected abstract createCanvasGeometry(context: UICanvasRenderingContext2D, box: UIPaintBox): CanvasGradient;
18
+ }
@@ -0,0 +1,35 @@
1
+ import { assertValidUnitNumber } from "../asserts.js";
2
+ import { toCanvasColor } from "../color/canvasColor.js";
3
+ /**
4
+ * Base class for gradients that fill text, its strokes and the shapes of `UIGraphics`. A gradient
5
+ * is laid over the box of what it fills, so its geometry is given in fractions of that box, from
6
+ * the top left corner, y pointing down. A gradient does not change after it is created.
7
+ */
8
+ export class UIGradient {
9
+ /**
10
+ * @param stops Color stops, at least one. Their order does not matter.
11
+ * @throws If there are no stops or an offset is outside 0 to 1
12
+ */
13
+ constructor(stops) {
14
+ if (stops.length === 0) {
15
+ throw new Error("UIGradient.constructor.stops: at least one stop is required");
16
+ }
17
+ for (const stop of stops) {
18
+ assertValidUnitNumber(stop.offset, "UIGradient.constructor.stops.offset");
19
+ }
20
+ this.stops = stops
21
+ .map((stop) => ({ offset: stop.offset, color: toCanvasColor(stop.color) }))
22
+ .sort((a, b) => a.offset - b.offset);
23
+ }
24
+ /**
25
+ * Builds the canvas gradient over a box given in the current canvas coordinates.
26
+ * @internal
27
+ */
28
+ createCanvasGradient(context, box) {
29
+ const gradient = this.createCanvasGeometry(context, box);
30
+ for (const stop of this.stops) {
31
+ gradient.addColorStop(stop.offset, stop.color);
32
+ }
33
+ return gradient;
34
+ }
35
+ }
@@ -0,0 +1,14 @@
1
+ import type { UICanvasRenderingContext2D } from "../canvas.js";
2
+ import type { UIGradientStop, UILinearGradientOptions } from "./UIGradient.Internal.js";
3
+ import { UIGradient } from "./UIGradient.js";
4
+ import type { UIPaintBox } from "./UIPaint.Internal.js";
5
+ /** Gradient along a line from a start point to an end point, top to bottom by default */
6
+ export declare class UILinearGradient extends UIGradient {
7
+ private readonly options;
8
+ /**
9
+ * @param stops Color stops, at least one
10
+ * @param options Start and end in fractions of the filled box
11
+ */
12
+ constructor(stops: readonly UIGradientStop[], options?: Partial<UILinearGradientOptions>);
13
+ protected createCanvasGeometry(context: UICanvasRenderingContext2D, box: UIPaintBox): CanvasGradient;
14
+ }
@@ -0,0 +1,22 @@
1
+ import { assertValidNumber } from "../asserts.js";
2
+ import { LINEAR_GRADIENT_DEFAULT_OPTIONS } from "./UIGradient.Internal.js";
3
+ import { UIGradient } from "./UIGradient.js";
4
+ /** Gradient along a line from a start point to an end point, top to bottom by default */
5
+ export class UILinearGradient extends UIGradient {
6
+ /**
7
+ * @param stops Color stops, at least one
8
+ * @param options Start and end in fractions of the filled box
9
+ */
10
+ constructor(stops, options = {}) {
11
+ super(stops);
12
+ this.options = { ...LINEAR_GRADIENT_DEFAULT_OPTIONS, ...options };
13
+ assertValidNumber(this.options.startX, "UILinearGradient.constructor.options.startX");
14
+ assertValidNumber(this.options.startY, "UILinearGradient.constructor.options.startY");
15
+ assertValidNumber(this.options.endX, "UILinearGradient.constructor.options.endX");
16
+ assertValidNumber(this.options.endY, "UILinearGradient.constructor.options.endY");
17
+ }
18
+ createCanvasGeometry(context, box) {
19
+ const { startX, startY, endX, endY } = this.options;
20
+ return context.createLinearGradient(box.x + startX * box.width, box.y + startY * box.height, box.x + endX * box.width, box.y + endY * box.height);
21
+ }
22
+ }
@@ -0,0 +1,21 @@
1
+ import type { UIColorConfig } from "../color/UIColor.Internal.js";
2
+ import type { UIGradient } from "./UIGradient.js";
3
+ /** Fill of text, a stroke or a shape, either a color or a gradient. A string is a `UIColor` name or a CSS color. */
4
+ export type UIPaintConfig = UIColorConfig | UIGradient;
5
+ /** Paint as it is stored, a CSS color string or a gradient */
6
+ export type UIPaint = string | UIGradient;
7
+ /** How the corners of a stroke are joined */
8
+ export type UILineJoin = "round" | "bevel" | "miter";
9
+ /** How the open ends of a stroke look */
10
+ export type UILineCap = "butt" | "round" | "square";
11
+ /** Box a gradient is laid over, in canvas coordinates */
12
+ export interface UIPaintBox {
13
+ /** Left edge */
14
+ x: number;
15
+ /** Top edge */
16
+ y: number;
17
+ /** Width */
18
+ width: number;
19
+ /** Height */
20
+ height: number;
21
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { UICanvasRenderingContext2D } from "../canvas.js";
2
+ import type { UIPaint, UIPaintBox, UIPaintConfig } from "./UIPaint.Internal.js";
3
+ /**
4
+ * Converts a paint config to the stored paint. Colors become CSS strings, so a `UIColor` changed
5
+ * later does not change the paint.
6
+ * @param paint Paint to convert
7
+ * @returns CSS color string or the gradient itself
8
+ */
9
+ export declare function resolvePaint(paint: UIPaintConfig): UIPaint;
10
+ /**
11
+ * Builds the canvas fill or stroke style of a paint.
12
+ * @param context Canvas context the style is used on
13
+ * @param paint Stored paint
14
+ * @param box Box a gradient is laid over, in the current canvas coordinates
15
+ * @returns Value for `fillStyle` or `strokeStyle`
16
+ */
17
+ export declare function toCanvasPaint(context: UICanvasRenderingContext2D, paint: UIPaint, box: UIPaintBox): string | CanvasGradient;
@@ -0,0 +1,21 @@
1
+ import { toCanvasColor } from "../color/canvasColor.js";
2
+ import { UIGradient } from "./UIGradient.js";
3
+ /**
4
+ * Converts a paint config to the stored paint. Colors become CSS strings, so a `UIColor` changed
5
+ * later does not change the paint.
6
+ * @param paint Paint to convert
7
+ * @returns CSS color string or the gradient itself
8
+ */
9
+ export function resolvePaint(paint) {
10
+ return paint instanceof UIGradient ? paint : toCanvasColor(paint);
11
+ }
12
+ /**
13
+ * Builds the canvas fill or stroke style of a paint.
14
+ * @param context Canvas context the style is used on
15
+ * @param paint Stored paint
16
+ * @param box Box a gradient is laid over, in the current canvas coordinates
17
+ * @returns Value for `fillStyle` or `strokeStyle`
18
+ */
19
+ export function toCanvasPaint(context, paint, box) {
20
+ return typeof paint === "string" ? paint : paint.createCanvasGradient(context, box);
21
+ }
@@ -0,0 +1,18 @@
1
+ import type { UICanvasRenderingContext2D } from "../canvas.js";
2
+ import type { UIGradientStop, UIRadialGradientOptions } from "./UIGradient.Internal.js";
3
+ import { UIGradient } from "./UIGradient.js";
4
+ import type { UIPaintBox } from "./UIPaint.Internal.js";
5
+ /**
6
+ * Circular gradient between two radii around a center, by default from the center to the ends of
7
+ * the longer axis of the box. The circle stays round in a box that is not square.
8
+ */
9
+ export declare class UIRadialGradient extends UIGradient {
10
+ private readonly options;
11
+ /**
12
+ * @param stops Color stops, at least one
13
+ * @param options Center in fractions of the filled box, radii in fractions of its longer side
14
+ * @throws If the outer radius is not larger than the inner one
15
+ */
16
+ constructor(stops: readonly UIGradientStop[], options?: Partial<UIRadialGradientOptions>);
17
+ protected createCanvasGeometry(context: UICanvasRenderingContext2D, box: UIPaintBox): CanvasGradient;
18
+ }
@@ -0,0 +1,33 @@
1
+ import { assertValidNonNegativeNumber, assertValidNumber } from "../asserts.js";
2
+ import { RADIAL_GRADIENT_DEFAULT_OPTIONS } from "./UIGradient.Internal.js";
3
+ import { UIGradient } from "./UIGradient.js";
4
+ /**
5
+ * Circular gradient between two radii around a center, by default from the center to the ends of
6
+ * the longer axis of the box. The circle stays round in a box that is not square.
7
+ */
8
+ export class UIRadialGradient extends UIGradient {
9
+ /**
10
+ * @param stops Color stops, at least one
11
+ * @param options Center in fractions of the filled box, radii in fractions of its longer side
12
+ * @throws If the outer radius is not larger than the inner one
13
+ */
14
+ constructor(stops, options = {}) {
15
+ super(stops);
16
+ this.options = { ...RADIAL_GRADIENT_DEFAULT_OPTIONS, ...options };
17
+ const { centerX, centerY, innerRadius, outerRadius } = this.options;
18
+ assertValidNumber(centerX, "UIRadialGradient.constructor.options.centerX");
19
+ assertValidNumber(centerY, "UIRadialGradient.constructor.options.centerY");
20
+ assertValidNonNegativeNumber(innerRadius, "UIRadialGradient.constructor.options.innerRadius");
21
+ assertValidNonNegativeNumber(outerRadius, "UIRadialGradient.constructor.options.outerRadius");
22
+ if (outerRadius <= innerRadius) {
23
+ throw new Error("UIRadialGradient.constructor.options.outerRadius: must be larger than innerRadius");
24
+ }
25
+ }
26
+ createCanvasGeometry(context, box) {
27
+ const { centerX, centerY, innerRadius, outerRadius } = this.options;
28
+ const x = box.x + centerX * box.width;
29
+ const y = box.y + centerY * box.height;
30
+ const side = Math.max(box.width, box.height);
31
+ return context.createRadialGradient(x, y, innerRadius * side, x, y, outerRadius * side);
32
+ }
33
+ }
@@ -1,3 +1,4 @@
1
+ import type { FerrsignView1 } from "ferrsign";
1
2
  import { UILayer } from "../layers/UILayer/UILayer.js";
2
3
  /** Objects that belong to a UI layer */
3
4
  export interface UILayerElement {
@@ -34,6 +35,19 @@ export interface UIPlaneElement extends UIPointElement {
34
35
  /** Center Y coordinate in world units */
35
36
  readonly centerY: number;
36
37
  }
38
+ /** UI elements whose content has its own aspect ratio, such as a picture or laid out text */
39
+ export interface UIContentAspectElement {
40
+ /** Width of the content divided by its height */
41
+ readonly contentAspect: number;
42
+ /** Signal fired with the new aspect when the content changes it */
43
+ readonly signalContentAspectChanged: FerrsignView1<number>;
44
+ }
45
+ /**
46
+ * Checks if object implements UIContentAspectElement.
47
+ * @param obj Object to check
48
+ * @returns True if object reports the aspect of its content
49
+ */
50
+ export declare function isUIContentAspectElement(obj: unknown): obj is UIContentAspectElement;
37
51
  /**
38
52
  * Checks if object implements UILayerElement.
39
53
  * @param obj Object to check
@@ -1,4 +1,15 @@
1
1
  import { UILayer } from "../layers/UILayer/UILayer.js";
2
+ /**
3
+ * Checks if object implements UIContentAspectElement.
4
+ * @param obj Object to check
5
+ * @returns True if object reports the aspect of its content
6
+ */
7
+ export function isUIContentAspectElement(obj) {
8
+ return (typeof obj === "object" &&
9
+ obj !== null &&
10
+ "contentAspect" in obj &&
11
+ "signalContentAspectChanged" in obj);
12
+ }
2
13
  /**
3
14
  * Checks if object implements UILayerElement.
4
15
  * @param obj Object to check
@@ -1,9 +1,67 @@
1
+ import type { UIColorConfig } from "../color/UIColor.Internal.js";
2
+ import type { UILineJoin, UIPaint, UIPaintConfig } from "../paint/UIPaint.Internal.js";
1
3
  /** Text alignment. `start` and `end` are resolved against the text direction. */
2
4
  export type UITextAlign = "start" | "left" | "center" | "right" | "end";
3
- /** Complete text style configuration with all properties resolved */
5
+ /** Font style */
6
+ export type UITextFontStyle = "normal" | "italic" | "oblique";
7
+ /** Font weight */
8
+ export type UITextFontWeight = "normal" | "bold" | "bolder" | "lighter" | number;
9
+ /** Box a gradient of the fill or of a stroke is laid over */
10
+ export declare enum UITextPaintBox {
11
+ /** Each line, as high as its line box (see `UIText.lineBox`) */
12
+ LINE = 0,
13
+ /** The whole text without its padding */
14
+ TEXT = 1
15
+ }
16
+ /** Outline around the glyphs */
17
+ export interface UITextStrokeConfig {
18
+ /** Color or gradient of the outline */
19
+ paint: UIPaintConfig;
20
+ /** Width of the outline outside the glyphs, or outside the previous outline, in pixels */
21
+ thickness: number;
22
+ /** How the corners are joined. Round by default. */
23
+ join?: UILineJoin;
24
+ }
25
+ /** Outline around the glyphs, as stored by a style */
26
+ export interface UITextStroke {
27
+ /** Color or gradient of the outline */
28
+ readonly paint: UIPaint;
29
+ /** Width of the outline outside the glyphs, or outside the previous outline, in pixels */
30
+ readonly thickness: number;
31
+ /** How the corners are joined */
32
+ readonly join: UILineJoin;
33
+ }
34
+ /**
35
+ * Shadow cast by the glyphs together with their outlines. A shadow without an offset and with a
36
+ * blur is a glow.
37
+ */
38
+ export interface UITextShadowConfig {
39
+ /** Shadow color. A string is a `UIColor` name or a CSS color. */
40
+ color: UIColorConfig;
41
+ /** Horizontal offset in pixels, 0 by default */
42
+ offsetX?: number;
43
+ /** Vertical offset in pixels, down is positive, 0 by default */
44
+ offsetY?: number;
45
+ /** Blur radius in pixels, 0 by default */
46
+ blur?: number;
47
+ }
48
+ /** Shadow, as stored by a style */
49
+ export interface UITextShadow {
50
+ /** Shadow color as a CSS color */
51
+ readonly color: string;
52
+ /** Horizontal offset in pixels */
53
+ readonly offsetX: number;
54
+ /** Vertical offset in pixels, down is positive */
55
+ readonly offsetY: number;
56
+ /** Blur radius in pixels */
57
+ readonly blur: number;
58
+ }
59
+ /** Text style configuration */
4
60
  export interface UITextStyleConfig {
5
- /** Text color */
6
- color: string;
61
+ /** Color or gradient of the glyphs. A string is a `UIColor` name or a CSS color. */
62
+ color: UIPaintConfig;
63
+ /** Box the gradients of the fill and of the strokes are laid over */
64
+ paintBox: UITextPaintBox;
7
65
  /** Text alignment */
8
66
  align: UITextAlign;
9
67
  /** Font family name */
@@ -11,40 +69,43 @@ export interface UITextStyleConfig {
11
69
  /** Font size in pixels */
12
70
  fontSize: number;
13
71
  /** Font style */
14
- fontStyle: "normal" | "italic" | "oblique";
72
+ fontStyle: UITextFontStyle;
15
73
  /** Font weight */
16
- fontWeight: "normal" | "bold" | "bolder" | "lighter" | number;
17
- /** Line height in pixels */
74
+ fontWeight: UITextFontWeight;
75
+ /**
76
+ * Line height in pixels, the distance between baselines, not a multiple of the font size.
77
+ * Defaults to 1.2 times the font size.
78
+ */
79
+ lineHeight: number;
80
+ /**
81
+ * Outlines from the innermost to the outermost. Each one lies outside the previous one, so the
82
+ * text is as wide as the sum of their thicknesses on each side.
83
+ */
84
+ strokes: readonly UITextStrokeConfig[];
85
+ /** Shadows and glows, the first one on top */
86
+ shadows: readonly UITextShadowConfig[];
87
+ }
88
+ /** Text style with every property resolved, as the text is measured and drawn with */
89
+ export interface UIResolvedTextStyle {
90
+ color: UIPaint;
91
+ paintBox: UITextPaintBox;
92
+ align: UITextAlign;
93
+ fontFamily: string;
94
+ fontSize: number;
95
+ fontStyle: UITextFontStyle;
96
+ fontWeight: UITextFontWeight;
18
97
  lineHeight: number;
19
- /** Whether shadow is enabled */
20
- enableShadow: boolean;
21
- /** Shadow horizontal offset in pixels */
22
- shadowOffsetX: number;
23
- /** Shadow vertical offset in pixels */
24
- shadowOffsetY: number;
25
- /** Shadow blur radius in pixels */
26
- shadowBlur: number;
27
- /** Shadow color */
28
- shadowColor: string;
29
- /** Whether stroke is enabled */
30
- enableStroke: boolean;
31
- /** Stroke color */
32
- strokeColor: string;
33
- /** Stroke thickness in pixels */
34
- strokeThickness: number;
98
+ strokes: readonly UITextStroke[];
99
+ shadows: readonly UITextShadow[];
35
100
  }
36
101
  export declare const TEXT_STYLE_DEFAULT_COLOR = "#000000";
102
+ export declare const TEXT_STYLE_DEFAULT_PAINT_BOX = UITextPaintBox.LINE;
37
103
  export declare const TEXT_STYLE_DEFAULT_ALIGN: "start";
38
104
  export declare const TEXT_STYLE_DEFAULT_FONT_FAMILY = "Arial";
39
105
  export declare const TEXT_STYLE_DEFAULT_FONT_SIZE = 16;
40
106
  export declare const TEXT_STYLE_DEFAULT_FONT_STYLE: "normal";
41
107
  export declare const TEXT_STYLE_DEFAULT_FONT_WEIGHT: "normal";
42
108
  export declare const TEXT_STYLE_DEFAULT_LINE_HEIGHT = 1.2;
43
- export declare const TEXT_STYLE_DEFAULT_ENABLE_SHADOW = false;
44
- export declare const TEXT_STYLE_DEFAULT_SHADOW_OFFSET_X = 0;
45
- export declare const TEXT_STYLE_DEFAULT_SHADOW_OFFSET_Y = 0;
46
- export declare const TEXT_STYLE_DEFAULT_SHADOW_BLUR = 0;
47
- export declare const TEXT_STYLE_DEFAULT_SHADOW_COLOR = "transparent";
48
- export declare const TEXT_STYLE_DEFAULT_ENABLE_STROKE = false;
49
- export declare const TEXT_STYLE_DEFAULT_STROKE_COLOR = "#000000";
50
- export declare const TEXT_STYLE_DEFAULT_STROKE_THICKNESS = 0;
109
+ export declare const TEXT_STYLE_DEFAULT_STROKES: readonly UITextStroke[];
110
+ export declare const TEXT_STYLE_DEFAULT_SHADOWS: readonly UITextShadow[];
111
+ export declare const TEXT_STYLE_DEFAULT_STROKE_JOIN: "round";
@@ -1,15 +1,19 @@
1
+ /** Box a gradient of the fill or of a stroke is laid over */
2
+ export var UITextPaintBox;
3
+ (function (UITextPaintBox) {
4
+ /** Each line, as high as its line box (see `UIText.lineBox`) */
5
+ UITextPaintBox[UITextPaintBox["LINE"] = 0] = "LINE";
6
+ /** The whole text without its padding */
7
+ UITextPaintBox[UITextPaintBox["TEXT"] = 1] = "TEXT";
8
+ })(UITextPaintBox || (UITextPaintBox = {}));
1
9
  export const TEXT_STYLE_DEFAULT_COLOR = "#000000";
10
+ export const TEXT_STYLE_DEFAULT_PAINT_BOX = UITextPaintBox.LINE;
2
11
  export const TEXT_STYLE_DEFAULT_ALIGN = "start";
3
12
  export const TEXT_STYLE_DEFAULT_FONT_FAMILY = "Arial";
4
13
  export const TEXT_STYLE_DEFAULT_FONT_SIZE = 16;
5
14
  export const TEXT_STYLE_DEFAULT_FONT_STYLE = "normal";
6
15
  export const TEXT_STYLE_DEFAULT_FONT_WEIGHT = "normal";
7
16
  export const TEXT_STYLE_DEFAULT_LINE_HEIGHT = 1.2;
8
- export const TEXT_STYLE_DEFAULT_ENABLE_SHADOW = false;
9
- export const TEXT_STYLE_DEFAULT_SHADOW_OFFSET_X = 0;
10
- export const TEXT_STYLE_DEFAULT_SHADOW_OFFSET_Y = 0;
11
- export const TEXT_STYLE_DEFAULT_SHADOW_BLUR = 0;
12
- export const TEXT_STYLE_DEFAULT_SHADOW_COLOR = "transparent";
13
- export const TEXT_STYLE_DEFAULT_ENABLE_STROKE = false;
14
- export const TEXT_STYLE_DEFAULT_STROKE_COLOR = "#000000";
15
- export const TEXT_STYLE_DEFAULT_STROKE_THICKNESS = 0;
17
+ export const TEXT_STYLE_DEFAULT_STROKES = Object.freeze([]);
18
+ export const TEXT_STYLE_DEFAULT_SHADOWS = Object.freeze([]);
19
+ export const TEXT_STYLE_DEFAULT_STROKE_JOIN = "round";