targetj 1.1.4 → 1.1.5

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.
@@ -434,7 +434,7 @@ var BaseModel = /*#__PURE__*/function () {
434
434
  this.calcAbsolutePosition(this.getX(), this.getY());
435
435
  }
436
436
  } else if (key === 'width' || key === 'height') {
437
- var dimension = Math.floor(key === 'width' ? this.getWidth() : this.getHeight());
437
+ var dimension = Math.floor(key === 'width' ? this.val('width') : this.val('height'));
438
438
  if (this.styleMap[key] === dimension) {
439
439
  styleFlag = false;
440
440
  }
package/build/TModel.js CHANGED
@@ -22,7 +22,7 @@ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? O
22
22
  function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
23
23
  function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
24
24
  import { BaseModel } from "./BaseModel.js";
25
- import { App, getLocationManager, getRunScheduler, getEvents, getManager } from "./App.js";
25
+ import { App, getLocationManager, getRunScheduler, getEvents, getManager, getScreenWidth, getScreenHeight } from "./App.js";
26
26
  import { Viewport } from "./Viewport.js";
27
27
  import { TUtil } from "./TUtil.js";
28
28
  import { VisibilityUtil } from "./VisibilityUtil.js";
@@ -907,7 +907,7 @@ var TModel = /*#__PURE__*/function (_BaseModel) {
907
907
  key: "getLayoutHeight",
908
908
  value: function getLayoutHeight() {
909
909
  var height = this.getHeight();
910
- if (this.usesContentBoxSizing()) {
910
+ if (!this.isDomIsland() && this.usesContentBoxSizing()) {
911
911
  height += this.getPaddingTop() + this.getPaddingBottom();
912
912
  }
913
913
  return height;
@@ -916,7 +916,7 @@ var TModel = /*#__PURE__*/function (_BaseModel) {
916
916
  key: "getLayoutWidth",
917
917
  value: function getLayoutWidth() {
918
918
  var width = this.getWidth();
919
- if (this.usesContentBoxSizing()) {
919
+ if (!this.isDomIsland() && this.usesContentBoxSizing()) {
920
920
  width += this.getPaddingLeft() + this.getPaddingRight();
921
921
  }
922
922
  return width;
@@ -1200,24 +1200,34 @@ var TModel = /*#__PURE__*/function (_BaseModel) {
1200
1200
  }, {
1201
1201
  key: "getWidth",
1202
1202
  value: function getWidth() {
1203
- if (TUtil.isDefined(this.targets.width) || TUtil.isDefined(this.targetValues.width)) {
1204
- return this.val("width");
1203
+ if (this.isDomIsland() && this.domIslandSize) {
1204
+ return this.domIslandSize.width;
1205
1205
  }
1206
- if (TUtil.isDefined(this.targets.dim) || TUtil.isDefined(this.targetValues.dim)) {
1207
- return this.val("dim");
1206
+ var hasWidth = TUtil.isDefined(this.targets.width) || TUtil.isDefined(this.targetValues.width);
1207
+ var hasDim = TUtil.isDefined(this.targets.dim) || TUtil.isDefined(this.targetValues.dim);
1208
+ var value = this.val(!hasWidth && hasDim ? 'dim' : 'width');
1209
+ if (typeof value !== 'string') {
1210
+ return value;
1208
1211
  }
1209
- return this.val("width");
1212
+ var parent = this.getRealParent();
1213
+ var parentWidth = parent ? parent.getWidth() : getScreenWidth();
1214
+ return TModelUtil.resolveDimension(value, parentWidth);
1210
1215
  }
1211
1216
  }, {
1212
1217
  key: "getHeight",
1213
1218
  value: function getHeight() {
1214
- if (TUtil.isDefined(this.targets.height) || TUtil.isDefined(this.targetValues.height)) {
1215
- return this.val("height");
1219
+ if (this.isDomIsland() && this.domIslandSize) {
1220
+ return this.domIslandSize.height;
1216
1221
  }
1217
- if (TUtil.isDefined(this.targets.dim) || TUtil.isDefined(this.targetValues.dim)) {
1218
- return this.val("dim");
1222
+ var hasHeight = TUtil.isDefined(this.targets.height) || TUtil.isDefined(this.targetValues.height);
1223
+ var hasDim = TUtil.isDefined(this.targets.dim) || TUtil.isDefined(this.targetValues.dim);
1224
+ var value = this.val(!hasHeight && hasDim ? 'dim' : 'height');
1225
+ if (typeof value !== 'string') {
1226
+ return value;
1219
1227
  }
1220
- return this.val("height");
1228
+ var parent = this.getRealParent();
1229
+ var parentHeight = parent ? parent.getHeight() : getScreenHeight();
1230
+ return TModelUtil.resolveDimension(value, parentHeight);
1221
1231
  }
1222
1232
  }, {
1223
1233
  key: "getScrollTop",
@@ -548,27 +548,11 @@ var TModelUtil = /*#__PURE__*/function () {
548
548
  transformUpdate = true;
549
549
  }
550
550
  } else if (key === 'dim') {
551
- var dim = Math.floor(tmodel.val('dim'));
552
- if (tmodel.styleMap['height'] !== dim || tmodel.$dom.getStyleValue('height') !== dim) {
553
- tmodel.styleMap['height'] = dim;
554
- tmodel.$dom.height(dim);
555
- }
556
- if (tmodel.styleMap['width'] !== dim || tmodel.$dom.getStyleValue('width') !== dim) {
557
- tmodel.styleMap['width'] = dim;
558
- tmodel.$dom.width(dim);
559
- }
560
- } else if (key === 'width') {
561
- var width = Math.floor(tmodel.getWidth());
562
- if (tmodel.styleMap['width'] !== width || tmodel.$dom.getStyleValue('width') !== width) {
563
- tmodel.styleMap['width'] = width;
564
- tmodel.$dom.width(width);
565
- }
566
- } else if (key === 'height') {
567
- var height = Math.floor(tmodel.getHeight());
568
- if (tmodel.styleMap['height'] !== height || tmodel.$dom.getStyleValue('height') !== height) {
569
- tmodel.styleMap['height'] = height;
570
- tmodel.$dom.height(height);
571
- }
551
+ var dim = tmodel.val('dim');
552
+ TModelUtil.applyDimensionStyle(tmodel, 'width', dim);
553
+ TModelUtil.applyDimensionStyle(tmodel, 'height', dim);
554
+ } else if (key === 'width' || key === 'height') {
555
+ TModelUtil.applyDimensionStyle(tmodel, key, tmodel.val(key));
572
556
  } else if (TargetData.styleWithUnitMap[key]) {
573
557
  if (TUtil.isDefined(tmodel.val(key)) && tmodel.styleMap[key] !== tmodel.val(key)) {
574
558
  tmodel.$dom.style(key, TUtil.isNumber(tmodel.val(key)) ? "".concat(tmodel.val(key), "px") : tmodel.val(key));
@@ -586,6 +570,58 @@ var TModelUtil = /*#__PURE__*/function () {
586
570
  }
587
571
  tmodel.styleTargetMap.clear();
588
572
  }
573
+ }, {
574
+ key: "applyDimensionStyle",
575
+ value: function applyDimensionStyle(tmodel, key, value) {
576
+ if (!TUtil.isDefined(value)) {
577
+ return;
578
+ }
579
+ var cssValue = typeof value === 'number' ? "".concat(Math.floor(value), "px") : value;
580
+ if (tmodel.styleMap[key] !== value || tmodel.$dom.style(key) !== cssValue) {
581
+ tmodel.styleMap[key] = value;
582
+ tmodel.$dom.style(key, cssValue);
583
+ if (tmodel.isDomIsland()) {
584
+ tmodel.originWindowEpoch = -1;
585
+ getRunScheduler().schedule(1, 'domIslandDimensionStyle');
586
+ }
587
+ }
588
+ }
589
+ }, {
590
+ key: "resolveDimension",
591
+ value: function resolveDimension(value, parentSize) {
592
+ if (typeof value !== 'string') {
593
+ return value;
594
+ }
595
+ var str = value.trim();
596
+ var single = /^([+-]?(?:\d+\.?\d*|\.\d+))(px|%)$/i.exec(str);
597
+ var convert = function convert(term) {
598
+ var number = parseFloat(term);
599
+ if (term.endsWith('%')) {
600
+ if (!Number.isFinite(parentSize)) {
601
+ throw new Error("Percentage dimension requires a definite parent size: ".concat(value));
602
+ }
603
+ return number * parentSize / 100;
604
+ }
605
+ return number;
606
+ };
607
+ if (single) {
608
+ return convert(str);
609
+ }
610
+ var calc = /^calc\((.*)\)$/i.exec(str);
611
+ if (!calc) {
612
+ throw new Error("Unsupported dimension: ".concat(value));
613
+ }
614
+ var expression = calc[1].replace(/\s+/g, '');
615
+ var terms = expression.match(/[+-]?(?:\d+\.?\d*|\.\d+)(?:%|px)/gi);
616
+ if (!terms || terms.join('') !== expression || terms.slice(1).some(function (term) {
617
+ return !/^[+-]/.test(term);
618
+ })) {
619
+ throw new Error("Unsupported calc expression: ".concat(value));
620
+ }
621
+ return terms.reduce(function (total, term) {
622
+ return total + convert(term);
623
+ }, 0);
624
+ }
589
625
  }, {
590
626
  key: "commitAnimatedStyles",
591
627
  value: function commitAnimatedStyles(tmodel, originalKeys) {
@@ -611,24 +647,13 @@ var TModelUtil = /*#__PURE__*/function () {
611
647
  }
612
648
  continue;
613
649
  }
614
- if (key === "dim") {
615
- var dim = Math.floor(value);
616
- tmodel.styleMap.width = dim;
617
- tmodel.styleMap.height = dim;
618
- tmodel.$dom.width(dim);
619
- tmodel.$dom.height(dim);
620
- continue;
621
- }
622
- if (key === "width") {
623
- var width = Math.floor(value);
624
- tmodel.styleMap.width = width;
625
- tmodel.$dom.width(width);
650
+ if (key === 'dim') {
651
+ TModelUtil.applyDimensionStyle(tmodel, 'width', value);
652
+ TModelUtil.applyDimensionStyle(tmodel, 'height', value);
626
653
  continue;
627
654
  }
628
- if (key === "height") {
629
- var height = Math.floor(value);
630
- tmodel.styleMap.height = height;
631
- tmodel.$dom.height(height);
655
+ if (key === 'width' || key === 'height') {
656
+ TModelUtil.applyDimensionStyle(tmodel, key, value);
632
657
  continue;
633
658
  }
634
659
  var styleValue = typeof value === "number" && TargetData.styleWithUnitMap[key] ? "".concat(value, "px") : "".concat(value);
@@ -736,10 +761,10 @@ var TModelUtil = /*#__PURE__*/function () {
736
761
  if (TUtil.isDefined(style) && tmodel.styleMap.style !== style) {
737
762
  tmodel.$dom.setStyleByMap(style);
738
763
  if (style.height) {
739
- tmodel.val('height', parseInt(style.height, 10));
764
+ tmodel.val('height', style.height);
740
765
  }
741
766
  if (style.width) {
742
- tmodel.val('width', parseInt(style.width, 10));
767
+ tmodel.val('width', style.width);
743
768
  }
744
769
  tmodel.styleMap.style = style;
745
770
  }
@@ -1095,6 +1120,17 @@ var TModelUtil = /*#__PURE__*/function () {
1095
1120
  tmodel.absY = rect.top;
1096
1121
  tmodel.markLayoutDirty('islandAbsXY');
1097
1122
  }
1123
+ var size = tmodel.domIslandSize;
1124
+ if (!size || size.width !== rect.width || size.height !== rect.height) {
1125
+ tmodel.domIslandSize = {
1126
+ width: rect.width,
1127
+ height: rect.height
1128
+ };
1129
+ var now = TUtil.now();
1130
+ tmodel.domWidthTimestamp = now;
1131
+ tmodel.domHeightTimestamp = now;
1132
+ tmodel.markLayoutDirty('islandDimensions');
1133
+ }
1098
1134
  }
1099
1135
  }]);
1100
1136
  }();