@onerjs/gui 8.23.1

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 (354) hide show
  1. package/2D/FrameGraph/guiTask.d.ts +34 -0
  2. package/2D/FrameGraph/guiTask.js +62 -0
  3. package/2D/FrameGraph/guiTask.js.map +1 -0
  4. package/2D/FrameGraph/renderGraphGUIBlock.d.ts +43 -0
  5. package/2D/FrameGraph/renderGraphGUIBlock.js +66 -0
  6. package/2D/FrameGraph/renderGraphGUIBlock.js.map +1 -0
  7. package/2D/adtInstrumentation.d.ts +52 -0
  8. package/2D/adtInstrumentation.js +107 -0
  9. package/2D/adtInstrumentation.js.map +1 -0
  10. package/2D/advancedDynamicTexture.d.ts +548 -0
  11. package/2D/advancedDynamicTexture.js +1522 -0
  12. package/2D/advancedDynamicTexture.js.map +1 -0
  13. package/2D/controls/button.d.ts +109 -0
  14. package/2D/controls/button.js +246 -0
  15. package/2D/controls/button.js.map +1 -0
  16. package/2D/controls/checkbox.d.ts +53 -0
  17. package/2D/controls/checkbox.js +164 -0
  18. package/2D/controls/checkbox.js.map +1 -0
  19. package/2D/controls/colorpicker.d.ts +101 -0
  20. package/2D/controls/colorpicker.js +1396 -0
  21. package/2D/controls/colorpicker.js.map +1 -0
  22. package/2D/controls/container.d.ts +179 -0
  23. package/2D/controls/container.js +616 -0
  24. package/2D/controls/container.js.map +1 -0
  25. package/2D/controls/control.d.ts +943 -0
  26. package/2D/controls/control.js +2460 -0
  27. package/2D/controls/control.js.map +1 -0
  28. package/2D/controls/displayGrid.d.ts +53 -0
  29. package/2D/controls/displayGrid.js +202 -0
  30. package/2D/controls/displayGrid.js.map +1 -0
  31. package/2D/controls/ellipse.d.ts +25 -0
  32. package/2D/controls/ellipse.js +93 -0
  33. package/2D/controls/ellipse.js.map +1 -0
  34. package/2D/controls/focusableButton.d.ts +17 -0
  35. package/2D/controls/focusableButton.js +25 -0
  36. package/2D/controls/focusableButton.js.map +1 -0
  37. package/2D/controls/focusableControl.d.ts +43 -0
  38. package/2D/controls/focusableControl.js +2 -0
  39. package/2D/controls/focusableControl.js.map +1 -0
  40. package/2D/controls/gradient/BaseGradient.d.ts +69 -0
  41. package/2D/controls/gradient/BaseGradient.js +84 -0
  42. package/2D/controls/gradient/BaseGradient.js.map +1 -0
  43. package/2D/controls/gradient/LinearGradient.d.ts +45 -0
  44. package/2D/controls/gradient/LinearGradient.js +73 -0
  45. package/2D/controls/gradient/LinearGradient.js.map +1 -0
  46. package/2D/controls/gradient/RadialGradient.d.ts +53 -0
  47. package/2D/controls/gradient/RadialGradient.js +89 -0
  48. package/2D/controls/gradient/RadialGradient.js.map +1 -0
  49. package/2D/controls/grid.d.ts +151 -0
  50. package/2D/controls/grid.js +528 -0
  51. package/2D/controls/grid.js.map +1 -0
  52. package/2D/controls/image.d.ts +228 -0
  53. package/2D/controls/image.js +915 -0
  54. package/2D/controls/image.js.map +1 -0
  55. package/2D/controls/index.d.ts +34 -0
  56. package/2D/controls/index.js +35 -0
  57. package/2D/controls/index.js.map +1 -0
  58. package/2D/controls/inputPassword.d.ts +9 -0
  59. package/2D/controls/inputPassword.js +22 -0
  60. package/2D/controls/inputPassword.js.map +1 -0
  61. package/2D/controls/inputText.d.ts +197 -0
  62. package/2D/controls/inputText.js +1035 -0
  63. package/2D/controls/inputText.js.map +1 -0
  64. package/2D/controls/inputTextArea.d.ts +142 -0
  65. package/2D/controls/inputTextArea.js +1025 -0
  66. package/2D/controls/inputTextArea.js.map +1 -0
  67. package/2D/controls/line.d.ts +73 -0
  68. package/2D/controls/line.js +227 -0
  69. package/2D/controls/line.js.map +1 -0
  70. package/2D/controls/multiLine.d.ts +75 -0
  71. package/2D/controls/multiLine.js +237 -0
  72. package/2D/controls/multiLine.js.map +1 -0
  73. package/2D/controls/radioButton.d.ts +49 -0
  74. package/2D/controls/radioButton.js +185 -0
  75. package/2D/controls/radioButton.js.map +1 -0
  76. package/2D/controls/rectangle.d.ts +43 -0
  77. package/2D/controls/rectangle.js +204 -0
  78. package/2D/controls/rectangle.js.map +1 -0
  79. package/2D/controls/scrollViewers/scrollViewer.d.ts +178 -0
  80. package/2D/controls/scrollViewers/scrollViewer.js +587 -0
  81. package/2D/controls/scrollViewers/scrollViewer.js.map +1 -0
  82. package/2D/controls/scrollViewers/scrollViewerWindow.d.ts +51 -0
  83. package/2D/controls/scrollViewers/scrollViewerWindow.js +254 -0
  84. package/2D/controls/scrollViewers/scrollViewerWindow.js.map +1 -0
  85. package/2D/controls/selector.d.ts +237 -0
  86. package/2D/controls/selector.js +579 -0
  87. package/2D/controls/selector.js.map +1 -0
  88. package/2D/controls/sliders/baseSlider.d.ts +80 -0
  89. package/2D/controls/sliders/baseSlider.js +299 -0
  90. package/2D/controls/sliders/baseSlider.js.map +1 -0
  91. package/2D/controls/sliders/imageBasedSlider.d.ts +47 -0
  92. package/2D/controls/sliders/imageBasedSlider.js +168 -0
  93. package/2D/controls/sliders/imageBasedSlider.js.map +1 -0
  94. package/2D/controls/sliders/imageScrollBar.d.ts +67 -0
  95. package/2D/controls/sliders/imageScrollBar.js +248 -0
  96. package/2D/controls/sliders/imageScrollBar.js.map +1 -0
  97. package/2D/controls/sliders/scrollBar.d.ts +50 -0
  98. package/2D/controls/sliders/scrollBar.js +175 -0
  99. package/2D/controls/sliders/scrollBar.js.map +1 -0
  100. package/2D/controls/sliders/slider.d.ts +46 -0
  101. package/2D/controls/sliders/slider.js +281 -0
  102. package/2D/controls/sliders/slider.js.map +1 -0
  103. package/2D/controls/stackPanel.d.ts +64 -0
  104. package/2D/controls/stackPanel.js +244 -0
  105. package/2D/controls/stackPanel.js.map +1 -0
  106. package/2D/controls/statics.d.ts +6 -0
  107. package/2D/controls/statics.js +50 -0
  108. package/2D/controls/statics.js.map +1 -0
  109. package/2D/controls/textBlock.d.ts +219 -0
  110. package/2D/controls/textBlock.js +670 -0
  111. package/2D/controls/textBlock.js.map +1 -0
  112. package/2D/controls/textWrapper.d.ts +13 -0
  113. package/2D/controls/textWrapper.js +88 -0
  114. package/2D/controls/textWrapper.js.map +1 -0
  115. package/2D/controls/toggleButton.d.ts +93 -0
  116. package/2D/controls/toggleButton.js +229 -0
  117. package/2D/controls/toggleButton.js.map +1 -0
  118. package/2D/controls/virtualKeyboard.d.ts +102 -0
  119. package/2D/controls/virtualKeyboard.js +275 -0
  120. package/2D/controls/virtualKeyboard.js.map +1 -0
  121. package/2D/index.d.ts +11 -0
  122. package/2D/index.js +13 -0
  123. package/2D/index.js.map +1 -0
  124. package/2D/math2D.d.ts +136 -0
  125. package/2D/math2D.js +235 -0
  126. package/2D/math2D.js.map +1 -0
  127. package/2D/measure.d.ts +77 -0
  128. package/2D/measure.js +138 -0
  129. package/2D/measure.js.map +1 -0
  130. package/2D/multiLinePoint.d.ts +47 -0
  131. package/2D/multiLinePoint.js +110 -0
  132. package/2D/multiLinePoint.js.map +1 -0
  133. package/2D/style.d.ts +46 -0
  134. package/2D/style.js +80 -0
  135. package/2D/style.js.map +1 -0
  136. package/2D/valueAndUnit.d.ts +89 -0
  137. package/2D/valueAndUnit.js +194 -0
  138. package/2D/valueAndUnit.js.map +1 -0
  139. package/2D/xmlLoader.d.ts +60 -0
  140. package/2D/xmlLoader.js +348 -0
  141. package/2D/xmlLoader.js.map +1 -0
  142. package/3D/behaviors/defaultBehavior.d.ts +73 -0
  143. package/3D/behaviors/defaultBehavior.js +103 -0
  144. package/3D/behaviors/defaultBehavior.js.map +1 -0
  145. package/3D/controls/MRTK3/touchHolographicButton.d.ts +220 -0
  146. package/3D/controls/MRTK3/touchHolographicButton.js +868 -0
  147. package/3D/controls/MRTK3/touchHolographicButton.js.map +1 -0
  148. package/3D/controls/abstractButton3D.d.ts +15 -0
  149. package/3D/controls/abstractButton3D.js +22 -0
  150. package/3D/controls/abstractButton3D.js.map +1 -0
  151. package/3D/controls/button3D.d.ts +51 -0
  152. package/3D/controls/button3D.js +98 -0
  153. package/3D/controls/button3D.js.map +1 -0
  154. package/3D/controls/container3D.d.ts +72 -0
  155. package/3D/controls/container3D.js +126 -0
  156. package/3D/controls/container3D.js.map +1 -0
  157. package/3D/controls/contentDisplay3D.d.ts +42 -0
  158. package/3D/controls/contentDisplay3D.js +81 -0
  159. package/3D/controls/contentDisplay3D.js.map +1 -0
  160. package/3D/controls/control3D.d.ts +183 -0
  161. package/3D/controls/control3D.js +401 -0
  162. package/3D/controls/control3D.js.map +1 -0
  163. package/3D/controls/cylinderPanel.d.ts +17 -0
  164. package/3D/controls/cylinderPanel.js +57 -0
  165. package/3D/controls/cylinderPanel.js.map +1 -0
  166. package/3D/controls/handMenu.d.ts +28 -0
  167. package/3D/controls/handMenu.js +39 -0
  168. package/3D/controls/handMenu.js.map +1 -0
  169. package/3D/controls/holographicBackplate.d.ts +49 -0
  170. package/3D/controls/holographicBackplate.js +104 -0
  171. package/3D/controls/holographicBackplate.js.map +1 -0
  172. package/3D/controls/holographicButton.d.ts +84 -0
  173. package/3D/controls/holographicButton.js +300 -0
  174. package/3D/controls/holographicButton.js.map +1 -0
  175. package/3D/controls/holographicSlate.d.ts +134 -0
  176. package/3D/controls/holographicSlate.js +413 -0
  177. package/3D/controls/holographicSlate.js.map +1 -0
  178. package/3D/controls/index.d.ts +22 -0
  179. package/3D/controls/index.js +24 -0
  180. package/3D/controls/index.js.map +1 -0
  181. package/3D/controls/meshButton3D.d.ts +21 -0
  182. package/3D/controls/meshButton3D.js +58 -0
  183. package/3D/controls/meshButton3D.js.map +1 -0
  184. package/3D/controls/nearMenu.d.ts +44 -0
  185. package/3D/controls/nearMenu.js +103 -0
  186. package/3D/controls/nearMenu.js.map +1 -0
  187. package/3D/controls/planePanel.d.ts +9 -0
  188. package/3D/controls/planePanel.js +30 -0
  189. package/3D/controls/planePanel.js.map +1 -0
  190. package/3D/controls/scatterPanel.d.ts +18 -0
  191. package/3D/controls/scatterPanel.js +98 -0
  192. package/3D/controls/scatterPanel.js.map +1 -0
  193. package/3D/controls/slider3D.d.ts +95 -0
  194. package/3D/controls/slider3D.js +256 -0
  195. package/3D/controls/slider3D.js.map +1 -0
  196. package/3D/controls/spherePanel.d.ts +17 -0
  197. package/3D/controls/spherePanel.js +58 -0
  198. package/3D/controls/spherePanel.js.map +1 -0
  199. package/3D/controls/stackPanel3D.d.ts +22 -0
  200. package/3D/controls/stackPanel3D.js +95 -0
  201. package/3D/controls/stackPanel3D.js.map +1 -0
  202. package/3D/controls/touchButton3D.d.ts +77 -0
  203. package/3D/controls/touchButton3D.js +205 -0
  204. package/3D/controls/touchButton3D.js.map +1 -0
  205. package/3D/controls/touchHolographicButton.d.ts +110 -0
  206. package/3D/controls/touchHolographicButton.js +400 -0
  207. package/3D/controls/touchHolographicButton.js.map +1 -0
  208. package/3D/controls/touchHolographicMenu.d.ts +61 -0
  209. package/3D/controls/touchHolographicMenu.js +139 -0
  210. package/3D/controls/touchHolographicMenu.js.map +1 -0
  211. package/3D/controls/touchMeshButton3D.d.ts +21 -0
  212. package/3D/controls/touchMeshButton3D.js +58 -0
  213. package/3D/controls/touchMeshButton3D.js.map +1 -0
  214. package/3D/controls/volumeBasedPanel.d.ts +53 -0
  215. package/3D/controls/volumeBasedPanel.js +158 -0
  216. package/3D/controls/volumeBasedPanel.js.map +1 -0
  217. package/3D/gizmos/gizmoHandle.d.ts +108 -0
  218. package/3D/gizmos/gizmoHandle.js +175 -0
  219. package/3D/gizmos/gizmoHandle.js.map +1 -0
  220. package/3D/gizmos/index.d.ts +2 -0
  221. package/3D/gizmos/index.js +3 -0
  222. package/3D/gizmos/index.js.map +1 -0
  223. package/3D/gizmos/slateGizmo.d.ts +57 -0
  224. package/3D/gizmos/slateGizmo.js +353 -0
  225. package/3D/gizmos/slateGizmo.js.map +1 -0
  226. package/3D/gui3DManager.d.ts +94 -0
  227. package/3D/gui3DManager.js +233 -0
  228. package/3D/gui3DManager.js.map +1 -0
  229. package/3D/index.d.ts +5 -0
  230. package/3D/index.js +7 -0
  231. package/3D/index.js.map +1 -0
  232. package/3D/materials/fluent/fluentMaterial.d.ts +91 -0
  233. package/3D/materials/fluent/fluentMaterial.js +286 -0
  234. package/3D/materials/fluent/fluentMaterial.js.map +1 -0
  235. package/3D/materials/fluent/index.d.ts +1 -0
  236. package/3D/materials/fluent/index.js +2 -0
  237. package/3D/materials/fluent/index.js.map +1 -0
  238. package/3D/materials/fluent/shaders/fluent.fragment.d.ts +5 -0
  239. package/3D/materials/fluent/shaders/fluent.fragment.js +41 -0
  240. package/3D/materials/fluent/shaders/fluent.fragment.js.map +1 -0
  241. package/3D/materials/fluent/shaders/fluent.vertex.d.ts +5 -0
  242. package/3D/materials/fluent/shaders/fluent.vertex.js +40 -0
  243. package/3D/materials/fluent/shaders/fluent.vertex.js.map +1 -0
  244. package/3D/materials/fluentBackplate/fluentBackplateMaterial.d.ts +155 -0
  245. package/3D/materials/fluentBackplate/fluentBackplateMaterial.js +466 -0
  246. package/3D/materials/fluentBackplate/fluentBackplateMaterial.js.map +1 -0
  247. package/3D/materials/fluentBackplate/index.d.ts +1 -0
  248. package/3D/materials/fluentBackplate/index.js +2 -0
  249. package/3D/materials/fluentBackplate/index.js.map +1 -0
  250. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.d.ts +5 -0
  251. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.js +60 -0
  252. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.js.map +1 -0
  253. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.d.ts +5 -0
  254. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.js +127 -0
  255. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.js.map +1 -0
  256. package/3D/materials/fluentButton/fluentButtonMaterial.d.ts +190 -0
  257. package/3D/materials/fluentButton/fluentButtonMaterial.js +536 -0
  258. package/3D/materials/fluentButton/fluentButtonMaterial.js.map +1 -0
  259. package/3D/materials/fluentButton/index.d.ts +1 -0
  260. package/3D/materials/fluentButton/index.js +2 -0
  261. package/3D/materials/fluentButton/index.js.map +1 -0
  262. package/3D/materials/fluentButton/shaders/fluentButton.fragment.d.ts +5 -0
  263. package/3D/materials/fluentButton/shaders/fluentButton.fragment.js +57 -0
  264. package/3D/materials/fluentButton/shaders/fluentButton.fragment.js.map +1 -0
  265. package/3D/materials/fluentButton/shaders/fluentButton.vertex.d.ts +5 -0
  266. package/3D/materials/fluentButton/shaders/fluentButton.vertex.js +162 -0
  267. package/3D/materials/fluentButton/shaders/fluentButton.vertex.js.map +1 -0
  268. package/3D/materials/fluentMaterial.d.ts +4 -0
  269. package/3D/materials/fluentMaterial.js +5 -0
  270. package/3D/materials/fluentMaterial.js.map +1 -0
  271. package/3D/materials/handle/handleMaterial.d.ts +68 -0
  272. package/3D/materials/handle/handleMaterial.js +114 -0
  273. package/3D/materials/handle/handleMaterial.js.map +1 -0
  274. package/3D/materials/handle/index.d.ts +1 -0
  275. package/3D/materials/handle/index.js +2 -0
  276. package/3D/materials/handle/index.js.map +1 -0
  277. package/3D/materials/handle/shaders/handle.fragment.d.ts +5 -0
  278. package/3D/materials/handle/shaders/handle.fragment.js +11 -0
  279. package/3D/materials/handle/shaders/handle.fragment.js.map +1 -0
  280. package/3D/materials/handle/shaders/handle.vertex.d.ts +5 -0
  281. package/3D/materials/handle/shaders/handle.vertex.js +11 -0
  282. package/3D/materials/handle/shaders/handle.vertex.js.map +1 -0
  283. package/3D/materials/index.d.ts +5 -0
  284. package/3D/materials/index.js +7 -0
  285. package/3D/materials/index.js.map +1 -0
  286. package/3D/materials/mrdl/index.d.ts +3 -0
  287. package/3D/materials/mrdl/index.js +4 -0
  288. package/3D/materials/mrdl/index.js.map +1 -0
  289. package/3D/materials/mrdl/mrdlBackglowMaterial.d.ts +87 -0
  290. package/3D/materials/mrdl/mrdlBackglowMaterial.js +302 -0
  291. package/3D/materials/mrdl/mrdlBackglowMaterial.js.map +1 -0
  292. package/3D/materials/mrdl/mrdlBackplateMaterial.d.ts +148 -0
  293. package/3D/materials/mrdl/mrdlBackplateMaterial.js +433 -0
  294. package/3D/materials/mrdl/mrdlBackplateMaterial.js.map +1 -0
  295. package/3D/materials/mrdl/mrdlFrontplateMaterial.d.ts +186 -0
  296. package/3D/materials/mrdl/mrdlFrontplateMaterial.js +532 -0
  297. package/3D/materials/mrdl/mrdlFrontplateMaterial.js.map +1 -0
  298. package/3D/materials/mrdl/mrdlInnerquadMaterial.d.ts +56 -0
  299. package/3D/materials/mrdl/mrdlInnerquadMaterial.js +230 -0
  300. package/3D/materials/mrdl/mrdlInnerquadMaterial.js.map +1 -0
  301. package/3D/materials/mrdl/mrdlSliderBarMaterial.d.ts +337 -0
  302. package/3D/materials/mrdl/mrdlSliderBarMaterial.js +855 -0
  303. package/3D/materials/mrdl/mrdlSliderBarMaterial.js.map +1 -0
  304. package/3D/materials/mrdl/mrdlSliderThumbMaterial.d.ts +337 -0
  305. package/3D/materials/mrdl/mrdlSliderThumbMaterial.js +855 -0
  306. package/3D/materials/mrdl/mrdlSliderThumbMaterial.js.map +1 -0
  307. package/3D/materials/mrdl/shaders/mrdlBackglow.fragment.d.ts +5 -0
  308. package/3D/materials/mrdl/shaders/mrdlBackglow.fragment.js +25 -0
  309. package/3D/materials/mrdl/shaders/mrdlBackglow.fragment.js.map +1 -0
  310. package/3D/materials/mrdl/shaders/mrdlBackglow.vertex.d.ts +5 -0
  311. package/3D/materials/mrdl/shaders/mrdlBackglow.vertex.js +12 -0
  312. package/3D/materials/mrdl/shaders/mrdlBackglow.vertex.js.map +1 -0
  313. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.d.ts +5 -0
  314. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.js +88 -0
  315. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.js.map +1 -0
  316. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.d.ts +5 -0
  317. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.js +96 -0
  318. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.js.map +1 -0
  319. package/3D/materials/mrdl/shaders/mrdlFrontplate.fragment.d.ts +5 -0
  320. package/3D/materials/mrdl/shaders/mrdlFrontplate.fragment.js +48 -0
  321. package/3D/materials/mrdl/shaders/mrdlFrontplate.fragment.js.map +1 -0
  322. package/3D/materials/mrdl/shaders/mrdlFrontplate.vertex.d.ts +5 -0
  323. package/3D/materials/mrdl/shaders/mrdlFrontplate.vertex.js +158 -0
  324. package/3D/materials/mrdl/shaders/mrdlFrontplate.vertex.js.map +1 -0
  325. package/3D/materials/mrdl/shaders/mrdlInnerquad.fragment.d.ts +5 -0
  326. package/3D/materials/mrdl/shaders/mrdlInnerquad.fragment.js +27 -0
  327. package/3D/materials/mrdl/shaders/mrdlInnerquad.fragment.js.map +1 -0
  328. package/3D/materials/mrdl/shaders/mrdlInnerquad.vertex.d.ts +5 -0
  329. package/3D/materials/mrdl/shaders/mrdlInnerquad.vertex.js +13 -0
  330. package/3D/materials/mrdl/shaders/mrdlInnerquad.vertex.js.map +1 -0
  331. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.d.ts +5 -0
  332. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.js +236 -0
  333. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.js.map +1 -0
  334. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.d.ts +5 -0
  335. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.js +137 -0
  336. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.js.map +1 -0
  337. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.d.ts +5 -0
  338. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.js +236 -0
  339. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.js.map +1 -0
  340. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.d.ts +5 -0
  341. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.js +137 -0
  342. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.js.map +1 -0
  343. package/3D/vector3WithInfo.d.ts +16 -0
  344. package/3D/vector3WithInfo.js +18 -0
  345. package/3D/vector3WithInfo.js.map +1 -0
  346. package/index.d.ts +2 -0
  347. package/index.js +4 -0
  348. package/index.js.map +1 -0
  349. package/legacy/legacy.d.ts +1 -0
  350. package/legacy/legacy.js +17 -0
  351. package/legacy/legacy.js.map +1 -0
  352. package/license.md +71 -0
  353. package/package.json +47 -0
  354. package/readme.md +31 -0
@@ -0,0 +1,915 @@
1
+ import { __decorate } from "@babylonjs/core/tslib.es6.js";
2
+ import { Observable } from "@babylonjs/core/Misc/observable.js";
3
+ import { Tools } from "@babylonjs/core/Misc/tools.js";
4
+ import { Control } from "./control.js";
5
+ import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
6
+ import { serialize } from "@babylonjs/core/Misc/decorators.js";
7
+ import { EngineStore } from "@babylonjs/core/Engines/engineStore.js";
8
+ /**
9
+ * Class used to create 2D images
10
+ */
11
+ export class Image extends Control {
12
+ /**
13
+ * Gets a boolean indicating that the content is loaded
14
+ */
15
+ get isLoaded() {
16
+ return this._loaded;
17
+ }
18
+ isReady() {
19
+ return this.isLoaded;
20
+ }
21
+ /**
22
+ * Gets or sets a boolean indicating if pointers should only be validated on pixels with alpha > 0.
23
+ * Beware using this as this will consume more memory as the image has to be stored twice
24
+ */
25
+ get detectPointerOnOpaqueOnly() {
26
+ return this._detectPointerOnOpaqueOnly;
27
+ }
28
+ set detectPointerOnOpaqueOnly(value) {
29
+ if (this._detectPointerOnOpaqueOnly === value) {
30
+ return;
31
+ }
32
+ this._detectPointerOnOpaqueOnly = value;
33
+ }
34
+ /**
35
+ * Gets or sets the left value for slicing (9-patch)
36
+ */
37
+ get sliceLeft() {
38
+ return this._sliceLeft;
39
+ }
40
+ set sliceLeft(value) {
41
+ if (this._sliceLeft === value) {
42
+ return;
43
+ }
44
+ this._sliceLeft = value;
45
+ this._markAsDirty();
46
+ }
47
+ /**
48
+ * Gets or sets the right value for slicing (9-patch)
49
+ */
50
+ get sliceRight() {
51
+ return this._sliceRight;
52
+ }
53
+ set sliceRight(value) {
54
+ if (this._sliceRight === value) {
55
+ return;
56
+ }
57
+ this._sliceRight = value;
58
+ this._markAsDirty();
59
+ }
60
+ /**
61
+ * Gets or sets the top value for slicing (9-patch)
62
+ */
63
+ get sliceTop() {
64
+ return this._sliceTop;
65
+ }
66
+ set sliceTop(value) {
67
+ if (this._sliceTop === value) {
68
+ return;
69
+ }
70
+ this._sliceTop = value;
71
+ this._markAsDirty();
72
+ }
73
+ /**
74
+ * Gets or sets the bottom value for slicing (9-patch)
75
+ */
76
+ get sliceBottom() {
77
+ return this._sliceBottom;
78
+ }
79
+ set sliceBottom(value) {
80
+ if (this._sliceBottom === value) {
81
+ return;
82
+ }
83
+ this._sliceBottom = value;
84
+ this._markAsDirty();
85
+ }
86
+ /**
87
+ * Gets or sets the left coordinate in the source image
88
+ */
89
+ get sourceLeft() {
90
+ return this._sourceLeft;
91
+ }
92
+ set sourceLeft(value) {
93
+ if (this._sourceLeft === value) {
94
+ return;
95
+ }
96
+ this._sourceLeft = value;
97
+ this._markAsDirty();
98
+ }
99
+ /**
100
+ * Gets or sets the top coordinate in the source image
101
+ */
102
+ get sourceTop() {
103
+ return this._sourceTop;
104
+ }
105
+ set sourceTop(value) {
106
+ if (this._sourceTop === value) {
107
+ return;
108
+ }
109
+ this._sourceTop = value;
110
+ this._markAsDirty();
111
+ }
112
+ /**
113
+ * Gets or sets the width to capture in the source image
114
+ */
115
+ get sourceWidth() {
116
+ return this._sourceWidth;
117
+ }
118
+ set sourceWidth(value) {
119
+ if (this._sourceWidth === value) {
120
+ return;
121
+ }
122
+ this._sourceWidth = value;
123
+ this._markAsDirty();
124
+ }
125
+ /**
126
+ * Gets or sets the height to capture in the source image
127
+ */
128
+ get sourceHeight() {
129
+ return this._sourceHeight;
130
+ }
131
+ set sourceHeight(value) {
132
+ if (this._sourceHeight === value) {
133
+ return;
134
+ }
135
+ this._sourceHeight = value;
136
+ this._markAsDirty();
137
+ }
138
+ /**
139
+ * Gets the image width
140
+ */
141
+ get imageWidth() {
142
+ return this._imageWidth;
143
+ }
144
+ /**
145
+ * Gets the image height
146
+ */
147
+ get imageHeight() {
148
+ return this._imageHeight;
149
+ }
150
+ /**
151
+ * Gets or sets a boolean indicating if nine patch slices (left, top, right, bottom) should be read from image data
152
+ */
153
+ get populateNinePatchSlicesFromImage() {
154
+ return this._populateNinePatchSlicesFromImage;
155
+ }
156
+ set populateNinePatchSlicesFromImage(value) {
157
+ if (this._populateNinePatchSlicesFromImage === value) {
158
+ return;
159
+ }
160
+ this._populateNinePatchSlicesFromImage = value;
161
+ if (this._populateNinePatchSlicesFromImage && this._loaded) {
162
+ this._extractNinePatchSliceDataFromImage();
163
+ }
164
+ }
165
+ /** Indicates if the format of the image is SVG */
166
+ get isSVG() {
167
+ return this._isSVG;
168
+ }
169
+ /** Gets the status of the SVG attributes computation (sourceLeft, sourceTop, sourceWidth, sourceHeight) */
170
+ get svgAttributesComputationCompleted() {
171
+ return this._svgAttributesComputationCompleted;
172
+ }
173
+ /**
174
+ * Gets or sets a boolean indicating if the image can force its container to adapt its size
175
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/gui/gui#image
176
+ */
177
+ get autoScale() {
178
+ return this._autoScale;
179
+ }
180
+ set autoScale(value) {
181
+ if (this._autoScale === value) {
182
+ return;
183
+ }
184
+ this._autoScale = value;
185
+ if (value && this._loaded) {
186
+ this.synchronizeSizeWithContent();
187
+ }
188
+ }
189
+ /** Gets or sets the stretching mode used by the image */
190
+ get stretch() {
191
+ return this._stretch;
192
+ }
193
+ set stretch(value) {
194
+ if (this._stretch === value) {
195
+ return;
196
+ }
197
+ this._stretch = value;
198
+ this._markAsDirty();
199
+ }
200
+ /**
201
+ * @internal
202
+ */
203
+ _rotate90(n, preserveProperties = false) {
204
+ const width = this._domImage.width;
205
+ const height = this._domImage.height;
206
+ // Should abstract platform instead of using LastCreatedEngine
207
+ const engine = this._host?.getScene()?.getEngine() || EngineStore.LastCreatedEngine;
208
+ if (!engine) {
209
+ throw new Error("Invalid engine. Unable to create a canvas.");
210
+ }
211
+ const canvas = engine.createCanvas(height, width);
212
+ const context = canvas.getContext("2d");
213
+ context.translate(canvas.width / 2, canvas.height / 2);
214
+ context.rotate((n * Math.PI) / 2);
215
+ context.drawImage(this._domImage, 0, 0, width, height, -width / 2, -height / 2, width, height);
216
+ const dataUrl = canvas.toDataURL("image/jpg");
217
+ const rotatedImage = new Image(this.name + "rotated", dataUrl);
218
+ if (preserveProperties) {
219
+ rotatedImage._stretch = this._stretch;
220
+ rotatedImage._autoScale = this._autoScale;
221
+ rotatedImage._cellId = this._cellId;
222
+ rotatedImage._cellWidth = n % 1 ? this._cellHeight : this._cellWidth;
223
+ rotatedImage._cellHeight = n % 1 ? this._cellWidth : this._cellHeight;
224
+ }
225
+ this._handleRotationForSVGImage(this, rotatedImage, n);
226
+ this._imageDataCache.data = null;
227
+ return rotatedImage;
228
+ }
229
+ _handleRotationForSVGImage(srcImage, dstImage, n) {
230
+ if (!srcImage._isSVG) {
231
+ return;
232
+ }
233
+ if (srcImage._svgAttributesComputationCompleted) {
234
+ this._rotate90SourceProperties(srcImage, dstImage, n);
235
+ this._markAsDirty();
236
+ }
237
+ else {
238
+ srcImage.onSVGAttributesComputedObservable.addOnce(() => {
239
+ this._rotate90SourceProperties(srcImage, dstImage, n);
240
+ this._markAsDirty();
241
+ });
242
+ }
243
+ }
244
+ _rotate90SourceProperties(srcImage, dstImage, n) {
245
+ let srcLeft = srcImage.sourceLeft, srcTop = srcImage.sourceTop, srcWidth = srcImage.domImage.width, srcHeight = srcImage.domImage.height;
246
+ let dstLeft = srcLeft, dstTop = srcTop, dstWidth = srcImage.sourceWidth, dstHeight = srcImage.sourceHeight;
247
+ if (n != 0) {
248
+ const mult = n < 0 ? -1 : 1;
249
+ n = n % 4;
250
+ for (let i = 0; i < Math.abs(n); ++i) {
251
+ dstLeft = -(srcTop - srcHeight / 2) * mult + srcHeight / 2;
252
+ dstTop = (srcLeft - srcWidth / 2) * mult + srcWidth / 2;
253
+ [dstWidth, dstHeight] = [dstHeight, dstWidth];
254
+ if (n < 0) {
255
+ dstTop -= dstHeight;
256
+ }
257
+ else {
258
+ dstLeft -= dstWidth;
259
+ }
260
+ srcLeft = dstLeft;
261
+ srcTop = dstTop;
262
+ [srcWidth, srcHeight] = [srcHeight, srcWidth];
263
+ }
264
+ }
265
+ dstImage.sourceLeft = dstLeft;
266
+ dstImage.sourceTop = dstTop;
267
+ dstImage.sourceWidth = dstWidth;
268
+ dstImage.sourceHeight = dstHeight;
269
+ }
270
+ _extractNinePatchSliceDataFromImage() {
271
+ const width = this._domImage.width;
272
+ const height = this._domImage.height;
273
+ if (!this._workingCanvas) {
274
+ const engine = this._host?.getScene()?.getEngine() || EngineStore.LastCreatedEngine;
275
+ if (!engine) {
276
+ throw new Error("Invalid engine. Unable to create a canvas.");
277
+ }
278
+ this._workingCanvas = engine.createCanvas(width, height);
279
+ }
280
+ const canvas = this._workingCanvas;
281
+ const context = canvas.getContext("2d");
282
+ context.drawImage(this._domImage, 0, 0, width, height);
283
+ const imageData = context.getImageData(0, 0, width, height);
284
+ // Left and right
285
+ this._sliceLeft = -1;
286
+ this._sliceRight = -1;
287
+ for (let x = 0; x < width; x++) {
288
+ const alpha = imageData.data[x * 4 + 3];
289
+ if (alpha > 127 && this._sliceLeft === -1) {
290
+ this._sliceLeft = x;
291
+ continue;
292
+ }
293
+ if (alpha < 127 && this._sliceLeft > -1) {
294
+ this._sliceRight = x;
295
+ break;
296
+ }
297
+ }
298
+ // top and bottom
299
+ this._sliceTop = -1;
300
+ this._sliceBottom = -1;
301
+ for (let y = 0; y < height; y++) {
302
+ const alpha = imageData.data[y * width * 4 + 3];
303
+ if (alpha > 127 && this._sliceTop === -1) {
304
+ this._sliceTop = y;
305
+ continue;
306
+ }
307
+ if (alpha < 127 && this._sliceTop > -1) {
308
+ this._sliceBottom = y;
309
+ break;
310
+ }
311
+ }
312
+ }
313
+ /**
314
+ * Gets or sets the internal DOM image used to render the control
315
+ */
316
+ set domImage(value) {
317
+ this._domImage = value;
318
+ this._loaded = false;
319
+ this._imageDataCache.data = null;
320
+ if (this._domImage.width) {
321
+ this._onImageLoaded();
322
+ }
323
+ else {
324
+ this._domImage.onload = () => {
325
+ this._onImageLoaded();
326
+ };
327
+ }
328
+ }
329
+ get domImage() {
330
+ return this._domImage;
331
+ }
332
+ _onImageLoaded() {
333
+ this._imageDataCache.data = null;
334
+ this._imageWidth = this._domImage.width;
335
+ this._imageHeight = this._domImage.height;
336
+ this._loaded = true;
337
+ if (this._populateNinePatchSlicesFromImage) {
338
+ this._extractNinePatchSliceDataFromImage();
339
+ }
340
+ if (this._autoScale) {
341
+ this.synchronizeSizeWithContent();
342
+ }
343
+ this.onImageLoadedObservable.notifyObservers(this);
344
+ this._markAsDirty();
345
+ }
346
+ /**
347
+ * Gets the image source url
348
+ */
349
+ get source() {
350
+ return this._source;
351
+ }
352
+ /**
353
+ * Resets the internal Image Element cache. Can reduce memory usage.
354
+ */
355
+ static ResetImageCache() {
356
+ Image.SourceImgCache.clear();
357
+ }
358
+ _removeCacheUsage(source) {
359
+ const value = source && Image.SourceImgCache.get(source);
360
+ if (value) {
361
+ value.timesUsed -= 1;
362
+ // Remove from DOM
363
+ const htmlElement = value.img;
364
+ if (htmlElement.parentNode) {
365
+ htmlElement.parentNode.removeChild(htmlElement);
366
+ }
367
+ // Since the image isn't being used anymore, we can clean it from the cache
368
+ if (value.timesUsed === 0) {
369
+ Image.SourceImgCache.delete(source);
370
+ }
371
+ }
372
+ }
373
+ /**
374
+ * Gets or sets image source url
375
+ */
376
+ set source(value) {
377
+ if (this._urlRewriter && value) {
378
+ value = this._urlRewriter(value);
379
+ }
380
+ if (this._source === value) {
381
+ return;
382
+ }
383
+ this._removeCacheUsage(this._source);
384
+ this._loaded = false;
385
+ this._source = value;
386
+ this._imageDataCache.data = null;
387
+ if (value) {
388
+ value = this._svgCheck(value);
389
+ }
390
+ // Should abstract platform instead of using LastCreatedEngine
391
+ const engine = this._host?.getScene()?.getEngine() || EngineStore.LastCreatedEngine;
392
+ // If no engine, skip all other DOM operations.
393
+ if (!engine) {
394
+ return;
395
+ }
396
+ if (value && Image.SourceImgCache.has(value)) {
397
+ const cachedData = Image.SourceImgCache.get(value);
398
+ this._domImage = cachedData.img;
399
+ cachedData.timesUsed += 1;
400
+ if (cachedData.loaded) {
401
+ this._onImageLoaded();
402
+ }
403
+ else {
404
+ cachedData.waitingForLoadCallback.push(this._onImageLoaded.bind(this));
405
+ }
406
+ return;
407
+ }
408
+ this._domImage = engine.createCanvasImage();
409
+ // need to add to enforce rendering
410
+ const imgElement = this._domImage;
411
+ let addedToDom = false;
412
+ if (imgElement.style && this._source?.endsWith(".svg")) {
413
+ imgElement.style.visibility = "hidden";
414
+ imgElement.style.position = "absolute";
415
+ imgElement.style.top = "0";
416
+ engine.getRenderingCanvas()?.parentNode?.appendChild(imgElement);
417
+ addedToDom = true;
418
+ }
419
+ if (value) {
420
+ Image.SourceImgCache.set(value, { img: this._domImage, timesUsed: 1, loaded: false, waitingForLoadCallback: [this._onImageLoaded.bind(this)] });
421
+ }
422
+ this._domImage.onload = () => {
423
+ if (value) {
424
+ const cachedData = Image.SourceImgCache.get(value);
425
+ if (cachedData) {
426
+ cachedData.loaded = true;
427
+ for (const waitingCallback of cachedData.waitingForLoadCallback) {
428
+ waitingCallback();
429
+ }
430
+ cachedData.waitingForLoadCallback.length = 0;
431
+ addedToDom && imgElement.remove();
432
+ return;
433
+ }
434
+ }
435
+ this._onImageLoaded();
436
+ addedToDom && imgElement.remove();
437
+ };
438
+ if (value) {
439
+ Tools.SetCorsBehavior(value, this._domImage);
440
+ Tools.SetReferrerPolicyBehavior(this.referrerPolicy, this._domImage);
441
+ this._domImage.src = value;
442
+ }
443
+ }
444
+ _sanitizeSVG(svgString) {
445
+ if (svgString.indexOf("<svg") === -1) {
446
+ return svgString; // Not an SVG, return as is
447
+ }
448
+ const parser = new DOMParser();
449
+ const doc = parser.parseFromString(svgString, "image/svg+xml");
450
+ const dangerousTags = ["script", "iframe", "foreignObject", "object", "embed", "link", "style"];
451
+ const dangerousAttrs = [/^on/i, /^xlink:href$/, /^href$/];
452
+ // Remove dangerous elements
453
+ dangerousTags.forEach((tag) => {
454
+ const elements = doc.getElementsByTagName(tag);
455
+ for (let i = elements.length - 1; i >= 0; i--) {
456
+ elements[i].remove();
457
+ }
458
+ });
459
+ // Recursively sanitize attributes
460
+ function sanitizeElement(el) {
461
+ if (el.attributes) {
462
+ for (let i = el.attributes.length - 1; i >= 0; i--) {
463
+ const attr = el.attributes[i];
464
+ const name = attr.name;
465
+ const value = attr.value;
466
+ // Remove dangerous attributes
467
+ if (dangerousAttrs.some((regex) => regex.test(name))) {
468
+ el.removeAttribute(name);
469
+ }
470
+ // Remove javascript: links
471
+ if (typeof value === "string" && value.trim().toLowerCase().startsWith("javascript:")) {
472
+ el.removeAttribute(name);
473
+ }
474
+ }
475
+ }
476
+ // Recursively sanitize children
477
+ for (let i = 0; i < el.children.length; i++) {
478
+ sanitizeElement(el.children[i]);
479
+ }
480
+ }
481
+ sanitizeElement(doc.documentElement);
482
+ return new XMLSerializer().serializeToString(doc);
483
+ }
484
+ /**
485
+ * Checks for svg document with icon id present
486
+ * @param value the source svg
487
+ * @returns the svg
488
+ */
489
+ _svgCheck(value) {
490
+ // Skip SVG processing if no window/document or SVG support
491
+ if (typeof window === "undefined" || typeof document === "undefined" || !window.SVGSVGElement) {
492
+ return value;
493
+ }
494
+ if (window.SVGSVGElement && value.search(/(\.svg|\.svg?[?|#].*)$/gi) !== -1 && value.indexOf("#") === value.lastIndexOf("#")) {
495
+ this._isSVG = true;
496
+ value = this._sanitizeSVG(value);
497
+ const svgsrc = value.split("#")[0];
498
+ const elemid = value.split("#")[1];
499
+ // check if object alr exist in document
500
+ const svgExist = document.body.querySelector('object[data="' + svgsrc + '"]');
501
+ if (svgExist) {
502
+ const svgDoc = svgExist.contentDocument;
503
+ // get viewbox width and height, get svg document width and height in px
504
+ if (svgDoc && svgDoc.documentElement) {
505
+ const vb = svgDoc.documentElement.getAttribute("viewBox");
506
+ const docwidth = Number(svgDoc.documentElement.getAttribute("width"));
507
+ const docheight = Number(svgDoc.documentElement.getAttribute("height"));
508
+ const elem = svgDoc.getElementById(elemid);
509
+ if (elem && vb && docwidth && docheight) {
510
+ this._getSVGAttribs(svgExist, elemid);
511
+ return value;
512
+ }
513
+ }
514
+ // wait for object to load
515
+ svgExist.addEventListener("load", () => {
516
+ this._getSVGAttribs(svgExist, elemid);
517
+ });
518
+ }
519
+ else {
520
+ // create document object
521
+ const svgImage = document.createElement("object");
522
+ svgImage.data = svgsrc;
523
+ svgImage.type = "image/svg+xml";
524
+ svgImage.width = "0%";
525
+ svgImage.height = "0%";
526
+ document.body.appendChild(svgImage);
527
+ // when the object has loaded, get the element attribs
528
+ svgImage.onload = () => {
529
+ const svgobj = document.body.querySelector('object[data="' + svgsrc + '"]');
530
+ if (svgobj) {
531
+ this._getSVGAttribs(svgobj, elemid);
532
+ }
533
+ };
534
+ }
535
+ return svgsrc;
536
+ }
537
+ else {
538
+ return value;
539
+ }
540
+ }
541
+ /**
542
+ * Sets sourceLeft, sourceTop, sourceWidth, sourceHeight automatically
543
+ * given external svg file and icon id
544
+ * @param svgsrc
545
+ * @param elemid
546
+ */
547
+ _getSVGAttribs(svgsrc, elemid) {
548
+ const svgDoc = svgsrc.contentDocument;
549
+ // get viewbox width and height, get svg document width and height in px
550
+ if (svgDoc && svgDoc.documentElement) {
551
+ const vb = svgDoc.documentElement.getAttribute("viewBox");
552
+ const docwidth = Number(svgDoc.documentElement.getAttribute("width"));
553
+ const docheight = Number(svgDoc.documentElement.getAttribute("height"));
554
+ // get element bbox and matrix transform
555
+ const elem = svgDoc.getElementById(elemid);
556
+ if (vb && docwidth && docheight && elem) {
557
+ const vbWidth = Number(vb.split(" ")[2]);
558
+ const vbHeight = Number(vb.split(" ")[3]);
559
+ const elemBbox = elem.getBBox();
560
+ let elemMatrixA = 1;
561
+ let elemMatrixD = 1;
562
+ let elemMatrixE = 0;
563
+ let elemMatrixF = 0;
564
+ const mainMatrix = elem.transform.baseVal.consolidate().matrix;
565
+ if (elem.transform && elem.transform.baseVal.consolidate()) {
566
+ elemMatrixA = mainMatrix.a;
567
+ elemMatrixD = mainMatrix.d;
568
+ elemMatrixE = mainMatrix.e;
569
+ elemMatrixF = mainMatrix.f;
570
+ }
571
+ // compute source coordinates and dimensions
572
+ this.sourceLeft = ((elemMatrixA * elemBbox.x + elemMatrixE) * docwidth) / vbWidth;
573
+ this.sourceTop = ((elemMatrixD * elemBbox.y + elemMatrixF) * docheight) / vbHeight;
574
+ this.sourceWidth = elemBbox.width * elemMatrixA * (docwidth / vbWidth);
575
+ this.sourceHeight = elemBbox.height * elemMatrixD * (docheight / vbHeight);
576
+ this._svgAttributesComputationCompleted = true;
577
+ this.onSVGAttributesComputedObservable.notifyObservers(this);
578
+ }
579
+ }
580
+ }
581
+ /**
582
+ * Gets or sets the cell width to use when animation sheet is enabled
583
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/gui/gui#image
584
+ */
585
+ get cellWidth() {
586
+ return this._cellWidth;
587
+ }
588
+ set cellWidth(value) {
589
+ if (this._cellWidth === value) {
590
+ return;
591
+ }
592
+ this._cellWidth = value;
593
+ this._markAsDirty();
594
+ }
595
+ /**
596
+ * Gets or sets the cell height to use when animation sheet is enabled
597
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/gui/gui#image
598
+ */
599
+ get cellHeight() {
600
+ return this._cellHeight;
601
+ }
602
+ set cellHeight(value) {
603
+ if (this._cellHeight === value) {
604
+ return;
605
+ }
606
+ this._cellHeight = value;
607
+ this._markAsDirty();
608
+ }
609
+ /**
610
+ * Gets or sets the cell id to use (this will turn on the animation sheet mode)
611
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/gui/gui#image
612
+ */
613
+ get cellId() {
614
+ return this._cellId;
615
+ }
616
+ set cellId(value) {
617
+ if (this._cellId === value) {
618
+ return;
619
+ }
620
+ this._cellId = value;
621
+ this._markAsDirty();
622
+ }
623
+ /**
624
+ * Creates a new Image
625
+ * @param name defines the control name
626
+ * @param url defines the image url
627
+ */
628
+ constructor(name, url = null) {
629
+ super(name);
630
+ this.name = name;
631
+ this._workingCanvas = null;
632
+ this._loaded = false;
633
+ this._stretch = Image.STRETCH_FILL;
634
+ this._source = null;
635
+ this._autoScale = false;
636
+ this._sourceLeft = 0;
637
+ this._sourceTop = 0;
638
+ this._sourceWidth = 0;
639
+ this._sourceHeight = 0;
640
+ this._svgAttributesComputationCompleted = false;
641
+ this._isSVG = false;
642
+ this._cellWidth = 0;
643
+ this._cellHeight = 0;
644
+ this._cellId = -1;
645
+ this._populateNinePatchSlicesFromImage = false;
646
+ this._imageDataCache = { data: null, key: "" };
647
+ /**
648
+ * Observable notified when the content is loaded
649
+ */
650
+ this.onImageLoadedObservable = new Observable();
651
+ /**
652
+ * Observable notified when _sourceLeft, _sourceTop, _sourceWidth and _sourceHeight are computed
653
+ */
654
+ this.onSVGAttributesComputedObservable = new Observable();
655
+ this.source = url;
656
+ }
657
+ /**
658
+ * Tests if a given coordinates belong to the current control
659
+ * @param x defines x coordinate to test
660
+ * @param y defines y coordinate to test
661
+ * @returns true if the coordinates are inside the control
662
+ */
663
+ contains(x, y) {
664
+ if (!super.contains(x, y)) {
665
+ return false;
666
+ }
667
+ if (!this._detectPointerOnOpaqueOnly || !this._workingCanvas) {
668
+ return true;
669
+ }
670
+ const width = this._currentMeasure.width | 0;
671
+ const height = this._currentMeasure.height | 0;
672
+ const key = width + "_" + height;
673
+ let imageData = this._imageDataCache.data;
674
+ if (!imageData || this._imageDataCache.key !== key) {
675
+ const canvas = this._workingCanvas;
676
+ const context = canvas.getContext("2d");
677
+ this._imageDataCache.data = imageData = context.getImageData(0, 0, width, height).data;
678
+ this._imageDataCache.key = key;
679
+ }
680
+ x = (x - this._currentMeasure.left) | 0;
681
+ y = (y - this._currentMeasure.top) | 0;
682
+ const pickedPixel = imageData[(x + y * width) * 4 + 3];
683
+ return pickedPixel > 0;
684
+ }
685
+ _getTypeName() {
686
+ return "Image";
687
+ }
688
+ /** Force the control to synchronize with its content */
689
+ synchronizeSizeWithContent() {
690
+ if (!this._loaded) {
691
+ return;
692
+ }
693
+ this.width = this._domImage.width + "px";
694
+ this.height = this._domImage.height + "px";
695
+ }
696
+ _processMeasures(parentMeasure, context) {
697
+ if (this._loaded) {
698
+ switch (this._stretch) {
699
+ case Image.STRETCH_NONE:
700
+ break;
701
+ case Image.STRETCH_FILL:
702
+ break;
703
+ case Image.STRETCH_UNIFORM:
704
+ break;
705
+ case Image.STRETCH_NINE_PATCH:
706
+ break;
707
+ case Image.STRETCH_EXTEND:
708
+ if (this._autoScale) {
709
+ this.synchronizeSizeWithContent();
710
+ }
711
+ if (this.parent && this.parent.parent) {
712
+ // Will update root size if root is not the top root
713
+ this.parent.adaptWidthToChildren = true;
714
+ this.parent.adaptHeightToChildren = true;
715
+ }
716
+ break;
717
+ }
718
+ }
719
+ super._processMeasures(parentMeasure, context);
720
+ }
721
+ _prepareWorkingCanvasForOpaqueDetection() {
722
+ if (!this._detectPointerOnOpaqueOnly) {
723
+ return;
724
+ }
725
+ const width = this._currentMeasure.width;
726
+ const height = this._currentMeasure.height;
727
+ if (!this._workingCanvas) {
728
+ const engine = this._host?.getScene()?.getEngine() || EngineStore.LastCreatedEngine;
729
+ if (!engine) {
730
+ throw new Error("Invalid engine. Unable to create a canvas.");
731
+ }
732
+ this._workingCanvas = engine.createCanvas(width, height);
733
+ }
734
+ const canvas = this._workingCanvas;
735
+ const context = canvas.getContext("2d");
736
+ context.clearRect(0, 0, width, height);
737
+ }
738
+ _drawImage(context, sx, sy, sw, sh, tx, ty, tw, th) {
739
+ context.drawImage(this._domImage, sx, sy, sw, sh, tx, ty, tw, th);
740
+ if (!this._detectPointerOnOpaqueOnly) {
741
+ return;
742
+ }
743
+ const transform = context.getTransform();
744
+ const canvas = this._workingCanvas;
745
+ const workingCanvasContext = canvas.getContext("2d");
746
+ workingCanvasContext.save();
747
+ const ttx = tx - this._currentMeasure.left;
748
+ const tty = ty - this._currentMeasure.top;
749
+ workingCanvasContext.setTransform(transform.a, transform.b, transform.c, transform.d, (ttx + tw) / 2, (tty + th) / 2);
750
+ workingCanvasContext.translate(-(ttx + tw) / 2, -(tty + th) / 2);
751
+ workingCanvasContext.drawImage(this._domImage, sx, sy, sw, sh, ttx, tty, tw, th);
752
+ workingCanvasContext.restore();
753
+ }
754
+ _draw(context) {
755
+ context.save();
756
+ if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
757
+ context.shadowColor = this.shadowColor;
758
+ context.shadowBlur = this.shadowBlur;
759
+ context.shadowOffsetX = this.shadowOffsetX;
760
+ context.shadowOffsetY = this.shadowOffsetY;
761
+ }
762
+ let x, y, width, height;
763
+ if (this.cellId == -1) {
764
+ x = this._sourceLeft;
765
+ y = this._sourceTop;
766
+ width = this._sourceWidth ? this._sourceWidth : this._imageWidth;
767
+ height = this._sourceHeight ? this._sourceHeight : this._imageHeight;
768
+ }
769
+ else {
770
+ const rowCount = this._domImage.naturalWidth / this.cellWidth;
771
+ const column = (this.cellId / rowCount) >> 0;
772
+ const row = this.cellId % rowCount;
773
+ x = this.cellWidth * row;
774
+ y = this.cellHeight * column;
775
+ width = this.cellWidth;
776
+ height = this.cellHeight;
777
+ }
778
+ this._prepareWorkingCanvasForOpaqueDetection();
779
+ this._applyStates(context);
780
+ if (this._loaded) {
781
+ switch (this._stretch) {
782
+ case Image.STRETCH_NONE:
783
+ this._drawImage(context, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
784
+ break;
785
+ case Image.STRETCH_FILL:
786
+ this._drawImage(context, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
787
+ break;
788
+ case Image.STRETCH_UNIFORM: {
789
+ const hRatio = this._currentMeasure.width / width;
790
+ const vRatio = this._currentMeasure.height / height;
791
+ const ratio = Math.min(hRatio, vRatio);
792
+ const centerX = (this._currentMeasure.width - width * ratio) / 2;
793
+ const centerY = (this._currentMeasure.height - height * ratio) / 2;
794
+ this._drawImage(context, x, y, width, height, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, width * ratio, height * ratio);
795
+ break;
796
+ }
797
+ case Image.STRETCH_EXTEND:
798
+ this._drawImage(context, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
799
+ break;
800
+ case Image.STRETCH_NINE_PATCH:
801
+ this._renderNinePatch(context, x, y, width, height);
802
+ break;
803
+ }
804
+ }
805
+ context.restore();
806
+ }
807
+ _renderNinePatch(context, sx, sy, sw, sh) {
808
+ const idealRatio = this.host.idealRatio;
809
+ const leftWidth = this._sliceLeft;
810
+ const topHeight = this._sliceTop;
811
+ const bottomHeight = sh - this._sliceBottom;
812
+ const rightWidth = sw - this._sliceRight;
813
+ const centerWidth = this._sliceRight - this._sliceLeft;
814
+ const centerHeight = this._sliceBottom - this._sliceTop;
815
+ const leftWidthAdjusted = Math.round(leftWidth * idealRatio);
816
+ const topHeightAdjusted = Math.round(topHeight * idealRatio);
817
+ const bottomHeightAdjusted = Math.round(bottomHeight * idealRatio);
818
+ const rightWidthAdjusted = Math.round(rightWidth * idealRatio);
819
+ const targetCenterWidth = Math.round(this._currentMeasure.width) - rightWidthAdjusted - leftWidthAdjusted + 2;
820
+ const targetCenterHeight = Math.round(this._currentMeasure.height) - bottomHeightAdjusted - topHeightAdjusted + 2;
821
+ const centerLeftOffset = Math.round(this._currentMeasure.left) + leftWidthAdjusted - 1;
822
+ const centerTopOffset = Math.round(this._currentMeasure.top) + topHeightAdjusted - 1;
823
+ const rightOffset = Math.round(this._currentMeasure.left + this._currentMeasure.width) - rightWidthAdjusted;
824
+ const bottomOffset = Math.round(this._currentMeasure.top + this._currentMeasure.height) - bottomHeightAdjusted;
825
+ //Top Left
826
+ this._drawImage(context, sx, sy, leftWidth, topHeight, this._currentMeasure.left, this._currentMeasure.top, leftWidthAdjusted, topHeightAdjusted);
827
+ //Top
828
+ this._drawImage(context, sx + this._sliceLeft, sy, centerWidth, topHeight, centerLeftOffset + 1, this._currentMeasure.top, targetCenterWidth - 2, topHeightAdjusted);
829
+ //Top Right
830
+ this._drawImage(context, sx + this._sliceRight, sy, rightWidth, topHeight, rightOffset, this._currentMeasure.top, rightWidthAdjusted, topHeightAdjusted);
831
+ //Left
832
+ this._drawImage(context, sx, sy + this._sliceTop, leftWidth, centerHeight, this._currentMeasure.left, centerTopOffset + 1, leftWidthAdjusted, targetCenterHeight - 2);
833
+ // Center
834
+ this._drawImage(context, sx + this._sliceLeft, sy + this._sliceTop, centerWidth, centerHeight, centerLeftOffset + 1, centerTopOffset + 1, targetCenterWidth - 2, targetCenterHeight - 2);
835
+ //Right
836
+ this._drawImage(context, sx + this._sliceRight, sy + this._sliceTop, rightWidth, centerHeight, rightOffset, centerTopOffset + 1, rightWidthAdjusted, targetCenterHeight - 2);
837
+ //Bottom Left
838
+ this._drawImage(context, sx, sy + this._sliceBottom, leftWidth, bottomHeight, this._currentMeasure.left, bottomOffset, leftWidthAdjusted, bottomHeightAdjusted);
839
+ //Bottom
840
+ this._drawImage(context, sx + this.sliceLeft, sy + this._sliceBottom, centerWidth, bottomHeight, centerLeftOffset + 1, bottomOffset, targetCenterWidth - 2, bottomHeightAdjusted);
841
+ //Bottom Right
842
+ this._drawImage(context, sx + this._sliceRight, sy + this._sliceBottom, rightWidth, bottomHeight, rightOffset, bottomOffset, rightWidthAdjusted, bottomHeightAdjusted);
843
+ }
844
+ dispose() {
845
+ super.dispose();
846
+ this.onImageLoadedObservable.clear();
847
+ this.onSVGAttributesComputedObservable.clear();
848
+ this._removeCacheUsage(this._source);
849
+ }
850
+ }
851
+ /**
852
+ * Cache of images to avoid loading the same image multiple times
853
+ */
854
+ Image.SourceImgCache = new Map();
855
+ // Static
856
+ /** STRETCH_NONE */
857
+ Image.STRETCH_NONE = 0;
858
+ /** STRETCH_FILL */
859
+ Image.STRETCH_FILL = 1;
860
+ /** STRETCH_UNIFORM */
861
+ Image.STRETCH_UNIFORM = 2;
862
+ /** STRETCH_EXTEND */
863
+ Image.STRETCH_EXTEND = 3;
864
+ /** NINE_PATCH */
865
+ Image.STRETCH_NINE_PATCH = 4;
866
+ __decorate([
867
+ serialize()
868
+ ], Image.prototype, "detectPointerOnOpaqueOnly", null);
869
+ __decorate([
870
+ serialize()
871
+ ], Image.prototype, "sliceLeft", null);
872
+ __decorate([
873
+ serialize()
874
+ ], Image.prototype, "sliceRight", null);
875
+ __decorate([
876
+ serialize()
877
+ ], Image.prototype, "sliceTop", null);
878
+ __decorate([
879
+ serialize()
880
+ ], Image.prototype, "sliceBottom", null);
881
+ __decorate([
882
+ serialize()
883
+ ], Image.prototype, "sourceLeft", null);
884
+ __decorate([
885
+ serialize()
886
+ ], Image.prototype, "sourceTop", null);
887
+ __decorate([
888
+ serialize()
889
+ ], Image.prototype, "sourceWidth", null);
890
+ __decorate([
891
+ serialize()
892
+ ], Image.prototype, "sourceHeight", null);
893
+ __decorate([
894
+ serialize()
895
+ ], Image.prototype, "populateNinePatchSlicesFromImage", null);
896
+ __decorate([
897
+ serialize()
898
+ ], Image.prototype, "autoScale", null);
899
+ __decorate([
900
+ serialize()
901
+ ], Image.prototype, "stretch", null);
902
+ __decorate([
903
+ serialize()
904
+ ], Image.prototype, "source", null);
905
+ __decorate([
906
+ serialize()
907
+ ], Image.prototype, "cellWidth", null);
908
+ __decorate([
909
+ serialize()
910
+ ], Image.prototype, "cellHeight", null);
911
+ __decorate([
912
+ serialize()
913
+ ], Image.prototype, "cellId", null);
914
+ RegisterClass("BABYLON.GUI.Image", Image);
915
+ //# sourceMappingURL=image.js.map