siteguide.js 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css/siteguide.css +70 -0
- package/dist/index.d.ts +106 -110
- package/dist/index.js +194 -0
- package/dist/index.mjs +192 -159
- package/package.json +11 -5
- package/dist/index.cjs +0 -1
- package/dist/styles/siteguide.css +0 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
.overview {
|
|
2
|
+
width: 300px;
|
|
3
|
+
height: fit-content;
|
|
4
|
+
background: #fff;
|
|
5
|
+
border-radius: 4px;
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-direction: column;
|
|
8
|
+
align-items: center;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
position: relative;
|
|
11
|
+
z-index: 1000001;
|
|
12
|
+
transition: all 0.3s ease-out;
|
|
13
|
+
}
|
|
14
|
+
.overview-helper {
|
|
15
|
+
box-shadow:
|
|
16
|
+
0 0 #212121cc,
|
|
17
|
+
0 0 0 5000px #21212180;
|
|
18
|
+
border: 2px dashed rgba(33, 33, 33, 0.8);
|
|
19
|
+
border-radius: 4px;
|
|
20
|
+
opacity: 1;
|
|
21
|
+
z-index: 1000000;
|
|
22
|
+
box-sizing: border-box;
|
|
23
|
+
position: absolute;
|
|
24
|
+
transition: all 0.3s ease-out;
|
|
25
|
+
}
|
|
26
|
+
.overview-content {
|
|
27
|
+
width: 100%;
|
|
28
|
+
display: flex;
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
}
|
|
31
|
+
.overview-title {
|
|
32
|
+
font-size: 20px;
|
|
33
|
+
font-weight: 700;
|
|
34
|
+
color: #1b1b1b;
|
|
35
|
+
}
|
|
36
|
+
.overview-description {
|
|
37
|
+
font-weight: 100;
|
|
38
|
+
color: #666;
|
|
39
|
+
}
|
|
40
|
+
.overview-button-list {
|
|
41
|
+
width: 100%;
|
|
42
|
+
display: flex;
|
|
43
|
+
align-items: center;
|
|
44
|
+
justify-content: center;
|
|
45
|
+
}
|
|
46
|
+
.overview-button {
|
|
47
|
+
width: 50%;
|
|
48
|
+
height: 35px;
|
|
49
|
+
border-radius: 10px;
|
|
50
|
+
border: none;
|
|
51
|
+
cursor: pointer;
|
|
52
|
+
font-weight: 600;
|
|
53
|
+
}
|
|
54
|
+
.exit-button {
|
|
55
|
+
display: flex;
|
|
56
|
+
align-items: center;
|
|
57
|
+
justify-content: center;
|
|
58
|
+
border: none;
|
|
59
|
+
background-color: transparent;
|
|
60
|
+
position: absolute;
|
|
61
|
+
top: 20px;
|
|
62
|
+
right: 20px;
|
|
63
|
+
cursor: pointer;
|
|
64
|
+
}
|
|
65
|
+
.exit-button:hover svg {
|
|
66
|
+
fill: #000;
|
|
67
|
+
}
|
|
68
|
+
.exit-button svg {
|
|
69
|
+
fill: #afafaf;
|
|
70
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,110 +1,106 @@
|
|
|
1
|
-
export declare type ButtonConfig = {
|
|
2
|
-
title: string;
|
|
3
|
-
className?: string;
|
|
4
|
-
action: () => void | (() => Promise<void>);
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Creates an HTML element with the specified tag name and applies the given class list.
|
|
9
|
-
* @template T
|
|
10
|
-
* @param {T} tagName - The name of the HTML tag to create.
|
|
11
|
-
* @param {string[]} [classList] - An array of class names to add to the created element.
|
|
12
|
-
* @returns {HTMLElementTagNameMap[T]} The created HTML element with the specified tag name and class list.
|
|
13
|
-
*/
|
|
14
|
-
export declare function createElement<T extends keyof HTMLElementTagNameMap>(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export declare
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export declare type
|
|
42
|
-
|
|
43
|
-
export declare type
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
private
|
|
68
|
-
private
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
popup: PopupData;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export { }
|
|
1
|
+
export declare type ButtonConfig = {
|
|
2
|
+
title: string;
|
|
3
|
+
className?: string;
|
|
4
|
+
action: () => void | (() => Promise<void>);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Creates an HTML element with the specified tag name and applies the given class list.
|
|
9
|
+
* @template T
|
|
10
|
+
* @param {T} tagName - The name of the HTML tag to create.
|
|
11
|
+
* @param {string[]} [classList] - An array of class names to add to the created element.
|
|
12
|
+
* @returns {HTMLElementTagNameMap[T]} The created HTML element with the specified tag name and class list.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createElement<T extends keyof HTMLElementTagNameMap>(
|
|
15
|
+
tagName: T,
|
|
16
|
+
classList?: string[]
|
|
17
|
+
): HTMLElementTagNameMap[T];
|
|
18
|
+
|
|
19
|
+
export declare type CustomPopupData = SharedPopupData & {
|
|
20
|
+
type: Extract<PopupType, 'custom'>;
|
|
21
|
+
node: HTMLElement;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export declare type DefaultPopupData = SharedPopupData & {
|
|
25
|
+
type: Extract<PopupType, 'default'>;
|
|
26
|
+
title: string;
|
|
27
|
+
text: string;
|
|
28
|
+
buttonCollection: ButtonConfig[];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export declare type HostData = string | HTMLElement | (() => HTMLElement | string);
|
|
32
|
+
|
|
33
|
+
declare interface IUpdatePopup {
|
|
34
|
+
updatePopupView(popupElement: HTMLElement, popupData: PopupData): void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export declare type PopupData = DefaultPopupData | CustomPopupData;
|
|
38
|
+
|
|
39
|
+
export declare type PopupPosition = 'top' | 'bottom' | 'left' | 'right';
|
|
40
|
+
|
|
41
|
+
export declare type PopupType = 'default' | 'custom';
|
|
42
|
+
|
|
43
|
+
export declare type SharedPopupData = {
|
|
44
|
+
className?: string;
|
|
45
|
+
position: PopupPosition;
|
|
46
|
+
buttonCollection: ButtonConfig[];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
declare type StepId = string;
|
|
50
|
+
|
|
51
|
+
export declare class Tour {
|
|
52
|
+
private readonly _config;
|
|
53
|
+
get stepList(): TourStep[];
|
|
54
|
+
get config(): TourConfig;
|
|
55
|
+
get popupElement(): HTMLElement | null;
|
|
56
|
+
get helperElement(): HTMLElement | null;
|
|
57
|
+
/**
|
|
58
|
+
* TODO remove
|
|
59
|
+
* @deprecated remove later
|
|
60
|
+
*/
|
|
61
|
+
isStarted: boolean;
|
|
62
|
+
readonly updatePopupStrategies: Map<PopupType, IUpdatePopup>;
|
|
63
|
+
private _popupElement;
|
|
64
|
+
private _helperElement;
|
|
65
|
+
private readonly _stepMap;
|
|
66
|
+
private _stepList;
|
|
67
|
+
private _currentStep;
|
|
68
|
+
private _bodyResizeObserver;
|
|
69
|
+
constructor(_config: TourConfig);
|
|
70
|
+
addStep(config: TourStepConfig): void;
|
|
71
|
+
removeStep(stepId: StepId): void;
|
|
72
|
+
start(): void;
|
|
73
|
+
complete(): void;
|
|
74
|
+
prev(): void;
|
|
75
|
+
next(): void;
|
|
76
|
+
private setUpStrategies;
|
|
77
|
+
private setUpBodySizeObserver;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export declare type TourConfig = {
|
|
81
|
+
className?: string;
|
|
82
|
+
helperClassName?: string;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export declare class TourStep {
|
|
86
|
+
readonly id: StepId;
|
|
87
|
+
private readonly _hostData;
|
|
88
|
+
private readonly _popupData;
|
|
89
|
+
private readonly _tour;
|
|
90
|
+
private _hostElement;
|
|
91
|
+
constructor(tour: Tour, config: TourStepConfig);
|
|
92
|
+
show(): void;
|
|
93
|
+
hide(): void;
|
|
94
|
+
updatePopupPosition(): void;
|
|
95
|
+
private updatePopup;
|
|
96
|
+
private resolveHostElement;
|
|
97
|
+
private resolvePopupPosition;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export declare type TourStepConfig = {
|
|
101
|
+
id: StepId;
|
|
102
|
+
host: HostData;
|
|
103
|
+
popup: PopupData;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var m = Object.defineProperty;
|
|
3
|
+
var w = (i, t, e) => (t in i ? m(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : (i[t] = e));
|
|
4
|
+
var o = (i, t, e) => w(i, typeof t != 'symbol' ? t + '' : t, e);
|
|
5
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
6
|
+
function n(i, t) {
|
|
7
|
+
const e = document.createElement(i);
|
|
8
|
+
return t && t.length > 0 && ((t = t.filter((s) => s)), e.classList.add(...t)), e;
|
|
9
|
+
}
|
|
10
|
+
function c(i, t) {
|
|
11
|
+
i.innerHTML = '';
|
|
12
|
+
const e = n('div', ['overview-header']);
|
|
13
|
+
i.appendChild(e);
|
|
14
|
+
const s = n('button', ['overview-exit-button']);
|
|
15
|
+
e.appendChild(s);
|
|
16
|
+
const r = n('div', ['overview-content']);
|
|
17
|
+
i.appendChild(r);
|
|
18
|
+
const p = n('div', ['overview-button-list']);
|
|
19
|
+
t.buttonCollection.forEach((h) => {
|
|
20
|
+
var a;
|
|
21
|
+
const l = n('button', ['overview-button', (a = h.className) != null ? a : '']);
|
|
22
|
+
(l.innerText = h.title),
|
|
23
|
+
(l.onclick = () => {
|
|
24
|
+
h.action();
|
|
25
|
+
}),
|
|
26
|
+
p.appendChild(l);
|
|
27
|
+
}),
|
|
28
|
+
i.appendChild(p);
|
|
29
|
+
}
|
|
30
|
+
class f {
|
|
31
|
+
updatePopupView(t, e) {
|
|
32
|
+
c(t, e), t.querySelector('.overview-content').appendChild(e.node);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
class v {
|
|
36
|
+
updatePopupView(t, e) {
|
|
37
|
+
c(t, e);
|
|
38
|
+
const s = t.querySelector('.overview-content');
|
|
39
|
+
this.appendContent(s, 'h2', e.title, ['overview-title']),
|
|
40
|
+
this.appendContent(s, 'p', e.text, ['overview-description']);
|
|
41
|
+
}
|
|
42
|
+
appendContent(t, e, s, r) {
|
|
43
|
+
const p = n(e, r);
|
|
44
|
+
(p.innerText = s), t.appendChild(p);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function E(i) {
|
|
48
|
+
return i === null || typeof i == 'undefined';
|
|
49
|
+
}
|
|
50
|
+
class _ {
|
|
51
|
+
constructor(t, e) {
|
|
52
|
+
o(this, 'id');
|
|
53
|
+
o(this, '_hostData');
|
|
54
|
+
o(this, '_popupData');
|
|
55
|
+
o(this, '_tour');
|
|
56
|
+
o(this, '_hostElement', null);
|
|
57
|
+
(this.id = e.id), (this._hostData = e.host), (this._popupData = e.popup), (this._tour = t);
|
|
58
|
+
}
|
|
59
|
+
show() {
|
|
60
|
+
(this._hostElement = this.resolveHostElement(
|
|
61
|
+
typeof this._hostData == 'function' ? this._hostData() : this._hostData
|
|
62
|
+
)),
|
|
63
|
+
this.updatePopup();
|
|
64
|
+
}
|
|
65
|
+
hide() {}
|
|
66
|
+
updatePopupPosition() {
|
|
67
|
+
const t = this._hostElement.getBoundingClientRect(),
|
|
68
|
+
e = 8,
|
|
69
|
+
s = 4,
|
|
70
|
+
r = this.resolvePopupPosition();
|
|
71
|
+
(this._tour.helperElement.style.position = r),
|
|
72
|
+
(this._tour.helperElement.style.left = `${t.left - e}px`),
|
|
73
|
+
(this._tour.helperElement.style.top = `${t.top - s}px`),
|
|
74
|
+
(this._tour.helperElement.style.width = `${t.width + 2 * e}px`),
|
|
75
|
+
(this._tour.helperElement.style.height = `${t.height + 2 * s}px`),
|
|
76
|
+
(this._tour.popupElement.style.position = r);
|
|
77
|
+
const p = this._tour.popupElement.offsetHeight,
|
|
78
|
+
h = this._tour.popupElement.offsetWidth,
|
|
79
|
+
l = window.innerHeight,
|
|
80
|
+
a = window.innerWidth;
|
|
81
|
+
let u = t.top + window.scrollY - p,
|
|
82
|
+
d = t.left + window.scrollX;
|
|
83
|
+
u < 0 && (u = t.bottom + window.scrollY),
|
|
84
|
+
d + h > a && (d = t.right + window.scrollX - h),
|
|
85
|
+
d < 0 && (d = t.left + window.scrollX),
|
|
86
|
+
u + p > l && (u = t.top + window.scrollY),
|
|
87
|
+
(this._tour.popupElement.style.left = `${d}px`),
|
|
88
|
+
(this._tour.popupElement.style.top = `${u}px`);
|
|
89
|
+
}
|
|
90
|
+
updatePopup() {
|
|
91
|
+
var t;
|
|
92
|
+
if (!this._tour.updatePopupStrategies.has(this._popupData.type))
|
|
93
|
+
throw new Error('Missing popup creator strategy');
|
|
94
|
+
this._tour.updatePopupStrategies
|
|
95
|
+
.get(this._popupData.type)
|
|
96
|
+
.updatePopupView(this._tour.popupElement, this._popupData),
|
|
97
|
+
this.updatePopupPosition(),
|
|
98
|
+
(t = this._hostElement) == null ||
|
|
99
|
+
t.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' });
|
|
100
|
+
}
|
|
101
|
+
resolveHostElement(t) {
|
|
102
|
+
return typeof this._hostData == 'string' ? document.querySelector(this._hostData) : t;
|
|
103
|
+
}
|
|
104
|
+
resolvePopupPosition() {
|
|
105
|
+
var s;
|
|
106
|
+
let t = this.resolveHostElement(typeof this._hostData == 'function' ? this._hostData() : this._hostData),
|
|
107
|
+
e = 'absolute';
|
|
108
|
+
for (; !E(t); )
|
|
109
|
+
(t == null ? void 0 : t.style.position) === 'fixed' && (e = 'fixed'),
|
|
110
|
+
(t = (s = t == null ? void 0 : t.parentElement) != null ? s : null);
|
|
111
|
+
return e;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
class S {
|
|
115
|
+
constructor(t) {
|
|
116
|
+
o(this, 'isStarted', !1);
|
|
117
|
+
o(this, 'updatePopupStrategies', new Map());
|
|
118
|
+
o(this, '_popupElement', null);
|
|
119
|
+
o(this, '_helperElement', null);
|
|
120
|
+
o(this, '_stepMap', new Map());
|
|
121
|
+
o(this, '_stepList', []);
|
|
122
|
+
o(this, '_currentStep', null);
|
|
123
|
+
o(this, '_bodyResizeObserver');
|
|
124
|
+
(this._config = t), this.setUpStrategies(), this.setUpBodySizeObserver();
|
|
125
|
+
}
|
|
126
|
+
get stepList() {
|
|
127
|
+
return [...this._stepList];
|
|
128
|
+
}
|
|
129
|
+
get config() {
|
|
130
|
+
return this._config;
|
|
131
|
+
}
|
|
132
|
+
get popupElement() {
|
|
133
|
+
return this._popupElement;
|
|
134
|
+
}
|
|
135
|
+
get helperElement() {
|
|
136
|
+
return this._helperElement;
|
|
137
|
+
}
|
|
138
|
+
addStep(t) {
|
|
139
|
+
if (this._stepMap.has(t.id)) throw new Error('Step with provided id has been already registered');
|
|
140
|
+
const e = new _(this, t);
|
|
141
|
+
t.popup.buttonCollection.forEach((s) => (s.action = s.action.bind(this))),
|
|
142
|
+
this._stepList.push(e),
|
|
143
|
+
this._stepMap.set(t.id, e);
|
|
144
|
+
}
|
|
145
|
+
removeStep(t) {
|
|
146
|
+
(this._stepList = this._stepList.filter((e) => t !== e.id)), this._stepMap.delete(t);
|
|
147
|
+
}
|
|
148
|
+
start() {
|
|
149
|
+
var t, e;
|
|
150
|
+
(this.isStarted = !0),
|
|
151
|
+
(this._popupElement = n('div', ['overview', (t = this._config.className) != null ? t : ''])),
|
|
152
|
+
document.body.appendChild(this._popupElement),
|
|
153
|
+
(this._helperElement = n('div', ['overview-helper', (e = this._config.helperClassName) != null ? e : ''])),
|
|
154
|
+
document.body.appendChild(this._helperElement),
|
|
155
|
+
this.next();
|
|
156
|
+
}
|
|
157
|
+
complete() {
|
|
158
|
+
(this.isStarted = !1),
|
|
159
|
+
this._popupElement && document.body.removeChild(this._popupElement),
|
|
160
|
+
this._helperElement && document.body.removeChild(this._helperElement);
|
|
161
|
+
}
|
|
162
|
+
prev() {
|
|
163
|
+
var e;
|
|
164
|
+
(e = this._currentStep) == null || e.hide();
|
|
165
|
+
const t = this._stepList.indexOf(this._currentStep) - 1;
|
|
166
|
+
if (t < 0) {
|
|
167
|
+
this.complete();
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
(this._currentStep = this._stepList[t]), this._currentStep.show();
|
|
171
|
+
}
|
|
172
|
+
next() {
|
|
173
|
+
var e;
|
|
174
|
+
const t = this._stepList.indexOf(this._currentStep) + 1;
|
|
175
|
+
if (((e = this._currentStep) == null || e.hide(), t >= this._stepList.length)) {
|
|
176
|
+
this.complete();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
(this._currentStep = this._stepList[t]), this._currentStep.show();
|
|
180
|
+
}
|
|
181
|
+
setUpStrategies() {
|
|
182
|
+
this.updatePopupStrategies.set('default', new v()), this.updatePopupStrategies.set('custom', new f());
|
|
183
|
+
}
|
|
184
|
+
setUpBodySizeObserver() {
|
|
185
|
+
(this._bodyResizeObserver = new ResizeObserver(() => {
|
|
186
|
+
var t;
|
|
187
|
+
this.isStarted && ((t = this._currentStep) == null || t.updatePopupPosition());
|
|
188
|
+
})),
|
|
189
|
+
this._bodyResizeObserver.observe(document.body);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.Tour = S;
|
|
193
|
+
exports.TourStep = _;
|
|
194
|
+
exports.createElement = n;
|
package/dist/index.mjs
CHANGED
|
@@ -1,173 +1,206 @@
|
|
|
1
1
|
var _ = Object.defineProperty;
|
|
2
|
-
var m = (i, t, e) => t in i ? _(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
|
|
3
|
-
var o = (i, t, e) => m(i, typeof t !=
|
|
2
|
+
var m = (i, t, e) => (t in i ? _(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : (i[t] = e));
|
|
3
|
+
var o = (i, t, e) => m(i, typeof t != 'symbol' ? t + '' : t, e);
|
|
4
4
|
function p(i, t) {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const e = document.createElement(i);
|
|
6
|
+
return t && t.length > 0 && ((t = t.filter((s) => s)), e.classList.add(...t)), e;
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
function c(i, t) {
|
|
9
|
+
i.innerHTML = '';
|
|
10
|
+
const e = p('div', ['overview-header']);
|
|
11
|
+
i.appendChild(e);
|
|
12
|
+
const s = p('button', ['overview-exit-button']);
|
|
13
|
+
e.appendChild(s);
|
|
14
|
+
const r = p('div', ['overview-content']);
|
|
15
|
+
i.appendChild(r);
|
|
16
|
+
const n = p('div', ['overview-button-list']);
|
|
17
|
+
t.buttonCollection.forEach((h) => {
|
|
18
|
+
var a;
|
|
19
|
+
const l = p('button', ['overview-button', (a = h.className) != null ? a : '']);
|
|
20
|
+
(l.innerText = h.title),
|
|
21
|
+
(l.onclick = () => {
|
|
22
|
+
h.action();
|
|
23
|
+
}),
|
|
24
|
+
n.appendChild(l);
|
|
25
|
+
}),
|
|
26
|
+
i.appendChild(n);
|
|
23
27
|
}
|
|
24
28
|
class w {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
updatePopupView(t, e) {
|
|
30
|
+
c(t, e), t.querySelector('.overview-content').appendChild(e.node);
|
|
31
|
+
}
|
|
28
32
|
}
|
|
29
33
|
class f {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
34
|
+
updatePopupView(t, e) {
|
|
35
|
+
c(t, e);
|
|
36
|
+
const s = t.querySelector('.overview-content');
|
|
37
|
+
this.appendContent(s, 'h2', e.title, ['overview-title']),
|
|
38
|
+
this.appendContent(s, 'p', e.text, ['overview-description']);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Appends a new HTML element with the specified class list and inner text to the parent element.
|
|
42
|
+
* @param {HTMLElement} parent - The parent element to which the new element will be appended.
|
|
43
|
+
* @param {keyof HTMLElementTagNameMap} tagType - The type of HTML element to create and append.
|
|
44
|
+
* @param {string} innerText - The inner text to set for the new element.
|
|
45
|
+
* @param {string[]} classList - An array of class names to add to the new element.
|
|
46
|
+
* @returns {void}
|
|
47
|
+
*/
|
|
48
|
+
appendContent(t, e, s, r) {
|
|
49
|
+
const n = p(e, r);
|
|
50
|
+
(n.innerText = s), t.appendChild(n);
|
|
51
|
+
}
|
|
47
52
|
}
|
|
48
53
|
function v(i) {
|
|
49
|
-
|
|
54
|
+
return i === null || typeof i == 'undefined';
|
|
50
55
|
}
|
|
51
56
|
class E {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
57
|
+
constructor(t, e) {
|
|
58
|
+
o(this, 'id');
|
|
59
|
+
o(this, '_hostData');
|
|
60
|
+
o(this, '_popupData');
|
|
61
|
+
o(this, '_tour');
|
|
62
|
+
o(this, '_hostElement', null);
|
|
63
|
+
(this.id = e.id), (this._hostData = e.host), (this._popupData = e.popup), (this._tour = t);
|
|
64
|
+
}
|
|
65
|
+
show() {
|
|
66
|
+
(this._hostElement = this.resolveHostElement(
|
|
67
|
+
typeof this._hostData == 'function' ? this._hostData() : this._hostData
|
|
68
|
+
)),
|
|
69
|
+
this.updatePopup();
|
|
70
|
+
}
|
|
71
|
+
hide() {}
|
|
72
|
+
updatePopupPosition() {
|
|
73
|
+
const t = this._hostElement.getBoundingClientRect(),
|
|
74
|
+
e = 8,
|
|
75
|
+
s = 4,
|
|
76
|
+
r = this.resolvePopupPosition();
|
|
77
|
+
(this._tour.helperElement.style.position = r),
|
|
78
|
+
(this._tour.helperElement.style.left = `${t.left - e}px`),
|
|
79
|
+
(this._tour.helperElement.style.top = `${t.top - s}px`),
|
|
80
|
+
(this._tour.helperElement.style.width = `${t.width + 2 * e}px`),
|
|
81
|
+
(this._tour.helperElement.style.height = `${t.height + 2 * s}px`),
|
|
82
|
+
(this._tour.popupElement.style.position = r);
|
|
83
|
+
const n = this._tour.popupElement.offsetHeight,
|
|
84
|
+
h = this._tour.popupElement.offsetWidth,
|
|
85
|
+
l = window.innerHeight,
|
|
86
|
+
a = window.innerWidth;
|
|
87
|
+
let u = t.top + window.scrollY - n,
|
|
88
|
+
d = t.left + window.scrollX;
|
|
89
|
+
u < 0 && (u = t.bottom + window.scrollY),
|
|
90
|
+
d + h > a && (d = t.right + window.scrollX - h),
|
|
91
|
+
d < 0 && (d = t.left + window.scrollX),
|
|
92
|
+
u + n > l && (u = t.top + window.scrollY),
|
|
93
|
+
(this._tour.popupElement.style.left = `${d}px`),
|
|
94
|
+
(this._tour.popupElement.style.top = `${u}px`);
|
|
95
|
+
}
|
|
96
|
+
updatePopup() {
|
|
97
|
+
var t;
|
|
98
|
+
if (!this._tour.updatePopupStrategies.has(this._popupData.type))
|
|
99
|
+
throw new Error('Missing popup creator strategy');
|
|
100
|
+
this._tour.updatePopupStrategies
|
|
101
|
+
.get(this._popupData.type)
|
|
102
|
+
.updatePopupView(this._tour.popupElement, this._popupData),
|
|
103
|
+
this.updatePopupPosition(),
|
|
104
|
+
(t = this._hostElement) == null ||
|
|
105
|
+
t.scrollIntoView({
|
|
106
|
+
behavior: 'smooth',
|
|
107
|
+
block: 'center',
|
|
108
|
+
inline: 'center',
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
resolveHostElement(t) {
|
|
112
|
+
return typeof this._hostData == 'string' ? document.querySelector(this._hostData) : t;
|
|
113
|
+
}
|
|
114
|
+
resolvePopupPosition() {
|
|
115
|
+
var s;
|
|
116
|
+
let t = this.resolveHostElement(typeof this._hostData == 'function' ? this._hostData() : this._hostData),
|
|
117
|
+
e = 'absolute';
|
|
118
|
+
for (; !v(t); )
|
|
119
|
+
(t == null ? void 0 : t.style.position) === 'fixed' && (e = 'fixed'),
|
|
120
|
+
(t = (s = t == null ? void 0 : t.parentElement) != null ? s : null);
|
|
121
|
+
return e;
|
|
122
|
+
}
|
|
95
123
|
}
|
|
96
124
|
class y {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
125
|
+
constructor(t) {
|
|
126
|
+
/**
|
|
127
|
+
* TODO remove
|
|
128
|
+
* @deprecated remove later
|
|
129
|
+
*/
|
|
130
|
+
o(this, 'isStarted', !1);
|
|
131
|
+
o(this, 'updatePopupStrategies', /* @__PURE__ */ new Map());
|
|
132
|
+
o(this, '_popupElement', null);
|
|
133
|
+
o(this, '_helperElement', null);
|
|
134
|
+
o(this, '_stepMap', /* @__PURE__ */ new Map());
|
|
135
|
+
o(this, '_stepList', []);
|
|
136
|
+
o(this, '_currentStep', null);
|
|
137
|
+
o(this, '_bodyResizeObserver');
|
|
138
|
+
(this._config = t), this.setUpStrategies(), this.setUpBodySizeObserver();
|
|
139
|
+
}
|
|
140
|
+
get stepList() {
|
|
141
|
+
return [...this._stepList];
|
|
142
|
+
}
|
|
143
|
+
get config() {
|
|
144
|
+
return this._config;
|
|
145
|
+
}
|
|
146
|
+
get popupElement() {
|
|
147
|
+
return this._popupElement;
|
|
148
|
+
}
|
|
149
|
+
get helperElement() {
|
|
150
|
+
return this._helperElement;
|
|
151
|
+
}
|
|
152
|
+
addStep(t) {
|
|
153
|
+
if (this._stepMap.has(t.id)) throw new Error('Step with provided id has been already registered');
|
|
154
|
+
const e = new E(this, t);
|
|
155
|
+
t.popup.buttonCollection.forEach((s) => (s.action = s.action.bind(this))),
|
|
156
|
+
this._stepList.push(e),
|
|
157
|
+
this._stepMap.set(t.id, e);
|
|
158
|
+
}
|
|
159
|
+
removeStep(t) {
|
|
160
|
+
(this._stepList = this._stepList.filter((e) => t !== e.id)), this._stepMap.delete(t);
|
|
161
|
+
}
|
|
162
|
+
start() {
|
|
163
|
+
var t, e;
|
|
164
|
+
(this.isStarted = !0),
|
|
165
|
+
(this._popupElement = p('div', ['overview', (t = this._config.className) != null ? t : ''])),
|
|
166
|
+
document.body.appendChild(this._popupElement),
|
|
167
|
+
(this._helperElement = p('div', ['overview-helper', (e = this._config.helperClassName) != null ? e : ''])),
|
|
168
|
+
document.body.appendChild(this._helperElement),
|
|
169
|
+
this.next();
|
|
170
|
+
}
|
|
171
|
+
complete() {
|
|
172
|
+
(this.isStarted = !1),
|
|
173
|
+
this._popupElement && document.body.removeChild(this._popupElement),
|
|
174
|
+
this._helperElement && document.body.removeChild(this._helperElement);
|
|
175
|
+
}
|
|
176
|
+
prev() {
|
|
177
|
+
var e;
|
|
178
|
+
(e = this._currentStep) == null || e.hide();
|
|
179
|
+
const t = this._stepList.indexOf(this._currentStep) - 1;
|
|
180
|
+
if (t < 0) {
|
|
181
|
+
this.complete();
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
(this._currentStep = this._stepList[t]), this._currentStep.show();
|
|
185
|
+
}
|
|
186
|
+
next() {
|
|
187
|
+
var e;
|
|
188
|
+
const t = this._stepList.indexOf(this._currentStep) + 1;
|
|
189
|
+
if (((e = this._currentStep) == null || e.hide(), t >= this._stepList.length)) {
|
|
190
|
+
this.complete();
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
(this._currentStep = this._stepList[t]), this._currentStep.show();
|
|
194
|
+
}
|
|
195
|
+
setUpStrategies() {
|
|
196
|
+
this.updatePopupStrategies.set('default', new f()), this.updatePopupStrategies.set('custom', new w());
|
|
197
|
+
}
|
|
198
|
+
setUpBodySizeObserver() {
|
|
199
|
+
(this._bodyResizeObserver = new ResizeObserver(() => {
|
|
200
|
+
var t;
|
|
201
|
+
this.isStarted && ((t = this._currentStep) == null || t.updatePopupPosition());
|
|
202
|
+
})),
|
|
203
|
+
this._bodyResizeObserver.observe(document.body);
|
|
204
|
+
}
|
|
167
205
|
}
|
|
168
|
-
export {
|
|
169
|
-
y as Tour,
|
|
170
|
-
E as TourStep,
|
|
171
|
-
p as createElement,
|
|
172
|
-
v as isNullOrUndefined
|
|
173
|
-
};
|
|
206
|
+
export { y as Tour, E as TourStep, p as createElement };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "siteguide.js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Site guide and tours building lib",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -20,12 +20,18 @@
|
|
|
20
20
|
"name": "Borislav Shelanov",
|
|
21
21
|
"email": "borislav.shelanov@gmail.com"
|
|
22
22
|
},
|
|
23
|
-
"main": "dist/index.cjs",
|
|
24
|
-
"module": "dist/index.mjs",
|
|
25
|
-
"types": "dist/index.d.ts",
|
|
23
|
+
"main": "./dist/index.cjs",
|
|
24
|
+
"module": "./dist/index.mjs",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
26
|
"type": "module",
|
|
27
27
|
"exports": {
|
|
28
|
-
"
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"require": "./dist/index.js",
|
|
31
|
+
"import": "./dist/index.mjs",
|
|
32
|
+
"default": "./dist/index.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./dist/css/siteguide.css": "./dist/css/siteguide.css"
|
|
29
35
|
},
|
|
30
36
|
"files": [
|
|
31
37
|
"dist"
|
package/dist/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var w=Object.defineProperty;var f=(i,t,e)=>t in i?w(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var o=(i,t,e)=>f(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function n(i,t){const e=document.createElement(i);return t&&t.length>0&&(t=t.filter(s=>s),e.classList.add(...t)),e}function a(i,t){i.innerHTML="";const e=n("div",["overview-header"]);i.appendChild(e);const s=n("button",["overview-exit-button"]);e.appendChild(s);const r=n("div",["overview-content"]);i.appendChild(r);const p=n("div",["overview-button-list"]);t.buttonCollection.forEach(h=>{const l=n("button",["overview-button",h.className??""]);l.innerText=h.title,l.onclick=()=>{h.action()},p.appendChild(l)}),i.appendChild(p)}class v{updatePopupView(t,e){a(t,e),t.querySelector(".overview-content").appendChild(e.node)}}class E{updatePopupView(t,e){a(t,e);const s=t.querySelector(".overview-content");this.appendContent(s,"h2",e.title,["overview-title"]),this.appendContent(s,"p",e.text,["overview-description"])}appendContent(t,e,s,r){const p=n(e,r);p.innerText=s,t.appendChild(p)}}function c(i){return i===null||typeof i>"u"}class _{constructor(t,e){o(this,"id");o(this,"_hostData");o(this,"_popupData");o(this,"_tour");o(this,"_hostElement",null);this.id=e.id,this._hostData=e.host,this._popupData=e.popup,this._tour=t}show(){this._hostElement=this.resolveHostElement(typeof this._hostData=="function"?this._hostData():this._hostData),this.updatePopup()}hide(){}updatePopupPosition(){const t=this._hostElement.getBoundingClientRect(),e=8,s=4,r=this.resolvePopupPosition();this._tour.helperElement.style.position=r,this._tour.helperElement.style.left=`${t.left-e}px`,this._tour.helperElement.style.top=`${t.top-s}px`,this._tour.helperElement.style.width=`${t.width+2*e}px`,this._tour.helperElement.style.height=`${t.height+2*s}px`,this._tour.popupElement.style.position=r;const p=this._tour.popupElement.offsetHeight,h=this._tour.popupElement.offsetWidth,l=window.innerHeight,m=window.innerWidth;let u=t.top+window.scrollY-p,d=t.left+window.scrollX;u<0&&(u=t.bottom+window.scrollY),d+h>m&&(d=t.right+window.scrollX-h),d<0&&(d=t.left+window.scrollX),u+p>l&&(u=t.top+window.scrollY),this._tour.popupElement.style.left=`${d}px`,this._tour.popupElement.style.top=`${u}px`}updatePopup(){var t;if(!this._tour.updatePopupStrategies.has(this._popupData.type))throw new Error("Missing popup creator strategy");this._tour.updatePopupStrategies.get(this._popupData.type).updatePopupView(this._tour.popupElement,this._popupData),this.updatePopupPosition(),(t=this._hostElement)==null||t.scrollIntoView({behavior:"smooth",block:"center",inline:"center"})}resolveHostElement(t){return typeof this._hostData=="string"?document.querySelector(this._hostData):t}resolvePopupPosition(){let t=this.resolveHostElement(typeof this._hostData=="function"?this._hostData():this._hostData),e="absolute";for(;!c(t);)(t==null?void 0:t.style.position)==="fixed"&&(e="fixed"),t=(t==null?void 0:t.parentElement)??null;return e}}class S{constructor(t){o(this,"isStarted",!1);o(this,"updatePopupStrategies",new Map);o(this,"_popupElement",null);o(this,"_helperElement",null);o(this,"_stepMap",new Map);o(this,"_stepList",[]);o(this,"_currentStep",null);o(this,"_bodyResizeObserver");this._config=t,this.setUpStrategies(),this.setUpBodySizeObserver()}get stepList(){return[...this._stepList]}get config(){return this._config}get popupElement(){return this._popupElement}get helperElement(){return this._helperElement}addStep(t){if(this._stepMap.has(t.id))throw new Error("Step with provided id has been already registered");const e=new _(this,t);t.popup.buttonCollection.forEach(s=>s.action=s.action.bind(this)),this._stepList.push(e),this._stepMap.set(t.id,e)}removeStep(t){this._stepList=this._stepList.filter(e=>t!==e.id),this._stepMap.delete(t)}start(){this.isStarted=!0,this._popupElement=n("div",["overview",this._config.className??""]),document.body.appendChild(this._popupElement),this._helperElement=n("div",["overview-helper",this._config.helperClassName??""]),document.body.appendChild(this._helperElement),this.next()}complete(){this.isStarted=!1,this._popupElement&&document.body.removeChild(this._popupElement),this._helperElement&&document.body.removeChild(this._helperElement)}prev(){var e;(e=this._currentStep)==null||e.hide();const t=this._stepList.indexOf(this._currentStep)-1;if(t<0){this.complete();return}this._currentStep=this._stepList[t],this._currentStep.show()}next(){var e;const t=this._stepList.indexOf(this._currentStep)+1;if((e=this._currentStep)==null||e.hide(),t>=this._stepList.length){this.complete();return}this._currentStep=this._stepList[t],this._currentStep.show()}setUpStrategies(){this.updatePopupStrategies.set("default",new E),this.updatePopupStrategies.set("custom",new v)}setUpBodySizeObserver(){this._bodyResizeObserver=new ResizeObserver(()=>{var t;this.isStarted&&((t=this._currentStep)==null||t.updatePopupPosition())}),this._bodyResizeObserver.observe(document.body)}}exports.Tour=S;exports.TourStep=_;exports.createElement=n;exports.isNullOrUndefined=c;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.overview{width:300px;height:fit-content;background:#fff;border-radius:4px;display:flex;flex-direction:column;align-items:center;justify-content:center;position:relative;z-index:1000001;transition:all .3s ease-out}.overview-helper{box-shadow:0 0 #212121cc,0 0 0 5000px #21212180;border:2px dashed rgba(33,33,33,.8);border-radius:4px;opacity:1;z-index:1000000;box-sizing:border-box;position:absolute;transition:all .3s ease-out}.overview-content{width:100%;display:flex;flex-direction:column}.overview-title{font-size:20px;font-weight:700;color:#1b1b1b}.overview-description{font-weight:100;color:#666}.overview-button-list{width:100%;display:flex;align-items:center;justify-content:center}.overview-button{width:50%;height:35px;border-radius:10px;border:none;cursor:pointer;font-weight:600}.exit-button{display:flex;align-items:center;justify-content:center;border:none;background-color:transparent;position:absolute;top:20px;right:20px;cursor:pointer}.exit-button:hover svg{fill:#000}.exit-button svg{fill:#afafaf}
|