@almadar/ui 5.136.0 → 5.137.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.
@@ -13207,6 +13207,11 @@ function Canvas2D({
13207
13207
  }
13208
13208
  return { width: maxX + 1, height: maxY + 1 };
13209
13209
  }, [scenePositions]);
13210
+ const defaultGridFocus = React92.useMemo(() => {
13211
+ if (isFree || projection === "side") return void 0;
13212
+ if (gridExtent.width < 2 || gridExtent.height < 2) return void 0;
13213
+ return { x: (gridExtent.width - 1) / 2, y: (gridExtent.height - 1) / 2 };
13214
+ }, [isFree, projection, gridExtent]);
13210
13215
  const baseOffsetX = React92.useMemo(() => {
13211
13216
  if (isFree || projection === "flat" || projection === "side") return 0;
13212
13217
  return (gridExtent.height - 1) * (scaledTileWidth / 2);
@@ -13311,10 +13316,13 @@ function Canvas2D({
13311
13316
  }
13312
13317
  if (!drawables || drawables.length === 0) return;
13313
13318
  const cam = cameraRef.current;
13314
- if (cameraPos && dragDistance() === 0) {
13315
- const p = projector.anchorPoint(cameraPos, "center");
13316
- cam.x = p.x - viewportSize.width / 2;
13317
- cam.y = p.y - viewportSize.height / 2;
13319
+ if (camera !== "follow" && dragDistance() === 0) {
13320
+ const focus = cameraPos ?? defaultGridFocus;
13321
+ if (focus) {
13322
+ const p = projector.anchorPoint(focus, "center");
13323
+ cam.x = p.x - viewportSize.width / 2;
13324
+ cam.y = p.y - viewportSize.height / 2;
13325
+ }
13318
13326
  }
13319
13327
  const containerRect = containerRef.current?.getBoundingClientRect();
13320
13328
  const canvasRect = canvas.getBoundingClientRect();
@@ -13327,7 +13335,7 @@ function Canvas2D({
13327
13335
  const dctx = { projector, time: 0, invalidate: bumpAtlas };
13328
13336
  for (const node of drawables) paintDrawable(painter, node, dctx);
13329
13337
  painter.restore();
13330
- }, [viewportSize, backgroundImage, bgColor, drawables, projector, cameraRef, bumpAtlas, getImage]);
13338
+ }, [viewportSize, backgroundImage, bgColor, drawables, projector, cameraRef, bumpAtlas, getImage, cameraPos, defaultGridFocus, camera, dragDistance]);
13331
13339
  React92.useEffect(() => {
13332
13340
  if (camera !== "follow" || !followTarget) return;
13333
13341
  const p = projector.anchorPoint(followTarget, "center");
package/dist/avl/index.js CHANGED
@@ -13131,6 +13131,11 @@ function Canvas2D({
13131
13131
  }
13132
13132
  return { width: maxX + 1, height: maxY + 1 };
13133
13133
  }, [scenePositions]);
13134
+ const defaultGridFocus = useMemo(() => {
13135
+ if (isFree || projection === "side") return void 0;
13136
+ if (gridExtent.width < 2 || gridExtent.height < 2) return void 0;
13137
+ return { x: (gridExtent.width - 1) / 2, y: (gridExtent.height - 1) / 2 };
13138
+ }, [isFree, projection, gridExtent]);
13134
13139
  const baseOffsetX = useMemo(() => {
13135
13140
  if (isFree || projection === "flat" || projection === "side") return 0;
13136
13141
  return (gridExtent.height - 1) * (scaledTileWidth / 2);
@@ -13235,10 +13240,13 @@ function Canvas2D({
13235
13240
  }
13236
13241
  if (!drawables || drawables.length === 0) return;
13237
13242
  const cam = cameraRef.current;
13238
- if (cameraPos && dragDistance() === 0) {
13239
- const p = projector.anchorPoint(cameraPos, "center");
13240
- cam.x = p.x - viewportSize.width / 2;
13241
- cam.y = p.y - viewportSize.height / 2;
13243
+ if (camera !== "follow" && dragDistance() === 0) {
13244
+ const focus = cameraPos ?? defaultGridFocus;
13245
+ if (focus) {
13246
+ const p = projector.anchorPoint(focus, "center");
13247
+ cam.x = p.x - viewportSize.width / 2;
13248
+ cam.y = p.y - viewportSize.height / 2;
13249
+ }
13242
13250
  }
13243
13251
  const containerRect = containerRef.current?.getBoundingClientRect();
13244
13252
  const canvasRect = canvas.getBoundingClientRect();
@@ -13251,7 +13259,7 @@ function Canvas2D({
13251
13259
  const dctx = { projector, time: 0, invalidate: bumpAtlas };
13252
13260
  for (const node of drawables) paintDrawable(painter, node, dctx);
13253
13261
  painter.restore();
13254
- }, [viewportSize, backgroundImage, bgColor, drawables, projector, cameraRef, bumpAtlas, getImage]);
13262
+ }, [viewportSize, backgroundImage, bgColor, drawables, projector, cameraRef, bumpAtlas, getImage, cameraPos, defaultGridFocus, camera, dragDistance]);
13255
13263
  useEffect(() => {
13256
13264
  if (camera !== "follow" || !followTarget) return;
13257
13265
  const p = projector.anchorPoint(followTarget, "center");
@@ -16337,6 +16337,11 @@ function Canvas2D({
16337
16337
  }
16338
16338
  return { width: maxX + 1, height: maxY + 1 };
16339
16339
  }, [scenePositions]);
16340
+ const defaultGridFocus = React75.useMemo(() => {
16341
+ if (isFree || projection === "side") return void 0;
16342
+ if (gridExtent.width < 2 || gridExtent.height < 2) return void 0;
16343
+ return { x: (gridExtent.width - 1) / 2, y: (gridExtent.height - 1) / 2 };
16344
+ }, [isFree, projection, gridExtent]);
16340
16345
  const baseOffsetX = React75.useMemo(() => {
16341
16346
  if (isFree || projection === "flat" || projection === "side") return 0;
16342
16347
  return (gridExtent.height - 1) * (scaledTileWidth / 2);
@@ -16441,10 +16446,13 @@ function Canvas2D({
16441
16446
  }
16442
16447
  if (!drawables || drawables.length === 0) return;
16443
16448
  const cam = cameraRef.current;
16444
- if (cameraPos && dragDistance() === 0) {
16445
- const p = projector.anchorPoint(cameraPos, "center");
16446
- cam.x = p.x - viewportSize.width / 2;
16447
- cam.y = p.y - viewportSize.height / 2;
16449
+ if (camera !== "follow" && dragDistance() === 0) {
16450
+ const focus = cameraPos ?? defaultGridFocus;
16451
+ if (focus) {
16452
+ const p = projector.anchorPoint(focus, "center");
16453
+ cam.x = p.x - viewportSize.width / 2;
16454
+ cam.y = p.y - viewportSize.height / 2;
16455
+ }
16448
16456
  }
16449
16457
  const containerRect = containerRef.current?.getBoundingClientRect();
16450
16458
  const canvasRect = canvas.getBoundingClientRect();
@@ -16457,7 +16465,7 @@ function Canvas2D({
16457
16465
  const dctx = { projector, time: 0, invalidate: bumpAtlas };
16458
16466
  for (const node of drawables) paintDrawable(painter, node, dctx);
16459
16467
  painter.restore();
16460
- }, [viewportSize, backgroundImage, bgColor, drawables, projector, cameraRef, bumpAtlas, getImage]);
16468
+ }, [viewportSize, backgroundImage, bgColor, drawables, projector, cameraRef, bumpAtlas, getImage, cameraPos, defaultGridFocus, camera, dragDistance]);
16461
16469
  React75.useEffect(() => {
16462
16470
  if (camera !== "follow" || !followTarget) return;
16463
16471
  const p = projector.anchorPoint(followTarget, "center");
@@ -16262,6 +16262,11 @@ function Canvas2D({
16262
16262
  }
16263
16263
  return { width: maxX + 1, height: maxY + 1 };
16264
16264
  }, [scenePositions]);
16265
+ const defaultGridFocus = useMemo(() => {
16266
+ if (isFree || projection === "side") return void 0;
16267
+ if (gridExtent.width < 2 || gridExtent.height < 2) return void 0;
16268
+ return { x: (gridExtent.width - 1) / 2, y: (gridExtent.height - 1) / 2 };
16269
+ }, [isFree, projection, gridExtent]);
16265
16270
  const baseOffsetX = useMemo(() => {
16266
16271
  if (isFree || projection === "flat" || projection === "side") return 0;
16267
16272
  return (gridExtent.height - 1) * (scaledTileWidth / 2);
@@ -16366,10 +16371,13 @@ function Canvas2D({
16366
16371
  }
16367
16372
  if (!drawables || drawables.length === 0) return;
16368
16373
  const cam = cameraRef.current;
16369
- if (cameraPos && dragDistance() === 0) {
16370
- const p = projector.anchorPoint(cameraPos, "center");
16371
- cam.x = p.x - viewportSize.width / 2;
16372
- cam.y = p.y - viewportSize.height / 2;
16374
+ if (camera !== "follow" && dragDistance() === 0) {
16375
+ const focus = cameraPos ?? defaultGridFocus;
16376
+ if (focus) {
16377
+ const p = projector.anchorPoint(focus, "center");
16378
+ cam.x = p.x - viewportSize.width / 2;
16379
+ cam.y = p.y - viewportSize.height / 2;
16380
+ }
16373
16381
  }
16374
16382
  const containerRect = containerRef.current?.getBoundingClientRect();
16375
16383
  const canvasRect = canvas.getBoundingClientRect();
@@ -16382,7 +16390,7 @@ function Canvas2D({
16382
16390
  const dctx = { projector, time: 0, invalidate: bumpAtlas };
16383
16391
  for (const node of drawables) paintDrawable(painter, node, dctx);
16384
16392
  painter.restore();
16385
- }, [viewportSize, backgroundImage, bgColor, drawables, projector, cameraRef, bumpAtlas, getImage]);
16393
+ }, [viewportSize, backgroundImage, bgColor, drawables, projector, cameraRef, bumpAtlas, getImage, cameraPos, defaultGridFocus, camera, dragDistance]);
16386
16394
  useEffect(() => {
16387
16395
  if (camera !== "follow" || !followTarget) return;
16388
16396
  const p = projector.anchorPoint(followTarget, "center");
@@ -9465,6 +9465,11 @@ function Canvas2D({
9465
9465
  }
9466
9466
  return { width: maxX + 1, height: maxY + 1 };
9467
9467
  }, [scenePositions]);
9468
+ const defaultGridFocus = React85.useMemo(() => {
9469
+ if (isFree || projection === "side") return void 0;
9470
+ if (gridExtent.width < 2 || gridExtent.height < 2) return void 0;
9471
+ return { x: (gridExtent.width - 1) / 2, y: (gridExtent.height - 1) / 2 };
9472
+ }, [isFree, projection, gridExtent]);
9468
9473
  const baseOffsetX = React85.useMemo(() => {
9469
9474
  if (isFree || projection === "flat" || projection === "side") return 0;
9470
9475
  return (gridExtent.height - 1) * (scaledTileWidth / 2);
@@ -9569,10 +9574,13 @@ function Canvas2D({
9569
9574
  }
9570
9575
  if (!drawables || drawables.length === 0) return;
9571
9576
  const cam = cameraRef.current;
9572
- if (cameraPos && dragDistance() === 0) {
9573
- const p = projector.anchorPoint(cameraPos, "center");
9574
- cam.x = p.x - viewportSize.width / 2;
9575
- cam.y = p.y - viewportSize.height / 2;
9577
+ if (camera !== "follow" && dragDistance() === 0) {
9578
+ const focus = cameraPos ?? defaultGridFocus;
9579
+ if (focus) {
9580
+ const p = projector.anchorPoint(focus, "center");
9581
+ cam.x = p.x - viewportSize.width / 2;
9582
+ cam.y = p.y - viewportSize.height / 2;
9583
+ }
9576
9584
  }
9577
9585
  const containerRect = containerRef.current?.getBoundingClientRect();
9578
9586
  const canvasRect = canvas.getBoundingClientRect();
@@ -9585,7 +9593,7 @@ function Canvas2D({
9585
9593
  const dctx = { projector, time: 0, invalidate: bumpAtlas };
9586
9594
  for (const node of drawables) paintDrawable(painter, node, dctx);
9587
9595
  painter.restore();
9588
- }, [viewportSize, backgroundImage, bgColor, drawables, projector, cameraRef, bumpAtlas, getImage]);
9596
+ }, [viewportSize, backgroundImage, bgColor, drawables, projector, cameraRef, bumpAtlas, getImage, cameraPos, defaultGridFocus, camera, dragDistance]);
9589
9597
  React85.useEffect(() => {
9590
9598
  if (camera !== "follow" || !followTarget) return;
9591
9599
  const p = projector.anchorPoint(followTarget, "center");
@@ -9391,6 +9391,11 @@ function Canvas2D({
9391
9391
  }
9392
9392
  return { width: maxX + 1, height: maxY + 1 };
9393
9393
  }, [scenePositions]);
9394
+ const defaultGridFocus = useMemo(() => {
9395
+ if (isFree || projection === "side") return void 0;
9396
+ if (gridExtent.width < 2 || gridExtent.height < 2) return void 0;
9397
+ return { x: (gridExtent.width - 1) / 2, y: (gridExtent.height - 1) / 2 };
9398
+ }, [isFree, projection, gridExtent]);
9394
9399
  const baseOffsetX = useMemo(() => {
9395
9400
  if (isFree || projection === "flat" || projection === "side") return 0;
9396
9401
  return (gridExtent.height - 1) * (scaledTileWidth / 2);
@@ -9495,10 +9500,13 @@ function Canvas2D({
9495
9500
  }
9496
9501
  if (!drawables || drawables.length === 0) return;
9497
9502
  const cam = cameraRef.current;
9498
- if (cameraPos && dragDistance() === 0) {
9499
- const p = projector.anchorPoint(cameraPos, "center");
9500
- cam.x = p.x - viewportSize.width / 2;
9501
- cam.y = p.y - viewportSize.height / 2;
9503
+ if (camera !== "follow" && dragDistance() === 0) {
9504
+ const focus = cameraPos ?? defaultGridFocus;
9505
+ if (focus) {
9506
+ const p = projector.anchorPoint(focus, "center");
9507
+ cam.x = p.x - viewportSize.width / 2;
9508
+ cam.y = p.y - viewportSize.height / 2;
9509
+ }
9502
9510
  }
9503
9511
  const containerRect = containerRef.current?.getBoundingClientRect();
9504
9512
  const canvasRect = canvas.getBoundingClientRect();
@@ -9511,7 +9519,7 @@ function Canvas2D({
9511
9519
  const dctx = { projector, time: 0, invalidate: bumpAtlas };
9512
9520
  for (const node of drawables) paintDrawable(painter, node, dctx);
9513
9521
  painter.restore();
9514
- }, [viewportSize, backgroundImage, bgColor, drawables, projector, cameraRef, bumpAtlas, getImage]);
9522
+ }, [viewportSize, backgroundImage, bgColor, drawables, projector, cameraRef, bumpAtlas, getImage, cameraPos, defaultGridFocus, camera, dragDistance]);
9515
9523
  useEffect(() => {
9516
9524
  if (camera !== "follow" || !followTarget) return;
9517
9525
  const p = projector.anchorPoint(followTarget, "center");
@@ -9819,6 +9819,11 @@ function Canvas2D({
9819
9819
  }
9820
9820
  return { width: maxX + 1, height: maxY + 1 };
9821
9821
  }, [scenePositions]);
9822
+ const defaultGridFocus = React83.useMemo(() => {
9823
+ if (isFree || projection === "side") return void 0;
9824
+ if (gridExtent.width < 2 || gridExtent.height < 2) return void 0;
9825
+ return { x: (gridExtent.width - 1) / 2, y: (gridExtent.height - 1) / 2 };
9826
+ }, [isFree, projection, gridExtent]);
9822
9827
  const baseOffsetX = React83.useMemo(() => {
9823
9828
  if (isFree || projection === "flat" || projection === "side") return 0;
9824
9829
  return (gridExtent.height - 1) * (scaledTileWidth / 2);
@@ -9923,10 +9928,13 @@ function Canvas2D({
9923
9928
  }
9924
9929
  if (!drawables || drawables.length === 0) return;
9925
9930
  const cam = cameraRef.current;
9926
- if (cameraPos && dragDistance() === 0) {
9927
- const p = projector.anchorPoint(cameraPos, "center");
9928
- cam.x = p.x - viewportSize.width / 2;
9929
- cam.y = p.y - viewportSize.height / 2;
9931
+ if (camera !== "follow" && dragDistance() === 0) {
9932
+ const focus = cameraPos ?? defaultGridFocus;
9933
+ if (focus) {
9934
+ const p = projector.anchorPoint(focus, "center");
9935
+ cam.x = p.x - viewportSize.width / 2;
9936
+ cam.y = p.y - viewportSize.height / 2;
9937
+ }
9930
9938
  }
9931
9939
  const containerRect = containerRef.current?.getBoundingClientRect();
9932
9940
  const canvasRect = canvas.getBoundingClientRect();
@@ -9939,7 +9947,7 @@ function Canvas2D({
9939
9947
  const dctx = { projector, time: 0, invalidate: bumpAtlas };
9940
9948
  for (const node of drawables) paintDrawable(painter, node, dctx);
9941
9949
  painter.restore();
9942
- }, [viewportSize, backgroundImage, bgColor, drawables, projector, cameraRef, bumpAtlas, getImage]);
9950
+ }, [viewportSize, backgroundImage, bgColor, drawables, projector, cameraRef, bumpAtlas, getImage, cameraPos, defaultGridFocus, camera, dragDistance]);
9943
9951
  React83.useEffect(() => {
9944
9952
  if (camera !== "follow" || !followTarget) return;
9945
9953
  const p = projector.anchorPoint(followTarget, "center");
@@ -9745,6 +9745,11 @@ function Canvas2D({
9745
9745
  }
9746
9746
  return { width: maxX + 1, height: maxY + 1 };
9747
9747
  }, [scenePositions]);
9748
+ const defaultGridFocus = useMemo(() => {
9749
+ if (isFree || projection === "side") return void 0;
9750
+ if (gridExtent.width < 2 || gridExtent.height < 2) return void 0;
9751
+ return { x: (gridExtent.width - 1) / 2, y: (gridExtent.height - 1) / 2 };
9752
+ }, [isFree, projection, gridExtent]);
9748
9753
  const baseOffsetX = useMemo(() => {
9749
9754
  if (isFree || projection === "flat" || projection === "side") return 0;
9750
9755
  return (gridExtent.height - 1) * (scaledTileWidth / 2);
@@ -9849,10 +9854,13 @@ function Canvas2D({
9849
9854
  }
9850
9855
  if (!drawables || drawables.length === 0) return;
9851
9856
  const cam = cameraRef.current;
9852
- if (cameraPos && dragDistance() === 0) {
9853
- const p = projector.anchorPoint(cameraPos, "center");
9854
- cam.x = p.x - viewportSize.width / 2;
9855
- cam.y = p.y - viewportSize.height / 2;
9857
+ if (camera !== "follow" && dragDistance() === 0) {
9858
+ const focus = cameraPos ?? defaultGridFocus;
9859
+ if (focus) {
9860
+ const p = projector.anchorPoint(focus, "center");
9861
+ cam.x = p.x - viewportSize.width / 2;
9862
+ cam.y = p.y - viewportSize.height / 2;
9863
+ }
9856
9864
  }
9857
9865
  const containerRect = containerRef.current?.getBoundingClientRect();
9858
9866
  const canvasRect = canvas.getBoundingClientRect();
@@ -9865,7 +9873,7 @@ function Canvas2D({
9865
9873
  const dctx = { projector, time: 0, invalidate: bumpAtlas };
9866
9874
  for (const node of drawables) paintDrawable(painter, node, dctx);
9867
9875
  painter.restore();
9868
- }, [viewportSize, backgroundImage, bgColor, drawables, projector, cameraRef, bumpAtlas, getImage]);
9876
+ }, [viewportSize, backgroundImage, bgColor, drawables, projector, cameraRef, bumpAtlas, getImage, cameraPos, defaultGridFocus, camera, dragDistance]);
9869
9877
  useEffect(() => {
9870
9878
  if (camera !== "follow" || !followTarget) return;
9871
9879
  const p = projector.anchorPoint(followTarget, "center");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/ui",
3
- "version": "5.136.0",
3
+ "version": "5.137.0",
4
4
  "description": "React UI components, hooks, and providers for Almadar",
5
5
  "type": "module",
6
6
  "sideEffects": [