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
@@ -0,0 +1,171 @@
1
+ import { UILayer } from "../layers/UILayer/UILayer.js";
2
+ import { EPSILON } from "../miscellaneous/math.js";
3
+ import { isUILayerElement } from "../miscellaneous/shared.js";
4
+ /**
5
+ * Validates constraint arguments are from same layer.
6
+ * @param a First constraint subject
7
+ * @param b Second constraint subject
8
+ * @param subject Constraint name for error messages
9
+ * @returns Common layer for both subjects
10
+ * @throws If subjects are invalid or from different layers
11
+ */
12
+ export function assertValidConstraintArguments(a, b, subject) {
13
+ if (process.env.NODE_ENV !== "production") {
14
+ assertNotDestroyed(a, "A", subject);
15
+ assertNotDestroyed(b, "B", subject);
16
+ if (a instanceof UILayer && b instanceof UILayer) {
17
+ throw new Error(`${subject}: layer cannot be snapped to another layer`);
18
+ }
19
+ let layerA;
20
+ let layerB;
21
+ if (a instanceof UILayer) {
22
+ layerA = a;
23
+ }
24
+ else if (isUILayerElement(a)) {
25
+ layerA = a.layer;
26
+ }
27
+ else {
28
+ throw new Error(`${subject}: A must be a UILayer or a UILayerElement`);
29
+ }
30
+ if (b instanceof UILayer) {
31
+ layerB = b;
32
+ }
33
+ else if (isUILayerElement(b)) {
34
+ layerB = b.layer;
35
+ }
36
+ else {
37
+ throw new Error(`${subject}: B must be a UILayer or a UILayerElement`);
38
+ }
39
+ if (layerA !== layerB) {
40
+ throw new Error(`${subject}: elements must be on the same layer`);
41
+ }
42
+ return layerA;
43
+ }
44
+ if (a instanceof UILayer) {
45
+ return a;
46
+ }
47
+ if (isUILayerElement(a)) {
48
+ return a.layer;
49
+ }
50
+ if (b instanceof UILayer) {
51
+ return b;
52
+ }
53
+ if (isUILayerElement(b)) {
54
+ return b.layer;
55
+ }
56
+ throw new Error(`${subject}: A or B must be a UILayer or a UILayerElement`);
57
+ }
58
+ /**
59
+ * Validates interpolation constraint subjects.
60
+ * @param subject Constraint name for error messages
61
+ * @param a First element
62
+ * @param b Second element
63
+ * @param c Element to interpolate
64
+ * @param anchorA Anchor on element A
65
+ * @param anchorB Anchor on element B
66
+ * @returns Common layer for all subjects
67
+ * @throws If subjects violate interpolation constraints
68
+ */
69
+ export function assertValidInterpolationConstraintArguments(subject, a, b, c, anchorA, anchorB) {
70
+ if (process.env.NODE_ENV !== "production") {
71
+ assertNotDestroyed(a, "A", subject);
72
+ assertNotDestroyed(b, "B", subject);
73
+ assertNotDestroyed(c, "C", subject);
74
+ if (c instanceof UILayer) {
75
+ throw new Error(`${subject}: C cannot be a layer`);
76
+ }
77
+ if (!isUILayerElement(c)) {
78
+ throw new Error(`${subject}: C must be a UILayerElement`);
79
+ }
80
+ let layerA;
81
+ let layerB;
82
+ if (a instanceof UILayer || isUILayerElement(a)) {
83
+ layerA = a instanceof UILayer ? a : a.layer;
84
+ }
85
+ else {
86
+ throw new Error(`${subject}: A must be a UILayer or a UILayerElement`);
87
+ }
88
+ if (b instanceof UILayer || isUILayerElement(b)) {
89
+ layerB = b instanceof UILayer ? b : b.layer;
90
+ }
91
+ else {
92
+ throw new Error(`${subject}: B must be a UILayer or a UILayerElement`);
93
+ }
94
+ const layerC = c.layer;
95
+ if (layerA !== layerB || layerA !== layerC) {
96
+ throw new Error(`${subject}: all elements must be on the same layer`);
97
+ }
98
+ if (c === a || c === b) {
99
+ throw new Error(`${subject}: C cannot be equal to A or B`);
100
+ }
101
+ if (a === b) {
102
+ if (Math.abs(anchorA - anchorB) <= EPSILON) {
103
+ throw new Error(`${subject}: when A and B are the same, anchorA and anchorB must differ by more than ${EPSILON}`);
104
+ }
105
+ }
106
+ return layerA;
107
+ }
108
+ if (isUILayerElement(a)) {
109
+ return a.layer;
110
+ }
111
+ if (isUILayerElement(b)) {
112
+ return b.layer;
113
+ }
114
+ if (a instanceof UILayer) {
115
+ return a;
116
+ }
117
+ if (b instanceof UILayer) {
118
+ return b;
119
+ }
120
+ throw new Error(`${subject}: A or B must be a UILayer or a UILayerElement`);
121
+ }
122
+ /**
123
+ * Validates the element of a single element constraint.
124
+ * @param element Constrained element
125
+ * @param subject Constraint name for error messages
126
+ * @returns Layer of the element
127
+ * @throws If the element is destroyed
128
+ */
129
+ export function assertValidConstraintElement(element, subject) {
130
+ if (process.env.NODE_ENV !== "production") {
131
+ assertNotDestroyed(element, "element", subject);
132
+ }
133
+ return element.layer;
134
+ }
135
+ /**
136
+ * Validates that the expressions of a custom constraint refer only to existing variables.
137
+ * @param layer Layer of the constraint
138
+ * @param expressions Constraint expressions
139
+ * @param subject Constraint name for error messages
140
+ * @returns The layer
141
+ * @throws If the layer is destroyed or a variable does not exist
142
+ */
143
+ export function assertValidConstraintExpressions(layer, expressions, subject) {
144
+ if (process.env.NODE_ENV !== "production") {
145
+ assertNotDestroyed(layer, "layer", subject);
146
+ for (const expression of expressions) {
147
+ for (const [variableIndex] of expression.prepareTerms()) {
148
+ if (!layer.solverWrapper.hasVariable(variableIndex)) {
149
+ throw new Error(`${subject}: variable ${variableIndex} does not exist`);
150
+ }
151
+ }
152
+ }
153
+ }
154
+ return layer;
155
+ }
156
+ /**
157
+ * Validates that a constraint subject is not destroyed. A constraint made with a destroyed
158
+ * subject would stay in the layer without a solver constraint.
159
+ * @param value Element or layer
160
+ * @param name Subject name for error messages
161
+ * @param subject Constraint name for error messages
162
+ * @throws If the subject is destroyed
163
+ */
164
+ function assertNotDestroyed(value, name, subject) {
165
+ if (typeof value === "object" &&
166
+ value !== null &&
167
+ "destroyed" in value &&
168
+ value.destroyed === true) {
169
+ throw new Error(`${subject}: ${name} is destroyed`);
170
+ }
171
+ }
@@ -0,0 +1,54 @@
1
+ import type { WebGLRenderer } from "three";
2
+ import type { UILayer } from "../../layers/UILayer/UILayer.js";
3
+ import type { UICanvasRenderingContext2D } from "../../miscellaneous/canvas.js";
4
+ import { UICanvasSurface } from "../../miscellaneous/canvas-surface/UICanvasSurface.js";
5
+ import type { UIColorConfig } from "../../miscellaneous/color/UIColor.Internal.js";
6
+ import { UIColor } from "../../miscellaneous/color/UIColor.js";
7
+ import type { UIElementOptions } from "../UIElement/UIElement.Internal.js";
8
+ import { UIElement } from "../UIElement/UIElement.js";
9
+ /**
10
+ * Element showing content drawn on a canvas. The content is drawn in content units and
11
+ * rasterized at the size the element takes on the screen, so it stays sharp when constraints
12
+ * enlarge the element and on high-DPI screens. The canvas is drawn again when the content changes
13
+ * or when the needed raster scale crosses a step. Micro transforms and the tint do not redraw it.
14
+ */
15
+ export declare abstract class UICanvasElement extends UIElement {
16
+ /** Canvas the content is drawn on, also usable for measuring between drawings */
17
+ protected readonly surface: UICanvasSurface;
18
+ private readonly colorInternal;
19
+ /** Raster scale the canvas holds, NaN before the first drawing */
20
+ private rasterScale;
21
+ /** Pixel density of the layer the raster scale was calculated for */
22
+ private rasterPixelDensity;
23
+ /** Width of the content in content units */
24
+ protected abstract readonly contentWidth: number;
25
+ /** Height of the content in content units */
26
+ protected abstract readonly contentHeight: number;
27
+ /**
28
+ * @param layer - Layer containing this element
29
+ * @param subject - Name of the subclass constructor, used in errors
30
+ * @param options - Configuration options
31
+ */
32
+ constructor(layer: UILayer, subject: string, options?: Partial<UIElementOptions> & {
33
+ color?: UIColorConfig;
34
+ });
35
+ /** Multiplicative tint. Alpha channel controls opacity. */
36
+ get color(): UIColor;
37
+ /** Multiplicative tint. Alpha channel controls opacity. */
38
+ set color(value: UIColorConfig);
39
+ /** Frees the canvas texture */
40
+ protected destroyInternal(): void;
41
+ protected onWillRender(renderer: WebGLRenderer, deltaTime: number): void;
42
+ /**
43
+ * Brings the content up to date before a frame.
44
+ * @param layoutChanged - Whether the solver changed the layout since the last frame
45
+ * @returns True when the content changed and has to be drawn again
46
+ */
47
+ protected abstract updateContent(layoutChanged: boolean): boolean;
48
+ /**
49
+ * Draws the content on the cleared canvas. The context transform maps content units onto the
50
+ * canvas.
51
+ * @param context - Canvas context
52
+ */
53
+ protected abstract drawContent(context: UICanvasRenderingContext2D): void;
54
+ }
@@ -0,0 +1,70 @@
1
+ import { calculateRasterScale, UICanvasSurface, } from "../../miscellaneous/canvas-surface/UICanvasSurface.js";
2
+ import { UIColor } from "../../miscellaneous/color/UIColor.js";
3
+ import { UIAffineMatrix3 } from "../../miscellaneous/UIAffineMatrix3.js";
4
+ import source from "../../shaders/UIImage.js";
5
+ import { UIElement } from "../UIElement/UIElement.js";
6
+ /**
7
+ * Element showing content drawn on a canvas. The content is drawn in content units and
8
+ * rasterized at the size the element takes on the screen, so it stays sharp when constraints
9
+ * enlarge the element and on high-DPI screens. The canvas is drawn again when the content changes
10
+ * or when the needed raster scale crosses a step. Micro transforms and the tint do not redraw it.
11
+ */
12
+ export class UICanvasElement extends UIElement {
13
+ /**
14
+ * @param layer - Layer containing this element
15
+ * @param subject - Name of the subclass constructor, used in errors
16
+ * @param options - Configuration options
17
+ */
18
+ constructor(layer, subject, options) {
19
+ const surface = new UICanvasSurface(subject);
20
+ const color = new UIColor(options?.color);
21
+ super(layer, source, {
22
+ texture: surface.texture,
23
+ textureTransform: new UIAffineMatrix3(),
24
+ color,
25
+ }, options);
26
+ /** Raster scale the canvas holds, NaN before the first drawing */
27
+ this.rasterScale = Number.NaN;
28
+ /** Pixel density of the layer the raster scale was calculated for */
29
+ this.rasterPixelDensity = Number.NaN;
30
+ this.surface = surface;
31
+ this.colorInternal = color;
32
+ }
33
+ /** Multiplicative tint. Alpha channel controls opacity. */
34
+ get color() {
35
+ return this.colorInternal;
36
+ }
37
+ /** Multiplicative tint. Alpha channel controls opacity. */
38
+ set color(value) {
39
+ this.colorInternal.set(value);
40
+ }
41
+ /** Frees the canvas texture */
42
+ destroyInternal() {
43
+ this.surface.dispose();
44
+ super.destroyInternal();
45
+ }
46
+ onWillRender(renderer, deltaTime) {
47
+ const layoutChanged = this.consumeLayoutChange();
48
+ const contentChanged = this.updateContent(layoutChanged);
49
+ const pixelDensity = this.layer.pixelDensity;
50
+ if (contentChanged || layoutChanged || pixelDensity !== this.rasterPixelDensity) {
51
+ this.rasterPixelDensity = pixelDensity;
52
+ const width = this.contentWidth;
53
+ const height = this.contentHeight;
54
+ const rasterScale = calculateRasterScale(width, height, pixelDensity * Math.max(this.width / width, this.height / height));
55
+ if (contentChanged || rasterScale !== this.rasterScale) {
56
+ this.rasterScale = rasterScale;
57
+ const textureReplaced = this.surface.begin(width, height, rasterScale);
58
+ this.drawContent(this.surface.context);
59
+ if (textureReplaced) {
60
+ this.sceneWrapper.setProperties(this.planeHandler, { texture: this.surface.texture });
61
+ }
62
+ }
63
+ }
64
+ if (this.colorInternal.dirty) {
65
+ this.sceneWrapper.setProperties(this.planeHandler, { color: this.colorInternal });
66
+ this.colorInternal.setDirtyFalse();
67
+ }
68
+ super.onWillRender(renderer, deltaTime);
69
+ }
70
+ }
@@ -34,6 +34,8 @@ export interface UIDummyOptions extends UIAnchorOptions {
34
34
  interactionArea: UIArea;
35
35
  /** Controls visibility and interactivity */
36
36
  mode: UIMode;
37
+ /** Rendering and input priority, see UIDummy.zIndex */
38
+ zIndex: number;
37
39
  /** Mask clipping the element, see UIDummy.mask */
38
40
  mask: UIMask | null;
39
41
  }
@@ -71,8 +71,8 @@ export declare class UIDummy extends UIAnchor implements UIPlaneElement {
71
71
  /** Signal fired when pointer enters element */
72
72
  get signalPointerEntered(): FerrsignView1<UIInputEventData>;
73
73
  /**
74
- * Signal fired when pointer leaves element. A released or cancelled pointer leaves too: a
75
- * mouse still over the element enters again on its next move.
74
+ * Signal fired when pointer leaves element. A released touch or pen and a cancelled pointer
75
+ * leave too; a released mouse stays over the element.
76
76
  */
77
77
  get signalPointerLeft(): FerrsignView1<UIInputEventData>;
78
78
  /** Signal fired when a pointer pressed on the element is released over it */
@@ -129,7 +129,8 @@ export declare class UIDummy extends UIAnchor implements UIPlaneElement {
129
129
  protected destroyInternal(): void;
130
130
  protected readonly catchPointerDown: (x: number, y: number, identifier: number) => boolean;
131
131
  protected readonly catchPointerMove: (x: number, y: number, identifier: number) => boolean;
132
- protected readonly catchPointerUp: (x: number, y: number, identifier: number) => boolean;
132
+ /** A mouse stays over the element after the release; a touch or a pen leaves it */
133
+ protected readonly catchPointerUp: (x: number, y: number, identifier: number, hovering: boolean) => boolean;
133
134
  /** Signals of a cancel carry the last known position */
134
135
  protected readonly catchPointerCancel: (identifier: number) => void;
135
136
  /**
@@ -139,10 +140,12 @@ export declare class UIDummy extends UIAnchor implements UIPlaneElement {
139
140
  private trackPointer;
140
141
  /**
141
142
  * Ends a pointer: a press on the element ends as a click or as cancelled, and the pointer
142
- * leaves. A released or cancelled pointer is forgotten, so that a touch, which never comes
143
- * back with the same identifier, does not stay over the element.
143
+ * leaves. The pointer is forgotten, so that a touch, which never comes back with the same
144
+ * identifier, does not stay over the element.
144
145
  */
145
146
  private endPointer;
147
+ /** Ends a press on the element, if there is one, as a click or as cancelled */
148
+ private endPress;
146
149
  /** Ends every pointer, for an element that stops taking input */
147
150
  private dropPointers;
148
151
  private forgetIfUntracked;
@@ -21,6 +21,8 @@ export class UIDummy extends UIAnchor {
21
21
  const h = options?.height ?? DUMMY_DEFAULT_HEIGHT;
22
22
  assertValidPositiveNumber(w, "UIDummy.constructor.width");
23
23
  assertValidPositiveNumber(h, "UIDummy.constructor.height");
24
+ const zIndex = options?.zIndex ?? DUMMY_DEFAULT_Z_INDEX;
25
+ assertValidNumber(zIndex, "UIDummy.constructor.options.zIndex");
24
26
  super(layer, options);
25
27
  this.pointers = new Map();
26
28
  this.maskInternal = null;
@@ -49,10 +51,17 @@ export class UIDummy extends UIAnchor {
49
51
  this.forgetIfUntracked(identifier, state);
50
52
  return this.catches(state);
51
53
  };
52
- this.catchPointerUp = (x, y, identifier) => {
54
+ /** A mouse stays over the element after the release; a touch or a pen leaves it */
55
+ this.catchPointerUp = (x, y, identifier, hovering) => {
53
56
  const state = this.trackPointer(x, y, identifier, this.signalPointerReleasedInternal);
54
57
  const caught = this.catches(state);
55
- this.endPointer(identifier, state, state.inside);
58
+ if (hovering) {
59
+ this.endPress(identifier, state, state.inside);
60
+ this.forgetIfUntracked(identifier, state);
61
+ }
62
+ else {
63
+ this.endPointer(identifier, state, state.inside);
64
+ }
56
65
  return caught;
57
66
  };
58
67
  /** Signals of a cancel carry the last known position */
@@ -72,7 +81,7 @@ export class UIDummy extends UIAnchor {
72
81
  catchPointerMove: this.catchPointerMove,
73
82
  catchPointerUp: this.catchPointerUp,
74
83
  catchPointerCancel: this.catchPointerCancel,
75
- }, DUMMY_DEFAULT_Z_INDEX);
84
+ }, zIndex);
76
85
  this.inputWrapper.setActive(this.catcherHandler, isUIModeInteractive(this.modeInternal));
77
86
  const mask = options?.mask ?? null;
78
87
  if (mask !== null) {
@@ -141,8 +150,8 @@ export class UIDummy extends UIAnchor {
141
150
  return this.signalPointerEnteredInternal;
142
151
  }
143
152
  /**
144
- * Signal fired when pointer leaves element. A released or cancelled pointer leaves too: a
145
- * mouse still over the element enters again on its next move.
153
+ * Signal fired when pointer leaves element. A released touch or pen and a cancelled pointer
154
+ * leave too; a released mouse stays over the element.
146
155
  */
147
156
  get signalPointerLeft() {
148
157
  return this.signalPointerLeftInternal;
@@ -312,20 +321,24 @@ export class UIDummy extends UIAnchor {
312
321
  }
313
322
  /**
314
323
  * Ends a pointer: a press on the element ends as a click or as cancelled, and the pointer
315
- * leaves. A released or cancelled pointer is forgotten, so that a touch, which never comes
316
- * back with the same identifier, does not stay over the element.
324
+ * leaves. The pointer is forgotten, so that a touch, which never comes back with the same
325
+ * identifier, does not stay over the element.
317
326
  */
318
327
  endPointer(identifier, state, clicked) {
319
328
  this.pointers.delete(identifier);
320
- if (state.pressed) {
321
- state.pressed = false;
322
- this.emitPointer(clicked ? this.signalPointerClickedInternal : this.signalPointerCancelledInternal, state, identifier);
323
- }
329
+ this.endPress(identifier, state, clicked);
324
330
  if (state.inside) {
325
331
  state.inside = false;
326
332
  this.emitPointer(this.signalPointerLeftInternal, state, identifier);
327
333
  }
328
334
  }
335
+ /** Ends a press on the element, if there is one, as a click or as cancelled */
336
+ endPress(identifier, state, clicked) {
337
+ if (state.pressed) {
338
+ state.pressed = false;
339
+ this.emitPointer(clicked ? this.signalPointerClickedInternal : this.signalPointerCancelledInternal, state, identifier);
340
+ }
341
+ }
329
342
  /** Ends every pointer, for an element that stops taking input */
330
343
  dropPointers() {
331
344
  for (const [identifier, state] of [...this.pointers]) {
@@ -11,11 +11,14 @@ export interface UIElementOptions extends UIDummyOptions {
11
11
  transparencyMode: UITransparencyMode;
12
12
  /** Color blending mode (only affects BLEND transparency) */
13
13
  blendMode: UIBlendMode;
14
- /** Hue shift in degrees */
14
+ /**
15
+ * Hue shift in degrees. Applied to the linear color, so the hue of a color is not the one a
16
+ * color picker shows for its sRGB value.
17
+ */
15
18
  hue: number;
16
- /** Saturation multiplier (1 = unchanged, 0 = grayscale) */
19
+ /** Saturation multiplier (1 = unchanged, 0 = grayscale), applied to the linear color */
17
20
  saturation: number;
18
- /** Lightness offset (0 = unchanged) */
21
+ /** Lightness offset (0 = unchanged), applied to the linear color */
19
22
  lightness: number;
20
23
  }
21
24
  export declare const ELEMENT_DEFAULT_TRANSPARENCY_MODE = UITransparencyMode.BLEND;
@@ -23,8 +26,6 @@ export declare const ELEMENT_DEFAULT_BLEND_MODE = UIBlendMode.NORMAL;
23
26
  export declare const ELEMENT_DEFAULT_HUE = 0;
24
27
  export declare const ELEMENT_DEFAULT_SATURATION = 1;
25
28
  export declare const ELEMENT_DEFAULT_LIGHTNESS = 0;
26
- /** Maps a blend mode to the output-alpha multiplier used by the premultiplied shader. */
27
- export declare function blendModeToFactor(mode: UIBlendMode): number;
28
29
  /**
29
30
  * Packs HSL adjustment into the shader attribute layout (hue in turns, saturation
30
31
  * multiplier, lightness offset). Hue degrees become turns so the shader can wrap
@@ -5,10 +5,6 @@ export const ELEMENT_DEFAULT_BLEND_MODE = UIBlendMode.NORMAL;
5
5
  export const ELEMENT_DEFAULT_HUE = 0;
6
6
  export const ELEMENT_DEFAULT_SATURATION = 1;
7
7
  export const ELEMENT_DEFAULT_LIGHTNESS = 0;
8
- /** Maps a blend mode to the output-alpha multiplier used by the premultiplied shader. */
9
- export function blendModeToFactor(mode) {
10
- return mode === UIBlendMode.ADDITIVE ? 0 : 1;
11
- }
12
8
  /**
13
9
  * Packs HSL adjustment into the shader attribute layout (hue in turns, saturation
14
10
  * multiplier, lightness offset). Hue degrees become turns so the shader can wrap
@@ -53,11 +53,14 @@ export declare abstract class UIElement extends UIDummy {
53
53
  get transparencyMode(): UITransparencyMode;
54
54
  /** Color blending mode (only affects BLEND transparency) */
55
55
  get blendMode(): UIBlendMode;
56
- /** Hue shift in degrees */
56
+ /**
57
+ * Hue shift in degrees. Applied to the linear color, so the hue of a color is not the one a
58
+ * color picker shows for its sRGB value.
59
+ */
57
60
  get hue(): number;
58
- /** Saturation multiplier (1 = unchanged, 0 = grayscale) */
61
+ /** Saturation multiplier (1 = unchanged, 0 = grayscale), applied to the linear color */
59
62
  get saturation(): number;
60
- /** Lightness offset (0 = unchanged) */
63
+ /** Lightness offset (0 = unchanged), applied to the linear color */
61
64
  get lightness(): number;
62
65
  /**
63
66
  * Controls visibility and interactivity.
@@ -72,11 +75,14 @@ export declare abstract class UIElement extends UIDummy {
72
75
  set transparencyMode(value: UITransparencyMode);
73
76
  /** Color blending mode (only affects BLEND transparency) */
74
77
  set blendMode(value: UIBlendMode);
75
- /** Hue shift in degrees */
78
+ /**
79
+ * Hue shift in degrees. Applied to the linear color, so the hue of a color is not the one a
80
+ * color picker shows for its sRGB value.
81
+ */
76
82
  set hue(value: number);
77
- /** Saturation multiplier (1 = unchanged, 0 = grayscale) */
83
+ /** Saturation multiplier (1 = unchanged, 0 = grayscale), applied to the linear color */
78
84
  set saturation(value: number);
79
- /** Lightness offset (0 = unchanged) */
85
+ /** Lightness offset (0 = unchanged), applied to the linear color */
80
86
  set lightness(value: number);
81
87
  /** Controls visibility and interactivity */
82
88
  set mode(value: UIMode);
@@ -1,8 +1,9 @@
1
1
  import { Matrix4 } from "three";
2
2
  import { UIMicro } from "../../miscellaneous/micro/UIMicro.js";
3
+ import { blendModeToFactor } from "../../miscellaneous/UIBlendMode.js";
3
4
  import { isUIModeVisible } from "../../miscellaneous/UIMode.js";
4
5
  import { UIDummy } from "../UIDummy/UIDummy.js";
5
- import { blendModeToFactor, ELEMENT_DEFAULT_BLEND_MODE, ELEMENT_DEFAULT_HUE, ELEMENT_DEFAULT_LIGHTNESS, ELEMENT_DEFAULT_SATURATION, ELEMENT_DEFAULT_TRANSPARENCY_MODE, packHSL, } from "./UIElement.Internal.js";
6
+ import { ELEMENT_DEFAULT_BLEND_MODE, ELEMENT_DEFAULT_HUE, ELEMENT_DEFAULT_LIGHTNESS, ELEMENT_DEFAULT_SATURATION, ELEMENT_DEFAULT_TRANSPARENCY_MODE, packHSL, } from "./UIElement.Internal.js";
6
7
  const TEMP_TRANSFORM = new Matrix4();
7
8
  /**
8
9
  * Base class for renderable UI elements: a quad drawn with a custom fragment shader.
@@ -60,15 +61,18 @@ export class UIElement extends UIDummy {
60
61
  get blendMode() {
61
62
  return this.blendModeInternal;
62
63
  }
63
- /** Hue shift in degrees */
64
+ /**
65
+ * Hue shift in degrees. Applied to the linear color, so the hue of a color is not the one a
66
+ * color picker shows for its sRGB value.
67
+ */
64
68
  get hue() {
65
69
  return this.hueInternal;
66
70
  }
67
- /** Saturation multiplier (1 = unchanged, 0 = grayscale) */
71
+ /** Saturation multiplier (1 = unchanged, 0 = grayscale), applied to the linear color */
68
72
  get saturation() {
69
73
  return this.saturationInternal;
70
74
  }
71
- /** Lightness offset (0 = unchanged) */
75
+ /** Lightness offset (0 = unchanged), applied to the linear color */
72
76
  get lightness() {
73
77
  return this.lightnessInternal;
74
78
  }
@@ -100,21 +104,24 @@ export class UIElement extends UIDummy {
100
104
  this.blendModeDirty = true;
101
105
  }
102
106
  }
103
- /** Hue shift in degrees */
107
+ /**
108
+ * Hue shift in degrees. Applied to the linear color, so the hue of a color is not the one a
109
+ * color picker shows for its sRGB value.
110
+ */
104
111
  set hue(value) {
105
112
  if (this.hueInternal !== value) {
106
113
  this.hueInternal = value;
107
114
  this.hslDirty = true;
108
115
  }
109
116
  }
110
- /** Saturation multiplier (1 = unchanged, 0 = grayscale) */
117
+ /** Saturation multiplier (1 = unchanged, 0 = grayscale), applied to the linear color */
111
118
  set saturation(value) {
112
119
  if (this.saturationInternal !== value) {
113
120
  this.saturationInternal = value;
114
121
  this.hslDirty = true;
115
122
  }
116
123
  }
117
- /** Lightness offset (0 = unchanged) */
124
+ /** Lightness offset (0 = unchanged), applied to the linear color */
118
125
  set lightness(value) {
119
126
  if (this.lightnessInternal !== value) {
120
127
  this.lightnessInternal = value;
@@ -1,11 +1,51 @@
1
1
  import type { UIColorConfig } from "../../miscellaneous/color/UIColor.Internal.js";
2
- import { UIColor } from "../../miscellaneous/color/UIColor.js";
2
+ import type { UILineCap, UILineJoin, UIPaint, UIPaintBox, UIPaintConfig } from "../../miscellaneous/paint/UIPaint.Internal.js";
3
3
  import type { UIElementOptions } from "../UIElement/UIElement.Internal.js";
4
4
  /** Configuration options for UIGraphics */
5
5
  export interface UIGraphicsOptions extends UIElementOptions {
6
6
  /** Multiplicative tint */
7
7
  color: UIColorConfig;
8
8
  }
9
+ /** Line along the outline of a shape, centered on it */
10
+ export interface UIGraphicsStrokeConfig {
11
+ /** Color or gradient of the line */
12
+ paint: UIPaintConfig;
13
+ /** Line width in drawing units */
14
+ width: number;
15
+ /** How the corners are joined. Miter by default. */
16
+ join?: UILineJoin;
17
+ /** How the open ends look. Butt by default. */
18
+ cap?: UILineCap;
19
+ }
20
+ /** How a shape is painted. A shape without a fill and a stroke is not drawn. */
21
+ export interface UIGraphicsStyle {
22
+ /** Color or gradient inside the shape */
23
+ fill?: UIPaintConfig;
24
+ /** Line along the outline of the shape */
25
+ stroke?: UIGraphicsStrokeConfig;
26
+ }
27
+ /** Shape as kept until the graphics is cleared */
28
+ export interface UIGraphicsShape {
29
+ /** Builds the path of the shape on a context */
30
+ buildPath: (context: CanvasPath) => void;
31
+ /**
32
+ * Bounds of the path. A fill gradient is laid over them, a stroke gradient over them widened
33
+ * by half the stroke on each side.
34
+ */
35
+ box: UIPaintBox;
36
+ /** Fill, if any */
37
+ fill?: UIPaint;
38
+ /** Stroke, if any */
39
+ stroke?: {
40
+ paint: UIPaint;
41
+ width: number;
42
+ join: UILineJoin;
43
+ cap: UILineCap;
44
+ };
45
+ }
46
+ /** Corner radius of a rounded rectangle, one for all corners or four from the top left clockwise */
47
+ export type UIGraphicsCornerRadius = number | readonly [number, number, number, number];
9
48
  export declare const GRAPHICS_DEFAULT_WIDTH = 2;
10
49
  export declare const GRAPHICS_DEFAULT_HEIGHT = 2;
11
- export declare const GRAPHICS_TEMP_COLOR: UIColor;
50
+ export declare const GRAPHICS_DEFAULT_STROKE_JOIN: "miter";
51
+ export declare const GRAPHICS_DEFAULT_STROKE_CAP: "butt";
@@ -1,4 +1,4 @@
1
- import { UIColor } from "../../miscellaneous/color/UIColor.js";
2
1
  export const GRAPHICS_DEFAULT_WIDTH = 2;
3
2
  export const GRAPHICS_DEFAULT_HEIGHT = 2;
4
- export const GRAPHICS_TEMP_COLOR = new UIColor();
3
+ export const GRAPHICS_DEFAULT_STROKE_JOIN = "miter";
4
+ export const GRAPHICS_DEFAULT_STROKE_CAP = "butt";