add star-blur component
This commit is contained in:
parent
36f6292873
commit
026fc2c60c
|
@ -0,0 +1,10 @@
|
||||||
|
# 0.0.1
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- add ul
|
||||||
|
- add li
|
||||||
|
- add button
|
||||||
|
- add bubble
|
||||||
|
- add indicator-page-point
|
||||||
|
- add blur
|
23
index.html
23
index.html
|
@ -3,7 +3,10 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0" />
|
<meta
|
||||||
|
name="viewport"
|
||||||
|
content="width=device-width, user-scalable=no, initial-scale=1.0"
|
||||||
|
/>
|
||||||
<title>Star Web Components</title>
|
<title>Star Web Components</title>
|
||||||
<script type="module" src="/src/index.ts"></script>
|
<script type="module" src="/src/index.ts"></script>
|
||||||
</head>
|
</head>
|
||||||
|
@ -38,6 +41,24 @@
|
||||||
--li-base-height: 43px;
|
--li-base-height: 43px;
|
||||||
--li-left-padding: 10px;
|
--li-left-padding: 10px;
|
||||||
--li-right-padding: 10px;
|
--li-right-padding: 10px;
|
||||||
|
--blur-image: '';
|
||||||
|
--blur-radius-factor: 20;
|
||||||
|
--blur-radius: calc(1px * var(--blur-radius-factor));
|
||||||
|
--blur-scale-base-factor: 1.05;
|
||||||
|
--blur-scale-factor: calc(
|
||||||
|
var(--blur-scale-base-factor) + (var(--blur-radius-factor) - 20) *
|
||||||
|
0.0025
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* for nanopcT4 */
|
||||||
|
@media (max-width: 500px) {
|
||||||
|
:root {
|
||||||
|
--blur-radius-factor: 5;
|
||||||
|
--blur-scale-factor: calc(
|
||||||
|
var(--blur-scale-base-factor) + (var(--blur-radius-factor)) * 0.005
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "start-element",
|
"name": "start-element",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.0",
|
"version": "0.0.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/my-element.es.js",
|
"main": "dist/my-element.es.js",
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
import {html, css, LitElement} from 'lit'
|
||||||
|
import {customElement, property} from 'lit/decorators.js'
|
||||||
|
import {classMap} from 'lit/directives/class-map.js'
|
||||||
|
|
||||||
|
@customElement('star-blur')
|
||||||
|
export class StarBlur extends LitElement {
|
||||||
|
@property({type: Boolean}) openblur = false
|
||||||
|
@property({type: String}) imagesrc = ''
|
||||||
|
|
||||||
|
attributeChangedCallback(name: string, _old: string | null, value: string | null): void {
|
||||||
|
super.attributeChangedCallback(name, _old, value)
|
||||||
|
|
||||||
|
if (name === 'imagesrc') {
|
||||||
|
if (!this.imagesrc) console.error('StarBlur has no imagesrc')
|
||||||
|
document.documentElement.style.setProperty('--blur-image', this.imagesrc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const styles = {
|
||||||
|
blur: this.openblur,
|
||||||
|
}
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<div id="blur-mask" class=${classMap(styles)}></div>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
static styles = css`
|
||||||
|
:host {
|
||||||
|
position: absolute;
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
#blur-mask {
|
||||||
|
position: absolute;
|
||||||
|
width: inherit;
|
||||||
|
height: inherit;
|
||||||
|
background: no-repeat center fixed;
|
||||||
|
background-size: cover;
|
||||||
|
background-image: var(--blur-image);
|
||||||
|
transform: scale(var(--blur-scale-factor));
|
||||||
|
}
|
||||||
|
#blur-mask.blur {
|
||||||
|
filter: blur(var(--blur-radius));
|
||||||
|
}
|
||||||
|
#blur-mask::before {
|
||||||
|
position: absolute;
|
||||||
|
content: ' ';
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
background: no-repeat center fixed;
|
||||||
|
background-size: cover;
|
||||||
|
background-image: var(--blur-image);
|
||||||
|
transform: scale(1 / var(--blur-scale-factor));
|
||||||
|
}
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
'star-blur': StarBlur
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
import {html, css, LitElement, TemplateResult} from 'lit'
|
||||||
|
import {customElement, state} from 'lit/decorators.js'
|
||||||
|
import '../../../components/blur/blur'
|
||||||
|
|
||||||
|
@customElement('panel-blur')
|
||||||
|
export class PanelBlur extends LitElement {
|
||||||
|
@state() openblur = false
|
||||||
|
|
||||||
|
@state() backgroundImage = ''
|
||||||
|
|
||||||
|
handleInputFile(evt: Event) {
|
||||||
|
const imgfile = (evt.target as HTMLInputElement).files?.[0]
|
||||||
|
if (imgfile) {
|
||||||
|
this.backgroundImage = `url(${URL.createObjectURL(imgfile)})`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleInputRange(evt: Event) {
|
||||||
|
document.documentElement.style.setProperty(
|
||||||
|
'--blur-radius-factor',
|
||||||
|
(evt.target as HTMLInputElement).value
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
dynamicInput(): TemplateResult {
|
||||||
|
const mql = [window.matchMedia('(max-width: 500px)')]
|
||||||
|
if (mql[0].matches) {
|
||||||
|
return html`
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min="1"
|
||||||
|
max="10"
|
||||||
|
value="5"
|
||||||
|
step="1"
|
||||||
|
@input=${this.handleInputRange}
|
||||||
|
/>
|
||||||
|
`
|
||||||
|
} else {
|
||||||
|
return html`
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min="10"
|
||||||
|
max="40"
|
||||||
|
value="10"
|
||||||
|
step="1"
|
||||||
|
@input=${this.handleInputRange}
|
||||||
|
/>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return html`
|
||||||
|
<div>
|
||||||
|
<input type="file" @change=${this.handleInputFile} />
|
||||||
|
<button @click=${() => (this.openblur = !this.openblur)}>
|
||||||
|
toggle blur
|
||||||
|
</button>
|
||||||
|
${this.dynamicInput()}
|
||||||
|
</div>
|
||||||
|
<star-blur
|
||||||
|
?openblur=${this.openblur}
|
||||||
|
imagesrc=${this.backgroundImage}
|
||||||
|
></star-blur>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
static styles = css`
|
||||||
|
div {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
'panel-blur': PanelBlur
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ import './about/about'
|
||||||
import './icon/icon'
|
import './icon/icon'
|
||||||
import './general/general'
|
import './general/general'
|
||||||
import './indicators/indicators'
|
import './indicators/indicators'
|
||||||
|
import './blur/use-blur'
|
||||||
|
|
||||||
type SEID = String
|
type SEID = String
|
||||||
|
|
||||||
|
@ -117,10 +118,10 @@ export class PanelRoot extends LitElement {
|
||||||
<hr />
|
<hr />
|
||||||
<star-li
|
<star-li
|
||||||
type=${LiType.ICON_LABEL}
|
type=${LiType.ICON_LABEL}
|
||||||
label="成就"
|
label="毛玻璃"
|
||||||
icon="achievement"
|
icon="achievement"
|
||||||
iconcolor="gold"
|
iconcolor="gold"
|
||||||
href="#about"
|
href="#blur"
|
||||||
></star-li>
|
></star-li>
|
||||||
<hr />
|
<hr />
|
||||||
<star-li
|
<star-li
|
||||||
|
|
Loading…
Reference in New Issue