index.js 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114
  1. "use strict";
  2. var __create = Object.create;
  3. var __defProp = Object.defineProperty;
  4. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  5. var __getOwnPropNames = Object.getOwnPropertyNames;
  6. var __getProtoOf = Object.getPrototypeOf;
  7. var __hasOwnProp = Object.prototype.hasOwnProperty;
  8. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  9. var __export = (target, all) => {
  10. for (var name in all)
  11. __defProp(target, name, { get: all[name], enumerable: true });
  12. };
  13. var __copyProps = (to, from, except, desc) => {
  14. if (from && typeof from === "object" || typeof from === "function") {
  15. for (let key of __getOwnPropNames(from))
  16. if (!__hasOwnProp.call(to, key) && key !== except)
  17. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  18. }
  19. return to;
  20. };
  21. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  22. // If the importer is in node compatibility mode or this is not an ESM
  23. // file that has been converted to a CommonJS file using a Babel-
  24. // compatible transform (i.e. "__esModule" has not been set), then set
  25. // "default" to the CommonJS "module.exports" for node compatibility.
  26. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  27. mod
  28. ));
  29. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  30. var __publicField = (obj, key, value) => {
  31. __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  32. return value;
  33. };
  34. // src/index.tsx
  35. var src_exports = {};
  36. __export(src_exports, {
  37. ACTIONS: () => ACTIONS,
  38. EVENTS: () => EVENTS,
  39. LIFECYCLE: () => LIFECYCLE,
  40. STATUS: () => STATUS,
  41. default: () => components_default
  42. });
  43. module.exports = __toCommonJS(src_exports);
  44. // src/literals/index.ts
  45. var ACTIONS = {
  46. INIT: "init",
  47. START: "start",
  48. STOP: "stop",
  49. RESET: "reset",
  50. PREV: "prev",
  51. NEXT: "next",
  52. GO: "go",
  53. CLOSE: "close",
  54. SKIP: "skip",
  55. UPDATE: "update"
  56. };
  57. var EVENTS = {
  58. TOUR_START: "tour:start",
  59. STEP_BEFORE: "step:before",
  60. BEACON: "beacon",
  61. TOOLTIP: "tooltip",
  62. STEP_AFTER: "step:after",
  63. TOUR_END: "tour:end",
  64. TOUR_STATUS: "tour:status",
  65. TARGET_NOT_FOUND: "error:target_not_found",
  66. ERROR: "error"
  67. };
  68. var LIFECYCLE = {
  69. INIT: "init",
  70. READY: "ready",
  71. BEACON: "beacon",
  72. TOOLTIP: "tooltip",
  73. COMPLETE: "complete",
  74. ERROR: "error"
  75. };
  76. var STATUS = {
  77. IDLE: "idle",
  78. READY: "ready",
  79. WAITING: "waiting",
  80. RUNNING: "running",
  81. PAUSED: "paused",
  82. SKIPPED: "skipped",
  83. FINISHED: "finished",
  84. ERROR: "error"
  85. };
  86. // src/components/index.tsx
  87. var React9 = __toESM(require("react"));
  88. var import_deep_equal = __toESM(require("@gilbarbara/deep-equal"));
  89. var import_is_lite6 = __toESM(require("is-lite"));
  90. var import_tree_changes3 = __toESM(require("tree-changes"));
  91. // src/modules/dom.ts
  92. var import_scroll = __toESM(require("scroll"));
  93. var import_scrollparent = __toESM(require("scrollparent"));
  94. function canUseDOM() {
  95. return !!(typeof window !== "undefined" && window.document && window.document.createElement);
  96. }
  97. function getClientRect(element) {
  98. if (!element) {
  99. return null;
  100. }
  101. return element.getBoundingClientRect();
  102. }
  103. function getDocumentHeight() {
  104. const { body, documentElement } = document;
  105. if (!body || !documentElement) {
  106. return 0;
  107. }
  108. return Math.max(
  109. body.scrollHeight,
  110. body.offsetHeight,
  111. documentElement.clientHeight,
  112. documentElement.scrollHeight,
  113. documentElement.offsetHeight
  114. );
  115. }
  116. function getElement(element) {
  117. if (typeof element === "string") {
  118. return document.querySelector(element);
  119. }
  120. return element;
  121. }
  122. function getStyleComputedProperty(el) {
  123. if (!el || el.nodeType !== 1) {
  124. return null;
  125. }
  126. return getComputedStyle(el);
  127. }
  128. function getScrollParent(element, skipFix, forListener) {
  129. if (!element) {
  130. return scrollDocument();
  131. }
  132. const parent = (0, import_scrollparent.default)(element);
  133. if (parent) {
  134. if (parent.isSameNode(scrollDocument())) {
  135. if (forListener) {
  136. return document;
  137. }
  138. return scrollDocument();
  139. }
  140. const hasScrolling = parent.scrollHeight > parent.offsetHeight;
  141. if (!hasScrolling && !skipFix) {
  142. parent.style.overflow = "initial";
  143. return scrollDocument();
  144. }
  145. }
  146. return parent;
  147. }
  148. function hasCustomScrollParent(element, skipFix) {
  149. if (!element) {
  150. return false;
  151. }
  152. const parent = getScrollParent(element, skipFix);
  153. return parent ? !parent.isSameNode(scrollDocument()) : false;
  154. }
  155. function hasCustomOffsetParent(element) {
  156. return element.offsetParent !== document.body;
  157. }
  158. function hasPosition(el, type = "fixed") {
  159. if (!el || !(el instanceof HTMLElement)) {
  160. return false;
  161. }
  162. const { nodeName } = el;
  163. const styles = getStyleComputedProperty(el);
  164. if (nodeName === "BODY" || nodeName === "HTML") {
  165. return false;
  166. }
  167. if (styles && styles.position === type) {
  168. return true;
  169. }
  170. if (!el.parentNode) {
  171. return false;
  172. }
  173. return hasPosition(el.parentNode, type);
  174. }
  175. function isElementVisible(element) {
  176. var _a;
  177. if (!element) {
  178. return false;
  179. }
  180. let parentElement = element;
  181. while (parentElement) {
  182. if (parentElement === document.body) {
  183. break;
  184. }
  185. if (parentElement instanceof HTMLElement) {
  186. const { display, visibility } = getComputedStyle(parentElement);
  187. if (display === "none" || visibility === "hidden") {
  188. return false;
  189. }
  190. }
  191. parentElement = (_a = parentElement.parentElement) != null ? _a : null;
  192. }
  193. return true;
  194. }
  195. function getElementPosition(element, offset, skipFix) {
  196. var _a;
  197. const elementRect = getClientRect(element);
  198. const parent = getScrollParent(element, skipFix);
  199. const hasScrollParent = hasCustomScrollParent(element, skipFix);
  200. let parentTop = 0;
  201. let top = (_a = elementRect == null ? void 0 : elementRect.top) != null ? _a : 0;
  202. if (parent instanceof HTMLElement) {
  203. parentTop = parent.scrollTop;
  204. if (!hasScrollParent && !hasPosition(element)) {
  205. top += parentTop;
  206. }
  207. if (!parent.isSameNode(scrollDocument())) {
  208. top += scrollDocument().scrollTop;
  209. }
  210. }
  211. return Math.floor(top - offset);
  212. }
  213. function getScrollTo(element, offset, skipFix) {
  214. var _a;
  215. if (!element) {
  216. return 0;
  217. }
  218. const { offsetTop = 0, scrollTop = 0 } = (_a = (0, import_scrollparent.default)(element)) != null ? _a : {};
  219. let top = element.getBoundingClientRect().top + scrollTop;
  220. if (!!offsetTop && (hasCustomScrollParent(element, skipFix) || hasCustomOffsetParent(element))) {
  221. top -= offsetTop;
  222. }
  223. const output = Math.floor(top - offset);
  224. return output < 0 ? 0 : output;
  225. }
  226. function scrollDocument() {
  227. var _a;
  228. return (_a = document.scrollingElement) != null ? _a : document.documentElement;
  229. }
  230. function scrollTo(value, options) {
  231. const { duration, element } = options;
  232. return new Promise((resolve, reject) => {
  233. const { scrollTop } = element;
  234. const limit = value > scrollTop ? value - scrollTop : scrollTop - value;
  235. import_scroll.default.top(element, value, { duration: limit < 100 ? 50 : duration }, (error) => {
  236. if (error && error.message !== "Element already at target scroll position") {
  237. return reject(error);
  238. }
  239. return resolve();
  240. });
  241. });
  242. }
  243. // src/modules/helpers.ts
  244. var import_react = require("react");
  245. var import_react_dom = require("react-dom");
  246. var import_is_lite = __toESM(require("is-lite"));
  247. var isReact16 = import_react_dom.createPortal !== void 0;
  248. function getBrowser(userAgent = navigator.userAgent) {
  249. let browser = userAgent;
  250. if (typeof window === "undefined") {
  251. browser = "node";
  252. } else if (document.documentMode) {
  253. browser = "ie";
  254. } else if (/Edge/.test(userAgent)) {
  255. browser = "edge";
  256. } else if (Boolean(window.opera) || userAgent.includes(" OPR/")) {
  257. browser = "opera";
  258. } else if (typeof window.InstallTrigger !== "undefined") {
  259. browser = "firefox";
  260. } else if (window.chrome) {
  261. browser = "chrome";
  262. } else if (/(Version\/([\d._]+).*Safari|CriOS|FxiOS| Mobile\/)/.test(userAgent)) {
  263. browser = "safari";
  264. }
  265. return browser;
  266. }
  267. function getText(root) {
  268. const content = [];
  269. const recurse = (child) => {
  270. if (typeof child === "string" || typeof child === "number") {
  271. content.push(child);
  272. } else if (Array.isArray(child)) {
  273. child.forEach((c) => recurse(c));
  274. } else if ((0, import_react.isValidElement)(child)) {
  275. const { children } = child.props;
  276. if (Array.isArray(children)) {
  277. children.forEach((c) => recurse(c));
  278. } else {
  279. recurse(children);
  280. }
  281. }
  282. };
  283. recurse(root);
  284. return content.join(" ").trim();
  285. }
  286. function hasValidKeys(object, keys) {
  287. if (!import_is_lite.default.plainObject(object) || !import_is_lite.default.array(keys)) {
  288. return false;
  289. }
  290. return Object.keys(object).every((d) => keys.includes(d));
  291. }
  292. function hexToRGB(hex) {
  293. const shorthandRegex = /^#?([\da-f])([\da-f])([\da-f])$/i;
  294. const properHex = hex.replace(shorthandRegex, (_m, r, g, b) => r + r + g + g + b + b);
  295. const result = /^#?([\da-f]{2})([\da-f]{2})([\da-f]{2})$/i.exec(properHex);
  296. return result ? [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)] : [];
  297. }
  298. function hideBeacon(step) {
  299. return step.disableBeacon || step.placement === "center";
  300. }
  301. function isLegacy() {
  302. return !["chrome", "safari", "firefox", "opera"].includes(getBrowser());
  303. }
  304. function log({ data, debug = false, title, warn = false }) {
  305. const logFn = warn ? console.warn || console.error : console.log;
  306. if (debug) {
  307. if (title && data) {
  308. console.groupCollapsed(
  309. `%creact-joyride: ${title}`,
  310. "color: #ff0044; font-weight: bold; font-size: 12px;"
  311. );
  312. if (Array.isArray(data)) {
  313. data.forEach((d) => {
  314. if (import_is_lite.default.plainObject(d) && d.key) {
  315. logFn.apply(console, [d.key, d.value]);
  316. } else {
  317. logFn.apply(console, [d]);
  318. }
  319. });
  320. } else {
  321. logFn.apply(console, [data]);
  322. }
  323. console.groupEnd();
  324. } else {
  325. console.error("Missing title or data props");
  326. }
  327. }
  328. }
  329. function shouldScroll(options) {
  330. const { isFirstStep, lifecycle, previousLifecycle, scrollToFirstStep, step, target } = options;
  331. return !step.disableScrolling && (!isFirstStep || scrollToFirstStep || lifecycle === LIFECYCLE.TOOLTIP) && step.placement !== "center" && (!step.isFixed || !hasPosition(target)) && // fixed steps don't need to scroll
  332. previousLifecycle !== lifecycle && [LIFECYCLE.BEACON, LIFECYCLE.TOOLTIP].includes(lifecycle);
  333. }
  334. // src/modules/step.ts
  335. var import_helpers3 = require("@gilbarbara/helpers");
  336. var import_deepmerge2 = __toESM(require("deepmerge"));
  337. var import_is_lite2 = __toESM(require("is-lite"));
  338. // src/defaults.ts
  339. var import_helpers = require("@gilbarbara/helpers");
  340. var defaultFloaterProps = {
  341. options: {
  342. preventOverflow: {
  343. boundariesElement: "scrollParent"
  344. }
  345. },
  346. wrapperOptions: {
  347. offset: -18,
  348. position: true
  349. }
  350. };
  351. var defaultLocale = {
  352. back: "Back",
  353. close: "Close",
  354. last: "Last",
  355. next: "Next",
  356. open: "Open the dialog",
  357. skip: "Skip"
  358. };
  359. var defaultStep = {
  360. event: "click",
  361. placement: "bottom",
  362. offset: 10,
  363. disableBeacon: false,
  364. disableCloseOnEsc: false,
  365. disableOverlay: false,
  366. disableOverlayClose: false,
  367. disableScrollParentFix: false,
  368. disableScrolling: false,
  369. hideBackButton: false,
  370. hideCloseButton: false,
  371. hideFooter: false,
  372. isFixed: false,
  373. locale: defaultLocale,
  374. showProgress: false,
  375. showSkipButton: false,
  376. spotlightClicks: false,
  377. spotlightPadding: 10
  378. };
  379. var defaultProps = {
  380. continuous: false,
  381. debug: false,
  382. disableCloseOnEsc: false,
  383. disableOverlay: false,
  384. disableOverlayClose: false,
  385. disableScrolling: false,
  386. disableScrollParentFix: false,
  387. getHelpers: (0, import_helpers.noop)(),
  388. hideBackButton: false,
  389. run: true,
  390. scrollOffset: 20,
  391. scrollDuration: 300,
  392. scrollToFirstStep: false,
  393. showSkipButton: false,
  394. showProgress: false,
  395. spotlightClicks: false,
  396. spotlightPadding: 10,
  397. steps: []
  398. };
  399. // src/styles.ts
  400. var import_deepmerge = __toESM(require("deepmerge"));
  401. var defaultOptions = {
  402. arrowColor: "#fff",
  403. backgroundColor: "#fff",
  404. beaconSize: 36,
  405. overlayColor: "rgba(0, 0, 0, 0.5)",
  406. primaryColor: "#f04",
  407. spotlightShadow: "0 0 15px rgba(0, 0, 0, 0.5)",
  408. textColor: "#333",
  409. width: 380,
  410. zIndex: 100
  411. };
  412. var buttonBase = {
  413. backgroundColor: "transparent",
  414. border: 0,
  415. borderRadius: 0,
  416. color: "#555",
  417. cursor: "pointer",
  418. fontSize: 16,
  419. lineHeight: 1,
  420. padding: 8,
  421. WebkitAppearance: "none"
  422. };
  423. var spotlight = {
  424. borderRadius: 4,
  425. position: "absolute"
  426. };
  427. function getStyles(propsStyles, stepStyles) {
  428. const mergedStyles = (0, import_deepmerge.default)(propsStyles != null ? propsStyles : {}, stepStyles != null ? stepStyles : {});
  429. const options = (0, import_deepmerge.default)(defaultOptions, mergedStyles.options || {});
  430. let { width } = options;
  431. if (window.innerWidth > 480) {
  432. width = 380;
  433. }
  434. if ("width" in options) {
  435. width = typeof options.width === "number" && window.innerWidth < options.width ? window.innerWidth - 30 : options.width;
  436. }
  437. const overlay = {
  438. bottom: 0,
  439. left: 0,
  440. overflow: "hidden",
  441. position: "absolute",
  442. right: 0,
  443. top: 0,
  444. zIndex: options.zIndex
  445. };
  446. const defaultStyles = {
  447. beacon: {
  448. ...buttonBase,
  449. display: "inline-block",
  450. height: options.beaconSize,
  451. position: "relative",
  452. width: options.beaconSize,
  453. zIndex: options.zIndex
  454. },
  455. beaconInner: {
  456. animation: "joyride-beacon-inner 1.2s infinite ease-in-out",
  457. backgroundColor: options.primaryColor,
  458. borderRadius: "50%",
  459. display: "block",
  460. height: "50%",
  461. left: "50%",
  462. opacity: 0.7,
  463. position: "absolute",
  464. top: "50%",
  465. transform: "translate(-50%, -50%)",
  466. width: "50%"
  467. },
  468. beaconOuter: {
  469. animation: "joyride-beacon-outer 1.2s infinite ease-in-out",
  470. backgroundColor: `rgba(${hexToRGB(options.primaryColor).join(",")}, 0.2)`,
  471. border: `2px solid ${options.primaryColor}`,
  472. borderRadius: "50%",
  473. boxSizing: "border-box",
  474. display: "block",
  475. height: "100%",
  476. left: 0,
  477. opacity: 0.9,
  478. position: "absolute",
  479. top: 0,
  480. transformOrigin: "center",
  481. width: "100%"
  482. },
  483. tooltip: {
  484. backgroundColor: options.backgroundColor,
  485. borderRadius: 5,
  486. boxSizing: "border-box",
  487. color: options.textColor,
  488. fontSize: 16,
  489. maxWidth: "100%",
  490. padding: 15,
  491. position: "relative",
  492. width
  493. },
  494. tooltipContainer: {
  495. lineHeight: 1.4,
  496. textAlign: "center"
  497. },
  498. tooltipTitle: {
  499. fontSize: 18,
  500. margin: 0
  501. },
  502. tooltipContent: {
  503. padding: "20px 10px"
  504. },
  505. tooltipFooter: {
  506. alignItems: "center",
  507. display: "flex",
  508. justifyContent: "flex-end",
  509. marginTop: 15
  510. },
  511. tooltipFooterSpacer: {
  512. flex: 1
  513. },
  514. buttonNext: {
  515. ...buttonBase,
  516. backgroundColor: options.primaryColor,
  517. borderRadius: 4,
  518. color: "#fff"
  519. },
  520. buttonBack: {
  521. ...buttonBase,
  522. color: options.primaryColor,
  523. marginLeft: "auto",
  524. marginRight: 5
  525. },
  526. buttonClose: {
  527. ...buttonBase,
  528. color: options.textColor,
  529. height: 14,
  530. padding: 15,
  531. position: "absolute",
  532. right: 0,
  533. top: 0,
  534. width: 14
  535. },
  536. buttonSkip: {
  537. ...buttonBase,
  538. color: options.textColor,
  539. fontSize: 14
  540. },
  541. overlay: {
  542. ...overlay,
  543. backgroundColor: options.overlayColor,
  544. mixBlendMode: "hard-light"
  545. },
  546. overlayLegacy: {
  547. ...overlay
  548. },
  549. overlayLegacyCenter: {
  550. ...overlay,
  551. backgroundColor: options.overlayColor
  552. },
  553. spotlight: {
  554. ...spotlight,
  555. backgroundColor: "gray"
  556. },
  557. spotlightLegacy: {
  558. ...spotlight,
  559. boxShadow: `0 0 0 9999px ${options.overlayColor}, ${options.spotlightShadow}`
  560. },
  561. floaterStyles: {
  562. arrow: {
  563. color: options.arrowColor
  564. },
  565. options: {
  566. zIndex: options.zIndex + 100
  567. }
  568. },
  569. options
  570. };
  571. return (0, import_deepmerge.default)(defaultStyles, mergedStyles);
  572. }
  573. // src/modules/step.ts
  574. function getTourProps(props) {
  575. return (0, import_helpers3.pick)(
  576. props,
  577. "beaconComponent",
  578. "disableCloseOnEsc",
  579. "disableOverlay",
  580. "disableOverlayClose",
  581. "disableScrolling",
  582. "disableScrollParentFix",
  583. "floaterProps",
  584. "hideBackButton",
  585. "hideCloseButton",
  586. "locale",
  587. "showProgress",
  588. "showSkipButton",
  589. "spotlightClicks",
  590. "spotlightPadding",
  591. "styles",
  592. "tooltipComponent"
  593. );
  594. }
  595. function getMergedStep(currentStep, props) {
  596. var _a, _b, _c, _d, _e, _f;
  597. const step = currentStep != null ? currentStep : {};
  598. const mergedStep = import_deepmerge2.default.all([defaultStep, getTourProps(props), step], {
  599. isMergeableObject: import_is_lite2.default.plainObject
  600. });
  601. const mergedStyles = getStyles(props.styles, mergedStep.styles);
  602. const scrollParent2 = hasCustomScrollParent(
  603. getElement(mergedStep.target),
  604. mergedStep.disableScrollParentFix
  605. );
  606. const floaterProps = import_deepmerge2.default.all([
  607. defaultFloaterProps,
  608. (_a = props.floaterProps) != null ? _a : {},
  609. (_b = mergedStep.floaterProps) != null ? _b : {}
  610. ]);
  611. floaterProps.offset = mergedStep.offset;
  612. floaterProps.styles = (0, import_deepmerge2.default)((_c = floaterProps.styles) != null ? _c : {}, mergedStyles.floaterStyles);
  613. floaterProps.offset += (_e = (_d = props.spotlightPadding) != null ? _d : mergedStep.spotlightPadding) != null ? _e : 0;
  614. if (mergedStep.placementBeacon && floaterProps.wrapperOptions) {
  615. floaterProps.wrapperOptions.placement = mergedStep.placementBeacon;
  616. }
  617. if (scrollParent2 && floaterProps.options.preventOverflow) {
  618. floaterProps.options.preventOverflow.boundariesElement = "window";
  619. }
  620. return {
  621. ...mergedStep,
  622. locale: import_deepmerge2.default.all([defaultLocale, (_f = props.locale) != null ? _f : {}, mergedStep.locale || {}]),
  623. floaterProps,
  624. styles: (0, import_helpers3.omit)(mergedStyles, "floaterStyles")
  625. };
  626. }
  627. function validateStep(step, debug = false) {
  628. if (!import_is_lite2.default.plainObject(step)) {
  629. log({
  630. title: "validateStep",
  631. data: "step must be an object",
  632. warn: true,
  633. debug
  634. });
  635. return false;
  636. }
  637. if (!step.target) {
  638. log({
  639. title: "validateStep",
  640. data: "target is missing from the step",
  641. warn: true,
  642. debug
  643. });
  644. return false;
  645. }
  646. return true;
  647. }
  648. function validateSteps(steps, debug = false) {
  649. if (!import_is_lite2.default.array(steps)) {
  650. log({
  651. title: "validateSteps",
  652. data: "steps must be an array",
  653. warn: true,
  654. debug
  655. });
  656. return false;
  657. }
  658. return steps.every((d) => validateStep(d, debug));
  659. }
  660. // src/modules/store.ts
  661. var import_is_lite3 = __toESM(require("is-lite"));
  662. var defaultState = {
  663. action: "init",
  664. controlled: false,
  665. index: 0,
  666. lifecycle: LIFECYCLE.INIT,
  667. size: 0,
  668. status: STATUS.IDLE
  669. };
  670. var validKeys = ["action", "index", "lifecycle", "status"];
  671. var Store = class {
  672. constructor(options) {
  673. __publicField(this, "beaconPopper");
  674. __publicField(this, "tooltipPopper");
  675. __publicField(this, "data", /* @__PURE__ */ new Map());
  676. __publicField(this, "listener");
  677. __publicField(this, "store", /* @__PURE__ */ new Map());
  678. __publicField(this, "addListener", (listener) => {
  679. this.listener = listener;
  680. });
  681. __publicField(this, "setSteps", (steps) => {
  682. const { size, status } = this.getState();
  683. const state = {
  684. size: steps.length,
  685. status
  686. };
  687. this.data.set("steps", steps);
  688. if (status === STATUS.WAITING && !size && steps.length) {
  689. state.status = STATUS.RUNNING;
  690. }
  691. this.setState(state);
  692. });
  693. __publicField(this, "getPopper", (name) => {
  694. if (name === "beacon") {
  695. return this.beaconPopper;
  696. }
  697. return this.tooltipPopper;
  698. });
  699. __publicField(this, "setPopper", (name, popper) => {
  700. if (name === "beacon") {
  701. this.beaconPopper = popper;
  702. } else {
  703. this.tooltipPopper = popper;
  704. }
  705. });
  706. __publicField(this, "cleanupPoppers", () => {
  707. this.beaconPopper = null;
  708. this.tooltipPopper = null;
  709. });
  710. __publicField(this, "close", () => {
  711. const { index, status } = this.getState();
  712. if (status !== STATUS.RUNNING) {
  713. return;
  714. }
  715. this.setState({
  716. ...this.getNextState({ action: ACTIONS.CLOSE, index: index + 1 })
  717. });
  718. });
  719. __publicField(this, "go", (nextIndex) => {
  720. const { controlled, status } = this.getState();
  721. if (controlled || status !== STATUS.RUNNING) {
  722. return;
  723. }
  724. const step = this.getSteps()[nextIndex];
  725. this.setState({
  726. ...this.getNextState({ action: ACTIONS.GO, index: nextIndex }),
  727. status: step ? status : STATUS.FINISHED
  728. });
  729. });
  730. __publicField(this, "info", () => this.getState());
  731. __publicField(this, "next", () => {
  732. const { index, status } = this.getState();
  733. if (status !== STATUS.RUNNING) {
  734. return;
  735. }
  736. this.setState(this.getNextState({ action: ACTIONS.NEXT, index: index + 1 }));
  737. });
  738. __publicField(this, "open", () => {
  739. const { status } = this.getState();
  740. if (status !== STATUS.RUNNING) {
  741. return;
  742. }
  743. this.setState({
  744. ...this.getNextState({ action: ACTIONS.UPDATE, lifecycle: LIFECYCLE.TOOLTIP })
  745. });
  746. });
  747. __publicField(this, "prev", () => {
  748. const { index, status } = this.getState();
  749. if (status !== STATUS.RUNNING) {
  750. return;
  751. }
  752. this.setState({
  753. ...this.getNextState({ action: ACTIONS.PREV, index: index - 1 })
  754. });
  755. });
  756. __publicField(this, "reset", (restart = false) => {
  757. const { controlled } = this.getState();
  758. if (controlled) {
  759. return;
  760. }
  761. this.setState({
  762. ...this.getNextState({ action: ACTIONS.RESET, index: 0 }),
  763. status: restart ? STATUS.RUNNING : STATUS.READY
  764. });
  765. });
  766. __publicField(this, "skip", () => {
  767. const { status } = this.getState();
  768. if (status !== STATUS.RUNNING) {
  769. return;
  770. }
  771. this.setState({
  772. action: ACTIONS.SKIP,
  773. lifecycle: LIFECYCLE.INIT,
  774. status: STATUS.SKIPPED
  775. });
  776. });
  777. __publicField(this, "start", (nextIndex) => {
  778. const { index, size } = this.getState();
  779. this.setState({
  780. ...this.getNextState(
  781. {
  782. action: ACTIONS.START,
  783. index: import_is_lite3.default.number(nextIndex) ? nextIndex : index
  784. },
  785. true
  786. ),
  787. status: size ? STATUS.RUNNING : STATUS.WAITING
  788. });
  789. });
  790. __publicField(this, "stop", (advance = false) => {
  791. const { index, status } = this.getState();
  792. if ([STATUS.FINISHED, STATUS.SKIPPED].includes(status)) {
  793. return;
  794. }
  795. this.setState({
  796. ...this.getNextState({ action: ACTIONS.STOP, index: index + (advance ? 1 : 0) }),
  797. status: STATUS.PAUSED
  798. });
  799. });
  800. __publicField(this, "update", (state) => {
  801. var _a;
  802. if (!hasValidKeys(state, validKeys)) {
  803. throw new Error(`State is not valid. Valid keys: ${validKeys.join(", ")}`);
  804. }
  805. this.setState({
  806. ...this.getNextState(
  807. {
  808. ...this.getState(),
  809. ...state,
  810. action: (_a = state.action) != null ? _a : ACTIONS.UPDATE
  811. },
  812. true
  813. )
  814. });
  815. });
  816. const { continuous = false, stepIndex, steps = [] } = options != null ? options : {};
  817. this.setState(
  818. {
  819. action: ACTIONS.INIT,
  820. controlled: import_is_lite3.default.number(stepIndex),
  821. continuous,
  822. index: import_is_lite3.default.number(stepIndex) ? stepIndex : 0,
  823. lifecycle: LIFECYCLE.INIT,
  824. status: steps.length ? STATUS.READY : STATUS.IDLE
  825. },
  826. true
  827. );
  828. this.beaconPopper = null;
  829. this.tooltipPopper = null;
  830. this.listener = null;
  831. this.setSteps(steps);
  832. }
  833. getState() {
  834. if (!this.store.size) {
  835. return { ...defaultState };
  836. }
  837. return {
  838. action: this.store.get("action") || "",
  839. controlled: this.store.get("controlled") || false,
  840. index: parseInt(this.store.get("index"), 10),
  841. lifecycle: this.store.get("lifecycle") || "",
  842. size: this.store.get("size") || 0,
  843. status: this.store.get("status") || ""
  844. };
  845. }
  846. getNextState(state, force = false) {
  847. var _a, _b, _c, _d;
  848. const { action, controlled, index, size, status } = this.getState();
  849. const newIndex = import_is_lite3.default.number(state.index) ? state.index : index;
  850. const nextIndex = controlled && !force ? index : Math.min(Math.max(newIndex, 0), size);
  851. return {
  852. action: (_a = state.action) != null ? _a : action,
  853. controlled,
  854. index: nextIndex,
  855. lifecycle: (_b = state.lifecycle) != null ? _b : LIFECYCLE.INIT,
  856. size: (_c = state.size) != null ? _c : size,
  857. status: nextIndex === size ? STATUS.FINISHED : (_d = state.status) != null ? _d : status
  858. };
  859. }
  860. getSteps() {
  861. const steps = this.data.get("steps");
  862. return Array.isArray(steps) ? steps : [];
  863. }
  864. hasUpdatedState(oldState) {
  865. const before = JSON.stringify(oldState);
  866. const after = JSON.stringify(this.getState());
  867. return before !== after;
  868. }
  869. setState(nextState, initial = false) {
  870. const state = this.getState();
  871. const { action, index, lifecycle, size, status } = {
  872. ...state,
  873. ...nextState
  874. };
  875. this.store.set("action", action);
  876. this.store.set("index", index);
  877. this.store.set("lifecycle", lifecycle);
  878. this.store.set("size", size);
  879. this.store.set("status", status);
  880. if (initial) {
  881. this.store.set("controlled", nextState.controlled);
  882. this.store.set("continuous", nextState.continuous);
  883. }
  884. if (this.listener && this.hasUpdatedState(state)) {
  885. this.listener(this.getState());
  886. }
  887. }
  888. getHelpers() {
  889. return {
  890. close: this.close,
  891. go: this.go,
  892. info: this.info,
  893. next: this.next,
  894. open: this.open,
  895. prev: this.prev,
  896. reset: this.reset,
  897. skip: this.skip
  898. };
  899. }
  900. };
  901. function createStore(options) {
  902. return new Store(options);
  903. }
  904. // src/components/Step.tsx
  905. var React8 = __toESM(require("react"));
  906. var import_react_floater = __toESM(require("react-floater"));
  907. var import_is_lite5 = __toESM(require("is-lite"));
  908. var import_tree_changes2 = __toESM(require("tree-changes"));
  909. // src/modules/scope.ts
  910. var Scope = class {
  911. constructor(element, options) {
  912. __publicField(this, "element");
  913. __publicField(this, "options");
  914. __publicField(this, "canBeTabbed", (element) => {
  915. const { tabIndex } = element;
  916. if (tabIndex === null || tabIndex < 0) {
  917. return false;
  918. }
  919. return this.canHaveFocus(element);
  920. });
  921. __publicField(this, "canHaveFocus", (element) => {
  922. const validTabNodes = /input|select|textarea|button|object/;
  923. const nodeName = element.nodeName.toLowerCase();
  924. const isValid = validTabNodes.test(nodeName) && !element.getAttribute("disabled") || nodeName === "a" && !!element.getAttribute("href");
  925. return isValid && this.isVisible(element);
  926. });
  927. __publicField(this, "findValidTabElements", () => [].slice.call(this.element.querySelectorAll("*"), 0).filter(this.canBeTabbed));
  928. __publicField(this, "handleKeyDown", (event) => {
  929. const { code = "Tab" } = this.options;
  930. if (event.code === code) {
  931. this.interceptTab(event);
  932. }
  933. });
  934. __publicField(this, "interceptTab", (event) => {
  935. event.preventDefault();
  936. const elements = this.findValidTabElements();
  937. const { shiftKey } = event;
  938. if (!elements.length) {
  939. return;
  940. }
  941. let x = document.activeElement ? elements.indexOf(document.activeElement) : 0;
  942. if (x === -1 || !shiftKey && x + 1 === elements.length) {
  943. x = 0;
  944. } else if (shiftKey && x === 0) {
  945. x = elements.length - 1;
  946. } else {
  947. x += shiftKey ? -1 : 1;
  948. }
  949. elements[x].focus();
  950. });
  951. // eslint-disable-next-line class-methods-use-this
  952. __publicField(this, "isHidden", (element) => {
  953. const noSize = element.offsetWidth <= 0 && element.offsetHeight <= 0;
  954. const style = window.getComputedStyle(element);
  955. if (noSize && !element.innerHTML) {
  956. return true;
  957. }
  958. return noSize && style.getPropertyValue("overflow") !== "visible" || style.getPropertyValue("display") === "none";
  959. });
  960. __publicField(this, "isVisible", (element) => {
  961. let parentElement = element;
  962. while (parentElement) {
  963. if (parentElement instanceof HTMLElement) {
  964. if (parentElement === document.body) {
  965. break;
  966. }
  967. if (this.isHidden(parentElement)) {
  968. return false;
  969. }
  970. parentElement = parentElement.parentNode;
  971. }
  972. }
  973. return true;
  974. });
  975. __publicField(this, "removeScope", () => {
  976. window.removeEventListener("keydown", this.handleKeyDown);
  977. });
  978. __publicField(this, "checkFocus", (target) => {
  979. if (document.activeElement !== target) {
  980. target.focus();
  981. window.requestAnimationFrame(() => this.checkFocus(target));
  982. }
  983. });
  984. __publicField(this, "setFocus", () => {
  985. const { selector } = this.options;
  986. if (!selector) {
  987. return;
  988. }
  989. const target = this.element.querySelector(selector);
  990. if (target) {
  991. window.requestAnimationFrame(() => this.checkFocus(target));
  992. }
  993. });
  994. if (!(element instanceof HTMLElement)) {
  995. throw new TypeError("Invalid parameter: element must be an HTMLElement");
  996. }
  997. this.element = element;
  998. this.options = options;
  999. window.addEventListener("keydown", this.handleKeyDown, false);
  1000. this.setFocus();
  1001. }
  1002. };
  1003. // src/components/Beacon.tsx
  1004. var React = __toESM(require("react"));
  1005. var import_react_innertext = __toESM(require("react-innertext"));
  1006. var import_is_lite4 = __toESM(require("is-lite"));
  1007. var JoyrideBeacon = class extends React.Component {
  1008. constructor(props) {
  1009. super(props);
  1010. __publicField(this, "beacon", null);
  1011. __publicField(this, "setBeaconRef", (c) => {
  1012. this.beacon = c;
  1013. });
  1014. if (props.beaconComponent) {
  1015. return;
  1016. }
  1017. const head = document.head || document.getElementsByTagName("head")[0];
  1018. const style = document.createElement("style");
  1019. style.id = "joyride-beacon-animation";
  1020. if (props.nonce) {
  1021. style.setAttribute("nonce", props.nonce);
  1022. }
  1023. const css = `
  1024. @keyframes joyride-beacon-inner {
  1025. 20% {
  1026. opacity: 0.9;
  1027. }
  1028. 90% {
  1029. opacity: 0.7;
  1030. }
  1031. }
  1032. @keyframes joyride-beacon-outer {
  1033. 0% {
  1034. transform: scale(1);
  1035. }
  1036. 45% {
  1037. opacity: 0.7;
  1038. transform: scale(0.75);
  1039. }
  1040. 100% {
  1041. opacity: 0.9;
  1042. transform: scale(1);
  1043. }
  1044. }
  1045. `;
  1046. style.appendChild(document.createTextNode(css));
  1047. head.appendChild(style);
  1048. }
  1049. componentDidMount() {
  1050. const { shouldFocus } = this.props;
  1051. if (process.env.NODE_ENV !== "production") {
  1052. if (!import_is_lite4.default.domElement(this.beacon)) {
  1053. console.warn("beacon is not a valid DOM element");
  1054. }
  1055. }
  1056. setTimeout(() => {
  1057. if (import_is_lite4.default.domElement(this.beacon) && shouldFocus) {
  1058. this.beacon.focus();
  1059. }
  1060. }, 0);
  1061. }
  1062. componentWillUnmount() {
  1063. const style = document.getElementById("joyride-beacon-animation");
  1064. if (style == null ? void 0 : style.parentNode) {
  1065. style.parentNode.removeChild(style);
  1066. }
  1067. }
  1068. render() {
  1069. const {
  1070. beaconComponent,
  1071. continuous,
  1072. index,
  1073. isLastStep,
  1074. locale,
  1075. onClickOrHover,
  1076. size,
  1077. step,
  1078. styles
  1079. } = this.props;
  1080. const title = import_is_lite4.default.string(locale.open) ? locale.open : (0, import_react_innertext.default)(locale.open);
  1081. const sharedProps = {
  1082. "aria-label": title,
  1083. onClick: onClickOrHover,
  1084. onMouseEnter: onClickOrHover,
  1085. ref: this.setBeaconRef,
  1086. title
  1087. };
  1088. let component;
  1089. if (beaconComponent) {
  1090. const BeaconComponent = beaconComponent;
  1091. component = /* @__PURE__ */ React.createElement(
  1092. BeaconComponent,
  1093. {
  1094. continuous,
  1095. index,
  1096. isLastStep,
  1097. size,
  1098. step,
  1099. ...sharedProps
  1100. }
  1101. );
  1102. } else {
  1103. component = /* @__PURE__ */ React.createElement(
  1104. "button",
  1105. {
  1106. key: "JoyrideBeacon",
  1107. className: "react-joyride__beacon",
  1108. "data-test-id": "button-beacon",
  1109. style: styles.beacon,
  1110. type: "button",
  1111. ...sharedProps
  1112. },
  1113. /* @__PURE__ */ React.createElement("span", { style: styles.beaconInner }),
  1114. /* @__PURE__ */ React.createElement("span", { style: styles.beaconOuter })
  1115. );
  1116. }
  1117. return component;
  1118. }
  1119. };
  1120. // src/components/Overlay.tsx
  1121. var React3 = __toESM(require("react"));
  1122. var import_tree_changes = __toESM(require("tree-changes"));
  1123. // src/components/Spotlight.tsx
  1124. var React2 = __toESM(require("react"));
  1125. function JoyrideSpotlight({ styles }) {
  1126. return /* @__PURE__ */ React2.createElement(
  1127. "div",
  1128. {
  1129. key: "JoyrideSpotlight",
  1130. className: "react-joyride__spotlight",
  1131. "data-test-id": "spotlight",
  1132. style: styles
  1133. }
  1134. );
  1135. }
  1136. var Spotlight_default = JoyrideSpotlight;
  1137. // src/components/Overlay.tsx
  1138. var JoyrideOverlay = class extends React3.Component {
  1139. constructor() {
  1140. super(...arguments);
  1141. __publicField(this, "isActive", false);
  1142. __publicField(this, "resizeTimeout");
  1143. __publicField(this, "scrollTimeout");
  1144. __publicField(this, "scrollParent");
  1145. __publicField(this, "state", {
  1146. isScrolling: false,
  1147. mouseOverSpotlight: false,
  1148. showSpotlight: true
  1149. });
  1150. __publicField(this, "handleMouseMove", (event) => {
  1151. const { mouseOverSpotlight } = this.state;
  1152. const { height, left, position, top, width } = this.spotlightStyles;
  1153. const offsetY = position === "fixed" ? event.clientY : event.pageY;
  1154. const offsetX = position === "fixed" ? event.clientX : event.pageX;
  1155. const inSpotlightHeight = offsetY >= top && offsetY <= top + height;
  1156. const inSpotlightWidth = offsetX >= left && offsetX <= left + width;
  1157. const inSpotlight = inSpotlightWidth && inSpotlightHeight;
  1158. if (inSpotlight !== mouseOverSpotlight) {
  1159. this.updateState({ mouseOverSpotlight: inSpotlight });
  1160. }
  1161. });
  1162. __publicField(this, "handleScroll", () => {
  1163. const { target } = this.props;
  1164. const element = getElement(target);
  1165. if (this.scrollParent !== document) {
  1166. const { isScrolling } = this.state;
  1167. if (!isScrolling) {
  1168. this.updateState({ isScrolling: true, showSpotlight: false });
  1169. }
  1170. clearTimeout(this.scrollTimeout);
  1171. this.scrollTimeout = window.setTimeout(() => {
  1172. this.updateState({ isScrolling: false, showSpotlight: true });
  1173. }, 50);
  1174. } else if (hasPosition(element, "sticky")) {
  1175. this.updateState({});
  1176. }
  1177. });
  1178. __publicField(this, "handleResize", () => {
  1179. clearTimeout(this.resizeTimeout);
  1180. this.resizeTimeout = window.setTimeout(() => {
  1181. if (!this.isActive) {
  1182. return;
  1183. }
  1184. this.forceUpdate();
  1185. }, 100);
  1186. });
  1187. }
  1188. componentDidMount() {
  1189. const { debug, disableScrolling, disableScrollParentFix = false, target } = this.props;
  1190. const element = getElement(target);
  1191. this.scrollParent = getScrollParent(element != null ? element : document.body, disableScrollParentFix, true);
  1192. this.isActive = true;
  1193. if (process.env.NODE_ENV !== "production") {
  1194. if (!disableScrolling && hasCustomScrollParent(element, true)) {
  1195. log({
  1196. title: "step has a custom scroll parent and can cause trouble with scrolling",
  1197. data: [{ key: "parent", value: this.scrollParent }],
  1198. debug
  1199. });
  1200. }
  1201. }
  1202. window.addEventListener("resize", this.handleResize);
  1203. }
  1204. componentDidUpdate(previousProps) {
  1205. var _a;
  1206. const { lifecycle, spotlightClicks } = this.props;
  1207. const { changed } = (0, import_tree_changes.default)(previousProps, this.props);
  1208. if (changed("lifecycle", LIFECYCLE.TOOLTIP)) {
  1209. (_a = this.scrollParent) == null ? void 0 : _a.addEventListener("scroll", this.handleScroll, { passive: true });
  1210. setTimeout(() => {
  1211. const { isScrolling } = this.state;
  1212. if (!isScrolling) {
  1213. this.updateState({ showSpotlight: true });
  1214. }
  1215. }, 100);
  1216. }
  1217. if (changed("spotlightClicks") || changed("disableOverlay") || changed("lifecycle")) {
  1218. if (spotlightClicks && lifecycle === LIFECYCLE.TOOLTIP) {
  1219. window.addEventListener("mousemove", this.handleMouseMove, false);
  1220. } else if (lifecycle !== LIFECYCLE.TOOLTIP) {
  1221. window.removeEventListener("mousemove", this.handleMouseMove);
  1222. }
  1223. }
  1224. }
  1225. componentWillUnmount() {
  1226. var _a;
  1227. this.isActive = false;
  1228. window.removeEventListener("mousemove", this.handleMouseMove);
  1229. window.removeEventListener("resize", this.handleResize);
  1230. clearTimeout(this.resizeTimeout);
  1231. clearTimeout(this.scrollTimeout);
  1232. (_a = this.scrollParent) == null ? void 0 : _a.removeEventListener("scroll", this.handleScroll);
  1233. }
  1234. get spotlightStyles() {
  1235. var _a, _b, _c;
  1236. const { showSpotlight } = this.state;
  1237. const {
  1238. disableScrollParentFix = false,
  1239. spotlightClicks,
  1240. spotlightPadding = 0,
  1241. styles,
  1242. target
  1243. } = this.props;
  1244. const element = getElement(target);
  1245. const elementRect = getClientRect(element);
  1246. const isFixedTarget = hasPosition(element);
  1247. const top = getElementPosition(element, spotlightPadding, disableScrollParentFix);
  1248. return {
  1249. ...isLegacy() ? styles.spotlightLegacy : styles.spotlight,
  1250. height: Math.round(((_a = elementRect == null ? void 0 : elementRect.height) != null ? _a : 0) + spotlightPadding * 2),
  1251. left: Math.round(((_b = elementRect == null ? void 0 : elementRect.left) != null ? _b : 0) - spotlightPadding),
  1252. opacity: showSpotlight ? 1 : 0,
  1253. pointerEvents: spotlightClicks ? "none" : "auto",
  1254. position: isFixedTarget ? "fixed" : "absolute",
  1255. top,
  1256. transition: "opacity 0.2s",
  1257. width: Math.round(((_c = elementRect == null ? void 0 : elementRect.width) != null ? _c : 0) + spotlightPadding * 2)
  1258. };
  1259. }
  1260. updateState(state) {
  1261. if (!this.isActive) {
  1262. return;
  1263. }
  1264. this.setState((previousState) => ({ ...previousState, ...state }));
  1265. }
  1266. render() {
  1267. const { mouseOverSpotlight, showSpotlight } = this.state;
  1268. const { disableOverlay, disableOverlayClose, lifecycle, onClickOverlay, placement, styles } = this.props;
  1269. if (disableOverlay || lifecycle !== LIFECYCLE.TOOLTIP) {
  1270. return null;
  1271. }
  1272. let baseStyles = styles.overlay;
  1273. if (isLegacy()) {
  1274. baseStyles = placement === "center" ? styles.overlayLegacyCenter : styles.overlayLegacy;
  1275. }
  1276. const stylesOverlay = {
  1277. cursor: disableOverlayClose ? "default" : "pointer",
  1278. height: getDocumentHeight(),
  1279. pointerEvents: mouseOverSpotlight ? "none" : "auto",
  1280. ...baseStyles
  1281. };
  1282. let spotlight2 = placement !== "center" && showSpotlight && /* @__PURE__ */ React3.createElement(Spotlight_default, { styles: this.spotlightStyles });
  1283. if (getBrowser() === "safari") {
  1284. const { mixBlendMode, zIndex, ...safarOverlay } = stylesOverlay;
  1285. spotlight2 = /* @__PURE__ */ React3.createElement("div", { style: { ...safarOverlay } }, spotlight2);
  1286. delete stylesOverlay.backgroundColor;
  1287. }
  1288. return /* @__PURE__ */ React3.createElement(
  1289. "div",
  1290. {
  1291. className: "react-joyride__overlay",
  1292. "data-test-id": "overlay",
  1293. onClick: onClickOverlay,
  1294. role: "presentation",
  1295. style: stylesOverlay
  1296. },
  1297. spotlight2
  1298. );
  1299. }
  1300. };
  1301. // src/components/Portal.tsx
  1302. var React4 = __toESM(require("react"));
  1303. var ReactDOM = __toESM(require("react-dom"));
  1304. var JoyridePortal = class extends React4.Component {
  1305. constructor() {
  1306. super(...arguments);
  1307. __publicField(this, "node", null);
  1308. }
  1309. componentDidMount() {
  1310. const { id } = this.props;
  1311. if (!canUseDOM()) {
  1312. return;
  1313. }
  1314. this.node = document.createElement("div");
  1315. this.node.id = id;
  1316. document.body.appendChild(this.node);
  1317. if (!isReact16) {
  1318. this.renderReact15();
  1319. }
  1320. }
  1321. componentDidUpdate() {
  1322. if (!canUseDOM()) {
  1323. return;
  1324. }
  1325. if (!isReact16) {
  1326. this.renderReact15();
  1327. }
  1328. }
  1329. componentWillUnmount() {
  1330. if (!canUseDOM() || !this.node) {
  1331. return;
  1332. }
  1333. if (!isReact16) {
  1334. ReactDOM.unmountComponentAtNode(this.node);
  1335. }
  1336. if (this.node.parentNode === document.body) {
  1337. document.body.removeChild(this.node);
  1338. this.node = null;
  1339. }
  1340. }
  1341. renderReact15() {
  1342. if (!canUseDOM()) {
  1343. return;
  1344. }
  1345. const { children } = this.props;
  1346. if (this.node) {
  1347. ReactDOM.unstable_renderSubtreeIntoContainer(this, children, this.node);
  1348. }
  1349. }
  1350. renderReact16() {
  1351. if (!canUseDOM() || !isReact16) {
  1352. return null;
  1353. }
  1354. const { children } = this.props;
  1355. if (!this.node) {
  1356. return null;
  1357. }
  1358. return ReactDOM.createPortal(children, this.node);
  1359. }
  1360. render() {
  1361. if (!isReact16) {
  1362. return null;
  1363. }
  1364. return this.renderReact16();
  1365. }
  1366. };
  1367. // src/components/Tooltip/index.tsx
  1368. var React7 = __toESM(require("react"));
  1369. // src/components/Tooltip/Container.tsx
  1370. var React6 = __toESM(require("react"));
  1371. // src/components/Tooltip/CloseButton.tsx
  1372. var import_react2 = __toESM(require("react"));
  1373. function JoyrideTooltipCloseButton({ styles, ...props }) {
  1374. const { color, height, width, ...style } = styles;
  1375. return /* @__PURE__ */ import_react2.default.createElement("button", { style, type: "button", ...props }, /* @__PURE__ */ import_react2.default.createElement(
  1376. "svg",
  1377. {
  1378. height: typeof height === "number" ? `${height}px` : height,
  1379. preserveAspectRatio: "xMidYMid",
  1380. version: "1.1",
  1381. viewBox: "0 0 18 18",
  1382. width: typeof width === "number" ? `${width}px` : width,
  1383. xmlns: "http://www.w3.org/2000/svg"
  1384. },
  1385. /* @__PURE__ */ import_react2.default.createElement("g", null, /* @__PURE__ */ import_react2.default.createElement(
  1386. "path",
  1387. {
  1388. d: "M8.13911129,9.00268191 L0.171521827,17.0258467 C-0.0498027049,17.248715 -0.0498027049,17.6098394 0.171521827,17.8327545 C0.28204354,17.9443526 0.427188206,17.9998706 0.572051765,17.9998706 C0.71714958,17.9998706 0.862013139,17.9443526 0.972581703,17.8327545 L9.0000937,9.74924618 L17.0276057,17.8327545 C17.1384085,17.9443526 17.2832721,17.9998706 17.4281356,17.9998706 C17.5729992,17.9998706 17.718097,17.9443526 17.8286656,17.8327545 C18.0499901,17.6098862 18.0499901,17.2487618 17.8286656,17.0258467 L9.86135722,9.00268191 L17.8340066,0.973848225 C18.0553311,0.750979934 18.0553311,0.389855532 17.8340066,0.16694039 C17.6126821,-0.0556467968 17.254037,-0.0556467968 17.0329467,0.16694039 L9.00042166,8.25611765 L0.967006424,0.167268345 C0.745681892,-0.0553188426 0.387317931,-0.0553188426 0.165993399,0.167268345 C-0.0553311331,0.390136635 -0.0553311331,0.751261038 0.165993399,0.974176179 L8.13920499,9.00268191 L8.13911129,9.00268191 Z",
  1389. fill: color
  1390. }
  1391. ))
  1392. ));
  1393. }
  1394. var CloseButton_default = JoyrideTooltipCloseButton;
  1395. // src/components/Tooltip/Container.tsx
  1396. function JoyrideTooltipContainer(props) {
  1397. const {
  1398. backProps,
  1399. closeProps,
  1400. continuous,
  1401. index,
  1402. isLastStep,
  1403. primaryProps,
  1404. size,
  1405. skipProps,
  1406. step,
  1407. tooltipProps
  1408. } = props;
  1409. const {
  1410. content,
  1411. hideBackButton,
  1412. hideCloseButton,
  1413. hideFooter,
  1414. locale,
  1415. showProgress,
  1416. showSkipButton,
  1417. styles,
  1418. title
  1419. } = step;
  1420. const { back, close, last, next, skip } = locale;
  1421. const output = {
  1422. primary: close
  1423. };
  1424. if (continuous) {
  1425. output.primary = isLastStep ? last : next;
  1426. if (showProgress) {
  1427. output.primary = /* @__PURE__ */ React6.createElement("span", null, output.primary, " (", index + 1, "/", size, ")");
  1428. }
  1429. }
  1430. if (showSkipButton && !isLastStep) {
  1431. output.skip = /* @__PURE__ */ React6.createElement(
  1432. "button",
  1433. {
  1434. "aria-live": "off",
  1435. "data-test-id": "button-skip",
  1436. style: styles.buttonSkip,
  1437. type: "button",
  1438. ...skipProps
  1439. },
  1440. skip
  1441. );
  1442. }
  1443. if (!hideBackButton && index > 0) {
  1444. output.back = /* @__PURE__ */ React6.createElement("button", { "data-test-id": "button-back", style: styles.buttonBack, type: "button", ...backProps }, back);
  1445. }
  1446. output.close = !hideCloseButton && /* @__PURE__ */ React6.createElement(CloseButton_default, { "data-test-id": "button-close", styles: styles.buttonClose, ...closeProps });
  1447. return /* @__PURE__ */ React6.createElement(
  1448. "div",
  1449. {
  1450. key: "JoyrideTooltip",
  1451. "aria-label": getText(title) || getText(content),
  1452. className: "react-joyride__tooltip",
  1453. style: styles.tooltip,
  1454. ...tooltipProps
  1455. },
  1456. /* @__PURE__ */ React6.createElement("div", { style: styles.tooltipContainer }, title && /* @__PURE__ */ React6.createElement("h1", { "aria-label": getText(title), style: styles.tooltipTitle }, title), /* @__PURE__ */ React6.createElement("div", { style: styles.tooltipContent }, content)),
  1457. !hideFooter && /* @__PURE__ */ React6.createElement("div", { style: styles.tooltipFooter }, /* @__PURE__ */ React6.createElement("div", { style: styles.tooltipFooterSpacer }, output.skip), output.back, /* @__PURE__ */ React6.createElement(
  1458. "button",
  1459. {
  1460. "data-test-id": "button-primary",
  1461. style: styles.buttonNext,
  1462. type: "button",
  1463. ...primaryProps
  1464. },
  1465. output.primary
  1466. )),
  1467. output.close
  1468. );
  1469. }
  1470. var Container_default = JoyrideTooltipContainer;
  1471. // src/components/Tooltip/index.tsx
  1472. var JoyrideTooltip = class extends React7.Component {
  1473. constructor() {
  1474. super(...arguments);
  1475. __publicField(this, "handleClickBack", (event) => {
  1476. event.preventDefault();
  1477. const { helpers } = this.props;
  1478. helpers.prev();
  1479. });
  1480. __publicField(this, "handleClickClose", (event) => {
  1481. event.preventDefault();
  1482. const { helpers } = this.props;
  1483. helpers.close();
  1484. });
  1485. __publicField(this, "handleClickPrimary", (event) => {
  1486. event.preventDefault();
  1487. const { continuous, helpers } = this.props;
  1488. if (!continuous) {
  1489. helpers.close();
  1490. return;
  1491. }
  1492. helpers.next();
  1493. });
  1494. __publicField(this, "handleClickSkip", (event) => {
  1495. event.preventDefault();
  1496. const { helpers } = this.props;
  1497. helpers.skip();
  1498. });
  1499. __publicField(this, "getElementsProps", () => {
  1500. const { continuous, isLastStep, setTooltipRef, step } = this.props;
  1501. const back = getText(step.locale.back);
  1502. const close = getText(step.locale.close);
  1503. const last = getText(step.locale.last);
  1504. const next = getText(step.locale.next);
  1505. const skip = getText(step.locale.skip);
  1506. let primaryText = continuous ? next : close;
  1507. if (isLastStep) {
  1508. primaryText = last;
  1509. }
  1510. return {
  1511. backProps: {
  1512. "aria-label": back,
  1513. "data-action": "back",
  1514. onClick: this.handleClickBack,
  1515. role: "button",
  1516. title: back
  1517. },
  1518. closeProps: {
  1519. "aria-label": close,
  1520. "data-action": "close",
  1521. onClick: this.handleClickClose,
  1522. role: "button",
  1523. title: close
  1524. },
  1525. primaryProps: {
  1526. "aria-label": primaryText,
  1527. "data-action": "primary",
  1528. onClick: this.handleClickPrimary,
  1529. role: "button",
  1530. title: primaryText
  1531. },
  1532. skipProps: {
  1533. "aria-label": skip,
  1534. "data-action": "skip",
  1535. onClick: this.handleClickSkip,
  1536. role: "button",
  1537. title: skip
  1538. },
  1539. tooltipProps: {
  1540. "aria-modal": true,
  1541. ref: setTooltipRef,
  1542. role: "alertdialog"
  1543. }
  1544. };
  1545. });
  1546. }
  1547. render() {
  1548. const { continuous, index, isLastStep, setTooltipRef, size, step } = this.props;
  1549. const { beaconComponent, tooltipComponent, ...cleanStep } = step;
  1550. let component;
  1551. if (tooltipComponent) {
  1552. const renderProps = {
  1553. ...this.getElementsProps(),
  1554. continuous,
  1555. index,
  1556. isLastStep,
  1557. size,
  1558. step: cleanStep,
  1559. setTooltipRef
  1560. };
  1561. const TooltipComponent = tooltipComponent;
  1562. component = /* @__PURE__ */ React7.createElement(TooltipComponent, { ...renderProps });
  1563. } else {
  1564. component = /* @__PURE__ */ React7.createElement(
  1565. Container_default,
  1566. {
  1567. ...this.getElementsProps(),
  1568. continuous,
  1569. index,
  1570. isLastStep,
  1571. size,
  1572. step
  1573. }
  1574. );
  1575. }
  1576. return component;
  1577. }
  1578. };
  1579. // src/components/Step.tsx
  1580. var JoyrideStep = class extends React8.Component {
  1581. constructor() {
  1582. super(...arguments);
  1583. __publicField(this, "scope", null);
  1584. __publicField(this, "tooltip", null);
  1585. /**
  1586. * Beacon click/hover event listener
  1587. */
  1588. __publicField(this, "handleClickHoverBeacon", (event) => {
  1589. const { step, store } = this.props;
  1590. if (event.type === "mouseenter" && step.event !== "hover") {
  1591. return;
  1592. }
  1593. store.update({ lifecycle: LIFECYCLE.TOOLTIP });
  1594. });
  1595. __publicField(this, "handleClickOverlay", () => {
  1596. const { helpers, step } = this.props;
  1597. if (!step.disableOverlayClose) {
  1598. helpers.close();
  1599. }
  1600. });
  1601. __publicField(this, "setTooltipRef", (element) => {
  1602. this.tooltip = element;
  1603. });
  1604. __publicField(this, "setPopper", (popper, type) => {
  1605. var _a;
  1606. const { action, step, store } = this.props;
  1607. if (type === "wrapper") {
  1608. store.setPopper("beacon", popper);
  1609. } else {
  1610. store.setPopper("tooltip", popper);
  1611. }
  1612. if (store.getPopper("beacon") && store.getPopper("tooltip")) {
  1613. store.update({
  1614. action,
  1615. lifecycle: LIFECYCLE.READY
  1616. });
  1617. }
  1618. if ((_a = step.floaterProps) == null ? void 0 : _a.getPopper) {
  1619. step.floaterProps.getPopper(popper, type);
  1620. }
  1621. });
  1622. __publicField(this, "renderTooltip", (renderProps) => {
  1623. const { continuous, helpers, index, size, step } = this.props;
  1624. return /* @__PURE__ */ React8.createElement(
  1625. JoyrideTooltip,
  1626. {
  1627. continuous,
  1628. helpers,
  1629. index,
  1630. isLastStep: index + 1 === size,
  1631. setTooltipRef: this.setTooltipRef,
  1632. size,
  1633. step,
  1634. ...renderProps
  1635. }
  1636. );
  1637. });
  1638. }
  1639. componentDidMount() {
  1640. const { debug, index } = this.props;
  1641. log({
  1642. title: `step:${index}`,
  1643. data: [{ key: "props", value: this.props }],
  1644. debug
  1645. });
  1646. }
  1647. componentDidUpdate(previousProps) {
  1648. var _a;
  1649. const {
  1650. action,
  1651. callback,
  1652. continuous,
  1653. controlled,
  1654. debug,
  1655. index,
  1656. lifecycle,
  1657. size,
  1658. status,
  1659. step,
  1660. store
  1661. } = this.props;
  1662. const { changed, changedFrom } = (0, import_tree_changes2.default)(previousProps, this.props);
  1663. const state = { action, controlled, index, lifecycle, size, status };
  1664. const skipBeacon = continuous && action !== ACTIONS.CLOSE && (index > 0 || action === ACTIONS.PREV);
  1665. const hasStoreChanged = changed("action") || changed("index") || changed("lifecycle") || changed("status");
  1666. const isInitial = changedFrom("lifecycle", [LIFECYCLE.TOOLTIP, LIFECYCLE.INIT], LIFECYCLE.INIT);
  1667. const isAfterAction = changed("action", [
  1668. ACTIONS.NEXT,
  1669. ACTIONS.PREV,
  1670. ACTIONS.SKIP,
  1671. ACTIONS.CLOSE
  1672. ]);
  1673. const isControlled = controlled && index === previousProps.index;
  1674. if (isAfterAction && (isInitial || isControlled)) {
  1675. callback({
  1676. ...state,
  1677. index: previousProps.index,
  1678. lifecycle: LIFECYCLE.COMPLETE,
  1679. step: previousProps.step,
  1680. type: EVENTS.STEP_AFTER
  1681. });
  1682. }
  1683. if (step.placement === "center" && status === STATUS.RUNNING && changed("index") && action !== ACTIONS.START && lifecycle === LIFECYCLE.INIT) {
  1684. store.update({ lifecycle: LIFECYCLE.READY });
  1685. }
  1686. if (hasStoreChanged) {
  1687. const element = getElement(step.target);
  1688. const elementExists = !!element;
  1689. const hasRenderedTarget = elementExists && isElementVisible(element);
  1690. if (hasRenderedTarget) {
  1691. if (changedFrom("status", STATUS.READY, STATUS.RUNNING) || changedFrom("lifecycle", LIFECYCLE.INIT, LIFECYCLE.READY)) {
  1692. callback({
  1693. ...state,
  1694. step,
  1695. type: EVENTS.STEP_BEFORE
  1696. });
  1697. }
  1698. } else {
  1699. console.warn(elementExists ? "Target not visible" : "Target not mounted", step);
  1700. callback({
  1701. ...state,
  1702. type: EVENTS.TARGET_NOT_FOUND,
  1703. step
  1704. });
  1705. if (!controlled) {
  1706. store.update({ index: index + (action === ACTIONS.PREV ? -1 : 1) });
  1707. }
  1708. }
  1709. }
  1710. if (changedFrom("lifecycle", LIFECYCLE.INIT, LIFECYCLE.READY)) {
  1711. store.update({
  1712. lifecycle: hideBeacon(step) || skipBeacon ? LIFECYCLE.TOOLTIP : LIFECYCLE.BEACON
  1713. });
  1714. }
  1715. if (changed("index")) {
  1716. log({
  1717. title: `step:${lifecycle}`,
  1718. data: [{ key: "props", value: this.props }],
  1719. debug
  1720. });
  1721. }
  1722. if (changed("lifecycle", LIFECYCLE.BEACON)) {
  1723. callback({
  1724. ...state,
  1725. step,
  1726. type: EVENTS.BEACON
  1727. });
  1728. }
  1729. if (changed("lifecycle", LIFECYCLE.TOOLTIP)) {
  1730. callback({
  1731. ...state,
  1732. step,
  1733. type: EVENTS.TOOLTIP
  1734. });
  1735. if (this.tooltip) {
  1736. this.scope = new Scope(this.tooltip, { selector: "[data-action=primary]" });
  1737. this.scope.setFocus();
  1738. }
  1739. }
  1740. if (changedFrom("lifecycle", [LIFECYCLE.TOOLTIP, LIFECYCLE.INIT], LIFECYCLE.INIT)) {
  1741. (_a = this.scope) == null ? void 0 : _a.removeScope();
  1742. store.cleanupPoppers();
  1743. }
  1744. }
  1745. componentWillUnmount() {
  1746. var _a;
  1747. (_a = this.scope) == null ? void 0 : _a.removeScope();
  1748. }
  1749. get open() {
  1750. const { lifecycle, step } = this.props;
  1751. return hideBeacon(step) || lifecycle === LIFECYCLE.TOOLTIP;
  1752. }
  1753. render() {
  1754. const { continuous, debug, index, lifecycle, nonce, shouldScroll: shouldScroll2, size, step } = this.props;
  1755. const target = getElement(step.target);
  1756. if (!validateStep(step) || !import_is_lite5.default.domElement(target)) {
  1757. return null;
  1758. }
  1759. return /* @__PURE__ */ React8.createElement("div", { key: `JoyrideStep-${index}`, className: "react-joyride__step" }, /* @__PURE__ */ React8.createElement(JoyridePortal, { id: "react-joyride-portal" }, /* @__PURE__ */ React8.createElement(
  1760. JoyrideOverlay,
  1761. {
  1762. ...step,
  1763. debug,
  1764. lifecycle,
  1765. onClickOverlay: this.handleClickOverlay
  1766. }
  1767. )), /* @__PURE__ */ React8.createElement(
  1768. import_react_floater.default,
  1769. {
  1770. ...step.floaterProps,
  1771. component: this.renderTooltip,
  1772. debug,
  1773. getPopper: this.setPopper,
  1774. id: `react-joyride-step-${index}`,
  1775. open: this.open,
  1776. placement: step.placement,
  1777. target: step.target
  1778. },
  1779. /* @__PURE__ */ React8.createElement(
  1780. JoyrideBeacon,
  1781. {
  1782. beaconComponent: step.beaconComponent,
  1783. continuous,
  1784. index,
  1785. isLastStep: index + 1 === size,
  1786. locale: step.locale,
  1787. nonce,
  1788. onClickOrHover: this.handleClickHoverBeacon,
  1789. shouldFocus: shouldScroll2,
  1790. size,
  1791. step,
  1792. styles: step.styles
  1793. }
  1794. )
  1795. ));
  1796. }
  1797. };
  1798. // src/components/index.tsx
  1799. var Joyride = class extends React9.Component {
  1800. constructor(props) {
  1801. super(props);
  1802. __publicField(this, "helpers");
  1803. __publicField(this, "store");
  1804. /**
  1805. * Trigger the callback.
  1806. */
  1807. __publicField(this, "callback", (data) => {
  1808. const { callback } = this.props;
  1809. if (import_is_lite6.default.function(callback)) {
  1810. callback(data);
  1811. }
  1812. });
  1813. /**
  1814. * Keydown event listener
  1815. */
  1816. __publicField(this, "handleKeyboard", (event) => {
  1817. const { index, lifecycle } = this.state;
  1818. const { steps } = this.props;
  1819. const step = steps[index];
  1820. if (lifecycle === LIFECYCLE.TOOLTIP) {
  1821. if (event.code === "Escape" && step && !step.disableCloseOnEsc) {
  1822. this.store.close();
  1823. }
  1824. }
  1825. });
  1826. /**
  1827. * Sync the store with the component's state
  1828. */
  1829. __publicField(this, "syncState", (state) => {
  1830. this.setState(state);
  1831. });
  1832. const { debug, getHelpers, run, stepIndex } = props;
  1833. this.store = createStore({
  1834. ...props,
  1835. controlled: run && import_is_lite6.default.number(stepIndex)
  1836. });
  1837. this.helpers = this.store.getHelpers();
  1838. const { addListener } = this.store;
  1839. log({
  1840. title: "init",
  1841. data: [
  1842. { key: "props", value: this.props },
  1843. { key: "state", value: this.state }
  1844. ],
  1845. debug
  1846. });
  1847. addListener(this.syncState);
  1848. if (getHelpers) {
  1849. getHelpers(this.helpers);
  1850. }
  1851. this.state = this.store.getState();
  1852. }
  1853. componentDidMount() {
  1854. if (!canUseDOM()) {
  1855. return;
  1856. }
  1857. const { debug, disableCloseOnEsc, run, steps } = this.props;
  1858. const { start } = this.store;
  1859. if (validateSteps(steps, debug) && run) {
  1860. start();
  1861. }
  1862. if (!disableCloseOnEsc) {
  1863. document.body.addEventListener("keydown", this.handleKeyboard, { passive: true });
  1864. }
  1865. }
  1866. componentDidUpdate(previousProps, previousState) {
  1867. if (!canUseDOM()) {
  1868. return;
  1869. }
  1870. const { action, controlled, index, lifecycle, status } = this.state;
  1871. const { debug, run, stepIndex, steps } = this.props;
  1872. const { stepIndex: previousStepIndex, steps: previousSteps } = previousProps;
  1873. const { reset, setSteps, start, stop, update } = this.store;
  1874. const { changed: changedProps } = (0, import_tree_changes3.default)(previousProps, this.props);
  1875. const { changed, changedFrom } = (0, import_tree_changes3.default)(previousState, this.state);
  1876. const step = getMergedStep(steps[index], this.props);
  1877. const stepsChanged = !(0, import_deep_equal.default)(previousSteps, steps);
  1878. const stepIndexChanged = import_is_lite6.default.number(stepIndex) && changedProps("stepIndex");
  1879. const target = getElement(step.target);
  1880. if (stepsChanged) {
  1881. if (validateSteps(steps, debug)) {
  1882. setSteps(steps);
  1883. } else {
  1884. console.warn("Steps are not valid", steps);
  1885. }
  1886. }
  1887. if (changedProps("run")) {
  1888. if (run) {
  1889. start(stepIndex);
  1890. } else {
  1891. stop();
  1892. }
  1893. }
  1894. if (stepIndexChanged) {
  1895. let nextAction = import_is_lite6.default.number(previousStepIndex) && previousStepIndex < stepIndex ? ACTIONS.NEXT : ACTIONS.PREV;
  1896. if (action === ACTIONS.STOP) {
  1897. nextAction = ACTIONS.START;
  1898. }
  1899. if (![STATUS.FINISHED, STATUS.SKIPPED].includes(status)) {
  1900. update({
  1901. action: action === ACTIONS.CLOSE ? ACTIONS.CLOSE : nextAction,
  1902. index: stepIndex,
  1903. lifecycle: LIFECYCLE.INIT
  1904. });
  1905. }
  1906. }
  1907. if (!controlled && status === STATUS.RUNNING && index === 0 && !target) {
  1908. this.store.update({ index: index + 1 });
  1909. this.callback({
  1910. ...this.state,
  1911. type: EVENTS.TARGET_NOT_FOUND,
  1912. step
  1913. });
  1914. }
  1915. const callbackData = {
  1916. ...this.state,
  1917. index,
  1918. step
  1919. };
  1920. const isAfterAction = changed("action", [
  1921. ACTIONS.NEXT,
  1922. ACTIONS.PREV,
  1923. ACTIONS.SKIP,
  1924. ACTIONS.CLOSE
  1925. ]);
  1926. if (isAfterAction && changed("status", STATUS.PAUSED)) {
  1927. const previousStep = getMergedStep(steps[previousState.index], this.props);
  1928. this.callback({
  1929. ...callbackData,
  1930. index: previousState.index,
  1931. lifecycle: LIFECYCLE.COMPLETE,
  1932. step: previousStep,
  1933. type: EVENTS.STEP_AFTER
  1934. });
  1935. }
  1936. if (changed("status", [STATUS.FINISHED, STATUS.SKIPPED])) {
  1937. const previousStep = getMergedStep(steps[previousState.index], this.props);
  1938. if (!controlled) {
  1939. this.callback({
  1940. ...callbackData,
  1941. index: previousState.index,
  1942. lifecycle: LIFECYCLE.COMPLETE,
  1943. step: previousStep,
  1944. type: EVENTS.STEP_AFTER
  1945. });
  1946. }
  1947. this.callback({
  1948. ...callbackData,
  1949. type: EVENTS.TOUR_END,
  1950. // Return the last step when the tour is finished
  1951. step: previousStep,
  1952. index: previousState.index
  1953. });
  1954. reset();
  1955. } else if (changedFrom("status", [STATUS.IDLE, STATUS.READY], STATUS.RUNNING)) {
  1956. this.callback({
  1957. ...callbackData,
  1958. type: EVENTS.TOUR_START
  1959. });
  1960. } else if (changed("status") || changed("action", ACTIONS.RESET)) {
  1961. this.callback({
  1962. ...callbackData,
  1963. type: EVENTS.TOUR_STATUS
  1964. });
  1965. }
  1966. this.scrollToStep(previousState);
  1967. if (step.placement === "center" && status === STATUS.RUNNING && lifecycle === LIFECYCLE.INIT) {
  1968. this.store.update({ lifecycle: LIFECYCLE.READY });
  1969. }
  1970. }
  1971. componentWillUnmount() {
  1972. const { disableCloseOnEsc } = this.props;
  1973. if (!disableCloseOnEsc) {
  1974. document.body.removeEventListener("keydown", this.handleKeyboard);
  1975. }
  1976. }
  1977. scrollToStep(previousState) {
  1978. const { index, lifecycle, status } = this.state;
  1979. const {
  1980. debug,
  1981. disableScrollParentFix = false,
  1982. scrollDuration,
  1983. scrollOffset = 20,
  1984. scrollToFirstStep = false,
  1985. steps
  1986. } = this.props;
  1987. const step = getMergedStep(steps[index], this.props);
  1988. const target = getElement(step.target);
  1989. const shouldScrollToStep = shouldScroll({
  1990. isFirstStep: index === 0,
  1991. lifecycle,
  1992. previousLifecycle: previousState.lifecycle,
  1993. scrollToFirstStep,
  1994. step,
  1995. target
  1996. });
  1997. if (status === STATUS.RUNNING && shouldScrollToStep) {
  1998. const hasCustomScroll = hasCustomScrollParent(target, disableScrollParentFix);
  1999. const scrollParent2 = getScrollParent(target, disableScrollParentFix);
  2000. let scrollY = Math.floor(getScrollTo(target, scrollOffset, disableScrollParentFix)) || 0;
  2001. log({
  2002. title: "scrollToStep",
  2003. data: [
  2004. { key: "index", value: index },
  2005. { key: "lifecycle", value: lifecycle },
  2006. { key: "status", value: status }
  2007. ],
  2008. debug
  2009. });
  2010. const beaconPopper = this.store.getPopper("beacon");
  2011. const tooltipPopper = this.store.getPopper("tooltip");
  2012. if (lifecycle === LIFECYCLE.BEACON && beaconPopper) {
  2013. const { offsets, placement } = beaconPopper;
  2014. if (!["bottom"].includes(placement) && !hasCustomScroll) {
  2015. scrollY = Math.floor(offsets.popper.top - scrollOffset);
  2016. }
  2017. } else if (lifecycle === LIFECYCLE.TOOLTIP && tooltipPopper) {
  2018. const { flipped, offsets, placement } = tooltipPopper;
  2019. if (["top", "right", "left"].includes(placement) && !flipped && !hasCustomScroll) {
  2020. scrollY = Math.floor(offsets.popper.top - scrollOffset);
  2021. } else {
  2022. scrollY -= step.spotlightPadding;
  2023. }
  2024. }
  2025. scrollY = scrollY >= 0 ? scrollY : 0;
  2026. if (status === STATUS.RUNNING) {
  2027. scrollTo(scrollY, { element: scrollParent2, duration: scrollDuration }).then(
  2028. () => {
  2029. setTimeout(() => {
  2030. var _a;
  2031. (_a = this.store.getPopper("tooltip")) == null ? void 0 : _a.instance.update();
  2032. }, 10);
  2033. }
  2034. );
  2035. }
  2036. }
  2037. }
  2038. render() {
  2039. if (!canUseDOM()) {
  2040. return null;
  2041. }
  2042. const { index, status } = this.state;
  2043. const {
  2044. continuous = false,
  2045. debug = false,
  2046. nonce,
  2047. scrollToFirstStep = false,
  2048. steps
  2049. } = this.props;
  2050. let output;
  2051. if (status === STATUS.RUNNING && steps[index]) {
  2052. const step = getMergedStep(steps[index], this.props);
  2053. output = /* @__PURE__ */ React9.createElement(
  2054. JoyrideStep,
  2055. {
  2056. ...this.state,
  2057. callback: this.callback,
  2058. continuous,
  2059. debug,
  2060. helpers: this.helpers,
  2061. nonce,
  2062. shouldScroll: !step.disableScrolling && (index !== 0 || scrollToFirstStep),
  2063. step,
  2064. store: this.store
  2065. }
  2066. );
  2067. }
  2068. return /* @__PURE__ */ React9.createElement("div", { className: "react-joyride" }, output);
  2069. }
  2070. };
  2071. __publicField(Joyride, "defaultProps", defaultProps);
  2072. var components_default = Joyride;
  2073. // Annotate the CommonJS export names for ESM import in node:
  2074. 0 && (module.exports = {
  2075. ACTIONS,
  2076. EVENTS,
  2077. LIFECYCLE,
  2078. STATUS
  2079. });
  2080. //# sourceMappingURL=index.js.map
  2081. // fix-cjs-exports
  2082. if (module.exports.default) {
  2083. Object.assign(module.exports.default, module.exports);
  2084. module.exports = module.exports.default;
  2085. delete module.exports.default;
  2086. }