@lightningjs/renderer 3.0.0-beta22 → 3.0.0-beta23
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/README.md +93 -0
- package/dist/exports/platform.d.ts +7 -0
- package/dist/exports/platform.js +27 -0
- package/dist/exports/platform.js.map +1 -0
- package/dist/src/core/AutosizeManager.d.ts +29 -0
- package/dist/src/core/AutosizeManager.js +169 -0
- package/dist/src/core/AutosizeManager.js.map +1 -0
- package/dist/src/core/CoreNode.js +10 -14
- package/dist/src/core/CoreNode.js.map +1 -1
- package/dist/src/core/CoreTextureManager.d.ts +0 -13
- package/dist/src/core/CoreTextureManager.js +4 -78
- package/dist/src/core/CoreTextureManager.js.map +1 -1
- package/dist/src/core/Stage.js +2 -12
- package/dist/src/core/Stage.js.map +1 -1
- package/dist/src/core/animations/Animation.d.ts +21 -0
- package/dist/src/core/animations/Animation.js +194 -0
- package/dist/src/core/animations/Animation.js.map +1 -0
- package/dist/src/core/animations/CoreAnimationController.d.ts +1 -1
- package/dist/src/core/animations/CoreAnimationController.js +4 -2
- package/dist/src/core/animations/CoreAnimationController.js.map +1 -1
- package/dist/src/core/animations/Playback.d.ts +64 -0
- package/dist/src/core/animations/Playback.js +169 -0
- package/dist/src/core/animations/Playback.js.map +1 -0
- package/dist/src/core/animations/Transition.d.ts +27 -0
- package/dist/src/core/animations/Transition.js +52 -0
- package/dist/src/core/animations/Transition.js.map +1 -0
- package/dist/src/core/animations/utils.d.ts +2 -0
- package/dist/src/core/animations/utils.js +136 -0
- package/dist/src/core/animations/utils.js.map +1 -0
- package/dist/src/core/lib/collectionUtils.js +3 -2
- package/dist/src/core/lib/collectionUtils.js.map +1 -1
- package/dist/src/core/lib/utils.d.ts +0 -5
- package/dist/src/core/lib/utils.js +0 -63
- package/dist/src/core/lib/utils.js.map +1 -1
- package/dist/src/core/platforms/GlContextWrapper.d.ts +136 -0
- package/dist/src/core/platforms/GlContextWrapper.js +32 -0
- package/dist/src/core/platforms/GlContextWrapper.js.map +1 -0
- package/dist/src/core/platforms/Platform.d.ts +74 -13
- package/dist/src/core/platforms/Platform.js +18 -0
- package/dist/src/core/platforms/Platform.js.map +1 -1
- package/dist/src/core/platforms/web/WebGlContextWrapper.d.ts +776 -0
- package/dist/src/core/platforms/web/WebGlContextWrapper.js +1208 -0
- package/dist/src/core/platforms/web/WebGlContextWrapper.js.map +1 -0
- package/dist/src/core/platforms/web/WebPlatform.d.ts +13 -2
- package/dist/src/core/platforms/web/WebPlatform.js +109 -8
- package/dist/src/core/platforms/web/WebPlatform.js.map +1 -1
- package/dist/src/core/platforms/web/WebPlatformChrome50.d.ts +17 -0
- package/dist/src/core/platforms/web/WebPlatformChrome50.js +50 -0
- package/dist/src/core/platforms/web/WebPlatformChrome50.js.map +1 -0
- package/dist/src/core/platforms/web/WebPlatformLegacy.d.ts +18 -0
- package/dist/src/core/platforms/web/WebPlatformLegacy.js +99 -0
- package/dist/src/core/platforms/web/WebPlatformLegacy.js.map +1 -0
- package/dist/src/core/platforms/web/WebPlatformNext.d.ts +21 -0
- package/dist/src/core/platforms/web/WebPlatformNext.js +52 -0
- package/dist/src/core/platforms/web/WebPlatformNext.js.map +1 -0
- package/dist/src/core/platforms/web/lib/ImageWorker.d.ts +15 -0
- package/dist/src/core/platforms/web/lib/ImageWorker.js +189 -0
- package/dist/src/core/platforms/web/lib/ImageWorker.js.map +1 -0
- package/dist/src/core/platforms/web/lib/createImageBitmap.d.ts +1 -0
- package/dist/src/core/platforms/web/lib/createImageBitmap.js +27 -0
- package/dist/src/core/platforms/web/lib/createImageBitmap.js.map +1 -0
- package/dist/src/core/platforms/web/lib/textureCompression.d.ts +26 -0
- package/dist/src/core/platforms/web/lib/textureCompression.js +301 -0
- package/dist/src/core/platforms/web/lib/textureCompression.js.map +1 -0
- package/dist/src/core/platforms/web/lib/textureSvg.d.ts +7 -0
- package/dist/src/core/platforms/web/lib/textureSvg.js +51 -0
- package/dist/src/core/platforms/web/lib/textureSvg.js.map +1 -0
- package/dist/src/core/platforms/web/lib/utils.d.ts +5 -0
- package/dist/src/core/platforms/web/lib/utils.js +86 -0
- package/dist/src/core/platforms/web/lib/utils.js.map +1 -0
- package/dist/src/core/renderers/CoreRenderer.d.ts +1 -9
- package/dist/src/core/renderers/CoreRenderer.js +2 -4
- package/dist/src/core/renderers/CoreRenderer.js.map +1 -1
- package/dist/src/core/renderers/canvas/CanvasRenderer.d.ts +3 -2
- package/dist/src/core/renderers/canvas/CanvasRenderer.js +4 -3
- package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +1 -1
- package/dist/src/core/renderers/webgl/SdfRenderOp.js +3 -2
- package/dist/src/core/renderers/webgl/SdfRenderOp.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.d.ts +2 -2
- package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.d.ts +2 -2
- package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlCtxTexture.d.ts +3 -3
- package/dist/src/core/renderers/webgl/WebGlCtxTexture.js +1 -2
- package/dist/src/core/renderers/webgl/WebGlCtxTexture.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlRenderer.d.ts +5 -5
- package/dist/src/core/renderers/webgl/WebGlRenderer.js +7 -8
- package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlShaderNode.d.ts +2 -2
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.d.ts +2 -2
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +1 -1
- package/dist/src/core/renderers/webgl/internal/RendererUtils.d.ts +4 -4
- package/dist/src/core/renderers/webgl/internal/RendererUtils.js.map +1 -1
- package/dist/src/core/renderers/webgl/internal/ShaderUtils.d.ts +3 -3
- package/dist/src/core/renderers/webgl/internal/ShaderUtils.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js +24 -8
- package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js +25 -8
- package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js.map +1 -1
- package/dist/src/core/shaders/webgl/Border.js +6 -4
- package/dist/src/core/shaders/webgl/Border.js.map +1 -1
- package/dist/src/core/shaders/webgl/RoundedWithBorder.js +6 -4
- package/dist/src/core/shaders/webgl/RoundedWithBorder.js.map +1 -1
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +6 -4
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js.map +1 -1
- package/dist/src/core/shaders/webgl/SdfShadowShader.d.ts +9 -0
- package/dist/src/core/shaders/webgl/SdfShadowShader.js +100 -0
- package/dist/src/core/shaders/webgl/SdfShadowShader.js.map +1 -0
- package/dist/src/core/text-rendering/CanvasFont.d.ts +1 -1
- package/dist/src/core/text-rendering/CanvasFont.js +2 -6
- package/dist/src/core/text-rendering/CanvasFont.js.map +1 -1
- package/dist/src/core/text-rendering/CoreFont.d.ts +1 -1
- package/dist/src/core/text-rendering/CoreFont.js +1 -1
- package/dist/src/core/text-rendering/CoreFont.js.map +1 -1
- package/dist/src/core/text-rendering/FontManager.js +2 -1
- package/dist/src/core/text-rendering/FontManager.js.map +1 -1
- package/dist/src/core/textures/ImageTexture.d.ts +24 -11
- package/dist/src/core/textures/ImageTexture.js +32 -95
- package/dist/src/core/textures/ImageTexture.js.map +1 -1
- package/dist/src/core/textures/Texture.d.ts +1 -1
- package/dist/src/main-api/Renderer.js +18 -21
- package/dist/src/main-api/Renderer.js.map +1 -1
- package/dist/src/utils.d.ts +0 -2
- package/dist/src/utils.js +0 -36
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/exports/platform.ts +31 -0
- package/package.json +3 -2
- package/src/core/CoreNode.ts +11 -15
- package/src/core/CoreTextureManager.ts +10 -103
- package/src/core/Stage.ts +1 -14
- package/src/core/animations/CoreAnimationController.ts +5 -2
- package/src/core/lib/collectionUtils.ts +3 -2
- package/src/core/lib/utils.ts +0 -78
- package/src/core/platforms/GlContextWrapper.ts +291 -0
- package/src/core/platforms/Platform.ts +121 -28
- package/src/core/{lib → platforms/web}/WebGlContextWrapper.ts +129 -4
- package/src/core/platforms/web/WebPlatform.ts +171 -22
- package/src/core/platforms/web/WebPlatformChrome50.ts +57 -0
- package/src/core/platforms/web/WebPlatformLegacy.ts +140 -0
- package/src/core/platforms/web/WebPlatformNext.ts +57 -0
- package/src/core/{lib → platforms/web/lib}/ImageWorker.ts +10 -74
- package/src/core/platforms/web/lib/createImageBitmap.ts +40 -0
- package/src/core/{lib → platforms/web/lib}/textureCompression.ts +19 -138
- package/src/core/{lib → platforms/web/lib}/textureSvg.ts +3 -15
- package/src/core/platforms/web/lib/utils.ts +105 -0
- package/src/core/renderers/CoreRenderer.ts +2 -11
- package/src/core/renderers/canvas/CanvasRenderer.ts +6 -4
- package/src/core/renderers/webgl/SdfRenderOp.ts +3 -2
- package/src/core/renderers/webgl/WebGlCtxRenderTexture.ts +2 -2
- package/src/core/renderers/webgl/WebGlCtxSubTexture.ts +2 -2
- package/src/core/renderers/webgl/WebGlCtxTexture.ts +3 -4
- package/src/core/renderers/webgl/WebGlRenderer.ts +12 -19
- package/src/core/renderers/webgl/WebGlShaderNode.ts +2 -2
- package/src/core/renderers/webgl/WebGlShaderProgram.ts +2 -2
- package/src/core/renderers/webgl/internal/RendererUtils.ts +4 -8
- package/src/core/renderers/webgl/internal/ShaderUtils.ts +3 -3
- package/src/core/shaders/webgl/Border.ts +6 -4
- package/src/core/shaders/webgl/RoundedWithBorder.ts +6 -4
- package/src/core/shaders/webgl/RoundedWithBorderAndShadow.ts +6 -4
- package/src/core/textures/ImageTexture.ts +42 -161
- package/src/core/textures/Texture.ts +1 -1
- package/src/main-api/Renderer.ts +24 -22
- package/src/utils.ts +0 -47
- package/src/core/lib/validateImageBitmap.ts +0 -87
package/README.md
CHANGED
|
@@ -45,6 +45,99 @@ Any JavaScript language features or browser APIs that cannot be automatically tr
|
|
|
45
45
|
|
|
46
46
|
For a more detailed and comprehensive list of browsers and their features please see [browsers](./BROWSERS.md).
|
|
47
47
|
|
|
48
|
+
## Platform Architecture
|
|
49
|
+
|
|
50
|
+
The Lightning 3 Renderer uses a modular platform architecture that allows it to adapt to different browser capabilities and environments. This enables optimal performance across a wide range of devices, from modern browsers to legacy embedded systems.
|
|
51
|
+
|
|
52
|
+
### Available Platforms
|
|
53
|
+
|
|
54
|
+
The Renderer includes several platform implementations, each tailored for specific browser capabilities:
|
|
55
|
+
|
|
56
|
+
#### WebPlatform (Default)
|
|
57
|
+
|
|
58
|
+
The standard platform for modern browsers with full WebGL and createImageBitmap support.
|
|
59
|
+
|
|
60
|
+
- Uses XMLHttpRequest for loading resources
|
|
61
|
+
- Full createImageBitmap API with options (premultiplyAlpha, colorSpaceConversion, imageOrientation)
|
|
62
|
+
- Supports image cropping
|
|
63
|
+
- Multi-threaded image processing via Web Workers
|
|
64
|
+
- **Use case:** Modern browsers, default choice for most applications
|
|
65
|
+
|
|
66
|
+
#### WebPlatformNext
|
|
67
|
+
|
|
68
|
+
Platform using the modern Fetch API instead of XMLHttpRequest.
|
|
69
|
+
|
|
70
|
+
- Uses Fetch API for loading resources (promise-based, Service Worker compatible)
|
|
71
|
+
- Full createImageBitmap API with options
|
|
72
|
+
- Supports image cropping
|
|
73
|
+
- Multi-threaded image processing via Web Workers
|
|
74
|
+
- **Use case:** Modern browsers where Fetch API is preferred, progressive web apps
|
|
75
|
+
|
|
76
|
+
#### WebPlatformChrome50
|
|
77
|
+
|
|
78
|
+
Compatibility platform for browsers with limited createImageBitmap support (Chrome 50-51).
|
|
79
|
+
|
|
80
|
+
- Uses XMLHttpRequest for loading resources
|
|
81
|
+
- Limited createImageBitmap API (no options or cropping parameters)
|
|
82
|
+
- Multi-threaded image processing via Web Workers (if enabled)
|
|
83
|
+
- **Use case:** Chrome 50-51, browsers with basic createImageBitmap support
|
|
84
|
+
|
|
85
|
+
#### WebPlatformLegacy
|
|
86
|
+
|
|
87
|
+
Legacy platform for older browsers without createImageBitmap support.
|
|
88
|
+
|
|
89
|
+
- Uses direct Image element loading (no blob conversion for URLs)
|
|
90
|
+
- HTMLImageElement instead of createImageBitmap
|
|
91
|
+
- Single-threaded image processing (no Web Workers)
|
|
92
|
+
- No image cropping support
|
|
93
|
+
- No compressed texture support
|
|
94
|
+
- **Use case:** Chrome 38-49, older embedded device browsers
|
|
95
|
+
|
|
96
|
+
### Using a Platform
|
|
97
|
+
|
|
98
|
+
Platforms can be specified when initializing the Renderer:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { RendererMain } from '@lightningjs/renderer';
|
|
102
|
+
import { WebGlRenderer } from '@lightningjs/renderer/webgl';
|
|
103
|
+
import {
|
|
104
|
+
WebPlatform,
|
|
105
|
+
WebPlatformNext,
|
|
106
|
+
WebPlatformChrome50,
|
|
107
|
+
WebPlatformLegacy,
|
|
108
|
+
} from '@lightningjs/renderer/platforms';
|
|
109
|
+
|
|
110
|
+
const renderer = new RendererMain(
|
|
111
|
+
{
|
|
112
|
+
appWidth: 1920,
|
|
113
|
+
appHeight: 1080,
|
|
114
|
+
renderEngine: WebGlRenderer,
|
|
115
|
+
platform: WebPlatformLegacy, // Use legacy platform for older browsers
|
|
116
|
+
// ...Other Renderer Config
|
|
117
|
+
},
|
|
118
|
+
'app',
|
|
119
|
+
);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Note:** `WebPlatformLegacy` automatically sets `numImageWorkers` to 0 since it doesn't support Web Workers.
|
|
123
|
+
|
|
124
|
+
### Creating Custom Platforms
|
|
125
|
+
|
|
126
|
+
You can create your own custom platform tailored to your specific device or environment by extending the `Platform` base class or one of the existing platform implementations.
|
|
127
|
+
|
|
128
|
+
**Key methods you can override:**
|
|
129
|
+
|
|
130
|
+
- `fetch(url: string): Promise<Blob>` - Resource loading
|
|
131
|
+
- `createImage(...)` - Image bitmap creation
|
|
132
|
+
- `loadImage(...)` - Complete image loading pipeline
|
|
133
|
+
- `loadSvg(...)` - SVG loading
|
|
134
|
+
- `loadCompressedTexture(...)` - Compressed texture loading
|
|
135
|
+
- `createCanvas()` - Canvas element creation
|
|
136
|
+
- `createContext()` - WebGL context creation
|
|
137
|
+
- `startLoop(stage)` - Animation loop implementation
|
|
138
|
+
|
|
139
|
+
This allows you to optimize the Renderer for proprietary platforms, embedded systems, or environments with unique capabilities and constraints.
|
|
140
|
+
|
|
48
141
|
## Example Tests
|
|
49
142
|
|
|
50
143
|
The Example Tests sub-project define a set of tests for various Renderer
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Platform, type PlatformSettings, } from '../src/core/platforms/Platform.js';
|
|
2
|
+
export { WebPlatform } from '../src/core/platforms/web/WebPlatform.js';
|
|
3
|
+
export { WebPlatformNext } from '../src/core/platforms/web/WebPlatformNext.js';
|
|
4
|
+
export { WebPlatformChrome50 } from '../src/core/platforms/web/WebPlatformChrome50.js';
|
|
5
|
+
export { WebPlatformLegacy } from '../src/core/platforms/web/WebPlatformLegacy.js';
|
|
6
|
+
export { GlContextWrapper } from '../src/core/platforms/GlContextWrapper.js';
|
|
7
|
+
export { WebGlContextWrapper } from '../src/core/platforms/web/WebGlContextWrapper.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* If not stated otherwise in this file or this component's LICENSE file the
|
|
3
|
+
* following copyright and licenses apply:
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2026 Comcast Cable Communications Management, LLC.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the License);
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
export { Platform, } from '../src/core/platforms/Platform.js';
|
|
20
|
+
export { WebPlatform } from '../src/core/platforms/web/WebPlatform.js';
|
|
21
|
+
export { WebPlatformNext } from '../src/core/platforms/web/WebPlatformNext.js';
|
|
22
|
+
export { WebPlatformChrome50 } from '../src/core/platforms/web/WebPlatformChrome50.js';
|
|
23
|
+
export { WebPlatformLegacy } from '../src/core/platforms/web/WebPlatformLegacy.js';
|
|
24
|
+
// GL Context Wrappers
|
|
25
|
+
export { GlContextWrapper } from '../src/core/platforms/GlContextWrapper.js';
|
|
26
|
+
export { WebGlContextWrapper } from '../src/core/platforms/web/WebGlContextWrapper.js';
|
|
27
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../../exports/platform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,QAAQ,GAET,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kDAAkD,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AAEnF,sBAAsB;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kDAAkD,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CoreNode } from './CoreNode.js';
|
|
2
|
+
/**
|
|
3
|
+
* Result of autosize calculation containing the new dimensions
|
|
4
|
+
*/
|
|
5
|
+
interface AutosizeResult {
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
hasChanged: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates an autosize manager for efficient child bounds calculation
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* This function creates a closure-based manager that tracks child transform
|
|
15
|
+
* changes and calculates parent dimensions based on children's bounding boxes.
|
|
16
|
+
* It's optimized for performance with minimal allocations and fast lookups.
|
|
17
|
+
*
|
|
18
|
+
* @param parentNode - The autosize parent node
|
|
19
|
+
* @returns Object with autosize management methods
|
|
20
|
+
*/
|
|
21
|
+
export declare function createAutosizeManager(parentNode: CoreNode): {
|
|
22
|
+
addOrUpdateChild: (child: CoreNode) => void;
|
|
23
|
+
removeChild: (child: CoreNode) => void;
|
|
24
|
+
calculateAutosize: () => AutosizeResult;
|
|
25
|
+
deactivate: () => void;
|
|
26
|
+
readonly active: boolean;
|
|
27
|
+
readonly childCount: number;
|
|
28
|
+
};
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* If not stated otherwise in this file or this component's LICENSE file the
|
|
3
|
+
* following copyright and licenses apply:
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2023 Comcast Cable Communications Management, LLC.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the License);
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { Matrix3d } from './lib/Matrix3d.js';
|
|
20
|
+
/**
|
|
21
|
+
* Creates an autosize manager for efficient child bounds calculation
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* This function creates a closure-based manager that tracks child transform
|
|
25
|
+
* changes and calculates parent dimensions based on children's bounding boxes.
|
|
26
|
+
* It's optimized for performance with minimal allocations and fast lookups.
|
|
27
|
+
*
|
|
28
|
+
* @param parentNode - The autosize parent node
|
|
29
|
+
* @returns Object with autosize management methods
|
|
30
|
+
*/
|
|
31
|
+
export function createAutosizeManager(parentNode) {
|
|
32
|
+
const childDataMap = new Map();
|
|
33
|
+
let isActive = true;
|
|
34
|
+
let lastWidth = 0;
|
|
35
|
+
let lastHeight = 0;
|
|
36
|
+
let lastHasChanged = false;
|
|
37
|
+
const corners = [
|
|
38
|
+
{ x: 0, y: 0 },
|
|
39
|
+
{ x: 0, y: 0 },
|
|
40
|
+
{ x: 0, y: 0 },
|
|
41
|
+
{ x: 0, y: 0 },
|
|
42
|
+
];
|
|
43
|
+
/**
|
|
44
|
+
* Add or update a child node in the autosize calculation chain
|
|
45
|
+
* @param child - Child node to add or update
|
|
46
|
+
*/
|
|
47
|
+
const addOrUpdateChild = (child) => {
|
|
48
|
+
if (isActive === false)
|
|
49
|
+
return;
|
|
50
|
+
if (child === parentNode)
|
|
51
|
+
return; // Avoid circular references
|
|
52
|
+
const currentTransform = child.localTransform || Matrix3d.identity();
|
|
53
|
+
const existingData = childDataMap.get(child);
|
|
54
|
+
if (existingData !== undefined) {
|
|
55
|
+
// Update existing child
|
|
56
|
+
Matrix3d.copy(currentTransform, existingData.localTransform);
|
|
57
|
+
existingData.width = child.w;
|
|
58
|
+
existingData.height = child.h;
|
|
59
|
+
existingData.hasChanged = true;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// Add new child
|
|
63
|
+
childDataMap.set(child, {
|
|
64
|
+
localTransform: Matrix3d.copy(currentTransform),
|
|
65
|
+
hasChanged: true,
|
|
66
|
+
width: child.w,
|
|
67
|
+
height: child.h,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
// Mark parent for recalculation
|
|
71
|
+
parentNode.autosizeNeedsUpdate = true;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Remove a child node from the autosize calculation chain
|
|
75
|
+
* @param child - Child node to remove
|
|
76
|
+
*/
|
|
77
|
+
const removeChild = (child) => {
|
|
78
|
+
if (childDataMap.delete(child) === true) {
|
|
79
|
+
parentNode.autosizeNeedsUpdate = true;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Calculate the autosize dimensions based on all child bounds
|
|
84
|
+
* @returns Autosize calculation result
|
|
85
|
+
*/
|
|
86
|
+
const calculateAutosize = () => {
|
|
87
|
+
if (isActive === false || childDataMap.size === 0) {
|
|
88
|
+
return { width: 0, height: 0, hasChanged: false };
|
|
89
|
+
}
|
|
90
|
+
let hasAnyChildChanged = false;
|
|
91
|
+
for (const childData of childDataMap.values()) {
|
|
92
|
+
if (childData.hasChanged) {
|
|
93
|
+
hasAnyChildChanged = true;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (hasAnyChildChanged === false) {
|
|
98
|
+
return {
|
|
99
|
+
width: lastWidth,
|
|
100
|
+
height: lastHeight,
|
|
101
|
+
hasChanged: lastHasChanged,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
let minX = Infinity;
|
|
105
|
+
let minY = Infinity;
|
|
106
|
+
let maxX = -Infinity;
|
|
107
|
+
let maxY = -Infinity;
|
|
108
|
+
for (const [child, childData] of childDataMap) {
|
|
109
|
+
if (!child.isRenderable)
|
|
110
|
+
continue;
|
|
111
|
+
const transform = child.localTransform || Matrix3d.identity();
|
|
112
|
+
const width = childData.width;
|
|
113
|
+
const height = childData.height;
|
|
114
|
+
corners[0].x = 0;
|
|
115
|
+
corners[0].y = 0;
|
|
116
|
+
corners[1].x = width;
|
|
117
|
+
corners[1].y = 0;
|
|
118
|
+
corners[2].x = width;
|
|
119
|
+
corners[2].y = height;
|
|
120
|
+
corners[3].x = 0;
|
|
121
|
+
corners[3].y = height;
|
|
122
|
+
for (let i = 0; i < 4; i++) {
|
|
123
|
+
const corner = corners[i];
|
|
124
|
+
const localX = transform.ta * corner.x + transform.tb * corner.y + transform.tx;
|
|
125
|
+
const localY = transform.tc * corner.x + transform.td * corner.y + transform.ty;
|
|
126
|
+
if (localX < minX)
|
|
127
|
+
minX = localX;
|
|
128
|
+
if (localY < minY)
|
|
129
|
+
minY = localY;
|
|
130
|
+
if (localX > maxX)
|
|
131
|
+
maxX = localX;
|
|
132
|
+
if (localY > maxY)
|
|
133
|
+
maxY = localY;
|
|
134
|
+
}
|
|
135
|
+
childData.hasChanged = false;
|
|
136
|
+
}
|
|
137
|
+
const newWidth = maxX > minX ? maxX - minX : 0;
|
|
138
|
+
const newHeight = maxY > minY ? maxY - minY : 0;
|
|
139
|
+
const dimensionsChanged = lastWidth !== newWidth || lastHeight !== newHeight;
|
|
140
|
+
lastWidth = newWidth;
|
|
141
|
+
lastHeight = newHeight;
|
|
142
|
+
lastHasChanged = dimensionsChanged;
|
|
143
|
+
return {
|
|
144
|
+
width: newWidth,
|
|
145
|
+
height: newHeight,
|
|
146
|
+
hasChanged: dimensionsChanged,
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Deactivate this autosize manager and clean up resources
|
|
151
|
+
*/
|
|
152
|
+
const deactivate = () => {
|
|
153
|
+
isActive = false;
|
|
154
|
+
childDataMap.clear();
|
|
155
|
+
};
|
|
156
|
+
return {
|
|
157
|
+
addOrUpdateChild,
|
|
158
|
+
removeChild,
|
|
159
|
+
calculateAutosize,
|
|
160
|
+
deactivate,
|
|
161
|
+
get active() {
|
|
162
|
+
return isActive;
|
|
163
|
+
},
|
|
164
|
+
get childCount() {
|
|
165
|
+
return childDataMap.size;
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=AutosizeManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutosizeManager.js","sourceRoot":"","sources":["../../../src/core/AutosizeManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAqB7C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CAAC,UAAoB;IACxD,MAAM,YAAY,GAAG,IAAI,GAAG,EAA+B,CAAC;IAC5D,IAAI,QAAQ,GAAG,IAAI,CAAC;IACpB,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,cAAc,GAAG,KAAK,CAAC;IAE3B,MAAM,OAAO,GAAG;QACd,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;QACd,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;QACd,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;QACd,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;KACf,CAAC;IAEF;;;OAGG;IACH,MAAM,gBAAgB,GAAG,CAAC,KAAe,EAAQ,EAAE;QACjD,IAAI,QAAQ,KAAK,KAAK;YAAE,OAAO;QAC/B,IAAI,KAAK,KAAK,UAAU;YAAE,OAAO,CAAC,4BAA4B;QAE9D,MAAM,gBAAgB,GAAG,KAAK,CAAC,cAAc,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACrE,MAAM,YAAY,GAAG,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAE7C,IAAI,YAAY,KAAK,S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GAAG,KAAK,CAAC;QACjB,YAAY,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC,CAAC;IAEF,OAAO;QACL,gBAAgB;QAChB,WAAW;QACX,iBAAiB;QACjB,UAAU;QACV,IAAI,MAAM;YACR,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,IAAI,UAAU;YACZ,OAAO,YAAY,CAAC,IAAI,CAAC;QAC3B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -330,15 +330,6 @@ export class CoreNode extends EventEmitter {
|
|
|
330
330
|
texture.on('loaded', this.onTextureLoaded);
|
|
331
331
|
texture.on('failed', this.onTextureFailed);
|
|
332
332
|
texture.on('freed', this.onTextureFreed);
|
|
333
|
-
// If the parent is a render texture, the initial texture status
|
|
334
|
-
// will be set to freed until the texture is processed by the
|
|
335
|
-
// Render RTT nodes. So we only need to listen fo changes and
|
|
336
|
-
// no need to check the texture.state until we restructure how
|
|
337
|
-
// textures are being processed.
|
|
338
|
-
if (this.parentHasRenderTexture) {
|
|
339
|
-
this.notifyParentRTTOfUpdate();
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
333
|
if (texture.state === 'loaded') {
|
|
343
334
|
this.onTextureLoaded(texture, texture.dimensions);
|
|
344
335
|
}
|
|
@@ -1072,8 +1063,6 @@ export class CoreNode extends EventEmitter {
|
|
|
1072
1063
|
addChild(node, previousParent = null) {
|
|
1073
1064
|
const inRttCluster = this.props.rtt === true || this.parentHasRenderTexture === true;
|
|
1074
1065
|
const children = this.children;
|
|
1075
|
-
const min = this.zIndexMin;
|
|
1076
|
-
const max = this.zIndexMax;
|
|
1077
1066
|
const zIndex = node.zIndex;
|
|
1078
1067
|
const autosizeTarget = this.autosizer || this.parentAutosizer;
|
|
1079
1068
|
let attachToAutosizer = autosizeTarget !== null;
|
|
@@ -1102,7 +1091,13 @@ export class CoreNode extends EventEmitter {
|
|
|
1102
1091
|
node.markChildrenWithRTT(this);
|
|
1103
1092
|
}
|
|
1104
1093
|
children.push(node);
|
|
1105
|
-
if (
|
|
1094
|
+
if (zIndex < this.zIndexMin) {
|
|
1095
|
+
this.zIndexMin = zIndex;
|
|
1096
|
+
}
|
|
1097
|
+
if (zIndex > this.zIndexMax) {
|
|
1098
|
+
this.zIndexMax = zIndex;
|
|
1099
|
+
}
|
|
1100
|
+
if (this.zIndexMax !== this.zIndexMin) {
|
|
1106
1101
|
this.zIndexSortList.push(node);
|
|
1107
1102
|
this.setUpdateType(UpdateType.SortZIndexChildren);
|
|
1108
1103
|
}
|
|
@@ -1746,7 +1741,8 @@ export class CoreNode extends EventEmitter {
|
|
|
1746
1741
|
return length;
|
|
1747
1742
|
}
|
|
1748
1743
|
draw(renderer) {
|
|
1749
|
-
const { glw,
|
|
1744
|
+
const { glw, stage } = renderer;
|
|
1745
|
+
const canvas = stage.platform.canvas;
|
|
1750
1746
|
const shader = this.props.shader;
|
|
1751
1747
|
stage.shManager.useShader(shader.program);
|
|
1752
1748
|
shader.program.bindRenderOp(this);
|
|
@@ -1756,7 +1752,7 @@ export class CoreNode extends EventEmitter {
|
|
|
1756
1752
|
const clipX = Math.round(this.clippingRect.x * pixelRatio);
|
|
1757
1753
|
const clipWidth = Math.round(this.clippingRect.w * pixelRatio);
|
|
1758
1754
|
const clipHeight = Math.round(this.clippingRect.h * pixelRatio);
|
|
1759
|
-
let clipY = Math.round(
|
|
1755
|
+
let clipY = Math.round(canvas.height - clipHeight - this.clippingRect.y * pixelRatio);
|
|
1760
1756
|
// if parent has render texture, we need to adjust the scissor rect
|
|
1761
1757
|
// to be relative to the parent's framebuffer
|
|
1762
1758
|
if (this.parentHasRenderTexture) {
|