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