UNPKG

@armin-eslami/persian-calendar

Version:

Big persian calendar component made by react.

1,192 lines (1,175 loc) 111 kB
import { jsx, jsxs } from 'react/jsx-runtime'; import { useState, useEffect, useMemo } from 'react'; function styleInject(css, ref) { if ( ref === void 0 ) ref = {}; var insertAt = ref.insertAt; if (typeof document === 'undefined') { return; } var head = document.head || document.getElementsByTagName('head')[0]; var style = document.createElement('style'); style.type = 'text/css'; if (insertAt === 'top') { if (head.firstChild) { head.insertBefore(style, head.firstChild); } else { head.appendChild(style); } } else { head.appendChild(style); } if (style.styleSheet) { style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } } var css_248z = ".persian-calendar *,.persian-calendar :after,.persian-calendar :before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }.persian-calendar ::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }/*! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com*/.persian-calendar *,.persian-calendar :after,.persian-calendar :before{border:0 solid #e5e7eb;box-sizing:border-box}.persian-calendar :after,.persian-calendar :before{--tw-content:\"\"}.persian-calendar :host,html{-webkit-text-size-adjust:100%;font-feature-settings:normal;-webkit-tap-highlight-color:transparent;font-family:ui-sans-serif,system-ui,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-variation-settings:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4}body{line-height:inherit;margin:0}.persian-calendar hr{border-top-width:1px;color:inherit;height:0}.persian-calendar abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}.persian-calendar h1,.persian-calendar h2,.persian-calendar h3,.persian-calendar h4,.persian-calendar h5,.persian-calendar h6{font-size:inherit;font-weight:inherit}.persian-calendar a{color:inherit;text-decoration:inherit}.persian-calendar b,.persian-calendar strong{font-weight:bolder}.persian-calendar code,.persian-calendar kbd,.persian-calendar pre,.persian-calendar samp{font-feature-settings:normal;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em;font-variation-settings:normal}.persian-calendar small{font-size:80%}.persian-calendar sub,.persian-calendar sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}.persian-calendar sub{bottom:-.25em}.persian-calendar sup{top:-.5em}.persian-calendar table{border-collapse:collapse;border-color:inherit;text-indent:0}.persian-calendar button,.persian-calendar input,.persian-calendar optgroup,.persian-calendar select,.persian-calendar textarea{font-feature-settings:inherit;color:inherit;font-family:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;letter-spacing:inherit;line-height:inherit;margin:0;padding:0}.persian-calendar button,.persian-calendar select{text-transform:none}.persian-calendar button,.persian-calendar input:where([type=button]),.persian-calendar input:where([type=reset]),.persian-calendar input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}.persian-calendar :-moz-focusring{outline:auto}.persian-calendar :-moz-ui-invalid{box-shadow:none}.persian-calendar progress{vertical-align:baseline}.persian-calendar ::-webkit-inner-spin-button,.persian-calendar ::-webkit-outer-spin-button{height:auto}.persian-calendar [type=search]{-webkit-appearance:textfield;outline-offset:-2px}.persian-calendar ::-webkit-search-decoration{-webkit-appearance:none}.persian-calendar ::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}.persian-calendar summary{display:list-item}.persian-calendar blockquote,.persian-calendar dd,.persian-calendar dl,.persian-calendar figure,.persian-calendar h1,.persian-calendar h2,.persian-calendar h3,.persian-calendar h4,.persian-calendar h5,.persian-calendar h6,.persian-calendar hr,.persian-calendar p,.persian-calendar pre{margin:0}.persian-calendar fieldset{margin:0;padding:0}.persian-calendar legend{padding:0}.persian-calendar menu,.persian-calendar ol,.persian-calendar ul{list-style:none;margin:0;padding:0}.persian-calendar dialog{padding:0}.persian-calendar textarea{resize:vertical}.persian-calendar input::-moz-placeholder,.persian-calendar textarea::-moz-placeholder{color:#9ca3af;opacity:1}.persian-calendar input::placeholder,.persian-calendar textarea::placeholder{color:#9ca3af;opacity:1}.persian-calendar [role=button],.persian-calendar button{cursor:pointer}.persian-calendar :disabled{cursor:default}.persian-calendar audio,.persian-calendar canvas,.persian-calendar embed,.persian-calendar iframe,.persian-calendar img,.persian-calendar object,.persian-calendar svg,.persian-calendar video{display:block;vertical-align:middle}.persian-calendar img,.persian-calendar video{height:auto;max-width:100%}.persian-calendar [hidden]:where(:not([hidden=until-found])){display:none}.persian-calendar .absolute{position:absolute}.persian-calendar .relative{position:relative}.persian-calendar .sticky{position:sticky}.persian-calendar .-bottom-1\\.5{bottom:-.375rem}.persian-calendar .bottom-0{bottom:0}.persian-calendar .left-1\\/2{left:50%}.persian-calendar .top-0{top:0}.persian-calendar .z-10{z-index:10}.persian-calendar .z-50{z-index:50}.persian-calendar .block{display:block}.persian-calendar .flex{display:flex}.persian-calendar .grid{display:grid}.persian-calendar .aspect-square{aspect-ratio:1/1}.persian-calendar .h-1\\.5{height:.375rem}.persian-calendar .h-fit{height:-moz-fit-content;height:fit-content}.persian-calendar .min-h-32{min-height:8rem}.persian-calendar .min-h-dvh{min-height:100dvh}.persian-calendar .w-1\\.5{width:.375rem}.persian-calendar .w-1\\/2{width:50%}.persian-calendar .w-10{width:2.5rem}.persian-calendar .w-full{width:100%}.persian-calendar .min-w-32{min-width:8rem}.persian-calendar .min-w-full{min-width:100%}.persian-calendar .max-w-\\[40px\\]{max-width:40px}.persian-calendar .-translate-x-1\\/2{--tw-translate-x:-50%}.persian-calendar .-translate-x-1\\/2,.persian-calendar .transform{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.persian-calendar .cursor-default{cursor:default}.persian-calendar .cursor-pointer{cursor:pointer}.persian-calendar .select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.persian-calendar .grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.persian-calendar .grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.persian-calendar .grid-cols-7{grid-template-columns:repeat(7,minmax(0,1fr))}.persian-calendar .flex-row{flex-direction:row}.persian-calendar .flex-col{flex-direction:column}.persian-calendar .items-center{align-items:center}.persian-calendar .justify-end{justify-content:flex-end}.persian-calendar .justify-center{justify-content:center}.persian-calendar .justify-between{justify-content:space-between}.persian-calendar .gap-1{gap:.25rem}.persian-calendar .gap-2{gap:.5rem}.persian-calendar .gap-4{gap:1rem}.persian-calendar .gap-6{gap:1.5rem}.persian-calendar .space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(.5rem*var(--tw-space-y-reverse));margin-top:calc(.5rem*(1 - var(--tw-space-y-reverse)))}.persian-calendar .space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(1rem*var(--tw-space-y-reverse));margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)))}.persian-calendar .space-y-8>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(2rem*var(--tw-space-y-reverse));margin-top:calc(2rem*(1 - var(--tw-space-y-reverse)))}.persian-calendar .self-start{align-self:flex-start}.persian-calendar .overflow-auto{overflow:auto}.persian-calendar .overflow-x-auto{overflow-x:auto}.persian-calendar .truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.persian-calendar .text-wrap{text-wrap:wrap}.persian-calendar .rounded-full{border-radius:9999px}.persian-calendar .rounded-lg{border-radius:.5rem}.persian-calendar .rounded-md{border-radius:.375rem}.persian-calendar .rounded-sm{border-radius:.125rem}.persian-calendar .border{border-width:1px}.persian-calendar .p-4{padding:1rem}.persian-calendar .px-1{padding-left:.25rem;padding-right:.25rem}.persian-calendar .px-2{padding-left:.5rem;padding-right:.5rem}.persian-calendar .px-4{padding-left:1rem;padding-right:1rem}.persian-calendar .py-0\\.5{padding-bottom:.125rem;padding-top:.125rem}.persian-calendar .py-1{padding-bottom:.25rem;padding-top:.25rem}.persian-calendar .py-2{padding-bottom:.5rem;padding-top:.5rem}.persian-calendar .pb-2{padding-bottom:.5rem}.persian-calendar .text-center{text-align:center}.persian-calendar .text-start{text-align:start}.persian-calendar .font-bold{font-weight:700}.persian-calendar .text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity,1))}.persian-calendar .transition-transform{transition-duration:.15s;transition-property:transform;transition-timing-function:cubic-bezier(.4,0,.2,1)}.persian-calendar .duration-300{transition-duration:.3s}.persian-calendar .ease-in-out{transition-timing-function:cubic-bezier(.4,0,.2,1)}@keyframes year-slide{0%{opacity:0;transform:translateY(-100%)}to{opacity:1;transform:translateY(0)}}.persian-calendar .animate-year-slide{animation:year-slide .3s ease}.persian-calendar .month-row-text{color:var(--text)}.persian-calendar .month-row-text-hover:hover{background-color:var(--hover-bg);color:#fff}@media (min-width:768px){.persian-calendar .md\\:w-fit{width:-moz-fit-content;width:fit-content}.persian-calendar .md\\:grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.persian-calendar .md\\:grid-cols-10{grid-template-columns:repeat(10,minmax(0,1fr))}.persian-calendar .md\\:grid-cols-11{grid-template-columns:repeat(11,minmax(0,1fr))}.persian-calendar .md\\:grid-cols-12{grid-template-columns:repeat(12,minmax(0,1fr))}.persian-calendar .md\\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.persian-calendar .md\\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.persian-calendar .md\\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.persian-calendar .md\\:grid-cols-5{grid-template-columns:repeat(5,minmax(0,1fr))}.persian-calendar .md\\:grid-cols-6{grid-template-columns:repeat(6,minmax(0,1fr))}.persian-calendar .md\\:grid-cols-7{grid-template-columns:repeat(7,minmax(0,1fr))}.persian-calendar .md\\:grid-cols-8{grid-template-columns:repeat(8,minmax(0,1fr))}.persian-calendar .md\\:grid-cols-9{grid-template-columns:repeat(9,minmax(0,1fr))}.persian-calendar .md\\:flex-row{flex-direction:row}.persian-calendar .md\\:items-center{align-items:center}.persian-calendar .md\\:space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-bottom:calc(.5rem*var(--tw-space-y-reverse));margin-top:calc(.5rem*(1 - var(--tw-space-y-reverse)))}.persian-calendar .md\\:pb-0{padding-bottom:0}}@media (min-width:1024px){.persian-calendar .lg\\:gap-4{gap:1rem}}@media (min-width:1280px){.persian-calendar .xl\\:grid-cols-7{grid-template-columns:repeat(7,minmax(0,1fr))}}"; styleInject(css_248z); /****************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */ var __assign = function() { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { var e = new Error(message); return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; }; var PersianCalendarMode; (function (PersianCalendarMode) { PersianCalendarMode["YEAR"] = "1"; PersianCalendarMode["MONTH"] = "2"; })(PersianCalendarMode || (PersianCalendarMode = {})); function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n} const CLASS_PART_SEPARATOR = '-'; const createClassGroupUtils = config => { const classMap = createClassMap(config); const { conflictingClassGroups, conflictingClassGroupModifiers } = config; const getClassGroupId = className => { const classParts = className.split(CLASS_PART_SEPARATOR); // Classes like `-inset-1` produce an empty string as first classPart. We assume that classes for negative values are used correctly and remove it from classParts. if (classParts[0] === '' && classParts.length !== 1) { classParts.shift(); } return getGroupRecursive(classParts, classMap) || getGroupIdForArbitraryProperty(className); }; const getConflictingClassGroupIds = (classGroupId, hasPostfixModifier) => { const conflicts = conflictingClassGroups[classGroupId] || []; if (hasPostfixModifier && conflictingClassGroupModifiers[classGroupId]) { return [...conflicts, ...conflictingClassGroupModifiers[classGroupId]]; } return conflicts; }; return { getClassGroupId, getConflictingClassGroupIds }; }; const getGroupRecursive = (classParts, classPartObject) => { if (classParts.length === 0) { return classPartObject.classGroupId; } const currentClassPart = classParts[0]; const nextClassPartObject = classPartObject.nextPart.get(currentClassPart); const classGroupFromNextClassPart = nextClassPartObject ? getGroupRecursive(classParts.slice(1), nextClassPartObject) : undefined; if (classGroupFromNextClassPart) { return classGroupFromNextClassPart; } if (classPartObject.validators.length === 0) { return undefined; } const classRest = classParts.join(CLASS_PART_SEPARATOR); return classPartObject.validators.find(({ validator }) => validator(classRest))?.classGroupId; }; const arbitraryPropertyRegex = /^\[(.+)\]$/; const getGroupIdForArbitraryProperty = className => { if (arbitraryPropertyRegex.test(className)) { const arbitraryPropertyClassName = arbitraryPropertyRegex.exec(className)[1]; const property = arbitraryPropertyClassName?.substring(0, arbitraryPropertyClassName.indexOf(':')); if (property) { // I use two dots here because one dot is used as prefix for class groups in plugins return 'arbitrary..' + property; } } }; /** * Exported for testing only */ const createClassMap = config => { const { theme, prefix } = config; const classMap = { nextPart: new Map(), validators: [] }; const prefixedClassGroupEntries = getPrefixedClassGroupEntries(Object.entries(config.classGroups), prefix); prefixedClassGroupEntries.forEach(([classGroupId, classGroup]) => { processClassesRecursively(classGroup, classMap, classGroupId, theme); }); return classMap; }; const processClassesRecursively = (classGroup, classPartObject, classGroupId, theme) => { classGroup.forEach(classDefinition => { if (typeof classDefinition === 'string') { const classPartObjectToEdit = classDefinition === '' ? classPartObject : getPart(classPartObject, classDefinition); classPartObjectToEdit.classGroupId = classGroupId; return; } if (typeof classDefinition === 'function') { if (isThemeGetter(classDefinition)) { processClassesRecursively(classDefinition(theme), classPartObject, classGroupId, theme); return; } classPartObject.validators.push({ validator: classDefinition, classGroupId }); return; } Object.entries(classDefinition).forEach(([key, classGroup]) => { processClassesRecursively(classGroup, getPart(classPartObject, key), classGroupId, theme); }); }); }; const getPart = (classPartObject, path) => { let currentClassPartObject = classPartObject; path.split(CLASS_PART_SEPARATOR).forEach(pathPart => { if (!currentClassPartObject.nextPart.has(pathPart)) { currentClassPartObject.nextPart.set(pathPart, { nextPart: new Map(), validators: [] }); } currentClassPartObject = currentClassPartObject.nextPart.get(pathPart); }); return currentClassPartObject; }; const isThemeGetter = func => func.isThemeGetter; const getPrefixedClassGroupEntries = (classGroupEntries, prefix) => { if (!prefix) { return classGroupEntries; } return classGroupEntries.map(([classGroupId, classGroup]) => { const prefixedClassGroup = classGroup.map(classDefinition => { if (typeof classDefinition === 'string') { return prefix + classDefinition; } if (typeof classDefinition === 'object') { return Object.fromEntries(Object.entries(classDefinition).map(([key, value]) => [prefix + key, value])); } return classDefinition; }); return [classGroupId, prefixedClassGroup]; }); }; // LRU cache inspired from hashlru (https://github.com/dominictarr/hashlru/blob/v1.0.4/index.js) but object replaced with Map to improve performance const createLruCache = maxCacheSize => { if (maxCacheSize < 1) { return { get: () => undefined, set: () => {} }; } let cacheSize = 0; let cache = new Map(); let previousCache = new Map(); const update = (key, value) => { cache.set(key, value); cacheSize++; if (cacheSize > maxCacheSize) { cacheSize = 0; previousCache = cache; cache = new Map(); } }; return { get(key) { let value = cache.get(key); if (value !== undefined) { return value; } if ((value = previousCache.get(key)) !== undefined) { update(key, value); return value; } }, set(key, value) { if (cache.has(key)) { cache.set(key, value); } else { update(key, value); } } }; }; const IMPORTANT_MODIFIER = '!'; const createParseClassName = config => { const { separator, experimentalParseClassName } = config; const isSeparatorSingleCharacter = separator.length === 1; const firstSeparatorCharacter = separator[0]; const separatorLength = separator.length; // parseClassName inspired by https://github.com/tailwindlabs/tailwindcss/blob/v3.2.2/src/util/splitAtTopLevelOnly.js const parseClassName = className => { const modifiers = []; let bracketDepth = 0; let modifierStart = 0; let postfixModifierPosition; for (let index = 0; index < className.length; index++) { let currentCharacter = className[index]; if (bracketDepth === 0) { if (currentCharacter === firstSeparatorCharacter && (isSeparatorSingleCharacter || className.slice(index, index + separatorLength) === separator)) { modifiers.push(className.slice(modifierStart, index)); modifierStart = index + separatorLength; continue; } if (currentCharacter === '/') { postfixModifierPosition = index; continue; } } if (currentCharacter === '[') { bracketDepth++; } else if (currentCharacter === ']') { bracketDepth--; } } const baseClassNameWithImportantModifier = modifiers.length === 0 ? className : className.substring(modifierStart); const hasImportantModifier = baseClassNameWithImportantModifier.startsWith(IMPORTANT_MODIFIER); const baseClassName = hasImportantModifier ? baseClassNameWithImportantModifier.substring(1) : baseClassNameWithImportantModifier; const maybePostfixModifierPosition = postfixModifierPosition && postfixModifierPosition > modifierStart ? postfixModifierPosition - modifierStart : undefined; return { modifiers, hasImportantModifier, baseClassName, maybePostfixModifierPosition }; }; if (experimentalParseClassName) { return className => experimentalParseClassName({ className, parseClassName }); } return parseClassName; }; /** * Sorts modifiers according to following schema: * - Predefined modifiers are sorted alphabetically * - When an arbitrary variant appears, it must be preserved which modifiers are before and after it */ const sortModifiers = modifiers => { if (modifiers.length <= 1) { return modifiers; } const sortedModifiers = []; let unsortedModifiers = []; modifiers.forEach(modifier => { const isArbitraryVariant = modifier[0] === '['; if (isArbitraryVariant) { sortedModifiers.push(...unsortedModifiers.sort(), modifier); unsortedModifiers = []; } else { unsortedModifiers.push(modifier); } }); sortedModifiers.push(...unsortedModifiers.sort()); return sortedModifiers; }; const createConfigUtils = config => ({ cache: createLruCache(config.cacheSize), parseClassName: createParseClassName(config), ...createClassGroupUtils(config) }); const SPLIT_CLASSES_REGEX = /\s+/; const mergeClassList = (classList, configUtils) => { const { parseClassName, getClassGroupId, getConflictingClassGroupIds } = configUtils; /** * Set of classGroupIds in following format: * `{importantModifier}{variantModifiers}{classGroupId}` * @example 'float' * @example 'hover:focus:bg-color' * @example 'md:!pr' */ const classGroupsInConflict = []; const classNames = classList.trim().split(SPLIT_CLASSES_REGEX); let result = ''; for (let index = classNames.length - 1; index >= 0; index -= 1) { const originalClassName = classNames[index]; const { modifiers, hasImportantModifier, baseClassName, maybePostfixModifierPosition } = parseClassName(originalClassName); let hasPostfixModifier = Boolean(maybePostfixModifierPosition); let classGroupId = getClassGroupId(hasPostfixModifier ? baseClassName.substring(0, maybePostfixModifierPosition) : baseClassName); if (!classGroupId) { if (!hasPostfixModifier) { // Not a Tailwind class result = originalClassName + (result.length > 0 ? ' ' + result : result); continue; } classGroupId = getClassGroupId(baseClassName); if (!classGroupId) { // Not a Tailwind class result = originalClassName + (result.length > 0 ? ' ' + result : result); continue; } hasPostfixModifier = false; } const variantModifier = sortModifiers(modifiers).join(':'); const modifierId = hasImportantModifier ? variantModifier + IMPORTANT_MODIFIER : variantModifier; const classId = modifierId + classGroupId; if (classGroupsInConflict.includes(classId)) { // Tailwind class omitted due to conflict continue; } classGroupsInConflict.push(classId); const conflictGroups = getConflictingClassGroupIds(classGroupId, hasPostfixModifier); for (let i = 0; i < conflictGroups.length; ++i) { const group = conflictGroups[i]; classGroupsInConflict.push(modifierId + group); } // Tailwind class not in conflict result = originalClassName + (result.length > 0 ? ' ' + result : result); } return result; }; /** * The code in this file is copied from https://github.com/lukeed/clsx and modified to suit the needs of tailwind-merge better. * * Specifically: * - Runtime code from https://github.com/lukeed/clsx/blob/v1.2.1/src/index.js * - TypeScript types from https://github.com/lukeed/clsx/blob/v1.2.1/clsx.d.ts * * Original code has MIT license: Copyright (c) Luke Edwards <luke.edwards05@gmail.com> (lukeed.com) */ function twJoin() { let index = 0; let argument; let resolvedValue; let string = ''; while (index < arguments.length) { if (argument = arguments[index++]) { if (resolvedValue = toValue(argument)) { string && (string += ' '); string += resolvedValue; } } } return string; } const toValue = mix => { if (typeof mix === 'string') { return mix; } let resolvedValue; let string = ''; for (let k = 0; k < mix.length; k++) { if (mix[k]) { if (resolvedValue = toValue(mix[k])) { string && (string += ' '); string += resolvedValue; } } } return string; }; function createTailwindMerge(createConfigFirst, ...createConfigRest) { let configUtils; let cacheGet; let cacheSet; let functionToCall = initTailwindMerge; function initTailwindMerge(classList) { const config = createConfigRest.reduce((previousConfig, createConfigCurrent) => createConfigCurrent(previousConfig), createConfigFirst()); configUtils = createConfigUtils(config); cacheGet = configUtils.cache.get; cacheSet = configUtils.cache.set; functionToCall = tailwindMerge; return tailwindMerge(classList); } function tailwindMerge(classList) { const cachedResult = cacheGet(classList); if (cachedResult) { return cachedResult; } const result = mergeClassList(classList, configUtils); cacheSet(classList, result); return result; } return function callTailwindMerge() { return functionToCall(twJoin.apply(null, arguments)); }; } const fromTheme = key => { const themeGetter = theme => theme[key] || []; themeGetter.isThemeGetter = true; return themeGetter; }; const arbitraryValueRegex = /^\[(?:([a-z-]+):)?(.+)\]$/i; const fractionRegex = /^\d+\/\d+$/; const stringLengths = /*#__PURE__*/new Set(['px', 'full', 'screen']); const tshirtUnitRegex = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/; const lengthUnitRegex = /\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/; const colorFunctionRegex = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/; // Shadow always begins with x and y offset separated by underscore optionally prepended by inset const shadowRegex = /^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/; const imageRegex = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/; const isLength = value => isNumber(value) || stringLengths.has(value) || fractionRegex.test(value); const isArbitraryLength = value => getIsArbitraryValue(value, 'length', isLengthOnly); const isNumber = value => Boolean(value) && !Number.isNaN(Number(value)); const isArbitraryNumber = value => getIsArbitraryValue(value, 'number', isNumber); const isInteger = value => Boolean(value) && Number.isInteger(Number(value)); const isPercent = value => value.endsWith('%') && isNumber(value.slice(0, -1)); const isArbitraryValue = value => arbitraryValueRegex.test(value); const isTshirtSize = value => tshirtUnitRegex.test(value); const sizeLabels = /*#__PURE__*/new Set(['length', 'size', 'percentage']); const isArbitrarySize = value => getIsArbitraryValue(value, sizeLabels, isNever); const isArbitraryPosition = value => getIsArbitraryValue(value, 'position', isNever); const imageLabels = /*#__PURE__*/new Set(['image', 'url']); const isArbitraryImage = value => getIsArbitraryValue(value, imageLabels, isImage); const isArbitraryShadow = value => getIsArbitraryValue(value, '', isShadow); const isAny = () => true; const getIsArbitraryValue = (value, label, testValue) => { const result = arbitraryValueRegex.exec(value); if (result) { if (result[1]) { return typeof label === 'string' ? result[1] === label : label.has(result[1]); } return testValue(result[2]); } return false; }; const isLengthOnly = value => // `colorFunctionRegex` check is necessary because color functions can have percentages in them which which would be incorrectly classified as lengths. // For example, `hsl(0 0% 0%)` would be classified as a length without this check. // I could also use lookbehind assertion in `lengthUnitRegex` but that isn't supported widely enough. lengthUnitRegex.test(value) && !colorFunctionRegex.test(value); const isNever = () => false; const isShadow = value => shadowRegex.test(value); const isImage = value => imageRegex.test(value); const getDefaultConfig = () => { const colors = fromTheme('colors'); const spacing = fromTheme('spacing'); const blur = fromTheme('blur'); const brightness = fromTheme('brightness'); const borderColor = fromTheme('borderColor'); const borderRadius = fromTheme('borderRadius'); const borderSpacing = fromTheme('borderSpacing'); const borderWidth = fromTheme('borderWidth'); const contrast = fromTheme('contrast'); const grayscale = fromTheme('grayscale'); const hueRotate = fromTheme('hueRotate'); const invert = fromTheme('invert'); const gap = fromTheme('gap'); const gradientColorStops = fromTheme('gradientColorStops'); const gradientColorStopPositions = fromTheme('gradientColorStopPositions'); const inset = fromTheme('inset'); const margin = fromTheme('margin'); const opacity = fromTheme('opacity'); const padding = fromTheme('padding'); const saturate = fromTheme('saturate'); const scale = fromTheme('scale'); const sepia = fromTheme('sepia'); const skew = fromTheme('skew'); const space = fromTheme('space'); const translate = fromTheme('translate'); const getOverscroll = () => ['auto', 'contain', 'none']; const getOverflow = () => ['auto', 'hidden', 'clip', 'visible', 'scroll']; const getSpacingWithAutoAndArbitrary = () => ['auto', isArbitraryValue, spacing]; const getSpacingWithArbitrary = () => [isArbitraryValue, spacing]; const getLengthWithEmptyAndArbitrary = () => ['', isLength, isArbitraryLength]; const getNumberWithAutoAndArbitrary = () => ['auto', isNumber, isArbitraryValue]; const getPositions = () => ['bottom', 'center', 'left', 'left-bottom', 'left-top', 'right', 'right-bottom', 'right-top', 'top']; const getLineStyles = () => ['solid', 'dashed', 'dotted', 'double', 'none']; const getBlendModes = () => ['normal', 'multiply', 'screen', 'overlay', 'darken', 'lighten', 'color-dodge', 'color-burn', 'hard-light', 'soft-light', 'difference', 'exclusion', 'hue', 'saturation', 'color', 'luminosity']; const getAlign = () => ['start', 'end', 'center', 'between', 'around', 'evenly', 'stretch']; const getZeroAndEmpty = () => ['', '0', isArbitraryValue]; const getBreaks = () => ['auto', 'avoid', 'all', 'avoid-page', 'page', 'left', 'right', 'column']; const getNumberAndArbitrary = () => [isNumber, isArbitraryValue]; return { cacheSize: 500, separator: ':', theme: { colors: [isAny], spacing: [isLength, isArbitraryLength], blur: ['none', '', isTshirtSize, isArbitraryValue], brightness: getNumberAndArbitrary(), borderColor: [colors], borderRadius: ['none', '', 'full', isTshirtSize, isArbitraryValue], borderSpacing: getSpacingWithArbitrary(), borderWidth: getLengthWithEmptyAndArbitrary(), contrast: getNumberAndArbitrary(), grayscale: getZeroAndEmpty(), hueRotate: getNumberAndArbitrary(), invert: getZeroAndEmpty(), gap: getSpacingWithArbitrary(), gradientColorStops: [colors], gradientColorStopPositions: [isPercent, isArbitraryLength], inset: getSpacingWithAutoAndArbitrary(), margin: getSpacingWithAutoAndArbitrary(), opacity: getNumberAndArbitrary(), padding: getSpacingWithArbitrary(), saturate: getNumberAndArbitrary(), scale: getNumberAndArbitrary(), sepia: getZeroAndEmpty(), skew: getNumberAndArbitrary(), space: getSpacingWithArbitrary(), translate: getSpacingWithArbitrary() }, classGroups: { // Layout /** * Aspect Ratio * @see https://tailwindcss.com/docs/aspect-ratio */ aspect: [{ aspect: ['auto', 'square', 'video', isArbitraryValue] }], /** * Container * @see https://tailwindcss.com/docs/container */ container: ['container'], /** * Columns * @see https://tailwindcss.com/docs/columns */ columns: [{ columns: [isTshirtSize] }], /** * Break After * @see https://tailwindcss.com/docs/break-after */ 'break-after': [{ 'break-after': getBreaks() }], /** * Break Before * @see https://tailwindcss.com/docs/break-before */ 'break-before': [{ 'break-before': getBreaks() }], /** * Break Inside * @see https://tailwindcss.com/docs/break-inside */ 'break-inside': [{ 'break-inside': ['auto', 'avoid', 'avoid-page', 'avoid-column'] }], /** * Box Decoration Break * @see https://tailwindcss.com/docs/box-decoration-break */ 'box-decoration': [{ 'box-decoration': ['slice', 'clone'] }], /** * Box Sizing * @see https://tailwindcss.com/docs/box-sizing */ box: [{ box: ['border', 'content'] }], /** * Display * @see https://tailwindcss.com/docs/display */ display: ['block', 'inline-block', 'inline', 'flex', 'inline-flex', 'table', 'inline-table', 'table-caption', 'table-cell', 'table-column', 'table-column-group', 'table-footer-group', 'table-header-group', 'table-row-group', 'table-row', 'flow-root', 'grid', 'inline-grid', 'contents', 'list-item', 'hidden'], /** * Floats * @see https://tailwindcss.com/docs/float */ float: [{ float: ['right', 'left', 'none', 'start', 'end'] }], /** * Clear * @see https://tailwindcss.com/docs/clear */ clear: [{ clear: ['left', 'right', 'both', 'none', 'start', 'end'] }], /** * Isolation * @see https://tailwindcss.com/docs/isolation */ isolation: ['isolate', 'isolation-auto'], /** * Object Fit * @see https://tailwindcss.com/docs/object-fit */ 'object-fit': [{ object: ['contain', 'cover', 'fill', 'none', 'scale-down'] }], /** * Object Position * @see https://tailwindcss.com/docs/object-position */ 'object-position': [{ object: [...getPositions(), isArbitraryValue] }], /** * Overflow * @see https://tailwindcss.com/docs/overflow */ overflow: [{ overflow: getOverflow() }], /** * Overflow X * @see https://tailwindcss.com/docs/overflow */ 'overflow-x': [{ 'overflow-x': getOverflow() }], /** * Overflow Y * @see https://tailwindcss.com/docs/overflow */ 'overflow-y': [{ 'overflow-y': getOverflow() }], /** * Overscroll Behavior * @see https://tailwindcss.com/docs/overscroll-behavior */ overscroll: [{ overscroll: getOverscroll() }], /** * Overscroll Behavior X * @see https://tailwindcss.com/docs/overscroll-behavior */ 'overscroll-x': [{ 'overscroll-x': getOverscroll() }], /** * Overscroll Behavior Y * @see https://tailwindcss.com/docs/overscroll-behavior */ 'overscroll-y': [{ 'overscroll-y': getOverscroll() }], /** * Position * @see https://tailwindcss.com/docs/position */ position: ['static', 'fixed', 'absolute', 'relative', 'sticky'], /** * Top / Right / Bottom / Left * @see https://tailwindcss.com/docs/top-right-bottom-left */ inset: [{ inset: [inset] }], /** * Right / Left * @see https://tailwindcss.com/docs/top-right-bottom-left */ 'inset-x': [{ 'inset-x': [inset] }], /** * Top / Bottom * @see https://tailwindcss.com/docs/top-right-bottom-left */ 'inset-y': [{ 'inset-y': [inset] }], /** * Start * @see https://tailwindcss.com/docs/top-right-bottom-left */ start: [{ start: [inset] }], /** * End * @see https://tailwindcss.com/docs/top-right-bottom-left */ end: [{ end: [inset] }], /** * Top * @see https://tailwindcss.com/docs/top-right-bottom-left */ top: [{ top: [inset] }], /** * Right * @see https://tailwindcss.com/docs/top-right-bottom-left */ right: [{ right: [inset] }], /** * Bottom * @see https://tailwindcss.com/docs/top-right-bottom-left */ bottom: [{ bottom: [inset] }], /** * Left * @see https://tailwindcss.com/docs/top-right-bottom-left */ left: [{ left: [inset] }], /** * Visibility * @see https://tailwindcss.com/docs/visibility */ visibility: ['visible', 'invisible', 'collapse'], /** * Z-Index * @see https://tailwindcss.com/docs/z-index */ z: [{ z: ['auto', isInteger, isArbitraryValue] }], // Flexbox and Grid /** * Flex Basis * @see https://tailwindcss.com/docs/flex-basis */ basis: [{ basis: getSpacingWithAutoAndArbitrary() }], /** * Flex Direction * @see https://tailwindcss.com/docs/flex-direction */ 'flex-direction': [{ flex: ['row', 'row-reverse', 'col', 'col-reverse'] }], /** * Flex Wrap * @see https://tailwindcss.com/docs/flex-wrap */ 'flex-wrap': [{ flex: ['wrap', 'wrap-reverse', 'nowrap'] }], /** * Flex * @see https://tailwindcss.com/docs/flex */ flex: [{ flex: ['1', 'auto', 'initial', 'none', isArbitraryValue] }], /** * Flex Grow * @see https://tailwindcss.com/docs/flex-grow */ grow: [{ grow: getZeroAndEmpty() }], /** * Flex Shrink * @see https://tailwindcss.com/docs/flex-shrink */ shrink: [{ shrink: getZeroAndEmpty() }], /** * Order * @see https://tailwindcss.com/docs/order */ order: [{ order: ['first', 'last', 'none', isInteger, isArbitraryValue] }], /** * Grid Template Columns * @see https://tailwindcss.com/docs/grid-template-columns */ 'grid-cols': [{ 'grid-cols': [isAny] }], /** * Grid Column Start / End * @see https://tailwindcss.com/docs/grid-column */ 'col-start-end': [{ col: ['auto', { span: ['full', isInteger, isArbitraryValue] }, isArbitraryValue] }], /** * Grid Column Start * @see https://tailwindcss.com/docs/grid-column */ 'col-start': [{ 'col-start': getNumberWithAutoAndArbitrary() }], /** * Grid Column End * @see https://tailwindcss.com/docs/grid-column */ 'col-end': [{ 'col-end': getNumberWithAutoAndArbitrary() }], /** * Grid Template Rows * @see https://tailwindcss.com/docs/grid-template-rows */ 'grid-rows': [{ 'grid-rows': [isAny] }], /** * Grid Row Start / End * @see https://tailwindcss.com/docs/grid-row */ 'row-start-end': [{ row: ['auto', { span: [isInteger, isArbitraryValue] }, isArbitraryValue] }], /** * Grid Row Start * @see https://tailwindcss.com/docs/grid-row */ 'row-start': [{ 'row-start': getNumberWithAutoAndArbitrary() }], /** * Grid Row End * @see https://tailwindcss.com/docs/grid-row */ 'row-end': [{ 'row-end': getNumberWithAutoAndArbitrary() }], /** * Grid Auto Flow * @see https://tailwindcss.com/docs/grid-auto-flow */ 'grid-flow': [{ 'grid-flow': ['row', 'col', 'dense', 'row-dense', 'col-dense'] }], /** * Grid Auto Columns * @see https://tailwindcss.com/docs/grid-auto-columns */ 'auto-cols': [{ 'auto-cols': ['auto', 'min', 'max', 'fr', isArbitraryValue] }], /** * Grid Auto Rows * @see https://tailwindcss.com/docs/grid-auto-rows */ 'auto-rows': [{ 'auto-rows': ['auto', 'min', 'max', 'fr', isArbitraryValue] }], /** * Gap * @see https://tailwindcss.com/docs/gap */ gap: [{ gap: [gap] }], /** * Gap X * @see https://tailwindcss.com/docs/gap */ 'gap-x': [{ 'gap-x': [gap] }], /** * Gap Y * @see https://tailwindcss.com/docs/gap */ 'gap-y': [{ 'gap-y': [gap] }], /** * Justify Content * @see https://tailwindcss.com/docs/justify-content */ 'justify-content': [{ justify: ['normal', ...getAlign()] }], /** * Justify Items * @see https://tailwindcss.com/docs/justify-items */ 'justify-items': [{ 'justify-items': ['start', 'end', 'center', 'stretch'] }], /** * Justify Self * @see https://tailwindcss.com/docs/justify-self */ 'justify-self': [{ 'justify-self': ['auto', 'start', 'end', 'center', 'stretch'] }], /** * Align Content * @see https://tailwindcss.com/docs/align-content */ 'align-content': [{ content: ['normal', ...getAlign(), 'baseline'] }], /** * Align Items * @see https://tailwindcss.com/docs/align-items */ 'align-items': [{ items: ['start', 'end', 'center', 'baseline', 'stretch'] }], /** * Align Self * @see https://tailwindcss.com/docs/align-self */ 'align-self': [{ self: ['auto', 'start', 'end', 'center', 'stretch', 'baseline'] }], /** * Place Content * @see https://tailwindcss.com/docs/place-content */ 'place-content': [{ 'place-content': [...getAlign(), 'baseline'] }], /** * Place Items * @see https://tailwindcss.com/docs/place-items */ 'place-items': [{ 'place-items': ['start', 'end', 'center', 'baseline', 'stretch'] }], /** * Place Self * @see https://tailwindcss.com/docs/place-self */ 'place-self': [{ 'place-self': ['auto', 'start', 'end', 'center', 'stretch'] }], // Spacing /** * Padding * @see https://tailwindcss.com/docs/padding */ p: [{ p: [padding] }], /** * Padding X * @see https://tailwindcss.com/docs/padding */ px: [{ px: [padding] }], /** * Padding Y * @see https://tailwindcss.com/docs/padding */ py: [{ py: [padding] }], /** * Padding Start * @see https://tailwindcss.com/docs/padding */ ps: [{ ps: [padding] }], /** * Padding End * @see https://tailwindcss.com/docs/padding */ pe: [{ pe: [padding] }], /** * Padding Top * @see https://tailwindcss.com/docs/padding */ pt: [{ pt: [padding] }], /** * Padding Right * @see https://tailwindcss.com/docs/padding */ pr: [{ pr: [padding] }], /** * Padding Bottom * @see https://tailwindcss.com/docs/padding */ pb: [{ pb: [padding] }], /** * Padding Left * @see https://tailwindcss.com/docs/padding */ pl: [{ pl: [padding] }], /** * Margin * @see https://tailwindcss.com/docs/margin */ m: [{ m: [margin] }], /** * Margin X * @see https://tailwindcss.com/docs/margin */ mx: [{ mx: [margin] }], /** * Margin Y * @see https://tailwindcss.com/docs/margin */ my: [{ my: [margin] }], /** * Margin Start * @see https://tailwindcss.com/docs/margin */ ms: [{ ms: [margin] }], /** * Margin End * @see https://tailwindcss.com/docs/margin */ me: [{ me: [margin] }], /** * Margin Top * @see https://tailwindcss.com/docs/margin */ mt: [{ mt: [margin] }], /** * Margin Right * @see https://tailwindcss.com/docs/margin */ mr: [{ mr: [margin] }], /** * Margin Bottom * @see https://tailwindcss.com/docs/margin */ mb: [{ mb: [margin] }], /** * Margin Left * @see https://tailwindcss.com/docs/margin */ ml: [{ ml: [margin] }], /** * Space Between X * @see https://tailwindcss.com/docs/space */ 'space-x': [{ 'space-x': [space] }], /** * Space Between X Reverse * @see https://tailwindcss.com/docs/space */ 'space-x-reverse': ['space-x-reverse'], /** * Space Between Y * @see https://tailwindcss.com/docs/space */ 'space-y': [{ 'space-y': [space] }], /** * Space Between Y Reverse * @see https://tailwindcss.com/docs/space */ 'space-y-reverse': ['space-y-reverse'], // Sizing /** * Width * @see https://tailwindcss.com/docs/width */ w: [{ w: ['auto', 'min', 'max', 'fit', 'svw', 'lvw', 'dvw', isArbitraryValue, spacing] }], /** * Min-Width * @see https://tailwindcss.com/docs/min-width */ 'min-w': [{ 'min-w': [isArbitraryValue, spacing, 'min', 'max', 'fit'] }], /** * Max-Width * @see https://tailwindcss.com/docs/max-width */ 'max-w': [{ 'max-w': [isArbitraryValue, spacing, 'none', 'full', 'min', 'max', 'fit', 'prose', { screen: [isTshirtSize] }, isTshirtSize] }], /** * Height * @see https://tailwindcss.com/docs/height */ h: [{ h: [isArbitraryValue, spacing, 'auto', 'min', 'max', 'fit', 'svh', 'lvh', 'dvh'] }], /** * Min-Height * @see https://tailwindcss.com/docs/min-height */ 'min-h': [{ 'min-h': [isArbitraryValue, spacing, 'min', 'max', 'fit', 'svh', 'lvh', 'dvh'] }], /** * Max-Height * @see https://tailwindcss.com/docs/max-height */ 'max-h': [{ 'max-h': [isArbitraryValue, spacing, 'min', 'max', 'fit',