@lightningjs/renderer 3.0.0-beta21 → 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/index.d.ts +1 -0
- package/dist/exports/index.js +1 -0
- package/dist/exports/index.js.map +1 -1
- 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/common/CommonTypes.d.ts +2 -1
- 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/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/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/WebGlRenderOp.d.ts +3 -2
- package/dist/src/core/renderers/webgl/WebGlRenderOp.js +3 -1
- package/dist/src/core/renderers/webgl/WebGlRenderOp.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/shaders/webgl/Border.js +13 -17
- package/dist/src/core/shaders/webgl/Border.js.map +1 -1
- package/dist/src/core/shaders/webgl/RoundedWithBorder.js +12 -21
- package/dist/src/core/shaders/webgl/RoundedWithBorder.js.map +1 -1
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +10 -12
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js.map +1 -1
- package/dist/src/core/text-rendering/CanvasFont.d.ts +14 -0
- package/dist/src/core/text-rendering/CanvasFont.js +111 -0
- package/dist/src/core/text-rendering/CanvasFont.js.map +1 -0
- package/dist/src/core/text-rendering/CoreFont.d.ts +33 -0
- package/dist/src/core/text-rendering/CoreFont.js +48 -0
- package/dist/src/core/text-rendering/CoreFont.js.map +1 -0
- package/dist/src/core/text-rendering/FontManager.d.ts +11 -0
- package/dist/src/core/text-rendering/FontManager.js +42 -0
- package/dist/src/core/text-rendering/FontManager.js.map +1 -0
- package/dist/src/core/text-rendering/SdfFont.d.ts +29 -0
- package/dist/src/core/text-rendering/SdfFont.js +142 -0
- package/dist/src/core/text-rendering/SdfFont.js.map +1 -0
- 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 +5 -4
- package/dist/src/core/textures/Texture.js.map +1 -1
- package/dist/src/core/utils.d.ts +1 -1
- package/dist/src/main-api/Inspector.d.ts +4 -0
- package/dist/src/main-api/Inspector.js +160 -0
- package/dist/src/main-api/Inspector.js.map +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/exports/index.ts +5 -0
- package/exports/platform.ts +31 -0
- package/package.json +3 -2
- package/src/common/CommonTypes.ts +2 -1
- 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 +13 -17
- package/src/core/shaders/webgl/RoundedWithBorder.ts +12 -21
- package/src/core/shaders/webgl/RoundedWithBorderAndShadow.ts +10 -12
- package/src/core/textures/ImageTexture.ts +42 -161
- package/src/core/textures/Texture.ts +11 -7
- package/src/main-api/Inspector.ts +215 -0
- package/src/main-api/Renderer.ts +24 -22
- package/src/utils.ts +0 -47
- package/src/core/lib/validateImageBitmap.ts +0 -87
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Stage } from '../Stage.js';
|
|
2
|
+
import type { ImageTexture } from '../textures/ImageTexture.js';
|
|
3
|
+
import { CoreFont, type CoreFontProps } from './CoreFont.js';
|
|
4
|
+
import { type SdfFontData } from './SdfFontHandler.js';
|
|
5
|
+
import type { NormalizedFontMetrics, TextRenderer } from './TextRenderer.js';
|
|
6
|
+
export type SdfFontProps = CoreFontProps & {
|
|
7
|
+
atlasUrl: string;
|
|
8
|
+
atlasDataUrl: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class SdfFont extends CoreFont {
|
|
11
|
+
private stage;
|
|
12
|
+
type: string;
|
|
13
|
+
atlasUrl: string;
|
|
14
|
+
atlasDataUrl: string;
|
|
15
|
+
atlasTexture?: ImageTexture;
|
|
16
|
+
private glyphMap?;
|
|
17
|
+
private kerningTable?;
|
|
18
|
+
private data?;
|
|
19
|
+
constructor(textRenderer: TextRenderer, props: SdfFontProps, stage: Stage);
|
|
20
|
+
load(): void;
|
|
21
|
+
private hardFail;
|
|
22
|
+
private processFontData;
|
|
23
|
+
measureText(text: string, letterSpacing: number): number;
|
|
24
|
+
getMetrics(fontSize: number): NormalizedFontMetrics;
|
|
25
|
+
getGlyph(codepoint: number): import("./SdfFontHandler.js").SdfGlyph | null;
|
|
26
|
+
getKerning(firstGlyph: number, secondGlyph: number): number;
|
|
27
|
+
getAtlas(): ImageTexture;
|
|
28
|
+
getData(): SdfFontData;
|
|
29
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
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 2025 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 { CoreFont, FontState } from './CoreFont.js';
|
|
20
|
+
import { buildGlyphMap, buildKerningTable, } from './SdfFontHandler.js';
|
|
21
|
+
import { normalizeFontMetrics } from './TextLayoutEngine.js';
|
|
22
|
+
import { hasZeroWidthSpace } from './Utils.js';
|
|
23
|
+
export class SdfFont extends CoreFont {
|
|
24
|
+
stage;
|
|
25
|
+
type = 'sdf';
|
|
26
|
+
atlasUrl;
|
|
27
|
+
atlasDataUrl;
|
|
28
|
+
atlasTexture;
|
|
29
|
+
glyphMap;
|
|
30
|
+
kerningTable;
|
|
31
|
+
data;
|
|
32
|
+
constructor(textRenderer, props, stage) {
|
|
33
|
+
super(textRenderer, props);
|
|
34
|
+
this.stage = stage;
|
|
35
|
+
this.atlasUrl = props.atlasUrl;
|
|
36
|
+
this.atlasDataUrl = props.atlasDataUrl;
|
|
37
|
+
}
|
|
38
|
+
load() {
|
|
39
|
+
new Promise(async () => {
|
|
40
|
+
const atlasData = await fetch(this.atlasDataUrl);
|
|
41
|
+
if (atlasData.ok === false) {
|
|
42
|
+
this.hardFail(`Failed to load font data: ${atlasData.statusText}`);
|
|
43
|
+
}
|
|
44
|
+
const fontData = (await atlasData.json());
|
|
45
|
+
if (fontData.chars === undefined) {
|
|
46
|
+
this.hardFail('Invalid SDF font data format');
|
|
47
|
+
}
|
|
48
|
+
const atlasTexture = this.stage.txManager.createTexture('ImageTexture', {
|
|
49
|
+
src: this.atlasUrl,
|
|
50
|
+
premultiplyAlpha: false,
|
|
51
|
+
});
|
|
52
|
+
atlasTexture.setRenderableOwner(this.family, true);
|
|
53
|
+
atlasTexture.preventCleanup = true;
|
|
54
|
+
atlasTexture.on('loaded', () => {
|
|
55
|
+
this.onLoaded();
|
|
56
|
+
});
|
|
57
|
+
atlasTexture.on('failed', (error) => {
|
|
58
|
+
console.error(`Failed to load SDF font: ${this.family}`, error);
|
|
59
|
+
this.emit('failed');
|
|
60
|
+
});
|
|
61
|
+
this.atlasTexture = atlasTexture;
|
|
62
|
+
this.processFontData(fontData);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
hardFail(message) {
|
|
66
|
+
this.state = FontState.Failed;
|
|
67
|
+
throw new Error(message);
|
|
68
|
+
}
|
|
69
|
+
processFontData(fontData) {
|
|
70
|
+
this.glyphMap = buildGlyphMap(fontData.chars);
|
|
71
|
+
this.kerningTable = buildKerningTable(fontData.kernings);
|
|
72
|
+
this.metrics = this.metrics ||
|
|
73
|
+
fontData.lightningMetrics || {
|
|
74
|
+
ascender: 800,
|
|
75
|
+
descender: -200,
|
|
76
|
+
lineGap: 200,
|
|
77
|
+
unitsPerEm: 1000,
|
|
78
|
+
};
|
|
79
|
+
this.data = fontData;
|
|
80
|
+
}
|
|
81
|
+
measureText(text, letterSpacing) {
|
|
82
|
+
if (text.length === 1) {
|
|
83
|
+
const char = text.charAt(0);
|
|
84
|
+
const codepoint = text.codePointAt(0);
|
|
85
|
+
if (codepoint === undefined)
|
|
86
|
+
return 0;
|
|
87
|
+
if (hasZeroWidthSpace(char) === true)
|
|
88
|
+
return 0;
|
|
89
|
+
const glyph = this.getGlyph(codepoint);
|
|
90
|
+
if (glyph === null)
|
|
91
|
+
return 0;
|
|
92
|
+
return glyph.xadvance + letterSpacing;
|
|
93
|
+
}
|
|
94
|
+
let width = 0;
|
|
95
|
+
let prevCodepoint = 0;
|
|
96
|
+
for (let i = 0; i < text.length; i++) {
|
|
97
|
+
const char = text.charAt(i);
|
|
98
|
+
const codepoint = text.codePointAt(i);
|
|
99
|
+
if (codepoint === undefined)
|
|
100
|
+
continue;
|
|
101
|
+
// Skip zero-width spaces in width calculations
|
|
102
|
+
if (hasZeroWidthSpace(char)) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const glyph = this.getGlyph(codepoint);
|
|
106
|
+
if (glyph === null)
|
|
107
|
+
continue;
|
|
108
|
+
let advance = glyph.xadvance;
|
|
109
|
+
// Add kerning if there's a previous character
|
|
110
|
+
if (prevCodepoint !== 0) {
|
|
111
|
+
const kerning = this.getKerning(prevCodepoint, codepoint);
|
|
112
|
+
advance += kerning;
|
|
113
|
+
}
|
|
114
|
+
width += advance + letterSpacing;
|
|
115
|
+
prevCodepoint = codepoint;
|
|
116
|
+
}
|
|
117
|
+
return width;
|
|
118
|
+
}
|
|
119
|
+
getMetrics(fontSize) {
|
|
120
|
+
let m = this.normalizedMetrics[fontSize];
|
|
121
|
+
if (m !== undefined) {
|
|
122
|
+
return m;
|
|
123
|
+
}
|
|
124
|
+
m = this.normalizedMetrics[fontSize] = normalizeFontMetrics(this.metrics, fontSize);
|
|
125
|
+
return m;
|
|
126
|
+
}
|
|
127
|
+
getGlyph(codepoint) {
|
|
128
|
+
const gm = this.glyphMap;
|
|
129
|
+
return gm[codepoint] || gm[63] || null;
|
|
130
|
+
}
|
|
131
|
+
getKerning(firstGlyph, secondGlyph) {
|
|
132
|
+
const seconds = this.kerningTable[secondGlyph];
|
|
133
|
+
return (seconds !== undefined && seconds[firstGlyph]) || 0;
|
|
134
|
+
}
|
|
135
|
+
getAtlas() {
|
|
136
|
+
return this.atlasTexture;
|
|
137
|
+
}
|
|
138
|
+
getData() {
|
|
139
|
+
return this.data;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=SdfFont.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SdfFont.js","sourceRoot":"","sources":["../../../../src/core/text-rendering/SdfFont.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAsB,MAAM,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AC;gBAC1D,OAAO,IAAI,OAAO,CAAC;YACrB,CAAC;YAED,KAAK,IAAI,OAAO,GAAG,aAAa,CAAC;YACjC,aAAa,GAAG,SAAS,CAAC;QAC5B,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,UAAU,CAAC,QAAgB;QACzB,IAAI,CAAC,GAAG,IAAI,CAAC,iBAAkB,CAAC,QAAQ,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;YACpB,OAAO,CAAC,CAAC;QACX,CAAC;QACD,CAAC,GAAG,IAAI,CAAC,iBAAkB,CAAC,QAAQ,CAAC,GAAG,oBAAoB,CAC1D,IAAI,CAAC,OAAQ,EACb,QAAQ,CACT,CAAC;QACF,OAAO,CAAC,CAAC;IACX,CAAC;IAED,QAAQ,CAAC,SAAiB;QACxB,MAAM,EAAE,GAAG,IAAI,CAAC,QAAuB,CAAC;QACxC,OAAO,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC;IACzC,CAAC;IAED,UAAU,CAAC,UAAkB,EAAE,WAAmB;QAChD,MAAM,OAAO,GAAG,IAAI,CAAC,YAAa,CAAC,WAAW,CAAC,CAAC;QAChD,OAAO,CAAC,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC;IAC7D,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,YAAa,CAAC;IAC5B,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAK,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CoreTextureManager } from '../CoreTextureManager.js';
|
|
2
2
|
import { Texture, TextureType, type TextureData } from './Texture.js';
|
|
3
|
+
import type { CompressedImageData } from '../platforms/web/lib/textureCompression.js';
|
|
3
4
|
/**
|
|
4
5
|
* Properties of the {@link ImageTexture}
|
|
5
6
|
*/
|
|
@@ -83,6 +84,10 @@ export interface ImageTextureProps {
|
|
|
83
84
|
*/
|
|
84
85
|
maxRetryCount?: number;
|
|
85
86
|
}
|
|
87
|
+
export interface ImageResponse {
|
|
88
|
+
data: ImageBitmap | ImageData | CompressedImageData | HTMLImageElement | null;
|
|
89
|
+
premultiplyAlpha: boolean | null;
|
|
90
|
+
}
|
|
86
91
|
/**
|
|
87
92
|
* Texture consisting of an image loaded from a URL
|
|
88
93
|
*
|
|
@@ -102,18 +107,8 @@ export declare class ImageTexture extends Texture {
|
|
|
102
107
|
props: Required<ImageTextureProps>;
|
|
103
108
|
type: TextureType;
|
|
104
109
|
constructor(txManager: CoreTextureManager, props: Required<ImageTextureProps>);
|
|
105
|
-
hasAlphaChannel(mimeType: string): boolean;
|
|
106
|
-
loadImageFallback(src: string | Blob, hasAlpha: boolean): Promise<{
|
|
107
|
-
data: HTMLImageElement | null;
|
|
108
|
-
premultiplyAlpha: boolean;
|
|
109
|
-
}>;
|
|
110
|
-
createImageBitmap(blob: Blob, premultiplyAlpha: boolean | null, sx: number | null, sy: number | null, sw: number | null, sh: number | null): Promise<{
|
|
111
|
-
data: ImageBitmap | HTMLImageElement;
|
|
112
|
-
premultiplyAlpha: boolean;
|
|
113
|
-
}>;
|
|
114
|
-
loadImage(src: string): Promise<TextureData>;
|
|
115
110
|
getTextureSource(): Promise<TextureData>;
|
|
116
|
-
determineImageTypeAndLoadImage(): Promise<
|
|
111
|
+
determineImageTypeAndLoadImage(): Promise<ImageResponse> | {
|
|
117
112
|
data: null;
|
|
118
113
|
premultiplyAlpha?: undefined;
|
|
119
114
|
} | {
|
|
@@ -129,3 +124,21 @@ export declare class ImageTexture extends Texture {
|
|
|
129
124
|
static resolveDefaults(props: ImageTextureProps): Required<ImageTextureProps>;
|
|
130
125
|
static z$__type__Props: ImageTextureProps;
|
|
131
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Tests if the given location is a SVG
|
|
129
|
+
* @param url
|
|
130
|
+
* @remarks
|
|
131
|
+
* This function is used to determine if the given image url is a SVG
|
|
132
|
+
* image
|
|
133
|
+
* @returns
|
|
134
|
+
*/
|
|
135
|
+
export declare function isSvgImage(url: string): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Tests if the given location is a compressed texture container
|
|
138
|
+
* @param url
|
|
139
|
+
* @remarks
|
|
140
|
+
* This function is used to determine if the given image url is a compressed
|
|
141
|
+
* and only supports the following extensions: .ktx and .pvr
|
|
142
|
+
* @returns
|
|
143
|
+
*/
|
|
144
|
+
export declare function isCompressedTextureContainer(src: string): boolean;
|
|
@@ -17,11 +17,6 @@
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { Texture, TextureType } from './Texture.js';
|
|
20
|
-
import { isCompressedTextureContainer, loadCompressedTexture, } from '../lib/textureCompression.js';
|
|
21
|
-
import { convertUrlToAbsolute, dataURIToBlob, isBase64Image, } from '../lib/utils.js';
|
|
22
|
-
import { isSvgImage, loadSvg } from '../lib/textureSvg.js';
|
|
23
|
-
import { fetchJson } from '../lib/utils.js';
|
|
24
|
-
import { isProductionEnvironment } from '../../utils.js';
|
|
25
20
|
/**
|
|
26
21
|
* Texture consisting of an image loaded from a URL
|
|
27
22
|
*
|
|
@@ -46,81 +41,6 @@ export class ImageTexture extends Texture {
|
|
|
46
41
|
this.props = props;
|
|
47
42
|
this.maxRetryCount = props.maxRetryCount;
|
|
48
43
|
}
|
|
49
|
-
hasAlphaChannel(mimeType) {
|
|
50
|
-
return mimeType.indexOf('image/png') !== -1;
|
|
51
|
-
}
|
|
52
|
-
async loadImageFallback(src, hasAlpha) {
|
|
53
|
-
const img = new Image();
|
|
54
|
-
if (typeof src === 'string' && isBase64Image(src) === false) {
|
|
55
|
-
img.crossOrigin = 'anonymous';
|
|
56
|
-
}
|
|
57
|
-
return new Promise((resolve, reject) => {
|
|
58
|
-
img.onload = () => {
|
|
59
|
-
resolve({ data: img, premultiplyAlpha: hasAlpha });
|
|
60
|
-
};
|
|
61
|
-
img.onerror = (err) => {
|
|
62
|
-
const errorMessage = err instanceof Error
|
|
63
|
-
? err.message
|
|
64
|
-
: err instanceof Event
|
|
65
|
-
? `Image loading failed for ${img.src}`
|
|
66
|
-
: 'Unknown image loading error';
|
|
67
|
-
reject(new Error(`Image loading failed: ${errorMessage}`));
|
|
68
|
-
};
|
|
69
|
-
if (src instanceof Blob) {
|
|
70
|
-
img.src = URL.createObjectURL(src);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
img.src = src;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
async createImageBitmap(blob, premultiplyAlpha, sx, sy, sw, sh) {
|
|
78
|
-
const hasAlphaChannel = premultiplyAlpha ?? blob.type.includes('image/png');
|
|
79
|
-
const imageBitmapSupported = this.txManager.imageBitmapSupported;
|
|
80
|
-
if (imageBitmapSupported.full === true && sw !== null && sh !== null) {
|
|
81
|
-
// createImageBitmap with crop
|
|
82
|
-
const bitmap = await this.platform.createImageBitmap(blob, sx || 0, sy || 0, sw, sh, {
|
|
83
|
-
premultiplyAlpha: hasAlphaChannel ? 'premultiply' : 'none',
|
|
84
|
-
colorSpaceConversion: 'none',
|
|
85
|
-
imageOrientation: 'none',
|
|
86
|
-
});
|
|
87
|
-
return { data: bitmap, premultiplyAlpha: hasAlphaChannel };
|
|
88
|
-
}
|
|
89
|
-
else if (imageBitmapSupported.basic === true) {
|
|
90
|
-
// basic createImageBitmap without options or crop
|
|
91
|
-
// this is supported for Chrome v50 to v52/54 that doesn't support options
|
|
92
|
-
return {
|
|
93
|
-
data: await this.platform.createImageBitmap(blob),
|
|
94
|
-
premultiplyAlpha: hasAlphaChannel,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
// default createImageBitmap without crop but with options
|
|
98
|
-
const bitmap = await this.platform.createImageBitmap(blob, {
|
|
99
|
-
premultiplyAlpha: hasAlphaChannel ? 'premultiply' : 'none',
|
|
100
|
-
colorSpaceConversion: 'none',
|
|
101
|
-
imageOrientation: 'none',
|
|
102
|
-
});
|
|
103
|
-
return { data: bitmap, premultiplyAlpha: hasAlphaChannel };
|
|
104
|
-
}
|
|
105
|
-
async loadImage(src) {
|
|
106
|
-
const { premultiplyAlpha, sx, sy, sw, sh } = this.props;
|
|
107
|
-
if (this.txManager.hasCreateImageBitmap === true) {
|
|
108
|
-
if (isBase64Image(src) === false &&
|
|
109
|
-
this.txManager.hasWorker === true &&
|
|
110
|
-
this.txManager.imageWorkerManager !== null) {
|
|
111
|
-
return this.txManager.imageWorkerManager.getImage(src, premultiplyAlpha, sx, sy, sw, sh);
|
|
112
|
-
}
|
|
113
|
-
let blob;
|
|
114
|
-
if (isBase64Image(src) === true) {
|
|
115
|
-
blob = dataURIToBlob(src);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
blob = await fetchJson(src, 'blob').then((response) => response);
|
|
119
|
-
}
|
|
120
|
-
return this.createImageBitmap(blob, premultiplyAlpha, sx, sy, sw, sh);
|
|
121
|
-
}
|
|
122
|
-
return this.loadImageFallback(src, premultiplyAlpha ?? true);
|
|
123
|
-
}
|
|
124
44
|
async getTextureSource() {
|
|
125
45
|
let resp;
|
|
126
46
|
try {
|
|
@@ -144,7 +64,9 @@ export class ImageTexture extends Texture {
|
|
|
144
64
|
};
|
|
145
65
|
}
|
|
146
66
|
determineImageTypeAndLoadImage() {
|
|
147
|
-
const { src, premultiplyAlpha, type } = this.props;
|
|
67
|
+
const { src, premultiplyAlpha, type, w, h, sx, sy, sw, sh } = this.props;
|
|
68
|
+
const platform = this.platform;
|
|
69
|
+
const premultiply = premultiplyAlpha ?? true;
|
|
148
70
|
if (src === null) {
|
|
149
71
|
return {
|
|
150
72
|
data: null,
|
|
@@ -152,13 +74,7 @@ export class ImageTexture extends Texture {
|
|
|
152
74
|
}
|
|
153
75
|
if (typeof src !== 'string') {
|
|
154
76
|
if (src instanceof Blob) {
|
|
155
|
-
|
|
156
|
-
const { sx, sy, sw, sh } = this.props;
|
|
157
|
-
return this.createImageBitmap(src, premultiplyAlpha, sx, sy, sw, sh);
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
return this.loadImageFallback(src, premultiplyAlpha ?? true);
|
|
161
|
-
}
|
|
77
|
+
return platform.createImage(src, premultiply, sx, sy, sw, sh);
|
|
162
78
|
}
|
|
163
79
|
if (src instanceof ImageData) {
|
|
164
80
|
return {
|
|
@@ -171,24 +87,23 @@ export class ImageTexture extends Texture {
|
|
|
171
87
|
premultiplyAlpha,
|
|
172
88
|
};
|
|
173
89
|
}
|
|
174
|
-
const absoluteSrc = convertUrlToAbsolute(src);
|
|
175
90
|
if (type === 'regular') {
|
|
176
|
-
return
|
|
91
|
+
return platform.loadImage(src, premultiply, sx, sy, sw, sh);
|
|
177
92
|
}
|
|
178
93
|
if (type === 'svg') {
|
|
179
|
-
return loadSvg(
|
|
94
|
+
return platform.loadSvg(src, w, h, sx, sy, sw, sh);
|
|
180
95
|
}
|
|
181
96
|
if (isSvgImage(src) === true) {
|
|
182
|
-
return loadSvg(
|
|
97
|
+
return platform.loadSvg(src, w, h, sx, sy, sw, sh);
|
|
183
98
|
}
|
|
184
99
|
if (type === 'compressed') {
|
|
185
|
-
return loadCompressedTexture(
|
|
100
|
+
return platform.loadCompressedTexture(src);
|
|
186
101
|
}
|
|
187
102
|
if (isCompressedTextureContainer(src) === true) {
|
|
188
|
-
return loadCompressedTexture(
|
|
103
|
+
return platform.loadCompressedTexture(src);
|
|
189
104
|
}
|
|
190
105
|
// default
|
|
191
|
-
return
|
|
106
|
+
return platform.loadImage(src, premultiply, sx, sy, sw, sh);
|
|
192
107
|
}
|
|
193
108
|
/**
|
|
194
109
|
* Generates a cache key for the ImageTexture based on the provided props.
|
|
@@ -228,4 +143,26 @@ export class ImageTexture extends Texture {
|
|
|
228
143
|
}
|
|
229
144
|
static z$__type__Props;
|
|
230
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Tests if the given location is a SVG
|
|
148
|
+
* @param url
|
|
149
|
+
* @remarks
|
|
150
|
+
* This function is used to determine if the given image url is a SVG
|
|
151
|
+
* image
|
|
152
|
+
* @returns
|
|
153
|
+
*/
|
|
154
|
+
export function isSvgImage(url) {
|
|
155
|
+
return /\.(svg)(\?.*)?$/.test(url);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Tests if the given location is a compressed texture container
|
|
159
|
+
* @param url
|
|
160
|
+
* @remarks
|
|
161
|
+
* This function is used to determine if the given image url is a compressed
|
|
162
|
+
* and only supports the following extensions: .ktx and .pvr
|
|
163
|
+
* @returns
|
|
164
|
+
*/
|
|
165
|
+
export function isCompressedTextureContainer(src) {
|
|
166
|
+
return /\.(ktx|pvr)$/.test(src);
|
|
167
|
+
}
|
|
231
168
|
//# sourceMappingURL=ImageTexture.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageTexture.js","sourceRoot":"","sources":["../../../../src/core/textures/ImageTexture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAoB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"ImageTexture.js","sourceRoot":"","sources":["../../../../src/core/textures/ImageTexture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAoB,MAAM,cAAc,CAAC;AA6FtE;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,YAAa,SAAQ,OAAO;IAC/B,QAAQ,CAAW;IAEpB,KAAK,CAA8B;IAC1B,IAAI,GAAgB,WAAW,CAAC,KAAK,CAAC;IAEtD,YACE,SAA6B,EAC7B,KAAkC;QAElC,KAAK,CAAC,SAAS,CAAC,CAAC;QAEjB,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;QACnC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,aAAa,GA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K,CAAC,aAAa,IAAI,CAAC;SACxC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,eAAe,CAAoB;CAC3C;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,OAAO,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B,CAAC,GAAW;IACtD,OAAO,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -4,6 +4,7 @@ import type { Dimensions } from '../../common/CommonTypes.js';
|
|
|
4
4
|
import { EventEmitter } from '../../common/EventEmitter.js';
|
|
5
5
|
import type { CoreContextTexture } from '../renderers/CoreContextTexture.js';
|
|
6
6
|
import type { Bound } from '../lib/utils.js';
|
|
7
|
+
import type { TextureError } from '../TextureError.js';
|
|
7
8
|
/**
|
|
8
9
|
* Event handler for when a Texture is freed
|
|
9
10
|
*/
|
|
@@ -31,7 +32,7 @@ export interface CompressedData {
|
|
|
31
32
|
/**
|
|
32
33
|
* Supported container types ('pvr' or 'ktx').
|
|
33
34
|
*/
|
|
34
|
-
type: '
|
|
35
|
+
type: 'PVR' | 'KTX' | 'ASTC';
|
|
35
36
|
/**
|
|
36
37
|
* The width of the compressed texture in pixels. Defaults to 0.
|
|
37
38
|
*
|
|
@@ -54,7 +55,7 @@ export interface CompressedData {
|
|
|
54
55
|
/**
|
|
55
56
|
* Event handler for when a Texture fails to load
|
|
56
57
|
*/
|
|
57
|
-
export type TextureFailedEventHandler = (target: any, error:
|
|
58
|
+
export type TextureFailedEventHandler = (target: any, error: TextureError) => void;
|
|
58
59
|
/**
|
|
59
60
|
* TextureData that is used to populate a CoreContextTexture
|
|
60
61
|
*/
|
|
@@ -135,7 +136,7 @@ export declare abstract class Texture extends EventEmitter {
|
|
|
135
136
|
private static readonly STARTUP_GRACE_PERIOD;
|
|
136
137
|
constructor(txManager: CoreTextureManager);
|
|
137
138
|
get dimensions(): Dimensions | null;
|
|
138
|
-
get error():
|
|
139
|
+
get error(): TextureError | null;
|
|
139
140
|
/**
|
|
140
141
|
* Checks if the texture is within the startup grace period.
|
|
141
142
|
* During this period, textures are protected from cleanup to prevent
|
|
@@ -210,7 +211,7 @@ export declare abstract class Texture extends EventEmitter {
|
|
|
210
211
|
* e.g. ImageData that is downloaded from a URL.
|
|
211
212
|
*/
|
|
212
213
|
freeTextureData(): void;
|
|
213
|
-
setState(state: TextureState, errorOrDimensions?:
|
|
214
|
+
setState(state: TextureState, errorOrDimensions?: TextureError | Dimensions): void;
|
|
214
215
|
/**
|
|
215
216
|
* Get the texture data for this texture.
|
|
216
217
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Texture.js","sourceRoot":"","sources":["../../../../src/core/textures/Texture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"Texture.js","sourceRoot":"","sources":["../../../../src/core/textures/Texture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AA4G5D,MAAM,CAAN,IAAY,WAOX;AAPD,WAAY,WAAW;IACrB,mDAAa,CAAA;IACb,+CAAW,CAAA;IACX,+CAAW,CAAA;IACX,+CAAW,CAAA;IACX,mEAAqB,CAAA;IACrB,yDAAgB,CAAA;AAClB,CAAC,EAPW,WAAW,KAAX,WAAW,QAOtB;AAED;;;;;;;;GAQG;AACH,MAAM,OAAgB,OAAQ,SAAQ,YAAY;IAsD1B;IArDtB;;;;;;OAMG;IACK,WAAW,GAAsB,IAAI,CAAC;IACtC,MAAM,GAAwB,IAAI,CAAC;IAE3C,kBAAkB;IACX,KAAK,GAAiB,SAAS,CAAC;IAE9B,gBAAgB,GAAU,EAAE,CAAC;IAE7B,UAAU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C9B,IAAI,CAAC,WAAW,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACnD,CAAC;QAED,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACK,mBAAmB,GAAG,GAAS,EAAE;QACvC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC,CAAC;IAEF;;;;;OAKG;IACK,WAAW,GAAG,GAAS,EAAE;QAC/B,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC,CAAC;IAWF;;;;;;;;;;;;;OAaG;IACH,6DAA6D;IAC7D,MAAM,CAAC,YAAY,CAAC,KAAc;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,eAAe;IACpB,6DAA6D;IAC7D,KAAc;QAEd,OAAO,EAAE,CAAC;IACZ,CAAC"}
|
package/dist/src/core/utils.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
export declare const EPSILON = 0.000001;
|
|
7
|
-
export declare let ARRAY_TYPE:
|
|
7
|
+
export declare let ARRAY_TYPE: ArrayConstructor | Float32ArrayConstructor;
|
|
8
8
|
export declare const RANDOM: () => number;
|
|
9
9
|
export declare const ANGLE_ORDER = "zyx";
|
|
10
10
|
export type TimingFunction = (t: number) => number;
|
|
@@ -3,6 +3,7 @@ import { type RendererMainSettings } from './Renderer.js';
|
|
|
3
3
|
import type { AnimationSettings } from '../core/animations/CoreAnimation.js';
|
|
4
4
|
import type { AnimationControllerState } from '../common/IAnimationController.js';
|
|
5
5
|
import { CoreTextNode, type CoreTextNodeProps } from '../core/CoreTextNode.js';
|
|
6
|
+
import type { Texture } from '../core/textures/Texture.js';
|
|
6
7
|
/**
|
|
7
8
|
* Inspector Options
|
|
8
9
|
*
|
|
@@ -55,6 +56,7 @@ export declare class Inspector {
|
|
|
55
56
|
private width;
|
|
56
57
|
private scaleX;
|
|
57
58
|
private scaleY;
|
|
59
|
+
private textureMetrics;
|
|
58
60
|
private static setterCallCount;
|
|
59
61
|
private static activeAnimations;
|
|
60
62
|
private static animationHistory;
|
|
@@ -142,6 +144,8 @@ export declare class Inspector {
|
|
|
142
144
|
createNode(node: CoreNode): CoreNode;
|
|
143
145
|
createTextNode(node: CoreTextNode): CoreTextNode;
|
|
144
146
|
createProxy(node: CoreNode | CoreTextNode, div: HTMLElement): CoreNode | CoreTextNode;
|
|
147
|
+
updateTextNodeDimensions(div: HTMLElement, node: CoreTextNode): void;
|
|
148
|
+
updateTextureAttributes(div: HTMLElement, texture: Texture): void;
|
|
145
149
|
destroy(): void;
|
|
146
150
|
destroyNode(id: number): void;
|
|
147
151
|
updateNodeProperty(div: HTMLElement, property: keyof CoreNodeProps | keyof CoreTextNodeProps, value: any, props: CoreNodeProps | CoreTextNodeProps): void;
|