@kineviz/gl 0.4.2 → 0.4.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/dist/index.mjs CHANGED
@@ -7771,6 +7771,61 @@ var GPUForceLayoutController = class {
7771
7771
  const edgeRatio = (nearMin + nearMax) / count2;
7772
7772
  }
7773
7773
  };
7774
+ var GPULayoutControllerAdapter = class {
7775
+ constructor(c2) {
7776
+ this.c = c2;
7777
+ this.mode = "gpu";
7778
+ }
7779
+ // mode='gpu' → positions live in the WebGL FBO texture; the engine's
7780
+ // GPUNodeRenderer/GPUEdgeRenderer sample it directly (no CPU readback).
7781
+ getPositionTexture() {
7782
+ return this.c.getPositionTexture();
7783
+ }
7784
+ getTextureSize() {
7785
+ return this.c.getTextureSize();
7786
+ }
7787
+ getSpaceSize() {
7788
+ return this.c.getSpaceSize();
7789
+ }
7790
+ // The controller self-ticks via its own RAF; the engine's per-frame tick()
7791
+ // is a no-op here (same as the WebGPU adapter).
7792
+ tick() {
7793
+ }
7794
+ start() {
7795
+ this.c.startLayout();
7796
+ }
7797
+ stop() {
7798
+ this.c.stopLayout();
7799
+ }
7800
+ // Annotated to the interface shape so the public getter doesn't leak the
7801
+ // controller's non-exported LayoutGraph type (TS4041 in standalone DTS build).
7802
+ get graph() {
7803
+ return this.c.graph;
7804
+ }
7805
+ // Drive the engine's render loop while the simulation is converging: positions
7806
+ // keep moving until alpha decays (isFinish). Without this, RenderRuntime.update()
7807
+ // short-circuits on _needsRender=false and never reflects the moving layout.
7808
+ get needsUpdate() {
7809
+ return !this.c.isFinish;
7810
+ }
7811
+ clearNeedsUpdate() {
7812
+ }
7813
+ pinNodes(nodes) {
7814
+ this.c.pinNodes(nodes);
7815
+ }
7816
+ unpinNodes(nodeIds) {
7817
+ this.c.unpinNodes(nodeIds);
7818
+ }
7819
+ transitionDimensions(dimensions, duration) {
7820
+ this.c.transitionDimensions(dimensions, duration);
7821
+ }
7822
+ getDimensions() {
7823
+ return this.c.getDimensions();
7824
+ }
7825
+ updateOption(name, value) {
7826
+ this.c.updateLayoutOption(name, value);
7827
+ }
7828
+ };
7774
7829
  var DEFAULTS = {
7775
7830
  charge: -0.01,
7776
7831
  gravity: 0.1,
@@ -8447,6 +8502,36 @@ var WebGPULayoutControllerAdapter = class {
8447
8502
  this.c.updateLayoutOption(name, value);
8448
8503
  }
8449
8504
  };
8505
+ function createForceLayout(options) {
8506
+ const { backend = "auto", renderer, config, graph, autoStart = true } = options;
8507
+ let chosen;
8508
+ if (backend === "webgpu") {
8509
+ if (isWebGPUAvailable()) {
8510
+ chosen = "webgpu";
8511
+ } else {
8512
+ console.warn('[createForceLayout] backend="webgpu" requested but navigator.gpu is unavailable; falling back to WebGL.');
8513
+ chosen = "webgl";
8514
+ }
8515
+ } else if (backend === "webgl") {
8516
+ chosen = "webgl";
8517
+ } else {
8518
+ chosen = isWebGPUAvailable() ? "webgpu" : "webgl";
8519
+ }
8520
+ const scratch = graph ?? { layoutNodes: [], layoutEdges: [], renderNeedsUpdate: true };
8521
+ if (chosen === "webgpu") {
8522
+ const controller = new WebGPUForceLayoutController(scratch);
8523
+ controller.config(config);
8524
+ const adapter = new WebGPULayoutControllerAdapter(controller);
8525
+ if (autoStart) controller.startLayout();
8526
+ return { controller, adapter, backend: "webgpu" };
8527
+ } else {
8528
+ const controller = new GPUForceLayoutController(scratch, renderer);
8529
+ controller.config(config);
8530
+ const adapter = new GPULayoutControllerAdapter(controller);
8531
+ if (autoStart) controller.startLayout();
8532
+ return { controller, adapter, backend: "webgl" };
8533
+ }
8534
+ }
8450
8535
  function mergeSnapshotWithDelta(snapshot, delta) {
8451
8536
  const nodeMap = new Map(snapshot.nodes.map((n) => [n.id, { ...n }]));
8452
8537
  const edgeMap = new Map(snapshot.edges.map((e) => [e.id, { ...e }]));
@@ -55743,6 +55828,7 @@ export {
55743
55828
  GPUForceLayoutController,
55744
55829
  GPUForceLayoutEngine,
55745
55830
  GPUGroupRingRenderer,
55831
+ GPULayoutControllerAdapter,
55746
55832
  GPULayoutProviderAdapter,
55747
55833
  GPUNodeRenderer,
55748
55834
  GPUPositionProvider,
@@ -55836,6 +55922,7 @@ export {
55836
55922
  createDefaultItems,
55837
55923
  createDefaultRegistry,
55838
55924
  createEdgeTextCloud,
55925
+ createForceLayout,
55839
55926
  createTextCloud,
55840
55927
  cubeLayout,
55841
55928
  defaultEdgeStyles,