targetj 1.0.69 → 1.0.70

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/README.md CHANGED
@@ -4,28 +4,66 @@ Welcome to TargetJ, a powerful JavaScript UI framework designed to simplify deve
4
4
 
5
5
  TargetJ distinguishes itself by introducing a novel concept known as 'targets', which forms its core. Targets are used as the main building blocks of components instead of direct variables and methods. Each component in TargetJ is a set of targets. Targets are employed across all aspects of the program. They are used in animation, controlling program flow, loading data from external APIs, handling user events, and more.
6
6
 
7
+ ## What is a target?
8
+
9
+ Targets enhance variables by enabling them to iterate until they reach the specified value, rather than being immediately assigned their values. They can also introduce pauses between each iteration and provide various callbacks, allowing you to track the progress of the variables as well as the progress of other variables. Similarly, targets enhance methods by introducing conditions for execution, controlling the number of executions, and offering the same capabilities as those applied to variables.
10
+
11
+ Each target consists of the following:
12
+ 1. Target Value and Actual Value. The target Value can be either be a static value or a method represented by the value method. The actual Value is always represented as a value. When the target value differs from the actual value, TargetJ iteratively updates the actual value until it matches the target value. This process is controlled by two additional variables: Step which dictates the number of iterations, and Interval which specifies the duration (in milliseconds) that the system waits before executing the next iteration.
13
+
14
+ 2. State: Targets have three states that control their lifecycle: active, updating, and complete. Active: Indicates that the target value is being initialized or the target has not been executed yet. Updating: Indicates that the actual value is being updated to reach the target value. Complete: Indicates that the target execution is finished, and the actual value equals the target value.
15
+
16
+ 3. Target Methods: All methods are optional. They are used to control the lifecycle of targets or serve as callbacks to reflect changes. The controlling methods are: enabledOn, loop, steps, cycles. The callbacks are: onValueChange, onStepsEnd, onImperativeStep, onImperativeEnd.
17
+
7
18
  ## Brief overview of how it operates
8
19
 
9
- Each target in TargetJ essentially has two variables: target and actual. When the target value does not equal the actual value, TargetJ will update the actual value iteratively until it matches the target value. This iteration is determined by two additional variables: steps and step interval. Steps dictate the number of iterations, and the step interval specifies the duration in milliseconds that the system waits before executing the next iteration.
20
+ Here's a brief and condensed overview of how it operates: The target task monitors all active targets. If a target is enabled, it will be executed. The target value is generated based on either the result of the value method or the static value defined in the targets. In simple targets with no steps, the actual value is immediately set based on the target value. Once a target is executed, its state becomes complete, and it will not be executed again.
10
21
 
11
- To animate a variable, create a target after its name. The variable can be of any type: boolean, number, string, object, or array.
22
+ If the target has loop or cycles methods defined, the value method of the target will be executed again after a pause specified by the interval. The number of executions will be based on the cycles or as long as the loop returns true. If the target has steps defined, its state will change to updating, and the actual value will be updated till it reaches its target value. It will be updated iteratively according to the number of steps and pauses specified by steps and intervals.
12
23
 
13
24
  ## Target life cycle and methods
14
25
 
15
- By default, a target in TargetJ has a simple life cycle: it executes only once. However, targets come with a number of methods that control execution and extend their behavior.
26
+ By default, a target has a simple life cycle, executing only once. However, several methods can extend its life cycle, allowing it to execute multiple times, add pauses between executions, control how the actual value is updated to reach the target value, and trigger various callbacks based on specific conditions during the extended cycle:
16
27
 
17
28
  1. **onEnabled**
18
- Determines whether the target is eligible for execution. Targets remain inactive until enabled. This method ensures that targets are executed only under suitable conditions and are commonly used to establish dependencies between targets, ensuring they execute at precisely the right moment.
29
+ Determines whether the target is eligible for execution. If enabledOn() returns false, the target remains active until it is enabled and gets executed.
19
30
 
20
31
  2. **loop**
21
- Controls the repetition of target execution. If loop() returns true, the target will stay active and continue to execute indefinitely. It will become inactive and stop executing when it returns false.
32
+ Controls the repetition of target execution. If loop() returns true, the target will continue to execute indefinitely. It can also be defined as a boolean instead of a method.
33
+
34
+ 3. **cycles**
35
+ Its purpose is similar to loop, but the number of repetitions is specified explicitly as a number.
36
+
37
+ 4. **interval**
38
+ It specifies the pause between each target execution or each actual value update when steps are defined.
39
+
40
+ 5. **steps**
41
+ By default, the actual value is updated immediately after the target value. The steps option allows the actual value to be updated in iterations specified by the number of steps.
42
+
43
+ 6. **easing**
44
+ An easing function that operates when steps are defined. It controls how the actual value is updated in relation to the steps.
45
+
46
+ 8. **onValueChange**
47
+ This callbak is triggered whenever there is a change returned by the target value().
48
+
49
+ 9. **onStepsEnd**
50
+ This method is invoked only after the final step of updating the actual value is completed, assuming the target has a defined steps value.
51
+
52
+ 10. **onImperativeStep**
53
+ onImperativeStep() This callback tracks the progress of imperative targets defined inside the declarative target. If there are multiple imperative targets, this method is called at every step, identifiable by their target name. It allows for easy orchestration between several targets.
54
+
55
+ 11. **onImperativeEnd**
56
+ It is similar to onImperativeStep, but it is called when the imperative target is completed.
57
+
58
+ ## Declarative and imperative targets
59
+
60
+ Targets in TargetJ can be defined in two ways: declaratively or imperatively.
22
61
 
23
- 3. **onValueChange**
24
- Monitors changes in the value returned by the main value() for the target. It is triggered whenever there is a change in the value returned by value(). This could be used, for example, to wait for asynchronous responses.
62
+ The declarative approach offers a structured way to define targets. However, orchestrating multiple targets simultaneously can be challenging, especially when each target has different speed and timing requirements that depend on each other.
25
63
 
26
- 4. **onStepsEnd**
27
- Executes actions after all increments are completed. This method is invoked only after the final step is executed, assuming the target has a defined steps value. It's useful for cleanup or finalization tasks after a sequence of steps.
64
+ To address this, TargetJ provides a way to call imperative targets using the setTarget function. This allows you to set multiple targets from one declarative target. Additionally, it offers onImperativeStep and onImperativeEnd callbacks, which enable declarative targets to track every step of each imperative target or just their completion.
28
65
 
66
+ By combining both declarative and imperative targets, you gain a powerful toolset for designing complex interactions.
29
67
 
30
68
  ## Special target names used by TargetJ
31
69
 
@@ -48,6 +86,11 @@ The following are special target names to impact the UI or control properties of
48
86
  15. textOnly: A boolean flag that sets the type of content to be text or HTML.
49
87
  16. canBeBracketed: A boolean flag that controls if the object will be optimized and included in the TargetJ task process only when visible.
50
88
  17. isInFlow: A boolean flag that determines if the object will be used to calculate the content height and width of its parent.
89
+ 18. onResize: An array of targets that will be reset and re-executed after a resize event.
90
+ 19. onClickEvent: An array of targets that will be reset and re-executed after a click event.
91
+ 20. onTouchEvent: An array of targets that will be reset and re-executed after a touch event.
92
+ 21. onScrollEvent: An array of targets that will be reset and re-executed after a scroll event.
93
+ 22. onKeyEvent: An array of targets that will be reset and re-executed after a key event.
51
94
 
52
95
  ## Features
53
96
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "targetj",
3
- "version": "1.0.69",
3
+ "version": "1.0.70",
4
4
  "keywords": [
5
5
  "targetj"
6
6
  ],
package/src/Moves.js CHANGED
@@ -1,19 +1,44 @@
1
1
  import { Easing } from "./Easing.js";
2
+ import { getScreenWidth } from "./App.js";
2
3
 
3
4
  function Moves() {}
4
5
 
5
- Moves.bounce = function (from, to, bounceFactor) {
6
+ Moves.bounce = function (from, to, initialX, initialWidth, initialHeight, bounceFactor, compressionFactor) {
7
+
8
+ initialX = initialX || getScreenWidth() / 2;
9
+ initialWidth = initialWidth || 50;
10
+ initialHeight = initialHeight || 50;
6
11
  bounceFactor = bounceFactor || 0.6;
7
12
 
13
+ compressionFactor = compressionFactor || 0.2;
14
+
8
15
  var bounce = to * bounceFactor;
9
- var moves = [from];
16
+ var ys = [from];
17
+ var xs = [initialX];
18
+ var widths = [initialWidth];
19
+ var heights = [initialHeight];
20
+
10
21
  while ((bounce | 0) > 1) {
11
- moves.push(to);
12
- moves.push(to - bounce);
13
- bounce *= 0.5;
22
+ ys.push(to);
23
+ ys.push(to - bounce);
24
+
25
+ var compressedWidth = initialWidth * (1 + compressionFactor);
26
+ var compressedHeight = initialHeight * (1 - compressionFactor);
27
+
28
+ widths.push(compressedWidth);
29
+ widths.push(initialWidth);
30
+
31
+ heights.push(compressedHeight);
32
+ heights.push(initialHeight);
33
+
34
+ xs.push(initialX - (compressedWidth - initialWidth) / 2);
35
+ xs.push(initialX);
36
+
37
+ bounce *= bounceFactor;
38
+ compressionFactor *= bounceFactor;
14
39
  }
15
40
 
16
- return moves;
41
+ return { x: xs, y: ys, width: widths, height: heights };
17
42
  };
18
43
 
19
44
  Moves.spiral = function (startAngle, endAngle, angleStep, x, y, width, height) {
package/src/TModel.js CHANGED
@@ -63,6 +63,7 @@ function TModel(type, targets) {
63
63
  calculateChildren: undefined,
64
64
  isVisible: undefined,
65
65
  onResize: undefined,
66
+ onClickEvent: undefined,
66
67
  onTouchEvent: undefined,
67
68
  onScrollEvent: undefined,
68
69
  onKeyEvent: undefined
@@ -541,27 +542,16 @@ TModel.prototype.updateTargetStatus = function(key) {
541
542
  } else {
542
543
  this.targetValues[key].status = 'done';
543
544
  }
544
-
545
- var parent = this.getParent();
546
-
545
+
547
546
  if (this.isTargetUpdating(key)) {
548
547
  this.addToUpdatingTargets(key);
549
548
  this.removeFromActiveTargets(key);
550
- if (parent) {
551
- parent.addToUpdatingChildren(this);
552
- }
553
549
  } else if (this.isTargetActive(key)) {
554
550
  this.addToActiveTargets(key);
555
551
  this.removeFromUpdatingTargets(key);
556
- if (parent && this.updatingTargetList.length === 0) {
557
- parent.removeFromUpdatingChildren(this);
558
- }
559
552
  } else {
560
553
  this.removeFromActiveTargets(key);
561
554
  this.removeFromUpdatingTargets(key);
562
- if (parent && this.updatingTargetList.length === 0) {
563
- parent.removeFromUpdatingChildren(this);
564
- }
565
555
  tapp.manager.doneTargets.push({ tmodel: this, key: key });
566
556
  }
567
557
  return this.targetValues[key].status;
@@ -857,6 +847,9 @@ TModel.prototype.addToUpdatingTargets = function(key) {
857
847
  if (!this.updatingTargetMap[key]) {
858
848
  this.updatingTargetMap[key] = true;
859
849
  this.updatingTargetList.push(key);
850
+ if (this.getParent()) {
851
+ this.getParent().addToUpdatingChildren(this);
852
+ }
860
853
  }
861
854
  };
862
855
 
@@ -866,6 +859,9 @@ TModel.prototype.removeFromUpdatingTargets = function(key) {
866
859
  var index = this.updatingTargetList.indexOf(key);
867
860
  if (index >= 0) {
868
861
  this.updatingTargetList.splice(index, 1);
862
+ }
863
+ if (this.updatingTargetList.length === 0 && this.getParent()) {
864
+ this.getParent().removeFromUpdatingChildren(this);
869
865
  }
870
866
  }
871
867
  };
@@ -340,10 +340,7 @@ TModelManager.prototype.completeDoneTModels = function() {
340
340
  if (tmodel.isTargetDone(key)) {
341
341
  tmodel.setTargetComplete(key);
342
342
  tmodel.removeFromActiveTargets(tmodel);
343
- tmodel.removeFromUpdatingTargets(tmodel);
344
- if (tmodel.getParent() && tmodel.updatingTargetList.length === 0) {
345
- tmodel.getParent().removeFromUpdatingChildren(tmodel);
346
- }
343
+ tmodel.removeFromUpdatingTargets(tmodel);
347
344
  }
348
345
  });
349
346
  };