targetj 1.0.257 → 1.0.258
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 +40 -25
- package/build/App.js +31 -27
- package/dist/targetjs.js +1 -1
- package/dist/targetjs.js.gz +0 -0
- package/package.json +22 -6
- package/types/index.d.ts +303 -0
package/README.md
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
# TargetJS: State
|
|
1
|
+
# TargetJS: State Includes the Journey
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Code order defines the UI sequence.**
|
|
4
|
+
|
|
5
|
+
Most frameworks are great at rendering state. TargetJS is designed for the journey between states.
|
|
4
6
|
|
|
5
7
|
**[targetjs.io](https://targetjs.io)**
|
|
6
8
|
[](https://github.com/livetrails/targetjs/blob/main/LICENSE)
|
|
7
9
|
[](https://github.com/livetrails/targetjs/stargazers)
|
|
8
10
|
[](https://www.npmjs.com/package/targetj)
|
|
9
11
|
|
|
10
|
-
TargetJS is a JavaScript UI framework that replaces the "State → Render" model with "State → Transition → Render".
|
|
12
|
+
TargetJS is a JavaScript UI framework that replaces the "State → Render" model with "State → Transition → Render".
|
|
13
|
+
|
|
14
|
+
Transitions are part of the state itself. This allows the entire UI, including an animation in progress, to be captured and later restored from the exact point at which it was saved.
|
|
11
15
|
|
|
12
16
|
TargetJS also lets code order directly define the UI sequence. UI, transitions, API calls, event handling, and state are unified into self-contained Targets that chain together through Code-Ordered Reactivity.
|
|
13
17
|
|
|
@@ -16,15 +20,15 @@ It can be used as a full-featured framework or as a lightweight library alongsid
|
|
|
16
20
|
|
|
17
21
|
## What problems TargetJS solves
|
|
18
22
|
|
|
19
|
-
**UI frameworks model the final result, not transition**
|
|
23
|
+
**UI frameworks model the final result, not the transition**
|
|
20
24
|
|
|
21
25
|
Traditional frameworks model the UI as a function of state: change state, re-render the UI. When state changes from A → B, the UI immediately jumps to B. The framework doesn’t naturally represent the journey from A → B. But modern, rich user experiences are more like: A → transition → B.
|
|
22
26
|
|
|
23
|
-
TargetJS
|
|
27
|
+
TargetJS makes that transition part of the state change itself. Values are not limited to being assigned immediately. They can move toward their destination over configurable steps, intervals, and easing. Transitions therefore become a native part of the UI model rather than effects added after rendering. TargetJS also delivers CSS-level transition efficiency.
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
Because each Target has its own lifecycle, transitions can also adapt dynamically. For example, pausing when an element leaves the screen or changing speed on scroll.
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
Since the transition belongs to the runtime state, the UI can be captured while a transition is in progress. That state can later be restored, allowing the transition to resume from the point at which it was saved.
|
|
28
32
|
|
|
29
33
|
**Fragmentation across multiple mental models**
|
|
30
34
|
|
|
@@ -47,11 +51,12 @@ With its compact style, TargetJS makes the journey from A → B explicit and eff
|
|
|
47
51
|
## 🚀 Why TargetJS?
|
|
48
52
|
|
|
49
53
|
1. Unified State: One single state. Transitions are state too.
|
|
50
|
-
1. Adaptive Transitions: Transitions can pause, resume, change speed, and respond to input.
|
|
54
|
+
1. Adaptive Transitions: Transitions can pause, resume, change speed, and respond to input.
|
|
55
|
+
1. Restorable UI: Capture the UI during a transition and later resume the complete state including the transition from the saved point.
|
|
51
56
|
1. UI as Sequence: Code describes the UI story from top to bottom, just like the user experiences the interaction: "When this finishes, do that."
|
|
52
57
|
1. Ultra-Compact: Minimal code, with no coordination variables.
|
|
53
58
|
1. Zero Boilerplate Async: Targets handle waiting for nested asynchronous operations automatically.
|
|
54
|
-
1. Animation by Default:
|
|
59
|
+
1. Animation by Default: Turn value into high-performance animations simply by adding `steps`.
|
|
55
60
|
|
|
56
61
|
## ⚡ Quick Start (30 Seconds)
|
|
57
62
|
|
|
@@ -71,28 +76,36 @@ bounce → move → turn red → log
|
|
|
71
76
|
|
|
72
77
|
Notice how the code reads in the same order as the UI sequence. The `$$` suffix makes each target wait for all preceding targets to complete.
|
|
73
78
|
|
|
74
|
-
There is only one state, and transitions are part of that state.
|
|
79
|
+
There is only one state, and the transitions are part of that state. Click the square while it is animating to save its current state. Click it again to restore the state and resume the animation from the exact point at which it was saved.
|
|
75
80
|
|
|
76
81
|
```javascript
|
|
77
|
-
import { App } from "targetj";
|
|
82
|
+
import { App, state } from "targetj";
|
|
78
83
|
|
|
79
84
|
App({
|
|
80
85
|
width: 100,
|
|
81
86
|
height: 100,
|
|
82
87
|
backgroundColor: "blue",
|
|
88
|
+
cursor: "pointer",
|
|
83
89
|
|
|
84
|
-
// Starts immediately
|
|
85
|
-
scale: { value: [0.5, 1.2, 1], steps:
|
|
90
|
+
// Starts immediately.
|
|
91
|
+
scale: { value: [0.5, 1.2, 1], steps: 100 },
|
|
86
92
|
|
|
87
|
-
//
|
|
88
|
-
x$$: { value: [0, 180], steps:
|
|
93
|
+
// $$ waits for the previous target to finish.
|
|
94
|
+
x$$: { value: [0, 180], steps: 100 },
|
|
89
95
|
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
backgroundColor$$: {
|
|
97
|
+
value: "crimson",
|
|
98
|
+
steps: 100
|
|
99
|
+
},
|
|
92
100
|
|
|
93
|
-
// Waits for the color change to finish.
|
|
94
101
|
done$$() {
|
|
95
102
|
console.log("Sequence complete");
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
// Click once to save the state.
|
|
106
|
+
// Click again to restore it including animation progress.
|
|
107
|
+
onClick() {
|
|
108
|
+
state().toggle();
|
|
96
109
|
}
|
|
97
110
|
}).mount("#app");
|
|
98
111
|
```
|
|
@@ -140,15 +153,15 @@ A target can also be defined as an object with optional controls that manage its
|
|
|
140
153
|
|
|
141
154
|
### Compact Execution Syntax
|
|
142
155
|
|
|
143
|
-
Target names can include special
|
|
156
|
+
Target names can include special suffixes that determine when they execute. This provides a compact alternative to coordinating the same behavior with callbacks.
|
|
144
157
|
|
|
145
|
-
|
|
|
146
|
-
|
|
147
|
-
| `name`
|
|
148
|
-
| `name$`
|
|
149
|
-
| `name$$` | Deferred | Runs
|
|
150
|
-
| `_name` | Inactive | Does not run automatically. Trigger it manually with `.activateTarget()`. Equivalent to `{ active: false }`. |
|
|
158
|
+
| Syntax | Name | Behavior |
|
|
159
|
+
| -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
160
|
+
| `name` | Standard | Runs immediately in code order unless `active` is `false`. |
|
|
161
|
+
| `name$` | Reactive | Runs whenever the preceding sibling Target updates. Similar to activating the next Target from `onValueChange()` or `on<PropertyName>Step()`. |
|
|
162
|
+
| `name$$` | Deferred | Runs after the entire preceding Target chain—including children, animations, and API calls—has completed. Similar to activating the next Target from `onComplete()`. |
|
|
151
163
|
|
|
164
|
+
To prevent a Target from running automatically, set `active: false` and activate it later with `.activateTarget()`.
|
|
152
165
|
|
|
153
166
|
## Examples: Like Button → Animated Like (in 3 Steps)
|
|
154
167
|
|
|
@@ -567,6 +580,8 @@ These targets update CSS properties and transforms:
|
|
|
567
580
|
|
|
568
581
|
These can be animated simply by adding `steps`.
|
|
569
582
|
|
|
583
|
+
For custom CSS, use the `css` Target.
|
|
584
|
+
|
|
570
585
|
**Structure**
|
|
571
586
|
|
|
572
587
|
These targets define the structure of the interface:
|
package/build/App.js
CHANGED
|
@@ -285,57 +285,61 @@ var getPager = function getPager() {
|
|
|
285
285
|
var _tApp5;
|
|
286
286
|
return (_tApp5 = tApp) === null || _tApp5 === void 0 ? void 0 : _tApp5.pager;
|
|
287
287
|
};
|
|
288
|
-
var state = function state() {
|
|
289
|
-
var _tApp6;
|
|
290
|
-
return (_tApp6 = tApp) === null || _tApp6 === void 0 ? void 0 : _tApp6.stateManager;
|
|
291
|
-
};
|
|
292
288
|
var getLoader = function getLoader() {
|
|
293
|
-
var
|
|
294
|
-
return (
|
|
289
|
+
var _tApp6;
|
|
290
|
+
return (_tApp6 = tApp) === null || _tApp6 === void 0 ? void 0 : _tApp6.loader;
|
|
295
291
|
};
|
|
296
292
|
var fetch = function fetch(tmodel, url, query, cacheId) {
|
|
297
|
-
var
|
|
298
|
-
return (
|
|
293
|
+
var _tApp7;
|
|
294
|
+
return (_tApp7 = tApp) === null || _tApp7 === void 0 || (_tApp7 = _tApp7.loader) === null || _tApp7 === void 0 ? void 0 : _tApp7.fetch(tmodel, url, query, cacheId);
|
|
299
295
|
};
|
|
300
296
|
var fetchImage = function fetchImage(tmodel, src, cacheId) {
|
|
301
|
-
var
|
|
302
|
-
return (
|
|
297
|
+
var _tApp8;
|
|
298
|
+
return (_tApp8 = tApp) === null || _tApp8 === void 0 || (_tApp8 = _tApp8.loader) === null || _tApp8 === void 0 ? void 0 : _tApp8.fetchImage(tmodel, src, cacheId);
|
|
303
299
|
};
|
|
304
300
|
var getManager = function getManager() {
|
|
305
|
-
var
|
|
306
|
-
return (
|
|
301
|
+
var _tApp9;
|
|
302
|
+
return (_tApp9 = tApp) === null || _tApp9 === void 0 ? void 0 : _tApp9.manager;
|
|
307
303
|
};
|
|
308
304
|
var getTargetManager = function getTargetManager() {
|
|
309
|
-
var
|
|
310
|
-
return (
|
|
305
|
+
var _tApp10;
|
|
306
|
+
return (_tApp10 = tApp) === null || _tApp10 === void 0 ? void 0 : _tApp10.targetManager;
|
|
311
307
|
};
|
|
312
308
|
var getAnimationManager = function getAnimationManager() {
|
|
313
|
-
var
|
|
314
|
-
return (
|
|
309
|
+
var _tApp11;
|
|
310
|
+
return (_tApp11 = tApp) === null || _tApp11 === void 0 ? void 0 : _tApp11.animationManager;
|
|
315
311
|
};
|
|
316
312
|
var getRunScheduler = function getRunScheduler() {
|
|
317
|
-
var
|
|
318
|
-
return (
|
|
313
|
+
var _tApp12;
|
|
314
|
+
return (_tApp12 = tApp) === null || _tApp12 === void 0 ? void 0 : _tApp12.runScheduler;
|
|
319
315
|
};
|
|
320
316
|
var getLocationManager = function getLocationManager() {
|
|
321
|
-
var
|
|
322
|
-
return (
|
|
317
|
+
var _tApp13;
|
|
318
|
+
return (_tApp13 = tApp) === null || _tApp13 === void 0 ? void 0 : _tApp13.locationManager;
|
|
323
319
|
};
|
|
324
320
|
var getScreenWidth = function getScreenWidth() {
|
|
325
|
-
var _tApp$tRoot$val,
|
|
326
|
-
return (_tApp$tRoot$val = (
|
|
321
|
+
var _tApp$tRoot$val, _tApp14;
|
|
322
|
+
return (_tApp$tRoot$val = (_tApp14 = tApp) === null || _tApp14 === void 0 || (_tApp14 = _tApp14.tRoot) === null || _tApp14 === void 0 ? void 0 : _tApp14.val('screenWidth')) !== null && _tApp$tRoot$val !== void 0 ? _tApp$tRoot$val : 0;
|
|
327
323
|
};
|
|
328
324
|
var getScreenHeight = function getScreenHeight() {
|
|
329
|
-
var _tApp$tRoot$val2,
|
|
330
|
-
return (_tApp$tRoot$val2 = (
|
|
325
|
+
var _tApp$tRoot$val2, _tApp15;
|
|
326
|
+
return (_tApp$tRoot$val2 = (_tApp15 = tApp) === null || _tApp15 === void 0 || (_tApp15 = _tApp15.tRoot) === null || _tApp15 === void 0 ? void 0 : _tApp15.val('screenHeight')) !== null && _tApp$tRoot$val2 !== void 0 ? _tApp$tRoot$val2 : 0;
|
|
331
327
|
};
|
|
332
328
|
var getVisibles = function getVisibles() {
|
|
333
|
-
var
|
|
334
|
-
return (
|
|
329
|
+
var _tApp16;
|
|
330
|
+
return (_tApp16 = tApp) === null || _tApp16 === void 0 || (_tApp16 = _tApp16.manager) === null || _tApp16 === void 0 ? void 0 : _tApp16.getVisibles();
|
|
335
331
|
};
|
|
336
332
|
var getResizeLastUpdate = function getResizeLastUpdate() {
|
|
333
|
+
var _tApp17;
|
|
334
|
+
return (_tApp17 = tApp) === null || _tApp17 === void 0 ? void 0 : _tApp17.resizeLastUpdate;
|
|
335
|
+
};
|
|
336
|
+
var state = function state() {
|
|
337
337
|
var _tApp18;
|
|
338
|
-
|
|
338
|
+
var manager = (_tApp18 = tApp) === null || _tApp18 === void 0 ? void 0 : _tApp18.stateManager;
|
|
339
|
+
if (!manager) {
|
|
340
|
+
throw new Error("TargetJS state manager is not initialized.");
|
|
341
|
+
}
|
|
342
|
+
return manager;
|
|
339
343
|
};
|
|
340
344
|
var getTModelById = function getTModelById(id) {
|
|
341
345
|
return App.tmodelIdMap[id];
|