uicore-ts 1.1.66 → 1.1.82

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uicore-ts",
3
- "version": "1.1.66",
3
+ "version": "1.1.82",
4
4
  "description": "UICore is a library to build native-like user interfaces using pure Typescript. No HTML is needed at all. Components are described as TS classes and all user interactions are handled explicitly. This library is strongly inspired by the UIKit framework that is used in IOS. In addition, UICore has tools to handle URL based routing, array sorting and filtering and adds a number of other utilities for convenience.",
5
5
  "main": "compiledScripts/index.js",
6
6
  "types": "compiledScripts/index.d.ts",
@@ -65,6 +65,10 @@ export class UIColor extends UIObject {
65
65
  return new UIColor("transparent")
66
66
  }
67
67
 
68
+ static get clearColor() {
69
+ return new UIColor("transparent")
70
+ }
71
+
68
72
  static get undefinedColor() {
69
73
  return new UIColor("")
70
74
  }
package/scripts/UIView.ts CHANGED
@@ -161,7 +161,10 @@ export class UIView extends UIObject {
161
161
 
162
162
  _localizedTextObject?: UILocalizedTextObject
163
163
 
164
- _controlEventTargets: ControlEventTargetsObject = {} //{ "PointerDown": Function[]; "PointerMove": Function[]; "PointerLeave": Function[]; "PointerEnter": Function[]; "PointerUpInside": Function[]; "PointerUp": Function[]; "PointerHover": Function[]; };
164
+ _controlEventTargets: ControlEventTargetsObject = {} //{ "PointerDown": Function[]; "PointerMove": Function[];
165
+ // "PointerLeave": Function[]; "PointerEnter": Function[];
166
+ // "PointerUpInside": Function[]; "PointerUp": Function[];
167
+ // "PointerHover": Function[]; };
165
168
  _frameTransform: string
166
169
  viewController?: UIViewController
167
170
  _updateLayoutFunction?: Function
@@ -225,6 +228,13 @@ export class UIView extends UIObject {
225
228
  private _resizeObserverEntry?: ResizeObserverEntry
226
229
  protected _intrinsicSizesCache: Record<string, UIRectangle> = {}
227
230
 
231
+ static isVirtualLayouting = NO
232
+ _frameForVirtualLayouting?: UIRectangle
233
+
234
+ // Change this to no if the view contains pure HTML content that does not
235
+ // use frame logic that can influence the intrinsic size
236
+ usesVirtualLayoutingForIntrinsicSizing = YES
237
+
228
238
 
229
239
  constructor(
230
240
  elementID: string = ("UIView" + UIView.nextIndex),
@@ -720,93 +730,23 @@ export class UIView extends UIObject {
720
730
  }
721
731
 
722
732
 
723
- static createStyleSelector(selector: string, style: string) {
733
+ static injectCSS(cssText: string, id?: string) {
734
+ // Prevent duplicate injection if an ID is supplied
735
+ if (id && document.getElementById(id)) {
736
+ return
737
+ }
724
738
 
725
- return
739
+ const style = document.createElement("style")
740
+ if (id) {
741
+ style.id = id
742
+ }
726
743
 
727
- // // @ts-ignore
728
- // if (!document.styleSheets) {
729
- // return
730
- // }
731
- // if (document.getElementsByTagName("head").length == 0) {
732
- // return
733
- // }
734
- //
735
- // let styleSheet
736
- // let mediaType
737
- //
738
- // if (document.styleSheets.length > 0) {
739
- // for (var i = 0, l: any = document.styleSheets.length; i < l; i++) {
740
- // if (document.styleSheets[i].disabled) {
741
- // continue
742
- // }
743
- // const media = document.styleSheets[i].media
744
- // mediaType = typeof media
745
- //
746
- // if (mediaType === "string") {
747
- // if (media as any === "" || ((media as any).indexOf("screen") !== -1)) {
748
- // styleSheet = document.styleSheets[i]
749
- // }
750
- // }
751
- // else if (mediaType == "object") {
752
- // if (media.mediaText === "" || (media.mediaText.indexOf("screen") !== -1)) {
753
- // styleSheet = document.styleSheets[i]
754
- // }
755
- // }
756
- //
757
- // if (typeof styleSheet !== "undefined") {
758
- // break
759
- // }
760
- // }
761
- // }
762
- //
763
- // if (typeof styleSheet === "undefined") {
764
- // const styleSheetElement = document.createElement("style")
765
- // styleSheetElement.type = "text/css"
766
- // document.getElementsByTagName("head")[0].appendChild(styleSheetElement)
767
- //
768
- // for (i = 0; i < document.styleSheets.length; i++) {
769
- // if (document.styleSheets[i].disabled) {
770
- // continue
771
- // }
772
- // styleSheet = document.styleSheets[i]
773
- // }
774
- //
775
- // mediaType = typeof styleSheet.media
776
- // }
777
- //
778
- // if (mediaType === "string") {
779
- // for (var i = 0, l = styleSheet.rules.length; i < l; i++) {
780
- // if (styleSheet.rules[i].selectorText && styleSheet.rules[i].selectorText.toLowerCase() ==
781
- // selector.toLowerCase()) {
782
- // styleSheet.rules[i].style.cssText = style
783
- // return
784
- // }
785
- // }
786
- // styleSheet.addRule(selector, style)
787
- // }
788
- // else if (mediaType === "object") {
789
- //
790
- // var styleSheetLength = 0
791
- //
792
- // try {
793
- //
794
- // styleSheetLength = (styleSheet.cssRules) ? styleSheet.cssRules.length : 0
795
- //
796
- // } catch (error) {
797
- //
798
- // }
799
- //
800
- //
801
- // for (var i = 0; i < styleSheetLength; i++) {
802
- // if (styleSheet.cssRules[i].selectorText && styleSheet.cssRules[i].selectorText.toLowerCase() ==
803
- // selector.toLowerCase()) {
804
- // styleSheet.cssRules[i].style.cssText = style
805
- // return
806
- // }
807
- // }
808
- // styleSheet.insertRule(selector + "{" + style + "}", styleSheetLength)
809
- // }
744
+ style.textContent = cssText
745
+ document.head.appendChild(style)
746
+ }
747
+
748
+ static createStyleSelector(selector: string, style: string) {
749
+ this.injectCSS(selector + " { " + style + " }")
810
750
  }
811
751
 
812
752
  static getStyleRules(selector: string) {
@@ -949,7 +889,13 @@ export class UIView extends UIObject {
949
889
 
950
890
 
951
891
  public get frame() {
952
- let result: UIRectangle & { zIndex?: number } = this._frame?.copy() as any
892
+ let result: UIRectangle & { zIndex?: number }
893
+ if (!UIView.isVirtualLayouting) {
894
+ result = this._frame?.copy() as any
895
+ }
896
+ else {
897
+ result = this._frameForVirtualLayouting?.copy() as any
898
+ }
953
899
  if (!result) {
954
900
  result = new UIRectangle(
955
901
  this._resizeObserverEntry?.contentRect.left ?? this.viewHTMLElement.offsetLeft,
@@ -977,9 +923,15 @@ export class UIView extends UIObject {
977
923
  if (zIndex != undefined) {
978
924
  rectangle.zIndex = zIndex
979
925
  }
980
- this._frame = rectangle
926
+ if (!UIView.isVirtualLayouting) {
927
+ this._frame = rectangle
928
+ }
929
+ else {
930
+ this._frameForVirtualLayouting = rectangle
931
+ }
981
932
 
982
- if (frame && frame != nil && frame.isEqualTo(rectangle) && frame.zIndex == rectangle.zIndex && !performUncheckedLayout) {
933
+ if (frame && frame != nil && frame.isEqualTo(
934
+ rectangle) && frame.zIndex == rectangle.zIndex && !performUncheckedLayout) {
983
935
  return
984
936
  }
985
937
 
@@ -987,15 +939,17 @@ export class UIView extends UIObject {
987
939
  rectangle.scale(1 / this.scale)
988
940
  }
989
941
 
990
- UIView._setAbsoluteSizeAndPosition(
991
- this.viewHTMLElement,
992
- rectangle.topLeft.x,
993
- rectangle.topLeft.y,
994
- rectangle.width,
995
- rectangle.height,
996
- rectangle.zIndex,
997
- this.frameTransform
998
- )
942
+ if (!UIView.isVirtualLayouting) {
943
+ UIView._setAbsoluteSizeAndPosition(
944
+ this.viewHTMLElement,
945
+ rectangle.topLeft.x,
946
+ rectangle.topLeft.y,
947
+ rectangle.width,
948
+ rectangle.height,
949
+ rectangle.zIndex,
950
+ this.frameTransform
951
+ )
952
+ }
999
953
 
1000
954
  if (frame.height != rectangle.height || frame.width != rectangle.width || performUncheckedLayout) {
1001
955
  this.setNeedsLayout()
@@ -1005,8 +959,17 @@ export class UIView extends UIObject {
1005
959
  }
1006
960
 
1007
961
  get bounds() {
962
+
963
+ let _frame: (UIRectangle & { zIndex?: number }) | undefined
964
+ if (!UIView.isVirtualLayouting) {
965
+ _frame = this._frame
966
+ }
967
+ else {
968
+ _frame = this._frameForVirtualLayouting
969
+ }
970
+
1008
971
  let result: UIRectangle
1009
- if (IS_NOT(this._frame)) {
972
+ if (IS_NOT(_frame)) {
1010
973
  result = new UIRectangle(
1011
974
  0,
1012
975
  0,
@@ -1015,7 +978,14 @@ export class UIView extends UIObject {
1015
978
  )
1016
979
  }
1017
980
  else {
1018
- result = this.frame.copy()
981
+ let frame: (UIRectangle & { zIndex?: number })
982
+ if (!UIView.isVirtualLayouting) {
983
+ frame = this.frame
984
+ }
985
+ else {
986
+ frame = this._frameForVirtualLayouting ?? this.frame
987
+ }
988
+ result = frame.copy()
1019
989
  result.x = 0
1020
990
  result.y = 0
1021
991
  }
@@ -1224,7 +1194,8 @@ export class UIView extends UIObject {
1224
1194
  // @ts-ignore
1225
1195
  this.style[propertyName] = value
1226
1196
 
1227
- } catch (exception) {
1197
+ }
1198
+ catch (exception) {
1228
1199
 
1229
1200
  console.log(exception)
1230
1201
 
@@ -1524,7 +1495,8 @@ export class UIView extends UIObject {
1524
1495
 
1525
1496
  element = parentElement.querySelector("#" + key)
1526
1497
 
1527
- } catch (error) {
1498
+ }
1499
+ catch (error) {
1528
1500
 
1529
1501
  //console.log("Error occurred " + error);
1530
1502
 
@@ -1654,7 +1626,8 @@ export class UIView extends UIObject {
1654
1626
 
1655
1627
  this.layoutSubviews()
1656
1628
 
1657
- } catch (exception) {
1629
+ }
1630
+ catch (exception) {
1658
1631
 
1659
1632
  console.log(exception)
1660
1633
 
@@ -1811,7 +1784,8 @@ export class UIView extends UIObject {
1811
1784
 
1812
1785
  try {
1813
1786
  resultHTMLElement = this.viewHTMLElement.querySelector("#" + viewID)
1814
- } catch (error) {
1787
+ }
1788
+ catch (error) {
1815
1789
  console.log(error)
1816
1790
  }
1817
1791
 
@@ -3349,7 +3323,8 @@ export class UIView extends UIObject {
3349
3323
  selfOffsetPoint = selfOffsetPoint.add(
3350
3324
  element.UIViewObject?.frame.min ?? new UIPoint(element.offsetLeft, element.offsetTop)
3351
3325
  )
3352
- //selfScale = selfScale * (element.UIView?.scale ?? (element.getBoundingClientRect().width / element.offsetWidth))
3326
+ //selfScale = selfScale * (element.UIView?.scale ?? (element.getBoundingClientRect().width /
3327
+ // element.offsetWidth))
3353
3328
  }
3354
3329
 
3355
3330
  let viewOffsetPoint = new UIPoint(0, 0)
@@ -3359,7 +3334,8 @@ export class UIView extends UIObject {
3359
3334
  viewOffsetPoint = viewOffsetPoint.add(
3360
3335
  element.UIViewObject?.frame.min ?? new UIPoint(element.offsetLeft, element.offsetTop)
3361
3336
  )
3362
- //viewScale = viewScale * (element.UIView?.scale ?? (element.getBoundingClientRect().width / element.offsetWidth))
3337
+ //viewScale = viewScale * (element.UIView?.scale ?? (element.getBoundingClientRect().width /
3338
+ // element.offsetWidth))
3363
3339
  }
3364
3340
 
3365
3341
  const offsetPoint = selfOffsetPoint.subtract(viewOffsetPoint)
@@ -3458,12 +3434,48 @@ export class UIView extends UIObject {
3458
3434
 
3459
3435
  intrinsicContentWidth(constrainingHeight: number = 0): number {
3460
3436
 
3437
+ if (this.usesVirtualLayoutingForIntrinsicSizing) {
3438
+ UIView.isVirtualLayouting = YES
3439
+ this.frame = this.frame.rectangleWithHeight(constrainingHeight)
3440
+ this.layoutIfNeeded()
3441
+ const framePoints: UIPoint[] = []
3442
+ this.forEachViewInSubtree(view => {
3443
+ const frame = view.rectangleInView(
3444
+ view.frame,
3445
+ this
3446
+ )
3447
+ framePoints.push(frame.min)
3448
+ framePoints.push(frame.max)
3449
+ })
3450
+ const resultFrame = UIRectangle.boundingBoxForPoints(framePoints)
3451
+ UIView.isVirtualLayouting = NO
3452
+ return resultFrame.width
3453
+ }
3454
+
3461
3455
  return this.intrinsicContentSizeWithConstraints(constrainingHeight).width
3462
3456
 
3463
3457
  }
3464
3458
 
3465
3459
  intrinsicContentHeight(constrainingWidth: number = 0): number {
3466
3460
 
3461
+ if (this.usesVirtualLayoutingForIntrinsicSizing) {
3462
+ UIView.isVirtualLayouting = YES
3463
+ this.frame = this.frame.rectangleWithWidth(constrainingWidth)
3464
+ this.layoutIfNeeded()
3465
+ const framePoints: UIPoint[] = []
3466
+ this.forEachViewInSubtree(view => {
3467
+ const frame = view.rectangleInView(
3468
+ view.frame,
3469
+ this
3470
+ )
3471
+ framePoints.push(frame.min)
3472
+ framePoints.push(frame.max)
3473
+ })
3474
+ const resultFrame = UIRectangle.boundingBoxForPoints(framePoints)
3475
+ UIView.isVirtualLayouting = NO
3476
+ return resultFrame.height
3477
+ }
3478
+
3467
3479
  return this.intrinsicContentSizeWithConstraints(undefined, constrainingWidth).height
3468
3480
 
3469
3481
 
@@ -3472,6 +3484,23 @@ export class UIView extends UIObject {
3472
3484
 
3473
3485
  intrinsicContentSize(): UIRectangle {
3474
3486
 
3487
+ if (this.usesVirtualLayoutingForIntrinsicSizing) {
3488
+ UIView.isVirtualLayouting = YES
3489
+ this.layoutIfNeeded()
3490
+ const framePoints: UIPoint[] = []
3491
+ this.forEachViewInSubtree(view => {
3492
+ const frame = view.rectangleInView(
3493
+ view.frame,
3494
+ this
3495
+ )
3496
+ framePoints.push(frame.min)
3497
+ framePoints.push(frame.max)
3498
+ })
3499
+ const resultFrame = UIRectangle.boundingBoxForPoints(framePoints)
3500
+ UIView.isVirtualLayouting = NO
3501
+ return resultFrame
3502
+ }
3503
+
3475
3504
  return nil
3476
3505
 
3477
3506
  }