siteguide.js 0.1.2 → 0.2.0-alpha
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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/css/siteguide.css +1 -70
- package/dist/index.d.ts +277 -106
- package/dist/index.js +21 -194
- package/dist/index.mjs +250 -197
- package/package.json +4 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Borislav
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Siteguide
|
package/dist/css/siteguide.css
CHANGED
|
@@ -1,70 +1 @@
|
|
|
1
|
-
.
|
|
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
|
-
}
|
|
1
|
+
.siteguide{box-sizing:border-box;width:280px;background-color:snow;border-radius:8px;border:1px solid #e1dfdf;display:flex;flex-direction:column;position:relative;font-family:Arial,Helvetica,sans-serif;box-shadow:0 10px 10px #0001;z-index:1000001;transition:all .3s ease-out}.siteguide-helper{box-shadow:0 0 #212121cc,0 0 0 5000px #21212180;border:2px solid rgba(33,33,33,.8);border-radius:4px;opacity:1;z-index:1000000;box-sizing:border-box;position:absolute;transition:all .3s ease-out}.siteguide-header{display:flex;align-items:center;width:100%;padding:12px 20px 0}.siteguide-content{width:100%;padding:12px 20px}.siteguide-title{display:block;font-size:18px;font-weight:800;color:#222}.siteguide-description{font-size:14px;font-weight:400;color:#222}.siteguide-footer{width:100%;display:flex;align-items:center;justify-content:space-between;padding:12px;border-top:1px solid #e1dfdf;gap:16px}.siteguide-button{padding:8px 16px;border:none;border-radius:4px;cursor:pointer;font-size:14px;line-height:20px}.siteguide-button-secondary{background-color:#e1dfdf;color:#222}.siteguide-button-secondary:hover{background-color:#ddd}.siteguide-button-primary{background-color:#222;color:#fff}.siteguide-button-primary:hover{background-color:#000}.siteguide-close{width:20px;height:20px;display:flex;align-items:center;justify-content:center;background-color:transparent;border-radius:4px;cursor:pointer;position:absolute;top:10px;right:10px}.siteguide-close:hover{background-color:#ddd;color:#fff}.siteguide-close-icon{height:10px}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,106 +1,277 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
declare interface IUpdatePopup {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Creates an HTML element with the specified tag name and applies the given class list.
|
|
3
|
+
* @template T
|
|
4
|
+
* @param {T} tagName - The name of the HTML tag to create.
|
|
5
|
+
* @param {string[]} [classList] - An array of class names to add to the created element.
|
|
6
|
+
* @returns {HTMLElementTagNameMap[T]} The created HTML element with the specified tag name and class list.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createElement<T extends keyof HTMLElementTagNameMap>(tagName: T, classList?: string[]): HTMLElementTagNameMap[T];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Represents the data for a custom popup
|
|
12
|
+
*/
|
|
13
|
+
export declare type CustomPopupData = SharedPopupData & {
|
|
14
|
+
type: Extract<PopupType, 'custom'>;
|
|
15
|
+
/**
|
|
16
|
+
* The HTML element to use as the content of the custom popup
|
|
17
|
+
*/
|
|
18
|
+
node: HTMLElement;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Represents a deep required type, ensuring all properties of an object are required and recursively applies to nested objects
|
|
23
|
+
* @template T The type to make deep required
|
|
24
|
+
* @returns A type that represents a deep required version of T
|
|
25
|
+
*/
|
|
26
|
+
declare type DeepRequired<T> = Required<{
|
|
27
|
+
[P in keyof T]: T[P] extends object | undefined ? DeepRequired<Required<T[P]>> : T[P];
|
|
28
|
+
}>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Interface for updating popup view
|
|
32
|
+
*/
|
|
33
|
+
declare interface IUpdatePopup {
|
|
34
|
+
/**
|
|
35
|
+
* Updates the popup view with the provided data
|
|
36
|
+
* @param {HTMLElement} popup - The popup element to update
|
|
37
|
+
* @param {PopupData} popupData - The data to use for updating the popup
|
|
38
|
+
* @param {Tour} tour - The tour instance
|
|
39
|
+
*/
|
|
40
|
+
updatePopupView(popup: HTMLElement, popupData: PopupData, tour: Tour): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export declare type PopupCloseIconElement = InnerHTML | HTMLElement;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Represents the customization options for a popup
|
|
47
|
+
*/
|
|
48
|
+
export declare type PopupCustomization = {
|
|
49
|
+
/**
|
|
50
|
+
* The CSS class to apply to the popup container
|
|
51
|
+
*/
|
|
52
|
+
class?: string;
|
|
53
|
+
/**
|
|
54
|
+
* The CSS class to apply to the popup header
|
|
55
|
+
*/
|
|
56
|
+
headerClass?: string;
|
|
57
|
+
/**
|
|
58
|
+
* The CSS class to apply to the popup title
|
|
59
|
+
*/
|
|
60
|
+
titleClass?: string;
|
|
61
|
+
/**
|
|
62
|
+
* The CSS class to apply to the popup close button
|
|
63
|
+
*/
|
|
64
|
+
closeButtonClass?: string;
|
|
65
|
+
/**
|
|
66
|
+
* The CSS class to apply to the popup content
|
|
67
|
+
*/
|
|
68
|
+
contentClass?: string;
|
|
69
|
+
/**
|
|
70
|
+
* The CSS class to apply to the popup description
|
|
71
|
+
*/
|
|
72
|
+
descriptionClass?: string;
|
|
73
|
+
/**
|
|
74
|
+
* The CSS class to apply to the popup footer
|
|
75
|
+
*/
|
|
76
|
+
footerClass?: string;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Represents the data for a popup
|
|
81
|
+
*/
|
|
82
|
+
export declare type PopupData = TextPopupData | CustomPopupData;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Represents the host of a tour step. It can be a string, an HTMLElement, or a function that returns either an HTMLElement or a string.
|
|
86
|
+
* @example
|
|
87
|
+
* // Example 1: Class as host
|
|
88
|
+
* { host: '.example-element' }
|
|
89
|
+
* @example
|
|
90
|
+
* // Example 2: HTMLElement as host
|
|
91
|
+
* { host: document.querySelector('.example-element') }
|
|
92
|
+
* @example
|
|
93
|
+
* // Example 3: Function returning HTMLElement as host
|
|
94
|
+
* { host: () => document.querySelector('.example-element') };
|
|
95
|
+
* @example
|
|
96
|
+
* // Example 4: Function returning string as host
|
|
97
|
+
* { host: () => '.example-element' };
|
|
98
|
+
*/
|
|
99
|
+
export declare type PopupHost = string | HTMLElement | (() => HTMLElement | string);
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The position of a popup
|
|
103
|
+
*/
|
|
104
|
+
export declare type PopupPosition = 'top' | 'bottom' | 'left' | 'right';
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The type of a popup
|
|
108
|
+
*/
|
|
109
|
+
export declare type PopupType = 'text' | 'custom';
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Represents the shared data for a popup, including title, position, customization, and button collection.
|
|
113
|
+
*/
|
|
114
|
+
export declare type SharedPopupData = {
|
|
115
|
+
/**
|
|
116
|
+
* The title of the popup
|
|
117
|
+
*/
|
|
118
|
+
title?: string;
|
|
119
|
+
/**
|
|
120
|
+
* The position of the popup
|
|
121
|
+
*/
|
|
122
|
+
position?: PopupPosition;
|
|
123
|
+
/**
|
|
124
|
+
* Customization options for the popup
|
|
125
|
+
*
|
|
126
|
+
* Each step-popup can have own styles by providing it's own classes
|
|
127
|
+
*/
|
|
128
|
+
customization?: PopupCustomization;
|
|
129
|
+
/**
|
|
130
|
+
* A collection of button configurations for the popup
|
|
131
|
+
*/
|
|
132
|
+
buttonCollection: TourButtonConfig[];
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
declare type StepId = string;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Represents the data for a text popup
|
|
139
|
+
*/
|
|
140
|
+
export declare type TextPopupData = SharedPopupData & {
|
|
141
|
+
type: Extract<PopupType, 'text'>;
|
|
142
|
+
/**
|
|
143
|
+
* The text to display in the popup
|
|
144
|
+
*/
|
|
145
|
+
text: string;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export declare class Tour {
|
|
149
|
+
get stepList(): readonly TourStep[];
|
|
150
|
+
get config(): DeepRequired<TourConfig>;
|
|
151
|
+
/**
|
|
152
|
+
* Popup element getter
|
|
153
|
+
* @returns {HTMLElement | null} The popup element or null if not found.
|
|
154
|
+
* @example siteguide popup layout
|
|
155
|
+
*
|
|
156
|
+
* <div class="siteguide">
|
|
157
|
+
* <div class="siteguide-header">
|
|
158
|
+
* <h1 class="siteguide-title"></h1>
|
|
159
|
+
* <div class="siteguide-close"></div>
|
|
160
|
+
* </div>
|
|
161
|
+
* <div class="siteguide-content"></div>
|
|
162
|
+
* <div class="siteguide-footer">
|
|
163
|
+
* <button class="siteguide-button"></button>
|
|
164
|
+
* <button class="siteguide-button"></button>
|
|
165
|
+
* </div>
|
|
166
|
+
* </div>
|
|
167
|
+
*/
|
|
168
|
+
get popup(): HTMLElement | null;
|
|
169
|
+
get helperLayout(): HTMLElement | null;
|
|
170
|
+
/**
|
|
171
|
+
* TODO remove
|
|
172
|
+
* @deprecated remove later
|
|
173
|
+
*/
|
|
174
|
+
isStarted: boolean;
|
|
175
|
+
readonly updatePopupStrategies: Map<PopupType, IUpdatePopup>;
|
|
176
|
+
private _popup;
|
|
177
|
+
private _helperLayout;
|
|
178
|
+
private readonly _stepMap;
|
|
179
|
+
private _stepList;
|
|
180
|
+
private _currentStep;
|
|
181
|
+
private _bodyResizeObserver;
|
|
182
|
+
private readonly _config;
|
|
183
|
+
constructor(config: TourConfig);
|
|
184
|
+
addStep(config: TourStepConfig): void;
|
|
185
|
+
removeStep(stepId: StepId): void;
|
|
186
|
+
start(): void;
|
|
187
|
+
complete(): void;
|
|
188
|
+
prev(): void;
|
|
189
|
+
next(): void;
|
|
190
|
+
private setUpStrategies;
|
|
191
|
+
private setUpBodySizeObserver;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Represents the configuration for a button
|
|
196
|
+
*/
|
|
197
|
+
export declare type TourButtonConfig = {
|
|
198
|
+
text: string;
|
|
199
|
+
type?: TourButtonType;
|
|
200
|
+
/**
|
|
201
|
+
* Additional CSS class to apply to the button
|
|
202
|
+
*/
|
|
203
|
+
class?: string;
|
|
204
|
+
/**
|
|
205
|
+
* The action to perform when the button is clicked.
|
|
206
|
+
* This can be a function that returns void or a Promise that resolves to void
|
|
207
|
+
*/
|
|
208
|
+
action: (() => void) | (() => Promise<void>);
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Type of a button
|
|
213
|
+
*/
|
|
214
|
+
export declare type TourButtonType = 'primary' | 'secondary';
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Represents the configuration for a tour.
|
|
218
|
+
*/
|
|
219
|
+
export declare type TourConfig = {
|
|
220
|
+
/**
|
|
221
|
+
* The prefix for the CSS classes used in the tour
|
|
222
|
+
* Overriding this prefix will replace all 'siteguide-' prefixes with '{classPrefix}-'
|
|
223
|
+
* This option allows to easily replace all classes for customizing popup html
|
|
224
|
+
* @default 'siteguide'
|
|
225
|
+
*/
|
|
226
|
+
classPrefix?: string;
|
|
227
|
+
/**
|
|
228
|
+
* Indicates if the tour popup can be closed by the user
|
|
229
|
+
* @default true
|
|
230
|
+
*/
|
|
231
|
+
allowClose?: boolean;
|
|
232
|
+
/**
|
|
233
|
+
* Specifies if the tour should scroll to the current step and how to scroll
|
|
234
|
+
* Can be a boolean to enable or disable scrolling, or an object with options for scrollIntoView
|
|
235
|
+
* @default {behavior:'smooth',block:'center',inline:'center'}
|
|
236
|
+
*/
|
|
237
|
+
scrollTo?: boolean | ScrollIntoViewOptions;
|
|
238
|
+
/**
|
|
239
|
+
* The element or HTML to use as the close icon
|
|
240
|
+
*/
|
|
241
|
+
closeIcon?: PopupCloseIconElement;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export declare class TourStep {
|
|
245
|
+
readonly id: StepId;
|
|
246
|
+
private readonly _hostData;
|
|
247
|
+
private readonly _popupData;
|
|
248
|
+
private readonly _tour;
|
|
249
|
+
private _hostElement;
|
|
250
|
+
constructor(tour: Tour, config: TourStepConfig);
|
|
251
|
+
show(): void;
|
|
252
|
+
hide(): void;
|
|
253
|
+
updatePopupPosition(): void;
|
|
254
|
+
private updatePopup;
|
|
255
|
+
private resolveHostElement;
|
|
256
|
+
private resolvePopupPosition;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Represents the configuration for a single step in a tour
|
|
261
|
+
*/
|
|
262
|
+
export declare type TourStepConfig = {
|
|
263
|
+
/**
|
|
264
|
+
* The unique identifier for the tour step.
|
|
265
|
+
*/
|
|
266
|
+
id: StepId;
|
|
267
|
+
/**
|
|
268
|
+
* The host element or a function that returns the host element for the tour step
|
|
269
|
+
*/
|
|
270
|
+
host: PopupHost;
|
|
271
|
+
/**
|
|
272
|
+
* The popup data for the tour step
|
|
273
|
+
*/
|
|
274
|
+
popup: PopupData;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,194 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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;
|
|
1
|
+
"use strict";var $=Object.defineProperty;var E=(i,t,e)=>t in i?$(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var o=(i,t,e)=>E(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function y(i){return i===null||typeof i=="undefined"}function h(i,t){const e=document.createElement(i);return t&&t.length>0&&(t=t.filter(s=>s),e.classList.add(...t)),e}function v(i,t,e){var d,u,c,a,g,w,m,x,P,S,L;i.innerHTML="";const s=h("div",[`${e.config.classPrefix}-header`,`${(u=(d=t.customization)==null?void 0:d.headerClass)!=null?u:""}`]);i.appendChild(s);const n=h("h1",[`${e.config.classPrefix}-title`,`${(a=(c=t.customization)==null?void 0:c.titleClass)!=null?a:""}`]);if(n.innerHTML=(g=t.title)!=null?g:"",s.appendChild(n),e.config.allowClose){const r=h("button",[`${e.config.classPrefix}-close`,`${(m=(w=t.customization)==null?void 0:w.closeButtonClass)!=null?m:""}`]);T(r,e.config.closeIcon),r.onclick=()=>{e.complete()},s.appendChild(r)}const p=h("div",[`${e.config.classPrefix}-content`,`${(P=(x=t.customization)==null?void 0:x.contentClass)!=null?P:""}`]);i.appendChild(p);const l=h("div",[`${e.config.classPrefix}-footer`,`${(L=(S=t.customization)==null?void 0:S.footerClass)!=null?L:""}`]);t.buttonCollection.forEach(r=>{var C;const f=[`${e.config.classPrefix}-button`,(C=r.class)!=null?C:""];y(r.type)||r.type==="secondary"?f.push(`${e.config.classPrefix}-button-secondary`):r.type==="primary"&&f.push(`${e.config.classPrefix}-button-primary`),!y(r.class)&&r.class!==""&&f.push(r.class);const _=h("button",f);_.innerText=r.text,_.onclick=()=>{r.action()},l.appendChild(_)}),i.appendChild(l)}function T(i,t){t instanceof HTMLElement?i.appendChild(t):i.innerHTML=t.innerHTML}class M{updatePopupView(t,e,s){v(t,e,s),t.querySelector(`.${s.config.classPrefix}-content`).appendChild(e.node)}}class H{updatePopupView(t,e,s){var p,l;v(t,e,s);const n=t.querySelector(`.${s.config.classPrefix}-content`);this.appendContent(n,"p",e.text,[`${s.config.classPrefix}-description`,`${(l=(p=e.customization)==null?void 0:p.descriptionClass)!=null?l:""}`])}appendContent(t,e,s,n){const p=h(e,n);p.innerText=s,t.appendChild(p)}}class b{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,n=this.resolvePopupPosition();this._tour.helperLayout.style.position=n,this._tour.helperLayout.style.left=`${t.left-e}px`,this._tour.helperLayout.style.top=`${t.top-s}px`,this._tour.helperLayout.style.width=`${t.width+2*e}px`,this._tour.helperLayout.style.height=`${t.height+2*s}px`,this._tour.popup.style.position=n;const p=this._tour.popup.offsetHeight,l=this._tour.popup.offsetWidth,d=window.innerHeight,u=window.innerWidth;let c=t.top+window.scrollY-p,a=t.left+window.scrollX;c<0&&(c=t.bottom+window.scrollY),a+l>u&&(a=t.right+window.scrollX-l),a<0&&(a=t.left+window.scrollX),c+p>d&&(c=t.top+window.scrollY),this._tour.popup.style.left=`${a}px`,this._tour.popup.style.top=`${c}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.popup,this._popupData,this._tour),this.updatePopupPosition(),(t=this._hostElement)==null||t.scrollIntoView(this._tour.config.scrollTo)}resolveHostElement(t){return typeof this._hostData=="string"?document.querySelector(this._hostData):t}resolvePopupPosition(){var s;let t=this.resolveHostElement(typeof this._hostData=="function"?this._hostData():this._hostData),e="absolute";for(;!y(t);)(t==null?void 0:t.style.position)==="fixed"&&(e="fixed"),t=(s=t==null?void 0:t.parentElement)!=null?s:null;return e}}function k(i){return{innerHTML:`
|
|
2
|
+
<svg
|
|
3
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
4
|
+
fill="none"
|
|
5
|
+
viewBox="0 0 162 162"
|
|
6
|
+
class="${i}-close-icon"
|
|
7
|
+
>
|
|
8
|
+
<path
|
|
9
|
+
stroke-linecap="round"
|
|
10
|
+
stroke-width="17"
|
|
11
|
+
stroke="black"
|
|
12
|
+
d="M9.01074 8.98926L153.021 153"
|
|
13
|
+
></path>
|
|
14
|
+
<path
|
|
15
|
+
stroke-linecap="round"
|
|
16
|
+
stroke-width="17"
|
|
17
|
+
stroke="black"
|
|
18
|
+
d="M9.01074 153L153.021 8.98926"
|
|
19
|
+
></path>
|
|
20
|
+
</svg>
|
|
21
|
+
`}}class z{constructor(t){o(this,"isStarted",!1);o(this,"updatePopupStrategies",new Map);o(this,"_popup",null);o(this,"_helperLayout",null);o(this,"_stepMap",new Map);o(this,"_stepList",[]);o(this,"_currentStep",null);o(this,"_bodyResizeObserver");o(this,"_config");var e,s,n,p,l;this.setUpStrategies(),this.setUpBodySizeObserver(),this._config={classPrefix:(e=t.classPrefix)!=null?e:"siteguide",allowClose:(s=t.allowClose)!=null?s:!0,scrollTo:(n=t.scrollTo)!=null?n:{behavior:"smooth",block:"center",inline:"center"},closeIcon:(l=t.closeIcon)!=null?l:k((p=t.classPrefix)!=null?p:"siteguide")}}get stepList(){return this._stepList}get config(){return this._config}get popup(){return this._popup}get helperLayout(){return this._helperLayout}addStep(t){if(this._stepMap.has(t.id))throw new Error("Step with provided id has been already registered");const e=new b(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._popup=h("div",[this._config.classPrefix]),document.body.appendChild(this._popup),this._helperLayout=h("div",[`${this._config.classPrefix}-helper`]),this._helperLayout.addEventListener("click",()=>{this.complete()}),document.body.appendChild(this._helperLayout),this.next()}complete(){this.isStarted=!1,this._popup&&document.body.removeChild(this._popup),this._helperLayout&&document.body.removeChild(this._helperLayout)}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("text",new H),this.updatePopupStrategies.set("custom",new M)}setUpBodySizeObserver(){this._bodyResizeObserver=new ResizeObserver(()=>{var t;this.isStarted&&((t=this._currentStep)==null||t.updatePopupPosition())}),this._bodyResizeObserver.observe(document.body)}}exports.Tour=z;exports.TourStep=b;exports.createElement=h;
|
package/dist/index.mjs
CHANGED
|
@@ -1,206 +1,259 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var o = (i, t, e) =>
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
return t && t.length > 0 && ((t = t.filter((s) => s)), e.classList.add(...t)), e;
|
|
1
|
+
var $ = Object.defineProperty;
|
|
2
|
+
var b = (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) => b(i, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
function y(i) {
|
|
5
|
+
return i === null || typeof i == "undefined";
|
|
7
6
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
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);
|
|
7
|
+
function h(i, t) {
|
|
8
|
+
const e = document.createElement(i);
|
|
9
|
+
return t && t.length > 0 && (t = t.filter((s) => s), e.classList.add(...t)), e;
|
|
27
10
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
11
|
+
function v(i, t, e) {
|
|
12
|
+
var d, u, c, a, g, w, m, x, P, S, L;
|
|
13
|
+
i.innerHTML = "";
|
|
14
|
+
const s = h("div", [
|
|
15
|
+
`${e.config.classPrefix}-header`,
|
|
16
|
+
`${(u = (d = t.customization) == null ? void 0 : d.headerClass) != null ? u : ""}`
|
|
17
|
+
]);
|
|
18
|
+
i.appendChild(s);
|
|
19
|
+
const n = h("h1", [
|
|
20
|
+
`${e.config.classPrefix}-title`,
|
|
21
|
+
`${(a = (c = t.customization) == null ? void 0 : c.titleClass) != null ? a : ""}`
|
|
22
|
+
]);
|
|
23
|
+
if (n.innerHTML = (g = t.title) != null ? g : "", s.appendChild(n), e.config.allowClose) {
|
|
24
|
+
const r = h("button", [
|
|
25
|
+
`${e.config.classPrefix}-close`,
|
|
26
|
+
`${(m = (w = t.customization) == null ? void 0 : w.closeButtonClass) != null ? m : ""}`
|
|
27
|
+
]);
|
|
28
|
+
E(r, e.config.closeIcon), r.onclick = () => {
|
|
29
|
+
e.complete();
|
|
30
|
+
}, s.appendChild(r);
|
|
31
|
+
}
|
|
32
|
+
const p = h("div", [
|
|
33
|
+
`${e.config.classPrefix}-content`,
|
|
34
|
+
`${(P = (x = t.customization) == null ? void 0 : x.contentClass) != null ? P : ""}`
|
|
35
|
+
]);
|
|
36
|
+
i.appendChild(p);
|
|
37
|
+
const l = h("div", [
|
|
38
|
+
`${e.config.classPrefix}-footer`,
|
|
39
|
+
`${(L = (S = t.customization) == null ? void 0 : S.footerClass) != null ? L : ""}`
|
|
40
|
+
]);
|
|
41
|
+
t.buttonCollection.forEach((r) => {
|
|
42
|
+
var C;
|
|
43
|
+
const f = [`${e.config.classPrefix}-button`, (C = r.class) != null ? C : ""];
|
|
44
|
+
y(r.type) || r.type === "secondary" ? f.push(`${e.config.classPrefix}-button-secondary`) : r.type === "primary" && f.push(`${e.config.classPrefix}-button-primary`), !y(r.class) && r.class !== "" && f.push(r.class);
|
|
45
|
+
const _ = h("button", f);
|
|
46
|
+
_.innerText = r.text, _.onclick = () => {
|
|
47
|
+
r.action();
|
|
48
|
+
}, l.appendChild(_);
|
|
49
|
+
}), i.appendChild(l);
|
|
32
50
|
}
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
}
|
|
51
|
+
function E(i, t) {
|
|
52
|
+
t instanceof HTMLElement ? i.appendChild(t) : i.innerHTML = t.innerHTML;
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
class M {
|
|
55
|
+
/**
|
|
56
|
+
* @inheritdoc
|
|
57
|
+
*/
|
|
58
|
+
updatePopupView(t, e, s) {
|
|
59
|
+
v(t, e, s), t.querySelector(`.${s.config.classPrefix}-content`).appendChild(e.node);
|
|
60
|
+
}
|
|
55
61
|
}
|
|
56
|
-
class
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
}
|
|
62
|
+
class T {
|
|
63
|
+
/** @inheritdoc */
|
|
64
|
+
updatePopupView(t, e, s) {
|
|
65
|
+
var p, l;
|
|
66
|
+
v(t, e, s);
|
|
67
|
+
const n = t.querySelector(`.${s.config.classPrefix}-content`);
|
|
68
|
+
this.appendContent(n, "p", e.text, [
|
|
69
|
+
`${s.config.classPrefix}-description`,
|
|
70
|
+
`${(l = (p = e.customization) == null ? void 0 : p.descriptionClass) != null ? l : ""}`
|
|
71
|
+
]);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Appends a new HTML element with the specified class list and inner text to the parent element.
|
|
75
|
+
* @param {HTMLElement} parent - The parent element to which the new element will be appended.
|
|
76
|
+
* @param {keyof HTMLElementTagNameMap} tagType - The type of HTML element to create and append.
|
|
77
|
+
* @param {string} innerText - The inner text to set for the new element.
|
|
78
|
+
* @param {string[]} classList - An array of class names to add to the new element.
|
|
79
|
+
* @returns {void}
|
|
80
|
+
*/
|
|
81
|
+
appendContent(t, e, s, n) {
|
|
82
|
+
const p = h(e, n);
|
|
83
|
+
p.innerText = s, t.appendChild(p);
|
|
84
|
+
}
|
|
123
85
|
}
|
|
124
|
-
class
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
86
|
+
class H {
|
|
87
|
+
constructor(t, e) {
|
|
88
|
+
o(this, "id");
|
|
89
|
+
o(this, "_hostData");
|
|
90
|
+
o(this, "_popupData");
|
|
91
|
+
o(this, "_tour");
|
|
92
|
+
o(this, "_hostElement", null);
|
|
93
|
+
this.id = e.id, this._hostData = e.host, this._popupData = e.popup, this._tour = t;
|
|
94
|
+
}
|
|
95
|
+
show() {
|
|
96
|
+
this._hostElement = this.resolveHostElement(
|
|
97
|
+
typeof this._hostData == "function" ? this._hostData() : this._hostData
|
|
98
|
+
), this.updatePopup();
|
|
99
|
+
}
|
|
100
|
+
hide() {
|
|
101
|
+
}
|
|
102
|
+
updatePopupPosition() {
|
|
103
|
+
const t = this._hostElement.getBoundingClientRect(), e = 8, s = 4, n = this.resolvePopupPosition();
|
|
104
|
+
this._tour.helperLayout.style.position = n, this._tour.helperLayout.style.left = `${t.left - e}px`, this._tour.helperLayout.style.top = `${t.top - s}px`, this._tour.helperLayout.style.width = `${t.width + 2 * e}px`, this._tour.helperLayout.style.height = `${t.height + 2 * s}px`, this._tour.popup.style.position = n;
|
|
105
|
+
const p = this._tour.popup.offsetHeight, l = this._tour.popup.offsetWidth, d = window.innerHeight, u = window.innerWidth;
|
|
106
|
+
let c = t.top + window.scrollY - p, a = t.left + window.scrollX;
|
|
107
|
+
c < 0 && (c = t.bottom + window.scrollY), a + l > u && (a = t.right + window.scrollX - l), a < 0 && (a = t.left + window.scrollX), c + p > d && (c = t.top + window.scrollY), this._tour.popup.style.left = `${a}px`, this._tour.popup.style.top = `${c}px`;
|
|
108
|
+
}
|
|
109
|
+
updatePopup() {
|
|
110
|
+
var t;
|
|
111
|
+
if (!this._tour.updatePopupStrategies.has(this._popupData.type))
|
|
112
|
+
throw new Error("Missing popup creator strategy");
|
|
113
|
+
this._tour.updatePopupStrategies.get(this._popupData.type).updatePopupView(this._tour.popup, this._popupData, this._tour), this.updatePopupPosition(), (t = this._hostElement) == null || t.scrollIntoView(this._tour.config.scrollTo);
|
|
114
|
+
}
|
|
115
|
+
resolveHostElement(t) {
|
|
116
|
+
return typeof this._hostData == "string" ? document.querySelector(this._hostData) : t;
|
|
117
|
+
}
|
|
118
|
+
resolvePopupPosition() {
|
|
119
|
+
var s;
|
|
120
|
+
let t = this.resolveHostElement(
|
|
121
|
+
typeof this._hostData == "function" ? this._hostData() : this._hostData
|
|
122
|
+
), e = "absolute";
|
|
123
|
+
for (; !y(t); )
|
|
124
|
+
(t == null ? void 0 : t.style.position) === "fixed" && (e = "fixed"), t = (s = t == null ? void 0 : t.parentElement) != null ? s : null;
|
|
125
|
+
return e;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function k(i) {
|
|
129
|
+
return {
|
|
130
|
+
innerHTML: `
|
|
131
|
+
<svg
|
|
132
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
133
|
+
fill="none"
|
|
134
|
+
viewBox="0 0 162 162"
|
|
135
|
+
class="${i}-close-icon"
|
|
136
|
+
>
|
|
137
|
+
<path
|
|
138
|
+
stroke-linecap="round"
|
|
139
|
+
stroke-width="17"
|
|
140
|
+
stroke="black"
|
|
141
|
+
d="M9.01074 8.98926L153.021 153"
|
|
142
|
+
></path>
|
|
143
|
+
<path
|
|
144
|
+
stroke-linecap="round"
|
|
145
|
+
stroke-width="17"
|
|
146
|
+
stroke="black"
|
|
147
|
+
d="M9.01074 153L153.021 8.98926"
|
|
148
|
+
></path>
|
|
149
|
+
</svg>
|
|
150
|
+
`
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
class O {
|
|
154
|
+
constructor(t) {
|
|
155
|
+
/**
|
|
156
|
+
* TODO remove
|
|
157
|
+
* @deprecated remove later
|
|
158
|
+
*/
|
|
159
|
+
o(this, "isStarted", !1);
|
|
160
|
+
o(this, "updatePopupStrategies", /* @__PURE__ */ new Map());
|
|
161
|
+
o(this, "_popup", null);
|
|
162
|
+
o(this, "_helperLayout", null);
|
|
163
|
+
o(this, "_stepMap", /* @__PURE__ */ new Map());
|
|
164
|
+
o(this, "_stepList", []);
|
|
165
|
+
o(this, "_currentStep", null);
|
|
166
|
+
o(this, "_bodyResizeObserver");
|
|
167
|
+
o(this, "_config");
|
|
168
|
+
var e, s, n, p, l;
|
|
169
|
+
this.setUpStrategies(), this.setUpBodySizeObserver(), this._config = {
|
|
170
|
+
classPrefix: (e = t.classPrefix) != null ? e : "siteguide",
|
|
171
|
+
allowClose: (s = t.allowClose) != null ? s : !0,
|
|
172
|
+
scrollTo: (n = t.scrollTo) != null ? n : {
|
|
173
|
+
behavior: "smooth",
|
|
174
|
+
block: "center",
|
|
175
|
+
inline: "center"
|
|
176
|
+
},
|
|
177
|
+
closeIcon: (l = t.closeIcon) != null ? l : k((p = t.classPrefix) != null ? p : "siteguide")
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
get stepList() {
|
|
181
|
+
return this._stepList;
|
|
182
|
+
}
|
|
183
|
+
get config() {
|
|
184
|
+
return this._config;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Popup element getter
|
|
188
|
+
* @returns {HTMLElement | null} The popup element or null if not found.
|
|
189
|
+
* @example siteguide popup layout
|
|
190
|
+
*
|
|
191
|
+
* <div class="siteguide">
|
|
192
|
+
* <div class="siteguide-header">
|
|
193
|
+
* <h1 class="siteguide-title"></h1>
|
|
194
|
+
* <div class="siteguide-close"></div>
|
|
195
|
+
* </div>
|
|
196
|
+
* <div class="siteguide-content"></div>
|
|
197
|
+
* <div class="siteguide-footer">
|
|
198
|
+
* <button class="siteguide-button"></button>
|
|
199
|
+
* <button class="siteguide-button"></button>
|
|
200
|
+
* </div>
|
|
201
|
+
* </div>
|
|
202
|
+
*/
|
|
203
|
+
get popup() {
|
|
204
|
+
return this._popup;
|
|
205
|
+
}
|
|
206
|
+
get helperLayout() {
|
|
207
|
+
return this._helperLayout;
|
|
208
|
+
}
|
|
209
|
+
addStep(t) {
|
|
210
|
+
if (this._stepMap.has(t.id))
|
|
211
|
+
throw new Error("Step with provided id has been already registered");
|
|
212
|
+
const e = new H(this, t);
|
|
213
|
+
t.popup.buttonCollection.forEach((s) => s.action = s.action.bind(this)), this._stepList.push(e), this._stepMap.set(t.id, e);
|
|
214
|
+
}
|
|
215
|
+
removeStep(t) {
|
|
216
|
+
this._stepList = this._stepList.filter((e) => t !== e.id), this._stepMap.delete(t);
|
|
217
|
+
}
|
|
218
|
+
start() {
|
|
219
|
+
this.isStarted = !0, this._popup = h("div", [this._config.classPrefix]), document.body.appendChild(this._popup), this._helperLayout = h("div", [`${this._config.classPrefix}-helper`]), this._helperLayout.addEventListener("click", () => {
|
|
220
|
+
this.complete();
|
|
221
|
+
}), document.body.appendChild(this._helperLayout), this.next();
|
|
222
|
+
}
|
|
223
|
+
complete() {
|
|
224
|
+
this.isStarted = !1, this._popup && document.body.removeChild(this._popup), this._helperLayout && document.body.removeChild(this._helperLayout);
|
|
225
|
+
}
|
|
226
|
+
prev() {
|
|
227
|
+
var e;
|
|
228
|
+
(e = this._currentStep) == null || e.hide();
|
|
229
|
+
const t = this._stepList.indexOf(this._currentStep) - 1;
|
|
230
|
+
if (t < 0) {
|
|
231
|
+
this.complete();
|
|
232
|
+
return;
|
|
197
233
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
234
|
+
this._currentStep = this._stepList[t], this._currentStep.show();
|
|
235
|
+
}
|
|
236
|
+
next() {
|
|
237
|
+
var e;
|
|
238
|
+
const t = this._stepList.indexOf(this._currentStep) + 1;
|
|
239
|
+
if ((e = this._currentStep) == null || e.hide(), t >= this._stepList.length) {
|
|
240
|
+
this.complete();
|
|
241
|
+
return;
|
|
204
242
|
}
|
|
243
|
+
this._currentStep = this._stepList[t], this._currentStep.show();
|
|
244
|
+
}
|
|
245
|
+
setUpStrategies() {
|
|
246
|
+
this.updatePopupStrategies.set("text", new T()), this.updatePopupStrategies.set("custom", new M());
|
|
247
|
+
}
|
|
248
|
+
setUpBodySizeObserver() {
|
|
249
|
+
this._bodyResizeObserver = new ResizeObserver(() => {
|
|
250
|
+
var t;
|
|
251
|
+
this.isStarted && ((t = this._currentStep) == null || t.updatePopupPosition());
|
|
252
|
+
}), this._bodyResizeObserver.observe(document.body);
|
|
253
|
+
}
|
|
205
254
|
}
|
|
206
|
-
export {
|
|
255
|
+
export {
|
|
256
|
+
O as Tour,
|
|
257
|
+
H as TourStep,
|
|
258
|
+
h as createElement
|
|
259
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "siteguide.js",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0-alpha",
|
|
4
|
+
"description": "Web-site guides and tours building lib",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"siteguide",
|
|
8
|
+
"siteguide.js",
|
|
8
9
|
"site tour",
|
|
9
10
|
"tour",
|
|
10
11
|
"tutorial",
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
],
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|
|
17
|
-
"url": "git+https://github.com/Handehoch/siteguide.
|
|
18
|
+
"url": "git+https://github.com/Handehoch/siteguide.git"
|
|
18
19
|
},
|
|
19
20
|
"author": {
|
|
20
21
|
"name": "Borislav Shelanov",
|