laymur 0.15.1 → 0.17.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 (248) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/.editorconfig +14 -0
  3. package/CLAUDE.md +181 -0
  4. package/README.md +84 -208
  5. package/assets/logotype.png +0 -0
  6. package/eslint.config.js +111 -0
  7. package/package.json +20 -36
  8. package/rollup.config.js +52 -0
  9. package/{dist/constraints/UIAspectConstraint/UIAspectConstraint.Internal.d.ts → src/core/constraints/UIAspectConstraint/UIAspectConstraint.Internal.ts} +3 -2
  10. package/src/core/constraints/UIAspectConstraint/UIAspectConstraint.ts +60 -0
  11. package/src/core/constraints/UIConstraint.ts +20 -0
  12. package/src/core/constraints/UICustomConstraint.ts +62 -0
  13. package/{dist/constraints/UIHeightConstraint/UIHeightConstraint.Internal.d.ts → src/core/constraints/UIHeightConstraint/UIHeightConstraint.Internal.ts} +3 -2
  14. package/src/core/constraints/UIHeightConstraint/UIHeightConstraint.ts +52 -0
  15. package/src/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.Internal.ts +13 -0
  16. package/src/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.ts +139 -0
  17. package/src/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.Internal.ts +16 -0
  18. package/src/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.ts +189 -0
  19. package/{dist/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.Internal.d.ts → src/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.Internal.ts} +3 -2
  20. package/src/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.ts +68 -0
  21. package/{dist/constraints/UISingleParameterConstraint/UISingleParameterConstraint.Internal.d.ts → src/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.Internal.ts} +9 -8
  22. package/src/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.ts +94 -0
  23. package/src/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.Internal.ts +13 -0
  24. package/src/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.ts +135 -0
  25. package/src/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.Internal.ts +16 -0
  26. package/src/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.ts +189 -0
  27. package/{dist/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.Internal.d.ts → src/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.Internal.ts} +3 -2
  28. package/src/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.ts +68 -0
  29. package/{dist/constraints/UIWidthConstraint/UIWidthConstraint.Internal.d.ts → src/core/constraints/UIWidthConstraint/UIWidthConstraint.Internal.ts} +3 -2
  30. package/src/core/constraints/UIWidthConstraint/UIWidthConstraint.ts +52 -0
  31. package/src/core/constraints/builders/UIConstraint2DBuilder.Internal.ts +84 -0
  32. package/src/core/constraints/builders/UIConstraint2DBuilder.ts +168 -0
  33. package/src/core/constraints/builders/UICoverConstraintBuilder.Internal.ts +15 -0
  34. package/src/core/constraints/builders/UICoverConstraintBuilder.ts +84 -0
  35. package/src/core/constraints/builders/UIFitConstraintBuilder.Internal.ts +15 -0
  36. package/src/core/constraints/builders/UIFitConstraintBuilder.ts +84 -0
  37. package/src/core/elements/UIAnchor/UIAnchor.Internal.ts +13 -0
  38. package/src/core/elements/UIAnchor/UIAnchor.ts +70 -0
  39. package/src/core/elements/UIAnimatedImage/UIAnimatedImage.Internal.ts +30 -0
  40. package/src/core/elements/UIAnimatedImage/UIAnimatedImage.ts +355 -0
  41. package/src/core/elements/UIDummy/UIDummy.Internal.ts +33 -0
  42. package/src/core/elements/UIDummy/UIDummy.ts +244 -0
  43. package/src/core/elements/UIElement/UIElement.Internal.ts +13 -0
  44. package/src/core/elements/UIElement/UIElement.ts +127 -0
  45. package/{dist/elements/UIGraphics/UIGraphics.Internal.d.ts → src/core/elements/UIGraphics/UIGraphics.Internal.ts} +7 -5
  46. package/src/core/elements/UIGraphics/UIGraphics.ts +168 -0
  47. package/{dist/elements/UIImage/UIImage.Internal.d.ts → src/core/elements/UIImage/UIImage.Internal.ts} +3 -2
  48. package/src/core/elements/UIImage/UIImage.ts +138 -0
  49. package/src/core/elements/UINineSlice/UINineSlice.Internal.ts +26 -0
  50. package/src/core/elements/UINineSlice/UINineSlice.ts +296 -0
  51. package/src/core/elements/UIProgress/UIProgress.Internal.ts +24 -0
  52. package/src/core/elements/UIProgress/UIProgress.ts +259 -0
  53. package/src/core/elements/UIScene/UIScene.Internal.ts +46 -0
  54. package/src/core/elements/UIScene/UIScene.ts +259 -0
  55. package/{dist/elements/UIText/UIText.Interfaces.d.ts → src/core/elements/UIText/UIText.Interfaces.ts} +21 -16
  56. package/src/core/elements/UIText/UIText.Internal.ts +29 -0
  57. package/src/core/elements/UIText/UIText.Measuring.ts +183 -0
  58. package/src/core/elements/UIText/UIText.Rendering.ts +83 -0
  59. package/src/core/elements/UIText/UIText.ts +376 -0
  60. package/{dist/index.d.ts → src/core/index.ts} +2 -1
  61. package/{dist/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.d.ts → src/core/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.ts} +14 -11
  62. package/src/core/layers/UIFullscreenLayer/UIFullscreenLayer.ts +233 -0
  63. package/{dist/layers/UILayer/UILayer.Internal.d.ts → src/core/layers/UILayer/UILayer.Internal.ts} +15 -11
  64. package/src/core/layers/UILayer/UILayer.ts +156 -0
  65. package/src/core/miscellaneous/UIExpression.ts +142 -0
  66. package/src/core/miscellaneous/UIMode.ts +29 -0
  67. package/src/core/miscellaneous/UIOrientation.ts +18 -0
  68. package/src/core/miscellaneous/UIPriority.ts +63 -0
  69. package/src/core/miscellaneous/UIRelation.ts +39 -0
  70. package/src/core/miscellaneous/UITransparencyMode.ts +9 -0
  71. package/src/core/miscellaneous/area/UIArea.ts +5 -0
  72. package/src/core/miscellaneous/area/UIAreaCircle.ts +32 -0
  73. package/src/core/miscellaneous/area/UIAreaPolygon.ts +50 -0
  74. package/src/core/miscellaneous/area/UIAreaRectangle.ts +38 -0
  75. package/src/core/miscellaneous/area/UIAreaRoundedRectangle.ts +78 -0
  76. package/src/core/miscellaneous/asserts.ts +187 -0
  77. package/src/core/miscellaneous/canvas.ts +73 -0
  78. package/src/core/miscellaneous/color/UIColor.Internal.ts +89 -0
  79. package/src/core/miscellaneous/color/UIColor.ts +844 -0
  80. package/src/core/miscellaneous/computeTransform.ts +127 -0
  81. package/src/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.ts +235 -0
  82. package/src/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.ts +524 -0
  83. package/{dist/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.d.ts → src/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.ts} +10 -8
  84. package/src/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.ts +448 -0
  85. package/src/core/miscellaneous/generic-plane/shared.ts +323 -0
  86. package/src/core/miscellaneous/insets/UIInsets.Internal.ts +9 -0
  87. package/src/core/miscellaneous/insets/UIInsets.ts +248 -0
  88. package/src/core/miscellaneous/mask-function/UIProgressMaskFunction.ts +24 -0
  89. package/src/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.ts +58 -0
  90. package/src/core/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.ts +52 -0
  91. package/src/core/miscellaneous/math.ts +16 -0
  92. package/src/core/miscellaneous/micro/UIMicro.Internal.ts +33 -0
  93. package/src/core/miscellaneous/micro/UIMicro.ts +222 -0
  94. package/src/core/miscellaneous/resize-policy/UIResizePolicy.ts +8 -0
  95. package/src/core/miscellaneous/resize-policy/UIResizePolicyCover.ts +57 -0
  96. package/src/core/miscellaneous/resize-policy/UIResizePolicyCross.ts +65 -0
  97. package/src/core/miscellaneous/resize-policy/UIResizePolicyCrossInverted.ts +65 -0
  98. package/src/core/miscellaneous/resize-policy/UIResizePolicyFit.ts +57 -0
  99. package/src/core/miscellaneous/resize-policy/UIResizePolicyFixedHeight.ts +65 -0
  100. package/src/core/miscellaneous/resize-policy/UIResizePolicyFixedWidth.ts +65 -0
  101. package/src/core/miscellaneous/resize-policy/UIResizePolicyNone.ts +11 -0
  102. package/src/core/miscellaneous/shared.ts +73 -0
  103. package/{dist/miscellaneous/text-span/UITextSpan.Internal.d.ts → src/core/miscellaneous/text-span/UITextSpan.Internal.ts} +5 -4
  104. package/src/core/miscellaneous/text-span/UITextSpan.ts +43 -0
  105. package/src/core/miscellaneous/text-style/UITextStyle.Internal.ts +52 -0
  106. package/src/core/miscellaneous/text-style/UITextStyle.ts +479 -0
  107. package/src/core/miscellaneous/texture/UITextureView.Internal.ts +55 -0
  108. package/src/core/miscellaneous/texture/UITextureView.ts +308 -0
  109. package/src/core/miscellaneous/webglCapabilities.ts +129 -0
  110. package/src/core/shaders/UIImage.glsl +10 -0
  111. package/src/core/shaders/UINineSlice.glsl +53 -0
  112. package/src/core/shaders/UIProgress.glsl +15 -0
  113. package/src/core/shaders/UIProgressMaskFunctionCircular.glsl +13 -0
  114. package/src/core/shaders/UIProgressMaskFunctionDirectional.glsl +12 -0
  115. package/src/core/shaders/glsl.d.ts +27 -0
  116. package/src/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.ts +23 -0
  117. package/src/core/wrappers/UIInputWrapper/UIInputWrapper.ts +124 -0
  118. package/src/core/wrappers/UISceneWrapper/UISceneWrapper.Internal.ts +22 -0
  119. package/src/core/wrappers/UISceneWrapper/UISceneWrapper.ts +101 -0
  120. package/src/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.ts +58 -0
  121. package/src/core/wrappers/UISolverWrapper/UISolverWrapper.ts +605 -0
  122. package/src/particles/behaviorModules/UIBehaviorDirectionalGravity.ts +70 -0
  123. package/src/particles/behaviorModules/UIBehaviorModule.ts +20 -0
  124. package/src/particles/behaviorModules/UIBehaviorPointGravity.ts +173 -0
  125. package/src/particles/behaviorModules/UIBehaviorScaleOverLife.ts +104 -0
  126. package/src/particles/behaviorModules/UIBehaviorTorqueDamping.ts +75 -0
  127. package/src/particles/behaviorModules/UIBehaviorTorqueNoise.ts +115 -0
  128. package/src/particles/behaviorModules/UIBehaviorVelocityDamping.ts +77 -0
  129. package/src/particles/behaviorModules/UIBehaviorVelocityNoise.ts +118 -0
  130. package/src/particles/elements/UIEmitter.Internal.ts +22 -0
  131. package/src/particles/elements/UIEmitter.ts +313 -0
  132. package/src/particles/index.ts +18 -0
  133. package/src/particles/instancedParticle/UIInstancedParticle.Internal.ts +263 -0
  134. package/src/particles/instancedParticle/UIInstancedParticle.ts +138 -0
  135. package/src/particles/miscellaneous/miscellaneous.ts +115 -0
  136. package/src/particles/renderingModules/UIRenderingColorOverLife.ts +39 -0
  137. package/src/particles/renderingModules/UIRenderingColorOverVelocity.ts +49 -0
  138. package/src/particles/renderingModules/UIRenderingModule.ts +17 -0
  139. package/src/particles/renderingModules/UIRenderingTexture.ts +30 -0
  140. package/src/particles/shaders/UIRenderingColorOverLife.glsl +4 -0
  141. package/src/particles/shaders/UIRenderingColorOverVelocity.glsl +6 -0
  142. package/src/particles/shaders/UIRenderingTexture.glsl +4 -0
  143. package/src/particles/spawnModules/UISpawnModule.ts +22 -0
  144. package/src/particles/spawnModules/UISpawnOffset.ts +62 -0
  145. package/src/particles/spawnModules/UISpawnRandomLifetime.ts +68 -0
  146. package/src/particles/spawnModules/UISpawnRandomRotation.ts +60 -0
  147. package/src/particles/spawnModules/UISpawnRandomScale.ts +81 -0
  148. package/src/particles/spawnModules/UISpawnRandomTorque.ts +62 -0
  149. package/src/particles/spawnModules/UISpawnRandomVelocity.ts +92 -0
  150. package/src/particles/spawnModules/UISpawnRectangle.ts +81 -0
  151. package/tsconfig.json +29 -0
  152. package/dist/constraints/UIAspectConstraint/UIAspectConstraint.d.ts +0 -22
  153. package/dist/constraints/UIConstraint.d.ts +0 -12
  154. package/dist/constraints/UICustomConstraint.d.ts +0 -28
  155. package/dist/constraints/UIHeightConstraint/UIHeightConstraint.d.ts +0 -20
  156. package/dist/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.Internal.d.ts +0 -11
  157. package/dist/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.d.ts +0 -36
  158. package/dist/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.Internal.d.ts +0 -14
  159. package/dist/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.d.ts +0 -44
  160. package/dist/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.d.ts +0 -22
  161. package/dist/constraints/UISingleParameterConstraint/UISingleParameterConstraint.d.ts +0 -43
  162. package/dist/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.Internal.d.ts +0 -11
  163. package/dist/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.d.ts +0 -32
  164. package/dist/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.Internal.d.ts +0 -14
  165. package/dist/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.d.ts +0 -44
  166. package/dist/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.d.ts +0 -22
  167. package/dist/constraints/UIWidthConstraint/UIWidthConstraint.d.ts +0 -20
  168. package/dist/constraints/builders/UIConstraint2DBuilder.Internal.d.ts +0 -64
  169. package/dist/constraints/builders/UIConstraint2DBuilder.d.ts +0 -46
  170. package/dist/constraints/builders/UICoverConstraintBuilder.Internal.d.ts +0 -13
  171. package/dist/constraints/builders/UICoverConstraintBuilder.d.ts +0 -29
  172. package/dist/constraints/builders/UIFitConstraintBuilder.Internal.d.ts +0 -13
  173. package/dist/constraints/builders/UIFitConstraintBuilder.d.ts +0 -29
  174. package/dist/elements/UIAnchor/UIAnchor.Internal.d.ts +0 -9
  175. package/dist/elements/UIAnchor/UIAnchor.d.ts +0 -32
  176. package/dist/elements/UIAnimatedImage/UIAnimatedImage.Internal.d.ts +0 -27
  177. package/dist/elements/UIAnimatedImage/UIAnimatedImage.d.ts +0 -77
  178. package/dist/elements/UIElement/UIElement.Internal.d.ts +0 -11
  179. package/dist/elements/UIElement/UIElement.d.ts +0 -38
  180. package/dist/elements/UIGraphics/UIGraphics.d.ts +0 -51
  181. package/dist/elements/UIImage/UIImage.d.ts +0 -32
  182. package/dist/elements/UIInputDummy/UIInputDummy.Internal.d.ts +0 -30
  183. package/dist/elements/UIInputDummy/UIInputDummy.d.ts +0 -82
  184. package/dist/elements/UINineSlice/UINineSlice.Internal.d.ts +0 -23
  185. package/dist/elements/UINineSlice/UINineSlice.d.ts +0 -60
  186. package/dist/elements/UIProgress/UIProgress.Internal.d.ts +0 -14
  187. package/dist/elements/UIProgress/UIProgress.d.ts +0 -45
  188. package/dist/elements/UIScene/UIScene.Internal.d.ts +0 -43
  189. package/dist/elements/UIScene/UIScene.d.ts +0 -59
  190. package/dist/elements/UIText/UIText.Internal.d.ts +0 -26
  191. package/dist/elements/UIText/UIText.Measuring.d.ts +0 -50
  192. package/dist/elements/UIText/UIText.Rendering.d.ts +0 -20
  193. package/dist/elements/UIText/UIText.d.ts +0 -71
  194. package/dist/index.js +0 -9236
  195. package/dist/index.js.map +0 -1
  196. package/dist/index.min.js +0 -2
  197. package/dist/index.min.js.map +0 -1
  198. package/dist/layers/UIFullscreenLayer/UIFullscreenLayer.d.ts +0 -63
  199. package/dist/layers/UILayer/UILayer.d.ts +0 -49
  200. package/dist/miscellaneous/UIExpression.d.ts +0 -69
  201. package/dist/miscellaneous/UIMode.d.ts +0 -23
  202. package/dist/miscellaneous/UIOrientation.d.ts +0 -15
  203. package/dist/miscellaneous/UIPriority.d.ts +0 -32
  204. package/dist/miscellaneous/UIRelation.d.ts +0 -23
  205. package/dist/miscellaneous/UITransparencyMode.d.ts +0 -9
  206. package/dist/miscellaneous/area/UIArea.d.ts +0 -3
  207. package/dist/miscellaneous/area/UIAreaCircle.d.ts +0 -15
  208. package/dist/miscellaneous/area/UIAreaPolygon.d.ts +0 -12
  209. package/dist/miscellaneous/area/UIAreaRectangle.d.ts +0 -17
  210. package/dist/miscellaneous/area/UIAreaRoundedRectangle.d.ts +0 -21
  211. package/dist/miscellaneous/asserts.d.ts +0 -43
  212. package/dist/miscellaneous/canvas.d.ts +0 -31
  213. package/dist/miscellaneous/color/UIColor.Internal.d.ts +0 -7
  214. package/dist/miscellaneous/color/UIColor.d.ts +0 -234
  215. package/dist/miscellaneous/computeTransform.d.ts +0 -18
  216. package/dist/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.d.ts +0 -19
  217. package/dist/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.d.ts +0 -1
  218. package/dist/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.d.ts +0 -1
  219. package/dist/miscellaneous/generic-plane/shared.d.ts +0 -38
  220. package/dist/miscellaneous/insets/UIInsets.Internal.d.ts +0 -11
  221. package/dist/miscellaneous/insets/UIInsets.d.ts +0 -48
  222. package/dist/miscellaneous/mask-function/UIProgressMaskFunction.d.ts +0 -9
  223. package/dist/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +0 -21
  224. package/dist/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.d.ts +0 -16
  225. package/dist/miscellaneous/math.d.ts +0 -5
  226. package/dist/miscellaneous/micro/UIMicro.Internal.d.ts +0 -31
  227. package/dist/miscellaneous/micro/UIMicro.d.ts +0 -59
  228. package/dist/miscellaneous/resize-policy/UIResizePolicy.d.ts +0 -3
  229. package/dist/miscellaneous/resize-policy/UIResizePolicyCover.d.ts +0 -22
  230. package/dist/miscellaneous/resize-policy/UIResizePolicyCross.d.ts +0 -22
  231. package/dist/miscellaneous/resize-policy/UIResizePolicyCrossInverted.d.ts +0 -22
  232. package/dist/miscellaneous/resize-policy/UIResizePolicyFit.d.ts +0 -22
  233. package/dist/miscellaneous/resize-policy/UIResizePolicyFixedHeight.d.ts +0 -22
  234. package/dist/miscellaneous/resize-policy/UIResizePolicyFixedWidth.d.ts +0 -22
  235. package/dist/miscellaneous/resize-policy/UIResizePolicyNone.d.ts +0 -5
  236. package/dist/miscellaneous/shared.d.ts +0 -46
  237. package/dist/miscellaneous/text-span/UITextSpan.d.ts +0 -14
  238. package/dist/miscellaneous/text-style/UITextStyle.Internal.d.ts +0 -48
  239. package/dist/miscellaneous/text-style/UITextStyle.d.ts +0 -85
  240. package/dist/miscellaneous/texture/UITextureView.Internal.d.ts +0 -49
  241. package/dist/miscellaneous/texture/UITextureView.d.ts +0 -67
  242. package/dist/miscellaneous/webglCapabilities.d.ts +0 -2
  243. package/dist/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +0 -17
  244. package/dist/wrappers/UIInputWrapper/UIInputWrapper.d.ts +0 -13
  245. package/dist/wrappers/UISceneWrapper/UISceneWrapper.Internal.d.ts +0 -13
  246. package/dist/wrappers/UISceneWrapper/UISceneWrapper.d.ts +0 -20
  247. package/dist/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +0 -49
  248. package/dist/wrappers/UISolverWrapper/UISolverWrapper.d.ts +0 -215
@@ -0,0 +1,308 @@
1
+ import type { FerrsignView3 } from "ferrsign";
2
+ import { Ferrsign3 } from "ferrsign";
3
+ import { Matrix3, Texture, Vector2 } from "three";
4
+ import { assertValidNonNegativeNumber, assertValidPositiveNumber } from "../asserts";
5
+ import type {
6
+ UITextureAtlasConfig,
7
+ UITextureConfig,
8
+ UITextureTrim,
9
+ } from "./UITextureView.Internal";
10
+ import { TEXTURE_DEFAULT_SIZE, TEXTURE_DEFAULT_TEXTURE } from "./UITextureView.Internal";
11
+
12
+ /** Wrapper for Three.js texture with atlas and trim support. Does not own the underlying texture; user must dispose it. */
13
+ export class UITextureView {
14
+ private textureInternal: Texture = TEXTURE_DEFAULT_TEXTURE;
15
+
16
+ private sourceWidth = TEXTURE_DEFAULT_SIZE;
17
+ private sourceHeight = TEXTURE_DEFAULT_SIZE;
18
+
19
+ private frameX = 0;
20
+ private frameY = 0;
21
+ private frameWidth = TEXTURE_DEFAULT_SIZE;
22
+ private frameHeight = TEXTURE_DEFAULT_SIZE;
23
+
24
+ private rotatedInternal = false;
25
+ private scaleInternal = 1;
26
+
27
+ private trimLeft = 0;
28
+ private trimRight = 0;
29
+ private trimTop = 0;
30
+ private trimBottom = 0;
31
+
32
+ private textureDirtyInternal = false;
33
+ private uvTransformDirtyInternal = false;
34
+ private trimDirtyInternal = false;
35
+
36
+ private readonly signalDiminsionsChangedInternal = new Ferrsign3<number, number, UITextureView>();
37
+
38
+ /** @param config Texture or atlas configuration */
39
+ constructor(config?: UITextureConfig) {
40
+ if (config !== undefined) {
41
+ this.set(config);
42
+ }
43
+ }
44
+
45
+ /** Original width before trimming in world units */
46
+ public get width(): number {
47
+ return this.sourceWidth / this.scaleInternal;
48
+ }
49
+
50
+ /** Original height before trimming in world units */
51
+ public get height(): number {
52
+ return this.sourceHeight / this.scaleInternal;
53
+ }
54
+
55
+ /** Visible width after trimming in world units */
56
+ public get trimmedWidth(): number {
57
+ const frameSize = this.rotatedInternal ? this.frameHeight : this.frameWidth;
58
+ return frameSize / this.scaleInternal;
59
+ }
60
+
61
+ /** Visible height after trimming in world units */
62
+ public get trimmedHeight(): number {
63
+ const frameSize = this.rotatedInternal ? this.frameWidth : this.frameHeight;
64
+ return frameSize / this.scaleInternal;
65
+ }
66
+
67
+ /** Underlying Three.js texture */
68
+ public get texture(): Texture {
69
+ return this.textureInternal;
70
+ }
71
+
72
+ /** Whether sprite is rotated in atlas */
73
+ public get rotated(): boolean {
74
+ return this.rotatedInternal;
75
+ }
76
+
77
+ /** Scale factor for resolution independence */
78
+ public get scale(): number {
79
+ return this.scaleInternal;
80
+ }
81
+
82
+ /** Transparent padding around visible content */
83
+ public get trim(): Readonly<UITextureTrim> {
84
+ const scale = this.scaleInternal;
85
+ return {
86
+ left: this.trimLeft / scale,
87
+ right: this.trimRight / scale,
88
+ top: this.trimTop / scale,
89
+ bottom: this.trimBottom / scale,
90
+ };
91
+ }
92
+
93
+ public get textureDirty(): boolean {
94
+ return this.textureDirtyInternal;
95
+ }
96
+
97
+ /** Whether UV transform inputs changed since last check */
98
+ public get uvTransformDirty(): boolean {
99
+ return this.uvTransformDirtyInternal;
100
+ }
101
+
102
+ /** Whether trim values changed since last check */
103
+ public get trimDirty(): boolean {
104
+ return this.trimDirtyInternal;
105
+ }
106
+
107
+ public get signalDiminsionsChanged(): FerrsignView3<number, number, UITextureView> {
108
+ return this.signalDiminsionsChangedInternal;
109
+ }
110
+
111
+ public setTextureDirtyFalse(): void {
112
+ this.textureDirtyInternal = false;
113
+ }
114
+
115
+ /** Marks UV transform as clean. @internal */
116
+ public setUVTransformDirtyFalse(): void {
117
+ this.uvTransformDirtyInternal = false;
118
+ }
119
+
120
+ /** Marks trim as clean. @internal */
121
+ public setTrimDirtyFalse(): void {
122
+ this.trimDirtyInternal = false;
123
+ }
124
+
125
+ /**
126
+ * Calculates UV transform matrix for shader sampling.
127
+ * @param result Matrix to store result in
128
+ * @returns UV transform matrix
129
+ */
130
+ public calculateUVTransform(result = new Matrix3()): Matrix3 {
131
+ const atlasWidth = this.textureInternal.image?.naturalWidth ?? TEXTURE_DEFAULT_SIZE;
132
+ const atlasHeight = this.textureInternal.image?.naturalHeight ?? TEXTURE_DEFAULT_SIZE;
133
+
134
+ if (this.rotatedInternal) {
135
+ const physicalWidth = this.frameHeight;
136
+ const physicalHeight = this.frameWidth;
137
+
138
+ const u0 = this.frameX / atlasWidth;
139
+ const v0 = (atlasHeight - this.frameY - physicalHeight) / atlasHeight;
140
+ const uSize = physicalWidth / atlasWidth;
141
+ const vSize = physicalHeight / atlasHeight;
142
+
143
+ result.set(0, uSize, u0, -vSize, 0, v0 + vSize, 0, 0, 1);
144
+ } else {
145
+ const u0 = this.frameX / atlasWidth;
146
+ const v0 = (atlasHeight - this.frameY - this.frameHeight) / atlasHeight;
147
+ const uSize = this.frameWidth / atlasWidth;
148
+ const vSize = this.frameHeight / atlasHeight;
149
+
150
+ result.set(uSize, 0, u0, 0, vSize, v0, 0, 0, 1);
151
+ }
152
+
153
+ return result;
154
+ }
155
+
156
+ /**
157
+ * Gets original dimensions before trimming.
158
+ * @param result Vector to store result in
159
+ * @returns Width and height in world units
160
+ */
161
+ public getResolution(result = new Vector2()): Vector2 {
162
+ return result.set(this.width, this.height);
163
+ }
164
+
165
+ /**
166
+ * Replaces texture with new configuration.
167
+ * @param config Texture or atlas configuration
168
+ */
169
+ public set(config: UITextureConfig): void {
170
+ const lastWidth = this.width;
171
+ const lastHeight = this.height;
172
+
173
+ if (config instanceof Texture) {
174
+ this.setFromTexture(config);
175
+ } else {
176
+ this.setFromAtlasConfig(config);
177
+ }
178
+
179
+ if (this.width !== lastWidth || this.height !== lastHeight) {
180
+ this.signalDiminsionsChangedInternal.emit(this.width, this.height, this);
181
+ }
182
+ }
183
+
184
+ private setFromTexture(texture: Texture): void {
185
+ const width = texture.image?.naturalWidth ?? TEXTURE_DEFAULT_SIZE;
186
+ const height = texture.image?.naturalHeight ?? TEXTURE_DEFAULT_SIZE;
187
+
188
+ this.sourceWidth = width;
189
+ this.sourceHeight = height;
190
+
191
+ if (this.texture !== texture) {
192
+ this.textureInternal = texture;
193
+ this.textureDirtyInternal = true;
194
+ }
195
+
196
+ if (
197
+ this.frameX !== 0 ||
198
+ this.frameY !== 0 ||
199
+ this.frameWidth !== width ||
200
+ this.frameHeight !== height ||
201
+ this.scaleInternal !== 1 ||
202
+ this.rotatedInternal
203
+ ) {
204
+ this.frameX = 0;
205
+ this.frameY = 0;
206
+ this.frameWidth = width;
207
+ this.frameHeight = height;
208
+ this.rotatedInternal = false;
209
+ this.scaleInternal = 1;
210
+ this.uvTransformDirtyInternal = true;
211
+ }
212
+
213
+ if (
214
+ this.trimLeft !== 0 ||
215
+ this.trimRight !== 0 ||
216
+ this.trimTop !== 0 ||
217
+ this.trimBottom !== 0
218
+ ) {
219
+ this.trimLeft = 0;
220
+ this.trimRight = 0;
221
+ this.trimTop = 0;
222
+ this.trimBottom = 0;
223
+ this.trimDirtyInternal = true;
224
+ }
225
+ }
226
+
227
+ private setFromAtlasConfig(config: UITextureAtlasConfig): void {
228
+ assertValidPositiveNumber(
229
+ config.sourceSize.w,
230
+ "UITextureView.setFromAtlasConfig.config.sourceSize.w",
231
+ );
232
+ assertValidPositiveNumber(
233
+ config.sourceSize.h,
234
+ "UITextureView.setFromAtlasConfig.config.sourceSize.h",
235
+ );
236
+ assertValidNonNegativeNumber(config.frame.x, "UITextureView.setFromAtlasConfig.config.frame.x");
237
+ assertValidNonNegativeNumber(config.frame.y, "UITextureView.setFromAtlasConfig.config.frame.y");
238
+ assertValidPositiveNumber(config.frame.w, "UITextureView.setFromAtlasConfig.config.frame.w");
239
+ assertValidPositiveNumber(config.frame.h, "UITextureView.setFromAtlasConfig.config.frame.h");
240
+ assertValidNonNegativeNumber(
241
+ config.spriteSourceSize.x,
242
+ "UITextureView.setFromAtlasConfig.config.spriteSourceSize.x",
243
+ );
244
+ assertValidNonNegativeNumber(
245
+ config.spriteSourceSize.y,
246
+ "UITextureView.setFromAtlasConfig.config.spriteSourceSize.y",
247
+ );
248
+ assertValidPositiveNumber(
249
+ config.spriteSourceSize.w,
250
+ "UITextureView.setFromAtlasConfig.config.spriteSourceSize.w",
251
+ );
252
+ assertValidPositiveNumber(
253
+ config.spriteSourceSize.h,
254
+ "UITextureView.setFromAtlasConfig.config.spriteSourceSize.h",
255
+ );
256
+
257
+ if (config.scale !== undefined) {
258
+ assertValidPositiveNumber(config.scale, "UITextureView.setFromAtlasConfig.config.scale");
259
+ }
260
+
261
+ this.sourceWidth = config.sourceSize.w;
262
+ this.sourceHeight = config.sourceSize.h;
263
+
264
+ if (this.texture !== config.texture) {
265
+ this.textureInternal = config.texture;
266
+ this.textureDirtyInternal = true;
267
+ }
268
+
269
+ const scale = config.scale ?? 1;
270
+ const rotated = config.rotated ?? false;
271
+
272
+ if (
273
+ this.frameX !== 0 ||
274
+ this.frameY !== 0 ||
275
+ this.frameWidth !== config.frame.w ||
276
+ this.frameHeight !== config.frame.h ||
277
+ this.scaleInternal !== scale ||
278
+ this.rotatedInternal !== rotated
279
+ ) {
280
+ this.frameX = config.frame.x;
281
+ this.frameY = config.frame.y;
282
+ this.frameWidth = config.frame.w;
283
+ this.frameHeight = config.frame.h;
284
+ this.scaleInternal = scale;
285
+ this.rotatedInternal = rotated;
286
+ this.uvTransformDirtyInternal = true;
287
+ }
288
+
289
+ const spriteSource = config.spriteSourceSize;
290
+ const trimLeft = spriteSource.x;
291
+ const trimTop = spriteSource.y;
292
+ const trimRight = this.sourceWidth - spriteSource.x - spriteSource.w;
293
+ const trimBottom = this.sourceHeight - spriteSource.y - spriteSource.h;
294
+
295
+ if (
296
+ this.trimLeft !== trimLeft ||
297
+ this.trimRight !== trimRight ||
298
+ this.trimTop !== trimTop ||
299
+ this.trimBottom !== trimBottom
300
+ ) {
301
+ this.trimLeft = trimLeft;
302
+ this.trimRight = trimRight;
303
+ this.trimTop = trimTop;
304
+ this.trimBottom = trimBottom;
305
+ this.trimDirtyInternal = true;
306
+ }
307
+ }
308
+ }
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Checks real OffscreenCanvas support as a texture source
3
+ */
4
+ function checkOffscreenCanvasSupportInternal(): boolean {
5
+ if (typeof OffscreenCanvas === "undefined") {
6
+ return false;
7
+ }
8
+
9
+ const testCanvasElement = document.createElement("canvas");
10
+ testCanvasElement.width = 4;
11
+ testCanvasElement.height = 4;
12
+
13
+ const gl = testCanvasElement.getContext("webgl") ?? testCanvasElement.getContext("webgl2");
14
+ if (!gl) {
15
+ return false;
16
+ }
17
+
18
+ try {
19
+ const offscreenCanvas = new OffscreenCanvas(4, 4);
20
+ const offscreenContext = offscreenCanvas.getContext("2d");
21
+ if (!offscreenContext) {
22
+ return false;
23
+ }
24
+
25
+ offscreenContext.fillStyle = "#ff0000";
26
+ offscreenContext.fillRect(0, 0, 4, 4);
27
+
28
+ const texture = gl.createTexture();
29
+ gl.bindTexture(gl.TEXTURE_2D, texture);
30
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, offscreenCanvas);
31
+
32
+ if (gl.getError() !== gl.NO_ERROR) {
33
+ gl.deleteTexture(texture);
34
+ return false;
35
+ }
36
+
37
+ const framebuffer = gl.createFramebuffer();
38
+ gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
39
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
40
+
41
+ if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE) {
42
+ gl.deleteFramebuffer(framebuffer);
43
+ gl.deleteTexture(texture);
44
+ return false;
45
+ }
46
+
47
+ const pixelData = new Uint8Array(4);
48
+ gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixelData);
49
+
50
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
51
+ gl.deleteFramebuffer(framebuffer);
52
+ gl.deleteTexture(texture);
53
+
54
+ // Check that the read pixel is red (with tolerance)
55
+ const isRedPixel =
56
+ pixelData[0] > 200 && pixelData[1] < 50 && pixelData[2] < 50 && pixelData[3] > 200;
57
+ if (!isRedPixel) {
58
+ return false;
59
+ }
60
+
61
+ return true;
62
+ } catch (error) {
63
+ void error;
64
+ return false;
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Checks sRGB support
70
+ */
71
+ function checkSRGBSupportInternal(): boolean {
72
+ const canvasElement = document.createElement("canvas");
73
+ const gl = canvasElement.getContext("webgl2") ?? canvasElement.getContext("webgl");
74
+ if (!gl) {
75
+ return false;
76
+ }
77
+
78
+ if (gl instanceof WebGL2RenderingContext) {
79
+ try {
80
+ const texture = gl.createTexture();
81
+ gl.bindTexture(gl.TEXTURE_2D, texture);
82
+ gl.texStorage2D(gl.TEXTURE_2D, 1, gl.SRGB8_ALPHA8, 2, 2);
83
+ const errorCode = gl.getError();
84
+ gl.deleteTexture(texture);
85
+ return errorCode === gl.NO_ERROR;
86
+ } catch {
87
+ return false;
88
+ }
89
+ }
90
+
91
+ const extension = gl.getExtension("EXT_sRGB");
92
+ if (!extension) {
93
+ return false;
94
+ }
95
+
96
+ try {
97
+ const texture = gl.createTexture();
98
+ gl.bindTexture(gl.TEXTURE_2D, texture);
99
+ gl.texImage2D(
100
+ gl.TEXTURE_2D,
101
+ 0,
102
+ extension.SRGB_ALPHA_EXT,
103
+ 2,
104
+ 2,
105
+ 0,
106
+ extension.SRGB_ALPHA_EXT,
107
+ gl.UNSIGNED_BYTE,
108
+ null,
109
+ );
110
+ const errorCode = gl.getError();
111
+ gl.deleteTexture(texture);
112
+ return errorCode === gl.NO_ERROR;
113
+ } catch {
114
+ return false;
115
+ }
116
+ }
117
+
118
+ let OFFSCREEN_CANVAS_SUPPORTED_INTERNAL: boolean | undefined;
119
+ let SRGB_SUPPORTED_INTERNAL: boolean | undefined;
120
+
121
+ export const checkOffscreenCanvasSupport = (): boolean => {
122
+ OFFSCREEN_CANVAS_SUPPORTED_INTERNAL ??= checkOffscreenCanvasSupportInternal();
123
+ return OFFSCREEN_CANVAS_SUPPORTED_INTERNAL;
124
+ };
125
+
126
+ export const checkSRGBSupport = (): boolean => {
127
+ SRGB_SUPPORTED_INTERNAL ??= checkSRGBSupportInternal();
128
+ return SRGB_SUPPORTED_INTERNAL;
129
+ };
@@ -0,0 +1,10 @@
1
+ // Required properties:
2
+ // - p_uv: vec2 (builtin)
3
+ // - p_texture: sampler2D
4
+ // - p_textureTransform: mat3
5
+ // - p_color: vec4
6
+
7
+ vec4 draw() {
8
+ vec2 transformedUV = (p_textureTransform * vec3(p_uv, 1.0)).xy;
9
+ return srgbTexture2D(p_texture, transformedUV) * p_color;
10
+ }
@@ -0,0 +1,53 @@
1
+ // Required properties:
2
+ // - p_uv: vec2 (builtin)
3
+ // - p_texture: sampler2D
4
+ // - p_textureTransform: mat3
5
+ // - p_color: vec4
6
+ // - p_sliceBorders: vec4
7
+ // - p_sliceRegions: vec4
8
+
9
+ vec4 draw() {
10
+ vec2 localUV = p_uv;
11
+
12
+ float left = p_sliceBorders.x;
13
+ float right = p_sliceBorders.y;
14
+ float top = p_sliceBorders.z;
15
+ float bottom = p_sliceBorders.w;
16
+
17
+ float leftFill = p_sliceRegions.x;
18
+ float rightFill = p_sliceRegions.y;
19
+ float topFill = p_sliceRegions.z;
20
+ float bottomFill = p_sliceRegions.w;
21
+
22
+ float lB = leftFill;
23
+ float rB = 1.0 - rightFill;
24
+ float bB = bottomFill;
25
+ float tB = 1.0 - topFill;
26
+
27
+ {
28
+ float regionL = step(p_uv.x, lB);
29
+ float regionR = step(rB, p_uv.x);
30
+ float regionM = 1.0 - regionL - regionR;
31
+
32
+ float xL = (p_uv.x / lB) * left;
33
+ float xR = 1.0 - right + ((p_uv.x - rB) / rightFill) * right;
34
+ float xM = left + ((p_uv.x - lB) / (rB - lB)) * (1.0 - left - right);
35
+
36
+ localUV.x = regionL * xL + regionM * xM + regionR * xR;
37
+ }
38
+
39
+ {
40
+ float regionB = step(p_uv.y, bB);
41
+ float regionT = step(tB, p_uv.y);
42
+ float regionC = 1.0 - regionB - regionT;
43
+
44
+ float yB = (p_uv.y / bB) * bottom;
45
+ float yT = 1.0 - top + ((p_uv.y - tB) / topFill) * top;
46
+ float yC = bottom + ((p_uv.y - bB) / (tB - bB)) * (1.0 - bottom - top);
47
+
48
+ localUV.y = regionB * yB + regionC * yC + regionT * yT;
49
+ }
50
+
51
+ vec2 transformedUV = (p_textureTransform * vec3(localUV, 1.0)).xy;
52
+ return srgbTexture2D(p_texture, transformedUV) * p_color;
53
+ }
@@ -0,0 +1,15 @@
1
+ // Required properties:
2
+ // - p_uv: vec2 (builtin)
3
+ // - p_texture: sampler2D
4
+ // - p_textureTransform: mat3
5
+ // - p_textureResolution: vec2
6
+ // - p_color: vec4
7
+ // - p_progress: float
8
+ // - p_direction: float
9
+
10
+ vec4 draw() {
11
+ vec2 transformedUV = (p_textureTransform * vec3(p_uv, 1.0)).xy;
12
+ vec4 diffuseColor = srgbTexture2D(p_texture, transformedUV) * p_color;
13
+ diffuseColor.a *= calculateMask();
14
+ return diffuseColor;
15
+ }
@@ -0,0 +1,13 @@
1
+ float calculateMask() {
2
+ float aspect = p_textureResolution.x / p_textureResolution.y;
3
+ vec2 p = (p_uv - 0.5) * vec2(aspect, 1.0);
4
+
5
+ float angle = atan(p.y, p.x);
6
+ angle = (angle + PI) / (2.0 * PI);
7
+
8
+ float adjusted = angle - p_startAngle;
9
+ adjusted = p_direction > 0.0 ? adjusted : -adjusted;
10
+ adjusted = fract(adjusted);
11
+
12
+ return step(adjusted, p_progress);
13
+ }
@@ -0,0 +1,12 @@
1
+ float calculateMask() {
2
+ float aspect = p_textureResolution.x / p_textureResolution.y;
3
+ vec2 halfExtents = vec2(aspect, 1.0) * 0.5;
4
+
5
+ float maxProjection = dot(halfExtents, abs(p_direction));
6
+
7
+ vec2 correctedUV = (p_uv - 0.5) * vec2(aspect, 1.0);
8
+ float projection = dot(correctedUV, p_direction);
9
+
10
+ float offset = (projection / maxProjection + 1.0) * 0.5;
11
+ return step(offset, p_progress);
12
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Type declarations for GLSL shader files imported as strings
3
+ */
4
+ declare module "*.glsl" {
5
+ const content: string;
6
+ export default content;
7
+ }
8
+
9
+ declare module "*.vert" {
10
+ const content: string;
11
+ export default content;
12
+ }
13
+
14
+ declare module "*.frag" {
15
+ const content: string;
16
+ export default content;
17
+ }
18
+
19
+ declare module "*.vs" {
20
+ const content: string;
21
+ export default content;
22
+ }
23
+
24
+ declare module "*.fs" {
25
+ const content: string;
26
+ export default content;
27
+ }
@@ -0,0 +1,23 @@
1
+ export interface UIInputWrapperView {
2
+ get dirty(): boolean;
3
+ createInputCatcher(
4
+ catchPointerDown: (x: number, y: number, identifier: number) => boolean,
5
+ catchPointerMove: (x: number, y: number, identifier: number) => boolean,
6
+ catchPointerUp: (x: number, y: number, identifier: number) => boolean,
7
+ zIndex: number,
8
+ ): number;
9
+ destroyInputCatcher(handler: number): void;
10
+ getZIndex(handler: number): number;
11
+ setZIndex(handler: number, zIndex: number): void;
12
+ getActive(handler: number): boolean;
13
+ setActive(handler: number, active: boolean): void;
14
+ }
15
+
16
+ export interface UIInputWrapperCatcher {
17
+ handler: number;
18
+ catchPointerDown: (x: number, y: number, identifier: number) => boolean;
19
+ catchPointerMove: (x: number, y: number, identifier: number) => boolean;
20
+ catchPointerUp: (x: number, y: number, identifier: number) => boolean;
21
+ zIndex: number;
22
+ active: boolean;
23
+ }