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,85 +1,123 @@
1
1
  import { assertValidNonNegativeNumber, assertValidNumber, assertValidPositiveNumber, } from "../asserts.js";
2
- import { TEXT_STYLE_DEFAULT_ALIGN, TEXT_STYLE_DEFAULT_COLOR, TEXT_STYLE_DEFAULT_ENABLE_SHADOW, TEXT_STYLE_DEFAULT_ENABLE_STROKE, TEXT_STYLE_DEFAULT_FONT_FAMILY, TEXT_STYLE_DEFAULT_FONT_SIZE, TEXT_STYLE_DEFAULT_FONT_STYLE, TEXT_STYLE_DEFAULT_FONT_WEIGHT, TEXT_STYLE_DEFAULT_LINE_HEIGHT, TEXT_STYLE_DEFAULT_SHADOW_BLUR, TEXT_STYLE_DEFAULT_SHADOW_COLOR, TEXT_STYLE_DEFAULT_SHADOW_OFFSET_X, TEXT_STYLE_DEFAULT_SHADOW_OFFSET_Y, TEXT_STYLE_DEFAULT_STROKE_COLOR, TEXT_STYLE_DEFAULT_STROKE_THICKNESS, } from "./UITextStyle.Internal.js";
3
- /** Text style configuration for UI text rendering */
2
+ import { toCanvasColor } from "../color/canvasColor.js";
3
+ import { resolvePaint } from "../paint/UIPaint.js";
4
+ import { TEXT_STYLE_DEFAULT_ALIGN, TEXT_STYLE_DEFAULT_COLOR, TEXT_STYLE_DEFAULT_FONT_FAMILY, TEXT_STYLE_DEFAULT_FONT_SIZE, TEXT_STYLE_DEFAULT_FONT_STYLE, TEXT_STYLE_DEFAULT_FONT_WEIGHT, TEXT_STYLE_DEFAULT_LINE_HEIGHT, TEXT_STYLE_DEFAULT_PAINT_BOX, TEXT_STYLE_DEFAULT_SHADOWS, TEXT_STYLE_DEFAULT_STROKE_JOIN, TEXT_STYLE_DEFAULT_STROKES, } from "./UITextStyle.Internal.js";
5
+ /** Value of every property after `setDefaults` */
6
+ const TEXT_STYLE_DEFAULTS = {
7
+ color: TEXT_STYLE_DEFAULT_COLOR,
8
+ paintBox: TEXT_STYLE_DEFAULT_PAINT_BOX,
9
+ align: TEXT_STYLE_DEFAULT_ALIGN,
10
+ fontFamily: TEXT_STYLE_DEFAULT_FONT_FAMILY,
11
+ fontSize: TEXT_STYLE_DEFAULT_FONT_SIZE,
12
+ fontStyle: TEXT_STYLE_DEFAULT_FONT_STYLE,
13
+ fontWeight: TEXT_STYLE_DEFAULT_FONT_WEIGHT,
14
+ lineHeight: TEXT_STYLE_DEFAULT_FONT_SIZE * TEXT_STYLE_DEFAULT_LINE_HEIGHT,
15
+ strokes: TEXT_STYLE_DEFAULT_STROKES,
16
+ shadows: TEXT_STYLE_DEFAULT_SHADOWS,
17
+ };
18
+ const TEXT_STYLE_KEYS = Object.keys(TEXT_STYLE_DEFAULTS);
19
+ /**
20
+ * Sets a property of a resolved style when the value is defined.
21
+ * @param style Style to change
22
+ * @param key Property
23
+ * @param value Value, or undefined to keep the current one
24
+ */
25
+ function assignDefined(style, key, value) {
26
+ if (value !== undefined) {
27
+ style[key] = value;
28
+ }
29
+ }
30
+ /**
31
+ * Converts outline configs to stored outlines.
32
+ * @param strokes Outline configs
33
+ * @returns Frozen outlines with colors as CSS strings
34
+ */
35
+ function resolveStrokes(strokes) {
36
+ return Object.freeze(strokes.map((stroke) => {
37
+ assertValidNonNegativeNumber(stroke.thickness, "UITextStyle.strokes.thickness");
38
+ return Object.freeze({
39
+ paint: resolvePaint(stroke.paint),
40
+ thickness: stroke.thickness,
41
+ join: stroke.join ?? TEXT_STYLE_DEFAULT_STROKE_JOIN,
42
+ });
43
+ }));
44
+ }
45
+ /**
46
+ * Converts shadow configs to stored shadows.
47
+ * @param shadows Shadow configs
48
+ * @returns Frozen shadows with colors as CSS strings
49
+ */
50
+ function resolveShadows(shadows) {
51
+ return Object.freeze(shadows.map((shadow) => {
52
+ const offsetX = shadow.offsetX ?? 0;
53
+ const offsetY = shadow.offsetY ?? 0;
54
+ const blur = shadow.blur ?? 0;
55
+ assertValidNumber(offsetX, "UITextStyle.shadows.offsetX");
56
+ assertValidNumber(offsetY, "UITextStyle.shadows.offsetY");
57
+ assertValidNonNegativeNumber(blur, "UITextStyle.shadows.blur");
58
+ return Object.freeze({ color: toCanvasColor(shadow.color), offsetX, offsetY, blur });
59
+ }));
60
+ }
61
+ /**
62
+ * Text style of a span or of a whole text. Properties left undefined are taken from the
63
+ * fallback style, the common style of the text for a span, then from the defaults. Lists of
64
+ * strokes and shadows are taken as a whole.
65
+ */
4
66
  export class UITextStyle {
5
67
  /** @param config Partial style configuration. Unspecified properties remain undefined. */
6
68
  constructor(config) {
69
+ this.values = {};
7
70
  this.dirtyInternal = true;
8
- this.colorInternal = config?.color;
9
- this.alignInternal = config?.align;
10
- this.fontFamilyInternal = config?.fontFamily;
11
- this.fontSizeInternal = config?.fontSize;
12
- this.fontStyleInternal = config?.fontStyle;
13
- this.fontWeightInternal = config?.fontWeight;
14
- this.lineHeightInternal = config?.lineHeight;
15
- this.enableShadowInternal = config?.enableShadow;
16
- this.shadowOffsetXInternal = config?.shadowOffsetX;
17
- this.shadowOffsetYInternal = config?.shadowOffsetY;
18
- this.shadowBlurInternal = config?.shadowBlur;
19
- this.shadowColorInternal = config?.shadowColor;
20
- this.enableStrokeInternal = config?.enableStroke;
21
- this.strokeColorInternal = config?.strokeColor;
22
- this.strokeThicknessInternal = config?.strokeThickness;
23
- }
24
- /** Text color */
71
+ this.color = config?.color;
72
+ this.paintBox = config?.paintBox;
73
+ this.align = config?.align;
74
+ this.fontFamily = config?.fontFamily;
75
+ this.fontSize = config?.fontSize;
76
+ this.fontStyle = config?.fontStyle;
77
+ this.fontWeight = config?.fontWeight;
78
+ this.lineHeight = config?.lineHeight;
79
+ this.strokes = config?.strokes;
80
+ this.shadows = config?.shadows;
81
+ }
82
+ /** Color or gradient of the glyphs. A color is kept as a CSS string. */
25
83
  get color() {
26
- return this.colorInternal;
84
+ return this.values.color;
85
+ }
86
+ /** Box the gradients of the fill and of the strokes are laid over */
87
+ get paintBox() {
88
+ return this.values.paintBox;
27
89
  }
28
90
  /** Text alignment */
29
91
  get align() {
30
- return this.alignInternal;
92
+ return this.values.align;
31
93
  }
32
94
  /** Font family name */
33
95
  get fontFamily() {
34
- return this.fontFamilyInternal;
96
+ return this.values.fontFamily;
35
97
  }
36
98
  /** Font size in pixels */
37
99
  get fontSize() {
38
- return this.fontSizeInternal;
100
+ return this.values.fontSize;
39
101
  }
40
102
  /** Font style */
41
103
  get fontStyle() {
42
- return this.fontStyleInternal;
104
+ return this.values.fontStyle;
43
105
  }
44
106
  /** Font weight */
45
107
  get fontWeight() {
46
- return this.fontWeightInternal;
108
+ return this.values.fontWeight;
47
109
  }
48
- /** Line height in pixels */
110
+ /** Line height in pixels, the distance between baselines */
49
111
  get lineHeight() {
50
- return this.lineHeightInternal;
51
- }
52
- /** Whether shadow is enabled */
53
- get enableShadow() {
54
- return this.enableShadowInternal;
55
- }
56
- /** Shadow horizontal offset in pixels */
57
- get shadowOffsetX() {
58
- return this.shadowOffsetXInternal;
59
- }
60
- /** Shadow vertical offset in pixels */
61
- get shadowOffsetY() {
62
- return this.shadowOffsetYInternal;
63
- }
64
- /** Shadow blur radius in pixels */
65
- get shadowBlur() {
66
- return this.shadowBlurInternal;
112
+ return this.values.lineHeight;
67
113
  }
68
- /** Shadow color */
69
- get shadowColor() {
70
- return this.shadowColorInternal;
114
+ /** Outlines from the innermost to the outermost */
115
+ get strokes() {
116
+ return this.values.strokes;
71
117
  }
72
- /** Whether stroke is enabled */
73
- get enableStroke() {
74
- return this.enableStrokeInternal;
75
- }
76
- /** Stroke color */
77
- get strokeColor() {
78
- return this.strokeColorInternal;
79
- }
80
- /** Stroke thickness in pixels */
81
- get strokeThickness() {
82
- return this.strokeThicknessInternal;
118
+ /** Shadows and glows, the first one on top */
119
+ get shadows() {
120
+ return this.values.shadows;
83
121
  }
84
122
  /**
85
123
  * Indicates whether any property has been modified.
@@ -89,181 +127,98 @@ export class UITextStyle {
89
127
  get dirty() {
90
128
  return this.dirtyInternal;
91
129
  }
130
+ /** Color or gradient of the glyphs. A string is a `UIColor` name or a CSS color. */
92
131
  set color(value) {
93
- if (value !== this.colorInternal) {
94
- this.colorInternal = value;
95
- this.dirtyInternal = true;
96
- }
132
+ this.setValue("color", value === undefined ? undefined : resolvePaint(value));
133
+ }
134
+ /** Box the gradients of the fill and of the strokes are laid over */
135
+ set paintBox(value) {
136
+ this.setValue("paintBox", value);
97
137
  }
138
+ /** Text alignment */
98
139
  set align(value) {
99
- if (value !== this.alignInternal) {
100
- this.alignInternal = value;
101
- this.dirtyInternal = true;
102
- }
140
+ this.setValue("align", value);
103
141
  }
142
+ /** Font family name */
104
143
  set fontFamily(value) {
105
- if (value !== this.fontFamilyInternal) {
106
- this.fontFamilyInternal = value;
107
- this.dirtyInternal = true;
108
- }
144
+ this.setValue("fontFamily", value);
109
145
  }
146
+ /** Font size in pixels */
110
147
  set fontSize(value) {
111
148
  if (value !== undefined) {
112
149
  assertValidPositiveNumber(value, "UITextStyle.fontSize");
113
150
  }
114
- if (value !== this.fontSizeInternal) {
115
- this.fontSizeInternal = value;
116
- this.dirtyInternal = true;
117
- }
151
+ this.setValue("fontSize", value);
118
152
  }
153
+ /** Font style */
119
154
  set fontStyle(value) {
120
- if (value !== this.fontStyleInternal) {
121
- this.fontStyleInternal = value;
122
- this.dirtyInternal = true;
123
- }
155
+ this.setValue("fontStyle", value);
124
156
  }
157
+ /** Font weight */
125
158
  set fontWeight(value) {
126
159
  if (typeof value === "number") {
127
160
  assertValidPositiveNumber(value, "UITextStyle.fontWeight");
128
161
  }
129
- if (value !== this.fontWeightInternal) {
130
- this.fontWeightInternal = value;
131
- this.dirtyInternal = true;
132
- }
162
+ this.setValue("fontWeight", value);
133
163
  }
164
+ /** Line height in pixels, the distance between baselines */
134
165
  set lineHeight(value) {
135
166
  if (value !== undefined) {
136
167
  assertValidNumber(value, "UITextStyle.lineHeight");
137
168
  }
138
- if (value !== this.lineHeightInternal) {
139
- this.lineHeightInternal = value;
140
- this.dirtyInternal = true;
141
- }
142
- }
143
- set enableShadow(value) {
144
- if (value !== this.enableShadowInternal) {
145
- this.enableShadowInternal = value;
146
- this.dirtyInternal = true;
147
- }
169
+ this.setValue("lineHeight", value);
148
170
  }
149
- set shadowOffsetX(value) {
150
- if (value !== undefined) {
151
- assertValidNumber(value, "UITextStyle.shadowOffsetX");
152
- }
153
- if (value !== this.shadowOffsetXInternal) {
154
- this.shadowOffsetXInternal = value;
155
- this.dirtyInternal = true;
156
- }
157
- }
158
- set shadowOffsetY(value) {
159
- if (value !== undefined) {
160
- assertValidNumber(value, "UITextStyle.shadowOffsetY");
161
- }
162
- if (value !== this.shadowOffsetYInternal) {
163
- this.shadowOffsetYInternal = value;
164
- this.dirtyInternal = true;
165
- }
166
- }
167
- set shadowBlur(value) {
168
- if (value !== undefined) {
169
- assertValidNonNegativeNumber(value, "UITextStyle.shadowBlur");
170
- }
171
- if (value !== this.shadowBlurInternal) {
172
- this.shadowBlurInternal = value;
173
- this.dirtyInternal = true;
174
- }
175
- }
176
- set shadowColor(value) {
177
- if (value !== this.shadowColorInternal) {
178
- this.shadowColorInternal = value;
179
- this.dirtyInternal = true;
180
- }
181
- }
182
- set enableStroke(value) {
183
- if (value !== this.enableStrokeInternal) {
184
- this.enableStrokeInternal = value;
185
- this.dirtyInternal = true;
186
- }
187
- }
188
- set strokeColor(value) {
189
- if (value !== this.strokeColorInternal) {
190
- this.strokeColorInternal = value;
191
- this.dirtyInternal = true;
192
- }
171
+ /**
172
+ * Outlines from the innermost to the outermost. Each one lies outside the previous one. An
173
+ * empty list draws no outline, undefined takes the outlines of the fallback style.
174
+ */
175
+ set strokes(value) {
176
+ this.setValue("strokes", value === undefined ? undefined : resolveStrokes(value));
193
177
  }
194
- set strokeThickness(value) {
195
- if (value !== undefined) {
196
- assertValidNonNegativeNumber(value, "UITextStyle.strokeThickness");
197
- }
198
- if (value !== this.strokeThicknessInternal) {
199
- this.strokeThicknessInternal = value;
200
- this.dirtyInternal = true;
201
- }
178
+ /**
179
+ * Shadows and glows, the first one on top. An empty list draws no shadow, undefined takes the
180
+ * shadows of the fallback style.
181
+ */
182
+ set shadows(value) {
183
+ this.setValue("shadows", value === undefined ? undefined : resolveShadows(value));
202
184
  }
203
185
  /**
204
186
  * Resolves complete style from primary and fallback sources.
205
187
  * @param primary First style to check for each property
206
188
  * @param fallback Second style to check if primary is undefined
207
- * @returns Complete style configuration with all defaults applied
189
+ * @returns Complete style, with defaults for what neither defines. The default line height
190
+ * follows the resolved font size.
191
+ * @internal
208
192
  */
209
193
  static resolve(primary, fallback) {
210
- const fontSize = primary?.fontSizeInternal ?? fallback?.fontSizeInternal ?? TEXT_STYLE_DEFAULT_FONT_SIZE;
211
- return {
212
- color: primary?.colorInternal ?? fallback?.colorInternal ?? TEXT_STYLE_DEFAULT_COLOR,
213
- align: primary?.alignInternal ?? fallback?.alignInternal ?? TEXT_STYLE_DEFAULT_ALIGN,
214
- fontFamily: primary?.fontFamilyInternal ??
215
- fallback?.fontFamilyInternal ??
216
- TEXT_STYLE_DEFAULT_FONT_FAMILY,
217
- fontSize,
218
- fontStyle: primary?.fontStyleInternal ?? fallback?.fontStyleInternal ?? TEXT_STYLE_DEFAULT_FONT_STYLE,
219
- fontWeight: primary?.fontWeightInternal ??
220
- fallback?.fontWeightInternal ??
221
- TEXT_STYLE_DEFAULT_FONT_WEIGHT,
222
- lineHeight: primary?.lineHeightInternal ??
223
- fallback?.lineHeightInternal ??
224
- fontSize * TEXT_STYLE_DEFAULT_LINE_HEIGHT,
225
- enableShadow: primary?.enableShadowInternal ??
226
- fallback?.enableShadowInternal ??
227
- TEXT_STYLE_DEFAULT_ENABLE_SHADOW,
228
- shadowOffsetX: primary?.shadowOffsetXInternal ??
229
- fallback?.shadowOffsetXInternal ??
230
- TEXT_STYLE_DEFAULT_SHADOW_OFFSET_X,
231
- shadowOffsetY: primary?.shadowOffsetYInternal ??
232
- fallback?.shadowOffsetYInternal ??
233
- TEXT_STYLE_DEFAULT_SHADOW_OFFSET_Y,
234
- shadowBlur: primary?.shadowBlurInternal ??
235
- fallback?.shadowBlurInternal ??
236
- TEXT_STYLE_DEFAULT_SHADOW_BLUR,
237
- shadowColor: primary?.shadowColorInternal ??
238
- fallback?.shadowColorInternal ??
239
- TEXT_STYLE_DEFAULT_SHADOW_COLOR,
240
- enableStroke: primary?.enableStrokeInternal ??
241
- fallback?.enableStrokeInternal ??
242
- TEXT_STYLE_DEFAULT_ENABLE_STROKE,
243
- strokeColor: primary?.strokeColorInternal ??
244
- fallback?.strokeColorInternal ??
245
- TEXT_STYLE_DEFAULT_STROKE_COLOR,
246
- strokeThickness: primary?.strokeThicknessInternal ??
247
- fallback?.strokeThicknessInternal ??
248
- TEXT_STYLE_DEFAULT_STROKE_THICKNESS,
249
- };
194
+ const resolved = { ...TEXT_STYLE_DEFAULTS };
195
+ for (const key of TEXT_STYLE_KEYS) {
196
+ assignDefined(resolved, key, primary?.values[key] ?? fallback?.values[key]);
197
+ }
198
+ if (primary?.values.lineHeight === undefined && fallback?.values.lineHeight === undefined) {
199
+ resolved.lineHeight = resolved.fontSize * TEXT_STYLE_DEFAULT_LINE_HEIGHT;
200
+ }
201
+ return resolved;
250
202
  }
251
203
  /**
252
- * Calculates maximum padding required for stroke and shadow of a resolved style.
253
- * The stroke is centered on the glyph outline, so only half of it is outside.
254
- * The shadow is cast by the stroke as well as by the fill.
204
+ * Calculates the padding a resolved style needs on every side for its outlines and shadows.
205
+ * The outlines add up outside the glyphs. A shadow is cast by the outlined glyphs and spreads
206
+ * by its offset and about twice its blur radius.
255
207
  * @param style Resolved style
256
- * @returns Padding in pixels needed on all sides
208
+ * @returns Padding in pixels
209
+ * @internal
257
210
  */
258
211
  static calculatePadding(style) {
259
- let padding = style.enableStroke ? style.strokeThickness / 2 : 0;
260
- if (style.enableShadow) {
261
- const shadowSpread = style.shadowBlur * 2;
262
- const shadowMaxX = Math.abs(style.shadowOffsetX) + shadowSpread;
263
- const shadowMaxY = Math.abs(style.shadowOffsetY) + shadowSpread;
264
- padding += Math.max(shadowMaxX, shadowMaxY);
212
+ let outline = 0;
213
+ for (const stroke of style.strokes) {
214
+ outline += stroke.thickness;
215
+ }
216
+ let shadowSpread = 0;
217
+ for (const shadow of style.shadows) {
218
+ const offset = Math.max(Math.abs(shadow.offsetX), Math.abs(shadow.offsetY));
219
+ shadowSpread = Math.max(shadowSpread, offset + shadow.blur * 2);
265
220
  }
266
- return Math.ceil(padding);
221
+ return Math.ceil(outline + shadowSpread);
267
222
  }
268
223
  /** @internal */
269
224
  setDirtyFalse() {
@@ -271,117 +226,36 @@ export class UITextStyle {
271
226
  }
272
227
  /** Sets all properties to default values */
273
228
  setDefaults() {
274
- if (this.colorInternal !== TEXT_STYLE_DEFAULT_COLOR ||
275
- this.alignInternal !== TEXT_STYLE_DEFAULT_ALIGN ||
276
- this.fontFamilyInternal !== TEXT_STYLE_DEFAULT_FONT_FAMILY ||
277
- this.fontSizeInternal !== TEXT_STYLE_DEFAULT_FONT_SIZE ||
278
- this.fontStyleInternal !== TEXT_STYLE_DEFAULT_FONT_STYLE ||
279
- this.fontWeightInternal !== TEXT_STYLE_DEFAULT_FONT_WEIGHT ||
280
- this.lineHeightInternal !== TEXT_STYLE_DEFAULT_FONT_SIZE * TEXT_STYLE_DEFAULT_LINE_HEIGHT ||
281
- this.enableShadowInternal !== TEXT_STYLE_DEFAULT_ENABLE_SHADOW ||
282
- this.shadowOffsetXInternal !== TEXT_STYLE_DEFAULT_SHADOW_OFFSET_X ||
283
- this.shadowOffsetYInternal !== TEXT_STYLE_DEFAULT_SHADOW_OFFSET_Y ||
284
- this.shadowBlurInternal !== TEXT_STYLE_DEFAULT_SHADOW_BLUR ||
285
- this.shadowColorInternal !== TEXT_STYLE_DEFAULT_SHADOW_COLOR ||
286
- this.enableStrokeInternal !== TEXT_STYLE_DEFAULT_ENABLE_STROKE ||
287
- this.strokeColorInternal !== TEXT_STYLE_DEFAULT_STROKE_COLOR ||
288
- this.strokeThicknessInternal !== TEXT_STYLE_DEFAULT_STROKE_THICKNESS) {
289
- this.colorInternal = TEXT_STYLE_DEFAULT_COLOR;
290
- this.alignInternal = TEXT_STYLE_DEFAULT_ALIGN;
291
- this.fontFamilyInternal = TEXT_STYLE_DEFAULT_FONT_FAMILY;
292
- this.fontSizeInternal = TEXT_STYLE_DEFAULT_FONT_SIZE;
293
- this.fontStyleInternal = TEXT_STYLE_DEFAULT_FONT_STYLE;
294
- this.fontWeightInternal = TEXT_STYLE_DEFAULT_FONT_WEIGHT;
295
- this.lineHeightInternal = TEXT_STYLE_DEFAULT_FONT_SIZE * TEXT_STYLE_DEFAULT_LINE_HEIGHT;
296
- this.enableShadowInternal = TEXT_STYLE_DEFAULT_ENABLE_SHADOW;
297
- this.shadowOffsetXInternal = TEXT_STYLE_DEFAULT_SHADOW_OFFSET_X;
298
- this.shadowOffsetYInternal = TEXT_STYLE_DEFAULT_SHADOW_OFFSET_Y;
299
- this.shadowBlurInternal = TEXT_STYLE_DEFAULT_SHADOW_BLUR;
300
- this.shadowColorInternal = TEXT_STYLE_DEFAULT_SHADOW_COLOR;
301
- this.enableStrokeInternal = TEXT_STYLE_DEFAULT_ENABLE_STROKE;
302
- this.strokeColorInternal = TEXT_STYLE_DEFAULT_STROKE_COLOR;
303
- this.strokeThicknessInternal = TEXT_STYLE_DEFAULT_STROKE_THICKNESS;
304
- this.dirtyInternal = true;
229
+ for (const key of TEXT_STYLE_KEYS) {
230
+ this.setValue(key, TEXT_STYLE_DEFAULTS[key]);
305
231
  }
306
232
  }
307
233
  /** Sets all properties to undefined */
308
234
  clear() {
309
- if (this.colorInternal !== undefined ||
310
- this.alignInternal !== undefined ||
311
- this.fontFamilyInternal !== undefined ||
312
- this.fontSizeInternal !== undefined ||
313
- this.fontStyleInternal !== undefined ||
314
- this.fontWeightInternal !== undefined ||
315
- this.lineHeightInternal !== undefined ||
316
- this.enableShadowInternal !== undefined ||
317
- this.shadowOffsetXInternal !== undefined ||
318
- this.shadowOffsetYInternal !== undefined ||
319
- this.shadowBlurInternal !== undefined ||
320
- this.shadowColorInternal !== undefined ||
321
- this.enableStrokeInternal !== undefined ||
322
- this.strokeColorInternal !== undefined ||
323
- this.strokeThicknessInternal !== undefined) {
324
- this.colorInternal = undefined;
325
- this.alignInternal = undefined;
326
- this.fontFamilyInternal = undefined;
327
- this.fontSizeInternal = undefined;
328
- this.fontStyleInternal = undefined;
329
- this.fontWeightInternal = undefined;
330
- this.lineHeightInternal = undefined;
331
- this.enableShadowInternal = undefined;
332
- this.shadowOffsetXInternal = undefined;
333
- this.shadowOffsetYInternal = undefined;
334
- this.shadowBlurInternal = undefined;
335
- this.shadowColorInternal = undefined;
336
- this.enableStrokeInternal = undefined;
337
- this.strokeColorInternal = undefined;
338
- this.strokeThicknessInternal = undefined;
339
- this.dirtyInternal = true;
235
+ for (const key of TEXT_STYLE_KEYS) {
236
+ this.setValue(key, undefined);
340
237
  }
341
238
  }
342
239
  /** Copies from another style instance */
343
240
  copy(value) {
344
- if (this.colorInternal !== value.colorInternal ||
345
- this.alignInternal !== value.alignInternal ||
346
- this.fontFamilyInternal !== value.fontFamilyInternal ||
347
- this.fontSizeInternal !== value.fontSizeInternal ||
348
- this.fontStyleInternal !== value.fontStyleInternal ||
349
- this.fontWeightInternal !== value.fontWeightInternal ||
350
- this.lineHeightInternal !== value.lineHeightInternal ||
351
- this.enableShadowInternal !== value.enableShadowInternal ||
352
- this.shadowOffsetXInternal !== value.shadowOffsetXInternal ||
353
- this.shadowOffsetYInternal !== value.shadowOffsetYInternal ||
354
- this.shadowBlurInternal !== value.shadowBlurInternal ||
355
- this.shadowColorInternal !== value.shadowColorInternal ||
356
- this.enableStrokeInternal !== value.enableStrokeInternal ||
357
- this.strokeColorInternal !== value.strokeColorInternal ||
358
- this.strokeThicknessInternal !== value.strokeThicknessInternal) {
359
- this.colorInternal = value.colorInternal;
360
- this.alignInternal = value.alignInternal;
361
- this.fontFamilyInternal = value.fontFamilyInternal;
362
- this.fontSizeInternal = value.fontSizeInternal;
363
- this.fontStyleInternal = value.fontStyleInternal;
364
- this.fontWeightInternal = value.fontWeightInternal;
365
- this.lineHeightInternal = value.lineHeightInternal;
366
- this.enableShadowInternal = value.enableShadowInternal;
367
- this.shadowOffsetXInternal = value.shadowOffsetXInternal;
368
- this.shadowOffsetYInternal = value.shadowOffsetYInternal;
369
- this.shadowBlurInternal = value.shadowBlurInternal;
370
- this.shadowColorInternal = value.shadowColorInternal;
371
- this.enableStrokeInternal = value.enableStrokeInternal;
372
- this.strokeColorInternal = value.strokeColorInternal;
373
- this.strokeThicknessInternal = value.strokeThicknessInternal;
374
- this.dirtyInternal = true;
241
+ for (const key of TEXT_STYLE_KEYS) {
242
+ this.setValue(key, value.values[key]);
375
243
  }
376
244
  }
377
245
  /**
378
- * Calculates maximum padding required for stroke and shadow.
246
+ * Calculates the padding needed on every side for outlines and shadows.
379
247
  * Properties left undefined here are taken from `fallback`, then from defaults,
380
- * so a span style is measured with the stroke and shadow it is drawn with.
248
+ * so a span style is measured with the outlines and shadows it is drawn with.
381
249
  * @param fallback Style that supplies undefined properties (usually the common style)
382
- * @returns Padding in pixels needed on all sides
250
+ * @returns Padding in pixels
383
251
  */
384
252
  calculatePadding(fallback) {
385
253
  return UITextStyle.calculatePadding(UITextStyle.resolve(this, fallback));
386
254
  }
255
+ setValue(key, value) {
256
+ if (this.values[key] !== value) {
257
+ this.values[key] = value;
258
+ this.dirtyInternal = true;
259
+ }
260
+ }
387
261
  }
@@ -3,7 +3,8 @@ export declare const TEXTURE_DEFAULT_TEXTURE: Texture;
3
3
  export declare const TEXTURE_DEFAULT_SIZE = 2;
4
4
  /**
5
5
  * Reads the pixel size of a texture image: an image, a video, a canvas, a bitmap
6
- * or the data of a DataTexture.
6
+ * or the data of a DataTexture. An image or video that is not loaded yet reports 0, which is
7
+ * taken as unknown.
7
8
  * @param texture Texture to measure
8
9
  * @returns Width and height in pixels
9
10
  */
@@ -1,16 +1,25 @@
1
1
  import { Texture } from "three";
2
2
  export const TEXTURE_DEFAULT_TEXTURE = new Texture();
3
3
  export const TEXTURE_DEFAULT_SIZE = 2;
4
+ /**
5
+ * First of the sizes that is known, that is, positive.
6
+ * @param sizes Candidate sizes in order of preference
7
+ * @returns The size, or the default size when none is known
8
+ */
9
+ function firstKnownSize(...sizes) {
10
+ return sizes.find((size) => size !== undefined && size > 0) ?? TEXTURE_DEFAULT_SIZE;
11
+ }
4
12
  /**
5
13
  * Reads the pixel size of a texture image: an image, a video, a canvas, a bitmap
6
- * or the data of a DataTexture.
14
+ * or the data of a DataTexture. An image or video that is not loaded yet reports 0, which is
15
+ * taken as unknown.
7
16
  * @param texture Texture to measure
8
17
  * @returns Width and height in pixels
9
18
  */
10
19
  export function getTextureImageSize(texture) {
11
20
  const image = texture.image;
12
21
  return {
13
- w: image?.naturalWidth ?? image?.videoWidth ?? image?.width ?? TEXTURE_DEFAULT_SIZE,
14
- h: image?.naturalHeight ?? image?.videoHeight ?? image?.height ?? TEXTURE_DEFAULT_SIZE,
22
+ w: firstKnownSize(image?.naturalWidth, image?.videoWidth, image?.width),
23
+ h: firstKnownSize(image?.naturalHeight, image?.videoHeight, image?.height),
15
24
  };
16
25
  }
@@ -3,8 +3,7 @@ float calculateMask() {
3
3
  float aspect = p_textureResolution.x / p_textureResolution.y;
4
4
  vec2 p = (p_uv - 0.5) * vec2(aspect, 1.0);
5
5
 
6
- float angle = atan(p.y, p.x);
7
- angle = (angle + PI) / (2.0 * PI);
6
+ float angle = atan(p.y, p.x) / (2.0 * PI);
8
7
 
9
8
  float adjusted = angle - p_startAngle;
10
9
  adjusted = p_direction > 0.0 ? adjusted : -adjusted;
@@ -10,8 +10,12 @@ export interface UIInputCatcherCallbacks {
10
10
  catchPointerDown: (x: number, y: number, identifier: number) => boolean;
11
11
  /** Returns true to stop the event for catchers below; ignored for a captured pointer */
12
12
  catchPointerMove: (x: number, y: number, identifier: number) => boolean;
13
- /** Returns true to stop the event for catchers below; ignored for a captured pointer */
14
- catchPointerUp: (x: number, y: number, identifier: number) => boolean;
13
+ /**
14
+ * Returns true to stop the event for catchers below; ignored for a captured pointer.
15
+ * `hovering` is true for a pointer that stays over the page after the release, as a mouse
16
+ * does: its next events come with the same identifier.
17
+ */
18
+ catchPointerUp: (x: number, y: number, identifier: number, hovering: boolean) => boolean;
15
19
  /**
16
20
  * The pointer is gone for this catcher: drop what is known of it. Called when a pressed
17
21
  * pointer is cancelled (by the browser or by the layer), on the catcher that captured it, or
@@ -23,7 +27,7 @@ export interface UIInputCatcherCallbacks {
23
27
  catchPointerCancel: (identifier: number) => void;
24
28
  }
25
29
  export interface UIInputWrapperView {
26
- /** Bumped by every change to the draw order; compare with the last seen value */
30
+ /** Bumped by every change to the draw order, to compare with a value seen before */
27
31
  readonly version: number;
28
32
  createInputCatcher(callbacks: UIInputCatcherCallbacks, zIndex: number): number;
29
33
  destroyInputCatcher(handler: number): void;
@@ -8,7 +8,7 @@ export declare class UIInputWrapper implements UIInputWrapperView {
8
8
  /** Pointers seen moving while not pressed, such as a hovering mouse */
9
9
  private readonly hoveringPointers;
10
10
  private lastHandler;
11
- /** Bumped by every change to the draw order; compare with the last seen value */
11
+ /** Bumped by every change to the draw order, to compare with a value seen before */
12
12
  get version(): number;
13
13
  createInputCatcher(callbacks: UIInputCatcherCallbacks, zIndex: number): number;
14
14
  destroyInputCatcher(handler: number): void;
@@ -20,6 +20,7 @@ export declare class UIInputWrapper implements UIInputWrapperView {
20
20
  /**
21
21
  * Passes a pointer event from the top catcher down until one catches it. A handler may
22
22
  * destroy elements, so the catchers are walked over a copy and a destroyed one is skipped.
23
+ * @param catchEvent Passes the event to a catcher; true if it caught it
23
24
  * @param pointer Pressed pointer the event belongs to: the walk stops once a handler ends it
24
25
  * @returns The catcher that caught the event, or null
25
26
  */