siteguide.js 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +110 -0
- package/dist/index.mjs +4 -1
- package/package.json +5 -5
- package/dist/d/element-creator/interfaces/update-popup.interface.d.ts +0 -4
- package/dist/d/element-creator/strategies/custom-step.strategy.d.ts +0 -5
- package/dist/d/element-creator/strategies/default-step.strategy.d.ts +0 -14
- package/dist/d/element-creator/utils/update-popup-layout.util.d.ts +0 -8
- package/dist/d/index.d.ts +0 -1
- package/dist/d/tour-step.d.ts +0 -16
- package/dist/d/tour.d.ts +0 -33
- package/dist/d/types/button-config.type.d.ts +0 -5
- package/dist/d/types/popup.type.d.ts +0 -19
- package/dist/d/types/tour-config.type.d.ts +0 -4
- package/dist/d/types/tour-step-config.type.d.ts +0 -8
- package/dist/d/utils/base.util.d.ts +0 -6
- package/dist/d/utils/create-element.util.d.ts +0 -8
- package/dist/index.iife +0 -1
- package/dist/index.umd +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
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>(tagName: T, classList?: string[]): HTMLElementTagNameMap[T];
|
|
15
|
+
|
|
16
|
+
export declare type CustomPopupData = SharedPopupData & {
|
|
17
|
+
type: Extract<PopupType, 'custom'>;
|
|
18
|
+
node: HTMLElement;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export declare type DefaultPopupData = SharedPopupData & {
|
|
22
|
+
type: Extract<PopupType, 'default'>;
|
|
23
|
+
title: string;
|
|
24
|
+
text: string;
|
|
25
|
+
buttonCollection: ButtonConfig[];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export declare type HostData = string | HTMLElement | (() => HTMLElement | string);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Checks if a value is null or undefined.
|
|
32
|
+
* @param {any} value - The value to check.
|
|
33
|
+
* @returns {boolean} True if the value is null or undefined, false otherwise.
|
|
34
|
+
*/
|
|
35
|
+
export declare function isNullOrUndefined(value: any): value is null | undefined;
|
|
36
|
+
|
|
37
|
+
export declare interface IUpdatePopup {
|
|
38
|
+
updatePopupView(popupElement: HTMLElement, popupData: PopupData): void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export declare type PopupData = DefaultPopupData | CustomPopupData;
|
|
42
|
+
|
|
43
|
+
export declare type PopupPosition = 'top' | 'bottom' | 'left' | 'right';
|
|
44
|
+
|
|
45
|
+
export declare type PopupType = 'default' | 'custom';
|
|
46
|
+
|
|
47
|
+
export declare type SharedPopupData = {
|
|
48
|
+
className?: string;
|
|
49
|
+
position: PopupPosition;
|
|
50
|
+
buttonCollection: ButtonConfig[];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export declare type StepId = string;
|
|
54
|
+
|
|
55
|
+
export declare class Tour {
|
|
56
|
+
private readonly _config;
|
|
57
|
+
get stepList(): TourStep[];
|
|
58
|
+
get config(): TourConfig;
|
|
59
|
+
get popupElement(): HTMLElement | null;
|
|
60
|
+
get helperElement(): HTMLElement | null;
|
|
61
|
+
/**
|
|
62
|
+
* TODO remove
|
|
63
|
+
* @deprecated remove later
|
|
64
|
+
*/
|
|
65
|
+
isStarted: boolean;
|
|
66
|
+
readonly updatePopupStrategies: Map<PopupType, IUpdatePopup>;
|
|
67
|
+
private _popupElement;
|
|
68
|
+
private _helperElement;
|
|
69
|
+
private readonly _stepMap;
|
|
70
|
+
private _stepList;
|
|
71
|
+
private _currentStep;
|
|
72
|
+
private _bodyResizeObserver;
|
|
73
|
+
constructor(_config: TourConfig);
|
|
74
|
+
addStep(config: TourStepConfig): void;
|
|
75
|
+
removeStep(stepId: StepId): void;
|
|
76
|
+
start(): void;
|
|
77
|
+
complete(): void;
|
|
78
|
+
prev(): void;
|
|
79
|
+
next(): void;
|
|
80
|
+
private setUpStrategies;
|
|
81
|
+
private setUpBodySizeObserver;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export declare type TourConfig = {
|
|
85
|
+
className?: string;
|
|
86
|
+
helperClassName?: string;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export declare class TourStep {
|
|
90
|
+
readonly id: StepId;
|
|
91
|
+
private readonly _hostData;
|
|
92
|
+
private readonly _popupData;
|
|
93
|
+
private readonly _tour;
|
|
94
|
+
private _hostElement;
|
|
95
|
+
constructor(tour: Tour, config: TourStepConfig);
|
|
96
|
+
show(): void;
|
|
97
|
+
hide(): void;
|
|
98
|
+
updatePopupPosition(): void;
|
|
99
|
+
private updatePopup;
|
|
100
|
+
private resolveHostElement;
|
|
101
|
+
private resolvePopupPosition;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export declare type TourStepConfig = {
|
|
105
|
+
id: StepId;
|
|
106
|
+
host: HostData;
|
|
107
|
+
popup: PopupData;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export { }
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "siteguide.js",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Site
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Site guide and tours building lib",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
|
+
"siteguide",
|
|
7
8
|
"site tour",
|
|
8
9
|
"tour",
|
|
9
10
|
"tutorial",
|
|
10
11
|
"tour",
|
|
11
12
|
"guide",
|
|
12
|
-
"onboarding tour"
|
|
13
|
-
"siteguide"
|
|
13
|
+
"onboarding tour"
|
|
14
14
|
],
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"postcss": "^8.4.49",
|
|
53
53
|
"rollup": "^4.27.4",
|
|
54
54
|
"rollup-plugin-postcss": "^4.0.2",
|
|
55
|
-
"typescript": "
|
|
55
|
+
"typescript": "^5.4.2",
|
|
56
56
|
"vite": "^5.4.10",
|
|
57
57
|
"vite-plugin-dts": "^4.3.0"
|
|
58
58
|
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { CustomPopupData } from '../../types/popup.type';
|
|
2
|
-
import { IUpdatePopup } from '../interfaces/update-popup.interface';
|
|
3
|
-
export declare class CustomStepStrategy implements IUpdatePopup {
|
|
4
|
-
updatePopupView(popupElement: HTMLElement, popupData: CustomPopupData): void;
|
|
5
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { DefaultPopupData } from '../../types/popup.type';
|
|
2
|
-
import { IUpdatePopup } from '../interfaces/update-popup.interface';
|
|
3
|
-
export declare class DefaultStepStrategy implements IUpdatePopup {
|
|
4
|
-
updatePopupView(popupElement: HTMLElement, popupData: DefaultPopupData): void;
|
|
5
|
-
/**
|
|
6
|
-
* Appends a new HTML element with the specified class list and inner text to the parent element.
|
|
7
|
-
* @param {HTMLElement} parent - The parent element to which the new element will be appended.
|
|
8
|
-
* @param {keyof HTMLElementTagNameMap} tagType - The type of HTML element to create and append.
|
|
9
|
-
* @param {string} innerText - The inner text to set for the new element.
|
|
10
|
-
* @param {string[]} classList - An array of class names to add to the new element.
|
|
11
|
-
* @returns {void}
|
|
12
|
-
*/
|
|
13
|
-
private appendContent;
|
|
14
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { PopupData } from '../../types/popup.type';
|
|
2
|
-
/**
|
|
3
|
-
* Updates the layout of a popup element by clearing its content and adding new elements
|
|
4
|
-
* such as a header, exit button, content area, and a collection of buttons.
|
|
5
|
-
* @param {HTMLElement} popup - The popup element to be updated.
|
|
6
|
-
* @param {PopupData} popupData - The data containing configuration for the popup, including button configurations.
|
|
7
|
-
*/
|
|
8
|
-
export declare function updatePopupLayout(popup: HTMLElement, popupData: PopupData): void;
|
package/dist/d/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/d/tour-step.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Tour } from './tour';
|
|
2
|
-
import { StepId, TourStepConfig } from './types/tour-step-config.type';
|
|
3
|
-
export declare class TourStep {
|
|
4
|
-
readonly id: StepId;
|
|
5
|
-
private readonly _hostData;
|
|
6
|
-
private readonly _popupData;
|
|
7
|
-
private readonly _tour;
|
|
8
|
-
private _hostElement;
|
|
9
|
-
constructor(tour: Tour, config: TourStepConfig);
|
|
10
|
-
show(): void;
|
|
11
|
-
hide(): void;
|
|
12
|
-
updatePopupPosition(): void;
|
|
13
|
-
private updatePopup;
|
|
14
|
-
private resolveHostElement;
|
|
15
|
-
private resolvePopupPosition;
|
|
16
|
-
}
|
package/dist/d/tour.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { IUpdatePopup } from './element-creator/interfaces/update-popup.interface';
|
|
2
|
-
import { TourStep } from './tour-step';
|
|
3
|
-
import { PopupType } from './types/popup.type';
|
|
4
|
-
import { TourConfig } from './types/tour-config.type';
|
|
5
|
-
import { StepId, TourStepConfig } from './types/tour-step-config.type';
|
|
6
|
-
export declare class Tour {
|
|
7
|
-
private readonly _config;
|
|
8
|
-
get stepList(): TourStep[];
|
|
9
|
-
get config(): TourConfig;
|
|
10
|
-
get popupElement(): HTMLElement | null;
|
|
11
|
-
get helperElement(): HTMLElement | null;
|
|
12
|
-
/**
|
|
13
|
-
* TODO remove
|
|
14
|
-
* @deprecated remove later
|
|
15
|
-
*/
|
|
16
|
-
isStarted: boolean;
|
|
17
|
-
readonly updatePopupStrategies: Map<PopupType, IUpdatePopup>;
|
|
18
|
-
private _popupElement;
|
|
19
|
-
private _helperElement;
|
|
20
|
-
private readonly _stepMap;
|
|
21
|
-
private _stepList;
|
|
22
|
-
private _currentStep;
|
|
23
|
-
private _bodyResizeObserver;
|
|
24
|
-
constructor(_config: TourConfig);
|
|
25
|
-
addStep(config: TourStepConfig): void;
|
|
26
|
-
removeStep(stepId: StepId): void;
|
|
27
|
-
start(): void;
|
|
28
|
-
complete(): void;
|
|
29
|
-
prev(): void;
|
|
30
|
-
next(): void;
|
|
31
|
-
private setUpStrategies;
|
|
32
|
-
private setUpBodySizeObserver;
|
|
33
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ButtonConfig } from './button-config.type';
|
|
2
|
-
export type PopupData = DefaultPopupData | CustomPopupData;
|
|
3
|
-
export type PopupType = 'default' | 'custom';
|
|
4
|
-
export type PopupPosition = 'top' | 'bottom' | 'left' | 'right';
|
|
5
|
-
export type SharedPopupData = {
|
|
6
|
-
className?: string;
|
|
7
|
-
position: PopupPosition;
|
|
8
|
-
buttonCollection: ButtonConfig[];
|
|
9
|
-
};
|
|
10
|
-
export type DefaultPopupData = SharedPopupData & {
|
|
11
|
-
type: Extract<PopupType, 'default'>;
|
|
12
|
-
title: string;
|
|
13
|
-
text: string;
|
|
14
|
-
buttonCollection: ButtonConfig[];
|
|
15
|
-
};
|
|
16
|
-
export type CustomPopupData = SharedPopupData & {
|
|
17
|
-
type: Extract<PopupType, 'custom'>;
|
|
18
|
-
node: HTMLElement;
|
|
19
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
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];
|
package/dist/index.iife
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var g=Object.defineProperty;var S=(p,i,h)=>i in p?g(p,i,{enumerable:!0,configurable:!0,writable:!0,value:h}):p[i]=h;var o=(p,i,h)=>S(p,typeof i!="symbol"?i+"":i,h);this.siteguide=this.siteguide||{};this.siteguide.js=function(p){"use strict";function i(n,t){const e=document.createElement(n);return t&&t.length>0&&(t=t.filter(s=>s),e.classList.add(...t)),e}function h(n,t){n.innerHTML="";const e=i("div",["overview-header"]);n.appendChild(e);const s=i("button",["overview-exit-button"]);e.appendChild(s);const l=i("div",["overview-content"]);n.appendChild(l);const r=i("div",["overview-button-list"]);t.buttonCollection.forEach(u=>{const d=i("button",["overview-button",u.className??""]);d.innerText=u.title,d.onclick=()=>{u.action()},r.appendChild(d)}),n.appendChild(r)}class _{updatePopupView(t,e){h(t,e),t.querySelector(".overview-content").appendChild(e.node)}}class m{updatePopupView(t,e){h(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,l){const r=i(e,l);r.innerText=s,t.appendChild(r)}}function w(n){return n===null||typeof n>"u"}class f{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,l=this.resolvePopupPosition();this._tour.helperElement.style.position=l,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=l;const r=this._tour.popupElement.offsetHeight,u=this._tour.popupElement.offsetWidth,d=window.innerHeight,E=window.innerWidth;let a=t.top+window.scrollY-r,c=t.left+window.scrollX;a<0&&(a=t.bottom+window.scrollY),c+u>E&&(c=t.right+window.scrollX-u),c<0&&(c=t.left+window.scrollX),a+r>d&&(a=t.top+window.scrollY),this._tour.popupElement.style.left=`${c}px`,this._tour.popupElement.style.top=`${a}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(;!w(t);)(t==null?void 0:t.style.position)==="fixed"&&(e="fixed"),t=(t==null?void 0:t.parentElement)??null;return e}}class v{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 f(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=i("div",["overview",this._config.className??""]),document.body.appendChild(this._popupElement),this._helperElement=i("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 m),this.updatePopupStrategies.set("custom",new _)}setUpBodySizeObserver(){this._bodyResizeObserver=new ResizeObserver(()=>{var t;this.isStarted&&((t=this._currentStep)==null||t.updatePopupPosition())}),this._bodyResizeObserver.observe(document.body)}}return p.Tour=v,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"}),p}({});
|
package/dist/index.umd
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(o,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(o=typeof globalThis<"u"?globalThis:o||self,i((o.siteguide=o.siteguide||{},o.siteguide.js={})))})(this,function(o){"use strict";var y=Object.defineProperty;var S=(o,i,h)=>i in o?y(o,i,{enumerable:!0,configurable:!0,writable:!0,value:h}):o[i]=h;var n=(o,i,h)=>S(o,typeof i!="symbol"?i+"":i,h);function i(p,t){const e=document.createElement(p);return t&&t.length>0&&(t=t.filter(s=>s),e.classList.add(...t)),e}function h(p,t){p.innerHTML="";const e=i("div",["overview-header"]);p.appendChild(e);const s=i("button",["overview-exit-button"]);e.appendChild(s);const l=i("div",["overview-content"]);p.appendChild(l);const r=i("div",["overview-button-list"]);t.buttonCollection.forEach(u=>{const d=i("button",["overview-button",u.className??""]);d.innerText=u.title,d.onclick=()=>{u.action()},r.appendChild(d)}),p.appendChild(r)}class _{updatePopupView(t,e){h(t,e),t.querySelector(".overview-content").appendChild(e.node)}}class f{updatePopupView(t,e){h(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,l){const r=i(e,l);r.innerText=s,t.appendChild(r)}}function m(p){return p===null||typeof p>"u"}class w{constructor(t,e){n(this,"id");n(this,"_hostData");n(this,"_popupData");n(this,"_tour");n(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,l=this.resolvePopupPosition();this._tour.helperElement.style.position=l,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=l;const r=this._tour.popupElement.offsetHeight,u=this._tour.popupElement.offsetWidth,d=window.innerHeight,E=window.innerWidth;let a=t.top+window.scrollY-r,c=t.left+window.scrollX;a<0&&(a=t.bottom+window.scrollY),c+u>E&&(c=t.right+window.scrollX-u),c<0&&(c=t.left+window.scrollX),a+r>d&&(a=t.top+window.scrollY),this._tour.popupElement.style.left=`${c}px`,this._tour.popupElement.style.top=`${a}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(;!m(t);)(t==null?void 0:t.style.position)==="fixed"&&(e="fixed"),t=(t==null?void 0:t.parentElement)??null;return e}}class v{constructor(t){n(this,"isStarted",!1);n(this,"updatePopupStrategies",new Map);n(this,"_popupElement",null);n(this,"_helperElement",null);n(this,"_stepMap",new Map);n(this,"_stepList",[]);n(this,"_currentStep",null);n(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 w(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=i("div",["overview",this._config.className??""]),document.body.appendChild(this._popupElement),this._helperElement=i("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 f),this.updatePopupStrategies.set("custom",new _)}setUpBodySizeObserver(){this._bodyResizeObserver=new ResizeObserver(()=>{var t;this.isStarted&&((t=this._currentStep)==null||t.updatePopupPosition())}),this._bodyResizeObserver.observe(document.body)}}o.Tour=v,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|