feat: enhance CSS handling and optimize global styles

- Enabled PostCSS nesting with specific configuration for modern compatibility
- Added global CSS reset for consistent tap highlights across browsers
- Optimized package configuration for broader browser support
- Refactored and streamlined global CSS, removing redundant styles for better maintainability
- Integrated additional CSS import in component for modular styling approach
This commit is contained in:
ccbikai
2024-08-06 19:02:56 +08:00
parent a1b7f80017
commit bd7bba2f06
6 changed files with 234 additions and 197 deletions

View File

@@ -47,5 +47,8 @@
},
"lint-staged": {
"*": "eslint --fix"
}
},
"browserslist": [
"defaults"
]
}

View File

@@ -1,6 +1,9 @@
module.exports = {
plugins: [
// require('postcss-nesting'),
require('postcss-nesting')({
edition: '2021',
noIsPseudoSelector: true,
}),
require('autoprefixer'),
require('cssnano'),
],

View File

@@ -1,3 +1,7 @@
* {
-webkit-tap-highlight-color: transparent;
}
.site-title {
view-transition-name: site-title;
transition: 0.2s ease;
@@ -7,55 +11,6 @@
transition: 0.2s ease;
}
[popover] {
display: none;
&:popover-open {
display: block;
}
}
.image-preview-wrap {
display: block;
}
.image-preview-button {
-webkit-appearance: none;
outline: none;
border: none;
background: transparent;
padding: 0;
margin-bottom: 16px;
}
.modal {
position: fixed;
top: 0px;
left: 0px;
z-index: 1000;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
backdrop-filter: blur(20px);
}
.modal-img {
margin: auto;
max-width: calc(100% - 40px) !important;
max-height: calc(100% - 40px) !important;
border-radius: var(--media-border-radius);
border: 1px solid var(--border-color);
box-shadow: var(--shadows);
cursor: pointer;
object-fit: scale-down;
}
@media screen and (min-width: 600px) {
.modal-img {
max-width: calc(100% - 80px) !important;
max-height: calc(100% - 80px) !important;
}
}
.search-icon {
position: absolute;
top: 20px;
@@ -63,8 +18,10 @@
width: 24px;
height: 24px;
padding: 4px;
appearance: none;
outline: none;
&::after {
&:after {
content: '🔍';
width: 100%;
height: 100%;
@@ -81,6 +38,7 @@
.search-icon:checked + .search-form {
display: block !important;
}
.search-form {
display: none;
background: rgba(255, 255, 255, 0.75);

208
src/assets/item.css Normal file
View File

@@ -0,0 +1,208 @@
.content {
word-break: break-word;
img {
width: calc(100% - var(--box-margin));
}
.tgme_widget_message_link_preview {
margin-top: 16px;
display: none;
.link_preview_site_name,
.link_preview_title,
.link_preview_description {
display: none;
}
}
.tgme_widget_message_link_preview:has(.link_preview_site_name) {
display: block;
background: var(--cell-background-color);
border-left: 3px solid var(--highlight-color);
padding: 6px;
padding-left: 10px;
border-radius: var(--box-border-radius);
.link_preview_title {
display: block;
font-size: 1em;
font-weight: bolder;
line-height: 2;
}
.link_preview_description {
display: block;
font-size: 0.8em;
line-height: 1.5;
}
}
.tgme_widget_message_video,
.tgme_widget_message_roundvideo {
aspect-ratio: 1 / 1;
}
.tgme_widget_message_link_preview:has(.link_preview_image) {
display: flex;
position: relative;
border: none;
padding: 0;
background: transparent;
.link_preview_image {
aspect-ratio: 1200 / 630;
object-fit: cover;
}
.link_preview_site_name {
display: block;
position: absolute;
bottom: var(--box-margin);
left: var(--box-margin);
padding-left: 4px;
padding-right: 4px;
background-color: rgba(0, 0, 0, 0.66);
font-size: 14px;
color: #fff;
line-height: 1.5;
border-radius: var(--box-border-radius);
text-overflow: ellipsis;
max-width: calc(100% - 28px);
white-space: nowrap;
overflow: hidden;
}
.link_preview_title,
.link_preview_description {
display: none;
}
}
blockquote {
margin: 16px 0;
font-size: 0.8em;
background: var(--cell-background-color);
border-left: 3px solid var(--highlight-color);
padding: 6px;
padding-left: 10px;
border-radius: var(--box-border-radius);
}
.tgme_widget_message_sticker {
display: block;
}
&:has(.tgme_widget_message_user_photo) {
display: flex;
.tgme_widget_message_user_photo {
width: 60px;
height: 60px;
}
}
.tgme_widget_message_voice {
display: block !important;
}
.tgme_widget_message_poll_options {
display: block;
.tgme_widget_message_poll_option_percent {
float: left;
margin-right: 8px;
}
}
.tgme_widget_message_location_wrap {
display: block;
.tgme_widget_message_location {
padding-top: 50%;
background: no-repeat center;
background-size: cover;
}
}
.emoji {
font-style: normal;
margin-right: 2px;
}
.sticker {
box-shadow: none;
border: none;
}
.spoiler-button {
cursor: pointer;
input {
display: none;
}
tg-spoiler {
color: #ccc;
background: repeating-conic-gradient(#000 0 0.0001%, #0000 0 0.0002%) 60%
60% / 3000px 3000px;
}
input:checked + tg-spoiler {
background: unset;
color: unset;
}
}
}
.tag-box {
flex-wrap: wrap;
}
[popover] {
display: none;
&:popover-open {
display: block;
}
}
.image-preview-wrap {
display: block;
}
.image-preview-button {
appearance: none;
outline: none;
border: none;
background: transparent;
padding: 0;
margin-bottom: 16px;
}
.modal {
position: fixed;
top: 0px;
left: 0px;
z-index: 1000;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
backdrop-filter: blur(20px);
}
.modal-img {
margin: auto;
max-width: calc(100% - 40px) !important;
max-height: calc(100% - 40px) !important;
border-radius: var(--media-border-radius);
border: 1px solid var(--border-color);
box-shadow: var(--shadows);
cursor: pointer;
object-fit: scale-down;
}
@media screen and (min-width: 600px) {
.modal-img {
max-width: calc(100% - 80px) !important;
max-height: calc(100% - 80px) !important;
}
}

View File

@@ -1,4 +1,5 @@
---
import '../assets/item.css'
import dayjs from '../lib/dayjs'
import { getEnv } from '../lib/env'
@@ -48,145 +49,3 @@ const timeago = datetime.isBefore(dayjs().subtract(1, 'w'))
)
}
</div>
<style>
.content {
word-break: break-word;
}
.content :global(img) {
width: calc(100% - var(--box-margin));
}
.content :global(.tgme_widget_message_link_preview) {
margin-top: 16px;
display: none;
.link_preview_site_name,
.link_preview_title,
.link_preview_description {
display: none;
}
}
.content
:global(.tgme_widget_message_link_preview):has(.link_preview_site_name) {
display: block;
background: var(--cell-background-color);
border-left: 3px solid var(--highlight-color);
padding: 6px;
padding-left: 10px;
border-radius: var(--box-border-radius);
.link_preview_title {
display: block;
font-size: 1em;
font-weight: bolder;
line-height: 2;
}
.link_preview_description {
display: block;
font-size: 0.8em;
line-height: 1.5;
}
}
.content
:global(.tgme_widget_message_video, .tgme_widget_message_roundvideo) {
aspect-ratio: 1 / 1;
}
.content :global(.tgme_widget_message_link_preview):has(.link_preview_image) {
display: flex;
position: relative;
border: none;
padding: 0;
background: transparent;
.link_preview_image {
aspect-ratio: 1200 / 630;
object-fit: cover;
}
.link_preview_site_name {
display: block;
position: absolute;
bottom: var(--box-margin);
left: var(--box-margin);
padding-left: 4px;
padding-right: 4px;
background-color: rgba(0, 0, 0, 0.66);
font-size: 14px;
color: #fff;
line-height: 1.5;
border-radius: var(--box-border-radius);
text-overflow: ellipsis;
max-width: calc(100% - 28px);
white-space: nowrap;
overflow: hidden;
}
.link_preview_title,
.link_preview_description {
display: none;
}
}
.content :global(blockquote) {
margin: 16px 0;
font-size: 0.8em;
background: var(--cell-background-color);
border-left: 3px solid var(--highlight-color);
padding: 6px;
padding-left: 10px;
border-radius: var(--box-border-radius);
}
.content :global(.tgme_widget_message_sticker) {
display: block;
}
.item :global(.content):has(.tgme_widget_message_user_photo) {
display: flex;
.tgme_widget_message_user_photo {
width: 60px;
height: 60px;
}
}
.content :global(.tgme_widget_message_voice) {
display: block !important;
}
.content :global(.tgme_widget_message_poll_options) {
display: block;
.tgme_widget_message_poll_option_percent {
float: left;
margin-right: 8px;
}
}
.content :global(.tgme_widget_message_location_wrap) {
display: block;
.tgme_widget_message_location {
padding-top: 50%;
background: no-repeat center;
background-size: cover;
}
}
.content :global(.emoji) {
font-style: normal;
margin-right: 2px;
}
.content :global(.sticker) {
box-shadow: none;
border: none;
}
.tag-box {
flex-wrap: wrap;
}
</style>

View File

@@ -76,17 +76,23 @@ function getLinkPreview($, item, { staticProxy, index }) {
return $.html(link)
}
function modifyHTMLContent($, content) {
function modifyHTMLContent($, content, { index } = {}) {
$(content).find('.emoji')?.attr('style', '')
$(content).find('a')?.each((_index, a) => {
$(a)?.attr('title', $(a)?.text())
})
$(content).find('.emoji')?.attr('style', '')
$(content).find('tg-spoiler')?.each((_index, spoiler) => {
const id = `spoiler-${index}-${_index}`
$(spoiler)?.attr('id', id)
?.wrap('<label class="spoiler-button"></label>')
?.before(`<input type="checkbox" />`)
})
return content
}
function getPost($, item, { channel, staticProxy, index = 0 }) {
item = item ? $(item).find('.tgme_widget_message') : $('.tgme_widget_message')
const content = modifyHTMLContent($, $(item).find('.tgme_widget_message_text'))
const content = modifyHTMLContent($, $(item).find('.tgme_widget_message_text'), { index })
const title = content?.text()?.match(/[^。\n]*(?=[。\n]|http)/g)?.[0] ?? content?.text() ?? ''
const id = $(item).attr('data-post')?.replace(`${channel}/`, '')