siteguide.js 0.1.0
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/d/element-creator/interfaces/update-popup.interface.d.ts +4 -0
- package/dist/d/element-creator/strategies/custom-step.strategy.d.ts +5 -0
- package/dist/d/element-creator/strategies/default-step.strategy.d.ts +14 -0
- package/dist/d/element-creator/utils/update-popup-layout.util.d.ts +8 -0
- package/dist/d/index.d.ts +1 -0
- package/dist/d/tour-step.d.ts +16 -0
- package/dist/d/tour.d.ts +33 -0
- package/dist/d/types/button-config.type.d.ts +5 -0
- package/dist/d/types/popup.type.d.ts +19 -0
- package/dist/d/types/tour-config.type.d.ts +4 -0
- package/dist/d/types/tour-step-config.type.d.ts +8 -0
- package/dist/d/utils/base.util.d.ts +6 -0
- package/dist/d/utils/create-element.util.d.ts +8 -0
- package/dist/index.cjs +1 -0
- package/dist/index.iife +1 -0
- package/dist/index.mjs +170 -0
- package/dist/index.umd +1 -0
- package/dist/styles/siteguide.css +1 -0
- package/package.json +59 -0
@@ -0,0 +1,5 @@
|
|
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
|
+
}
|
@@ -0,0 +1,14 @@
|
|
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
|
+
}
|
@@ -0,0 +1,8 @@
|
|
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;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,16 @@
|
|
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
ADDED
@@ -0,0 +1,33 @@
|
|
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
|
+
}
|
@@ -0,0 +1,19 @@
|
|
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
|
+
};
|
@@ -0,0 +1,8 @@
|
|
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.cjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";var _=Object.defineProperty;var m=(i,t,e)=>t in i?_(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var o=(i,t,e)=>m(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function p(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=p("div",["overview-header"]);i.appendChild(e);const s=p("button",["overview-exit-button"]);e.appendChild(s);const r=p("div",["overview-content"]);i.appendChild(r);const n=p("div",["overview-button-list"]);t.buttonCollection.forEach(h=>{const l=p("button",["overview-button",h.className??""]);l.innerText=h.title,l.onclick=()=>{h.action()},n.appendChild(l)}),i.appendChild(n)}class w{updatePopupView(t,e){a(t,e),t.querySelector(".overview-content").appendChild(e.node)}}class f{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 n=p(e,r);n.innerText=s,t.appendChild(n)}}function v(i){return i===null||typeof i>"u"}class E{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 n=this._tour.popupElement.offsetHeight,h=this._tour.popupElement.offsetWidth,l=window.innerHeight,c=window.innerWidth;let u=t.top+window.scrollY-n,d=t.left+window.scrollX;u<0&&(u=t.bottom+window.scrollY),d+h>c&&(d=t.right+window.scrollX-h),d<0&&(d=t.left+window.scrollX),u+n>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(;!v(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 E(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=p("div",["overview",this._config.className??""]),document.body.appendChild(this._popupElement),this._helperElement=p("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 w)}setUpBodySizeObserver(){this._bodyResizeObserver=new ResizeObserver(()=>{var t;this.isStarted&&((t=this._currentStep)==null||t.updatePopupPosition())}),this._bodyResizeObserver.observe(document.body)}}exports.Tour=S;
|
package/dist/index.iife
ADDED
@@ -0,0 +1 @@
|
|
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.mjs
ADDED
@@ -0,0 +1,170 @@
|
|
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 != "symbol" ? t + "" : t, e);
|
4
|
+
function p(i, t) {
|
5
|
+
const e = document.createElement(i);
|
6
|
+
return t && t.length > 0 && (t = t.filter((s) => s), e.classList.add(...t)), e;
|
7
|
+
}
|
8
|
+
function a(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
|
+
const l = p("button", ["overview-button", h.className ?? ""]);
|
19
|
+
l.innerText = h.title, l.onclick = () => {
|
20
|
+
h.action();
|
21
|
+
}, n.appendChild(l);
|
22
|
+
}), i.appendChild(n);
|
23
|
+
}
|
24
|
+
class w {
|
25
|
+
updatePopupView(t, e) {
|
26
|
+
a(t, e), t.querySelector(".overview-content").appendChild(e.node);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
class f {
|
30
|
+
updatePopupView(t, e) {
|
31
|
+
a(t, e);
|
32
|
+
const s = t.querySelector(".overview-content");
|
33
|
+
this.appendContent(s, "h2", e.title, ["overview-title"]), this.appendContent(s, "p", e.text, ["overview-description"]);
|
34
|
+
}
|
35
|
+
/**
|
36
|
+
* Appends a new HTML element with the specified class list and inner text to the parent element.
|
37
|
+
* @param {HTMLElement} parent - The parent element to which the new element will be appended.
|
38
|
+
* @param {keyof HTMLElementTagNameMap} tagType - The type of HTML element to create and append.
|
39
|
+
* @param {string} innerText - The inner text to set for the new element.
|
40
|
+
* @param {string[]} classList - An array of class names to add to the new element.
|
41
|
+
* @returns {void}
|
42
|
+
*/
|
43
|
+
appendContent(t, e, s, r) {
|
44
|
+
const n = p(e, r);
|
45
|
+
n.innerText = s, t.appendChild(n);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
function v(i) {
|
49
|
+
return i === null || typeof i > "u";
|
50
|
+
}
|
51
|
+
class E {
|
52
|
+
constructor(t, e) {
|
53
|
+
o(this, "id");
|
54
|
+
o(this, "_hostData");
|
55
|
+
o(this, "_popupData");
|
56
|
+
o(this, "_tour");
|
57
|
+
o(this, "_hostElement", null);
|
58
|
+
this.id = e.id, this._hostData = e.host, this._popupData = e.popup, this._tour = t;
|
59
|
+
}
|
60
|
+
show() {
|
61
|
+
this._hostElement = this.resolveHostElement(
|
62
|
+
typeof this._hostData == "function" ? this._hostData() : this._hostData
|
63
|
+
), this.updatePopup();
|
64
|
+
}
|
65
|
+
hide() {
|
66
|
+
}
|
67
|
+
updatePopupPosition() {
|
68
|
+
const t = this._hostElement.getBoundingClientRect(), e = 8, s = 4, r = this.resolvePopupPosition();
|
69
|
+
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;
|
70
|
+
const n = this._tour.popupElement.offsetHeight, h = this._tour.popupElement.offsetWidth, l = window.innerHeight, c = window.innerWidth;
|
71
|
+
let u = t.top + window.scrollY - n, d = t.left + window.scrollX;
|
72
|
+
u < 0 && (u = t.bottom + window.scrollY), d + h > c && (d = t.right + window.scrollX - h), d < 0 && (d = t.left + window.scrollX), u + n > l && (u = t.top + window.scrollY), this._tour.popupElement.style.left = `${d}px`, this._tour.popupElement.style.top = `${u}px`;
|
73
|
+
}
|
74
|
+
updatePopup() {
|
75
|
+
var t;
|
76
|
+
if (!this._tour.updatePopupStrategies.has(this._popupData.type))
|
77
|
+
throw new Error("Missing popup creator strategy");
|
78
|
+
this._tour.updatePopupStrategies.get(this._popupData.type).updatePopupView(this._tour.popupElement, this._popupData), this.updatePopupPosition(), (t = this._hostElement) == null || t.scrollIntoView({
|
79
|
+
behavior: "smooth",
|
80
|
+
block: "center",
|
81
|
+
inline: "center"
|
82
|
+
});
|
83
|
+
}
|
84
|
+
resolveHostElement(t) {
|
85
|
+
return typeof this._hostData == "string" ? document.querySelector(this._hostData) : t;
|
86
|
+
}
|
87
|
+
resolvePopupPosition() {
|
88
|
+
let t = this.resolveHostElement(
|
89
|
+
typeof this._hostData == "function" ? this._hostData() : this._hostData
|
90
|
+
), e = "absolute";
|
91
|
+
for (; !v(t); )
|
92
|
+
(t == null ? void 0 : t.style.position) === "fixed" && (e = "fixed"), t = (t == null ? void 0 : t.parentElement) ?? null;
|
93
|
+
return e;
|
94
|
+
}
|
95
|
+
}
|
96
|
+
class y {
|
97
|
+
constructor(t) {
|
98
|
+
/**
|
99
|
+
* TODO remove
|
100
|
+
* @deprecated remove later
|
101
|
+
*/
|
102
|
+
o(this, "isStarted", !1);
|
103
|
+
o(this, "updatePopupStrategies", /* @__PURE__ */ new Map());
|
104
|
+
o(this, "_popupElement", null);
|
105
|
+
o(this, "_helperElement", null);
|
106
|
+
o(this, "_stepMap", /* @__PURE__ */ new Map());
|
107
|
+
o(this, "_stepList", []);
|
108
|
+
o(this, "_currentStep", null);
|
109
|
+
o(this, "_bodyResizeObserver");
|
110
|
+
this._config = t, this.setUpStrategies(), this.setUpBodySizeObserver();
|
111
|
+
}
|
112
|
+
get stepList() {
|
113
|
+
return [...this._stepList];
|
114
|
+
}
|
115
|
+
get config() {
|
116
|
+
return this._config;
|
117
|
+
}
|
118
|
+
get popupElement() {
|
119
|
+
return this._popupElement;
|
120
|
+
}
|
121
|
+
get helperElement() {
|
122
|
+
return this._helperElement;
|
123
|
+
}
|
124
|
+
addStep(t) {
|
125
|
+
if (this._stepMap.has(t.id))
|
126
|
+
throw new Error("Step with provided id has been already registered");
|
127
|
+
const e = new E(this, t);
|
128
|
+
t.popup.buttonCollection.forEach((s) => s.action = s.action.bind(this)), this._stepList.push(e), this._stepMap.set(t.id, e);
|
129
|
+
}
|
130
|
+
removeStep(t) {
|
131
|
+
this._stepList = this._stepList.filter((e) => t !== e.id), this._stepMap.delete(t);
|
132
|
+
}
|
133
|
+
start() {
|
134
|
+
this.isStarted = !0, this._popupElement = p("div", ["overview", this._config.className ?? ""]), document.body.appendChild(this._popupElement), this._helperElement = p("div", ["overview-helper", this._config.helperClassName ?? ""]), document.body.appendChild(this._helperElement), this.next();
|
135
|
+
}
|
136
|
+
complete() {
|
137
|
+
this.isStarted = !1, this._popupElement && document.body.removeChild(this._popupElement), this._helperElement && document.body.removeChild(this._helperElement);
|
138
|
+
}
|
139
|
+
prev() {
|
140
|
+
var e;
|
141
|
+
(e = this._currentStep) == null || e.hide();
|
142
|
+
const t = this._stepList.indexOf(this._currentStep) - 1;
|
143
|
+
if (t < 0) {
|
144
|
+
this.complete();
|
145
|
+
return;
|
146
|
+
}
|
147
|
+
this._currentStep = this._stepList[t], this._currentStep.show();
|
148
|
+
}
|
149
|
+
next() {
|
150
|
+
var e;
|
151
|
+
const t = this._stepList.indexOf(this._currentStep) + 1;
|
152
|
+
if ((e = this._currentStep) == null || e.hide(), t >= this._stepList.length) {
|
153
|
+
this.complete();
|
154
|
+
return;
|
155
|
+
}
|
156
|
+
this._currentStep = this._stepList[t], this._currentStep.show();
|
157
|
+
}
|
158
|
+
setUpStrategies() {
|
159
|
+
this.updatePopupStrategies.set("default", new f()), this.updatePopupStrategies.set("custom", new w());
|
160
|
+
}
|
161
|
+
setUpBodySizeObserver() {
|
162
|
+
this._bodyResizeObserver = new ResizeObserver(() => {
|
163
|
+
var t;
|
164
|
+
this.isStarted && ((t = this._currentStep) == null || t.updatePopupPosition());
|
165
|
+
}), this._bodyResizeObserver.observe(document.body);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
export {
|
169
|
+
y as Tour
|
170
|
+
};
|
package/dist/index.umd
ADDED
@@ -0,0 +1 @@
|
|
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"})});
|
@@ -0,0 +1 @@
|
|
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}
|
package/package.json
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
{
|
2
|
+
"name": "siteguide.js",
|
3
|
+
"version": "0.1.0",
|
4
|
+
"description": "Site guid and tours building lib.",
|
5
|
+
"license": "MIT",
|
6
|
+
"keywords": [
|
7
|
+
"site tour",
|
8
|
+
"tour",
|
9
|
+
"tutorial",
|
10
|
+
"tour",
|
11
|
+
"guide",
|
12
|
+
"onboarding tour",
|
13
|
+
"siteguide"
|
14
|
+
],
|
15
|
+
"repository": {
|
16
|
+
"type": "git",
|
17
|
+
"url": "git+https://github.com/Handehoch/siteguide.js.git"
|
18
|
+
},
|
19
|
+
"author": {
|
20
|
+
"name": "Borislav Shelanov",
|
21
|
+
"email": "borislav.shelanov@gmail.com"
|
22
|
+
},
|
23
|
+
"main": "dist/index.cjs",
|
24
|
+
"module": "dist/index.mjs",
|
25
|
+
"types": "dist/index.d.ts",
|
26
|
+
"type": "module",
|
27
|
+
"exports": {
|
28
|
+
"./dist/styles/siteguide.css": "./dist/styles/siteguide.css"
|
29
|
+
},
|
30
|
+
"files": [
|
31
|
+
"dist"
|
32
|
+
],
|
33
|
+
"private": false,
|
34
|
+
"publishConfig": {
|
35
|
+
"registry": "https://registry.npmjs.org/",
|
36
|
+
"access": "public"
|
37
|
+
},
|
38
|
+
"scripts": {
|
39
|
+
"clean": "rimraf dist",
|
40
|
+
"dev": "vite build --watch",
|
41
|
+
"start": "vite --host --open",
|
42
|
+
"build": "npm run clean && vite build",
|
43
|
+
"rollup:dts": "api-extractor run",
|
44
|
+
"append:dts": "npm run rollup:dts",
|
45
|
+
"lint:scripts": "eslint ./src --ext .ts",
|
46
|
+
"lint:styles": "stylelint ./**/*.{css,scss}",
|
47
|
+
"format:scripts": "prettier ./src --write",
|
48
|
+
"format:styles": "stylelint ./**/*.{css,scss} --fix"
|
49
|
+
},
|
50
|
+
"devDependencies": {
|
51
|
+
"@types/node": "^22.9.1",
|
52
|
+
"postcss": "^8.4.49",
|
53
|
+
"rollup": "^4.27.4",
|
54
|
+
"rollup-plugin-postcss": "^4.0.2",
|
55
|
+
"typescript": "~5.6.2",
|
56
|
+
"vite": "^5.4.10",
|
57
|
+
"vite-plugin-dts": "^4.3.0"
|
58
|
+
}
|
59
|
+
}
|