{"version":3,"file":"vendor-Cz8Q5hqE.js","sources":["../../../node_modules/ky/distribution/errors/HTTPError.js","../../../node_modules/ky/distribution/errors/TimeoutError.js","../../../node_modules/ky/distribution/utils/is.js","../../../node_modules/ky/distribution/utils/merge.js","../../../node_modules/ky/distribution/core/constants.js","../../../node_modules/ky/distribution/utils/normalize.js","../../../node_modules/ky/distribution/utils/timeout.js","../../../node_modules/ky/distribution/utils/delay.js","../../../node_modules/ky/distribution/utils/options.js","../../../node_modules/ky/distribution/core/Ky.js","../../../node_modules/ky/distribution/index.js","../../../node_modules/selector-set/selector-set.next.js","../../../node_modules/delegated-events/dist/index.js","../../../node_modules/a11y-dialog/dist/a11y-dialog.esm.js","../../../node_modules/vanillajs-datepicker/js/lib/utils.js","../../../node_modules/vanillajs-datepicker/js/lib/date.js","../../../node_modules/vanillajs-datepicker/js/lib/date-format.js","../../../node_modules/vanillajs-datepicker/js/lib/dom.js","../../../node_modules/vanillajs-datepicker/js/lib/event.js","../../../node_modules/vanillajs-datepicker/js/i18n/base-locales.js","../../../node_modules/vanillajs-datepicker/js/options/defaultOptions.js","../../../node_modules/vanillajs-datepicker/js/options/processOptions.js","../../../node_modules/vanillajs-datepicker/js/options/shortcutKeys.js","../../../node_modules/vanillajs-datepicker/js/picker/templates/pickerTemplate.js","../../../node_modules/vanillajs-datepicker/js/picker/templates/daysTemplate.js","../../../node_modules/vanillajs-datepicker/js/picker/templates/weekNumbersTemplate.js","../../../node_modules/vanillajs-datepicker/js/picker/views/View.js","../../../node_modules/vanillajs-datepicker/js/picker/views/DaysView.js","../../../node_modules/vanillajs-datepicker/js/picker/views/MonthsView.js","../../../node_modules/vanillajs-datepicker/js/picker/views/YearsView.js","../../../node_modules/vanillajs-datepicker/js/events/functions.js","../../../node_modules/vanillajs-datepicker/js/events/pickerListeners.js","../../../node_modules/vanillajs-datepicker/js/picker/Picker.js","../../../node_modules/vanillajs-datepicker/js/events/elementListeners.js","../../../node_modules/vanillajs-datepicker/js/events/otherListeners.js","../../../node_modules/vanillajs-datepicker/js/Datepicker.js","../../../node_modules/tom-select/dist/esm/tom-select.js","../../../node_modules/imask/esm/core/utils.js","../../../node_modules/imask/esm/core/action-details.js","../../../node_modules/imask/esm/core/holder.js","../../../node_modules/imask/esm/masked/factory.js","../../../node_modules/imask/esm/controls/mask-element.js","../../../node_modules/imask/esm/controls/html-mask-element.js","../../../node_modules/imask/esm/controls/html-input-mask-element.js","../../../node_modules/imask/esm/controls/html-contenteditable-mask-element.js","../../../node_modules/imask/esm/controls/input-history.js","../../../node_modules/imask/esm/controls/input.js","../../../node_modules/imask/esm/core/change-details.js","../../../node_modules/imask/esm/core/continuous-tail-details.js","../../../node_modules/imask/esm/masked/base.js","../../../node_modules/imask/esm/masked/pattern/chunk-tail-details.js","../../../node_modules/imask/esm/masked/pattern/cursor.js","../../../node_modules/imask/esm/masked/pattern/fixed-definition.js","../../../node_modules/imask/esm/masked/pattern/input-definition.js","../../../node_modules/imask/esm/masked/regexp.js","../../../node_modules/imask/esm/masked/pattern.js","../../../node_modules/imask/esm/masked/range.js","../../../node_modules/imask/esm/masked/date.js","../../../node_modules/imask/esm/masked/number.js","../../../node_modules/js-cookie/dist/js.cookie.mjs","../../../node_modules/slide-element/dist/index.es.js","../../../node_modules/alpinejs/dist/module.esm.js","../../../node_modules/@alpinejs/collapse/dist/module.esm.js","../../../node_modules/@alpinejs/focus/dist/module.esm.js","../../../node_modules/vanillajs-datepicker/js/DateRangePicker.js"],"sourcesContent":["// eslint-lint-disable-next-line @typescript-eslint/naming-convention\nexport class HTTPError extends Error {\n constructor(response, request, options) {\n const code = (response.status || response.status === 0) ? response.status : '';\n const title = response.statusText || '';\n const status = `${code} ${title}`.trim();\n const reason = status ? `status code ${status}` : 'an unknown error';\n super(`Request failed with ${reason}`);\n Object.defineProperty(this, \"response\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"request\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"options\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n this.name = 'HTTPError';\n this.response = response;\n this.request = request;\n this.options = options;\n }\n}\n//# sourceMappingURL=HTTPError.js.map","export class TimeoutError extends Error {\n constructor(request) {\n super('Request timed out');\n Object.defineProperty(this, \"request\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n this.name = 'TimeoutError';\n this.request = request;\n }\n}\n//# sourceMappingURL=TimeoutError.js.map","// eslint-disable-next-line @typescript-eslint/ban-types\nexport const isObject = (value) => value !== null && typeof value === 'object';\n//# sourceMappingURL=is.js.map","import { isObject } from './is.js';\nexport const validateAndMerge = (...sources) => {\n for (const source of sources) {\n if ((!isObject(source) || Array.isArray(source)) && source !== undefined) {\n throw new TypeError('The `options` argument must be an object');\n }\n }\n return deepMerge({}, ...sources);\n};\nexport const mergeHeaders = (source1 = {}, source2 = {}) => {\n const result = new globalThis.Headers(source1);\n const isHeadersInstance = source2 instanceof globalThis.Headers;\n const source = new globalThis.Headers(source2);\n for (const [key, value] of source.entries()) {\n if ((isHeadersInstance && value === 'undefined') || value === undefined) {\n result.delete(key);\n }\n else {\n result.set(key, value);\n }\n }\n return result;\n};\n// TODO: Make this strongly-typed (no `any`).\nexport const deepMerge = (...sources) => {\n let returnValue = {};\n let headers = {};\n for (const source of sources) {\n if (Array.isArray(source)) {\n if (!Array.isArray(returnValue)) {\n returnValue = [];\n }\n returnValue = [...returnValue, ...source];\n }\n else if (isObject(source)) {\n for (let [key, value] of Object.entries(source)) {\n if (isObject(value) && key in returnValue) {\n value = deepMerge(returnValue[key], value);\n }\n returnValue = { ...returnValue, [key]: value };\n }\n if (isObject(source.headers)) {\n headers = mergeHeaders(headers, source.headers);\n returnValue.headers = headers;\n }\n }\n }\n return returnValue;\n};\n//# sourceMappingURL=merge.js.map","export const supportsRequestStreams = (() => {\n let duplexAccessed = false;\n let hasContentType = false;\n const supportsReadableStream = typeof globalThis.ReadableStream === 'function';\n const supportsRequest = typeof globalThis.Request === 'function';\n if (supportsReadableStream && supportsRequest) {\n hasContentType = new globalThis.Request('https://empty.invalid', {\n body: new globalThis.ReadableStream(),\n method: 'POST',\n // @ts-expect-error - Types are outdated.\n get duplex() {\n duplexAccessed = true;\n return 'half';\n },\n }).headers.has('Content-Type');\n }\n return duplexAccessed && !hasContentType;\n})();\nexport const supportsAbortController = typeof globalThis.AbortController === 'function';\nexport const supportsResponseStreams = typeof globalThis.ReadableStream === 'function';\nexport const supportsFormData = typeof globalThis.FormData === 'function';\nexport const requestMethods = ['get', 'post', 'put', 'patch', 'head', 'delete'];\nconst validate = () => undefined;\nvalidate();\nexport const responseTypes = {\n json: 'application/json',\n text: 'text/*',\n formData: 'multipart/form-data',\n arrayBuffer: '*/*',\n blob: '*/*',\n};\n// The maximum value of a 32bit int (see issue #117)\nexport const maxSafeTimeout = 2_147_483_647;\nexport const stop = Symbol('stop');\nexport const kyOptionKeys = {\n json: true,\n parseJson: true,\n stringifyJson: true,\n searchParams: true,\n prefixUrl: true,\n retry: true,\n timeout: true,\n hooks: true,\n throwHttpErrors: true,\n onDownloadProgress: true,\n fetch: true,\n};\nexport const requestOptionsRegistry = {\n method: true,\n headers: true,\n body: true,\n mode: true,\n credentials: true,\n cache: true,\n redirect: true,\n referrer: true,\n referrerPolicy: true,\n integrity: true,\n keepalive: true,\n signal: true,\n window: true,\n dispatcher: true,\n duplex: true,\n priority: true,\n};\n//# sourceMappingURL=constants.js.map","import { requestMethods } from '../core/constants.js';\nexport const normalizeRequestMethod = (input) => requestMethods.includes(input) ? input.toUpperCase() : input;\nconst retryMethods = ['get', 'put', 'head', 'delete', 'options', 'trace'];\nconst retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];\nconst retryAfterStatusCodes = [413, 429, 503];\nconst defaultRetryOptions = {\n limit: 2,\n methods: retryMethods,\n statusCodes: retryStatusCodes,\n afterStatusCodes: retryAfterStatusCodes,\n maxRetryAfter: Number.POSITIVE_INFINITY,\n backoffLimit: Number.POSITIVE_INFINITY,\n delay: attemptCount => 0.3 * (2 ** (attemptCount - 1)) * 1000,\n};\nexport const normalizeRetryOptions = (retry = {}) => {\n if (typeof retry === 'number') {\n return {\n ...defaultRetryOptions,\n limit: retry,\n };\n }\n if (retry.methods && !Array.isArray(retry.methods)) {\n throw new Error('retry.methods must be an array');\n }\n if (retry.statusCodes && !Array.isArray(retry.statusCodes)) {\n throw new Error('retry.statusCodes must be an array');\n }\n return {\n ...defaultRetryOptions,\n ...retry,\n afterStatusCodes: retryAfterStatusCodes,\n };\n};\n//# sourceMappingURL=normalize.js.map","import { TimeoutError } from '../errors/TimeoutError.js';\n// `Promise.race()` workaround (#91)\nexport default async function timeout(request, init, abortController, options) {\n return new Promise((resolve, reject) => {\n const timeoutId = setTimeout(() => {\n if (abortController) {\n abortController.abort();\n }\n reject(new TimeoutError(request));\n }, options.timeout);\n void options\n .fetch(request, init)\n .then(resolve)\n .catch(reject)\n .then(() => {\n clearTimeout(timeoutId);\n });\n });\n}\n//# sourceMappingURL=timeout.js.map","// https://github.com/sindresorhus/delay/tree/ab98ae8dfcb38e1593286c94d934e70d14a4e111\nexport default async function delay(ms, { signal }) {\n return new Promise((resolve, reject) => {\n if (signal) {\n signal.throwIfAborted();\n signal.addEventListener('abort', abortHandler, { once: true });\n }\n function abortHandler() {\n clearTimeout(timeoutId);\n reject(signal.reason);\n }\n const timeoutId = setTimeout(() => {\n signal?.removeEventListener('abort', abortHandler);\n resolve();\n }, ms);\n });\n}\n//# sourceMappingURL=delay.js.map","import { kyOptionKeys, requestOptionsRegistry } from '../core/constants.js';\nexport const findUnknownOptions = (request, options) => {\n const unknownOptions = {};\n for (const key in options) {\n if (!(key in requestOptionsRegistry) && !(key in kyOptionKeys) && !(key in request)) {\n unknownOptions[key] = options[key];\n }\n }\n return unknownOptions;\n};\n//# sourceMappingURL=options.js.map","import { HTTPError } from '../errors/HTTPError.js';\nimport { TimeoutError } from '../errors/TimeoutError.js';\nimport { deepMerge, mergeHeaders } from '../utils/merge.js';\nimport { normalizeRequestMethod, normalizeRetryOptions } from '../utils/normalize.js';\nimport timeout from '../utils/timeout.js';\nimport delay from '../utils/delay.js';\nimport { findUnknownOptions } from '../utils/options.js';\nimport { maxSafeTimeout, responseTypes, stop, supportsAbortController, supportsFormData, supportsResponseStreams, supportsRequestStreams, } from './constants.js';\nexport class Ky {\n static create(input, options) {\n const ky = new Ky(input, options);\n const function_ = async () => {\n if (typeof ky._options.timeout === 'number' && ky._options.timeout > maxSafeTimeout) {\n throw new RangeError(`The \\`timeout\\` option cannot be greater than ${maxSafeTimeout}`);\n }\n // Delay the fetch so that body method shortcuts can set the Accept header\n await Promise.resolve();\n let response = await ky._fetch();\n for (const hook of ky._options.hooks.afterResponse) {\n // eslint-disable-next-line no-await-in-loop\n const modifiedResponse = await hook(ky.request, ky._options, ky._decorateResponse(response.clone()));\n if (modifiedResponse instanceof globalThis.Response) {\n response = modifiedResponse;\n }\n }\n ky._decorateResponse(response);\n if (!response.ok && ky._options.throwHttpErrors) {\n let error = new HTTPError(response, ky.request, ky._options);\n for (const hook of ky._options.hooks.beforeError) {\n // eslint-disable-next-line no-await-in-loop\n error = await hook(error);\n }\n throw error;\n }\n // If `onDownloadProgress` is passed, it uses the stream API internally\n /* istanbul ignore next */\n if (ky._options.onDownloadProgress) {\n if (typeof ky._options.onDownloadProgress !== 'function') {\n throw new TypeError('The `onDownloadProgress` option must be a function');\n }\n if (!supportsResponseStreams) {\n throw new Error('Streams are not supported in your environment. `ReadableStream` is missing.');\n }\n return ky._stream(response.clone(), ky._options.onDownloadProgress);\n }\n return response;\n };\n const isRetriableMethod = ky._options.retry.methods.includes(ky.request.method.toLowerCase());\n const result = (isRetriableMethod ? ky._retry(function_) : function_());\n for (const [type, mimeType] of Object.entries(responseTypes)) {\n result[type] = async () => {\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n ky.request.headers.set('accept', ky.request.headers.get('accept') || mimeType);\n const awaitedResult = await result;\n const response = awaitedResult.clone();\n if (type === 'json') {\n if (response.status === 204) {\n return '';\n }\n const arrayBuffer = await response.clone().arrayBuffer();\n const responseSize = arrayBuffer.byteLength;\n if (responseSize === 0) {\n return '';\n }\n if (options.parseJson) {\n return options.parseJson(await response.text());\n }\n }\n return response[type]();\n };\n }\n return result;\n }\n // eslint-disable-next-line complexity\n constructor(input, options = {}) {\n Object.defineProperty(this, \"request\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"abortController\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"_retryCount\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: 0\n });\n Object.defineProperty(this, \"_input\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"_options\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n this._input = input;\n const credentials = this._input instanceof Request && 'credentials' in Request.prototype\n ? this._input.credentials\n : undefined;\n this._options = {\n ...(credentials && { credentials }), // For exactOptionalPropertyTypes\n ...options,\n headers: mergeHeaders(this._input.headers, options.headers),\n hooks: deepMerge({\n beforeRequest: [],\n beforeRetry: [],\n beforeError: [],\n afterResponse: [],\n }, options.hooks),\n method: normalizeRequestMethod(options.method ?? this._input.method),\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n prefixUrl: String(options.prefixUrl || ''),\n retry: normalizeRetryOptions(options.retry),\n throwHttpErrors: options.throwHttpErrors !== false,\n timeout: options.timeout ?? 10_000,\n fetch: options.fetch ?? globalThis.fetch.bind(globalThis),\n };\n if (typeof this._input !== 'string' && !(this._input instanceof URL || this._input instanceof globalThis.Request)) {\n throw new TypeError('`input` must be a string, URL, or Request');\n }\n if (this._options.prefixUrl && typeof this._input === 'string') {\n if (this._input.startsWith('/')) {\n throw new Error('`input` must not begin with a slash when using `prefixUrl`');\n }\n if (!this._options.prefixUrl.endsWith('/')) {\n this._options.prefixUrl += '/';\n }\n this._input = this._options.prefixUrl + this._input;\n }\n if (supportsAbortController) {\n this.abortController = new globalThis.AbortController();\n if (this._options.signal) {\n const originalSignal = this._options.signal;\n this._options.signal.addEventListener('abort', () => {\n this.abortController.abort(originalSignal.reason);\n });\n }\n this._options.signal = this.abortController.signal;\n }\n if (supportsRequestStreams) {\n // @ts-expect-error - Types are outdated.\n this._options.duplex = 'half';\n }\n this.request = new globalThis.Request(this._input, this._options);\n if (this._options.searchParams) {\n // eslint-disable-next-line unicorn/prevent-abbreviations\n const textSearchParams = typeof this._options.searchParams === 'string'\n ? this._options.searchParams.replace(/^\\?/, '')\n : new URLSearchParams(this._options.searchParams).toString();\n // eslint-disable-next-line unicorn/prevent-abbreviations\n const searchParams = '?' + textSearchParams;\n const url = this.request.url.replace(/(?:\\?.*?)?(?=#|$)/, searchParams);\n // To provide correct form boundary, Content-Type header should be deleted each time when new Request instantiated from another one\n if (((supportsFormData && this._options.body instanceof globalThis.FormData)\n || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers['content-type'])) {\n this.request.headers.delete('content-type');\n }\n // The spread of `this.request` is required as otherwise it misses the `duplex` option for some reason and throws.\n this.request = new globalThis.Request(new globalThis.Request(url, { ...this.request }), this._options);\n }\n if (this._options.json !== undefined) {\n this._options.body = this._options.stringifyJson?.(this._options.json) ?? JSON.stringify(this._options.json);\n this.request.headers.set('content-type', this._options.headers.get('content-type') ?? 'application/json');\n this.request = new globalThis.Request(this.request, { body: this._options.body });\n }\n }\n _calculateRetryDelay(error) {\n this._retryCount++;\n if (this._retryCount <= this._options.retry.limit && !(error instanceof TimeoutError)) {\n if (error instanceof HTTPError) {\n if (!this._options.retry.statusCodes.includes(error.response.status)) {\n return 0;\n }\n const retryAfter = error.response.headers.get('Retry-After');\n if (retryAfter && this._options.retry.afterStatusCodes.includes(error.response.status)) {\n let after = Number(retryAfter);\n if (Number.isNaN(after)) {\n after = Date.parse(retryAfter) - Date.now();\n }\n else {\n after *= 1000;\n }\n if (this._options.retry.maxRetryAfter !== undefined && after > this._options.retry.maxRetryAfter) {\n return 0;\n }\n return after;\n }\n if (error.response.status === 413) {\n return 0;\n }\n }\n const retryDelay = this._options.retry.delay(this._retryCount);\n return Math.min(this._options.retry.backoffLimit, retryDelay);\n }\n return 0;\n }\n _decorateResponse(response) {\n if (this._options.parseJson) {\n response.json = async () => this._options.parseJson(await response.text());\n }\n return response;\n }\n async _retry(function_) {\n try {\n return await function_();\n }\n catch (error) {\n const ms = Math.min(this._calculateRetryDelay(error), maxSafeTimeout);\n if (ms !== 0 && this._retryCount > 0) {\n await delay(ms, { signal: this._options.signal });\n for (const hook of this._options.hooks.beforeRetry) {\n // eslint-disable-next-line no-await-in-loop\n const hookResult = await hook({\n request: this.request,\n options: this._options,\n error: error,\n retryCount: this._retryCount,\n });\n // If `stop` is returned from the hook, the retry process is stopped\n if (hookResult === stop) {\n return;\n }\n }\n return this._retry(function_);\n }\n throw error;\n }\n }\n async _fetch() {\n for (const hook of this._options.hooks.beforeRequest) {\n // eslint-disable-next-line no-await-in-loop\n const result = await hook(this.request, this._options);\n if (result instanceof Request) {\n this.request = result;\n break;\n }\n if (result instanceof Response) {\n return result;\n }\n }\n const nonRequestOptions = findUnknownOptions(this.request, this._options);\n if (this._options.timeout === false) {\n return this._options.fetch(this.request.clone(), nonRequestOptions);\n }\n return timeout(this.request.clone(), nonRequestOptions, this.abortController, this._options);\n }\n /* istanbul ignore next */\n _stream(response, onDownloadProgress) {\n const totalBytes = Number(response.headers.get('content-length')) || 0;\n let transferredBytes = 0;\n if (response.status === 204) {\n if (onDownloadProgress) {\n onDownloadProgress({ percent: 1, totalBytes, transferredBytes }, new Uint8Array());\n }\n return new globalThis.Response(null, {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n });\n }\n return new globalThis.Response(new globalThis.ReadableStream({\n async start(controller) {\n const reader = response.body.getReader();\n if (onDownloadProgress) {\n onDownloadProgress({ percent: 0, transferredBytes: 0, totalBytes }, new Uint8Array());\n }\n async function read() {\n const { done, value } = await reader.read();\n if (done) {\n controller.close();\n return;\n }\n if (onDownloadProgress) {\n transferredBytes += value.byteLength;\n const percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;\n onDownloadProgress({ percent, transferredBytes, totalBytes }, value);\n }\n controller.enqueue(value);\n await read();\n }\n await read();\n },\n }), {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n });\n }\n}\n//# sourceMappingURL=Ky.js.map","/*! MIT License © Sindre Sorhus */\nimport { Ky } from './core/Ky.js';\nimport { requestMethods, stop } from './core/constants.js';\nimport { validateAndMerge } from './utils/merge.js';\nconst createInstance = (defaults) => {\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n const ky = (input, options) => Ky.create(input, validateAndMerge(defaults, options));\n for (const method of requestMethods) {\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n ky[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method }));\n }\n ky.create = (newDefaults) => createInstance(validateAndMerge(newDefaults));\n ky.extend = (newDefaults) => createInstance(validateAndMerge(defaults, newDefaults));\n ky.stop = stop;\n return ky;\n};\nconst ky = createInstance();\nexport default ky;\nexport { HTTPError } from './errors/HTTPError.js';\nexport { TimeoutError } from './errors/TimeoutError.js';\n//# sourceMappingURL=index.js.map","// Public: Create a new SelectorSet.\nexport default function SelectorSet() {\n // Construct new SelectorSet if called as a function.\n if (!(this instanceof SelectorSet)) {\n return new SelectorSet();\n }\n\n // Public: Number of selectors added to the set\n this.size = 0;\n\n // Internal: Incrementing ID counter\n this.uid = 0;\n\n // Internal: Array of String selectors in the set\n this.selectors = [];\n\n // Internal: Map of selector ids to objects\n this.selectorObjects = {};\n\n // Internal: All Object index String names mapping to Index objects.\n this.indexes = Object.create(this.indexes);\n\n // Internal: Used Object index String names mapping to Index objects.\n this.activeIndexes = [];\n}\n\n// Detect prefixed Element#matches function.\nvar docElem = window.document.documentElement;\nvar matches =\n docElem.matches ||\n docElem.webkitMatchesSelector ||\n docElem.mozMatchesSelector ||\n docElem.oMatchesSelector ||\n docElem.msMatchesSelector;\n\n// Public: Check if element matches selector.\n//\n// Maybe overridden with custom Element.matches function.\n//\n// el - An Element\n// selector - String CSS selector\n//\n// Returns true or false.\nSelectorSet.prototype.matchesSelector = function(el, selector) {\n return matches.call(el, selector);\n};\n\n// Public: Find all elements in the context that match the selector.\n//\n// Maybe overridden with custom querySelectorAll function.\n//\n// selectors - String CSS selectors.\n// context - Element context\n//\n// Returns non-live list of Elements.\nSelectorSet.prototype.querySelectorAll = function(selectors, context) {\n return context.querySelectorAll(selectors);\n};\n\n// Public: Array of indexes.\n//\n// name - Unique String name\n// selector - Function that takes a String selector and returns a String key\n// or undefined if it can't be used by the index.\n// element - Function that takes an Element and returns an Array of String\n// keys that point to indexed values.\n//\nSelectorSet.prototype.indexes = [];\n\n// Index by element id\nvar idRe = /^#((?:[\\w\\u00c0-\\uFFFF\\-]|\\\\.)+)/g;\nSelectorSet.prototype.indexes.push({\n name: 'ID',\n selector: function matchIdSelector(sel) {\n var m;\n if ((m = sel.match(idRe))) {\n return m[0].slice(1);\n }\n },\n element: function getElementId(el) {\n if (el.id) {\n return [el.id];\n }\n }\n});\n\n// Index by all of its class names\nvar classRe = /^\\.((?:[\\w\\u00c0-\\uFFFF\\-]|\\\\.)+)/g;\nSelectorSet.prototype.indexes.push({\n name: 'CLASS',\n selector: function matchClassSelector(sel) {\n var m;\n if ((m = sel.match(classRe))) {\n return m[0].slice(1);\n }\n },\n element: function getElementClassNames(el) {\n var className = el.className;\n if (className) {\n if (typeof className === 'string') {\n return className.split(/\\s/);\n } else if (typeof className === 'object' && 'baseVal' in className) {\n // className is a SVGAnimatedString\n // global SVGAnimatedString is not an exposed global in Opera 12\n return className.baseVal.split(/\\s/);\n }\n }\n }\n});\n\n// Index by tag/node name: `DIV`, `FORM`, `A`\nvar tagRe = /^((?:[\\w\\u00c0-\\uFFFF\\-]|\\\\.)+)/g;\nSelectorSet.prototype.indexes.push({\n name: 'TAG',\n selector: function matchTagSelector(sel) {\n var m;\n if ((m = sel.match(tagRe))) {\n return m[0].toUpperCase();\n }\n },\n element: function getElementTagName(el) {\n return [el.nodeName.toUpperCase()];\n }\n});\n\n// Default index just contains a single array of elements.\nSelectorSet.prototype.indexes['default'] = {\n name: 'UNIVERSAL',\n selector: function() {\n return true;\n },\n element: function() {\n return [true];\n }\n};\n\n// Use ES Maps when supported\nvar Map;\nif (typeof window.Map === 'function') {\n Map = window.Map;\n} else {\n Map = (function() {\n function Map() {\n this.map = {};\n }\n Map.prototype.get = function(key) {\n return this.map[key + ' '];\n };\n Map.prototype.set = function(key, value) {\n this.map[key + ' '] = value;\n };\n return Map;\n })();\n}\n\n// Regexps adopted from Sizzle\n// https://github.com/jquery/sizzle/blob/1.7/sizzle.js\n//\nvar chunker = /((?:\\((?:\\([^()]+\\)|[^()]+)+\\)|\\[(?:\\[[^\\[\\]]*\\]|['\"][^'\"]*['\"]|[^\\[\\]'\"]+)+\\]|\\\\.|[^ >+~,(\\[\\\\]+)+|[>+~])(\\s*,\\s*)?((?:.|\\r|\\n)*)/g;\n\n// Internal: Get indexes for selector.\n//\n// selector - String CSS selector\n//\n// Returns Array of {index, key}.\nfunction parseSelectorIndexes(allIndexes, selector) {\n allIndexes = allIndexes.slice(0).concat(allIndexes['default']);\n\n var allIndexesLen = allIndexes.length,\n i,\n j,\n m,\n dup,\n rest = selector,\n key,\n index,\n indexes = [];\n\n do {\n chunker.exec('');\n if ((m = chunker.exec(rest))) {\n rest = m[3];\n if (m[2] || !rest) {\n for (i = 0; i < allIndexesLen; i++) {\n index = allIndexes[i];\n if ((key = index.selector(m[1]))) {\n j = indexes.length;\n dup = false;\n while (j--) {\n if (indexes[j].index === index && indexes[j].key === key) {\n dup = true;\n break;\n }\n }\n if (!dup) {\n indexes.push({ index: index, key: key });\n }\n break;\n }\n }\n }\n }\n } while (m);\n\n return indexes;\n}\n\n// Internal: Find first item in Array that is a prototype of `proto`.\n//\n// ary - Array of objects\n// proto - Prototype of expected item in `ary`\n//\n// Returns object from `ary` if found. Otherwise returns undefined.\nfunction findByPrototype(ary, proto) {\n var i, len, item;\n for (i = 0, len = ary.length; i < len; i++) {\n item = ary[i];\n if (proto.isPrototypeOf(item)) {\n return item;\n }\n }\n}\n\n// Public: Log when added selector falls under the default index.\n//\n// This API should not be considered stable. May change between\n// minor versions.\n//\n// obj - {selector, data} Object\n//\n// SelectorSet.prototype.logDefaultIndexUsed = function(obj) {\n// console.warn(obj.selector, \"could not be indexed\");\n// };\n//\n// Returns nothing.\nSelectorSet.prototype.logDefaultIndexUsed = function() {};\n\n// Public: Add selector to set.\n//\n// selector - String CSS selector\n// data - Optional data Object (default: undefined)\n//\n// Returns nothing.\nSelectorSet.prototype.add = function(selector, data) {\n var obj,\n i,\n indexProto,\n key,\n index,\n objs,\n selectorIndexes,\n selectorIndex,\n indexes = this.activeIndexes,\n selectors = this.selectors,\n selectorObjects = this.selectorObjects;\n\n if (typeof selector !== 'string') {\n return;\n }\n\n obj = {\n id: this.uid++,\n selector: selector,\n data: data\n };\n selectorObjects[obj.id] = obj;\n\n selectorIndexes = parseSelectorIndexes(this.indexes, selector);\n for (i = 0; i < selectorIndexes.length; i++) {\n selectorIndex = selectorIndexes[i];\n key = selectorIndex.key;\n indexProto = selectorIndex.index;\n\n index = findByPrototype(indexes, indexProto);\n if (!index) {\n index = Object.create(indexProto);\n index.map = new Map();\n indexes.push(index);\n }\n\n if (indexProto === this.indexes['default']) {\n this.logDefaultIndexUsed(obj);\n }\n objs = index.map.get(key);\n if (!objs) {\n objs = [];\n index.map.set(key, objs);\n }\n objs.push(obj);\n }\n\n this.size++;\n selectors.push(selector);\n};\n\n// Public: Remove selector from set.\n//\n// selector - String CSS selector\n// data - Optional data Object (default: undefined)\n//\n// Returns nothing.\nSelectorSet.prototype.remove = function(selector, data) {\n if (typeof selector !== 'string') {\n return;\n }\n\n var selectorIndexes,\n selectorIndex,\n i,\n j,\n k,\n selIndex,\n objs,\n obj,\n indexes = this.activeIndexes,\n selectors = (this.selectors = []),\n selectorObjects = this.selectorObjects,\n removedIds = {},\n removeAll = arguments.length === 1;\n\n selectorIndexes = parseSelectorIndexes(this.indexes, selector);\n for (i = 0; i < selectorIndexes.length; i++) {\n selectorIndex = selectorIndexes[i];\n\n j = indexes.length;\n while (j--) {\n selIndex = indexes[j];\n if (selectorIndex.index.isPrototypeOf(selIndex)) {\n objs = selIndex.map.get(selectorIndex.key);\n if (objs) {\n k = objs.length;\n while (k--) {\n obj = objs[k];\n if (obj.selector === selector && (removeAll || obj.data === data)) {\n objs.splice(k, 1);\n removedIds[obj.id] = true;\n }\n }\n }\n break;\n }\n }\n }\n\n for (i in removedIds) {\n delete selectorObjects[i];\n this.size--;\n }\n\n for (i in selectorObjects) {\n selectors.push(selectorObjects[i].selector);\n }\n};\n\n// Sort by id property handler.\n//\n// a - Selector obj.\n// b - Selector obj.\n//\n// Returns Number.\nfunction sortById(a, b) {\n return a.id - b.id;\n}\n\n// Public: Find all matching decendants of the context element.\n//\n// context - An Element\n//\n// Returns Array of {selector, data, elements} matches.\nSelectorSet.prototype.queryAll = function(context) {\n if (!this.selectors.length) {\n return [];\n }\n\n var matches = {},\n results = [];\n var els = this.querySelectorAll(this.selectors.join(', '), context);\n\n var i, j, len, len2, el, m, match, obj;\n for (i = 0, len = els.length; i < len; i++) {\n el = els[i];\n m = this.matches(el);\n for (j = 0, len2 = m.length; j < len2; j++) {\n obj = m[j];\n if (!matches[obj.id]) {\n match = {\n id: obj.id,\n selector: obj.selector,\n data: obj.data,\n elements: []\n };\n matches[obj.id] = match;\n results.push(match);\n } else {\n match = matches[obj.id];\n }\n match.elements.push(el);\n }\n }\n\n return results.sort(sortById);\n};\n\n// Public: Match element against all selectors in set.\n//\n// el - An Element\n//\n// Returns Array of {selector, data} matches.\nSelectorSet.prototype.matches = function(el) {\n if (!el) {\n return [];\n }\n\n var i, j, k, len, len2, len3, index, keys, objs, obj, id;\n var indexes = this.activeIndexes,\n matchedIds = {},\n matches = [];\n\n for (i = 0, len = indexes.length; i < len; i++) {\n index = indexes[i];\n keys = index.element(el);\n if (keys) {\n for (j = 0, len2 = keys.length; j < len2; j++) {\n if ((objs = index.map.get(keys[j]))) {\n for (k = 0, len3 = objs.length; k < len3; k++) {\n obj = objs[k];\n id = obj.id;\n if (!matchedIds[id] && this.matchesSelector(el, obj.selector)) {\n matchedIds[id] = true;\n matches.push(obj);\n }\n }\n }\n }\n }\n }\n\n return matches.sort(sortById);\n};\n","import SelectorSet from 'selector-set';\n\nvar bubbleEvents = {};\nvar captureEvents = {};\nvar propagationStopped = new WeakMap();\nvar immediatePropagationStopped = new WeakMap();\nvar currentTargets = new WeakMap();\nvar currentTargetDesc = Object.getOwnPropertyDescriptor(Event.prototype, 'currentTarget');\n\nfunction before(subject, verb, fn) {\n var source = subject[verb];\n\n subject[verb] = function () {\n fn.apply(subject, arguments);\n return source.apply(subject, arguments);\n };\n\n return subject;\n}\n\nfunction matches(selectors, target, reverse) {\n var queue = [];\n var node = target;\n\n do {\n if (node.nodeType !== 1) break;\n\n var _matches = selectors.matches(node);\n\n if (_matches.length) {\n var matched = {\n node: node,\n observers: _matches\n };\n\n if (reverse) {\n queue.unshift(matched);\n } else {\n queue.push(matched);\n }\n }\n } while (node = node.parentElement);\n\n return queue;\n}\n\nfunction trackPropagation() {\n propagationStopped.set(this, true);\n}\n\nfunction trackImmediate() {\n propagationStopped.set(this, true);\n immediatePropagationStopped.set(this, true);\n}\n\nfunction getCurrentTarget() {\n return currentTargets.get(this) || null;\n}\n\nfunction defineCurrentTarget(event, getter) {\n if (!currentTargetDesc) return;\n Object.defineProperty(event, 'currentTarget', {\n configurable: true,\n enumerable: true,\n get: getter || currentTargetDesc.get\n });\n}\n\nfunction canDispatch(event) {\n try {\n event.eventPhase;\n return true;\n } catch (_) {\n return false;\n }\n}\n\nfunction dispatch(event) {\n if (!canDispatch(event)) return;\n var events = event.eventPhase === 1 ? captureEvents : bubbleEvents;\n var selectors = events[event.type];\n if (!selectors) return;\n var queue = matches(selectors, event.target, event.eventPhase === 1);\n if (!queue.length) return;\n before(event, 'stopPropagation', trackPropagation);\n before(event, 'stopImmediatePropagation', trackImmediate);\n defineCurrentTarget(event, getCurrentTarget);\n\n for (var i = 0, len1 = queue.length; i < len1; i++) {\n if (propagationStopped.get(event)) break;\n var matched = queue[i];\n currentTargets.set(event, matched.node);\n\n for (var j = 0, len2 = matched.observers.length; j < len2; j++) {\n if (immediatePropagationStopped.get(event)) break;\n matched.observers[j].data.call(matched.node, event);\n }\n }\n\n currentTargets[\"delete\"](event);\n defineCurrentTarget(event);\n}\n\nfunction on(name, selector, fn) {\n var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};\n var capture = options.capture ? true : false;\n var events = capture ? captureEvents : bubbleEvents;\n var selectors = events[name];\n\n if (!selectors) {\n selectors = new SelectorSet();\n events[name] = selectors;\n document.addEventListener(name, dispatch, capture);\n }\n\n selectors.add(selector, fn);\n}\nfunction off(name, selector, fn) {\n var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};\n var capture = options.capture ? true : false;\n var events = capture ? captureEvents : bubbleEvents;\n var selectors = events[name];\n if (!selectors) return;\n selectors.remove(selector, fn);\n if (selectors.size) return;\n delete events[name];\n document.removeEventListener(name, dispatch, capture);\n}\nfunction fire(target, name, detail) {\n return target.dispatchEvent(new CustomEvent(name, {\n bubbles: true,\n cancelable: true,\n detail: detail\n }));\n}\n\nexport { fire, off, on };\n","const not = {\n inert: ':not([inert]):not([inert] *)',\n negTabIndex: ':not([tabindex^=\"-\"])',\n disabled: ':not(:disabled)',\n};\n\nvar focusableSelectors = [\n `a[href]${not.inert}${not.negTabIndex}`,\n `area[href]${not.inert}${not.negTabIndex}`,\n `input:not([type=\"hidden\"]):not([type=\"radio\"])${not.inert}${not.negTabIndex}${not.disabled}`,\n `input[type=\"radio\"]${not.inert}${not.negTabIndex}${not.disabled}`,\n `select${not.inert}${not.negTabIndex}${not.disabled}`,\n `textarea${not.inert}${not.negTabIndex}${not.disabled}`,\n `button${not.inert}${not.negTabIndex}${not.disabled}`,\n `details${not.inert} > summary:first-of-type${not.negTabIndex}`,\n // Discard until Firefox supports `:has()`\n // See: https://github.com/KittyGiraudel/focusable-selectors/issues/12\n // `details:not(:has(> summary))${not.inert}${not.negTabIndex}`,\n `iframe${not.inert}${not.negTabIndex}`,\n `audio[controls]${not.inert}${not.negTabIndex}`,\n `video[controls]${not.inert}${not.negTabIndex}`,\n `[contenteditable]${not.inert}${not.negTabIndex}`,\n `[tabindex]${not.inert}${not.negTabIndex}`,\n];\n\n/**\n * Set the focus to the first element with `autofocus` with the element or the\n * element itself.\n */\nfunction moveFocusToDialog(el) {\n const focused = (el.querySelector('[autofocus]') || el);\n focused.focus();\n}\n/**\n * Get the first and last focusable elements in a given tree.\n */\nfunction getFocusableEdges(el) {\n // Check for a focusable element within the subtree of `el`.\n const first = findFocusableElement(el, true);\n // Only if we find the first element do we need to look for the last one. If\n // there’s no last element, we set `last` as a reference to `first` so that\n // the returned array is always of length 2.\n const last = first ? findFocusableElement(el, false) || first : null;\n return [first, last];\n}\n/**\n * Find the first focusable element inside the given node if `forward` is truthy\n * or the last focusable element otherwise.\n */\nfunction findFocusableElement(node, forward) {\n // If we’re walking forward, check if this node is focusable, and return it\n // immediately if it is.\n if (forward && isFocusable(node))\n return node;\n // We should only search the subtree of this node if it can have focusable\n // children.\n if (canHaveFocusableChildren(node)) {\n // Start walking the DOM tree, looking for focusable elements.\n // Case 1: If this node has a shadow root, search it recursively.\n if (node.shadowRoot) {\n // Descend into this subtree.\n let next = getNextChildEl(node.shadowRoot, forward);\n // Traverse siblings, searching the subtree of each one\n // for focusable elements.\n while (next) {\n const focusableEl = findFocusableElement(next, forward);\n if (focusableEl)\n return focusableEl;\n next = getNextSiblingEl(next, forward);\n }\n }\n // Case 2: If this node is a slot for a Custom Element, search its assigned\n // nodes recursively.\n else if (node.localName === 'slot') {\n const assignedElements = node.assignedElements({\n flatten: true,\n });\n if (!forward)\n assignedElements.reverse();\n for (const assignedElement of assignedElements) {\n const focusableEl = findFocusableElement(assignedElement, forward);\n if (focusableEl)\n return focusableEl;\n }\n }\n // Case 3: this is a regular Light DOM node. Search its subtree.\n else {\n // Descend into this subtree.\n let next = getNextChildEl(node, forward);\n // Traverse siblings, searching the subtree of each one\n // for focusable elements.\n while (next) {\n const focusableEl = findFocusableElement(next, forward);\n if (focusableEl)\n return focusableEl;\n next = getNextSiblingEl(next, forward);\n }\n }\n }\n // If we’re walking backward, we want to check the node’s entire subtree\n // before checking the node itself. If this node is focusable, return it.\n if (!forward && isFocusable(node))\n return node;\n return null;\n}\nfunction getNextChildEl(node, forward) {\n return forward ? node.firstElementChild : node.lastElementChild;\n}\nfunction getNextSiblingEl(el, forward) {\n return forward ? el.nextElementSibling : el.previousElementSibling;\n}\n/**\n * Determine if an element is hidden from the user.\n */\nconst isHidden = (el) => {\n // Browsers hide all non- descendants of closed
elements\n // from user interaction, but those non- elements may still match our\n // focusable-selectors and may still have dimensions, so we need a special\n // case to ignore them.\n if (el.matches('details:not([open]) *') &&\n !el.matches('details>summary:first-of-type'))\n return true;\n // If this element has no painted dimensions, it's hidden.\n return !(el.offsetWidth || el.offsetHeight || el.getClientRects().length);\n};\n/**\n * Determine if an element is focusable and has user-visible painted dimensions.\n */\nconst isFocusable = (el) => {\n // A shadow host that delegates focus will never directly receive focus,\n // even with `tabindex=0`. Consider our custom element, which\n // delegates focus to its shadow button:\n //\n // \n // #shadow-root\n // \n // \n //\n // The browser acts as as if there is only one focusable element – the shadow\n // button. Our library should behave the same way.\n if (el.shadowRoot?.delegatesFocus)\n return false;\n return el.matches(focusableSelectors.join(',')) && !isHidden(el);\n};\n/**\n * Determine if an element can have focusable children. Useful for bailing out\n * early when walking the DOM tree.\n * @example\n * This div is inert, so none of its children can be focused, even though they\n * meet our criteria for what is focusable. Once we check the div, we can skip\n * the rest of the subtree.\n * ```html\n *
\n * \n * Link\n *
\n * ```\n */\nfunction canHaveFocusableChildren(el) {\n // The browser will never send focus into a Shadow DOM if the host element\n // has a negative tabindex. This applies to both slotted Light DOM Shadow DOM\n // children\n if (el.shadowRoot && el.getAttribute('tabindex') === '-1')\n return false;\n // Elemments matching this selector are either hidden entirely from the user,\n // or are visible but unavailable for interaction. Their descentants can never\n // receive focus.\n return !el.matches(':disabled,[hidden],[inert]');\n}\n/**\n * Get the active element, accounting for Shadow DOM subtrees.\n * @author Cory LaViska\n * @see: https://www.abeautifulsite.net/posts/finding-the-active-element-in-a-shadow-root/\n */\nfunction getActiveElement(root = document) {\n const activeEl = root.activeElement;\n if (!activeEl)\n return null;\n // If there’s a shadow root, recursively find the active element within it.\n // If the recursive call returns null, return the active element\n // of the top-level Document.\n if (activeEl.shadowRoot)\n return getActiveElement(activeEl.shadowRoot) || document.activeElement;\n // If not, we can just return the active element\n return activeEl;\n}\n/**\n * Trap the focus inside the given element\n */\nfunction trapTabKey(el, event) {\n const [firstFocusableChild, lastFocusableChild] = getFocusableEdges(el);\n // If there are no focusable children in the dialog, prevent the user from\n // tabbing out of it\n if (!firstFocusableChild)\n return event.preventDefault();\n const activeElement = getActiveElement();\n // If the SHIFT key is pressed while tabbing (moving backwards) and the\n // currently focused item is the first one, move the focus to the last\n // focusable item from the dialog element\n if (event.shiftKey && activeElement === firstFocusableChild) {\n // @ts-ignore: we know that `lastFocusableChild` is not null here\n lastFocusableChild.focus();\n event.preventDefault();\n }\n // If the SHIFT key is not pressed (moving forwards) and the currently focused\n // item is the last one, move the focus to the first focusable item from the\n // dialog element\n else if (!event.shiftKey && activeElement === lastFocusableChild) {\n firstFocusableChild.focus();\n event.preventDefault();\n }\n}\n\nclass A11yDialog {\n $el;\n id;\n previouslyFocused;\n shown;\n constructor(element) {\n this.$el = element;\n this.id = this.$el.getAttribute('data-a11y-dialog') || this.$el.id;\n this.previouslyFocused = null;\n this.shown = false;\n this.maintainFocus = this.maintainFocus.bind(this);\n this.bindKeypress = this.bindKeypress.bind(this);\n this.handleTriggerClicks = this.handleTriggerClicks.bind(this);\n this.show = this.show.bind(this);\n this.hide = this.hide.bind(this);\n this.$el.setAttribute('aria-hidden', 'true');\n this.$el.setAttribute('aria-modal', 'true');\n this.$el.setAttribute('tabindex', '-1');\n if (!this.$el.hasAttribute('role')) {\n this.$el.setAttribute('role', 'dialog');\n }\n document.addEventListener('click', this.handleTriggerClicks, true);\n }\n /**\n * Destroy the current instance (after making sure the dialog has been hidden)\n * and remove all associated listeners from dialog openers and closers\n */\n destroy() {\n // Hide the dialog to avoid destroying an open instance\n this.hide();\n // Remove the click event delegates for our openers and closers\n document.removeEventListener('click', this.handleTriggerClicks, true);\n // Clone and replace the dialog element to prevent memory leaks caused by\n // event listeners that the author might not have cleaned up.\n this.$el.replaceWith(this.$el.cloneNode(true));\n // Dispatch a `destroy` event\n this.fire('destroy');\n return this;\n }\n /**\n * Show the dialog element, trap the current focus within it, listen for some\n * specific key presses and fire all registered callbacks for `show` event\n */\n show(event) {\n // If the dialog is already open, abort\n if (this.shown)\n return this;\n // Keep a reference to the currently focused element to be able to restore\n // it later\n this.shown = true;\n this.$el.removeAttribute('aria-hidden');\n this.previouslyFocused = getActiveElement();\n // Due to a long lasting bug in Safari, clicking an interactive element\n // (like a `)\n .join('');\n\nexport default optimizeTemplateHTML(`
\n
\n
\n
\n
\n ${getButtons([\n 'prev-button prev-btn',\n 'view-switch',\n 'next-button next-btn',\n ])}\n
\n
\n
\n
\n
\n ${getButtons([\n 'today-button today-btn',\n 'clear-button clear-btn',\n ])}\n
\n
\n
\n
`);\n","import {createTagRepeat, optimizeTemplateHTML} from '../../lib/utils.js';\n\nexport default optimizeTemplateHTML(`
\n
${createTagRepeat('span', 7, {class: 'dow'})}
\n
${createTagRepeat('span', 42)}
\n
`);\n","import {createTagRepeat, optimizeTemplateHTML} from '../../lib/utils.js';\n\nexport default optimizeTemplateHTML(`
\n
\n
${createTagRepeat('span', 6, {class: 'week'})}
\n
`);\n\n","import {pushUnique} from '../../lib/utils.js';\nimport {parseHTML, replaceChildNodes} from '../../lib/dom.js';\n\n// Base class of the view classes\nexport default class View {\n constructor(picker, config) {\n Object.assign(this, config, {\n picker,\n element: parseHTML(`
`).firstChild,\n selected: [],\n isRangeEnd: !!picker.datepicker.rangeSideIndex,\n });\n this.init(this.picker.datepicker.config);\n }\n\n init(options) {\n if ('pickLevel' in options) {\n this.isMinView = this.id === options.pickLevel;\n }\n this.setOptions(options);\n this.updateFocus();\n this.updateSelection();\n }\n\n prepareForRender(switchLabel, prevButtonDisabled, nextButtonDisabled) {\n // refresh disabled years on every render in order to clear the ones added\n // by beforeShow hook at previous render\n this.disabled = [];\n\n const picker = this.picker;\n picker.setViewSwitchLabel(switchLabel);\n picker.setPrevButtonDisabled(prevButtonDisabled);\n picker.setNextButtonDisabled(nextButtonDisabled);\n }\n\n setDisabled(date, classList) {\n classList.add('disabled');\n pushUnique(this.disabled, date);\n }\n\n // Execute beforeShow() callback and apply the result to the element\n // args:\n performBeforeHook(el, timeValue) {\n let result = this.beforeShow(new Date(timeValue));\n switch (typeof result) {\n case 'boolean':\n result = {enabled: result};\n break;\n case 'string':\n result = {classes: result};\n }\n\n if (result) {\n const classList = el.classList;\n if (result.enabled === false) {\n this.setDisabled(timeValue, classList);\n }\n if (result.classes) {\n const extraClasses = result.classes.split(/\\s+/);\n classList.add(...extraClasses);\n if (extraClasses.includes('disabled')) {\n this.setDisabled(timeValue, classList);\n }\n }\n if (result.content) {\n replaceChildNodes(el, result.content);\n }\n }\n }\n\n renderCell(el, content, cellVal, date, {selected, range}, outOfScope, extraClasses = []) {\n el.textContent = content;\n if (this.isMinView) {\n el.dataset.date = date;\n }\n\n const classList = el.classList;\n el.className = `datepicker-cell ${this.cellClass}`;\n if (cellVal < this.first) {\n classList.add('prev');\n } else if (cellVal > this.last) {\n classList.add('next');\n }\n classList.add(...extraClasses);\n if (outOfScope || this.checkDisabled(date, this.id)) {\n this.setDisabled(date, classList);\n }\n if (range) {\n const [rangeStart, rangeEnd] = range;\n if (cellVal > rangeStart && cellVal < rangeEnd) {\n classList.add('range');\n }\n if (cellVal === rangeStart) {\n classList.add('range-start');\n }\n if (cellVal === rangeEnd) {\n classList.add('range-end');\n }\n }\n if (selected.includes(cellVal)) {\n classList.add('selected');\n }\n if (cellVal === this.focused) {\n classList.add('focused');\n }\n\n if (this.beforeShow) {\n this.performBeforeHook(el, date);\n }\n }\n\n refreshCell(el, cellVal, selected, [rangeStart, rangeEnd]) {\n const classList = el.classList;\n classList.remove('range', 'range-start', 'range-end', 'selected', 'focused');\n if (cellVal > rangeStart && cellVal < rangeEnd) {\n classList.add('range');\n }\n if (cellVal === rangeStart) {\n classList.add('range-start');\n }\n if (cellVal === rangeEnd) {\n classList.add('range-end');\n }\n if (selected.includes(cellVal)) {\n classList.add('selected');\n }\n if (cellVal === this.focused) {\n classList.add('focused');\n }\n }\n\n changeFocusedCell(cellIndex) {\n this.grid.querySelectorAll('.focused').forEach((el) => {\n el.classList.remove('focused');\n });\n this.grid.children[cellIndex].classList.add('focused');\n }\n}\n","import {today, dateValue, addDays, addWeeks, dayOfTheWeekOf} from '../../lib/date.js';\nimport {formatDate} from '../../lib/date-format.js';\nimport {parseHTML, showElement, hideElement} from '../../lib/dom.js';\nimport daysTemplate from '../templates/daysTemplate.js';\nimport weekNumbersTemplate from '../templates/weekNumbersTemplate.js';\nimport View from './View.js';\n\nexport default class DaysView extends View {\n constructor(picker) {\n super(picker, {\n id: 0,\n name: 'days',\n cellClass: 'day',\n });\n }\n\n init(options, onConstruction = true) {\n if (onConstruction) {\n const inner = parseHTML(daysTemplate).firstChild;\n this.dow = inner.firstChild;\n this.grid = inner.lastChild;\n this.element.appendChild(inner);\n }\n super.init(options);\n }\n\n setOptions(options) {\n let updateDOW;\n\n if ('minDate' in options) {\n this.minDate = options.minDate;\n }\n if ('maxDate' in options) {\n this.maxDate = options.maxDate;\n }\n if (options.checkDisabled) {\n this.checkDisabled = options.checkDisabled;\n }\n if (options.daysOfWeekDisabled) {\n this.daysOfWeekDisabled = options.daysOfWeekDisabled;\n updateDOW = true;\n }\n if (options.daysOfWeekHighlighted) {\n this.daysOfWeekHighlighted = options.daysOfWeekHighlighted;\n }\n if ('todayHighlight' in options) {\n this.todayHighlight = options.todayHighlight;\n }\n if ('weekStart' in options) {\n this.weekStart = options.weekStart;\n this.weekEnd = options.weekEnd;\n updateDOW = true;\n }\n if (options.locale) {\n const locale = this.locale = options.locale;\n this.dayNames = locale.daysMin;\n this.switchLabelFormat = locale.titleFormat;\n updateDOW = true;\n }\n if ('beforeShowDay' in options) {\n this.beforeShow = typeof options.beforeShowDay === 'function'\n ? options.beforeShowDay\n : undefined;\n }\n\n if ('weekNumbers' in options) {\n if (options.weekNumbers && !this.weekNumbers) {\n const weeksElem = parseHTML(weekNumbersTemplate).firstChild;\n this.weekNumbers = {\n element: weeksElem,\n dow: weeksElem.firstChild,\n weeks: weeksElem.lastChild,\n };\n this.element.insertBefore(weeksElem, this.element.firstChild);\n } else if (this.weekNumbers && !options.weekNumbers) {\n this.element.removeChild(this.weekNumbers.element);\n this.weekNumbers = null;\n }\n }\n\n if ('getWeekNumber' in options) {\n this.getWeekNumber = options.getWeekNumber;\n }\n\n if ('showDaysOfWeek' in options) {\n if (options.showDaysOfWeek) {\n showElement(this.dow);\n if (this.weekNumbers) {\n showElement(this.weekNumbers.dow);\n }\n } else {\n hideElement(this.dow);\n if (this.weekNumbers) {\n hideElement(this.weekNumbers.dow);\n }\n }\n }\n\n // update days-of-week when locale, daysOfweekDisabled or weekStart is changed\n if (updateDOW) {\n Array.from(this.dow.children).forEach((el, index) => {\n const dow = (this.weekStart + index) % 7;\n el.textContent = this.dayNames[dow];\n el.className = this.daysOfWeekDisabled.includes(dow) ? 'dow disabled' : 'dow';\n });\n }\n }\n\n // Apply update on the focused date to view's settings\n updateFocus() {\n const viewDate = new Date(this.picker.viewDate);\n const viewYear = viewDate.getFullYear();\n const viewMonth = viewDate.getMonth();\n const firstOfMonth = dateValue(viewYear, viewMonth, 1);\n const start = dayOfTheWeekOf(firstOfMonth, this.weekStart, this.weekStart);\n\n this.first = firstOfMonth;\n this.last = dateValue(viewYear, viewMonth + 1, 0);\n this.start = start;\n this.focused = this.picker.viewDate;\n }\n\n // Apply update on the selected dates to view's settings\n updateSelection() {\n const {dates, rangepicker} = this.picker.datepicker;\n this.selected = dates;\n if (rangepicker) {\n this.range = rangepicker.dates;\n }\n }\n\n // Update the entire view UI\n render() {\n // update today marker on ever render\n this.today = this.todayHighlight ? today() : undefined;\n\n this.prepareForRender(\n formatDate(this.focused, this.switchLabelFormat, this.locale),\n this.first <= this.minDate,\n this.last >= this.maxDate\n );\n\n if (this.weekNumbers) {\n const weekStart = this.weekStart;\n const startOfWeek = dayOfTheWeekOf(this.first, weekStart, weekStart);\n Array.from(this.weekNumbers.weeks.children).forEach((el, index) => {\n const dateOfWeekStart = addWeeks(startOfWeek, index);\n el.textContent = this.getWeekNumber(dateOfWeekStart, weekStart);\n if (index > 3) {\n el.classList[dateOfWeekStart > this.last ? 'add' : 'remove']('next');\n }\n });\n }\n Array.from(this.grid.children).forEach((el, index) => {\n const current = addDays(this.start, index);\n const dateObj = new Date(current);\n const day = dateObj.getDay();\n const extraClasses = [];\n\n if (this.today === current) {\n extraClasses.push('today');\n }\n if (this.daysOfWeekHighlighted.includes(day)) {\n extraClasses.push('highlighted');\n }\n\n this.renderCell(\n el,\n dateObj.getDate(),\n current,\n current,\n this,\n current < this.minDate\n || current > this.maxDate\n || this.daysOfWeekDisabled.includes(day),\n extraClasses\n );\n });\n }\n\n // Update the view UI by applying the changes of selected and focused items\n refresh() {\n const range = this.range || [];\n Array.from(this.grid.children).forEach((el) => {\n this.refreshCell(el, Number(el.dataset.date), this.selected, range);\n });\n }\n\n // Update the view UI by applying the change of focused item\n refreshFocus() {\n this.changeFocusedCell(Math.round((this.focused - this.start) / 86400000));\n }\n}\n","import {pushUnique, createTagRepeat} from '../../lib/utils.js';\nimport {dateValue, regularizeDate} from '../../lib/date.js';\nimport {parseHTML} from '../../lib/dom.js';\nimport View from './View.js';\n\nfunction computeMonthRange(range, thisYear) {\n if (!range || !range[0] || !range[1]) {\n return;\n }\n\n const [[startY, startM], [endY, endM]] = range;\n if (startY > thisYear || endY < thisYear) {\n return;\n }\n return [\n startY === thisYear ? startM : -1,\n endY === thisYear ? endM : 12,\n ];\n}\n\nexport default class MonthsView extends View {\n constructor(picker) {\n super(picker, {\n id: 1,\n name: 'months',\n cellClass: 'month',\n });\n }\n\n init(options, onConstruction = true) {\n if (onConstruction) {\n this.grid = this.element;\n this.element.classList.add('months', 'datepicker-grid');\n this.grid.appendChild(parseHTML(createTagRepeat('span', 12, {'data-month': ix => ix})));\n this.first = 0;\n this.last = 11;\n }\n super.init(options);\n }\n\n setOptions(options) {\n if (options.locale) {\n this.monthNames = options.locale.monthsShort;\n }\n if ('minDate' in options) {\n if (options.minDate === undefined) {\n this.minYear = this.minMonth = this.minDate = undefined;\n } else {\n const minDateObj = new Date(options.minDate);\n this.minYear = minDateObj.getFullYear();\n this.minMonth = minDateObj.getMonth();\n this.minDate = minDateObj.setDate(1);\n }\n }\n if ('maxDate' in options) {\n if (options.maxDate === undefined) {\n this.maxYear = this.maxMonth = this.maxDate = undefined;\n } else {\n const maxDateObj = new Date(options.maxDate);\n this.maxYear = maxDateObj.getFullYear();\n this.maxMonth = maxDateObj.getMonth();\n this.maxDate = dateValue(this.maxYear, this.maxMonth + 1, 0);\n }\n }\n if (options.checkDisabled) {\n this.checkDisabled = this.isMinView || options.datesDisabled === null\n ? options.checkDisabled\n : () => false;\n }\n if ('beforeShowMonth' in options) {\n this.beforeShow = typeof options.beforeShowMonth === 'function'\n ? options.beforeShowMonth\n : undefined;\n }\n }\n\n // Update view's settings to reflect the viewDate set on the picker\n updateFocus() {\n const viewDate = new Date(this.picker.viewDate);\n this.year = viewDate.getFullYear();\n this.focused = viewDate.getMonth();\n }\n\n // Update view's settings to reflect the selected dates\n updateSelection() {\n const {dates, rangepicker} = this.picker.datepicker;\n this.selected = dates.reduce((selected, timeValue) => {\n const date = new Date(timeValue);\n const year = date.getFullYear();\n const month = date.getMonth();\n if (selected[year] === undefined) {\n selected[year] = [month];\n } else {\n pushUnique(selected[year], month);\n }\n return selected;\n }, {});\n if (rangepicker && rangepicker.dates) {\n this.range = rangepicker.dates.map(timeValue => {\n const date = new Date(timeValue);\n return isNaN(date) ? undefined : [date.getFullYear(), date.getMonth()];\n });\n }\n }\n\n // Update the entire view UI\n render() {\n this.prepareForRender(\n this.year,\n this.year <= this.minYear,\n this.year >= this.maxYear\n );\n\n const selected = this.selected[this.year] || [];\n const yrOutOfRange = this.year < this.minYear || this.year > this.maxYear;\n const isMinYear = this.year === this.minYear;\n const isMaxYear = this.year === this.maxYear;\n const range = computeMonthRange(this.range, this.year);\n\n Array.from(this.grid.children).forEach((el, index) => {\n const date = regularizeDate(new Date(this.year, index, 1), 1, this.isRangeEnd);\n\n this.renderCell(\n el,\n this.monthNames[index],\n index,\n date,\n {selected, range},\n yrOutOfRange\n || isMinYear && index < this.minMonth\n || isMaxYear && index > this.maxMonth\n );\n });\n }\n\n // Update the view UI by applying the changes of selected and focused items\n refresh() {\n const selected = this.selected[this.year] || [];\n const range = computeMonthRange(this.range, this.year) || [];\n Array.from(this.grid.children).forEach((el, index) => {\n this.refreshCell(el, index, selected, range);\n });\n }\n\n // Update the view UI by applying the change of focused item\n refreshFocus() {\n this.changeFocusedCell(this.focused);\n }\n}","import {pushUnique, createTagRepeat} from '../../lib/utils.js';\nimport {dateValue, regularizeDate, startOfYearPeriod} from '../../lib/date.js';\nimport {parseHTML} from '../../lib/dom.js';\nimport View from './View.js';\n\nfunction toTitleCase(word) {\n return [...word].reduce((str, ch, ix) => str += ix ? ch : ch.toUpperCase(), '');\n}\n\n// Class representing the years and decades view elements\nexport default class YearsView extends View {\n constructor(picker, config) {\n super(picker, config);\n }\n\n init(options, onConstruction = true) {\n if (onConstruction) {\n this.navStep = this.step * 10;\n this.beforeShowOption = `beforeShow${toTitleCase(this.cellClass)}`;\n this.grid = this.element;\n this.element.classList.add(this.name, 'datepicker-grid');\n this.grid.appendChild(parseHTML(createTagRepeat('span', 12)));\n }\n super.init(options);\n }\n\n setOptions(options) {\n if ('minDate' in options) {\n if (options.minDate === undefined) {\n this.minYear = this.minDate = undefined;\n } else {\n this.minYear = startOfYearPeriod(options.minDate, this.step);\n this.minDate = dateValue(this.minYear, 0, 1);\n }\n }\n if ('maxDate' in options) {\n if (options.maxDate === undefined) {\n this.maxYear = this.maxDate = undefined;\n } else {\n this.maxYear = startOfYearPeriod(options.maxDate, this.step);\n this.maxDate = dateValue(this.maxYear, 11, 31);\n }\n }\n if (options.checkDisabled) {\n this.checkDisabled = this.isMinView || options.datesDisabled === null\n ? options.checkDisabled\n : () => false;\n }\n if (this.beforeShowOption in options) {\n const beforeShow = options[this.beforeShowOption];\n this.beforeShow = typeof beforeShow === 'function' ? beforeShow : undefined;\n }\n }\n\n // Update view's settings to reflect the viewDate set on the picker\n updateFocus() {\n const viewDate = new Date(this.picker.viewDate);\n const first = startOfYearPeriod(viewDate, this.navStep);\n const last = first + 9 * this.step;\n\n this.first = first;\n this.last = last;\n this.start = first - this.step;\n this.focused = startOfYearPeriod(viewDate, this.step);\n }\n\n // Update view's settings to reflect the selected dates\n updateSelection() {\n const {dates, rangepicker} = this.picker.datepicker;\n this.selected = dates.reduce((years, timeValue) => {\n return pushUnique(years, startOfYearPeriod(timeValue, this.step));\n }, []);\n if (rangepicker && rangepicker.dates) {\n this.range = rangepicker.dates.map(timeValue => {\n if (timeValue !== undefined) {\n return startOfYearPeriod(timeValue, this.step);\n }\n });\n }\n }\n\n // Update the entire view UI\n render() {\n this.prepareForRender(\n `${this.first}-${this.last}`,\n this.first <= this.minYear,\n this.last >= this.maxYear\n );\n\n Array.from(this.grid.children).forEach((el, index) => {\n const current = this.start + (index * this.step);\n const date = regularizeDate(new Date(current, 0, 1), 2, this.isRangeEnd);\n\n el.dataset.year = current;\n this.renderCell(\n el,\n current,\n current,\n date,\n this,\n current < this.minYear || current > this.maxYear\n );\n });\n }\n\n // Update the view UI by applying the changes of selected and focused items\n refresh() {\n const range = this.range || [];\n Array.from(this.grid.children).forEach((el) => {\n this.refreshCell(el, Number(el.textContent), this.selected, range);\n });\n }\n\n // Update the view UI by applying the change of focused item\n refreshFocus() {\n this.changeFocusedCell(Math.round((this.focused - this.start) / this.step));\n }\n}\n","import {limitToRange} from '../lib/utils.js';\nimport {today, addMonths, addYears} from '../lib/date.js';\nimport {isActiveElement} from '../lib/dom.js';\n\nexport function triggerDatepickerEvent(datepicker, type) {\n const options = {\n bubbles: true,\n cancelable: true,\n detail: {\n date: datepicker.getDate(),\n viewDate: new Date(datepicker.picker.viewDate),\n viewId: datepicker.picker.currentView.id,\n datepicker,\n },\n };\n datepicker.element.dispatchEvent(new CustomEvent(type, options));\n}\n\n// direction: -1 (to previous), 1 (to next)\nexport function goToPrevOrNext(datepicker, direction) {\n const {config, picker} = datepicker;\n const {currentView, viewDate} = picker;\n let newViewDate;\n switch (currentView.id) {\n case 0:\n newViewDate = addMonths(viewDate, direction);\n break;\n case 1:\n newViewDate = addYears(viewDate, direction);\n break;\n default:\n newViewDate = addYears(viewDate, direction * currentView.navStep);\n }\n newViewDate = limitToRange(newViewDate, config.minDate, config.maxDate);\n picker.changeFocus(newViewDate).render();\n}\n\nexport function switchView(datepicker) {\n const viewId = datepicker.picker.currentView.id;\n if (viewId === datepicker.config.maxView) {\n return;\n }\n datepicker.picker.changeView(viewId + 1).render();\n}\n\nexport function clearSelection(datepicker) {\n datepicker.setDate({clear: true});\n}\n\nexport function goToOrSelectToday(datepicker) {\n const currentDate = today();\n if (datepicker.config.todayButtonMode === 1) {\n datepicker.setDate(currentDate, {forceRefresh: true, viewDate: currentDate});\n } else {\n datepicker.setFocusedDate(currentDate, true);\n }\n}\n\nexport function unfocus(datepicker) {\n const onBlur = () => {\n if (datepicker.config.updateOnBlur) {\n datepicker.update({revert: true});\n } else {\n datepicker.refresh('input');\n }\n datepicker.hide();\n };\n const element = datepicker.element;\n\n if (isActiveElement(element)) {\n element.addEventListener('blur', onBlur, {once: true});\n } else {\n onBlur();\n }\n}\n","import {addMonths, addYears} from '../lib/date.js';\nimport {findElementInEventPath} from '../lib/event.js';\nimport {goToPrevOrNext, switchView} from './functions.js';\n\nfunction goToSelectedMonthOrYear(datepicker, selection) {\n const picker = datepicker.picker;\n const viewDate = new Date(picker.viewDate);\n const viewId = picker.currentView.id;\n const newDate = viewId === 1\n ? addMonths(viewDate, selection - viewDate.getMonth())\n : addYears(viewDate, selection - viewDate.getFullYear());\n\n picker.changeFocus(newDate).changeView(viewId - 1).render();\n}\n\nexport function onClickViewSwitch(datepicker) {\n switchView(datepicker);\n}\n\nexport function onClickPrevButton(datepicker) {\n goToPrevOrNext(datepicker, -1);\n}\n\nexport function onClickNextButton(datepicker) {\n goToPrevOrNext(datepicker, 1);\n}\n\n// For the picker's main block to delegete the events from `datepicker-cell`s\nexport function onClickView(datepicker, ev) {\n const target = findElementInEventPath(ev, '.datepicker-cell');\n if (!target || target.classList.contains('disabled')) {\n return;\n }\n\n const {id, isMinView} = datepicker.picker.currentView;\n const data = target.dataset;\n if (isMinView) {\n datepicker.setDate(Number(data.date));\n } else if (id === 1) {\n goToSelectedMonthOrYear(datepicker, Number(data.month));\n } else {\n goToSelectedMonthOrYear(datepicker, Number(data.year));\n }\n}\n\nexport function onMousedownPicker(ev) {\n ev.preventDefault();\n}\n","import {lastItemOf, isInRange, limitToRange} from '../lib/utils.js';\nimport {today, regularizeDate} from '../lib/date.js';\nimport {\n parseHTML,\n getParent,\n showElement,\n hideElement,\n emptyChildNodes,\n} from '../lib/dom.js';\nimport {registerListeners} from '../lib/event.js';\nimport pickerTemplate from './templates/pickerTemplate.js';\nimport DaysView from './views/DaysView.js';\nimport MonthsView from './views/MonthsView.js';\nimport YearsView from './views/YearsView.js';\nimport {\n triggerDatepickerEvent,\n clearSelection,\n goToOrSelectToday,\n} from '../events/functions.js';\nimport {\n onClickViewSwitch,\n onClickPrevButton,\n onClickNextButton,\n onClickView,\n onMousedownPicker,\n} from '../events/pickerListeners.js';\n\nconst orientClasses = ['left', 'top', 'right', 'bottom'].reduce((obj, key) => {\n obj[key] = `datepicker-orient-${key}`;\n return obj;\n}, {});\nconst toPx = num => num ? `${num}px` : num;\n\nfunction processPickerOptions(picker, options) {\n if ('title' in options) {\n if (options.title) {\n picker.controls.title.textContent = options.title;\n showElement(picker.controls.title);\n } else {\n picker.controls.title.textContent = '';\n hideElement(picker.controls.title);\n }\n }\n if (options.prevArrow) {\n const prevButton = picker.controls.prevButton;\n emptyChildNodes(prevButton);\n options.prevArrow.forEach((node) => {\n prevButton.appendChild(node.cloneNode(true));\n });\n }\n if (options.nextArrow) {\n const nextButton = picker.controls.nextButton;\n emptyChildNodes(nextButton);\n options.nextArrow.forEach((node) => {\n nextButton.appendChild(node.cloneNode(true));\n });\n }\n if (options.locale) {\n picker.controls.todayButton.textContent = options.locale.today;\n picker.controls.clearButton.textContent = options.locale.clear;\n }\n if ('todayButton' in options) {\n if (options.todayButton) {\n showElement(picker.controls.todayButton);\n } else {\n hideElement(picker.controls.todayButton);\n }\n }\n if ('minDate' in options || 'maxDate' in options) {\n const {minDate, maxDate} = picker.datepicker.config;\n picker.controls.todayButton.disabled = !isInRange(today(), minDate, maxDate);\n }\n if ('clearButton' in options) {\n if (options.clearButton) {\n showElement(picker.controls.clearButton);\n } else {\n hideElement(picker.controls.clearButton);\n }\n }\n}\n\n// Compute view date to reset, which will be...\n// - the last item of the selected dates or defaultViewDate if no selection\n// - limitted to minDate or maxDate if it exceeds the range\nfunction computeResetViewDate(datepicker) {\n const {dates, config, rangeSideIndex} = datepicker;\n const viewDate = dates.length > 0\n ? lastItemOf(dates)\n : regularizeDate(config.defaultViewDate, config.pickLevel, rangeSideIndex);\n return limitToRange(viewDate, config.minDate, config.maxDate);\n}\n\n// Change current view's view date\nfunction setViewDate(picker, newDate) {\n if (!('_oldViewDate' in picker) && newDate !== picker.viewDate) {\n picker._oldViewDate = picker.viewDate;\n }\n picker.viewDate = newDate;\n\n // return whether the new date is in different period on time from the one\n // displayed in the current view\n // when true, the view needs to be re-rendered on the next UI refresh.\n const {id, year, first, last} = picker.currentView;\n const viewYear = new Date(newDate).getFullYear();\n switch (id) {\n case 0:\n return newDate < first || newDate > last;\n case 1:\n return viewYear !== year;\n default:\n return viewYear < first || viewYear > last;\n }\n}\n\nfunction getTextDirection(el) {\n return window.getComputedStyle(el).direction;\n}\n\n// find the closet scrollable ancestor elemnt under the body\nfunction findScrollParents(el) {\n const parent = getParent(el);\n if (parent === document.body || !parent) {\n return;\n }\n\n // checking overflow only is enough because computed overflow cannot be\n // visible or a combination of visible and other when either axis is set\n // to other than visible.\n // (Setting one axis to other than 'visible' while the other is 'visible'\n // results in the other axis turning to 'auto')\n return window.getComputedStyle(parent).overflow !== 'visible'\n ? parent\n : findScrollParents(parent);\n}\n\n// Class representing the picker UI\nexport default class Picker {\n constructor(datepicker) {\n const {config, inputField} = this.datepicker = datepicker;\n\n const template = pickerTemplate.replace(/%buttonClass%/g, config.buttonClass);\n const element = this.element = parseHTML(template).firstChild;\n const [header, main, footer] = element.firstChild.children;\n const title = header.firstElementChild;\n const [prevButton, viewSwitch, nextButton] = header.lastElementChild.children;\n const [todayButton, clearButton] = footer.firstChild.children;\n const controls = {\n title,\n prevButton,\n viewSwitch,\n nextButton,\n todayButton,\n clearButton,\n };\n this.main = main;\n this.controls = controls;\n\n const elementClass = inputField ? 'dropdown' : 'inline';\n element.classList.add(`datepicker-${elementClass}`);\n\n processPickerOptions(this, config);\n this.viewDate = computeResetViewDate(datepicker);\n\n // set up event listeners\n registerListeners(datepicker, [\n [element, 'mousedown', onMousedownPicker],\n [main, 'click', onClickView.bind(null, datepicker)],\n [controls.viewSwitch, 'click', onClickViewSwitch.bind(null, datepicker)],\n [controls.prevButton, 'click', onClickPrevButton.bind(null, datepicker)],\n [controls.nextButton, 'click', onClickNextButton.bind(null, datepicker)],\n [controls.todayButton, 'click', goToOrSelectToday.bind(null, datepicker)],\n [controls.clearButton, 'click', clearSelection.bind(null, datepicker)],\n ]);\n\n // set up views\n this.views = [\n new DaysView(this),\n new MonthsView(this),\n new YearsView(this, {id: 2, name: 'years', cellClass: 'year', step: 1}),\n new YearsView(this, {id: 3, name: 'decades', cellClass: 'decade', step: 10}),\n ];\n this.currentView = this.views[config.startView];\n\n this.currentView.render();\n this.main.appendChild(this.currentView.element);\n if (config.container) {\n config.container.appendChild(this.element);\n } else {\n inputField.after(this.element);\n }\n }\n\n setOptions(options) {\n processPickerOptions(this, options);\n this.views.forEach((view) => {\n view.init(options, false);\n });\n this.currentView.render();\n }\n\n detach() {\n this.element.remove();\n }\n\n show() {\n if (this.active) {\n return;\n }\n\n const {datepicker, element} = this;\n const inputField = datepicker.inputField;\n if (inputField) {\n // ensure picker's direction matches input's\n const inputDirection = getTextDirection(inputField);\n if (inputDirection !== getTextDirection(getParent(element))) {\n element.dir = inputDirection;\n } else if (element.dir) {\n element.removeAttribute('dir');\n }\n\n // Determine the picker's position first to prevent `orientation: 'auto'`\n // from being miscalculated to 'bottom' after the picker temporarily\n // shown below the input field expands the document height if the field\n // is at the bottom edge of the document\n this.place();\n element.classList.add('active');\n\n if (datepicker.config.disableTouchKeyboard) {\n inputField.blur();\n }\n } else {\n element.classList.add('active');\n }\n this.active = true;\n triggerDatepickerEvent(datepicker, 'show');\n }\n\n hide() {\n if (!this.active) {\n return;\n }\n this.datepicker.exitEditMode();\n this.element.classList.remove('active');\n this.active = false;\n triggerDatepickerEvent(this.datepicker, 'hide');\n }\n\n place() {\n const {classList, style} = this.element;\n // temporarily display the picker to get its size and offset parent\n style.display = 'block';\n\n const {\n width: calendarWidth,\n height: calendarHeight,\n } = this.element.getBoundingClientRect();\n const offsetParent = this.element.offsetParent;\n // turn the picker back to hidden so that the position is determined with\n // the state before it is shown.\n style.display = '';\n\n const {config, inputField} = this.datepicker;\n const {\n left: inputLeft,\n top: inputTop,\n right: inputRight,\n bottom: inputBottom,\n width: inputWidth,\n height: inputHeight\n } = inputField.getBoundingClientRect();\n let {x: orientX, y: orientY} = config.orientation;\n let left = inputLeft;\n let top = inputTop;\n\n // caliculate offsetLeft/Top of inputField\n if (offsetParent === document.body || !offsetParent) {\n left += window.scrollX;\n top += window.scrollY;\n } else {\n const offsetParentRect = offsetParent.getBoundingClientRect();\n left -= offsetParentRect.left - offsetParent.scrollLeft;\n top -= offsetParentRect.top - offsetParent.scrollTop;\n }\n\n // caliculate the boundaries of the visible area that contains inputField\n const scrollParent = findScrollParents(inputField);\n let scrollAreaLeft = 0;\n let scrollAreaTop = 0;\n let {\n clientWidth: scrollAreaRight,\n clientHeight: scrollAreaBottom,\n } = document.documentElement;\n\n if (scrollParent) {\n const scrollParentRect = scrollParent.getBoundingClientRect();\n if (scrollParentRect.top > 0) {\n scrollAreaTop = scrollParentRect.top;\n }\n if (scrollParentRect.left > 0) {\n scrollAreaLeft = scrollParentRect.left;\n }\n if (scrollParentRect.right < scrollAreaRight) {\n scrollAreaRight = scrollParentRect.right;\n }\n if (scrollParentRect.bottom < scrollAreaBottom) {\n scrollAreaBottom = scrollParentRect.bottom;\n }\n }\n\n // determine the horizontal orientation and left position\n let adjustment = 0;\n if (orientX === 'auto') {\n if (inputLeft < scrollAreaLeft) {\n orientX = 'left';\n adjustment = scrollAreaLeft - inputLeft;\n } else if (inputLeft + calendarWidth > scrollAreaRight) {\n orientX = 'right';\n if (scrollAreaRight < inputRight) {\n adjustment = scrollAreaRight - inputRight;\n }\n } else if (getTextDirection(inputField) === 'rtl') {\n orientX = inputRight - calendarWidth < scrollAreaLeft ? 'left' : 'right';\n } else {\n orientX = 'left';\n }\n }\n if (orientX === 'right') {\n left += inputWidth - calendarWidth;\n }\n left += adjustment;\n\n // determine the vertical orientation and top position\n if (orientY === 'auto') {\n if (inputTop - calendarHeight > scrollAreaTop) {\n orientY = inputBottom + calendarHeight > scrollAreaBottom ? 'top' : 'bottom';\n } else {\n orientY = 'bottom';\n }\n }\n if (orientY === 'top') {\n top -= calendarHeight;\n } else {\n top += inputHeight;\n }\n\n classList.remove(...Object.values(orientClasses));\n classList.add(orientClasses[orientX], orientClasses[orientY]);\n\n style.left = toPx(left);\n style.top = toPx(top);\n }\n\n setViewSwitchLabel(labelText) {\n this.controls.viewSwitch.textContent = labelText;\n }\n\n setPrevButtonDisabled(disabled) {\n this.controls.prevButton.disabled = disabled;\n }\n\n setNextButtonDisabled(disabled) {\n this.controls.nextButton.disabled = disabled;\n }\n\n changeView(viewId) {\n const currentView = this.currentView;\n if (viewId !== currentView.id) {\n if (!this._oldView) {\n this._oldView = currentView;\n }\n this.currentView = this.views[viewId];\n this._renderMethod = 'render';\n }\n return this;\n }\n\n // Change the focused date (view date)\n changeFocus(newViewDate) {\n this._renderMethod = setViewDate(this, newViewDate) ? 'render' : 'refreshFocus';\n this.views.forEach((view) => {\n view.updateFocus();\n });\n return this;\n }\n\n // Apply the change of the selected dates\n update(viewDate = undefined) {\n const newViewDate = viewDate === undefined\n ? computeResetViewDate(this.datepicker)\n : viewDate;\n this._renderMethod = setViewDate(this, newViewDate) ? 'render' : 'refresh';\n this.views.forEach((view) => {\n view.updateFocus();\n view.updateSelection();\n });\n return this;\n }\n\n // Refresh the picker UI\n render(quickRender = true) {\n const {currentView, datepicker, _oldView: oldView} = this;\n const oldViewDate = new Date(this._oldViewDate);\n const renderMethod = (quickRender && this._renderMethod) || 'render';\n delete this._oldView;\n delete this._oldViewDate;\n delete this._renderMethod;\n\n currentView[renderMethod]();\n if (oldView) {\n this.main.replaceChild(currentView.element, oldView.element);\n triggerDatepickerEvent(datepicker, 'changeView');\n }\n if (!isNaN(oldViewDate)) {\n const newViewDate = new Date(this.viewDate);\n if (newViewDate.getFullYear() !== oldViewDate.getFullYear()) {\n triggerDatepickerEvent(datepicker, 'changeYear');\n }\n if (newViewDate.getMonth() !== oldViewDate.getMonth()) {\n triggerDatepickerEvent(datepicker, 'changeMonth');\n }\n }\n }\n}\n","import {isInRange} from '../lib/utils.js';\nimport {isActiveElement} from '../lib/dom.js';\nimport {addDays, addMonths, addYears} from '../lib/date.js';\nimport {\n goToPrevOrNext,\n switchView,\n clearSelection,\n goToOrSelectToday,\n unfocus,\n} from './functions.js';\n\n// Find the closest date that doesn't meet the condition for unavailable date\n// Returns undefined if no available date is found\n// addFn: function to calculate the next date\n// - args: time value, amount\n// increase: amount to pass to addFn\n// testFn: function to test the unavailability of the date\n// - args: time value; return: true if unavailable\nfunction findNextAvailableOne(date, addFn, increase, testFn, min, max) {\n if (!isInRange(date, min, max)) {\n return;\n }\n if (testFn(date)) {\n const newDate = addFn(date, increase);\n return findNextAvailableOne(newDate, addFn, increase, testFn, min, max);\n }\n return date;\n}\n\n// direction: -1 (left/up), 1 (right/down)\n// vertical: true for up/down, false for left/right\nfunction moveByArrowKey(datepicker, direction, vertical) {\n const picker = datepicker.picker;\n const currentView = picker.currentView;\n const step = currentView.step || 1;\n let viewDate = picker.viewDate;\n let addFn;\n switch (currentView.id) {\n case 0:\n viewDate = addDays(viewDate, vertical ? direction * 7 : direction);\n addFn = addDays;\n break;\n case 1:\n viewDate = addMonths(viewDate, vertical ? direction * 4 : direction);\n addFn = addMonths;\n break;\n default:\n viewDate = addYears(viewDate, direction * (vertical ? 4 : 1) * step);\n addFn = addYears;\n }\n viewDate = findNextAvailableOne(\n viewDate,\n addFn,\n direction < 0 ? -step : step,\n (date) => currentView.disabled.includes(date),\n currentView.minDate,\n currentView.maxDate\n );\n if (viewDate !== undefined) {\n picker.changeFocus(viewDate).render();\n }\n}\n\nexport function onKeydown(datepicker, ev) {\n const {config, picker, editMode} = datepicker;\n const active = picker.active;\n const {key, altKey, shiftKey} = ev;\n const ctrlOrMetaKey = ev.ctrlKey || ev.metaKey;\n const cancelEvent = () => {\n ev.preventDefault();\n ev.stopPropagation();\n };\n\n // tab/enter keys should not be taken by shortcut keys\n if (key === 'Tab') {\n unfocus(datepicker);\n return;\n }\n if (key === 'Enter') {\n if (!active) {\n datepicker.update();\n } else if (editMode) {\n datepicker.exitEditMode({update: true, autohide: config.autohide});\n } else {\n const currentView = picker.currentView;\n if (currentView.isMinView) {\n datepicker.setDate(picker.viewDate);\n } else {\n picker.changeView(currentView.id - 1).render();\n cancelEvent();\n }\n }\n return;\n }\n\n const shortcutKeys = config.shortcutKeys;\n const keyInfo = {key, ctrlOrMetaKey, altKey, shiftKey};\n const shortcut = Object.keys(shortcutKeys).find((item) => {\n const keyDef = shortcutKeys[item];\n return !Object.keys(keyDef).find(prop => keyDef[prop] !== keyInfo[prop]);\n });\n if (shortcut) {\n let action;\n if (shortcut === 'toggle') {\n action = shortcut;\n } else if (editMode) {\n if (shortcut === 'exitEditMode') {\n action = shortcut;\n }\n } else if (active) {\n if (shortcut === 'hide') {\n action = shortcut;\n } else if (shortcut === 'prevButton') {\n action = [goToPrevOrNext, [datepicker, -1]];\n } else if (shortcut === 'nextButton') {\n action = [goToPrevOrNext, [datepicker, 1]];\n } else if (shortcut === 'viewSwitch') {\n action = [switchView, [datepicker]];\n } else if (config.clearButton && shortcut === 'clearButton') {\n action = [clearSelection, [datepicker]];\n } else if (config.todayButton && shortcut === 'todayButton') {\n action = [goToOrSelectToday, [datepicker]];\n }\n } else if (shortcut === 'show') {\n action = shortcut;\n }\n if (action) {\n if (Array.isArray(action)) {\n action[0].apply(null, action[1]);\n } else {\n datepicker[action]();\n }\n cancelEvent();\n return;\n }\n }\n\n // perform as a regular when picker in hidden or in edit mode\n if (!active || editMode) {\n return;\n }\n\n const handleArrowKeyPress = (direction, vertical) => {\n if (shiftKey || ctrlOrMetaKey || altKey) {\n datepicker.enterEditMode();\n } else {\n moveByArrowKey(datepicker, direction, vertical);\n ev.preventDefault();\n }\n };\n\n if (key === 'ArrowLeft') {\n handleArrowKeyPress(-1, false);\n } else if (key === 'ArrowRight') {\n handleArrowKeyPress(1, false);\n } else if (key === 'ArrowUp') {\n handleArrowKeyPress(-1, true);\n } else if (key === 'ArrowDown') {\n handleArrowKeyPress(1, true);\n } else if (\n key === 'Backspace'\n || key === 'Delete'\n // When autofill is performed, Chromium-based browsers trigger fake\n // keydown/keyup events that don't have the `key` property (on Edge,\n // keyup only) in addition to the input event. Therefore, we need to\n // check the existence of `key`'s value before checking the length.\n // (issue #144)\n || (key && key.length === 1 && !ctrlOrMetaKey)\n ) {\n datepicker.enterEditMode();\n }\n}\n\nexport function onFocus(datepicker) {\n if (datepicker.config.showOnFocus && !datepicker._showing) {\n datepicker.show();\n }\n}\n\n// for the prevention for entering edit mode while getting focus on click\nexport function onMousedown(datepicker, ev) {\n const el = ev.target;\n if (datepicker.picker.active || datepicker.config.showOnClick) {\n el._active = isActiveElement(el);\n el._clicking = setTimeout(() => {\n delete el._active;\n delete el._clicking;\n }, 2000);\n }\n}\n\nexport function onClickInput(datepicker, ev) {\n const el = ev.target;\n if (!el._clicking) {\n return;\n }\n clearTimeout(el._clicking);\n delete el._clicking;\n\n if (el._active) {\n datepicker.enterEditMode();\n }\n delete el._active;\n\n if (datepicker.config.showOnClick) {\n datepicker.show();\n }\n}\n\nexport function onPaste(datepicker, ev) {\n if (ev.clipboardData.types.includes('text/plain')) {\n datepicker.enterEditMode();\n }\n}\n","import {isActiveElement} from '../lib/dom.js';\nimport {findElementInEventPath} from '../lib/event.js';\nimport {unfocus} from './functions.js';\n\n// for the `document` to delegate the events from outside the picker/input field\nexport function onClickOutside(datepicker, ev) {\n const {element, picker} = datepicker;\n // check both picker's and input's activeness to make updateOnBlur work in\n // the cases where...\n // - picker is hidden by ESC key press → input stays focused\n // - input is unfocused by closing mobile keyboard → piker is kept shown\n if (!picker.active && !isActiveElement(element)) {\n return;\n }\n const pickerElem = picker.element;\n if (findElementInEventPath(ev, el => el === element || el === pickerElem)) {\n return;\n }\n unfocus(datepicker);\n}\n","import {lastItemOf, stringToArray, isInRange} from './lib/utils.js';\nimport {today, regularizeDate} from './lib/date.js';\nimport {parseDate, formatDate} from './lib/date-format.js';\nimport {isActiveElement} from './lib/dom.js';\nimport {registerListeners, unregisterListeners} from './lib/event.js';\nimport locales from './i18n/base-locales.js';\nimport defaultOptions from './options/defaultOptions.js';\nimport processOptions from './options/processOptions.js';\nimport createShortcutKeyConfig from './options/shortcutKeys.js';\nimport Picker from './picker/Picker.js';\nimport {triggerDatepickerEvent} from './events/functions.js';\nimport {\n onKeydown,\n onFocus,\n onMousedown,\n onClickInput,\n onPaste,\n} from './events/elementListeners.js';\nimport {onClickOutside} from './events/otherListeners.js';\n\nfunction stringifyDates(dates, config) {\n return dates\n .map(dt => formatDate(dt, config.format, config.locale))\n .join(config.dateDelimiter);\n}\n\n// parse input dates and create an array of time values for selection\n// returns undefined if there are no valid dates in inputDates\n// when origDates (current selection) is passed, the function works to mix\n// the input dates into the current selection\nfunction processInputDates(datepicker, inputDates, clear = false) {\n if (inputDates.length === 0) {\n // empty input is considered valid unless origiDates is passed\n return clear ? [] : undefined;\n }\n\n const {config, dates: origDates, rangeSideIndex} = datepicker;\n const {pickLevel, maxNumberOfDates} = config;\n let newDates = inputDates.reduce((dates, dt) => {\n let date = parseDate(dt, config.format, config.locale);\n if (date === undefined) {\n return dates;\n }\n // adjust to 1st of the month/Jan 1st of the year\n // or to the last day of the monh/Dec 31st of the year if the datepicker\n // is the range-end picker of a rangepicker\n date = regularizeDate(date, pickLevel, rangeSideIndex);\n if (\n isInRange(date, config.minDate, config.maxDate)\n && !dates.includes(date)\n && !config.checkDisabled(date, pickLevel)\n && (pickLevel > 0 || !config.daysOfWeekDisabled.includes(new Date(date).getDay()))\n ) {\n dates.push(date);\n }\n return dates;\n }, []);\n if (newDates.length === 0) {\n return;\n }\n if (config.multidate && !clear) {\n // get the synmetric difference between origDates and newDates\n newDates = newDates.reduce((dates, date) => {\n if (!origDates.includes(date)) {\n dates.push(date);\n }\n return dates;\n }, origDates.filter(date => !newDates.includes(date)));\n }\n // do length check always because user can input multiple dates regardless of the mode\n return maxNumberOfDates && newDates.length > maxNumberOfDates\n ? newDates.slice(maxNumberOfDates * -1)\n : newDates;\n}\n\n// refresh the UI elements\n// modes: 1: input only, 2, picker only, 3 both\nfunction refreshUI(datepicker, mode = 3, quickRender = true, viewDate = undefined) {\n const {config, picker, inputField} = datepicker;\n if (mode & 2) {\n const newView = picker.active ? config.pickLevel : config.startView;\n picker.update(viewDate).changeView(newView).render(quickRender);\n }\n if (mode & 1 && inputField) {\n inputField.value = stringifyDates(datepicker.dates, config);\n }\n}\n\nfunction setDate(datepicker, inputDates, options) {\n const config = datepicker.config;\n let {clear, render, autohide, revert, forceRefresh, viewDate} = options;\n if (render === undefined) {\n render = true;\n }\n if (!render) {\n autohide = forceRefresh = false;\n } else if (autohide === undefined) {\n autohide = config.autohide;\n }\n viewDate = parseDate(viewDate, config.format, config.locale);\n\n const newDates = processInputDates(datepicker, inputDates, clear);\n if (!newDates && !revert) {\n return;\n }\n if (newDates && newDates.toString() !== datepicker.dates.toString()) {\n datepicker.dates = newDates;\n refreshUI(datepicker, render ? 3 : 1, true, viewDate);\n triggerDatepickerEvent(datepicker, 'changeDate');\n } else {\n refreshUI(datepicker, forceRefresh ? 3 : 1, true, viewDate);\n }\n\n if (autohide) {\n datepicker.hide();\n }\n}\n\nfunction getOutputConverter(datepicker, format) {\n return format\n ? date => formatDate(date, format, datepicker.config.locale)\n : date => new Date(date);\n}\n\n/**\n * Class representing a date picker\n */\nexport default class Datepicker {\n /**\n * Create a date picker\n * @param {Element} element - element to bind a date picker\n * @param {Object} [options] - config options\n * @param {DateRangePicker} [rangepicker] - DateRangePicker instance the\n * date picker belongs to. Use this only when creating date picker as a part\n * of date range picker\n */\n constructor(element, options = {}, rangepicker = undefined) {\n element.datepicker = this;\n this.element = element;\n this.dates = [];\n\n // initialize config\n const config = this.config = Object.assign({\n buttonClass: (options.buttonClass && String(options.buttonClass)) || 'button',\n container: null,\n defaultViewDate: today(),\n maxDate: undefined,\n minDate: undefined,\n }, processOptions(defaultOptions, this));\n\n // configure by type\n let inputField;\n if (element.tagName === 'INPUT') {\n inputField = this.inputField = element;\n inputField.classList.add('datepicker-input');\n if (options.container) {\n // omit string type check because it doesn't guarantee to avoid errors\n // (invalid selector string causes abend with sytax error)\n config.container = options.container instanceof HTMLElement\n ? options.container\n : document.querySelector(options.container);\n }\n } else {\n config.container = element;\n }\n if (rangepicker) {\n // check validiry\n const index = rangepicker.inputs.indexOf(inputField);\n const datepickers = rangepicker.datepickers;\n if (index < 0 || index > 1 || !Array.isArray(datepickers)) {\n throw Error('Invalid rangepicker object.');\n }\n // attach itaelf to the rangepicker here so that processInputDates() can\n // determine if this is the range-end picker of the rangepicker while\n // setting inital values when pickLevel > 0\n datepickers[index] = this;\n this.rangepicker = rangepicker;\n this.rangeSideIndex = index;\n }\n\n // set up config\n this._options = options;\n Object.assign(config, processOptions(options, this));\n config.shortcutKeys = createShortcutKeyConfig(options.shortcutKeys || {});\n\n // process initial value\n const initialDates = stringToArray(\n element.value || element.dataset.date,\n config.dateDelimiter\n );\n delete element.dataset.date;\n const inputDateValues = processInputDates(this, initialDates);\n if (inputDateValues && inputDateValues.length > 0) {\n this.dates = inputDateValues;\n }\n if (inputField) {\n inputField.value = stringifyDates(this.dates, config);\n }\n\n // set up picekr element\n const picker = this.picker = new Picker(this);\n\n const keydownListener = [element, 'keydown', onKeydown.bind(null, this)];\n if (inputField) {\n registerListeners(this, [\n keydownListener,\n [inputField, 'focus', onFocus.bind(null, this)],\n [inputField, 'mousedown', onMousedown.bind(null, this)],\n [inputField, 'click', onClickInput.bind(null, this)],\n [inputField, 'paste', onPaste.bind(null, this)],\n // To detect a click on outside, just listening to mousedown is enough,\n // no need to listen to touchstart.\n // Actually, listening to touchstart can be a problem because, while\n // mousedown is fired only on tapping but not on swiping/pinching,\n // touchstart is fired on swiping/pinching as well.\n // (issue #95)\n [document, 'mousedown', onClickOutside.bind(null, this)],\n [window, 'resize', picker.place.bind(picker)]\n ]);\n } else {\n registerListeners(this, [keydownListener]);\n this.show();\n }\n }\n\n /**\n * Format Date object or time value in given format and language\n * @param {Date|Number} date - date or time value to format\n * @param {String|Object} format - format string or object that contains\n * toDisplay() custom formatter, whose signature is\n * - args:\n * - date: {Date} - Date instance of the date passed to the method\n * - format: {Object} - the format object passed to the method\n * - locale: {Object} - locale for the language specified by `lang`\n * - return:\n * {String} formatted date\n * @param {String} [lang=en] - language code for the locale to use\n * @return {String} formatted date\n */\n static formatDate(date, format, lang) {\n return formatDate(date, format, lang && locales[lang] || locales.en);\n }\n\n /**\n * Parse date string\n * @param {String|Date|Number} dateStr - date string, Date object or time\n * value to parse\n * @param {String|Object} format - format string or object that contains\n * toValue() custom parser, whose signature is\n * - args:\n * - dateStr: {String|Date|Number} - the dateStr passed to the method\n * - format: {Object} - the format object passed to the method\n * - locale: {Object} - locale for the language specified by `lang`\n * - return:\n * {Date|Number} parsed date or its time value\n * @param {String} [lang=en] - language code for the locale to use\n * @return {Number} time value of parsed date\n */\n static parseDate(dateStr, format, lang) {\n return parseDate(dateStr, format, lang && locales[lang] || locales.en);\n }\n\n /**\n * @type {Object} - Installed locales in `[languageCode]: localeObject` format\n * en`:_English (US)_ is pre-installed.\n */\n static get locales() {\n return locales;\n }\n\n /**\n * @type {Boolean} - Whether the picker element is shown. `true` whne shown\n */\n get active() {\n return !!(this.picker && this.picker.active);\n }\n\n /**\n * @type {HTMLDivElement} - DOM object of picker element\n */\n get pickerElement() {\n return this.picker ? this.picker.element : undefined;\n }\n\n /**\n * Set new values to the config options\n * @param {Object} options - config options to update\n */\n setOptions(options) {\n const newOptions = processOptions(options, this);\n Object.assign(this._options, options);\n Object.assign(this.config, newOptions);\n this.picker.setOptions(newOptions);\n\n refreshUI(this, 3);\n }\n\n /**\n * Show the picker element\n */\n show() {\n if (this.inputField) {\n const {config, inputField} = this;\n if (inputField.disabled || (inputField.readOnly && !config.enableOnReadonly)) {\n return;\n }\n if (!isActiveElement(inputField) && !config.disableTouchKeyboard) {\n this._showing = true;\n inputField.focus();\n delete this._showing;\n }\n }\n this.picker.show();\n }\n\n /**\n * Hide the picker element\n * Not available on inline picker\n */\n hide() {\n if (!this.inputField) {\n return;\n }\n this.picker.hide();\n this.picker.update().changeView(this.config.startView).render();\n }\n\n /**\n * Toggle the display of the picker element\n * Not available on inline picker\n *\n * Unlike hide(), the picker does not return to the start view when hiding.\n */\n toggle() {\n if (!this.picker.active) {\n this.show();\n } else if (this.inputField) {\n this.picker.hide();\n }\n }\n\n /**\n * Destroy the Datepicker instance\n * @return {Detepicker} - the instance destroyed\n */\n destroy() {\n this.hide();\n unregisterListeners(this);\n this.picker.detach();\n const element = this.element;\n element.classList.remove('datepicker-input');\n delete element.datepicker;\n return this;\n }\n\n /**\n * Get the selected date(s)\n *\n * The method returns a Date object of selected date by default, and returns\n * an array of selected dates in multidate mode. If format string is passed,\n * it returns date string(s) formatted in given format.\n *\n * @param {String} [format] - format string to stringify the date(s)\n * @return {Date|String|Date[]|String[]} - selected date(s), or if none is\n * selected, empty array in multidate mode and undefined in sigledate mode\n */\n getDate(format = undefined) {\n const callback = getOutputConverter(this, format);\n\n if (this.config.multidate) {\n return this.dates.map(callback);\n }\n if (this.dates.length > 0) {\n return callback(this.dates[0]);\n }\n }\n\n /**\n * Set selected date(s)\n *\n * In multidate mode, you can pass multiple dates as a series of arguments\n * or an array. (Since each date is parsed individually, the type of the\n * dates doesn't have to be the same.)\n * The given dates are used to toggle the select status of each date. The\n * number of selected dates is kept from exceeding the length set to\n * maxNumberOfDates.\n *\n * With clear: true option, the method can be used to clear the selection\n * and to replace the selection instead of toggling in multidate mode.\n * If the option is passed with no date arguments or an empty dates array,\n * it works as \"clear\" (clear the selection then set nothing), and if the\n * option is passed with new dates to select, it works as \"replace\" (clear\n * the selection then set the given dates)\n *\n * When render: false option is used, the method omits re-rendering the\n * picker element. In this case, you need to call refresh() method later in\n * order for the picker element to reflect the changes. The input field is\n * refreshed always regardless of this option.\n *\n * When invalid (unparsable, repeated, disabled or out-of-range) dates are\n * passed, the method ignores them and applies only valid ones. In the case\n * that all the given dates are invalid, which is distinguished from passing\n * no dates, the method considers it as an error and leaves the selection\n * untouched. (The input field also remains untouched unless revert: true\n * option is used.)\n * Replacing the selection with the same date(s) also causes a similar\n * situation. In both cases, the method does not refresh the picker element\n * unless forceRefresh: true option is used.\n *\n * If viewDate option is used, the method changes the focused date to the\n * specified date instead of the last item of the selection.\n *\n * @param {...(Date|Number|String)|Array} [dates] - Date strings, Date\n * objects, time values or mix of those for new selection\n * @param {Object} [options] - function options\n * - clear: {boolean} - Whether to clear the existing selection\n * defualt: false\n * - render: {boolean} - Whether to re-render the picker element\n * default: true\n * - autohide: {boolean} - Whether to hide the picker element after re-render\n * Ignored when used with render: false\n * default: config.autohide\n * - revert: {boolean} - Whether to refresh the input field when all the\n * passed dates are invalid\n * default: false\n * - forceRefresh: {boolean} - Whether to refresh the picker element when\n * passed dates don't change the existing selection\n * default: false\n * - viewDate: {Date|Number|String} - Date to be focused after setiing date(s)\n * default: The last item of the resulting selection, or defaultViewDate\n * config option if none is selected\n */\n setDate(...args) {\n const dates = [...args];\n const opts = {};\n const lastArg = lastItemOf(args);\n if (\n lastArg\n && typeof lastArg === 'object'\n && !Array.isArray(lastArg)\n && !(lastArg instanceof Date)\n ) {\n Object.assign(opts, dates.pop());\n }\n\n const inputDates = Array.isArray(dates[0]) ? dates[0] : dates;\n setDate(this, inputDates, opts);\n }\n\n /**\n * Update the selected date(s) with input field's value\n * Not available on inline picker\n *\n * The input field will be refreshed with properly formatted date string.\n *\n * In the case that all the entered dates are invalid (unparsable, repeated,\n * disabled or out-of-range), which is distinguished from empty input field,\n * the method leaves the input field untouched as well as the selection by\n * default. If revert: true option is used in this case, the input field is\n * refreshed with the existing selection.\n * The method also doesn't refresh the picker element in this case and when\n * the entered dates are the same as the existing selection. If\n * forceRefresh: true option is used, the picker element is refreshed in\n * these cases too.\n *\n * @param {Object} [options] - function options\n * - autohide: {boolean} - whether to hide the picker element after refresh\n * default: false\n * - revert: {boolean} - Whether to refresh the input field when all the\n * passed dates are invalid\n * default: false\n * - forceRefresh: {boolean} - Whether to refresh the picer element when\n * input field's value doesn't change the existing selection\n * default: false\n */\n update(options = undefined) {\n if (!this.inputField) {\n return;\n }\n\n const opts = Object.assign(options || {}, {clear: true, render: true, viewDate: undefined});\n const inputDates = stringToArray(this.inputField.value, this.config.dateDelimiter);\n setDate(this, inputDates, opts);\n }\n\n /**\n * Get the focused date\n *\n * The method returns a Date object of focused date by default. If format\n * string is passed, it returns date string formatted in given format.\n *\n * @param {String} [format] - format string to stringify the date\n * @return {Date|String} - focused date (viewDate)\n */\n getFocusedDate(format = undefined) {\n return getOutputConverter(this, format)(this.picker.viewDate);\n }\n\n /**\n * Set focused date\n *\n * By default, the method updates the focus on the view shown at the time,\n * or the one set to the startView config option if the picker is hidden.\n * When resetView: true is passed, the view displayed is changed to the\n * pickLevel config option's if the picker is shown.\n *\n * @param {Date|Number|String} viewDate - date string, Date object, time\n * values of the date to focus\n * @param {Boolean} [resetView] - whether to change the view to pickLevel\n * config option's when the picker is shown. Ignored when the picker is\n * hidden\n */\n setFocusedDate(viewDate, resetView = false) {\n const {config, picker, active, rangeSideIndex} = this;\n const pickLevel = config.pickLevel;\n const newViewDate = parseDate(viewDate, config.format, config.locale);\n if (newViewDate === undefined) {\n return;\n }\n\n picker.changeFocus(regularizeDate(newViewDate, pickLevel, rangeSideIndex));\n if (active && resetView) {\n picker.changeView(pickLevel);\n }\n picker.render();\n }\n\n /**\n * Refresh the picker element and the associated input field\n * @param {String} [target] - target item when refreshing one item only\n * 'picker' or 'input'\n * @param {Boolean} [forceRender] - whether to re-render the picker element\n * regardless of its state instead of optimized refresh\n */\n refresh(target = undefined, forceRender = false) {\n if (target && typeof target !== 'string') {\n forceRender = target;\n target = undefined;\n }\n\n let mode;\n if (target === 'picker') {\n mode = 2;\n } else if (target === 'input') {\n mode = 1;\n } else {\n mode = 3;\n }\n refreshUI(this, mode, !forceRender);\n }\n\n /**\n * Enter edit mode\n * Not available on inline picker or when the picker element is hidden\n */\n enterEditMode() {\n const inputField = this.inputField;\n if (!inputField || inputField.readOnly || !this.picker.active || this.editMode) {\n return;\n }\n this.editMode = true;\n inputField.classList.add('in-edit');\n }\n\n /**\n * Exit from edit mode\n * Not available on inline picker\n * @param {Object} [options] - function options\n * - update: {boolean} - whether to call update() after exiting\n * If false, input field is revert to the existing selection\n * default: false\n */\n exitEditMode(options = undefined) {\n if (!this.inputField || !this.editMode) {\n return;\n }\n const opts = Object.assign({update: false}, options);\n delete this.editMode;\n this.inputField.classList.remove('in-edit');\n if (opts.update) {\n this.update(opts);\n }\n }\n}\n","/**\n* Tom Select v2.3.1\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n*/\n\n/**\n * MicroEvent - to make any js object an event emitter\n *\n * - pure javascript - server compatible, browser compatible\n * - dont rely on the browser doms\n * - super simple - you get it immediatly, no mistery, no magic involved\n *\n * @author Jerome Etienne (https://github.com/jeromeetienne)\n */\n\n/**\n * Execute callback for each event in space separated list of event names\n *\n */\nfunction forEvents(events, callback) {\n events.split(/\\s+/).forEach(event => {\n callback(event);\n });\n}\nclass MicroEvent {\n constructor() {\n this._events = void 0;\n this._events = {};\n }\n on(events, fct) {\n forEvents(events, event => {\n const event_array = this._events[event] || [];\n event_array.push(fct);\n this._events[event] = event_array;\n });\n }\n off(events, fct) {\n var n = arguments.length;\n if (n === 0) {\n this._events = {};\n return;\n }\n forEvents(events, event => {\n if (n === 1) {\n delete this._events[event];\n return;\n }\n const event_array = this._events[event];\n if (event_array === undefined) return;\n event_array.splice(event_array.indexOf(fct), 1);\n this._events[event] = event_array;\n });\n }\n trigger(events, ...args) {\n var self = this;\n forEvents(events, event => {\n const event_array = self._events[event];\n if (event_array === undefined) return;\n event_array.forEach(fct => {\n fct.apply(self, args);\n });\n });\n }\n}\n\n/**\n * microplugin.js\n * Copyright (c) 2013 Brian Reavis & contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n * @author Brian Reavis \n */\n\nfunction MicroPlugin(Interface) {\n Interface.plugins = {};\n return class extends Interface {\n constructor(...args) {\n super(...args);\n this.plugins = {\n names: [],\n settings: {},\n requested: {},\n loaded: {}\n };\n }\n /**\n * Registers a plugin.\n *\n * @param {function} fn\n */\n static define(name, fn) {\n Interface.plugins[name] = {\n 'name': name,\n 'fn': fn\n };\n }\n\n /**\n * Initializes the listed plugins (with options).\n * Acceptable formats:\n *\n * List (without options):\n * ['a', 'b', 'c']\n *\n * List (with options):\n * [{'name': 'a', options: {}}, {'name': 'b', options: {}}]\n *\n * Hash (with options):\n * {'a': { ... }, 'b': { ... }, 'c': { ... }}\n *\n * @param {array|object} plugins\n */\n initializePlugins(plugins) {\n var key, name;\n const self = this;\n const queue = [];\n if (Array.isArray(plugins)) {\n plugins.forEach(plugin => {\n if (typeof plugin === 'string') {\n queue.push(plugin);\n } else {\n self.plugins.settings[plugin.name] = plugin.options;\n queue.push(plugin.name);\n }\n });\n } else if (plugins) {\n for (key in plugins) {\n if (plugins.hasOwnProperty(key)) {\n self.plugins.settings[key] = plugins[key];\n queue.push(key);\n }\n }\n }\n while (name = queue.shift()) {\n self.require(name);\n }\n }\n loadPlugin(name) {\n var self = this;\n var plugins = self.plugins;\n var plugin = Interface.plugins[name];\n if (!Interface.plugins.hasOwnProperty(name)) {\n throw new Error('Unable to find \"' + name + '\" plugin');\n }\n plugins.requested[name] = true;\n plugins.loaded[name] = plugin.fn.apply(self, [self.plugins.settings[name] || {}]);\n plugins.names.push(name);\n }\n\n /**\n * Initializes a plugin.\n *\n */\n require(name) {\n var self = this;\n var plugins = self.plugins;\n if (!self.plugins.loaded.hasOwnProperty(name)) {\n if (plugins.requested[name]) {\n throw new Error('Plugin has circular dependency (\"' + name + '\")');\n }\n self.loadPlugin(name);\n }\n return plugins.loaded[name];\n }\n };\n}\n\n/*! @orchidjs/unicode-variants | https://github.com/orchidjs/unicode-variants | Apache License (v2) */\n/**\n * Convert array of strings to a regular expression\n *\tex ['ab','a'] => (?:ab|a)\n * \tex ['a','b'] => [ab]\n * @param {string[]} chars\n * @return {string}\n */\nconst arrayToPattern = chars => {\n chars = chars.filter(Boolean);\n\n if (chars.length < 2) {\n return chars[0] || '';\n }\n\n return maxValueLength(chars) == 1 ? '[' + chars.join('') + ']' : '(?:' + chars.join('|') + ')';\n};\n/**\n * @param {string[]} array\n * @return {string}\n */\n\nconst sequencePattern = array => {\n if (!hasDuplicates(array)) {\n return array.join('');\n }\n\n let pattern = '';\n let prev_char_count = 0;\n\n const prev_pattern = () => {\n if (prev_char_count > 1) {\n pattern += '{' + prev_char_count + '}';\n }\n };\n\n array.forEach((char, i) => {\n if (char === array[i - 1]) {\n prev_char_count++;\n return;\n }\n\n prev_pattern();\n pattern += char;\n prev_char_count = 1;\n });\n prev_pattern();\n return pattern;\n};\n/**\n * Convert array of strings to a regular expression\n *\tex ['ab','a'] => (?:ab|a)\n * \tex ['a','b'] => [ab]\n * @param {Set} chars\n * @return {string}\n */\n\nconst setToPattern = chars => {\n let array = toArray(chars);\n return arrayToPattern(array);\n};\n/**\n *\n * https://stackoverflow.com/questions/7376598/in-javascript-how-do-i-check-if-an-array-has-duplicate-values\n * @param {any[]} array\n */\n\nconst hasDuplicates = array => {\n return new Set(array).size !== array.length;\n};\n/**\n * https://stackoverflow.com/questions/63006601/why-does-u-throw-an-invalid-escape-error\n * @param {string} str\n * @return {string}\n */\n\nconst escape_regex = str => {\n return (str + '').replace(/([\\$\\(\\)\\*\\+\\.\\?\\[\\]\\^\\{\\|\\}\\\\])/gu, '\\\\$1');\n};\n/**\n * Return the max length of array values\n * @param {string[]} array\n *\n */\n\nconst maxValueLength = array => {\n return array.reduce((longest, value) => Math.max(longest, unicodeLength(value)), 0);\n};\n/**\n * @param {string} str\n */\n\nconst unicodeLength = str => {\n return toArray(str).length;\n};\n/**\n * @param {any} p\n * @return {any[]}\n */\n\nconst toArray = p => Array.from(p);\n\n/*! @orchidjs/unicode-variants | https://github.com/orchidjs/unicode-variants | Apache License (v2) */\n/**\n * Get all possible combinations of substrings that add up to the given string\n * https://stackoverflow.com/questions/30169587/find-all-the-combination-of-substrings-that-add-up-to-the-given-string\n * @param {string} input\n * @return {string[][]}\n */\nconst allSubstrings = input => {\n if (input.length === 1) return [[input]];\n /** @type {string[][]} */\n\n let result = [];\n const start = input.substring(1);\n const suba = allSubstrings(start);\n suba.forEach(function (subresult) {\n let tmp = subresult.slice(0);\n tmp[0] = input.charAt(0) + tmp[0];\n result.push(tmp);\n tmp = subresult.slice(0);\n tmp.unshift(input.charAt(0));\n result.push(tmp);\n });\n return result;\n};\n\n/*! @orchidjs/unicode-variants | https://github.com/orchidjs/unicode-variants | Apache License (v2) */\n\n/**\n * @typedef {{[key:string]:string}} TUnicodeMap\n * @typedef {{[key:string]:Set}} TUnicodeSets\n * @typedef {[[number,number]]} TCodePoints\n * @typedef {{folded:string,composed:string,code_point:number}} TCodePointObj\n * @typedef {{start:number,end:number,length:number,substr:string}} TSequencePart\n */\n/** @type {TCodePoints} */\n\nconst code_points = [[0, 65535]];\nconst accent_pat = '[\\u0300-\\u036F\\u{b7}\\u{2be}\\u{2bc}]';\n/** @type {TUnicodeMap} */\n\nlet unicode_map;\n/** @type {RegExp} */\n\nlet multi_char_reg;\nconst max_char_length = 3;\n/** @type {TUnicodeMap} */\n\nconst latin_convert = {};\n/** @type {TUnicodeMap} */\n\nconst latin_condensed = {\n '/': '⁄∕',\n '0': '߀',\n \"a\": \"ⱥɐɑ\",\n \"aa\": \"ꜳ\",\n \"ae\": \"æǽǣ\",\n \"ao\": \"ꜵ\",\n \"au\": \"ꜷ\",\n \"av\": \"ꜹꜻ\",\n \"ay\": \"ꜽ\",\n \"b\": \"ƀɓƃ\",\n \"c\": \"ꜿƈȼↄ\",\n \"d\": \"đɗɖᴅƌꮷԁɦ\",\n \"e\": \"ɛǝᴇɇ\",\n \"f\": \"ꝼƒ\",\n \"g\": \"ǥɠꞡᵹꝿɢ\",\n \"h\": \"ħⱨⱶɥ\",\n \"i\": \"ɨı\",\n \"j\": \"ɉȷ\",\n \"k\": \"ƙⱪꝁꝃꝅꞣ\",\n \"l\": \"łƚɫⱡꝉꝇꞁɭ\",\n \"m\": \"ɱɯϻ\",\n \"n\": \"ꞥƞɲꞑᴎлԉ\",\n \"o\": \"øǿɔɵꝋꝍᴑ\",\n \"oe\": \"œ\",\n \"oi\": \"ƣ\",\n \"oo\": \"ꝏ\",\n \"ou\": \"ȣ\",\n \"p\": \"ƥᵽꝑꝓꝕρ\",\n \"q\": \"ꝗꝙɋ\",\n \"r\": \"ɍɽꝛꞧꞃ\",\n \"s\": \"ßȿꞩꞅʂ\",\n \"t\": \"ŧƭʈⱦꞇ\",\n \"th\": \"þ\",\n \"tz\": \"ꜩ\",\n \"u\": \"ʉ\",\n \"v\": \"ʋꝟʌ\",\n \"vy\": \"ꝡ\",\n \"w\": \"ⱳ\",\n \"y\": \"ƴɏỿ\",\n \"z\": \"ƶȥɀⱬꝣ\",\n \"hv\": \"ƕ\"\n};\n\nfor (let latin in latin_condensed) {\n let unicode = latin_condensed[latin] || '';\n\n for (let i = 0; i < unicode.length; i++) {\n let char = unicode.substring(i, i + 1);\n latin_convert[char] = latin;\n }\n}\n\nconst convert_pat = new RegExp(Object.keys(latin_convert).join('|') + '|' + accent_pat, 'gu');\n/**\n * Initialize the unicode_map from the give code point ranges\n *\n * @param {TCodePoints=} _code_points\n */\n\nconst initialize = _code_points => {\n if (unicode_map !== undefined) return;\n unicode_map = generateMap(_code_points || code_points);\n};\n/**\n * Helper method for normalize a string\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize\n * @param {string} str\n * @param {string} form\n */\n\nconst normalize = (str, form = 'NFKD') => str.normalize(form);\n/**\n * Remove accents without reordering string\n * calling str.normalize('NFKD') on \\u{594}\\u{595}\\u{596} becomes \\u{596}\\u{594}\\u{595}\n * via https://github.com/krisk/Fuse/issues/133#issuecomment-318692703\n * @param {string} str\n * @return {string}\n */\n\nconst asciifold = str => {\n return toArray(str).reduce(\n /**\n * @param {string} result\n * @param {string} char\n */\n (result, char) => {\n return result + _asciifold(char);\n }, '');\n};\n/**\n * @param {string} str\n * @return {string}\n */\n\nconst _asciifold = str => {\n str = normalize(str).toLowerCase().replace(convert_pat, (\n /** @type {string} */\n char) => {\n return latin_convert[char] || '';\n }); //return str;\n\n return normalize(str, 'NFC');\n};\n/**\n * Generate a list of unicode variants from the list of code points\n * @param {TCodePoints} code_points\n * @yield {TCodePointObj}\n */\n\nfunction* generator(code_points) {\n for (const [code_point_min, code_point_max] of code_points) {\n for (let i = code_point_min; i <= code_point_max; i++) {\n let composed = String.fromCharCode(i);\n let folded = asciifold(composed);\n\n if (folded == composed.toLowerCase()) {\n continue;\n } // skip when folded is a string longer than 3 characters long\n // bc the resulting regex patterns will be long\n // eg:\n // folded صلى الله عليه وسلم length 18 code point 65018\n // folded جل جلاله length 8 code point 65019\n\n\n if (folded.length > max_char_length) {\n continue;\n }\n\n if (folded.length == 0) {\n continue;\n }\n\n yield {\n folded: folded,\n composed: composed,\n code_point: i\n };\n }\n }\n}\n/**\n * Generate a unicode map from the list of code points\n * @param {TCodePoints} code_points\n * @return {TUnicodeSets}\n */\n\nconst generateSets = code_points => {\n /** @type {{[key:string]:Set}} */\n const unicode_sets = {};\n /**\n * @param {string} folded\n * @param {string} to_add\n */\n\n const addMatching = (folded, to_add) => {\n /** @type {Set} */\n const folded_set = unicode_sets[folded] || new Set();\n const patt = new RegExp('^' + setToPattern(folded_set) + '$', 'iu');\n\n if (to_add.match(patt)) {\n return;\n }\n\n folded_set.add(escape_regex(to_add));\n unicode_sets[folded] = folded_set;\n };\n\n for (let value of generator(code_points)) {\n addMatching(value.folded, value.folded);\n addMatching(value.folded, value.composed);\n }\n\n return unicode_sets;\n};\n/**\n * Generate a unicode map from the list of code points\n * ae => (?:(?:ae|Æ|Ǽ|Ǣ)|(?:A|Ⓐ|A...)(?:E|ɛ|Ⓔ...))\n *\n * @param {TCodePoints} code_points\n * @return {TUnicodeMap}\n */\n\nconst generateMap = code_points => {\n /** @type {TUnicodeSets} */\n const unicode_sets = generateSets(code_points);\n /** @type {TUnicodeMap} */\n\n const unicode_map = {};\n /** @type {string[]} */\n\n let multi_char = [];\n\n for (let folded in unicode_sets) {\n let set = unicode_sets[folded];\n\n if (set) {\n unicode_map[folded] = setToPattern(set);\n }\n\n if (folded.length > 1) {\n multi_char.push(escape_regex(folded));\n }\n }\n\n multi_char.sort((a, b) => b.length - a.length);\n const multi_char_patt = arrayToPattern(multi_char);\n multi_char_reg = new RegExp('^' + multi_char_patt, 'u');\n return unicode_map;\n};\n/**\n * Map each element of an array from it's folded value to all possible unicode matches\n * @param {string[]} strings\n * @param {number} min_replacement\n * @return {string}\n */\n\nconst mapSequence = (strings, min_replacement = 1) => {\n let chars_replaced = 0;\n strings = strings.map(str => {\n if (unicode_map[str]) {\n chars_replaced += str.length;\n }\n\n return unicode_map[str] || str;\n });\n\n if (chars_replaced >= min_replacement) {\n return sequencePattern(strings);\n }\n\n return '';\n};\n/**\n * Convert a short string and split it into all possible patterns\n * Keep a pattern only if min_replacement is met\n *\n * 'abc'\n * \t\t=> [['abc'],['ab','c'],['a','bc'],['a','b','c']]\n *\t\t=> ['abc-pattern','ab-c-pattern'...]\n *\n *\n * @param {string} str\n * @param {number} min_replacement\n * @return {string}\n */\n\nconst substringsToPattern = (str, min_replacement = 1) => {\n min_replacement = Math.max(min_replacement, str.length - 1);\n return arrayToPattern(allSubstrings(str).map(sub_pat => {\n return mapSequence(sub_pat, min_replacement);\n }));\n};\n/**\n * Convert an array of sequences into a pattern\n * [{start:0,end:3,length:3,substr:'iii'}...] => (?:iii...)\n *\n * @param {Sequence[]} sequences\n * @param {boolean} all\n */\n\nconst sequencesToPattern = (sequences, all = true) => {\n let min_replacement = sequences.length > 1 ? 1 : 0;\n return arrayToPattern(sequences.map(sequence => {\n let seq = [];\n const len = all ? sequence.length() : sequence.length() - 1;\n\n for (let j = 0; j < len; j++) {\n seq.push(substringsToPattern(sequence.substrs[j] || '', min_replacement));\n }\n\n return sequencePattern(seq);\n }));\n};\n/**\n * Return true if the sequence is already in the sequences\n * @param {Sequence} needle_seq\n * @param {Sequence[]} sequences\n */\n\n\nconst inSequences = (needle_seq, sequences) => {\n for (const seq of sequences) {\n if (seq.start != needle_seq.start || seq.end != needle_seq.end) {\n continue;\n }\n\n if (seq.substrs.join('') !== needle_seq.substrs.join('')) {\n continue;\n }\n\n let needle_parts = needle_seq.parts;\n /**\n * @param {TSequencePart} part\n */\n\n const filter = part => {\n for (const needle_part of needle_parts) {\n if (needle_part.start === part.start && needle_part.substr === part.substr) {\n return false;\n }\n\n if (part.length == 1 || needle_part.length == 1) {\n continue;\n } // check for overlapping parts\n // a = ['::=','==']\n // b = ['::','===']\n // a = ['r','sm']\n // b = ['rs','m']\n\n\n if (part.start < needle_part.start && part.end > needle_part.start) {\n return true;\n }\n\n if (needle_part.start < part.start && needle_part.end > part.start) {\n return true;\n }\n }\n\n return false;\n };\n\n let filtered = seq.parts.filter(filter);\n\n if (filtered.length > 0) {\n continue;\n }\n\n return true;\n }\n\n return false;\n};\n\nclass Sequence {\n constructor() {\n /** @type {TSequencePart[]} */\n this.parts = [];\n /** @type {string[]} */\n\n this.substrs = [];\n this.start = 0;\n this.end = 0;\n }\n /**\n * @param {TSequencePart|undefined} part\n */\n\n\n add(part) {\n if (part) {\n this.parts.push(part);\n this.substrs.push(part.substr);\n this.start = Math.min(part.start, this.start);\n this.end = Math.max(part.end, this.end);\n }\n }\n\n last() {\n return this.parts[this.parts.length - 1];\n }\n\n length() {\n return this.parts.length;\n }\n /**\n * @param {number} position\n * @param {TSequencePart} last_piece\n */\n\n\n clone(position, last_piece) {\n let clone = new Sequence();\n let parts = JSON.parse(JSON.stringify(this.parts));\n let last_part = parts.pop();\n\n for (const part of parts) {\n clone.add(part);\n }\n\n let last_substr = last_piece.substr.substring(0, position - last_part.start);\n let clone_last_len = last_substr.length;\n clone.add({\n start: last_part.start,\n end: last_part.start + clone_last_len,\n length: clone_last_len,\n substr: last_substr\n });\n return clone;\n }\n\n}\n/**\n * Expand a regular expression pattern to include unicode variants\n * \teg /a/ becomes /aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐɑAⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ/\n *\n * Issue:\n * ﺊﺋ [ 'ﺊ = \\\\u{fe8a}', 'ﺋ = \\\\u{fe8b}' ]\n *\tbecomes:\tئئ [ 'ي = \\\\u{64a}', 'ٔ = \\\\u{654}', 'ي = \\\\u{64a}', 'ٔ = \\\\u{654}' ]\n *\n *\tİIJ = IIJ = ⅡJ\n *\n * \t1/2/4\n *\n * @param {string} str\n * @return {string|undefined}\n */\n\n\nconst getPattern = str => {\n initialize();\n str = asciifold(str);\n let pattern = '';\n let sequences = [new Sequence()];\n\n for (let i = 0; i < str.length; i++) {\n let substr = str.substring(i);\n let match = substr.match(multi_char_reg);\n const char = str.substring(i, i + 1);\n const match_str = match ? match[0] : null; // loop through sequences\n // add either the char or multi_match\n\n let overlapping = [];\n let added_types = new Set();\n\n for (const sequence of sequences) {\n const last_piece = sequence.last();\n\n if (!last_piece || last_piece.length == 1 || last_piece.end <= i) {\n // if we have a multi match\n if (match_str) {\n const len = match_str.length;\n sequence.add({\n start: i,\n end: i + len,\n length: len,\n substr: match_str\n });\n added_types.add('1');\n } else {\n sequence.add({\n start: i,\n end: i + 1,\n length: 1,\n substr: char\n });\n added_types.add('2');\n }\n } else if (match_str) {\n let clone = sequence.clone(i, last_piece);\n const len = match_str.length;\n clone.add({\n start: i,\n end: i + len,\n length: len,\n substr: match_str\n });\n overlapping.push(clone);\n } else {\n // don't add char\n // adding would create invalid patterns: 234 => [2,34,4]\n added_types.add('3');\n }\n } // if we have overlapping\n\n\n if (overlapping.length > 0) {\n // ['ii','iii'] before ['i','i','iii']\n overlapping = overlapping.sort((a, b) => {\n return a.length() - b.length();\n });\n\n for (let clone of overlapping) {\n // don't add if we already have an equivalent sequence\n if (inSequences(clone, sequences)) {\n continue;\n }\n\n sequences.push(clone);\n }\n\n continue;\n } // if we haven't done anything unique\n // clean up the patterns\n // helps keep patterns smaller\n // if str = 'r₨㎧aarss', pattern will be 446 instead of 655\n\n\n if (i > 0 && added_types.size == 1 && !added_types.has('3')) {\n pattern += sequencesToPattern(sequences, false);\n let new_seq = new Sequence();\n const old_seq = sequences[0];\n\n if (old_seq) {\n new_seq.add(old_seq.last());\n }\n\n sequences = [new_seq];\n }\n }\n\n pattern += sequencesToPattern(sequences, true);\n return pattern;\n};\n\n/*! sifter.js | https://github.com/orchidjs/sifter.js | Apache License (v2) */\n\n/**\n * A property getter resolving dot-notation\n * @param {Object} obj The root object to fetch property on\n * @param {String} name The optionally dotted property name to fetch\n * @return {Object} The resolved property value\n */\nconst getAttr = (obj, name) => {\n if (!obj) return;\n return obj[name];\n};\n/**\n * A property getter resolving dot-notation\n * @param {Object} obj The root object to fetch property on\n * @param {String} name The optionally dotted property name to fetch\n * @return {Object} The resolved property value\n */\n\nconst getAttrNesting = (obj, name) => {\n if (!obj) return;\n var part,\n names = name.split(\".\");\n\n while ((part = names.shift()) && (obj = obj[part]));\n\n return obj;\n};\n/**\n * Calculates how close of a match the\n * given value is against a search token.\n *\n */\n\nconst scoreValue = (value, token, weight) => {\n var score, pos;\n if (!value) return 0;\n value = value + '';\n if (token.regex == null) return 0;\n pos = value.search(token.regex);\n if (pos === -1) return 0;\n score = token.string.length / value.length;\n if (pos === 0) score += 0.5;\n return score * weight;\n};\n/**\n * Cast object property to an array if it exists and has a value\n *\n */\n\nconst propToArray = (obj, key) => {\n var value = obj[key];\n if (typeof value == 'function') return value;\n\n if (value && !Array.isArray(value)) {\n obj[key] = [value];\n }\n};\n/**\n * Iterates over arrays and hashes.\n *\n * ```\n * iterate(this.items, function(item, id) {\n * // invoked for each item\n * });\n * ```\n *\n */\n\nconst iterate$1 = (object, callback) => {\n if (Array.isArray(object)) {\n object.forEach(callback);\n } else {\n for (var key in object) {\n if (object.hasOwnProperty(key)) {\n callback(object[key], key);\n }\n }\n }\n};\nconst cmp = (a, b) => {\n if (typeof a === 'number' && typeof b === 'number') {\n return a > b ? 1 : a < b ? -1 : 0;\n }\n\n a = asciifold(a + '').toLowerCase();\n b = asciifold(b + '').toLowerCase();\n if (a > b) return 1;\n if (b > a) return -1;\n return 0;\n};\n\n/*! sifter.js | https://github.com/orchidjs/sifter.js | Apache License (v2) */\n\n/**\n * sifter.js\n * Copyright (c) 2013–2020 Brian Reavis & contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n * @author Brian Reavis \n */\n\nclass Sifter {\n // []|{};\n\n /**\n * Textually searches arrays and hashes of objects\n * by property (or multiple properties). Designed\n * specifically for autocomplete.\n *\n */\n constructor(items, settings) {\n this.items = void 0;\n this.settings = void 0;\n this.items = items;\n this.settings = settings || {\n diacritics: true\n };\n }\n\n /**\n * Splits a search string into an array of individual\n * regexps to be used to match results.\n *\n */\n tokenize(query, respect_word_boundaries, weights) {\n if (!query || !query.length) return [];\n const tokens = [];\n const words = query.split(/\\s+/);\n var field_regex;\n\n if (weights) {\n field_regex = new RegExp('^(' + Object.keys(weights).map(escape_regex).join('|') + ')\\:(.*)$');\n }\n\n words.forEach(word => {\n let field_match;\n let field = null;\n let regex = null; // look for \"field:query\" tokens\n\n if (field_regex && (field_match = word.match(field_regex))) {\n field = field_match[1];\n word = field_match[2];\n }\n\n if (word.length > 0) {\n if (this.settings.diacritics) {\n regex = getPattern(word) || null;\n } else {\n regex = escape_regex(word);\n }\n\n if (regex && respect_word_boundaries) regex = \"\\\\b\" + regex;\n }\n\n tokens.push({\n string: word,\n regex: regex ? new RegExp(regex, 'iu') : null,\n field: field\n });\n });\n return tokens;\n }\n\n /**\n * Returns a function to be used to score individual results.\n *\n * Good matches will have a higher score than poor matches.\n * If an item is not a match, 0 will be returned by the function.\n *\n * @returns {T.ScoreFn}\n */\n getScoreFunction(query, options) {\n var search = this.prepareSearch(query, options);\n return this._getScoreFunction(search);\n }\n /**\n * @returns {T.ScoreFn}\n *\n */\n\n\n _getScoreFunction(search) {\n const tokens = search.tokens,\n token_count = tokens.length;\n\n if (!token_count) {\n return function () {\n return 0;\n };\n }\n\n const fields = search.options.fields,\n weights = search.weights,\n field_count = fields.length,\n getAttrFn = search.getAttrFn;\n\n if (!field_count) {\n return function () {\n return 1;\n };\n }\n /**\n * Calculates the score of an object\n * against the search query.\n *\n */\n\n\n const scoreObject = function () {\n if (field_count === 1) {\n return function (token, data) {\n const field = fields[0].field;\n return scoreValue(getAttrFn(data, field), token, weights[field] || 1);\n };\n }\n\n return function (token, data) {\n var sum = 0; // is the token specific to a field?\n\n if (token.field) {\n const value = getAttrFn(data, token.field);\n\n if (!token.regex && value) {\n sum += 1 / field_count;\n } else {\n sum += scoreValue(value, token, 1);\n }\n } else {\n iterate$1(weights, (weight, field) => {\n sum += scoreValue(getAttrFn(data, field), token, weight);\n });\n }\n\n return sum / field_count;\n };\n }();\n\n if (token_count === 1) {\n return function (data) {\n return scoreObject(tokens[0], data);\n };\n }\n\n if (search.options.conjunction === 'and') {\n return function (data) {\n var score,\n sum = 0;\n\n for (let token of tokens) {\n score = scoreObject(token, data);\n if (score <= 0) return 0;\n sum += score;\n }\n\n return sum / token_count;\n };\n } else {\n return function (data) {\n var sum = 0;\n iterate$1(tokens, token => {\n sum += scoreObject(token, data);\n });\n return sum / token_count;\n };\n }\n }\n\n /**\n * Returns a function that can be used to compare two\n * results, for sorting purposes. If no sorting should\n * be performed, `null` will be returned.\n *\n * @return function(a,b)\n */\n getSortFunction(query, options) {\n var search = this.prepareSearch(query, options);\n return this._getSortFunction(search);\n }\n\n _getSortFunction(search) {\n var implicit_score,\n sort_flds = [];\n const self = this,\n options = search.options,\n sort = !search.query && options.sort_empty ? options.sort_empty : options.sort;\n\n if (typeof sort == 'function') {\n return sort.bind(this);\n }\n /**\n * Fetches the specified sort field value\n * from a search result item.\n *\n */\n\n\n const get_field = function get_field(name, result) {\n if (name === '$score') return result.score;\n return search.getAttrFn(self.items[result.id], name);\n }; // parse options\n\n\n if (sort) {\n for (let s of sort) {\n if (search.query || s.field !== '$score') {\n sort_flds.push(s);\n }\n }\n } // the \"$score\" field is implied to be the primary\n // sort field, unless it's manually specified\n\n\n if (search.query) {\n implicit_score = true;\n\n for (let fld of sort_flds) {\n if (fld.field === '$score') {\n implicit_score = false;\n break;\n }\n }\n\n if (implicit_score) {\n sort_flds.unshift({\n field: '$score',\n direction: 'desc'\n });\n } // without a search.query, all items will have the same score\n\n } else {\n sort_flds = sort_flds.filter(fld => fld.field !== '$score');\n } // build function\n\n\n const sort_flds_count = sort_flds.length;\n\n if (!sort_flds_count) {\n return null;\n }\n\n return function (a, b) {\n var result, field;\n\n for (let sort_fld of sort_flds) {\n field = sort_fld.field;\n let multiplier = sort_fld.direction === 'desc' ? -1 : 1;\n result = multiplier * cmp(get_field(field, a), get_field(field, b));\n if (result) return result;\n }\n\n return 0;\n };\n }\n\n /**\n * Parses a search query and returns an object\n * with tokens and fields ready to be populated\n * with results.\n *\n */\n prepareSearch(query, optsUser) {\n const weights = {};\n var options = Object.assign({}, optsUser);\n propToArray(options, 'sort');\n propToArray(options, 'sort_empty'); // convert fields to new format\n\n if (options.fields) {\n propToArray(options, 'fields');\n const fields = [];\n options.fields.forEach(field => {\n if (typeof field == 'string') {\n field = {\n field: field,\n weight: 1\n };\n }\n\n fields.push(field);\n weights[field.field] = 'weight' in field ? field.weight : 1;\n });\n options.fields = fields;\n }\n\n return {\n options: options,\n query: query.toLowerCase().trim(),\n tokens: this.tokenize(query, options.respect_word_boundaries, weights),\n total: 0,\n items: [],\n weights: weights,\n getAttrFn: options.nesting ? getAttrNesting : getAttr\n };\n }\n\n /**\n * Searches through all items and returns a sorted array of matches.\n *\n */\n search(query, options) {\n var self = this,\n score,\n search;\n search = this.prepareSearch(query, options);\n options = search.options;\n query = search.query; // generate result scoring function\n\n const fn_score = options.score || self._getScoreFunction(search); // perform search and sort\n\n\n if (query.length) {\n iterate$1(self.items, (item, id) => {\n score = fn_score(item);\n\n if (options.filter === false || score > 0) {\n search.items.push({\n 'score': score,\n 'id': id\n });\n }\n });\n } else {\n iterate$1(self.items, (_, id) => {\n search.items.push({\n 'score': 1,\n 'id': id\n });\n });\n }\n\n const fn_sort = self._getSortFunction(search);\n\n if (fn_sort) search.items.sort(fn_sort); // apply limits\n\n search.total = search.items.length;\n\n if (typeof options.limit === 'number') {\n search.items = search.items.slice(0, options.limit);\n }\n\n return search;\n }\n\n}\n\n/**\n * Iterates over arrays and hashes.\n *\n * ```\n * iterate(this.items, function(item, id) {\n * // invoked for each item\n * });\n * ```\n *\n */\nconst iterate = (object, callback) => {\n if (Array.isArray(object)) {\n object.forEach(callback);\n } else {\n for (var key in object) {\n if (object.hasOwnProperty(key)) {\n callback(object[key], key);\n }\n }\n }\n};\n\n/**\n * Return a dom element from either a dom query string, jQuery object, a dom element or html string\n * https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro/35385518#35385518\n *\n * param query should be {}\n */\nconst getDom = query => {\n if (query.jquery) {\n return query[0];\n }\n if (query instanceof HTMLElement) {\n return query;\n }\n if (isHtmlString(query)) {\n var tpl = document.createElement('template');\n tpl.innerHTML = query.trim(); // Never return a text node of whitespace as the result\n return tpl.content.firstChild;\n }\n return document.querySelector(query);\n};\nconst isHtmlString = arg => {\n if (typeof arg === 'string' && arg.indexOf('<') > -1) {\n return true;\n }\n return false;\n};\nconst escapeQuery = query => {\n return query.replace(/['\"\\\\]/g, '\\\\$&');\n};\n\n/**\n * Dispatch an event\n *\n */\nconst triggerEvent = (dom_el, event_name) => {\n var event = document.createEvent('HTMLEvents');\n event.initEvent(event_name, true, false);\n dom_el.dispatchEvent(event);\n};\n\n/**\n * Apply CSS rules to a dom element\n *\n */\nconst applyCSS = (dom_el, css) => {\n Object.assign(dom_el.style, css);\n};\n\n/**\n * Add css classes\n *\n */\nconst addClasses = (elmts, ...classes) => {\n var norm_classes = classesArray(classes);\n elmts = castAsArray(elmts);\n elmts.map(el => {\n norm_classes.map(cls => {\n el.classList.add(cls);\n });\n });\n};\n\n/**\n * Remove css classes\n *\n */\nconst removeClasses = (elmts, ...classes) => {\n var norm_classes = classesArray(classes);\n elmts = castAsArray(elmts);\n elmts.map(el => {\n norm_classes.map(cls => {\n el.classList.remove(cls);\n });\n });\n};\n\n/**\n * Return arguments\n *\n */\nconst classesArray = args => {\n var classes = [];\n iterate(args, _classes => {\n if (typeof _classes === 'string') {\n _classes = _classes.trim().split(/[\\11\\12\\14\\15\\40]/);\n }\n if (Array.isArray(_classes)) {\n classes = classes.concat(_classes);\n }\n });\n return classes.filter(Boolean);\n};\n\n/**\n * Create an array from arg if it's not already an array\n *\n */\nconst castAsArray = arg => {\n if (!Array.isArray(arg)) {\n arg = [arg];\n }\n return arg;\n};\n\n/**\n * Get the closest node to the evt.target matching the selector\n * Stops at wrapper\n *\n */\nconst parentMatch = (target, selector, wrapper) => {\n if (wrapper && !wrapper.contains(target)) {\n return;\n }\n while (target && target.matches) {\n if (target.matches(selector)) {\n return target;\n }\n target = target.parentNode;\n }\n};\n\n/**\n * Get the first or last item from an array\n *\n * > 0 - right (last)\n * <= 0 - left (first)\n *\n */\nconst getTail = (list, direction = 0) => {\n if (direction > 0) {\n return list[list.length - 1];\n }\n return list[0];\n};\n\n/**\n * Return true if an object is empty\n *\n */\nconst isEmptyObject = obj => {\n return Object.keys(obj).length === 0;\n};\n\n/**\n * Get the index of an element amongst sibling nodes of the same type\n *\n */\nconst nodeIndex = (el, amongst) => {\n if (!el) return -1;\n amongst = amongst || el.nodeName;\n var i = 0;\n while (el = el.previousElementSibling) {\n if (el.matches(amongst)) {\n i++;\n }\n }\n return i;\n};\n\n/**\n * Set attributes of an element\n *\n */\nconst setAttr = (el, attrs) => {\n iterate(attrs, (val, attr) => {\n if (val == null) {\n el.removeAttribute(attr);\n } else {\n el.setAttribute(attr, '' + val);\n }\n });\n};\n\n/**\n * Replace a node\n */\nconst replaceNode = (existing, replacement) => {\n if (existing.parentNode) existing.parentNode.replaceChild(replacement, existing);\n};\n\n/**\n * highlight v3 | MIT license | Johann Burkard \n * Highlights arbitrary terms in a node.\n *\n * - Modified by Marshal 2011-6-24 (added regex)\n * - Modified by Brian Reavis 2012-8-27 (cleanup)\n */\n\nconst highlight = (element, regex) => {\n if (regex === null) return;\n\n // convet string to regex\n if (typeof regex === 'string') {\n if (!regex.length) return;\n regex = new RegExp(regex, 'i');\n }\n\n // Wrap matching part of text node with highlighting , e.g.\n // Soccer -> Soccer for regex = /soc/i\n const highlightText = node => {\n var match = node.data.match(regex);\n if (match && node.data.length > 0) {\n var spannode = document.createElement('span');\n spannode.className = 'highlight';\n var middlebit = node.splitText(match.index);\n middlebit.splitText(match[0].length);\n var middleclone = middlebit.cloneNode(true);\n spannode.appendChild(middleclone);\n replaceNode(middlebit, spannode);\n return 1;\n }\n return 0;\n };\n\n // Recurse element node, looking for child text nodes to highlight, unless element\n // is childless,