@repere/react 0.0.3 → 0.1.1

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.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export type * from '@repere/core';
2
+ export { Animation, Position } from '@repere/core';
1
3
  export { Beacons, type BeaconsProps } from './components/Beacons';
2
4
  export { ReperePopover } from './components/Popover';
3
5
  export { RepereTrigger } from './components/RepereTrigger';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAElE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,YAAY,EACV,gBAAgB,EAChB,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,cAAc,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAElE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,YAAY,EACV,gBAAgB,EAChB,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,438 +1,772 @@
1
- import { jsx as u, jsxs as W } from "react/jsx-runtime";
2
- import { getAnimationConfig as x, mergeAnimationConfigs as D, PositionTracker as H, DEFAULT_POSITION as J, calculateDismissDuration as K, waitForAnimations as Q, MemoryStore as X, BeaconManager as Y, getPopoverAnimationStyles as Z, combineTranslateWithAnimation as oo } from "@repere/core";
3
- import { createContext as eo, useContext as to, useMemo as P, useState as w, useEffect as O, useCallback as y, isValidElement as j, cloneElement as no, useId as io, forwardRef as A } from "react";
4
- import { createPortal as ro } from "react-dom";
5
- import { motion as $ } from "motion/react";
6
- const S = eo(null);
7
- function I() {
8
- const o = to(S);
9
- if (!o)
1
+ import { jsx as g, jsxs as J } from "react/jsx-runtime";
2
+ import { createContext as K, useContext as Q, useMemo as y, useState as C, useEffect as $, useCallback as A, isValidElement as N, cloneElement as W, useId as Z, forwardRef as b } from "react";
3
+ import { createPortal as ee } from "react-dom";
4
+ import { motion as M } from "motion/react";
5
+ var m = /* @__PURE__ */ ((e) => (e.TopLeft = "top-left", e.TopCenter = "top-center", e.TopRight = "top-right", e.RightCenter = "right-center", e.BottomRight = "bottom-right", e.BottomCenter = "bottom-center", e.BottomLeft = "bottom-left", e.LeftCenter = "left-center", e))(m || {});
6
+ const te = m.TopRight;
7
+ class oe {
8
+ state = /* @__PURE__ */ new Map();
9
+ isDismissed(t) {
10
+ return this.state.get(t)?.isDismissed ?? !1;
11
+ }
12
+ dismiss(t) {
13
+ this.state.set(t, {
14
+ id: t,
15
+ isDismissed: !0
16
+ });
17
+ }
18
+ reset(t) {
19
+ this.state.delete(t);
20
+ }
21
+ resetAll() {
22
+ this.state.clear();
23
+ }
24
+ getAll() {
25
+ return Array.from(this.state.values());
26
+ }
27
+ }
28
+ var v = /* @__PURE__ */ ((e) => (e.Fade = "fade", e.Scale = "scale", e.Grow = "grow", e.Shrink = "shrink", e.SlideUp = "slide-up", e.SlideDown = "slide-down", e.SlideLeft = "slide-left", e.SlideRight = "slide-right", e.None = "none", e))(v || {});
29
+ const ne = {
30
+ [v.SlideDown]: {
31
+ initial: { y: -20, opacity: 0 },
32
+ animate: { y: 0, opacity: 1 },
33
+ exit: { y: -20, opacity: 0 }
34
+ },
35
+ [v.SlideUp]: {
36
+ initial: { y: 20, opacity: 0 },
37
+ animate: { y: 0, opacity: 1 },
38
+ exit: { y: 20, opacity: 0 }
39
+ },
40
+ [v.SlideLeft]: {
41
+ initial: { x: 20, opacity: 0 },
42
+ animate: { x: 0, opacity: 1 },
43
+ exit: { x: 20, opacity: 0 }
44
+ },
45
+ [v.SlideRight]: {
46
+ initial: { x: -20, opacity: 0 },
47
+ animate: { x: 0, opacity: 1 },
48
+ exit: { x: -20, opacity: 0 }
49
+ },
50
+ [v.Fade]: {
51
+ initial: { opacity: 0 },
52
+ animate: { opacity: 1 },
53
+ exit: { opacity: 0 }
54
+ },
55
+ [v.Shrink]: {
56
+ initial: { scale: 1.1, opacity: 0 },
57
+ animate: { scale: 1, opacity: 1 },
58
+ exit: { scale: 0.9, opacity: 0 }
59
+ },
60
+ [v.Grow]: {
61
+ initial: { scale: 0.9, opacity: 0 },
62
+ animate: { scale: 1, opacity: 1 },
63
+ exit: { scale: 1.1, opacity: 0 }
64
+ },
65
+ [v.Scale]: {
66
+ initial: { scale: 0, opacity: 0 },
67
+ animate: { scale: 1, opacity: 1 },
68
+ exit: { scale: 0, opacity: 0 }
69
+ },
70
+ [v.None]: {
71
+ initial: {},
72
+ animate: {},
73
+ exit: {}
74
+ }
75
+ };
76
+ function z(e) {
77
+ return e ? typeof e == "string" ? { variant: e } : e : null;
78
+ }
79
+ function L(e, t) {
80
+ const o = z(e), i = z(t);
81
+ return !o && !i ? null : o ? i ? {
82
+ variant: i.variant ?? o.variant,
83
+ duration: i.duration ?? o.duration,
84
+ delay: i.delay ?? o.delay,
85
+ ease: i.ease ?? o.ease
86
+ } : o : i;
87
+ }
88
+ function B(e) {
89
+ const t = z(e);
90
+ if (!t) return null;
91
+ const o = ne[t.variant];
92
+ return o ? {
93
+ variants: o,
94
+ transition: {
95
+ duration: (t.duration || 300) / 1e3,
96
+ // Convert ms to seconds
97
+ delay: (t.delay || 0) / 1e3,
98
+ ease: t.ease || [0.4, 0, 0.2, 1]
99
+ // cubic-bezier
100
+ }
101
+ } : (console.warn(`[Repere] Unknown animation variant: ${t.variant}`), null);
102
+ }
103
+ function ie(e, t) {
104
+ const o = (n) => {
105
+ const a = n.match(/(-?\d+)%/);
106
+ return a ? parseFloat(a[1]) : 0;
107
+ }, i = o(e.x), r = o(e.y), s = (n = 0) => r === 0 && n === 0 ? `translate(${i}%, 0)` : n === 0 ? `translate(${i}%, ${r}%)` : `translate(${i}%, calc(${r}% + ${n}px))`;
108
+ return {
109
+ initial: {
110
+ ...t.initial,
111
+ transform: s(t.initial.y || 0)
112
+ },
113
+ animate: {
114
+ ...t.animate,
115
+ transform: s(t.animate.y || 0)
116
+ },
117
+ exit: {
118
+ ...t.exit,
119
+ transform: s(t.exit.y || 0)
120
+ }
121
+ };
122
+ }
123
+ function se(e, t) {
124
+ if (!e && !t) return {};
125
+ const o = e?.variants, i = e?.transition, r = t?.variants, s = t?.transition, n = s?.ease ?? i?.ease ?? [0.4, 0, 0.2, 1], a = Array.isArray(n) ? `cubic-bezier(${n.join(", ")})` : n;
126
+ return {
127
+ // Initial state (when opening starts) - from onOpen animation
128
+ "--repere-initial-opacity": o?.initial.opacity ?? 0,
129
+ "--repere-initial-x": `${o?.initial.x ?? 0}px`,
130
+ "--repere-initial-y": `${o?.initial.y ?? 0}px`,
131
+ "--repere-initial-scale": o?.initial.scale ?? 1,
132
+ // Animate state (fully open) - from onOpen animation
133
+ "--repere-animate-opacity": o?.animate.opacity ?? 1,
134
+ "--repere-animate-x": `${o?.animate.x ?? 0}px`,
135
+ "--repere-animate-y": `${o?.animate.y ?? 0}px`,
136
+ "--repere-animate-scale": o?.animate.scale ?? 1,
137
+ // Exit state (when closing) - from onClose animation
138
+ "--repere-exit-opacity": r?.exit.opacity ?? 0,
139
+ "--repere-exit-x": `${r?.exit.x ?? 0}px`,
140
+ "--repere-exit-y": `${r?.exit.y ?? 0}px`,
141
+ "--repere-exit-scale": r?.exit.scale ?? 1,
142
+ // Transition timing
143
+ "--repere-transition-duration": `${s?.duration ?? i?.duration ?? 0.3}s`,
144
+ "--repere-transition-timing": a
145
+ };
146
+ }
147
+ function re(e, t) {
148
+ const o = e?.transition.duration ?? 0, i = t?.transition.duration ?? 0;
149
+ return Math.max(o, i) * 1e3;
150
+ }
151
+ function ae(e) {
152
+ return new Promise((t) => setTimeout(t, e));
153
+ }
154
+ function le(e, t) {
155
+ if (t instanceof RegExp)
156
+ return t.test(e);
157
+ if (t === e)
158
+ return !0;
159
+ if (t.includes("*")) {
160
+ const o = t.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
161
+ return new RegExp(`^${o}$`).test(e);
162
+ }
163
+ return !1;
164
+ }
165
+ class ce {
166
+ store;
167
+ debug;
168
+ constructor(t, o = {}) {
169
+ this.store = t, this.debug = o.debug ?? !1;
170
+ }
171
+ /**
172
+ * Find all pages that match the current path
173
+ * This supports wildcards - e.g., path="*" will match all pages
174
+ */
175
+ findMatchingPages(t, o) {
176
+ const i = t.filter((r) => typeof r.path == "function" ? r.path(o) : le(o, r.path));
177
+ return this.debug && console.log(
178
+ "[BeaconManager] Path:",
179
+ o,
180
+ "Matched pages:",
181
+ i.map((r) => r.id).join(", ") || "none"
182
+ ), i;
183
+ }
184
+ /**
185
+ * Get all active (non-dismissed) beacons for the current path
186
+ * Includes beacons from all matching pages (supports wildcards)
187
+ */
188
+ async getActiveBeacons(t, o) {
189
+ const i = this.findMatchingPages(t, o);
190
+ if (i.length === 0)
191
+ return this.debug && console.log("[BeaconManager] No matching pages found"), [];
192
+ this.debug && console.log(
193
+ "[BeaconManager] Found",
194
+ i.length,
195
+ "matching page(s):",
196
+ i.map((a) => a.id).join(", ")
197
+ );
198
+ const r = [], s = /* @__PURE__ */ new Set();
199
+ for (const a of i)
200
+ for (const l of a.beacons) {
201
+ if (s.has(l.id)) {
202
+ this.debug && console.warn(
203
+ `[BeaconManager] Duplicate beacon ID "${l.id}" in page "${a.id}", skipping`
204
+ );
205
+ continue;
206
+ }
207
+ s.add(l.id), r.push(l);
208
+ }
209
+ const n = [];
210
+ for (const a of r)
211
+ await Promise.resolve(
212
+ this.store.isDismissed(a.id)
213
+ ) ? this.debug && console.log("[BeaconManager] Beacon", a.id, "is dismissed") : n.push(a);
214
+ return this.debug && console.log("[BeaconManager] Active beacons:", n.length), n;
215
+ }
216
+ /**
217
+ * Get the store instance
218
+ */
219
+ getStore() {
220
+ return this.store;
221
+ }
222
+ }
223
+ function pe(e, t = m.TopRight, o = { x: 0, y: 0 }) {
224
+ const { x: i = 0, y: r = 0 } = o;
225
+ let s = 0, n = 0, a = "0", l = "0";
226
+ switch (t) {
227
+ // Top positions
228
+ case m.TopLeft:
229
+ s = e.top + window.scrollY, n = e.left + window.scrollX, a = "-50%", l = "-100%";
230
+ break;
231
+ case m.TopCenter:
232
+ s = e.top + window.scrollY, n = e.left + window.scrollX + e.width / 2, a = "-50%", l = "-100%";
233
+ break;
234
+ case m.TopRight:
235
+ s = e.top + window.scrollY, n = e.right + window.scrollX, a = "-50%", l = "-100%";
236
+ break;
237
+ // Right positions
238
+ case m.RightCenter:
239
+ s = e.top + window.scrollY + e.height / 2, n = e.right + window.scrollX, a = "0", l = "-50%";
240
+ break;
241
+ // Bottom positions
242
+ case m.BottomLeft:
243
+ s = e.bottom + window.scrollY, n = e.left + window.scrollX, a = "-50%", l = "0";
244
+ break;
245
+ case m.BottomCenter:
246
+ s = e.bottom + window.scrollY, n = e.left + window.scrollX + e.width / 2, a = "-50%", l = "0";
247
+ break;
248
+ case m.BottomRight:
249
+ s = e.bottom + window.scrollY, n = e.right + window.scrollX, a = "-50%", l = "0";
250
+ break;
251
+ // Left positions
252
+ case m.LeftCenter:
253
+ s = e.top + window.scrollY + e.height / 2, n = e.left + window.scrollX, a = "-100%", l = "-50%";
254
+ break;
255
+ }
256
+ return s += r, n += i, {
257
+ top: s,
258
+ left: n,
259
+ translate: { x: a, y: l }
260
+ };
261
+ }
262
+ class de {
263
+ tracked = /* @__PURE__ */ new Map();
264
+ scrollListener = null;
265
+ resizeListener = null;
266
+ resizeObserver = null;
267
+ mutationObserver = null;
268
+ debug = !1;
269
+ constructor(t = !1) {
270
+ this.debug = t;
271
+ }
272
+ /**
273
+ * Subscribe to position updates for an element
274
+ */
275
+ subscribe(t, o, i, r = {}) {
276
+ const s = t;
277
+ return this.tracked.has(s) || this.tracked.set(s, {
278
+ selector: t,
279
+ position: o,
280
+ offset: r.offset,
281
+ zIndex: r.zIndex ?? 9999,
282
+ callbacks: /* @__PURE__ */ new Set(),
283
+ element: null
284
+ }), this.tracked.get(s)?.callbacks.add(i), this.tracked.size === 1 && this.startListening(), this.updatePosition(s), () => {
285
+ const n = this.tracked.get(s);
286
+ n && (n.callbacks.delete(i), n.callbacks.size === 0 && (this.tracked.delete(s), this.tracked.size === 0 && this.stopListening()));
287
+ };
288
+ }
289
+ updatePosition(t) {
290
+ const o = this.tracked.get(t);
291
+ if (!o) return;
292
+ const i = document.querySelector(o.selector);
293
+ if (!i) {
294
+ this.debug && console.log(`[PositionTracker] Element not found: ${o.selector}`), o.element = null;
295
+ for (const n of o.callbacks)
296
+ n(null);
297
+ return;
298
+ }
299
+ o.element = i;
300
+ const r = i.getBoundingClientRect(), s = {
301
+ ...pe(
302
+ r,
303
+ o.position,
304
+ o.offset
305
+ ),
306
+ position: "fixed",
307
+ zIndex: o.zIndex
308
+ };
309
+ this.debug && console.log(
310
+ `[PositionTracker] Updated position for ${o.selector}:`,
311
+ s
312
+ );
313
+ for (const n of o.callbacks)
314
+ n(s);
315
+ }
316
+ updateAllPositions = () => {
317
+ for (const [t] of this.tracked)
318
+ this.updatePosition(t);
319
+ };
320
+ startListening() {
321
+ this.scrollListener = this.updateAllPositions, window.addEventListener("scroll", this.scrollListener, !0), this.resizeListener = this.updateAllPositions, window.addEventListener("resize", this.resizeListener), "ResizeObserver" in window && (this.resizeObserver = new ResizeObserver(this.updateAllPositions)), this.mutationObserver = new MutationObserver(() => {
322
+ this.updateAllPositions();
323
+ }), this.mutationObserver.observe(document.body, {
324
+ childList: !0,
325
+ subtree: !0
326
+ });
327
+ }
328
+ stopListening() {
329
+ this.scrollListener && (window.removeEventListener("scroll", this.scrollListener, !0), this.scrollListener = null), this.resizeListener && (window.removeEventListener("resize", this.resizeListener), this.resizeListener = null), this.resizeObserver?.disconnect(), this.resizeObserver = null, this.mutationObserver?.disconnect(), this.mutationObserver = null;
330
+ }
331
+ /**
332
+ * Clean up all listeners and subscriptions
333
+ */
334
+ destroy() {
335
+ this.stopListening(), this.tracked.clear();
336
+ }
337
+ }
338
+ const j = K(null);
339
+ function k() {
340
+ const e = Q(j);
341
+ if (!e)
10
342
  throw new Error("useRepereContext must be used within a Repere provider.");
11
- return o;
343
+ return e;
12
344
  }
13
- function so(o, e) {
14
- const t = P(() => {
15
- const n = e.trigger?.animations?.onRender, s = o.trigger?.animations?.onRender;
16
- return x(D(n, s));
17
- }, [e.trigger?.animations, o.trigger?.animations]), r = P(() => {
18
- const n = e.trigger?.animations?.onDismiss, s = o.trigger?.animations?.onDismiss;
19
- return x(D(n, s));
345
+ function ue(e, t) {
346
+ const o = y(() => {
347
+ const n = t.trigger?.animations?.onRender, a = e.trigger?.animations?.onRender;
348
+ return B(L(n, a));
349
+ }, [t.trigger?.animations, e.trigger?.animations]), i = y(() => {
350
+ const n = t.trigger?.animations?.onDismiss, a = e.trigger?.animations?.onDismiss;
351
+ return B(L(n, a));
20
352
  }, [
21
- e.trigger?.animations?.onDismiss,
22
- o.trigger?.animations?.onDismiss
23
- ]), i = P(() => {
24
- const n = e.popover?.animations?.onOpen, s = o.popover?.animations?.onOpen;
25
- return x(D(n, s));
26
- }, [e.popover?.animations?.onOpen, o.popover?.animations?.onOpen]), p = P(() => {
27
- const n = e.popover?.animations?.onClose, s = o.popover?.animations?.onClose;
28
- return x(D(n, s));
353
+ t.trigger?.animations?.onDismiss,
354
+ e.trigger?.animations?.onDismiss
355
+ ]), r = y(() => {
356
+ const n = t.popover?.animations?.onOpen, a = e.popover?.animations?.onOpen;
357
+ return B(L(n, a));
358
+ }, [t.popover?.animations?.onOpen, e.popover?.animations?.onOpen]), s = y(() => {
359
+ const n = t.popover?.animations?.onClose, a = e.popover?.animations?.onClose;
360
+ return B(L(n, a));
29
361
  }, [
30
- e.popover?.animations?.onClose,
31
- o.popover?.animations?.onClose
362
+ t.popover?.animations?.onClose,
363
+ e.popover?.animations?.onClose
32
364
  ]);
33
365
  return {
34
- triggerAnimation: t,
35
- triggerDismissAnimation: r,
36
- popoverOpenAnimation: i,
37
- popoverCloseAnimation: p
366
+ triggerAnimation: o,
367
+ triggerDismissAnimation: i,
368
+ popoverOpenAnimation: r,
369
+ popoverCloseAnimation: s
38
370
  };
39
371
  }
40
- function po({
41
- targetSelector: o,
42
- position: e,
43
- offset: t,
44
- zIndex: r = 9999,
45
- enabled: i = !0,
46
- debug: p = !1
372
+ function me({
373
+ targetSelector: e,
374
+ position: t,
375
+ offset: o,
376
+ zIndex: i = 9999,
377
+ enabled: r = !0,
378
+ debug: s = !1
47
379
  }) {
48
- const [n, s] = w(null), a = P(() => new H(p), [p]);
49
- return O(() => {
50
- if (!i) {
51
- s(null);
380
+ const [n, a] = C(null), l = y(() => new de(s), [s]);
381
+ return $(() => {
382
+ if (!r) {
383
+ a(null);
52
384
  return;
53
385
  }
54
- return a.subscribe(
55
- o,
386
+ return l.subscribe(
56
387
  e,
57
- s,
58
- { offset: t, zIndex: r }
388
+ t,
389
+ a,
390
+ { offset: o, zIndex: i }
59
391
  );
60
- }, [a, o, e, t, r, i]), O(() => () => a.destroy(), [a]), {
392
+ }, [l, e, t, o, i, r]), $(() => () => l.destroy(), [l]), {
61
393
  calculatedPosition: n,
62
- targetElement: n ? document.querySelector(o) : null
394
+ targetElement: n ? document.querySelector(e) : null
63
395
  };
64
396
  }
65
- function ao() {
66
- const [o, e] = w(!1), [t, r] = w(
397
+ function ge() {
398
+ const [e, t] = C(!1), [o, i] = C(
67
399
  null
68
- ), i = y((a) => {
69
- r(a);
70
- }, []), p = y(
71
- () => t?.togglePopover(),
72
- [t]
73
- ), n = y(
74
- () => t?.showPopover(),
75
- [t]
76
- ), s = y(
77
- () => t?.hidePopover(),
78
- [t]
400
+ ), r = A((l) => {
401
+ i(l);
402
+ }, []), s = A(
403
+ () => o?.togglePopover(),
404
+ [o]
405
+ ), n = A(
406
+ () => o?.showPopover(),
407
+ [o]
408
+ ), a = A(
409
+ () => o?.hidePopover(),
410
+ [o]
79
411
  );
80
- return O(() => {
81
- if (!t) return;
82
- const a = (c) => {
83
- e(c.newState === "open");
412
+ return $(() => {
413
+ if (!o) return;
414
+ const l = (c) => {
415
+ t(c.newState === "open");
84
416
  };
85
- return t.addEventListener("toggle", a), () => t.removeEventListener("toggle", a);
86
- }, [t]), {
87
- isOpen: o,
88
- popoverElement: t,
89
- handlePopoverRef: i,
90
- togglePopover: p,
417
+ return o.addEventListener("toggle", l), () => o.removeEventListener("toggle", l);
418
+ }, [o]), {
419
+ isOpen: e,
420
+ popoverElement: o,
421
+ handlePopoverRef: r,
422
+ togglePopover: s,
91
423
  showPopover: n,
92
- hidePopover: s
424
+ hidePopover: a
93
425
  };
94
426
  }
95
- function co(o, e) {
96
- return o ? j(o) ? o : /* @__PURE__ */ u(
97
- o,
427
+ function ve(e, t) {
428
+ return e ? N(e) ? e : /* @__PURE__ */ g(
429
+ e,
98
430
  {
99
- beacon: e.beacon,
100
- style: e.calculatedPosition,
101
- position: e.position,
102
- isOpen: e.isOpen,
103
- onClick: e.togglePopover
431
+ beacon: t.beacon,
432
+ style: t.calculatedPosition,
433
+ position: t.position,
434
+ isOpen: t.isOpen,
435
+ onClick: t.togglePopover
104
436
  }
105
437
  ) : null;
106
438
  }
107
- function lo(o, e) {
108
- let t;
109
- return j(o) ? t = o : t = /* @__PURE__ */ u(
110
- o,
439
+ function he(e, t) {
440
+ let o;
441
+ return N(e) ? o = e : o = /* @__PURE__ */ g(
442
+ e,
111
443
  {
112
- beacon: e.beacon,
113
- position: e.position,
114
- onDismiss: e.handleDismiss,
115
- onClose: e.hidePopover
444
+ beacon: t.beacon,
445
+ position: t.position,
446
+ onDismiss: t.handleDismiss,
447
+ onClose: t.hidePopover
116
448
  }
117
- ), no(t, {
449
+ ), W(o, {
118
450
  // @ts-expect-error - cloneElement ref typing doesn't handle callback refs properly
119
- ref: e.handlePopoverRef,
120
- id: e.popoverId,
451
+ ref: t.handlePopoverRef,
452
+ id: t.popoverId,
121
453
  popover: "auto"
122
454
  });
123
455
  }
124
- function mo(o, e) {
125
- const t = o.trigger?.position || e.trigger?.position || J, r = o.trigger?.zIndex || e.trigger?.zIndex || 9999, i = o.trigger?.offset, p = o.popover?.position || e.popover?.position || t, n = o.popover?.offset || e.popover?.offset || { x: 0, y: 0 };
456
+ function fe(e, t) {
457
+ const o = e.trigger?.position || t.trigger?.position || te, i = e.trigger?.zIndex || t.trigger?.zIndex || 9999, r = e.trigger?.offset, s = e.popover?.position || t.popover?.position || o, n = e.popover?.offset || t.popover?.offset || { x: 0, y: 0 };
126
458
  return {
127
- position: t,
128
- zIndex: r,
129
- offset: i,
130
- popoverPosition: p,
459
+ position: o,
460
+ zIndex: i,
461
+ offset: r,
462
+ popoverPosition: s,
131
463
  popoverOffset: n
132
464
  };
133
465
  }
134
- function vo({
135
- beacon: o,
136
- config: e,
137
- store: t,
138
- onDismiss: r,
139
- debug: i
466
+ function we({
467
+ beacon: e,
468
+ config: t,
469
+ store: o,
470
+ onDismiss: i,
471
+ debug: r
140
472
  }) {
141
- const p = io(), [n, s] = w(!1), { position: a, zIndex: c, offset: m, popoverPosition: f, popoverOffset: l } = mo(o, e), { calculatedPosition: v, targetElement: d } = po({
142
- targetSelector: o.selector,
143
- position: a,
144
- offset: m,
473
+ const s = Z(), [n, a] = C(!1), { position: l, zIndex: c, offset: d, popoverPosition: w, popoverOffset: p } = fe(e, t), { calculatedPosition: u, targetElement: h } = me({
474
+ targetSelector: e.selector,
475
+ position: l,
476
+ offset: d,
145
477
  zIndex: c,
146
478
  enabled: !0,
147
- debug: i
479
+ debug: r
148
480
  }), {
149
- isOpen: C,
481
+ isOpen: x,
150
482
  popoverElement: R,
151
- handlePopoverRef: h,
152
- togglePopover: g,
153
- showPopover: B,
154
- hidePopover: T
155
- } = ao(), {
156
- triggerAnimation: L,
157
- triggerDismissAnimation: b,
158
- popoverOpenAnimation: V,
159
- popoverCloseAnimation: E
160
- } = so(o, e), k = async () => {
161
- s(!0), R?.hidePopover();
162
- const U = K(
163
- b,
164
- E
483
+ handlePopoverRef: P,
484
+ togglePopover: f,
485
+ showPopover: O,
486
+ hidePopover: I
487
+ } = ge(), {
488
+ triggerAnimation: _,
489
+ triggerDismissAnimation: D,
490
+ popoverOpenAnimation: G,
491
+ popoverCloseAnimation: T
492
+ } = ue(e, t), E = async () => {
493
+ a(!0), R?.hidePopover();
494
+ const H = re(
495
+ D,
496
+ T
165
497
  );
166
- await Q(U), await Promise.resolve(t.dismiss(o.id)), r();
167
- }, q = {
168
- beaconId: o.id,
169
- position: a,
170
- popoverPosition: f,
171
- popoverOffset: l,
172
- calculatedPosition: v,
173
- isOpen: C,
498
+ await ae(H), await Promise.resolve(o.dismiss(e.id)), i();
499
+ }, V = {
500
+ beaconId: e.id,
501
+ position: l,
502
+ popoverPosition: w,
503
+ popoverOffset: p,
504
+ calculatedPosition: u,
505
+ isOpen: x,
174
506
  isDismissing: n,
175
- toggle: g,
176
- open: B,
177
- close: T,
178
- dismiss: k,
179
- triggerAnimation: L,
180
- triggerDismissAnimation: b,
181
- popoverOpenAnimation: V,
182
- popoverCloseAnimation: E,
183
- popoverId: p
184
- }, G = o.trigger?.component || e.trigger?.component, N = o.popover.component || e.popover?.component;
185
- return !v || !d ? (i && console.warn(
186
- `[Repere] ${o.id} waiting for target element: position=${!!v}, element=${!!d}`
187
- ), null) : N ? /* @__PURE__ */ W(S.Provider, { value: q, children: [
188
- co(G, {
189
- beacon: o,
190
- calculatedPosition: v,
191
- position: a,
192
- isOpen: C,
193
- togglePopover: g
507
+ toggle: f,
508
+ open: O,
509
+ close: I,
510
+ dismiss: E,
511
+ triggerAnimation: _,
512
+ triggerDismissAnimation: D,
513
+ popoverOpenAnimation: G,
514
+ popoverCloseAnimation: T,
515
+ popoverId: s
516
+ }, q = e.trigger?.component || t.trigger?.component, S = e.popover.component || t.popover?.component;
517
+ return !u || !h ? (r && console.warn(
518
+ `[Repere] ${e.id} waiting for target element: position=${!!u}, element=${!!h}`
519
+ ), null) : S ? /* @__PURE__ */ J(j.Provider, { value: V, children: [
520
+ ve(q, {
521
+ beacon: e,
522
+ calculatedPosition: u,
523
+ position: l,
524
+ isOpen: x,
525
+ togglePopover: f
194
526
  }),
195
- lo(N, {
196
- beacon: o,
197
- position: a,
198
- handleDismiss: k,
199
- hidePopover: T,
200
- handlePopoverRef: h,
201
- popoverId: p
527
+ he(S, {
528
+ beacon: e,
529
+ position: l,
530
+ handleDismiss: E,
531
+ hidePopover: I,
532
+ handlePopoverRef: P,
533
+ popoverId: s
202
534
  })
203
- ] }) : (i && console.warn(
535
+ ] }) : (r && console.warn(
204
536
  "[Repere] No popover component provided for beacon:",
205
- o.id
537
+ e.id
206
538
  ), null);
207
539
  }
208
- function Ro({
209
- config: o,
210
- currentPath: e,
211
- enabled: t = !0,
212
- debug: r = !1
540
+ function Be({
541
+ config: e,
542
+ currentPath: t,
543
+ enabled: o = !0,
544
+ debug: i = !1
213
545
  }) {
214
- const i = P(
215
- () => o.store || new X(),
216
- [o.store]
217
- ), p = P(
218
- () => new Y(i, { debug: r }),
219
- [i, r]
220
- ), [n, s] = w([]), [a, c] = w(
546
+ const r = y(
547
+ () => e.store || new oe(),
548
+ [e.store]
549
+ ), s = y(
550
+ () => new ce(r, { debug: i }),
551
+ [r, i]
552
+ ), [n, a] = C([]), [l, c] = C(
221
553
  /* @__PURE__ */ new Set()
222
554
  );
223
- O(() => {
224
- if (!t) {
225
- s([]), c(/* @__PURE__ */ new Set());
555
+ $(() => {
556
+ if (!o) {
557
+ a([]), c(/* @__PURE__ */ new Set());
226
558
  return;
227
559
  }
228
560
  (async () => {
229
- const v = await p.getActiveBeacons(
230
- o.pages,
231
- e
561
+ const u = await s.getActiveBeacons(
562
+ e.pages,
563
+ t
232
564
  );
233
- s(v);
565
+ a(u);
234
566
  })();
235
- }, [p, o.pages, e, t]);
236
- const m = (l) => {
237
- c((v) => /* @__PURE__ */ new Set([...v, l]));
238
- }, f = n.filter(
239
- (l) => !a.has(l.id)
567
+ }, [s, e.pages, t, o]);
568
+ const d = (p) => {
569
+ c((u) => /* @__PURE__ */ new Set([...u, p]));
570
+ }, w = n.filter(
571
+ (p) => !l.has(p.id)
240
572
  );
241
- return f.length === 0 ? null : ro(
242
- f.map((l) => /* @__PURE__ */ u(
243
- vo,
573
+ return w.length === 0 ? null : ee(
574
+ w.map((p) => /* @__PURE__ */ g(
575
+ we,
244
576
  {
245
- beacon: l,
246
- config: o,
247
- store: i,
248
- debug: r,
249
- onDismiss: () => m(l.id)
577
+ beacon: p,
578
+ config: e,
579
+ store: r,
580
+ debug: i,
581
+ onDismiss: () => d(p.id)
250
582
  },
251
- l.id
583
+ p.id
252
584
  )),
253
585
  document.body
254
586
  );
255
587
  }
256
- const z = A(
588
+ const X = b(
257
589
  ({
258
- children: o,
259
- style: e,
260
- popover: t = "auto",
261
- disableAnimation: r,
590
+ children: e,
591
+ style: t,
592
+ popover: o = "auto",
593
+ disableAnimation: i,
262
594
  // Destructure and discard internal props so they don't spread to DOM
263
- beacon: i,
264
- position: p,
595
+ beacon: r,
596
+ position: s,
265
597
  onDismiss: n,
266
- onClose: s,
267
- ...a
598
+ onClose: a,
599
+ ...l
268
600
  }, c) => {
269
601
  const {
270
- beaconId: m,
271
- popoverOpenAnimation: f,
272
- popoverCloseAnimation: l,
273
- popoverPosition: v,
274
- popoverOffset: d
275
- } = I(), C = y(
276
- (g) => {
277
- typeof c == "function" ? c(g) : c && (c.current = g);
602
+ beaconId: d,
603
+ popoverOpenAnimation: w,
604
+ popoverCloseAnimation: p,
605
+ popoverPosition: u,
606
+ popoverOffset: h
607
+ } = k(), x = A(
608
+ (f) => {
609
+ typeof c == "function" ? c(f) : c && (c.current = f);
278
610
  },
279
611
  [c]
280
- ), h = {
281
- positionAnchor: m ? `--repere-trigger-${m}` : void 0,
282
- ...d && {
283
- marginLeft: d.x || 0,
284
- marginTop: d.y || 0
612
+ ), P = {
613
+ positionAnchor: d ? `--repere-trigger-${d}` : void 0,
614
+ ...h && {
615
+ marginLeft: h.x || 0,
616
+ marginTop: h.y || 0
285
617
  },
286
- ...Z(f, l),
287
- ...e
618
+ ...se(w, p),
619
+ ...t
288
620
  };
289
- return /* @__PURE__ */ u(
621
+ return /* @__PURE__ */ g(
290
622
  "div",
291
623
  {
292
- ref: C,
624
+ ref: x,
293
625
  role: "dialog",
294
- "aria-labelledby": `repere-popover-${m}`,
626
+ "aria-labelledby": `repere-popover-${d}`,
295
627
  "data-repere-popover": "",
296
- "data-position": v,
297
- popover: t,
298
- ...a,
299
- style: h,
300
- children: o
628
+ "data-position": u,
629
+ popover: o,
630
+ ...l,
631
+ style: P,
632
+ children: e
301
633
  }
302
634
  );
303
635
  }
304
636
  );
305
- z.displayName = "ReperePopover";
306
- const uo = A(
637
+ X.displayName = "ReperePopover";
638
+ const ye = b(
307
639
  ({
308
- children: o = "Got it",
309
- onClick: e,
310
- as: t,
311
- ...r
312
- }, i) => {
313
- const p = I(), n = p?.dismiss || (() => {
314
- }), s = p?.popoverId;
315
- return /* @__PURE__ */ u(
316
- t || "button",
640
+ children: e = "Got it",
641
+ onClick: t,
642
+ as: o,
643
+ ...i
644
+ }, r) => {
645
+ const s = k(), n = s?.dismiss || (() => {
646
+ }), a = s?.popoverId;
647
+ return /* @__PURE__ */ g(
648
+ o || "button",
317
649
  {
318
- ref: i,
319
- onClick: (m) => {
320
- n(), e?.(m);
650
+ ref: r,
651
+ onClick: (d) => {
652
+ n(), t?.(d);
321
653
  },
322
- popovertarget: s,
654
+ popovertarget: a,
323
655
  popovertargetaction: "hide",
324
- ...r,
325
- children: o
656
+ ...i,
657
+ children: e
326
658
  }
327
659
  );
328
660
  }
329
- ), go = Object.assign(uo, {
661
+ ), xe = Object.assign(ye, {
330
662
  displayName: "ReperePopover.AcknowledgeButton"
331
- }), F = A(({ children: o = "×", ...e }, t) => {
332
- const i = I()?.popoverId;
333
- return /* @__PURE__ */ u(
663
+ }), Y = b(({ children: e = "×", ...t }, o) => {
664
+ const r = k()?.popoverId;
665
+ return /* @__PURE__ */ g(
334
666
  "button",
335
667
  {
336
- ref: t,
337
- popovertarget: i,
668
+ ref: o,
669
+ popovertarget: r,
338
670
  popovertargetaction: "hide",
339
671
  "aria-label": "Close",
340
- ...e,
341
- children: o
672
+ ...t,
673
+ children: e
342
674
  }
343
675
  );
344
676
  });
345
- F.displayName = "ReperePopover.CloseButton";
346
- const M = A(
347
- ({ children: o, ...e }, t) => /* @__PURE__ */ u("div", { ref: t, ...e, children: o })
677
+ Y.displayName = "ReperePopover.CloseButton";
678
+ const F = b(
679
+ ({ children: e, ...t }, o) => /* @__PURE__ */ g("div", { ref: o, ...t, children: e })
348
680
  );
349
- M.displayName = "ReperePopover.Content";
350
- const _ = A(
351
- ({ children: o, ...e }, t) => /* @__PURE__ */ u("div", { ref: t, ...e, children: o })
681
+ F.displayName = "ReperePopover.Content";
682
+ const U = b(
683
+ ({ children: e, ...t }, o) => /* @__PURE__ */ g("div", { ref: o, ...t, children: e })
352
684
  );
353
- _.displayName = "ReperePopover.Footer";
354
- const fo = A(
355
- ({ children: o, as: e, ...t }, r) => {
356
- const p = I()?.beaconId || "unknown";
357
- return /* @__PURE__ */ u(e || "h3", { ref: r, id: `repere-popover-${p}`, ...t, children: o });
685
+ U.displayName = "ReperePopover.Footer";
686
+ const be = b(
687
+ ({ children: e, as: t, ...o }, i) => {
688
+ const s = k()?.beaconId || "unknown";
689
+ return /* @__PURE__ */ g(t || "h3", { ref: i, id: `repere-popover-${s}`, ...o, children: e });
358
690
  }
359
- ), Po = Object.assign(fo, {
691
+ ), Pe = Object.assign(be, {
360
692
  displayName: "ReperePopover.Title"
361
- }), xo = Object.assign(z, {
362
- Title: Po,
363
- Content: M,
364
- Footer: _,
365
- AcknowledgeButton: go,
366
- CloseButton: F
367
- }), Co = A(
693
+ }), $e = Object.assign(X, {
694
+ Title: Pe,
695
+ Content: F,
696
+ Footer: U,
697
+ AcknowledgeButton: xe,
698
+ CloseButton: Y
699
+ }), Ce = b(
368
700
  ({
369
- children: o,
370
- as: e,
371
- style: t,
372
- disableAnimation: r,
373
- ...i
374
- }, p) => {
701
+ children: e,
702
+ as: t,
703
+ style: o,
704
+ disableAnimation: i,
705
+ ...r
706
+ }, s) => {
375
707
  const {
376
708
  calculatedPosition: n,
377
- beaconId: s,
378
- triggerAnimation: a,
709
+ beaconId: a,
710
+ triggerAnimation: l,
379
711
  triggerDismissAnimation: c,
380
- isDismissing: m,
381
- popoverId: f
382
- } = I(), l = e || "button", v = P(() => !e || e === "button" ? $.button : $.create(l), [e, l]);
712
+ isDismissing: d,
713
+ popoverId: w
714
+ } = k(), p = t || "button", u = y(() => !t || t === "button" ? M.button : M.create(p), [t, p]);
383
715
  if (!n) return null;
384
- const d = {
716
+ const h = {
385
717
  position: n.position,
386
718
  top: n.top,
387
719
  left: n.left,
388
720
  zIndex: n.zIndex,
389
721
  pointerEvents: "auto",
390
722
  cursor: "pointer",
391
- anchorName: `--repere-trigger-${s}`
392
- }, C = t ? { ...d, ...t } : d, R = !r && (a || c), h = {
393
- ref: p,
394
- popovertarget: f,
395
- "aria-label": `Beacon trigger for ${s}`,
723
+ anchorName: `--repere-trigger-${a}`
724
+ }, x = o ? { ...h, ...o } : h, R = !i && (l || c), P = {
725
+ ref: s,
726
+ popovertarget: w,
727
+ "aria-label": `Beacon trigger for ${a}`,
396
728
  "data-repere-trigger": "",
397
- ...i
729
+ ...r
398
730
  };
399
731
  if (R) {
400
- const g = m && c ? c : a;
401
- if (!g) return null;
402
- const B = oo(
732
+ const f = d && c ? c : l;
733
+ if (!f) return null;
734
+ const O = ie(
403
735
  n.translate,
404
- g.variants
736
+ f.variants
405
737
  );
406
- return /* @__PURE__ */ u(
407
- v,
738
+ return /* @__PURE__ */ g(
739
+ u,
408
740
  {
409
741
  initial: "initial",
410
- animate: m ? "exit" : "animate",
411
- variants: B,
412
- transition: g.transition,
413
- ...h,
414
- style: C,
415
- children: o
742
+ animate: d ? "exit" : "animate",
743
+ variants: O,
744
+ transition: f.transition,
745
+ ...P,
746
+ style: x,
747
+ children: e
416
748
  }
417
749
  );
418
750
  }
419
- return /* @__PURE__ */ u(
420
- l,
751
+ return /* @__PURE__ */ g(
752
+ p,
421
753
  {
422
- ...h,
754
+ ...P,
423
755
  style: {
424
- ...C,
756
+ ...x,
425
757
  translate: `${n.translate.x} ${n.translate.y}`
426
758
  },
427
- children: o
759
+ children: e
428
760
  }
429
761
  );
430
762
  }
431
- ), Do = Object.assign(Co, {
763
+ ), Oe = Object.assign(Ce, {
432
764
  displayName: "RepereTrigger"
433
765
  });
434
766
  export {
435
- Ro as Beacons,
436
- xo as ReperePopover,
437
- Do as RepereTrigger
767
+ v as Animation,
768
+ Be as Beacons,
769
+ m as Position,
770
+ $e as ReperePopover,
771
+ Oe as RepereTrigger
438
772
  };
@@ -0,0 +1 @@
1
+ [data-repere-popover]{position:absolute;position-anchor:var(--repere-anchor);inset:unset;margin:0;opacity:var(--repere-exit-opacity, 0);transform:translate(var(--repere-exit-x, 0)) translateY(var(--repere-exit-y, -20px)) scale(var(--repere-exit-scale, 1));transition-property:opacity,transform,overlay,display;transition-duration:var(--repere-transition-duration, .3s);transition-timing-function:var( --repere-transition-timing, cubic-bezier(.4, 0, .2, 1) );transition-behavior:allow-discrete}[data-repere-popover]:popover-open{opacity:var(--repere-animate-opacity, 1);transform:translate(var(--repere-animate-x, 0)) translateY(var(--repere-animate-y, 0)) scale(var(--repere-animate-scale, 1))}@starting-style{[data-repere-popover]:popover-open{opacity:var(--repere-initial-opacity, 0);transform:translate(var(--repere-initial-x, 0)) translateY(var(--repere-initial-y, -20px)) scale(var(--repere-initial-scale, 1))}}[data-repere-popover][data-position=bottom-left]{top:anchor(bottom);left:anchor(left);position-try-fallbacks:--bottom-right,--top-left,--top-right}[data-repere-popover][data-position=bottom-center]{top:anchor(bottom);left:anchor(center);translate:-50% 0;position-try-fallbacks:--bottom-left,--bottom-right,--top-center}[data-repere-popover][data-position=bottom-right]{top:anchor(bottom);right:anchor(right);position-try-fallbacks:--bottom-left,--top-right,--top-left}[data-repere-popover][data-position=top-left]{bottom:anchor(top);left:anchor(left);position-try-fallbacks:--top-right,--bottom-left,--bottom-right}[data-repere-popover][data-position=top-center]{bottom:anchor(top);left:anchor(center);translate:-50% 0;position-try-fallbacks:--top-left,--top-right,--bottom-center}[data-repere-popover][data-position=top-right]{bottom:anchor(top);right:anchor(right);position-try-fallbacks:--top-left,--bottom-right,--bottom-left}[data-repere-popover][data-position=left-center]:popover-open{top:anchor(center);right:anchor(left);translate:0 -50%;position-try-fallbacks:--right-center,--bottom-center,--top-center}[data-repere-popover][data-position=right-center]:popover-open{top:anchor(center);left:anchor(right);translate:0 -50%;position-try-fallbacks:--left-center,--bottom-center,--top-center}[data-repere-trigger]{anchor-name:var(--repere-anchor)}@position-try --bottom-left{top:anchor(bottom);left:anchor(left);right:auto;bottom:auto;translate:0 0}@position-try --bottom-right{top:anchor(bottom);right:anchor(right);left:auto;bottom:auto;translate:0 0}@position-try --bottom-center{top:anchor(bottom);left:anchor(center);right:auto;bottom:auto;translate:-50% 0}@position-try --top-left{bottom:anchor(top);left:anchor(left);right:auto;top:auto;translate:0 0}@position-try --top-right{bottom:anchor(top);right:anchor(right);left:auto;top:auto;translate:0 0}@position-try --top-center{bottom:anchor(top);left:anchor(center);right:auto;top:auto;translate:-50% 0}@position-try --left-center{top:anchor(center);right:anchor(left);left:auto;bottom:auto;translate:0 -50%}@position-try --right-center{top:anchor(center);left:anchor(right);right:auto;bottom:auto;translate:0 -50%}
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@repere/react",
3
- "version": "0.0.3",
3
+ "version": "0.1.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
8
  "types": "./dist/index.d.ts",
9
9
  "import": "./dist/index.js"
10
- }
10
+ },
11
+ "./styles.css": "./dist/styles.css"
11
12
  },
12
13
  "files": [
13
14
  "dist"
@@ -15,10 +16,10 @@
15
16
  "peerDependencies": {
16
17
  "motion": "^12.0.0",
17
18
  "react": "^18.0.0 || ^19.0.0",
18
- "react-dom": "^18.0.0 || ^19.0.0",
19
- "@repere/core": "0.0.3"
19
+ "react-dom": "^18.0.0 || ^19.0.0"
20
20
  },
21
21
  "devDependencies": {
22
+ "@types/node": "^25.0.3",
22
23
  "@types/react": "^19.2.7",
23
24
  "@types/react-dom": "^19.2.3",
24
25
  "@vitejs/plugin-react": "^5.1.2",