@carbonenginejs/runtime-utils 0.1.1 → 0.1.3
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/LICENSE +21 -21
- package/NOTICE +23 -23
- package/README.md +69 -69
- package/THIRD-PARTY-NOTICES.md +64 -64
- package/docs/README.md +74 -73
- package/docs/architecture.md +101 -101
- package/docs/concepts/foundation-consolidation.md +85 -85
- package/docs/concepts/model-lifecycle.md +111 -0
- package/docs/const-kb.md +85 -87
- package/docs/core-types/DECORATOR-TODOS.md +25 -25
- package/docs/core-types/README.md +229 -168
- package/docs/reference/api.md +105 -102
- package/docs/reference/classes/README.md +135 -135
- package/package.json +139 -139
- package/src/arrays.js +5 -5
- package/src/audio/audioFormats.js +34 -34
- package/src/audio/index.js +1 -1
- package/src/box3.js +331 -331
- package/src/bytes.js +56 -56
- package/src/compression.js +56 -56
- package/src/constants/index.js +7 -7
- package/src/constants/trinity.js +13 -13
- package/src/constants.js +15 -15
- package/src/curve.js +79 -79
- package/src/d3d/dxgiFormats.js +46 -46
- package/src/d3d/index.js +2 -2
- package/src/d3d/primitiveTopology.js +11 -11
- package/src/document/CjsCarbonDocument.js +212 -212
- package/src/document/CjsClassRegistry.js +373 -373
- package/src/document/CjsDocumentDehydrator.js +142 -142
- package/src/document/CjsDocumentHydrator.js +156 -156
- package/src/document/CjsStructRegistry.js +348 -348
- package/src/document/hydrationAdapter.js +129 -129
- package/src/document/index.js +6 -6
- package/src/errors/CjsError.js +286 -286
- package/src/errors/index.js +5 -5
- package/src/geometry/box.js +22 -22
- package/src/geometry/cylinder.js +22 -22
- package/src/geometry/helpers/earcut.js +1 -1
- package/src/geometry/helpers/misc.js +3 -3
- package/src/geometry/index.js +8 -8
- package/src/geometry/json.js +67 -67
- package/src/geometry/lathe.js +44 -44
- package/src/geometry/plane.js +14 -14
- package/src/geometry/shape.js +4 -4
- package/src/geometry/sphere.js +24 -24
- package/src/geometry/torus.js +14 -14
- package/src/graphics/colorSpaces.js +22 -22
- package/src/graphics/index.js +4 -4
- package/src/graphics/pixelFormats.js +158 -158
- package/src/graphics/textureDimensions.js +22 -22
- package/src/graphics/trinityEnums.js +87 -87
- package/src/index.js +62 -62
- package/src/is.js +108 -46
- package/src/json.js +23 -23
- package/src/lifecycle/CjsLifecycleState.js +77 -77
- package/src/lifecycle/index.js +1 -1
- package/src/lne3.js +70 -70
- package/src/lookup.js +48 -48
- package/src/mat3.js +51 -51
- package/src/mat4.js +699 -699
- package/src/math/index.js +25 -25
- package/src/math/scalar.js +63 -63
- package/src/media/index.js +1 -1
- package/src/media/mediaTypes.js +50 -50
- package/src/mesh.js +424 -424
- package/src/model/CjsEventEmitter.js +333 -333
- package/src/model/CjsModel.js +1589 -1544
- package/src/model/CjsModelState.js +72 -72
- package/src/model/index.js +4 -4
- package/src/model/sourceRecordUtils.js +54 -54
- package/src/noise.js +310 -310
- package/src/num.js +827 -827
- package/src/object.js +39 -39
- package/src/path.js +53 -53
- package/src/pln.js +125 -125
- package/src/pool.js +9 -9
- package/src/quat.js +144 -144
- package/src/ray3.js +188 -188
- package/src/renderContext/formats.js +145 -145
- package/src/renderContext/index.js +5 -5
- package/src/renderContext/presentation.js +125 -125
- package/src/renderContext/resources.js +27 -27
- package/src/renderContext/upscaling.js +22 -22
- package/src/renderContext/window.js +20 -20
- package/src/runtime/CjsRuntimeState.js +50 -50
- package/src/schema/CjsSchema.js +555 -318
- package/src/schema/index.js +4 -4
- package/src/shader/index.js +1 -1
- package/src/shader/shaderStages.js +37 -37
- package/src/sph3.js +181 -181
- package/src/tangent.js +288 -288
- package/src/text.js +40 -40
- package/src/tri3.js +98 -98
- package/src/types/carbonTypes.js +635 -635
- package/src/types/index.js +2 -2
- package/src/utils.js +58 -58
- package/src/validation.js +46 -46
- package/src/vec2.js +229 -229
- package/src/vec3.js +1188 -1172
- package/src/vec4.js +347 -347
- package/src/vertex.js +108 -108
- package/src/webgpu/index.js +1 -1
- package/src/webgpu/textureFormats.js +121 -121
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
import { CjsSchema } from "../schema/index.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Hydration adapter seam.
|
|
5
|
-
*
|
|
6
|
-
* runtime-utils deliberately does NOT impose a runtime lifecycle
|
|
7
|
-
* (SetValues / OnValueChanged / Initialize / etc. are one project's rules,
|
|
8
|
-
* not a contract). The only thing the library guarantees is ORDERING:
|
|
9
|
-
*
|
|
10
|
-
* 1. construct - build every instance (register refs before values, so
|
|
11
|
-
* cycles/back-references resolve)
|
|
12
|
-
* 2. applyValues - apply each node's field values
|
|
13
|
-
* 3. finalize - run once per instance AFTER the whole graph is built,
|
|
14
|
-
* so references are already resolved
|
|
15
|
-
*
|
|
16
|
-
* Callers inject HOW their own classes are constructed, populated, and
|
|
17
|
-
* finalized. Every hook is optional; when absent the built-in default is used
|
|
18
|
-
* so plain objects / `class {}` need zero configuration.
|
|
19
|
-
*
|
|
20
|
-
* Adapter shape (all methods optional):
|
|
21
|
-
* construct(kind, ctx) -> instance | undefined
|
|
22
|
-
* Return an instance, or `undefined` to fall back to the caller's
|
|
23
|
-
* built-in default construction (registry/class lookup).
|
|
24
|
-
* applyValues(instance, values, ctx) -> instance
|
|
25
|
-
* Apply `values` ({ fieldName: value }) to the instance. MUST mutate
|
|
26
|
-
* the given instance in place (returning a replacement would strip
|
|
27
|
-
* already-resolved references in cyclic graphs). Default: Object.assign.
|
|
28
|
-
* finalize(instance, ctx) -> void
|
|
29
|
-
* Post-graph initialization. Default: no-op.
|
|
30
|
-
*
|
|
31
|
-
* ctx: { kind, shape?, node?, options }
|
|
32
|
-
*
|
|
33
|
-
* Options consumed:
|
|
34
|
-
* options.adapter / options.hydrationAdapter : a single adapter object
|
|
35
|
-
* options.adapters : { [kind]: adapter } | Map per-kind override (wins over
|
|
36
|
-
* the single adapter)
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
function adapterOwning(perKind, global, kind, name)
|
|
40
|
-
{
|
|
41
|
-
if (perKind)
|
|
42
|
-
{
|
|
43
|
-
const specific = perKind instanceof Map ? perKind.get(kind) : perKind[kind];
|
|
44
|
-
if (specific && typeof specific[name] === "function") return specific;
|
|
45
|
-
}
|
|
46
|
-
if (global && typeof global[name] === "function") return global;
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Resolves a normalized adapter from hydration options. The returned object
|
|
52
|
-
* always exposes construct/applyValues/finalize with the documented defaults.
|
|
53
|
-
* @param {Object} [options]
|
|
54
|
-
* @returns {{ construct: Function, applyValues: Function, finalize: Function }}
|
|
55
|
-
*/
|
|
56
|
-
export function resolveHydrationAdapter(options = {})
|
|
57
|
-
{
|
|
58
|
-
const global = options.adapter || options.hydrationAdapter || null;
|
|
59
|
-
const perKind = options.adapters || null;
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
construct(kind, ctx)
|
|
63
|
-
{
|
|
64
|
-
const owner = adapterOwning(perKind, global, kind, "construct");
|
|
65
|
-
return owner ? owner.construct(kind, ctx) : undefined;
|
|
66
|
-
},
|
|
67
|
-
applyValues(instance, values, ctx)
|
|
68
|
-
{
|
|
69
|
-
const owner = adapterOwning(perKind, global, ctx?.kind, "applyValues");
|
|
70
|
-
if (owner) return owner.applyValues(instance, values, ctx);
|
|
71
|
-
return Object.assign(instance, values);
|
|
72
|
-
},
|
|
73
|
-
finalize(instance, ctx)
|
|
74
|
-
{
|
|
75
|
-
const owner = adapterOwning(perKind, global, ctx?.kind, "finalize");
|
|
76
|
-
if (owner) owner.finalize(instance, ctx);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Optional convenience adapter for callers whose classes follow a
|
|
83
|
-
* "SetValues + Initialize" convention (Carbon / ccpwgl / CjsModel style).
|
|
84
|
-
*
|
|
85
|
-
* This is NOT a default - opt in by passing it as `options.adapter`. Method
|
|
86
|
-
* names are configurable; pass `false`/`null` to disable a phase. When
|
|
87
|
-
* SetValues is enabled, applyValues throws if the populated instance does not
|
|
88
|
-
* implement it; this keeps class population from silently bypassing runtime
|
|
89
|
-
* validation. Finalize is skipped when the named initialize method is missing.
|
|
90
|
-
*
|
|
91
|
-
* @param {Object} [config]
|
|
92
|
-
* @param {String|false|null} [config.setValues="SetValues"]
|
|
93
|
-
* @param {String|false|null} [config.initialize="Initialize"]
|
|
94
|
-
* @param {Function} [config.construct] optional construct hook
|
|
95
|
-
* @returns {{ construct?: Function, applyValues: Function, finalize: Function }}
|
|
96
|
-
*/
|
|
97
|
-
export function createLifecycleAdapter(config = {})
|
|
98
|
-
{
|
|
99
|
-
const setValuesName = config.setValues === undefined ? "SetValues" : config.setValues;
|
|
100
|
-
const initializeName = config.initialize === undefined ? "Initialize" : config.initialize;
|
|
101
|
-
const construct = typeof config.construct === "function" ? config.construct : null;
|
|
102
|
-
|
|
103
|
-
const adapter = {
|
|
104
|
-
applyValues(instance, values, ctx)
|
|
105
|
-
{
|
|
106
|
-
if (setValuesName && instance && typeof instance[setValuesName] === "function")
|
|
107
|
-
{
|
|
108
|
-
instance[setValuesName](values, ctx?.options);
|
|
109
|
-
return instance;
|
|
110
|
-
}
|
|
111
|
-
if (setValuesName && instance && typeof instance === "object")
|
|
112
|
-
{
|
|
113
|
-
const kind = ctx?.kind ?? CjsSchema.getClassName(instance.constructor) ?? "unknown";
|
|
114
|
-
throw new TypeError(`${kind} cannot be populated by createLifecycleAdapter: missing ${setValuesName}().`);
|
|
115
|
-
}
|
|
116
|
-
return Object.assign(instance, values);
|
|
117
|
-
},
|
|
118
|
-
finalize(instance, ctx)
|
|
119
|
-
{
|
|
120
|
-
if (initializeName && instance && typeof instance[initializeName] === "function")
|
|
121
|
-
{
|
|
122
|
-
instance[initializeName](ctx?.options);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
if (construct) adapter.construct = construct;
|
|
128
|
-
return adapter;
|
|
129
|
-
}
|
|
1
|
+
import { CjsSchema } from "../schema/index.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hydration adapter seam.
|
|
5
|
+
*
|
|
6
|
+
* runtime-utils deliberately does NOT impose a runtime lifecycle
|
|
7
|
+
* (SetValues / OnValueChanged / Initialize / etc. are one project's rules,
|
|
8
|
+
* not a contract). The only thing the library guarantees is ORDERING:
|
|
9
|
+
*
|
|
10
|
+
* 1. construct - build every instance (register refs before values, so
|
|
11
|
+
* cycles/back-references resolve)
|
|
12
|
+
* 2. applyValues - apply each node's field values
|
|
13
|
+
* 3. finalize - run once per instance AFTER the whole graph is built,
|
|
14
|
+
* so references are already resolved
|
|
15
|
+
*
|
|
16
|
+
* Callers inject HOW their own classes are constructed, populated, and
|
|
17
|
+
* finalized. Every hook is optional; when absent the built-in default is used
|
|
18
|
+
* so plain objects / `class {}` need zero configuration.
|
|
19
|
+
*
|
|
20
|
+
* Adapter shape (all methods optional):
|
|
21
|
+
* construct(kind, ctx) -> instance | undefined
|
|
22
|
+
* Return an instance, or `undefined` to fall back to the caller's
|
|
23
|
+
* built-in default construction (registry/class lookup).
|
|
24
|
+
* applyValues(instance, values, ctx) -> instance
|
|
25
|
+
* Apply `values` ({ fieldName: value }) to the instance. MUST mutate
|
|
26
|
+
* the given instance in place (returning a replacement would strip
|
|
27
|
+
* already-resolved references in cyclic graphs). Default: Object.assign.
|
|
28
|
+
* finalize(instance, ctx) -> void
|
|
29
|
+
* Post-graph initialization. Default: no-op.
|
|
30
|
+
*
|
|
31
|
+
* ctx: { kind, shape?, node?, options }
|
|
32
|
+
*
|
|
33
|
+
* Options consumed:
|
|
34
|
+
* options.adapter / options.hydrationAdapter : a single adapter object
|
|
35
|
+
* options.adapters : { [kind]: adapter } | Map per-kind override (wins over
|
|
36
|
+
* the single adapter)
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
function adapterOwning(perKind, global, kind, name)
|
|
40
|
+
{
|
|
41
|
+
if (perKind)
|
|
42
|
+
{
|
|
43
|
+
const specific = perKind instanceof Map ? perKind.get(kind) : perKind[kind];
|
|
44
|
+
if (specific && typeof specific[name] === "function") return specific;
|
|
45
|
+
}
|
|
46
|
+
if (global && typeof global[name] === "function") return global;
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Resolves a normalized adapter from hydration options. The returned object
|
|
52
|
+
* always exposes construct/applyValues/finalize with the documented defaults.
|
|
53
|
+
* @param {Object} [options]
|
|
54
|
+
* @returns {{ construct: Function, applyValues: Function, finalize: Function }}
|
|
55
|
+
*/
|
|
56
|
+
export function resolveHydrationAdapter(options = {})
|
|
57
|
+
{
|
|
58
|
+
const global = options.adapter || options.hydrationAdapter || null;
|
|
59
|
+
const perKind = options.adapters || null;
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
construct(kind, ctx)
|
|
63
|
+
{
|
|
64
|
+
const owner = adapterOwning(perKind, global, kind, "construct");
|
|
65
|
+
return owner ? owner.construct(kind, ctx) : undefined;
|
|
66
|
+
},
|
|
67
|
+
applyValues(instance, values, ctx)
|
|
68
|
+
{
|
|
69
|
+
const owner = adapterOwning(perKind, global, ctx?.kind, "applyValues");
|
|
70
|
+
if (owner) return owner.applyValues(instance, values, ctx);
|
|
71
|
+
return Object.assign(instance, values);
|
|
72
|
+
},
|
|
73
|
+
finalize(instance, ctx)
|
|
74
|
+
{
|
|
75
|
+
const owner = adapterOwning(perKind, global, ctx?.kind, "finalize");
|
|
76
|
+
if (owner) owner.finalize(instance, ctx);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Optional convenience adapter for callers whose classes follow a
|
|
83
|
+
* "SetValues + Initialize" convention (Carbon / ccpwgl / CjsModel style).
|
|
84
|
+
*
|
|
85
|
+
* This is NOT a default - opt in by passing it as `options.adapter`. Method
|
|
86
|
+
* names are configurable; pass `false`/`null` to disable a phase. When
|
|
87
|
+
* SetValues is enabled, applyValues throws if the populated instance does not
|
|
88
|
+
* implement it; this keeps class population from silently bypassing runtime
|
|
89
|
+
* validation. Finalize is skipped when the named initialize method is missing.
|
|
90
|
+
*
|
|
91
|
+
* @param {Object} [config]
|
|
92
|
+
* @param {String|false|null} [config.setValues="SetValues"]
|
|
93
|
+
* @param {String|false|null} [config.initialize="Initialize"]
|
|
94
|
+
* @param {Function} [config.construct] optional construct hook
|
|
95
|
+
* @returns {{ construct?: Function, applyValues: Function, finalize: Function }}
|
|
96
|
+
*/
|
|
97
|
+
export function createLifecycleAdapter(config = {})
|
|
98
|
+
{
|
|
99
|
+
const setValuesName = config.setValues === undefined ? "SetValues" : config.setValues;
|
|
100
|
+
const initializeName = config.initialize === undefined ? "Initialize" : config.initialize;
|
|
101
|
+
const construct = typeof config.construct === "function" ? config.construct : null;
|
|
102
|
+
|
|
103
|
+
const adapter = {
|
|
104
|
+
applyValues(instance, values, ctx)
|
|
105
|
+
{
|
|
106
|
+
if (setValuesName && instance && typeof instance[setValuesName] === "function")
|
|
107
|
+
{
|
|
108
|
+
instance[setValuesName](values, ctx?.options);
|
|
109
|
+
return instance;
|
|
110
|
+
}
|
|
111
|
+
if (setValuesName && instance && typeof instance === "object")
|
|
112
|
+
{
|
|
113
|
+
const kind = ctx?.kind ?? CjsSchema.getClassName(instance.constructor) ?? "unknown";
|
|
114
|
+
throw new TypeError(`${kind} cannot be populated by createLifecycleAdapter: missing ${setValuesName}().`);
|
|
115
|
+
}
|
|
116
|
+
return Object.assign(instance, values);
|
|
117
|
+
},
|
|
118
|
+
finalize(instance, ctx)
|
|
119
|
+
{
|
|
120
|
+
if (initializeName && instance && typeof instance[initializeName] === "function")
|
|
121
|
+
{
|
|
122
|
+
instance[initializeName](ctx?.options);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
if (construct) adapter.construct = construct;
|
|
128
|
+
return adapter;
|
|
129
|
+
}
|
package/src/document/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./CjsCarbonDocument.js";
|
|
2
|
-
export * from "./CjsClassRegistry.js";
|
|
3
|
-
export * from "./CjsDocumentDehydrator.js";
|
|
4
|
-
export * from "./CjsDocumentHydrator.js";
|
|
5
|
-
export * from "./CjsStructRegistry.js";
|
|
6
|
-
export * from "./hydrationAdapter.js";
|
|
1
|
+
export * from "./CjsCarbonDocument.js";
|
|
2
|
+
export * from "./CjsClassRegistry.js";
|
|
3
|
+
export * from "./CjsDocumentDehydrator.js";
|
|
4
|
+
export * from "./CjsDocumentHydrator.js";
|
|
5
|
+
export * from "./CjsStructRegistry.js";
|
|
6
|
+
export * from "./hydrationAdapter.js";
|