mirror of
https://github.com/home-assistant/frontend.git
synced 2026-12-04 10:40:30 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd87f0fd2d |
No files matched your search
@@ -18,7 +18,6 @@ export const coverDrawingStyles = css`
|
||||
--cover-drawing-lift: #f5f5f5;
|
||||
--cover-drawing-stripe: #ffffff;
|
||||
--cover-drawing-slot: #cfe8fb;
|
||||
--cover-drawing-ghost: #e1e1e1;
|
||||
--cover-drawing-metal: #6f7a84;
|
||||
--cover-drawing-grass-top: #a8d49a;
|
||||
--cover-drawing-grass-bottom: #7fb071;
|
||||
@@ -39,7 +38,6 @@ export const coverDrawingStyles = css`
|
||||
--cover-drawing-lift: #6e757e;
|
||||
--cover-drawing-stripe: #676e78;
|
||||
--cover-drawing-slot: #3b5f96;
|
||||
--cover-drawing-ghost: #9aa3ad;
|
||||
--cover-drawing-metal: #9aa5b0;
|
||||
--cover-drawing-grass-top: #3f6b45;
|
||||
--cover-drawing-grass-bottom: #2b4a31;
|
||||
@@ -106,9 +104,6 @@ export const coverDrawingStyles = css`
|
||||
.panel-shadow {
|
||||
fill: #000;
|
||||
}
|
||||
.ghost {
|
||||
fill: var(--cover-drawing-ghost);
|
||||
}
|
||||
.target-line {
|
||||
fill: none;
|
||||
stroke: var(--cover-drawing-handle);
|
||||
|
||||
@@ -51,6 +51,8 @@ import { WaveMotion } from "./wave";
|
||||
|
||||
type HandleMotion = "follow" | "drag" | "swipe" | "request" | "return";
|
||||
|
||||
type DrawnMotion = "follow" | "drag" | "return";
|
||||
|
||||
type ModeSprings = Record<CoverControlMode, PercentSpring>;
|
||||
|
||||
type ModeMotions = Record<CoverControlMode, HandleMotion>;
|
||||
@@ -138,6 +140,10 @@ export class HaStateControlCover extends LitElement {
|
||||
|
||||
private _handleSprings = modeSprings();
|
||||
|
||||
private _drawnPosition = new PercentSpring();
|
||||
|
||||
private _drawnMotion: DrawnMotion = "follow";
|
||||
|
||||
private _handleMotions = modeMotions();
|
||||
|
||||
private _wave = new WaveMotion();
|
||||
@@ -187,6 +193,8 @@ export class HaStateControlCover extends LitElement {
|
||||
this._coverSprings[mode].jumpTo(value);
|
||||
this._handleSprings[mode].jumpTo(value);
|
||||
}
|
||||
this._drawnPosition.jumpTo(this._coverSprings.position.value);
|
||||
this._drawnMotion = "follow";
|
||||
this._handleMotions = modeMotions();
|
||||
this._wave.reset(this._coverSprings.position.value);
|
||||
}
|
||||
@@ -268,6 +276,7 @@ export class HaStateControlCover extends LitElement {
|
||||
changed = this._moveSpring(this._coverSprings[mode], goal, dt) || changed;
|
||||
changed = this._moveHandle(mode, dt) || changed;
|
||||
}
|
||||
changed = this._moveDrawnPosition(dt) || changed;
|
||||
if (this._shape.usesWave) {
|
||||
changed = this._moveWave(dt) || changed;
|
||||
}
|
||||
@@ -277,6 +286,34 @@ export class HaStateControlCover extends LitElement {
|
||||
}
|
||||
};
|
||||
|
||||
private _nextDrawnMotion(): DrawnMotion {
|
||||
if (this._drag && this.mode === "position") {
|
||||
return "drag";
|
||||
}
|
||||
const afterDrag = this._drawnMotion !== "follow";
|
||||
const distance = Math.abs(
|
||||
this._drawnPosition.value - this._coverSprings.position.value
|
||||
);
|
||||
if (afterDrag && distance > 0.5) {
|
||||
return "return";
|
||||
}
|
||||
return "follow";
|
||||
}
|
||||
|
||||
private _moveDrawnPosition(dt: number): boolean {
|
||||
const drawn = this._drawnPosition;
|
||||
const cover = this._coverSprings.position.value;
|
||||
this._drawnMotion = this._nextDrawnMotion();
|
||||
switch (this._drawnMotion) {
|
||||
case "drag":
|
||||
return drawn.jumpTo(this._handleSprings.position.value);
|
||||
case "return":
|
||||
return this._moveSpring(drawn, cover, dt, RETURN_SPRING);
|
||||
default:
|
||||
return drawn.jumpTo(cover);
|
||||
}
|
||||
}
|
||||
|
||||
private _moveSpring(
|
||||
spring: PercentSpring,
|
||||
goal: number,
|
||||
@@ -630,11 +667,11 @@ export class HaStateControlCover extends LitElement {
|
||||
);
|
||||
}
|
||||
|
||||
private _renderTarget(shape: CoverShape, value: number) {
|
||||
return svg`
|
||||
${shape.targetShape?.(value) ?? nothing}
|
||||
${shape.targetLine ? svg`<path class="target-line" d=${shape.targetLine(value)}></path>` : nothing}
|
||||
`;
|
||||
private _renderTargetLine(shape: CoverShape, value: number) {
|
||||
if (!shape.targetLine) {
|
||||
return nothing;
|
||||
}
|
||||
return svg`<path class="target-line" d=${shape.targetLine(value)}></path>`;
|
||||
}
|
||||
|
||||
private _renderHandle(shape: CoverShape, value: number) {
|
||||
@@ -709,7 +746,7 @@ export class HaStateControlCover extends LitElement {
|
||||
const withHandle = interactive && (!unknown || changing);
|
||||
const withTarget = changing && (unknown || Math.abs(handle - cover) > 1);
|
||||
const parts = shape.render({
|
||||
position: this._coverSprings.position.value,
|
||||
position: this._drawnPosition.value,
|
||||
tiltOpenness: this._drawnTiltOpenness(),
|
||||
wave: this._wave,
|
||||
});
|
||||
@@ -754,8 +791,9 @@ export class HaStateControlCover extends LitElement {
|
||||
>
|
||||
<g clip-path="url(#opening-clip)">
|
||||
${this._renderSky()} ${parts.back ?? nothing}
|
||||
${unknown ? nothing : parts.cover} ${parts.front ?? nothing}
|
||||
${withTarget ? this._renderTarget(shape, handle) : nothing}
|
||||
${unknown && this._drawnMotion === "follow" ? nothing : parts.cover}
|
||||
${parts.front ?? nothing}
|
||||
${withTarget ? this._renderTargetLine(shape, handle) : nothing}
|
||||
</g>
|
||||
<rect
|
||||
class="opening-edge"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { svg } from "lit";
|
||||
import type { CoverShape } from "./shared";
|
||||
import { FRAME, ghost, headrail, valueAxis } from "./shared";
|
||||
import { FRAME, headrail, valueAxis } from "./shared";
|
||||
|
||||
const SCALLOPS = 8;
|
||||
const SCALLOP_WIDTH = FRAME.width / SCALLOPS;
|
||||
@@ -44,5 +44,4 @@ export const awningShape: CoverShape = {
|
||||
const bottom = hemY(value);
|
||||
return `M${FRAME.right},${bottom}${scallops(bottom)}`;
|
||||
},
|
||||
targetShape: (value) => ghost(svg`<path d=${outline(hemY(value))}></path>`),
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import { svg } from "lit";
|
||||
import { clamp } from "../../../common/number/clamp";
|
||||
import type { CoverShape } from "./shared";
|
||||
import { FRAME, ghost, headrail, valueAxis } from "./shared";
|
||||
import { FRAME, headrail, valueAxis } from "./shared";
|
||||
|
||||
const GATHERED = 22;
|
||||
const ROWS = 12;
|
||||
@@ -103,8 +103,4 @@ export const curtainShape: CoverShape = {
|
||||
valueAt: (x) => freeEdge.valueAt(x),
|
||||
targetLine: (value) =>
|
||||
`M${freeEdge.coordAt(value).toFixed(1)} ${FRAME.top} V${FRAME.bottom}`,
|
||||
targetShape: (value) =>
|
||||
ghost(
|
||||
svg`<rect x=${FRAME.left} y=${FRAME.top} width=${(freeEdge.coordAt(value) - FRAME.left).toFixed(1)} height=${FRAME.height}></rect>`
|
||||
),
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { SVGTemplateResult } from "lit";
|
||||
import { svg } from "lit";
|
||||
import type { CoverShape } from "./shared";
|
||||
import { FRAME, ghost, headrail, horizontalLine, valueAxis } from "./shared";
|
||||
import { FRAME, headrail, horizontalLine, valueAxis } from "./shared";
|
||||
|
||||
const HEADRAIL = 10.4;
|
||||
const ROLL = 10;
|
||||
@@ -17,16 +17,12 @@ const handleY = (value: number) => coverBottom.coordAt(value) - HANDLE_INSET;
|
||||
|
||||
export const rollingGeometry: Pick<
|
||||
CoverShape,
|
||||
"opens" | "handleAt" | "valueAt" | "targetLine" | "targetShape"
|
||||
"opens" | "handleAt" | "valueAt" | "targetLine"
|
||||
> = {
|
||||
opens: "up",
|
||||
handleAt: (value) => [FRAME.centerX, handleY(value)],
|
||||
valueAt: (_x, y) => coverBottom.valueAt(y + HANDLE_INSET),
|
||||
targetLine: (value) => horizontalLine(handleY(value)),
|
||||
targetShape: (value) =>
|
||||
ghost(
|
||||
svg`<rect x=${FRAME.left} y=${FRAME.top} width=${FRAME.width} height=${(coverBottom.coordAt(value) - FRAME.top).toFixed(1)}></rect>`
|
||||
),
|
||||
};
|
||||
|
||||
const fabric = (bottom: number) =>
|
||||
|
||||
@@ -44,7 +44,6 @@ export interface CoverShape {
|
||||
handleAt(value: number): [number, number];
|
||||
valueAt(x: number, y: number): number;
|
||||
targetLine?(value: number): string;
|
||||
targetShape?(value: number): SVGTemplateResult;
|
||||
}
|
||||
|
||||
export const isHorizontal = (shape: CoverShape) => shape.opens === "left";
|
||||
@@ -68,9 +67,6 @@ export const tiltGeometry: Pick<
|
||||
valueAt: (_x, y) => tiltAxis.valueAt(y),
|
||||
};
|
||||
|
||||
export const ghost = (shape: SVGTemplateResult, opacity = 0.22) =>
|
||||
svg`<g class="ghost" opacity=${opacity}>${shape}</g>`;
|
||||
|
||||
export const horizontalLine = (y: number, inset = 0) =>
|
||||
`M${FRAME.left + inset} ${y.toFixed(1)} H${FRAME.right - inset}`;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { svg } from "lit";
|
||||
import type { CoverShape } from "./shared";
|
||||
import { FRAME, ghost, valueAxis } from "./shared";
|
||||
import { FRAME, valueAxis } from "./shared";
|
||||
|
||||
const TRAVEL = FRAME.width - 28;
|
||||
const GATE_TOP = FRAME.top + FRAME.height * 0.36;
|
||||
@@ -50,8 +50,4 @@ export const slideShape: CoverShape = {
|
||||
valueAt: (x) => leadingEdge.valueAt(x),
|
||||
targetLine: (value) =>
|
||||
`M${leadingEdge.coordAt(value).toFixed(1)} ${GATE_TOP} V${GROUND}`,
|
||||
targetShape: (value) =>
|
||||
ghost(
|
||||
svg`<rect x=${gateLeft(value)} y=${GATE_TOP} width=${FRAME.width} height=${GATE_HEIGHT} rx="2"></rect>`
|
||||
),
|
||||
};
|
||||
Reference in new issue
Block a user