mn-angular-lib 2.0.60 → 2.0.61
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/fesm2022/mn-angular-lib-tour.mjs +765 -0
- package/fesm2022/mn-angular-lib-tour.mjs.map +1 -0
- package/fesm2022/mn-angular-lib.mjs +1 -0
- package/package.json +5 -1
- package/tour/src/mn-tour/mn-tour-overlay.css +198 -0
- package/types/mn-angular-lib-tour.d.ts +320 -0
- package/types/mn-angular-lib.d.ts +1 -0
|
@@ -0,0 +1,765 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { ApplicationRef, Component, EnvironmentInjector, Injectable, computed, createComponent, inject, output, signal, viewChild } from "@angular/core";
|
|
3
|
+
import { MnButton } from "mn-angular-lib/button";
|
|
4
|
+
const MN_TOUR_MOTION = {
|
|
5
|
+
glideMs: 450,
|
|
6
|
+
fadeInMs: 450,
|
|
7
|
+
fadeOutMs: 200,
|
|
8
|
+
contentFadeMs: 120
|
|
9
|
+
};
|
|
10
|
+
function padBox(rect, pad = 6) {
|
|
11
|
+
return {
|
|
12
|
+
top: rect.top - pad,
|
|
13
|
+
left: rect.left - pad,
|
|
14
|
+
width: rect.width + pad * 2,
|
|
15
|
+
height: rect.height + pad * 2
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function boxChanged(a, b) {
|
|
19
|
+
if (!a || !b) return a !== b;
|
|
20
|
+
return Math.abs(a.top - b.top) > .5 || Math.abs(a.left - b.left) > .5 || Math.abs(a.width - b.width) > .5 || Math.abs(a.height - b.height) > .5;
|
|
21
|
+
}
|
|
22
|
+
function clamp(value, min, max) {
|
|
23
|
+
return Math.max(min, Math.min(value, max));
|
|
24
|
+
}
|
|
25
|
+
function placeBeside(hole, card, viewport) {
|
|
26
|
+
const m = 16;
|
|
27
|
+
const gap = 14;
|
|
28
|
+
const maxX = viewport.width - card.width - m;
|
|
29
|
+
const maxY = viewport.height - card.height - m;
|
|
30
|
+
const centredY = clamp(hole.top + hole.height / 2 - card.height / 2, m, maxY);
|
|
31
|
+
const centredX = clamp(hole.left + hole.width / 2 - card.width / 2, m, maxX);
|
|
32
|
+
const right = hole.left + hole.width + gap;
|
|
33
|
+
if (right + card.width + m <= viewport.width) return {
|
|
34
|
+
x: right,
|
|
35
|
+
y: centredY
|
|
36
|
+
};
|
|
37
|
+
const left = hole.left - gap - card.width;
|
|
38
|
+
if (left >= m) return {
|
|
39
|
+
x: left,
|
|
40
|
+
y: centredY
|
|
41
|
+
};
|
|
42
|
+
const below = hole.top + hole.height + gap;
|
|
43
|
+
if (below + card.height + m <= viewport.height) return {
|
|
44
|
+
x: centredX,
|
|
45
|
+
y: below
|
|
46
|
+
};
|
|
47
|
+
const above = hole.top - gap - card.height;
|
|
48
|
+
if (above >= m) return {
|
|
49
|
+
x: centredX,
|
|
50
|
+
y: above
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
x: centredX,
|
|
54
|
+
y: clamp(below, m, maxY)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function isRendered(el) {
|
|
58
|
+
const rect = el.getBoundingClientRect();
|
|
59
|
+
if (rect.width <= 0 || rect.height <= 0) return false;
|
|
60
|
+
return getComputedStyle(el).visibility !== "hidden";
|
|
61
|
+
}
|
|
62
|
+
function findTourTarget(name, root = document) {
|
|
63
|
+
const selector = `[data-tour="${CSS.escape(name)}"]`;
|
|
64
|
+
for (const el of Array.from(root.querySelectorAll(selector))) if (isRendered(el)) return el;
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const TARGET_POLL_MS = 50;
|
|
68
|
+
function waitForTourTarget(name, timeoutMs, isCancelled = () => false) {
|
|
69
|
+
const found = findTourTarget(name);
|
|
70
|
+
if (found || timeoutMs <= 0) return Promise.resolve(found);
|
|
71
|
+
return new Promise((resolve) => {
|
|
72
|
+
let settled = false;
|
|
73
|
+
const finish = (el) => {
|
|
74
|
+
if (settled) return;
|
|
75
|
+
settled = true;
|
|
76
|
+
observer.disconnect();
|
|
77
|
+
clearInterval(poll);
|
|
78
|
+
clearTimeout(timeout);
|
|
79
|
+
resolve(el);
|
|
80
|
+
};
|
|
81
|
+
const check = () => {
|
|
82
|
+
if (isCancelled()) {
|
|
83
|
+
finish(null);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const el = findTourTarget(name);
|
|
87
|
+
if (el) finish(el);
|
|
88
|
+
};
|
|
89
|
+
const observer = new MutationObserver(check);
|
|
90
|
+
observer.observe(document.documentElement, {
|
|
91
|
+
childList: true,
|
|
92
|
+
subtree: true,
|
|
93
|
+
attributes: true
|
|
94
|
+
});
|
|
95
|
+
const poll = setInterval(check, TARGET_POLL_MS);
|
|
96
|
+
const timeout = setTimeout(() => finish(findTourTarget(name)), timeoutMs);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
let nextOverlayId = 0;
|
|
100
|
+
var MnTourOverlay = class MnTourOverlay {
|
|
101
|
+
view = signal(null, ...ngDevMode ? [{ debugName: "view" }] : /* istanbul ignore next */ []);
|
|
102
|
+
contentVisible = signal(false, ...ngDevMode ? [{ debugName: "contentVisible" }] : /* istanbul ignore next */ []);
|
|
103
|
+
cardVisible = signal(false, ...ngDevMode ? [{ debugName: "cardVisible" }] : /* istanbul ignore next */ []);
|
|
104
|
+
variant = signal("centred", ...ngDevMode ? [{ debugName: "variant" }] : /* istanbul ignore next */ []);
|
|
105
|
+
dim = signal("none", ...ngDevMode ? [{ debugName: "dim" }] : /* istanbul ignore next */ []);
|
|
106
|
+
hole = signal(null, ...ngDevMode ? [{ debugName: "hole" }] : /* istanbul ignore next */ []);
|
|
107
|
+
holeVisible = signal(false, ...ngDevMode ? [{ debugName: "holeVisible" }] : /* istanbul ignore next */ []);
|
|
108
|
+
gliding = signal(false, ...ngDevMode ? [{ debugName: "gliding" }] : /* istanbul ignore next */ []);
|
|
109
|
+
cardPos = signal(null, ...ngDevMode ? [{ debugName: "cardPos" }] : /* istanbul ignore next */ []);
|
|
110
|
+
reducedMotion = signal(false, ...ngDevMode ? [{ debugName: "reducedMotion" }] : /* istanbul ignore next */ []);
|
|
111
|
+
action = output();
|
|
112
|
+
titleId = `mn-tour-title-${nextOverlayId}`;
|
|
113
|
+
bodyId = `mn-tour-body-${nextOverlayId++}`;
|
|
114
|
+
primaryButton = {
|
|
115
|
+
variant: "fill",
|
|
116
|
+
color: "primary",
|
|
117
|
+
size: "sm",
|
|
118
|
+
borderRadius: "lg",
|
|
119
|
+
wrap: false,
|
|
120
|
+
hover: true
|
|
121
|
+
};
|
|
122
|
+
secondaryButton = {
|
|
123
|
+
variant: "outline",
|
|
124
|
+
color: "gray",
|
|
125
|
+
size: "sm",
|
|
126
|
+
borderRadius: "lg",
|
|
127
|
+
wrap: false,
|
|
128
|
+
hover: true
|
|
129
|
+
};
|
|
130
|
+
cardTransform = computed(() => {
|
|
131
|
+
const pos = this.cardPos();
|
|
132
|
+
return this.variant() === "beside" && pos ? `translate(${pos.x}px, ${pos.y}px)` : null;
|
|
133
|
+
}, ...ngDevMode ? [{ debugName: "cardTransform" }] : /* istanbul ignore next */ []);
|
|
134
|
+
cardRef = viewChild("card", ...ngDevMode ? [{ debugName: "cardRef" }] : /* istanbul ignore next */ []);
|
|
135
|
+
cardSize() {
|
|
136
|
+
const el = this.cardRef()?.nativeElement;
|
|
137
|
+
return el ? {
|
|
138
|
+
width: el.offsetWidth,
|
|
139
|
+
height: el.offsetHeight
|
|
140
|
+
} : null;
|
|
141
|
+
}
|
|
142
|
+
focusCard() {
|
|
143
|
+
this.cardRef()?.nativeElement.focus({ preventScroll: true });
|
|
144
|
+
}
|
|
145
|
+
hasFocus() {
|
|
146
|
+
return this.contains(document.activeElement);
|
|
147
|
+
}
|
|
148
|
+
contains(node) {
|
|
149
|
+
const el = this.cardRef()?.nativeElement;
|
|
150
|
+
return !!el && !!node && el.contains(node);
|
|
151
|
+
}
|
|
152
|
+
trapTab(event) {
|
|
153
|
+
const el = this.cardRef()?.nativeElement;
|
|
154
|
+
if (!el) return;
|
|
155
|
+
const focusable = Array.from(el.querySelectorAll("button:not([disabled]), a[href], [tabindex]:not([tabindex=\"-1\"])"));
|
|
156
|
+
if (focusable.length === 0) {
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
el.focus({ preventScroll: true });
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const first = focusable[0];
|
|
162
|
+
const last = focusable[focusable.length - 1];
|
|
163
|
+
const active = document.activeElement;
|
|
164
|
+
const inside = !!active && focusable.includes(active);
|
|
165
|
+
if (event.shiftKey && (!inside || active === first)) {
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
last.focus({ preventScroll: true });
|
|
168
|
+
} else if (!event.shiftKey && (!inside || active === last)) {
|
|
169
|
+
event.preventDefault();
|
|
170
|
+
first.focus({ preventScroll: true });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
dots(total, active) {
|
|
174
|
+
return Array.from({ length: total }, (_, i) => i === active);
|
|
175
|
+
}
|
|
176
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
177
|
+
minVersion: "12.0.0",
|
|
178
|
+
version: "22.2.4",
|
|
179
|
+
ngImport: i0,
|
|
180
|
+
type: MnTourOverlay,
|
|
181
|
+
deps: [],
|
|
182
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
183
|
+
});
|
|
184
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
185
|
+
minVersion: "17.0.0",
|
|
186
|
+
version: "22.2.4",
|
|
187
|
+
type: MnTourOverlay,
|
|
188
|
+
isStandalone: true,
|
|
189
|
+
selector: "mn-tour-overlay",
|
|
190
|
+
outputs: { action: "action" },
|
|
191
|
+
viewQueries: [{
|
|
192
|
+
propertyName: "cardRef",
|
|
193
|
+
first: true,
|
|
194
|
+
predicate: ["card"],
|
|
195
|
+
descendants: true,
|
|
196
|
+
isSignal: true
|
|
197
|
+
}],
|
|
198
|
+
ngImport: i0,
|
|
199
|
+
template: "<div\n [class.mn-tour-passive]=\"dim() === 'none'\"\n [class.mn-tour-reduced]=\"reducedMotion()\"\n class=\"mn-tour-root\"\n>\n @if (dim() !== 'none') {\n <!-- Catches clicks on the page while the tour runs; the dim itself is purely visual. -->\n <div aria-hidden=\"true\" class=\"mn-tour-blocker\"></div>\n }\n <div [class.is-visible]=\"dim() === 'full'\" aria-hidden=\"true\" class=\"mn-tour-dim\"></div>\n <div\n [class.is-gliding]=\"gliding()\"\n [class.is-visible]=\"dim() === 'hole' && holeVisible()\"\n [style.height.px]=\"hole()?.height ?? 0\"\n [style.left.px]=\"hole()?.left ?? 0\"\n [style.top.px]=\"hole()?.top ?? 0\"\n [style.width.px]=\"hole()?.width ?? 0\"\n aria-hidden=\"true\"\n class=\"mn-tour-hole\"\n ></div>\n\n @if (view(); as v) {\n <div\n #card\n [attr.aria-describedby]=\"bodyId\"\n [attr.aria-labelledby]=\"titleId\"\n [attr.aria-modal]=\"dim() === 'none' ? null : 'true'\"\n [class.is-gliding]=\"gliding()\"\n [class.is-shown]=\"cardVisible()\"\n [class.mn-tour-card--beside]=\"variant() === 'beside'\"\n [class.mn-tour-card--centred]=\"variant() === 'centred'\"\n [class.mn-tour-card--corner]=\"variant() === 'corner'\"\n [class.mn-tour-card--sheet]=\"variant() === 'sheet'\"\n [style.transform]=\"cardTransform()\"\n class=\"mn-tour-card text-base-content\"\n role=\"dialog\"\n tabindex=\"-1\"\n >\n <div [class.is-visible]=\"contentVisible()\" aria-live=\"polite\" class=\"mn-tour-content\">\n <div class=\"flex items-start gap-4\">\n <div class=\"min-w-0 flex-1 text-left\">\n @if (v.kicker) {\n <p class=\"text-xs font-medium text-base-content/60\">{{ v.kicker }}</p>\n }\n <h2 [id]=\"titleId\" class=\"mt-0.5 text-base font-semibold leading-snug\">{{ v.title }}</h2>\n </div>\n @if (v.skip) {\n <button\n (click)=\"action.emit('skip')\"\n class=\"mn-tour-skip shrink-0 whitespace-nowrap rounded text-sm text-base-content/60 hover:text-base-content hover:underline underline-offset-2 cursor-pointer\"\n type=\"button\"\n >{{ v.skip }}</button>\n }\n </div>\n\n <p [id]=\"bodyId\" class=\"mt-1.5 text-left text-sm leading-relaxed text-base-content/80\">{{ v.body }}</p>\n\n @if (v.nextTour; as next) {\n <div class=\"mn-tour-next mt-4 rounded-xl bg-primary/10 px-3.5 py-3 text-left\">\n @if (next.kicker) {\n <p class=\"text-xs font-medium text-primary\">{{ next.kicker }}</p>\n }\n <p class=\"text-sm font-semibold\">{{ next.title }}</p>\n @if (next.meta) {\n <p class=\"text-xs text-base-content/60\">{{ next.meta }}</p>\n }\n </div>\n }\n\n <div class=\"mn-tour-footer mt-5 flex items-center gap-3\">\n @if (v.progress; as p) {\n <div aria-hidden=\"true\" class=\"mn-tour-dots flex shrink-0 items-center gap-1.5\">\n @for (active of dots(p.total, p.active); track $index) {\n <span [class.is-active]=\"active\" class=\"mn-tour-dot\"></span>\n }\n </div>\n <span class=\"sr-only\">{{ p.label }}</span>\n }\n <div class=\"mn-tour-actions ml-auto flex items-center gap-2\">\n @if (v.secondary) {\n <button\n (click)=\"action.emit('secondary')\"\n [data]=\"secondaryButton\"\n class=\"mn-tour-secondary\"\n mnButton\n type=\"button\"\n >{{ v.secondary }}</button>\n }\n <button\n (click)=\"action.emit('primary')\"\n [data]=\"primaryButton\"\n class=\"mn-tour-primary\"\n mnButton\n type=\"button\"\n >{{ v.primary }}</button>\n </div>\n </div>\n </div>\n </div>\n }\n</div>\n",
|
|
200
|
+
styles: [":host{--mn-tour-glide: .45s;--mn-tour-fade-in: .45s;--mn-tour-fade-out: .2s;--mn-tour-content-fade: .12s;--mn-tour-glide-ease: cubic-bezier(.2, .8, .2, 1);--mn-tour-sheet-ease: cubic-bezier(.32, .72, 0, 1);--mn-tour-dim-color: rgb(15 23 42 / .55);display:contents}.mn-tour-root{position:fixed;inset:0;z-index:9990}.mn-tour-root.mn-tour-passive{pointer-events:none}.mn-tour-passive .mn-tour-card{pointer-events:auto}.mn-tour-blocker{position:fixed;inset:0}.mn-tour-dim{position:fixed;inset:0;background:var(--mn-tour-dim-color);opacity:0;pointer-events:none;transition:opacity var(--mn-tour-fade-out) ease}.mn-tour-dim.is-visible{opacity:1;transition:opacity var(--mn-tour-fade-in) ease-out}.mn-tour-hole{position:fixed;border-radius:14px;box-shadow:0 0 0 3px var(--color-primary),0 0 0 200vmax var(--mn-tour-dim-color);opacity:0;pointer-events:none;transition:opacity var(--mn-tour-fade-out) ease}.mn-tour-hole.is-visible{opacity:1;transition:opacity var(--mn-tour-fade-in) ease-out}.mn-tour-hole.is-gliding{transition:opacity var(--mn-tour-fade-in) ease-out,top var(--mn-tour-glide) var(--mn-tour-glide-ease),left var(--mn-tour-glide) var(--mn-tour-glide-ease),width var(--mn-tour-glide) var(--mn-tour-glide-ease),height var(--mn-tour-glide) var(--mn-tour-glide-ease)}.mn-tour-card{position:fixed;box-sizing:border-box;padding:1.25rem;border:1px solid var(--color-base-300);border-radius:1rem;background:var(--color-base-100);box-shadow:0 20px 50px #00000047;outline:none;opacity:0;transition:opacity var(--mn-tour-fade-out) ease}.mn-tour-card.is-shown{opacity:1;transition:opacity var(--mn-tour-fade-in) ease-out}.mn-tour-card.is-shown.is-gliding{transition:opacity var(--mn-tour-fade-in) ease-out,transform var(--mn-tour-glide) var(--mn-tour-glide-ease)}.mn-tour-card--beside{top:0;left:0;width:max-content;min-width:min(18rem,calc(100vw - 2rem));max-width:min(23rem,calc(100vw - 2rem))}.mn-tour-card--centred{top:50%;left:50%;transform:translate(-50%,-50%);width:min(26rem,calc(100vw - 2rem))}.mn-tour-card--corner{right:1rem;bottom:1rem;width:min(23rem,calc(100vw - 2rem))}.mn-tour-card--sheet{right:0;bottom:0;left:0;width:auto;border-width:1px 0 0;border-radius:1rem 1rem 0 0;padding-bottom:calc(1rem + env(safe-area-inset-bottom));animation:mn-tour-sheet-in .35s var(--mn-tour-sheet-ease)}.mn-tour-card--sheet .mn-tour-actions,.mn-tour-card--sheet .mn-tour-primary{flex:1 1 auto}.mn-tour-content{opacity:0;transition:opacity var(--mn-tour-content-fade) ease}.mn-tour-content.is-visible{opacity:1}.mn-tour-dot{display:block;width:.375rem;height:.375rem;border-radius:9999px;background:var(--color-base-300);transition:width var(--mn-tour-glide) var(--mn-tour-glide-ease),background-color var(--mn-tour-glide) ease}.mn-tour-dot.is-active{width:1rem;background:var(--color-primary)}.mn-tour-skip:focus-visible{outline:2px solid var(--color-primary);outline-offset:2px}@keyframes mn-tour-sheet-in{0%{transform:translateY(100%)}to{transform:translateY(0)}}.mn-tour-reduced *,.mn-tour-reduced{transition:none!important;animation:none!important}@media(prefers-reduced-motion:reduce){.mn-tour-root *,.mn-tour-root{transition:none!important;animation:none!important}}\n"],
|
|
201
|
+
dependencies: [{
|
|
202
|
+
kind: "component",
|
|
203
|
+
type: MnButton,
|
|
204
|
+
selector: "button[mnButton], a[mnButton]",
|
|
205
|
+
inputs: ["data"]
|
|
206
|
+
}]
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
210
|
+
minVersion: "12.0.0",
|
|
211
|
+
version: "22.2.4",
|
|
212
|
+
ngImport: i0,
|
|
213
|
+
type: MnTourOverlay,
|
|
214
|
+
decorators: [{
|
|
215
|
+
type: Component,
|
|
216
|
+
args: [{
|
|
217
|
+
selector: "mn-tour-overlay",
|
|
218
|
+
standalone: true,
|
|
219
|
+
imports: [MnButton],
|
|
220
|
+
template: "<div\n [class.mn-tour-passive]=\"dim() === 'none'\"\n [class.mn-tour-reduced]=\"reducedMotion()\"\n class=\"mn-tour-root\"\n>\n @if (dim() !== 'none') {\n <!-- Catches clicks on the page while the tour runs; the dim itself is purely visual. -->\n <div aria-hidden=\"true\" class=\"mn-tour-blocker\"></div>\n }\n <div [class.is-visible]=\"dim() === 'full'\" aria-hidden=\"true\" class=\"mn-tour-dim\"></div>\n <div\n [class.is-gliding]=\"gliding()\"\n [class.is-visible]=\"dim() === 'hole' && holeVisible()\"\n [style.height.px]=\"hole()?.height ?? 0\"\n [style.left.px]=\"hole()?.left ?? 0\"\n [style.top.px]=\"hole()?.top ?? 0\"\n [style.width.px]=\"hole()?.width ?? 0\"\n aria-hidden=\"true\"\n class=\"mn-tour-hole\"\n ></div>\n\n @if (view(); as v) {\n <div\n #card\n [attr.aria-describedby]=\"bodyId\"\n [attr.aria-labelledby]=\"titleId\"\n [attr.aria-modal]=\"dim() === 'none' ? null : 'true'\"\n [class.is-gliding]=\"gliding()\"\n [class.is-shown]=\"cardVisible()\"\n [class.mn-tour-card--beside]=\"variant() === 'beside'\"\n [class.mn-tour-card--centred]=\"variant() === 'centred'\"\n [class.mn-tour-card--corner]=\"variant() === 'corner'\"\n [class.mn-tour-card--sheet]=\"variant() === 'sheet'\"\n [style.transform]=\"cardTransform()\"\n class=\"mn-tour-card text-base-content\"\n role=\"dialog\"\n tabindex=\"-1\"\n >\n <div [class.is-visible]=\"contentVisible()\" aria-live=\"polite\" class=\"mn-tour-content\">\n <div class=\"flex items-start gap-4\">\n <div class=\"min-w-0 flex-1 text-left\">\n @if (v.kicker) {\n <p class=\"text-xs font-medium text-base-content/60\">{{ v.kicker }}</p>\n }\n <h2 [id]=\"titleId\" class=\"mt-0.5 text-base font-semibold leading-snug\">{{ v.title }}</h2>\n </div>\n @if (v.skip) {\n <button\n (click)=\"action.emit('skip')\"\n class=\"mn-tour-skip shrink-0 whitespace-nowrap rounded text-sm text-base-content/60 hover:text-base-content hover:underline underline-offset-2 cursor-pointer\"\n type=\"button\"\n >{{ v.skip }}</button>\n }\n </div>\n\n <p [id]=\"bodyId\" class=\"mt-1.5 text-left text-sm leading-relaxed text-base-content/80\">{{ v.body }}</p>\n\n @if (v.nextTour; as next) {\n <div class=\"mn-tour-next mt-4 rounded-xl bg-primary/10 px-3.5 py-3 text-left\">\n @if (next.kicker) {\n <p class=\"text-xs font-medium text-primary\">{{ next.kicker }}</p>\n }\n <p class=\"text-sm font-semibold\">{{ next.title }}</p>\n @if (next.meta) {\n <p class=\"text-xs text-base-content/60\">{{ next.meta }}</p>\n }\n </div>\n }\n\n <div class=\"mn-tour-footer mt-5 flex items-center gap-3\">\n @if (v.progress; as p) {\n <div aria-hidden=\"true\" class=\"mn-tour-dots flex shrink-0 items-center gap-1.5\">\n @for (active of dots(p.total, p.active); track $index) {\n <span [class.is-active]=\"active\" class=\"mn-tour-dot\"></span>\n }\n </div>\n <span class=\"sr-only\">{{ p.label }}</span>\n }\n <div class=\"mn-tour-actions ml-auto flex items-center gap-2\">\n @if (v.secondary) {\n <button\n (click)=\"action.emit('secondary')\"\n [data]=\"secondaryButton\"\n class=\"mn-tour-secondary\"\n mnButton\n type=\"button\"\n >{{ v.secondary }}</button>\n }\n <button\n (click)=\"action.emit('primary')\"\n [data]=\"primaryButton\"\n class=\"mn-tour-primary\"\n mnButton\n type=\"button\"\n >{{ v.primary }}</button>\n </div>\n </div>\n </div>\n </div>\n }\n</div>\n",
|
|
221
|
+
styles: [":host{--mn-tour-glide: .45s;--mn-tour-fade-in: .45s;--mn-tour-fade-out: .2s;--mn-tour-content-fade: .12s;--mn-tour-glide-ease: cubic-bezier(.2, .8, .2, 1);--mn-tour-sheet-ease: cubic-bezier(.32, .72, 0, 1);--mn-tour-dim-color: rgb(15 23 42 / .55);display:contents}.mn-tour-root{position:fixed;inset:0;z-index:9990}.mn-tour-root.mn-tour-passive{pointer-events:none}.mn-tour-passive .mn-tour-card{pointer-events:auto}.mn-tour-blocker{position:fixed;inset:0}.mn-tour-dim{position:fixed;inset:0;background:var(--mn-tour-dim-color);opacity:0;pointer-events:none;transition:opacity var(--mn-tour-fade-out) ease}.mn-tour-dim.is-visible{opacity:1;transition:opacity var(--mn-tour-fade-in) ease-out}.mn-tour-hole{position:fixed;border-radius:14px;box-shadow:0 0 0 3px var(--color-primary),0 0 0 200vmax var(--mn-tour-dim-color);opacity:0;pointer-events:none;transition:opacity var(--mn-tour-fade-out) ease}.mn-tour-hole.is-visible{opacity:1;transition:opacity var(--mn-tour-fade-in) ease-out}.mn-tour-hole.is-gliding{transition:opacity var(--mn-tour-fade-in) ease-out,top var(--mn-tour-glide) var(--mn-tour-glide-ease),left var(--mn-tour-glide) var(--mn-tour-glide-ease),width var(--mn-tour-glide) var(--mn-tour-glide-ease),height var(--mn-tour-glide) var(--mn-tour-glide-ease)}.mn-tour-card{position:fixed;box-sizing:border-box;padding:1.25rem;border:1px solid var(--color-base-300);border-radius:1rem;background:var(--color-base-100);box-shadow:0 20px 50px #00000047;outline:none;opacity:0;transition:opacity var(--mn-tour-fade-out) ease}.mn-tour-card.is-shown{opacity:1;transition:opacity var(--mn-tour-fade-in) ease-out}.mn-tour-card.is-shown.is-gliding{transition:opacity var(--mn-tour-fade-in) ease-out,transform var(--mn-tour-glide) var(--mn-tour-glide-ease)}.mn-tour-card--beside{top:0;left:0;width:max-content;min-width:min(18rem,calc(100vw - 2rem));max-width:min(23rem,calc(100vw - 2rem))}.mn-tour-card--centred{top:50%;left:50%;transform:translate(-50%,-50%);width:min(26rem,calc(100vw - 2rem))}.mn-tour-card--corner{right:1rem;bottom:1rem;width:min(23rem,calc(100vw - 2rem))}.mn-tour-card--sheet{right:0;bottom:0;left:0;width:auto;border-width:1px 0 0;border-radius:1rem 1rem 0 0;padding-bottom:calc(1rem + env(safe-area-inset-bottom));animation:mn-tour-sheet-in .35s var(--mn-tour-sheet-ease)}.mn-tour-card--sheet .mn-tour-actions,.mn-tour-card--sheet .mn-tour-primary{flex:1 1 auto}.mn-tour-content{opacity:0;transition:opacity var(--mn-tour-content-fade) ease}.mn-tour-content.is-visible{opacity:1}.mn-tour-dot{display:block;width:.375rem;height:.375rem;border-radius:9999px;background:var(--color-base-300);transition:width var(--mn-tour-glide) var(--mn-tour-glide-ease),background-color var(--mn-tour-glide) ease}.mn-tour-dot.is-active{width:1rem;background:var(--color-primary)}.mn-tour-skip:focus-visible{outline:2px solid var(--color-primary);outline-offset:2px}@keyframes mn-tour-sheet-in{0%{transform:translateY(100%)}to{transform:translateY(0)}}.mn-tour-reduced *,.mn-tour-reduced{transition:none!important;animation:none!important}@media(prefers-reduced-motion:reduce){.mn-tour-root *,.mn-tour-root{transition:none!important;animation:none!important}}\n"]
|
|
222
|
+
}]
|
|
223
|
+
}],
|
|
224
|
+
propDecorators: {
|
|
225
|
+
action: [{
|
|
226
|
+
type: i0.Output,
|
|
227
|
+
args: ["action"]
|
|
228
|
+
}],
|
|
229
|
+
cardRef: [{
|
|
230
|
+
type: i0.ViewChild,
|
|
231
|
+
args: ["card", { isSignal: true }]
|
|
232
|
+
}]
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
const COMPACT_MAX_WIDTH = 1023.98;
|
|
236
|
+
const DEFAULT_TARGET_TIMEOUT_MS = 4e3;
|
|
237
|
+
const SCROLL_MARGIN = 16;
|
|
238
|
+
var MnTourRef = class {
|
|
239
|
+
result;
|
|
240
|
+
step;
|
|
241
|
+
closeFn;
|
|
242
|
+
constructor(result, step, closeFn) {
|
|
243
|
+
this.result = result;
|
|
244
|
+
this.step = step;
|
|
245
|
+
this.closeFn = closeFn;
|
|
246
|
+
}
|
|
247
|
+
close() {
|
|
248
|
+
this.closeFn();
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
var MnTourOfferRef = class {
|
|
252
|
+
result;
|
|
253
|
+
closeFn;
|
|
254
|
+
constructor(result, closeFn) {
|
|
255
|
+
this.result = result;
|
|
256
|
+
this.closeFn = closeFn;
|
|
257
|
+
}
|
|
258
|
+
close() {
|
|
259
|
+
this.closeFn();
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
var MnTourService = class MnTourService {
|
|
263
|
+
appRef = inject(ApplicationRef);
|
|
264
|
+
injector = inject(EnvironmentInjector);
|
|
265
|
+
overlayRef = null;
|
|
266
|
+
session = null;
|
|
267
|
+
teardownTimer = null;
|
|
268
|
+
returnFocus = null;
|
|
269
|
+
stopTrackingFn = null;
|
|
270
|
+
onKeyDown = (event) => this.handleKey(event);
|
|
271
|
+
onResize = () => this.reposition();
|
|
272
|
+
start(options) {
|
|
273
|
+
this.closeCurrent();
|
|
274
|
+
let resolve;
|
|
275
|
+
const result = new Promise((r) => resolve = r);
|
|
276
|
+
const index = signal(-1, ...ngDevMode ? [{ debugName: "index" }] : /* istanbul ignore next */ []);
|
|
277
|
+
const session = {
|
|
278
|
+
kind: "tour",
|
|
279
|
+
options,
|
|
280
|
+
index,
|
|
281
|
+
pendingAfter: -1,
|
|
282
|
+
missing: /* @__PURE__ */ new Set(),
|
|
283
|
+
target: null,
|
|
284
|
+
busy: false,
|
|
285
|
+
ended: false,
|
|
286
|
+
resolve
|
|
287
|
+
};
|
|
288
|
+
const ref = new MnTourRef(result, index.asReadonly(), () => {
|
|
289
|
+
this.endTour(session, {
|
|
290
|
+
status: "closed",
|
|
291
|
+
step: session.index()
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
if (options.steps.length === 0) {
|
|
295
|
+
session.ended = true;
|
|
296
|
+
resolve({
|
|
297
|
+
status: "completed",
|
|
298
|
+
step: -1,
|
|
299
|
+
startNext: false
|
|
300
|
+
});
|
|
301
|
+
return ref;
|
|
302
|
+
}
|
|
303
|
+
this.session = session;
|
|
304
|
+
this.ensureOverlay();
|
|
305
|
+
const first = Math.min(Math.max(options.startAt ?? 0, 0), options.steps.length - 1);
|
|
306
|
+
this.go(session, first, 1);
|
|
307
|
+
return ref;
|
|
308
|
+
}
|
|
309
|
+
offer(options) {
|
|
310
|
+
this.closeCurrent();
|
|
311
|
+
let resolve;
|
|
312
|
+
const result = new Promise((r) => resolve = r);
|
|
313
|
+
const session = {
|
|
314
|
+
kind: "offer",
|
|
315
|
+
options,
|
|
316
|
+
ended: false,
|
|
317
|
+
resolve
|
|
318
|
+
};
|
|
319
|
+
this.session = session;
|
|
320
|
+
const ov = this.ensureOverlay();
|
|
321
|
+
const corner = options.placement === "corner";
|
|
322
|
+
ov.variant.set(this.offerVariant(options));
|
|
323
|
+
ov.view.set({
|
|
324
|
+
kicker: options.kicker,
|
|
325
|
+
title: options.title,
|
|
326
|
+
body: options.body,
|
|
327
|
+
secondary: options.labels.dismiss,
|
|
328
|
+
primary: options.labels.accept
|
|
329
|
+
});
|
|
330
|
+
ov.dim.set(corner ? "none" : "full");
|
|
331
|
+
ov.holeVisible.set(false);
|
|
332
|
+
ov.gliding.set(false);
|
|
333
|
+
ov.cardPos.set(null);
|
|
334
|
+
ov.cardVisible.set(true);
|
|
335
|
+
ov.contentVisible.set(true);
|
|
336
|
+
this.render();
|
|
337
|
+
if (!corner) ov.focusCard();
|
|
338
|
+
return new MnTourOfferRef(result, () => this.answerOffer(session, { status: "closed" }));
|
|
339
|
+
}
|
|
340
|
+
isActive() {
|
|
341
|
+
return this.session !== null;
|
|
342
|
+
}
|
|
343
|
+
isCompactViewport() {
|
|
344
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia(`(max-width: ${COMPACT_MAX_WIDTH}px)`).matches : false;
|
|
345
|
+
}
|
|
346
|
+
prefersReducedMotion() {
|
|
347
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
348
|
+
}
|
|
349
|
+
ngOnDestroy() {
|
|
350
|
+
this.closeCurrent();
|
|
351
|
+
this.destroyOverlay();
|
|
352
|
+
}
|
|
353
|
+
async go(s, to, dir) {
|
|
354
|
+
if (s.busy || s.ended) return;
|
|
355
|
+
s.busy = true;
|
|
356
|
+
try {
|
|
357
|
+
await this.advance(s, to, dir, true);
|
|
358
|
+
} finally {
|
|
359
|
+
s.busy = false;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
async advance(s, to, dir, allowFallback) {
|
|
363
|
+
const steps = s.options.steps;
|
|
364
|
+
const ov = this.overlay();
|
|
365
|
+
const from = s.index();
|
|
366
|
+
const holeWasVisible = ov.dim() === "hole" && ov.holeVisible();
|
|
367
|
+
let left = false;
|
|
368
|
+
let i = to;
|
|
369
|
+
while (i >= 0 && i < steps.length) {
|
|
370
|
+
const step = steps[i];
|
|
371
|
+
const glide = holeWasVisible && !left && !!step.target && !step.before;
|
|
372
|
+
if (!left) {
|
|
373
|
+
left = true;
|
|
374
|
+
this.stopTracking();
|
|
375
|
+
ov.contentVisible.set(false);
|
|
376
|
+
if (glide) await this.wait(MN_TOUR_MOTION.contentFadeMs);
|
|
377
|
+
else await this.fadeOut();
|
|
378
|
+
await this.runAfter(s);
|
|
379
|
+
} else await this.fadeOut();
|
|
380
|
+
if (s.ended) return;
|
|
381
|
+
s.pendingAfter = i;
|
|
382
|
+
if (step.before) {
|
|
383
|
+
try {
|
|
384
|
+
await step.before();
|
|
385
|
+
} catch {
|
|
386
|
+
this.markMissing(s, i, "before-failed");
|
|
387
|
+
await this.runAfter(s);
|
|
388
|
+
i += dir;
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
if (s.ended) return;
|
|
392
|
+
}
|
|
393
|
+
let target = null;
|
|
394
|
+
if (step.target) {
|
|
395
|
+
target = await waitForTourTarget(step.target, s.options.targetTimeoutMs ?? DEFAULT_TARGET_TIMEOUT_MS, () => s.ended);
|
|
396
|
+
if (s.ended) return;
|
|
397
|
+
if (!target) {
|
|
398
|
+
this.markMissing(s, i, "target-not-found");
|
|
399
|
+
await this.runAfter(s);
|
|
400
|
+
i += dir;
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
await this.present(s, i, target, glide && i === to);
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
if (dir === -1 && from >= 0 && allowFallback) return this.advance(s, from, 1, false);
|
|
408
|
+
await this.endTour(s, s.index() >= 0 ? {
|
|
409
|
+
status: "completed",
|
|
410
|
+
step: s.index(),
|
|
411
|
+
startNext: false
|
|
412
|
+
} : {
|
|
413
|
+
status: "closed",
|
|
414
|
+
step: -1
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
async present(s, i, target, glide) {
|
|
418
|
+
const ov = this.overlay();
|
|
419
|
+
const reduced = this.prefersReducedMotion();
|
|
420
|
+
s.index.set(i);
|
|
421
|
+
s.pendingAfter = i;
|
|
422
|
+
s.target = target;
|
|
423
|
+
const variant = this.stepVariant(target);
|
|
424
|
+
ov.reducedMotion.set(reduced);
|
|
425
|
+
ov.variant.set(variant);
|
|
426
|
+
ov.view.set(this.stepView(s, i));
|
|
427
|
+
ov.dim.set(target ? "hole" : "full");
|
|
428
|
+
this.render();
|
|
429
|
+
if (target) this.scrollIntoView(target, variant === "sheet");
|
|
430
|
+
ov.gliding.set(glide && !reduced);
|
|
431
|
+
this.place(target);
|
|
432
|
+
ov.holeVisible.set(!!target);
|
|
433
|
+
ov.cardVisible.set(true);
|
|
434
|
+
ov.contentVisible.set(true);
|
|
435
|
+
this.render();
|
|
436
|
+
if (!ov.hasFocus()) ov.focusCard();
|
|
437
|
+
this.startTracking(target);
|
|
438
|
+
if (glide && !reduced) {
|
|
439
|
+
await this.wait(MN_TOUR_MOTION.glideMs);
|
|
440
|
+
if (this.session === s) ov.gliding.set(false);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
place(target) {
|
|
444
|
+
const ov = this.overlay();
|
|
445
|
+
if (target) ov.hole.set(padBox(target.getBoundingClientRect()));
|
|
446
|
+
const hole = ov.hole();
|
|
447
|
+
const size = ov.cardSize();
|
|
448
|
+
if (ov.variant() === "beside" && hole && size) ov.cardPos.set(placeBeside(hole, size, {
|
|
449
|
+
width: window.innerWidth,
|
|
450
|
+
height: window.innerHeight
|
|
451
|
+
}));
|
|
452
|
+
else ov.cardPos.set(null);
|
|
453
|
+
}
|
|
454
|
+
async fadeOut() {
|
|
455
|
+
const ov = this.overlay();
|
|
456
|
+
const holeVisible = ov.dim() === "hole" && ov.holeVisible();
|
|
457
|
+
const dimVisible = ov.dim() === "full";
|
|
458
|
+
const fadeCard = ov.cardVisible() && ov.variant() !== "sheet";
|
|
459
|
+
if (!holeVisible && !dimVisible && !fadeCard) return;
|
|
460
|
+
ov.gliding.set(false);
|
|
461
|
+
ov.holeVisible.set(false);
|
|
462
|
+
if (dimVisible) ov.dim.set("hole");
|
|
463
|
+
if (fadeCard) ov.cardVisible.set(false);
|
|
464
|
+
await this.wait(MN_TOUR_MOTION.fadeOutMs);
|
|
465
|
+
}
|
|
466
|
+
async endTour(s, outcome) {
|
|
467
|
+
if (s.ended) return;
|
|
468
|
+
s.ended = true;
|
|
469
|
+
if (this.session === s) {
|
|
470
|
+
this.session = null;
|
|
471
|
+
this.stopTracking();
|
|
472
|
+
}
|
|
473
|
+
await this.runAfter(s);
|
|
474
|
+
s.resolve(outcome);
|
|
475
|
+
this.scheduleTeardown();
|
|
476
|
+
}
|
|
477
|
+
answerOffer(s, outcome) {
|
|
478
|
+
if (s.ended) return;
|
|
479
|
+
s.ended = true;
|
|
480
|
+
if (this.session === s) this.session = null;
|
|
481
|
+
s.resolve(outcome);
|
|
482
|
+
this.scheduleTeardown();
|
|
483
|
+
}
|
|
484
|
+
closeCurrent() {
|
|
485
|
+
const s = this.session;
|
|
486
|
+
if (!s) return;
|
|
487
|
+
if (s.kind === "tour") this.endTour(s, {
|
|
488
|
+
status: "closed",
|
|
489
|
+
step: s.index()
|
|
490
|
+
});
|
|
491
|
+
else this.answerOffer(s, { status: "closed" });
|
|
492
|
+
}
|
|
493
|
+
async runAfter(s) {
|
|
494
|
+
const i = s.pendingAfter;
|
|
495
|
+
s.pendingAfter = -1;
|
|
496
|
+
const after = i >= 0 ? s.options.steps[i].after : void 0;
|
|
497
|
+
if (!after) return;
|
|
498
|
+
try {
|
|
499
|
+
await after();
|
|
500
|
+
} catch {}
|
|
501
|
+
}
|
|
502
|
+
markMissing(s, i, reason) {
|
|
503
|
+
s.missing.add(i);
|
|
504
|
+
s.options.onStepMissing?.(i, s.options.steps[i], reason);
|
|
505
|
+
}
|
|
506
|
+
onAction(action) {
|
|
507
|
+
const s = this.session;
|
|
508
|
+
if (!s) return;
|
|
509
|
+
if (s.kind === "offer") {
|
|
510
|
+
if (action === "primary") this.answerOffer(s, { status: "accepted" });
|
|
511
|
+
else if (action === "secondary") this.answerOffer(s, { status: "dismissed" });
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
const i = s.index();
|
|
515
|
+
if (i < 0) return;
|
|
516
|
+
if (action === "skip") {
|
|
517
|
+
this.endTour(s, {
|
|
518
|
+
status: "skipped",
|
|
519
|
+
step: i
|
|
520
|
+
});
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
if (s.busy) return;
|
|
524
|
+
const last = this.isLastStep(s, i);
|
|
525
|
+
if (action === "primary") {
|
|
526
|
+
if (last) this.endTour(s, {
|
|
527
|
+
status: "completed",
|
|
528
|
+
step: i,
|
|
529
|
+
startNext: !!s.options.nextTour
|
|
530
|
+
});
|
|
531
|
+
else this.go(s, i + 1, 1);
|
|
532
|
+
} else if (last && s.options.nextTour) this.endTour(s, {
|
|
533
|
+
status: "completed",
|
|
534
|
+
step: i,
|
|
535
|
+
startNext: false
|
|
536
|
+
});
|
|
537
|
+
else if (this.hasPrevious(s, i)) this.go(s, i - 1, -1);
|
|
538
|
+
}
|
|
539
|
+
handleKey(event) {
|
|
540
|
+
const s = this.session;
|
|
541
|
+
const ov = this.overlayRef?.instance;
|
|
542
|
+
if (!s || !ov || event.defaultPrevented || event.isComposing) return;
|
|
543
|
+
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
|
544
|
+
if (event.key === "Tab") {
|
|
545
|
+
if (ov.dim() !== "none") ov.trapTab(event);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
if (s.kind === "offer") {
|
|
549
|
+
const inScope = s.options.placement === "centred" || ov.hasFocus();
|
|
550
|
+
if (event.key === "Escape" && inScope) {
|
|
551
|
+
event.preventDefault();
|
|
552
|
+
this.answerOffer(s, { status: "dismissed" });
|
|
553
|
+
}
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
if (event.key === "Escape") {
|
|
557
|
+
event.preventDefault();
|
|
558
|
+
this.onAction("skip");
|
|
559
|
+
} else if (event.key === "ArrowRight") {
|
|
560
|
+
event.preventDefault();
|
|
561
|
+
this.onAction("primary");
|
|
562
|
+
} else if (event.key === "ArrowLeft") {
|
|
563
|
+
event.preventDefault();
|
|
564
|
+
if (!(this.isLastStep(s, s.index()) && s.options.nextTour)) this.onAction("secondary");
|
|
565
|
+
} else if (event.key === "Enter") {
|
|
566
|
+
if (event.target?.closest?.("button, a, input, textarea, select")) return;
|
|
567
|
+
event.preventDefault();
|
|
568
|
+
this.onAction("primary");
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
isLastStep(s, i) {
|
|
572
|
+
return i === s.options.steps.length - 1;
|
|
573
|
+
}
|
|
574
|
+
hasPrevious(s, i) {
|
|
575
|
+
for (let j = i - 1; j >= 0; j--) if (!s.missing.has(j)) return true;
|
|
576
|
+
return false;
|
|
577
|
+
}
|
|
578
|
+
stepView(s, i) {
|
|
579
|
+
const { steps, labels, nextTour } = s.options;
|
|
580
|
+
const step = steps[i];
|
|
581
|
+
const last = this.isLastStep(s, i);
|
|
582
|
+
const total = steps.length - s.missing.size;
|
|
583
|
+
let active = i;
|
|
584
|
+
for (const m of s.missing) if (m < i) active--;
|
|
585
|
+
const withNext = last && !!nextTour;
|
|
586
|
+
return {
|
|
587
|
+
kicker: step.kicker,
|
|
588
|
+
title: step.title,
|
|
589
|
+
body: step.body,
|
|
590
|
+
nextTour: withNext ? nextTour : void 0,
|
|
591
|
+
skip: last ? void 0 : labels.skip,
|
|
592
|
+
secondary: withNext ? labels.close : this.hasPrevious(s, i) ? labels.previous : void 0,
|
|
593
|
+
primary: withNext ? labels.startNext : last ? labels.done : labels.next,
|
|
594
|
+
progress: total > 1 ? {
|
|
595
|
+
total,
|
|
596
|
+
active,
|
|
597
|
+
label: labels.stepLabel(active + 1, total)
|
|
598
|
+
} : void 0
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
stepVariant(target) {
|
|
602
|
+
if (this.isCompactViewport()) return "sheet";
|
|
603
|
+
return target ? "beside" : "centred";
|
|
604
|
+
}
|
|
605
|
+
offerVariant(options) {
|
|
606
|
+
if (options.placement === "corner") return "corner";
|
|
607
|
+
return this.isCompactViewport() ? "sheet" : "centred";
|
|
608
|
+
}
|
|
609
|
+
scrollIntoView(target, sheet) {
|
|
610
|
+
const bottomReserve = SCROLL_MARGIN + (sheet ? this.overlay().cardSize()?.height ?? 0 : 0);
|
|
611
|
+
const rect = target.getBoundingClientRect();
|
|
612
|
+
if (rect.top >= SCROLL_MARGIN && rect.bottom <= window.innerHeight - bottomReserve) return;
|
|
613
|
+
const { scrollMarginTop, scrollMarginBottom } = target.style;
|
|
614
|
+
target.style.scrollMarginTop = `${SCROLL_MARGIN}px`;
|
|
615
|
+
target.style.scrollMarginBottom = `${bottomReserve}px`;
|
|
616
|
+
target.scrollIntoView({
|
|
617
|
+
block: sheet ? "nearest" : "center",
|
|
618
|
+
inline: "nearest",
|
|
619
|
+
behavior: "instant"
|
|
620
|
+
});
|
|
621
|
+
target.style.scrollMarginTop = scrollMarginTop;
|
|
622
|
+
target.style.scrollMarginBottom = scrollMarginBottom;
|
|
623
|
+
}
|
|
624
|
+
startTracking(target) {
|
|
625
|
+
this.stopTracking();
|
|
626
|
+
if (!target) return;
|
|
627
|
+
let frame = 0;
|
|
628
|
+
const update = () => {
|
|
629
|
+
if (frame) return;
|
|
630
|
+
frame = requestAnimationFrame(() => {
|
|
631
|
+
frame = 0;
|
|
632
|
+
this.reposition();
|
|
633
|
+
});
|
|
634
|
+
};
|
|
635
|
+
document.addEventListener("scroll", update, {
|
|
636
|
+
capture: true,
|
|
637
|
+
passive: true
|
|
638
|
+
});
|
|
639
|
+
const observer = typeof ResizeObserver === "function" ? new ResizeObserver(update) : null;
|
|
640
|
+
observer?.observe(target);
|
|
641
|
+
this.stopTrackingFn = () => {
|
|
642
|
+
document.removeEventListener("scroll", update, { capture: true });
|
|
643
|
+
observer?.disconnect();
|
|
644
|
+
if (frame) cancelAnimationFrame(frame);
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
stopTracking() {
|
|
648
|
+
this.stopTrackingFn?.();
|
|
649
|
+
this.stopTrackingFn = null;
|
|
650
|
+
}
|
|
651
|
+
reposition() {
|
|
652
|
+
const s = this.session;
|
|
653
|
+
const ov = this.overlayRef?.instance;
|
|
654
|
+
if (!s || !ov) return;
|
|
655
|
+
if (s.kind === "offer") {
|
|
656
|
+
ov.variant.set(this.offerVariant(s.options));
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
if (s.busy && !ov.gliding()) return;
|
|
660
|
+
const target = s.target;
|
|
661
|
+
if (target && !target.isConnected) {
|
|
662
|
+
ov.holeVisible.set(false);
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
const variant = this.stepVariant(target);
|
|
666
|
+
const moved = !target || boxChanged(ov.hole(), padBox(target.getBoundingClientRect()));
|
|
667
|
+
if (variant === ov.variant() && !moved && variant !== "beside") return;
|
|
668
|
+
ov.variant.set(variant);
|
|
669
|
+
this.render();
|
|
670
|
+
this.place(target);
|
|
671
|
+
}
|
|
672
|
+
ensureOverlay() {
|
|
673
|
+
if (this.teardownTimer) {
|
|
674
|
+
clearTimeout(this.teardownTimer);
|
|
675
|
+
this.teardownTimer = null;
|
|
676
|
+
}
|
|
677
|
+
if (this.overlayRef) return this.overlayRef.instance;
|
|
678
|
+
const active = document.activeElement;
|
|
679
|
+
this.returnFocus = active instanceof HTMLElement && active !== document.body ? active : null;
|
|
680
|
+
const ref = createComponent(MnTourOverlay, { environmentInjector: this.injector });
|
|
681
|
+
ref.instance.reducedMotion.set(this.prefersReducedMotion());
|
|
682
|
+
ref.instance.action.subscribe((action) => this.onAction(action));
|
|
683
|
+
this.appRef.attachView(ref.hostView);
|
|
684
|
+
document.body.appendChild(ref.location.nativeElement);
|
|
685
|
+
document.addEventListener("keydown", this.onKeyDown, true);
|
|
686
|
+
window.addEventListener("resize", this.onResize);
|
|
687
|
+
this.overlayRef = ref;
|
|
688
|
+
return ref.instance;
|
|
689
|
+
}
|
|
690
|
+
overlay() {
|
|
691
|
+
return this.overlayRef?.instance ?? this.ensureOverlay();
|
|
692
|
+
}
|
|
693
|
+
scheduleTeardown() {
|
|
694
|
+
if (this.teardownTimer) clearTimeout(this.teardownTimer);
|
|
695
|
+
this.teardownTimer = setTimeout(() => {
|
|
696
|
+
this.teardownTimer = null;
|
|
697
|
+
const ov = this.overlayRef?.instance;
|
|
698
|
+
if (this.session || !ov) return;
|
|
699
|
+
ov.gliding.set(false);
|
|
700
|
+
ov.contentVisible.set(false);
|
|
701
|
+
ov.holeVisible.set(false);
|
|
702
|
+
ov.cardVisible.set(false);
|
|
703
|
+
if (ov.dim() === "full") ov.dim.set("hole");
|
|
704
|
+
const delay = this.prefersReducedMotion() ? 0 : MN_TOUR_MOTION.fadeOutMs;
|
|
705
|
+
this.teardownTimer = setTimeout(() => {
|
|
706
|
+
this.teardownTimer = null;
|
|
707
|
+
if (!this.session) this.destroyOverlay();
|
|
708
|
+
}, delay);
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
destroyOverlay() {
|
|
712
|
+
if (this.teardownTimer) {
|
|
713
|
+
clearTimeout(this.teardownTimer);
|
|
714
|
+
this.teardownTimer = null;
|
|
715
|
+
}
|
|
716
|
+
this.stopTracking();
|
|
717
|
+
const ref = this.overlayRef;
|
|
718
|
+
if (!ref) return;
|
|
719
|
+
const hadFocus = ref.instance.hasFocus();
|
|
720
|
+
this.overlayRef = null;
|
|
721
|
+
document.removeEventListener("keydown", this.onKeyDown, true);
|
|
722
|
+
window.removeEventListener("resize", this.onResize);
|
|
723
|
+
this.appRef.detachView(ref.hostView);
|
|
724
|
+
ref.destroy();
|
|
725
|
+
ref.location.nativeElement.remove();
|
|
726
|
+
const back = this.returnFocus;
|
|
727
|
+
this.returnFocus = null;
|
|
728
|
+
if (back?.isConnected && (hadFocus || document.activeElement === document.body)) back.focus({ preventScroll: true });
|
|
729
|
+
}
|
|
730
|
+
render() {
|
|
731
|
+
this.overlayRef?.changeDetectorRef.detectChanges();
|
|
732
|
+
}
|
|
733
|
+
wait(ms) {
|
|
734
|
+
if (ms <= 0 || this.prefersReducedMotion()) return Promise.resolve();
|
|
735
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
736
|
+
}
|
|
737
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
738
|
+
minVersion: "12.0.0",
|
|
739
|
+
version: "22.2.4",
|
|
740
|
+
ngImport: i0,
|
|
741
|
+
type: MnTourService,
|
|
742
|
+
deps: [],
|
|
743
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
744
|
+
});
|
|
745
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
746
|
+
minVersion: "12.0.0",
|
|
747
|
+
version: "22.2.4",
|
|
748
|
+
ngImport: i0,
|
|
749
|
+
type: MnTourService,
|
|
750
|
+
providedIn: "root"
|
|
751
|
+
});
|
|
752
|
+
};
|
|
753
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
754
|
+
minVersion: "12.0.0",
|
|
755
|
+
version: "22.2.4",
|
|
756
|
+
ngImport: i0,
|
|
757
|
+
type: MnTourService,
|
|
758
|
+
decorators: [{
|
|
759
|
+
type: Injectable,
|
|
760
|
+
args: [{ providedIn: "root" }]
|
|
761
|
+
}]
|
|
762
|
+
});
|
|
763
|
+
export { MN_TOUR_MOTION, MnTourOfferRef, MnTourRef, MnTourService };
|
|
764
|
+
|
|
765
|
+
//# sourceMappingURL=mn-angular-lib-tour.mjs.map
|