targetj 1.1.4 → 1.1.6

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/Export.js CHANGED
@@ -24,6 +24,7 @@ export * from "./build/ParticleChild.js";
24
24
  export * from "./build/ParticleRenderer.js";
25
25
  export * from "./build/ParticleRuntime.js";
26
26
  export * from "./build/ParticleUtil.js";
27
+ export * from "./build/HtmlToCanvas.js";
27
28
 
28
29
  import * as AppModule from "./build/App.js";
29
30
  import * as TModelModule from "./build/TModel.js";
@@ -51,6 +52,7 @@ import * as ParticleChildModule from "./build/ParticleChild.js";
51
52
  import * as ParticleRendererModule from "./build/ParticleRenderer.js";
52
53
  import * as ParticleRuntimeModule from "./build/ParticleRuntime.js";
53
54
  import * as ParticleUtilModule from "./build/ParticleUtil.js";
55
+ import * as HtmlToCanvasModule from "./build/HtmlToCanvas.js";
54
56
 
55
57
  const TargetJS = {
56
58
  ...AppModule,
@@ -78,7 +80,8 @@ const TargetJS = {
78
80
  ...ParticleChildModule,
79
81
  ...ParticleRendererModule,
80
82
  ...ParticleRuntimeModule,
81
- ...ParticleUtilModule
83
+ ...ParticleUtilModule,
84
+ ...HtmlToCanvas
82
85
  };
83
86
 
84
87
  if (typeof window !== "undefined") {
package/build/$Dom.js CHANGED
@@ -697,14 +697,24 @@ var $Dom = /*#__PURE__*/function () {
697
697
  }).join('&');
698
698
  }
699
699
  xhr.onreadystatechange = function () {
700
- if (xhr.readyState === 4) {
701
- if (xhr.status === 200) {
702
- var response = query.dataType === 'json' ? JSON.parse(this.responseText) : this.responseText;
703
- query.success(response);
704
- } else {
705
- query.error(xhr.status);
700
+ if (xhr.readyState !== 4) {
701
+ return;
702
+ }
703
+ if (xhr.status < 200 || xhr.status >= 300) {
704
+ query.error(xhr.status);
705
+ return;
706
+ }
707
+ var response = xhr.responseText;
708
+ if (query.dataType === 'json') {
709
+ try {
710
+ response = response.trim() ? JSON.parse(response) : null;
711
+ } catch (error) {
712
+ console.error('Invalid JSON response:', xhr.responseURL, error);
713
+ query.error(error);
714
+ return;
706
715
  }
707
716
  }
717
+ query.success(response);
708
718
  };
709
719
  if (query.type === 'POST') {
710
720
  xhr.open(query.type, query.url, true);
@@ -3,6 +3,8 @@ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread n
3
3
  function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
4
4
  function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
5
5
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
6
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
8
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
7
9
  function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
8
10
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -301,7 +303,23 @@ var BaseModel = /*#__PURE__*/function () {
301
303
  if (doesNextTargetUsePrevValue || isInactiveKey || isExternalEvent || isInternalEvent || targetType === 'object' || targetType === 'function') {
302
304
  if (!TUtil.isDefined(target.value) && !TargetParser.isChildObjectTarget(key, target) && !TargetParser.isIntervalTarget(target)) {
303
305
  needsTargetExecution = true;
304
- target = TargetUtil.wrapTarget(this, target, key);
306
+ var value = _objectSpread({}, target);
307
+ target = TargetUtil.wrapTarget(this, value, key);
308
+ var _iterator = _createForOfIteratorHelper(TargetData.lifecycleCallbackSet),
309
+ _step;
310
+ try {
311
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
312
+ var name = _step.value;
313
+ if (Object.hasOwn(value, name)) {
314
+ target[name] = value[name];
315
+ delete value[name];
316
+ }
317
+ }
318
+ } catch (err) {
319
+ _iterator.e(err);
320
+ } finally {
321
+ _iterator.f();
322
+ }
305
323
  }
306
324
  TargetUtil.bindTarget(this, key, prevKey, nextKey, keyIndex);
307
325
  }
@@ -434,7 +452,7 @@ var BaseModel = /*#__PURE__*/function () {
434
452
  this.calcAbsolutePosition(this.getX(), this.getY());
435
453
  }
436
454
  } else if (key === 'width' || key === 'height') {
437
- var dimension = Math.floor(key === 'width' ? this.getWidth() : this.getHeight());
455
+ var dimension = Math.floor(key === 'width' ? this.val('width') : this.val('height'));
438
456
  if (this.styleMap[key] === dimension) {
439
457
  styleFlag = false;
440
458
  }
@@ -816,12 +834,12 @@ var BaseModel = /*#__PURE__*/function () {
816
834
  return false;
817
835
  }
818
836
  var activated = false;
819
- var _iterator = _createForOfIteratorHelper(this.passiveTargetList),
820
- _step;
837
+ var _iterator2 = _createForOfIteratorHelper(this.passiveTargetList),
838
+ _step2;
821
839
  try {
822
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
840
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
823
841
  var _this$animatingMap;
824
- var key = _step.value;
842
+ var key = _step2.value;
825
843
  if (!this.isTargetPassiveLoop(key)) {
826
844
  continue;
827
845
  }
@@ -836,9 +854,9 @@ var BaseModel = /*#__PURE__*/function () {
836
854
  activated = true;
837
855
  }
838
856
  } catch (err) {
839
- _iterator.e(err);
857
+ _iterator2.e(err);
840
858
  } finally {
841
- _iterator.f();
859
+ _iterator2.f();
842
860
  }
843
861
  return activated;
844
862
  }
@@ -1104,12 +1122,12 @@ var BaseModel = /*#__PURE__*/function () {
1104
1122
  value: function hasUpdatingImperativeTargets(originalTargetName) {
1105
1123
  var _this$updatingTargetL;
1106
1124
  var updatingList = [].concat(_toConsumableArray((_this$updatingTargetL = this.updatingTargetList) !== null && _this$updatingTargetL !== void 0 ? _this$updatingTargetL : []), _toConsumableArray(this.hasAnimatingTargets() ? _toConsumableArray(this.animatingMap.keys()) : []));
1107
- var _iterator2 = _createForOfIteratorHelper(updatingList),
1108
- _step2;
1125
+ var _iterator3 = _createForOfIteratorHelper(updatingList),
1126
+ _step3;
1109
1127
  try {
1110
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1128
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1111
1129
  var _this$targetValues$ta;
1112
- var target = _step2.value;
1130
+ var target = _step3.value;
1113
1131
  if (!this.isTargetImperative(target)) {
1114
1132
  continue;
1115
1133
  }
@@ -1118,9 +1136,9 @@ var BaseModel = /*#__PURE__*/function () {
1118
1136
  }
1119
1137
  }
1120
1138
  } catch (err) {
1121
- _iterator2.e(err);
1139
+ _iterator3.e(err);
1122
1140
  } finally {
1123
- _iterator2.f();
1141
+ _iterator3.f();
1124
1142
  }
1125
1143
  return false;
1126
1144
  }
@@ -1130,12 +1148,12 @@ var BaseModel = /*#__PURE__*/function () {
1130
1148
  var _this$updatingTargetL2;
1131
1149
  var updatingList = [].concat(_toConsumableArray((_this$updatingTargetL2 = this.updatingTargetList) !== null && _this$updatingTargetL2 !== void 0 ? _this$updatingTargetL2 : []), _toConsumableArray(this.hasAnimatingTargets() ? _toConsumableArray(this.animatingMap.keys()) : []));
1132
1150
  var targets = [];
1133
- var _iterator3 = _createForOfIteratorHelper(updatingList),
1134
- _step3;
1151
+ var _iterator4 = _createForOfIteratorHelper(updatingList),
1152
+ _step4;
1135
1153
  try {
1136
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1154
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1137
1155
  var _this$targetValues$ta2;
1138
- var target = _step3.value;
1156
+ var target = _step4.value;
1139
1157
  if (!this.isTargetImperative(target)) {
1140
1158
  continue;
1141
1159
  }
@@ -1144,9 +1162,9 @@ var BaseModel = /*#__PURE__*/function () {
1144
1162
  }
1145
1163
  }
1146
1164
  } catch (err) {
1147
- _iterator3.e(err);
1165
+ _iterator4.e(err);
1148
1166
  } finally {
1149
- _iterator3.f();
1167
+ _iterator4.f();
1150
1168
  }
1151
1169
  return targets;
1152
1170
  }
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";
@@ -34,7 +34,7 @@ import { DomInit } from "./DomInit.js";
34
34
  import { StateUtil } from "./StateUtil.js";
35
35
  import { TModelFactory } from "./TModelFactory.js";
36
36
  import { ParticleExplode } from "./ParticleExplode.js";
37
- import { HtmlToCanvas } from "./htmlToCanvas.js";
37
+ import { HtmlToCanvas } from "./HtmlToCanvas.js";
38
38
 
39
39
  /**
40
40
  * It provides the base class for all objects in an app where targets are defined.
@@ -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
  }();
package/build/index.js CHANGED
@@ -23,4 +23,5 @@ export * from "./ParticleTModel.js";
23
23
  export * from "./ParticleChild.js";
24
24
  export * from "./ParticleRenderer.js";
25
25
  export * from "./ParticleRuntime.js";
26
- export * from "./ParticleUtil.js";
26
+ export * from "./ParticleUtil.js";
27
+ export * from "./HtmlToCanvas.js";