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.
- package/.claude/settings.local.json +9 -0
- package/.editorconfig +14 -0
- package/CLAUDE.md +181 -0
- package/README.md +84 -208
- package/assets/logotype.png +0 -0
- package/eslint.config.js +111 -0
- package/package.json +20 -36
- package/rollup.config.js +52 -0
- package/{dist/constraints/UIAspectConstraint/UIAspectConstraint.Internal.d.ts → src/core/constraints/UIAspectConstraint/UIAspectConstraint.Internal.ts} +3 -2
- package/src/core/constraints/UIAspectConstraint/UIAspectConstraint.ts +60 -0
- package/src/core/constraints/UIConstraint.ts +20 -0
- package/src/core/constraints/UICustomConstraint.ts +62 -0
- package/{dist/constraints/UIHeightConstraint/UIHeightConstraint.Internal.d.ts → src/core/constraints/UIHeightConstraint/UIHeightConstraint.Internal.ts} +3 -2
- package/src/core/constraints/UIHeightConstraint/UIHeightConstraint.ts +52 -0
- package/src/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.Internal.ts +13 -0
- package/src/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.ts +139 -0
- package/src/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.Internal.ts +16 -0
- package/src/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.ts +189 -0
- package/{dist/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.Internal.d.ts → src/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.Internal.ts} +3 -2
- package/src/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.ts +68 -0
- package/{dist/constraints/UISingleParameterConstraint/UISingleParameterConstraint.Internal.d.ts → src/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.Internal.ts} +9 -8
- package/src/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.ts +94 -0
- package/src/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.Internal.ts +13 -0
- package/src/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.ts +135 -0
- package/src/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.Internal.ts +16 -0
- package/src/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.ts +189 -0
- package/{dist/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.Internal.d.ts → src/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.Internal.ts} +3 -2
- package/src/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.ts +68 -0
- package/{dist/constraints/UIWidthConstraint/UIWidthConstraint.Internal.d.ts → src/core/constraints/UIWidthConstraint/UIWidthConstraint.Internal.ts} +3 -2
- package/src/core/constraints/UIWidthConstraint/UIWidthConstraint.ts +52 -0
- package/src/core/constraints/builders/UIConstraint2DBuilder.Internal.ts +84 -0
- package/src/core/constraints/builders/UIConstraint2DBuilder.ts +168 -0
- package/src/core/constraints/builders/UICoverConstraintBuilder.Internal.ts +15 -0
- package/src/core/constraints/builders/UICoverConstraintBuilder.ts +84 -0
- package/src/core/constraints/builders/UIFitConstraintBuilder.Internal.ts +15 -0
- package/src/core/constraints/builders/UIFitConstraintBuilder.ts +84 -0
- package/src/core/elements/UIAnchor/UIAnchor.Internal.ts +13 -0
- package/src/core/elements/UIAnchor/UIAnchor.ts +70 -0
- package/src/core/elements/UIAnimatedImage/UIAnimatedImage.Internal.ts +30 -0
- package/src/core/elements/UIAnimatedImage/UIAnimatedImage.ts +355 -0
- package/src/core/elements/UIDummy/UIDummy.Internal.ts +33 -0
- package/src/core/elements/UIDummy/UIDummy.ts +244 -0
- package/src/core/elements/UIElement/UIElement.Internal.ts +13 -0
- package/src/core/elements/UIElement/UIElement.ts +127 -0
- package/{dist/elements/UIGraphics/UIGraphics.Internal.d.ts → src/core/elements/UIGraphics/UIGraphics.Internal.ts} +7 -5
- package/src/core/elements/UIGraphics/UIGraphics.ts +168 -0
- package/{dist/elements/UIImage/UIImage.Internal.d.ts → src/core/elements/UIImage/UIImage.Internal.ts} +3 -2
- package/src/core/elements/UIImage/UIImage.ts +138 -0
- package/src/core/elements/UINineSlice/UINineSlice.Internal.ts +26 -0
- package/src/core/elements/UINineSlice/UINineSlice.ts +296 -0
- package/src/core/elements/UIProgress/UIProgress.Internal.ts +24 -0
- package/src/core/elements/UIProgress/UIProgress.ts +259 -0
- package/src/core/elements/UIScene/UIScene.Internal.ts +46 -0
- package/src/core/elements/UIScene/UIScene.ts +259 -0
- package/{dist/elements/UIText/UIText.Interfaces.d.ts → src/core/elements/UIText/UIText.Interfaces.ts} +21 -16
- package/src/core/elements/UIText/UIText.Internal.ts +29 -0
- package/src/core/elements/UIText/UIText.Measuring.ts +183 -0
- package/src/core/elements/UIText/UIText.Rendering.ts +83 -0
- package/src/core/elements/UIText/UIText.ts +376 -0
- package/{dist/index.d.ts → src/core/index.ts} +2 -1
- package/{dist/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.d.ts → src/core/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.ts} +14 -11
- package/src/core/layers/UIFullscreenLayer/UIFullscreenLayer.ts +233 -0
- package/{dist/layers/UILayer/UILayer.Internal.d.ts → src/core/layers/UILayer/UILayer.Internal.ts} +15 -11
- package/src/core/layers/UILayer/UILayer.ts +156 -0
- package/src/core/miscellaneous/UIExpression.ts +142 -0
- package/src/core/miscellaneous/UIMode.ts +29 -0
- package/src/core/miscellaneous/UIOrientation.ts +18 -0
- package/src/core/miscellaneous/UIPriority.ts +63 -0
- package/src/core/miscellaneous/UIRelation.ts +39 -0
- package/src/core/miscellaneous/UITransparencyMode.ts +9 -0
- package/src/core/miscellaneous/area/UIArea.ts +5 -0
- package/src/core/miscellaneous/area/UIAreaCircle.ts +32 -0
- package/src/core/miscellaneous/area/UIAreaPolygon.ts +50 -0
- package/src/core/miscellaneous/area/UIAreaRectangle.ts +38 -0
- package/src/core/miscellaneous/area/UIAreaRoundedRectangle.ts +78 -0
- package/src/core/miscellaneous/asserts.ts +187 -0
- package/src/core/miscellaneous/canvas.ts +73 -0
- package/src/core/miscellaneous/color/UIColor.Internal.ts +89 -0
- package/src/core/miscellaneous/color/UIColor.ts +844 -0
- package/src/core/miscellaneous/computeTransform.ts +127 -0
- package/src/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.ts +235 -0
- package/src/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.ts +524 -0
- package/{dist/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.d.ts → src/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.ts} +10 -8
- package/src/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.ts +448 -0
- package/src/core/miscellaneous/generic-plane/shared.ts +323 -0
- package/src/core/miscellaneous/insets/UIInsets.Internal.ts +9 -0
- package/src/core/miscellaneous/insets/UIInsets.ts +248 -0
- package/src/core/miscellaneous/mask-function/UIProgressMaskFunction.ts +24 -0
- package/src/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.ts +58 -0
- package/src/core/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.ts +52 -0
- package/src/core/miscellaneous/math.ts +16 -0
- package/src/core/miscellaneous/micro/UIMicro.Internal.ts +33 -0
- package/src/core/miscellaneous/micro/UIMicro.ts +222 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicy.ts +8 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyCover.ts +57 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyCross.ts +65 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyCrossInverted.ts +65 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyFit.ts +57 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyFixedHeight.ts +65 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyFixedWidth.ts +65 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyNone.ts +11 -0
- package/src/core/miscellaneous/shared.ts +73 -0
- package/{dist/miscellaneous/text-span/UITextSpan.Internal.d.ts → src/core/miscellaneous/text-span/UITextSpan.Internal.ts} +5 -4
- package/src/core/miscellaneous/text-span/UITextSpan.ts +43 -0
- package/src/core/miscellaneous/text-style/UITextStyle.Internal.ts +52 -0
- package/src/core/miscellaneous/text-style/UITextStyle.ts +479 -0
- package/src/core/miscellaneous/texture/UITextureView.Internal.ts +55 -0
- package/src/core/miscellaneous/texture/UITextureView.ts +308 -0
- package/src/core/miscellaneous/webglCapabilities.ts +129 -0
- package/src/core/shaders/UIImage.glsl +10 -0
- package/src/core/shaders/UINineSlice.glsl +53 -0
- package/src/core/shaders/UIProgress.glsl +15 -0
- package/src/core/shaders/UIProgressMaskFunctionCircular.glsl +13 -0
- package/src/core/shaders/UIProgressMaskFunctionDirectional.glsl +12 -0
- package/src/core/shaders/glsl.d.ts +27 -0
- package/src/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.ts +23 -0
- package/src/core/wrappers/UIInputWrapper/UIInputWrapper.ts +124 -0
- package/src/core/wrappers/UISceneWrapper/UISceneWrapper.Internal.ts +22 -0
- package/src/core/wrappers/UISceneWrapper/UISceneWrapper.ts +101 -0
- package/src/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.ts +58 -0
- package/src/core/wrappers/UISolverWrapper/UISolverWrapper.ts +605 -0
- package/src/particles/behaviorModules/UIBehaviorDirectionalGravity.ts +70 -0
- package/src/particles/behaviorModules/UIBehaviorModule.ts +20 -0
- package/src/particles/behaviorModules/UIBehaviorPointGravity.ts +173 -0
- package/src/particles/behaviorModules/UIBehaviorScaleOverLife.ts +104 -0
- package/src/particles/behaviorModules/UIBehaviorTorqueDamping.ts +75 -0
- package/src/particles/behaviorModules/UIBehaviorTorqueNoise.ts +115 -0
- package/src/particles/behaviorModules/UIBehaviorVelocityDamping.ts +77 -0
- package/src/particles/behaviorModules/UIBehaviorVelocityNoise.ts +118 -0
- package/src/particles/elements/UIEmitter.Internal.ts +22 -0
- package/src/particles/elements/UIEmitter.ts +313 -0
- package/src/particles/index.ts +18 -0
- package/src/particles/instancedParticle/UIInstancedParticle.Internal.ts +263 -0
- package/src/particles/instancedParticle/UIInstancedParticle.ts +138 -0
- package/src/particles/miscellaneous/miscellaneous.ts +115 -0
- package/src/particles/renderingModules/UIRenderingColorOverLife.ts +39 -0
- package/src/particles/renderingModules/UIRenderingColorOverVelocity.ts +49 -0
- package/src/particles/renderingModules/UIRenderingModule.ts +17 -0
- package/src/particles/renderingModules/UIRenderingTexture.ts +30 -0
- package/src/particles/shaders/UIRenderingColorOverLife.glsl +4 -0
- package/src/particles/shaders/UIRenderingColorOverVelocity.glsl +6 -0
- package/src/particles/shaders/UIRenderingTexture.glsl +4 -0
- package/src/particles/spawnModules/UISpawnModule.ts +22 -0
- package/src/particles/spawnModules/UISpawnOffset.ts +62 -0
- package/src/particles/spawnModules/UISpawnRandomLifetime.ts +68 -0
- package/src/particles/spawnModules/UISpawnRandomRotation.ts +60 -0
- package/src/particles/spawnModules/UISpawnRandomScale.ts +81 -0
- package/src/particles/spawnModules/UISpawnRandomTorque.ts +62 -0
- package/src/particles/spawnModules/UISpawnRandomVelocity.ts +92 -0
- package/src/particles/spawnModules/UISpawnRectangle.ts +81 -0
- package/tsconfig.json +29 -0
- package/dist/constraints/UIAspectConstraint/UIAspectConstraint.d.ts +0 -22
- package/dist/constraints/UIConstraint.d.ts +0 -12
- package/dist/constraints/UICustomConstraint.d.ts +0 -28
- package/dist/constraints/UIHeightConstraint/UIHeightConstraint.d.ts +0 -20
- package/dist/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.Internal.d.ts +0 -11
- package/dist/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.d.ts +0 -36
- package/dist/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.Internal.d.ts +0 -14
- package/dist/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.d.ts +0 -44
- package/dist/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.d.ts +0 -22
- package/dist/constraints/UISingleParameterConstraint/UISingleParameterConstraint.d.ts +0 -43
- package/dist/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.Internal.d.ts +0 -11
- package/dist/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.d.ts +0 -32
- package/dist/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.Internal.d.ts +0 -14
- package/dist/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.d.ts +0 -44
- package/dist/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.d.ts +0 -22
- package/dist/constraints/UIWidthConstraint/UIWidthConstraint.d.ts +0 -20
- package/dist/constraints/builders/UIConstraint2DBuilder.Internal.d.ts +0 -64
- package/dist/constraints/builders/UIConstraint2DBuilder.d.ts +0 -46
- package/dist/constraints/builders/UICoverConstraintBuilder.Internal.d.ts +0 -13
- package/dist/constraints/builders/UICoverConstraintBuilder.d.ts +0 -29
- package/dist/constraints/builders/UIFitConstraintBuilder.Internal.d.ts +0 -13
- package/dist/constraints/builders/UIFitConstraintBuilder.d.ts +0 -29
- package/dist/elements/UIAnchor/UIAnchor.Internal.d.ts +0 -9
- package/dist/elements/UIAnchor/UIAnchor.d.ts +0 -32
- package/dist/elements/UIAnimatedImage/UIAnimatedImage.Internal.d.ts +0 -27
- package/dist/elements/UIAnimatedImage/UIAnimatedImage.d.ts +0 -77
- package/dist/elements/UIElement/UIElement.Internal.d.ts +0 -11
- package/dist/elements/UIElement/UIElement.d.ts +0 -38
- package/dist/elements/UIGraphics/UIGraphics.d.ts +0 -51
- package/dist/elements/UIImage/UIImage.d.ts +0 -32
- package/dist/elements/UIInputDummy/UIInputDummy.Internal.d.ts +0 -30
- package/dist/elements/UIInputDummy/UIInputDummy.d.ts +0 -82
- package/dist/elements/UINineSlice/UINineSlice.Internal.d.ts +0 -23
- package/dist/elements/UINineSlice/UINineSlice.d.ts +0 -60
- package/dist/elements/UIProgress/UIProgress.Internal.d.ts +0 -14
- package/dist/elements/UIProgress/UIProgress.d.ts +0 -45
- package/dist/elements/UIScene/UIScene.Internal.d.ts +0 -43
- package/dist/elements/UIScene/UIScene.d.ts +0 -59
- package/dist/elements/UIText/UIText.Internal.d.ts +0 -26
- package/dist/elements/UIText/UIText.Measuring.d.ts +0 -50
- package/dist/elements/UIText/UIText.Rendering.d.ts +0 -20
- package/dist/elements/UIText/UIText.d.ts +0 -71
- package/dist/index.js +0 -9236
- package/dist/index.js.map +0 -1
- package/dist/index.min.js +0 -2
- package/dist/index.min.js.map +0 -1
- package/dist/layers/UIFullscreenLayer/UIFullscreenLayer.d.ts +0 -63
- package/dist/layers/UILayer/UILayer.d.ts +0 -49
- package/dist/miscellaneous/UIExpression.d.ts +0 -69
- package/dist/miscellaneous/UIMode.d.ts +0 -23
- package/dist/miscellaneous/UIOrientation.d.ts +0 -15
- package/dist/miscellaneous/UIPriority.d.ts +0 -32
- package/dist/miscellaneous/UIRelation.d.ts +0 -23
- package/dist/miscellaneous/UITransparencyMode.d.ts +0 -9
- package/dist/miscellaneous/area/UIArea.d.ts +0 -3
- package/dist/miscellaneous/area/UIAreaCircle.d.ts +0 -15
- package/dist/miscellaneous/area/UIAreaPolygon.d.ts +0 -12
- package/dist/miscellaneous/area/UIAreaRectangle.d.ts +0 -17
- package/dist/miscellaneous/area/UIAreaRoundedRectangle.d.ts +0 -21
- package/dist/miscellaneous/asserts.d.ts +0 -43
- package/dist/miscellaneous/canvas.d.ts +0 -31
- package/dist/miscellaneous/color/UIColor.Internal.d.ts +0 -7
- package/dist/miscellaneous/color/UIColor.d.ts +0 -234
- package/dist/miscellaneous/computeTransform.d.ts +0 -18
- package/dist/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.d.ts +0 -19
- package/dist/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.d.ts +0 -1
- package/dist/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.d.ts +0 -1
- package/dist/miscellaneous/generic-plane/shared.d.ts +0 -38
- package/dist/miscellaneous/insets/UIInsets.Internal.d.ts +0 -11
- package/dist/miscellaneous/insets/UIInsets.d.ts +0 -48
- package/dist/miscellaneous/mask-function/UIProgressMaskFunction.d.ts +0 -9
- package/dist/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +0 -21
- package/dist/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.d.ts +0 -16
- package/dist/miscellaneous/math.d.ts +0 -5
- package/dist/miscellaneous/micro/UIMicro.Internal.d.ts +0 -31
- package/dist/miscellaneous/micro/UIMicro.d.ts +0 -59
- package/dist/miscellaneous/resize-policy/UIResizePolicy.d.ts +0 -3
- package/dist/miscellaneous/resize-policy/UIResizePolicyCover.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyCross.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyCrossInverted.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyFit.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyFixedHeight.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyFixedWidth.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyNone.d.ts +0 -5
- package/dist/miscellaneous/shared.d.ts +0 -46
- package/dist/miscellaneous/text-span/UITextSpan.d.ts +0 -14
- package/dist/miscellaneous/text-style/UITextStyle.Internal.d.ts +0 -48
- package/dist/miscellaneous/text-style/UITextStyle.d.ts +0 -85
- package/dist/miscellaneous/texture/UITextureView.Internal.d.ts +0 -49
- package/dist/miscellaneous/texture/UITextureView.d.ts +0 -67
- package/dist/miscellaneous/webglCapabilities.d.ts +0 -2
- package/dist/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +0 -17
- package/dist/wrappers/UIInputWrapper/UIInputWrapper.d.ts +0 -13
- package/dist/wrappers/UISceneWrapper/UISceneWrapper.Internal.d.ts +0 -13
- package/dist/wrappers/UISceneWrapper/UISceneWrapper.d.ts +0 -20
- package/dist/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +0 -49
- package/dist/wrappers/UISolverWrapper/UISolverWrapper.d.ts +0 -215
|
@@ -0,0 +1,844 @@
|
|
|
1
|
+
import { Color, MathUtils, Vector4 } from "three";
|
|
2
|
+
import { assertValidNumber } from "../asserts";
|
|
3
|
+
import { linearToSRGB, srgbToLinear } from "../math";
|
|
4
|
+
import type { UIColorConfig, UIColorName } from "./UIColor.Internal";
|
|
5
|
+
import { COLORS } from "./UIColor.Internal";
|
|
6
|
+
|
|
7
|
+
/** RGBA color with RGB, HSL, hex, and named color support */
|
|
8
|
+
export class UIColor {
|
|
9
|
+
private rInternal = 1;
|
|
10
|
+
private gInternal = 1;
|
|
11
|
+
private bInternal = 1;
|
|
12
|
+
private aInternal = 1;
|
|
13
|
+
|
|
14
|
+
private hInternal = 0;
|
|
15
|
+
private sInternal = 0;
|
|
16
|
+
private lInternal = 1;
|
|
17
|
+
|
|
18
|
+
private dirtyInternal = false;
|
|
19
|
+
private rgbDirty = false;
|
|
20
|
+
private hslDirty = false;
|
|
21
|
+
|
|
22
|
+
constructor();
|
|
23
|
+
/**
|
|
24
|
+
* @param r - Red (0-1)
|
|
25
|
+
* @param g - Green (0-1)
|
|
26
|
+
* @param b - Blue (0-1)
|
|
27
|
+
* @param a - Alpha (0-1)
|
|
28
|
+
*/
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures -- Separate overloads make the different constructor patterns more clear
|
|
30
|
+
constructor(r: number, g: number, b: number, a?: number);
|
|
31
|
+
/**
|
|
32
|
+
* @param colorName - Named color
|
|
33
|
+
* @param a - Alpha (0-1)
|
|
34
|
+
*/
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures -- Separate overloads make the different constructor patterns more clear
|
|
36
|
+
constructor(colorName: UIColorName, a?: number);
|
|
37
|
+
/**
|
|
38
|
+
* @param threeColor - Three.js Color object
|
|
39
|
+
* @param a - Alpha (0-1)
|
|
40
|
+
*/
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures -- Separate overloads make the different constructor patterns more clear
|
|
42
|
+
constructor(threeColor: Color, a?: number);
|
|
43
|
+
/**
|
|
44
|
+
* @param hexRGB - Hex RGB value (e.g., 0xff0000)
|
|
45
|
+
* @param a - Alpha (0-1)
|
|
46
|
+
*/
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures -- Separate overloads make the different constructor patterns more clear
|
|
48
|
+
constructor(hexRGB: number, a?: number);
|
|
49
|
+
/**
|
|
50
|
+
* @param hexString - Hex string (e.g., "#ffffff" or "#ffffffff")
|
|
51
|
+
*/
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures -- Separate overloads make the different constructor patterns more clear
|
|
53
|
+
constructor(hexString?: string);
|
|
54
|
+
/**
|
|
55
|
+
* @param uiColor - UIColor object to copy from
|
|
56
|
+
*/
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures -- Separate overloads make the different constructor patterns more clear
|
|
58
|
+
constructor(uiColor?: UIColor);
|
|
59
|
+
/**
|
|
60
|
+
* @param uiColorConfig - UIColorConfig object
|
|
61
|
+
*/
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures -- Separate overloads make the different constructor patterns more clear
|
|
63
|
+
constructor(uiColorConfig?: UIColorConfig);
|
|
64
|
+
constructor(...args: unknown[]) {
|
|
65
|
+
if (args.length > 0) {
|
|
66
|
+
(this.set as (...a: unknown[]) => this)(...args);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Black (0x000000) */
|
|
71
|
+
public static get black(): UIColor {
|
|
72
|
+
return new UIColor("black");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** White (0xffffff) */
|
|
76
|
+
public static get white(): UIColor {
|
|
77
|
+
return new UIColor("white");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Red (0xff0000) */
|
|
81
|
+
public static get red(): UIColor {
|
|
82
|
+
return new UIColor("red");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Green (0x008000) */
|
|
86
|
+
public static get green(): UIColor {
|
|
87
|
+
return new UIColor("green");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Blue (0x0000ff) */
|
|
91
|
+
public static get blue(): UIColor {
|
|
92
|
+
return new UIColor("blue");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Yellow (0xffff00) */
|
|
96
|
+
public static get yellow(): UIColor {
|
|
97
|
+
return new UIColor("yellow");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Cyan (0x00ffff) */
|
|
101
|
+
public static get cyan(): UIColor {
|
|
102
|
+
return new UIColor("cyan");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Magenta (0xff00ff) */
|
|
106
|
+
public static get magenta(): UIColor {
|
|
107
|
+
return new UIColor("magenta");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Gray (0x808080) */
|
|
111
|
+
public static get gray(): UIColor {
|
|
112
|
+
return new UIColor("gray");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Grey (0x808080) */
|
|
116
|
+
public static get grey(): UIColor {
|
|
117
|
+
return new UIColor("grey");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Silver (0xc0c0c0) */
|
|
121
|
+
public static get silver(): UIColor {
|
|
122
|
+
return new UIColor("silver");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Maroon (0x800000) */
|
|
126
|
+
public static get maroon(): UIColor {
|
|
127
|
+
return new UIColor("maroon");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Olive (0x808000) */
|
|
131
|
+
public static get olive(): UIColor {
|
|
132
|
+
return new UIColor("olive");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Lime (0x00ff00) */
|
|
136
|
+
public static get lime(): UIColor {
|
|
137
|
+
return new UIColor("lime");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Aqua (0x00ffff) */
|
|
141
|
+
public static get aqua(): UIColor {
|
|
142
|
+
return new UIColor("aqua");
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Teal (0x008080) */
|
|
146
|
+
public static get teal(): UIColor {
|
|
147
|
+
return new UIColor("teal");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Navy (0x000080) */
|
|
151
|
+
public static get navy(): UIColor {
|
|
152
|
+
return new UIColor("navy");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Fuchsia (0xff00ff) */
|
|
156
|
+
public static get fuchsia(): UIColor {
|
|
157
|
+
return new UIColor("fuchsia");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Purple (0x800080) */
|
|
161
|
+
public static get purple(): UIColor {
|
|
162
|
+
return new UIColor("purple");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Orange (0xffa500) */
|
|
166
|
+
public static get orange(): UIColor {
|
|
167
|
+
return new UIColor("orange");
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Pink (0xffc0cb) */
|
|
171
|
+
public static get pink(): UIColor {
|
|
172
|
+
return new UIColor("pink");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Brown (0xa52a2a) */
|
|
176
|
+
public static get brown(): UIColor {
|
|
177
|
+
return new UIColor("brown");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Gold (0xffd700) */
|
|
181
|
+
public static get gold(): UIColor {
|
|
182
|
+
return new UIColor("gold");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Violet (0xee82ee) */
|
|
186
|
+
public static get violet(): UIColor {
|
|
187
|
+
return new UIColor("violet");
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Indigo (0x4b0082) */
|
|
191
|
+
public static get indigo(): UIColor {
|
|
192
|
+
return new UIColor("indigo");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Coral (0xff7f50) */
|
|
196
|
+
public static get coral(): UIColor {
|
|
197
|
+
return new UIColor("coral");
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Salmon (0xfa8072) */
|
|
201
|
+
public static get salmon(): UIColor {
|
|
202
|
+
return new UIColor("salmon");
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Khaki (0xf0e68c) */
|
|
206
|
+
public static get khaki(): UIColor {
|
|
207
|
+
return new UIColor("khaki");
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Plum (0xdda0dd) */
|
|
211
|
+
public static get plum(): UIColor {
|
|
212
|
+
return new UIColor("plum");
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Orchid (0xda70d6) */
|
|
216
|
+
public static get orchid(): UIColor {
|
|
217
|
+
return new UIColor("orchid");
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Tan (0xd2b48c) */
|
|
221
|
+
public static get tan(): UIColor {
|
|
222
|
+
return new UIColor("tan");
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** Beige (0xf5f5dc) */
|
|
226
|
+
public static get beige(): UIColor {
|
|
227
|
+
return new UIColor("beige");
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Mint (0x98fb98) */
|
|
231
|
+
public static get mint(): UIColor {
|
|
232
|
+
return new UIColor("mint");
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Lavender (0xe6e6fa) */
|
|
236
|
+
public static get lavender(): UIColor {
|
|
237
|
+
return new UIColor("lavender");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Crimson (0xdc143c) */
|
|
241
|
+
public static get crimson(): UIColor {
|
|
242
|
+
return new UIColor("crimson");
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** Azure (0xf0ffff) */
|
|
246
|
+
public static get azure(): UIColor {
|
|
247
|
+
return new UIColor("azure");
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Ivory (0xfffff0) */
|
|
251
|
+
public static get ivory(): UIColor {
|
|
252
|
+
return new UIColor("ivory");
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** Snow (0xfffafa) */
|
|
256
|
+
public static get snow(): UIColor {
|
|
257
|
+
return new UIColor("snow");
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Red component (0 to 1) */
|
|
261
|
+
public get r(): number {
|
|
262
|
+
this.ensureRGBUpdatedFromHSL();
|
|
263
|
+
return this.rInternal;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Green component (0 to 1) */
|
|
267
|
+
public get g(): number {
|
|
268
|
+
this.ensureRGBUpdatedFromHSL();
|
|
269
|
+
return this.gInternal;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** Blue component (0 to 1) */
|
|
273
|
+
public get b(): number {
|
|
274
|
+
this.ensureRGBUpdatedFromHSL();
|
|
275
|
+
return this.bInternal;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Alpha component (0 to 1) */
|
|
279
|
+
public get a(): number {
|
|
280
|
+
return this.aInternal;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** Hue component (0 to 360) */
|
|
284
|
+
public get hue(): number {
|
|
285
|
+
this.ensureHSLUpdatedFromRGB();
|
|
286
|
+
return this.hInternal;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** Saturation component (0 to 1) */
|
|
290
|
+
public get saturation(): number {
|
|
291
|
+
this.ensureHSLUpdatedFromRGB();
|
|
292
|
+
return this.sInternal;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** Lightness component (0 to 1) */
|
|
296
|
+
public get lightness(): number {
|
|
297
|
+
this.ensureHSLUpdatedFromRGB();
|
|
298
|
+
return this.lInternal;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** @internal */
|
|
302
|
+
public get dirty(): boolean {
|
|
303
|
+
return this.dirtyInternal;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** Red component (0 to 1) */
|
|
307
|
+
public set r(value: number) {
|
|
308
|
+
assertValidNumber(value, "UIColor.r");
|
|
309
|
+
value = MathUtils.clamp(value, 0, 1);
|
|
310
|
+
this.ensureRGBUpdatedFromHSL();
|
|
311
|
+
if (value !== this.rInternal) {
|
|
312
|
+
this.rInternal = value;
|
|
313
|
+
this.hslDirty = true;
|
|
314
|
+
this.dirtyInternal = true;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** Green component (0 to 1) */
|
|
319
|
+
public set g(value: number) {
|
|
320
|
+
assertValidNumber(value, "UIColor.g");
|
|
321
|
+
value = MathUtils.clamp(value, 0, 1);
|
|
322
|
+
this.ensureRGBUpdatedFromHSL();
|
|
323
|
+
if (value !== this.gInternal) {
|
|
324
|
+
this.gInternal = value;
|
|
325
|
+
this.hslDirty = true;
|
|
326
|
+
this.dirtyInternal = true;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** Blue component (0 to 1) */
|
|
331
|
+
public set b(value: number) {
|
|
332
|
+
assertValidNumber(value, "UIColor.b");
|
|
333
|
+
value = MathUtils.clamp(value, 0, 1);
|
|
334
|
+
this.ensureRGBUpdatedFromHSL();
|
|
335
|
+
if (value !== this.bInternal) {
|
|
336
|
+
this.bInternal = value;
|
|
337
|
+
this.hslDirty = true;
|
|
338
|
+
this.dirtyInternal = true;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** Alpha component (0 to 1) */
|
|
343
|
+
public set a(value: number) {
|
|
344
|
+
assertValidNumber(value, "UIColor.a");
|
|
345
|
+
value = MathUtils.clamp(value, 0, 1);
|
|
346
|
+
if (value !== this.aInternal) {
|
|
347
|
+
this.aInternal = value;
|
|
348
|
+
this.dirtyInternal = true;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** Hue component (0 to 360) */
|
|
353
|
+
public set hue(value: number) {
|
|
354
|
+
assertValidNumber(value, "UIColor.hue");
|
|
355
|
+
value = MathUtils.clamp(value, 0, 360);
|
|
356
|
+
this.ensureHSLUpdatedFromRGB();
|
|
357
|
+
if (value !== this.hInternal) {
|
|
358
|
+
this.hInternal = value;
|
|
359
|
+
this.rgbDirty = true;
|
|
360
|
+
this.dirtyInternal = true;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** Saturation component (0 to 1) */
|
|
365
|
+
public set saturation(value: number) {
|
|
366
|
+
assertValidNumber(value, "UIColor.saturation");
|
|
367
|
+
value = MathUtils.clamp(value, 0, 1);
|
|
368
|
+
this.ensureHSLUpdatedFromRGB();
|
|
369
|
+
if (value !== this.sInternal) {
|
|
370
|
+
this.sInternal = value;
|
|
371
|
+
this.rgbDirty = true;
|
|
372
|
+
this.dirtyInternal = true;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/** Lightness component (0 to 1) */
|
|
377
|
+
public set lightness(value: number) {
|
|
378
|
+
assertValidNumber(value, "UIColor.lightness");
|
|
379
|
+
value = MathUtils.clamp(value, 0, 1);
|
|
380
|
+
this.ensureHSLUpdatedFromRGB();
|
|
381
|
+
if (value !== this.lInternal) {
|
|
382
|
+
this.lInternal = value;
|
|
383
|
+
this.rgbDirty = true;
|
|
384
|
+
this.dirtyInternal = true;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/** @internal */
|
|
389
|
+
public setDirtyFalse(): void {
|
|
390
|
+
this.dirtyInternal = false;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** Sets to white (default) */
|
|
394
|
+
public set(): this;
|
|
395
|
+
/**
|
|
396
|
+
* @param r - Red (0-1)
|
|
397
|
+
* @param g - Green (0-1)
|
|
398
|
+
* @param b - Blue (0-1)
|
|
399
|
+
* @param a - Alpha (0-1)
|
|
400
|
+
*/
|
|
401
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures -- Separate overloads make the different constructor patterns more clear
|
|
402
|
+
public set(r: number, g: number, b: number, a?: number): this;
|
|
403
|
+
/**
|
|
404
|
+
* @param colorName - Named color
|
|
405
|
+
* @param a - Alpha (0-1)
|
|
406
|
+
*/
|
|
407
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures -- Separate overloads make the different constructor patterns more clear
|
|
408
|
+
public set(colorName: UIColorName, a?: number): this;
|
|
409
|
+
/**
|
|
410
|
+
* @param threeColor - Three.js Color object
|
|
411
|
+
* @param a - Alpha (0-1)
|
|
412
|
+
*/
|
|
413
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures -- Separate overloads make the different constructor patterns more clear
|
|
414
|
+
public set(threeColor: Color, a?: number): this;
|
|
415
|
+
/**
|
|
416
|
+
* @param hexRGB - Hex RGB value (e.g., 0xff0000)
|
|
417
|
+
* @param a - Alpha (0-1)
|
|
418
|
+
*/
|
|
419
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures -- Separate overloads make the different constructor patterns more clear
|
|
420
|
+
public set(hexRGB: number, a?: number): this;
|
|
421
|
+
/**
|
|
422
|
+
* @param hexString - Hex string (e.g., "#ffffff" or "#ffffffff")
|
|
423
|
+
*/
|
|
424
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures -- Separate overloads make the different constructor patterns more clear
|
|
425
|
+
public set(hexString: string): this;
|
|
426
|
+
/**
|
|
427
|
+
* @param uiColor - UIColor object to copy from
|
|
428
|
+
*/
|
|
429
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures -- Separate overloads make the different constructor patterns more clear
|
|
430
|
+
public set(uiColor: UIColor): this;
|
|
431
|
+
/**
|
|
432
|
+
* @param uiColorConfig - UIColorConfig object
|
|
433
|
+
*/
|
|
434
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures -- Separate overloads make the different constructor patterns more clear
|
|
435
|
+
public set(uiColorConfig?: UIColorConfig): this;
|
|
436
|
+
public set(...args: unknown[]): this {
|
|
437
|
+
if (args.length === 0 || args[0] === undefined) {
|
|
438
|
+
return this.setRGBA(1, 1, 1, 1);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (args.length >= 3 && typeof args[0] === "number") {
|
|
442
|
+
const [r, g, b, a = 1] = args as number[];
|
|
443
|
+
return this.setRGBA(r, g, b, a);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const [firstArgument, a = 1] = args;
|
|
447
|
+
|
|
448
|
+
if (typeof firstArgument === "string") {
|
|
449
|
+
return firstArgument.startsWith("#")
|
|
450
|
+
? this.setHexString(firstArgument)
|
|
451
|
+
: this.setColorName(firstArgument as UIColorName, a as number);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (firstArgument instanceof UIColor) {
|
|
455
|
+
return this.copy(firstArgument);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
if (firstArgument instanceof Color) {
|
|
459
|
+
return this.setThreeColor(firstArgument, a as number);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
if (typeof firstArgument === "number") {
|
|
463
|
+
return this.setHexRGB(firstArgument, a as number);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
throw new Error("UIColor.set: cannot create color from provided arguments");
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/** Sets RGBA components directly */
|
|
470
|
+
public setRGBA(r: number, g: number, b: number, a: number = this.aInternal): this {
|
|
471
|
+
assertValidNumber(r, "UIColor.setRGBA.r");
|
|
472
|
+
assertValidNumber(g, "UIColor.setRGBA.g");
|
|
473
|
+
assertValidNumber(b, "UIColor.setRGBA.b");
|
|
474
|
+
assertValidNumber(a, "UIColor.setRGBA.a");
|
|
475
|
+
r = MathUtils.clamp(r, 0, 1);
|
|
476
|
+
g = MathUtils.clamp(g, 0, 1);
|
|
477
|
+
b = MathUtils.clamp(b, 0, 1);
|
|
478
|
+
a = MathUtils.clamp(a, 0, 1);
|
|
479
|
+
this.ensureRGBUpdatedFromHSL();
|
|
480
|
+
if (
|
|
481
|
+
r !== this.rInternal ||
|
|
482
|
+
g !== this.gInternal ||
|
|
483
|
+
b !== this.bInternal ||
|
|
484
|
+
a !== this.aInternal
|
|
485
|
+
) {
|
|
486
|
+
this.rInternal = r;
|
|
487
|
+
this.gInternal = g;
|
|
488
|
+
this.bInternal = b;
|
|
489
|
+
this.aInternal = a;
|
|
490
|
+
this.hslDirty = true;
|
|
491
|
+
this.dirtyInternal = true;
|
|
492
|
+
}
|
|
493
|
+
return this;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/** Returns RGBA as 32-bit hex (RRGGBBAA) */
|
|
497
|
+
public getHexRGBA(): number {
|
|
498
|
+
this.ensureRGBUpdatedFromHSL();
|
|
499
|
+
return (
|
|
500
|
+
(Math.round(this.rInternal * 255) << 24) |
|
|
501
|
+
(Math.round(this.gInternal * 255) << 16) |
|
|
502
|
+
(Math.round(this.bInternal * 255) << 8) |
|
|
503
|
+
Math.round(this.aInternal * 255)
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/** Returns RGB as 24-bit hex (RRGGBB) */
|
|
508
|
+
public getHexRGB(): number {
|
|
509
|
+
this.ensureRGBUpdatedFromHSL();
|
|
510
|
+
return (
|
|
511
|
+
(Math.round(this.rInternal * 255) << 16) |
|
|
512
|
+
(Math.round(this.gInternal * 255) << 8) |
|
|
513
|
+
Math.round(this.bInternal * 255)
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/** Returns RGB as hex string ("#ffffff") */
|
|
518
|
+
public getHexStringRGB(): string {
|
|
519
|
+
const hex = this.getHexRGB();
|
|
520
|
+
return `#${hex.toString(16).padStart(6, "0")}`;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/** Returns RGBA as hex string ("#ffffffff") */
|
|
524
|
+
public getHexStringRGBA(): string {
|
|
525
|
+
const hex = this.getHexRGBA();
|
|
526
|
+
return `#${hex.toString(16).padStart(8, "0")}`;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** Sets from 32-bit hex RGBA (RRGGBBAA) */
|
|
530
|
+
public setHexRGBA(hex: number): this {
|
|
531
|
+
assertValidNumber(hex, "UIColor.setHexRGBA.hex");
|
|
532
|
+
this.ensureRGBUpdatedFromHSL();
|
|
533
|
+
const r = ((hex >> 16) & 0xff) / 255;
|
|
534
|
+
const g = ((hex >> 8) & 0xff) / 255;
|
|
535
|
+
const b = (hex & 0xff) / 255;
|
|
536
|
+
const a = ((hex >> 24) & 0xff) / 255;
|
|
537
|
+
if (
|
|
538
|
+
r !== this.rInternal ||
|
|
539
|
+
g !== this.gInternal ||
|
|
540
|
+
b !== this.bInternal ||
|
|
541
|
+
a !== this.aInternal
|
|
542
|
+
) {
|
|
543
|
+
this.rInternal = r;
|
|
544
|
+
this.gInternal = g;
|
|
545
|
+
this.bInternal = b;
|
|
546
|
+
this.aInternal = a;
|
|
547
|
+
this.hslDirty = true;
|
|
548
|
+
this.dirtyInternal = true;
|
|
549
|
+
}
|
|
550
|
+
return this;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/** Sets from 24-bit hex RGB (RRGGBB) */
|
|
554
|
+
public setHexRGB(hex: number, a = this.aInternal): this {
|
|
555
|
+
assertValidNumber(hex, "UIColor.setHexRGB.hex");
|
|
556
|
+
assertValidNumber(a, "UIColor.setHexRGB.a");
|
|
557
|
+
a = MathUtils.clamp(a, 0, 1);
|
|
558
|
+
this.ensureRGBUpdatedFromHSL();
|
|
559
|
+
const r = ((hex >> 16) & 0xff) / 255;
|
|
560
|
+
const g = ((hex >> 8) & 0xff) / 255;
|
|
561
|
+
const b = (hex & 0xff) / 255;
|
|
562
|
+
if (
|
|
563
|
+
r !== this.rInternal ||
|
|
564
|
+
g !== this.gInternal ||
|
|
565
|
+
b !== this.bInternal ||
|
|
566
|
+
a !== this.aInternal
|
|
567
|
+
) {
|
|
568
|
+
this.rInternal = r;
|
|
569
|
+
this.gInternal = g;
|
|
570
|
+
this.bInternal = b;
|
|
571
|
+
this.aInternal = a;
|
|
572
|
+
this.hslDirty = true;
|
|
573
|
+
this.dirtyInternal = true;
|
|
574
|
+
}
|
|
575
|
+
return this;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Sets from hex string.
|
|
580
|
+
*
|
|
581
|
+
* @param hexString - Format: "#ffffff" or "#ffffffff"
|
|
582
|
+
* @throws If format invalid
|
|
583
|
+
*/
|
|
584
|
+
public setHexString(hexString: string): this {
|
|
585
|
+
if (!hexString.startsWith("#")) {
|
|
586
|
+
throw new Error(
|
|
587
|
+
`UIColor.setHexString.hexString: invalid hex string format. expected format: "#ffffff" or "#ffffffff"`,
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
const hex = hexString.slice(1);
|
|
592
|
+
|
|
593
|
+
if (hex.length === 6) {
|
|
594
|
+
const hexNumber = parseInt(hex, 16);
|
|
595
|
+
if (isNaN(hexNumber)) {
|
|
596
|
+
throw new Error(
|
|
597
|
+
`UIColor.setHexString.hexString: invalid hex string format. expected format: "#ffffff" or "#ffffffff"`,
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
return this.setHexRGB(hexNumber);
|
|
601
|
+
} else if (hex.length === 8) {
|
|
602
|
+
const hexNumber = parseInt(hex, 16);
|
|
603
|
+
if (isNaN(hexNumber)) {
|
|
604
|
+
throw new Error(
|
|
605
|
+
`UIColor.setHexString.hexString: invalid hex string format. expected format: "#ffffff" or "#ffffffff"`,
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
return this.setHexRGBA(hexNumber);
|
|
609
|
+
} else {
|
|
610
|
+
throw new Error(
|
|
611
|
+
`UIColor.setHexString.hexString: invalid hex string format. expected format: "#ffffff" or "#ffffffff"`,
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/** Sets from HSL values */
|
|
617
|
+
public setHSL(h: number, s: number, l: number, a = this.aInternal): this {
|
|
618
|
+
assertValidNumber(h, "UIColor.setHSL.h");
|
|
619
|
+
assertValidNumber(s, "UIColor.setHSL.s");
|
|
620
|
+
assertValidNumber(l, "UIColor.setHSL.l");
|
|
621
|
+
assertValidNumber(a, "UIColor.setHSL.a");
|
|
622
|
+
h = MathUtils.clamp(h, 0, 360);
|
|
623
|
+
s = MathUtils.clamp(s, 0, 1);
|
|
624
|
+
l = MathUtils.clamp(l, 0, 1);
|
|
625
|
+
a = MathUtils.clamp(a, 0, 1);
|
|
626
|
+
this.ensureHSLUpdatedFromRGB();
|
|
627
|
+
if (
|
|
628
|
+
h !== this.hInternal ||
|
|
629
|
+
s !== this.sInternal ||
|
|
630
|
+
l !== this.lInternal ||
|
|
631
|
+
a !== this.aInternal
|
|
632
|
+
) {
|
|
633
|
+
this.hInternal = h;
|
|
634
|
+
this.sInternal = s;
|
|
635
|
+
this.lInternal = l;
|
|
636
|
+
this.aInternal = a;
|
|
637
|
+
this.rgbDirty = true;
|
|
638
|
+
this.dirtyInternal = true;
|
|
639
|
+
}
|
|
640
|
+
return this;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Sets from predefined name.
|
|
645
|
+
*
|
|
646
|
+
* @throws If color name unknown
|
|
647
|
+
*/
|
|
648
|
+
public setColorName(colorName: UIColorName, a = this.aInternal): this {
|
|
649
|
+
assertValidNumber(a, "UIColor.setColorName.a");
|
|
650
|
+
a = MathUtils.clamp(a, 0, 1);
|
|
651
|
+
const normalizedName = colorName.toLowerCase().trim();
|
|
652
|
+
const hex = COLORS[normalizedName];
|
|
653
|
+
|
|
654
|
+
if (hex === undefined) {
|
|
655
|
+
throw new Error(`UIColor.setColorName.colorName: unknown color name`);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
return this.setHexRGB(hex, a);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
/** Sets from linear (GLSL) color space */
|
|
662
|
+
public setGLSLColor(r: number, g: number, b: number, a = this.aInternal): this {
|
|
663
|
+
assertValidNumber(r, "UIColor.setGLSLColor.r");
|
|
664
|
+
assertValidNumber(g, "UIColor.setGLSLColor.g");
|
|
665
|
+
assertValidNumber(b, "UIColor.setGLSLColor.b");
|
|
666
|
+
assertValidNumber(a, "UIColor.setGLSLColor.a");
|
|
667
|
+
a = MathUtils.clamp(a, 0, 1);
|
|
668
|
+
this.ensureRGBUpdatedFromHSL();
|
|
669
|
+
|
|
670
|
+
const sRGBR = linearToSRGB(r);
|
|
671
|
+
const sRGBG = linearToSRGB(g);
|
|
672
|
+
const sRGBB = linearToSRGB(b);
|
|
673
|
+
|
|
674
|
+
if (
|
|
675
|
+
sRGBR !== this.rInternal ||
|
|
676
|
+
sRGBG !== this.gInternal ||
|
|
677
|
+
sRGBB !== this.bInternal ||
|
|
678
|
+
a !== this.aInternal
|
|
679
|
+
) {
|
|
680
|
+
this.rInternal = sRGBR;
|
|
681
|
+
this.gInternal = sRGBG;
|
|
682
|
+
this.bInternal = sRGBB;
|
|
683
|
+
this.aInternal = a;
|
|
684
|
+
this.hslDirty = true;
|
|
685
|
+
this.dirtyInternal = true;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
return this;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/** Sets from Three.js Color */
|
|
692
|
+
public setThreeColor(threeColor: Color, a = this.aInternal): this {
|
|
693
|
+
assertValidNumber(a, "UIColor.setThreeColor.a");
|
|
694
|
+
a = MathUtils.clamp(a, 0, 1);
|
|
695
|
+
this.ensureRGBUpdatedFromHSL();
|
|
696
|
+
if (
|
|
697
|
+
threeColor.r !== this.rInternal ||
|
|
698
|
+
threeColor.g !== this.gInternal ||
|
|
699
|
+
threeColor.b !== this.bInternal ||
|
|
700
|
+
a !== this.aInternal
|
|
701
|
+
) {
|
|
702
|
+
this.rInternal = threeColor.r;
|
|
703
|
+
this.gInternal = threeColor.g;
|
|
704
|
+
this.bInternal = threeColor.b;
|
|
705
|
+
this.aInternal = a;
|
|
706
|
+
this.hslDirty = true;
|
|
707
|
+
this.dirtyInternal = true;
|
|
708
|
+
}
|
|
709
|
+
return this;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/** Returns CSS color string ("rgba(255, 0, 0, 1)") */
|
|
713
|
+
public toCSSColor(): string {
|
|
714
|
+
this.ensureRGBUpdatedFromHSL();
|
|
715
|
+
const r = Math.round(this.rInternal * 255);
|
|
716
|
+
const g = Math.round(this.gInternal * 255);
|
|
717
|
+
const b = Math.round(this.bInternal * 255);
|
|
718
|
+
return `rgba(${r}, ${g}, ${b}, ${this.aInternal})`;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/** Converts to linear (GLSL) color space */
|
|
722
|
+
public toGLSLColor(result: Vector4 = new Vector4()): Vector4 {
|
|
723
|
+
this.ensureRGBUpdatedFromHSL();
|
|
724
|
+
|
|
725
|
+
result.x = srgbToLinear(this.rInternal);
|
|
726
|
+
result.y = srgbToLinear(this.gInternal);
|
|
727
|
+
result.z = srgbToLinear(this.bInternal);
|
|
728
|
+
result.w = this.aInternal;
|
|
729
|
+
|
|
730
|
+
return result;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/** Converts to Three.js Color (without alpha) */
|
|
734
|
+
public toThreeColor(result: Color = new Color()): Color {
|
|
735
|
+
this.ensureRGBUpdatedFromHSL();
|
|
736
|
+
|
|
737
|
+
result.r = this.rInternal;
|
|
738
|
+
result.g = this.gInternal;
|
|
739
|
+
result.b = this.bInternal;
|
|
740
|
+
|
|
741
|
+
return result;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/** Copies from another color */
|
|
745
|
+
public copy(color: UIColor | Color): this {
|
|
746
|
+
if (color instanceof UIColor) {
|
|
747
|
+
this.ensureRGBUpdatedFromHSL();
|
|
748
|
+
color.ensureRGBUpdatedFromHSL();
|
|
749
|
+
|
|
750
|
+
if (
|
|
751
|
+
this.rInternal !== color.rInternal ||
|
|
752
|
+
this.gInternal !== color.gInternal ||
|
|
753
|
+
this.bInternal !== color.bInternal ||
|
|
754
|
+
this.aInternal !== color.aInternal
|
|
755
|
+
) {
|
|
756
|
+
this.rInternal = color.rInternal;
|
|
757
|
+
this.gInternal = color.gInternal;
|
|
758
|
+
this.bInternal = color.bInternal;
|
|
759
|
+
this.aInternal = color.aInternal;
|
|
760
|
+
this.hslDirty = true;
|
|
761
|
+
this.dirtyInternal = true;
|
|
762
|
+
}
|
|
763
|
+
} else {
|
|
764
|
+
this.ensureRGBUpdatedFromHSL();
|
|
765
|
+
if (
|
|
766
|
+
this.rInternal !== color.r ||
|
|
767
|
+
this.gInternal !== color.g ||
|
|
768
|
+
this.bInternal !== color.b ||
|
|
769
|
+
this.aInternal !== 1
|
|
770
|
+
) {
|
|
771
|
+
this.rInternal = color.r;
|
|
772
|
+
this.gInternal = color.g;
|
|
773
|
+
this.bInternal = color.b;
|
|
774
|
+
this.aInternal = 1;
|
|
775
|
+
this.hslDirty = true;
|
|
776
|
+
this.dirtyInternal = true;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
return this;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/** Returns copy of this color */
|
|
784
|
+
public clone(): UIColor {
|
|
785
|
+
this.ensureRGBUpdatedFromHSL();
|
|
786
|
+
return new UIColor(this.rInternal, this.gInternal, this.bInternal, this.aInternal);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
/** @internal */
|
|
790
|
+
private ensureRGBUpdatedFromHSL(): void {
|
|
791
|
+
if (this.rgbDirty) {
|
|
792
|
+
const { hInternal: h, sInternal: s, lInternal: l } = this;
|
|
793
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
794
|
+
const hp = h / 60;
|
|
795
|
+
const x = c * (1 - Math.abs((hp % 2) - 1));
|
|
796
|
+
let [r, g, b] =
|
|
797
|
+
hp < 1
|
|
798
|
+
? [c, x, 0]
|
|
799
|
+
: hp < 2
|
|
800
|
+
? [x, c, 0]
|
|
801
|
+
: hp < 3
|
|
802
|
+
? [0, c, x]
|
|
803
|
+
: hp < 4
|
|
804
|
+
? [0, x, c]
|
|
805
|
+
: hp < 5
|
|
806
|
+
? [x, 0, c]
|
|
807
|
+
: [c, 0, x];
|
|
808
|
+
|
|
809
|
+
const m = l - c / 2;
|
|
810
|
+
this.rInternal = r + m;
|
|
811
|
+
this.gInternal = g + m;
|
|
812
|
+
this.bInternal = b + m;
|
|
813
|
+
this.rgbDirty = false;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
private ensureHSLUpdatedFromRGB(): void {
|
|
818
|
+
if (this.hslDirty) {
|
|
819
|
+
const { rInternal: r, gInternal: g, bInternal: b } = this;
|
|
820
|
+
const max = Math.max(r, g, b);
|
|
821
|
+
const min = Math.min(r, g, b);
|
|
822
|
+
const d = max - min;
|
|
823
|
+
const l = (max + min) / 2;
|
|
824
|
+
|
|
825
|
+
let h = 0;
|
|
826
|
+
if (d !== 0) {
|
|
827
|
+
if (max === r) {
|
|
828
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
829
|
+
} else if (max === g) {
|
|
830
|
+
h = (b - r) / d + 2;
|
|
831
|
+
} else {
|
|
832
|
+
h = (r - g) / d + 4;
|
|
833
|
+
}
|
|
834
|
+
h *= 60;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
const s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1));
|
|
838
|
+
this.hInternal = h;
|
|
839
|
+
this.sInternal = s;
|
|
840
|
+
this.lInternal = l;
|
|
841
|
+
this.hslDirty = false;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|