@lightningjs/renderer 2.14.2 → 2.14.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (310) hide show
  1. package/LICENSE +202 -202
  2. package/NOTICE +3 -3
  3. package/README.md +147 -147
  4. package/dist/src/core/CoreTextNode.js +2 -2
  5. package/dist/src/core/CoreTextNode.js.map +1 -1
  6. package/dist/src/core/CoreTextureManager.d.ts +4 -3
  7. package/dist/src/core/CoreTextureManager.js +33 -23
  8. package/dist/src/core/CoreTextureManager.js.map +1 -1
  9. package/dist/src/core/Stage.js +7 -2
  10. package/dist/src/core/Stage.js.map +1 -1
  11. package/dist/src/core/TextureMemoryManager.d.ts +1 -1
  12. package/dist/src/core/TextureMemoryManager.js +25 -2
  13. package/dist/src/core/TextureMemoryManager.js.map +1 -1
  14. package/dist/src/core/renderers/CoreContextTexture.d.ts +1 -1
  15. package/dist/src/core/renderers/canvas/CanvasCoreTexture.d.ts +1 -1
  16. package/dist/src/core/renderers/canvas/CanvasCoreTexture.js +7 -6
  17. package/dist/src/core/renderers/canvas/CanvasCoreTexture.js.map +1 -1
  18. package/dist/src/core/renderers/webgl/WebGlCoreCtxRenderTexture.js +3 -0
  19. package/dist/src/core/renderers/webgl/WebGlCoreCtxRenderTexture.js.map +1 -1
  20. package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.d.ts +5 -6
  21. package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.js +30 -18
  22. package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.js.map +1 -1
  23. package/dist/src/core/renderers/webgl/WebGlCoreShader.destroy.js +2 -0
  24. package/dist/src/core/renderers/webgl/WebGlCoreShader.destroy.js.map +1 -0
  25. package/dist/src/core/renderers/webgl/shaders/DefaultShader.js +45 -45
  26. package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.js +61 -61
  27. package/dist/src/core/renderers/webgl/shaders/DynamicShader.js +93 -93
  28. package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.js +63 -63
  29. package/dist/src/core/renderers/webgl/shaders/SdfShader.js +62 -62
  30. package/dist/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.js +15 -15
  31. package/dist/src/core/renderers/webgl/shaders/effects/BorderEffect.js +6 -6
  32. package/dist/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.js +15 -15
  33. package/dist/src/core/renderers/webgl/shaders/effects/BorderRightEffect.js +15 -15
  34. package/dist/src/core/renderers/webgl/shaders/effects/BorderTopEffect.js +15 -15
  35. package/dist/src/core/renderers/webgl/shaders/effects/FadeOutEffect.js +42 -42
  36. package/dist/src/core/renderers/webgl/shaders/effects/GlitchEffect.js +44 -44
  37. package/dist/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.js +3 -3
  38. package/dist/src/core/renderers/webgl/shaders/effects/HolePunchEffect.js +22 -22
  39. package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js +28 -28
  40. package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js +10 -10
  41. package/dist/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.js +37 -37
  42. package/dist/src/core/renderers/webgl/shaders/effects/RadiusEffect.js +19 -19
  43. package/dist/src/core/textures/ImageTexture.d.ts +1 -1
  44. package/dist/src/core/textures/ImageTexture.js +1 -1
  45. package/dist/src/core/textures/ImageTexture.js.map +1 -1
  46. package/dist/src/core/textures/Texture.d.ts +4 -0
  47. package/dist/src/core/textures/Texture.js +9 -3
  48. package/dist/src/core/textures/Texture.js.map +1 -1
  49. package/dist/src/main-api/Renderer.js +1 -1
  50. package/dist/tsconfig.dist.tsbuildinfo +1 -1
  51. package/exports/canvas.ts +39 -39
  52. package/exports/index.ts +89 -89
  53. package/exports/inspector.ts +24 -24
  54. package/exports/utils.ts +44 -44
  55. package/exports/webgl.ts +38 -38
  56. package/package.json +1 -1
  57. package/scripts/please-use-pnpm.js +13 -13
  58. package/src/common/CommonTypes.ts +146 -146
  59. package/src/common/EventEmitter.ts +77 -77
  60. package/src/common/IAnimationController.ts +92 -92
  61. package/src/common/IEventEmitter.ts +28 -28
  62. package/src/core/CoreNode.test.ts +202 -202
  63. package/src/core/CoreNode.ts +2468 -2468
  64. package/src/core/CoreShaderManager.ts +292 -292
  65. package/src/core/CoreTextNode.ts +455 -455
  66. package/src/core/CoreTextureManager.ts +561 -558
  67. package/src/core/Stage.ts +748 -743
  68. package/src/core/TextureMemoryManager.ts +431 -404
  69. package/src/core/animations/AnimationManager.ts +38 -38
  70. package/src/core/animations/CoreAnimation.ts +347 -347
  71. package/src/core/animations/CoreAnimationController.ts +166 -166
  72. package/src/core/lib/ContextSpy.ts +41 -41
  73. package/src/core/lib/ImageWorker.ts +280 -280
  74. package/src/core/lib/Matrix3d.ts +244 -244
  75. package/src/core/lib/RenderCoords.ts +86 -86
  76. package/src/core/lib/WebGlContextWrapper.ts +1332 -1332
  77. package/src/core/lib/textureCompression.ts +152 -152
  78. package/src/core/lib/textureSvg.ts +78 -78
  79. package/src/core/lib/utils.ts +384 -384
  80. package/src/core/lib/validateImageBitmap.ts +76 -76
  81. package/src/core/platform.ts +63 -63
  82. package/src/core/renderers/CoreContextTexture.ts +43 -43
  83. package/src/core/renderers/CoreRenderOp.ts +22 -22
  84. package/src/core/renderers/CoreRenderer.ts +115 -115
  85. package/src/core/renderers/CoreShader.ts +41 -41
  86. package/src/core/renderers/canvas/CanvasCoreRenderer.ts +375 -375
  87. package/src/core/renderers/canvas/CanvasCoreTexture.ts +153 -153
  88. package/src/core/renderers/canvas/internal/C2DShaderUtils.ts +231 -231
  89. package/src/core/renderers/canvas/internal/ColorUtils.ts +69 -69
  90. package/src/core/renderers/canvas/shaders/UnsupportedShader.ts +48 -48
  91. package/src/core/renderers/webgl/WebGlCoreCtxRenderTexture.ts +91 -86
  92. package/src/core/renderers/webgl/WebGlCoreCtxSubTexture.ts +50 -50
  93. package/src/core/renderers/webgl/WebGlCoreCtxTexture.ts +313 -301
  94. package/src/core/renderers/webgl/WebGlCoreRenderOp.ts +125 -125
  95. package/src/core/renderers/webgl/WebGlCoreRenderer.ts +821 -821
  96. package/src/core/renderers/webgl/WebGlCoreShader.ts +365 -365
  97. package/src/core/renderers/webgl/internal/BufferCollection.ts +54 -54
  98. package/src/core/renderers/webgl/internal/RendererUtils.ts +155 -155
  99. package/src/core/renderers/webgl/internal/ShaderUtils.ts +143 -143
  100. package/src/core/renderers/webgl/internal/WebGlUtils.ts +35 -35
  101. package/src/core/renderers/webgl/shaders/DefaultShader.ts +93 -93
  102. package/src/core/renderers/webgl/shaders/DefaultShaderBatched.ts +132 -132
  103. package/src/core/renderers/webgl/shaders/DynamicShader.ts +580 -580
  104. package/src/core/renderers/webgl/shaders/RoundedRectangle.ts +167 -167
  105. package/src/core/renderers/webgl/shaders/SdfShader.ts +204 -204
  106. package/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.ts +101 -101
  107. package/src/core/renderers/webgl/shaders/effects/BorderEffect.ts +87 -87
  108. package/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.ts +101 -101
  109. package/src/core/renderers/webgl/shaders/effects/BorderRightEffect.ts +101 -101
  110. package/src/core/renderers/webgl/shaders/effects/BorderTopEffect.ts +101 -101
  111. package/src/core/renderers/webgl/shaders/effects/EffectUtils.ts +159 -159
  112. package/src/core/renderers/webgl/shaders/effects/FadeOutEffect.ts +127 -127
  113. package/src/core/renderers/webgl/shaders/effects/GlitchEffect.ts +148 -148
  114. package/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.ts +67 -67
  115. package/src/core/renderers/webgl/shaders/effects/HolePunchEffect.ts +157 -157
  116. package/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.ts +171 -171
  117. package/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.ts +168 -168
  118. package/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.ts +187 -187
  119. package/src/core/renderers/webgl/shaders/effects/RadiusEffect.ts +110 -110
  120. package/src/core/renderers/webgl/shaders/effects/ShaderEffect.ts +196 -196
  121. package/src/core/text-rendering/TextRenderingUtils.ts +36 -36
  122. package/src/core/text-rendering/TextTextureRendererUtils.ts +263 -263
  123. package/src/core/text-rendering/TrFontManager.ts +183 -183
  124. package/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.ts +176 -176
  125. package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/FontShaper.ts +139 -139
  126. package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.test.ts +173 -173
  127. package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.ts +171 -171
  128. package/src/core/text-rendering/font-face-types/TrFontFace.ts +187 -187
  129. package/src/core/text-rendering/font-face-types/WebTrFontFace.ts +94 -94
  130. package/src/core/text-rendering/font-face-types/utils.ts +39 -39
  131. package/src/core/text-rendering/renderers/CanvasTextRenderer.ts +509 -509
  132. package/src/core/text-rendering/renderers/LightningTextTextureRenderer.ts +808 -808
  133. package/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.ts +853 -853
  134. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.test.ts +48 -48
  135. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.ts +66 -66
  136. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/SpecialCodepoints.ts +52 -52
  137. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/constants.ts +32 -32
  138. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getStartConditions.ts +117 -117
  139. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.test.ts +133 -133
  140. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.ts +38 -38
  141. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.ts +408 -408
  142. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.test.ts +49 -49
  143. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.ts +52 -52
  144. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.test.ts +205 -205
  145. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.ts +93 -93
  146. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/util.ts +40 -40
  147. package/src/core/text-rendering/renderers/TextRenderer.ts +557 -557
  148. package/src/core/textures/ColorTexture.ts +102 -102
  149. package/src/core/textures/ImageTexture.ts +400 -399
  150. package/src/core/textures/NoiseTexture.ts +104 -104
  151. package/src/core/textures/RenderTexture.ts +85 -85
  152. package/src/core/textures/SubTexture.ts +205 -205
  153. package/src/core/textures/Texture.ts +376 -367
  154. package/src/core/utils.ts +227 -227
  155. package/src/env.d.ts +7 -7
  156. package/src/main-api/DynamicShaderController.ts +104 -104
  157. package/src/main-api/INode.ts +101 -101
  158. package/src/main-api/Inspector.ts +522 -522
  159. package/src/main-api/Renderer.ts +751 -751
  160. package/src/main-api/ShaderController.ts +80 -80
  161. package/src/main-api/utils.ts +45 -45
  162. package/src/utils.ts +248 -248
  163. package/COPYING +0 -1
  164. package/dist/exports/canvas-shaders.d.ts +0 -10
  165. package/dist/exports/canvas-shaders.js +0 -27
  166. package/dist/exports/canvas-shaders.js.map +0 -1
  167. package/dist/exports/webgl-shaders.d.ts +0 -11
  168. package/dist/exports/webgl-shaders.js +0 -28
  169. package/dist/exports/webgl-shaders.js.map +0 -1
  170. package/dist/src/core/platforms/Platform.d.ts +0 -37
  171. package/dist/src/core/platforms/Platform.js +0 -22
  172. package/dist/src/core/platforms/Platform.js.map +0 -1
  173. package/dist/src/core/platforms/web/WebPlatform.d.ts +0 -9
  174. package/dist/src/core/platforms/web/WebPlatform.js +0 -58
  175. package/dist/src/core/platforms/web/WebPlatform.js.map +0 -1
  176. package/dist/src/core/renderers/CoreShaderNode.d.ts +0 -58
  177. package/dist/src/core/renderers/CoreShaderNode.js +0 -104
  178. package/dist/src/core/renderers/CoreShaderNode.js.map +0 -1
  179. package/dist/src/core/renderers/CoreShaderProgram.d.ts +0 -4
  180. package/dist/src/core/renderers/CoreShaderProgram.js +0 -20
  181. package/dist/src/core/renderers/CoreShaderProgram.js.map +0 -1
  182. package/dist/src/core/renderers/canvas/CanvasRenderer.d.ts +0 -36
  183. package/dist/src/core/renderers/canvas/CanvasRenderer.js +0 -212
  184. package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +0 -1
  185. package/dist/src/core/renderers/canvas/CanvasShaderNode.d.ts +0 -21
  186. package/dist/src/core/renderers/canvas/CanvasShaderNode.js +0 -60
  187. package/dist/src/core/renderers/canvas/CanvasShaderNode.js.map +0 -1
  188. package/dist/src/core/renderers/canvas/CanvasTexture.d.ts +0 -16
  189. package/dist/src/core/renderers/canvas/CanvasTexture.js +0 -124
  190. package/dist/src/core/renderers/canvas/CanvasTexture.js.map +0 -1
  191. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.d.ts +0 -12
  192. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js +0 -55
  193. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js.map +0 -1
  194. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.d.ts +0 -9
  195. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js +0 -38
  196. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js.map +0 -1
  197. package/dist/src/core/renderers/webgl/WebGlCtxTexture.d.ts +0 -57
  198. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js +0 -227
  199. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js.map +0 -1
  200. package/dist/src/core/renderers/webgl/WebGlRenderOp.d.ts +0 -44
  201. package/dist/src/core/renderers/webgl/WebGlRenderOp.js +0 -118
  202. package/dist/src/core/renderers/webgl/WebGlRenderOp.js.map +0 -1
  203. package/dist/src/core/renderers/webgl/WebGlRenderer.d.ts +0 -135
  204. package/dist/src/core/renderers/webgl/WebGlRenderer.js +0 -571
  205. package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +0 -1
  206. package/dist/src/core/renderers/webgl/WebGlShaderNode.d.ts +0 -222
  207. package/dist/src/core/renderers/webgl/WebGlShaderNode.js +0 -334
  208. package/dist/src/core/renderers/webgl/WebGlShaderNode.js.map +0 -1
  209. package/dist/src/core/renderers/webgl/WebGlShaderProgram.d.ts +0 -35
  210. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js +0 -201
  211. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +0 -1
  212. package/dist/src/core/shaders/canvas/Border.d.ts +0 -9
  213. package/dist/src/core/shaders/canvas/Border.js +0 -57
  214. package/dist/src/core/shaders/canvas/Border.js.map +0 -1
  215. package/dist/src/core/shaders/canvas/HolePunch.d.ts +0 -7
  216. package/dist/src/core/shaders/canvas/HolePunch.js +0 -38
  217. package/dist/src/core/shaders/canvas/HolePunch.js.map +0 -1
  218. package/dist/src/core/shaders/canvas/LinearGradient.d.ts +0 -10
  219. package/dist/src/core/shaders/canvas/LinearGradient.js +0 -46
  220. package/dist/src/core/shaders/canvas/LinearGradient.js.map +0 -1
  221. package/dist/src/core/shaders/canvas/RadialGradient.d.ts +0 -11
  222. package/dist/src/core/shaders/canvas/RadialGradient.js +0 -68
  223. package/dist/src/core/shaders/canvas/RadialGradient.js.map +0 -1
  224. package/dist/src/core/shaders/canvas/Rounded.d.ts +0 -7
  225. package/dist/src/core/shaders/canvas/Rounded.js +0 -33
  226. package/dist/src/core/shaders/canvas/Rounded.js.map +0 -1
  227. package/dist/src/core/shaders/canvas/RoundedWithBorder.d.ts +0 -7
  228. package/dist/src/core/shaders/canvas/RoundedWithBorder.js +0 -41
  229. package/dist/src/core/shaders/canvas/RoundedWithBorder.js.map +0 -1
  230. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.d.ts +0 -8
  231. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js +0 -39
  232. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js.map +0 -1
  233. package/dist/src/core/shaders/canvas/RoundedWithShadow.d.ts +0 -7
  234. package/dist/src/core/shaders/canvas/RoundedWithShadow.js +0 -38
  235. package/dist/src/core/shaders/canvas/RoundedWithShadow.js.map +0 -1
  236. package/dist/src/core/shaders/canvas/Shadow.d.ts +0 -8
  237. package/dist/src/core/shaders/canvas/Shadow.js +0 -31
  238. package/dist/src/core/shaders/canvas/Shadow.js.map +0 -1
  239. package/dist/src/core/shaders/canvas/utils/render.d.ts +0 -5
  240. package/dist/src/core/shaders/canvas/utils/render.js +0 -84
  241. package/dist/src/core/shaders/canvas/utils/render.js.map +0 -1
  242. package/dist/src/core/shaders/templates/BorderTemplate.d.ts +0 -37
  243. package/dist/src/core/shaders/templates/BorderTemplate.js +0 -73
  244. package/dist/src/core/shaders/templates/BorderTemplate.js.map +0 -1
  245. package/dist/src/core/shaders/templates/HolePunchTemplate.d.ts +0 -46
  246. package/dist/src/core/shaders/templates/HolePunchTemplate.js +0 -35
  247. package/dist/src/core/shaders/templates/HolePunchTemplate.js.map +0 -1
  248. package/dist/src/core/shaders/templates/LinearGradientTemplate.d.ts +0 -23
  249. package/dist/src/core/shaders/templates/LinearGradientTemplate.js +0 -47
  250. package/dist/src/core/shaders/templates/LinearGradientTemplate.js.map +0 -1
  251. package/dist/src/core/shaders/templates/RadialGradientTemplate.d.ts +0 -31
  252. package/dist/src/core/shaders/templates/RadialGradientTemplate.js +0 -49
  253. package/dist/src/core/shaders/templates/RadialGradientTemplate.js.map +0 -1
  254. package/dist/src/core/shaders/templates/RoundedTemplate.d.ts +0 -29
  255. package/dist/src/core/shaders/templates/RoundedTemplate.js +0 -67
  256. package/dist/src/core/shaders/templates/RoundedTemplate.js.map +0 -1
  257. package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.d.ts +0 -7
  258. package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.js +0 -24
  259. package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.js.map +0 -1
  260. package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.d.ts +0 -6
  261. package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.js +0 -23
  262. package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.js.map +0 -1
  263. package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.d.ts +0 -6
  264. package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.js +0 -23
  265. package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.js.map +0 -1
  266. package/dist/src/core/shaders/templates/ShadowTemplate.d.ts +0 -34
  267. package/dist/src/core/shaders/templates/ShadowTemplate.js +0 -66
  268. package/dist/src/core/shaders/templates/ShadowTemplate.js.map +0 -1
  269. package/dist/src/core/shaders/templates/shaderUtils.d.ts +0 -5
  270. package/dist/src/core/shaders/templates/shaderUtils.js +0 -41
  271. package/dist/src/core/shaders/templates/shaderUtils.js.map +0 -1
  272. package/dist/src/core/shaders/webgl/Border.d.ts +0 -3
  273. package/dist/src/core/shaders/webgl/Border.js +0 -110
  274. package/dist/src/core/shaders/webgl/Border.js.map +0 -1
  275. package/dist/src/core/shaders/webgl/Default.d.ts +0 -2
  276. package/dist/src/core/shaders/webgl/Default.js +0 -86
  277. package/dist/src/core/shaders/webgl/Default.js.map +0 -1
  278. package/dist/src/core/shaders/webgl/DefaultBatched.d.ts +0 -2
  279. package/dist/src/core/shaders/webgl/DefaultBatched.js +0 -104
  280. package/dist/src/core/shaders/webgl/DefaultBatched.js.map +0 -1
  281. package/dist/src/core/shaders/webgl/HolePunch.d.ts +0 -3
  282. package/dist/src/core/shaders/webgl/HolePunch.js +0 -64
  283. package/dist/src/core/shaders/webgl/HolePunch.js.map +0 -1
  284. package/dist/src/core/shaders/webgl/LinearGradient.d.ts +0 -3
  285. package/dist/src/core/shaders/webgl/LinearGradient.js +0 -75
  286. package/dist/src/core/shaders/webgl/LinearGradient.js.map +0 -1
  287. package/dist/src/core/shaders/webgl/RadialGradient.d.ts +0 -3
  288. package/dist/src/core/shaders/webgl/RadialGradient.js +0 -73
  289. package/dist/src/core/shaders/webgl/RadialGradient.js.map +0 -1
  290. package/dist/src/core/shaders/webgl/Rounded.d.ts +0 -7
  291. package/dist/src/core/shaders/webgl/Rounded.js +0 -86
  292. package/dist/src/core/shaders/webgl/Rounded.js.map +0 -1
  293. package/dist/src/core/shaders/webgl/RoundedWithBorder.d.ts +0 -3
  294. package/dist/src/core/shaders/webgl/RoundedWithBorder.js +0 -129
  295. package/dist/src/core/shaders/webgl/RoundedWithBorder.js.map +0 -1
  296. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.d.ts +0 -3
  297. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +0 -149
  298. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js.map +0 -1
  299. package/dist/src/core/shaders/webgl/RoundedWithShadow.d.ts +0 -3
  300. package/dist/src/core/shaders/webgl/RoundedWithShadow.js +0 -84
  301. package/dist/src/core/shaders/webgl/RoundedWithShadow.js.map +0 -1
  302. package/dist/src/core/shaders/webgl/SdfShader.d.ts +0 -32
  303. package/dist/src/core/shaders/webgl/SdfShader.js +0 -116
  304. package/dist/src/core/shaders/webgl/SdfShader.js.map +0 -1
  305. package/dist/src/core/shaders/webgl/Shadow.d.ts +0 -3
  306. package/dist/src/core/shaders/webgl/Shadow.js +0 -110
  307. package/dist/src/core/shaders/webgl/Shadow.js.map +0 -1
  308. package/dist/src/core/temp.js +0 -77
  309. package/dist/src/core/temp.js.map +0 -1
  310. /package/dist/src/core/{temp.d.ts → renderers/webgl/WebGlCoreShader.destroy.d.ts} +0 -0
@@ -1,558 +1,561 @@
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
-
20
- import { ImageWorkerManager } from './lib/ImageWorker.js';
21
- import type { CoreRenderer } from './renderers/CoreRenderer.js';
22
- import { ColorTexture } from './textures/ColorTexture.js';
23
- import { ImageTexture } from './textures/ImageTexture.js';
24
- import { NoiseTexture } from './textures/NoiseTexture.js';
25
- import { SubTexture } from './textures/SubTexture.js';
26
- import { RenderTexture } from './textures/RenderTexture.js';
27
- import { TextureType, type Texture } from './textures/Texture.js';
28
- import { EventEmitter } from '../common/EventEmitter.js';
29
- import { getTimeStamp } from './platform.js';
30
- import type { Stage } from './Stage.js';
31
- import {
32
- validateCreateImageBitmap,
33
- type CreateImageBitmapSupport,
34
- } from './lib/validateImageBitmap.js';
35
-
36
- /**
37
- * Augmentable map of texture class types
38
- *
39
- * @remarks
40
- * This interface can be augmented by other modules/apps to add additional
41
- * texture types. The ones included directly here are the ones that are
42
- * included in the core library.
43
- */
44
- export interface TextureMap {
45
- ColorTexture: typeof ColorTexture;
46
- ImageTexture: typeof ImageTexture;
47
- NoiseTexture: typeof NoiseTexture;
48
- SubTexture: typeof SubTexture;
49
- RenderTexture: typeof RenderTexture;
50
- }
51
-
52
- export type ExtractProps<Type> = Type extends { z$__type__Props: infer Props }
53
- ? Props
54
- : never;
55
-
56
- /**
57
- * Contains information about the texture manager's internal state
58
- * for debugging purposes.
59
- */
60
- export interface TextureManagerDebugInfo {
61
- keyCacheSize: number;
62
- }
63
-
64
- export interface TextureManagerSettings {
65
- numImageWorkers: number;
66
- createImageBitmapSupport: 'auto' | 'basic' | 'options' | 'full';
67
- }
68
-
69
- export type ResizeModeOptions =
70
- | {
71
- /**
72
- * Specifies that the image should be resized to cover the specified dimensions.
73
- */
74
- type: 'cover';
75
- /**
76
- * The horizontal clipping position
77
- * To clip the left, set clipX to 0. To clip the right, set clipX to 1.
78
- * clipX 0.5 will clip a equal amount from left and right
79
- *
80
- * @defaultValue 0.5
81
- */
82
- clipX?: number;
83
- /**
84
- * The vertical clipping position
85
- * To clip the top, set clipY to 0. To clip the bottom, set clipY to 1.
86
- * clipY 0.5 will clip a equal amount from top and bottom
87
- *
88
- * @defaultValue 0.5
89
- */
90
- clipY?: number;
91
- }
92
- | {
93
- /**
94
- * Specifies that the image should be resized to fit within the specified dimensions.
95
- */
96
- type: 'contain';
97
- };
98
-
99
- /**
100
- * Universal options for all texture types
101
- *
102
- * @remarks
103
- * Texture Options provide a way to specify options that are relevant to the
104
- * texture loading process (including caching) and specifically for how a
105
- * texture is rendered within a specific Node (or set of Nodes).
106
- *
107
- * They are not used in determining the cache key for a texture (except if
108
- * the `cacheKey` option is provided explicitly to oveerride the default
109
- * cache key for the texture instance) nor are they stored/referenced within
110
- * the texture instance itself. Instead, the options are stored/referenced
111
- * within individual Nodes. So a single texture instance can be used in
112
- * multiple Nodes each using a different set of options.
113
- */
114
- export interface TextureOptions {
115
- /**
116
- * Preload the texture immediately even if it's not being rendered to the
117
- * screen.
118
- *
119
- * @remarks
120
- * This allows the texture to be used immediately without any delay when it
121
- * is first needed for rendering. Otherwise the loading process will start
122
- * when the texture is first rendered, which may cause a delay in that texture
123
- * being shown properly.
124
- *
125
- * @defaultValue `false`
126
- */
127
- preload?: boolean;
128
-
129
- /**
130
- * Prevent clean up of the texture when it is no longer being used.
131
- *
132
- * @remarks
133
- * This is useful when you want to keep the texture in memory for later use.
134
- * Regardless of whether the texture is being used or not, it will not be
135
- * cleaned up.
136
- *
137
- * @defaultValue `false`
138
- */
139
- preventCleanup?: boolean;
140
-
141
- /**
142
- * Flip the texture horizontally when rendering
143
- *
144
- * @defaultValue `false`
145
- */
146
- flipX?: boolean;
147
-
148
- /**
149
- * Flip the texture vertically when rendering
150
- *
151
- * @defaultValue `false`
152
- */
153
- flipY?: boolean;
154
-
155
- /**
156
- * You can use resizeMode to determine the clipping automatically from the width
157
- * and height of the source texture. This can be convenient if you are unsure about
158
- * the exact image sizes but want the image to cover a specific area.
159
- *
160
- * The resize modes cover and contain are supported
161
- */
162
- resizeMode?: ResizeModeOptions;
163
- }
164
-
165
- export class CoreTextureManager extends EventEmitter {
166
- /**
167
- * Map of textures by cache key
168
- */
169
- keyCache: Map<string, Texture> = new Map();
170
-
171
- /**
172
- * Map of cache keys by texture
173
- */
174
- inverseKeyCache: WeakMap<Texture, string> = new WeakMap();
175
-
176
- /**
177
- * Map of texture constructors by their type name
178
- */
179
- txConstructors: Partial<TextureMap> = {};
180
-
181
- private priorityQueue: Array<Texture> = [];
182
- private uploadTextureQueue: Array<Texture> = [];
183
- private initialized = false;
184
- private stage: Stage;
185
- private numImageWorkers: number;
186
-
187
- imageWorkerManager: ImageWorkerManager | null = null;
188
- hasCreateImageBitmap = !!self.createImageBitmap;
189
- imageBitmapSupported = {
190
- basic: false,
191
- options: false,
192
- full: false,
193
- };
194
-
195
- hasWorker = !!self.Worker;
196
- /**
197
- * Renderer that this texture manager is associated with
198
- *
199
- * @remarks
200
- * This MUST be set before the texture manager is used. Otherwise errors
201
- * will occur when using the texture manager.
202
- */
203
- renderer!: CoreRenderer;
204
-
205
- /**
206
- * The current frame time in milliseconds
207
- *
208
- * @remarks
209
- * This is used to populate the `lastRenderableChangeTime` property of
210
- * {@link Texture} instances when their renderable state changes.
211
- *
212
- * Set by stage via `updateFrameTime` method.
213
- */
214
- frameTime = 0;
215
-
216
- constructor(stage: Stage, settings: TextureManagerSettings) {
217
- super();
218
-
219
- const { numImageWorkers, createImageBitmapSupport } = settings;
220
- this.stage = stage;
221
- this.numImageWorkers = numImageWorkers;
222
-
223
- if (createImageBitmapSupport === 'auto') {
224
- validateCreateImageBitmap()
225
- .then((result) => {
226
- this.initialize(result);
227
- })
228
- .catch(() => {
229
- console.warn(
230
- '[Lightning] createImageBitmap is not supported on this browser. ImageTexture will be slower.',
231
- );
232
-
233
- // initialized without image worker manager and createImageBitmap
234
- this.initialized = true;
235
- this.emit('initialized');
236
- });
237
- } else {
238
- this.initialize({
239
- basic: createImageBitmapSupport === 'basic',
240
- options: createImageBitmapSupport === 'options',
241
- full: createImageBitmapSupport === 'full',
242
- });
243
- }
244
-
245
- this.registerTextureType('ImageTexture', ImageTexture);
246
- this.registerTextureType('ColorTexture', ColorTexture);
247
- this.registerTextureType('NoiseTexture', NoiseTexture);
248
- this.registerTextureType('SubTexture', SubTexture);
249
- this.registerTextureType('RenderTexture', RenderTexture);
250
- }
251
-
252
- registerTextureType<Type extends keyof TextureMap>(
253
- textureType: Type,
254
- textureClass: TextureMap[Type],
255
- ): void {
256
- this.txConstructors[textureType] = textureClass;
257
- }
258
-
259
- private initialize(support: CreateImageBitmapSupport) {
260
- this.hasCreateImageBitmap =
261
- support.basic || support.options || support.full;
262
- this.imageBitmapSupported = support;
263
-
264
- if (!this.hasCreateImageBitmap) {
265
- console.warn(
266
- '[Lightning] createImageBitmap is not supported on this browser. ImageTexture will be slower.',
267
- );
268
- }
269
-
270
- if (
271
- this.hasCreateImageBitmap &&
272
- this.hasWorker &&
273
- this.numImageWorkers > 0
274
- ) {
275
- this.imageWorkerManager = new ImageWorkerManager(
276
- this.numImageWorkers,
277
- support,
278
- );
279
- } else {
280
- console.warn(
281
- '[Lightning] Imageworker is 0 or not supported on this browser. Image loading will be slower.',
282
- );
283
- }
284
-
285
- this.initialized = true;
286
- this.emit('initialized');
287
- }
288
-
289
- /**
290
- * Enqueue a texture for uploading to the GPU.
291
- *
292
- * @param texture - The texture to upload
293
- */
294
- enqueueUploadTexture(texture: Texture): void {
295
- if (this.uploadTextureQueue.includes(texture) === false) {
296
- this.uploadTextureQueue.push(texture);
297
- }
298
- }
299
-
300
- /**
301
- * Create a texture
302
- *
303
- * @param textureType - The type of texture to create
304
- * @param props - The properties to use for the texture
305
- */
306
- createTexture<Type extends keyof TextureMap>(
307
- textureType: Type,
308
- props: ExtractProps<TextureMap[Type]>,
309
- ): InstanceType<TextureMap[Type]> {
310
- let texture: Texture | undefined;
311
- const TextureClass = this.txConstructors[textureType];
312
- if (!TextureClass) {
313
- throw new Error(`Texture type "${textureType}" is not registered`);
314
- }
315
-
316
- const cacheKey = TextureClass.makeCacheKey(props as any);
317
- if (cacheKey && this.keyCache.has(cacheKey)) {
318
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
319
- texture = this.keyCache.get(cacheKey)!;
320
- } else {
321
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
322
- texture = new TextureClass(this, props as any);
323
-
324
- if (cacheKey) {
325
- this.initTextureToCache(texture, cacheKey);
326
- }
327
- }
328
-
329
- return texture as InstanceType<TextureMap[Type]>;
330
- }
331
-
332
- orphanTexture(texture: Texture): void {
333
- // if it is part of the download or upload queue, remove it
334
- this.removeTextureFromQueue(texture);
335
-
336
- if (texture.type === TextureType.subTexture) {
337
- // ignore subtextures
338
- return;
339
- }
340
-
341
- this.stage.txMemManager.addToOrphanedTextures(texture);
342
- }
343
-
344
- /**
345
- * Override loadTexture to use the batched approach.
346
- *
347
- * @param texture - The texture to load
348
- * @param immediate - Whether to prioritize the texture for immediate loading
349
- */
350
- loadTexture(texture: Texture, priority?: boolean): void {
351
- this.stage.txMemManager.removeFromOrphanedTextures(texture);
352
-
353
- if (texture.type === TextureType.subTexture) {
354
- // ignore subtextures - they get loaded through their parent
355
- return;
356
- }
357
-
358
- // if the texture is already loaded, don't load it again
359
- if (
360
- texture.ctxTexture !== undefined &&
361
- texture.ctxTexture.state === 'loaded'
362
- ) {
363
- texture.setState('loaded');
364
- return;
365
- }
366
-
367
- // if the texture is already being processed, don't load it again
368
- if (this.uploadTextureQueue.includes(texture) === true) {
369
- return;
370
- }
371
-
372
- // if the texture is already loading, free it, this can happen if the texture is
373
- // orphaned and then reloaded
374
- if (
375
- texture.ctxTexture !== undefined &&
376
- texture.ctxTexture.state === 'loading'
377
- ) {
378
- texture.free();
379
- }
380
-
381
- // if we're not initialized, just queue the texture into the priority queue
382
- if (this.initialized === false) {
383
- this.priorityQueue.push(texture);
384
- return;
385
- }
386
-
387
- // If the texture failed to load, we need to re-download it.
388
- if (texture.state === 'failed') {
389
- texture.free();
390
- texture.freeTextureData();
391
- }
392
-
393
- texture.setState('loading');
394
-
395
- // Get the texture data
396
- texture
397
- .getTextureData()
398
- .then(() => {
399
- if (texture.state !== 'fetched') {
400
- texture.setState('failed');
401
- return;
402
- }
403
-
404
- // For non-image textures, upload immediately
405
- if (texture.type !== TextureType.image) {
406
- this.uploadTexture(texture);
407
- } else {
408
- // For image textures, queue for throttled upload
409
- // If it's a priority texture, upload it immediately
410
- if (priority === true) {
411
- this.uploadTexture(texture);
412
- } else {
413
- this.enqueueUploadTexture(texture);
414
- }
415
- }
416
- })
417
- .catch((err) => {
418
- console.error(err);
419
- texture.setState('failed');
420
- });
421
- }
422
-
423
- /**
424
- * Upload a texture to the GPU
425
- *
426
- * @param texture Texture to upload
427
- */
428
- uploadTexture(texture: Texture): void {
429
- if (
430
- this.stage.txMemManager.doNotExceedCriticalThreshold === true &&
431
- this.stage.txMemManager.criticalCleanupRequested === true
432
- ) {
433
- // we're at a critical memory threshold, don't upload textures
434
- this.enqueueUploadTexture(texture);
435
- return;
436
- }
437
-
438
- const coreContext = texture.loadCtxTexture();
439
- if (coreContext !== null && coreContext.state === 'loaded') {
440
- texture.setState('loaded');
441
- return;
442
- }
443
-
444
- coreContext.load();
445
- }
446
-
447
- /**
448
- * Check if a texture is being processed
449
- */
450
- isProcessingTexture(texture: Texture): boolean {
451
- return this.uploadTextureQueue.includes(texture) === true;
452
- }
453
-
454
- /**
455
- * Process a limited number of uploads.
456
- *
457
- * @param maxProcessingTime - The maximum processing time in milliseconds
458
- */
459
- processSome(maxProcessingTime: number): void {
460
- if (this.initialized === false) {
461
- return;
462
- }
463
-
464
- const startTime = getTimeStamp();
465
-
466
- // Process priority queue
467
- while (
468
- this.priorityQueue.length > 0 &&
469
- getTimeStamp() - startTime < maxProcessingTime
470
- ) {
471
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
472
- const texture = this.priorityQueue.pop()!;
473
- texture.getTextureData().then(() => {
474
- this.uploadTexture(texture);
475
- });
476
- }
477
-
478
- // Process uploads
479
- while (
480
- this.uploadTextureQueue.length > 0 &&
481
- getTimeStamp() - startTime < maxProcessingTime
482
- ) {
483
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
484
- this.uploadTexture(this.uploadTextureQueue.shift()!);
485
- }
486
- }
487
-
488
- public hasUpdates(): boolean {
489
- return this.uploadTextureQueue.length > 0;
490
- }
491
-
492
- /**
493
- * Initialize a texture to the cache
494
- *
495
- * @param texture Texture to cache
496
- * @param cacheKey Cache key for the texture
497
- */
498
- initTextureToCache(texture: Texture, cacheKey: string) {
499
- const { keyCache, inverseKeyCache } = this;
500
- keyCache.set(cacheKey, texture);
501
- inverseKeyCache.set(texture, cacheKey);
502
- }
503
-
504
- /**
505
- * Get a texture from the cache
506
- *
507
- * @param cacheKey
508
- */
509
- getTextureFromCache(cacheKey: string): Texture | undefined {
510
- return this.keyCache.get(cacheKey);
511
- }
512
-
513
- /**
514
- * Remove a texture from the cache
515
- *
516
- * @remarks
517
- * Called by Texture Cleanup when a texture is freed.
518
- *
519
- * @param texture
520
- */
521
- removeTextureFromCache(texture: Texture) {
522
- const { inverseKeyCache, keyCache } = this;
523
- const cacheKey = inverseKeyCache.get(texture);
524
- if (cacheKey) {
525
- keyCache.delete(cacheKey);
526
- }
527
- }
528
-
529
- /**
530
- * Remove texture from the upload queue
531
- *
532
- * @param texture - The texture to remove
533
- */
534
- removeTextureFromQueue(texture: Texture): void {
535
- const uploadIndex = this.uploadTextureQueue.indexOf(texture);
536
- if (uploadIndex !== -1) {
537
- this.uploadTextureQueue.splice(uploadIndex, 1);
538
- }
539
- }
540
-
541
- /**
542
- * Resolve a parent texture from the cache or fallback to the provided texture.
543
- *
544
- * @param texture - The provided texture to resolve.
545
- * @returns The cached or provided texture.
546
- */
547
- resolveParentTexture(texture: ImageTexture): Texture {
548
- if (!texture?.props) {
549
- return texture;
550
- }
551
-
552
- const cacheKey = ImageTexture.makeCacheKey(texture.props);
553
- const cachedTexture = cacheKey
554
- ? this.getTextureFromCache(cacheKey)
555
- : undefined;
556
- return cachedTexture ?? texture;
557
- }
558
- }
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
+
20
+ import { ImageWorkerManager } from './lib/ImageWorker.js';
21
+ import type { CoreRenderer } from './renderers/CoreRenderer.js';
22
+ import { ColorTexture } from './textures/ColorTexture.js';
23
+ import { ImageTexture } from './textures/ImageTexture.js';
24
+ import { NoiseTexture } from './textures/NoiseTexture.js';
25
+ import { SubTexture } from './textures/SubTexture.js';
26
+ import { RenderTexture } from './textures/RenderTexture.js';
27
+ import { Texture, TextureType } from './textures/Texture.js';
28
+ import { EventEmitter } from '../common/EventEmitter.js';
29
+ import { getTimeStamp } from './platform.js';
30
+ import type { Stage } from './Stage.js';
31
+ import {
32
+ validateCreateImageBitmap,
33
+ type CreateImageBitmapSupport,
34
+ } from './lib/validateImageBitmap.js';
35
+
36
+ /**
37
+ * Augmentable map of texture class types
38
+ *
39
+ * @remarks
40
+ * This interface can be augmented by other modules/apps to add additional
41
+ * texture types. The ones included directly here are the ones that are
42
+ * included in the core library.
43
+ */
44
+ export interface TextureMap {
45
+ ColorTexture: typeof ColorTexture;
46
+ ImageTexture: typeof ImageTexture;
47
+ NoiseTexture: typeof NoiseTexture;
48
+ SubTexture: typeof SubTexture;
49
+ RenderTexture: typeof RenderTexture;
50
+ }
51
+
52
+ export type ExtractProps<Type> = Type extends { z$__type__Props: infer Props }
53
+ ? Props
54
+ : never;
55
+
56
+ /**
57
+ * Contains information about the texture manager's internal state
58
+ * for debugging purposes.
59
+ */
60
+ export interface TextureManagerDebugInfo {
61
+ keyCacheSize: number;
62
+ }
63
+
64
+ export interface TextureManagerSettings {
65
+ numImageWorkers: number;
66
+ createImageBitmapSupport: 'auto' | 'basic' | 'options' | 'full';
67
+ }
68
+
69
+ export type ResizeModeOptions =
70
+ | {
71
+ /**
72
+ * Specifies that the image should be resized to cover the specified dimensions.
73
+ */
74
+ type: 'cover';
75
+ /**
76
+ * The horizontal clipping position
77
+ * To clip the left, set clipX to 0. To clip the right, set clipX to 1.
78
+ * clipX 0.5 will clip a equal amount from left and right
79
+ *
80
+ * @defaultValue 0.5
81
+ */
82
+ clipX?: number;
83
+ /**
84
+ * The vertical clipping position
85
+ * To clip the top, set clipY to 0. To clip the bottom, set clipY to 1.
86
+ * clipY 0.5 will clip a equal amount from top and bottom
87
+ *
88
+ * @defaultValue 0.5
89
+ */
90
+ clipY?: number;
91
+ }
92
+ | {
93
+ /**
94
+ * Specifies that the image should be resized to fit within the specified dimensions.
95
+ */
96
+ type: 'contain';
97
+ };
98
+
99
+ /**
100
+ * Universal options for all texture types
101
+ *
102
+ * @remarks
103
+ * Texture Options provide a way to specify options that are relevant to the
104
+ * texture loading process (including caching) and specifically for how a
105
+ * texture is rendered within a specific Node (or set of Nodes).
106
+ *
107
+ * They are not used in determining the cache key for a texture (except if
108
+ * the `cacheKey` option is provided explicitly to oveerride the default
109
+ * cache key for the texture instance) nor are they stored/referenced within
110
+ * the texture instance itself. Instead, the options are stored/referenced
111
+ * within individual Nodes. So a single texture instance can be used in
112
+ * multiple Nodes each using a different set of options.
113
+ */
114
+ export interface TextureOptions {
115
+ /**
116
+ * Preload the texture immediately even if it's not being rendered to the
117
+ * screen.
118
+ *
119
+ * @remarks
120
+ * This allows the texture to be used immediately without any delay when it
121
+ * is first needed for rendering. Otherwise the loading process will start
122
+ * when the texture is first rendered, which may cause a delay in that texture
123
+ * being shown properly.
124
+ *
125
+ * @defaultValue `false`
126
+ */
127
+ preload?: boolean;
128
+
129
+ /**
130
+ * Prevent clean up of the texture when it is no longer being used.
131
+ *
132
+ * @remarks
133
+ * This is useful when you want to keep the texture in memory for later use.
134
+ * Regardless of whether the texture is being used or not, it will not be
135
+ * cleaned up.
136
+ *
137
+ * @defaultValue `false`
138
+ */
139
+ preventCleanup?: boolean;
140
+
141
+ /**
142
+ * Flip the texture horizontally when rendering
143
+ *
144
+ * @defaultValue `false`
145
+ */
146
+ flipX?: boolean;
147
+
148
+ /**
149
+ * Flip the texture vertically when rendering
150
+ *
151
+ * @defaultValue `false`
152
+ */
153
+ flipY?: boolean;
154
+
155
+ /**
156
+ * You can use resizeMode to determine the clipping automatically from the width
157
+ * and height of the source texture. This can be convenient if you are unsure about
158
+ * the exact image sizes but want the image to cover a specific area.
159
+ *
160
+ * The resize modes cover and contain are supported
161
+ */
162
+ resizeMode?: ResizeModeOptions;
163
+ }
164
+
165
+ export class CoreTextureManager extends EventEmitter {
166
+ /**
167
+ * Map of textures by cache key
168
+ */
169
+ keyCache: Map<string, Texture> = new Map();
170
+
171
+ /**
172
+ * Map of cache keys by texture
173
+ */
174
+ inverseKeyCache: WeakMap<Texture, string> = new WeakMap();
175
+
176
+ /**
177
+ * Map of texture constructors by their type name
178
+ */
179
+ txConstructors: Partial<TextureMap> = {};
180
+
181
+ private priorityQueue: Array<Texture> = [];
182
+ private uploadTextureQueue: Array<Texture> = [];
183
+ private initialized = false;
184
+ private stage: Stage;
185
+ private numImageWorkers: number;
186
+
187
+ imageWorkerManager: ImageWorkerManager | null = null;
188
+ hasCreateImageBitmap = !!self.createImageBitmap;
189
+ imageBitmapSupported = {
190
+ basic: false,
191
+ options: false,
192
+ full: false,
193
+ };
194
+
195
+ hasWorker = !!self.Worker;
196
+ /**
197
+ * Renderer that this texture manager is associated with
198
+ *
199
+ * @remarks
200
+ * This MUST be set before the texture manager is used. Otherwise errors
201
+ * will occur when using the texture manager.
202
+ */
203
+ renderer!: CoreRenderer;
204
+
205
+ /**
206
+ * The current frame time in milliseconds
207
+ *
208
+ * @remarks
209
+ * This is used to populate the `lastRenderableChangeTime` property of
210
+ * {@link Texture} instances when their renderable state changes.
211
+ *
212
+ * Set by stage via `updateFrameTime` method.
213
+ */
214
+ frameTime = 0;
215
+
216
+ constructor(stage: Stage, settings: TextureManagerSettings) {
217
+ super();
218
+
219
+ const { numImageWorkers, createImageBitmapSupport } = settings;
220
+ this.stage = stage;
221
+ this.numImageWorkers = numImageWorkers;
222
+
223
+ if (createImageBitmapSupport === 'auto') {
224
+ validateCreateImageBitmap()
225
+ .then((result) => {
226
+ this.initialize(result);
227
+ })
228
+ .catch(() => {
229
+ console.warn(
230
+ '[Lightning] createImageBitmap is not supported on this browser. ImageTexture will be slower.',
231
+ );
232
+
233
+ // initialized without image worker manager and createImageBitmap
234
+ this.initialized = true;
235
+ this.emit('initialized');
236
+ });
237
+ } else {
238
+ this.initialize({
239
+ basic: createImageBitmapSupport === 'basic',
240
+ options: createImageBitmapSupport === 'options',
241
+ full: createImageBitmapSupport === 'full',
242
+ });
243
+ }
244
+
245
+ this.registerTextureType('ImageTexture', ImageTexture);
246
+ this.registerTextureType('ColorTexture', ColorTexture);
247
+ this.registerTextureType('NoiseTexture', NoiseTexture);
248
+ this.registerTextureType('SubTexture', SubTexture);
249
+ this.registerTextureType('RenderTexture', RenderTexture);
250
+ }
251
+
252
+ registerTextureType<Type extends keyof TextureMap>(
253
+ textureType: Type,
254
+ textureClass: TextureMap[Type],
255
+ ): void {
256
+ this.txConstructors[textureType] = textureClass;
257
+ }
258
+
259
+ private initialize(support: CreateImageBitmapSupport) {
260
+ this.hasCreateImageBitmap =
261
+ support.basic || support.options || support.full;
262
+ this.imageBitmapSupported = support;
263
+
264
+ if (!this.hasCreateImageBitmap) {
265
+ console.warn(
266
+ '[Lightning] createImageBitmap is not supported on this browser. ImageTexture will be slower.',
267
+ );
268
+ }
269
+
270
+ if (
271
+ this.hasCreateImageBitmap &&
272
+ this.hasWorker &&
273
+ this.numImageWorkers > 0
274
+ ) {
275
+ this.imageWorkerManager = new ImageWorkerManager(
276
+ this.numImageWorkers,
277
+ support,
278
+ );
279
+ } else {
280
+ console.warn(
281
+ '[Lightning] Imageworker is 0 or not supported on this browser. Image loading will be slower.',
282
+ );
283
+ }
284
+
285
+ this.initialized = true;
286
+ this.emit('initialized');
287
+ }
288
+
289
+ /**
290
+ * Enqueue a texture for uploading to the GPU.
291
+ *
292
+ * @param texture - The texture to upload
293
+ */
294
+ enqueueUploadTexture(texture: Texture): void {
295
+ if (this.uploadTextureQueue.includes(texture) === false) {
296
+ this.uploadTextureQueue.push(texture);
297
+ }
298
+ }
299
+
300
+ /**
301
+ * Create a texture
302
+ *
303
+ * @param textureType - The type of texture to create
304
+ * @param props - The properties to use for the texture
305
+ */
306
+ createTexture<Type extends keyof TextureMap>(
307
+ textureType: Type,
308
+ props: ExtractProps<TextureMap[Type]>,
309
+ ): InstanceType<TextureMap[Type]> {
310
+ let texture: Texture | undefined;
311
+ const TextureClass = this.txConstructors[textureType];
312
+ if (!TextureClass) {
313
+ throw new Error(`Texture type "${textureType}" is not registered`);
314
+ }
315
+
316
+ const cacheKey = TextureClass.makeCacheKey(props as any);
317
+ if (cacheKey && this.keyCache.has(cacheKey)) {
318
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
319
+ texture = this.keyCache.get(cacheKey)!;
320
+ } else {
321
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
322
+ texture = new TextureClass(this, props as any);
323
+
324
+ if (cacheKey) {
325
+ this.initTextureToCache(texture, cacheKey);
326
+ }
327
+ }
328
+
329
+ return texture as InstanceType<TextureMap[Type]>;
330
+ }
331
+
332
+ orphanTexture(texture: Texture): void {
333
+ // if it is part of the download or upload queue, remove it
334
+ this.removeTextureFromQueue(texture);
335
+
336
+ if (texture.type === TextureType.subTexture) {
337
+ // ignore subtextures
338
+ return;
339
+ }
340
+
341
+ this.stage.txMemManager.addToOrphanedTextures(texture);
342
+ }
343
+
344
+ /**
345
+ * Override loadTexture to use the batched approach.
346
+ *
347
+ * @param texture - The texture to load
348
+ * @param immediate - Whether to prioritize the texture for immediate loading
349
+ */
350
+ loadTexture(texture: Texture, priority?: boolean): void {
351
+ this.stage.txMemManager.removeFromOrphanedTextures(texture);
352
+
353
+ if (texture.type === TextureType.subTexture) {
354
+ // ignore subtextures - they get loaded through their parent
355
+ return;
356
+ }
357
+
358
+ if (texture.state === 'loaded') {
359
+ // if the texture is already loaded, just return
360
+ return;
361
+ }
362
+
363
+ if (Texture.TRANSITIONAL_TEXTURE_STATES.includes(texture.state)) {
364
+ return;
365
+ }
366
+
367
+ // if we're not initialized, just queue the texture into the priority queue
368
+ if (this.initialized === false) {
369
+ this.priorityQueue.push(texture);
370
+ return;
371
+ }
372
+
373
+ // If the texture failed to load, we need to re-download it.
374
+ if (texture.state === 'failed') {
375
+ texture.free();
376
+ texture.freeTextureData();
377
+ }
378
+
379
+ texture.setState('loading');
380
+
381
+ // Get the texture data
382
+ texture
383
+ .getTextureData()
384
+ .then(() => {
385
+ if (texture.state !== 'fetched') {
386
+ texture.setState('failed');
387
+ return;
388
+ }
389
+
390
+ // For non-image textures, upload immediately
391
+ if (texture.type !== TextureType.image) {
392
+ this.uploadTexture(texture).catch((err) => {
393
+ console.error('Failed to upload non-image texture:', err);
394
+ texture.setState('failed');
395
+ });
396
+ } else {
397
+ // For image textures, queue for throttled upload
398
+ // If it's a priority texture, upload it immediately
399
+ if (priority === true) {
400
+ this.uploadTexture(texture).catch((err) => {
401
+ console.error('Failed to upload priority texture:', err);
402
+ texture.setState('failed');
403
+ });
404
+ } else {
405
+ this.enqueueUploadTexture(texture);
406
+ }
407
+ }
408
+ })
409
+ .catch((err) => {
410
+ console.error(err);
411
+ texture.setState('failed');
412
+ });
413
+ }
414
+
415
+ /**
416
+ * Upload a texture to the GPU
417
+ *
418
+ * @param texture Texture to upload
419
+ * @returns Promise that resolves when the texture is fully loaded
420
+ */
421
+ async uploadTexture(texture: Texture): Promise<void> {
422
+ if (
423
+ this.stage.txMemManager.doNotExceedCriticalThreshold === true &&
424
+ this.stage.txMemManager.criticalCleanupRequested === true
425
+ ) {
426
+ // we're at a critical memory threshold, don't upload textures
427
+ this.enqueueUploadTexture(texture);
428
+ return;
429
+ }
430
+
431
+ const coreContext = texture.loadCtxTexture();
432
+ if (coreContext !== null && coreContext.state === 'loaded') {
433
+ texture.setState('loaded');
434
+ return;
435
+ }
436
+
437
+ await coreContext.load();
438
+ }
439
+
440
+ /**
441
+ * Check if a texture is being processed
442
+ */
443
+ isProcessingTexture(texture: Texture): boolean {
444
+ return this.uploadTextureQueue.includes(texture) === true;
445
+ }
446
+
447
+ /**
448
+ * Process a limited number of uploads.
449
+ *
450
+ * @param maxProcessingTime - The maximum processing time in milliseconds
451
+ */
452
+ async processSome(maxProcessingTime: number): Promise<void> {
453
+ if (this.initialized === false) {
454
+ return;
455
+ }
456
+
457
+ const startTime = getTimeStamp();
458
+
459
+ // Process priority queue
460
+ while (
461
+ this.priorityQueue.length > 0 &&
462
+ getTimeStamp() - startTime < maxProcessingTime
463
+ ) {
464
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
465
+ const texture = this.priorityQueue.pop()!;
466
+ try {
467
+ await texture.getTextureData();
468
+ await this.uploadTexture(texture);
469
+ } catch (error) {
470
+ console.error('Failed to process priority texture:', error);
471
+ // Continue with next texture instead of stopping entire queue
472
+ }
473
+ }
474
+
475
+ // Process uploads - await each upload to prevent GPU overload
476
+ while (
477
+ this.uploadTextureQueue.length > 0 &&
478
+ getTimeStamp() - startTime < maxProcessingTime
479
+ ) {
480
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
481
+ const texture = this.uploadTextureQueue.shift()!;
482
+ try {
483
+ await this.uploadTexture(texture);
484
+ } catch (error) {
485
+ console.error('Failed to upload texture:', error);
486
+ // Continue with next texture instead of stopping entire queue
487
+ }
488
+ }
489
+ }
490
+
491
+ public hasUpdates(): boolean {
492
+ return this.uploadTextureQueue.length > 0;
493
+ }
494
+
495
+ /**
496
+ * Initialize a texture to the cache
497
+ *
498
+ * @param texture Texture to cache
499
+ * @param cacheKey Cache key for the texture
500
+ */
501
+ initTextureToCache(texture: Texture, cacheKey: string) {
502
+ const { keyCache, inverseKeyCache } = this;
503
+ keyCache.set(cacheKey, texture);
504
+ inverseKeyCache.set(texture, cacheKey);
505
+ }
506
+
507
+ /**
508
+ * Get a texture from the cache
509
+ *
510
+ * @param cacheKey
511
+ */
512
+ getTextureFromCache(cacheKey: string): Texture | undefined {
513
+ return this.keyCache.get(cacheKey);
514
+ }
515
+
516
+ /**
517
+ * Remove a texture from the cache
518
+ *
519
+ * @remarks
520
+ * Called by Texture Cleanup when a texture is freed.
521
+ *
522
+ * @param texture
523
+ */
524
+ removeTextureFromCache(texture: Texture) {
525
+ const { inverseKeyCache, keyCache } = this;
526
+ const cacheKey = inverseKeyCache.get(texture);
527
+ if (cacheKey) {
528
+ keyCache.delete(cacheKey);
529
+ }
530
+ }
531
+
532
+ /**
533
+ * Remove texture from the upload queue
534
+ *
535
+ * @param texture - The texture to remove
536
+ */
537
+ removeTextureFromQueue(texture: Texture): void {
538
+ const uploadIndex = this.uploadTextureQueue.indexOf(texture);
539
+ if (uploadIndex !== -1) {
540
+ this.uploadTextureQueue.splice(uploadIndex, 1);
541
+ }
542
+ }
543
+
544
+ /**
545
+ * Resolve a parent texture from the cache or fallback to the provided texture.
546
+ *
547
+ * @param texture - The provided texture to resolve.
548
+ * @returns The cached or provided texture.
549
+ */
550
+ resolveParentTexture(texture: ImageTexture): Texture {
551
+ if (!texture?.props) {
552
+ return texture;
553
+ }
554
+
555
+ const cacheKey = ImageTexture.makeCacheKey(texture.props);
556
+ const cachedTexture = cacheKey
557
+ ? this.getTextureFromCache(cacheKey)
558
+ : undefined;
559
+ return cachedTexture ?? texture;
560
+ }
561
+ }