UNPKG

@rently-team/shepherd.js

Version:

Guide your users through a tour of your app.

1 lines 979 kB
{"version":3,"file":"shepherd.cjs","sources":["../../src/utils/type-check.ts","../../src/evented.ts","../../../node_modules/.pnpm/deepmerge-ts@7.1.1/node_modules/deepmerge-ts/dist/index.mjs","../../src/utils/auto-bind.ts","../../src/utils/bind.ts","../../src/utils/general.ts","../../../node_modules/.pnpm/@floating-ui+utils@0.2.8/node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs","../../../node_modules/.pnpm/@floating-ui+core@1.6.5/node_modules/@floating-ui/core/dist/floating-ui.core.mjs","../../../node_modules/.pnpm/@floating-ui+utils@0.2.8/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.mjs","../../../node_modules/.pnpm/@floating-ui+dom@1.6.12/node_modules/@floating-ui/dom/dist/floating-ui.dom.mjs","../../src/utils/floating-ui.ts","../../../node_modules/.pnpm/svelte@4.2.19/node_modules/svelte/src/runtime/internal/utils.js","../../../node_modules/.pnpm/svelte@4.2.19/node_modules/svelte/src/runtime/internal/dom.js","../../../node_modules/.pnpm/svelte@4.2.19/node_modules/svelte/src/runtime/internal/lifecycle.js","../../../node_modules/.pnpm/svelte@4.2.19/node_modules/svelte/src/runtime/internal/scheduler.js","../../../node_modules/.pnpm/svelte@4.2.19/node_modules/svelte/src/runtime/internal/transitions.js","../../../node_modules/.pnpm/svelte@4.2.19/node_modules/svelte/src/runtime/internal/each.js","../../../node_modules/.pnpm/svelte@4.2.19/node_modules/svelte/src/runtime/internal/spread.js","../../../node_modules/.pnpm/svelte@4.2.19/node_modules/svelte/src/runtime/internal/Component.js","../../../node_modules/.pnpm/svelte@4.2.19/node_modules/svelte/src/shared/version.js","../../../node_modules/.pnpm/svelte@4.2.19/node_modules/svelte/src/runtime/internal/disclose-version/index.js","../../src/components/shepherd-button.svelte","../../src/components/shepherd-footer.svelte","../../src/components/shepherd-cancel-icon.svelte","../../src/components/shepherd-title.svelte","../../src/components/shepherd-header.svelte","../../src/components/shepherd-text.svelte","../../src/components/shepherd-content.svelte","../../src/components/shepherd-element.svelte","../../src/step.ts","../../src/utils/cleanup.ts","../../src/utils/overlay-path.ts","../../src/components/shepherd-modal.svelte","../../src/tour.ts","../../src/shepherd.ts"],"sourcesContent":["/**\n * Checks if `value` is classified as an `Element`.\n * @param value The param to check if it is an Element\n */\nexport function isElement<T>(value: T | Element): value is Element {\n return value instanceof Element;\n}\n\n/**\n * Checks if `value` is classified as an `HTMLElement`.\n * @param value The param to check if it is an HTMLElement\n */\nexport function isHTMLElement<T>(value: T | HTMLElement): value is HTMLElement {\n return value instanceof HTMLElement;\n}\n\n/**\n * Checks if `value` is classified as a `Function` object.\n * @param value The param to check if it is a function\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function isFunction<T>(value: T | Function): value is Function {\n return typeof value === 'function';\n}\n\n/**\n * Checks if `value` is classified as a `String` object.\n * @param value The param to check if it is a string\n */\nexport function isString<T>(value: T | string): value is string {\n return typeof value === 'string';\n}\n\n/**\n * Checks if `value` is undefined.\n * @param value The param to check if it is undefined\n */\nexport function isUndefined<T>(value: T | undefined): value is undefined {\n return value === undefined;\n}\n","import { isUndefined } from './utils/type-check.ts';\n\nexport type Bindings = {\n [key: string]: Array<{ handler: () => void; ctx?: unknown; once?: boolean }>;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyHandler = (...args: any[]) => void;\n\nexport class Evented {\n declare bindings: Bindings;\n\n /**\n * Adds an event listener for the given event string.\n *\n * @param {string} event\n * @param {Function} handler\n * @param ctx\n * @param {boolean} once\n * @returns\n */\n on(event: string, handler: AnyHandler, ctx?: unknown, once = false) {\n if (isUndefined(this.bindings)) {\n this.bindings = {};\n }\n if (isUndefined(this.bindings[event])) {\n this.bindings[event] = [];\n }\n this.bindings[event]?.push({ handler, ctx, once });\n\n return this;\n }\n\n /**\n * Adds an event listener that only fires once for the given event string.\n *\n * @param {string} event\n * @param {Function} handler\n * @param ctx\n * @returns\n */\n once(event: string, handler: AnyHandler, ctx?: unknown) {\n return this.on(event, handler, ctx, true);\n }\n\n /**\n * Removes an event listener for the given event string.\n *\n * @param {string} event\n * @param {Function} handler\n * @returns\n */\n off(event: string, handler?: AnyHandler) {\n if (isUndefined(this.bindings) || isUndefined(this.bindings[event])) {\n return this;\n }\n\n if (isUndefined(handler)) {\n delete this.bindings[event];\n } else {\n this.bindings[event]?.forEach((binding, index) => {\n if (binding.handler === handler) {\n this.bindings[event]?.splice(index, 1);\n }\n });\n }\n\n return this;\n }\n\n /**\n * Triggers an event listener for the given event string.\n *\n * @param {string} event\n * @returns\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n trigger(event: string, ...args: any[]) {\n if (!isUndefined(this.bindings) && this.bindings[event]) {\n this.bindings[event]?.forEach((binding, index) => {\n const { ctx, handler, once } = binding;\n\n const context = ctx || this;\n\n handler.apply(context, args as []);\n\n if (once) {\n this.bindings[event]?.splice(index, 1);\n }\n });\n }\n\n return this;\n }\n}\n","/**\n * Special values that tell deepmerge to perform a certain action.\n */\nconst actions = {\n defaultMerge: Symbol(\"deepmerge-ts: default merge\"),\n skip: Symbol(\"deepmerge-ts: skip\"),\n};\n/**\n * Special values that tell deepmergeInto to perform a certain action.\n */\nconst actionsInto = {\n defaultMerge: actions.defaultMerge,\n};\n\n/**\n * The default function to update meta data.\n *\n * It doesn't update the meta data.\n */\nfunction defaultMetaDataUpdater(previousMeta, metaMeta) {\n return metaMeta;\n}\n/**\n * The default function to filter values.\n *\n * It filters out undefined values.\n */\nfunction defaultFilterValues(values, meta) {\n return values.filter((value) => value !== undefined);\n}\n\n/**\n * The different types of objects deepmerge-ts support.\n */\nvar ObjectType;\n(function (ObjectType) {\n ObjectType[ObjectType[\"NOT\"] = 0] = \"NOT\";\n ObjectType[ObjectType[\"RECORD\"] = 1] = \"RECORD\";\n ObjectType[ObjectType[\"ARRAY\"] = 2] = \"ARRAY\";\n ObjectType[ObjectType[\"SET\"] = 3] = \"SET\";\n ObjectType[ObjectType[\"MAP\"] = 4] = \"MAP\";\n ObjectType[ObjectType[\"OTHER\"] = 5] = \"OTHER\";\n})(ObjectType || (ObjectType = {}));\n/**\n * Get the type of the given object.\n *\n * @param object - The object to get the type of.\n * @returns The type of the given object.\n */\nfunction getObjectType(object) {\n if (typeof object !== \"object\" || object === null) {\n return 0 /* ObjectType.NOT */;\n }\n if (Array.isArray(object)) {\n return 2 /* ObjectType.ARRAY */;\n }\n if (isRecord(object)) {\n return 1 /* ObjectType.RECORD */;\n }\n if (object instanceof Set) {\n return 3 /* ObjectType.SET */;\n }\n if (object instanceof Map) {\n return 4 /* ObjectType.MAP */;\n }\n return 5 /* ObjectType.OTHER */;\n}\n/**\n * Get the keys of the given objects including symbol keys.\n *\n * Note: Only keys to enumerable properties are returned.\n *\n * @param objects - An array of objects to get the keys of.\n * @returns A set containing all the keys of all the given objects.\n */\nfunction getKeys(objects) {\n const keys = new Set();\n for (const object of objects) {\n for (const key of [...Object.keys(object), ...Object.getOwnPropertySymbols(object)]) {\n keys.add(key);\n }\n }\n return keys;\n}\n/**\n * Does the given object have the given property.\n *\n * @param object - The object to test.\n * @param property - The property to test.\n * @returns Whether the object has the property.\n */\nfunction objectHasProperty(object, property) {\n return typeof object === \"object\" && Object.prototype.propertyIsEnumerable.call(object, property);\n}\n/**\n * Get an iterable object that iterates over the given iterables.\n */\nfunction getIterableOfIterables(iterables) {\n return {\n *[Symbol.iterator]() {\n for (const iterable of iterables) {\n for (const value of iterable) {\n yield value;\n }\n }\n },\n };\n}\nconst validRecordToStringValues = new Set([\"[object Object]\", \"[object Module]\"]);\n/**\n * Does the given object appear to be a record.\n */\nfunction isRecord(value) {\n // All records are objects.\n if (!validRecordToStringValues.has(Object.prototype.toString.call(value))) {\n return false;\n }\n const { constructor } = value;\n // If has modified constructor.\n // eslint-disable-next-line ts/no-unnecessary-condition\n if (constructor === undefined) {\n return true;\n }\n const prototype = constructor.prototype;\n // If has modified prototype.\n if (prototype === null ||\n typeof prototype !== \"object\" ||\n !validRecordToStringValues.has(Object.prototype.toString.call(prototype))) {\n return false;\n }\n // If constructor does not have an Object-specific method.\n // eslint-disable-next-line sonar/prefer-single-boolean-return, no-prototype-builtins\n if (!prototype.hasOwnProperty(\"isPrototypeOf\")) {\n return false;\n }\n // Most likely a record.\n return true;\n}\n\n/**\n * The default strategy to merge records.\n *\n * @param values - The records.\n */\nfunction mergeRecords$1(values, utils, meta) {\n const result = {};\n for (const key of getKeys(values)) {\n const propValues = [];\n for (const value of values) {\n if (objectHasProperty(value, key)) {\n propValues.push(value[key]);\n }\n }\n if (propValues.length === 0) {\n continue;\n }\n const updatedMeta = utils.metaDataUpdater(meta, {\n key,\n parents: values,\n });\n const propertyResult = mergeUnknowns(propValues, utils, updatedMeta);\n if (propertyResult === actions.skip) {\n continue;\n }\n if (key === \"__proto__\") {\n Object.defineProperty(result, key, {\n value: propertyResult,\n configurable: true,\n enumerable: true,\n writable: true,\n });\n }\n else {\n result[key] = propertyResult;\n }\n }\n return result;\n}\n/**\n * The default strategy to merge arrays.\n *\n * @param values - The arrays.\n */\nfunction mergeArrays$1(values) {\n return values.flat();\n}\n/**\n * The default strategy to merge sets.\n *\n * @param values - The sets.\n */\nfunction mergeSets$1(values) {\n return new Set(getIterableOfIterables(values));\n}\n/**\n * The default strategy to merge maps.\n *\n * @param values - The maps.\n */\nfunction mergeMaps$1(values) {\n return new Map(getIterableOfIterables(values));\n}\n/**\n * Get the last non-undefined value in the given array.\n */\nfunction mergeOthers$1(values) {\n return values.at(-1);\n}\n/**\n * The merge functions.\n */\nconst mergeFunctions = {\n mergeRecords: mergeRecords$1,\n mergeArrays: mergeArrays$1,\n mergeSets: mergeSets$1,\n mergeMaps: mergeMaps$1,\n mergeOthers: mergeOthers$1,\n};\n\n/**\n * Deeply merge objects.\n *\n * @param objects - The objects to merge.\n */\nfunction deepmerge(...objects) {\n return deepmergeCustom({})(...objects);\n}\nfunction deepmergeCustom(options, rootMetaData) {\n const utils = getUtils(options, customizedDeepmerge);\n /**\n * The customized deepmerge function.\n */\n function customizedDeepmerge(...objects) {\n return mergeUnknowns(objects, utils, rootMetaData);\n }\n return customizedDeepmerge;\n}\n/**\n * The the utils that are available to the merge functions.\n *\n * @param options - The options the user specified\n */\nfunction getUtils(options, customizedDeepmerge) {\n return {\n defaultMergeFunctions: mergeFunctions,\n mergeFunctions: {\n ...mergeFunctions,\n ...Object.fromEntries(Object.entries(options)\n .filter(([key, option]) => Object.hasOwn(mergeFunctions, key))\n .map(([key, option]) => (option === false ? [key, mergeFunctions.mergeOthers] : [key, option]))),\n },\n metaDataUpdater: (options.metaDataUpdater ?? defaultMetaDataUpdater),\n deepmerge: customizedDeepmerge,\n useImplicitDefaultMerging: options.enableImplicitDefaultMerging ?? false,\n filterValues: options.filterValues === false ? undefined : (options.filterValues ?? defaultFilterValues),\n actions,\n };\n}\n/**\n * Merge unknown things.\n *\n * @param values - The values.\n */\nfunction mergeUnknowns(values, utils, meta) {\n const filteredValues = utils.filterValues?.(values, meta) ?? values;\n if (filteredValues.length === 0) {\n return undefined;\n }\n if (filteredValues.length === 1) {\n return mergeOthers(filteredValues, utils, meta);\n }\n const type = getObjectType(filteredValues[0]);\n if (type !== 0 /* ObjectType.NOT */ && type !== 5 /* ObjectType.OTHER */) {\n for (let m_index = 1; m_index < filteredValues.length; m_index++) {\n if (getObjectType(filteredValues[m_index]) === type) {\n continue;\n }\n return mergeOthers(filteredValues, utils, meta);\n }\n }\n switch (type) {\n case 1 /* ObjectType.RECORD */: {\n return mergeRecords(filteredValues, utils, meta);\n }\n case 2 /* ObjectType.ARRAY */: {\n return mergeArrays(filteredValues, utils, meta);\n }\n case 3 /* ObjectType.SET */: {\n return mergeSets(filteredValues, utils, meta);\n }\n case 4 /* ObjectType.MAP */: {\n return mergeMaps(filteredValues, utils, meta);\n }\n default: {\n return mergeOthers(filteredValues, utils, meta);\n }\n }\n}\n/**\n * Merge records.\n *\n * @param values - The records.\n */\nfunction mergeRecords(values, utils, meta) {\n const result = utils.mergeFunctions.mergeRecords(values, utils, meta);\n if (result === actions.defaultMerge ||\n (utils.useImplicitDefaultMerging &&\n result === undefined &&\n utils.mergeFunctions.mergeRecords !== utils.defaultMergeFunctions.mergeRecords)) {\n return utils.defaultMergeFunctions.mergeRecords(values, utils, meta);\n }\n return result;\n}\n/**\n * Merge arrays.\n *\n * @param values - The arrays.\n */\nfunction mergeArrays(values, utils, meta) {\n const result = utils.mergeFunctions.mergeArrays(values, utils, meta);\n if (result === actions.defaultMerge ||\n (utils.useImplicitDefaultMerging &&\n result === undefined &&\n utils.mergeFunctions.mergeArrays !== utils.defaultMergeFunctions.mergeArrays)) {\n return utils.defaultMergeFunctions.mergeArrays(values);\n }\n return result;\n}\n/**\n * Merge sets.\n *\n * @param values - The sets.\n */\nfunction mergeSets(values, utils, meta) {\n const result = utils.mergeFunctions.mergeSets(values, utils, meta);\n if (result === actions.defaultMerge ||\n (utils.useImplicitDefaultMerging &&\n result === undefined &&\n utils.mergeFunctions.mergeSets !== utils.defaultMergeFunctions.mergeSets)) {\n return utils.defaultMergeFunctions.mergeSets(values);\n }\n return result;\n}\n/**\n * Merge maps.\n *\n * @param values - The maps.\n */\nfunction mergeMaps(values, utils, meta) {\n const result = utils.mergeFunctions.mergeMaps(values, utils, meta);\n if (result === actions.defaultMerge ||\n (utils.useImplicitDefaultMerging &&\n result === undefined &&\n utils.mergeFunctions.mergeMaps !== utils.defaultMergeFunctions.mergeMaps)) {\n return utils.defaultMergeFunctions.mergeMaps(values);\n }\n return result;\n}\n/**\n * Merge other things.\n *\n * @param values - The other things.\n */\nfunction mergeOthers(values, utils, meta) {\n const result = utils.mergeFunctions.mergeOthers(values, utils, meta);\n if (result === actions.defaultMerge ||\n (utils.useImplicitDefaultMerging &&\n result === undefined &&\n utils.mergeFunctions.mergeOthers !== utils.defaultMergeFunctions.mergeOthers)) {\n return utils.defaultMergeFunctions.mergeOthers(values);\n }\n return result;\n}\n\n/**\n * The default strategy to merge records into a target record.\n *\n * @param m_target - The result will be mutated into this record\n * @param values - The records (including the target's value if there is one).\n */\nfunction mergeRecordsInto$1(m_target, values, utils, meta) {\n for (const key of getKeys(values)) {\n const propValues = [];\n for (const value of values) {\n if (objectHasProperty(value, key)) {\n propValues.push(value[key]);\n }\n }\n if (propValues.length === 0) {\n continue;\n }\n const updatedMeta = utils.metaDataUpdater(meta, {\n key,\n parents: values,\n });\n const propertyTarget = { value: propValues[0] };\n mergeUnknownsInto(propertyTarget, propValues, utils, updatedMeta);\n if (key === \"__proto__\") {\n Object.defineProperty(m_target.value, key, {\n value: propertyTarget.value,\n configurable: true,\n enumerable: true,\n writable: true,\n });\n }\n else {\n m_target.value[key] = propertyTarget.value;\n }\n }\n}\n/**\n * The default strategy to merge arrays into a target array.\n *\n * @param m_target - The result will be mutated into this array\n * @param values - The arrays (including the target's value if there is one).\n */\nfunction mergeArraysInto$1(m_target, values) {\n m_target.value.push(...values.slice(1).flat());\n}\n/**\n * The default strategy to merge sets into a target set.\n *\n * @param m_target - The result will be mutated into this set\n * @param values - The sets (including the target's value if there is one).\n */\nfunction mergeSetsInto$1(m_target, values) {\n for (const value of getIterableOfIterables(values.slice(1))) {\n m_target.value.add(value);\n }\n}\n/**\n * The default strategy to merge maps into a target map.\n *\n * @param m_target - The result will be mutated into this map\n * @param values - The maps (including the target's value if there is one).\n */\nfunction mergeMapsInto$1(m_target, values) {\n for (const [key, value] of getIterableOfIterables(values.slice(1))) {\n m_target.value.set(key, value);\n }\n}\n/**\n * Set the target to the last non-undefined value.\n */\nfunction mergeOthersInto$1(m_target, values) {\n m_target.value = values.at(-1);\n}\n/**\n * The merge functions.\n */\nconst mergeIntoFunctions = {\n mergeRecords: mergeRecordsInto$1,\n mergeArrays: mergeArraysInto$1,\n mergeSets: mergeSetsInto$1,\n mergeMaps: mergeMapsInto$1,\n mergeOthers: mergeOthersInto$1,\n};\n\nfunction deepmergeInto(target, ...objects) {\n return void deepmergeIntoCustom({})(target, ...objects);\n}\nfunction deepmergeIntoCustom(options, rootMetaData) {\n const utils = getIntoUtils(options, customizedDeepmergeInto);\n /**\n * The customized deepmerge function.\n */\n function customizedDeepmergeInto(target, ...objects) {\n mergeUnknownsInto({ value: target }, [target, ...objects], utils, rootMetaData);\n }\n return customizedDeepmergeInto;\n}\n/**\n * The the utils that are available to the merge functions.\n *\n * @param options - The options the user specified\n */\nfunction getIntoUtils(options, customizedDeepmergeInto) {\n return {\n defaultMergeFunctions: mergeIntoFunctions,\n mergeFunctions: {\n ...mergeIntoFunctions,\n ...Object.fromEntries(Object.entries(options)\n .filter(([key, option]) => Object.hasOwn(mergeIntoFunctions, key))\n .map(([key, option]) => (option === false ? [key, mergeIntoFunctions.mergeOthers] : [key, option]))),\n },\n metaDataUpdater: (options.metaDataUpdater ?? defaultMetaDataUpdater),\n deepmergeInto: customizedDeepmergeInto,\n filterValues: options.filterValues === false ? undefined : (options.filterValues ?? defaultFilterValues),\n actions: actionsInto,\n };\n}\n/**\n * Merge unknown things into a target.\n *\n * @param m_target - The target to merge into.\n * @param values - The values.\n */\nfunction mergeUnknownsInto(m_target, values, utils, meta) {\n const filteredValues = utils.filterValues?.(values, meta) ?? values;\n if (filteredValues.length === 0) {\n return;\n }\n if (filteredValues.length === 1) {\n return void mergeOthersInto(m_target, filteredValues, utils, meta);\n }\n const type = getObjectType(m_target.value);\n if (type !== 0 /* ObjectType.NOT */ && type !== 5 /* ObjectType.OTHER */) {\n for (let m_index = 1; m_index < filteredValues.length; m_index++) {\n if (getObjectType(filteredValues[m_index]) === type) {\n continue;\n }\n return void mergeOthersInto(m_target, filteredValues, utils, meta);\n }\n }\n switch (type) {\n case 1 /* ObjectType.RECORD */: {\n return void mergeRecordsInto(m_target, filteredValues, utils, meta);\n }\n case 2 /* ObjectType.ARRAY */: {\n return void mergeArraysInto(m_target, filteredValues, utils, meta);\n }\n case 3 /* ObjectType.SET */: {\n return void mergeSetsInto(m_target, filteredValues, utils, meta);\n }\n case 4 /* ObjectType.MAP */: {\n return void mergeMapsInto(m_target, filteredValues, utils, meta);\n }\n default: {\n return void mergeOthersInto(m_target, filteredValues, utils, meta);\n }\n }\n}\n/**\n * Merge records into a target record.\n *\n * @param m_target - The target to merge into.\n * @param values - The records.\n */\nfunction mergeRecordsInto(m_target, values, utils, meta) {\n const action = utils.mergeFunctions.mergeRecords(m_target, values, utils, meta);\n if (action === actionsInto.defaultMerge) {\n utils.defaultMergeFunctions.mergeRecords(m_target, values, utils, meta);\n }\n}\n/**\n * Merge arrays into a target array.\n *\n * @param m_target - The target to merge into.\n * @param values - The arrays.\n */\nfunction mergeArraysInto(m_target, values, utils, meta) {\n const action = utils.mergeFunctions.mergeArrays(m_target, values, utils, meta);\n if (action === actionsInto.defaultMerge) {\n utils.defaultMergeFunctions.mergeArrays(m_target, values);\n }\n}\n/**\n * Merge sets into a target set.\n *\n * @param m_target - The target to merge into.\n * @param values - The sets.\n */\nfunction mergeSetsInto(m_target, values, utils, meta) {\n const action = utils.mergeFunctions.mergeSets(m_target, values, utils, meta);\n if (action === actionsInto.defaultMerge) {\n utils.defaultMergeFunctions.mergeSets(m_target, values);\n }\n}\n/**\n * Merge maps into a target map.\n *\n * @param m_target - The target to merge into.\n * @param values - The maps.\n */\nfunction mergeMapsInto(m_target, values, utils, meta) {\n const action = utils.mergeFunctions.mergeMaps(m_target, values, utils, meta);\n if (action === actionsInto.defaultMerge) {\n utils.defaultMergeFunctions.mergeMaps(m_target, values);\n }\n}\n/**\n * Merge other things into a target.\n *\n * @param m_target - The target to merge into.\n * @param values - The other things.\n */\nfunction mergeOthersInto(m_target, values, utils, meta) {\n const action = utils.mergeFunctions.mergeOthers(m_target, values, utils, meta);\n if (action === actionsInto.defaultMerge || m_target.value === actionsInto.defaultMerge) {\n utils.defaultMergeFunctions.mergeOthers(m_target, values);\n }\n}\n\nexport { deepmerge, deepmergeCustom, deepmergeInto, deepmergeIntoCustom, getKeys, getObjectType, objectHasProperty };\n","/**\n * Binds all the methods on a JS Class to the `this` context of the class.\n * Adapted from https://github.com/sindresorhus/auto-bind\n * @param self The `this` context of the class\n * @return The `this` context of the class\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default function autoBind(self: any) {\n const keys = Object.getOwnPropertyNames(self.constructor.prototype);\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i] as keyof typeof self;\n const val = self[key];\n if (key !== 'constructor' && typeof val === 'function') {\n self[key] = val.bind(self);\n }\n }\n\n return self;\n}\n","import type { Step } from '../step.ts';\nimport { isUndefined } from './type-check.ts';\n\n/**\n * Sets up the handler to determine if we should advance the tour\n * @param step The step instance\n * @param selector\n * @private\n */\nfunction _setupAdvanceOnHandler(step: Step, selector?: string) {\n return (event: Event) => {\n if (step.isOpen()) {\n const targetIsEl = step.el && event.currentTarget === step.el;\n const targetIsSelector =\n !isUndefined(selector) &&\n (event.currentTarget as HTMLElement).matches(selector);\n\n if (targetIsSelector || targetIsEl) {\n step.tour.next();\n }\n }\n };\n}\n\n/**\n * Bind the event handler for advanceOn\n * @param step The step instance\n */\nexport function bindAdvance(step: Step) {\n // An empty selector matches the step element\n const { event, selector } = step.options.advanceOn || {};\n if (event) {\n const handler = _setupAdvanceOnHandler(step, selector);\n\n // TODO: this should also bind/unbind on show/hide\n let el: Element | null = null;\n\n if (!isUndefined(selector)) {\n el = document.querySelector(selector);\n\n if (!el) {\n return console.error(\n `No element was found for the selector supplied to advanceOn: ${selector}`\n );\n }\n\n step.advanceEl = el as HTMLElement;\n }\n\n if (el) {\n el.removeEventListener(event, handler);\n el.addEventListener(event, handler);\n step.on('destroy', () => {\n return (el as HTMLElement).removeEventListener(event, handler);\n });\n } else {\n document.body.removeEventListener(event, handler);\n document.body.addEventListener(event, handler, true);\n step.on('destroy', () => {\n return document.body.removeEventListener(event, handler, true);\n });\n }\n } else {\n return console.error(\n 'advanceOn was defined, but no event name was passed.'\n );\n }\n}\n","import { type Tour, type TourOptions } from '../tour.ts';\nimport {\n type StepOptionsAttachTo,\n type Step,\n type StepOptions\n} from '../step.ts';\nimport { isFunction, isString } from './type-check.ts';\n\nexport class StepNoOp {\n constructor(_options: StepOptions) {}\n}\n\nexport class TourNoOp {\n constructor(_tour: Tour, _options: TourOptions) {}\n}\n\n/**\n * Ensure class prefix ends in `-`\n * @param prefix - The prefix to prepend to the class names generated by nano-css\n * @return The prefix ending in `-`\n */\nexport function normalizePrefix(prefix?: string) {\n if (!isString(prefix) || prefix === '') {\n return '';\n }\n\n return prefix.charAt(prefix.length - 1) !== '-' ? `${prefix}-` : prefix;\n}\n\n/**\n * Resolves attachTo options, converting element option value to a qualified HTMLElement.\n * @param step - The step instance\n * @returns {{}|{element, on}}\n * `element` is a qualified HTML Element\n * `on` is a string position value\n */\nexport function parseAttachTo(step: Step) {\n const options = step.options.attachTo || {};\n const returnOpts = Object.assign({}, options);\n\n if (isFunction(returnOpts.element)) {\n // Bind the callback to step so that it has access to the object, to enable running additional logic\n returnOpts.element = returnOpts.element.call(step);\n }\n\n if (isString(returnOpts.element)) {\n // Can't override the element in user opts reference because we can't\n // guarantee that the element will exist in the future.\n try {\n returnOpts.element = document.querySelector(\n returnOpts.element\n ) as HTMLElement;\n } catch (e) {\n // TODO\n }\n if (!returnOpts.element) {\n console.error(\n `The element for this Shepherd step was not found ${options.element}`\n );\n }\n }\n\n return returnOpts;\n}\n\n/*\n * Resolves the step's `extraHighlights` option, converting any locator values to HTMLElements.\n */\nexport function parseExtraHighlights(step: Step): HTMLElement[] {\n if (step.options.extraHighlights) {\n return step.options.extraHighlights.flatMap((highlight) => {\n return Array.from(document.querySelectorAll(highlight)) as HTMLElement[];\n });\n }\n return [];\n}\n\n/**\n * Checks if the step should be centered or not. Does not trigger attachTo.element evaluation, making it a pure\n * alternative for the deprecated step.isCentered() method.\n */\nexport function shouldCenterStep(resolvedAttachToOptions: StepOptionsAttachTo) {\n if (\n resolvedAttachToOptions === undefined ||\n resolvedAttachToOptions === null\n ) {\n return true;\n }\n\n return !resolvedAttachToOptions.element || !resolvedAttachToOptions.on;\n}\n\n/**\n * Create a unique id for steps, tours, modals, etc\n */\nexport function uuid() {\n let d = Date.now();\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = (d + Math.random() * 16) % 16 | 0;\n d = Math.floor(d / 16);\n return (c == 'x' ? r : (r & 0x3) | 0x8).toString(16);\n });\n}\n","/**\n * Custom positioning reference element.\n * @see https://floating-ui.com/docs/virtual-elements\n */\n\nconst sides = ['top', 'right', 'bottom', 'left'];\nconst alignments = ['start', 'end'];\nconst placements = /*#__PURE__*/sides.reduce((acc, side) => acc.concat(side, side + \"-\" + alignments[0], side + \"-\" + alignments[1]), []);\nconst min = Math.min;\nconst max = Math.max;\nconst round = Math.round;\nconst floor = Math.floor;\nconst createCoords = v => ({\n x: v,\n y: v\n});\nconst oppositeSideMap = {\n left: 'right',\n right: 'left',\n bottom: 'top',\n top: 'bottom'\n};\nconst oppositeAlignmentMap = {\n start: 'end',\n end: 'start'\n};\nfunction clamp(start, value, end) {\n return max(start, min(value, end));\n}\nfunction evaluate(value, param) {\n return typeof value === 'function' ? value(param) : value;\n}\nfunction getSide(placement) {\n return placement.split('-')[0];\n}\nfunction getAlignment(placement) {\n return placement.split('-')[1];\n}\nfunction getOppositeAxis(axis) {\n return axis === 'x' ? 'y' : 'x';\n}\nfunction getAxisLength(axis) {\n return axis === 'y' ? 'height' : 'width';\n}\nfunction getSideAxis(placement) {\n return ['top', 'bottom'].includes(getSide(placement)) ? 'y' : 'x';\n}\nfunction getAlignmentAxis(placement) {\n return getOppositeAxis(getSideAxis(placement));\n}\nfunction getAlignmentSides(placement, rects, rtl) {\n if (rtl === void 0) {\n rtl = false;\n }\n const alignment = getAlignment(placement);\n const alignmentAxis = getAlignmentAxis(placement);\n const length = getAxisLength(alignmentAxis);\n let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';\n if (rects.reference[length] > rects.floating[length]) {\n mainAlignmentSide = getOppositePlacement(mainAlignmentSide);\n }\n return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];\n}\nfunction getExpandedPlacements(placement) {\n const oppositePlacement = getOppositePlacement(placement);\n return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];\n}\nfunction getOppositeAlignmentPlacement(placement) {\n return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);\n}\nfunction getSideList(side, isStart, rtl) {\n const lr = ['left', 'right'];\n const rl = ['right', 'left'];\n const tb = ['top', 'bottom'];\n const bt = ['bottom', 'top'];\n switch (side) {\n case 'top':\n case 'bottom':\n if (rtl) return isStart ? rl : lr;\n return isStart ? lr : rl;\n case 'left':\n case 'right':\n return isStart ? tb : bt;\n default:\n return [];\n }\n}\nfunction getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {\n const alignment = getAlignment(placement);\n let list = getSideList(getSide(placement), direction === 'start', rtl);\n if (alignment) {\n list = list.map(side => side + \"-\" + alignment);\n if (flipAlignment) {\n list = list.concat(list.map(getOppositeAlignmentPlacement));\n }\n }\n return list;\n}\nfunction getOppositePlacement(placement) {\n return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);\n}\nfunction expandPaddingObject(padding) {\n return {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n ...padding\n };\n}\nfunction getPaddingObject(padding) {\n return typeof padding !== 'number' ? expandPaddingObject(padding) : {\n top: padding,\n right: padding,\n bottom: padding,\n left: padding\n };\n}\nfunction rectToClientRect(rect) {\n const {\n x,\n y,\n width,\n height\n } = rect;\n return {\n width,\n height,\n top: y,\n left: x,\n right: x + width,\n bottom: y + height,\n x,\n y\n };\n}\n\nexport { alignments, clamp, createCoords, evaluate, expandPaddingObject, floor, getAlignment, getAlignmentAxis, getAlignmentSides, getAxisLength, getExpandedPlacements, getOppositeAlignmentPlacement, getOppositeAxis, getOppositeAxisPlacements, getOppositePlacement, getPaddingObject, getSide, getSideAxis, max, min, placements, rectToClientRect, round, sides };\n","import { getSideAxis, getAlignmentAxis, getAxisLength, getSide, getAlignment, evaluate, getPaddingObject, rectToClientRect, min, clamp, placements, getAlignmentSides, getOppositeAlignmentPlacement, getOppositePlacement, getExpandedPlacements, getOppositeAxisPlacements, sides, max, getOppositeAxis } from '@floating-ui/utils';\nexport { rectToClientRect } from '@floating-ui/utils';\n\nfunction computeCoordsFromPlacement(_ref, placement, rtl) {\n let {\n reference,\n floating\n } = _ref;\n const sideAxis = getSideAxis(placement);\n const alignmentAxis = getAlignmentAxis(placement);\n const alignLength = getAxisLength(alignmentAxis);\n const side = getSide(placement);\n const isVertical = sideAxis === 'y';\n const commonX = reference.x + reference.width / 2 - floating.width / 2;\n const commonY = reference.y + reference.height / 2 - floating.height / 2;\n const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;\n let coords;\n switch (side) {\n case 'top':\n coords = {\n x: commonX,\n y: reference.y - floating.height\n };\n break;\n case 'bottom':\n coords = {\n x: commonX,\n y: reference.y + reference.height\n };\n break;\n case 'right':\n coords = {\n x: reference.x + reference.width,\n y: commonY\n };\n break;\n case 'left':\n coords = {\n x: reference.x - floating.width,\n y: commonY\n };\n break;\n default:\n coords = {\n x: reference.x,\n y: reference.y\n };\n }\n switch (getAlignment(placement)) {\n case 'start':\n coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);\n break;\n case 'end':\n coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);\n break;\n }\n return coords;\n}\n\n/**\n * Computes the `x` and `y` coordinates that will place the floating element\n * next to a given reference element.\n *\n * This export does not have any `platform` interface logic. You will need to\n * write one for the platform you are using Floating UI with.\n */\nconst computePosition = async (reference, floating, config) => {\n const {\n placement = 'bottom',\n strategy = 'absolute',\n middleware = [],\n platform\n } = config;\n const validMiddleware = middleware.filter(Boolean);\n const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));\n let rects = await platform.getElementRects({\n reference,\n floating,\n strategy\n });\n let {\n x,\n y\n } = computeCoordsFromPlacement(rects, placement, rtl);\n let statefulPlacement = placement;\n let middlewareData = {};\n let resetCount = 0;\n for (let i = 0; i < validMiddleware.length; i++) {\n const {\n name,\n fn\n } = validMiddleware[i];\n const {\n x: nextX,\n y: nextY,\n data,\n reset\n } = await fn({\n x,\n y,\n initialPlacement: placement,\n placement: statefulPlacement,\n strategy,\n middlewareData,\n rects,\n platform,\n elements: {\n reference,\n floating\n }\n });\n x = nextX != null ? nextX : x;\n y = nextY != null ? nextY : y;\n middlewareData = {\n ...middlewareData,\n [name]: {\n ...middlewareData[name],\n ...data\n }\n };\n if (reset && resetCount <= 50) {\n resetCount++;\n if (typeof reset === 'object') {\n if (reset.placement) {\n statefulPlacement = reset.placement;\n }\n if (reset.rects) {\n rects = reset.rects === true ? await platform.getElementRects({\n reference,\n floating,\n strategy\n }) : reset.rects;\n }\n ({\n x,\n y\n } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));\n }\n i = -1;\n }\n }\n return {\n x,\n y,\n placement: statefulPlacement,\n strategy,\n middlewareData\n };\n};\n\n/**\n * Resolves with an object of overflow side offsets that determine how much the\n * element is overflowing a given clipping boundary on each side.\n * - positive = overflowing the boundary by that number of pixels\n * - negative = how many pixels left before it will overflow\n * - 0 = lies flush with the boundary\n * @see https://floating-ui.com/docs/detectOverflow\n */\nasync function detectOverflow(state, options) {\n var _await$platform$isEle;\n if (options === void 0) {\n options = {};\n }\n const {\n x,\n y,\n platform,\n rects,\n elements,\n strategy\n } = state;\n const {\n boundary = 'clippingAncestors',\n rootBoundary = 'viewport',\n elementContext = 'floating',\n altBoundary = false,\n padding = 0\n } = evaluate(options, state);\n const paddingObject = getPaddingObject(padding);\n const altContext = elementContext === 'floating' ? 'reference' : 'floating';\n const element = elements[altBoundary ? altContext : elementContext];\n const clippingClientRect = rectToClientRect(await platform.getClippingRect({\n element: ((_await$platform$isEle = await (platform.isElement == null ? void 0 : platform.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || (await (platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating))),\n boundary,\n rootBoundary,\n strategy\n }));\n const rect = elementContext === 'floating' ? {\n x,\n y,\n width: rects.floating.width,\n height: rects.floating.height\n } : rects.reference;\n const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));\n const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {\n x: 1,\n y: 1\n } : {\n x: 1,\n y: 1\n };\n const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({\n elements,\n rect,\n offsetParent,\n strategy\n }) : rect);\n return {\n top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,\n bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,\n left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,\n right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x\n };\n}\n\n/**\n * Provides data to position an inner element of the floating element so that it\n * appears centered to the reference element.\n * @see https://floating-ui.com/docs/arrow\n */\nconst arrow = options => ({\n name: 'arrow',\n options,\n async fn(state) {\n const {\n x,\n y,\n placement,\n rects,\n platform,\n elements,\n middlewareData\n } = state;\n // Since `element` is required, we don't Partial<> the type.\n const {\n element,\n padding = 0\n } = evaluate(options, state) || {};\n if (element == null) {\n return {};\n }\n const paddingObject = getPaddingObject(padding);\n const coords = {\n x,\n y\n };\n const axis = getAlignmentAxis(placement);\n const length = getAxisLength(axis);\n const arrowDimensions = await platform.getDimensions(element);\n const isYAxis = axis === 'y';\n const minProp = isYAxis ? 'top' : 'left';\n const maxProp = isYAxis ? 'bottom' : 'right';\n const clientProp = isYAxis ? 'clientHeight' : 'clientWidth';\n const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];\n const startDiff = coords[axis] - rects.reference[axis];\n const arrowOffsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element));\n let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;\n\n // DOM platform can return `window` as the `offsetParent`.\n if (!clientSize || !(await (platform.isElement == null ? void 0 : platform.isElement(arrowOffsetParent)))) {\n clientSize = elements.floating[clientProp] || rects.floating[length];\n }\n const centerToReference = endDiff / 2 - startDiff / 2;\n\n // If the padding is large enough that it causes the arrow to no longer be\n // centered, modify the padding so that it is centered.\n const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;\n const minPadding = min(paddingObject[minProp], largestPossiblePadding);\n const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);\n\n // Make sure the arrow doesn't overflow the floating element if the center\n // point is outside the floating element's bounds.\n const min$1 = minPadding;\n const max = clientSize - arrowDimensions[length] - maxPadding;\n const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;\n const offset = clamp(min$1, center, max);\n\n // If the reference is small enough that the arrow's padding causes it to\n // to point to nothing for an aligned placement, adjust the offset of the\n // floating element itself. To ensure `shift()` continues to take action,\n // a single reset is performed when this is true.\n const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;\n const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max : 0;\n return {\n [axis]: coords[axis] + alignmentOffset,\n data: {\n [axis]: offset,\n centerOffset: center - offset - alignmentOffset,\n ...(shouldAddOffset && {\n alignmentOffset\n })\n },\n reset: shouldAddOffset\n };\n }\n});\n\nfunction getPlacementList(alignment, autoAlignment, allowedPlacements) {\n const allowedPlacementsSortedByAlignment = alignment ? [...allowedPlacements.filter(placement => getAlignment(placement) === alignment), ...allowedPlacements.filter(placement => getAlignment(placement) !== alignment)] : allowedPlacements.filter(placement => getSide(placement) === placement);\n return allowedPlacementsSortedByAlignment.filter(placement => {\n if (alignment) {\n return getAlignment(placement) === alignment || (autoAlignment ? getOppositeAlignmentPlacement(placement) !== placement : false);\n }\n return true;\n });\n}\n/**\n * Optimizes the visibility of the floating element by choosing the placement\n * that has the most space available automatically, without needing to specify a\n * preferred placement. Alternative to `flip`.\n * @see https://floating-ui.com/docs/autoPlacement\n */\nconst autoPlacement = function (options) {\n if (options === void 0) {\n options = {};\n }\n return {\n name: 'autoPlacement',\n options,\n async fn(state) {\n var _middlewareData$autoP, _middlewareData$autoP2, _placementsThatFitOnE;\n const {\n rects,\n middlewareData,\n placement,\n platform,\n elements\n } = state;\n const {\n crossAxis = false,\n alignment,\n allowedPlacements = placements,\n autoAlignment = true,\n ...detectOverflowOptions\n } = evaluate(options, state);\n const placements$1 = alignment !== undefined || allowedPlacements === placements ? getPlacementList(alignment || null, autoAlignment, allowedPlacements) : allowedPlacements;\n const overflow = await detectOverflow(state, detectOverflowOptions);\n const currentIndex = ((_middlewareData$autoP = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP.index) || 0;\n const currentPlacement = placements$1[currentIndex];\n if (currentPlacement == null) {\n return {};\n }\n const alignmentSides = getAlignmentSides(currentPlacement, rects, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)));\n\n // Make `computeCoords` start from the right place.\n if (placement !== currentPlacement) {\n return {\n reset: {\n placement: placements$1[0]\n }\n };\n }\n const currentOverflows = [overflow[getSide(currentPlacement)], overflow[alignmentSides[0]], overflow[alignmentSides[1]]];\n const allOverflows = [...(((_middlewareData$autoP2 = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP2.overflows) || []), {\n placement: currentPlacement,\n overflows: currentOverflows\n }];\n const nextPlacement = placements$1[currentIndex + 1];\n\n // There are more placements to check.\n if (nextPlacement) {\n return {\n data: {\n index: currentIndex + 1,\n overflows: allOverflows\n },\n reset: {\n placement: nextPlacement\n }\n };\n }\n const placementsSortedByMostSpace = allOverflows.map(d => {\n const alignment = getAlignment(d.placement);\n return [d.placement, alignment && crossAxis ?\n // Check along the mainAxis and main crossAxis side.\n d.overflows.slice(0, 2).reduce((acc, v) => acc + v, 0) :\n // Check only the mainAxis.\n d.overflows[0], d.overflows];\n }).sort((a, b) => a[1] - b[1]);\n const placementsThatFitOnEachSide = placementsSortedByMostSpace.filter(d => d[2].slice(0,\n // Aligned placements should not check their opposite crossAxis\n // side.\n getAlignment(d[0]) ? 2 : 3).every(v => v <= 0));\n const resetPlacement = ((_placementsThatFitOnE = placementsThatFitOnEachSide[0]) == null ? void 0 : _placementsThatFitOnE[0]) || placementsSortedByMostSpace[0][0];\n if (resetPlacement !== placement) {\n return {\n data: {\n index: currentIndex + 1,\n overflows: allOverflows\n },\n reset: {\n placement: resetPlacement\n }\n };\n }\n return {};\n }\n };\n};\n\n/**\n * Optimizes the visibility of the floating element by flipping the `placement`\n * in order to keep it in view when the preferred placement(s) will overflow the\n * clipping boundary. Alternative to `autoPlacement`.\n * @see https://floating-ui.com/docs/flip\n */\nconst flip = function (options) {\n if (options === void 0) {\n options = {};\n }\n return {\n name: 'flip',\n options,\n async fn(state) {\n var _middlewareData$arrow, _middlewareData$flip;\n const {\n placement,\n middlewareData,\n rects,\n initialPlacement,\n platform,\n elements\n }