@relu-interactives/spatial-ecs 0.8.0 → 0.9.0

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.
Files changed (44) hide show
  1. package/dist/{XRHandPose-G0Dl-F0w.d.ts → XRHandPose-CWSrsnYN.d.ts} +144 -1
  2. package/dist/{XRHandPose-VQMT1WXj.d.cts → XRHandPose-Dn2yiALk.d.cts} +144 -1
  3. package/dist/{chunk-G4XJ53LS.js → chunk-JEPUCLZX.js} +3 -3
  4. package/dist/{chunk-G4XJ53LS.js.map → chunk-JEPUCLZX.js.map} +1 -1
  5. package/dist/{chunk-NNDUOQ7O.js → chunk-JNYPJB55.js} +250 -3
  6. package/dist/chunk-JNYPJB55.js.map +1 -0
  7. package/dist/{chunk-SGF73YTF.js → chunk-NXASMBDS.js} +4 -4
  8. package/dist/{chunk-SGF73YTF.js.map → chunk-NXASMBDS.js.map} +1 -1
  9. package/dist/{chunk-JIJQFW6P.js → chunk-VYIWOXAY.js} +1377 -480
  10. package/dist/chunk-VYIWOXAY.js.map +1 -0
  11. package/dist/{chunk-U727NTWQ.js → chunk-WWP46AEF.js} +26 -4
  12. package/dist/chunk-WWP46AEF.js.map +1 -0
  13. package/dist/components/index.cjs +151 -0
  14. package/dist/components/index.cjs.map +1 -1
  15. package/dist/components/index.d.cts +2 -2
  16. package/dist/components/index.d.ts +2 -2
  17. package/dist/components/index.js +1 -1
  18. package/dist/docs/guide/spatial-ui.md +83 -7
  19. package/dist/factories/index.cjs +151 -0
  20. package/dist/factories/index.cjs.map +1 -1
  21. package/dist/factories/index.d.cts +1 -1
  22. package/dist/factories/index.d.ts +1 -1
  23. package/dist/factories/index.js +3 -3
  24. package/dist/{index-D9DjrUn3.d.cts → index-CAZHrh0q.d.cts} +5 -2
  25. package/dist/{index-DppafVu4.d.ts → index-CLtSMf2M.d.ts} +5 -2
  26. package/dist/{index-C61n65PE.d.ts → index-D5MmJNyj.d.ts} +26 -1
  27. package/dist/{index-C70N4BYG.d.cts → index-DiIjV2lm.d.cts} +26 -1
  28. package/dist/index.cjs +1787 -621
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +5 -5
  31. package/dist/index.d.ts +5 -5
  32. package/dist/index.js +10 -10
  33. package/dist/network/index.cjs +177 -4
  34. package/dist/network/index.cjs.map +1 -1
  35. package/dist/network/index.js +3 -3
  36. package/dist/systems/index.cjs +1689 -523
  37. package/dist/systems/index.cjs.map +1 -1
  38. package/dist/systems/index.d.cts +1 -1
  39. package/dist/systems/index.d.ts +1 -1
  40. package/dist/systems/index.js +4 -4
  41. package/package.json +1 -1
  42. package/dist/chunk-JIJQFW6P.js.map +0 -1
  43. package/dist/chunk-NNDUOQ7O.js.map +0 -1
  44. package/dist/chunk-U727NTWQ.js.map +0 -1
@@ -2213,6 +2213,223 @@ var _IKComponent = class _IKComponent extends Component {
2213
2213
  __name(_IKComponent, "IKComponent");
2214
2214
  var IKComponent = _IKComponent;
2215
2215
 
2216
+ // core/ui/uiStyle.ts
2217
+ var isRecord = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null && !Array.isArray(value), "isRecord");
2218
+ var finite = /* @__PURE__ */ __name((value) => typeof value === "number" && Number.isFinite(value), "finite");
2219
+ var nonEmpty = /* @__PURE__ */ __name((value) => typeof value === "string" && value.length > 0, "nonEmpty");
2220
+ function normalizeStops(value) {
2221
+ if (!Array.isArray(value)) return null;
2222
+ const stops = [];
2223
+ for (const stop of value) {
2224
+ if (isRecord(stop) && finite(stop.at) && nonEmpty(stop.color)) {
2225
+ stops.push({ at: Math.min(1, Math.max(0, stop.at)), color: stop.color });
2226
+ }
2227
+ }
2228
+ return stops.length >= 2 ? stops : null;
2229
+ }
2230
+ __name(normalizeStops, "normalizeStops");
2231
+ function normalizePaint(value) {
2232
+ if (!isRecord(value)) return void 0;
2233
+ if (value.kind === "solid" && nonEmpty(value.color)) {
2234
+ return { kind: "solid", color: value.color };
2235
+ }
2236
+ if (value.kind === "linear") {
2237
+ const stops = normalizeStops(value.stops);
2238
+ if (stops) {
2239
+ return {
2240
+ kind: "linear",
2241
+ angle: finite(value.angle) ? value.angle : 180,
2242
+ stops
2243
+ };
2244
+ }
2245
+ }
2246
+ if (value.kind === "radial") {
2247
+ const stops = normalizeStops(value.stops);
2248
+ if (stops) return { kind: "radial", stops };
2249
+ }
2250
+ if (value.kind === "image" && nonEmpty(value.src)) {
2251
+ const fit = value.fit === "contain" || value.fit === "fill" ? value.fit : "cover";
2252
+ return {
2253
+ kind: "image",
2254
+ src: value.src,
2255
+ fit,
2256
+ ...nonEmpty(value.tint) ? { tint: value.tint } : {}
2257
+ };
2258
+ }
2259
+ return void 0;
2260
+ }
2261
+ __name(normalizePaint, "normalizePaint");
2262
+ function normalizeShadow(value) {
2263
+ if (!isRecord(value) || !nonEmpty(value.color)) return void 0;
2264
+ return {
2265
+ x: finite(value.x) ? value.x : 0,
2266
+ y: finite(value.y) ? value.y : 0,
2267
+ blur: finite(value.blur) ? Math.max(0, value.blur) : 0,
2268
+ color: value.color
2269
+ };
2270
+ }
2271
+ __name(normalizeShadow, "normalizeShadow");
2272
+ function normalizeText(value) {
2273
+ if (!isRecord(value)) return void 0;
2274
+ const text = {};
2275
+ if (nonEmpty(value.font)) text.font = value.font;
2276
+ if (finite(value.weight)) text.weight = value.weight;
2277
+ if (finite(value.tracking)) text.tracking = value.tracking;
2278
+ if (value.transform === "upper" || value.transform === "lower") {
2279
+ text.transform = value.transform;
2280
+ }
2281
+ const paint = normalizePaint(value.paint);
2282
+ if (paint) text.paint = paint;
2283
+ if (finite(value.maxLines) && value.maxLines >= 1) {
2284
+ text.maxLines = Math.floor(value.maxLines);
2285
+ }
2286
+ const shadow = normalizeShadow(value.shadow);
2287
+ if (shadow) text.shadow = shadow;
2288
+ return Object.keys(text).length > 0 ? text : void 0;
2289
+ }
2290
+ __name(normalizeText, "normalizeText");
2291
+ function normalizeUiStyle(value) {
2292
+ if (!isRecord(value)) return void 0;
2293
+ const style = {};
2294
+ const fill = normalizePaint(value.fill);
2295
+ if (fill) style.fill = fill;
2296
+ if (isRecord(value.border) && finite(value.border.width)) {
2297
+ const paint = normalizePaint(value.border.paint);
2298
+ if (paint) {
2299
+ style.border = { width: Math.max(0, value.border.width), paint };
2300
+ }
2301
+ }
2302
+ if (finite(value.radius)) {
2303
+ style.radius = Math.max(0, value.radius);
2304
+ } else if (Array.isArray(value.radius) && value.radius.length === 4 && value.radius.every(finite)) {
2305
+ style.radius = value.radius.map((r) => Math.max(0, r));
2306
+ }
2307
+ if (Array.isArray(value.shadows)) {
2308
+ const shadows = value.shadows.map(normalizeShadow).filter((s) => !!s);
2309
+ if (shadows.length > 0) style.shadows = shadows;
2310
+ }
2311
+ if (isRecord(value.edge) && finite(value.edge.width) && nonEmpty(value.edge.color)) {
2312
+ style.edge = {
2313
+ width: Math.max(0, value.edge.width),
2314
+ color: value.edge.color
2315
+ };
2316
+ }
2317
+ if (finite(value.opacity)) {
2318
+ style.opacity = Math.min(1, Math.max(0, value.opacity));
2319
+ }
2320
+ const text = normalizeText(value.text);
2321
+ if (text) style.text = text;
2322
+ return Object.keys(style).length > 0 ? style : void 0;
2323
+ }
2324
+ __name(normalizeUiStyle, "normalizeUiStyle");
2325
+ function normalizeUiTokens(value) {
2326
+ if (!isRecord(value)) return void 0;
2327
+ const tokens = {};
2328
+ for (const [key, token] of Object.entries(value)) {
2329
+ if (nonEmpty(token) && key.length > 0 && !key.includes("/")) {
2330
+ tokens[key] = token;
2331
+ }
2332
+ }
2333
+ return Object.keys(tokens).length > 0 ? tokens : void 0;
2334
+ }
2335
+ __name(normalizeUiTokens, "normalizeUiTokens");
2336
+ function resolveToken(value, tokens, fallback = value) {
2337
+ if (!value.startsWith("$")) return value;
2338
+ return tokens?.[value.slice(1)] ?? fallback;
2339
+ }
2340
+ __name(resolveToken, "resolveToken");
2341
+ function resolvePaint(paint, tokens) {
2342
+ switch (paint.kind) {
2343
+ case "solid":
2344
+ return { kind: "solid", color: resolveToken(paint.color, tokens) };
2345
+ case "linear":
2346
+ case "radial":
2347
+ return {
2348
+ ...paint,
2349
+ stops: paint.stops.map((stop) => ({
2350
+ at: stop.at,
2351
+ color: resolveToken(stop.color, tokens)
2352
+ }))
2353
+ };
2354
+ case "image":
2355
+ return {
2356
+ ...paint,
2357
+ src: resolveToken(paint.src, tokens),
2358
+ ...paint.tint ? { tint: resolveToken(paint.tint, tokens) } : {}
2359
+ };
2360
+ }
2361
+ }
2362
+ __name(resolvePaint, "resolvePaint");
2363
+ function solidOf(paint) {
2364
+ if (paint.kind === "solid") return paint.color;
2365
+ if (paint.kind === "image") return paint.tint ?? "#ffffff";
2366
+ return paint.stops[0].color;
2367
+ }
2368
+ __name(solidOf, "solidOf");
2369
+ function radiusOf(radius, fallback) {
2370
+ if (Array.isArray(radius)) return radius;
2371
+ const r = radius ?? fallback;
2372
+ return [r, r, r, r];
2373
+ }
2374
+ __name(radiusOf, "radiusOf");
2375
+ function resolveChrome(flat, style, tokens) {
2376
+ const borderWidth = style?.border?.width ?? flat.borderWidth;
2377
+ const border = borderWidth > 0 ? {
2378
+ width: borderWidth,
2379
+ color: style?.border ? solidOf(resolvePaint(style.border.paint, tokens)) : resolveToken(flat.borderColor, tokens)
2380
+ } : null;
2381
+ return {
2382
+ fill: style?.fill ? resolvePaint(style.fill, tokens) : { kind: "solid", color: resolveToken(flat.backgroundColor, tokens) },
2383
+ fillOpacity: style?.fill ? 1 : flat.backgroundOpacity,
2384
+ radius: radiusOf(style?.radius, flat.cornerRadius),
2385
+ border,
2386
+ shadows: (style?.shadows ?? []).map((shadow) => ({
2387
+ ...shadow,
2388
+ color: resolveToken(shadow.color, tokens)
2389
+ })),
2390
+ edge: style?.edge ? { ...style.edge, color: resolveToken(style.edge.color, tokens) } : null
2391
+ };
2392
+ }
2393
+ __name(resolveChrome, "resolveChrome");
2394
+ function resolveText(flat, style, tokens) {
2395
+ const text = style?.text;
2396
+ return {
2397
+ ...flat,
2398
+ color: resolveToken(flat.color, tokens),
2399
+ fontWeight: text?.weight ?? flat.fontWeight,
2400
+ paint: text?.paint ? resolvePaint(text.paint, tokens) : { kind: "solid", color: resolveToken(flat.color, tokens) },
2401
+ font: text?.font ? resolveToken(text.font, tokens) : null,
2402
+ tracking: text?.tracking ?? 0,
2403
+ transform: text?.transform ?? null,
2404
+ maxLines: text?.maxLines ?? null,
2405
+ shadow: text?.shadow ? {
2406
+ ...text.shadow,
2407
+ color: resolveToken(text.shadow.color, tokens)
2408
+ } : null
2409
+ };
2410
+ }
2411
+ __name(resolveText, "resolveText");
2412
+ function chromeBleed(chrome) {
2413
+ let bleed = 0;
2414
+ for (const shadow of chrome.shadows) {
2415
+ bleed = Math.max(
2416
+ bleed,
2417
+ shadow.blur + Math.max(Math.abs(shadow.x), Math.abs(shadow.y))
2418
+ );
2419
+ }
2420
+ return bleed;
2421
+ }
2422
+ __name(chromeBleed, "chromeBleed");
2423
+ function styleAssets(chrome, text) {
2424
+ const images = [];
2425
+ const fonts = [];
2426
+ if (chrome?.fill?.kind === "image") images.push(chrome.fill.src);
2427
+ if (text?.paint.kind === "image") images.push(text.paint.src);
2428
+ if (text?.font) fonts.push(text.font);
2429
+ return { images, fonts };
2430
+ }
2431
+ __name(styleAssets, "styleAssets");
2432
+
2216
2433
  // core/components/UIPanel.ts
2217
2434
  var _UIPanelComponent = class _UIPanelComponent extends Component {
2218
2435
  constructor(options) {
@@ -2226,6 +2443,10 @@ var _UIPanelComponent = class _UIPanelComponent extends Component {
2226
2443
  this.borderColor = options?.borderColor ?? "#333333";
2227
2444
  this.pixelDensity = options?.pixelDensity ?? 1024;
2228
2445
  this.follow = options?.follow ?? "world";
2446
+ const style = normalizeUiStyle(options?.style);
2447
+ if (style) this.style = style;
2448
+ const tokens = normalizeUiTokens(options?.tokens);
2449
+ if (tokens) this.tokens = tokens;
2229
2450
  }
2230
2451
  };
2231
2452
  __name(_UIPanelComponent, "UIPanelComponent");
@@ -2245,6 +2466,11 @@ var _UITextComponent = class _UITextComponent extends Component {
2245
2466
  this.valign = options?.valign ?? "middle";
2246
2467
  this.lineHeight = options?.lineHeight ?? 1.25;
2247
2468
  this.padding = options?.padding ?? 0.01;
2469
+ if (options?.pixelDensity !== void 0) {
2470
+ this.pixelDensity = options.pixelDensity;
2471
+ }
2472
+ const style = normalizeUiStyle(options?.style);
2473
+ if (style) this.style = style;
2248
2474
  }
2249
2475
  };
2250
2476
  __name(_UITextComponent, "UITextComponent");
@@ -2266,6 +2492,13 @@ var _UIButtonComponent = class _UIButtonComponent extends Component {
2266
2492
  this.cornerRadius = options?.cornerRadius ?? 0.02;
2267
2493
  this.borderWidth = options?.borderWidth ?? 2e-3;
2268
2494
  this.borderColor = options?.borderColor ?? "#3a3a3a";
2495
+ if (options?.pixelDensity !== void 0) {
2496
+ this.pixelDensity = options.pixelDensity;
2497
+ }
2498
+ const style = normalizeUiStyle(options?.style);
2499
+ if (style) this.style = style;
2500
+ if (options?.icon) this.icon = options.icon;
2501
+ if (options?.iconPosition) this.iconPosition = options.iconPosition;
2269
2502
  }
2270
2503
  };
2271
2504
  __name(_UIButtonComponent, "UIButtonComponent");
@@ -2282,6 +2515,12 @@ var _UIToggleComponent = class _UIToggleComponent extends Component {
2282
2515
  this.trackColor = options?.trackColor ?? "#2a2a2a";
2283
2516
  this.accentColor = options?.accentColor ?? "#ff6b35";
2284
2517
  this.knobColor = options?.knobColor ?? "#ffffff";
2518
+ if (options?.pixelDensity !== void 0) {
2519
+ this.pixelDensity = options.pixelDensity;
2520
+ }
2521
+ const style = normalizeUiStyle(options?.style);
2522
+ if (style) this.style = style;
2523
+ if (options?.variant) this.variant = options.variant;
2285
2524
  }
2286
2525
  };
2287
2526
  __name(_UIToggleComponent, "UIToggleComponent");
@@ -2302,6 +2541,14 @@ var _UISliderComponent = class _UISliderComponent extends Component {
2302
2541
  this.trackColor = options?.trackColor ?? "#2a2a2a";
2303
2542
  this.accentColor = options?.accentColor ?? "#ff6b35";
2304
2543
  this.knobColor = options?.knobColor ?? "#ffffff";
2544
+ if (options?.pixelDensity !== void 0) {
2545
+ this.pixelDensity = options.pixelDensity;
2546
+ }
2547
+ const style = normalizeUiStyle(options?.style);
2548
+ if (style) this.style = style;
2549
+ if (options?.variant) this.variant = options.variant;
2550
+ if (options?.step !== void 0) this.step = options.step;
2551
+ if (options?.readOnly !== void 0) this.readOnly = options.readOnly;
2305
2552
  }
2306
2553
  };
2307
2554
  __name(_UISliderComponent, "UISliderComponent");
@@ -2565,6 +2812,6 @@ var _XRHandPoseComponent = class _XRHandPoseComponent extends Component {
2565
2812
  __name(_XRHandPoseComponent, "XRHandPoseComponent");
2566
2813
  var XRHandPoseComponent = _XRHandPoseComponent;
2567
2814
 
2568
- export { AnimationComponent, AnimationStateMachine, AnimationStateManager, AudioComponent, BoneAttachmentComponent, CameraComponent, DEFAULT_COLLIDER_STATE, DEFAULT_ENVIRONMENT_LIGHTING, DEFAULT_ENVIRONMENT_STATE, DEFAULT_INSTANCED_MESH_PARAMETERS, DEFAULT_INSTANCE_TRANSFORM, DEFAULT_MESH_GEOMETRY_PARAMETERS, DEFAULT_PHYSICS_STATE, DEFAULT_POSE_CURLS, DEFAULT_POSE_DIRECTIONS, DEFAULT_POSTPROCESSING_STATE, DEFAULT_RIGIDBODY_STATE, EntityType, Environment, HAND_POSE_PRESETS, HAND_POSE_PRESET_IDS, IKComponent, ImageComponent, ImageTarget, ImageTargetAnchor, InstanceSlotComponent, InstancedMeshComponent, LightComponent, MODEL_NO_PATH_MESSAGE, MaterialComponent, MeshComponent, MeshGeometryComponent, ModelComponent, Name, NetworkIdentityComponent, NetworkSpawnerComponent, NetworkTransformComponent, NetworkedPropsComponent, Object3DRef, ParentId, PhysicsComponent, Postprocessing, PrefabInstance, PrefabNode, ScriptComponent, ScriptObjectComponent, Selectable, SelectionTransformState, SpriteComponent, TransformComponent, UIButtonComponent, UIPanelComponent, UISliderComponent, UITextComponent, UIToggleComponent, VRTeleportAreaComponent, VideoComponent, XRAnchorComponent, XREnvironmentComponent, XRHandPoseComponent, XRInteractableComponent, XRInteractorComponent, XRInteractorSideComponent, XRRigComponent, cloneHandPose, components_exports, createAttachPoint, createHandPoseEntry, defaultMaterialValue, getHandPosePreset, handPoseDefinitionFor, handPoseFromCurls, normalizeEnvironmentLighting, normalizeIKChain, normalizePhysicsState, setModelLoadState, setPhysicsLiveRef };
2569
- //# sourceMappingURL=chunk-NNDUOQ7O.js.map
2570
- //# sourceMappingURL=chunk-NNDUOQ7O.js.map
2815
+ export { AnimationComponent, AnimationStateMachine, AnimationStateManager, AudioComponent, BoneAttachmentComponent, CameraComponent, DEFAULT_COLLIDER_STATE, DEFAULT_ENVIRONMENT_LIGHTING, DEFAULT_ENVIRONMENT_STATE, DEFAULT_INSTANCED_MESH_PARAMETERS, DEFAULT_INSTANCE_TRANSFORM, DEFAULT_MESH_GEOMETRY_PARAMETERS, DEFAULT_PHYSICS_STATE, DEFAULT_POSE_CURLS, DEFAULT_POSE_DIRECTIONS, DEFAULT_POSTPROCESSING_STATE, DEFAULT_RIGIDBODY_STATE, EntityType, Environment, HAND_POSE_PRESETS, HAND_POSE_PRESET_IDS, IKComponent, ImageComponent, ImageTarget, ImageTargetAnchor, InstanceSlotComponent, InstancedMeshComponent, LightComponent, MODEL_NO_PATH_MESSAGE, MaterialComponent, MeshComponent, MeshGeometryComponent, ModelComponent, Name, NetworkIdentityComponent, NetworkSpawnerComponent, NetworkTransformComponent, NetworkedPropsComponent, Object3DRef, ParentId, PhysicsComponent, Postprocessing, PrefabInstance, PrefabNode, ScriptComponent, ScriptObjectComponent, Selectable, SelectionTransformState, SpriteComponent, TransformComponent, UIButtonComponent, UIPanelComponent, UISliderComponent, UITextComponent, UIToggleComponent, VRTeleportAreaComponent, VideoComponent, XRAnchorComponent, XREnvironmentComponent, XRHandPoseComponent, XRInteractableComponent, XRInteractorComponent, XRInteractorSideComponent, XRRigComponent, chromeBleed, cloneHandPose, components_exports, createAttachPoint, createHandPoseEntry, defaultMaterialValue, getHandPosePreset, handPoseDefinitionFor, handPoseFromCurls, normalizeEnvironmentLighting, normalizeIKChain, normalizePhysicsState, normalizeUiStyle, normalizeUiTokens, resolveChrome, resolveText, resolveToken, setModelLoadState, setPhysicsLiveRef, styleAssets };
2816
+ //# sourceMappingURL=chunk-JNYPJB55.js.map
2817
+ //# sourceMappingURL=chunk-JNYPJB55.js.map