-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
105 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { getDefaultStyle } from './get-default-style' | ||
import { uuid } from './utils' | ||
import type { Context } from './context' | ||
|
||
const ignoredStyles = [ | ||
'content', | ||
'-webkit-locale', | ||
] | ||
|
||
const pseudoClasses = [ | ||
':before', | ||
':after', | ||
':-webkit-scrollbar', | ||
':-webkit-scrollbar-button', | ||
// ':-webkit-scrollbar:horizontal', TODO | ||
':-webkit-scrollbar-thumb', | ||
':-webkit-scrollbar-track', | ||
':-webkit-scrollbar-track-piece', | ||
// ':-webkit-scrollbar:vertical', TODO | ||
':-webkit-scrollbar-corner', | ||
':-webkit-resizer', | ||
] | ||
|
||
export function copyPseudoClass<T extends HTMLElement | SVGElement>( | ||
node: T, | ||
cloned: T, | ||
context: Context, | ||
) { | ||
const { ownerDocument, ownerWindow, svgStyleElement } = context | ||
|
||
if (!svgStyleElement || !ownerDocument || !ownerWindow) return | ||
|
||
pseudoClasses.forEach(pseudoClass => { | ||
const style = ownerWindow.getComputedStyle(node, pseudoClass) | ||
const content = style.getPropertyValue('content') | ||
if (!content || content === 'none') return | ||
const klasses = [uuid()] | ||
const defaultStyle = getDefaultStyle(node.tagName, pseudoClass, context) | ||
const cloneStyle = [ | ||
`content: '${ content.replace(/'|"/g, '') }';`, | ||
] | ||
for (let i = style.length - 1; i >= 0; i--) { | ||
const name = style.item(i) | ||
if (ignoredStyles.includes(name)) continue | ||
const value = style.getPropertyValue(name) | ||
const priority = style.getPropertyPriority(name) | ||
// fix background-clip: text | ||
if (name === 'background-clip' && value === 'text') { | ||
klasses.push(' ______background-clip--text') | ||
} | ||
// Skip default style | ||
if (defaultStyle[name] === value && !priority) continue | ||
cloneStyle.push(`${ name }: ${ value }${ priority ? ' !important' : '' };`) | ||
} | ||
if (cloneStyle.length === 1) return | ||
try { | ||
(cloned as any).className += ` ${ klasses.join(' ') }` | ||
} catch (err) { | ||
return | ||
} | ||
svgStyleElement.appendChild( | ||
ownerDocument.createTextNode(`.${ klasses[0] }:${ pseudoClass } {\n ${ cloneStyle.join('\n ') }\n}\n`), | ||
) | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<style> | ||
.scrollbar { | ||
display: block; | ||
width: 10em; | ||
overflow: auto; | ||
height: 2em; | ||
} | ||
|
||
/* Demonstrate a "mostly customized" scrollbar | ||
* (won't be visible otherwise if width/height is specified) */ | ||
.scrollbar::-webkit-scrollbar { | ||
width: 5px; | ||
height: 8px; | ||
background-color: #aaa; /* or add it to the track */ | ||
} | ||
|
||
/* Add a thumb */ | ||
.scrollbar::-webkit-scrollbar-thumb { | ||
background: #000; | ||
} | ||
</style> | ||
|
||
<template> | ||
<div id="root" class="scrollbar"> | ||
Thisisaveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerylongword<br /> | ||
And pretty tall<br /> | ||
thing with weird scrollbars.<br /> | ||
Who thought scrollbars could be made weird? | ||
</div> | ||
</template> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
0a3bfe3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
modern-screenshot – ./
modern-screenshot-qq15725.vercel.app
modern-screenshot.vercel.app
modern-screenshot-git-main-qq15725.vercel.app