mn-angular-lib 2.0.60 → 2.0.62

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.
@@ -0,0 +1,775 @@
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.link) {\n <button\n (click)=\"action.emit('link')\"\n class=\"mn-tour-link mt-2 inline-flex items-center gap-1 rounded text-left text-sm font-medium text-primary hover:underline underline-offset-2 cursor-pointer\"\n type=\"button\"\n >{{ v.link }}<span aria-hidden=\"true\">&rarr;</span></button>\n }\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,.mn-tour-link: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.link) {\n <button\n (click)=\"action.emit('link')\"\n class=\"mn-tour-link mt-2 inline-flex items-center gap-1 rounded text-left text-sm font-medium text-primary hover:underline underline-offset-2 cursor-pointer\"\n type=\"button\"\n >{{ v.link }}<span aria-hidden=\"true\">&rarr;</span></button>\n }\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,.mn-tour-link: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 === "link") {
526
+ const link = s.options.finalLink;
527
+ if (last && link) this.endTour(s, {
528
+ status: "completed",
529
+ step: i,
530
+ startNext: false
531
+ }).then(() => link.run());
532
+ return;
533
+ }
534
+ if (action === "primary") {
535
+ if (last) this.endTour(s, {
536
+ status: "completed",
537
+ step: i,
538
+ startNext: !!s.options.nextTour
539
+ });
540
+ else this.go(s, i + 1, 1);
541
+ } else if (last && s.options.nextTour) this.endTour(s, {
542
+ status: "completed",
543
+ step: i,
544
+ startNext: false
545
+ });
546
+ else if (this.hasPrevious(s, i)) this.go(s, i - 1, -1);
547
+ }
548
+ handleKey(event) {
549
+ const s = this.session;
550
+ const ov = this.overlayRef?.instance;
551
+ if (!s || !ov || event.defaultPrevented || event.isComposing) return;
552
+ if (event.altKey || event.ctrlKey || event.metaKey) return;
553
+ if (event.key === "Tab") {
554
+ if (ov.dim() !== "none") ov.trapTab(event);
555
+ return;
556
+ }
557
+ if (s.kind === "offer") {
558
+ const inScope = s.options.placement === "centred" || ov.hasFocus();
559
+ if (event.key === "Escape" && inScope) {
560
+ event.preventDefault();
561
+ this.answerOffer(s, { status: "dismissed" });
562
+ }
563
+ return;
564
+ }
565
+ if (event.key === "Escape") {
566
+ event.preventDefault();
567
+ this.onAction("skip");
568
+ } else if (event.key === "ArrowRight") {
569
+ event.preventDefault();
570
+ this.onAction("primary");
571
+ } else if (event.key === "ArrowLeft") {
572
+ event.preventDefault();
573
+ if (!(this.isLastStep(s, s.index()) && s.options.nextTour)) this.onAction("secondary");
574
+ } else if (event.key === "Enter") {
575
+ if (event.target?.closest?.("button, a, input, textarea, select")) return;
576
+ event.preventDefault();
577
+ this.onAction("primary");
578
+ }
579
+ }
580
+ isLastStep(s, i) {
581
+ return i === s.options.steps.length - 1;
582
+ }
583
+ hasPrevious(s, i) {
584
+ for (let j = i - 1; j >= 0; j--) if (!s.missing.has(j)) return true;
585
+ return false;
586
+ }
587
+ stepView(s, i) {
588
+ const { steps, labels, nextTour } = s.options;
589
+ const step = steps[i];
590
+ const last = this.isLastStep(s, i);
591
+ const total = steps.length - s.missing.size;
592
+ let active = i;
593
+ for (const m of s.missing) if (m < i) active--;
594
+ const withNext = last && !!nextTour;
595
+ return {
596
+ kicker: step.kicker,
597
+ title: step.title,
598
+ body: step.body,
599
+ nextTour: withNext ? nextTour : void 0,
600
+ link: last ? s.options.finalLink?.label : void 0,
601
+ skip: last ? void 0 : labels.skip,
602
+ secondary: withNext ? labels.close : this.hasPrevious(s, i) ? labels.previous : void 0,
603
+ primary: withNext ? labels.startNext : last ? labels.done : labels.next,
604
+ progress: total > 1 ? {
605
+ total,
606
+ active,
607
+ label: labels.stepLabel(active + 1, total)
608
+ } : void 0
609
+ };
610
+ }
611
+ stepVariant(target) {
612
+ if (this.isCompactViewport()) return "sheet";
613
+ return target ? "beside" : "centred";
614
+ }
615
+ offerVariant(options) {
616
+ if (options.placement === "corner") return "corner";
617
+ return this.isCompactViewport() ? "sheet" : "centred";
618
+ }
619
+ scrollIntoView(target, sheet) {
620
+ const bottomReserve = SCROLL_MARGIN + (sheet ? this.overlay().cardSize()?.height ?? 0 : 0);
621
+ const rect = target.getBoundingClientRect();
622
+ if (rect.top >= SCROLL_MARGIN && rect.bottom <= window.innerHeight - bottomReserve) return;
623
+ const { scrollMarginTop, scrollMarginBottom } = target.style;
624
+ target.style.scrollMarginTop = `${SCROLL_MARGIN}px`;
625
+ target.style.scrollMarginBottom = `${bottomReserve}px`;
626
+ target.scrollIntoView({
627
+ block: sheet ? "nearest" : "center",
628
+ inline: "nearest",
629
+ behavior: "instant"
630
+ });
631
+ target.style.scrollMarginTop = scrollMarginTop;
632
+ target.style.scrollMarginBottom = scrollMarginBottom;
633
+ }
634
+ startTracking(target) {
635
+ this.stopTracking();
636
+ if (!target) return;
637
+ let frame = 0;
638
+ const update = () => {
639
+ if (frame) return;
640
+ frame = requestAnimationFrame(() => {
641
+ frame = 0;
642
+ this.reposition();
643
+ });
644
+ };
645
+ document.addEventListener("scroll", update, {
646
+ capture: true,
647
+ passive: true
648
+ });
649
+ const observer = typeof ResizeObserver === "function" ? new ResizeObserver(update) : null;
650
+ observer?.observe(target);
651
+ this.stopTrackingFn = () => {
652
+ document.removeEventListener("scroll", update, { capture: true });
653
+ observer?.disconnect();
654
+ if (frame) cancelAnimationFrame(frame);
655
+ };
656
+ }
657
+ stopTracking() {
658
+ this.stopTrackingFn?.();
659
+ this.stopTrackingFn = null;
660
+ }
661
+ reposition() {
662
+ const s = this.session;
663
+ const ov = this.overlayRef?.instance;
664
+ if (!s || !ov) return;
665
+ if (s.kind === "offer") {
666
+ ov.variant.set(this.offerVariant(s.options));
667
+ return;
668
+ }
669
+ if (s.busy && !ov.gliding()) return;
670
+ const target = s.target;
671
+ if (target && !target.isConnected) {
672
+ ov.holeVisible.set(false);
673
+ return;
674
+ }
675
+ const variant = this.stepVariant(target);
676
+ const moved = !target || boxChanged(ov.hole(), padBox(target.getBoundingClientRect()));
677
+ if (variant === ov.variant() && !moved && variant !== "beside") return;
678
+ ov.variant.set(variant);
679
+ this.render();
680
+ this.place(target);
681
+ }
682
+ ensureOverlay() {
683
+ if (this.teardownTimer) {
684
+ clearTimeout(this.teardownTimer);
685
+ this.teardownTimer = null;
686
+ }
687
+ if (this.overlayRef) return this.overlayRef.instance;
688
+ const active = document.activeElement;
689
+ this.returnFocus = active instanceof HTMLElement && active !== document.body ? active : null;
690
+ const ref = createComponent(MnTourOverlay, { environmentInjector: this.injector });
691
+ ref.instance.reducedMotion.set(this.prefersReducedMotion());
692
+ ref.instance.action.subscribe((action) => this.onAction(action));
693
+ this.appRef.attachView(ref.hostView);
694
+ document.body.appendChild(ref.location.nativeElement);
695
+ document.addEventListener("keydown", this.onKeyDown, true);
696
+ window.addEventListener("resize", this.onResize);
697
+ this.overlayRef = ref;
698
+ return ref.instance;
699
+ }
700
+ overlay() {
701
+ return this.overlayRef?.instance ?? this.ensureOverlay();
702
+ }
703
+ scheduleTeardown() {
704
+ if (this.teardownTimer) clearTimeout(this.teardownTimer);
705
+ this.teardownTimer = setTimeout(() => {
706
+ this.teardownTimer = null;
707
+ const ov = this.overlayRef?.instance;
708
+ if (this.session || !ov) return;
709
+ ov.gliding.set(false);
710
+ ov.contentVisible.set(false);
711
+ ov.holeVisible.set(false);
712
+ ov.cardVisible.set(false);
713
+ if (ov.dim() === "full") ov.dim.set("hole");
714
+ const delay = this.prefersReducedMotion() ? 0 : MN_TOUR_MOTION.fadeOutMs;
715
+ this.teardownTimer = setTimeout(() => {
716
+ this.teardownTimer = null;
717
+ if (!this.session) this.destroyOverlay();
718
+ }, delay);
719
+ });
720
+ }
721
+ destroyOverlay() {
722
+ if (this.teardownTimer) {
723
+ clearTimeout(this.teardownTimer);
724
+ this.teardownTimer = null;
725
+ }
726
+ this.stopTracking();
727
+ const ref = this.overlayRef;
728
+ if (!ref) return;
729
+ const hadFocus = ref.instance.hasFocus();
730
+ this.overlayRef = null;
731
+ document.removeEventListener("keydown", this.onKeyDown, true);
732
+ window.removeEventListener("resize", this.onResize);
733
+ this.appRef.detachView(ref.hostView);
734
+ ref.destroy();
735
+ ref.location.nativeElement.remove();
736
+ const back = this.returnFocus;
737
+ this.returnFocus = null;
738
+ if (back?.isConnected && (hadFocus || document.activeElement === document.body)) back.focus({ preventScroll: true });
739
+ }
740
+ render() {
741
+ this.overlayRef?.changeDetectorRef.detectChanges();
742
+ }
743
+ wait(ms) {
744
+ if (ms <= 0 || this.prefersReducedMotion()) return Promise.resolve();
745
+ return new Promise((resolve) => setTimeout(resolve, ms));
746
+ }
747
+ static ɵfac = i0.ɵɵngDeclareFactory({
748
+ minVersion: "12.0.0",
749
+ version: "22.2.4",
750
+ ngImport: i0,
751
+ type: MnTourService,
752
+ deps: [],
753
+ target: i0.ɵɵFactoryTarget.Injectable
754
+ });
755
+ static ɵprov = i0.ɵɵngDeclareInjectable({
756
+ minVersion: "12.0.0",
757
+ version: "22.2.4",
758
+ ngImport: i0,
759
+ type: MnTourService,
760
+ providedIn: "root"
761
+ });
762
+ };
763
+ i0.ɵɵngDeclareClassMetadata({
764
+ minVersion: "12.0.0",
765
+ version: "22.2.4",
766
+ ngImport: i0,
767
+ type: MnTourService,
768
+ decorators: [{
769
+ type: Injectable,
770
+ args: [{ providedIn: "root" }]
771
+ }]
772
+ });
773
+ export { MN_TOUR_MOTION, MnTourOfferRef, MnTourRef, MnTourService };
774
+
775
+ //# sourceMappingURL=mn-angular-lib-tour.mjs.map