uicore-ts 1.1.52 → 1.1.56

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.
@@ -3,6 +3,7 @@ import { UILocalizedTextObject } from "./UIInterfaces"
3
3
  import { FIRST, IS_LIKE_NULL, nil, NO, UIObject, YES } from "./UIObject"
4
4
  import { UIRectangle } from "./UIRectangle"
5
5
  import type { ValueOf } from "./UIObject"
6
+ import { UITextMeasurement } from "./UITextMeasurement"
6
7
  import { UIView, UIViewBroadcastEvent } from "./UIView"
7
8
 
8
9
 
@@ -40,6 +41,8 @@ export class UITextView extends UIView {
40
41
  static _pxToPt: number
41
42
  _text?: string
42
43
 
44
+ private _useFastMeasurement: boolean | undefined;
45
+
43
46
 
44
47
  constructor(
45
48
  elementID?: string,
@@ -204,30 +207,24 @@ export class UITextView extends UIView {
204
207
  }
205
208
 
206
209
  set text(text) {
207
-
208
210
  this._text = text
209
-
210
211
  var notificationText = ""
211
-
212
212
  if (this.notificationAmount) {
213
-
214
213
  notificationText = "<span style=\"color: " + UITextView.notificationTextColor.stringValue + ";\">" +
215
214
  (" (" + this.notificationAmount + ")").bold() + "</span>"
216
-
217
215
  }
218
216
 
219
217
  if (this.viewHTMLElement.innerHTML != this.textPrefix + text + this.textSuffix + notificationText) {
220
-
221
218
  this.viewHTMLElement.innerHTML = this.textPrefix + FIRST(text, "") + this.textSuffix + notificationText
222
-
223
219
  }
224
220
 
225
221
  if (this.changesOften) {
226
-
227
222
  this._intrinsicHeightCache = new UIObject() as any
228
223
  this._intrinsicWidthCache = new UIObject() as any
229
-
230
224
  }
225
+ // Invalidate measurement strategy when text changes significantly
226
+ this._useFastMeasurement = undefined;
227
+ this._intrinsicSizesCache = {};
231
228
 
232
229
  this.setNeedsLayout()
233
230
 
@@ -452,6 +449,73 @@ export class UITextView extends UIView {
452
449
  }
453
450
 
454
451
 
452
+ override intrinsicContentSizeWithConstraints(
453
+ constrainingHeight: number = 0,
454
+ constrainingWidth: number = 0
455
+ ): UIRectangle {
456
+ const cacheKey = "h_" + constrainingHeight + "__w_" + constrainingWidth;
457
+ const cachedResult = this._intrinsicSizesCache[cacheKey];
458
+ if (cachedResult) {
459
+ return cachedResult;
460
+ }
461
+
462
+ // Determine measurement strategy
463
+ const shouldUseFastPath = this._useFastMeasurement ?? this._shouldUseFastMeasurement();
464
+
465
+ let result: UIRectangle;
466
+
467
+ if (shouldUseFastPath) {
468
+ // Fast path: canvas-based measurement
469
+ const size = UITextMeasurement.calculateTextSize(
470
+ this.viewHTMLElement,
471
+ this.text || this.innerHTML,
472
+ constrainingWidth || undefined,
473
+ constrainingHeight || undefined
474
+ );
475
+ result = new UIRectangle(0, 0, size.height, size.width);
476
+ } else {
477
+ // Fallback: original DOM-based measurement for complex content
478
+ result = super.intrinsicContentSizeWithConstraints(constrainingHeight, constrainingWidth);
479
+ }
480
+
481
+ this._intrinsicSizesCache[cacheKey] = result.copy();
482
+ return result;
483
+ }
484
+
485
+ // Helper to determine if we can use fast measurement
486
+ private _shouldUseFastMeasurement(): boolean {
487
+ const content = this.text || this.innerHTML;
488
+
489
+ // If using dynamic innerHTML with parameters, use DOM measurement
490
+ if (this._innerHTMLKey || this._localizedTextObject) {
491
+ return false;
492
+ }
493
+
494
+ // Check for notification badges
495
+ if (this.notificationAmount > 0) {
496
+ return false; // Has span with colored text
497
+ }
498
+
499
+ // Check content complexity
500
+ const hasComplexHTML = /<(?!\/?(b|i|em|strong|span|br)\b)[^>]+>/i.test(content);
501
+
502
+ return !hasComplexHTML;
503
+ }
504
+
505
+ // Optional: Allow manual override for specific instances
506
+ setUseFastMeasurement(useFast: boolean): void {
507
+ this._useFastMeasurement = useFast;
508
+ this._intrinsicSizesCache = {};
509
+ }
510
+
511
+ // Optional: Force re-evaluation of measurement strategy
512
+ invalidateMeasurementStrategy(): void {
513
+ this._useFastMeasurement = undefined;
514
+ this._intrinsicSizesCache = {};
515
+ }
516
+
517
+
518
+
455
519
  override intrinsicContentSize() {
456
520
 
457
521
  // This works but is slow
package/scripts/UIView.ts CHANGED
@@ -223,7 +223,7 @@ export class UIView extends UIObject {
223
223
  static _onWindowMouseMove: (event: MouseEvent) => void = nil
224
224
  static _onWindowMouseup: (event: MouseEvent) => void = nil
225
225
  private _resizeObserverEntry?: ResizeObserverEntry
226
- private _intrinsicSizesCache: Record<string, UIRectangle> = {}
226
+ protected _intrinsicSizesCache: Record<string, UIRectangle> = {}
227
227
 
228
228
 
229
229
  constructor(