@krizaka/ui 3.33.1 → 3.35.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.
package/dist/map.d.ts CHANGED
@@ -321,9 +321,13 @@ type RouteProps = {
321
321
  replayKey?: string | number;
322
322
  /** `accent` or `soft`. Default `accent`. */
323
323
  tone?: "accent" | "soft";
324
+ /** The timing function of the drawing and of the trips: `ease-out`, `linear`, `ease-in-out`. Default: out for the drawing, in-out for a trip. */
325
+ easing?: "ease-out" | "linear" | "ease-in-out";
326
+ /** Holds the drawing and the trips where they are (a controlled pause, on top of the off-screen one). */
327
+ paused?: boolean;
324
328
  };
325
329
  /** A route on the map: a line that draws itself, and a courier that travels it. Under reduced motion the line is whole and the courier rests at the end. */
326
- declare function Route({ path, label, draw, duration, courier, tripDuration, repeatAfter, replayKey, tone }: RouteProps): null;
330
+ declare function Route({ path, label, draw, duration, courier, tripDuration, repeatAfter, replayKey, tone, easing, paused }: RouteProps): null;
327
331
  type RadiusCircleProps = {
328
332
  /** Its centre. */
329
333
  center: LngLat;
package/dist/map.js CHANGED
@@ -891,7 +891,12 @@ function Pulse({ position, label, size = 56, tone = "accent" }) {
891
891
  }, [m, lib, tone, size, position[0], position[1]]);
892
892
  return null;
893
893
  }
894
- function Route({ path, label, draw = true, duration = 1400, courier, tripDuration = 3200, repeatAfter, replayKey, tone = "accent" }) {
894
+ var ROUTE_CURVES = {
895
+ linear: (t) => t,
896
+ "ease-out": (t) => 1 - (1 - t) ** 3,
897
+ "ease-in-out": (t) => t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2
898
+ };
899
+ function Route({ path, label, draw = true, duration = 1400, courier, tripDuration = 3200, repeatAfter, replayKey, tone = "accent", easing, paused = false }) {
895
900
  const { map: m, lib, ready, reduce, places } = useMap();
896
901
  const id = `kz-route-${React2.useId().replace(/[^a-zA-Z0-9]/g, "")}`;
897
902
  const animated = draw && !reduce;
@@ -908,11 +913,12 @@ function Route({ path, label, draw = true, duration = 1400, courier, tripDuratio
908
913
  { id: `${id}-casing`, type: "line", source: id, layout: { "line-cap": "round", "line-join": "round" }, paint: { "line-color": c.accent, "line-width": 9, "line-opacity": tone === "soft" ? 0.08 : 0.16, "line-blur": 3 } },
909
914
  { id: `${id}-line`, type: "line", source: id, layout: { "line-cap": "round", "line-join": "round" }, paint: { "line-color": c.accent, "line-width": tone === "soft" ? 2 : 3.5, "line-opacity": tone === "soft" ? 0.6 : 1 } }
910
915
  ]);
911
- const [visible, setVisible] = React2.useState(() => typeof IntersectionObserver === "undefined");
916
+ const [seen, setSeen] = React2.useState(() => typeof IntersectionObserver === "undefined");
917
+ const visible = seen && !paused;
912
918
  React2.useEffect(() => {
913
919
  const el = m?.getContainer?.();
914
920
  if (!el || typeof IntersectionObserver === "undefined") return;
915
- const io = new IntersectionObserver(([entry]) => setVisible(!!entry?.isIntersecting), { threshold: 0.25 });
921
+ const io = new IntersectionObserver(([entry]) => setSeen(!!entry?.isIntersecting), { threshold: 0.25 });
916
922
  io.observe(el);
917
923
  return () => io.disconnect();
918
924
  }, [m]);
@@ -923,13 +929,13 @@ function Route({ path, label, draw = true, duration = 1400, courier, tripDuratio
923
929
  const began = performance.now();
924
930
  const step = (now) => {
925
931
  const t = Math.min(1, (now - began) / Math.max(1, duration));
926
- source?.setData?.(sliceLine(path, 1 - (1 - t) ** 3));
932
+ source?.setData?.(sliceLine(path, ROUTE_CURVES[easing ?? "ease-out"](t)));
927
933
  if (t < 1) frame = requestAnimationFrame(step);
928
934
  else setDoneFor(token);
929
935
  };
930
936
  frame = requestAnimationFrame(step);
931
937
  return () => cancelAnimationFrame(frame);
932
- }, [m, ready, animated, drawn, visible, id, path, duration, token]);
938
+ }, [m, ready, animated, drawn, visible, id, path, duration, token, easing]);
933
939
  const [trip, setTrip] = React2.useState(0);
934
940
  React2.useEffect(() => {
935
941
  if (!courier || !m || !lib || !ready || !drawn) return;
@@ -943,7 +949,7 @@ function Route({ path, label, draw = true, duration = 1400, courier, tripDuratio
943
949
  const began = performance.now();
944
950
  const step = (now) => {
945
951
  const t = Math.min(1, (now - began) / Math.max(1, tripDuration));
946
- const eased = t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2;
952
+ const eased = ROUTE_CURVES[easing ?? "ease-in-out"](t);
947
953
  marker.setLngLat([...pointAlong(path, eased).position]);
948
954
  if (t < 1) frame = requestAnimationFrame(step);
949
955
  else if (repeatAfter !== void 0) timer = setTimeout(() => setTrip((n) => n + 1), repeatAfter);
@@ -955,7 +961,7 @@ function Route({ path, label, draw = true, duration = 1400, courier, tripDuratio
955
961
  clearTimeout(timer);
956
962
  marker.remove();
957
963
  };
958
- }, [courier, m, lib, ready, drawn, visible, reduce, path, tripDuration, repeatAfter, trip, token]);
964
+ }, [courier, m, lib, ready, drawn, visible, reduce, path, tripDuration, repeatAfter, trip, token, easing]);
959
965
  return null;
960
966
  }
961
967
  function useGeoLayer(id, data, layers2, source = {}) {