|
| 1 | +<template> |
| 2 | + <table class="min-w-full divide-y divide-light"> |
| 3 | + <tr class=""> |
| 4 | + <th class="text-left rtl:text-right">Variable</th> |
| 5 | + <th class="px-2 text-left rtl:text-right">Value</th> |
| 6 | + </tr> |
| 7 | + <tr v-for="(variable, index) in cssVariables" :key="index"> |
| 8 | + <td class="whitespace-nowrap rtl:text-right" dir="ltr"> |
| 9 | + {{ variable.name }} |
| 10 | + </td> |
| 11 | + <td class="inline-flex p-2"> |
| 12 | + <div |
| 13 | + v-if="variable.styles" |
| 14 | + class="h-6 w-6" |
| 15 | + :style="variable.styles" |
| 16 | + ></div> |
| 17 | + <span class="px-1" dir="ltr">{{ variable.value }}</span> |
| 18 | + </td> |
| 19 | + </tr> |
| 20 | + </table> |
| 21 | +</template> |
| 22 | + |
| 23 | +<script setup> |
| 24 | +import {ref, onMounted} from 'vue'; |
| 25 | +
|
| 26 | +const cssVariables = ref([]); |
| 27 | +
|
| 28 | +onMounted(() => { |
| 29 | + const vars = []; |
| 30 | +
|
| 31 | + for (const sheet of document.styleSheets) { |
| 32 | + try { |
| 33 | + for (const rule of sheet.cssRules) { |
| 34 | + if (rule.style) { |
| 35 | + let primaryColor; |
| 36 | + for (let i = 0; i < rule.style.length; i++) { |
| 37 | + const prop = rule.style[i]; |
| 38 | + if (prop.startsWith('--') && !prop.startsWith('--tw')) { |
| 39 | + const value = rule.style.getPropertyValue(prop).trim(); |
| 40 | +
|
| 41 | + if (prop === '--background-color-primary') { |
| 42 | + primaryColor = value; |
| 43 | + } |
| 44 | + let styles; |
| 45 | + if (prop.includes('color')) { |
| 46 | + styles = { |
| 47 | + backgroundColor: value, |
| 48 | + }; |
| 49 | + } else if (prop.includes('shadow')) { |
| 50 | + styles = { |
| 51 | + boxShadow: value, |
| 52 | + borderRadius: '1px', |
| 53 | + }; |
| 54 | + } else if (prop.includes('radius')) { |
| 55 | + styles = { |
| 56 | + backgroundColor: primaryColor, |
| 57 | + borderRadius: value, |
| 58 | + }; |
| 59 | + } |
| 60 | +
|
| 61 | + vars.push({ |
| 62 | + name: prop, |
| 63 | + value, |
| 64 | + styles, |
| 65 | + }); |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + } catch (error) { |
| 71 | + console.warn('Cannot get all the stylesheets on the page.', error); |
| 72 | + } |
| 73 | + } |
| 74 | +
|
| 75 | + cssVariables.value = vars; |
| 76 | +}); |
| 77 | +</script> |
0 commit comments