@babylonjs/gui 5.0.0-rc.1 → 5.0.0-rc.12

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 (306) 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 -423
  5. package/2D/advancedDynamicTexture.js +1318 -1286
  6. package/2D/advancedDynamicTexture.js.map +1 -1
  7. package/2D/controls/button.d.ts +135 -97
  8. package/2D/controls/button.js +276 -238
  9. package/2D/controls/button.js.map +1 -1
  10. package/2D/controls/checkbox.d.ts +59 -51
  11. package/2D/controls/checkbox.js +188 -178
  12. package/2D/controls/checkbox.js.map +1 -1
  13. package/2D/controls/colorpicker.d.ts +103 -90
  14. package/2D/controls/colorpicker.js +1417 -1400
  15. package/2D/controls/colorpicker.js.map +1 -1
  16. package/2D/controls/container.d.ts +175 -130
  17. package/2D/controls/container.js +570 -525
  18. package/2D/controls/container.js.map +1 -1
  19. package/2D/controls/control.d.ts +866 -743
  20. package/2D/controls/control.js +2433 -2308
  21. package/2D/controls/control.js.map +1 -1
  22. package/2D/controls/displayGrid.d.ts +53 -55
  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 -52
  29. package/2D/controls/focusableButton.js +99 -92
  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 -135
  35. package/2D/controls/grid.js +529 -525
  36. package/2D/controls/grid.js.map +1 -1
  37. package/2D/controls/image.d.ts +204 -197
  38. package/2D/controls/image.js +887 -879
  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/index.js.map +1 -1
  43. package/2D/controls/inputPassword.d.ts +9 -8
  44. package/2D/controls/inputPassword.js +28 -25
  45. package/2D/controls/inputPassword.js.map +1 -1
  46. package/2D/controls/inputText.d.ts +201 -182
  47. package/2D/controls/inputText.js +1119 -1096
  48. package/2D/controls/inputText.js.map +1 -1
  49. package/2D/controls/line.d.ts +66 -66
  50. package/2D/controls/line.js +271 -271
  51. package/2D/controls/line.js.map +1 -1
  52. package/2D/controls/multiLine.d.ts +75 -77
  53. package/2D/controls/multiLine.js +262 -262
  54. package/2D/controls/multiLine.js.map +1 -1
  55. package/2D/controls/radioButton.d.ts +49 -49
  56. package/2D/controls/radioButton.js +205 -205
  57. package/2D/controls/radioButton.js.map +1 -1
  58. package/2D/controls/rectangle.d.ts +29 -29
  59. package/2D/controls/rectangle.js +150 -150
  60. package/2D/controls/rectangle.js.map +1 -1
  61. package/2D/controls/scrollViewers/scrollViewer.d.ts +182 -175
  62. package/2D/controls/scrollViewers/scrollViewer.js +677 -676
  63. package/2D/controls/scrollViewers/scrollViewer.js.map +1 -1
  64. package/2D/controls/scrollViewers/scrollViewerWindow.d.ts +57 -45
  65. package/2D/controls/scrollViewers/scrollViewerWindow.js +278 -263
  66. package/2D/controls/scrollViewers/scrollViewerWindow.js.map +1 -1
  67. package/2D/controls/selector.d.ts +263 -209
  68. package/2D/controls/selector.js +692 -629
  69. package/2D/controls/selector.js.map +1 -1
  70. package/2D/controls/sliders/baseSlider.d.ts +82 -78
  71. package/2D/controls/sliders/baseSlider.js +347 -343
  72. package/2D/controls/sliders/baseSlider.js.map +1 -1
  73. package/2D/controls/sliders/imageBasedSlider.d.ts +49 -47
  74. package/2D/controls/sliders/imageBasedSlider.js +192 -188
  75. package/2D/controls/sliders/imageBasedSlider.js.map +1 -1
  76. package/2D/controls/sliders/imageScrollBar.d.ts +65 -61
  77. package/2D/controls/sliders/imageScrollBar.js +263 -256
  78. package/2D/controls/sliders/imageScrollBar.js.map +1 -1
  79. package/2D/controls/sliders/scrollBar.d.ts +38 -34
  80. package/2D/controls/sliders/scrollBar.js +143 -136
  81. package/2D/controls/sliders/scrollBar.js.map +1 -1
  82. package/2D/controls/sliders/slider.d.ts +35 -37
  83. package/2D/controls/sliders/slider.js +271 -271
  84. package/2D/controls/sliders/slider.js.map +1 -1
  85. package/2D/controls/stackPanel.d.ts +64 -56
  86. package/2D/controls/stackPanel.js +246 -236
  87. package/2D/controls/stackPanel.js.map +1 -1
  88. package/2D/controls/statics.d.ts +6 -6
  89. package/2D/controls/statics.js +49 -47
  90. package/2D/controls/statics.js.map +1 -1
  91. package/2D/controls/textBlock.d.ts +175 -172
  92. package/2D/controls/textBlock.js +603 -598
  93. package/2D/controls/textBlock.js.map +1 -1
  94. package/2D/controls/textWrapper.d.ts +13 -13
  95. package/2D/controls/textWrapper.js +101 -101
  96. package/2D/controls/textWrapper.js.map +1 -1
  97. package/2D/controls/toggleButton.d.ts +117 -83
  98. package/2D/controls/toggleButton.js +268 -234
  99. package/2D/controls/toggleButton.js.map +1 -1
  100. package/2D/controls/virtualKeyboard.d.ts +96 -96
  101. package/2D/controls/virtualKeyboard.js +256 -256
  102. package/2D/controls/virtualKeyboard.js.map +1 -1
  103. package/2D/index.d.ts +9 -9
  104. package/2D/index.js +10 -9
  105. package/2D/index.js.map +1 -1
  106. package/2D/math2D.d.ts +117 -117
  107. package/2D/math2D.js +221 -221
  108. package/2D/math2D.js.map +1 -1
  109. package/2D/measure.d.ts +77 -77
  110. package/2D/measure.js +139 -149
  111. package/2D/measure.js.map +1 -1
  112. package/2D/multiLinePoint.d.ts +47 -47
  113. package/2D/multiLinePoint.js +127 -127
  114. package/2D/multiLinePoint.js.map +1 -1
  115. package/2D/style.d.ts +46 -46
  116. package/2D/style.js +97 -97
  117. package/2D/style.js.map +1 -1
  118. package/2D/valueAndUnit.d.ts +89 -89
  119. package/2D/valueAndUnit.js +226 -222
  120. package/2D/valueAndUnit.js.map +1 -1
  121. package/2D/xmlLoader.d.ts +60 -60
  122. package/2D/xmlLoader.js +348 -348
  123. package/2D/xmlLoader.js.map +1 -1
  124. package/3D/behaviors/defaultBehavior.d.ts +73 -73
  125. package/3D/behaviors/defaultBehavior.js +121 -121
  126. package/3D/behaviors/defaultBehavior.js.map +1 -1
  127. package/3D/controls/abstractButton3D.d.ts +15 -15
  128. package/3D/controls/abstractButton3D.js +25 -25
  129. package/3D/controls/abstractButton3D.js.map +1 -1
  130. package/3D/controls/button3D.d.ts +30 -30
  131. package/3D/controls/button3D.js +93 -93
  132. package/3D/controls/button3D.js.map +1 -1
  133. package/3D/controls/container3D.d.ts +72 -72
  134. package/3D/controls/container3D.js +139 -140
  135. package/3D/controls/container3D.js.map +1 -1
  136. package/3D/controls/contentDisplay3D.d.ts +30 -30
  137. package/3D/controls/contentDisplay3D.js +79 -78
  138. package/3D/controls/contentDisplay3D.js.map +1 -1
  139. package/3D/controls/control3D.d.ts +201 -165
  140. package/3D/controls/control3D.js +445 -408
  141. package/3D/controls/control3D.js.map +1 -1
  142. package/3D/controls/cylinderPanel.d.ts +17 -17
  143. package/3D/controls/cylinderPanel.js +66 -66
  144. package/3D/controls/cylinderPanel.js.map +1 -1
  145. package/3D/controls/handMenu.d.ts +28 -28
  146. package/3D/controls/handMenu.js +47 -47
  147. package/3D/controls/handMenu.js.map +1 -1
  148. package/3D/controls/holographicBackplate.d.ts +49 -48
  149. package/3D/controls/holographicBackplate.js +120 -120
  150. package/3D/controls/holographicBackplate.js.map +1 -1
  151. package/3D/controls/holographicButton.d.ts +84 -83
  152. package/3D/controls/holographicButton.js +339 -338
  153. package/3D/controls/holographicButton.js.map +1 -1
  154. package/3D/controls/holographicSlate.d.ts +131 -128
  155. package/3D/controls/holographicSlate.js +431 -428
  156. package/3D/controls/holographicSlate.js.map +1 -1
  157. package/3D/controls/index.d.ts +21 -21
  158. package/3D/controls/index.js +21 -21
  159. package/3D/controls/index.js.map +1 -1
  160. package/3D/controls/meshButton3D.d.ts +21 -21
  161. package/3D/controls/meshButton3D.js +62 -61
  162. package/3D/controls/meshButton3D.js.map +1 -1
  163. package/3D/controls/nearMenu.d.ts +44 -44
  164. package/3D/controls/nearMenu.js +114 -112
  165. package/3D/controls/nearMenu.js.map +1 -1
  166. package/3D/controls/planePanel.d.ts +9 -9
  167. package/3D/controls/planePanel.js +36 -36
  168. package/3D/controls/planePanel.js.map +1 -1
  169. package/3D/controls/scatterPanel.d.ts +18 -18
  170. package/3D/controls/scatterPanel.js +108 -108
  171. package/3D/controls/scatterPanel.js.map +1 -1
  172. package/3D/controls/slider3D.d.ts +81 -81
  173. package/3D/controls/slider3D.js +268 -267
  174. package/3D/controls/slider3D.js.map +1 -1
  175. package/3D/controls/spherePanel.d.ts +17 -17
  176. package/3D/controls/spherePanel.js +67 -67
  177. package/3D/controls/spherePanel.js.map +1 -1
  178. package/3D/controls/stackPanel3D.d.ts +22 -22
  179. package/3D/controls/stackPanel3D.js +107 -107
  180. package/3D/controls/stackPanel3D.js.map +1 -1
  181. package/3D/controls/touchButton3D.d.ts +80 -75
  182. package/3D/controls/touchButton3D.js +233 -227
  183. package/3D/controls/touchButton3D.js.map +1 -1
  184. package/3D/controls/touchHolographicButton.d.ts +110 -109
  185. package/3D/controls/touchHolographicButton.js +445 -445
  186. package/3D/controls/touchHolographicButton.js.map +1 -1
  187. package/3D/controls/touchHolographicMenu.d.ts +61 -61
  188. package/3D/controls/touchHolographicMenu.js +149 -148
  189. package/3D/controls/touchHolographicMenu.js.map +1 -1
  190. package/3D/controls/touchMeshButton3D.d.ts +21 -22
  191. package/3D/controls/touchMeshButton3D.js +62 -62
  192. package/3D/controls/touchMeshButton3D.js.map +1 -1
  193. package/3D/controls/volumeBasedPanel.d.ts +53 -52
  194. package/3D/controls/volumeBasedPanel.js +174 -174
  195. package/3D/controls/volumeBasedPanel.js.map +1 -1
  196. package/3D/gizmos/gizmoHandle.d.ts +108 -108
  197. package/3D/gizmos/gizmoHandle.js +209 -209
  198. package/3D/gizmos/gizmoHandle.js.map +1 -1
  199. package/3D/gizmos/index.d.ts +2 -2
  200. package/3D/gizmos/index.js +2 -2
  201. package/3D/gizmos/index.js.map +1 -1
  202. package/3D/gizmos/slateGizmo.d.ts +57 -57
  203. package/3D/gizmos/slateGizmo.js +369 -369
  204. package/3D/gizmos/slateGizmo.js.map +1 -1
  205. package/3D/gui3DManager.d.ts +94 -94
  206. package/3D/gui3DManager.js +257 -257
  207. package/3D/gui3DManager.js.map +1 -1
  208. package/3D/index.d.ts +5 -5
  209. package/3D/index.js +6 -5
  210. package/3D/index.js.map +1 -1
  211. package/3D/materials/fluent/fluentMaterial.d.ts +91 -90
  212. package/3D/materials/fluent/fluentMaterial.js +292 -281
  213. package/3D/materials/fluent/fluentMaterial.js.map +1 -1
  214. package/3D/materials/fluent/index.d.ts +1 -1
  215. package/3D/materials/fluent/index.js +1 -1
  216. package/3D/materials/fluent/index.js.map +1 -1
  217. package/3D/materials/fluent/shaders/fluent.fragment.d.ts +5 -5
  218. package/3D/materials/fluent/shaders/fluent.fragment.js +8 -6
  219. package/3D/materials/fluent/shaders/fluent.fragment.js.map +1 -1
  220. package/3D/materials/fluent/shaders/fluent.vertex.d.ts +5 -5
  221. package/3D/materials/fluent/shaders/fluent.vertex.js +8 -6
  222. package/3D/materials/fluent/shaders/fluent.vertex.js.map +1 -1
  223. package/3D/materials/fluentBackplate/fluentBackplateMaterial.d.ts +155 -154
  224. package/3D/materials/fluentBackplate/fluentBackplateMaterial.js +469 -434
  225. package/3D/materials/fluentBackplate/fluentBackplateMaterial.js.map +1 -1
  226. package/3D/materials/fluentBackplate/index.d.ts +1 -1
  227. package/3D/materials/fluentBackplate/index.js +1 -1
  228. package/3D/materials/fluentBackplate/index.js.map +1 -1
  229. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.d.ts +5 -5
  230. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.js +8 -6
  231. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.js.map +1 -1
  232. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.d.ts +5 -5
  233. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.js +8 -6
  234. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.js.map +1 -1
  235. package/3D/materials/fluentButton/fluentButtonMaterial.d.ts +190 -189
  236. package/3D/materials/fluentButton/fluentButtonMaterial.js +539 -537
  237. package/3D/materials/fluentButton/fluentButtonMaterial.js.map +1 -1
  238. package/3D/materials/fluentButton/index.d.ts +1 -1
  239. package/3D/materials/fluentButton/index.js +1 -1
  240. package/3D/materials/fluentButton/index.js.map +1 -1
  241. package/3D/materials/fluentButton/shaders/fluentButton.fragment.d.ts +5 -5
  242. package/3D/materials/fluentButton/shaders/fluentButton.fragment.js +8 -6
  243. package/3D/materials/fluentButton/shaders/fluentButton.fragment.js.map +1 -1
  244. package/3D/materials/fluentButton/shaders/fluentButton.vertex.d.ts +5 -5
  245. package/3D/materials/fluentButton/shaders/fluentButton.vertex.js +8 -6
  246. package/3D/materials/fluentButton/shaders/fluentButton.vertex.js.map +1 -1
  247. package/3D/materials/fluentMaterial.d.ts +4 -4
  248. package/3D/materials/fluentMaterial.js +4 -4
  249. package/3D/materials/fluentMaterial.js.map +1 -1
  250. package/3D/materials/handle/handleMaterial.d.ts +68 -68
  251. package/3D/materials/handle/handleMaterial.js +126 -126
  252. package/3D/materials/handle/handleMaterial.js.map +1 -1
  253. package/3D/materials/handle/index.d.ts +1 -1
  254. package/3D/materials/handle/index.js +1 -1
  255. package/3D/materials/handle/index.js.map +1 -1
  256. package/3D/materials/handle/shaders/handle.fragment.d.ts +5 -5
  257. package/3D/materials/handle/shaders/handle.fragment.js +8 -6
  258. package/3D/materials/handle/shaders/handle.fragment.js.map +1 -1
  259. package/3D/materials/handle/shaders/handle.vertex.d.ts +5 -5
  260. package/3D/materials/handle/shaders/handle.vertex.js +8 -6
  261. package/3D/materials/handle/shaders/handle.vertex.js.map +1 -1
  262. package/3D/materials/index.d.ts +5 -5
  263. package/3D/materials/index.js +6 -5
  264. package/3D/materials/index.js.map +1 -1
  265. package/3D/materials/mrdl/index.d.ts +3 -3
  266. package/3D/materials/mrdl/index.js +3 -3
  267. package/3D/materials/mrdl/index.js.map +1 -1
  268. package/3D/materials/mrdl/mrdlBackplateMaterial.d.ts +148 -147
  269. package/3D/materials/mrdl/mrdlBackplateMaterial.js +436 -409
  270. package/3D/materials/mrdl/mrdlBackplateMaterial.js.map +1 -1
  271. package/3D/materials/mrdl/mrdlSliderBarMaterial.d.ts +334 -333
  272. package/3D/materials/mrdl/mrdlSliderBarMaterial.js +851 -786
  273. package/3D/materials/mrdl/mrdlSliderBarMaterial.js.map +1 -1
  274. package/3D/materials/mrdl/mrdlSliderThumbMaterial.d.ts +334 -333
  275. package/3D/materials/mrdl/mrdlSliderThumbMaterial.js +851 -786
  276. package/3D/materials/mrdl/mrdlSliderThumbMaterial.js.map +1 -1
  277. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.d.ts +5 -5
  278. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.js +8 -6
  279. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.js.map +1 -1
  280. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.d.ts +5 -5
  281. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.js +8 -6
  282. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.js.map +1 -1
  283. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.d.ts +5 -5
  284. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.js +8 -6
  285. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.js.map +1 -1
  286. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.d.ts +5 -5
  287. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.js +8 -6
  288. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.js.map +1 -1
  289. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.d.ts +5 -5
  290. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.js +8 -6
  291. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.js.map +1 -1
  292. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.d.ts +5 -5
  293. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.js +8 -6
  294. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.js.map +1 -1
  295. package/3D/vector3WithInfo.d.ts +16 -16
  296. package/3D/vector3WithInfo.js +23 -23
  297. package/3D/vector3WithInfo.js.map +1 -1
  298. package/index.d.ts +2 -2
  299. package/index.js +3 -2
  300. package/index.js.map +1 -1
  301. package/legacy/legacy.d.ts +1 -1
  302. package/legacy/legacy.js +14 -13
  303. package/legacy/legacy.js.map +1 -1
  304. package/license.md +71 -0
  305. package/package.json +37 -325
  306. package/readme.md +2 -2
@@ -1,1097 +1,1120 @@
1
- import { __decorate, __extends } from "tslib";
2
- import { Observable } from "@babylonjs/core/Misc/observable.js";
3
- import { ClipboardEventTypes } from "@babylonjs/core/Events/clipboardEvents.js";
4
- import { PointerEventTypes } from '@babylonjs/core/Events/pointerEvents.js';
5
- import { Control } from "./control.js";
6
- import { ValueAndUnit } from "../valueAndUnit.js";
7
- import { RegisterClass } from '@babylonjs/core/Misc/typeStore.js';
8
- import { TextWrapper } from './textWrapper.js';
9
- import { serialize } from '@babylonjs/core/Misc/decorators.js';
10
- /**
11
- * Class used to create input text control
12
- */
13
- var InputText = /** @class */ (function (_super) {
14
- __extends(InputText, _super);
15
- /**
16
- * Creates a new InputText
17
- * @param name defines the control name
18
- * @param text defines the text of the control
19
- */
20
- function InputText(name, text) {
21
- if (text === void 0) { text = ""; }
22
- var _this = _super.call(this, name) || this;
23
- _this.name = name;
24
- _this._placeholderText = "";
25
- _this._background = "#222222";
26
- _this._focusedBackground = "#000000";
27
- _this._focusedColor = "white";
28
- _this._placeholderColor = "gray";
29
- _this._thickness = 1;
30
- _this._margin = new ValueAndUnit(10, ValueAndUnit.UNITMODE_PIXEL);
31
- _this._autoStretchWidth = true;
32
- _this._maxWidth = new ValueAndUnit(1, ValueAndUnit.UNITMODE_PERCENTAGE, false);
33
- _this._isFocused = false;
34
- _this._blinkIsEven = false;
35
- _this._cursorOffset = 0;
36
- _this._deadKey = false;
37
- _this._addKey = true;
38
- _this._currentKey = "";
39
- _this._isTextHighlightOn = false;
40
- _this._textHighlightColor = "#d5e0ff";
41
- _this._highligherOpacity = 0.4;
42
- _this._highlightedText = "";
43
- _this._startHighlightIndex = 0;
44
- _this._endHighlightIndex = 0;
45
- _this._cursorIndex = -1;
46
- _this._onFocusSelectAll = false;
47
- _this._isPointerDown = false;
48
- /** Gets or sets a string representing the message displayed on mobile when the control gets the focus */
49
- _this.promptMessage = "Please enter text:";
50
- /** Force disable prompt on mobile device */
51
- _this.disableMobilePrompt = false;
52
- /** Observable raised when the text changes */
53
- _this.onTextChangedObservable = new Observable();
54
- /** Observable raised just before an entered character is to be added */
55
- _this.onBeforeKeyAddObservable = new Observable();
56
- /** Observable raised when the control gets the focus */
57
- _this.onFocusObservable = new Observable();
58
- /** Observable raised when the control loses the focus */
59
- _this.onBlurObservable = new Observable();
60
- /**Observable raised when the text is highlighted */
61
- _this.onTextHighlightObservable = new Observable();
62
- /**Observable raised when copy event is triggered */
63
- _this.onTextCopyObservable = new Observable();
64
- /** Observable raised when cut event is triggered */
65
- _this.onTextCutObservable = new Observable();
66
- /** Observable raised when paste event is triggered */
67
- _this.onTextPasteObservable = new Observable();
68
- /** Observable raised when a key event was processed */
69
- _this.onKeyboardEventProcessedObservable = new Observable();
70
- _this.text = text;
71
- _this.isPointerBlocker = true;
72
- return _this;
73
- }
74
- Object.defineProperty(InputText.prototype, "maxWidth", {
75
- /** Gets or sets the maximum width allowed by the control */
76
- get: function () {
77
- return this._maxWidth.toString(this._host);
78
- },
79
- set: function (value) {
80
- if (this._maxWidth.toString(this._host) === value) {
81
- return;
82
- }
83
- if (this._maxWidth.fromString(value)) {
84
- this._markAsDirty();
85
- }
86
- },
87
- enumerable: false,
88
- configurable: true
89
- });
90
- Object.defineProperty(InputText.prototype, "maxWidthInPixels", {
91
- /** Gets the maximum width allowed by the control in pixels */
92
- get: function () {
93
- return this._maxWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
94
- },
95
- enumerable: false,
96
- configurable: true
97
- });
98
- Object.defineProperty(InputText.prototype, "highligherOpacity", {
99
- /** Gets or sets the text highlighter transparency; default: 0.4 */
100
- get: function () {
101
- return this._highligherOpacity;
102
- },
103
- set: function (value) {
104
- if (this._highligherOpacity === value) {
105
- return;
106
- }
107
- this._highligherOpacity = value;
108
- this._markAsDirty();
109
- },
110
- enumerable: false,
111
- configurable: true
112
- });
113
- Object.defineProperty(InputText.prototype, "onFocusSelectAll", {
114
- /** Gets or sets a boolean indicating whether to select complete text by default on input focus */
115
- get: function () {
116
- return this._onFocusSelectAll;
117
- },
118
- set: function (value) {
119
- if (this._onFocusSelectAll === value) {
120
- return;
121
- }
122
- this._onFocusSelectAll = value;
123
- this._markAsDirty();
124
- },
125
- enumerable: false,
126
- configurable: true
127
- });
128
- Object.defineProperty(InputText.prototype, "textHighlightColor", {
129
- /** Gets or sets the text hightlight color */
130
- get: function () {
131
- return this._textHighlightColor;
132
- },
133
- set: function (value) {
134
- if (this._textHighlightColor === value) {
135
- return;
136
- }
137
- this._textHighlightColor = value;
138
- this._markAsDirty();
139
- },
140
- enumerable: false,
141
- configurable: true
142
- });
143
- Object.defineProperty(InputText.prototype, "margin", {
144
- /** Gets or sets control margin */
145
- get: function () {
146
- return this._margin.toString(this._host);
147
- },
148
- set: function (value) {
149
- if (this._margin.toString(this._host) === value) {
150
- return;
151
- }
152
- if (this._margin.fromString(value)) {
153
- this._markAsDirty();
154
- }
155
- },
156
- enumerable: false,
157
- configurable: true
158
- });
159
- Object.defineProperty(InputText.prototype, "marginInPixels", {
160
- /** Gets control margin in pixels */
161
- get: function () {
162
- return this._margin.getValueInPixel(this._host, this._cachedParentMeasure.width);
163
- },
164
- enumerable: false,
165
- configurable: true
166
- });
167
- Object.defineProperty(InputText.prototype, "autoStretchWidth", {
168
- /** Gets or sets a boolean indicating if the control can auto stretch its width to adapt to the text */
169
- get: function () {
170
- return this._autoStretchWidth;
171
- },
172
- set: function (value) {
173
- if (this._autoStretchWidth === value) {
174
- return;
175
- }
176
- this._autoStretchWidth = value;
177
- this._markAsDirty();
178
- },
179
- enumerable: false,
180
- configurable: true
181
- });
182
- Object.defineProperty(InputText.prototype, "thickness", {
183
- /** Gets or sets border thickness */
184
- get: function () {
185
- return this._thickness;
186
- },
187
- set: function (value) {
188
- if (this._thickness === value) {
189
- return;
190
- }
191
- this._thickness = value;
192
- this._markAsDirty();
193
- },
194
- enumerable: false,
195
- configurable: true
196
- });
197
- Object.defineProperty(InputText.prototype, "focusedBackground", {
198
- /** Gets or sets the background color when focused */
199
- get: function () {
200
- return this._focusedBackground;
201
- },
202
- set: function (value) {
203
- if (this._focusedBackground === value) {
204
- return;
205
- }
206
- this._focusedBackground = value;
207
- this._markAsDirty();
208
- },
209
- enumerable: false,
210
- configurable: true
211
- });
212
- Object.defineProperty(InputText.prototype, "focusedColor", {
213
- /** Gets or sets the background color when focused */
214
- get: function () {
215
- return this._focusedColor;
216
- },
217
- set: function (value) {
218
- if (this._focusedColor === value) {
219
- return;
220
- }
221
- this._focusedColor = value;
222
- this._markAsDirty();
223
- },
224
- enumerable: false,
225
- configurable: true
226
- });
227
- Object.defineProperty(InputText.prototype, "background", {
228
- /** Gets or sets the background color */
229
- get: function () {
230
- return this._background;
231
- },
232
- set: function (value) {
233
- if (this._background === value) {
234
- return;
235
- }
236
- this._background = value;
237
- this._markAsDirty();
238
- },
239
- enumerable: false,
240
- configurable: true
241
- });
242
- Object.defineProperty(InputText.prototype, "placeholderColor", {
243
- /** Gets or sets the placeholder color */
244
- get: function () {
245
- return this._placeholderColor;
246
- },
247
- set: function (value) {
248
- if (this._placeholderColor === value) {
249
- return;
250
- }
251
- this._placeholderColor = value;
252
- this._markAsDirty();
253
- },
254
- enumerable: false,
255
- configurable: true
256
- });
257
- Object.defineProperty(InputText.prototype, "placeholderText", {
258
- /** Gets or sets the text displayed when the control is empty */
259
- get: function () {
260
- return this._placeholderText;
261
- },
262
- set: function (value) {
263
- if (this._placeholderText === value) {
264
- return;
265
- }
266
- this._placeholderText = value;
267
- this._markAsDirty();
268
- },
269
- enumerable: false,
270
- configurable: true
271
- });
272
- Object.defineProperty(InputText.prototype, "deadKey", {
273
- /** Gets or sets the dead key flag */
274
- get: function () {
275
- return this._deadKey;
276
- },
277
- set: function (flag) {
278
- this._deadKey = flag;
279
- },
280
- enumerable: false,
281
- configurable: true
282
- });
283
- Object.defineProperty(InputText.prototype, "highlightedText", {
284
- /** Gets or sets the highlight text */
285
- get: function () {
286
- return this._highlightedText;
287
- },
288
- set: function (text) {
289
- if (this._highlightedText === text) {
290
- return;
291
- }
292
- this._highlightedText = text;
293
- this._markAsDirty();
294
- },
295
- enumerable: false,
296
- configurable: true
297
- });
298
- Object.defineProperty(InputText.prototype, "addKey", {
299
- /** Gets or sets if the current key should be added */
300
- get: function () {
301
- return this._addKey;
302
- },
303
- set: function (flag) {
304
- this._addKey = flag;
305
- },
306
- enumerable: false,
307
- configurable: true
308
- });
309
- Object.defineProperty(InputText.prototype, "currentKey", {
310
- /** Gets or sets the value of the current key being entered */
311
- get: function () {
312
- return this._currentKey;
313
- },
314
- set: function (key) {
315
- this._currentKey = key;
316
- },
317
- enumerable: false,
318
- configurable: true
319
- });
320
- Object.defineProperty(InputText.prototype, "text", {
321
- /** Gets or sets the text displayed in the control */
322
- get: function () {
323
- return this._textWrapper.text;
324
- },
325
- set: function (value) {
326
- var valueAsString = value.toString(); // Forcing convertion
327
- if (!this._textWrapper) {
328
- this._textWrapper = new TextWrapper();
329
- }
330
- if (this._textWrapper.text === valueAsString) {
331
- return;
332
- }
333
- this._textWrapper.text = valueAsString;
334
- this._textHasChanged();
335
- },
336
- enumerable: false,
337
- configurable: true
338
- });
339
- InputText.prototype._textHasChanged = function () {
340
- this._markAsDirty();
341
- this.onTextChangedObservable.notifyObservers(this);
342
- };
343
- Object.defineProperty(InputText.prototype, "width", {
344
- /** Gets or sets control width */
345
- get: function () {
346
- return this._width.toString(this._host);
347
- },
348
- set: function (value) {
349
- if (this._width.toString(this._host) === value) {
350
- return;
351
- }
352
- if (this._width.fromString(value)) {
353
- this._markAsDirty();
354
- }
355
- this.autoStretchWidth = false;
356
- },
357
- enumerable: false,
358
- configurable: true
359
- });
360
- /** @hidden */
361
- InputText.prototype.onBlur = function () {
362
- this._isFocused = false;
363
- this._scrollLeft = null;
364
- this._cursorOffset = 0;
365
- clearTimeout(this._blinkTimeout);
366
- this._markAsDirty();
367
- this.onBlurObservable.notifyObservers(this);
368
- this._host.unRegisterClipboardEvents();
369
- if (this._onClipboardObserver) {
370
- this._host.onClipboardObservable.remove(this._onClipboardObserver);
371
- }
372
- var scene = this._host.getScene();
373
- if (this._onPointerDblTapObserver && scene) {
374
- scene.onPointerObservable.remove(this._onPointerDblTapObserver);
375
- }
376
- };
377
- /** @hidden */
378
- InputText.prototype.onFocus = function () {
379
- var _this = this;
380
- if (!this._isEnabled) {
381
- return;
382
- }
383
- this._scrollLeft = null;
384
- this._isFocused = true;
385
- this._blinkIsEven = false;
386
- this._cursorOffset = 0;
387
- this._markAsDirty();
388
- this.onFocusObservable.notifyObservers(this);
389
- if (this._focusedBy === "touch" && !this.disableMobilePrompt) {
390
- var value = prompt(this.promptMessage);
391
- if (value !== null) {
392
- this.text = value;
393
- }
394
- this._host.focusedControl = null;
395
- return;
396
- }
397
- this._host.registerClipboardEvents();
398
- this._onClipboardObserver = this._host.onClipboardObservable.add(function (clipboardInfo) {
399
- // process clipboard event, can be configured.
400
- switch (clipboardInfo.type) {
401
- case ClipboardEventTypes.COPY:
402
- _this._onCopyText(clipboardInfo.event);
403
- _this.onTextCopyObservable.notifyObservers(_this);
404
- break;
405
- case ClipboardEventTypes.CUT:
406
- _this._onCutText(clipboardInfo.event);
407
- _this.onTextCutObservable.notifyObservers(_this);
408
- break;
409
- case ClipboardEventTypes.PASTE:
410
- _this._onPasteText(clipboardInfo.event);
411
- _this.onTextPasteObservable.notifyObservers(_this);
412
- break;
413
- default: return;
414
- }
415
- });
416
- var scene = this._host.getScene();
417
- if (scene) {
418
- //register the pointer double tap event
419
- this._onPointerDblTapObserver = scene.onPointerObservable.add(function (pointerInfo) {
420
- if (!_this._isFocused) {
421
- return;
422
- }
423
- if (pointerInfo.type === PointerEventTypes.POINTERDOUBLETAP) {
424
- _this._processDblClick(pointerInfo);
425
- }
426
- });
427
- }
428
- if (this._onFocusSelectAll) {
429
- this._selectAllText();
430
- }
431
- };
432
- /**
433
- * Function to focus an inputText programmatically
434
- */
435
- InputText.prototype.focus = function () {
436
- this._host.moveFocusToControl(this);
437
- };
438
- /**
439
- * Function to unfocus an inputText programmatically
440
- */
441
- InputText.prototype.blur = function () {
442
- this._host.focusedControl = null;
443
- };
444
- InputText.prototype._getTypeName = function () {
445
- return "InputText";
446
- };
447
- /**
448
- * Function called to get the list of controls that should not steal the focus from this control
449
- * @returns an array of controls
450
- */
451
- InputText.prototype.keepsFocusWith = function () {
452
- if (!this._connectedVirtualKeyboard) {
453
- return null;
454
- }
455
- return [this._connectedVirtualKeyboard];
456
- };
457
- /** @hidden */
458
- InputText.prototype.processKey = function (keyCode, key, evt) {
459
- if (this.isReadOnly) {
460
- return;
461
- }
462
- //return if clipboard event keys (i.e -ctr/cmd + c,v,x)
463
- if (evt && (evt.ctrlKey || evt.metaKey) && (keyCode === 67 || keyCode === 86 || keyCode === 88)) {
464
- return;
465
- }
466
- //select all
467
- if (evt && (evt.ctrlKey || evt.metaKey) && keyCode === 65) {
468
- this._selectAllText();
469
- evt.preventDefault();
470
- return;
471
- }
472
- // Specific cases
473
- switch (keyCode) {
474
- case 32: //SPACE
475
- key = " "; //ie11 key for space is "Spacebar"
476
- break;
477
- case 191: //SLASH
478
- if (evt) {
479
- evt.preventDefault();
480
- }
481
- break;
482
- case 8: // BACKSPACE
483
- if (this._textWrapper.text && this._textWrapper.length > 0) {
484
- //delete the highlighted text
485
- if (this._isTextHighlightOn) {
486
- this._textWrapper.removePart(this._startHighlightIndex, this._endHighlightIndex);
487
- this._textHasChanged();
488
- this._isTextHighlightOn = false;
489
- this._cursorOffset = this._textWrapper.length - this._startHighlightIndex;
490
- this._blinkIsEven = false;
491
- if (evt) {
492
- evt.preventDefault();
493
- }
494
- return;
495
- }
496
- //delete single character
497
- if (this._cursorOffset === 0) {
498
- this.text = this._textWrapper.substr(0, this._textWrapper.length - 1);
499
- }
500
- else {
501
- var deletePosition = this._textWrapper.length - this._cursorOffset;
502
- if (deletePosition > 0) {
503
- this._textWrapper.removePart(deletePosition - 1, deletePosition);
504
- this._textHasChanged();
505
- }
506
- }
507
- }
508
- if (evt) {
509
- evt.preventDefault();
510
- }
511
- return;
512
- case 46: // DELETE
513
- if (this._isTextHighlightOn) {
514
- this._textWrapper.removePart(this._startHighlightIndex, this._endHighlightIndex);
515
- this._textHasChanged();
516
- this._isTextHighlightOn = false;
517
- this._cursorOffset = this._textWrapper.length - this._startHighlightIndex;
518
- if (evt) {
519
- evt.preventDefault();
520
- }
521
- return;
522
- }
523
- if (this._textWrapper.text && this._textWrapper.length > 0 && this._cursorOffset > 0) {
524
- var deletePosition = this._textWrapper.length - this._cursorOffset;
525
- this._textWrapper.removePart(deletePosition, deletePosition + 1);
526
- this._textHasChanged();
527
- this._cursorOffset--;
528
- }
529
- if (evt) {
530
- evt.preventDefault();
531
- }
532
- return;
533
- case 13: // RETURN
534
- this._host.focusedControl = null;
535
- this._isTextHighlightOn = false;
536
- return;
537
- case 35: // END
538
- this._cursorOffset = 0;
539
- this._blinkIsEven = false;
540
- this._isTextHighlightOn = false;
541
- this._markAsDirty();
542
- return;
543
- case 36: // HOME
544
- this._cursorOffset = this._textWrapper.length;
545
- this._blinkIsEven = false;
546
- this._isTextHighlightOn = false;
547
- this._markAsDirty();
548
- return;
549
- case 37: // LEFT
550
- this._cursorOffset++;
551
- if (this._cursorOffset > this._textWrapper.length) {
552
- this._cursorOffset = this._textWrapper.length;
553
- }
554
- if (evt && evt.shiftKey) {
555
- // update the cursor
556
- this._blinkIsEven = false;
557
- // shift + ctrl/cmd + <-
558
- if (evt.ctrlKey || evt.metaKey) {
559
- if (!this._isTextHighlightOn) {
560
- if (this._textWrapper.length === this._cursorOffset) {
561
- return;
562
- }
563
- else {
564
- this._endHighlightIndex = this._textWrapper.length - this._cursorOffset + 1;
565
- }
566
- }
567
- this._startHighlightIndex = 0;
568
- this._cursorIndex = this._textWrapper.length - this._endHighlightIndex;
569
- this._cursorOffset = this._textWrapper.length;
570
- this._isTextHighlightOn = true;
571
- this._markAsDirty();
572
- return;
573
- }
574
- //store the starting point
575
- if (!this._isTextHighlightOn) {
576
- this._isTextHighlightOn = true;
577
- this._cursorIndex = (this._cursorOffset >= this._textWrapper.length) ? this._textWrapper.length : this._cursorOffset - 1;
578
- }
579
- //if text is already highlighted
580
- else if (this._cursorIndex === -1) {
581
- this._cursorIndex = this._textWrapper.length - this._endHighlightIndex;
582
- this._cursorOffset = (this._startHighlightIndex === 0) ? this._textWrapper.length : this._textWrapper.length - this._startHighlightIndex + 1;
583
- }
584
- //set the highlight indexes
585
- if (this._cursorIndex < this._cursorOffset) {
586
- this._endHighlightIndex = this._textWrapper.length - this._cursorIndex;
587
- this._startHighlightIndex = this._textWrapper.length - this._cursorOffset;
588
- }
589
- else if (this._cursorIndex > this._cursorOffset) {
590
- this._endHighlightIndex = this._textWrapper.length - this._cursorOffset;
591
- this._startHighlightIndex = this._textWrapper.length - this._cursorIndex;
592
- }
593
- else {
594
- this._isTextHighlightOn = false;
595
- }
596
- this._markAsDirty();
597
- return;
598
- }
599
- if (this._isTextHighlightOn) {
600
- this._cursorOffset = this._textWrapper.length - this._startHighlightIndex;
601
- this._isTextHighlightOn = false;
602
- }
603
- if (evt && (evt.ctrlKey || evt.metaKey)) {
604
- this._cursorOffset = this._textWrapper.length;
605
- evt.preventDefault();
606
- }
607
- this._blinkIsEven = false;
608
- this._isTextHighlightOn = false;
609
- this._cursorIndex = -1;
610
- this._markAsDirty();
611
- return;
612
- case 39: // RIGHT
613
- this._cursorOffset--;
614
- if (this._cursorOffset < 0) {
615
- this._cursorOffset = 0;
616
- }
617
- if (evt && evt.shiftKey) {
618
- //update the cursor
619
- this._blinkIsEven = false;
620
- //shift + ctrl/cmd + ->
621
- if (evt.ctrlKey || evt.metaKey) {
622
- if (!this._isTextHighlightOn) {
623
- if (this._cursorOffset === 0) {
624
- return;
625
- }
626
- else {
627
- this._startHighlightIndex = this._textWrapper.length - this._cursorOffset - 1;
628
- }
629
- }
630
- this._endHighlightIndex = this._textWrapper.length;
631
- this._isTextHighlightOn = true;
632
- this._cursorIndex = this._textWrapper.length - this._startHighlightIndex;
633
- this._cursorOffset = 0;
634
- this._markAsDirty();
635
- return;
636
- }
637
- if (!this._isTextHighlightOn) {
638
- this._isTextHighlightOn = true;
639
- this._cursorIndex = (this._cursorOffset <= 0) ? 0 : this._cursorOffset + 1;
640
- }
641
- //if text is already highlighted
642
- else if (this._cursorIndex === -1) {
643
- this._cursorIndex = this._textWrapper.length - this._startHighlightIndex;
644
- this._cursorOffset = (this._textWrapper.length === this._endHighlightIndex) ? 0 : this._textWrapper.length - this._endHighlightIndex - 1;
645
- }
646
- //set the highlight indexes
647
- if (this._cursorIndex < this._cursorOffset) {
648
- this._endHighlightIndex = this._textWrapper.length - this._cursorIndex;
649
- this._startHighlightIndex = this._textWrapper.length - this._cursorOffset;
650
- }
651
- else if (this._cursorIndex > this._cursorOffset) {
652
- this._endHighlightIndex = this._textWrapper.length - this._cursorOffset;
653
- this._startHighlightIndex = this._textWrapper.length - this._cursorIndex;
654
- }
655
- else {
656
- this._isTextHighlightOn = false;
657
- }
658
- this._markAsDirty();
659
- return;
660
- }
661
- if (this._isTextHighlightOn) {
662
- this._cursorOffset = this._textWrapper.length - this._endHighlightIndex;
663
- this._isTextHighlightOn = false;
664
- }
665
- //ctr + ->
666
- if (evt && (evt.ctrlKey || evt.metaKey)) {
667
- this._cursorOffset = 0;
668
- evt.preventDefault();
669
- }
670
- this._blinkIsEven = false;
671
- this._isTextHighlightOn = false;
672
- this._cursorIndex = -1;
673
- this._markAsDirty();
674
- return;
675
- case 222: // Dead
676
- if (evt) {
677
- //add support for single and double quotes
678
- if (evt.code == "Quote") {
679
- if (evt.shiftKey) {
680
- keyCode = 34;
681
- key = '"';
682
- }
683
- else {
684
- keyCode = 39;
685
- key = "'";
686
- }
687
- }
688
- else {
689
- evt.preventDefault();
690
- this._cursorIndex = -1;
691
- this.deadKey = true;
692
- }
693
- }
694
- else {
695
- this._cursorIndex = -1;
696
- this.deadKey = true;
697
- }
698
- break;
699
- }
700
- // Printable characters
701
- if (key &&
702
- ((keyCode === -1) || // Direct access
703
- (keyCode === 32) || // Space
704
- (keyCode === 34) || // " add support for single and double quotes
705
- (keyCode === 39) || // '
706
- (keyCode > 47 && keyCode < 64) || // Numbers
707
- (keyCode > 64 && keyCode < 91) || // Letters
708
- (keyCode > 159 && keyCode < 193) || // Special characters
709
- (keyCode > 218 && keyCode < 223) || // Special characters
710
- (keyCode > 95 && keyCode < 112))) { // Numpad
711
- this._currentKey = key;
712
- this.onBeforeKeyAddObservable.notifyObservers(this);
713
- key = this._currentKey;
714
- if (this._addKey) {
715
- if (this._isTextHighlightOn) {
716
- this._textWrapper.removePart(this._startHighlightIndex, this._endHighlightIndex, key);
717
- this._textHasChanged();
718
- this._cursorOffset = this._textWrapper.length - (this._startHighlightIndex + 1);
719
- this._isTextHighlightOn = false;
720
- this._blinkIsEven = false;
721
- this._markAsDirty();
722
- }
723
- else if (this._cursorOffset === 0) {
724
- this.text += key;
725
- }
726
- else {
727
- var insertPosition = this._textWrapper.length - this._cursorOffset;
728
- this._textWrapper.removePart(insertPosition, insertPosition, key);
729
- this._textHasChanged();
730
- }
731
- }
732
- }
733
- };
734
- /** @hidden */
735
- InputText.prototype._updateValueFromCursorIndex = function (offset) {
736
- //update the cursor
737
- this._blinkIsEven = false;
738
- if (this._cursorIndex === -1) {
739
- this._cursorIndex = offset;
740
- }
741
- else {
742
- if (this._cursorIndex < this._cursorOffset) {
743
- this._endHighlightIndex = this._textWrapper.length - this._cursorIndex;
744
- this._startHighlightIndex = this._textWrapper.length - this._cursorOffset;
745
- }
746
- else if (this._cursorIndex > this._cursorOffset) {
747
- this._endHighlightIndex = this._textWrapper.length - this._cursorOffset;
748
- this._startHighlightIndex = this._textWrapper.length - this._cursorIndex;
749
- }
750
- else {
751
- this._isTextHighlightOn = false;
752
- this._markAsDirty();
753
- return;
754
- }
755
- }
756
- this._isTextHighlightOn = true;
757
- this._markAsDirty();
758
- };
759
- /** @hidden */
760
- InputText.prototype._processDblClick = function (evt) {
761
- //pre-find the start and end index of the word under cursor, speeds up the rendering
762
- this._startHighlightIndex = this._textWrapper.length - this._cursorOffset;
763
- this._endHighlightIndex = this._startHighlightIndex;
764
- var moveLeft, moveRight;
765
- do {
766
- moveRight = this._endHighlightIndex < this._textWrapper.length && this._textWrapper.isWord(this._endHighlightIndex) ? ++this._endHighlightIndex : 0;
767
- moveLeft = this._startHighlightIndex > 0 && this._textWrapper.isWord(this._startHighlightIndex - 1) ? --this._startHighlightIndex : 0;
768
- } while (moveLeft || moveRight);
769
- this._cursorOffset = this._textWrapper.length - this._startHighlightIndex;
770
- this.onTextHighlightObservable.notifyObservers(this);
771
- this._isTextHighlightOn = true;
772
- this._clickedCoordinate = null;
773
- this._blinkIsEven = true;
774
- this._cursorIndex = -1;
775
- this._markAsDirty();
776
- };
777
- /** @hidden */
778
- InputText.prototype._selectAllText = function () {
779
- this._blinkIsEven = true;
780
- this._isTextHighlightOn = true;
781
- this._startHighlightIndex = 0;
782
- this._endHighlightIndex = this._textWrapper.length;
783
- this._cursorOffset = this._textWrapper.length;
784
- this._cursorIndex = -1;
785
- this._markAsDirty();
786
- };
787
- /**
788
- * Handles the keyboard event
789
- * @param evt Defines the KeyboardEvent
790
- */
791
- InputText.prototype.processKeyboard = function (evt) {
792
- // process pressed key
793
- this.processKey(evt.keyCode, evt.key, evt);
794
- this.onKeyboardEventProcessedObservable.notifyObservers(evt);
795
- };
796
- /** @hidden */
797
- InputText.prototype._onCopyText = function (ev) {
798
- this._isTextHighlightOn = false;
799
- //when write permission to clipbaord data is denied
800
- try {
801
- ev.clipboardData && ev.clipboardData.setData("text/plain", this._highlightedText);
802
- }
803
- catch (_a) { } //pass
804
- this._host.clipboardData = this._highlightedText;
805
- };
806
- /** @hidden */
807
- InputText.prototype._onCutText = function (ev) {
808
- if (!this._highlightedText) {
809
- return;
810
- }
811
- this._textWrapper.removePart(this._startHighlightIndex, this._endHighlightIndex);
812
- this._textHasChanged();
813
- this._isTextHighlightOn = false;
814
- this._cursorOffset = this._textWrapper.length - this._startHighlightIndex;
815
- //when write permission to clipbaord data is denied
816
- try {
817
- ev.clipboardData && ev.clipboardData.setData("text/plain", this._highlightedText);
818
- }
819
- catch (_a) { } //pass
820
- this._host.clipboardData = this._highlightedText;
821
- this._highlightedText = "";
822
- };
823
- /** @hidden */
824
- InputText.prototype._onPasteText = function (ev) {
825
- var data = "";
826
- if (ev.clipboardData && ev.clipboardData.types.indexOf("text/plain") !== -1) {
827
- data = ev.clipboardData.getData("text/plain");
828
- }
829
- else {
830
- //get the cached data; returns blank string by default
831
- data = this._host.clipboardData;
832
- }
833
- var insertPosition = this._textWrapper.length - this._cursorOffset;
834
- this._textWrapper.removePart(insertPosition, insertPosition, data);
835
- this._textHasChanged();
836
- };
837
- InputText.prototype._draw = function (context, invalidatedRectangle) {
838
- var _this = this;
839
- context.save();
840
- this._applyStates(context);
841
- if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
842
- context.shadowColor = this.shadowColor;
843
- context.shadowBlur = this.shadowBlur;
844
- context.shadowOffsetX = this.shadowOffsetX;
845
- context.shadowOffsetY = this.shadowOffsetY;
846
- }
847
- // Background
848
- if (this._isFocused) {
849
- if (this._focusedBackground) {
850
- context.fillStyle = this._isEnabled ? this._focusedBackground : this._disabledColor;
851
- context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
852
- }
853
- }
854
- else if (this._background) {
855
- context.fillStyle = this._isEnabled ? this._background : this._disabledColor;
856
- context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
857
- }
858
- if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
859
- context.shadowBlur = 0;
860
- context.shadowOffsetX = 0;
861
- context.shadowOffsetY = 0;
862
- }
863
- if (!this._fontOffset || this._wasDirty) {
864
- this._fontOffset = Control._GetFontOffset(context.font);
865
- }
866
- // Text
867
- var clipTextLeft = this._currentMeasure.left + this._margin.getValueInPixel(this._host, this._tempParentMeasure.width);
868
- if (this.color) {
869
- context.fillStyle = this.color;
870
- }
871
- var text = this._beforeRenderText(this._textWrapper);
872
- if (!this._isFocused && !this._textWrapper.text && this._placeholderText) {
873
- text = new TextWrapper();
874
- text.text = this._placeholderText;
875
- if (this._placeholderColor) {
876
- context.fillStyle = this._placeholderColor;
877
- }
878
- }
879
- this._textWidth = context.measureText(text.text).width;
880
- var marginWidth = this._margin.getValueInPixel(this._host, this._tempParentMeasure.width) * 2;
881
- if (this._autoStretchWidth) {
882
- this.width = Math.min(this._maxWidth.getValueInPixel(this._host, this._tempParentMeasure.width), this._textWidth + marginWidth) + "px";
883
- this._autoStretchWidth = true; // setting the width will have reset _autoStretchWidth to false!
884
- }
885
- var rootY = this._fontOffset.ascent + (this._currentMeasure.height - this._fontOffset.height) / 2;
886
- var availableWidth = this._width.getValueInPixel(this._host, this._tempParentMeasure.width) - marginWidth;
887
- context.save();
888
- context.beginPath();
889
- context.rect(clipTextLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, availableWidth + 2, this._currentMeasure.height);
890
- context.clip();
891
- if (this._isFocused && this._textWidth > availableWidth) {
892
- var textLeft = clipTextLeft - this._textWidth + availableWidth;
893
- if (!this._scrollLeft) {
894
- this._scrollLeft = textLeft;
895
- }
896
- }
897
- else {
898
- this._scrollLeft = clipTextLeft;
899
- }
900
- context.fillText(text.text, this._scrollLeft, this._currentMeasure.top + rootY);
901
- // Cursor
902
- if (this._isFocused) {
903
- // Need to move cursor
904
- if (this._clickedCoordinate) {
905
- var rightPosition = this._scrollLeft + this._textWidth;
906
- var absoluteCursorPosition = rightPosition - this._clickedCoordinate;
907
- var currentSize = 0;
908
- this._cursorOffset = 0;
909
- var previousDist = 0;
910
- do {
911
- if (this._cursorOffset) {
912
- previousDist = Math.abs(absoluteCursorPosition - currentSize);
913
- }
914
- this._cursorOffset++;
915
- currentSize = context.measureText(text.substr(text.length - this._cursorOffset, this._cursorOffset)).width;
916
- } while (currentSize < absoluteCursorPosition && (text.length >= this._cursorOffset));
917
- // Find closest move
918
- if (Math.abs(absoluteCursorPosition - currentSize) > previousDist) {
919
- this._cursorOffset--;
920
- }
921
- this._blinkIsEven = false;
922
- this._clickedCoordinate = null;
923
- }
924
- // Render cursor
925
- if (!this._blinkIsEven) {
926
- var cursorOffsetText = text.substr(text.length - this._cursorOffset);
927
- var cursorOffsetWidth = context.measureText(cursorOffsetText).width;
928
- var cursorLeft = this._scrollLeft + this._textWidth - cursorOffsetWidth;
929
- if (cursorLeft < clipTextLeft) {
930
- this._scrollLeft += (clipTextLeft - cursorLeft);
931
- cursorLeft = clipTextLeft;
932
- this._markAsDirty();
933
- }
934
- else if (cursorLeft > clipTextLeft + availableWidth) {
935
- this._scrollLeft += (clipTextLeft + availableWidth - cursorLeft);
936
- cursorLeft = clipTextLeft + availableWidth;
937
- this._markAsDirty();
938
- }
939
- if (!this._isTextHighlightOn) {
940
- context.fillRect(cursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, 2, this._fontOffset.height);
941
- }
942
- }
943
- clearTimeout(this._blinkTimeout);
944
- this._blinkTimeout = setTimeout(function () {
945
- _this._blinkIsEven = !_this._blinkIsEven;
946
- _this._markAsDirty();
947
- }, 500);
948
- //show the highlighted text
949
- if (this._isTextHighlightOn) {
950
- clearTimeout(this._blinkTimeout);
951
- var highlightCursorOffsetWidth = context.measureText(text.substring(this._startHighlightIndex)).width;
952
- var highlightCursorLeft = this._scrollLeft + this._textWidth - highlightCursorOffsetWidth;
953
- this._highlightedText = text.substring(this._startHighlightIndex, this._endHighlightIndex);
954
- var width = context.measureText(text.substring(this._startHighlightIndex, this._endHighlightIndex)).width;
955
- if (highlightCursorLeft < clipTextLeft) {
956
- width = width - (clipTextLeft - highlightCursorLeft);
957
- if (!width) {
958
- // when using left arrow on text.length > availableWidth;
959
- // assigns the width of the first letter after clipTextLeft
960
- width = context.measureText(text.charAt(text.length - this._cursorOffset)).width;
961
- }
962
- highlightCursorLeft = clipTextLeft;
963
- }
964
- //for transparancy
965
- context.globalAlpha = this._highligherOpacity;
966
- context.fillStyle = this._textHighlightColor;
967
- context.fillRect(highlightCursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, width, this._fontOffset.height);
968
- context.globalAlpha = 1.0;
969
- }
970
- }
971
- context.restore();
972
- // Border
973
- if (this._thickness) {
974
- if (this._isFocused) {
975
- if (this.focusedColor) {
976
- context.strokeStyle = this.focusedColor;
977
- }
978
- }
979
- else {
980
- if (this.color) {
981
- context.strokeStyle = this.color;
982
- }
983
- }
984
- context.lineWidth = this._thickness;
985
- context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
986
- }
987
- context.restore();
988
- };
989
- InputText.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex, pi) {
990
- if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex, pi)) {
991
- return false;
992
- }
993
- if (this.isReadOnly) {
994
- return true;
995
- }
996
- this._clickedCoordinate = coordinates.x;
997
- this._isTextHighlightOn = false;
998
- this._highlightedText = "";
999
- this._cursorIndex = -1;
1000
- this._isPointerDown = true;
1001
- this._host._capturingControl[pointerId] = this;
1002
- this._focusedBy = pi.event.pointerType;
1003
- if (this._host.focusedControl === this) {
1004
- // Move cursor
1005
- clearTimeout(this._blinkTimeout);
1006
- this._markAsDirty();
1007
- return true;
1008
- }
1009
- if (!this._isEnabled) {
1010
- return false;
1011
- }
1012
- this._host.focusedControl = this;
1013
- return true;
1014
- };
1015
- InputText.prototype._onPointerMove = function (target, coordinates, pointerId, pi) {
1016
- if (this._host.focusedControl === this && this._isPointerDown && !this.isReadOnly) {
1017
- this._clickedCoordinate = coordinates.x;
1018
- this._markAsDirty();
1019
- this._updateValueFromCursorIndex(this._cursorOffset);
1020
- }
1021
- _super.prototype._onPointerMove.call(this, target, coordinates, pointerId, pi);
1022
- };
1023
- InputText.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
1024
- this._isPointerDown = false;
1025
- delete this._host._capturingControl[pointerId];
1026
- _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
1027
- };
1028
- InputText.prototype._beforeRenderText = function (textWrapper) {
1029
- return textWrapper;
1030
- };
1031
- InputText.prototype.dispose = function () {
1032
- _super.prototype.dispose.call(this);
1033
- this.onBlurObservable.clear();
1034
- this.onFocusObservable.clear();
1035
- this.onTextChangedObservable.clear();
1036
- this.onTextCopyObservable.clear();
1037
- this.onTextCutObservable.clear();
1038
- this.onTextPasteObservable.clear();
1039
- this.onTextHighlightObservable.clear();
1040
- this.onKeyboardEventProcessedObservable.clear();
1041
- };
1042
- __decorate([
1043
- serialize()
1044
- ], InputText.prototype, "promptMessage", void 0);
1045
- __decorate([
1046
- serialize()
1047
- ], InputText.prototype, "disableMobilePrompt", void 0);
1048
- __decorate([
1049
- serialize()
1050
- ], InputText.prototype, "maxWidth", null);
1051
- __decorate([
1052
- serialize()
1053
- ], InputText.prototype, "highligherOpacity", null);
1054
- __decorate([
1055
- serialize()
1056
- ], InputText.prototype, "onFocusSelectAll", null);
1057
- __decorate([
1058
- serialize()
1059
- ], InputText.prototype, "textHighlightColor", null);
1060
- __decorate([
1061
- serialize()
1062
- ], InputText.prototype, "margin", null);
1063
- __decorate([
1064
- serialize()
1065
- ], InputText.prototype, "autoStretchWidth", null);
1066
- __decorate([
1067
- serialize()
1068
- ], InputText.prototype, "thickness", null);
1069
- __decorate([
1070
- serialize()
1071
- ], InputText.prototype, "focusedBackground", null);
1072
- __decorate([
1073
- serialize()
1074
- ], InputText.prototype, "focusedColor", null);
1075
- __decorate([
1076
- serialize()
1077
- ], InputText.prototype, "background", null);
1078
- __decorate([
1079
- serialize()
1080
- ], InputText.prototype, "placeholderColor", null);
1081
- __decorate([
1082
- serialize()
1083
- ], InputText.prototype, "placeholderText", null);
1084
- __decorate([
1085
- serialize()
1086
- ], InputText.prototype, "deadKey", null);
1087
- __decorate([
1088
- serialize()
1089
- ], InputText.prototype, "text", null);
1090
- __decorate([
1091
- serialize()
1092
- ], InputText.prototype, "width", null);
1093
- return InputText;
1094
- }(Control));
1095
- export { InputText };
1096
- RegisterClass("BABYLON.GUI.InputText", InputText);
1
+ import { __decorate, __extends } from "tslib";
2
+ import { Observable } from "@babylonjs/core/Misc/observable.js";
3
+ import { ClipboardEventTypes } from "@babylonjs/core/Events/clipboardEvents.js";
4
+ import { PointerEventTypes } from "@babylonjs/core/Events/pointerEvents.js";
5
+ import { Control } from "./control";
6
+ import { ValueAndUnit } from "../valueAndUnit";
7
+ import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
8
+ import { TextWrapper } from "./textWrapper";
9
+ import { serialize } from "@babylonjs/core/Misc/decorators.js";
10
+ /**
11
+ * Class used to create input text control
12
+ */
13
+ var InputText = /** @class */ (function (_super) {
14
+ __extends(InputText, _super);
15
+ /**
16
+ * Creates a new InputText
17
+ * @param name defines the control name
18
+ * @param text defines the text of the control
19
+ */
20
+ function InputText(name, text) {
21
+ if (text === void 0) { text = ""; }
22
+ var _this = _super.call(this, name) || this;
23
+ _this.name = name;
24
+ _this._placeholderText = "";
25
+ _this._background = "#222222";
26
+ _this._focusedBackground = "#000000";
27
+ _this._focusedColor = "white";
28
+ _this._placeholderColor = "gray";
29
+ _this._thickness = 1;
30
+ _this._margin = new ValueAndUnit(10, ValueAndUnit.UNITMODE_PIXEL);
31
+ _this._autoStretchWidth = true;
32
+ _this._maxWidth = new ValueAndUnit(1, ValueAndUnit.UNITMODE_PERCENTAGE, false);
33
+ _this._isFocused = false;
34
+ _this._blinkIsEven = false;
35
+ _this._cursorOffset = 0;
36
+ _this._deadKey = false;
37
+ _this._addKey = true;
38
+ _this._currentKey = "";
39
+ _this._isTextHighlightOn = false;
40
+ _this._textHighlightColor = "#d5e0ff";
41
+ _this._highligherOpacity = 0.4;
42
+ _this._highlightedText = "";
43
+ _this._startHighlightIndex = 0;
44
+ _this._endHighlightIndex = 0;
45
+ _this._cursorIndex = -1;
46
+ _this._onFocusSelectAll = false;
47
+ _this._isPointerDown = false;
48
+ /** Gets or sets a string representing the message displayed on mobile when the control gets the focus */
49
+ _this.promptMessage = "Please enter text:";
50
+ /** Force disable prompt on mobile device */
51
+ _this.disableMobilePrompt = false;
52
+ /** Observable raised when the text changes */
53
+ _this.onTextChangedObservable = new Observable();
54
+ /** Observable raised just before an entered character is to be added */
55
+ _this.onBeforeKeyAddObservable = new Observable();
56
+ /** Observable raised when the control gets the focus */
57
+ _this.onFocusObservable = new Observable();
58
+ /** Observable raised when the control loses the focus */
59
+ _this.onBlurObservable = new Observable();
60
+ /**Observable raised when the text is highlighted */
61
+ _this.onTextHighlightObservable = new Observable();
62
+ /**Observable raised when copy event is triggered */
63
+ _this.onTextCopyObservable = new Observable();
64
+ /** Observable raised when cut event is triggered */
65
+ _this.onTextCutObservable = new Observable();
66
+ /** Observable raised when paste event is triggered */
67
+ _this.onTextPasteObservable = new Observable();
68
+ /** Observable raised when a key event was processed */
69
+ _this.onKeyboardEventProcessedObservable = new Observable();
70
+ _this.text = text;
71
+ _this.isPointerBlocker = true;
72
+ return _this;
73
+ }
74
+ Object.defineProperty(InputText.prototype, "maxWidth", {
75
+ /** Gets or sets the maximum width allowed by the control */
76
+ get: function () {
77
+ return this._maxWidth.toString(this._host);
78
+ },
79
+ set: function (value) {
80
+ if (this._maxWidth.toString(this._host) === value) {
81
+ return;
82
+ }
83
+ if (this._maxWidth.fromString(value)) {
84
+ this._markAsDirty();
85
+ }
86
+ },
87
+ enumerable: false,
88
+ configurable: true
89
+ });
90
+ Object.defineProperty(InputText.prototype, "maxWidthInPixels", {
91
+ /** Gets the maximum width allowed by the control in pixels */
92
+ get: function () {
93
+ return this._maxWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
94
+ },
95
+ enumerable: false,
96
+ configurable: true
97
+ });
98
+ Object.defineProperty(InputText.prototype, "highligherOpacity", {
99
+ /** Gets or sets the text highlighter transparency; default: 0.4 */
100
+ get: function () {
101
+ return this._highligherOpacity;
102
+ },
103
+ set: function (value) {
104
+ if (this._highligherOpacity === value) {
105
+ return;
106
+ }
107
+ this._highligherOpacity = value;
108
+ this._markAsDirty();
109
+ },
110
+ enumerable: false,
111
+ configurable: true
112
+ });
113
+ Object.defineProperty(InputText.prototype, "onFocusSelectAll", {
114
+ /** Gets or sets a boolean indicating whether to select complete text by default on input focus */
115
+ get: function () {
116
+ return this._onFocusSelectAll;
117
+ },
118
+ set: function (value) {
119
+ if (this._onFocusSelectAll === value) {
120
+ return;
121
+ }
122
+ this._onFocusSelectAll = value;
123
+ this._markAsDirty();
124
+ },
125
+ enumerable: false,
126
+ configurable: true
127
+ });
128
+ Object.defineProperty(InputText.prototype, "textHighlightColor", {
129
+ /** Gets or sets the text hightlight color */
130
+ get: function () {
131
+ return this._textHighlightColor;
132
+ },
133
+ set: function (value) {
134
+ if (this._textHighlightColor === value) {
135
+ return;
136
+ }
137
+ this._textHighlightColor = value;
138
+ this._markAsDirty();
139
+ },
140
+ enumerable: false,
141
+ configurable: true
142
+ });
143
+ Object.defineProperty(InputText.prototype, "margin", {
144
+ /** Gets or sets control margin */
145
+ get: function () {
146
+ return this._margin.toString(this._host);
147
+ },
148
+ set: function (value) {
149
+ if (this._margin.toString(this._host) === value) {
150
+ return;
151
+ }
152
+ if (this._margin.fromString(value)) {
153
+ this._markAsDirty();
154
+ }
155
+ },
156
+ enumerable: false,
157
+ configurable: true
158
+ });
159
+ Object.defineProperty(InputText.prototype, "marginInPixels", {
160
+ /** Gets control margin in pixels */
161
+ get: function () {
162
+ return this._margin.getValueInPixel(this._host, this._cachedParentMeasure.width);
163
+ },
164
+ enumerable: false,
165
+ configurable: true
166
+ });
167
+ Object.defineProperty(InputText.prototype, "autoStretchWidth", {
168
+ /** Gets or sets a boolean indicating if the control can auto stretch its width to adapt to the text */
169
+ get: function () {
170
+ return this._autoStretchWidth;
171
+ },
172
+ set: function (value) {
173
+ if (this._autoStretchWidth === value) {
174
+ return;
175
+ }
176
+ this._autoStretchWidth = value;
177
+ this._markAsDirty();
178
+ },
179
+ enumerable: false,
180
+ configurable: true
181
+ });
182
+ Object.defineProperty(InputText.prototype, "thickness", {
183
+ /** Gets or sets border thickness */
184
+ get: function () {
185
+ return this._thickness;
186
+ },
187
+ set: function (value) {
188
+ if (this._thickness === value) {
189
+ return;
190
+ }
191
+ this._thickness = value;
192
+ this._markAsDirty();
193
+ },
194
+ enumerable: false,
195
+ configurable: true
196
+ });
197
+ Object.defineProperty(InputText.prototype, "focusedBackground", {
198
+ /** Gets or sets the background color when focused */
199
+ get: function () {
200
+ return this._focusedBackground;
201
+ },
202
+ set: function (value) {
203
+ if (this._focusedBackground === value) {
204
+ return;
205
+ }
206
+ this._focusedBackground = value;
207
+ this._markAsDirty();
208
+ },
209
+ enumerable: false,
210
+ configurable: true
211
+ });
212
+ Object.defineProperty(InputText.prototype, "focusedColor", {
213
+ /** Gets or sets the background color when focused */
214
+ get: function () {
215
+ return this._focusedColor;
216
+ },
217
+ set: function (value) {
218
+ if (this._focusedColor === value) {
219
+ return;
220
+ }
221
+ this._focusedColor = value;
222
+ this._markAsDirty();
223
+ },
224
+ enumerable: false,
225
+ configurable: true
226
+ });
227
+ Object.defineProperty(InputText.prototype, "background", {
228
+ /** Gets or sets the background color */
229
+ get: function () {
230
+ return this._background;
231
+ },
232
+ set: function (value) {
233
+ if (this._background === value) {
234
+ return;
235
+ }
236
+ this._background = value;
237
+ this._markAsDirty();
238
+ },
239
+ enumerable: false,
240
+ configurable: true
241
+ });
242
+ Object.defineProperty(InputText.prototype, "placeholderColor", {
243
+ /** Gets or sets the placeholder color */
244
+ get: function () {
245
+ return this._placeholderColor;
246
+ },
247
+ set: function (value) {
248
+ if (this._placeholderColor === value) {
249
+ return;
250
+ }
251
+ this._placeholderColor = value;
252
+ this._markAsDirty();
253
+ },
254
+ enumerable: false,
255
+ configurable: true
256
+ });
257
+ Object.defineProperty(InputText.prototype, "placeholderText", {
258
+ /** Gets or sets the text displayed when the control is empty */
259
+ get: function () {
260
+ return this._placeholderText;
261
+ },
262
+ set: function (value) {
263
+ if (this._placeholderText === value) {
264
+ return;
265
+ }
266
+ this._placeholderText = value;
267
+ this._markAsDirty();
268
+ },
269
+ enumerable: false,
270
+ configurable: true
271
+ });
272
+ Object.defineProperty(InputText.prototype, "deadKey", {
273
+ /** Gets or sets the dead key flag */
274
+ get: function () {
275
+ return this._deadKey;
276
+ },
277
+ set: function (flag) {
278
+ this._deadKey = flag;
279
+ },
280
+ enumerable: false,
281
+ configurable: true
282
+ });
283
+ Object.defineProperty(InputText.prototype, "highlightedText", {
284
+ /** Gets or sets the highlight text */
285
+ get: function () {
286
+ return this._highlightedText;
287
+ },
288
+ set: function (text) {
289
+ if (this._highlightedText === text) {
290
+ return;
291
+ }
292
+ this._highlightedText = text;
293
+ this._markAsDirty();
294
+ },
295
+ enumerable: false,
296
+ configurable: true
297
+ });
298
+ Object.defineProperty(InputText.prototype, "addKey", {
299
+ /** Gets or sets if the current key should be added */
300
+ get: function () {
301
+ return this._addKey;
302
+ },
303
+ set: function (flag) {
304
+ this._addKey = flag;
305
+ },
306
+ enumerable: false,
307
+ configurable: true
308
+ });
309
+ Object.defineProperty(InputText.prototype, "currentKey", {
310
+ /** Gets or sets the value of the current key being entered */
311
+ get: function () {
312
+ return this._currentKey;
313
+ },
314
+ set: function (key) {
315
+ this._currentKey = key;
316
+ },
317
+ enumerable: false,
318
+ configurable: true
319
+ });
320
+ Object.defineProperty(InputText.prototype, "text", {
321
+ /** Gets or sets the text displayed in the control */
322
+ get: function () {
323
+ return this._textWrapper.text;
324
+ },
325
+ set: function (value) {
326
+ var valueAsString = value.toString(); // Forcing convertion
327
+ if (!this._textWrapper) {
328
+ this._textWrapper = new TextWrapper();
329
+ }
330
+ if (this._textWrapper.text === valueAsString) {
331
+ return;
332
+ }
333
+ this._textWrapper.text = valueAsString;
334
+ this._textHasChanged();
335
+ },
336
+ enumerable: false,
337
+ configurable: true
338
+ });
339
+ InputText.prototype._textHasChanged = function () {
340
+ this._markAsDirty();
341
+ this.onTextChangedObservable.notifyObservers(this);
342
+ };
343
+ Object.defineProperty(InputText.prototype, "width", {
344
+ /** Gets or sets control width */
345
+ get: function () {
346
+ return this._width.toString(this._host);
347
+ },
348
+ set: function (value) {
349
+ if (this._width.toString(this._host) === value) {
350
+ return;
351
+ }
352
+ if (this._width.fromString(value)) {
353
+ this._markAsDirty();
354
+ }
355
+ this.autoStretchWidth = false;
356
+ },
357
+ enumerable: false,
358
+ configurable: true
359
+ });
360
+ /** @hidden */
361
+ InputText.prototype.onBlur = function () {
362
+ this._isFocused = false;
363
+ this._scrollLeft = null;
364
+ this._cursorOffset = 0;
365
+ clearTimeout(this._blinkTimeout);
366
+ this._markAsDirty();
367
+ this.onBlurObservable.notifyObservers(this);
368
+ this._host.unRegisterClipboardEvents();
369
+ if (this._onClipboardObserver) {
370
+ this._host.onClipboardObservable.remove(this._onClipboardObserver);
371
+ }
372
+ var scene = this._host.getScene();
373
+ if (this._onPointerDblTapObserver && scene) {
374
+ scene.onPointerObservable.remove(this._onPointerDblTapObserver);
375
+ }
376
+ };
377
+ /** @hidden */
378
+ InputText.prototype.onFocus = function () {
379
+ var _this = this;
380
+ if (!this._isEnabled) {
381
+ return;
382
+ }
383
+ this._scrollLeft = null;
384
+ this._isFocused = true;
385
+ this._blinkIsEven = false;
386
+ this._cursorOffset = 0;
387
+ this._markAsDirty();
388
+ this.onFocusObservable.notifyObservers(this);
389
+ if (this._focusedBy === "touch" && !this.disableMobilePrompt) {
390
+ var value = prompt(this.promptMessage);
391
+ if (value !== null) {
392
+ this.text = value;
393
+ }
394
+ this._host.focusedControl = null;
395
+ return;
396
+ }
397
+ this._host.registerClipboardEvents();
398
+ this._onClipboardObserver = this._host.onClipboardObservable.add(function (clipboardInfo) {
399
+ // process clipboard event, can be configured.
400
+ switch (clipboardInfo.type) {
401
+ case ClipboardEventTypes.COPY:
402
+ _this._onCopyText(clipboardInfo.event);
403
+ _this.onTextCopyObservable.notifyObservers(_this);
404
+ break;
405
+ case ClipboardEventTypes.CUT:
406
+ _this._onCutText(clipboardInfo.event);
407
+ _this.onTextCutObservable.notifyObservers(_this);
408
+ break;
409
+ case ClipboardEventTypes.PASTE:
410
+ _this._onPasteText(clipboardInfo.event);
411
+ _this.onTextPasteObservable.notifyObservers(_this);
412
+ break;
413
+ default:
414
+ return;
415
+ }
416
+ });
417
+ var scene = this._host.getScene();
418
+ if (scene) {
419
+ //register the pointer double tap event
420
+ this._onPointerDblTapObserver = scene.onPointerObservable.add(function (pointerInfo) {
421
+ if (!_this._isFocused) {
422
+ return;
423
+ }
424
+ if (pointerInfo.type === PointerEventTypes.POINTERDOUBLETAP) {
425
+ _this._processDblClick(pointerInfo);
426
+ }
427
+ });
428
+ }
429
+ if (this._onFocusSelectAll) {
430
+ this._selectAllText();
431
+ }
432
+ };
433
+ /**
434
+ * Function to focus an inputText programmatically
435
+ */
436
+ InputText.prototype.focus = function () {
437
+ this._host.moveFocusToControl(this);
438
+ };
439
+ /**
440
+ * Function to unfocus an inputText programmatically
441
+ */
442
+ InputText.prototype.blur = function () {
443
+ this._host.focusedControl = null;
444
+ };
445
+ InputText.prototype._getTypeName = function () {
446
+ return "InputText";
447
+ };
448
+ /**
449
+ * Function called to get the list of controls that should not steal the focus from this control
450
+ * @returns an array of controls
451
+ */
452
+ InputText.prototype.keepsFocusWith = function () {
453
+ if (!this._connectedVirtualKeyboard) {
454
+ return null;
455
+ }
456
+ return [this._connectedVirtualKeyboard];
457
+ };
458
+ /**
459
+ * @param keyCode
460
+ * @param key
461
+ * @param evt
462
+ * @hidden
463
+ */
464
+ InputText.prototype.processKey = function (keyCode, key, evt) {
465
+ if (this.isReadOnly) {
466
+ return;
467
+ }
468
+ //return if clipboard event keys (i.e -ctr/cmd + c,v,x)
469
+ if (evt && (evt.ctrlKey || evt.metaKey) && (keyCode === 67 || keyCode === 86 || keyCode === 88)) {
470
+ return;
471
+ }
472
+ //select all
473
+ if (evt && (evt.ctrlKey || evt.metaKey) && keyCode === 65) {
474
+ this._selectAllText();
475
+ evt.preventDefault();
476
+ return;
477
+ }
478
+ // Specific cases
479
+ switch (keyCode) {
480
+ case 32: //SPACE
481
+ key = " "; //ie11 key for space is "Spacebar"
482
+ break;
483
+ case 191: //SLASH
484
+ if (evt) {
485
+ evt.preventDefault();
486
+ }
487
+ break;
488
+ case 8: // BACKSPACE
489
+ if (this._textWrapper.text && this._textWrapper.length > 0) {
490
+ //delete the highlighted text
491
+ if (this._isTextHighlightOn) {
492
+ this._textWrapper.removePart(this._startHighlightIndex, this._endHighlightIndex);
493
+ this._textHasChanged();
494
+ this._isTextHighlightOn = false;
495
+ this._cursorOffset = this._textWrapper.length - this._startHighlightIndex;
496
+ this._blinkIsEven = false;
497
+ if (evt) {
498
+ evt.preventDefault();
499
+ }
500
+ return;
501
+ }
502
+ //delete single character
503
+ if (this._cursorOffset === 0) {
504
+ this.text = this._textWrapper.substr(0, this._textWrapper.length - 1);
505
+ }
506
+ else {
507
+ var deletePosition = this._textWrapper.length - this._cursorOffset;
508
+ if (deletePosition > 0) {
509
+ this._textWrapper.removePart(deletePosition - 1, deletePosition);
510
+ this._textHasChanged();
511
+ }
512
+ }
513
+ }
514
+ if (evt) {
515
+ evt.preventDefault();
516
+ }
517
+ return;
518
+ case 46: // DELETE
519
+ if (this._isTextHighlightOn) {
520
+ this._textWrapper.removePart(this._startHighlightIndex, this._endHighlightIndex);
521
+ this._textHasChanged();
522
+ this._isTextHighlightOn = false;
523
+ this._cursorOffset = this._textWrapper.length - this._startHighlightIndex;
524
+ if (evt) {
525
+ evt.preventDefault();
526
+ }
527
+ return;
528
+ }
529
+ if (this._textWrapper.text && this._textWrapper.length > 0 && this._cursorOffset > 0) {
530
+ var deletePosition = this._textWrapper.length - this._cursorOffset;
531
+ this._textWrapper.removePart(deletePosition, deletePosition + 1);
532
+ this._textHasChanged();
533
+ this._cursorOffset--;
534
+ }
535
+ if (evt) {
536
+ evt.preventDefault();
537
+ }
538
+ return;
539
+ case 13: // RETURN
540
+ this._host.focusedControl = null;
541
+ this._isTextHighlightOn = false;
542
+ return;
543
+ case 35: // END
544
+ this._cursorOffset = 0;
545
+ this._blinkIsEven = false;
546
+ this._isTextHighlightOn = false;
547
+ this._markAsDirty();
548
+ return;
549
+ case 36: // HOME
550
+ this._cursorOffset = this._textWrapper.length;
551
+ this._blinkIsEven = false;
552
+ this._isTextHighlightOn = false;
553
+ this._markAsDirty();
554
+ return;
555
+ case 37: // LEFT
556
+ this._cursorOffset++;
557
+ if (this._cursorOffset > this._textWrapper.length) {
558
+ this._cursorOffset = this._textWrapper.length;
559
+ }
560
+ if (evt && evt.shiftKey) {
561
+ // update the cursor
562
+ this._blinkIsEven = false;
563
+ // shift + ctrl/cmd + <-
564
+ if (evt.ctrlKey || evt.metaKey) {
565
+ if (!this._isTextHighlightOn) {
566
+ if (this._textWrapper.length === this._cursorOffset) {
567
+ return;
568
+ }
569
+ else {
570
+ this._endHighlightIndex = this._textWrapper.length - this._cursorOffset + 1;
571
+ }
572
+ }
573
+ this._startHighlightIndex = 0;
574
+ this._cursorIndex = this._textWrapper.length - this._endHighlightIndex;
575
+ this._cursorOffset = this._textWrapper.length;
576
+ this._isTextHighlightOn = true;
577
+ this._markAsDirty();
578
+ return;
579
+ }
580
+ //store the starting point
581
+ if (!this._isTextHighlightOn) {
582
+ this._isTextHighlightOn = true;
583
+ this._cursorIndex = this._cursorOffset >= this._textWrapper.length ? this._textWrapper.length : this._cursorOffset - 1;
584
+ }
585
+ //if text is already highlighted
586
+ else if (this._cursorIndex === -1) {
587
+ this._cursorIndex = this._textWrapper.length - this._endHighlightIndex;
588
+ this._cursorOffset = this._startHighlightIndex === 0 ? this._textWrapper.length : this._textWrapper.length - this._startHighlightIndex + 1;
589
+ }
590
+ //set the highlight indexes
591
+ if (this._cursorIndex < this._cursorOffset) {
592
+ this._endHighlightIndex = this._textWrapper.length - this._cursorIndex;
593
+ this._startHighlightIndex = this._textWrapper.length - this._cursorOffset;
594
+ }
595
+ else if (this._cursorIndex > this._cursorOffset) {
596
+ this._endHighlightIndex = this._textWrapper.length - this._cursorOffset;
597
+ this._startHighlightIndex = this._textWrapper.length - this._cursorIndex;
598
+ }
599
+ else {
600
+ this._isTextHighlightOn = false;
601
+ }
602
+ this._markAsDirty();
603
+ return;
604
+ }
605
+ if (this._isTextHighlightOn) {
606
+ this._cursorOffset = this._textWrapper.length - this._startHighlightIndex;
607
+ this._isTextHighlightOn = false;
608
+ }
609
+ if (evt && (evt.ctrlKey || evt.metaKey)) {
610
+ this._cursorOffset = this._textWrapper.length;
611
+ evt.preventDefault();
612
+ }
613
+ this._blinkIsEven = false;
614
+ this._isTextHighlightOn = false;
615
+ this._cursorIndex = -1;
616
+ this._markAsDirty();
617
+ return;
618
+ case 39: // RIGHT
619
+ this._cursorOffset--;
620
+ if (this._cursorOffset < 0) {
621
+ this._cursorOffset = 0;
622
+ }
623
+ if (evt && evt.shiftKey) {
624
+ //update the cursor
625
+ this._blinkIsEven = false;
626
+ //shift + ctrl/cmd + ->
627
+ if (evt.ctrlKey || evt.metaKey) {
628
+ if (!this._isTextHighlightOn) {
629
+ if (this._cursorOffset === 0) {
630
+ return;
631
+ }
632
+ else {
633
+ this._startHighlightIndex = this._textWrapper.length - this._cursorOffset - 1;
634
+ }
635
+ }
636
+ this._endHighlightIndex = this._textWrapper.length;
637
+ this._isTextHighlightOn = true;
638
+ this._cursorIndex = this._textWrapper.length - this._startHighlightIndex;
639
+ this._cursorOffset = 0;
640
+ this._markAsDirty();
641
+ return;
642
+ }
643
+ if (!this._isTextHighlightOn) {
644
+ this._isTextHighlightOn = true;
645
+ this._cursorIndex = this._cursorOffset <= 0 ? 0 : this._cursorOffset + 1;
646
+ }
647
+ //if text is already highlighted
648
+ else if (this._cursorIndex === -1) {
649
+ this._cursorIndex = this._textWrapper.length - this._startHighlightIndex;
650
+ this._cursorOffset = this._textWrapper.length === this._endHighlightIndex ? 0 : this._textWrapper.length - this._endHighlightIndex - 1;
651
+ }
652
+ //set the highlight indexes
653
+ if (this._cursorIndex < this._cursorOffset) {
654
+ this._endHighlightIndex = this._textWrapper.length - this._cursorIndex;
655
+ this._startHighlightIndex = this._textWrapper.length - this._cursorOffset;
656
+ }
657
+ else if (this._cursorIndex > this._cursorOffset) {
658
+ this._endHighlightIndex = this._textWrapper.length - this._cursorOffset;
659
+ this._startHighlightIndex = this._textWrapper.length - this._cursorIndex;
660
+ }
661
+ else {
662
+ this._isTextHighlightOn = false;
663
+ }
664
+ this._markAsDirty();
665
+ return;
666
+ }
667
+ if (this._isTextHighlightOn) {
668
+ this._cursorOffset = this._textWrapper.length - this._endHighlightIndex;
669
+ this._isTextHighlightOn = false;
670
+ }
671
+ //ctr + ->
672
+ if (evt && (evt.ctrlKey || evt.metaKey)) {
673
+ this._cursorOffset = 0;
674
+ evt.preventDefault();
675
+ }
676
+ this._blinkIsEven = false;
677
+ this._isTextHighlightOn = false;
678
+ this._cursorIndex = -1;
679
+ this._markAsDirty();
680
+ return;
681
+ case 222: // Dead
682
+ if (evt) {
683
+ //add support for single and double quotes
684
+ if (evt.code == "Quote") {
685
+ if (evt.shiftKey) {
686
+ keyCode = 34;
687
+ key = '"';
688
+ }
689
+ else {
690
+ keyCode = 39;
691
+ key = "'";
692
+ }
693
+ }
694
+ else {
695
+ evt.preventDefault();
696
+ this._cursorIndex = -1;
697
+ this.deadKey = true;
698
+ }
699
+ }
700
+ else {
701
+ this._cursorIndex = -1;
702
+ this.deadKey = true;
703
+ }
704
+ break;
705
+ }
706
+ // Printable characters
707
+ if (key &&
708
+ (keyCode === -1 || // Direct access
709
+ keyCode === 32 || // Space
710
+ keyCode === 34 || // " add support for single and double quotes
711
+ keyCode === 39 || // '
712
+ (keyCode > 47 && keyCode < 64) || // Numbers
713
+ (keyCode > 64 && keyCode < 91) || // Letters
714
+ (keyCode > 159 && keyCode < 193) || // Special characters
715
+ (keyCode > 218 && keyCode < 223) || // Special characters
716
+ (keyCode > 95 && keyCode < 112))) {
717
+ // Numpad
718
+ this._currentKey = key;
719
+ this.onBeforeKeyAddObservable.notifyObservers(this);
720
+ key = this._currentKey;
721
+ if (this._addKey) {
722
+ if (this._isTextHighlightOn) {
723
+ this._textWrapper.removePart(this._startHighlightIndex, this._endHighlightIndex, key);
724
+ this._textHasChanged();
725
+ this._cursorOffset = this._textWrapper.length - (this._startHighlightIndex + 1);
726
+ this._isTextHighlightOn = false;
727
+ this._blinkIsEven = false;
728
+ this._markAsDirty();
729
+ }
730
+ else if (this._cursorOffset === 0) {
731
+ this.text += key;
732
+ }
733
+ else {
734
+ var insertPosition = this._textWrapper.length - this._cursorOffset;
735
+ this._textWrapper.removePart(insertPosition, insertPosition, key);
736
+ this._textHasChanged();
737
+ }
738
+ }
739
+ }
740
+ };
741
+ /**
742
+ * @param offset
743
+ * @hidden
744
+ */
745
+ InputText.prototype._updateValueFromCursorIndex = function (offset) {
746
+ //update the cursor
747
+ this._blinkIsEven = false;
748
+ if (this._cursorIndex === -1) {
749
+ this._cursorIndex = offset;
750
+ }
751
+ else {
752
+ if (this._cursorIndex < this._cursorOffset) {
753
+ this._endHighlightIndex = this._textWrapper.length - this._cursorIndex;
754
+ this._startHighlightIndex = this._textWrapper.length - this._cursorOffset;
755
+ }
756
+ else if (this._cursorIndex > this._cursorOffset) {
757
+ this._endHighlightIndex = this._textWrapper.length - this._cursorOffset;
758
+ this._startHighlightIndex = this._textWrapper.length - this._cursorIndex;
759
+ }
760
+ else {
761
+ this._isTextHighlightOn = false;
762
+ this._markAsDirty();
763
+ return;
764
+ }
765
+ }
766
+ this._isTextHighlightOn = true;
767
+ this._markAsDirty();
768
+ };
769
+ /**
770
+ * @param evt
771
+ * @hidden
772
+ */
773
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
774
+ InputText.prototype._processDblClick = function (evt) {
775
+ //pre-find the start and end index of the word under cursor, speeds up the rendering
776
+ this._startHighlightIndex = this._textWrapper.length - this._cursorOffset;
777
+ this._endHighlightIndex = this._startHighlightIndex;
778
+ var moveLeft, moveRight;
779
+ do {
780
+ moveRight = this._endHighlightIndex < this._textWrapper.length && this._textWrapper.isWord(this._endHighlightIndex) ? ++this._endHighlightIndex : 0;
781
+ moveLeft = this._startHighlightIndex > 0 && this._textWrapper.isWord(this._startHighlightIndex - 1) ? --this._startHighlightIndex : 0;
782
+ } while (moveLeft || moveRight);
783
+ this._cursorOffset = this._textWrapper.length - this._startHighlightIndex;
784
+ this.onTextHighlightObservable.notifyObservers(this);
785
+ this._isTextHighlightOn = true;
786
+ this._clickedCoordinate = null;
787
+ this._blinkIsEven = true;
788
+ this._cursorIndex = -1;
789
+ this._markAsDirty();
790
+ };
791
+ /** @hidden */
792
+ InputText.prototype._selectAllText = function () {
793
+ this._blinkIsEven = true;
794
+ this._isTextHighlightOn = true;
795
+ this._startHighlightIndex = 0;
796
+ this._endHighlightIndex = this._textWrapper.length;
797
+ this._cursorOffset = this._textWrapper.length;
798
+ this._cursorIndex = -1;
799
+ this._markAsDirty();
800
+ };
801
+ /**
802
+ * Handles the keyboard event
803
+ * @param evt Defines the KeyboardEvent
804
+ */
805
+ InputText.prototype.processKeyboard = function (evt) {
806
+ // process pressed key
807
+ this.processKey(evt.keyCode, evt.key, evt);
808
+ this.onKeyboardEventProcessedObservable.notifyObservers(evt);
809
+ };
810
+ /**
811
+ * @param ev
812
+ * @hidden
813
+ */
814
+ InputText.prototype._onCopyText = function (ev) {
815
+ this._isTextHighlightOn = false;
816
+ //when write permission to clipbaord data is denied
817
+ try {
818
+ ev.clipboardData && ev.clipboardData.setData("text/plain", this._highlightedText);
819
+ }
820
+ catch (_a) { } //pass
821
+ this._host.clipboardData = this._highlightedText;
822
+ };
823
+ /**
824
+ * @param ev
825
+ * @hidden
826
+ */
827
+ InputText.prototype._onCutText = function (ev) {
828
+ if (!this._highlightedText) {
829
+ return;
830
+ }
831
+ this._textWrapper.removePart(this._startHighlightIndex, this._endHighlightIndex);
832
+ this._textHasChanged();
833
+ this._isTextHighlightOn = false;
834
+ this._cursorOffset = this._textWrapper.length - this._startHighlightIndex;
835
+ //when write permission to clipbaord data is denied
836
+ try {
837
+ ev.clipboardData && ev.clipboardData.setData("text/plain", this._highlightedText);
838
+ }
839
+ catch (_a) { } //pass
840
+ this._host.clipboardData = this._highlightedText;
841
+ this._highlightedText = "";
842
+ };
843
+ /**
844
+ * @param ev
845
+ * @hidden
846
+ */
847
+ InputText.prototype._onPasteText = function (ev) {
848
+ var data = "";
849
+ if (ev.clipboardData && ev.clipboardData.types.indexOf("text/plain") !== -1) {
850
+ data = ev.clipboardData.getData("text/plain");
851
+ }
852
+ else {
853
+ //get the cached data; returns blank string by default
854
+ data = this._host.clipboardData;
855
+ }
856
+ var insertPosition = this._textWrapper.length - this._cursorOffset;
857
+ this._textWrapper.removePart(insertPosition, insertPosition, data);
858
+ this._textHasChanged();
859
+ };
860
+ InputText.prototype._draw = function (context) {
861
+ var _this = this;
862
+ context.save();
863
+ this._applyStates(context);
864
+ if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
865
+ context.shadowColor = this.shadowColor;
866
+ context.shadowBlur = this.shadowBlur;
867
+ context.shadowOffsetX = this.shadowOffsetX;
868
+ context.shadowOffsetY = this.shadowOffsetY;
869
+ }
870
+ // Background
871
+ if (this._isFocused) {
872
+ if (this._focusedBackground) {
873
+ context.fillStyle = this._isEnabled ? this._focusedBackground : this._disabledColor;
874
+ context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
875
+ }
876
+ }
877
+ else if (this._background) {
878
+ context.fillStyle = this._isEnabled ? this._background : this._disabledColor;
879
+ context.fillRect(this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
880
+ }
881
+ if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
882
+ context.shadowBlur = 0;
883
+ context.shadowOffsetX = 0;
884
+ context.shadowOffsetY = 0;
885
+ }
886
+ if (!this._fontOffset || this._wasDirty) {
887
+ this._fontOffset = Control._GetFontOffset(context.font);
888
+ }
889
+ // Text
890
+ var clipTextLeft = this._currentMeasure.left + this._margin.getValueInPixel(this._host, this._tempParentMeasure.width);
891
+ if (this.color) {
892
+ context.fillStyle = this.color;
893
+ }
894
+ var text = this._beforeRenderText(this._textWrapper);
895
+ if (!this._isFocused && !this._textWrapper.text && this._placeholderText) {
896
+ text = new TextWrapper();
897
+ text.text = this._placeholderText;
898
+ if (this._placeholderColor) {
899
+ context.fillStyle = this._placeholderColor;
900
+ }
901
+ }
902
+ this._textWidth = context.measureText(text.text).width;
903
+ var marginWidth = this._margin.getValueInPixel(this._host, this._tempParentMeasure.width) * 2;
904
+ if (this._autoStretchWidth) {
905
+ this.width = Math.min(this._maxWidth.getValueInPixel(this._host, this._tempParentMeasure.width), this._textWidth + marginWidth) + "px";
906
+ this._autoStretchWidth = true; // setting the width will have reset _autoStretchWidth to false!
907
+ }
908
+ var rootY = this._fontOffset.ascent + (this._currentMeasure.height - this._fontOffset.height) / 2;
909
+ var availableWidth = this._width.getValueInPixel(this._host, this._tempParentMeasure.width) - marginWidth;
910
+ context.save();
911
+ context.beginPath();
912
+ context.rect(clipTextLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, availableWidth + 2, this._currentMeasure.height);
913
+ context.clip();
914
+ if (this._isFocused && this._textWidth > availableWidth) {
915
+ var textLeft = clipTextLeft - this._textWidth + availableWidth;
916
+ if (!this._scrollLeft) {
917
+ this._scrollLeft = textLeft;
918
+ }
919
+ }
920
+ else {
921
+ this._scrollLeft = clipTextLeft;
922
+ }
923
+ context.fillText(text.text, this._scrollLeft, this._currentMeasure.top + rootY);
924
+ // Cursor
925
+ if (this._isFocused) {
926
+ // Need to move cursor
927
+ if (this._clickedCoordinate) {
928
+ var rightPosition = this._scrollLeft + this._textWidth;
929
+ var absoluteCursorPosition = rightPosition - this._clickedCoordinate;
930
+ var currentSize = 0;
931
+ this._cursorOffset = 0;
932
+ var previousDist = 0;
933
+ do {
934
+ if (this._cursorOffset) {
935
+ previousDist = Math.abs(absoluteCursorPosition - currentSize);
936
+ }
937
+ this._cursorOffset++;
938
+ currentSize = context.measureText(text.substr(text.length - this._cursorOffset, this._cursorOffset)).width;
939
+ } while (currentSize < absoluteCursorPosition && text.length >= this._cursorOffset);
940
+ // Find closest move
941
+ if (Math.abs(absoluteCursorPosition - currentSize) > previousDist) {
942
+ this._cursorOffset--;
943
+ }
944
+ this._blinkIsEven = false;
945
+ this._clickedCoordinate = null;
946
+ }
947
+ // Render cursor
948
+ if (!this._blinkIsEven) {
949
+ var cursorOffsetText = text.substr(text.length - this._cursorOffset);
950
+ var cursorOffsetWidth = context.measureText(cursorOffsetText).width;
951
+ var cursorLeft = this._scrollLeft + this._textWidth - cursorOffsetWidth;
952
+ if (cursorLeft < clipTextLeft) {
953
+ this._scrollLeft += clipTextLeft - cursorLeft;
954
+ cursorLeft = clipTextLeft;
955
+ this._markAsDirty();
956
+ }
957
+ else if (cursorLeft > clipTextLeft + availableWidth) {
958
+ this._scrollLeft += clipTextLeft + availableWidth - cursorLeft;
959
+ cursorLeft = clipTextLeft + availableWidth;
960
+ this._markAsDirty();
961
+ }
962
+ if (!this._isTextHighlightOn) {
963
+ context.fillRect(cursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, 2, this._fontOffset.height);
964
+ }
965
+ }
966
+ clearTimeout(this._blinkTimeout);
967
+ this._blinkTimeout = setTimeout(function () {
968
+ _this._blinkIsEven = !_this._blinkIsEven;
969
+ _this._markAsDirty();
970
+ }, 500);
971
+ //show the highlighted text
972
+ if (this._isTextHighlightOn) {
973
+ clearTimeout(this._blinkTimeout);
974
+ var highlightCursorOffsetWidth = context.measureText(text.substring(this._startHighlightIndex)).width;
975
+ var highlightCursorLeft = this._scrollLeft + this._textWidth - highlightCursorOffsetWidth;
976
+ this._highlightedText = text.substring(this._startHighlightIndex, this._endHighlightIndex);
977
+ var width = context.measureText(text.substring(this._startHighlightIndex, this._endHighlightIndex)).width;
978
+ if (highlightCursorLeft < clipTextLeft) {
979
+ width = width - (clipTextLeft - highlightCursorLeft);
980
+ if (!width) {
981
+ // when using left arrow on text.length > availableWidth;
982
+ // assigns the width of the first letter after clipTextLeft
983
+ width = context.measureText(text.charAt(text.length - this._cursorOffset)).width;
984
+ }
985
+ highlightCursorLeft = clipTextLeft;
986
+ }
987
+ //for transparancy
988
+ context.globalAlpha = this._highligherOpacity;
989
+ context.fillStyle = this._textHighlightColor;
990
+ context.fillRect(highlightCursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, width, this._fontOffset.height);
991
+ context.globalAlpha = 1.0;
992
+ }
993
+ }
994
+ context.restore();
995
+ // Border
996
+ if (this._thickness) {
997
+ if (this._isFocused) {
998
+ if (this.focusedColor) {
999
+ context.strokeStyle = this.focusedColor;
1000
+ }
1001
+ }
1002
+ else {
1003
+ if (this.color) {
1004
+ context.strokeStyle = this.color;
1005
+ }
1006
+ }
1007
+ context.lineWidth = this._thickness;
1008
+ context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2, this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
1009
+ }
1010
+ context.restore();
1011
+ };
1012
+ InputText.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex, pi) {
1013
+ if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex, pi)) {
1014
+ return false;
1015
+ }
1016
+ if (this.isReadOnly) {
1017
+ return true;
1018
+ }
1019
+ this._clickedCoordinate = coordinates.x;
1020
+ this._isTextHighlightOn = false;
1021
+ this._highlightedText = "";
1022
+ this._cursorIndex = -1;
1023
+ this._isPointerDown = true;
1024
+ this._host._capturingControl[pointerId] = this;
1025
+ this._focusedBy = pi.event.pointerType;
1026
+ if (this._host.focusedControl === this) {
1027
+ // Move cursor
1028
+ clearTimeout(this._blinkTimeout);
1029
+ this._markAsDirty();
1030
+ return true;
1031
+ }
1032
+ if (!this._isEnabled) {
1033
+ return false;
1034
+ }
1035
+ this._host.focusedControl = this;
1036
+ return true;
1037
+ };
1038
+ InputText.prototype._onPointerMove = function (target, coordinates, pointerId, pi) {
1039
+ if (this._host.focusedControl === this && this._isPointerDown && !this.isReadOnly) {
1040
+ this._clickedCoordinate = coordinates.x;
1041
+ this._markAsDirty();
1042
+ this._updateValueFromCursorIndex(this._cursorOffset);
1043
+ }
1044
+ _super.prototype._onPointerMove.call(this, target, coordinates, pointerId, pi);
1045
+ };
1046
+ InputText.prototype._onPointerUp = function (target, coordinates, pointerId, buttonIndex, notifyClick) {
1047
+ this._isPointerDown = false;
1048
+ delete this._host._capturingControl[pointerId];
1049
+ _super.prototype._onPointerUp.call(this, target, coordinates, pointerId, buttonIndex, notifyClick);
1050
+ };
1051
+ InputText.prototype._beforeRenderText = function (textWrapper) {
1052
+ return textWrapper;
1053
+ };
1054
+ InputText.prototype.dispose = function () {
1055
+ _super.prototype.dispose.call(this);
1056
+ this.onBlurObservable.clear();
1057
+ this.onFocusObservable.clear();
1058
+ this.onTextChangedObservable.clear();
1059
+ this.onTextCopyObservable.clear();
1060
+ this.onTextCutObservable.clear();
1061
+ this.onTextPasteObservable.clear();
1062
+ this.onTextHighlightObservable.clear();
1063
+ this.onKeyboardEventProcessedObservable.clear();
1064
+ };
1065
+ __decorate([
1066
+ serialize()
1067
+ ], InputText.prototype, "promptMessage", void 0);
1068
+ __decorate([
1069
+ serialize()
1070
+ ], InputText.prototype, "disableMobilePrompt", void 0);
1071
+ __decorate([
1072
+ serialize()
1073
+ ], InputText.prototype, "maxWidth", null);
1074
+ __decorate([
1075
+ serialize()
1076
+ ], InputText.prototype, "highligherOpacity", null);
1077
+ __decorate([
1078
+ serialize()
1079
+ ], InputText.prototype, "onFocusSelectAll", null);
1080
+ __decorate([
1081
+ serialize()
1082
+ ], InputText.prototype, "textHighlightColor", null);
1083
+ __decorate([
1084
+ serialize()
1085
+ ], InputText.prototype, "margin", null);
1086
+ __decorate([
1087
+ serialize()
1088
+ ], InputText.prototype, "autoStretchWidth", null);
1089
+ __decorate([
1090
+ serialize()
1091
+ ], InputText.prototype, "thickness", null);
1092
+ __decorate([
1093
+ serialize()
1094
+ ], InputText.prototype, "focusedBackground", null);
1095
+ __decorate([
1096
+ serialize()
1097
+ ], InputText.prototype, "focusedColor", null);
1098
+ __decorate([
1099
+ serialize()
1100
+ ], InputText.prototype, "background", null);
1101
+ __decorate([
1102
+ serialize()
1103
+ ], InputText.prototype, "placeholderColor", null);
1104
+ __decorate([
1105
+ serialize()
1106
+ ], InputText.prototype, "placeholderText", null);
1107
+ __decorate([
1108
+ serialize()
1109
+ ], InputText.prototype, "deadKey", null);
1110
+ __decorate([
1111
+ serialize()
1112
+ ], InputText.prototype, "text", null);
1113
+ __decorate([
1114
+ serialize()
1115
+ ], InputText.prototype, "width", null);
1116
+ return InputText;
1117
+ }(Control));
1118
+ export { InputText };
1119
+ RegisterClass("BABYLON.GUI.InputText", InputText);
1097
1120
  //# sourceMappingURL=inputText.js.map