@babylonjs/gui 5.0.0-rc.7 → 5.0.0-rc.9

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 (203) hide show
  1. package/2D/adtInstrumentation.d.ts +52 -52
  2. package/2D/adtInstrumentation.js +126 -126
  3. package/2D/advancedDynamicTexture.d.ts +448 -448
  4. package/2D/advancedDynamicTexture.js +1318 -1318
  5. package/2D/controls/button.d.ts +135 -135
  6. package/2D/controls/button.js +276 -276
  7. package/2D/controls/checkbox.d.ts +59 -59
  8. package/2D/controls/checkbox.js +188 -188
  9. package/2D/controls/colorpicker.d.ts +103 -103
  10. package/2D/controls/colorpicker.js +1417 -1417
  11. package/2D/controls/container.d.ts +175 -175
  12. package/2D/controls/container.js +570 -570
  13. package/2D/controls/control.d.ts +866 -866
  14. package/2D/controls/control.js +2433 -2433
  15. package/2D/controls/displayGrid.d.ts +53 -53
  16. package/2D/controls/displayGrid.js +245 -245
  17. package/2D/controls/ellipse.d.ts +21 -21
  18. package/2D/controls/ellipse.js +85 -85
  19. package/2D/controls/focusableButton.d.ts +59 -59
  20. package/2D/controls/focusableButton.js +99 -99
  21. package/2D/controls/focusableControl.d.ts +34 -34
  22. package/2D/controls/focusableControl.js +1 -1
  23. package/2D/controls/grid.d.ts +139 -139
  24. package/2D/controls/grid.js +529 -529
  25. package/2D/controls/image.d.ts +204 -204
  26. package/2D/controls/image.js +887 -887
  27. package/2D/controls/index.d.ts +29 -29
  28. package/2D/controls/index.js +29 -29
  29. package/2D/controls/inputPassword.d.ts +8 -8
  30. package/2D/controls/inputPassword.js +25 -25
  31. package/2D/controls/inputText.d.ts +201 -201
  32. package/2D/controls/inputText.js +1119 -1119
  33. package/2D/controls/line.d.ts +66 -66
  34. package/2D/controls/line.js +271 -271
  35. package/2D/controls/multiLine.d.ts +75 -75
  36. package/2D/controls/multiLine.js +262 -262
  37. package/2D/controls/radioButton.d.ts +49 -49
  38. package/2D/controls/radioButton.js +205 -205
  39. package/2D/controls/rectangle.d.ts +29 -29
  40. package/2D/controls/rectangle.js +150 -150
  41. package/2D/controls/scrollViewers/scrollViewer.d.ts +182 -182
  42. package/2D/controls/scrollViewers/scrollViewer.js +677 -677
  43. package/2D/controls/scrollViewers/scrollViewerWindow.d.ts +57 -57
  44. package/2D/controls/scrollViewers/scrollViewerWindow.js +278 -278
  45. package/2D/controls/selector.d.ts +263 -263
  46. package/2D/controls/selector.js +692 -692
  47. package/2D/controls/sliders/baseSlider.d.ts +82 -82
  48. package/2D/controls/sliders/baseSlider.js +347 -347
  49. package/2D/controls/sliders/imageBasedSlider.d.ts +49 -49
  50. package/2D/controls/sliders/imageBasedSlider.js +192 -192
  51. package/2D/controls/sliders/imageScrollBar.d.ts +65 -65
  52. package/2D/controls/sliders/imageScrollBar.js +263 -263
  53. package/2D/controls/sliders/scrollBar.d.ts +38 -38
  54. package/2D/controls/sliders/scrollBar.js +143 -143
  55. package/2D/controls/sliders/slider.d.ts +35 -35
  56. package/2D/controls/sliders/slider.js +271 -271
  57. package/2D/controls/stackPanel.d.ts +64 -64
  58. package/2D/controls/stackPanel.js +246 -246
  59. package/2D/controls/statics.d.ts +6 -6
  60. package/2D/controls/statics.js +49 -49
  61. package/2D/controls/textBlock.d.ts +175 -175
  62. package/2D/controls/textBlock.js +603 -603
  63. package/2D/controls/textWrapper.d.ts +13 -13
  64. package/2D/controls/textWrapper.js +101 -101
  65. package/2D/controls/toggleButton.d.ts +117 -117
  66. package/2D/controls/toggleButton.js +268 -268
  67. package/2D/controls/virtualKeyboard.d.ts +96 -96
  68. package/2D/controls/virtualKeyboard.js +256 -256
  69. package/2D/index.d.ts +9 -9
  70. package/2D/index.js +9 -9
  71. package/2D/math2D.d.ts +117 -117
  72. package/2D/math2D.js +221 -221
  73. package/2D/measure.d.ts +77 -77
  74. package/2D/measure.js +139 -139
  75. package/2D/multiLinePoint.d.ts +47 -47
  76. package/2D/multiLinePoint.js +127 -127
  77. package/2D/style.d.ts +46 -46
  78. package/2D/style.js +97 -97
  79. package/2D/valueAndUnit.d.ts +89 -89
  80. package/2D/valueAndUnit.js +226 -226
  81. package/2D/xmlLoader.d.ts +60 -60
  82. package/2D/xmlLoader.js +348 -348
  83. package/3D/behaviors/defaultBehavior.d.ts +73 -73
  84. package/3D/behaviors/defaultBehavior.js +121 -121
  85. package/3D/controls/abstractButton3D.d.ts +15 -15
  86. package/3D/controls/abstractButton3D.js +25 -25
  87. package/3D/controls/button3D.d.ts +30 -30
  88. package/3D/controls/button3D.js +93 -93
  89. package/3D/controls/container3D.d.ts +72 -72
  90. package/3D/controls/container3D.js +139 -139
  91. package/3D/controls/contentDisplay3D.d.ts +30 -30
  92. package/3D/controls/contentDisplay3D.js +79 -79
  93. package/3D/controls/control3D.d.ts +201 -201
  94. package/3D/controls/control3D.js +445 -445
  95. package/3D/controls/cylinderPanel.d.ts +17 -17
  96. package/3D/controls/cylinderPanel.js +66 -66
  97. package/3D/controls/handMenu.d.ts +28 -28
  98. package/3D/controls/handMenu.js +47 -47
  99. package/3D/controls/holographicBackplate.d.ts +49 -49
  100. package/3D/controls/holographicBackplate.js +120 -120
  101. package/3D/controls/holographicButton.d.ts +84 -84
  102. package/3D/controls/holographicButton.js +339 -339
  103. package/3D/controls/holographicSlate.d.ts +131 -131
  104. package/3D/controls/holographicSlate.js +431 -431
  105. package/3D/controls/index.d.ts +21 -21
  106. package/3D/controls/index.js +21 -21
  107. package/3D/controls/meshButton3D.d.ts +21 -21
  108. package/3D/controls/meshButton3D.js +62 -62
  109. package/3D/controls/nearMenu.d.ts +44 -44
  110. package/3D/controls/nearMenu.js +114 -114
  111. package/3D/controls/planePanel.d.ts +9 -9
  112. package/3D/controls/planePanel.js +36 -36
  113. package/3D/controls/scatterPanel.d.ts +18 -18
  114. package/3D/controls/scatterPanel.js +108 -108
  115. package/3D/controls/slider3D.d.ts +81 -81
  116. package/3D/controls/slider3D.js +268 -268
  117. package/3D/controls/spherePanel.d.ts +17 -17
  118. package/3D/controls/spherePanel.js +67 -67
  119. package/3D/controls/stackPanel3D.d.ts +22 -22
  120. package/3D/controls/stackPanel3D.js +107 -107
  121. package/3D/controls/touchButton3D.d.ts +80 -80
  122. package/3D/controls/touchButton3D.js +233 -233
  123. package/3D/controls/touchHolographicButton.d.ts +110 -110
  124. package/3D/controls/touchHolographicButton.js +445 -445
  125. package/3D/controls/touchHolographicMenu.d.ts +61 -61
  126. package/3D/controls/touchHolographicMenu.js +149 -149
  127. package/3D/controls/touchMeshButton3D.d.ts +21 -21
  128. package/3D/controls/touchMeshButton3D.js +62 -62
  129. package/3D/controls/volumeBasedPanel.d.ts +53 -53
  130. package/3D/controls/volumeBasedPanel.js +174 -174
  131. package/3D/gizmos/gizmoHandle.d.ts +108 -108
  132. package/3D/gizmos/gizmoHandle.js +209 -209
  133. package/3D/gizmos/index.d.ts +2 -2
  134. package/3D/gizmos/index.js +2 -2
  135. package/3D/gizmos/slateGizmo.d.ts +57 -57
  136. package/3D/gizmos/slateGizmo.js +369 -369
  137. package/3D/gui3DManager.d.ts +94 -94
  138. package/3D/gui3DManager.js +257 -257
  139. package/3D/index.d.ts +5 -5
  140. package/3D/index.js +5 -5
  141. package/3D/materials/fluent/fluentMaterial.d.ts +90 -90
  142. package/3D/materials/fluent/fluentMaterial.js +292 -292
  143. package/3D/materials/fluent/index.d.ts +1 -1
  144. package/3D/materials/fluent/index.js +1 -1
  145. package/3D/materials/fluent/shaders/fluent.fragment.d.ts +5 -5
  146. package/3D/materials/fluent/shaders/fluent.fragment.js +8 -8
  147. package/3D/materials/fluent/shaders/fluent.vertex.d.ts +5 -5
  148. package/3D/materials/fluent/shaders/fluent.vertex.js +8 -8
  149. package/3D/materials/fluentBackplate/fluentBackplateMaterial.d.ts +154 -154
  150. package/3D/materials/fluentBackplate/fluentBackplateMaterial.js +469 -469
  151. package/3D/materials/fluentBackplate/index.d.ts +1 -1
  152. package/3D/materials/fluentBackplate/index.js +1 -1
  153. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.d.ts +5 -5
  154. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.js +8 -8
  155. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.d.ts +5 -5
  156. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.js +8 -8
  157. package/3D/materials/fluentButton/fluentButtonMaterial.d.ts +189 -189
  158. package/3D/materials/fluentButton/fluentButtonMaterial.js +539 -539
  159. package/3D/materials/fluentButton/index.d.ts +1 -1
  160. package/3D/materials/fluentButton/index.js +1 -1
  161. package/3D/materials/fluentButton/shaders/fluentButton.fragment.d.ts +5 -5
  162. package/3D/materials/fluentButton/shaders/fluentButton.fragment.js +8 -8
  163. package/3D/materials/fluentButton/shaders/fluentButton.vertex.d.ts +5 -5
  164. package/3D/materials/fluentButton/shaders/fluentButton.vertex.js +8 -8
  165. package/3D/materials/fluentMaterial.d.ts +4 -4
  166. package/3D/materials/fluentMaterial.js +4 -4
  167. package/3D/materials/handle/handleMaterial.d.ts +68 -68
  168. package/3D/materials/handle/handleMaterial.js +126 -126
  169. package/3D/materials/handle/index.d.ts +1 -1
  170. package/3D/materials/handle/index.js +1 -1
  171. package/3D/materials/handle/shaders/handle.fragment.d.ts +5 -5
  172. package/3D/materials/handle/shaders/handle.fragment.js +8 -8
  173. package/3D/materials/handle/shaders/handle.vertex.d.ts +5 -5
  174. package/3D/materials/handle/shaders/handle.vertex.js +8 -8
  175. package/3D/materials/index.d.ts +5 -5
  176. package/3D/materials/index.js +5 -5
  177. package/3D/materials/mrdl/index.d.ts +3 -3
  178. package/3D/materials/mrdl/index.js +3 -3
  179. package/3D/materials/mrdl/mrdlBackplateMaterial.d.ts +147 -147
  180. package/3D/materials/mrdl/mrdlBackplateMaterial.js +436 -436
  181. package/3D/materials/mrdl/mrdlSliderBarMaterial.d.ts +333 -333
  182. package/3D/materials/mrdl/mrdlSliderBarMaterial.js +851 -851
  183. package/3D/materials/mrdl/mrdlSliderThumbMaterial.d.ts +333 -333
  184. package/3D/materials/mrdl/mrdlSliderThumbMaterial.js +851 -851
  185. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.d.ts +5 -5
  186. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.js +8 -8
  187. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.d.ts +5 -5
  188. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.js +8 -8
  189. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.d.ts +5 -5
  190. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.js +8 -8
  191. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.d.ts +5 -5
  192. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.js +8 -8
  193. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.d.ts +5 -5
  194. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.js +8 -8
  195. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.d.ts +5 -5
  196. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.js +8 -8
  197. package/3D/vector3WithInfo.d.ts +16 -16
  198. package/3D/vector3WithInfo.js +23 -23
  199. package/index.d.ts +2 -2
  200. package/index.js +2 -2
  201. package/legacy/legacy.d.ts +1 -1
  202. package/legacy/legacy.js +13 -13
  203. package/package.json +2 -2
package/2D/xmlLoader.js CHANGED
@@ -1,349 +1,349 @@
1
- import { __awaiter, __generator } from "tslib";
2
- import { GetClass } from "@babylonjs/core/Misc/typeStore.js";
3
- var XmlLoaderError = "XmlLoader Exception : XML file is malformed or corrupted.";
4
- /**
5
- * Class used to load GUI via XML.
6
- */
7
- var XmlLoader = /** @class */ (function () {
8
- /**
9
- * Create a new xml loader
10
- * @param parentClass Sets the class context. Used when the loader is instanced inside a class and not in a global context
11
- */
12
- function XmlLoader(parentClass) {
13
- if (parentClass === void 0) { parentClass = null; }
14
- this._nodes = {};
15
- this._nodeTypes = {
16
- element: 1,
17
- attribute: 2,
18
- text: 3,
19
- };
20
- this._isLoaded = false;
21
- this._objectAttributes = {
22
- textHorizontalAlignment: 1,
23
- textVerticalAlignment: 2,
24
- horizontalAlignment: 3,
25
- verticalAlignment: 4,
26
- stretch: 5,
27
- };
28
- if (parentClass) {
29
- this._parentClass = parentClass;
30
- }
31
- }
32
- XmlLoader.prototype._getChainElement = function (attributeValue) {
33
- var element = window;
34
- if (this._parentClass) {
35
- element = this._parentClass;
36
- }
37
- var value = attributeValue;
38
- value = value.split(".");
39
- for (var i = 0; i < value.length; i++) {
40
- element = element[value[i]];
41
- }
42
- return element;
43
- };
44
- XmlLoader.prototype._getClassAttribute = function (attributeName) {
45
- var attribute = attributeName.split(".");
46
- var className = GetClass("BABYLON.GUI." + attribute[0]);
47
- return className[attribute[1]];
48
- };
49
- XmlLoader.prototype._createGuiElement = function (node, parent, linkParent) {
50
- if (linkParent === void 0) { linkParent = true; }
51
- try {
52
- var className = GetClass("BABYLON.GUI." + node.nodeName);
53
- var guiNode = new className();
54
- if (parent && linkParent) {
55
- parent.addControl(guiNode);
56
- }
57
- for (var i = 0; i < node.attributes.length; i++) {
58
- if (node.attributes[i].name.toLowerCase().includes("datasource")) {
59
- continue;
60
- }
61
- if (node.attributes[i].name.toLowerCase().includes("observable")) {
62
- var element = this._getChainElement(node.attributes[i].value);
63
- guiNode[node.attributes[i].name].add(element);
64
- continue;
65
- }
66
- else if (node.attributes[i].name == "linkWithMesh") {
67
- if (this._parentClass) {
68
- guiNode.linkWithMesh(this._parentClass[node.attributes[i].value]);
69
- }
70
- else {
71
- guiNode.linkWithMesh(window[node.attributes[i].value]);
72
- }
73
- }
74
- else if (node.attributes[i].value.startsWith("{{") && node.attributes[i].value.endsWith("}}")) {
75
- var element = this._getChainElement(node.attributes[i].value.substring(2, node.attributes[i].value.length - 2));
76
- guiNode[node.attributes[i].name] = element;
77
- }
78
- else if (!this._objectAttributes[node.attributes[i].name]) {
79
- if (node.attributes[i].value == "true" || node.attributes[i].value == "false") {
80
- guiNode[node.attributes[i].name] = node.attributes[i].value == "true";
81
- }
82
- else {
83
- guiNode[node.attributes[i].name] = !isNaN(Number(node.attributes[i].value)) ? Number(node.attributes[i].value) : node.attributes[i].value;
84
- }
85
- }
86
- else {
87
- guiNode[node.attributes[i].name] = this._getClassAttribute(node.attributes[i].value);
88
- }
89
- }
90
- if (!node.attributes.getNamedItem("id")) {
91
- this._nodes[node.nodeName + Object.keys(this._nodes).length + "_gen"] = guiNode;
92
- return guiNode;
93
- }
94
- var id = node.attributes.getNamedItem("id").value;
95
- if (id.startsWith("{{") && id.endsWith("}}")) {
96
- id = this._getChainElement(id.substring(2, id.length - 2));
97
- }
98
- if (!this._nodes[id]) {
99
- this._nodes[id] = guiNode;
100
- }
101
- else {
102
- throw "XmlLoader Exception : Duplicate ID, every element should have an unique ID attribute";
103
- }
104
- return guiNode;
105
- }
106
- catch (exception) {
107
- throw "XmlLoader Exception : Error parsing Control " + node.nodeName + "," + exception + ".";
108
- }
109
- };
110
- XmlLoader.prototype._parseGrid = function (node, guiNode, parent) {
111
- var width;
112
- var height;
113
- var columns;
114
- var rows = node.children;
115
- var cells;
116
- var isPixel = false;
117
- var cellNode;
118
- var rowNumber = -1;
119
- var columnNumber = -1;
120
- var totalColumnsNumber = 0;
121
- for (var i = 0; i < rows.length; i++) {
122
- if (rows[i].nodeType != this._nodeTypes.element) {
123
- continue;
124
- }
125
- if (rows[i].nodeName != "Row") {
126
- throw "XmlLoader Exception : Expecting Row node, received " + rows[i].nodeName;
127
- }
128
- rowNumber += 1;
129
- columns = rows[i].children;
130
- if (!rows[i].attributes.getNamedItem("height")) {
131
- throw "XmlLoader Exception : Height must be defined for grid rows";
132
- }
133
- height = Number(rows[i].attributes.getNamedItem("height").nodeValue);
134
- isPixel = rows[i].attributes.getNamedItem("isPixel") ? JSON.parse(rows[i].attributes.getNamedItem("isPixel").nodeValue) : false;
135
- guiNode.addRowDefinition(height, isPixel);
136
- for (var j = 0; j < columns.length; j++) {
137
- if (columns[j].nodeType != this._nodeTypes.element) {
138
- continue;
139
- }
140
- if (columns[j].nodeName != "Column") {
141
- throw "XmlLoader Exception : Expecting Column node, received " + columns[j].nodeName;
142
- }
143
- columnNumber += 1;
144
- if (rowNumber > 0 && columnNumber > totalColumnsNumber) {
145
- throw "XmlLoader Exception : In the Grid element, the number of columns is defined in the first row, do not add more columns in the subsequent rows.";
146
- }
147
- if (rowNumber == 0) {
148
- if (!columns[j].attributes.getNamedItem("width")) {
149
- throw "XmlLoader Exception : Width must be defined for all the grid columns in the first row";
150
- }
151
- width = Number(columns[j].attributes.getNamedItem("width").nodeValue);
152
- isPixel = columns[j].attributes.getNamedItem("isPixel") ? JSON.parse(columns[j].attributes.getNamedItem("isPixel").nodeValue) : false;
153
- guiNode.addColumnDefinition(width, isPixel);
154
- }
155
- cells = columns[j].children;
156
- for (var k = 0; k < cells.length; k++) {
157
- if (cells[k].nodeType != this._nodeTypes.element) {
158
- continue;
159
- }
160
- cellNode = this._createGuiElement(cells[k], guiNode, false);
161
- guiNode.addControl(cellNode, rowNumber, columnNumber);
162
- if (cells[k].firstChild) {
163
- this._parseXml(cells[k].firstChild, cellNode);
164
- }
165
- }
166
- }
167
- if (rowNumber == 0) {
168
- totalColumnsNumber = columnNumber;
169
- }
170
- columnNumber = -1;
171
- }
172
- if (node.nextSibling) {
173
- this._parseXml(node.nextSibling, parent);
174
- }
175
- };
176
- XmlLoader.prototype._parseElement = function (node, guiNode, parent) {
177
- if (node.firstChild) {
178
- this._parseXml(node.firstChild, guiNode);
179
- }
180
- if (node.nextSibling) {
181
- this._parseXml(node.nextSibling, parent);
182
- }
183
- };
184
- XmlLoader.prototype._prepareSourceElement = function (node, guiNode, variable, source, iterator) {
185
- if (this._parentClass) {
186
- this._parentClass[variable] = source[iterator];
187
- }
188
- else {
189
- window[variable] = source[iterator];
190
- }
191
- if (node.firstChild) {
192
- this._parseXml(node.firstChild, guiNode, true);
193
- }
194
- };
195
- XmlLoader.prototype._parseElementsFromSource = function (node, guiNode, parent) {
196
- var dataSource = node.attributes.getNamedItem("dataSource").value;
197
- if (!dataSource.includes(" in ")) {
198
- throw "XmlLoader Exception : Malformed XML, Data Source must include an in";
199
- }
200
- else {
201
- var isArray = true;
202
- var splittedSource = dataSource.split(" in ");
203
- if (splittedSource.length < 2) {
204
- throw "XmlLoader Exception : Malformed XML, Data Source must have an iterator and a source";
205
- }
206
- var source = splittedSource[1];
207
- if (source.startsWith("{") && source.endsWith("}")) {
208
- isArray = false;
209
- }
210
- if (!isArray || (source.startsWith("[") && source.endsWith("]"))) {
211
- source = source.substring(1, source.length - 1);
212
- }
213
- if (this._parentClass) {
214
- source = this._parentClass[source];
215
- }
216
- else {
217
- source = window[source];
218
- }
219
- if (isArray) {
220
- for (var i = 0; i < source.length; i++) {
221
- this._prepareSourceElement(node, guiNode, splittedSource[0], source, i);
222
- }
223
- }
224
- else {
225
- for (var i in source) {
226
- this._prepareSourceElement(node, guiNode, splittedSource[0], source, i);
227
- }
228
- }
229
- if (node.nextSibling) {
230
- this._parseXml(node.nextSibling, parent);
231
- }
232
- }
233
- };
234
- XmlLoader.prototype._parseXml = function (node, parent, generated) {
235
- if (generated === void 0) { generated = false; }
236
- if (node.nodeType != this._nodeTypes.element) {
237
- if (node.nextSibling) {
238
- this._parseXml(node.nextSibling, parent, generated);
239
- }
240
- return;
241
- }
242
- if (generated) {
243
- node.setAttribute("id", parent.id + (parent._children.length + 1));
244
- }
245
- var guiNode = this._createGuiElement(node, parent);
246
- if (!this._rootNode) {
247
- this._rootNode = guiNode;
248
- }
249
- if (node.nodeName == "Grid") {
250
- this._parseGrid(node, guiNode, parent);
251
- }
252
- else if (!node.attributes.getNamedItem("dataSource")) {
253
- this._parseElement(node, guiNode, parent);
254
- }
255
- else {
256
- this._parseElementsFromSource(node, guiNode, parent);
257
- }
258
- };
259
- /**
260
- * Gets if the loading has finished.
261
- * @returns whether the loading has finished or not
262
- */
263
- XmlLoader.prototype.isLoaded = function () {
264
- return this._isLoaded;
265
- };
266
- /**
267
- * Gets a loaded node / control by id.
268
- * @param id the Controls id set in the xml
269
- * @returns element of type Control
270
- */
271
- XmlLoader.prototype.getNodeById = function (id) {
272
- return this._nodes[id];
273
- };
274
- /**
275
- * Gets all loaded nodes / controls
276
- * @returns Array of controls
277
- */
278
- XmlLoader.prototype.getNodes = function () {
279
- return this._nodes;
280
- };
281
- /**
282
- * Disposes the loaded layout
283
- */
284
- XmlLoader.prototype.dispose = function () {
285
- if (this._rootNode) {
286
- this._rootNode.dispose();
287
- this._rootNode = null;
288
- this._nodes = {};
289
- }
290
- };
291
- /**
292
- * Initiates the xml layout loading
293
- * @param xmlFile defines the xml layout to load
294
- * @param rootNode defines the node / control to use as a parent for the loaded layout controls.
295
- * @param onSuccess defines the callback called on layout load successfully.
296
- * @param onError defines the callback called on layout load failure.
297
- */
298
- XmlLoader.prototype.loadLayout = function (xmlFile, rootNode, onSuccess, onError) {
299
- var _this = this;
300
- if (onSuccess === void 0) { onSuccess = null; }
301
- if (onError === void 0) { onError = null; }
302
- var xhttp = new XMLHttpRequest();
303
- xhttp.onload = function () {
304
- if (xhttp.readyState === 4 && xhttp.status === 200) {
305
- if (!xhttp.responseXML) {
306
- if (onError) {
307
- onError(XmlLoaderError);
308
- return;
309
- }
310
- else {
311
- throw XmlLoaderError;
312
- }
313
- }
314
- var xmlDoc = xhttp.responseXML.documentElement;
315
- _this._parseXml(xmlDoc.firstChild, rootNode);
316
- _this._isLoaded = true;
317
- if (onSuccess) {
318
- onSuccess();
319
- }
320
- }
321
- };
322
- xhttp.onerror = function () {
323
- if (onError) {
324
- onError("an error occurred during loading the layout");
325
- }
326
- };
327
- xhttp.open("GET", xmlFile, true);
328
- xhttp.send();
329
- };
330
- /**
331
- * Initiates the xml layout loading asynchronously
332
- * @param xmlFile defines the xml layout to load
333
- * @param rootNode defines the node / control to use as a parent for the loaded layout controls.
334
- * @returns Promise
335
- */
336
- XmlLoader.prototype.loadLayoutAsync = function (xmlFile, rootNode) {
337
- return __awaiter(this, void 0, void 0, function () {
338
- var _this = this;
339
- return __generator(this, function (_a) {
340
- return [2 /*return*/, new Promise(function (resolve, reject) {
341
- _this.loadLayout(xmlFile, rootNode, resolve, reject);
342
- })];
343
- });
344
- });
345
- };
346
- return XmlLoader;
347
- }());
348
- export { XmlLoader };
1
+ import { __awaiter, __generator } from "tslib";
2
+ import { GetClass } from "@babylonjs/core/Misc/typeStore.js";
3
+ var XmlLoaderError = "XmlLoader Exception : XML file is malformed or corrupted.";
4
+ /**
5
+ * Class used to load GUI via XML.
6
+ */
7
+ var XmlLoader = /** @class */ (function () {
8
+ /**
9
+ * Create a new xml loader
10
+ * @param parentClass Sets the class context. Used when the loader is instanced inside a class and not in a global context
11
+ */
12
+ function XmlLoader(parentClass) {
13
+ if (parentClass === void 0) { parentClass = null; }
14
+ this._nodes = {};
15
+ this._nodeTypes = {
16
+ element: 1,
17
+ attribute: 2,
18
+ text: 3,
19
+ };
20
+ this._isLoaded = false;
21
+ this._objectAttributes = {
22
+ textHorizontalAlignment: 1,
23
+ textVerticalAlignment: 2,
24
+ horizontalAlignment: 3,
25
+ verticalAlignment: 4,
26
+ stretch: 5,
27
+ };
28
+ if (parentClass) {
29
+ this._parentClass = parentClass;
30
+ }
31
+ }
32
+ XmlLoader.prototype._getChainElement = function (attributeValue) {
33
+ var element = window;
34
+ if (this._parentClass) {
35
+ element = this._parentClass;
36
+ }
37
+ var value = attributeValue;
38
+ value = value.split(".");
39
+ for (var i = 0; i < value.length; i++) {
40
+ element = element[value[i]];
41
+ }
42
+ return element;
43
+ };
44
+ XmlLoader.prototype._getClassAttribute = function (attributeName) {
45
+ var attribute = attributeName.split(".");
46
+ var className = GetClass("BABYLON.GUI." + attribute[0]);
47
+ return className[attribute[1]];
48
+ };
49
+ XmlLoader.prototype._createGuiElement = function (node, parent, linkParent) {
50
+ if (linkParent === void 0) { linkParent = true; }
51
+ try {
52
+ var className = GetClass("BABYLON.GUI." + node.nodeName);
53
+ var guiNode = new className();
54
+ if (parent && linkParent) {
55
+ parent.addControl(guiNode);
56
+ }
57
+ for (var i = 0; i < node.attributes.length; i++) {
58
+ if (node.attributes[i].name.toLowerCase().includes("datasource")) {
59
+ continue;
60
+ }
61
+ if (node.attributes[i].name.toLowerCase().includes("observable")) {
62
+ var element = this._getChainElement(node.attributes[i].value);
63
+ guiNode[node.attributes[i].name].add(element);
64
+ continue;
65
+ }
66
+ else if (node.attributes[i].name == "linkWithMesh") {
67
+ if (this._parentClass) {
68
+ guiNode.linkWithMesh(this._parentClass[node.attributes[i].value]);
69
+ }
70
+ else {
71
+ guiNode.linkWithMesh(window[node.attributes[i].value]);
72
+ }
73
+ }
74
+ else if (node.attributes[i].value.startsWith("{{") && node.attributes[i].value.endsWith("}}")) {
75
+ var element = this._getChainElement(node.attributes[i].value.substring(2, node.attributes[i].value.length - 2));
76
+ guiNode[node.attributes[i].name] = element;
77
+ }
78
+ else if (!this._objectAttributes[node.attributes[i].name]) {
79
+ if (node.attributes[i].value == "true" || node.attributes[i].value == "false") {
80
+ guiNode[node.attributes[i].name] = node.attributes[i].value == "true";
81
+ }
82
+ else {
83
+ guiNode[node.attributes[i].name] = !isNaN(Number(node.attributes[i].value)) ? Number(node.attributes[i].value) : node.attributes[i].value;
84
+ }
85
+ }
86
+ else {
87
+ guiNode[node.attributes[i].name] = this._getClassAttribute(node.attributes[i].value);
88
+ }
89
+ }
90
+ if (!node.attributes.getNamedItem("id")) {
91
+ this._nodes[node.nodeName + Object.keys(this._nodes).length + "_gen"] = guiNode;
92
+ return guiNode;
93
+ }
94
+ var id = node.attributes.getNamedItem("id").value;
95
+ if (id.startsWith("{{") && id.endsWith("}}")) {
96
+ id = this._getChainElement(id.substring(2, id.length - 2));
97
+ }
98
+ if (!this._nodes[id]) {
99
+ this._nodes[id] = guiNode;
100
+ }
101
+ else {
102
+ throw "XmlLoader Exception : Duplicate ID, every element should have an unique ID attribute";
103
+ }
104
+ return guiNode;
105
+ }
106
+ catch (exception) {
107
+ throw "XmlLoader Exception : Error parsing Control " + node.nodeName + "," + exception + ".";
108
+ }
109
+ };
110
+ XmlLoader.prototype._parseGrid = function (node, guiNode, parent) {
111
+ var width;
112
+ var height;
113
+ var columns;
114
+ var rows = node.children;
115
+ var cells;
116
+ var isPixel = false;
117
+ var cellNode;
118
+ var rowNumber = -1;
119
+ var columnNumber = -1;
120
+ var totalColumnsNumber = 0;
121
+ for (var i = 0; i < rows.length; i++) {
122
+ if (rows[i].nodeType != this._nodeTypes.element) {
123
+ continue;
124
+ }
125
+ if (rows[i].nodeName != "Row") {
126
+ throw "XmlLoader Exception : Expecting Row node, received " + rows[i].nodeName;
127
+ }
128
+ rowNumber += 1;
129
+ columns = rows[i].children;
130
+ if (!rows[i].attributes.getNamedItem("height")) {
131
+ throw "XmlLoader Exception : Height must be defined for grid rows";
132
+ }
133
+ height = Number(rows[i].attributes.getNamedItem("height").nodeValue);
134
+ isPixel = rows[i].attributes.getNamedItem("isPixel") ? JSON.parse(rows[i].attributes.getNamedItem("isPixel").nodeValue) : false;
135
+ guiNode.addRowDefinition(height, isPixel);
136
+ for (var j = 0; j < columns.length; j++) {
137
+ if (columns[j].nodeType != this._nodeTypes.element) {
138
+ continue;
139
+ }
140
+ if (columns[j].nodeName != "Column") {
141
+ throw "XmlLoader Exception : Expecting Column node, received " + columns[j].nodeName;
142
+ }
143
+ columnNumber += 1;
144
+ if (rowNumber > 0 && columnNumber > totalColumnsNumber) {
145
+ throw "XmlLoader Exception : In the Grid element, the number of columns is defined in the first row, do not add more columns in the subsequent rows.";
146
+ }
147
+ if (rowNumber == 0) {
148
+ if (!columns[j].attributes.getNamedItem("width")) {
149
+ throw "XmlLoader Exception : Width must be defined for all the grid columns in the first row";
150
+ }
151
+ width = Number(columns[j].attributes.getNamedItem("width").nodeValue);
152
+ isPixel = columns[j].attributes.getNamedItem("isPixel") ? JSON.parse(columns[j].attributes.getNamedItem("isPixel").nodeValue) : false;
153
+ guiNode.addColumnDefinition(width, isPixel);
154
+ }
155
+ cells = columns[j].children;
156
+ for (var k = 0; k < cells.length; k++) {
157
+ if (cells[k].nodeType != this._nodeTypes.element) {
158
+ continue;
159
+ }
160
+ cellNode = this._createGuiElement(cells[k], guiNode, false);
161
+ guiNode.addControl(cellNode, rowNumber, columnNumber);
162
+ if (cells[k].firstChild) {
163
+ this._parseXml(cells[k].firstChild, cellNode);
164
+ }
165
+ }
166
+ }
167
+ if (rowNumber == 0) {
168
+ totalColumnsNumber = columnNumber;
169
+ }
170
+ columnNumber = -1;
171
+ }
172
+ if (node.nextSibling) {
173
+ this._parseXml(node.nextSibling, parent);
174
+ }
175
+ };
176
+ XmlLoader.prototype._parseElement = function (node, guiNode, parent) {
177
+ if (node.firstChild) {
178
+ this._parseXml(node.firstChild, guiNode);
179
+ }
180
+ if (node.nextSibling) {
181
+ this._parseXml(node.nextSibling, parent);
182
+ }
183
+ };
184
+ XmlLoader.prototype._prepareSourceElement = function (node, guiNode, variable, source, iterator) {
185
+ if (this._parentClass) {
186
+ this._parentClass[variable] = source[iterator];
187
+ }
188
+ else {
189
+ window[variable] = source[iterator];
190
+ }
191
+ if (node.firstChild) {
192
+ this._parseXml(node.firstChild, guiNode, true);
193
+ }
194
+ };
195
+ XmlLoader.prototype._parseElementsFromSource = function (node, guiNode, parent) {
196
+ var dataSource = node.attributes.getNamedItem("dataSource").value;
197
+ if (!dataSource.includes(" in ")) {
198
+ throw "XmlLoader Exception : Malformed XML, Data Source must include an in";
199
+ }
200
+ else {
201
+ var isArray = true;
202
+ var splittedSource = dataSource.split(" in ");
203
+ if (splittedSource.length < 2) {
204
+ throw "XmlLoader Exception : Malformed XML, Data Source must have an iterator and a source";
205
+ }
206
+ var source = splittedSource[1];
207
+ if (source.startsWith("{") && source.endsWith("}")) {
208
+ isArray = false;
209
+ }
210
+ if (!isArray || (source.startsWith("[") && source.endsWith("]"))) {
211
+ source = source.substring(1, source.length - 1);
212
+ }
213
+ if (this._parentClass) {
214
+ source = this._parentClass[source];
215
+ }
216
+ else {
217
+ source = window[source];
218
+ }
219
+ if (isArray) {
220
+ for (var i = 0; i < source.length; i++) {
221
+ this._prepareSourceElement(node, guiNode, splittedSource[0], source, i);
222
+ }
223
+ }
224
+ else {
225
+ for (var i in source) {
226
+ this._prepareSourceElement(node, guiNode, splittedSource[0], source, i);
227
+ }
228
+ }
229
+ if (node.nextSibling) {
230
+ this._parseXml(node.nextSibling, parent);
231
+ }
232
+ }
233
+ };
234
+ XmlLoader.prototype._parseXml = function (node, parent, generated) {
235
+ if (generated === void 0) { generated = false; }
236
+ if (node.nodeType != this._nodeTypes.element) {
237
+ if (node.nextSibling) {
238
+ this._parseXml(node.nextSibling, parent, generated);
239
+ }
240
+ return;
241
+ }
242
+ if (generated) {
243
+ node.setAttribute("id", parent.id + (parent._children.length + 1));
244
+ }
245
+ var guiNode = this._createGuiElement(node, parent);
246
+ if (!this._rootNode) {
247
+ this._rootNode = guiNode;
248
+ }
249
+ if (node.nodeName == "Grid") {
250
+ this._parseGrid(node, guiNode, parent);
251
+ }
252
+ else if (!node.attributes.getNamedItem("dataSource")) {
253
+ this._parseElement(node, guiNode, parent);
254
+ }
255
+ else {
256
+ this._parseElementsFromSource(node, guiNode, parent);
257
+ }
258
+ };
259
+ /**
260
+ * Gets if the loading has finished.
261
+ * @returns whether the loading has finished or not
262
+ */
263
+ XmlLoader.prototype.isLoaded = function () {
264
+ return this._isLoaded;
265
+ };
266
+ /**
267
+ * Gets a loaded node / control by id.
268
+ * @param id the Controls id set in the xml
269
+ * @returns element of type Control
270
+ */
271
+ XmlLoader.prototype.getNodeById = function (id) {
272
+ return this._nodes[id];
273
+ };
274
+ /**
275
+ * Gets all loaded nodes / controls
276
+ * @returns Array of controls
277
+ */
278
+ XmlLoader.prototype.getNodes = function () {
279
+ return this._nodes;
280
+ };
281
+ /**
282
+ * Disposes the loaded layout
283
+ */
284
+ XmlLoader.prototype.dispose = function () {
285
+ if (this._rootNode) {
286
+ this._rootNode.dispose();
287
+ this._rootNode = null;
288
+ this._nodes = {};
289
+ }
290
+ };
291
+ /**
292
+ * Initiates the xml layout loading
293
+ * @param xmlFile defines the xml layout to load
294
+ * @param rootNode defines the node / control to use as a parent for the loaded layout controls.
295
+ * @param onSuccess defines the callback called on layout load successfully.
296
+ * @param onError defines the callback called on layout load failure.
297
+ */
298
+ XmlLoader.prototype.loadLayout = function (xmlFile, rootNode, onSuccess, onError) {
299
+ var _this = this;
300
+ if (onSuccess === void 0) { onSuccess = null; }
301
+ if (onError === void 0) { onError = null; }
302
+ var xhttp = new XMLHttpRequest();
303
+ xhttp.onload = function () {
304
+ if (xhttp.readyState === 4 && xhttp.status === 200) {
305
+ if (!xhttp.responseXML) {
306
+ if (onError) {
307
+ onError(XmlLoaderError);
308
+ return;
309
+ }
310
+ else {
311
+ throw XmlLoaderError;
312
+ }
313
+ }
314
+ var xmlDoc = xhttp.responseXML.documentElement;
315
+ _this._parseXml(xmlDoc.firstChild, rootNode);
316
+ _this._isLoaded = true;
317
+ if (onSuccess) {
318
+ onSuccess();
319
+ }
320
+ }
321
+ };
322
+ xhttp.onerror = function () {
323
+ if (onError) {
324
+ onError("an error occurred during loading the layout");
325
+ }
326
+ };
327
+ xhttp.open("GET", xmlFile, true);
328
+ xhttp.send();
329
+ };
330
+ /**
331
+ * Initiates the xml layout loading asynchronously
332
+ * @param xmlFile defines the xml layout to load
333
+ * @param rootNode defines the node / control to use as a parent for the loaded layout controls.
334
+ * @returns Promise
335
+ */
336
+ XmlLoader.prototype.loadLayoutAsync = function (xmlFile, rootNode) {
337
+ return __awaiter(this, void 0, void 0, function () {
338
+ var _this = this;
339
+ return __generator(this, function (_a) {
340
+ return [2 /*return*/, new Promise(function (resolve, reject) {
341
+ _this.loadLayout(xmlFile, rootNode, resolve, reject);
342
+ })];
343
+ });
344
+ });
345
+ };
346
+ return XmlLoader;
347
+ }());
348
+ export { XmlLoader };
349
349
  //# sourceMappingURL=xmlLoader.js.map