@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.
Files changed (424) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +7 -0
  3. package/README.md +137 -0
  4. package/dist/exports/canvas-shaders.d.ts +10 -0
  5. package/dist/exports/canvas-shaders.js +11 -0
  6. package/dist/exports/canvas-shaders.js.map +1 -0
  7. package/dist/exports/canvas.d.ts +26 -0
  8. package/dist/exports/canvas.js +27 -0
  9. package/dist/exports/canvas.js.map +1 -0
  10. package/dist/exports/index.d.ts +50 -0
  11. package/dist/exports/index.js +40 -0
  12. package/dist/exports/index.js.map +1 -0
  13. package/dist/exports/inspector.d.ts +4 -0
  14. package/dist/exports/inspector.js +5 -0
  15. package/dist/exports/inspector.js.map +1 -0
  16. package/dist/exports/utils.d.ts +27 -0
  17. package/dist/exports/utils.js +28 -0
  18. package/dist/exports/utils.js.map +1 -0
  19. package/dist/exports/webgl-shaders.d.ts +11 -0
  20. package/dist/exports/webgl-shaders.js +12 -0
  21. package/dist/exports/webgl-shaders.js.map +1 -0
  22. package/dist/exports/webgl.d.ts +28 -0
  23. package/dist/exports/webgl.js +29 -0
  24. package/dist/exports/webgl.js.map +1 -0
  25. package/dist/src/common/CommonTypes.d.ts +110 -0
  26. package/dist/src/common/CommonTypes.js +2 -0
  27. package/dist/src/common/CommonTypes.js.map +1 -0
  28. package/dist/src/common/EventEmitter.d.ts +12 -0
  29. package/dist/src/common/EventEmitter.js +48 -0
  30. package/dist/src/common/EventEmitter.js.map +1 -0
  31. package/dist/src/common/IAnimationController.d.ts +58 -0
  32. package/dist/src/common/IAnimationController.js +2 -0
  33. package/dist/src/common/IAnimationController.js.map +1 -0
  34. package/dist/src/common/IEventEmitter.d.ts +8 -0
  35. package/dist/src/common/IEventEmitter.js +2 -0
  36. package/dist/src/common/IEventEmitter.js.map +1 -0
  37. package/dist/src/core/Autosizer.d.ts +35 -0
  38. package/dist/src/core/Autosizer.js +178 -0
  39. package/dist/src/core/Autosizer.js.map +1 -0
  40. package/dist/src/core/CoreNode.d.ts +908 -0
  41. package/dist/src/core/CoreNode.js +1837 -0
  42. package/dist/src/core/CoreNode.js.map +1 -0
  43. package/dist/src/core/CoreShaderManager.d.ts +38 -0
  44. package/dist/src/core/CoreShaderManager.js +123 -0
  45. package/dist/src/core/CoreShaderManager.js.map +1 -0
  46. package/dist/src/core/CoreTextNode.d.ts +91 -0
  47. package/dist/src/core/CoreTextNode.js +440 -0
  48. package/dist/src/core/CoreTextNode.js.map +1 -0
  49. package/dist/src/core/CoreTextureManager.d.ts +264 -0
  50. package/dist/src/core/CoreTextureManager.js +318 -0
  51. package/dist/src/core/CoreTextureManager.js.map +1 -0
  52. package/dist/src/core/Stage.d.ts +238 -0
  53. package/dist/src/core/Stage.js +804 -0
  54. package/dist/src/core/Stage.js.map +1 -0
  55. package/dist/src/core/TextureError.d.ts +11 -0
  56. package/dist/src/core/TextureError.js +37 -0
  57. package/dist/src/core/TextureError.js.map +1 -0
  58. package/dist/src/core/TextureMemoryManager.d.ts +150 -0
  59. package/dist/src/core/TextureMemoryManager.js +239 -0
  60. package/dist/src/core/TextureMemoryManager.js.map +1 -0
  61. package/dist/src/core/animations/AnimationManager.d.ts +33 -0
  62. package/dist/src/core/animations/AnimationManager.js +137 -0
  63. package/dist/src/core/animations/AnimationManager.js.map +1 -0
  64. package/dist/src/core/animations/CoreAnimation.d.ts +12 -0
  65. package/dist/src/core/animations/CoreAnimation.js +107 -0
  66. package/dist/src/core/animations/CoreAnimation.js.map +1 -0
  67. package/dist/src/core/lib/ContextSpy.d.ts +12 -0
  68. package/dist/src/core/lib/ContextSpy.js +20 -0
  69. package/dist/src/core/lib/ContextSpy.js.map +1 -0
  70. package/dist/src/core/lib/ImageWorker.d.ts +16 -0
  71. package/dist/src/core/lib/ImageWorker.js +202 -0
  72. package/dist/src/core/lib/ImageWorker.js.map +1 -0
  73. package/dist/src/core/lib/Matrix3d.d.ts +74 -0
  74. package/dist/src/core/lib/Matrix3d.js +218 -0
  75. package/dist/src/core/lib/Matrix3d.js.map +1 -0
  76. package/dist/src/core/lib/RenderCoords.d.ts +12 -0
  77. package/dist/src/core/lib/RenderCoords.js +35 -0
  78. package/dist/src/core/lib/RenderCoords.js.map +1 -0
  79. package/dist/src/core/lib/WebGlContextWrapper.d.ts +782 -0
  80. package/dist/src/core/lib/WebGlContextWrapper.js +1143 -0
  81. package/dist/src/core/lib/WebGlContextWrapper.js.map +1 -0
  82. package/dist/src/core/lib/collectionUtils.d.ts +5 -0
  83. package/dist/src/core/lib/collectionUtils.js +82 -0
  84. package/dist/src/core/lib/collectionUtils.js.map +1 -0
  85. package/dist/src/core/lib/colorCache.d.ts +1 -0
  86. package/dist/src/core/lib/colorCache.js +19 -0
  87. package/dist/src/core/lib/colorCache.js.map +1 -0
  88. package/dist/src/core/lib/colorParser.d.ts +21 -0
  89. package/dist/src/core/lib/colorParser.js +54 -0
  90. package/dist/src/core/lib/colorParser.js.map +1 -0
  91. package/dist/src/core/lib/textureCompression.d.ts +28 -0
  92. package/dist/src/core/lib/textureCompression.js +363 -0
  93. package/dist/src/core/lib/textureCompression.js.map +1 -0
  94. package/dist/src/core/lib/textureSvg.d.ts +16 -0
  95. package/dist/src/core/lib/textureSvg.js +45 -0
  96. package/dist/src/core/lib/textureSvg.js.map +1 -0
  97. package/dist/src/core/lib/utils.d.ts +66 -0
  98. package/dist/src/core/lib/utils.js +268 -0
  99. package/dist/src/core/lib/utils.js.map +1 -0
  100. package/dist/src/core/lib/validateImageBitmap.d.ts +7 -0
  101. package/dist/src/core/lib/validateImageBitmap.js +68 -0
  102. package/dist/src/core/lib/validateImageBitmap.js.map +1 -0
  103. package/dist/src/core/platforms/Platform.d.ts +42 -0
  104. package/dist/src/core/platforms/Platform.js +4 -0
  105. package/dist/src/core/platforms/Platform.js.map +1 -0
  106. package/dist/src/core/platforms/web/WebPlatform.d.ts +10 -0
  107. package/dist/src/core/platforms/web/WebPlatform.js +90 -0
  108. package/dist/src/core/platforms/web/WebPlatform.js.map +1 -0
  109. package/dist/src/core/renderers/CoreContextTexture.d.ts +13 -0
  110. package/dist/src/core/renderers/CoreContextTexture.js +16 -0
  111. package/dist/src/core/renderers/CoreContextTexture.js.map +1 -0
  112. package/dist/src/core/renderers/CoreRenderOp.d.ts +3 -0
  113. package/dist/src/core/renderers/CoreRenderOp.js +3 -0
  114. package/dist/src/core/renderers/CoreRenderOp.js.map +1 -0
  115. package/dist/src/core/renderers/CoreRenderer.d.ts +81 -0
  116. package/dist/src/core/renderers/CoreRenderer.js +14 -0
  117. package/dist/src/core/renderers/CoreRenderer.js.map +1 -0
  118. package/dist/src/core/renderers/CoreShaderNode.d.ts +69 -0
  119. package/dist/src/core/renderers/CoreShaderNode.js +130 -0
  120. package/dist/src/core/renderers/CoreShaderNode.js.map +1 -0
  121. package/dist/src/core/renderers/CoreShaderProgram.d.ts +4 -0
  122. package/dist/src/core/renderers/CoreShaderProgram.js +2 -0
  123. package/dist/src/core/renderers/CoreShaderProgram.js.map +1 -0
  124. package/dist/src/core/renderers/canvas/CanvasRenderer.d.ts +36 -0
  125. package/dist/src/core/renderers/canvas/CanvasRenderer.js +221 -0
  126. package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +1 -0
  127. package/dist/src/core/renderers/canvas/CanvasShaderNode.d.ts +21 -0
  128. package/dist/src/core/renderers/canvas/CanvasShaderNode.js +42 -0
  129. package/dist/src/core/renderers/canvas/CanvasShaderNode.js.map +1 -0
  130. package/dist/src/core/renderers/canvas/CanvasTexture.d.ts +17 -0
  131. package/dist/src/core/renderers/canvas/CanvasTexture.js +110 -0
  132. package/dist/src/core/renderers/canvas/CanvasTexture.js.map +1 -0
  133. package/dist/src/core/renderers/webgl/SdfRenderOp.d.ts +41 -0
  134. package/dist/src/core/renderers/webgl/SdfRenderOp.js +88 -0
  135. package/dist/src/core/renderers/webgl/SdfRenderOp.js.map +1 -0
  136. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.d.ts +14 -0
  137. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js +45 -0
  138. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js.map +1 -0
  139. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.d.ts +22 -0
  140. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js +49 -0
  141. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js.map +1 -0
  142. package/dist/src/core/renderers/webgl/WebGlCtxTexture.d.ts +67 -0
  143. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js +259 -0
  144. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js.map +1 -0
  145. package/dist/src/core/renderers/webgl/WebGlRenderer.d.ts +221 -0
  146. package/dist/src/core/renderers/webgl/WebGlRenderer.js +1015 -0
  147. package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -0
  148. package/dist/src/core/renderers/webgl/WebGlShaderNode.d.ts +213 -0
  149. package/dist/src/core/renderers/webgl/WebGlShaderNode.js +331 -0
  150. package/dist/src/core/renderers/webgl/WebGlShaderNode.js.map +1 -0
  151. package/dist/src/core/renderers/webgl/WebGlShaderProgram.d.ts +37 -0
  152. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js +240 -0
  153. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +1 -0
  154. package/dist/src/core/renderers/webgl/internal/BufferCollection.d.ts +28 -0
  155. package/dist/src/core/renderers/webgl/internal/BufferCollection.js +39 -0
  156. package/dist/src/core/renderers/webgl/internal/BufferCollection.js.map +1 -0
  157. package/dist/src/core/renderers/webgl/internal/RendererUtils.d.ts +55 -0
  158. package/dist/src/core/renderers/webgl/internal/RendererUtils.js +88 -0
  159. package/dist/src/core/renderers/webgl/internal/RendererUtils.js.map +1 -0
  160. package/dist/src/core/renderers/webgl/internal/ShaderUtils.d.ts +74 -0
  161. package/dist/src/core/renderers/webgl/internal/ShaderUtils.js +83 -0
  162. package/dist/src/core/renderers/webgl/internal/ShaderUtils.js.map +1 -0
  163. package/dist/src/core/renderers/webgl/internal/WebGlUtils.d.ts +10 -0
  164. package/dist/src/core/renderers/webgl/internal/WebGlUtils.js +13 -0
  165. package/dist/src/core/renderers/webgl/internal/WebGlUtils.js.map +1 -0
  166. package/dist/src/core/shaders/canvas/Border.d.ts +15 -0
  167. package/dist/src/core/shaders/canvas/Border.js +83 -0
  168. package/dist/src/core/shaders/canvas/Border.js.map +1 -0
  169. package/dist/src/core/shaders/canvas/HolePunch.d.ts +7 -0
  170. package/dist/src/core/shaders/canvas/HolePunch.js +22 -0
  171. package/dist/src/core/shaders/canvas/HolePunch.js.map +1 -0
  172. package/dist/src/core/shaders/canvas/LinearGradient.d.ts +10 -0
  173. package/dist/src/core/shaders/canvas/LinearGradient.js +32 -0
  174. package/dist/src/core/shaders/canvas/LinearGradient.js.map +1 -0
  175. package/dist/src/core/shaders/canvas/RadialGradient.d.ts +11 -0
  176. package/dist/src/core/shaders/canvas/RadialGradient.js +54 -0
  177. package/dist/src/core/shaders/canvas/RadialGradient.js.map +1 -0
  178. package/dist/src/core/shaders/canvas/Rounded.d.ts +7 -0
  179. package/dist/src/core/shaders/canvas/Rounded.js +17 -0
  180. package/dist/src/core/shaders/canvas/Rounded.js.map +1 -0
  181. package/dist/src/core/shaders/canvas/RoundedWithBorder.d.ts +10 -0
  182. package/dist/src/core/shaders/canvas/RoundedWithBorder.js +57 -0
  183. package/dist/src/core/shaders/canvas/RoundedWithBorder.js.map +1 -0
  184. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.d.ts +7 -0
  185. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js +61 -0
  186. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js.map +1 -0
  187. package/dist/src/core/shaders/canvas/RoundedWithShadow.d.ts +7 -0
  188. package/dist/src/core/shaders/canvas/RoundedWithShadow.js +26 -0
  189. package/dist/src/core/shaders/canvas/RoundedWithShadow.js.map +1 -0
  190. package/dist/src/core/shaders/canvas/Shadow.d.ts +8 -0
  191. package/dist/src/core/shaders/canvas/Shadow.js +15 -0
  192. package/dist/src/core/shaders/canvas/Shadow.js.map +1 -0
  193. package/dist/src/core/shaders/canvas/utils/render.d.ts +5 -0
  194. package/dist/src/core/shaders/canvas/utils/render.js +81 -0
  195. package/dist/src/core/shaders/canvas/utils/render.js.map +1 -0
  196. package/dist/src/core/shaders/templates/BorderTemplate.d.ts +47 -0
  197. package/dist/src/core/shaders/templates/BorderTemplate.js +77 -0
  198. package/dist/src/core/shaders/templates/BorderTemplate.js.map +1 -0
  199. package/dist/src/core/shaders/templates/HolePunchTemplate.d.ts +46 -0
  200. package/dist/src/core/shaders/templates/HolePunchTemplate.js +19 -0
  201. package/dist/src/core/shaders/templates/HolePunchTemplate.js.map +1 -0
  202. package/dist/src/core/shaders/templates/LinearGradientTemplate.d.ts +23 -0
  203. package/dist/src/core/shaders/templates/LinearGradientTemplate.js +31 -0
  204. package/dist/src/core/shaders/templates/LinearGradientTemplate.js.map +1 -0
  205. package/dist/src/core/shaders/templates/RadialGradientTemplate.d.ts +33 -0
  206. package/dist/src/core/shaders/templates/RadialGradientTemplate.js +33 -0
  207. package/dist/src/core/shaders/templates/RadialGradientTemplate.js.map +1 -0
  208. package/dist/src/core/shaders/templates/RoundedTemplate.d.ts +29 -0
  209. package/dist/src/core/shaders/templates/RoundedTemplate.js +51 -0
  210. package/dist/src/core/shaders/templates/RoundedTemplate.js.map +1 -0
  211. package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.d.ts +7 -0
  212. package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.js +8 -0
  213. package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.js.map +1 -0
  214. package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.d.ts +8 -0
  215. package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.js +9 -0
  216. package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.js.map +1 -0
  217. package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.d.ts +6 -0
  218. package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.js +7 -0
  219. package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.js.map +1 -0
  220. package/dist/src/core/shaders/templates/ShadowTemplate.d.ts +34 -0
  221. package/dist/src/core/shaders/templates/ShadowTemplate.js +50 -0
  222. package/dist/src/core/shaders/templates/ShadowTemplate.js.map +1 -0
  223. package/dist/src/core/shaders/utils.d.ts +5 -0
  224. package/dist/src/core/shaders/utils.js +25 -0
  225. package/dist/src/core/shaders/utils.js.map +1 -0
  226. package/dist/src/core/shaders/webgl/Border.d.ts +3 -0
  227. package/dist/src/core/shaders/webgl/Border.js +153 -0
  228. package/dist/src/core/shaders/webgl/Border.js.map +1 -0
  229. package/dist/src/core/shaders/webgl/Default.d.ts +2 -0
  230. package/dist/src/core/shaders/webgl/Default.js +51 -0
  231. package/dist/src/core/shaders/webgl/Default.js.map +1 -0
  232. package/dist/src/core/shaders/webgl/HolePunch.d.ts +3 -0
  233. package/dist/src/core/shaders/webgl/HolePunch.js +49 -0
  234. package/dist/src/core/shaders/webgl/HolePunch.js.map +1 -0
  235. package/dist/src/core/shaders/webgl/LinearGradient.d.ts +3 -0
  236. package/dist/src/core/shaders/webgl/LinearGradient.js +114 -0
  237. package/dist/src/core/shaders/webgl/LinearGradient.js.map +1 -0
  238. package/dist/src/core/shaders/webgl/RadialGradient.d.ts +3 -0
  239. package/dist/src/core/shaders/webgl/RadialGradient.js +81 -0
  240. package/dist/src/core/shaders/webgl/RadialGradient.js.map +1 -0
  241. package/dist/src/core/shaders/webgl/Rounded.d.ts +7 -0
  242. package/dist/src/core/shaders/webgl/Rounded.js +88 -0
  243. package/dist/src/core/shaders/webgl/Rounded.js.map +1 -0
  244. package/dist/src/core/shaders/webgl/RoundedWithBorder.d.ts +3 -0
  245. package/dist/src/core/shaders/webgl/RoundedWithBorder.js +202 -0
  246. package/dist/src/core/shaders/webgl/RoundedWithBorder.js.map +1 -0
  247. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.d.ts +3 -0
  248. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +223 -0
  249. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js.map +1 -0
  250. package/dist/src/core/shaders/webgl/RoundedWithShadow.d.ts +3 -0
  251. package/dist/src/core/shaders/webgl/RoundedWithShadow.js +123 -0
  252. package/dist/src/core/shaders/webgl/RoundedWithShadow.js.map +1 -0
  253. package/dist/src/core/shaders/webgl/SdfShader.d.ts +13 -0
  254. package/dist/src/core/shaders/webgl/SdfShader.js +72 -0
  255. package/dist/src/core/shaders/webgl/SdfShader.js.map +1 -0
  256. package/dist/src/core/shaders/webgl/Shadow.d.ts +3 -0
  257. package/dist/src/core/shaders/webgl/Shadow.js +115 -0
  258. package/dist/src/core/shaders/webgl/Shadow.js.map +1 -0
  259. package/dist/src/core/text-rendering/CanvasFontHandler.d.ts +59 -0
  260. package/dist/src/core/text-rendering/CanvasFontHandler.js +206 -0
  261. package/dist/src/core/text-rendering/CanvasFontHandler.js.map +1 -0
  262. package/dist/src/core/text-rendering/CanvasTextRenderer.d.ts +17 -0
  263. package/dist/src/core/text-rendering/CanvasTextRenderer.js +139 -0
  264. package/dist/src/core/text-rendering/CanvasTextRenderer.js.map +1 -0
  265. package/dist/src/core/text-rendering/SdfFontHandler.d.ts +167 -0
  266. package/dist/src/core/text-rendering/SdfFontHandler.js +371 -0
  267. package/dist/src/core/text-rendering/SdfFontHandler.js.map +1 -0
  268. package/dist/src/core/text-rendering/SdfTextRenderer.d.ts +17 -0
  269. package/dist/src/core/text-rendering/SdfTextRenderer.js +249 -0
  270. package/dist/src/core/text-rendering/SdfTextRenderer.js.map +1 -0
  271. package/dist/src/core/text-rendering/TextLayoutEngine.d.ts +18 -0
  272. package/dist/src/core/text-rendering/TextLayoutEngine.js +380 -0
  273. package/dist/src/core/text-rendering/TextLayoutEngine.js.map +1 -0
  274. package/dist/src/core/text-rendering/TextRenderer.d.ts +406 -0
  275. package/dist/src/core/text-rendering/TextRenderer.js +2 -0
  276. package/dist/src/core/text-rendering/TextRenderer.js.map +1 -0
  277. package/dist/src/core/text-rendering/Utils.d.ts +30 -0
  278. package/dist/src/core/text-rendering/Utils.js +66 -0
  279. package/dist/src/core/text-rendering/Utils.js.map +1 -0
  280. package/dist/src/core/textures/ColorTexture.d.ts +36 -0
  281. package/dist/src/core/textures/ColorTexture.js +57 -0
  282. package/dist/src/core/textures/ColorTexture.js.map +1 -0
  283. package/dist/src/core/textures/ImageTexture.d.ts +131 -0
  284. package/dist/src/core/textures/ImageTexture.js +211 -0
  285. package/dist/src/core/textures/ImageTexture.js.map +1 -0
  286. package/dist/src/core/textures/NoiseTexture.d.ts +43 -0
  287. package/dist/src/core/textures/NoiseTexture.js +50 -0
  288. package/dist/src/core/textures/NoiseTexture.js.map +1 -0
  289. package/dist/src/core/textures/RenderTexture.d.ts +29 -0
  290. package/dist/src/core/textures/RenderTexture.js +36 -0
  291. package/dist/src/core/textures/RenderTexture.js.map +1 -0
  292. package/dist/src/core/textures/SubTexture.d.ts +61 -0
  293. package/dist/src/core/textures/SubTexture.js +99 -0
  294. package/dist/src/core/textures/SubTexture.js.map +1 -0
  295. package/dist/src/core/textures/Texture.d.ts +275 -0
  296. package/dist/src/core/textures/Texture.js +326 -0
  297. package/dist/src/core/textures/Texture.js.map +1 -0
  298. package/dist/src/core/utils.d.ts +23 -0
  299. package/dist/src/core/utils.js +155 -0
  300. package/dist/src/core/utils.js.map +1 -0
  301. package/dist/src/main-api/INode.d.ts +65 -0
  302. package/dist/src/main-api/INode.js +2 -0
  303. package/dist/src/main-api/INode.js.map +1 -0
  304. package/dist/src/main-api/Inspector.d.ts +154 -0
  305. package/dist/src/main-api/Inspector.js +844 -0
  306. package/dist/src/main-api/Inspector.js.map +1 -0
  307. package/dist/src/main-api/Renderer.d.ts +629 -0
  308. package/dist/src/main-api/Renderer.js +471 -0
  309. package/dist/src/main-api/Renderer.js.map +1 -0
  310. package/dist/src/main-api/utils.d.ts +2 -0
  311. package/dist/src/main-api/utils.js +34 -0
  312. package/dist/src/main-api/utils.js.map +1 -0
  313. package/dist/src/utils.d.ts +123 -0
  314. package/dist/src/utils.js +234 -0
  315. package/dist/src/utils.js.map +1 -0
  316. package/dist/tsconfig.dist.tsbuildinfo +1 -0
  317. package/exports/canvas-shaders.ts +11 -0
  318. package/exports/canvas.ts +27 -0
  319. package/exports/index.ts +69 -0
  320. package/exports/inspector.ts +5 -0
  321. package/exports/utils.ts +32 -0
  322. package/exports/webgl-shaders.ts +12 -0
  323. package/exports/webgl.ts +33 -0
  324. package/package.json +99 -0
  325. package/src/common/CommonTypes.ts +145 -0
  326. package/src/common/EventEmitter.ts +58 -0
  327. package/src/common/IAnimationController.ts +65 -0
  328. package/src/common/IEventEmitter.ts +11 -0
  329. package/src/core/Autosizer.ts +205 -0
  330. package/src/core/CoreNode.test.ts +535 -0
  331. package/src/core/CoreNode.ts +2883 -0
  332. package/src/core/CoreShaderManager.ts +170 -0
  333. package/src/core/CoreTextNode.ts +573 -0
  334. package/src/core/CoreTextureManager.ts +552 -0
  335. package/src/core/Stage.ts +1037 -0
  336. package/src/core/TextureError.ts +46 -0
  337. package/src/core/TextureMemoryManager.ts +378 -0
  338. package/src/core/animations/AnimationManager.ts +178 -0
  339. package/src/core/animations/CoreAnimation.ts +138 -0
  340. package/src/core/lib/ContextSpy.ts +22 -0
  341. package/src/core/lib/ImageWorker.ts +292 -0
  342. package/src/core/lib/Matrix3d.ts +231 -0
  343. package/src/core/lib/RenderCoords.ts +55 -0
  344. package/src/core/lib/WebGlContextWrapper.ts +1448 -0
  345. package/src/core/lib/collectionUtils.ts +99 -0
  346. package/src/core/lib/colorCache.ts +20 -0
  347. package/src/core/lib/colorParser.ts +66 -0
  348. package/src/core/lib/textureCompression.ts +492 -0
  349. package/src/core/lib/textureSvg.ts +59 -0
  350. package/src/core/lib/utils.ts +400 -0
  351. package/src/core/lib/validateImageBitmap.ts +87 -0
  352. package/src/core/platforms/Platform.ts +64 -0
  353. package/src/core/platforms/web/WebPlatform.ts +132 -0
  354. package/src/core/renderers/CoreContextTexture.ts +25 -0
  355. package/src/core/renderers/CoreRenderOp.ts +3 -0
  356. package/src/core/renderers/CoreRenderer.ts +101 -0
  357. package/src/core/renderers/CoreShaderNode.ts +202 -0
  358. package/src/core/renderers/CoreShaderProgram.ts +4 -0
  359. package/src/core/renderers/canvas/CanvasRenderer.ts +274 -0
  360. package/src/core/renderers/canvas/CanvasShaderNode.ts +79 -0
  361. package/src/core/renderers/canvas/CanvasTexture.ts +141 -0
  362. package/src/core/renderers/webgl/SdfRenderOp.ts +103 -0
  363. package/src/core/renderers/webgl/WebGlCtxRenderTexture.ts +70 -0
  364. package/src/core/renderers/webgl/WebGlCtxSubTexture.ts +76 -0
  365. package/src/core/renderers/webgl/WebGlCtxTexture.ts +332 -0
  366. package/src/core/renderers/webgl/WebGlRenderer.ts +1323 -0
  367. package/src/core/renderers/webgl/WebGlShaderNode.ts +423 -0
  368. package/src/core/renderers/webgl/WebGlShaderProgram.ts +346 -0
  369. package/src/core/renderers/webgl/internal/BufferCollection.ts +46 -0
  370. package/src/core/renderers/webgl/internal/RendererUtils.ts +136 -0
  371. package/src/core/renderers/webgl/internal/ShaderUtils.ts +262 -0
  372. package/src/core/renderers/webgl/internal/WebGlUtils.ts +16 -0
  373. package/src/core/shaders/canvas/Border.ts +119 -0
  374. package/src/core/shaders/canvas/HolePunch.ts +38 -0
  375. package/src/core/shaders/canvas/LinearGradient.ts +54 -0
  376. package/src/core/shaders/canvas/RadialGradient.ts +82 -0
  377. package/src/core/shaders/canvas/Rounded.ts +38 -0
  378. package/src/core/shaders/canvas/RoundedWithBorder.ts +105 -0
  379. package/src/core/shaders/canvas/RoundedWithBorderAndShadow.ts +118 -0
  380. package/src/core/shaders/canvas/RoundedWithShadow.ts +56 -0
  381. package/src/core/shaders/canvas/Shadow.ts +35 -0
  382. package/src/core/shaders/canvas/utils/render.ts +143 -0
  383. package/src/core/shaders/templates/BorderTemplate.ts +128 -0
  384. package/src/core/shaders/templates/HolePunchTemplate.ts +65 -0
  385. package/src/core/shaders/templates/LinearGradientTemplate.ts +54 -0
  386. package/src/core/shaders/templates/RadialGradientTemplate.ts +66 -0
  387. package/src/core/shaders/templates/RoundedTemplate.ts +81 -0
  388. package/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.ts +21 -0
  389. package/src/core/shaders/templates/RoundedWithBorderTemplate.ts +23 -0
  390. package/src/core/shaders/templates/RoundedWithShadowTemplate.ts +18 -0
  391. package/src/core/shaders/templates/ShadowTemplate.ts +89 -0
  392. package/src/core/shaders/utils.ts +30 -0
  393. package/src/core/shaders/webgl/Border.ts +158 -0
  394. package/src/core/shaders/webgl/Default.ts +52 -0
  395. package/src/core/shaders/webgl/HolePunch.ts +58 -0
  396. package/src/core/shaders/webgl/LinearGradient.ts +119 -0
  397. package/src/core/shaders/webgl/RadialGradient.ts +91 -0
  398. package/src/core/shaders/webgl/Rounded.ts +97 -0
  399. package/src/core/shaders/webgl/RoundedWithBorder.ts +212 -0
  400. package/src/core/shaders/webgl/RoundedWithBorderAndShadow.ts +235 -0
  401. package/src/core/shaders/webgl/RoundedWithShadow.ts +132 -0
  402. package/src/core/shaders/webgl/SdfShader.ts +73 -0
  403. package/src/core/shaders/webgl/Shadow.ts +119 -0
  404. package/src/core/text-rendering/CanvasFontHandler.ts +285 -0
  405. package/src/core/text-rendering/CanvasTextRenderer.ts +236 -0
  406. package/src/core/text-rendering/SdfFontHandler.ts +566 -0
  407. package/src/core/text-rendering/SdfTextRenderer.ts +352 -0
  408. package/src/core/text-rendering/TextLayoutEngine.ts +672 -0
  409. package/src/core/text-rendering/TextRenderer.ts +449 -0
  410. package/src/core/text-rendering/Utils.ts +80 -0
  411. package/src/core/text-rendering/tests/TextLayoutEngine.test.ts +434 -0
  412. package/src/core/textures/ColorTexture.ts +85 -0
  413. package/src/core/textures/ImageTexture.ts +394 -0
  414. package/src/core/textures/NoiseTexture.ts +87 -0
  415. package/src/core/textures/RenderTexture.ts +68 -0
  416. package/src/core/textures/SubTexture.ts +165 -0
  417. package/src/core/textures/Texture.ts +505 -0
  418. package/src/core/utils.ts +210 -0
  419. package/src/env.d.ts +7 -0
  420. package/src/main-api/INode.ts +92 -0
  421. package/src/main-api/Inspector.ts +1267 -0
  422. package/src/main-api/Renderer.ts +1011 -0
  423. package/src/main-api/utils.ts +45 -0
  424. package/src/utils.ts +302 -0
@@ -0,0 +1,1837 @@
1
+ import { assertTruthy, getNewId, premultiplyColorABGR, USE_RTT, ENABLE_AUTOSIZE, EMIT_BOUNDS_EVENTS, } from '../utils.js';
2
+ import {} from './textures/Texture.js';
3
+ import { EventEmitter } from '../common/EventEmitter.js';
4
+ import { copyRect, intersectRect, createBound, boundInsideBound, boundLargeThanBound, createPreloadBounds, } from './lib/utils.js';
5
+ import { Matrix3d } from './lib/Matrix3d.js';
6
+ import { RenderCoords } from './lib/RenderCoords.js';
7
+ import { createAnimation } from './animations/CoreAnimation.js';
8
+ import { AutosizeMode, Autosizer } from './Autosizer.js';
9
+ import { removeChild } from './lib/collectionUtils.js';
10
+ export var CoreNodeRenderState;
11
+ (function (CoreNodeRenderState) {
12
+ CoreNodeRenderState[CoreNodeRenderState["Init"] = 0] = "Init";
13
+ CoreNodeRenderState[CoreNodeRenderState["OutOfBounds"] = 2] = "OutOfBounds";
14
+ CoreNodeRenderState[CoreNodeRenderState["InBounds"] = 4] = "InBounds";
15
+ CoreNodeRenderState[CoreNodeRenderState["InViewport"] = 8] = "InViewport";
16
+ })(CoreNodeRenderState || (CoreNodeRenderState = {}));
17
+ const NO_CLIPPING_RECT = {
18
+ x: 0,
19
+ y: 0,
20
+ width: 0,
21
+ height: 0,
22
+ valid: false,
23
+ };
24
+ const CoreNodeRenderStateMap = new Map();
25
+ CoreNodeRenderStateMap.set(CoreNodeRenderState.Init, 'init');
26
+ CoreNodeRenderStateMap.set(CoreNodeRenderState.OutOfBounds, 'outOfBounds');
27
+ CoreNodeRenderStateMap.set(CoreNodeRenderState.InBounds, 'inBounds');
28
+ CoreNodeRenderStateMap.set(CoreNodeRenderState.InViewport, 'inViewport');
29
+ export var UpdateType;
30
+ (function (UpdateType) {
31
+ /**
32
+ * Child updates
33
+ */
34
+ UpdateType[UpdateType["Children"] = 1] = "Children";
35
+ /**
36
+ * localTransform
37
+ *
38
+ * @remarks
39
+ * CoreNode Properties Updated:
40
+ * - `localTransform`
41
+ */
42
+ UpdateType[UpdateType["Local"] = 2] = "Local";
43
+ /**
44
+ * globalTransform
45
+ *
46
+ * * @remarks
47
+ * CoreNode Properties Updated:
48
+ * - `globalTransform`
49
+ * - `renderBounds`
50
+ * - `renderCoords`
51
+ */
52
+ UpdateType[UpdateType["Global"] = 4] = "Global";
53
+ /**
54
+ * Clipping rect update
55
+ *
56
+ * @remarks
57
+ * CoreNode Properties Updated:
58
+ * - `clippingRect`
59
+ */
60
+ UpdateType[UpdateType["Clipping"] = 8] = "Clipping";
61
+ /**
62
+ * Sort Z-Index Children update
63
+ *
64
+ * @remarks
65
+ * CoreNode Properties Updated:
66
+ * - `children` (sorts children by their `calcZIndex`)
67
+ */
68
+ UpdateType[UpdateType["SortZIndexChildren"] = 16] = "SortZIndexChildren";
69
+ /**
70
+ * Premultiplied Colors update
71
+ *
72
+ * @remarks
73
+ * CoreNode Properties Updated:
74
+ * - `premultipliedColorTl`
75
+ * - `premultipliedColorTr`
76
+ * - `premultipliedColorBl`
77
+ * - `premultipliedColorBr`
78
+ */
79
+ UpdateType[UpdateType["PremultipliedColors"] = 32] = "PremultipliedColors";
80
+ /**
81
+ * World Alpha update
82
+ *
83
+ * @remarks
84
+ * CoreNode Properties Updated:
85
+ * - `worldAlpha` = `parent.worldAlpha` * `alpha`
86
+ */
87
+ UpdateType[UpdateType["WorldAlpha"] = 64] = "WorldAlpha";
88
+ /**
89
+ * Render State update
90
+ *
91
+ * @remarks
92
+ * CoreNode Properties Updated:
93
+ * - `renderState`
94
+ */
95
+ UpdateType[UpdateType["RenderState"] = 128] = "RenderState";
96
+ /**
97
+ * Is Renderable update
98
+ *
99
+ * @remarks
100
+ * CoreNode Properties Updated:
101
+ * - `isRenderable`
102
+ */
103
+ UpdateType[UpdateType["IsRenderable"] = 256] = "IsRenderable";
104
+ /**
105
+ * Render Texture update
106
+ */
107
+ UpdateType[UpdateType["RenderTexture"] = 512] = "RenderTexture";
108
+ /**
109
+ * Track if parent has render texture
110
+ */
111
+ UpdateType[UpdateType["ParentRenderTexture"] = 1024] = "ParentRenderTexture";
112
+ /**
113
+ * Render Bounds update
114
+ */
115
+ UpdateType[UpdateType["RenderBounds"] = 2048] = "RenderBounds";
116
+ /**
117
+ * RecalcUniforms
118
+ */
119
+ UpdateType[UpdateType["RecalcUniforms"] = 4096] = "RecalcUniforms";
120
+ /**
121
+ * Autosize update
122
+ */
123
+ UpdateType[UpdateType["Autosize"] = 8192] = "Autosize";
124
+ /**
125
+ * None
126
+ */
127
+ UpdateType[UpdateType["None"] = 0] = "None";
128
+ /**
129
+ * All
130
+ */
131
+ UpdateType[UpdateType["All"] = 16383] = "All";
132
+ })(UpdateType || (UpdateType = {}));
133
+ /**
134
+ * A visual Node in the Renderer scene graph.
135
+ *
136
+ * @remarks
137
+ * CoreNode is an internally used class that represents a Renderer Node in the
138
+ * scene graph. See INode.ts for the public APIs exposed to Renderer users
139
+ * that include generic types for Shaders.
140
+ */
141
+ export class CoreNode extends EventEmitter {
142
+ stage;
143
+ children = [];
144
+ _id = getNewId();
145
+ props;
146
+ isCoreNode = true;
147
+ _animations = {};
148
+ // WebGL Render Op State
149
+ renderOpBufferIdx = 0;
150
+ numQuads = 0;
151
+ renderOpTextures = [];
152
+ /**
153
+ * Permanent index (in float32 units) into the renderer's quad buffer.
154
+ * -1 means this node has not yet been assigned a slot.
155
+ */
156
+ quadBufferIndex = -1;
157
+ /**
158
+ * True when renderCoords, premultiplied colors, or textureCoords changed
159
+ * since the node's quad was last written to the GPU.
160
+ */
161
+ isQuadDirty = true;
162
+ hasShaderUpdater = false;
163
+ hasShaderTimeFn = false;
164
+ hasColorProps = false;
165
+ textureLoaded = false;
166
+ updateType = UpdateType.All;
167
+ childUpdateType = UpdateType.None;
168
+ globalTransform;
169
+ localTransform;
170
+ sceneGlobalTransform;
171
+ renderCoords;
172
+ sceneRenderCoords;
173
+ renderBound;
174
+ strictBound;
175
+ preloadBound;
176
+ clippingRect = {
177
+ x: 0,
178
+ y: 0,
179
+ width: 0,
180
+ height: 0,
181
+ valid: false,
182
+ };
183
+ textureCoords;
184
+ updateShaderUniforms = false;
185
+ isRenderable = false;
186
+ renderState = CoreNodeRenderState.Init;
187
+ isSimple = true;
188
+ worldAlpha = 1;
189
+ premultipliedColorTl = 0;
190
+ premultipliedColorTr = 0;
191
+ premultipliedColorBl = 0;
192
+ premultipliedColorBr = 0;
193
+ calcZIndex = 0;
194
+ hasRTTupdates = false;
195
+ parentHasRenderTexture = false;
196
+ rttParent = null;
197
+ /**
198
+ * only used when rtt = true
199
+ */
200
+ framebufferDimensions = null;
201
+ /**Autosize properties */
202
+ autosizer = null;
203
+ parentAutosizer = null;
204
+ destroyed = false;
205
+ constructor(stage, props) {
206
+ super();
207
+ this.stage = stage;
208
+ //inital update type
209
+ let initialUpdateType = UpdateType.Local | UpdateType.RenderBounds | UpdateType.RenderState;
210
+ // Fast-path assign only known keys
211
+ const p = (this.props = {
212
+ x: props.x,
213
+ y: props.y,
214
+ w: props.w,
215
+ h: props.h,
216
+ alpha: props.alpha,
217
+ autosize: props.autosize,
218
+ clipping: props.clipping,
219
+ color: props.color,
220
+ colorTop: props.colorTop,
221
+ colorBottom: props.colorBottom,
222
+ colorLeft: props.colorLeft,
223
+ colorRight: props.colorRight,
224
+ colorTl: props.colorTl,
225
+ colorTr: props.colorTr,
226
+ colorBl: props.colorBl,
227
+ colorBr: props.colorBr,
228
+ scaleX: props.scaleX,
229
+ scaleY: props.scaleY,
230
+ rotation: props.rotation,
231
+ pivotX: props.pivotX,
232
+ pivotY: props.pivotY,
233
+ mountX: props.mountX,
234
+ mountY: props.mountY,
235
+ mount: props.mount,
236
+ pivot: props.pivot,
237
+ zIndex: props.zIndex,
238
+ textureOptions: props.textureOptions,
239
+ data: props.data,
240
+ imageType: props.imageType,
241
+ srcX: props.srcX,
242
+ srcY: props.srcY,
243
+ srcWidth: props.srcWidth,
244
+ srcHeight: props.srcHeight,
245
+ parent: props.parent,
246
+ texture: null,
247
+ shader: null,
248
+ src: null,
249
+ rtt: false,
250
+ boundsMargin: null,
251
+ scale: null,
252
+ interactive: props.interactive,
253
+ preventDestroy: props.preventDestroy,
254
+ });
255
+ //check if any color props are set for premultiplied color updates
256
+ if (p.color > 0 ||
257
+ p.colorTop > 0 ||
258
+ p.colorBottom > 0 ||
259
+ p.colorLeft > 0 ||
260
+ p.colorRight > 0 ||
261
+ p.colorTl > 0 ||
262
+ p.colorTr > 0 ||
263
+ p.colorBl > 0 ||
264
+ p.colorBr > 0) {
265
+ this.hasColorProps = true;
266
+ initialUpdateType |= UpdateType.PremultipliedColors;
267
+ }
268
+ // Only set non-default values
269
+ if (p.zIndex !== 0) {
270
+ this.zIndex = p.zIndex;
271
+ }
272
+ if (props.parent !== null) {
273
+ props.parent.addChild(this);
274
+ }
275
+ // Assign props to instances
276
+ this.texture = props.texture;
277
+ this.shader = props.shader;
278
+ this.src = props.src;
279
+ this.rtt = props.rtt;
280
+ this.boundsMargin = props.boundsMargin;
281
+ this.interactive = props.interactive;
282
+ // Initialize autosize if enabled
283
+ if (p.autosize === true) {
284
+ this.autosizer = new Autosizer(this);
285
+ }
286
+ this.setUpdateType(initialUpdateType);
287
+ // if the default texture isn't loaded yet, wait for it to load
288
+ // this only happens when the node is created before the stage is ready
289
+ const dt = this.stage.defaultTexture;
290
+ if (dt !== null && dt.state !== 'loaded') {
291
+ dt.once('loaded', () => this.setUpdateType(UpdateType.IsRenderable));
292
+ }
293
+ this.updateIsSimple();
294
+ }
295
+ //#region Textures
296
+ loadTexture() {
297
+ if (this.props.texture === null) {
298
+ return;
299
+ }
300
+ // If texture is already loaded / failed, trigger loaded event manually
301
+ // so that users get a consistent event experience.
302
+ // We do this in a microtask to allow listeners to be attached in the same
303
+ // synchronous task after calling loadTexture()
304
+ queueMicrotask(this.loadTextureTask);
305
+ }
306
+ /**
307
+ * Task for queueMicrotask to loadTexture
308
+ *
309
+ * @remarks
310
+ * This method is called in a microtask to release the texture.
311
+ */
312
+ loadTextureTask = () => {
313
+ const texture = this.props.texture;
314
+ //it is possible that texture is null here if user sets the texture to null right after loadTexture call
315
+ if (texture === null) {
316
+ return;
317
+ }
318
+ if (this.textureOptions.preload === true) {
319
+ this.stage.txManager.loadTexture(texture);
320
+ }
321
+ texture.preventCleanup = this.props.textureOptions?.preventCleanup ?? false;
322
+ texture.on('loaded', this.onTextureLoaded);
323
+ texture.on('failed', this.onTextureFailed);
324
+ texture.on('freed', this.onTextureFreed);
325
+ // If the parent is a render texture, the initial texture status
326
+ // will be set to freed until the texture is processed by the
327
+ // Render RTT nodes. So we only need to listen fo changes and
328
+ // no need to check the texture.state until we restructure how
329
+ // textures are being processed.
330
+ if (this.parentHasRenderTexture) {
331
+ this.notifyParentRTTOfUpdate();
332
+ return;
333
+ }
334
+ if (texture.state === 'loaded') {
335
+ this.onTextureLoaded(texture, texture.dimensions);
336
+ }
337
+ else if (texture.state === 'failed') {
338
+ this.onTextureFailed(texture, texture.error);
339
+ }
340
+ else if (texture.state === 'freed') {
341
+ this.onTextureFreed(texture);
342
+ }
343
+ };
344
+ unloadTexture() {
345
+ if (this.texture === null) {
346
+ return;
347
+ }
348
+ const texture = this.texture;
349
+ texture.off('loaded', this.onTextureLoaded);
350
+ texture.off('failed', this.onTextureFailed);
351
+ texture.off('freed', this.onTextureFreed);
352
+ texture.setRenderableOwner(this._id, false);
353
+ }
354
+ onTextureLoaded = (_, dimensions) => {
355
+ if (this.autosizer !== null) {
356
+ this.autosizer.update();
357
+ }
358
+ this.textureLoaded = true;
359
+ this.setUpdateType(UpdateType.IsRenderable);
360
+ // Texture was loaded. In case the RAF loop has already stopped, we request
361
+ // a render to ensure the texture is rendered.
362
+ this.stage.requestRender();
363
+ // If parent has a render texture, flag that we need to update
364
+ if (this.parentHasRenderTexture) {
365
+ this.notifyParentRTTOfUpdate();
366
+ }
367
+ // ignore 1x1 pixel textures
368
+ if (dimensions.w > 1 && dimensions.h > 1) {
369
+ this.emit('loaded', {
370
+ type: 'texture',
371
+ dimensions,
372
+ });
373
+ }
374
+ if (this.stage.calculateTextureCoord === true &&
375
+ this.props.textureOptions !== null) {
376
+ this.textureCoords = this.stage.renderer.getTextureCoords(this);
377
+ }
378
+ // Trigger a local update if the texture is loaded and the resizeMode is 'contain'
379
+ if (this.props.textureOptions?.resizeMode?.type === 'contain') {
380
+ this.setUpdateType(UpdateType.Local);
381
+ }
382
+ };
383
+ onTextureFailed = (_, error) => {
384
+ // immediately set isRenderable to false, so that we handle the error
385
+ // without waiting for the next frame loop
386
+ this.textureLoaded = false;
387
+ this.isRenderable = false;
388
+ this.updateTextureOwnership(false);
389
+ this.setUpdateType(UpdateType.IsRenderable);
390
+ // If parent has a render texture, flag that we need to update
391
+ if (this.parentHasRenderTexture) {
392
+ this.notifyParentRTTOfUpdate();
393
+ }
394
+ if (this.texture !== null &&
395
+ this.texture.retryCount > this.texture.maxRetryCount) {
396
+ this.emit('failed', {
397
+ type: 'texture',
398
+ error,
399
+ });
400
+ }
401
+ };
402
+ onTextureFreed = () => {
403
+ // immediately set isRenderable to false, so that we handle the error
404
+ // without waiting for the next frame loop
405
+ this.textureLoaded = false;
406
+ this.isRenderable = false;
407
+ this.updateTextureOwnership(false);
408
+ this.setUpdateType(UpdateType.IsRenderable);
409
+ // If parent has a render texture, flag that we need to update
410
+ if (this.parentHasRenderTexture) {
411
+ this.notifyParentRTTOfUpdate();
412
+ }
413
+ this.emit('freed', {
414
+ type: 'texture',
415
+ });
416
+ };
417
+ //#endregion Textures
418
+ /**
419
+ * Change types types is used to determine the scope of the changes being applied
420
+ *
421
+ * @remarks
422
+ * See {@link UpdateType} for more information on each type
423
+ *
424
+ * @param type
425
+ */
426
+ setUpdateType(type) {
427
+ this.updateType |= type;
428
+ const parent = this.props.parent;
429
+ if (!parent || parent.updateType & UpdateType.Children)
430
+ return;
431
+ parent.setUpdateType(UpdateType.Children);
432
+ }
433
+ updateLocalTransform() {
434
+ const p = this.props;
435
+ const { x, y } = p;
436
+ if (this.isSimple) {
437
+ this.localTransform = Matrix3d.translate(x, y, this.localTransform);
438
+ return;
439
+ }
440
+ const { w, h } = p;
441
+ const mountTranslateX = p.mountX * w;
442
+ const mountTranslateY = p.mountY * h;
443
+ if (p.rotation !== 0 || p.scaleX !== 1 || p.scaleY !== 1) {
444
+ const scaleRotate = Matrix3d.rotate(p.rotation, Matrix3d.temp).scale(p.scaleX, p.scaleY);
445
+ const pivotTranslateX = p.pivotX * w;
446
+ const pivotTranslateY = p.pivotY * h;
447
+ this.localTransform = Matrix3d.translate(x - mountTranslateX + pivotTranslateX, y - mountTranslateY + pivotTranslateY, this.localTransform)
448
+ .multiply(scaleRotate)
449
+ .translate(-pivotTranslateX, -pivotTranslateY);
450
+ }
451
+ else {
452
+ this.localTransform = Matrix3d.translate(x - mountTranslateX, y - mountTranslateY, this.localTransform);
453
+ }
454
+ // Handle 'contain' resize mode
455
+ const texture = p.texture;
456
+ if (texture &&
457
+ texture.dimensions &&
458
+ p.textureOptions.resizeMode?.type === 'contain') {
459
+ let resizeModeScaleX = 1;
460
+ let resizeModeScaleY = 1;
461
+ let extraX = 0;
462
+ let extraY = 0;
463
+ const { w: tw, h: th } = texture.dimensions;
464
+ const txAspectRatio = tw / th;
465
+ const nodeAspectRatio = w / h;
466
+ if (txAspectRatio > nodeAspectRatio) {
467
+ // Texture is wider than node
468
+ // Center the node vertically (shift down by extraY)
469
+ // Scale the node vertically to maintain original aspect ratio
470
+ const scaleX = w / tw;
471
+ const scaledTxHeight = th * scaleX;
472
+ extraY = (h - scaledTxHeight) / 2;
473
+ resizeModeScaleY = scaledTxHeight / h;
474
+ }
475
+ else {
476
+ // Texture is taller than node (or equal)
477
+ // Center the node horizontally (shift right by extraX)
478
+ // Scale the node horizontally to maintain original aspect ratio
479
+ const scaleY = h / th;
480
+ const scaledTxWidth = tw * scaleY;
481
+ extraX = (w - scaledTxWidth) / 2;
482
+ resizeModeScaleX = scaledTxWidth / w;
483
+ }
484
+ // Apply the extra translation and scale to the local transform
485
+ this.localTransform
486
+ .translate(extraX, extraY)
487
+ .scale(resizeModeScaleX, resizeModeScaleY);
488
+ }
489
+ }
490
+ updateIsSimple() {
491
+ const p = this.props;
492
+ this.isSimple =
493
+ p.rotation === 0 &&
494
+ p.scaleX === 1 &&
495
+ p.scaleY === 1 &&
496
+ p.mountX === 0 &&
497
+ p.mountY === 0 &&
498
+ !(p.texture && p.textureOptions.resizeMode?.type === 'contain');
499
+ }
500
+ /**
501
+ * @todo: test for correct calculation flag
502
+ * @param delta
503
+ */
504
+ update(delta, parentClippingRect) {
505
+ const props = this.props;
506
+ //parent can be forced to ! because the root node update loop uses updateRoot which implies that
507
+ //all other loops using this update method have a parent
508
+ const parent = props.parent;
509
+ const parentHasRenderTexture = this.parentHasRenderTexture;
510
+ let newRenderState = null;
511
+ let updateType = this.updateType;
512
+ let childUpdateType = this.childUpdateType;
513
+ //this needs to be handled before setting updateTypes are reset
514
+ if (ENABLE_AUTOSIZE &&
515
+ updateType & UpdateType.Autosize &&
516
+ this.autosizer !== null) {
517
+ this.autosizer.update();
518
+ }
519
+ // reset update type
520
+ this.updateType = 0;
521
+ this.childUpdateType = 0;
522
+ if (updateType & UpdateType.Local) {
523
+ this.updateLocalTransform();
524
+ updateType |= UpdateType.Global;
525
+ }
526
+ // Handle specific RTT updates at this node level
527
+ if (USE_RTT && updateType & UpdateType.RenderTexture && this.rtt === true) {
528
+ this.hasRTTupdates = true;
529
+ }
530
+ if (updateType & UpdateType.Global) {
531
+ if (USE_RTT &&
532
+ this.parentHasRenderTexture === true &&
533
+ parent.rtt === true) {
534
+ // we are at the start of the RTT chain, so we need to reset the globalTransform
535
+ // for correct RTT rendering
536
+ this.globalTransform = Matrix3d.identity(this.globalTransform);
537
+ // Maintain a full scene global transform for bounds detection
538
+ const parentTransform = parent.globalTransform || Matrix3d.identity(Matrix3d.temp);
539
+ this.sceneGlobalTransform = Matrix3d.copy(parentTransform, this.sceneGlobalTransform).translateOrMultiply(this.localTransform);
540
+ }
541
+ else if (USE_RTT &&
542
+ this.parentHasRenderTexture === true &&
543
+ parent.rtt === false) {
544
+ // we're part of an RTT chain but our parent is not the main RTT node
545
+ // so we need to propogate the sceneGlobalTransform of the parent
546
+ // to maintain a full scene global transform for bounds detection
547
+ const parentSceneTransform = parent.sceneGlobalTransform || this.localTransform;
548
+ this.sceneGlobalTransform = Matrix3d.copy(parentSceneTransform, this.sceneGlobalTransform).translateOrMultiply(this.localTransform);
549
+ this.globalTransform = Matrix3d.copy(parent.globalTransform || this.localTransform, this.globalTransform);
550
+ }
551
+ else {
552
+ this.globalTransform = Matrix3d.copy(parent.globalTransform || this.localTransform, this.globalTransform);
553
+ }
554
+ if (this.isSimple) {
555
+ this.globalTransform.translate(this.localTransform.tx, this.localTransform.ty);
556
+ }
557
+ else {
558
+ this.globalTransform.translateOrMultiply(this.localTransform);
559
+ }
560
+ this.calculateRenderCoords();
561
+ this.updateBoundingRect();
562
+ updateType |= UpdateType.RenderState | UpdateType.RecalcUniforms;
563
+ //only propagate children updates if not autosizing
564
+ if ((updateType & UpdateType.Autosize) === 0) {
565
+ updateType |= UpdateType.Children;
566
+ childUpdateType |= UpdateType.Global;
567
+ }
568
+ if (this.clipping === true) {
569
+ updateType |= UpdateType.Clipping | UpdateType.RenderBounds;
570
+ childUpdateType |= UpdateType.RenderBounds;
571
+ }
572
+ }
573
+ if (updateType & UpdateType.RenderBounds) {
574
+ this.createRenderBounds();
575
+ updateType |= UpdateType.RenderState | UpdateType.Children;
576
+ childUpdateType |= UpdateType.RenderBounds;
577
+ }
578
+ if (updateType & UpdateType.RenderState) {
579
+ newRenderState = this.checkRenderBounds();
580
+ updateType |= UpdateType.IsRenderable;
581
+ // if we're not going out of bounds, update the render state
582
+ // this is done so the update loop can finish before we mark a node
583
+ // as out of bounds
584
+ if (newRenderState !== CoreNodeRenderState.OutOfBounds) {
585
+ this.updateRenderState(newRenderState);
586
+ }
587
+ }
588
+ if (updateType & UpdateType.WorldAlpha) {
589
+ this.worldAlpha = parent.worldAlpha * this.props.alpha;
590
+ updateType |=
591
+ UpdateType.PremultipliedColors |
592
+ UpdateType.Children |
593
+ UpdateType.IsRenderable;
594
+ childUpdateType |= UpdateType.WorldAlpha;
595
+ }
596
+ if (updateType & UpdateType.IsRenderable) {
597
+ this.updateIsRenderable();
598
+ }
599
+ // Handle autosize updates when children transforms change
600
+ if (ENABLE_AUTOSIZE &&
601
+ updateType & UpdateType.Global &&
602
+ this.isRenderable === true &&
603
+ this.parentAutosizer !== null) {
604
+ this.parentAutosizer.patch(this.id);
605
+ }
606
+ if (updateType & UpdateType.Clipping) {
607
+ this.calculateClippingRect(parentClippingRect);
608
+ updateType |= UpdateType.Children;
609
+ childUpdateType |= UpdateType.Clipping | UpdateType.RenderBounds;
610
+ }
611
+ if (updateType & UpdateType.PremultipliedColors) {
612
+ const alpha = this.worldAlpha;
613
+ const tl = props.colorTl;
614
+ const tr = props.colorTr;
615
+ const bl = props.colorBl;
616
+ const br = props.colorBr;
617
+ // Fast equality check (covers all 4 corners)
618
+ const same = tl === tr && tl === bl && tl === br;
619
+ const merged = premultiplyColorABGR(tl, alpha);
620
+ this.premultipliedColorTl = merged;
621
+ if (same === true) {
622
+ this.premultipliedColorTr =
623
+ this.premultipliedColorBl =
624
+ this.premultipliedColorBr =
625
+ merged;
626
+ }
627
+ else {
628
+ this.premultipliedColorTr = premultiplyColorABGR(tr, alpha);
629
+ this.premultipliedColorBl = premultiplyColorABGR(bl, alpha);
630
+ this.premultipliedColorBr = premultiplyColorABGR(br, alpha);
631
+ }
632
+ }
633
+ if (this.renderState === CoreNodeRenderState.OutOfBounds) {
634
+ // Delay updating children until the node is in bounds
635
+ this.updateType = updateType;
636
+ this.childUpdateType = childUpdateType;
637
+ return;
638
+ }
639
+ if (updateType & UpdateType.RecalcUniforms &&
640
+ this.hasShaderUpdater === true) {
641
+ this.updateShaderUniforms = true;
642
+ }
643
+ if (this.isRenderable === true && this.updateShaderUniforms === true) {
644
+ this.updateShaderUniforms = false;
645
+ //this exists because the boolean hasShaderUpdater === true
646
+ this.shader.update();
647
+ }
648
+ if (updateType & UpdateType.Children && this.children.length > 0) {
649
+ let childClippingRect = this.clippingRect;
650
+ if (USE_RTT && this.rtt === true) {
651
+ childClippingRect = NO_CLIPPING_RECT;
652
+ }
653
+ for (let i = 0, length = this.children.length; i < length; i++) {
654
+ const child = this.children[i];
655
+ if (childUpdateType !== 0) {
656
+ child.updateType |= childUpdateType;
657
+ }
658
+ if (child.updateType === 0) {
659
+ continue;
660
+ }
661
+ child.update(delta, childClippingRect);
662
+ }
663
+ }
664
+ // If the node has an RTT parent and requires a texture re-render, inform the RTT parent
665
+ // if (this.parentHasRenderTexture && updateType & UpdateType.RenderTexture) {
666
+ // @TODO have a more scoped down updateType for RTT updates
667
+ if (USE_RTT === true && parentHasRenderTexture === true) {
668
+ this.notifyParentRTTOfUpdate();
669
+ }
670
+ //Resort children if needed
671
+ if (updateType & UpdateType.SortZIndexChildren) {
672
+ // reorder z-index
673
+ this.sortChildren();
674
+ }
675
+ // If we're out of bounds, apply the render state now
676
+ // this is done so nodes can finish their entire update loop before
677
+ // being marked as out of bounds
678
+ if (newRenderState === CoreNodeRenderState.OutOfBounds) {
679
+ this.updateRenderState(newRenderState);
680
+ this.updateIsRenderable();
681
+ if (USE_RTT === true &&
682
+ this.rtt === true &&
683
+ newRenderState === CoreNodeRenderState.OutOfBounds) {
684
+ // notify children that we are going out of bounds
685
+ // we have to do this now before we stop processing the render tree
686
+ this.notifyChildrenRTTOfUpdate(newRenderState);
687
+ }
688
+ }
689
+ // Mark quad dirty only when visual data (transforms, colors) actually
690
+ // changed, so the WebGL renderer only re-uploads modified slots.
691
+ if (updateType &
692
+ (UpdateType.Global |
693
+ UpdateType.PremultipliedColors |
694
+ UpdateType.WorldAlpha)) {
695
+ this.isQuadDirty = true;
696
+ }
697
+ }
698
+ findParentRTTNode() {
699
+ let rttNode = this.parent;
700
+ while (rttNode && !rttNode.rtt) {
701
+ rttNode = rttNode.parent;
702
+ }
703
+ return rttNode;
704
+ }
705
+ notifyChildrenRTTOfUpdate(renderState) {
706
+ for (const child of this.children) {
707
+ // force child to update render state
708
+ child.updateRenderState(renderState);
709
+ child.updateIsRenderable();
710
+ child.notifyChildrenRTTOfUpdate(renderState);
711
+ }
712
+ }
713
+ notifyParentRTTOfUpdate() {
714
+ if (this.parent === null) {
715
+ return;
716
+ }
717
+ const rttNode = this.rttParent || this.findParentRTTNode();
718
+ if (!rttNode) {
719
+ return;
720
+ }
721
+ // If an RTT node is found, mark it for re-rendering
722
+ rttNode.hasRTTupdates = true;
723
+ rttNode.setUpdateType(UpdateType.RenderTexture);
724
+ // if rttNode is nested, also make it update its RTT parent
725
+ if (rttNode.parentHasRenderTexture === true) {
726
+ rttNode.notifyParentRTTOfUpdate();
727
+ }
728
+ }
729
+ checkRenderBounds() {
730
+ if (boundInsideBound(this.renderBound, this.strictBound)) {
731
+ return CoreNodeRenderState.InViewport;
732
+ }
733
+ if (boundInsideBound(this.renderBound, this.preloadBound)) {
734
+ return CoreNodeRenderState.InBounds;
735
+ }
736
+ // check if we're larger then our parent, we're definitely in the viewport
737
+ if (boundLargeThanBound(this.renderBound, this.strictBound)) {
738
+ return CoreNodeRenderState.InViewport;
739
+ }
740
+ // check if we dont have dimensions, take our parent's render state
741
+ if (this.parent !== null && (this.props.w === 0 || this.props.h === 0)) {
742
+ return this.parent.renderState;
743
+ }
744
+ return CoreNodeRenderState.OutOfBounds;
745
+ }
746
+ updateBoundingRect() {
747
+ const transform = (this.sceneGlobalTransform ||
748
+ this.globalTransform);
749
+ const renderCoords = (this.sceneRenderCoords ||
750
+ this.renderCoords);
751
+ if (transform.tb === 0 || transform.tc === 0) {
752
+ this.renderBound = createBound(renderCoords.x1, renderCoords.y1, renderCoords.x3, renderCoords.y3, this.renderBound);
753
+ }
754
+ else {
755
+ const { x1, y1, x2, y2, x3, y3, x4, y4 } = renderCoords;
756
+ this.renderBound = createBound(Math.min(x1, x2, x3, x4), Math.min(y1, y2, y3, y4), Math.max(x1, x2, x3, x4), Math.max(y1, y2, y3, y4), this.renderBound);
757
+ }
758
+ }
759
+ createRenderBounds() {
760
+ if (this.parent !== null && this.parent.strictBound !== undefined) {
761
+ // we have a parent with a valid bound, copy it
762
+ const parentBound = this.parent.strictBound;
763
+ this.strictBound = createBound(parentBound.x1, parentBound.y1, parentBound.x2, parentBound.y2, this.strictBound);
764
+ this.preloadBound = createPreloadBounds(this.strictBound, this.boundsMargin, this.preloadBound);
765
+ }
766
+ else {
767
+ // no parent or parent does not have a bound, take the stage boundaries
768
+ this.strictBound = this.stage.strictBound;
769
+ this.preloadBound = this.stage.preloadBound;
770
+ }
771
+ // if clipping is disabled, we're done
772
+ if (this.props.clipping === false) {
773
+ return;
774
+ }
775
+ // only create local clipping bounds if node itself is in bounds
776
+ // this can only be done if we have a render bound already
777
+ if (this.renderBound === undefined) {
778
+ return;
779
+ }
780
+ // if we're out of bounds, we're done
781
+ if (boundInsideBound(this.renderBound, this.strictBound) === false) {
782
+ return;
783
+ }
784
+ // clipping is enabled and we are in bounds create our own bounds
785
+ const { x, y, w, h } = this.props;
786
+ // Pick the global transform if available, otherwise use the local transform
787
+ // global transform is only available if the node in an RTT chain
788
+ const { tx, ty } = this.sceneGlobalTransform || this.globalTransform || {};
789
+ const _x = tx ?? x;
790
+ const _y = ty ?? y;
791
+ this.strictBound = createBound(_x, _y, _x + w, _y + h, this.strictBound);
792
+ this.preloadBound = createPreloadBounds(this.strictBound, this.boundsMargin, this.preloadBound);
793
+ }
794
+ updateRenderState(renderState) {
795
+ if (renderState === this.renderState) {
796
+ return;
797
+ }
798
+ const previous = this.renderState;
799
+ this.renderState = renderState;
800
+ // If node visibility changes, dirty the render list cache
801
+ if (renderState === CoreNodeRenderState.OutOfBounds ||
802
+ previous === CoreNodeRenderState.OutOfBounds) {
803
+ this.stage.requestRenderListUpdate();
804
+ }
805
+ if (EMIT_BOUNDS_EVENTS) {
806
+ const event = CoreNodeRenderStateMap.get(renderState);
807
+ assertTruthy(event);
808
+ this.emit(event, {
809
+ previous,
810
+ current: renderState,
811
+ });
812
+ }
813
+ }
814
+ /**
815
+ * Checks if the node is renderable based on world alpha, dimensions and out of bounds status.
816
+ */
817
+ checkBasicRenderability() {
818
+ if (this.worldAlpha === 0 || this.isOutOfBounds() === true) {
819
+ return false;
820
+ }
821
+ else {
822
+ return true;
823
+ }
824
+ }
825
+ /**
826
+ * Updates the `isRenderable` property based on various conditions.
827
+ */
828
+ updateIsRenderable() {
829
+ let newIsRenderable = false;
830
+ let needsTextureOwnership = false;
831
+ // If the node is out of bounds or has an alpha of 0, it is not renderable
832
+ if (this.checkBasicRenderability() === false) {
833
+ this.updateTextureOwnership(false);
834
+ this.setRenderable(false);
835
+ return;
836
+ }
837
+ if (this.texture !== null) {
838
+ // preemptive check for failed textures this will mark the current node as non-renderable
839
+ // and will prevent further checks until the texture is reloaded or retry is reset on the texture
840
+ if (this.texture.retryCount > this.texture.maxRetryCount) {
841
+ // texture has failed to load, we cannot render
842
+ this.updateTextureOwnership(false);
843
+ this.setRenderable(false);
844
+ return;
845
+ }
846
+ needsTextureOwnership = true;
847
+ // Use cached boolean instead of string comparison
848
+ newIsRenderable = this.textureLoaded;
849
+ }
850
+ else if (
851
+ // check shader
852
+ (this.props.shader !== this.stage.renderer.getDefaultShaderNode() ||
853
+ this.hasColorProps === true) &&
854
+ // check dimensions
855
+ this.hasDimensions() === true) {
856
+ // This mean we have dimensions and a color set, so we can render a ColorTexture
857
+ newIsRenderable = true;
858
+ }
859
+ this.updateTextureOwnership(needsTextureOwnership);
860
+ this.setRenderable(newIsRenderable);
861
+ }
862
+ /**
863
+ * Sets the renderable state and triggers changes if necessary.
864
+ * @param isRenderable - The new renderable state
865
+ */
866
+ setRenderable(isRenderable) {
867
+ const previousIsRenderable = this.isRenderable;
868
+ this.isRenderable = isRenderable;
869
+ // Emit event if renderable status has changed
870
+ if (previousIsRenderable !== isRenderable) {
871
+ this.stage.requestRenderListUpdate();
872
+ if (EMIT_BOUNDS_EVENTS) {
873
+ this.emit('renderable', {
874
+ type: 'renderable',
875
+ isRenderable,
876
+ });
877
+ }
878
+ }
879
+ }
880
+ /**
881
+ * Changes the renderable state of the node.
882
+ */
883
+ updateTextureOwnership(isRenderable) {
884
+ this.texture?.setRenderableOwner(this._id, isRenderable);
885
+ }
886
+ /**
887
+ * Checks if the node is out of the viewport bounds.
888
+ */
889
+ isOutOfBounds() {
890
+ return this.renderState <= CoreNodeRenderState.OutOfBounds;
891
+ }
892
+ /**
893
+ * Checks if the node has dimensions (width/height)
894
+ */
895
+ hasDimensions() {
896
+ return this.props.w !== 0 && this.props.h !== 0;
897
+ }
898
+ calculateRenderCoords() {
899
+ const { w, h } = this.props;
900
+ const g = this.globalTransform;
901
+ const tx = g.tx, ty = g.ty, ta = g.ta, tb = g.tb, tc = g.tc, td = g.td;
902
+ if (tb === 0 && tc === 0) {
903
+ const minX = tx;
904
+ const maxX = tx + w * ta;
905
+ const minY = ty;
906
+ const maxY = ty + h * td;
907
+ this.renderCoords = RenderCoords.translate(
908
+ //top-left
909
+ minX, minY,
910
+ //top-right
911
+ maxX, minY,
912
+ //bottom-right
913
+ maxX, maxY,
914
+ //bottom-left
915
+ minX, maxY, this.renderCoords);
916
+ }
917
+ else {
918
+ this.renderCoords = RenderCoords.translate(
919
+ //top-left
920
+ tx, ty,
921
+ //top-right
922
+ tx + w * ta, ty + w * tc,
923
+ //bottom-right
924
+ tx + w * ta + h * tb, ty + w * tc + h * td,
925
+ //bottom-left
926
+ tx + h * tb, ty + h * td, this.renderCoords);
927
+ }
928
+ if (!USE_RTT || this.sceneGlobalTransform === undefined) {
929
+ return;
930
+ }
931
+ const { tx: stx, ty: sty, ta: sta, tb: stb, tc: stc, td: std, } = this.sceneGlobalTransform;
932
+ if (stb === 0 && stc === 0) {
933
+ const minX = stx;
934
+ const maxX = stx + w * sta;
935
+ const minY = sty;
936
+ const maxY = sty + h * std;
937
+ this.sceneRenderCoords = RenderCoords.translate(
938
+ //top-left
939
+ minX, minY,
940
+ //top-right
941
+ maxX, minY,
942
+ //bottom-right
943
+ maxX, maxY,
944
+ //bottom-left
945
+ minX, maxY, this.sceneRenderCoords);
946
+ }
947
+ else {
948
+ this.sceneRenderCoords = RenderCoords.translate(
949
+ //top-left
950
+ stx, sty,
951
+ //top-right
952
+ stx + w * sta, sty + w * stc,
953
+ //bottom-right
954
+ stx + w * sta + h * stb, sty + w * stc + h * std,
955
+ //bottom-left
956
+ stx + h * stb, sty + h * std, this.sceneRenderCoords);
957
+ }
958
+ }
959
+ /**
960
+ * This function calculates the clipping rectangle for a node.
961
+ *
962
+ * The function then checks if the node is rotated. If the node requires clipping and is not rotated, a new clipping rectangle is created based on the node's global transform and dimensions.
963
+ * If a parent clipping rectangle exists, it is intersected with the node's clipping rectangle (if it exists), or replaces the node's clipping rectangle.
964
+ *
965
+ * Finally, the node's parentClippingRect and clippingRect properties are updated.
966
+ */
967
+ calculateClippingRect(parentClippingRect) {
968
+ const { clippingRect, props, globalTransform: gt } = this;
969
+ const { clipping } = props;
970
+ const isRotated = gt.tb !== 0 || gt.tc !== 0;
971
+ if (clipping === true && isRotated === false) {
972
+ clippingRect.x = gt.tx;
973
+ clippingRect.y = gt.ty;
974
+ clippingRect.width = this.props.w * gt.ta;
975
+ clippingRect.height = this.props.h * gt.td;
976
+ clippingRect.valid = true;
977
+ }
978
+ else {
979
+ clippingRect.valid = false;
980
+ }
981
+ if (parentClippingRect.valid === true && clippingRect.valid === true) {
982
+ // Intersect parent clipping rect with node clipping rect
983
+ intersectRect(parentClippingRect, clippingRect, clippingRect);
984
+ }
985
+ else if (parentClippingRect.valid === true) {
986
+ // Copy parent clipping rect
987
+ copyRect(parentClippingRect, clippingRect);
988
+ clippingRect.valid = true;
989
+ }
990
+ }
991
+ /**
992
+ * Destroy the node and cleanup all resources
993
+ */
994
+ destroy(isChild = false) {
995
+ if (this.destroyed === true || this.preventDestroy === true) {
996
+ if (isChild && this.preventDestroy === true) {
997
+ this.props.parent = null;
998
+ }
999
+ return;
1000
+ }
1001
+ this.destroyed = true;
1002
+ // Detach from parent first to stop propagation of updates
1003
+ if (isChild === false) {
1004
+ const parent = this.parent;
1005
+ if (parent !== null) {
1006
+ parent.removeChild(this);
1007
+ }
1008
+ this.props.parent = null;
1009
+ this.stage.requestRender();
1010
+ }
1011
+ this.removeAllListeners();
1012
+ this.unloadTexture();
1013
+ this.isRenderable = false;
1014
+ if (this.hasShaderTimeFn === true) {
1015
+ this.stage.untrackTimedNode(this);
1016
+ }
1017
+ if (USE_RTT && this.rtt === true) {
1018
+ this.stage.renderer.removeRTTNode(this);
1019
+ }
1020
+ // Kill children
1021
+ for (let i = 0, n = this.children.length; i < n; i++) {
1022
+ this.children[i].destroy(true);
1023
+ }
1024
+ this.children.length = 0;
1025
+ this.props.texture = null;
1026
+ }
1027
+ renderQuads(renderer) {
1028
+ if (USE_RTT && this.parentHasRenderTexture === true) {
1029
+ const rtt = renderer.renderToTextureActive;
1030
+ if (rtt === false || this.parentRenderTexture !== renderer.activeRttNode)
1031
+ return;
1032
+ }
1033
+ // There is a race condition where the texture can be null
1034
+ // with RTT nodes. Adding this defensively to avoid errors.
1035
+ // Also check if we have a valid texture or default texture to render
1036
+ if (USE_RTT && this.renderTexture.state !== 'loaded') {
1037
+ return;
1038
+ }
1039
+ renderer.addQuad(this);
1040
+ }
1041
+ get renderTexture() {
1042
+ return this.props.texture || this.stage.defaultTexture;
1043
+ }
1044
+ get renderTextureCoords() {
1045
+ return this.textureCoords || this.stage.renderer.defaultTextureCoords;
1046
+ }
1047
+ get quadBufferCollection() {
1048
+ return this.stage.renderer.quadBufferCollection;
1049
+ }
1050
+ get width() {
1051
+ return this.props.w;
1052
+ }
1053
+ get height() {
1054
+ return this.props.h;
1055
+ }
1056
+ get time() {
1057
+ if (this.hasShaderTimeFn === true) {
1058
+ return this.getTimerValue();
1059
+ }
1060
+ return 0;
1061
+ }
1062
+ getTimerValue() {
1063
+ if (typeof this.shader.time === 'function') {
1064
+ return this.shader.time(this.stage);
1065
+ }
1066
+ return this.stage.elapsedTime;
1067
+ }
1068
+ sortChildren() {
1069
+ this.children.sort((a, b) => a.props.zIndex - b.props.zIndex);
1070
+ this.stage.requestRenderListUpdate();
1071
+ }
1072
+ removeChild(node, targetParent = null) {
1073
+ if (targetParent === null) {
1074
+ if (USE_RTT &&
1075
+ this.props.rtt === true &&
1076
+ this.parentHasRenderTexture === true) {
1077
+ node.clearRTTInheritance();
1078
+ }
1079
+ if (ENABLE_AUTOSIZE) {
1080
+ const autosizeTarget = this.autosizer || this.parentAutosizer;
1081
+ if (autosizeTarget !== null) {
1082
+ autosizeTarget.detach(node);
1083
+ }
1084
+ }
1085
+ }
1086
+ removeChild(node, this.children);
1087
+ this.stage.requestRenderListUpdate();
1088
+ }
1089
+ addChild(node, previousParent = null) {
1090
+ const inRttCluster = USE_RTT &&
1091
+ (this.props.rtt === true || this.parentHasRenderTexture === true);
1092
+ const children = this.children;
1093
+ let attachToAutosizer = false;
1094
+ let autosizeTarget = null;
1095
+ if (ENABLE_AUTOSIZE) {
1096
+ autosizeTarget = this.autosizer || this.parentAutosizer;
1097
+ attachToAutosizer = autosizeTarget !== null;
1098
+ }
1099
+ node.parentHasRenderTexture = inRttCluster;
1100
+ if (previousParent !== null) {
1101
+ const previousParentInRttCluster = USE_RTT &&
1102
+ (previousParent.props.rtt === true ||
1103
+ previousParent.parentHasRenderTexture === true);
1104
+ if (inRttCluster === false && previousParentInRttCluster === true) {
1105
+ // update child RTT status
1106
+ node.clearRTTInheritance();
1107
+ }
1108
+ if (ENABLE_AUTOSIZE) {
1109
+ const previousAutosizer = node.autosizer || node.parentAutosizer;
1110
+ if (previousAutosizer !== null) {
1111
+ if (!autosizeTarget || previousAutosizer.id !== autosizeTarget.id) {
1112
+ previousAutosizer.detach(node);
1113
+ }
1114
+ attachToAutosizer = false;
1115
+ }
1116
+ }
1117
+ }
1118
+ if (ENABLE_AUTOSIZE && attachToAutosizer === true && autosizeTarget) {
1119
+ //if this is true, then the autosizer really exists
1120
+ autosizeTarget.attach(node);
1121
+ }
1122
+ if (inRttCluster === true) {
1123
+ node.markChildrenWithRTT(this);
1124
+ }
1125
+ children.push(node);
1126
+ // check if we need to sort
1127
+ const lastIndex = children.length - 1;
1128
+ let shouldSort = node.zIndex !== 0;
1129
+ if (shouldSort === false && lastIndex > 0) {
1130
+ // If the new node has zIndex 0, we check if any existing children have (had) non-zero zIndex.
1131
+ // Since children are sorted, we only need to check the first and the last (before the new one).
1132
+ // The new node is at `lastIndex`. The previous last node is at `lastIndex - 1`.
1133
+ const first = children[0];
1134
+ const last = children[lastIndex - 1];
1135
+ shouldSort = first.zIndex !== 0 || last.zIndex !== 0;
1136
+ }
1137
+ if (shouldSort) {
1138
+ this.setUpdateType(UpdateType.SortZIndexChildren);
1139
+ }
1140
+ this.setUpdateType(UpdateType.Children);
1141
+ this.stage.requestRenderListUpdate();
1142
+ }
1143
+ //#region Properties
1144
+ get id() {
1145
+ return this._id;
1146
+ }
1147
+ get data() {
1148
+ return this.props.data;
1149
+ }
1150
+ set data(d) {
1151
+ this.props.data = d;
1152
+ }
1153
+ get x() {
1154
+ return this.props.x;
1155
+ }
1156
+ set x(value) {
1157
+ if (this.props.x !== value) {
1158
+ this.props.x = value;
1159
+ this.setUpdateType(UpdateType.Local);
1160
+ }
1161
+ }
1162
+ get absX() {
1163
+ return (this.props.x +
1164
+ -this.props.w * this.props.mountX +
1165
+ (this.props.parent?.absX || this.props.parent?.globalTransform?.tx || 0));
1166
+ }
1167
+ get absY() {
1168
+ return (this.props.y +
1169
+ -this.props.h * this.props.mountY +
1170
+ (this.props.parent?.absY ?? 0));
1171
+ }
1172
+ get y() {
1173
+ return this.props.y;
1174
+ }
1175
+ set y(value) {
1176
+ if (this.props.y !== value) {
1177
+ this.props.y = value;
1178
+ this.setUpdateType(UpdateType.Local);
1179
+ }
1180
+ }
1181
+ get w() {
1182
+ return this.props.w;
1183
+ }
1184
+ set w(value) {
1185
+ const props = this.props;
1186
+ if (props.w !== value) {
1187
+ props.w = value;
1188
+ let updateType = UpdateType.Local;
1189
+ if (props.texture !== null &&
1190
+ this.stage.calculateTextureCoord === true &&
1191
+ props.textureOptions !== null) {
1192
+ this.textureCoords = this.stage.renderer.getTextureCoords(this);
1193
+ }
1194
+ if (props.rtt === true) {
1195
+ this.framebufferDimensions.w = value;
1196
+ this.texture = this.stage.txManager.createTexture('RenderTexture', this.framebufferDimensions);
1197
+ updateType |= UpdateType.RenderTexture;
1198
+ }
1199
+ this.setUpdateType(updateType);
1200
+ }
1201
+ }
1202
+ get h() {
1203
+ return this.props.h;
1204
+ }
1205
+ set h(value) {
1206
+ const props = this.props;
1207
+ if (props.h !== value) {
1208
+ props.h = value;
1209
+ let updateType = UpdateType.Local;
1210
+ if (props.texture !== null &&
1211
+ this.stage.calculateTextureCoord === true &&
1212
+ props.textureOptions !== null) {
1213
+ this.textureCoords = this.stage.renderer.getTextureCoords(this);
1214
+ }
1215
+ if (props.rtt === true) {
1216
+ this.framebufferDimensions.h = value;
1217
+ this.texture = this.stage.txManager.createTexture('RenderTexture', this.framebufferDimensions);
1218
+ updateType |= UpdateType.RenderTexture;
1219
+ }
1220
+ this.setUpdateType(updateType);
1221
+ }
1222
+ }
1223
+ get scale() {
1224
+ // The CoreNode `scale` property is only used by Animations.
1225
+ // Unlike INode, `null` should never be possibility for Animations.
1226
+ return this.scaleX;
1227
+ }
1228
+ set scale(value) {
1229
+ // The CoreNode `scale` property is only used by Animations.
1230
+ // Unlike INode, `null` should never be possibility for Animations.
1231
+ this.scaleX = value;
1232
+ this.scaleY = value;
1233
+ this.updateIsSimple();
1234
+ }
1235
+ get scaleX() {
1236
+ return this.props.scaleX;
1237
+ }
1238
+ set scaleX(value) {
1239
+ if (this.props.scaleX !== value) {
1240
+ this.props.scaleX = value;
1241
+ this.setUpdateType(UpdateType.Local);
1242
+ this.updateIsSimple();
1243
+ }
1244
+ }
1245
+ get scaleY() {
1246
+ return this.props.scaleY;
1247
+ }
1248
+ set scaleY(value) {
1249
+ if (this.props.scaleY !== value) {
1250
+ this.props.scaleY = value;
1251
+ this.setUpdateType(UpdateType.Local);
1252
+ this.updateIsSimple();
1253
+ }
1254
+ }
1255
+ get mount() {
1256
+ return this.props.mount;
1257
+ }
1258
+ set mount(value) {
1259
+ if (this.props.mountX !== value || this.props.mountY !== value) {
1260
+ this.props.mountX = value;
1261
+ this.props.mountY = value;
1262
+ this.props.mount = value;
1263
+ this.setUpdateType(UpdateType.Local);
1264
+ this.updateIsSimple();
1265
+ }
1266
+ }
1267
+ get mountX() {
1268
+ return this.props.mountX;
1269
+ }
1270
+ set mountX(value) {
1271
+ if (this.props.mountX !== value) {
1272
+ this.props.mountX = value;
1273
+ this.setUpdateType(UpdateType.Local);
1274
+ this.updateIsSimple();
1275
+ }
1276
+ }
1277
+ get mountY() {
1278
+ return this.props.mountY;
1279
+ }
1280
+ set mountY(value) {
1281
+ if (this.props.mountY !== value) {
1282
+ this.props.mountY = value;
1283
+ this.setUpdateType(UpdateType.Local);
1284
+ this.updateIsSimple();
1285
+ }
1286
+ }
1287
+ get pivot() {
1288
+ return this.props.pivot;
1289
+ }
1290
+ set pivot(value) {
1291
+ if (this.props.pivotX !== value || this.props.pivotY !== value) {
1292
+ this.props.pivotX = value;
1293
+ this.props.pivotY = value;
1294
+ this.props.pivot = value;
1295
+ this.setUpdateType(UpdateType.Local);
1296
+ }
1297
+ }
1298
+ get pivotX() {
1299
+ return this.props.pivotX;
1300
+ }
1301
+ set pivotX(value) {
1302
+ if (this.props.pivotX !== value) {
1303
+ this.props.pivotX = value;
1304
+ this.setUpdateType(UpdateType.Local);
1305
+ }
1306
+ }
1307
+ get pivotY() {
1308
+ return this.props.pivotY;
1309
+ }
1310
+ set pivotY(value) {
1311
+ if (this.props.pivotY !== value) {
1312
+ this.props.pivotY = value;
1313
+ this.setUpdateType(UpdateType.Local);
1314
+ }
1315
+ }
1316
+ get rotation() {
1317
+ return this.props.rotation;
1318
+ }
1319
+ set rotation(value) {
1320
+ if (this.props.rotation !== value) {
1321
+ this.props.rotation = value;
1322
+ this.setUpdateType(UpdateType.Local);
1323
+ this.updateIsSimple();
1324
+ }
1325
+ }
1326
+ get alpha() {
1327
+ return this.props.alpha;
1328
+ }
1329
+ set alpha(value) {
1330
+ this.props.alpha = value;
1331
+ this.setUpdateType(UpdateType.PremultipliedColors |
1332
+ UpdateType.WorldAlpha |
1333
+ UpdateType.Children |
1334
+ UpdateType.IsRenderable);
1335
+ this.childUpdateType |= UpdateType.WorldAlpha;
1336
+ }
1337
+ get autosize() {
1338
+ return this.props.autosize;
1339
+ }
1340
+ set autosize(value) {
1341
+ if (this.props.autosize === value) {
1342
+ return;
1343
+ }
1344
+ this.props.autosize = value;
1345
+ if (value === true && this.autosizer === null) {
1346
+ this.autosizer = new Autosizer(this);
1347
+ }
1348
+ else {
1349
+ this.autosizer = null;
1350
+ }
1351
+ }
1352
+ get boundsMargin() {
1353
+ const props = this.props;
1354
+ if (props.boundsMargin !== null) {
1355
+ return props.boundsMargin;
1356
+ }
1357
+ const parent = this.parent;
1358
+ if (parent !== null) {
1359
+ const margin = parent.boundsMargin;
1360
+ if (margin !== undefined) {
1361
+ return margin;
1362
+ }
1363
+ }
1364
+ return this.stage.boundsMargin;
1365
+ }
1366
+ set boundsMargin(value) {
1367
+ if (value === this.props.boundsMargin) {
1368
+ return;
1369
+ }
1370
+ if (value === null) {
1371
+ this.props.boundsMargin = value;
1372
+ }
1373
+ else {
1374
+ const bm = Array.isArray(value)
1375
+ ? value
1376
+ : [value, value, value, value];
1377
+ this.props.boundsMargin = bm;
1378
+ }
1379
+ this.setUpdateType(UpdateType.RenderBounds);
1380
+ }
1381
+ get clipping() {
1382
+ return this.props.clipping;
1383
+ }
1384
+ set clipping(value) {
1385
+ this.props.clipping = value;
1386
+ this.setUpdateType(UpdateType.Clipping | UpdateType.RenderBounds | UpdateType.Children);
1387
+ this.childUpdateType |= UpdateType.Global | UpdateType.Clipping;
1388
+ }
1389
+ get color() {
1390
+ return this.props.color;
1391
+ }
1392
+ set color(value) {
1393
+ const p = this.props;
1394
+ if (p.color === value)
1395
+ return;
1396
+ p.color = value;
1397
+ const has = value > 0;
1398
+ if (has !== this.hasColorProps) {
1399
+ this.setUpdateType(UpdateType.IsRenderable);
1400
+ }
1401
+ this.hasColorProps = has;
1402
+ if (p.colorTop !== value)
1403
+ this.colorTop = value;
1404
+ if (p.colorBottom !== value)
1405
+ this.colorBottom = value;
1406
+ if (p.colorLeft !== value)
1407
+ this.colorLeft = value;
1408
+ if (p.colorRight !== value)
1409
+ this.colorRight = value;
1410
+ this.setUpdateType(UpdateType.PremultipliedColors);
1411
+ }
1412
+ get colorTop() {
1413
+ return this.props.colorTop;
1414
+ }
1415
+ set colorTop(value) {
1416
+ if (this.props.colorTl !== value || this.props.colorTr !== value) {
1417
+ this.colorTl = value;
1418
+ this.colorTr = value;
1419
+ }
1420
+ this.props.colorTop = value;
1421
+ this.hasColorProps = value > 0;
1422
+ this.setUpdateType(UpdateType.PremultipliedColors | UpdateType.IsRenderable);
1423
+ }
1424
+ get colorBottom() {
1425
+ return this.props.colorBottom;
1426
+ }
1427
+ set colorBottom(value) {
1428
+ if (this.props.colorBl !== value || this.props.colorBr !== value) {
1429
+ this.colorBl = value;
1430
+ this.colorBr = value;
1431
+ }
1432
+ this.props.colorBottom = value;
1433
+ this.hasColorProps = value > 0;
1434
+ this.setUpdateType(UpdateType.PremultipliedColors | UpdateType.IsRenderable);
1435
+ }
1436
+ get colorLeft() {
1437
+ return this.props.colorLeft;
1438
+ }
1439
+ set colorLeft(value) {
1440
+ if (this.props.colorTl !== value || this.props.colorBl !== value) {
1441
+ this.colorTl = value;
1442
+ this.colorBl = value;
1443
+ }
1444
+ this.props.colorLeft = value;
1445
+ this.hasColorProps = value > 0;
1446
+ this.setUpdateType(UpdateType.PremultipliedColors | UpdateType.IsRenderable);
1447
+ }
1448
+ get colorRight() {
1449
+ return this.props.colorRight;
1450
+ }
1451
+ set colorRight(value) {
1452
+ if (this.props.colorTr !== value || this.props.colorBr !== value) {
1453
+ this.colorTr = value;
1454
+ this.colorBr = value;
1455
+ }
1456
+ this.props.colorRight = value;
1457
+ this.hasColorProps = value > 0;
1458
+ this.setUpdateType(UpdateType.PremultipliedColors | UpdateType.IsRenderable);
1459
+ }
1460
+ get colorTl() {
1461
+ return this.props.colorTl;
1462
+ }
1463
+ set colorTl(value) {
1464
+ this.props.colorTl = value;
1465
+ this.hasColorProps = value > 0;
1466
+ this.setUpdateType(UpdateType.PremultipliedColors | UpdateType.IsRenderable);
1467
+ }
1468
+ get colorTr() {
1469
+ return this.props.colorTr;
1470
+ }
1471
+ set colorTr(value) {
1472
+ this.props.colorTr = value;
1473
+ this.hasColorProps = value > 0;
1474
+ this.setUpdateType(UpdateType.PremultipliedColors | UpdateType.IsRenderable);
1475
+ }
1476
+ get colorBl() {
1477
+ return this.props.colorBl;
1478
+ }
1479
+ set colorBl(value) {
1480
+ this.props.colorBl = value;
1481
+ this.hasColorProps = value > 0;
1482
+ this.setUpdateType(UpdateType.PremultipliedColors | UpdateType.IsRenderable);
1483
+ }
1484
+ get colorBr() {
1485
+ return this.props.colorBr;
1486
+ }
1487
+ set colorBr(value) {
1488
+ this.props.colorBr = value;
1489
+ this.hasColorProps = value > 0;
1490
+ this.setUpdateType(UpdateType.PremultipliedColors | UpdateType.IsRenderable);
1491
+ }
1492
+ get zIndex() {
1493
+ return this.props.zIndex;
1494
+ }
1495
+ set zIndex(value) {
1496
+ let sanitizedValue = value;
1497
+ if (isNaN(sanitizedValue) || Number.isFinite(sanitizedValue) === false) {
1498
+ console.warn(`zIndex was set to an invalid value: ${value}, defaulting to 0`);
1499
+ sanitizedValue = 0;
1500
+ }
1501
+ //Clamp to safe integer range
1502
+ if (sanitizedValue > Number.MAX_SAFE_INTEGER) {
1503
+ sanitizedValue = 1000;
1504
+ }
1505
+ else if (sanitizedValue < Number.MIN_SAFE_INTEGER) {
1506
+ sanitizedValue = -1000;
1507
+ }
1508
+ if (this.props.zIndex === sanitizedValue) {
1509
+ return;
1510
+ }
1511
+ this.props.zIndex = sanitizedValue;
1512
+ const parent = this.parent;
1513
+ if (parent !== null) {
1514
+ parent.setUpdateType(UpdateType.SortZIndexChildren);
1515
+ }
1516
+ }
1517
+ get parent() {
1518
+ return this.props.parent;
1519
+ }
1520
+ set parent(newParent) {
1521
+ const oldParent = this.props.parent;
1522
+ if (oldParent === newParent) {
1523
+ return;
1524
+ }
1525
+ this.props.parent = newParent;
1526
+ if (oldParent) {
1527
+ oldParent.removeChild(this, newParent);
1528
+ }
1529
+ if (newParent !== null) {
1530
+ newParent.addChild(this, oldParent);
1531
+ }
1532
+ //since this node has a new parent, recalc global and render bounds
1533
+ this.setUpdateType(UpdateType.Global | UpdateType.RenderBounds);
1534
+ }
1535
+ get rtt() {
1536
+ return this.props.rtt;
1537
+ }
1538
+ set rtt(value) {
1539
+ if (this.props.rtt === value) {
1540
+ return;
1541
+ }
1542
+ this.props.rtt = value;
1543
+ if (value === true) {
1544
+ this.initRenderTexture();
1545
+ this.markChildrenWithRTT();
1546
+ }
1547
+ else {
1548
+ this.cleanupRenderTexture();
1549
+ }
1550
+ this.setUpdateType(UpdateType.RenderTexture);
1551
+ if (this.parentHasRenderTexture === true) {
1552
+ this.notifyParentRTTOfUpdate();
1553
+ }
1554
+ }
1555
+ get preventDestroy() {
1556
+ return this.props.preventDestroy;
1557
+ }
1558
+ set preventDestroy(value) {
1559
+ this.props.preventDestroy = value;
1560
+ }
1561
+ initRenderTexture() {
1562
+ this.framebufferDimensions = {
1563
+ w: this.props.w,
1564
+ h: this.props.h,
1565
+ };
1566
+ this.texture = this.stage.txManager.createTexture('RenderTexture', this.framebufferDimensions);
1567
+ this.stage.renderer.renderToTexture(this);
1568
+ }
1569
+ cleanupRenderTexture() {
1570
+ this.unloadTexture();
1571
+ this.clearRTTInheritance();
1572
+ this.hasRTTupdates = false;
1573
+ this.texture = null;
1574
+ this.framebufferDimensions = null;
1575
+ }
1576
+ markChildrenWithRTT(node = null) {
1577
+ const parent = node || this;
1578
+ for (const child of parent.children) {
1579
+ child.setUpdateType(UpdateType.All);
1580
+ child.parentHasRenderTexture = true;
1581
+ child.markChildrenWithRTT();
1582
+ }
1583
+ }
1584
+ // Apply RTT inheritance when a node has an RTT-enabled parent
1585
+ applyRTTInheritance(parent) {
1586
+ if (parent.rtt) {
1587
+ // Only the RTT node should be added to `renderToTexture`
1588
+ parent.setUpdateType(UpdateType.RenderTexture);
1589
+ }
1590
+ // Propagate `parentHasRenderTexture` downwards
1591
+ this.markChildrenWithRTT(parent);
1592
+ }
1593
+ // Clear RTT inheritance when detaching from an RTT chain
1594
+ clearRTTInheritance() {
1595
+ // if this node is RTT itself stop the propagation important for nested RTT nodes
1596
+ // for the initial RTT node this is already handled in `set rtt`
1597
+ if (this.rtt) {
1598
+ return;
1599
+ }
1600
+ for (const child of this.children) {
1601
+ // force child to update everything as the RTT inheritance has changed
1602
+ child.parentHasRenderTexture = false;
1603
+ child.rttParent = null;
1604
+ child.setUpdateType(UpdateType.All);
1605
+ child.clearRTTInheritance();
1606
+ }
1607
+ }
1608
+ get shader() {
1609
+ return this.props.shader;
1610
+ }
1611
+ set shader(shader) {
1612
+ if (this.props.shader === shader) {
1613
+ return;
1614
+ }
1615
+ if (shader === null) {
1616
+ this.hasShaderUpdater = false;
1617
+ this.props.shader = this.stage.defShaderNode;
1618
+ this.setUpdateType(UpdateType.IsRenderable);
1619
+ return;
1620
+ }
1621
+ if (shader.shaderKey !== 'default') {
1622
+ this.hasShaderUpdater = shader.update !== undefined;
1623
+ this.hasShaderTimeFn = shader.time !== undefined;
1624
+ shader.attachNode(this);
1625
+ }
1626
+ if (this.hasShaderTimeFn === true) {
1627
+ this.stage.trackTimedNode(this);
1628
+ }
1629
+ else {
1630
+ this.stage.untrackTimedNode(this);
1631
+ }
1632
+ this.props.shader = shader;
1633
+ this.setUpdateType(UpdateType.IsRenderable | UpdateType.RecalcUniforms);
1634
+ }
1635
+ get src() {
1636
+ return this.props.src;
1637
+ }
1638
+ set src(imageUrl) {
1639
+ if (this.props.src === imageUrl) {
1640
+ return;
1641
+ }
1642
+ this.props.src = imageUrl;
1643
+ if (!imageUrl) {
1644
+ this.texture = null;
1645
+ return;
1646
+ }
1647
+ this.texture = this.stage.txManager.createTexture('ImageTexture', {
1648
+ src: imageUrl,
1649
+ w: this.props.w,
1650
+ h: this.props.h,
1651
+ type: this.props.imageType,
1652
+ sx: this.props.srcX,
1653
+ sy: this.props.srcY,
1654
+ sw: this.props.srcWidth,
1655
+ sh: this.props.srcHeight,
1656
+ });
1657
+ }
1658
+ set imageType(type) {
1659
+ if (this.props.imageType === type) {
1660
+ return;
1661
+ }
1662
+ this.props.imageType = type;
1663
+ }
1664
+ get imageType() {
1665
+ return this.props.imageType || null;
1666
+ }
1667
+ get srcHeight() {
1668
+ return this.props.srcHeight;
1669
+ }
1670
+ set srcHeight(value) {
1671
+ this.props.srcHeight = value;
1672
+ }
1673
+ get srcWidth() {
1674
+ return this.props.srcWidth;
1675
+ }
1676
+ set srcWidth(value) {
1677
+ this.props.srcWidth = value;
1678
+ }
1679
+ get srcX() {
1680
+ return this.props.srcX;
1681
+ }
1682
+ set srcX(value) {
1683
+ this.props.srcX = value;
1684
+ }
1685
+ get srcY() {
1686
+ return this.props.srcY;
1687
+ }
1688
+ set srcY(value) {
1689
+ this.props.srcY = value;
1690
+ }
1691
+ /**
1692
+ * Returns the framebuffer dimensions of the RTT parent
1693
+ */
1694
+ get parentFramebufferDimensions() {
1695
+ if (this.rttParent !== null) {
1696
+ return this.rttParent.framebufferDimensions;
1697
+ }
1698
+ this.rttParent = this.findParentRTTNode();
1699
+ return this.rttParent ? this.rttParent.framebufferDimensions : null;
1700
+ }
1701
+ /**
1702
+ * Returns the parent render texture node if it exists.
1703
+ */
1704
+ get parentRenderTexture() {
1705
+ let parent = this.parent;
1706
+ while (parent) {
1707
+ if (parent.rtt) {
1708
+ return parent;
1709
+ }
1710
+ parent = parent.parent;
1711
+ }
1712
+ return null;
1713
+ }
1714
+ get texture() {
1715
+ return this.props.texture;
1716
+ }
1717
+ set texture(value) {
1718
+ if (this.props.texture === value) {
1719
+ return;
1720
+ }
1721
+ const oldTexture = this.props.texture;
1722
+ if (oldTexture) {
1723
+ this.unloadTexture();
1724
+ if (this.autosizer !== null && value === null) {
1725
+ this.autosizer.setMode(AutosizeMode.Children); // Set to children size mode
1726
+ }
1727
+ }
1728
+ this.textureCoords = undefined;
1729
+ this.props.texture = value;
1730
+ this.textureLoaded = value !== null && value.state === 'loaded';
1731
+ if (value !== null) {
1732
+ if (this.autosizer !== null) {
1733
+ this.autosizer.setMode(AutosizeMode.Texture); // Set to texture size mode
1734
+ }
1735
+ value.setRenderableOwner(this._id, this.isRenderable);
1736
+ this.loadTexture();
1737
+ }
1738
+ this.setUpdateType(UpdateType.IsRenderable);
1739
+ this.updateIsSimple();
1740
+ }
1741
+ set textureOptions(value) {
1742
+ this.props.textureOptions = value;
1743
+ if (this.stage.calculateTextureCoord === true && value !== null) {
1744
+ this.textureCoords = this.stage.renderer.getTextureCoords(this);
1745
+ }
1746
+ this.updateIsSimple();
1747
+ }
1748
+ get textureOptions() {
1749
+ return this.props.textureOptions;
1750
+ }
1751
+ set interactive(value) {
1752
+ this.props.interactive = value;
1753
+ // Update Stage's interactive Set
1754
+ if (value === true) {
1755
+ this.stage.interactiveNodes.add(this);
1756
+ }
1757
+ }
1758
+ get interactive() {
1759
+ return this.props.interactive;
1760
+ }
1761
+ setRTTUpdates(type) {
1762
+ this.hasRTTupdates = true;
1763
+ this.parent?.setRTTUpdates(type);
1764
+ }
1765
+ animate(props, settings) {
1766
+ return createAnimation(this.stage.animationManager, this, props, settings);
1767
+ }
1768
+ animateProp(name, value, settings) {
1769
+ const existing = this._animations[name];
1770
+ if (existing && existing.settings === settings) {
1771
+ const controller = existing.controller;
1772
+ const values = controller.props ? controller.props[name] : null;
1773
+ if (values) {
1774
+ values.start = this[name] ?? 0;
1775
+ values.target = value;
1776
+ controller.progress = 0;
1777
+ return controller.start();
1778
+ }
1779
+ }
1780
+ const animationProps = { [name]: value };
1781
+ const controller = createAnimation(this.stage.animationManager, this, animationProps, settings);
1782
+ this._animations[name] = { controller, settings };
1783
+ return controller.start();
1784
+ }
1785
+ flush() {
1786
+ // no-op
1787
+ }
1788
+ /**
1789
+ * Add a texture to the current RenderOp.
1790
+ *
1791
+ * @param texture
1792
+ * @returns Assigned Texture Index of the texture in the render op
1793
+ */
1794
+ addTexture(texture) {
1795
+ const textures = this.renderOpTextures;
1796
+ const length = textures.length;
1797
+ for (let i = 0; i < length; i++) {
1798
+ if (textures[i] === texture) {
1799
+ return i;
1800
+ }
1801
+ }
1802
+ if (length >= 1) {
1803
+ return 0xffffffff;
1804
+ }
1805
+ textures.push(texture);
1806
+ return length;
1807
+ }
1808
+ draw(renderer) {
1809
+ const { glw, options, stage } = renderer;
1810
+ const shader = this.props.shader;
1811
+ stage.shManager.useShader(shader.program);
1812
+ shader.program.bindRenderOp(this);
1813
+ // Clipping
1814
+ if (this.clippingRect.valid === true) {
1815
+ const pixelRatio = USE_RTT && this.parentHasRenderTexture ? 1 : stage.pixelRatio;
1816
+ const clipX = Math.round(this.clippingRect.x * pixelRatio);
1817
+ const clipWidth = Math.round(this.clippingRect.width * pixelRatio);
1818
+ const clipHeight = Math.round(this.clippingRect.height * pixelRatio);
1819
+ let clipY = Math.round(options.canvas.height - clipHeight - this.clippingRect.y * pixelRatio);
1820
+ // if parent has render texture, we need to adjust the scissor rect
1821
+ // to be relative to the parent's framebuffer
1822
+ if (USE_RTT && this.parentHasRenderTexture) {
1823
+ clipY = this.parentFramebufferDimensions
1824
+ ? this.parentFramebufferDimensions.h - this.props.h
1825
+ : 0;
1826
+ }
1827
+ glw.setScissorTest(true);
1828
+ glw.scissor(clipX, clipY, clipWidth, clipHeight);
1829
+ }
1830
+ else {
1831
+ glw.setScissorTest(false);
1832
+ }
1833
+ const quadIdx = (this.renderOpBufferIdx / 20) * 6 * 2;
1834
+ glw.drawElements(glw.TRIANGLES, 6 * this.numQuads, glw.UNSIGNED_SHORT, quadIdx);
1835
+ }
1836
+ }
1837
+ //# sourceMappingURL=CoreNode.js.map