@x-plat/design-system 0.16.0 → 0.16.2

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.
@@ -85,8 +85,7 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
85
85
  if (left + popW > clip.right - 8) {
86
86
  left = triggerRect.right - popW;
87
87
  }
88
- left = Math.min(left, clip.right - 8 - popW);
89
- left = Math.max(left, clip.left + 8);
88
+ if (left < clip.left + 8) left = clip.left + 8;
90
89
  return {
91
90
  direction,
92
91
  top,
@@ -49,8 +49,7 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
49
49
  if (left + popW > clip.right - 8) {
50
50
  left = triggerRect.right - popW;
51
51
  }
52
- left = Math.min(left, clip.right - 8 - popW);
53
- left = Math.max(left, clip.left + 8);
52
+ if (left < clip.left + 8) left = clip.left + 8;
54
53
  return {
55
54
  direction,
56
55
  top,
@@ -85,8 +85,7 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
85
85
  if (left + popW > clip.right - 8) {
86
86
  left = triggerRect.right - popW;
87
87
  }
88
- left = Math.min(left, clip.right - 8 - popW);
89
- left = Math.max(left, clip.left + 8);
88
+ if (left < clip.left + 8) left = clip.left + 8;
90
89
  return {
91
90
  direction,
92
91
  top,
@@ -49,8 +49,7 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
49
49
  if (left + popW > clip.right - 8) {
50
50
  left = triggerRect.right - popW;
51
51
  }
52
- left = Math.min(left, clip.right - 8 - popW);
53
- left = Math.max(left, clip.left + 8);
52
+ if (left < clip.left + 8) left = clip.left + 8;
54
53
  return {
55
54
  direction,
56
55
  top,
@@ -86,8 +86,7 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
86
86
  if (left + popW > clip.right - 8) {
87
87
  left = triggerRect.right - popW;
88
88
  }
89
- left = Math.min(left, clip.right - 8 - popW);
90
- left = Math.max(left, clip.left + 8);
89
+ if (left < clip.left + 8) left = clip.left + 8;
91
90
  return {
92
91
  direction,
93
92
  top,
@@ -49,8 +49,7 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
49
49
  if (left + popW > clip.right - 8) {
50
50
  left = triggerRect.right - popW;
51
51
  }
52
- left = Math.min(left, clip.right - 8 - popW);
53
- left = Math.max(left, clip.left + 8);
52
+ if (left < clip.left + 8) left = clip.left + 8;
54
53
  return {
55
54
  direction,
56
55
  top,
@@ -85,8 +85,7 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
85
85
  if (left + popW > clip.right - 8) {
86
86
  left = triggerRect.right - popW;
87
87
  }
88
- left = Math.min(left, clip.right - 8 - popW);
89
- left = Math.max(left, clip.left + 8);
88
+ if (left < clip.left + 8) left = clip.left + 8;
90
89
  return {
91
90
  direction,
92
91
  top,
@@ -49,8 +49,7 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
49
49
  if (left + popW > clip.right - 8) {
50
50
  left = triggerRect.right - popW;
51
51
  }
52
- left = Math.min(left, clip.right - 8 - popW);
53
- left = Math.max(left, clip.left + 8);
52
+ if (left < clip.left + 8) left = clip.left + 8;
54
53
  return {
55
54
  direction,
56
55
  top,
@@ -76,8 +76,7 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
76
76
  if (left + popW > clip.right - 8) {
77
77
  left = triggerRect.right - popW;
78
78
  }
79
- left = Math.min(left, clip.right - 8 - popW);
80
- left = Math.max(left, clip.left + 8);
79
+ if (left < clip.left + 8) left = clip.left + 8;
81
80
  return {
82
81
  direction,
83
82
  top,
@@ -181,6 +180,7 @@ var clsx_default = clsx;
181
180
  var import_jsx_runtime = require("react/jsx-runtime");
182
181
  var VIEWPORT_MARGIN = 16;
183
182
  var DEFAULT_PADDING = 8;
183
+ var clamp = (v, min, max) => Math.max(min, Math.min(v, max));
184
184
  var resolve = (target) => {
185
185
  if (typeof target === "string") return document.querySelector(target);
186
186
  return target.current;
@@ -213,12 +213,33 @@ var Tour = (props) => {
213
213
  );
214
214
  useEscapeKey(open, () => onClose("skip"));
215
215
  useFocusTrap(cardRef, open, { trap: true });
216
+ const stepsRef = import_react3.default.useRef(steps);
217
+ stepsRef.current = steps;
216
218
  import_react3.default.useEffect(() => {
217
- if (!open || !step) return;
218
- const el = resolve(step.target);
219
- setTargetFound(!!el);
220
- el?.scrollIntoView({ block: "center", inline: "nearest", behavior: "smooth" });
221
- }, [open, step]);
219
+ if (!open) return;
220
+ const target = stepsRef.current[index]?.target;
221
+ if (!target) return;
222
+ let stop = false;
223
+ let tries = 0;
224
+ const look = () => {
225
+ if (stop) return;
226
+ const el = resolve(target);
227
+ if (el) {
228
+ setTargetFound(true);
229
+ el.scrollIntoView({ block: "center", inline: "nearest", behavior: "smooth" });
230
+ return;
231
+ }
232
+ setTargetFound(false);
233
+ if (tries < 60) {
234
+ tries += 1;
235
+ requestAnimationFrame(look);
236
+ }
237
+ };
238
+ look();
239
+ return () => {
240
+ stop = true;
241
+ };
242
+ }, [open, index]);
222
243
  const place = import_react3.default.useCallback(() => {
223
244
  const spot = spotRef.current;
224
245
  const card = cardRef.current;
@@ -259,16 +280,30 @@ var Tour = (props) => {
259
280
  right: window.innerWidth - VIEWPORT_MARGIN
260
281
  }
261
282
  );
262
- card.style.top = `${placed.top}px`;
263
- card.style.left = `${placed.left}px`;
264
- card.style.maxHeight = placed.maxHeight === null ? "" : `${placed.maxHeight}px`;
283
+ const limit = window.innerHeight - VIEWPORT_MARGIN * 2;
284
+ const cardH = Math.min(placed.maxHeight ?? card.offsetHeight, limit);
285
+ const cardW = card.offsetWidth;
286
+ card.style.maxHeight = `${cardH}px`;
287
+ card.style.top = `${clamp(placed.top, VIEWPORT_MARGIN, window.innerHeight - VIEWPORT_MARGIN - cardH)}px`;
288
+ card.style.left = `${clamp(placed.left, VIEWPORT_MARGIN, window.innerWidth - VIEWPORT_MARGIN - cardW)}px`;
265
289
  }, [step]);
266
290
  import_react3.default.useLayoutEffect(() => {
267
291
  if (!open) return;
268
292
  place();
269
- const t = setTimeout(place, 400);
270
- return () => clearTimeout(t);
271
- }, [open, place]);
293
+ let raf = 0;
294
+ let settled = 0;
295
+ let last = "";
296
+ const follow = () => {
297
+ const el = resolve(stepsRef.current[index]?.target ?? "");
298
+ const now = el ? JSON.stringify(el.getBoundingClientRect()) : "";
299
+ settled = now === last ? settled + 1 : 0;
300
+ last = now;
301
+ place();
302
+ if (settled < 3) raf = requestAnimationFrame(follow);
303
+ };
304
+ raf = requestAnimationFrame(follow);
305
+ return () => cancelAnimationFrame(raf);
306
+ }, [open, index, place]);
272
307
  import_react3.default.useEffect(() => {
273
308
  if (!open) return;
274
309
  const onMove = () => place();
@@ -40,8 +40,7 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
40
40
  if (left + popW > clip.right - 8) {
41
41
  left = triggerRect.right - popW;
42
42
  }
43
- left = Math.min(left, clip.right - 8 - popW);
44
- left = Math.max(left, clip.left + 8);
43
+ if (left < clip.left + 8) left = clip.left + 8;
45
44
  return {
46
45
  direction,
47
46
  top,
@@ -145,6 +144,7 @@ var clsx_default = clsx;
145
144
  import { jsx, jsxs } from "react/jsx-runtime";
146
145
  var VIEWPORT_MARGIN = 16;
147
146
  var DEFAULT_PADDING = 8;
147
+ var clamp = (v, min, max) => Math.max(min, Math.min(v, max));
148
148
  var resolve = (target) => {
149
149
  if (typeof target === "string") return document.querySelector(target);
150
150
  return target.current;
@@ -177,12 +177,33 @@ var Tour = (props) => {
177
177
  );
178
178
  useEscapeKey(open, () => onClose("skip"));
179
179
  useFocusTrap(cardRef, open, { trap: true });
180
+ const stepsRef = React3.useRef(steps);
181
+ stepsRef.current = steps;
180
182
  React3.useEffect(() => {
181
- if (!open || !step) return;
182
- const el = resolve(step.target);
183
- setTargetFound(!!el);
184
- el?.scrollIntoView({ block: "center", inline: "nearest", behavior: "smooth" });
185
- }, [open, step]);
183
+ if (!open) return;
184
+ const target = stepsRef.current[index]?.target;
185
+ if (!target) return;
186
+ let stop = false;
187
+ let tries = 0;
188
+ const look = () => {
189
+ if (stop) return;
190
+ const el = resolve(target);
191
+ if (el) {
192
+ setTargetFound(true);
193
+ el.scrollIntoView({ block: "center", inline: "nearest", behavior: "smooth" });
194
+ return;
195
+ }
196
+ setTargetFound(false);
197
+ if (tries < 60) {
198
+ tries += 1;
199
+ requestAnimationFrame(look);
200
+ }
201
+ };
202
+ look();
203
+ return () => {
204
+ stop = true;
205
+ };
206
+ }, [open, index]);
186
207
  const place = React3.useCallback(() => {
187
208
  const spot = spotRef.current;
188
209
  const card = cardRef.current;
@@ -223,16 +244,30 @@ var Tour = (props) => {
223
244
  right: window.innerWidth - VIEWPORT_MARGIN
224
245
  }
225
246
  );
226
- card.style.top = `${placed.top}px`;
227
- card.style.left = `${placed.left}px`;
228
- card.style.maxHeight = placed.maxHeight === null ? "" : `${placed.maxHeight}px`;
247
+ const limit = window.innerHeight - VIEWPORT_MARGIN * 2;
248
+ const cardH = Math.min(placed.maxHeight ?? card.offsetHeight, limit);
249
+ const cardW = card.offsetWidth;
250
+ card.style.maxHeight = `${cardH}px`;
251
+ card.style.top = `${clamp(placed.top, VIEWPORT_MARGIN, window.innerHeight - VIEWPORT_MARGIN - cardH)}px`;
252
+ card.style.left = `${clamp(placed.left, VIEWPORT_MARGIN, window.innerWidth - VIEWPORT_MARGIN - cardW)}px`;
229
253
  }, [step]);
230
254
  React3.useLayoutEffect(() => {
231
255
  if (!open) return;
232
256
  place();
233
- const t = setTimeout(place, 400);
234
- return () => clearTimeout(t);
235
- }, [open, place]);
257
+ let raf = 0;
258
+ let settled = 0;
259
+ let last = "";
260
+ const follow = () => {
261
+ const el = resolve(stepsRef.current[index]?.target ?? "");
262
+ const now = el ? JSON.stringify(el.getBoundingClientRect()) : "";
263
+ settled = now === last ? settled + 1 : 0;
264
+ last = now;
265
+ place();
266
+ if (settled < 3) raf = requestAnimationFrame(follow);
267
+ };
268
+ raf = requestAnimationFrame(follow);
269
+ return () => cancelAnimationFrame(raf);
270
+ }, [open, index, place]);
236
271
  React3.useEffect(() => {
237
272
  if (!open) return;
238
273
  const onMove = () => place();
@@ -3272,8 +3272,7 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
3272
3272
  if (left + popW > clip.right - 8) {
3273
3273
  left = triggerRect.right - popW;
3274
3274
  }
3275
- left = Math.min(left, clip.right - 8 - popW);
3276
- left = Math.max(left, clip.left + 8);
3275
+ if (left < clip.left + 8) left = clip.left + 8;
3277
3276
  return {
3278
3277
  direction,
3279
3278
  top,
@@ -7590,7 +7589,7 @@ var Tooltip = (props) => {
7590
7589
  const delayTimer = import_react43.default.useRef(0);
7591
7590
  const rafRef = import_react43.default.useRef(0);
7592
7591
  const cursor = import_react43.default.useRef(null);
7593
- const clamp = import_react43.default.useCallback((left, top, w, h) => {
7592
+ const clamp2 = import_react43.default.useCallback((left, top, w, h) => {
7594
7593
  const vw = window.innerWidth;
7595
7594
  const vh = window.innerHeight;
7596
7595
  return {
@@ -7607,8 +7606,8 @@ var Tooltip = (props) => {
7607
7606
  let top = y - h - OFFSET;
7608
7607
  if (left + w > window.innerWidth - GAP) left = x - w - OFFSET;
7609
7608
  if (top < GAP) top = y + OFFSET;
7610
- setPos(clamp(left, top, w, h));
7611
- }, [clamp]);
7609
+ setPos(clamp2(left, top, w, h));
7610
+ }, [clamp2]);
7612
7611
  const placeAtTrigger = import_react43.default.useCallback(() => {
7613
7612
  const el = tooltipRef.current;
7614
7613
  const trigger = triggerRef.current;
@@ -7619,8 +7618,8 @@ var Tooltip = (props) => {
7619
7618
  let top = rect.top - h - GAP;
7620
7619
  if (top < GAP) top = rect.bottom + GAP;
7621
7620
  const left = rect.left + rect.width / 2 - w / 2;
7622
- setPos(clamp(left, top, w, h));
7623
- }, [clamp]);
7621
+ setPos(clamp2(left, top, w, h));
7622
+ }, [clamp2]);
7624
7623
  const reposition = import_react43.default.useCallback(() => {
7625
7624
  if (follow && cursor.current) {
7626
7625
  placeAtCursor(cursor.current.x, cursor.current.y);
@@ -7712,6 +7711,7 @@ var import_react44 = __toESM(require("react"), 1);
7712
7711
  var import_jsx_runtime355 = require("react/jsx-runtime");
7713
7712
  var VIEWPORT_MARGIN = 16;
7714
7713
  var DEFAULT_PADDING = 8;
7714
+ var clamp = (v, min, max) => Math.max(min, Math.min(v, max));
7715
7715
  var resolve = (target) => {
7716
7716
  if (typeof target === "string") return document.querySelector(target);
7717
7717
  return target.current;
@@ -7744,12 +7744,33 @@ var Tour = (props) => {
7744
7744
  );
7745
7745
  useEscapeKey(open, () => onClose("skip"));
7746
7746
  useFocusTrap(cardRef, open, { trap: true });
7747
+ const stepsRef = import_react44.default.useRef(steps);
7748
+ stepsRef.current = steps;
7747
7749
  import_react44.default.useEffect(() => {
7748
- if (!open || !step) return;
7749
- const el = resolve(step.target);
7750
- setTargetFound(!!el);
7751
- el?.scrollIntoView({ block: "center", inline: "nearest", behavior: "smooth" });
7752
- }, [open, step]);
7750
+ if (!open) return;
7751
+ const target = stepsRef.current[index]?.target;
7752
+ if (!target) return;
7753
+ let stop = false;
7754
+ let tries = 0;
7755
+ const look = () => {
7756
+ if (stop) return;
7757
+ const el = resolve(target);
7758
+ if (el) {
7759
+ setTargetFound(true);
7760
+ el.scrollIntoView({ block: "center", inline: "nearest", behavior: "smooth" });
7761
+ return;
7762
+ }
7763
+ setTargetFound(false);
7764
+ if (tries < 60) {
7765
+ tries += 1;
7766
+ requestAnimationFrame(look);
7767
+ }
7768
+ };
7769
+ look();
7770
+ return () => {
7771
+ stop = true;
7772
+ };
7773
+ }, [open, index]);
7753
7774
  const place = import_react44.default.useCallback(() => {
7754
7775
  const spot = spotRef.current;
7755
7776
  const card = cardRef.current;
@@ -7790,16 +7811,30 @@ var Tour = (props) => {
7790
7811
  right: window.innerWidth - VIEWPORT_MARGIN
7791
7812
  }
7792
7813
  );
7793
- card.style.top = `${placed.top}px`;
7794
- card.style.left = `${placed.left}px`;
7795
- card.style.maxHeight = placed.maxHeight === null ? "" : `${placed.maxHeight}px`;
7814
+ const limit = window.innerHeight - VIEWPORT_MARGIN * 2;
7815
+ const cardH = Math.min(placed.maxHeight ?? card.offsetHeight, limit);
7816
+ const cardW = card.offsetWidth;
7817
+ card.style.maxHeight = `${cardH}px`;
7818
+ card.style.top = `${clamp(placed.top, VIEWPORT_MARGIN, window.innerHeight - VIEWPORT_MARGIN - cardH)}px`;
7819
+ card.style.left = `${clamp(placed.left, VIEWPORT_MARGIN, window.innerWidth - VIEWPORT_MARGIN - cardW)}px`;
7796
7820
  }, [step]);
7797
7821
  import_react44.default.useLayoutEffect(() => {
7798
7822
  if (!open) return;
7799
7823
  place();
7800
- const t = setTimeout(place, 400);
7801
- return () => clearTimeout(t);
7802
- }, [open, place]);
7824
+ let raf = 0;
7825
+ let settled = 0;
7826
+ let last = "";
7827
+ const follow = () => {
7828
+ const el = resolve(stepsRef.current[index]?.target ?? "");
7829
+ const now = el ? JSON.stringify(el.getBoundingClientRect()) : "";
7830
+ settled = now === last ? settled + 1 : 0;
7831
+ last = now;
7832
+ place();
7833
+ if (settled < 3) raf = requestAnimationFrame(follow);
7834
+ };
7835
+ raf = requestAnimationFrame(follow);
7836
+ return () => cancelAnimationFrame(raf);
7837
+ }, [open, index, place]);
7803
7838
  import_react44.default.useEffect(() => {
7804
7839
  if (!open) return;
7805
7840
  const onMove = () => place();
@@ -3169,8 +3169,7 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
3169
3169
  if (left + popW > clip.right - 8) {
3170
3170
  left = triggerRect.right - popW;
3171
3171
  }
3172
- left = Math.min(left, clip.right - 8 - popW);
3173
- left = Math.max(left, clip.left + 8);
3172
+ if (left < clip.left + 8) left = clip.left + 8;
3174
3173
  return {
3175
3174
  direction,
3176
3175
  top,
@@ -7487,7 +7486,7 @@ var Tooltip = (props) => {
7487
7486
  const delayTimer = React43.useRef(0);
7488
7487
  const rafRef = React43.useRef(0);
7489
7488
  const cursor = React43.useRef(null);
7490
- const clamp = React43.useCallback((left, top, w, h) => {
7489
+ const clamp2 = React43.useCallback((left, top, w, h) => {
7491
7490
  const vw = window.innerWidth;
7492
7491
  const vh = window.innerHeight;
7493
7492
  return {
@@ -7504,8 +7503,8 @@ var Tooltip = (props) => {
7504
7503
  let top = y - h - OFFSET;
7505
7504
  if (left + w > window.innerWidth - GAP) left = x - w - OFFSET;
7506
7505
  if (top < GAP) top = y + OFFSET;
7507
- setPos(clamp(left, top, w, h));
7508
- }, [clamp]);
7506
+ setPos(clamp2(left, top, w, h));
7507
+ }, [clamp2]);
7509
7508
  const placeAtTrigger = React43.useCallback(() => {
7510
7509
  const el = tooltipRef.current;
7511
7510
  const trigger = triggerRef.current;
@@ -7516,8 +7515,8 @@ var Tooltip = (props) => {
7516
7515
  let top = rect.top - h - GAP;
7517
7516
  if (top < GAP) top = rect.bottom + GAP;
7518
7517
  const left = rect.left + rect.width / 2 - w / 2;
7519
- setPos(clamp(left, top, w, h));
7520
- }, [clamp]);
7518
+ setPos(clamp2(left, top, w, h));
7519
+ }, [clamp2]);
7521
7520
  const reposition = React43.useCallback(() => {
7522
7521
  if (follow && cursor.current) {
7523
7522
  placeAtCursor(cursor.current.x, cursor.current.y);
@@ -7609,6 +7608,7 @@ import React44 from "react";
7609
7608
  import { jsx as jsx355, jsxs as jsxs225 } from "react/jsx-runtime";
7610
7609
  var VIEWPORT_MARGIN = 16;
7611
7610
  var DEFAULT_PADDING = 8;
7611
+ var clamp = (v, min, max) => Math.max(min, Math.min(v, max));
7612
7612
  var resolve = (target) => {
7613
7613
  if (typeof target === "string") return document.querySelector(target);
7614
7614
  return target.current;
@@ -7641,12 +7641,33 @@ var Tour = (props) => {
7641
7641
  );
7642
7642
  useEscapeKey(open, () => onClose("skip"));
7643
7643
  useFocusTrap(cardRef, open, { trap: true });
7644
+ const stepsRef = React44.useRef(steps);
7645
+ stepsRef.current = steps;
7644
7646
  React44.useEffect(() => {
7645
- if (!open || !step) return;
7646
- const el = resolve(step.target);
7647
- setTargetFound(!!el);
7648
- el?.scrollIntoView({ block: "center", inline: "nearest", behavior: "smooth" });
7649
- }, [open, step]);
7647
+ if (!open) return;
7648
+ const target = stepsRef.current[index]?.target;
7649
+ if (!target) return;
7650
+ let stop = false;
7651
+ let tries = 0;
7652
+ const look = () => {
7653
+ if (stop) return;
7654
+ const el = resolve(target);
7655
+ if (el) {
7656
+ setTargetFound(true);
7657
+ el.scrollIntoView({ block: "center", inline: "nearest", behavior: "smooth" });
7658
+ return;
7659
+ }
7660
+ setTargetFound(false);
7661
+ if (tries < 60) {
7662
+ tries += 1;
7663
+ requestAnimationFrame(look);
7664
+ }
7665
+ };
7666
+ look();
7667
+ return () => {
7668
+ stop = true;
7669
+ };
7670
+ }, [open, index]);
7650
7671
  const place = React44.useCallback(() => {
7651
7672
  const spot = spotRef.current;
7652
7673
  const card = cardRef.current;
@@ -7687,16 +7708,30 @@ var Tour = (props) => {
7687
7708
  right: window.innerWidth - VIEWPORT_MARGIN
7688
7709
  }
7689
7710
  );
7690
- card.style.top = `${placed.top}px`;
7691
- card.style.left = `${placed.left}px`;
7692
- card.style.maxHeight = placed.maxHeight === null ? "" : `${placed.maxHeight}px`;
7711
+ const limit = window.innerHeight - VIEWPORT_MARGIN * 2;
7712
+ const cardH = Math.min(placed.maxHeight ?? card.offsetHeight, limit);
7713
+ const cardW = card.offsetWidth;
7714
+ card.style.maxHeight = `${cardH}px`;
7715
+ card.style.top = `${clamp(placed.top, VIEWPORT_MARGIN, window.innerHeight - VIEWPORT_MARGIN - cardH)}px`;
7716
+ card.style.left = `${clamp(placed.left, VIEWPORT_MARGIN, window.innerWidth - VIEWPORT_MARGIN - cardW)}px`;
7693
7717
  }, [step]);
7694
7718
  React44.useLayoutEffect(() => {
7695
7719
  if (!open) return;
7696
7720
  place();
7697
- const t = setTimeout(place, 400);
7698
- return () => clearTimeout(t);
7699
- }, [open, place]);
7721
+ let raf = 0;
7722
+ let settled = 0;
7723
+ let last = "";
7724
+ const follow = () => {
7725
+ const el = resolve(stepsRef.current[index]?.target ?? "");
7726
+ const now = el ? JSON.stringify(el.getBoundingClientRect()) : "";
7727
+ settled = now === last ? settled + 1 : 0;
7728
+ last = now;
7729
+ place();
7730
+ if (settled < 3) raf = requestAnimationFrame(follow);
7731
+ };
7732
+ raf = requestAnimationFrame(follow);
7733
+ return () => cancelAnimationFrame(raf);
7734
+ }, [open, index, place]);
7700
7735
  React44.useEffect(() => {
7701
7736
  if (!open) return;
7702
7737
  const onMove = () => place();
package/dist/index.cjs CHANGED
@@ -7684,8 +7684,7 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
7684
7684
  if (left + popW > clip.right - 8) {
7685
7685
  left = triggerRect.right - popW;
7686
7686
  }
7687
- left = Math.min(left, clip.right - 8 - popW);
7688
- left = Math.max(left, clip.left + 8);
7687
+ if (left < clip.left + 8) left = clip.left + 8;
7689
7688
  return {
7690
7689
  direction,
7691
7690
  top,
@@ -12002,7 +12001,7 @@ var Tooltip = (props) => {
12002
12001
  const delayTimer = import_react43.default.useRef(0);
12003
12002
  const rafRef = import_react43.default.useRef(0);
12004
12003
  const cursor = import_react43.default.useRef(null);
12005
- const clamp = import_react43.default.useCallback((left, top, w, h) => {
12004
+ const clamp2 = import_react43.default.useCallback((left, top, w, h) => {
12006
12005
  const vw = window.innerWidth;
12007
12006
  const vh = window.innerHeight;
12008
12007
  return {
@@ -12019,8 +12018,8 @@ var Tooltip = (props) => {
12019
12018
  let top = y - h - OFFSET;
12020
12019
  if (left + w > window.innerWidth - GAP) left = x - w - OFFSET;
12021
12020
  if (top < GAP) top = y + OFFSET;
12022
- setPos(clamp(left, top, w, h));
12023
- }, [clamp]);
12021
+ setPos(clamp2(left, top, w, h));
12022
+ }, [clamp2]);
12024
12023
  const placeAtTrigger = import_react43.default.useCallback(() => {
12025
12024
  const el = tooltipRef.current;
12026
12025
  const trigger = triggerRef.current;
@@ -12031,8 +12030,8 @@ var Tooltip = (props) => {
12031
12030
  let top = rect.top - h - GAP;
12032
12031
  if (top < GAP) top = rect.bottom + GAP;
12033
12032
  const left = rect.left + rect.width / 2 - w / 2;
12034
- setPos(clamp(left, top, w, h));
12035
- }, [clamp]);
12033
+ setPos(clamp2(left, top, w, h));
12034
+ }, [clamp2]);
12036
12035
  const reposition = import_react43.default.useCallback(() => {
12037
12036
  if (follow && cursor.current) {
12038
12037
  placeAtCursor(cursor.current.x, cursor.current.y);
@@ -12124,6 +12123,7 @@ var import_react44 = __toESM(require("react"), 1);
12124
12123
  var import_jsx_runtime355 = require("react/jsx-runtime");
12125
12124
  var VIEWPORT_MARGIN = 16;
12126
12125
  var DEFAULT_PADDING = 8;
12126
+ var clamp = (v, min, max) => Math.max(min, Math.min(v, max));
12127
12127
  var resolve = (target) => {
12128
12128
  if (typeof target === "string") return document.querySelector(target);
12129
12129
  return target.current;
@@ -12156,12 +12156,33 @@ var Tour = (props) => {
12156
12156
  );
12157
12157
  useEscapeKey(open, () => onClose("skip"));
12158
12158
  useFocusTrap(cardRef, open, { trap: true });
12159
+ const stepsRef = import_react44.default.useRef(steps);
12160
+ stepsRef.current = steps;
12159
12161
  import_react44.default.useEffect(() => {
12160
- if (!open || !step) return;
12161
- const el = resolve(step.target);
12162
- setTargetFound(!!el);
12163
- el?.scrollIntoView({ block: "center", inline: "nearest", behavior: "smooth" });
12164
- }, [open, step]);
12162
+ if (!open) return;
12163
+ const target = stepsRef.current[index]?.target;
12164
+ if (!target) return;
12165
+ let stop = false;
12166
+ let tries = 0;
12167
+ const look = () => {
12168
+ if (stop) return;
12169
+ const el = resolve(target);
12170
+ if (el) {
12171
+ setTargetFound(true);
12172
+ el.scrollIntoView({ block: "center", inline: "nearest", behavior: "smooth" });
12173
+ return;
12174
+ }
12175
+ setTargetFound(false);
12176
+ if (tries < 60) {
12177
+ tries += 1;
12178
+ requestAnimationFrame(look);
12179
+ }
12180
+ };
12181
+ look();
12182
+ return () => {
12183
+ stop = true;
12184
+ };
12185
+ }, [open, index]);
12165
12186
  const place = import_react44.default.useCallback(() => {
12166
12187
  const spot = spotRef.current;
12167
12188
  const card = cardRef.current;
@@ -12202,16 +12223,30 @@ var Tour = (props) => {
12202
12223
  right: window.innerWidth - VIEWPORT_MARGIN
12203
12224
  }
12204
12225
  );
12205
- card.style.top = `${placed.top}px`;
12206
- card.style.left = `${placed.left}px`;
12207
- card.style.maxHeight = placed.maxHeight === null ? "" : `${placed.maxHeight}px`;
12226
+ const limit = window.innerHeight - VIEWPORT_MARGIN * 2;
12227
+ const cardH = Math.min(placed.maxHeight ?? card.offsetHeight, limit);
12228
+ const cardW = card.offsetWidth;
12229
+ card.style.maxHeight = `${cardH}px`;
12230
+ card.style.top = `${clamp(placed.top, VIEWPORT_MARGIN, window.innerHeight - VIEWPORT_MARGIN - cardH)}px`;
12231
+ card.style.left = `${clamp(placed.left, VIEWPORT_MARGIN, window.innerWidth - VIEWPORT_MARGIN - cardW)}px`;
12208
12232
  }, [step]);
12209
12233
  import_react44.default.useLayoutEffect(() => {
12210
12234
  if (!open) return;
12211
12235
  place();
12212
- const t = setTimeout(place, 400);
12213
- return () => clearTimeout(t);
12214
- }, [open, place]);
12236
+ let raf = 0;
12237
+ let settled = 0;
12238
+ let last = "";
12239
+ const follow = () => {
12240
+ const el = resolve(stepsRef.current[index]?.target ?? "");
12241
+ const now = el ? JSON.stringify(el.getBoundingClientRect()) : "";
12242
+ settled = now === last ? settled + 1 : 0;
12243
+ last = now;
12244
+ place();
12245
+ if (settled < 3) raf = requestAnimationFrame(follow);
12246
+ };
12247
+ raf = requestAnimationFrame(follow);
12248
+ return () => cancelAnimationFrame(raf);
12249
+ }, [open, index, place]);
12215
12250
  import_react44.default.useEffect(() => {
12216
12251
  if (!open) return;
12217
12252
  const onMove = () => place();
package/dist/index.js CHANGED
@@ -7272,8 +7272,7 @@ var computePlacement = (triggerRect, popW, popH, clip) => {
7272
7272
  if (left + popW > clip.right - 8) {
7273
7273
  left = triggerRect.right - popW;
7274
7274
  }
7275
- left = Math.min(left, clip.right - 8 - popW);
7276
- left = Math.max(left, clip.left + 8);
7275
+ if (left < clip.left + 8) left = clip.left + 8;
7277
7276
  return {
7278
7277
  direction,
7279
7278
  top,
@@ -11590,7 +11589,7 @@ var Tooltip = (props) => {
11590
11589
  const delayTimer = React43.useRef(0);
11591
11590
  const rafRef = React43.useRef(0);
11592
11591
  const cursor = React43.useRef(null);
11593
- const clamp = React43.useCallback((left, top, w, h) => {
11592
+ const clamp2 = React43.useCallback((left, top, w, h) => {
11594
11593
  const vw = window.innerWidth;
11595
11594
  const vh = window.innerHeight;
11596
11595
  return {
@@ -11607,8 +11606,8 @@ var Tooltip = (props) => {
11607
11606
  let top = y - h - OFFSET;
11608
11607
  if (left + w > window.innerWidth - GAP) left = x - w - OFFSET;
11609
11608
  if (top < GAP) top = y + OFFSET;
11610
- setPos(clamp(left, top, w, h));
11611
- }, [clamp]);
11609
+ setPos(clamp2(left, top, w, h));
11610
+ }, [clamp2]);
11612
11611
  const placeAtTrigger = React43.useCallback(() => {
11613
11612
  const el = tooltipRef.current;
11614
11613
  const trigger = triggerRef.current;
@@ -11619,8 +11618,8 @@ var Tooltip = (props) => {
11619
11618
  let top = rect.top - h - GAP;
11620
11619
  if (top < GAP) top = rect.bottom + GAP;
11621
11620
  const left = rect.left + rect.width / 2 - w / 2;
11622
- setPos(clamp(left, top, w, h));
11623
- }, [clamp]);
11621
+ setPos(clamp2(left, top, w, h));
11622
+ }, [clamp2]);
11624
11623
  const reposition = React43.useCallback(() => {
11625
11624
  if (follow && cursor.current) {
11626
11625
  placeAtCursor(cursor.current.x, cursor.current.y);
@@ -11712,6 +11711,7 @@ import React44 from "react";
11712
11711
  import { jsx as jsx355, jsxs as jsxs225 } from "react/jsx-runtime";
11713
11712
  var VIEWPORT_MARGIN = 16;
11714
11713
  var DEFAULT_PADDING = 8;
11714
+ var clamp = (v, min, max) => Math.max(min, Math.min(v, max));
11715
11715
  var resolve = (target) => {
11716
11716
  if (typeof target === "string") return document.querySelector(target);
11717
11717
  return target.current;
@@ -11744,12 +11744,33 @@ var Tour = (props) => {
11744
11744
  );
11745
11745
  useEscapeKey(open, () => onClose("skip"));
11746
11746
  useFocusTrap(cardRef, open, { trap: true });
11747
+ const stepsRef = React44.useRef(steps);
11748
+ stepsRef.current = steps;
11747
11749
  React44.useEffect(() => {
11748
- if (!open || !step) return;
11749
- const el = resolve(step.target);
11750
- setTargetFound(!!el);
11751
- el?.scrollIntoView({ block: "center", inline: "nearest", behavior: "smooth" });
11752
- }, [open, step]);
11750
+ if (!open) return;
11751
+ const target = stepsRef.current[index]?.target;
11752
+ if (!target) return;
11753
+ let stop = false;
11754
+ let tries = 0;
11755
+ const look = () => {
11756
+ if (stop) return;
11757
+ const el = resolve(target);
11758
+ if (el) {
11759
+ setTargetFound(true);
11760
+ el.scrollIntoView({ block: "center", inline: "nearest", behavior: "smooth" });
11761
+ return;
11762
+ }
11763
+ setTargetFound(false);
11764
+ if (tries < 60) {
11765
+ tries += 1;
11766
+ requestAnimationFrame(look);
11767
+ }
11768
+ };
11769
+ look();
11770
+ return () => {
11771
+ stop = true;
11772
+ };
11773
+ }, [open, index]);
11753
11774
  const place = React44.useCallback(() => {
11754
11775
  const spot = spotRef.current;
11755
11776
  const card = cardRef.current;
@@ -11790,16 +11811,30 @@ var Tour = (props) => {
11790
11811
  right: window.innerWidth - VIEWPORT_MARGIN
11791
11812
  }
11792
11813
  );
11793
- card.style.top = `${placed.top}px`;
11794
- card.style.left = `${placed.left}px`;
11795
- card.style.maxHeight = placed.maxHeight === null ? "" : `${placed.maxHeight}px`;
11814
+ const limit = window.innerHeight - VIEWPORT_MARGIN * 2;
11815
+ const cardH = Math.min(placed.maxHeight ?? card.offsetHeight, limit);
11816
+ const cardW = card.offsetWidth;
11817
+ card.style.maxHeight = `${cardH}px`;
11818
+ card.style.top = `${clamp(placed.top, VIEWPORT_MARGIN, window.innerHeight - VIEWPORT_MARGIN - cardH)}px`;
11819
+ card.style.left = `${clamp(placed.left, VIEWPORT_MARGIN, window.innerWidth - VIEWPORT_MARGIN - cardW)}px`;
11796
11820
  }, [step]);
11797
11821
  React44.useLayoutEffect(() => {
11798
11822
  if (!open) return;
11799
11823
  place();
11800
- const t = setTimeout(place, 400);
11801
- return () => clearTimeout(t);
11802
- }, [open, place]);
11824
+ let raf = 0;
11825
+ let settled = 0;
11826
+ let last = "";
11827
+ const follow = () => {
11828
+ const el = resolve(stepsRef.current[index]?.target ?? "");
11829
+ const now = el ? JSON.stringify(el.getBoundingClientRect()) : "";
11830
+ settled = now === last ? settled + 1 : 0;
11831
+ last = now;
11832
+ place();
11833
+ if (settled < 3) raf = requestAnimationFrame(follow);
11834
+ };
11835
+ raf = requestAnimationFrame(follow);
11836
+ return () => cancelAnimationFrame(raf);
11837
+ }, [open, index, place]);
11803
11838
  React44.useEffect(() => {
11804
11839
  if (!open) return;
11805
11840
  const onMove = () => place();
@@ -58,11 +58,18 @@ const [guide, setGuide] = useState(true);
58
58
 
59
59
  ## 스크롤
60
60
 
61
- 대상이 화면 밖이면 데려온다. **페이지가 스크롤하든 안쪽 상자가 스크롤하든**
62
- 브라우저가 알아서 한다.
61
+ **그 단계 차례가 되면 대상을 화면 안으로 데려온다.** 페이지가 스크롤하든 안쪽
62
+ 상자가 스크롤하든 브라우저가 알아서 한다(`scrollIntoView`). 부드럽게 움직이는
63
+ 동안 구멍과 말풍선이 **프레임마다 따라붙고**, 멎으면 따라붙기도 멈춘다.
63
64
 
64
- 그 뒤 사용자가 굴리면 구멍이 **한 프레임 늦게** 따라온다. 화면 전체가 어두운
65
- 상태라 눈에 잘 띄지 않지만, 알고는 있어야 한다.
65
+ 대상이 아직 안 그려졌으면 **1초까지 기다린다.** 앞 단계에서 눌러야 나타나는
66
+ 요소를 가리키는 경우가 있어서다. 그래도 없으면 구멍 없이 말풍선만 띄운다.
67
+
68
+ 안내 중에 사용자가 직접 굴리면 구멍이 **한 프레임 늦게** 따라온다. 화면 전체가
69
+ 어두운 상태라 눈에 잘 띄지 않지만, 알고는 있어야 한다.
70
+
71
+ > `steps` 를 인라인 배열로 넘겨도 된다. 단계 바뀜은 **차례(index)** 로만
72
+ > 판단하므로 배열이 매 렌더 새로 만들어져도 스크롤이 다시 시작되지 않는다.
66
73
 
67
74
  ## 다시 보지 않기
68
75
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-plat/design-system",
3
- "version": "0.16.0",
3
+ "version": "0.16.2",
4
4
  "description": "XPLAT UI Design System",
5
5
  "author": "XPLAT WOONG",
6
6
  "main": "dist/index.cjs",