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 CHANGED
@@ -1,13 +1,17 @@
1
- # TargetJS: State as Destination, Code Order as UI Sequence
1
+ # TargetJS: State Includes the Journey
2
2
 
3
- ### Most frameworks are great at rendering state. TargetJS is designed for the journey between states.
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
  [![MIT LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/livetrails/targetjs/blob/main/LICENSE)
7
9
  [![Stars](https://img.shields.io/github/stars/livetrails/targetjs.svg)](https://github.com/livetrails/targetjs/stargazers)
8
10
  [![npm version](https://img.shields.io/npm/v/targetj.svg)](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". Transitions are part of state, which means they can adapt dynamically, be serialized mid-transition, and resume when the UI is restored.
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 treats state as a destination. Values are not only assigned. They can be approached over time through configurable steps. This makes transitions a native part of state change. TargetJS also delivers CSS-level transition efficiency.
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
- More importantly, it unlocks a new level of flexibility. Because a target has its own lifecycle, its transitions can adapt dynamically. For example, pausing when an element leaves the screen or changing speed on scroll.
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
- And since the transition is part of the state, it can be serialized. This means a transition can survive a page flip and resume when the UI is restored.
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. They can also be serialized and continue, for instance, after a page flip.
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: High-performance animations are baked into the logic.
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. Although not shown here, the state can also be serialized mid-transition, for example, during a page flip and restored when the UI remounts.
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: bounce.
85
- scale: { value: [0.5, 1.2, 1], steps: 24, interval: 12 },
90
+ // Starts immediately.
91
+ scale: { value: [0.5, 1.2, 1], steps: 100 },
86
92
 
87
- // Waits for scale to finish, then moves right.
88
- x$$: { value: [0, 180], steps: 40, interval: 8 },
93
+ // $$ waits for the previous target to finish.
94
+ x$$: { value: [0, 180], steps: 100 },
89
95
 
90
- // Waits for x to finish, then turns red.
91
- backgroundColor$$: { value: "crimson", steps: 30, interval: 8 },
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 symbols that define when they execute. This provides a compact alternative to implementing the same behavior with callbacks.
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
- | Symbol | Name | Behavior |
146
- |------|------|------|
147
- | `name` | Standard | Runs immediately in the order it appears. |
148
- | `name$` | Reactive | Runs every time the previous sibling target updates. Equivalent to using `on<PropertyName>Step()` or `onValueChange()` to activate the next target . |
149
- | `name$$` | Deferred | Runs only after the entire preceding target chain, including children, animations, and API calls, completes. Equivalent to using `onComplete()` to activate the next target. |
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 _tApp7;
294
- return (_tApp7 = tApp) === null || _tApp7 === void 0 ? void 0 : _tApp7.loader;
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 _tApp8;
298
- return (_tApp8 = tApp) === null || _tApp8 === void 0 || (_tApp8 = _tApp8.loader) === null || _tApp8 === void 0 ? void 0 : _tApp8.fetch(tmodel, url, query, cacheId);
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 _tApp9;
302
- return (_tApp9 = tApp) === null || _tApp9 === void 0 || (_tApp9 = _tApp9.loader) === null || _tApp9 === void 0 ? void 0 : _tApp9.fetchImage(tmodel, src, cacheId);
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 _tApp10;
306
- return (_tApp10 = tApp) === null || _tApp10 === void 0 ? void 0 : _tApp10.manager;
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 _tApp11;
310
- return (_tApp11 = tApp) === null || _tApp11 === void 0 ? void 0 : _tApp11.targetManager;
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 _tApp12;
314
- return (_tApp12 = tApp) === null || _tApp12 === void 0 ? void 0 : _tApp12.animationManager;
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 _tApp13;
318
- return (_tApp13 = tApp) === null || _tApp13 === void 0 ? void 0 : _tApp13.runScheduler;
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 _tApp14;
322
- return (_tApp14 = tApp) === null || _tApp14 === void 0 ? void 0 : _tApp14.locationManager;
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, _tApp15;
326
- return (_tApp$tRoot$val = (_tApp15 = tApp) === null || _tApp15 === void 0 || (_tApp15 = _tApp15.tRoot) === null || _tApp15 === void 0 ? void 0 : _tApp15.val('screenWidth')) !== null && _tApp$tRoot$val !== void 0 ? _tApp$tRoot$val : 0;
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, _tApp16;
330
- return (_tApp$tRoot$val2 = (_tApp16 = tApp) === null || _tApp16 === void 0 || (_tApp16 = _tApp16.tRoot) === null || _tApp16 === void 0 ? void 0 : _tApp16.val('screenHeight')) !== null && _tApp$tRoot$val2 !== void 0 ? _tApp$tRoot$val2 : 0;
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 _tApp17;
334
- return (_tApp17 = tApp) === null || _tApp17 === void 0 || (_tApp17 = _tApp17.manager) === null || _tApp17 === void 0 ? void 0 : _tApp17.getVisibles();
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
- return (_tApp18 = tApp) === null || _tApp18 === void 0 ? void 0 : _tApp18.resizeLastUpdate;
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];