UNPKG

@spaced-out/ui-design-system

Version:
165 lines (161 loc) β€’ 11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleDownload = exports.getSortedTokenNames = exports.getRandomDataVariation = exports.filterTableDataBySearchText = exports.dataVariations = void 0; const dataVariations = exports.dataVariations = [{ title: 'The Great HTML Escape 🎩🌐', description: 'Watch out! Our HTML has escaped and is running wild on the web. It\'s causing mischief, adding tags and styles wherever it pleases! <div>πŸ™ˆ</div>' }, { title: 'The CSS Enigma πŸ”πŸ’‘', description: 'Behold the CSS enigma! Our styles have tangled themselves into a web of complexity. Can you decipher the mystery and bring order to the chaos? πŸ’»πŸŽ¨' }, { title: 'The Missing Dependency πŸ˜±πŸ“¦', description: 'Uh-oh! It seems like a crucial frontend dependency went on a vacation and forgot to come back. Without it, our application feels a bit incomplete. We\'re on the lookout for its grand return! πŸ–οΈπŸŒ΄' }, { title: 'The Vanishing CSS Rule πŸ™€πŸŽ©', description: 'Hocus pocus! A CSS rule vanished into thin air, leaving our styles in a state of bewilderment. We\'re summoning all our magical powers to bring it back. Abracadabra, where did it go? πŸ§™β€β™‚οΈβœ¨' }, { title: 'The Mysterious JavaScript Bug πŸžβ“', description: 'We\'ve encountered a puzzling JavaScript bug that seems to have hidden itself in the shadows of our codebase. It\'s playing hide-and-seek, but fear not! We\'ll track it down and restore order to our application. πŸ”πŸ”¦' }, { title: 'The Lost Code Snippet πŸ§πŸ”', description: 'Oh no! It appears that a valuable code snippet has gone missing, leaving us scratching our heads. We\'re combing through the archives and retracing our steps to recover it. We won\'t stop until it\'s back where it belongs! πŸ•΅οΈβ€β™‚οΈπŸ”Ž' }, { title: 'The Hidden API Endpoint πŸ•΅οΈβ€β™€οΈπŸ”', description: 'We\'re on a mission to find an elusive API endpoint that seems to have vanished into the depths of the backend. We\'re following the clues, decoding cryptic messages, and hacking our way through the digital maze. Stay tuned for its triumphant rediscovery! πŸš€πŸŒ' }, { title: 'The Ghostly UI Element πŸ‘»πŸ‘οΈ', description: 'Beware of the ghostly UI element! It has mysteriously disappeared from our interface, leaving behind an empty void. We\'ve dispatched our best designers to investigate and resurrect it. Soon, it\'ll return to haunt the pixels once again! πŸŽƒπŸ’»' }, { title: 'The Evaporating Stylesheet πŸ’¦πŸŽ¨', description: 'Uh-oh! It seems like our stylesheet got caught in a cosmic evaporation event, and now our carefully crafted styles are floating in the digital ether. We\'re working on a rescue mission to bring them back to the realm of the browser. βœ¨πŸš€' }, { title: 'The Missing Feature Fairy 🧚✨', description: 'We\'ve sent out an APB (All Points Bulletin) for the missing feature fairy. She\'s known for sprinkling delightful functionalities into our applications, but it seems she took a detour. We\'re patiently waiting for her magical return! πŸŒŸπŸ§šβ€β™€οΈ' }, { title: 'The Invisible DOM Element πŸ™ˆπŸŒ', description: 'Something peculiar has happened! A DOM element has turned invisible, playing tricks on our frontend. We\'ve called in our best detectives to investigate this optical illusion and restore its rightful visibility. Stay tuned for the grand unveiling! πŸ‘€βœ¨' }, { title: 'The Elusive Frontend Bug πŸ›β“', description: 'Our frontend bug seems to have gained a PhD in camouflage and disappeared into the code jungle. We\'re conducting bug-hunting expeditions, armed with magnifying glasses and a good sense of humor. It won\'t escape our watchful eyes for long! πŸ•΅οΈβ€β™€οΈπŸ”' }, { title: 'The Abducted Animation πŸŒͺ️πŸŽ₯', description: 'Alert! An animation has been abducted from our frontend, leaving us with static screens. We suspect interdimensional interference. We\'re assembling a rescue team armed with keyframes and transition effects. Together, we\'ll bring motion back to our digital world! ⚑️🎬' }, { title: 'The Disappearing Click Event πŸ™€πŸ–±οΈ', description: 'In a twist of events, a click event has mysteriously vanished, eluding our attempts to capture it. We\'ve set up mouse traps and deployed debugging tools to solve this enigma. Don\'t worry, we\'ll catch that sneaky click and restore its functionality! πŸ”πŸ”§' }, { title: 'The Phantom Mobile Responsiveness πŸ‘»πŸ“±', description: 'Beware of the phantom mobile responsiveness! It likes to hide in the shadows, making our web pages look like a ghost town on small screens. We\'re summoning our media queries and responsive design tactics to banish this spectral issue. Soon, our pages will be mobile-friendly once more! πŸ“²πŸ’ͺ' }, { title: 'The Misplaced UI Element πŸ§­πŸ”„', description: 'Oops! It seems like a UI element lost its way and ended up in the wrong place. We\'re guiding it back to its rightful position with pixel-perfect precision. Soon, order will be restored, and our interface will be back in balance! πŸ—ΊοΈπŸ”€' }, { title: 'The Cryptic JavaScript Error πŸ”β“', description: 'We\'ve stumbled upon a cryptic JavaScript error that speaks in riddles, leaving us scratching our heads. Fear not, our code sorcerers are deciphering the error message, searching for the hidden clues to resolve this enigmatic mystery. βœ¨πŸ”' }, { title: 'The Broken CSS Grid πŸ“πŸ”©', description: 'Oh no! Our CSS grid has sprung a leak and lost its structure. We\'re patching it up with grid areas and grid-template-areas to bring order back to the layout. Soon, the grid will stand strong and proud! πŸ§°πŸ”§' }, { title: 'The Disappearing Web Fonts πŸ™ˆπŸ–ŠοΈ', description: 'Web fonts have vanished without a trace, leaving our text looking plain and dull. We\'re calling in the font detectives to investigate this typographic disappearance. We won\'t rest until our words are dressed in style once again! πŸ‘“πŸ”Ž' }, { title: 'The Forgotten Vendor Prefixes πŸ€”πŸ”', description: 'Oops! It seems that some vendor prefixes got lost in the shuffle, leaving our CSS properties puzzled. We\'re on a mission to rediscover these elusive prefixes and ensure our styles are cross-browser compatible. Together, we\'ll navigate the prefix labyrinth and emerge victorious! πŸ’ͺπŸš€' }, { title: 'The Invisible API Response πŸ™ˆπŸ“‘', description: 'We\'re experiencing an API response that\'s mastered the art of invisibility. It\'s hiding behind layers of middleware and network protocols. We\'ve enlisted our finest backend wizards to conjure it back into visibility. Be patient, and soon the data will reappear like magic! πŸ§™β€β™‚οΈβœ¨' }]; /** * * This function takes in an object containing key-value pairs of tokens, * where values are strings representing numerical * values with optional percentage or viewport units. It also takes in an optional * sort order ('asc' or 'desc') and an optional sort by parameter ('name' or 'value'). * * The function sorts the tokens by either their key names (if sortBy='name') or their * numerical values (if sortBy='value'). The sort order can be specified as * ascending (order='asc') or descending (order='desc'). * * The function handles values with different units by comparing their numerical values. * If both values have the same unit, their numerical values are compared directly. * If their units are different, tokens with percentage values are considered greater than * those with viewport units, and tokens without a percentage or viewport unit are compared * based on their numerical values. * */ const getSortedTokenNames = function (obj) { let order = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'asc'; let sortBy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'value'; // Create an array from the object keys and sort the array const sortedTokens = Object.keys(obj).sort((token1, token2) => { const value1 = obj[token1]; const value2 = obj[token2]; // Convert value1 to a number const numValue1 = parseFloat(value1); // Convert value2 to a number const numValue2 = parseFloat(value2); if (sortBy === 'name') { // Sorting by name return order === 'asc' ? token1.localeCompare(token2) // Compare key names directly : token2.localeCompare(token1); } else { const isPercentage1 = value1.endsWith('%'); const isPercentage2 = value2.endsWith('%'); const isViewport1 = value1.endsWith('vw') || value1.endsWith('vh'); const isViewport2 = value2.endsWith('vw') || value2.endsWith('vh'); if (isPercentage1 && isPercentage2 || isViewport1 && isViewport2) { // If both tokens have the same unit (percentage or viewport), compare their numerical values return order === 'asc' ? numValue1 - numValue2 : numValue2 - numValue1; } if (isPercentage1 && !isPercentage2) { // Only token1 has a percentage value, consider it greater than token2 return order === 'asc' ? 1 : -1; } if (!isPercentage1 && isPercentage2) { // Only token2 has a percentage value, consider it greater than token1 return order === 'asc' ? -1 : 1; } if (isViewport1 && !isViewport2) { // Only token1 has a viewport unit value, consider it greater than token2 return order === 'asc' ? 1 : -1; } if (!isViewport1 && isViewport2) { // Only token2 has a viewport unit value, consider it greater than token1 return order === 'asc' ? -1 : 1; } // Neither token has a percentage or viewport unit value, compare their numerical values return order === 'asc' ? numValue1 - numValue2 : numValue2 - numValue1; } }); return sortedTokens; }; exports.getSortedTokenNames = getSortedTokenNames; const filterTableDataBySearchText = (TABLE_DATA, searchText) => { const filteredData = TABLE_DATA.filter(item => { const nameMatch = item.name.toLowerCase().includes(searchText.toLowerCase()); const valueMatch = item.value.toLowerCase().includes(searchText.toLowerCase()); return nameMatch || valueMatch; }); return filteredData; }; exports.filterTableDataBySearchText = filterTableDataBySearchText; const getRandomDataVariation = () => { const randomIndex = Math.floor(Math.random() * dataVariations.length); return dataVariations[randomIndex]; }; exports.getRandomDataVariation = getRandomDataVariation; const handleDownload = (filePath, fileName) => { fetch(filePath).then(response => response.blob()).then(blob => { const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = fileName; link.click(); URL.revokeObjectURL(url); }).catch(error => { console.error('Error downloading the JSON file:', error); }); }; exports.handleDownload = handleDownload;