@solidtv/renderer 1.0.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/LICENSE +202 -0
- package/NOTICE +7 -0
- package/README.md +137 -0
- package/dist/exports/canvas-shaders.d.ts +10 -0
- package/dist/exports/canvas-shaders.js +11 -0
- package/dist/exports/canvas-shaders.js.map +1 -0
- package/dist/exports/canvas.d.ts +26 -0
- package/dist/exports/canvas.js +27 -0
- package/dist/exports/canvas.js.map +1 -0
- package/dist/exports/index.d.ts +50 -0
- package/dist/exports/index.js +40 -0
- package/dist/exports/index.js.map +1 -0
- package/dist/exports/inspector.d.ts +4 -0
- package/dist/exports/inspector.js +5 -0
- package/dist/exports/inspector.js.map +1 -0
- package/dist/exports/utils.d.ts +27 -0
- package/dist/exports/utils.js +28 -0
- package/dist/exports/utils.js.map +1 -0
- package/dist/exports/webgl-shaders.d.ts +11 -0
- package/dist/exports/webgl-shaders.js +12 -0
- package/dist/exports/webgl-shaders.js.map +1 -0
- package/dist/exports/webgl.d.ts +28 -0
- package/dist/exports/webgl.js +29 -0
- package/dist/exports/webgl.js.map +1 -0
- package/dist/src/common/CommonTypes.d.ts +110 -0
- package/dist/src/common/CommonTypes.js +2 -0
- package/dist/src/common/CommonTypes.js.map +1 -0
- package/dist/src/common/EventEmitter.d.ts +12 -0
- package/dist/src/common/EventEmitter.js +48 -0
- package/dist/src/common/EventEmitter.js.map +1 -0
- package/dist/src/common/IAnimationController.d.ts +58 -0
- package/dist/src/common/IAnimationController.js +2 -0
- package/dist/src/common/IAnimationController.js.map +1 -0
- package/dist/src/common/IEventEmitter.d.ts +8 -0
- package/dist/src/common/IEventEmitter.js +2 -0
- package/dist/src/common/IEventEmitter.js.map +1 -0
- package/dist/src/core/Autosizer.d.ts +35 -0
- package/dist/src/core/Autosizer.js +178 -0
- package/dist/src/core/Autosizer.js.map +1 -0
- package/dist/src/core/CoreNode.d.ts +908 -0
- package/dist/src/core/CoreNode.js +1837 -0
- package/dist/src/core/CoreNode.js.map +1 -0
- package/dist/src/core/CoreShaderManager.d.ts +38 -0
- package/dist/src/core/CoreShaderManager.js +123 -0
- package/dist/src/core/CoreShaderManager.js.map +1 -0
- package/dist/src/core/CoreTextNode.d.ts +91 -0
- package/dist/src/core/CoreTextNode.js +440 -0
- package/dist/src/core/CoreTextNode.js.map +1 -0
- package/dist/src/core/CoreTextureManager.d.ts +264 -0
- package/dist/src/core/CoreTextureManager.js +318 -0
- package/dist/src/core/CoreTextureManager.js.map +1 -0
- package/dist/src/core/Stage.d.ts +238 -0
- package/dist/src/core/Stage.js +804 -0
- package/dist/src/core/Stage.js.map +1 -0
- package/dist/src/core/TextureError.d.ts +11 -0
- package/dist/src/core/TextureError.js +37 -0
- package/dist/src/core/TextureError.js.map +1 -0
- package/dist/src/core/TextureMemoryManager.d.ts +150 -0
- package/dist/src/core/TextureMemoryManager.js +239 -0
- package/dist/src/core/TextureMemoryManager.js.map +1 -0
- package/dist/src/core/animations/AnimationManager.d.ts +33 -0
- package/dist/src/core/animations/AnimationManager.js +137 -0
- package/dist/src/core/animations/AnimationManager.js.map +1 -0
- package/dist/src/core/animations/CoreAnimation.d.ts +12 -0
- package/dist/src/core/animations/CoreAnimation.js +107 -0
- package/dist/src/core/animations/CoreAnimation.js.map +1 -0
- package/dist/src/core/lib/ContextSpy.d.ts +12 -0
- package/dist/src/core/lib/ContextSpy.js +20 -0
- package/dist/src/core/lib/ContextSpy.js.map +1 -0
- package/dist/src/core/lib/ImageWorker.d.ts +16 -0
- package/dist/src/core/lib/ImageWorker.js +202 -0
- package/dist/src/core/lib/ImageWorker.js.map +1 -0
- package/dist/src/core/lib/Matrix3d.d.ts +74 -0
- package/dist/src/core/lib/Matrix3d.js +218 -0
- package/dist/src/core/lib/Matrix3d.js.map +1 -0
- package/dist/src/core/lib/RenderCoords.d.ts +12 -0
- package/dist/src/core/lib/RenderCoords.js +35 -0
- package/dist/src/core/lib/RenderCoords.js.map +1 -0
- package/dist/src/core/lib/WebGlContextWrapper.d.ts +782 -0
- package/dist/src/core/lib/WebGlContextWrapper.js +1143 -0
- package/dist/src/core/lib/WebGlContextWrapper.js.map +1 -0
- package/dist/src/core/lib/collectionUtils.d.ts +5 -0
- package/dist/src/core/lib/collectionUtils.js +82 -0
- package/dist/src/core/lib/collectionUtils.js.map +1 -0
- package/dist/src/core/lib/colorCache.d.ts +1 -0
- package/dist/src/core/lib/colorCache.js +19 -0
- package/dist/src/core/lib/colorCache.js.map +1 -0
- package/dist/src/core/lib/colorParser.d.ts +21 -0
- package/dist/src/core/lib/colorParser.js +54 -0
- package/dist/src/core/lib/colorParser.js.map +1 -0
- package/dist/src/core/lib/textureCompression.d.ts +28 -0
- package/dist/src/core/lib/textureCompression.js +363 -0
- package/dist/src/core/lib/textureCompression.js.map +1 -0
- package/dist/src/core/lib/textureSvg.d.ts +16 -0
- package/dist/src/core/lib/textureSvg.js +45 -0
- package/dist/src/core/lib/textureSvg.js.map +1 -0
- package/dist/src/core/lib/utils.d.ts +66 -0
- package/dist/src/core/lib/utils.js +268 -0
- package/dist/src/core/lib/utils.js.map +1 -0
- package/dist/src/core/lib/validateImageBitmap.d.ts +7 -0
- package/dist/src/core/lib/validateImageBitmap.js +68 -0
- package/dist/src/core/lib/validateImageBitmap.js.map +1 -0
- package/dist/src/core/platforms/Platform.d.ts +42 -0
- package/dist/src/core/platforms/Platform.js +4 -0
- package/dist/src/core/platforms/Platform.js.map +1 -0
- package/dist/src/core/platforms/web/WebPlatform.d.ts +10 -0
- package/dist/src/core/platforms/web/WebPlatform.js +90 -0
- package/dist/src/core/platforms/web/WebPlatform.js.map +1 -0
- package/dist/src/core/renderers/CoreContextTexture.d.ts +13 -0
- package/dist/src/core/renderers/CoreContextTexture.js +16 -0
- package/dist/src/core/renderers/CoreContextTexture.js.map +1 -0
- package/dist/src/core/renderers/CoreRenderOp.d.ts +3 -0
- package/dist/src/core/renderers/CoreRenderOp.js +3 -0
- package/dist/src/core/renderers/CoreRenderOp.js.map +1 -0
- package/dist/src/core/renderers/CoreRenderer.d.ts +81 -0
- package/dist/src/core/renderers/CoreRenderer.js +14 -0
- package/dist/src/core/renderers/CoreRenderer.js.map +1 -0
- package/dist/src/core/renderers/CoreShaderNode.d.ts +69 -0
- package/dist/src/core/renderers/CoreShaderNode.js +130 -0
- package/dist/src/core/renderers/CoreShaderNode.js.map +1 -0
- package/dist/src/core/renderers/CoreShaderProgram.d.ts +4 -0
- package/dist/src/core/renderers/CoreShaderProgram.js +2 -0
- package/dist/src/core/renderers/CoreShaderProgram.js.map +1 -0
- package/dist/src/core/renderers/canvas/CanvasRenderer.d.ts +36 -0
- package/dist/src/core/renderers/canvas/CanvasRenderer.js +221 -0
- package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +1 -0
- package/dist/src/core/renderers/canvas/CanvasShaderNode.d.ts +21 -0
- package/dist/src/core/renderers/canvas/CanvasShaderNode.js +42 -0
- package/dist/src/core/renderers/canvas/CanvasShaderNode.js.map +1 -0
- package/dist/src/core/renderers/canvas/CanvasTexture.d.ts +17 -0
- package/dist/src/core/renderers/canvas/CanvasTexture.js +110 -0
- package/dist/src/core/renderers/canvas/CanvasTexture.js.map +1 -0
- package/dist/src/core/renderers/webgl/SdfRenderOp.d.ts +41 -0
- package/dist/src/core/renderers/webgl/SdfRenderOp.js +88 -0
- package/dist/src/core/renderers/webgl/SdfRenderOp.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.d.ts +14 -0
- package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js +45 -0
- package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.d.ts +22 -0
- package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js +49 -0
- package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlCtxTexture.d.ts +67 -0
- package/dist/src/core/renderers/webgl/WebGlCtxTexture.js +259 -0
- package/dist/src/core/renderers/webgl/WebGlCtxTexture.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlRenderer.d.ts +221 -0
- package/dist/src/core/renderers/webgl/WebGlRenderer.js +1015 -0
- package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlShaderNode.d.ts +213 -0
- package/dist/src/core/renderers/webgl/WebGlShaderNode.js +331 -0
- package/dist/src/core/renderers/webgl/WebGlShaderNode.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.d.ts +37 -0
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.js +240 -0
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +1 -0
- package/dist/src/core/renderers/webgl/internal/BufferCollection.d.ts +28 -0
- package/dist/src/core/renderers/webgl/internal/BufferCollection.js +39 -0
- package/dist/src/core/renderers/webgl/internal/BufferCollection.js.map +1 -0
- package/dist/src/core/renderers/webgl/internal/RendererUtils.d.ts +55 -0
- package/dist/src/core/renderers/webgl/internal/RendererUtils.js +88 -0
- package/dist/src/core/renderers/webgl/internal/RendererUtils.js.map +1 -0
- package/dist/src/core/renderers/webgl/internal/ShaderUtils.d.ts +74 -0
- package/dist/src/core/renderers/webgl/internal/ShaderUtils.js +83 -0
- package/dist/src/core/renderers/webgl/internal/ShaderUtils.js.map +1 -0
- package/dist/src/core/renderers/webgl/internal/WebGlUtils.d.ts +10 -0
- package/dist/src/core/renderers/webgl/internal/WebGlUtils.js +13 -0
- package/dist/src/core/renderers/webgl/internal/WebGlUtils.js.map +1 -0
- package/dist/src/core/shaders/canvas/Border.d.ts +15 -0
- package/dist/src/core/shaders/canvas/Border.js +83 -0
- package/dist/src/core/shaders/canvas/Border.js.map +1 -0
- package/dist/src/core/shaders/canvas/HolePunch.d.ts +7 -0
- package/dist/src/core/shaders/canvas/HolePunch.js +22 -0
- package/dist/src/core/shaders/canvas/HolePunch.js.map +1 -0
- package/dist/src/core/shaders/canvas/LinearGradient.d.ts +10 -0
- package/dist/src/core/shaders/canvas/LinearGradient.js +32 -0
- package/dist/src/core/shaders/canvas/LinearGradient.js.map +1 -0
- package/dist/src/core/shaders/canvas/RadialGradient.d.ts +11 -0
- package/dist/src/core/shaders/canvas/RadialGradient.js +54 -0
- package/dist/src/core/shaders/canvas/RadialGradient.js.map +1 -0
- package/dist/src/core/shaders/canvas/Rounded.d.ts +7 -0
- package/dist/src/core/shaders/canvas/Rounded.js +17 -0
- package/dist/src/core/shaders/canvas/Rounded.js.map +1 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorder.d.ts +10 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorder.js +57 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorder.js.map +1 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.d.ts +7 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js +61 -0
- package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js.map +1 -0
- package/dist/src/core/shaders/canvas/RoundedWithShadow.d.ts +7 -0
- package/dist/src/core/shaders/canvas/RoundedWithShadow.js +26 -0
- package/dist/src/core/shaders/canvas/RoundedWithShadow.js.map +1 -0
- package/dist/src/core/shaders/canvas/Shadow.d.ts +8 -0
- package/dist/src/core/shaders/canvas/Shadow.js +15 -0
- package/dist/src/core/shaders/canvas/Shadow.js.map +1 -0
- package/dist/src/core/shaders/canvas/utils/render.d.ts +5 -0
- package/dist/src/core/shaders/canvas/utils/render.js +81 -0
- package/dist/src/core/shaders/canvas/utils/render.js.map +1 -0
- package/dist/src/core/shaders/templates/BorderTemplate.d.ts +47 -0
- package/dist/src/core/shaders/templates/BorderTemplate.js +77 -0
- package/dist/src/core/shaders/templates/BorderTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/HolePunchTemplate.d.ts +46 -0
- package/dist/src/core/shaders/templates/HolePunchTemplate.js +19 -0
- package/dist/src/core/shaders/templates/HolePunchTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/LinearGradientTemplate.d.ts +23 -0
- package/dist/src/core/shaders/templates/LinearGradientTemplate.js +31 -0
- package/dist/src/core/shaders/templates/LinearGradientTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/RadialGradientTemplate.d.ts +33 -0
- package/dist/src/core/shaders/templates/RadialGradientTemplate.js +33 -0
- package/dist/src/core/shaders/templates/RadialGradientTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/RoundedTemplate.d.ts +29 -0
- package/dist/src/core/shaders/templates/RoundedTemplate.js +51 -0
- package/dist/src/core/shaders/templates/RoundedTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.d.ts +7 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.js +8 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.d.ts +8 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.js +9 -0
- package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.d.ts +6 -0
- package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.js +7 -0
- package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.js.map +1 -0
- package/dist/src/core/shaders/templates/ShadowTemplate.d.ts +34 -0
- package/dist/src/core/shaders/templates/ShadowTemplate.js +50 -0
- package/dist/src/core/shaders/templates/ShadowTemplate.js.map +1 -0
- package/dist/src/core/shaders/utils.d.ts +5 -0
- package/dist/src/core/shaders/utils.js +25 -0
- package/dist/src/core/shaders/utils.js.map +1 -0
- package/dist/src/core/shaders/webgl/Border.d.ts +3 -0
- package/dist/src/core/shaders/webgl/Border.js +153 -0
- package/dist/src/core/shaders/webgl/Border.js.map +1 -0
- package/dist/src/core/shaders/webgl/Default.d.ts +2 -0
- package/dist/src/core/shaders/webgl/Default.js +51 -0
- package/dist/src/core/shaders/webgl/Default.js.map +1 -0
- package/dist/src/core/shaders/webgl/HolePunch.d.ts +3 -0
- package/dist/src/core/shaders/webgl/HolePunch.js +49 -0
- package/dist/src/core/shaders/webgl/HolePunch.js.map +1 -0
- package/dist/src/core/shaders/webgl/LinearGradient.d.ts +3 -0
- package/dist/src/core/shaders/webgl/LinearGradient.js +114 -0
- package/dist/src/core/shaders/webgl/LinearGradient.js.map +1 -0
- package/dist/src/core/shaders/webgl/RadialGradient.d.ts +3 -0
- package/dist/src/core/shaders/webgl/RadialGradient.js +81 -0
- package/dist/src/core/shaders/webgl/RadialGradient.js.map +1 -0
- package/dist/src/core/shaders/webgl/Rounded.d.ts +7 -0
- package/dist/src/core/shaders/webgl/Rounded.js +88 -0
- package/dist/src/core/shaders/webgl/Rounded.js.map +1 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorder.d.ts +3 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorder.js +202 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorder.js.map +1 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.d.ts +3 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +223 -0
- package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js.map +1 -0
- package/dist/src/core/shaders/webgl/RoundedWithShadow.d.ts +3 -0
- package/dist/src/core/shaders/webgl/RoundedWithShadow.js +123 -0
- package/dist/src/core/shaders/webgl/RoundedWithShadow.js.map +1 -0
- package/dist/src/core/shaders/webgl/SdfShader.d.ts +13 -0
- package/dist/src/core/shaders/webgl/SdfShader.js +72 -0
- package/dist/src/core/shaders/webgl/SdfShader.js.map +1 -0
- package/dist/src/core/shaders/webgl/Shadow.d.ts +3 -0
- package/dist/src/core/shaders/webgl/Shadow.js +115 -0
- package/dist/src/core/shaders/webgl/Shadow.js.map +1 -0
- package/dist/src/core/text-rendering/CanvasFontHandler.d.ts +59 -0
- package/dist/src/core/text-rendering/CanvasFontHandler.js +206 -0
- package/dist/src/core/text-rendering/CanvasFontHandler.js.map +1 -0
- package/dist/src/core/text-rendering/CanvasTextRenderer.d.ts +17 -0
- package/dist/src/core/text-rendering/CanvasTextRenderer.js +139 -0
- package/dist/src/core/text-rendering/CanvasTextRenderer.js.map +1 -0
- package/dist/src/core/text-rendering/SdfFontHandler.d.ts +167 -0
- package/dist/src/core/text-rendering/SdfFontHandler.js +371 -0
- package/dist/src/core/text-rendering/SdfFontHandler.js.map +1 -0
- package/dist/src/core/text-rendering/SdfTextRenderer.d.ts +17 -0
- package/dist/src/core/text-rendering/SdfTextRenderer.js +249 -0
- package/dist/src/core/text-rendering/SdfTextRenderer.js.map +1 -0
- package/dist/src/core/text-rendering/TextLayoutEngine.d.ts +18 -0
- package/dist/src/core/text-rendering/TextLayoutEngine.js +380 -0
- package/dist/src/core/text-rendering/TextLayoutEngine.js.map +1 -0
- package/dist/src/core/text-rendering/TextRenderer.d.ts +406 -0
- package/dist/src/core/text-rendering/TextRenderer.js +2 -0
- package/dist/src/core/text-rendering/TextRenderer.js.map +1 -0
- package/dist/src/core/text-rendering/Utils.d.ts +30 -0
- package/dist/src/core/text-rendering/Utils.js +66 -0
- package/dist/src/core/text-rendering/Utils.js.map +1 -0
- package/dist/src/core/textures/ColorTexture.d.ts +36 -0
- package/dist/src/core/textures/ColorTexture.js +57 -0
- package/dist/src/core/textures/ColorTexture.js.map +1 -0
- package/dist/src/core/textures/ImageTexture.d.ts +131 -0
- package/dist/src/core/textures/ImageTexture.js +211 -0
- package/dist/src/core/textures/ImageTexture.js.map +1 -0
- package/dist/src/core/textures/NoiseTexture.d.ts +43 -0
- package/dist/src/core/textures/NoiseTexture.js +50 -0
- package/dist/src/core/textures/NoiseTexture.js.map +1 -0
- package/dist/src/core/textures/RenderTexture.d.ts +29 -0
- package/dist/src/core/textures/RenderTexture.js +36 -0
- package/dist/src/core/textures/RenderTexture.js.map +1 -0
- package/dist/src/core/textures/SubTexture.d.ts +61 -0
- package/dist/src/core/textures/SubTexture.js +99 -0
- package/dist/src/core/textures/SubTexture.js.map +1 -0
- package/dist/src/core/textures/Texture.d.ts +275 -0
- package/dist/src/core/textures/Texture.js +326 -0
- package/dist/src/core/textures/Texture.js.map +1 -0
- package/dist/src/core/utils.d.ts +23 -0
- package/dist/src/core/utils.js +155 -0
- package/dist/src/core/utils.js.map +1 -0
- package/dist/src/main-api/INode.d.ts +65 -0
- package/dist/src/main-api/INode.js +2 -0
- package/dist/src/main-api/INode.js.map +1 -0
- package/dist/src/main-api/Inspector.d.ts +154 -0
- package/dist/src/main-api/Inspector.js +844 -0
- package/dist/src/main-api/Inspector.js.map +1 -0
- package/dist/src/main-api/Renderer.d.ts +629 -0
- package/dist/src/main-api/Renderer.js +471 -0
- package/dist/src/main-api/Renderer.js.map +1 -0
- package/dist/src/main-api/utils.d.ts +2 -0
- package/dist/src/main-api/utils.js +34 -0
- package/dist/src/main-api/utils.js.map +1 -0
- package/dist/src/utils.d.ts +123 -0
- package/dist/src/utils.js +234 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/tsconfig.dist.tsbuildinfo +1 -0
- package/exports/canvas-shaders.ts +11 -0
- package/exports/canvas.ts +27 -0
- package/exports/index.ts +69 -0
- package/exports/inspector.ts +5 -0
- package/exports/utils.ts +32 -0
- package/exports/webgl-shaders.ts +12 -0
- package/exports/webgl.ts +33 -0
- package/package.json +99 -0
- package/src/common/CommonTypes.ts +145 -0
- package/src/common/EventEmitter.ts +58 -0
- package/src/common/IAnimationController.ts +65 -0
- package/src/common/IEventEmitter.ts +11 -0
- package/src/core/Autosizer.ts +205 -0
- package/src/core/CoreNode.test.ts +535 -0
- package/src/core/CoreNode.ts +2883 -0
- package/src/core/CoreShaderManager.ts +170 -0
- package/src/core/CoreTextNode.ts +573 -0
- package/src/core/CoreTextureManager.ts +552 -0
- package/src/core/Stage.ts +1037 -0
- package/src/core/TextureError.ts +46 -0
- package/src/core/TextureMemoryManager.ts +378 -0
- package/src/core/animations/AnimationManager.ts +178 -0
- package/src/core/animations/CoreAnimation.ts +138 -0
- package/src/core/lib/ContextSpy.ts +22 -0
- package/src/core/lib/ImageWorker.ts +292 -0
- package/src/core/lib/Matrix3d.ts +231 -0
- package/src/core/lib/RenderCoords.ts +55 -0
- package/src/core/lib/WebGlContextWrapper.ts +1448 -0
- package/src/core/lib/collectionUtils.ts +99 -0
- package/src/core/lib/colorCache.ts +20 -0
- package/src/core/lib/colorParser.ts +66 -0
- package/src/core/lib/textureCompression.ts +492 -0
- package/src/core/lib/textureSvg.ts +59 -0
- package/src/core/lib/utils.ts +400 -0
- package/src/core/lib/validateImageBitmap.ts +87 -0
- package/src/core/platforms/Platform.ts +64 -0
- package/src/core/platforms/web/WebPlatform.ts +132 -0
- package/src/core/renderers/CoreContextTexture.ts +25 -0
- package/src/core/renderers/CoreRenderOp.ts +3 -0
- package/src/core/renderers/CoreRenderer.ts +101 -0
- package/src/core/renderers/CoreShaderNode.ts +202 -0
- package/src/core/renderers/CoreShaderProgram.ts +4 -0
- package/src/core/renderers/canvas/CanvasRenderer.ts +274 -0
- package/src/core/renderers/canvas/CanvasShaderNode.ts +79 -0
- package/src/core/renderers/canvas/CanvasTexture.ts +141 -0
- package/src/core/renderers/webgl/SdfRenderOp.ts +103 -0
- package/src/core/renderers/webgl/WebGlCtxRenderTexture.ts +70 -0
- package/src/core/renderers/webgl/WebGlCtxSubTexture.ts +76 -0
- package/src/core/renderers/webgl/WebGlCtxTexture.ts +332 -0
- package/src/core/renderers/webgl/WebGlRenderer.ts +1323 -0
- package/src/core/renderers/webgl/WebGlShaderNode.ts +423 -0
- package/src/core/renderers/webgl/WebGlShaderProgram.ts +346 -0
- package/src/core/renderers/webgl/internal/BufferCollection.ts +46 -0
- package/src/core/renderers/webgl/internal/RendererUtils.ts +136 -0
- package/src/core/renderers/webgl/internal/ShaderUtils.ts +262 -0
- package/src/core/renderers/webgl/internal/WebGlUtils.ts +16 -0
- package/src/core/shaders/canvas/Border.ts +119 -0
- package/src/core/shaders/canvas/HolePunch.ts +38 -0
- package/src/core/shaders/canvas/LinearGradient.ts +54 -0
- package/src/core/shaders/canvas/RadialGradient.ts +82 -0
- package/src/core/shaders/canvas/Rounded.ts +38 -0
- package/src/core/shaders/canvas/RoundedWithBorder.ts +105 -0
- package/src/core/shaders/canvas/RoundedWithBorderAndShadow.ts +118 -0
- package/src/core/shaders/canvas/RoundedWithShadow.ts +56 -0
- package/src/core/shaders/canvas/Shadow.ts +35 -0
- package/src/core/shaders/canvas/utils/render.ts +143 -0
- package/src/core/shaders/templates/BorderTemplate.ts +128 -0
- package/src/core/shaders/templates/HolePunchTemplate.ts +65 -0
- package/src/core/shaders/templates/LinearGradientTemplate.ts +54 -0
- package/src/core/shaders/templates/RadialGradientTemplate.ts +66 -0
- package/src/core/shaders/templates/RoundedTemplate.ts +81 -0
- package/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.ts +21 -0
- package/src/core/shaders/templates/RoundedWithBorderTemplate.ts +23 -0
- package/src/core/shaders/templates/RoundedWithShadowTemplate.ts +18 -0
- package/src/core/shaders/templates/ShadowTemplate.ts +89 -0
- package/src/core/shaders/utils.ts +30 -0
- package/src/core/shaders/webgl/Border.ts +158 -0
- package/src/core/shaders/webgl/Default.ts +52 -0
- package/src/core/shaders/webgl/HolePunch.ts +58 -0
- package/src/core/shaders/webgl/LinearGradient.ts +119 -0
- package/src/core/shaders/webgl/RadialGradient.ts +91 -0
- package/src/core/shaders/webgl/Rounded.ts +97 -0
- package/src/core/shaders/webgl/RoundedWithBorder.ts +212 -0
- package/src/core/shaders/webgl/RoundedWithBorderAndShadow.ts +235 -0
- package/src/core/shaders/webgl/RoundedWithShadow.ts +132 -0
- package/src/core/shaders/webgl/SdfShader.ts +73 -0
- package/src/core/shaders/webgl/Shadow.ts +119 -0
- package/src/core/text-rendering/CanvasFontHandler.ts +285 -0
- package/src/core/text-rendering/CanvasTextRenderer.ts +236 -0
- package/src/core/text-rendering/SdfFontHandler.ts +566 -0
- package/src/core/text-rendering/SdfTextRenderer.ts +352 -0
- package/src/core/text-rendering/TextLayoutEngine.ts +672 -0
- package/src/core/text-rendering/TextRenderer.ts +449 -0
- package/src/core/text-rendering/Utils.ts +80 -0
- package/src/core/text-rendering/tests/TextLayoutEngine.test.ts +434 -0
- package/src/core/textures/ColorTexture.ts +85 -0
- package/src/core/textures/ImageTexture.ts +394 -0
- package/src/core/textures/NoiseTexture.ts +87 -0
- package/src/core/textures/RenderTexture.ts +68 -0
- package/src/core/textures/SubTexture.ts +165 -0
- package/src/core/textures/Texture.ts +505 -0
- package/src/core/utils.ts +210 -0
- package/src/env.d.ts +7 -0
- package/src/main-api/INode.ts +92 -0
- package/src/main-api/Inspector.ts +1267 -0
- package/src/main-api/Renderer.ts +1011 -0
- package/src/main-api/utils.ts +45 -0
- package/src/utils.ts +302 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SdfShader supports multi-channel and single-channel signed distance field textures.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* All per-glyph data (position, color, distance range) is provided via vertex
|
|
6
|
+
* attributes so that multiple text nodes sharing the same font atlas can be
|
|
7
|
+
* batched into a single draw call.
|
|
8
|
+
*
|
|
9
|
+
* This Shader is used by the {@link SdfTextRenderer}. Do not use this Shader
|
|
10
|
+
* directly. Instead create a Text Node and assign a SDF font family to it.
|
|
11
|
+
*/
|
|
12
|
+
export const Sdf = {
|
|
13
|
+
vertex: `
|
|
14
|
+
# ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
15
|
+
precision highp float;
|
|
16
|
+
# else
|
|
17
|
+
precision mediump float;
|
|
18
|
+
# endif
|
|
19
|
+
|
|
20
|
+
// Pre-transformed world-pixel position
|
|
21
|
+
attribute vec2 a_position;
|
|
22
|
+
attribute vec2 a_textureCoords;
|
|
23
|
+
// Per-vertex color (RGBA, unsigned byte, normalized)
|
|
24
|
+
attribute vec4 a_color;
|
|
25
|
+
// Per-vertex SDF distance range
|
|
26
|
+
attribute float a_distRange;
|
|
27
|
+
|
|
28
|
+
uniform vec2 u_resolution;
|
|
29
|
+
uniform float u_pixelRatio;
|
|
30
|
+
|
|
31
|
+
varying vec2 v_texcoord;
|
|
32
|
+
varying float v_scaledDistRange;
|
|
33
|
+
varying vec4 v_color;
|
|
34
|
+
|
|
35
|
+
void main() {
|
|
36
|
+
// a_position is already in world pixel space (pre-transformed on CPU)
|
|
37
|
+
vec2 screenSpace = (a_position * u_pixelRatio / u_resolution * 2.0 - 1.0) * vec2(1, -1);
|
|
38
|
+
|
|
39
|
+
gl_Position = vec4(screenSpace, 0.0, 1.0);
|
|
40
|
+
v_texcoord = a_textureCoords;
|
|
41
|
+
v_scaledDistRange = a_distRange * u_pixelRatio;
|
|
42
|
+
v_color = a_color;
|
|
43
|
+
}
|
|
44
|
+
`,
|
|
45
|
+
fragment: `
|
|
46
|
+
# ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
47
|
+
precision highp float;
|
|
48
|
+
# else
|
|
49
|
+
precision mediump float;
|
|
50
|
+
# endif
|
|
51
|
+
|
|
52
|
+
uniform sampler2D u_texture;
|
|
53
|
+
|
|
54
|
+
varying vec2 v_texcoord;
|
|
55
|
+
varying float v_scaledDistRange;
|
|
56
|
+
varying vec4 v_color;
|
|
57
|
+
|
|
58
|
+
float median(float r, float g, float b) {
|
|
59
|
+
return clamp(b, min(r, g), max(r, g));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
void main() {
|
|
63
|
+
vec3 s = texture2D(u_texture, v_texcoord).rgb;
|
|
64
|
+
float sigDist = v_scaledDistRange * (median(s.r, s.g, s.b) - 0.5);
|
|
65
|
+
float opacity = clamp(sigDist + 0.5, 0.0, 1.0) * v_color.a;
|
|
66
|
+
|
|
67
|
+
// Premultiply RGB by final opacity
|
|
68
|
+
gl_FragColor = vec4(v_color.rgb * opacity, opacity);
|
|
69
|
+
}
|
|
70
|
+
`,
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=SdfShader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SdfShader.js","sourceRoot":"","sources":["../../../../../src/core/shaders/webgl/SdfShader.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,GAAG,GAAoB;IAClC,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BP;IACD,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBT;CACF,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { ShadowTemplate, } from '../templates/ShadowTemplate.js';
|
|
2
|
+
export const Shadow = {
|
|
3
|
+
props: ShadowTemplate.props,
|
|
4
|
+
update() {
|
|
5
|
+
this.uniformRGBA('u_color', this.props.color);
|
|
6
|
+
this.uniform4fa('u_shadow', this.props.projection);
|
|
7
|
+
},
|
|
8
|
+
vertex: `
|
|
9
|
+
# ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
10
|
+
precision highp float;
|
|
11
|
+
# else
|
|
12
|
+
precision mediump float;
|
|
13
|
+
# endif
|
|
14
|
+
|
|
15
|
+
attribute vec2 a_position;
|
|
16
|
+
attribute vec2 a_textureCoords;
|
|
17
|
+
attribute vec4 a_color;
|
|
18
|
+
attribute vec2 a_nodeCoords;
|
|
19
|
+
|
|
20
|
+
uniform vec2 u_resolution;
|
|
21
|
+
uniform float u_pixelRatio;
|
|
22
|
+
uniform vec2 u_dimensions;
|
|
23
|
+
|
|
24
|
+
uniform vec4 u_shadow;
|
|
25
|
+
|
|
26
|
+
varying vec4 v_color;
|
|
27
|
+
varying vec2 v_textureCoords;
|
|
28
|
+
|
|
29
|
+
varying vec2 v_boxUv;
|
|
30
|
+
varying vec2 v_boxSize;
|
|
31
|
+
varying vec2 v_boxSmooth;
|
|
32
|
+
varying vec2 v_shadowBox;
|
|
33
|
+
varying vec2 v_shadowSize;
|
|
34
|
+
varying float v_shadowRadius;
|
|
35
|
+
varying vec2 v_shadowSmooth;
|
|
36
|
+
|
|
37
|
+
void main() {
|
|
38
|
+
vec2 screenSpace = vec2(2.0 / u_resolution.x, -2.0 / u_resolution.y);
|
|
39
|
+
vec2 outerEdge = clamp(a_nodeCoords * 2.0 - vec2(1.0), -1.0, 1.0);
|
|
40
|
+
|
|
41
|
+
vec2 padding = vec2(max(0.0, u_shadow.w) + u_shadow.z);
|
|
42
|
+
vec2 offsetShift = mix(min(vec2(0.0), u_shadow.xy), max(vec2(0.0), u_shadow.xy), (outerEdge + 1.0) * 0.5);
|
|
43
|
+
vec2 shadowEdge = outerEdge * padding + offsetShift;
|
|
44
|
+
|
|
45
|
+
vec2 vertexPos = (a_position + outerEdge + shadowEdge) * u_pixelRatio;
|
|
46
|
+
gl_Position = vec4(vertexPos.x * screenSpace.x - 1.0, -sign(screenSpace.y) * (vertexPos.y * -abs(screenSpace.y)) + 1.0, 0.0, 1.0);
|
|
47
|
+
|
|
48
|
+
v_color = a_color;
|
|
49
|
+
v_textureCoords = a_textureCoords + (screenSpace + shadowEdge) / (u_dimensions);
|
|
50
|
+
|
|
51
|
+
float edgeWidth = 1.0 / u_pixelRatio;
|
|
52
|
+
vec2 halfDimensions = u_dimensions * 0.5;
|
|
53
|
+
|
|
54
|
+
v_boxUv = (a_nodeCoords + (screenSpace + shadowEdge) / (u_dimensions)) * u_dimensions - halfDimensions;
|
|
55
|
+
v_boxSize = halfDimensions - edgeWidth;
|
|
56
|
+
v_boxSmooth = vec2(0.0, edgeWidth);
|
|
57
|
+
|
|
58
|
+
v_shadowBox = v_boxUv - u_shadow.xy;
|
|
59
|
+
v_shadowSize = halfDimensions + u_shadow.w - edgeWidth;
|
|
60
|
+
v_shadowRadius = max(0.0, u_shadow.w);
|
|
61
|
+
v_shadowSmooth = vec2(-u_shadow.z, u_shadow.z + 0.001);
|
|
62
|
+
}
|
|
63
|
+
`,
|
|
64
|
+
fragment: `
|
|
65
|
+
# ifdef GL_FRAGMENT_PRECISION_HIGH
|
|
66
|
+
precision highp float;
|
|
67
|
+
# else
|
|
68
|
+
precision mediump float;
|
|
69
|
+
# endif
|
|
70
|
+
|
|
71
|
+
uniform float u_alpha;
|
|
72
|
+
uniform sampler2D u_texture;
|
|
73
|
+
|
|
74
|
+
uniform vec4 u_color;
|
|
75
|
+
|
|
76
|
+
varying vec4 v_color;
|
|
77
|
+
varying vec2 v_textureCoords;
|
|
78
|
+
|
|
79
|
+
varying vec2 v_boxUv;
|
|
80
|
+
varying vec2 v_boxSize;
|
|
81
|
+
varying vec2 v_boxSmooth;
|
|
82
|
+
varying vec2 v_shadowBox;
|
|
83
|
+
varying vec2 v_shadowSize;
|
|
84
|
+
varying float v_shadowRadius;
|
|
85
|
+
varying vec2 v_shadowSmooth;
|
|
86
|
+
|
|
87
|
+
float box(vec2 p, vec2 s) {
|
|
88
|
+
vec2 q = abs(p) - s;
|
|
89
|
+
return (min(max(q.x, q.y), 0.0) + length(max(q, 0.0))) + 2.0;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
float shadowBox(vec2 p, vec2 s, float r) {
|
|
93
|
+
vec2 q = abs(p) - s + r;
|
|
94
|
+
float dist = min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - r;
|
|
95
|
+
return 1.0 - smoothstep(v_shadowSmooth.x, v_shadowSmooth.y, dist);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
void main() {
|
|
99
|
+
vec4 color = texture2D(u_texture, v_textureCoords) * v_color;
|
|
100
|
+
|
|
101
|
+
float boxDist = box(v_boxUv, v_boxSize);
|
|
102
|
+
float boxAlpha = 1.0 - smoothstep(v_boxSmooth.x, v_boxSmooth.y, boxDist);
|
|
103
|
+
|
|
104
|
+
vec4 resColor = vec4(0.0);
|
|
105
|
+
if (u_color.a > 0.0) {
|
|
106
|
+
float shadowDist = shadowBox(v_shadowBox, v_shadowSize, v_shadowRadius);
|
|
107
|
+
resColor = u_color * shadowDist;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
resColor = mix(resColor, color, min(color.a, boxAlpha));
|
|
111
|
+
gl_FragColor = resColor * u_alpha;
|
|
112
|
+
}
|
|
113
|
+
`,
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=Shadow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Shadow.js","sourceRoot":"","sources":["../../../../../src/core/shaders/webgl/Shadow.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,GAEf,MAAM,gCAAgC,CAAC;AAExC,MAAM,CAAC,MAAM,MAAM,GAAiC;IAClD,KAAK,EAAE,cAAc,CAAC,KAAK;IAC3B,MAAM;QACJ,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC,KAAM,CAAC,KAAK,CAAC,CAAC;QAC/C,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,KAAM,CAAC,UAAU,CAAC,CAAC;IACtD,CAAC;IACD,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDP;IACD,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDT;CACF,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { FontFamilyMap, FontLoadOptions, FontMetrics, NormalizedFontMetrics } from './TextRenderer.js';
|
|
2
|
+
import type { Stage } from '../Stage.js';
|
|
3
|
+
import type { CoreTextNode } from '../CoreTextNode.js';
|
|
4
|
+
/**
|
|
5
|
+
* Check if a font can be rendered
|
|
6
|
+
*/
|
|
7
|
+
export declare const canRenderFont: () => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Load a font by providing fontFamily, fontUrl, and optional metrics
|
|
10
|
+
*/
|
|
11
|
+
export declare const loadFont: (stage: Stage, options: FontLoadOptions) => Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Get the font families map for resolving fonts
|
|
14
|
+
*/
|
|
15
|
+
export declare const getFontFamilies: () => FontFamilyMap;
|
|
16
|
+
/**
|
|
17
|
+
* Initialize the global font handler
|
|
18
|
+
*/
|
|
19
|
+
export declare const init: (c: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, mc: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D) => void;
|
|
20
|
+
export declare const type = "canvas";
|
|
21
|
+
/**
|
|
22
|
+
* Check if a font is already loaded by font family
|
|
23
|
+
*/
|
|
24
|
+
export declare const isFontLoaded: (fontFamily: string) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Wait for a font to load
|
|
27
|
+
*
|
|
28
|
+
* @param fontFamily
|
|
29
|
+
* @param node
|
|
30
|
+
*/
|
|
31
|
+
export declare const waitingForFont: (fontFamily: string, node: CoreTextNode) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Stop waiting for a font to load
|
|
34
|
+
*
|
|
35
|
+
* @param fontFamily
|
|
36
|
+
* @param node
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
export declare const stopWaitingForFont: (fontFamily: string, node: CoreTextNode) => void;
|
|
40
|
+
export declare const getFontMetrics: (fontFamily: string, fontSize: number) => NormalizedFontMetrics;
|
|
41
|
+
export declare const processFontMetrics: (fontFamily: string, fontSize: number, metrics: FontMetrics) => NormalizedFontMetrics;
|
|
42
|
+
export declare const measureText: (text: string, fontFamily: string, letterSpacing: number) => number;
|
|
43
|
+
/**
|
|
44
|
+
* Get the font metrics for a font face.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* This function will attempt to grab the explicitly defined metrics from the
|
|
48
|
+
* font face first. If the font face does not have metrics defined, it will
|
|
49
|
+
* attempt to calculate the metrics using the browser's measureText method.
|
|
50
|
+
*
|
|
51
|
+
* If the browser does not support the font metrics API, it will use some
|
|
52
|
+
* default values.
|
|
53
|
+
*
|
|
54
|
+
* @param context
|
|
55
|
+
* @param fontFace
|
|
56
|
+
* @param fontSize
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
export declare function calculateFontMetrics(fontFamily: string, fontSize: number): FontMetrics;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { hasZeroWidthSpace } from './Utils.js';
|
|
2
|
+
import { UpdateType } from '../CoreNode.js';
|
|
3
|
+
import { defaultFontMetrics, normalizeFontMetrics, } from './TextLayoutEngine.js';
|
|
4
|
+
/**
|
|
5
|
+
* Global font set regardless of if run in the main thread or a web worker
|
|
6
|
+
*/
|
|
7
|
+
// const globalFontSet: FontFaceSet = (resolvedGlobal.document?.fonts ||
|
|
8
|
+
// (resolvedGlobal as unknown as { fonts: FontFaceSet }).fonts) as FontFaceSet;
|
|
9
|
+
// Global state variables for fontHandler
|
|
10
|
+
const fontFamilies = {};
|
|
11
|
+
const fontLoadPromises = new Map();
|
|
12
|
+
const normalizedMetrics = new Map();
|
|
13
|
+
const nodesWaitingForFont = Object.create(null);
|
|
14
|
+
const fontCache = new Map();
|
|
15
|
+
let initialized = false;
|
|
16
|
+
let context;
|
|
17
|
+
let measureContext;
|
|
18
|
+
/**
|
|
19
|
+
* Check if a font can be rendered
|
|
20
|
+
*/
|
|
21
|
+
export const canRenderFont = () => {
|
|
22
|
+
// Canvas can always render any font family (assuming the browser supports it)
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
25
|
+
const processFontData = (fontFamily, fontFace, metrics) => {
|
|
26
|
+
metrics = metrics || defaultFontMetrics;
|
|
27
|
+
fontCache.set(fontFamily, {
|
|
28
|
+
fontFamily,
|
|
29
|
+
fontFace,
|
|
30
|
+
metrics,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Load a font by providing fontFamily, fontUrl, and optional metrics
|
|
35
|
+
*/
|
|
36
|
+
export const loadFont = async (stage, options) => {
|
|
37
|
+
const { fontFamily, fontUrl, metrics } = options;
|
|
38
|
+
// If already loaded, return immediately
|
|
39
|
+
if (fontCache.has(fontFamily) === true) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const existingPromise = fontLoadPromises.get(fontFamily);
|
|
43
|
+
// If already loading, return the existing promise
|
|
44
|
+
if (existingPromise !== undefined) {
|
|
45
|
+
return existingPromise;
|
|
46
|
+
}
|
|
47
|
+
const nwff = (nodesWaitingForFont[fontFamily] = []);
|
|
48
|
+
// Create and store the loading promise
|
|
49
|
+
const loadPromise = new FontFace(fontFamily, `url(${fontUrl})`)
|
|
50
|
+
.load()
|
|
51
|
+
.then((loadedFont) => {
|
|
52
|
+
stage.platform.addFont(loadedFont);
|
|
53
|
+
processFontData(fontFamily, loadedFont, metrics);
|
|
54
|
+
fontLoadPromises.delete(fontFamily);
|
|
55
|
+
for (let key in nwff) {
|
|
56
|
+
nwff[key].setUpdateType(UpdateType.Local);
|
|
57
|
+
}
|
|
58
|
+
delete nodesWaitingForFont[fontFamily];
|
|
59
|
+
})
|
|
60
|
+
.catch((error) => {
|
|
61
|
+
fontLoadPromises.delete(fontFamily);
|
|
62
|
+
console.error(`Failed to load font: ${fontFamily}`, error);
|
|
63
|
+
throw error;
|
|
64
|
+
});
|
|
65
|
+
fontLoadPromises.set(fontFamily, loadPromise);
|
|
66
|
+
return loadPromise;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Get the font families map for resolving fonts
|
|
70
|
+
*/
|
|
71
|
+
export const getFontFamilies = () => {
|
|
72
|
+
return fontFamilies;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Initialize the global font handler
|
|
76
|
+
*/
|
|
77
|
+
export const init = (c, mc) => {
|
|
78
|
+
if (initialized === true) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (c === undefined) {
|
|
82
|
+
throw new Error('Canvas context is not provided for font handler initialization');
|
|
83
|
+
}
|
|
84
|
+
context = c;
|
|
85
|
+
measureContext = mc;
|
|
86
|
+
// Register the default 'sans-serif' font face
|
|
87
|
+
const defaultMetrics = {
|
|
88
|
+
ascender: 800,
|
|
89
|
+
descender: -200,
|
|
90
|
+
lineGap: 200,
|
|
91
|
+
unitsPerEm: 1000,
|
|
92
|
+
};
|
|
93
|
+
processFontData('sans-serif', undefined, defaultMetrics);
|
|
94
|
+
initialized = true;
|
|
95
|
+
};
|
|
96
|
+
export const type = 'canvas';
|
|
97
|
+
/**
|
|
98
|
+
* Check if a font is already loaded by font family
|
|
99
|
+
*/
|
|
100
|
+
export const isFontLoaded = (fontFamily) => {
|
|
101
|
+
return fontCache.has(fontFamily);
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Wait for a font to load
|
|
105
|
+
*
|
|
106
|
+
* @param fontFamily
|
|
107
|
+
* @param node
|
|
108
|
+
*/
|
|
109
|
+
export const waitingForFont = (fontFamily, node) => {
|
|
110
|
+
if (nodesWaitingForFont[fontFamily] === undefined) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
nodesWaitingForFont[fontFamily][node.id] = node;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Stop waiting for a font to load
|
|
117
|
+
*
|
|
118
|
+
* @param fontFamily
|
|
119
|
+
* @param node
|
|
120
|
+
* @returns
|
|
121
|
+
*/
|
|
122
|
+
export const stopWaitingForFont = (fontFamily, node) => {
|
|
123
|
+
if (nodesWaitingForFont[fontFamily] === undefined) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
delete nodesWaitingForFont[fontFamily][node.id];
|
|
127
|
+
};
|
|
128
|
+
export const getFontMetrics = (fontFamily, fontSize) => {
|
|
129
|
+
const out = normalizedMetrics.get(fontFamily + fontSize);
|
|
130
|
+
if (out !== undefined) {
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
let metrics = fontCache.get(fontFamily).metrics;
|
|
134
|
+
if (metrics === undefined) {
|
|
135
|
+
metrics = calculateFontMetrics(fontFamily, fontSize);
|
|
136
|
+
}
|
|
137
|
+
return processFontMetrics(fontFamily, fontSize, metrics);
|
|
138
|
+
};
|
|
139
|
+
export const processFontMetrics = (fontFamily, fontSize, metrics) => {
|
|
140
|
+
const label = fontFamily + fontSize;
|
|
141
|
+
const normalized = normalizeFontMetrics(metrics, fontSize);
|
|
142
|
+
normalizedMetrics.set(label, normalized);
|
|
143
|
+
return normalized;
|
|
144
|
+
};
|
|
145
|
+
export const measureText = (text, fontFamily, letterSpacing) => {
|
|
146
|
+
if (letterSpacing === 0) {
|
|
147
|
+
return measureContext.measureText(text).width;
|
|
148
|
+
}
|
|
149
|
+
if (hasZeroWidthSpace(text) === false) {
|
|
150
|
+
return measureContext.measureText(text).width + letterSpacing * text.length;
|
|
151
|
+
}
|
|
152
|
+
return text.split('').reduce((acc, char) => {
|
|
153
|
+
if (hasZeroWidthSpace(char) === true) {
|
|
154
|
+
return acc;
|
|
155
|
+
}
|
|
156
|
+
return acc + measureContext.measureText(char).width + letterSpacing;
|
|
157
|
+
}, 0);
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Get the font metrics for a font face.
|
|
161
|
+
*
|
|
162
|
+
* @remarks
|
|
163
|
+
* This function will attempt to grab the explicitly defined metrics from the
|
|
164
|
+
* font face first. If the font face does not have metrics defined, it will
|
|
165
|
+
* attempt to calculate the metrics using the browser's measureText method.
|
|
166
|
+
*
|
|
167
|
+
* If the browser does not support the font metrics API, it will use some
|
|
168
|
+
* default values.
|
|
169
|
+
*
|
|
170
|
+
* @param context
|
|
171
|
+
* @param fontFace
|
|
172
|
+
* @param fontSize
|
|
173
|
+
* @returns
|
|
174
|
+
*/
|
|
175
|
+
export function calculateFontMetrics(fontFamily, fontSize) {
|
|
176
|
+
// If the font face doesn't have metrics defined, we fallback to using the
|
|
177
|
+
// browser's measureText method to calculate take a best guess at the font
|
|
178
|
+
// actual font's metrics.
|
|
179
|
+
// - fontBoundingBox[Ascent|Descent] is the best estimate but only supported
|
|
180
|
+
// in Chrome 87+ (2020), Firefox 116+ (2023), and Safari 11.1+ (2018).
|
|
181
|
+
// - It is an estimate as it can vary between browsers.
|
|
182
|
+
// - actualBoundingBox[Ascent|Descent] is less accurate and supported in
|
|
183
|
+
// Chrome 77+ (2019), Firefox 74+ (2020), and Safari 11.1+ (2018).
|
|
184
|
+
// - If neither are supported, we'll use some default values which will
|
|
185
|
+
// get text on the screen but likely not be great.
|
|
186
|
+
// NOTE: It's been decided not to rely on fontBoundingBox[Ascent|Descent]
|
|
187
|
+
// as it's browser support is limited and it also tends to produce higher than
|
|
188
|
+
// expected values. It is instead HIGHLY RECOMMENDED that developers provide
|
|
189
|
+
// explicit metrics in the font face definition.
|
|
190
|
+
const metrics = measureContext.measureText('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
|
|
191
|
+
console.warn(`Font metrics not provided for Canvas Web font ${fontFamily}. ` +
|
|
192
|
+
'Using fallback values. It is HIGHLY recommended you use the latest ' +
|
|
193
|
+
'version of the Lightning 3 `msdf-generator` tool to extract the default ' +
|
|
194
|
+
'metrics for the font and provide them in the Canvas Web font definition.');
|
|
195
|
+
const ascender = metrics.fontBoundingBoxAscent ?? metrics.actualBoundingBoxAscent ?? 0;
|
|
196
|
+
const descender = metrics.fontBoundingBoxDescent ?? metrics.actualBoundingBoxDescent ?? 0;
|
|
197
|
+
return {
|
|
198
|
+
ascender,
|
|
199
|
+
descender: -descender,
|
|
200
|
+
lineGap: (metrics.emHeightAscent ?? 0) +
|
|
201
|
+
(metrics.emHeightDescent ?? 0) -
|
|
202
|
+
(ascender + descender),
|
|
203
|
+
unitsPerEm: (metrics.emHeightAscent ?? 0) + (metrics.emHeightDescent ?? 0),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=CanvasFontHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CanvasFontHandler.js","sourceRoot":"","sources":["../../../../src/core/text-rendering/CanvasFontHandler.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,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AI,CAAC,CAAC;KAC3E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Stage } from '../Stage.js';
|
|
2
|
+
import type { TextRenderInfo } from './TextRenderer.js';
|
|
3
|
+
import * as CanvasFontHandler from './CanvasFontHandler.js';
|
|
4
|
+
import type { CoreTextNodeProps } from '../CoreTextNode.js';
|
|
5
|
+
/**
|
|
6
|
+
* Canvas Text Renderer - implements TextRenderer interface
|
|
7
|
+
*/
|
|
8
|
+
declare const CanvasTextRenderer: {
|
|
9
|
+
type: "canvas";
|
|
10
|
+
font: typeof CanvasFontHandler;
|
|
11
|
+
renderText: (props: CoreTextNodeProps) => TextRenderInfo;
|
|
12
|
+
addQuads: () => Float32Array | null;
|
|
13
|
+
renderQuads: () => void;
|
|
14
|
+
init: (stage: Stage) => void;
|
|
15
|
+
clearLayoutCache: () => void;
|
|
16
|
+
};
|
|
17
|
+
export default CanvasTextRenderer;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { assertTruthy } from '../../utils.js';
|
|
2
|
+
import * as CanvasFontHandler from './CanvasFontHandler.js';
|
|
3
|
+
import { hasZeroWidthSpace } from './Utils.js';
|
|
4
|
+
import { mapTextLayout } from './TextLayoutEngine.js';
|
|
5
|
+
const MAX_TEXTURE_DIMENSION = 4096;
|
|
6
|
+
const type = 'canvas';
|
|
7
|
+
let canvas = null;
|
|
8
|
+
let context = null;
|
|
9
|
+
// Separate canvas and context for text measurements
|
|
10
|
+
let measureCanvas = null;
|
|
11
|
+
let measureContext = null;
|
|
12
|
+
// Cache for text layout calculations
|
|
13
|
+
const layoutCache = new Map();
|
|
14
|
+
// Initialize the Text Renderer
|
|
15
|
+
const init = (stage) => {
|
|
16
|
+
const dpr = stage.options.devicePhysicalPixelRatio;
|
|
17
|
+
// Drawing canvas and context
|
|
18
|
+
canvas = stage.platform.createCanvas();
|
|
19
|
+
context = canvas.getContext('2d', { willReadFrequently: true });
|
|
20
|
+
context.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
21
|
+
context.textRendering = 'optimizeSpeed';
|
|
22
|
+
// Separate measuring canvas and context
|
|
23
|
+
measureCanvas = stage.platform.createCanvas();
|
|
24
|
+
measureContext = measureCanvas.getContext('2d');
|
|
25
|
+
measureContext.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
26
|
+
measureContext.textRendering = 'optimizeSpeed';
|
|
27
|
+
// Set up a minimal size for the measuring canvas since we only use it for measurements
|
|
28
|
+
measureCanvas.width = 1;
|
|
29
|
+
measureCanvas.height = 1;
|
|
30
|
+
CanvasFontHandler.init(context, measureContext);
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Canvas text renderer
|
|
34
|
+
*
|
|
35
|
+
* @param stage - Stage instance for font resolution
|
|
36
|
+
* @param props - Text rendering properties
|
|
37
|
+
* @returns Object containing ImageData and dimensions
|
|
38
|
+
*/
|
|
39
|
+
const renderText = (props) => {
|
|
40
|
+
assertTruthy(canvas, 'Canvas is not initialized');
|
|
41
|
+
assertTruthy(context, 'Canvas context is not available');
|
|
42
|
+
assertTruthy(measureContext, 'Canvas measureContext is not available');
|
|
43
|
+
// Extract already normalized properties
|
|
44
|
+
const { text, fontFamily, fontStyle, fontSize, textAlign, maxLines, lineHeight, verticalAlign, overflowSuffix, maxWidth, maxHeight, wordBreak, } = props;
|
|
45
|
+
const font = `${fontStyle} ${fontSize}px Unknown, ${fontFamily}`;
|
|
46
|
+
// Get font metrics and calculate line height
|
|
47
|
+
measureContext.font = font;
|
|
48
|
+
measureContext.textBaseline = 'hanging';
|
|
49
|
+
const metrics = CanvasFontHandler.getFontMetrics(fontFamily, fontSize);
|
|
50
|
+
const letterSpacing = props.letterSpacing;
|
|
51
|
+
const [lines, remainingLines, hasRemainingText, bareLineHeight, lineHeightPx, effectiveWidth, effectiveHeight,] = mapTextLayout(CanvasFontHandler.measureText, metrics, text, textAlign, fontFamily, lineHeight, overflowSuffix, wordBreak, letterSpacing, maxLines, maxWidth, maxHeight);
|
|
52
|
+
const lineAmount = lines.length;
|
|
53
|
+
const canvasW = Math.ceil(effectiveWidth);
|
|
54
|
+
const canvasH = Math.ceil(effectiveHeight);
|
|
55
|
+
canvas.width = canvasW;
|
|
56
|
+
canvas.height = canvasH;
|
|
57
|
+
context.fillStyle = 'white';
|
|
58
|
+
context.font = font;
|
|
59
|
+
context.textBaseline = 'hanging';
|
|
60
|
+
// Performance optimization for large fonts
|
|
61
|
+
if (fontSize >= 128) {
|
|
62
|
+
context.globalAlpha = 0.01;
|
|
63
|
+
context.fillRect(0, 0, 0.01, 0.01);
|
|
64
|
+
context.globalAlpha = 1.0;
|
|
65
|
+
}
|
|
66
|
+
for (let i = 0; i < lineAmount; i++) {
|
|
67
|
+
const line = lines[i];
|
|
68
|
+
const textLine = line[0];
|
|
69
|
+
let currentX = Math.ceil(line[3]);
|
|
70
|
+
const currentY = Math.ceil(line[4]);
|
|
71
|
+
if (letterSpacing === 0) {
|
|
72
|
+
context.fillText(textLine, currentX, currentY);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const textLineLength = textLine.length;
|
|
76
|
+
for (let j = 0; j < textLineLength; j++) {
|
|
77
|
+
const char = textLine.charAt(j);
|
|
78
|
+
if (hasZeroWidthSpace(char) === true) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
context.fillText(char, currentX, currentY);
|
|
82
|
+
currentX += CanvasFontHandler.measureText(char, fontFamily, letterSpacing);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Extract image data
|
|
87
|
+
let imageData = null;
|
|
88
|
+
if (canvas.width > 0 && canvas.height > 0) {
|
|
89
|
+
imageData = context.getImageData(0, 0, canvasW, canvasH);
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
imageData,
|
|
93
|
+
width: effectiveWidth,
|
|
94
|
+
height: effectiveHeight,
|
|
95
|
+
remainingLines,
|
|
96
|
+
hasRemainingText,
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Generate a cache key for text layout calculations
|
|
101
|
+
*/
|
|
102
|
+
function generateLayoutCacheKey(text, fontFamily, fontSize, fontStyle, wordWrap, wordWrapWidth, letterSpacing, maxLines, overflowSuffix) {
|
|
103
|
+
return `${text}-${fontFamily}-${fontSize}-${fontStyle}-${wordWrap}-${wordWrapWidth}-${letterSpacing}-${maxLines}-${overflowSuffix}`;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Clear layout cache for memory management
|
|
107
|
+
*/
|
|
108
|
+
const clearLayoutCache = () => {
|
|
109
|
+
layoutCache.clear();
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Add quads for rendering (Canvas doesn't use quads)
|
|
113
|
+
*/
|
|
114
|
+
const addQuads = () => {
|
|
115
|
+
// Canvas renderer doesn't use quad-based rendering
|
|
116
|
+
// Return null for interface compatibility
|
|
117
|
+
return null;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Render quads for Canvas renderer (Canvas doesn't use quad-based rendering)
|
|
121
|
+
*/
|
|
122
|
+
const renderQuads = () => {
|
|
123
|
+
// Canvas renderer doesn't use quad-based rendering
|
|
124
|
+
// This method is for interface compatibility only
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Canvas Text Renderer - implements TextRenderer interface
|
|
128
|
+
*/
|
|
129
|
+
const CanvasTextRenderer = {
|
|
130
|
+
type,
|
|
131
|
+
font: CanvasFontHandler,
|
|
132
|
+
renderText,
|
|
133
|
+
addQuads,
|
|
134
|
+
renderQuads,
|
|
135
|
+
init,
|
|
136
|
+
clearLayoutCache,
|
|
137
|
+
};
|
|
138
|
+
export default CanvasTextRenderer;
|
|
139
|
+
//# sourceMappingURL=CanvasTextRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CanvasTextRenderer.js","sourceRoot":"","sources":["../../../../src/core/text-rendering/CanvasTextRender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