uicore-ts 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/.idea/misc.xml +6 -0
  2. package/.idea/modules.xml +8 -0
  3. package/.idea/uicore.iml +9 -0
  4. package/.idea/vcs.xml +6 -0
  5. package/LICENSE +21 -0
  6. package/README.md +5 -0
  7. package/compiledScripts/UIActionIndicator.d.ts +12 -0
  8. package/compiledScripts/UIActionIndicator.js +54 -0
  9. package/compiledScripts/UIActionIndicator.js.map +1 -0
  10. package/compiledScripts/UIBaseButton.d.ts +52 -0
  11. package/compiledScripts/UIBaseButton.js +268 -0
  12. package/compiledScripts/UIBaseButton.js.map +1 -0
  13. package/compiledScripts/UIButton.d.ts +54 -0
  14. package/compiledScripts/UIButton.js +247 -0
  15. package/compiledScripts/UIButton.js.map +1 -0
  16. package/compiledScripts/UIColor.d.ts +41 -0
  17. package/compiledScripts/UIColor.js +286 -0
  18. package/compiledScripts/UIColor.js.map +1 -0
  19. package/compiledScripts/UICore.d.ts +27 -0
  20. package/compiledScripts/UICore.js +105 -0
  21. package/compiledScripts/UICore.js.map +1 -0
  22. package/compiledScripts/UICoreExtensions.d.ts +60 -0
  23. package/compiledScripts/UICoreExtensions.js +527 -0
  24. package/compiledScripts/UICoreExtensions.js.map +1 -0
  25. package/compiledScripts/UIDateTimeInput.d.ts +40 -0
  26. package/compiledScripts/UIDateTimeInput.js +38 -0
  27. package/compiledScripts/UIDateTimeInput.js.map +1 -0
  28. package/compiledScripts/UIDialogView.d.ts +23 -0
  29. package/compiledScripts/UIDialogView.js +118 -0
  30. package/compiledScripts/UIDialogView.js.map +1 -0
  31. package/compiledScripts/UIImageView.d.ts +36 -0
  32. package/compiledScripts/UIImageView.js +170 -0
  33. package/compiledScripts/UIImageView.js.map +1 -0
  34. package/compiledScripts/UIKeyValueStringFilter.d.ts +21 -0
  35. package/compiledScripts/UIKeyValueStringFilter.js +98 -0
  36. package/compiledScripts/UIKeyValueStringFilter.js.map +1 -0
  37. package/compiledScripts/UIKeyValueStringSorter.d.ts +38 -0
  38. package/compiledScripts/UIKeyValueStringSorter.js +117 -0
  39. package/compiledScripts/UIKeyValueStringSorter.js.map +1 -0
  40. package/compiledScripts/UILayoutGrid.d.ts +8 -0
  41. package/compiledScripts/UILayoutGrid.js +22 -0
  42. package/compiledScripts/UILayoutGrid.js.map +1 -0
  43. package/compiledScripts/UILink.d.ts +25 -0
  44. package/compiledScripts/UILink.js +81 -0
  45. package/compiledScripts/UILink.js.map +1 -0
  46. package/compiledScripts/UILinkButton.d.ts +18 -0
  47. package/compiledScripts/UILinkButton.js +60 -0
  48. package/compiledScripts/UILinkButton.js.map +1 -0
  49. package/compiledScripts/UINativeScrollView.d.ts +20 -0
  50. package/compiledScripts/UINativeScrollView.js +121 -0
  51. package/compiledScripts/UINativeScrollView.js.map +1 -0
  52. package/compiledScripts/UIObject.d.ts +69 -0
  53. package/compiledScripts/UIObject.js +442 -0
  54. package/compiledScripts/UIObject.js.map +1 -0
  55. package/compiledScripts/UIPoint.d.ts +18 -0
  56. package/compiledScripts/UIPoint.js +68 -0
  57. package/compiledScripts/UIPoint.js.map +1 -0
  58. package/compiledScripts/UIRectangle.d.ts +61 -0
  59. package/compiledScripts/UIRectangle.js +421 -0
  60. package/compiledScripts/UIRectangle.js.map +1 -0
  61. package/compiledScripts/UIRoute.d.ts +39 -0
  62. package/compiledScripts/UIRoute.js +202 -0
  63. package/compiledScripts/UIRoute.js.map +1 -0
  64. package/compiledScripts/UIScrollView.d.ts +19 -0
  65. package/compiledScripts/UIScrollView.js +121 -0
  66. package/compiledScripts/UIScrollView.js.map +1 -0
  67. package/compiledScripts/UISlideScrollerView.d.ts +40 -0
  68. package/compiledScripts/UISlideScrollerView.js +242 -0
  69. package/compiledScripts/UISlideScrollerView.js.map +1 -0
  70. package/compiledScripts/UIStringFilter.d.ts +26 -0
  71. package/compiledScripts/UIStringFilter.js +107 -0
  72. package/compiledScripts/UIStringFilter.js.map +1 -0
  73. package/compiledScripts/UITableView.d.ts +61 -0
  74. package/compiledScripts/UITableView.js +383 -0
  75. package/compiledScripts/UITableView.js.map +1 -0
  76. package/compiledScripts/UITextArea.d.ts +7 -0
  77. package/compiledScripts/UITextArea.js +27 -0
  78. package/compiledScripts/UITextArea.js.map +1 -0
  79. package/compiledScripts/UITextField.d.ts +44 -0
  80. package/compiledScripts/UITextField.js +83 -0
  81. package/compiledScripts/UITextField.js.map +1 -0
  82. package/compiledScripts/UITextView.d.ts +89 -0
  83. package/compiledScripts/UITextView.js +237 -0
  84. package/compiledScripts/UITextView.js.map +1 -0
  85. package/compiledScripts/UITimer.d.ts +13 -0
  86. package/compiledScripts/UITimer.js +45 -0
  87. package/compiledScripts/UITimer.js.map +1 -0
  88. package/compiledScripts/UIView.d.ts +330 -0
  89. package/compiledScripts/UIView.js +1533 -0
  90. package/compiledScripts/UIView.js.map +1 -0
  91. package/compiledScripts/UIViewController.d.ts +38 -0
  92. package/compiledScripts/UIViewController.js +153 -0
  93. package/compiledScripts/UIViewController.js.map +1 -0
  94. package/compiledScripts/index.d.ts +29 -0
  95. package/compiledScripts/index.js +46 -0
  96. package/compiledScripts/index.js.map +1 -0
  97. package/package.json +36 -0
  98. package/scripts/UIActionIndicator.ts +139 -0
  99. package/scripts/UIBaseButton.ts +563 -0
  100. package/scripts/UIButton.ts +552 -0
  101. package/scripts/UIColor.ts +427 -0
  102. package/scripts/UICore.ts +223 -0
  103. package/scripts/UICoreExtensions.ts +949 -0
  104. package/scripts/UIDateTimeInput.ts +109 -0
  105. package/scripts/UIDialogView.ts +297 -0
  106. package/scripts/UIImageView.ts +366 -0
  107. package/scripts/UIKeyValueStringFilter.ts +260 -0
  108. package/scripts/UIKeyValueStringSorter.ts +337 -0
  109. package/scripts/UILayoutGrid.ts +83 -0
  110. package/scripts/UILink.ts +292 -0
  111. package/scripts/UILinkButton.ts +238 -0
  112. package/scripts/UINativeScrollView.ts +254 -0
  113. package/scripts/UIObject.ts +827 -0
  114. package/scripts/UIPoint.ts +123 -0
  115. package/scripts/UIRectangle.ts +730 -0
  116. package/scripts/UIRoute.ts +391 -0
  117. package/scripts/UIScrollView.ts +290 -0
  118. package/scripts/UISlideScrollerView.ts +530 -0
  119. package/scripts/UIStringFilter.ts +293 -0
  120. package/scripts/UITableView.ts +790 -0
  121. package/scripts/UITextArea.ts +91 -0
  122. package/scripts/UITextField.ts +218 -0
  123. package/scripts/UITextView.ts +561 -0
  124. package/scripts/UITimer.ts +107 -0
  125. package/scripts/UIView.ts +2789 -0
  126. package/scripts/UIViewController.ts +304 -0
  127. package/scripts/index.ts +36 -0
  128. package/tsconfig.json +59 -0
@@ -0,0 +1,2789 @@
1
+
2
+ import { UIColor } from "./UIColor"
3
+ import { IS_FIREFOX, IS_SAFARI, UICore, UILocalizedTextObject } from "./UICore"
4
+ import { UIDialogView } from "./UIDialogView"
5
+ import { FIRST, IS, IS_DEFINED, IS_NIL, IS_NOT, nil, NO, UIObject, YES } from "./UIObject"
6
+ import { UIPoint } from "./UIPoint"
7
+ import { UIRectangle } from "./UIRectangle"
8
+ import "./UICoreExtensions"
9
+
10
+
11
+ declare module AutoLayout {
12
+
13
+
14
+ class Constraint {
15
+
16
+ [key: string]: any
17
+
18
+ }
19
+
20
+
21
+ class View {
22
+
23
+ [key: string]: any
24
+
25
+ }
26
+
27
+
28
+ class VisualFormat {
29
+
30
+ static parse(arg0: any, arg1: any): any;
31
+
32
+ [key: string]: any
33
+
34
+ }
35
+
36
+
37
+ enum Attribute {
38
+
39
+ LEFT, RIGHT, BOTTOM, TOP, CENTERX, CENTERY, WIDTH, HEIGHT, ZINDEX, VARIABLE, NOTANATTRIBUTE
40
+
41
+ }
42
+
43
+
44
+ enum Relation {
45
+
46
+ EQU, LEQ, GEQ
47
+
48
+ }
49
+
50
+
51
+ }
52
+
53
+
54
+
55
+
56
+
57
+ interface LooseObject {
58
+ [key: string]: any
59
+ }
60
+
61
+
62
+ export interface ControlEventTargetsObject {
63
+
64
+ [key: string]: Function[];
65
+
66
+ }
67
+
68
+
69
+ export interface UIViewBroadcastEvent {
70
+
71
+ name: string;
72
+ parameters: {
73
+ [key: string]: string | string[];
74
+ }
75
+
76
+ }
77
+
78
+
79
+
80
+ export type UIViewAddControlEventTargetObject<T extends typeof UIView.controlEvent> = {
81
+
82
+ [K in keyof T]: ((sender: UIView, event: Event) => void) & Partial<UIViewAddControlEventTargetObject<T>>
83
+
84
+ }
85
+
86
+
87
+
88
+
89
+
90
+ export class UIView extends UIObject {
91
+
92
+ _nativeSelectionEnabled: boolean = YES
93
+ _shouldLayout: boolean
94
+ _UITableViewRowIndex: number
95
+ _UITableViewReusabilityIdentifier: any
96
+ _UIViewIntrinsicTemporaryWidth: string
97
+ _UIViewIntrinsicTemporaryHeight: string
98
+ _enabled: boolean = YES
99
+ _frame: any
100
+ _backgroundColor: UIColor = UIColor.transparentColor
101
+
102
+ _viewHTMLElement: HTMLElement & LooseObject
103
+
104
+ _innerHTMLKey: string
105
+ _defaultInnerHTML: string
106
+ _parameters: { [x: string]: (string | UILocalizedTextObject) }
107
+
108
+ _localizedTextObject: UILocalizedTextObject = nil
109
+
110
+ _controlEventTargets: ControlEventTargetsObject = {} //{ "PointerDown": Function[]; "PointerMove": Function[]; "PointerLeave": Function[]; "PointerEnter": Function[]; "PointerUpInside": Function[]; "PointerUp": Function[]; "PointerHover": Function[]; };
111
+ _frameTransform: string
112
+ _viewControllerLayoutFunction: () => void = nil
113
+ _didLayoutSubviewsDelegateFunction: () => void
114
+ _didReceiveBroadcastEventDelegateFunction: (event: UIViewBroadcastEvent) => void
115
+ _updateLayoutFunction: any
116
+ // @ts-ignore
117
+ _constraints: any[] //AutoLayout.Constraint[];
118
+ superview: UIView
119
+ subviews: UIView[]
120
+ _styleClasses: any[]
121
+ _isHidden: boolean = NO
122
+
123
+ pausesPointerEvents: boolean = NO
124
+ stopsPointerEventPropagation: boolean = YES
125
+ _isPointerInside: boolean
126
+ _isPointerValid: boolean
127
+ _initialPointerPosition: UIPoint
128
+ _hasPointerDragged: boolean
129
+ _pointerDragThreshold = 2
130
+
131
+ ignoresTouches: boolean = NO
132
+ ignoresMouse: boolean = NO
133
+
134
+
135
+ static _UIViewIndex: number = -1
136
+ _UIViewIndex: number
137
+
138
+ static _viewsToLayout: UIView[] = []
139
+
140
+ forceIntrinsicSizeZero: boolean = NO
141
+ _touchEventTime: number
142
+
143
+ static _pageScale = 1
144
+
145
+ constructor(
146
+ elementID: string = ("UIView" +
147
+ UIView.nextIndex),
148
+ viewHTMLElement: HTMLElement & LooseObject = null,
149
+ elementType: string = null,
150
+ initViewData?: any
151
+ ) {
152
+
153
+ super()
154
+
155
+ this._class = UIView
156
+ this.superclass = UIObject
157
+
158
+ // Instance variables
159
+
160
+ UIView._UIViewIndex = UIView.nextIndex
161
+ this._UIViewIndex = UIView._UIViewIndex
162
+
163
+ this._styleClasses = []
164
+ // Object.defineProperty(this, "styleClasses", { get: this.styleClasses, set: this.setStyleClasses });
165
+ // Object.defineProperty(this, "styleClassName", { get: this.styleClassName });
166
+
167
+ this._initViewHTMLElement(elementID, viewHTMLElement, elementType)
168
+
169
+ this.subviews = []
170
+ this.superview = nil
171
+
172
+ // Object.defineProperty(this, "elementID", { get: this.elementID });
173
+
174
+ // Object.defineProperty(this, "constraints", { get: this.constraints, set: this.setConstraints });
175
+ this._constraints = []
176
+
177
+ this._updateLayoutFunction = nil
178
+
179
+ //Object.defineProperty(this, "backgroundColor", { get: this.backgroundColor, set: this.setBackgroundColor });
180
+ //this.backgroundColor = "transparent";
181
+
182
+ // Object.defineProperty(this, "alpha", { get: this.alpha, set: this.setAlpha });
183
+
184
+ // Object.defineProperty(this, "frame", { get: this.frame, set: this.setFrame });
185
+ // Object.defineProperty(this, "bounds", { get: this.bounds, set: this.setBounds });
186
+
187
+ // Object.defineProperty(this, "userInteractionEnabled", { get: this.userInteractionEnabled, set: this.setUserInteractionEnabled });
188
+
189
+ // this._controlEventTargets = {
190
+ // "PointerDown": [],
191
+ // "PointerMove": [],
192
+ // "PointerLeave": [],
193
+ // "PointerEnter": [],
194
+ // "PointerUpInside": [],
195
+ // "PointerUp": [],
196
+ // "PointerHover": []
197
+ // }
198
+
199
+ this._didLayoutSubviewsDelegateFunction = function () {
200
+ }
201
+
202
+ this._frameTransform = ""
203
+
204
+ this.initView(this.viewHTMLElement.id, this.viewHTMLElement, initViewData)
205
+
206
+ this._initViewCSSSelectorsIfNeeded()
207
+
208
+ this._loadUIEvents()
209
+
210
+
211
+ this.setNeedsLayout()
212
+
213
+
214
+ }
215
+
216
+
217
+ static get nextIndex() {
218
+
219
+ return UIView._UIViewIndex + 1
220
+
221
+ }
222
+
223
+ static get pageHeight() {
224
+
225
+ const body = document.body
226
+ const html = document.documentElement
227
+
228
+ const height = Math.max(
229
+ body.scrollHeight,
230
+ body.offsetHeight,
231
+ html.clientHeight,
232
+ html.scrollHeight,
233
+ html.offsetHeight
234
+ )
235
+
236
+ return height
237
+
238
+ }
239
+
240
+ static get pageWidth() {
241
+
242
+ const body = document.body
243
+ const html = document.documentElement
244
+
245
+ const width = Math.max(body.scrollWidth, body.offsetWidth, html.clientWidth, html.scrollWidth, html.offsetWidth)
246
+
247
+ return width
248
+
249
+ }
250
+
251
+
252
+
253
+
254
+
255
+ initView(elementID: string, viewHTMLElement: HTMLElement, initViewData?: any) {
256
+
257
+
258
+
259
+ }
260
+
261
+
262
+
263
+
264
+
265
+ centerInContainer() {
266
+ this.style.left = "50%"
267
+ this.style.top = "50%"
268
+ this.style.transform = "translateX(-50%) translateY(-50%)"
269
+ }
270
+
271
+ centerXInContainer() {
272
+ this.style.left = "50%"
273
+ this.style.transform = "translateX(-50%)"
274
+ }
275
+
276
+ centerYInContainer() {
277
+ this.style.top = "50%"
278
+ this.style.transform = "translateY(-50%)"
279
+ }
280
+
281
+
282
+
283
+ _initViewHTMLElement(elementID, viewHTMLElement, elementType = "div") {
284
+
285
+
286
+ if (!IS(elementType)) {
287
+
288
+ elementType = "div"
289
+
290
+ }
291
+
292
+ if (!IS(viewHTMLElement)) {
293
+
294
+ this._viewHTMLElement = this.createElement(elementID, elementType)
295
+
296
+ this.style.position = "absolute"
297
+ this.style.margin = "0"
298
+
299
+ }
300
+ else {
301
+
302
+ this._viewHTMLElement = viewHTMLElement
303
+
304
+ }
305
+
306
+ if (IS(elementID)) {
307
+
308
+
309
+ this.viewHTMLElement.id = elementID
310
+
311
+
312
+ }
313
+
314
+
315
+ this.viewHTMLElement.obeyAutolayout = YES
316
+
317
+ this.viewHTMLElement.UIView = this
318
+
319
+ this.addStyleClass(this.styleClassName)
320
+
321
+ }
322
+
323
+
324
+
325
+ set nativeSelectionEnabled(selectable: boolean) {
326
+ this._nativeSelectionEnabled = selectable
327
+ if (!selectable) {
328
+ this.style.cssText = this.style.cssText +
329
+ " -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;"
330
+ }
331
+ else {
332
+ this.style.cssText = this.style.cssText +
333
+ " -webkit-touch-callout: text; -webkit-user-select: text; -khtml-user-select: text; -moz-user-select: text; -ms-user-select: text; user-select: text;"
334
+ }
335
+ }
336
+
337
+
338
+ get nativeSelectionEnabled() {
339
+ return this._nativeSelectionEnabled
340
+ }
341
+
342
+
343
+
344
+ get styleClassName() {
345
+
346
+ const result = "UICore_UIView_" + this.class.name
347
+
348
+ return result
349
+
350
+ }
351
+
352
+ _initViewCSSSelectorsIfNeeded() {
353
+
354
+ if (!this.class._areViewCSSSelectorsInitialized) {
355
+
356
+ this.initViewStyleSelectors()
357
+
358
+ this.class._areViewCSSSelectorsInitialized = YES
359
+
360
+ }
361
+
362
+ }
363
+
364
+ initViewStyleSelectors() {
365
+
366
+ // Override this in a subclass
367
+
368
+ }
369
+
370
+ initStyleSelector(selector, style) {
371
+
372
+ const styleRules = UIView.getStyleRules(selector)
373
+
374
+ if (!styleRules) {
375
+
376
+ UIView.createStyleSelector(selector, style)
377
+
378
+ }
379
+
380
+ }
381
+
382
+
383
+ createElement(elementID, elementType) {
384
+ var result = document.getElementById(elementID)
385
+ if (!result) {
386
+ result = document.createElement(elementType)
387
+ }
388
+ return result
389
+ }
390
+
391
+ public get viewHTMLElement() {
392
+ return this._viewHTMLElement
393
+ }
394
+
395
+ public get elementID() {
396
+
397
+ return this.viewHTMLElement.id
398
+
399
+ }
400
+
401
+
402
+ setInnerHTML(key: string, defaultString: string, parameters?: { [x: string]: string | UILocalizedTextObject }) {
403
+
404
+ this._innerHTMLKey = key
405
+ this._defaultInnerHTML = defaultString
406
+ this._parameters = parameters
407
+
408
+ const languageName = UICore.languageService.currentLanguageKey
409
+ const result = UICore.languageService.stringForKey(key, languageName, defaultString, parameters)
410
+
411
+ this.innerHTML = result
412
+
413
+ }
414
+
415
+
416
+ _setInnerHTMLFromKeyIfPossible() {
417
+
418
+ if (this._innerHTMLKey && this._defaultInnerHTML) {
419
+
420
+ this.setInnerHTML(this._innerHTMLKey, this._defaultInnerHTML, this._parameters)
421
+
422
+ }
423
+
424
+ }
425
+
426
+ _setInnerHTMLFromLocalizedTextObjectIfPossible() {
427
+
428
+ if (IS(this._localizedTextObject)) {
429
+
430
+ this.innerHTML = UICore.languageService.stringForCurrentLanguage(this._localizedTextObject)
431
+
432
+ }
433
+
434
+ }
435
+
436
+
437
+ get localizedTextObject() {
438
+
439
+ return this._localizedTextObject
440
+
441
+ }
442
+
443
+ set localizedTextObject(localizedTextObject: UILocalizedTextObject) {
444
+
445
+ this._localizedTextObject = localizedTextObject
446
+
447
+ this._setInnerHTMLFromLocalizedTextObjectIfPossible()
448
+
449
+ }
450
+
451
+
452
+ get innerHTML() {
453
+ return this.viewHTMLElement.innerHTML
454
+ }
455
+
456
+
457
+ set innerHTML(innerHTML) {
458
+
459
+ if (this.innerHTML != innerHTML) {
460
+
461
+ this.viewHTMLElement.innerHTML = FIRST(innerHTML, "")
462
+
463
+ }
464
+
465
+ }
466
+
467
+
468
+
469
+ set hoverText(hoverText: string) {
470
+ this.viewHTMLElement.setAttribute("title", hoverText)
471
+ }
472
+
473
+ get hoverText() {
474
+ return this.viewHTMLElement.getAttribute("title")
475
+ }
476
+
477
+
478
+ get scrollSize() {
479
+
480
+ const result = new UIRectangle(0, 0, this.viewHTMLElement.scrollHeight, this.viewHTMLElement.scrollWidth)
481
+
482
+ return result
483
+
484
+ }
485
+
486
+
487
+
488
+ get dialogView(): UIDialogView {
489
+ if (!IS(this.superview)) {
490
+ return nil
491
+ }
492
+ if (!(this instanceof UIDialogView)) {
493
+ return this.superview.dialogView
494
+ }
495
+ return this
496
+ }
497
+
498
+
499
+ get rootView(): UIView {
500
+ if (IS(this.superview)) {
501
+ return this.superview.rootView
502
+ }
503
+ return this
504
+ }
505
+
506
+
507
+ public set enabled(enabled: boolean) {
508
+ this._enabled = enabled
509
+ this.updateContentForCurrentEnabledState()
510
+ }
511
+
512
+ public get enabled(): boolean {
513
+ return this._enabled
514
+ }
515
+
516
+ updateContentForCurrentEnabledState() {
517
+ this.hidden = !this.enabled
518
+ this.userInteractionEnabled = this.enabled
519
+ }
520
+
521
+
522
+
523
+
524
+ public get tabIndex(): number {
525
+
526
+ return Number(this.viewHTMLElement.getAttribute("tabindex"))
527
+
528
+ }
529
+
530
+
531
+ public set tabIndex(index: number) {
532
+
533
+ this.viewHTMLElement.setAttribute("tabindex", "" + index)
534
+
535
+ }
536
+
537
+
538
+
539
+
540
+
541
+ get styleClasses() {
542
+
543
+ return this._styleClasses
544
+
545
+ }
546
+
547
+ set styleClasses(styleClasses) {
548
+
549
+ this._styleClasses = styleClasses
550
+
551
+ }
552
+
553
+ hasStyleClass(styleClass) {
554
+
555
+ // This is for performance reasons
556
+ if (!IS(styleClass)) {
557
+ return NO
558
+ }
559
+
560
+ const index = this.styleClasses.indexOf(styleClass)
561
+ if (index > -1) {
562
+ return YES
563
+ }
564
+ return NO
565
+
566
+ }
567
+
568
+
569
+
570
+ addStyleClass(styleClass: string) {
571
+
572
+ if (!IS(styleClass)) {
573
+ return
574
+ }
575
+
576
+ if (!this.hasStyleClass(styleClass)) {
577
+ this._styleClasses.push(styleClass)
578
+ }
579
+
580
+ }
581
+
582
+ removeStyleClass(styleClass: string) {
583
+
584
+ // This is for performance reasons
585
+ if (!IS(styleClass)) {
586
+ return
587
+ }
588
+
589
+ const index = this.styleClasses.indexOf(styleClass)
590
+ if (index > -1) {
591
+
592
+ this.styleClasses.splice(index, 1)
593
+
594
+ }
595
+
596
+
597
+ }
598
+
599
+
600
+
601
+ static findViewWithElementID(elementID: string): UIView {
602
+ const viewHTMLElement = document.getElementById(elementID)
603
+ if (IS_NOT(viewHTMLElement)) {
604
+ return nil
605
+ }
606
+ // @ts-ignore
607
+ const result = viewHTMLElement.UIView
608
+ return result
609
+ }
610
+
611
+
612
+
613
+
614
+ static createStyleSelector(selector, style) {
615
+
616
+ return
617
+
618
+ // @ts-ignore
619
+ if (!document.styleSheets) {
620
+ return
621
+ }
622
+ if (document.getElementsByTagName("head").length == 0) {
623
+ return
624
+ }
625
+
626
+ var styleSheet
627
+ var mediaType
628
+
629
+ if (document.styleSheets.length > 0) {
630
+ for (var i = 0, l: any = document.styleSheets.length; i < l; i++) {
631
+ if (document.styleSheets[i].disabled) {
632
+ continue
633
+ }
634
+ const media = document.styleSheets[i].media
635
+ mediaType = typeof media
636
+
637
+ if (mediaType === "string") {
638
+ if (media as any === "" || ((media as any).indexOf("screen") !== -1)) {
639
+ styleSheet = document.styleSheets[i]
640
+ }
641
+ }
642
+ else if (mediaType == "object") {
643
+ if (media.mediaText === "" || (media.mediaText.indexOf("screen") !== -1)) {
644
+ styleSheet = document.styleSheets[i]
645
+ }
646
+ }
647
+
648
+ if (typeof styleSheet !== "undefined") {
649
+ break
650
+ }
651
+ }
652
+ }
653
+
654
+ if (typeof styleSheet === "undefined") {
655
+ const styleSheetElement = document.createElement("style")
656
+ styleSheetElement.type = "text/css"
657
+ document.getElementsByTagName("head")[0].appendChild(styleSheetElement)
658
+
659
+ for (i = 0; i < document.styleSheets.length; i++) {
660
+ if (document.styleSheets[i].disabled) {
661
+ continue
662
+ }
663
+ styleSheet = document.styleSheets[i]
664
+ }
665
+
666
+ mediaType = typeof styleSheet.media
667
+ }
668
+
669
+ if (mediaType === "string") {
670
+ for (var i = 0, l = styleSheet.rules.length; i < l; i++) {
671
+ if (styleSheet.rules[i].selectorText && styleSheet.rules[i].selectorText.toLowerCase() ==
672
+ selector.toLowerCase()) {
673
+ styleSheet.rules[i].style.cssText = style
674
+ return
675
+ }
676
+ }
677
+ styleSheet.addRule(selector, style)
678
+ }
679
+ else if (mediaType === "object") {
680
+
681
+ var styleSheetLength = 0
682
+
683
+ try {
684
+
685
+ styleSheetLength = (styleSheet.cssRules) ? styleSheet.cssRules.length : 0
686
+
687
+ } catch (error) {
688
+
689
+ }
690
+
691
+
692
+ for (var i = 0; i < styleSheetLength; i++) {
693
+ if (styleSheet.cssRules[i].selectorText && styleSheet.cssRules[i].selectorText.toLowerCase() ==
694
+ selector.toLowerCase()) {
695
+ styleSheet.cssRules[i].style.cssText = style
696
+ return
697
+ }
698
+ }
699
+ styleSheet.insertRule(selector + "{" + style + "}", styleSheetLength)
700
+ }
701
+ }
702
+
703
+ static getStyleRules(selector) {
704
+ var selector = selector.toLowerCase()
705
+ for (var i = 0; i < document.styleSheets.length; i++) {
706
+ const styleSheet = document.styleSheets[i] as any
707
+ var styleRules
708
+
709
+ try {
710
+
711
+ styleRules = styleSheet.cssRules ? styleSheet.cssRules : styleSheet.rules
712
+
713
+ } catch (error) {
714
+
715
+ }
716
+
717
+ return styleRules
718
+ }
719
+ }
720
+
721
+
722
+
723
+ get style() {
724
+ return this.viewHTMLElement.style
725
+ }
726
+
727
+ get computedStyle() {
728
+ return getComputedStyle(this.viewHTMLElement)
729
+ }
730
+
731
+ public get hidden(): boolean {
732
+ return this._isHidden
733
+ }
734
+
735
+
736
+ public set hidden(v: boolean) {
737
+
738
+ this._isHidden = v
739
+
740
+ if (this._isHidden) {
741
+ this.style.visibility = "hidden"
742
+ }
743
+ else {
744
+ this.style.visibility = "visible"
745
+ }
746
+
747
+
748
+ }
749
+
750
+ static set pageScale(scale: number) {
751
+
752
+ UIView._pageScale = scale
753
+
754
+ const zoom = scale
755
+ const width = 100 / zoom
756
+ const viewHTMLElement = UICore.main.rootViewController.view.viewHTMLElement
757
+ viewHTMLElement.style.transformOrigin = "left top"
758
+ viewHTMLElement.style.transform = "scale(" + zoom + ")"
759
+ viewHTMLElement.style.width = width + "%"
760
+
761
+ }
762
+
763
+ static get pageScale() {
764
+
765
+ return UIView._pageScale
766
+
767
+ }
768
+
769
+
770
+
771
+
772
+
773
+ calculateAndSetViewFrame() {
774
+
775
+ // Use this method to calculate the frame for the view itself
776
+
777
+ // This can be used when adding subviews to existing views like buttons
778
+
779
+ }
780
+
781
+
782
+
783
+
784
+
785
+ public get frame(): UIRectangle {
786
+
787
+ // var result = new UIRectangle(1 * this.viewHTMLElement.offsetLeft, 1 * this.viewHTMLElement.offsetTop, 1 * this.viewHTMLElement.offsetHeight, 1 * this.viewHTMLElement.offsetWidth);
788
+
789
+ // result.zIndex = 1 * this.style.zIndex;
790
+
791
+ var result = this._frame
792
+
793
+ if (!result) {
794
+
795
+ result = new UIRectangle(1 * this.viewHTMLElement.offsetLeft, 1 * this.viewHTMLElement.offsetTop, 1 *
796
+ this.viewHTMLElement.offsetHeight, 1 * this.viewHTMLElement.offsetWidth)
797
+ result.zIndex = 0
798
+
799
+ }
800
+
801
+ return result.copy()
802
+
803
+ }
804
+
805
+ public set frame(rectangle: UIRectangle) {
806
+
807
+ if (IS(rectangle)) {
808
+ this.setFrame(rectangle)
809
+ }
810
+
811
+ }
812
+
813
+ setFrame(rectangle, zIndex = 0, performUncheckedLayout = NO) {
814
+
815
+
816
+ const frame = this._frame || new UIRectangle(nil, nil, nil, nil)
817
+
818
+ if (zIndex != undefined) {
819
+ rectangle.zIndex = zIndex
820
+ }
821
+ this._frame = rectangle
822
+
823
+ // This is useless because frames are copied
824
+ // frame.didChange = function () {
825
+ // // Do nothing
826
+ // }
827
+ // rectangle.didChange = function () {
828
+ // this.frame = rectangle;
829
+ // }.bind(this);
830
+
831
+ if (frame && frame.isEqualTo(rectangle) && !performUncheckedLayout) {
832
+ return
833
+ }
834
+
835
+
836
+ UIView._setAbsoluteSizeAndPosition(
837
+ this.viewHTMLElement,
838
+ rectangle.topLeft.x,
839
+ rectangle.topLeft.y,
840
+ rectangle.width,
841
+ rectangle.height,
842
+ rectangle.zIndex
843
+ )
844
+
845
+
846
+ if (frame.height != rectangle.height || frame.width != rectangle.width || performUncheckedLayout) {
847
+
848
+ this.setNeedsLayout()
849
+
850
+ this.boundsDidChange()
851
+
852
+ //this.layoutSubviews();
853
+
854
+ }
855
+
856
+
857
+
858
+ }
859
+
860
+
861
+
862
+ get bounds() {
863
+
864
+ var result: UIRectangle
865
+
866
+ // if (IS_NOT(this._frame) && this.style.height == "" && this.style.width == "" && this.style.left == "" && this.style.right == "" && this.style.bottom == "" && this.style.top == "") {
867
+
868
+ // result = new UIRectangle(0, 0, 0, 0)
869
+
870
+ // }
871
+ // else
872
+ if (IS_NOT(this._frame)) {
873
+
874
+ result = new UIRectangle(0, 0, 1 * this.viewHTMLElement.offsetHeight, 1 * this.viewHTMLElement.offsetWidth)
875
+
876
+ }
877
+ else {
878
+
879
+ result = this.frame.copy()
880
+
881
+ result.x = 0
882
+ result.y = 0
883
+
884
+ }
885
+
886
+ return result
887
+
888
+ }
889
+
890
+ set bounds(rectangle) {
891
+
892
+ const frame = this.frame
893
+
894
+ this.frame = new UIRectangle(frame.topLeft.x, frame.topLeft.y, rectangle.height, rectangle.width)
895
+
896
+ }
897
+
898
+
899
+ boundsDidChange() {
900
+
901
+
902
+
903
+ }
904
+
905
+
906
+ setPosition(
907
+ left: number | string = nil,
908
+ right: number | string = nil,
909
+ bottom: number | string = nil,
910
+ top: number | string = nil,
911
+ height: number | string = nil,
912
+ width: number | string = nil
913
+ ) {
914
+
915
+ const previousBounds = this.bounds
916
+
917
+ this.setStyleProperty("left", left)
918
+ this.setStyleProperty("right", right)
919
+ this.setStyleProperty("bottom", bottom)
920
+ this.setStyleProperty("top", top)
921
+ this.setStyleProperty("height", height)
922
+ this.setStyleProperty("width", width)
923
+
924
+ const bounds = this.bounds
925
+ if (bounds.height != previousBounds.height || bounds.width != previousBounds.width) {
926
+ this.setNeedsLayout()
927
+ this.boundsDidChange()
928
+ }
929
+
930
+ }
931
+
932
+ setSizes(height?: number | string, width?: number | string) {
933
+
934
+ const previousBounds = this.bounds
935
+
936
+ this.setStyleProperty("height", height)
937
+ this.setStyleProperty("width", width)
938
+
939
+ const bounds = this.bounds
940
+ if (bounds.height != previousBounds.height || bounds.width != previousBounds.width) {
941
+ this.setNeedsLayout()
942
+ this.boundsDidChange()
943
+ }
944
+
945
+ }
946
+
947
+ setMinSizes(height?: number | string, width?: number | string) {
948
+
949
+ const previousBounds = this.bounds
950
+
951
+ this.setStyleProperty("minHeight", height)
952
+ this.setStyleProperty("minWidth", width)
953
+
954
+ const bounds = this.bounds
955
+ if (bounds.height != previousBounds.height || bounds.width != previousBounds.width) {
956
+ this.setNeedsLayout()
957
+ this.boundsDidChange()
958
+ }
959
+
960
+ }
961
+
962
+ setMaxSizes(height?: number | string, width?: number | string) {
963
+
964
+ const previousBounds = this.bounds
965
+
966
+ this.setStyleProperty("maxHeight", height)
967
+ this.setStyleProperty("maxWidth", width)
968
+
969
+ const bounds = this.bounds
970
+ if (bounds.height != previousBounds.height || bounds.width != previousBounds.width) {
971
+ this.setNeedsLayout()
972
+ this.boundsDidChange()
973
+ }
974
+
975
+ }
976
+
977
+ setMargin(margin?: number | string) {
978
+
979
+ const previousBounds = this.bounds
980
+
981
+ this.setStyleProperty("margin", margin)
982
+
983
+ const bounds = this.bounds
984
+ if (bounds.height != previousBounds.height || bounds.width != previousBounds.width) {
985
+ this.setNeedsLayout()
986
+ this.boundsDidChange()
987
+ }
988
+
989
+ }
990
+
991
+ setMargins(left?: number | string, right?: number | string, bottom?: number | string, top?: number | string) {
992
+
993
+ const previousBounds = this.bounds
994
+
995
+ this.setStyleProperty("marginLeft", left)
996
+ this.setStyleProperty("marginRight", right)
997
+ this.setStyleProperty("marginBottom", bottom)
998
+ this.setStyleProperty("marginTop", top)
999
+
1000
+ const bounds = this.bounds
1001
+ if (bounds.height != previousBounds.height || bounds.width != previousBounds.width) {
1002
+ this.setNeedsLayout()
1003
+ this.boundsDidChange()
1004
+ }
1005
+
1006
+ }
1007
+
1008
+ setPadding(padding?: number | string) {
1009
+
1010
+ const previousBounds = this.bounds
1011
+
1012
+ this.setStyleProperty("padding", padding)
1013
+
1014
+ const bounds = this.bounds
1015
+ if (bounds.height != previousBounds.height || bounds.width != previousBounds.width) {
1016
+ this.setNeedsLayout()
1017
+ this.boundsDidChange()
1018
+ }
1019
+
1020
+ }
1021
+
1022
+ setPaddings(left?: number | string, right?: number | string, bottom?: number | string, top?: number | string) {
1023
+
1024
+ const previousBounds = this.bounds
1025
+
1026
+ this.setStyleProperty("paddingLeft", left)
1027
+ this.setStyleProperty("paddingRight", right)
1028
+ this.setStyleProperty("paddingBottom", bottom)
1029
+ this.setStyleProperty("paddingTop", top)
1030
+
1031
+ const bounds = this.bounds
1032
+ if (bounds.height != previousBounds.height || bounds.width != previousBounds.width) {
1033
+ this.setNeedsLayout()
1034
+ this.boundsDidChange()
1035
+ }
1036
+
1037
+ }
1038
+
1039
+
1040
+
1041
+
1042
+
1043
+ setBorder(
1044
+ radius: number | string = nil,
1045
+ width: number | string = 1,
1046
+ color: UIColor = UIColor.blackColor,
1047
+ style: string = "solid"
1048
+ ) {
1049
+
1050
+ this.setStyleProperty("borderStyle", style)
1051
+
1052
+ this.setStyleProperty("borderRadius", radius)
1053
+
1054
+ this.setStyleProperty("borderColor", color.stringValue)
1055
+
1056
+ this.setStyleProperty("borderWidth", width)
1057
+
1058
+ }
1059
+
1060
+
1061
+
1062
+
1063
+
1064
+ setStyleProperty(propertyName: string, value?: number | string) {
1065
+
1066
+
1067
+ try {
1068
+
1069
+ if (IS_NIL(value)) {
1070
+ return
1071
+ }
1072
+ if (IS_DEFINED(value) && (value as Number).isANumber) {
1073
+ value = "" + (value as number).integerValue + "px"
1074
+ }
1075
+ this.style[propertyName] = value
1076
+
1077
+ } catch (exception) {
1078
+
1079
+ console.log(exception)
1080
+
1081
+ }
1082
+
1083
+
1084
+ }
1085
+
1086
+
1087
+
1088
+ get userInteractionEnabled() {
1089
+
1090
+ const result = (this.style.pointerEvents != "none")
1091
+
1092
+ return result
1093
+
1094
+ }
1095
+
1096
+ set userInteractionEnabled(userInteractionEnabled) {
1097
+
1098
+ if (userInteractionEnabled) {
1099
+
1100
+ this.style.pointerEvents = ""
1101
+
1102
+ }
1103
+ else {
1104
+
1105
+ this.style.pointerEvents = "none"
1106
+
1107
+ }
1108
+
1109
+ }
1110
+
1111
+
1112
+
1113
+ get backgroundColor() {
1114
+ return this._backgroundColor
1115
+ }
1116
+
1117
+ set backgroundColor(backgroundColor: UIColor) {
1118
+
1119
+ this._backgroundColor = backgroundColor
1120
+
1121
+ this.style.backgroundColor = backgroundColor.stringValue
1122
+
1123
+ }
1124
+
1125
+
1126
+
1127
+ get alpha() {
1128
+ return 1 * (this.style.opacity as any)
1129
+ }
1130
+
1131
+ set alpha(alpha) {
1132
+ this.style.opacity = "" + alpha
1133
+ }
1134
+
1135
+
1136
+
1137
+
1138
+
1139
+ static animateViewOrViewsWithDurationDelayAndFunction(
1140
+ viewOrViews: UIView | HTMLElement | UIView[] | HTMLElement[],
1141
+ duration: number,
1142
+ delay: number,
1143
+ timingStyle = "cubic-bezier(0.25,0.1,0.25,1)",
1144
+ transformFunction: Function,
1145
+ transitioncompletionFunction: Function
1146
+ ) {
1147
+
1148
+
1149
+ function callTransitioncompletionFunction() {
1150
+
1151
+ (transitioncompletionFunction || nil)();
1152
+
1153
+ (viewOrViews as UIView[]).forEach(function (view, index, array) {
1154
+
1155
+ view.animationDidFinish()
1156
+
1157
+ })
1158
+
1159
+ }
1160
+
1161
+
1162
+ if (IS_FIREFOX) {
1163
+
1164
+ // Firefox does not fire the transition completion event properly
1165
+ new UIObject().performFunctionWithDelay(delay + duration, callTransitioncompletionFunction)
1166
+
1167
+
1168
+
1169
+ }
1170
+
1171
+
1172
+ if (!(viewOrViews instanceof Array)) {
1173
+ viewOrViews = [viewOrViews] as any
1174
+ }
1175
+
1176
+ const transitionStyles = []
1177
+ const transitionDurations = []
1178
+ const transitionDelays = []
1179
+ const transitionTimings = []
1180
+
1181
+ for (var i = 0; i < (viewOrViews as any).length; i++) {
1182
+
1183
+ var view = viewOrViews[i]
1184
+
1185
+ if (view.viewHTMLElement) {
1186
+
1187
+ view = view.viewHTMLElement
1188
+
1189
+ }
1190
+
1191
+ view.addEventListener("transitionend", transitionDidFinish, true)
1192
+
1193
+ transitionStyles.push(view.style.transition)
1194
+ transitionDurations.push(view.style.transitionDuration)
1195
+ transitionDelays.push(view.style.transitionDelay)
1196
+ transitionTimings.push(view.style.transitionTimingFunction)
1197
+
1198
+ view.style.transition = "all"
1199
+ view.style.transitionDuration = "" + duration + "s"
1200
+ view.style.transitionDelay = "" + delay + "s"
1201
+ view.style.transitionTimingFunction = timingStyle
1202
+
1203
+ }
1204
+
1205
+
1206
+
1207
+ transformFunction()
1208
+
1209
+
1210
+ const transitionObject = {
1211
+
1212
+ "finishImmediately": finishTransitionImmediately,
1213
+ "didFinish": transitionDidFinishManually,
1214
+ "views": viewOrViews,
1215
+ "registrationTime": Date.now()
1216
+
1217
+ }
1218
+
1219
+ function finishTransitionImmediately() {
1220
+ for (var i = 0; i < (viewOrViews as any).length; i++) {
1221
+ var view = viewOrViews[i]
1222
+ if (view.viewHTMLElement) {
1223
+ view = view.viewHTMLElement
1224
+ }
1225
+ view.style.transition = "all"
1226
+ view.style.transitionDuration = "" + duration + "s"
1227
+ view.style.transitionDelay = "" + delay + "s"
1228
+ view.style.transition = transitionStyles[i]
1229
+ view.style.transitionDuration = transitionDurations[i]
1230
+ view.style.transitionDelay = transitionDelays[i]
1231
+ view.style.transitionTimingFunction = transitionTimings[i]
1232
+ }
1233
+ }
1234
+
1235
+ function transitionDidFinish(event) {
1236
+ var view = event.srcElement
1237
+ if (!view) {
1238
+ return
1239
+ }
1240
+ if (view.viewHTMLElement) {
1241
+ view = view.viewHTMLElement
1242
+ }
1243
+ view.style.transition = transitionStyles[i]
1244
+ view.style.transitionDuration = transitionDurations[i]
1245
+ view.style.transitionDelay = transitionDelays[i]
1246
+ view.style.transitionTimingFunction = transitionTimings[i]
1247
+
1248
+ callTransitioncompletionFunction()
1249
+
1250
+ view.removeEventListener("transitionend", transitionDidFinish, true)
1251
+
1252
+ }
1253
+
1254
+ function transitionDidFinishManually() {
1255
+ for (var i = 0; i < (viewOrViews as any).length; i++) {
1256
+
1257
+ var view = viewOrViews[i]
1258
+
1259
+ if (view.viewHTMLElement) {
1260
+ view = view.viewHTMLElement
1261
+ }
1262
+
1263
+ view.style.transition = transitionStyles[i]
1264
+ view.style.transitionDuration = transitionDurations[i]
1265
+ view.style.transitionDelay = transitionDelays[i]
1266
+ view.style.transitionTimingFunction = transitionTimings[i]
1267
+
1268
+ view.removeEventListener("transitionend", transitionDidFinish, true)
1269
+
1270
+ }
1271
+
1272
+
1273
+
1274
+ }
1275
+
1276
+ return transitionObject
1277
+
1278
+ }
1279
+
1280
+
1281
+
1282
+
1283
+
1284
+ animationDidFinish() {
1285
+
1286
+
1287
+
1288
+ }
1289
+
1290
+
1291
+
1292
+
1293
+
1294
+ static _transformAttribute = (("transform" in document.documentElement.style) ? "transform" : undefined) ||
1295
+ (("-webkit-transform" in document.documentElement.style) ? "-webkit-transform" : "undefined") ||
1296
+ (("-moz-transform" in document.documentElement.style) ? "-moz-transform" : "undefined") ||
1297
+ (("-ms-transform" in document.documentElement.style) ? "-ms-transform" : "undefined") ||
1298
+ (("-o-transform" in document.documentElement.style) ? "-o-transform" : "undefined")
1299
+
1300
+ static _setAbsoluteSizeAndPosition(element, left, top, width, height, zIndex = 0) {
1301
+
1302
+ // if (!UIView._transformAttribute) {
1303
+
1304
+ // UIView._transformAttribute = (('transform' in document.documentElement.style) ? 'transform' : undefined);
1305
+ // UIView._transformAttribute = UIView._transformAttribute || (('-webkit-transform' in document.documentElement.style) ? '-webkit-transform' : 'undefined');
1306
+ // UIView._transformAttribute = UIView._transformAttribute || (('-moz-transform' in document.documentElement.style) ? '-moz-transform' : 'undefined');
1307
+ // UIView._transformAttribute = UIView._transformAttribute || (('-ms-transform' in document.documentElement.style) ? '-ms-transform' : 'undefined');
1308
+ // UIView._transformAttribute = UIView._transformAttribute || (('-o-transform' in document.documentElement.style) ? '-o-transform' : 'undefined');
1309
+
1310
+ // }
1311
+
1312
+ if (!IS(element) || !element.obeyAutolayout && !element.getAttribute("obeyAutolayout")) {
1313
+ return
1314
+ }
1315
+
1316
+ if (element.id == "mainView") {
1317
+
1318
+
1319
+ var asd = 1
1320
+
1321
+ }
1322
+
1323
+ if (IS(height)) {
1324
+ height = height.integerValue + "px"
1325
+ }
1326
+
1327
+ if (IS(width)) {
1328
+ width = width.integerValue + "px"
1329
+ }
1330
+
1331
+ var str = element.style.cssText
1332
+
1333
+ const frameTransform = UIView._transformAttribute + ": translate3d(" + (1 * left).integerValue + "px, " +
1334
+ (1 * top).integerValue + "px, " + zIndex.integerValue + "px)"
1335
+
1336
+ if (element.UIView) {
1337
+ str = str + frameTransform + ";"
1338
+ }
1339
+ else {
1340
+ element.UIView._frameTransform = frameTransform
1341
+ }
1342
+
1343
+ if (height == nil) {
1344
+ str = str + " height: unset;"
1345
+ }
1346
+ else {
1347
+ str = str + " height:" + height + ";"
1348
+ }
1349
+
1350
+ if (width == nil) {
1351
+ str = str + " width: unset;"
1352
+ }
1353
+ else {
1354
+ str = str + " width:" + width + ";"
1355
+ }
1356
+
1357
+ if (element.id == "mainView") {
1358
+
1359
+
1360
+ var asd = 1
1361
+
1362
+ }
1363
+
1364
+ element.style.cssText = element.style.cssText + str
1365
+
1366
+ }
1367
+
1368
+
1369
+
1370
+ static performAutoLayout(parentElement, visualFormatArray, constraintsArray) {
1371
+
1372
+
1373
+ const view = new AutoLayout.View()
1374
+
1375
+ if (IS(visualFormatArray) && IS(visualFormatArray.length)) {
1376
+ view.addConstraints(AutoLayout.VisualFormat.parse(visualFormatArray, { extended: true }))
1377
+ }
1378
+
1379
+ if (IS(constraintsArray) && IS(constraintsArray.length)) {
1380
+ view.addConstraints(constraintsArray)
1381
+ }
1382
+
1383
+ const elements = {}
1384
+ for (var key in view.subViews) {
1385
+
1386
+ if (!view.subViews.hasOwnProperty(key)) {
1387
+ continue
1388
+ }
1389
+
1390
+ var element = nil
1391
+
1392
+ try {
1393
+
1394
+ element = parentElement.querySelector("#" + key)
1395
+
1396
+ } catch (error) {
1397
+
1398
+ //console.log("Error occurred " + error);
1399
+
1400
+ }
1401
+
1402
+ if (element && !element.obeyAutolayout && !element.getAttribute("obeyAutolayout")) {
1403
+
1404
+
1405
+
1406
+ }
1407
+ else if (element) {
1408
+
1409
+ element.className += element.className ? " abs" : "abs"
1410
+ elements[key] = element
1411
+
1412
+ }
1413
+
1414
+ }
1415
+
1416
+ var parentUIView = nil
1417
+
1418
+ if (parentElement.UIView) {
1419
+
1420
+ parentUIView = parentElement.UIView
1421
+
1422
+ }
1423
+
1424
+ const updateLayout = function () {
1425
+ view.setSize(
1426
+ parentElement ? parentElement.clientWidth : window.innerWidth,
1427
+ parentElement ? parentElement.clientHeight : window.innerHeight
1428
+ )
1429
+ for (key in view.subViews) {
1430
+
1431
+ if (!view.subViews.hasOwnProperty(key)) {
1432
+ continue
1433
+ }
1434
+
1435
+ const subView = view.subViews[key]
1436
+
1437
+ if (elements[key]) {
1438
+ UIView._setAbsoluteSizeAndPosition(
1439
+ elements[key],
1440
+ subView.left,
1441
+ subView.top,
1442
+ subView.width,
1443
+ subView.height
1444
+ )
1445
+ }
1446
+ }
1447
+
1448
+ parentUIView.didLayoutSubviews()
1449
+
1450
+ }
1451
+
1452
+ updateLayout()
1453
+ return updateLayout
1454
+
1455
+ }
1456
+
1457
+
1458
+ static runFunctionBeforeNextFrame(step: () => void) {
1459
+
1460
+ if (IS_SAFARI) {
1461
+
1462
+ // This creates a microtask
1463
+ Promise.resolve().then(step)
1464
+
1465
+ }
1466
+ else {
1467
+
1468
+ window.requestAnimationFrame(step)
1469
+
1470
+ }
1471
+
1472
+ }
1473
+
1474
+
1475
+ static scheduleLayoutViewsIfNeeded() {
1476
+
1477
+ UIView.runFunctionBeforeNextFrame(UIView.layoutViewsIfNeeded)
1478
+
1479
+ }
1480
+
1481
+
1482
+ static layoutViewsIfNeeded() {
1483
+ for (var i = 0; i < UIView._viewsToLayout.length; i++) {
1484
+ const view = UIView._viewsToLayout[i]
1485
+ view.layoutIfNeeded()
1486
+ }
1487
+ UIView._viewsToLayout = []
1488
+ }
1489
+
1490
+
1491
+ setNeedsLayout() {
1492
+
1493
+ if (this._shouldLayout) {
1494
+ return
1495
+ }
1496
+
1497
+ this._shouldLayout = YES
1498
+
1499
+ // Register view for layout before next frame
1500
+ UIView._viewsToLayout.push(this)
1501
+
1502
+ if (UIView._viewsToLayout.length == 1) {
1503
+ UIView.scheduleLayoutViewsIfNeeded()
1504
+ }
1505
+
1506
+ }
1507
+
1508
+
1509
+ get needsLayout() {
1510
+
1511
+ return this._shouldLayout
1512
+
1513
+ }
1514
+
1515
+
1516
+ layoutIfNeeded() {
1517
+
1518
+ if (!this._shouldLayout) {
1519
+ return
1520
+ }
1521
+
1522
+ this._shouldLayout = NO
1523
+
1524
+ try {
1525
+
1526
+ this.layoutSubviews()
1527
+
1528
+ } catch (exception) {
1529
+
1530
+ console.log(exception)
1531
+
1532
+ }
1533
+
1534
+ }
1535
+
1536
+
1537
+ layoutSubviews() {
1538
+
1539
+
1540
+ this._shouldLayout = NO
1541
+
1542
+ // Autolayout
1543
+ //window.removeEventListener('resize', this._updateLayoutFunction);
1544
+ if (this.constraints.length) {
1545
+
1546
+ this._updateLayoutFunction = UIView.performAutoLayout(this.viewHTMLElement, null, this.constraints)
1547
+
1548
+ }
1549
+
1550
+ //this._updateLayoutFunction = this.layoutSubviews.bind(this);
1551
+
1552
+ //window.addEventListener('resize', this._updateLayoutFunction);
1553
+
1554
+ this._viewControllerLayoutFunction()
1555
+
1556
+ this.applyClassesAndStyles()
1557
+
1558
+ for (var i = 0; i < this.subviews.length; i++) {
1559
+
1560
+ const subview = this.subviews[i]
1561
+
1562
+ subview.calculateAndSetViewFrame()
1563
+
1564
+ //subview.layoutSubviews();
1565
+
1566
+ }
1567
+
1568
+ this.didLayoutSubviews()
1569
+
1570
+ }
1571
+
1572
+
1573
+
1574
+ applyClassesAndStyles() {
1575
+
1576
+
1577
+
1578
+ //var classesString = "";
1579
+
1580
+ for (var i = 0; i < this.styleClasses.length; i++) {
1581
+
1582
+ const styleClass = this.styleClasses[i]
1583
+
1584
+ if (styleClass) {
1585
+
1586
+ this.viewHTMLElement.classList.add(styleClass)
1587
+
1588
+ }
1589
+
1590
+
1591
+
1592
+ //classesString = classesString + " " + styleClass;
1593
+
1594
+ }
1595
+
1596
+
1597
+ //this.viewHTMLElement.className = classesString;
1598
+
1599
+
1600
+
1601
+ }
1602
+
1603
+ didLayoutSubviews() {
1604
+
1605
+ this._didLayoutSubviewsDelegateFunction()
1606
+
1607
+ }
1608
+
1609
+ get constraints() {
1610
+ return this._constraints
1611
+ }
1612
+
1613
+ set constraints(constraints) {
1614
+ this._constraints = constraints
1615
+ }
1616
+
1617
+ addConstraint(constraint) {
1618
+
1619
+ this.constraints.push(constraint)
1620
+
1621
+ }
1622
+
1623
+
1624
+
1625
+ addConstraintsWithVisualFormat(visualFormatArray) {
1626
+
1627
+ this.constraints = this.constraints.concat(AutoLayout.VisualFormat.parse(
1628
+ visualFormatArray,
1629
+ { extended: true }
1630
+ ))
1631
+
1632
+ }
1633
+
1634
+ static constraintWithView(view, attribute, relation, toView, toAttribute, multiplier, constant, priority) {
1635
+
1636
+ var UIViewObject = nil
1637
+ var viewID = null
1638
+ if (view) {
1639
+ if (view.isKindOfClass && view.isKindOfClass(UIView)) {
1640
+ UIViewObject = view
1641
+ view = view.viewHTMLElement
1642
+ }
1643
+ viewID = view.id
1644
+ }
1645
+
1646
+ var toUIViewObject = nil
1647
+ var toViewID = null
1648
+ if (toView) {
1649
+ if (toView.isKindOfClass && view.isKindOfClass(UIView)) {
1650
+ toUIViewObject = toView
1651
+ toView = toView.viewHTMLElement
1652
+ }
1653
+ toViewID = toView.id
1654
+ }
1655
+
1656
+ const constraint = {
1657
+
1658
+ view1: viewID,
1659
+ attr1: attribute,
1660
+ relation: relation,
1661
+ view2: toViewID,
1662
+ attr2: toAttribute,
1663
+ multiplier: multiplier,
1664
+ constant: constant,
1665
+ priority: priority
1666
+
1667
+ }
1668
+
1669
+ return constraint
1670
+
1671
+ }
1672
+
1673
+ static constraintAttribute = {
1674
+
1675
+ "left": AutoLayout.Attribute.LEFT,
1676
+ "right": AutoLayout.Attribute.RIGHT,
1677
+ "bottom": AutoLayout.Attribute.BOTTOM,
1678
+ "top": AutoLayout.Attribute.TOP,
1679
+ "centerX": AutoLayout.Attribute.CENTERX,
1680
+ "centerY": AutoLayout.Attribute.CENTERY,
1681
+ "height": AutoLayout.Attribute.HEIGHT,
1682
+ "width": AutoLayout.Attribute.WIDTH,
1683
+ "zIndex": AutoLayout.Attribute.ZINDEX,
1684
+ // Not sure what these are for
1685
+ "constant": AutoLayout.Attribute.NOTANATTRIBUTE,
1686
+ "variable": AutoLayout.Attribute.VARIABLE
1687
+
1688
+ }
1689
+
1690
+ static constraintRelation = {
1691
+
1692
+ "equal": AutoLayout.Relation.EQU,
1693
+ "lessThanOrEqual": AutoLayout.Relation.LEQ,
1694
+ "greaterThanOrEqual": AutoLayout.Relation.GEQ
1695
+
1696
+ }
1697
+
1698
+
1699
+
1700
+ subviewWithID(viewID) {
1701
+
1702
+
1703
+ var resultHTMLElement = nil
1704
+
1705
+ try {
1706
+
1707
+ resultHTMLElement = this.viewHTMLElement.querySelector("#" + viewID)
1708
+
1709
+ } catch (error) {
1710
+
1711
+ }
1712
+
1713
+ if (resultHTMLElement && resultHTMLElement.UIView) {
1714
+ return resultHTMLElement.UIView
1715
+ }
1716
+ return nil
1717
+ }
1718
+
1719
+
1720
+
1721
+ rectangleContainingSubviews() {
1722
+
1723
+ const center = this.bounds.center
1724
+
1725
+ var result = new UIRectangle(center.x, center.y, 0, 0)
1726
+
1727
+ for (var i = 0; i < this.subviews.length; i++) {
1728
+
1729
+ const subview = this.subviews[i]
1730
+
1731
+ var frame = subview.frame
1732
+
1733
+ const rectangleContainingSubviews = subview.rectangleContainingSubviews()
1734
+
1735
+ frame = frame.concatenateWithRectangle(rectangleContainingSubviews)
1736
+
1737
+ result = result.concatenateWithRectangle(frame)
1738
+
1739
+ }
1740
+
1741
+ return result
1742
+
1743
+ }
1744
+
1745
+
1746
+
1747
+
1748
+ hasSubview(view: UIView) {
1749
+
1750
+ // This is for performance reasons
1751
+ if (!IS(view)) {
1752
+ return NO
1753
+ }
1754
+
1755
+ for (var i = 0; i < this.subviews.length; i++) {
1756
+ const subview = this.subviews[i]
1757
+ if (subview == view) {
1758
+ return YES
1759
+ }
1760
+ }
1761
+ return NO
1762
+ }
1763
+
1764
+ get viewBelowThisView() {
1765
+ const result: UIView = (this.viewHTMLElement.previousElementSibling as any || {}).UIView
1766
+ return result
1767
+ }
1768
+
1769
+ get viewAboveThisView() {
1770
+ const result: UIView = (this.viewHTMLElement.nextElementSibling as any || {}).UIView
1771
+ return result
1772
+ }
1773
+
1774
+ addSubview(view: UIView, aboveView?: UIView) {
1775
+
1776
+ if (!this.hasSubview(view) && IS(view)) {
1777
+
1778
+ view.willMoveToSuperview(this)
1779
+
1780
+ if (IS(aboveView)) {
1781
+ this.viewHTMLElement.insertBefore(view.viewHTMLElement, aboveView.viewHTMLElement.nextSibling)
1782
+ this.subviews.insertElementAtIndex(this.subviews.indexOf(aboveView), view)
1783
+ }
1784
+ else {
1785
+ this.viewHTMLElement.appendChild(view.viewHTMLElement)
1786
+ this.subviews.push(view)
1787
+ }
1788
+ view.didMoveToSuperview(this)
1789
+
1790
+ if (this.superview && this.isMemberOfViewTree) {
1791
+
1792
+ view.broadcastEventInSubtree({
1793
+
1794
+ name: UIView.broadcastEventName.AddedToViewTree,
1795
+ parameters: nil
1796
+
1797
+ })
1798
+
1799
+ }
1800
+
1801
+ this.setNeedsLayout()
1802
+
1803
+ }
1804
+
1805
+ }
1806
+
1807
+ addSubviews(views: UIView[]) {
1808
+ views.forEach(function (this: UIView, view: UIView, index, array) {
1809
+ this.addSubview(view)
1810
+ }, this)
1811
+ }
1812
+
1813
+
1814
+ moveToBottomOfSuperview() {
1815
+
1816
+ if (IS(this.superview)) {
1817
+
1818
+ const bottomView = this.superview.subviews.firstElement
1819
+
1820
+ if (bottomView == this) {
1821
+
1822
+ return
1823
+
1824
+ }
1825
+
1826
+ this.superview.subviews.removeElement(this)
1827
+
1828
+ this.superview.subviews.insertElementAtIndex(0, this)
1829
+
1830
+ this.superview.viewHTMLElement.insertBefore(this.viewHTMLElement, bottomView.viewHTMLElement)
1831
+
1832
+
1833
+ }
1834
+
1835
+
1836
+
1837
+ }
1838
+
1839
+ moveToTopOfSuperview() {
1840
+
1841
+ if (IS(this.superview)) {
1842
+
1843
+ const topView = this.superview.subviews.lastElement
1844
+
1845
+ if (topView == this) {
1846
+
1847
+ return
1848
+
1849
+ }
1850
+
1851
+ this.superview.subviews.removeElement(this)
1852
+
1853
+ this.superview.subviews.push(this)
1854
+
1855
+ this.superview.viewHTMLElement.appendChild(this.viewHTMLElement)
1856
+
1857
+
1858
+ }
1859
+
1860
+
1861
+
1862
+ }
1863
+
1864
+
1865
+ removeFromSuperview() {
1866
+ if (IS(this.superview)) {
1867
+
1868
+ this.forEachViewInSubtree(function (view) {
1869
+
1870
+ view.blur()
1871
+
1872
+ })
1873
+
1874
+ const index = this.superview.subviews.indexOf(this)
1875
+ if (index > -1) {
1876
+ this.superview.subviews.splice(index, 1)
1877
+ this.superview.viewHTMLElement.removeChild(this.viewHTMLElement)
1878
+ this.superview = nil
1879
+
1880
+ this.broadcastEventInSubtree({
1881
+
1882
+ name: UIView.broadcastEventName.RemovedFromViewTree,
1883
+ parameters: nil
1884
+
1885
+ })
1886
+
1887
+ }
1888
+ }
1889
+ }
1890
+
1891
+
1892
+ willAppear() {
1893
+
1894
+
1895
+
1896
+ }
1897
+
1898
+
1899
+
1900
+ willMoveToSuperview(superview: UIView) {
1901
+
1902
+ this._setInnerHTMLFromKeyIfPossible()
1903
+
1904
+ this._setInnerHTMLFromLocalizedTextObjectIfPossible()
1905
+
1906
+ }
1907
+
1908
+ didMoveToSuperview(superview: UIView) {
1909
+
1910
+ this.superview = superview
1911
+
1912
+ }
1913
+
1914
+ wasAddedToViewTree() {
1915
+
1916
+ }
1917
+
1918
+ wasRemovedFromViewTree() {
1919
+
1920
+ }
1921
+
1922
+ get isMemberOfViewTree() {
1923
+ var element = this.viewHTMLElement
1924
+ for (var i = 0; element; i = i) {
1925
+ if (element.parentElement && element.parentElement == document.body) {
1926
+ return YES
1927
+ }
1928
+ element = element.parentElement
1929
+ }
1930
+ return NO
1931
+ }
1932
+
1933
+
1934
+ get allSuperviews() {
1935
+ const result = []
1936
+ var view: UIView = this
1937
+ for (var i = 0; IS(view); i = i) {
1938
+ result.push(view)
1939
+ view = view.superview
1940
+ }
1941
+ return result
1942
+ }
1943
+
1944
+
1945
+ setNeedsLayoutOnAllSuperviews() {
1946
+
1947
+ this.allSuperviews.reverse().forEach(function (view: UIView, index, array) {
1948
+
1949
+ view.setNeedsLayout()
1950
+
1951
+ })
1952
+
1953
+ }
1954
+
1955
+
1956
+ setNeedsLayoutUpToRootView() {
1957
+
1958
+ this.setNeedsLayoutOnAllSuperviews()
1959
+
1960
+ this.setNeedsLayout()
1961
+
1962
+ }
1963
+
1964
+
1965
+ focus() {
1966
+
1967
+ this.viewHTMLElement.focus()
1968
+
1969
+ }
1970
+
1971
+
1972
+ blur() {
1973
+
1974
+ this.viewHTMLElement.blur()
1975
+
1976
+ }
1977
+
1978
+
1979
+
1980
+
1981
+
1982
+ _loadUIEvents() {
1983
+
1984
+ //this.viewHTMLElement = nil;
1985
+
1986
+
1987
+ const isTouchEventClassDefined: boolean = NO || (window as any).TouchEvent
1988
+
1989
+ const pauseEvent = (event: Event, forced = NO) => {
1990
+
1991
+ if (this.pausesPointerEvents || forced) {
1992
+
1993
+ if (event.stopPropagation) {
1994
+ event.stopPropagation()
1995
+ }
1996
+ if (event.preventDefault) {
1997
+ event.preventDefault()
1998
+ }
1999
+ event.cancelBubble = true
2000
+ event.returnValue = false
2001
+ return false
2002
+
2003
+ }
2004
+
2005
+ if (event.stopPropagation && this.stopsPointerEventPropagation) {
2006
+ event.stopPropagation()
2007
+ }
2008
+
2009
+ }
2010
+
2011
+ const onMouseDown = (event) => {
2012
+
2013
+ if ((this.ignoresTouches && isTouchEventClassDefined && event instanceof TouchEvent) ||
2014
+ ((this.ignoresMouse || (IS(this._touchEventTime) && (Date.now() - this._touchEventTime) > 500)) &&
2015
+ event instanceof MouseEvent)) {
2016
+ return
2017
+ }
2018
+
2019
+ this.sendControlEventForKey(UIView.controlEvent.PointerDown, event)
2020
+
2021
+ this._isPointerInside = YES
2022
+ this._isPointerValid = YES
2023
+ this._initialPointerPosition = new UIPoint(event.clientX, event.clientY)
2024
+ if (isTouchEventClassDefined && event instanceof TouchEvent) {
2025
+
2026
+ this._touchEventTime = Date.now()
2027
+
2028
+ this._initialPointerPosition = new UIPoint(event.touches[0].clientX, event.touches[0].clientY)
2029
+
2030
+ if (event.touches.length > 1) {
2031
+
2032
+ onTouchCancel(event)
2033
+
2034
+ return
2035
+
2036
+ }
2037
+
2038
+
2039
+ }
2040
+ else {
2041
+
2042
+ this._touchEventTime = nil
2043
+
2044
+ pauseEvent(event)
2045
+
2046
+ }
2047
+
2048
+
2049
+ this._hasPointerDragged = NO
2050
+
2051
+ }
2052
+
2053
+ const onTouchStart = onMouseDown as any
2054
+
2055
+ const onmouseup = (event) => {
2056
+
2057
+ if (!this._isPointerValid) {
2058
+ return
2059
+ }
2060
+
2061
+ if ((this.ignoresTouches && isTouchEventClassDefined && event instanceof TouchEvent) ||
2062
+ (this.ignoresMouse && event instanceof MouseEvent)) {
2063
+ return
2064
+ }
2065
+
2066
+ if (this._isPointerInside) {
2067
+
2068
+ onPointerUpInside(event)
2069
+
2070
+ if (!this._hasPointerDragged) {
2071
+
2072
+ this.sendControlEventForKey(UIView.controlEvent.PointerTap, event)
2073
+
2074
+ }
2075
+
2076
+
2077
+ }
2078
+
2079
+ // This has to be sent after the more specific event so that UIButton can ignore it when not highlighted
2080
+ this.sendControlEventForKey(UIView.controlEvent.PointerUp, event)
2081
+
2082
+ pauseEvent(event)
2083
+
2084
+ }
2085
+
2086
+ const onTouchEnd = onmouseup
2087
+
2088
+ // function onMouseEnter(event) {
2089
+
2090
+ // this.sendControlEventForKey(UIView.controlEvent.PointerEnter, event);
2091
+
2092
+ // this._isPointerInside = YES;
2093
+
2094
+ // pauseEvent(event);
2095
+
2096
+ // }
2097
+
2098
+ const onmouseout = (event) => {
2099
+
2100
+ if ((this.ignoresTouches && isTouchEventClassDefined && event instanceof TouchEvent) ||
2101
+ (this.ignoresMouse && event instanceof MouseEvent)) {
2102
+ return
2103
+ }
2104
+
2105
+ this.sendControlEventForKey(UIView.controlEvent.PointerLeave, event)
2106
+
2107
+ this._isPointerInside = NO
2108
+
2109
+ pauseEvent(event)
2110
+
2111
+ }
2112
+
2113
+ const onTouchLeave = onmouseout
2114
+
2115
+ var onTouchCancel = function (event) {
2116
+
2117
+ if (!this._isPointerValid) {
2118
+ return
2119
+ }
2120
+
2121
+ if ((this.ignoresTouches && isTouchEventClassDefined && event instanceof TouchEvent) ||
2122
+ (this.ignoresMouse && event instanceof MouseEvent)) {
2123
+ return
2124
+ }
2125
+
2126
+ this._isPointerValid = NO
2127
+
2128
+ this.sendControlEventForKey(UIView.controlEvent.PointerCancel, event)
2129
+
2130
+ }.bind(this)
2131
+
2132
+ const onmouseover = (event) => {
2133
+
2134
+ if ((this.ignoresTouches && isTouchEventClassDefined && event instanceof TouchEvent) ||
2135
+ (this.ignoresMouse && event instanceof MouseEvent)) {
2136
+ return
2137
+ }
2138
+
2139
+ this.sendControlEventForKey(UIView.controlEvent.PointerHover, event)
2140
+
2141
+ this._isPointerInside = YES
2142
+
2143
+ this._isPointerValid = YES
2144
+
2145
+ pauseEvent(event)
2146
+
2147
+ }
2148
+
2149
+ const onMouseMove = (event) => {
2150
+
2151
+ if (!this._isPointerValid) {
2152
+ return
2153
+ }
2154
+
2155
+ if ((this.ignoresTouches && isTouchEventClassDefined && event instanceof TouchEvent) ||
2156
+ (this.ignoresMouse && event instanceof MouseEvent)) {
2157
+ return
2158
+ }
2159
+
2160
+ if (IS_NOT(this._initialPointerPosition)) {
2161
+
2162
+ this._initialPointerPosition = new UIPoint(event.clientX, event.clientY)
2163
+
2164
+ }
2165
+
2166
+ if (new UIPoint(event.clientX, event.clientY).to(this._initialPointerPosition).length >
2167
+ this._pointerDragThreshold) {
2168
+
2169
+ this._hasPointerDragged = YES
2170
+
2171
+ }
2172
+
2173
+
2174
+ this.sendControlEventForKey(UIView.controlEvent.PointerMove, event)
2175
+
2176
+ pauseEvent(event)
2177
+
2178
+ }
2179
+
2180
+ const onTouchMove = function (event: TouchEvent) {
2181
+
2182
+ if (!this._isPointerValid) {
2183
+ return
2184
+ }
2185
+
2186
+ if ((this.ignoresTouches && isTouchEventClassDefined && event instanceof TouchEvent) ||
2187
+ (this.ignoresMouse && event instanceof MouseEvent)) {
2188
+ return
2189
+ }
2190
+
2191
+ if (event.touches.length > 1) {
2192
+
2193
+ onTouchZoom(event)
2194
+
2195
+ return
2196
+
2197
+ }
2198
+
2199
+ const touch = event.touches[0]
2200
+
2201
+ if (new UIPoint(touch.clientX, touch.clientY).to(this._initialPointerPosition).length >
2202
+ this._pointerDragThreshold) {
2203
+
2204
+ this._hasPointerDragged = YES
2205
+
2206
+ }
2207
+
2208
+
2209
+ if (this._isPointerInside && this.viewHTMLElement !=
2210
+ document.elementFromPoint(touch.clientX, touch.clientY)) {
2211
+
2212
+ this._isPointerInside = NO
2213
+
2214
+ this.sendControlEventForKey(UIView.controlEvent.PointerLeave, event)
2215
+
2216
+ }
2217
+
2218
+
2219
+ this.sendControlEventForKey(UIView.controlEvent.PointerMove, event)
2220
+
2221
+ //pauseEvent(event);
2222
+
2223
+
2224
+ }
2225
+
2226
+ var onTouchZoom = function onTouchZoom(event: TouchEvent) {
2227
+
2228
+ this.sendControlEventForKey(UIView.controlEvent.MultipleTouches, event)
2229
+
2230
+ }.bind(this)
2231
+
2232
+
2233
+ var onPointerUpInside = (event) => {
2234
+ pauseEvent(event)
2235
+
2236
+ this.sendControlEventForKey(UIView.controlEvent.PointerUpInside, event)
2237
+ }
2238
+
2239
+ function eventKeyIsEnter(event) {
2240
+ if (event.keyCode !== 13) {
2241
+ return NO
2242
+ }
2243
+ return YES
2244
+ }
2245
+
2246
+ function eventKeyIsTab(event) {
2247
+ if (event.keyCode !== 9) {
2248
+ return NO
2249
+ }
2250
+ return YES
2251
+ }
2252
+
2253
+ function eventKeyIsEsc(event) {
2254
+ var result = false
2255
+ if ("key" in event) {
2256
+ result = (event.key == "Escape" || event.key == "Esc")
2257
+ }
2258
+ else {
2259
+ result = (event.keyCode == 27)
2260
+ }
2261
+ return result
2262
+ }
2263
+
2264
+ function eventKeyIsLeft(event) {
2265
+ if (event.keyCode != "37") {
2266
+ return NO
2267
+ }
2268
+ return YES
2269
+ }
2270
+
2271
+ function eventKeyIsRight(event) {
2272
+ if (event.keyCode != "39") {
2273
+ return NO
2274
+ }
2275
+ return YES
2276
+ }
2277
+
2278
+ function eventKeyIsDown(event) {
2279
+ if (event.keyCode != "40") {
2280
+ return NO
2281
+ }
2282
+ return YES
2283
+ }
2284
+
2285
+ function eventKeyIsUp(event) {
2286
+ if (event.keyCode != "38") {
2287
+ return NO
2288
+ }
2289
+ return YES
2290
+ }
2291
+
2292
+ const onKeyDown = function (event) {
2293
+
2294
+ if (eventKeyIsEnter(event)) {
2295
+
2296
+ this.sendControlEventForKey(UIView.controlEvent.EnterDown, event)
2297
+
2298
+ }
2299
+
2300
+ if (eventKeyIsEsc(event)) {
2301
+
2302
+ this.sendControlEventForKey(UIView.controlEvent.EscDown, event)
2303
+
2304
+ }
2305
+
2306
+ if (eventKeyIsTab(event) && this._controlEventTargets.TabDown && this._controlEventTargets.TabDown.length) {
2307
+
2308
+ this.sendControlEventForKey(UIView.controlEvent.TabDown, event)
2309
+
2310
+ pauseEvent(event, YES)
2311
+
2312
+ }
2313
+
2314
+ if (eventKeyIsLeft(event)) {
2315
+
2316
+ this.sendControlEventForKey(UIView.controlEvent.LeftArrowDown, event)
2317
+
2318
+ }
2319
+
2320
+ if (eventKeyIsRight(event)) {
2321
+
2322
+ this.sendControlEventForKey(UIView.controlEvent.RightArrowDown, event)
2323
+
2324
+ }
2325
+
2326
+ if (eventKeyIsDown(event)) {
2327
+
2328
+ this.sendControlEventForKey(UIView.controlEvent.DownArrowDown, event)
2329
+
2330
+ }
2331
+
2332
+ if (eventKeyIsUp(event)) {
2333
+
2334
+ this.sendControlEventForKey(UIView.controlEvent.UpArrowDown, event)
2335
+
2336
+ }
2337
+
2338
+ }.bind(this)
2339
+
2340
+ const onKeyUp = function (event) {
2341
+
2342
+ if (eventKeyIsEnter(event)) {
2343
+
2344
+ this.sendControlEventForKey(UIView.controlEvent.EnterUp, event)
2345
+
2346
+ }
2347
+
2348
+ }.bind(this)
2349
+
2350
+
2351
+ const onfocus = function (event: Event) {
2352
+
2353
+ this.sendControlEventForKey(UIView.controlEvent.Focus, event)
2354
+
2355
+ }.bind(this)
2356
+
2357
+ const onblur = function (event: Event) {
2358
+
2359
+ this.sendControlEventForKey(UIView.controlEvent.Blur, event)
2360
+
2361
+ }.bind(this)
2362
+
2363
+
2364
+ // Mouse and touch start events
2365
+ this._viewHTMLElement.onmousedown = onMouseDown.bind(this)
2366
+ this._viewHTMLElement.ontouchstart = onTouchStart.bind(this)
2367
+ // this.viewHTMLElement.addEventListener("mousedown", onMouseDown.bind(this), false)
2368
+ // this.viewHTMLElement.addEventListener('touchstart', onTouchStart.bind(this), false)
2369
+ // //this.viewHTMLElement.addEventListener("mouseenter", onMouseEnter.bind(this), false);
2370
+
2371
+ // Mouse and touch move events
2372
+ this._viewHTMLElement.onmousemove = onMouseMove.bind(this)
2373
+ this._viewHTMLElement.ontouchmove = onTouchMove.bind(this)
2374
+ // this.viewHTMLElement.addEventListener("mousemove", onMouseMove.bind(this), false)
2375
+ // this.viewHTMLElement.addEventListener('touchmove', onTouchMove.bind(this), false)
2376
+
2377
+ //this.viewHTMLElement.addEventListener("mousewheel", onmousewheel.bind(this), false)
2378
+
2379
+ this._viewHTMLElement.onmouseover = onmouseover.bind(this)
2380
+ // this.viewHTMLElement.addEventListener("mouseover", onmouseover.bind(this), false)
2381
+
2382
+ // Mouse and touch end events
2383
+ this._viewHTMLElement.onmouseup = onmouseup.bind(this)
2384
+ this._viewHTMLElement.ontouchend = onTouchEnd.bind(this)
2385
+ this._viewHTMLElement.ontouchcancel = onTouchCancel.bind(this)
2386
+ // this.viewHTMLElement.addEventListener("mouseup", onmouseup.bind(this), false)
2387
+ // this.viewHTMLElement.addEventListener('touchend', onTouchEnd.bind(this), false)
2388
+ // this.viewHTMLElement.addEventListener('touchcancel', onTouchCancel.bind(this), false)
2389
+
2390
+ this._viewHTMLElement.onmouseout = onmouseout.bind(this)
2391
+ // this.viewHTMLElement.addEventListener("mouseout", onmouseout.bind(this), false)
2392
+ this._viewHTMLElement.addEventListener("touchleave", onTouchLeave.bind(this), false)
2393
+
2394
+ // this.viewHTMLElement.onkeydown = onkeydown
2395
+ // this.viewHTMLElement.onkeyup = onkeyup
2396
+ this._viewHTMLElement.addEventListener("keydown", onKeyDown, false)
2397
+ this._viewHTMLElement.addEventListener("keyup", onKeyUp, false)
2398
+
2399
+ // Focus events
2400
+ this._viewHTMLElement.onfocus = onfocus
2401
+ this._viewHTMLElement.onblur = onblur
2402
+ // this.viewHTMLElement.addEventListener("focus", onfocus, true)
2403
+ // this.viewHTMLElement.addEventListener("blur", onblur, true)
2404
+
2405
+
2406
+ }
2407
+
2408
+
2409
+
2410
+
2411
+
2412
+ public static controlEvent = {
2413
+
2414
+ "PointerDown": "PointerDown",
2415
+ "PointerMove": "PointerMove",
2416
+ "PointerLeave": "PointerLeave",
2417
+ "PointerEnter": "PointerEnter",
2418
+ "PointerUpInside": "PointerUpInside",
2419
+ "PointerTap": "PointerTap",
2420
+ "PointerUp": "PointerUp",
2421
+ "MultipleTouches": "PointerZoom",
2422
+ "PointerCancel": "PointerCancel",
2423
+ "PointerHover": "PointerHover",
2424
+ "EnterDown": "EnterDown",
2425
+ "EnterUp": "EnterUp",
2426
+ "EscDown": "EscDown",
2427
+ "TabDown": "TabDown",
2428
+ "LeftArrowDown": "LeftArrowDown",
2429
+ "RightArrowDown": "RightArrowDown",
2430
+ "DownArrowDown": "DownArrowDown",
2431
+ "UpArrowDown": "UpArrowDown",
2432
+ "Focus": "Focus",
2433
+ "Blur": "Blur"
2434
+
2435
+ }
2436
+
2437
+ controlEvent = UIView.controlEvent
2438
+
2439
+
2440
+
2441
+ public get addControlEventTarget() {
2442
+
2443
+ const eventKeys = []
2444
+
2445
+
2446
+ const result: UIViewAddControlEventTargetObject<typeof UIView.controlEvent> = new Proxy(
2447
+ (this.constructor as any).controlEvent,
2448
+ {
2449
+
2450
+ get: (target, key, receiver) => {
2451
+
2452
+ eventKeys.push(key)
2453
+
2454
+ return result
2455
+
2456
+ },
2457
+ set: (target, key, value, receiver) => {
2458
+
2459
+ eventKeys.push(key)
2460
+
2461
+ this.addTargetForControlEvents(eventKeys, value)
2462
+
2463
+ return true
2464
+
2465
+ }
2466
+
2467
+ }
2468
+ )
2469
+
2470
+ return result
2471
+
2472
+ }
2473
+
2474
+
2475
+
2476
+
2477
+
2478
+ addTargetForControlEvents(eventKeys: string[], targetFunction: (sender: UIView, event: Event) => void) {
2479
+
2480
+ eventKeys.forEach(function (this: UIView, key: string, index: number, array: string[]) {
2481
+
2482
+ this.addTargetForControlEvent(key, targetFunction)
2483
+
2484
+ }, this)
2485
+
2486
+ }
2487
+
2488
+
2489
+
2490
+ addTargetForControlEvent(eventKey: string, targetFunction: (sender: UIView, event: Event) => void) {
2491
+
2492
+ var targets = this._controlEventTargets[eventKey]
2493
+
2494
+ if (!targets) {
2495
+ // @ts-ignore
2496
+ targets = []
2497
+ this._controlEventTargets[eventKey] = targets
2498
+ }
2499
+
2500
+ if (targets.indexOf(targetFunction) == -1) {
2501
+ targets.push(targetFunction)
2502
+ }
2503
+
2504
+ }
2505
+
2506
+ removeTargetForControlEvent(eventKey: string, targetFunction: (sender: UIView, event: Event) => void) {
2507
+ const targets = this._controlEventTargets[eventKey]
2508
+ if (!targets) {
2509
+ return
2510
+ }
2511
+ const index = targets.indexOf(targetFunction)
2512
+ if (index != -1) {
2513
+ targets.splice(index, 1)
2514
+ }
2515
+ }
2516
+
2517
+ removeTargetForControlEvents(eventKeys: string[], targetFunction: (sender: UIView, event: Event) => void) {
2518
+
2519
+ eventKeys.forEach(function (key, index, array) {
2520
+
2521
+ this.removeTargetForControlEvent(key, targetFunction)
2522
+
2523
+ }, this)
2524
+
2525
+ }
2526
+
2527
+ sendControlEventForKey(eventKey: string, nativeEvent: Event) {
2528
+ var targets = this._controlEventTargets[eventKey]
2529
+ if (!targets) {
2530
+ return
2531
+ }
2532
+ targets = targets.copy()
2533
+ for (var i = 0; i < targets.length; i++) {
2534
+ const target = targets[i]
2535
+ target(this, nativeEvent)
2536
+ }
2537
+ }
2538
+
2539
+
2540
+
2541
+
2542
+
2543
+ static broadcastEventName = {
2544
+
2545
+ "LanguageChanged": "LanguageChanged",
2546
+ "RemovedFromViewTree": "RemovedFromViewTree",
2547
+ "AddedToViewTree": "AddedToViewTree",
2548
+ "PageDidScroll": "PageDidScroll"
2549
+
2550
+ }
2551
+
2552
+
2553
+ broadcastEventInSubtree(event: UIViewBroadcastEvent) {
2554
+
2555
+ this.forEachViewInSubtree(function (view) {
2556
+
2557
+ view.didReceiveBroadcastEvent(event)
2558
+
2559
+ if (view._didReceiveBroadcastEventDelegateFunction) {
2560
+
2561
+ view._didReceiveBroadcastEventDelegateFunction(event)
2562
+
2563
+ }
2564
+
2565
+ })
2566
+
2567
+
2568
+ }
2569
+
2570
+ didReceiveBroadcastEvent(event: UIViewBroadcastEvent) {
2571
+
2572
+ if (event.name == UIView.broadcastEventName.PageDidScroll) {
2573
+
2574
+ this._isPointerValid = NO
2575
+
2576
+ }
2577
+
2578
+ if (event.name == UIView.broadcastEventName.AddedToViewTree) {
2579
+
2580
+ this.wasAddedToViewTree()
2581
+
2582
+ }
2583
+
2584
+ if (event.name == UIView.broadcastEventName.RemovedFromViewTree) {
2585
+
2586
+ this.wasRemovedFromViewTree()
2587
+
2588
+ }
2589
+
2590
+ if (event.name == UIView.broadcastEventName.LanguageChanged || event.name ==
2591
+ UIView.broadcastEventName.AddedToViewTree) {
2592
+
2593
+ this._setInnerHTMLFromKeyIfPossible()
2594
+
2595
+ this._setInnerHTMLFromLocalizedTextObjectIfPossible()
2596
+
2597
+ }
2598
+
2599
+
2600
+
2601
+ }
2602
+
2603
+
2604
+
2605
+
2606
+
2607
+ forEachViewInSubtree(functionToCall: (view: UIView) => void) {
2608
+
2609
+ functionToCall(this)
2610
+
2611
+ this.subviews.forEach(function (subview, index, array) {
2612
+
2613
+ subview.forEachViewInSubtree(functionToCall)
2614
+
2615
+ })
2616
+
2617
+ }
2618
+
2619
+
2620
+
2621
+
2622
+
2623
+ rectangleInView(rectangle: UIRectangle, view: UIView) {
2624
+ if (!view.isMemberOfViewTree || !this.isMemberOfViewTree) {
2625
+ return nil
2626
+ }
2627
+
2628
+ const viewClientRectangle = view.viewHTMLElement.getBoundingClientRect()
2629
+ const viewLocation = new UIPoint(viewClientRectangle.left, viewClientRectangle.top)
2630
+
2631
+ const selfClientRectangle = this.viewHTMLElement.getBoundingClientRect()
2632
+ const selfLocation = new UIPoint(selfClientRectangle.left, selfClientRectangle.top)
2633
+
2634
+ const offsetPoint = selfLocation.subtract(viewLocation)
2635
+
2636
+ return rectangle.copy().offsetByPoint(offsetPoint)
2637
+ }
2638
+
2639
+ rectangleFromView(rectangle: UIRectangle, view: UIView) {
2640
+ return view.rectangleInView(rectangle, this)
2641
+ }
2642
+
2643
+
2644
+
2645
+
2646
+
2647
+ intrinsicContentSizeWithConstraints(constrainingHeight: number = 0, constrainingWidth: number = 0) {
2648
+
2649
+ // This works but is slow
2650
+
2651
+ const result = new UIRectangle(0, 0, 0, 0)
2652
+ if (this.rootView.forceIntrinsicSizeZero) {
2653
+ return result
2654
+ }
2655
+
2656
+ var temporarilyInViewTree = NO
2657
+ var nodeAboveThisView: Node
2658
+ if (!this.isMemberOfViewTree) {
2659
+ document.body.appendChild(this.viewHTMLElement)
2660
+ temporarilyInViewTree = YES
2661
+ nodeAboveThisView = this.viewHTMLElement.nextSibling
2662
+ }
2663
+
2664
+ const height = this.style.height
2665
+ const width = this.style.width
2666
+
2667
+ this.style.height = "" + constrainingHeight
2668
+ this.style.width = "" + constrainingWidth
2669
+
2670
+
2671
+ const left = this.style.left
2672
+ const right = this.style.right
2673
+ const bottom = this.style.bottom
2674
+ const top = this.style.top
2675
+
2676
+ this.style.left = ""
2677
+ this.style.right = ""
2678
+ this.style.bottom = ""
2679
+ this.style.top = ""
2680
+
2681
+
2682
+ const resultHeight = this.viewHTMLElement.scrollHeight
2683
+
2684
+
2685
+ const whiteSpace = this.style.whiteSpace
2686
+ this.style.whiteSpace = "nowrap"
2687
+
2688
+ const resultWidth = this.viewHTMLElement.scrollWidth
2689
+
2690
+ this.style.whiteSpace = whiteSpace
2691
+
2692
+
2693
+
2694
+ this.style.height = height
2695
+ this.style.width = width
2696
+
2697
+ this.style.left = left
2698
+ this.style.right = right
2699
+ this.style.bottom = bottom
2700
+ this.style.top = top
2701
+
2702
+ if (temporarilyInViewTree) {
2703
+ document.body.removeChild(this.viewHTMLElement)
2704
+ if (this.superview) {
2705
+ if (nodeAboveThisView) {
2706
+ this.superview.viewHTMLElement.insertBefore(this.viewHTMLElement, nodeAboveThisView)
2707
+ }
2708
+ else {
2709
+ this.superview.viewHTMLElement.appendChild(this.viewHTMLElement)
2710
+ }
2711
+ }
2712
+ }
2713
+
2714
+ result.height = resultHeight
2715
+ result.width = resultWidth
2716
+
2717
+
2718
+ return result
2719
+
2720
+ }
2721
+
2722
+
2723
+
2724
+
2725
+
2726
+ intrinsicContentWidth(constrainingHeight: number = 0): number {
2727
+
2728
+ const result = this.intrinsicContentSizeWithConstraints(constrainingHeight).width
2729
+
2730
+ return result
2731
+
2732
+ }
2733
+
2734
+ intrinsicContentHeight(constrainingWidth: number = 0): number {
2735
+
2736
+ const result = this.intrinsicContentSizeWithConstraints(undefined, constrainingWidth).height
2737
+
2738
+ return result
2739
+
2740
+
2741
+ }
2742
+
2743
+ intrinsicContentSize(): UIRectangle {
2744
+
2745
+ return nil
2746
+
2747
+ }
2748
+
2749
+
2750
+
2751
+
2752
+
2753
+ }
2754
+
2755
+
2756
+
2757
+
2758
+
2759
+
2760
+
2761
+
2762
+
2763
+
2764
+
2765
+
2766
+
2767
+
2768
+
2769
+
2770
+
2771
+
2772
+
2773
+
2774
+
2775
+
2776
+
2777
+
2778
+
2779
+
2780
+
2781
+
2782
+
2783
+
2784
+
2785
+
2786
+
2787
+
2788
+
2789
+