@vived/core 2.0.1 → 2.0.2

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,7 +4,7 @@ Core Components for VIVED Apps and Hosts
4
4
 
5
5
  ## Overview
6
6
 
7
- @vived/core provides foundational architecture components used across VIVED applications. This library implements a component-based architecture pattern that enables building complex applications with proper separation of concerns.
7
+ `@vived/core` provides a comprehensive architecture framework for building scalable, maintainable applications using Clean Architecture principles. The library combines a component-based architecture (AppObject pattern) with reactive entities, immutable value objects, and utility functions optimized for 3D graphics and interactive applications.
8
8
 
9
9
  ## Installation
10
10
 
@@ -12,93 +12,303 @@ Core Components for VIVED Apps and Hosts
12
12
  npm install @vived/core
13
13
  ```
14
14
 
15
- ## Core Concepts
15
+ ## Documentation
16
16
 
17
- The package is built around the "AppObject" architecture, which follows a component-based design pattern:
17
+ This package includes comprehensive documentation for each module:
18
18
 
19
- ### AppObject
19
+ - **[AppObject Architecture](src/AppObject/README.md)** - Component-based architecture pattern with entities, use cases, presentation managers, views, and controllers
20
+ - **[DomainFactories](src/DomainFactories/README.md)** - Multi-phase initialization system for organizing domain components
21
+ - **[Entities](src/Entities/README.md)** - Observable entities with memoized properties for automatic change detection
22
+ - **[ValueObjects](src/ValueObjects/README.md)** - Immutable mathematical primitives for 3D graphics and geometry
23
+ - **[Utilities](src/Utilities/README.md)** - Helper functions for animations, colors, conversions, and file operations
24
+ - **[Types](src/Types/README.md)** - TypeScript interfaces for adapters and application boundaries
25
+ - **[ExampleFeature](src/ExampleFeature/README.md)** - Complete reference implementation demonstrating best practices
20
26
 
21
- - The central entity that acts as a container for components
22
- - Each AppObject has a unique ID and belongs to an AppObjectRepo
23
- - Components can be added, removed, and queried
24
- - AppObjects are observable entities, notifying observers when components change
27
+ ## Quick Start
25
28
 
26
- ### AppObjectRepo
29
+ ### AppObject Architecture
27
30
 
28
- - Manages a collection of AppObjects
29
- - Provides methods to find, create, and manage AppObjects
30
- - Handles singleton components across the application
31
- - Includes logging infrastructure for debugging
31
+ The core architecture follows Clean Architecture dependency rules with a component-based design:
32
32
 
33
- ### Component Types
33
+ ```typescript
34
+ import { makeAppObjectRepo } from "@vived/core";
34
35
 
35
- The architecture implements a clean separation of concerns through specialized components:
36
+ // Create the application repository
37
+ const appObjects = makeAppObjectRepo();
36
38
 
37
- 1. **Entity (AppObjectEntity)**
38
- - Holds and manages application state
39
- - Provides change notifications when state is modified
39
+ // Create an AppObject
40
+ const myObject = appObjects.getOrCreate("myObject");
40
41
 
41
- 2. **Presentation Manager (AppObjectPM)**
42
- - Manages view models for UI representation
43
- - Transforms application state into UI-ready data
44
- - Notifies views when view models change
42
+ // Add components to it
43
+ const entity = makeMyEntity(myObject);
44
+ const useCase = makeMyUseCase(myObject);
45
+ const presentationManager = makeMyPM(myObject);
46
+ ```
47
+
48
+ **Key Components:**
49
+ - **Entities** - Store and manage domain data with automatic change notifications
50
+ - **Use Cases** - Implement business logic and operations
51
+ - **Presentation Managers** - Transform entity data into view models for UI
52
+ - **Controllers** - Provide simplified APIs for UI interactions
53
+ - **Adapters** - Connect UI frameworks (React, Vue, etc.) to presentation managers
54
+
55
+ ### Domain Factories
56
+
57
+ Organize features using domain factories with phased initialization:
58
+
59
+ ```typescript
60
+ import { makeDomainFactoryRepo } from "@vived/core";
61
+
62
+ // Create domain factory repository
63
+ const domainFactoryRepo = makeDomainFactoryRepo(appObjects);
64
+
65
+ // Create your feature factories
66
+ new MyFeatureDomainFactory(appObjects.getOrCreate("MyFeature"));
67
+
68
+ // Initialize all features in proper order
69
+ domainFactoryRepo.setupDomain();
70
+ ```
71
+
72
+ ### Reactive Entities
73
+
74
+ Build reactive data models with automatic change detection:
75
+
76
+ ```typescript
77
+ import { MemoizedString, MemoizedNumber, ObservableEntity } from "@vived/core";
78
+
79
+ class UserEntity extends ObservableEntity
80
+ {
81
+ private nameProperty = new MemoizedString("", () => this.notify());
82
+ private ageProperty = new MemoizedNumber(0, () => this.notify());
83
+
84
+ get name() { return this.nameProperty.val; }
85
+ set name(value: string) { this.nameProperty.val = value; }
86
+
87
+ get age() { return this.ageProperty.val; }
88
+ set age(value: number) { this.ageProperty.val = value; }
89
+ }
90
+
91
+ // Changes automatically notify observers
92
+ const user = new UserEntity();
93
+ user.addObserver(() => console.log("User changed!"));
94
+ user.name = "John"; // Triggers notification
95
+ ```
45
96
 
46
- 3. **Use Case (AppObjectUC)**
47
- - Implements business logic
48
- - Coordinates between data layer and presentation
97
+ ### Value Objects for 3D Graphics
49
98
 
50
- 4. **Controller (AppObjectController)**
51
- - Handles external inputs (user actions, system events)
52
- - Delegates to appropriate use cases
99
+ Work with immutable mathematical primitives:
53
100
 
54
- 5. **View (AppObjectView)**
55
- - UI representation components
56
- - Consumes view models and renders UI
101
+ ```typescript
102
+ import { Vector3, Quaternion, Matrix, Color } from "@vived/core";
57
103
 
58
- ## Example Implementation
104
+ // Vector operations
105
+ const position = new Vector3(10, 20, 30);
106
+ const direction = Vector3.Forward();
107
+ const sum = Vector3.Add(position, direction);
59
108
 
60
- The package includes a fully implemented `ExampleFeature` that demonstrates the App Object Component architecture. This example demonstrates how to structure your code following the recommended patterns:
109
+ // Rotations with quaternions
110
+ const rotation = Quaternion.FromYawPitchRoll(
111
+ Angle.FromDegrees(45),
112
+ Angle.FromDegrees(0),
113
+ Angle.FromDegrees(0)
114
+ );
115
+
116
+ // Transformation matrices
117
+ const transform = Matrix.Translation(position);
118
+ const rotationMatrix = Matrix.FromQuaternion(rotation);
119
+
120
+ // Colors
121
+ const red = Color.RGB(255, 0, 0);
122
+ const transparent = Color.RGBA(0, 0, 0, 128);
123
+ const named = Color.X11("CornflowerBlue");
124
+ ```
125
+
126
+ ### Animation Utilities
127
+
128
+ Create smooth animations with easing functions:
129
+
130
+ ```typescript
131
+ import { LerpNumber, quintInOut } from "@vived/core";
132
+
133
+ const lerper = new LerpNumber();
134
+
135
+ // Animate a value from 0 to 100 over 2 seconds
136
+ await lerper.lerp({
137
+ start: 0,
138
+ end: 100,
139
+ durationMS: 2000,
140
+ ease: quintInOut,
141
+ update: (value) => {
142
+ element.style.opacity = value / 100;
143
+ },
144
+ onComplete: () => {
145
+ console.log("Animation complete!");
146
+ }
147
+ });
148
+ ```
149
+
150
+ ### UI Integration with Adapters
151
+
152
+ Connect your UI framework to the architecture:
153
+
154
+ ```typescript
155
+ import { useEffect, useState } from "react";
156
+ import { myFeatureAdapter } from "@vived/core";
157
+
158
+ function MyComponent({ id, appObjects })
159
+ {
160
+ const [viewModel, setViewModel] = useState(myFeatureAdapter.defaultVM);
161
+
162
+ useEffect(() => {
163
+ // Subscribe to updates
164
+ myFeatureAdapter.subscribe(id, appObjects, setViewModel);
165
+
166
+ // Cleanup on unmount
167
+ return () => {
168
+ myFeatureAdapter.unsubscribe(id, appObjects, setViewModel);
169
+ };
170
+ }, [id]);
171
+
172
+ return <div>{viewModel.someProperty}</div>;
173
+ }
174
+ ```
61
175
 
62
- ### Directory Structure
63
- - **Entities/** - Domain models for storing and managing state
64
- - **PMs/** - Presentation Managers that transform data for UI consumption
65
- - **UCs/** - Use Cases that implement business logic operations
66
- - **Controllers/** - Simplified API for UI interaction
67
- - **Adapters/** - Connect UI frameworks to PMs
68
- - **Mocks/** - Test doubles for unit testing
69
- - **Factory/** - Factories for creating the features at runtime
176
+ ## Package Contents
70
177
 
71
- Refer to the `ExampleFeature` directory for a complete implementation example that shows the interaction between all component types.
178
+ ### Architecture Components
72
179
 
73
- ## Value Objects
180
+ - **AppObject System** - Component container pattern with dependency injection
181
+ - **Entity System** - Observable entities with memoized properties
182
+ - **Repository Pattern** - Manage collections of entities
183
+ - **Use Cases** - Business logic layer
184
+ - **Presentation Managers** - View model transformation layer
185
+ - **Controllers** - Simplified UI interaction APIs
186
+ - **Adapters** - Framework-agnostic UI integration
74
187
 
75
- The package provides immutable value objects for mathematical and graphical operations:
188
+ ### Value Objects
76
189
 
77
- ### Geometric & Mathematical Types
78
- - **Vector2**: 2D vector with operations like addition, dot product, rotation, and unit vector calculation
79
- - **Vector3**: 3D vector with similar operations plus cross product and coordinate transformations
80
- - **Quaternion**: For 3D rotations with methods for creation from angles, Euler angles, and matrices plus interpolation
81
- - **Matrix**: For transformation operations like translation, rotation, and scaling
82
- - **Angle**: Encapsulates angle values with automatic conversion between degrees and radians
83
- - **Rectangle**: For 2D rectangular regions with intersection testing
190
+ **Vectors & Geometry:**
191
+ - Vector2, Vector3 - 2D and 3D vectors with full operations
192
+ - Quaternion - 3D rotation representation
193
+ - Matrix - 4x4 transformation matrices
194
+ - Angle - Type-safe angle conversions
195
+ - Rectangle - 2D rectangular bounds
196
+ - LineSegment2D - 2D line segment operations
197
+ - ParametricLine - 3D parametric line representation
198
+ - ParametricPlane - 3D plane representation
84
199
 
85
- ### Parametric Geometry
86
- - **ParametricLine**: Represents lines with point and direction for intersection calculations
87
- - **ParametricPlane**: Represents planes with point and normal for 3D geometric operations
88
- - **LineSegment2D**: Represents finite line segments with intersection testing
200
+ **Graphics:**
201
+ - Color - RGBA color with hex and X11 color support
89
202
 
90
- ### Graphics & Utilities
91
- - **Color**: RGBA color representation with utility methods for conversion between formats (RGB, Hex, X11 names)
92
- - **Version**: Semantic versioning implementation with comparison operators
203
+ **Versioning:**
204
+ - Version - Semantic version parsing and comparison
93
205
 
94
- ## Utilities
206
+ ### Utilities
95
207
 
96
- The package also includes various utility functions:
97
- - Color manipulation (adding alpha to hex, converting alpha to hex)
98
- - Length converters for different measurement systems
99
- - Linear interpolation and easing functions
100
- - Angle conversion between degrees and radians
101
- - File operations like downloading
208
+ **Animation:**
209
+ - LerpNumber - Smooth numeric interpolation
210
+ - Easing functions - 20+ easing functions (quad, cubic, quart, quint, sin, expo, circ)
211
+ - interpolateNumber - Basic numeric interpolation
212
+
213
+ **Color:**
214
+ - addAlphaToHex - Add transparency to hex colors
215
+ - alphaToHex - Convert alpha values to hex
216
+
217
+ **Conversion:**
218
+ - degreesToRadians - Angle conversion
219
+ - Length converters - Inches/feet to meters and vice versa
220
+
221
+ **File Operations:**
222
+ - downloadFile - Trigger browser downloads
223
+ - generateUniqueID - UUID v4 generation
224
+
225
+ ### Types
226
+
227
+ - PmAdapter - Interface for connecting UI to presentation managers
228
+ - SingletonPmAdapter - Interface for singleton presentation managers
229
+ - EaseFn - Type definition for easing functions
230
+ - AppBoundary - Application embedding interfaces
231
+
232
+ ## Architecture Principles
233
+
234
+ ### Clean Architecture
235
+
236
+ The library enforces dependency rules where inner layers never depend on outer layers:
237
+
238
+ ```
239
+ UI Layer
240
+
241
+ Adapters & Controllers
242
+
243
+ Presentation Managers
244
+
245
+ Use Cases
246
+
247
+ Entities
248
+ ```
249
+
250
+ ### Component-Based Design
251
+
252
+ Everything is a component attached to an AppObject:
253
+ - Promotes composition over inheritance
254
+ - Enables dependency injection
255
+ - Facilitates testing with mock components
256
+ - Supports both instance and singleton patterns
257
+
258
+ ### Reactive by Default
259
+
260
+ Entities notify observers when they change:
261
+ - Automatic UI updates
262
+ - No manual refresh logic needed
263
+ - Performance optimized with memoization
264
+
265
+ ### Immutable Value Objects
266
+
267
+ Mathematical primitives are immutable:
268
+ - Thread-safe operations
269
+ - Predictable behavior
270
+ - Easy to reason about
271
+ - Optimal for 3D graphics pipelines
272
+
273
+ ## Example Feature
274
+
275
+ See [ExampleFeature](src/ExampleFeature/README.md) for a complete, production-ready reference implementation showing:
276
+ - Feature folder structure
277
+ - Entity, Use Case, and PM implementation
278
+ - Controller and Adapter patterns
279
+ - React integration examples
280
+ - Testing strategies
281
+ - Factory-based initialization
282
+
283
+ ## Use Cases
284
+
285
+ - **3D Graphics Applications** - WebGL, Three.js, Babylon.js applications
286
+ - **VR/AR Experiences** - Interactive virtual environments
287
+ - **Data Visualization** - Charts, graphs, and interactive dashboards
288
+ - **Game Development** - Game engines and interactive experiences
289
+ - **Educational Software** - Interactive learning applications
290
+ - **Configuration Tools** - Complex application settings and preferences
291
+
292
+ ## TypeScript Support
293
+
294
+ Fully typed with TypeScript definitions included. Supports both ESM and CommonJS:
295
+
296
+ ```json
297
+ {
298
+ "exports": {
299
+ ".": {
300
+ "import": "./dist/esm/index.js",
301
+ "require": "./dist/cjs/index.js",
302
+ "types": "./dist/types/index.d.ts"
303
+ }
304
+ }
305
+ }
306
+ ```
307
+
308
+ ## Contributing
309
+
310
+ This is a foundational library for VIVED applications. For detailed architecture decisions and patterns, refer to the comprehensive documentation in each module's README.
102
311
 
103
312
  ## License
313
+
104
314
  ISC
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Controllers
18
+ __exportStar(require("./Controllers/setExampleText"), exports);
19
+ __exportStar(require("./Controllers/toggleExampleBoolean"), exports);
20
+ // Adapters
21
+ __exportStar(require("./Adapters/examplePmAdapter"), exports);
22
+ __exportStar(require("./Adapters/exampleSingletonPmAdapter"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ExampleFeature/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,cAAc;AACd,+DAA6C;AAC7C,qEAAmD;AAEnD,WAAW;AACX,8DAA4C;AAC5C,uEAAqD","sourcesContent":["// Controllers\r\nexport * from \"./Controllers/setExampleText\";\r\nexport * from \"./Controllers/toggleExampleBoolean\";\r\n\r\n// Adapters\r\nexport * from \"./Adapters/examplePmAdapter\";\r\nexport * from \"./Adapters/exampleSingletonPmAdapter\";\r\n"]}
@@ -0,0 +1,7 @@
1
+ // Controllers
2
+ export * from "./Controllers/setExampleText";
3
+ export * from "./Controllers/toggleExampleBoolean";
4
+ // Adapters
5
+ export * from "./Adapters/examplePmAdapter";
6
+ export * from "./Adapters/exampleSingletonPmAdapter";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ExampleFeature/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AAEnD,WAAW;AACX,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sCAAsC,CAAC","sourcesContent":["// Controllers\r\nexport * from \"./Controllers/setExampleText\";\r\nexport * from \"./Controllers/toggleExampleBoolean\";\r\n\r\n// Adapters\r\nexport * from \"./Adapters/examplePmAdapter\";\r\nexport * from \"./Adapters/exampleSingletonPmAdapter\";\r\n"]}
@@ -0,0 +1,5 @@
1
+ export * from "./Controllers/setExampleText";
2
+ export * from "./Controllers/toggleExampleBoolean";
3
+ export * from "./Adapters/examplePmAdapter";
4
+ export * from "./Adapters/exampleSingletonPmAdapter";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ExampleFeature/index.ts"],"names":[],"mappings":"AACA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AAGnD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sCAAsC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vived/core",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Core Components for VIVED Apps and Hosts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -55,6 +55,7 @@
55
55
  "uuid": "^11.1.0"
56
56
  },
57
57
  "files": [
58
- "dist"
58
+ "dist",
59
+ "src/**/README.md"
59
60
  ]
60
61
  }