@droans/ha-components 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +8 -0
- package/.gitattributes +4 -0
- package/.github/workflows/publish.yaml +24 -0
- package/.vscode/settings.json +19 -0
- package/.yarnrc.yml +1 -0
- package/LICENSE +21 -0
- package/README.md +6 -0
- package/eslint.config.mjs +55 -0
- package/package.json +63 -0
- package/packages/components/marquee-text.ts +176 -0
- package/tsconfig.json +18 -0
package/.editorconfig
ADDED
package/.gitattributes
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
3
|
+
|
|
4
|
+
name: Node.js Package
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types:
|
|
9
|
+
- published
|
|
10
|
+
permissions:
|
|
11
|
+
id-token: write
|
|
12
|
+
contents: read
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
publish:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- uses: actions/setup-node@v4
|
|
21
|
+
with:
|
|
22
|
+
node-version: '24'
|
|
23
|
+
registry-url: 'https://registry.npmjs.org'
|
|
24
|
+
- run: npm publish
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cSpell.words": [
|
|
3
|
+
"dimgray",
|
|
4
|
+
"Hacs",
|
|
5
|
+
"Hass",
|
|
6
|
+
"homeassistant"
|
|
7
|
+
],
|
|
8
|
+
"typescript.tsdk": "node_modules/typescript/lib",
|
|
9
|
+
"editor.defaultFormatter": "vscode.typescript-language-features",
|
|
10
|
+
"[typescript]": {
|
|
11
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
12
|
+
},
|
|
13
|
+
"tslint.configFile": "./tsconfig.json",
|
|
14
|
+
"tslint.packageManager": "yarn",
|
|
15
|
+
"tslint.suppressWhileTypeErrorsPresent": true,
|
|
16
|
+
"js/ts.implicitProjectConfig.target": "ES2021",
|
|
17
|
+
"typescript.reportStyleChecksAsWarnings": true,
|
|
18
|
+
"tslint.alwaysShowRuleFailuresAsWarnings": true
|
|
19
|
+
}
|
package/.yarnrc.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
nodeLinker: node-modules
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Gábor Tolnai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import eslint from "@eslint/js";
|
|
2
|
+
import prettierConfig from "eslint-config-prettier";
|
|
3
|
+
import globals from "globals";
|
|
4
|
+
import tseslint from "typescript-eslint";
|
|
5
|
+
import wc from 'eslint-plugin-wc';
|
|
6
|
+
const rootConfigFiles = [".prettierrc.js", "eslint.config.mjs"];
|
|
7
|
+
|
|
8
|
+
export default tseslint.config(
|
|
9
|
+
{ ignores: ["dist", "node_modules/*"] },
|
|
10
|
+
// apply default config
|
|
11
|
+
prettierConfig,
|
|
12
|
+
eslint.configs.recommended,
|
|
13
|
+
tseslint.configs.strictTypeChecked,
|
|
14
|
+
tseslint.configs.stylisticTypeChecked,
|
|
15
|
+
{
|
|
16
|
+
plugins: {
|
|
17
|
+
wc: wc,
|
|
18
|
+
},
|
|
19
|
+
rules: {
|
|
20
|
+
...wc.configs.recommended.rules,
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
// default language/parser options
|
|
24
|
+
{
|
|
25
|
+
languageOptions: {
|
|
26
|
+
parserOptions: {
|
|
27
|
+
projectService: {
|
|
28
|
+
allowDefaultProject: rootConfigFiles,
|
|
29
|
+
},
|
|
30
|
+
tsconfigRootDir: import.meta.dirname,
|
|
31
|
+
},
|
|
32
|
+
globals: {
|
|
33
|
+
...globals.browser,
|
|
34
|
+
...globals.node,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
// individual rule overrides
|
|
39
|
+
{
|
|
40
|
+
rules: {
|
|
41
|
+
"no-console": "warn",
|
|
42
|
+
"@typescript-eslint/no-unnecessary-condition": "off",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
// disable type checking for root config files
|
|
46
|
+
{
|
|
47
|
+
files: rootConfigFiles,
|
|
48
|
+
...tseslint.configs.disableTypeChecked,
|
|
49
|
+
languageOptions: { sourceType: "commonjs" },
|
|
50
|
+
rules: {
|
|
51
|
+
...tseslint.configs.disableTypeChecked.rules,
|
|
52
|
+
"@typescript-eslint/no-require-imports": "off",
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
);
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@droans/ha-components",
|
|
3
|
+
"description": "Home Assistant Built-In Components re-exported for reuse",
|
|
4
|
+
"repository": "https://github.com/droans/mass-queue-types",
|
|
5
|
+
"author": "Michael Carroll",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"home-assistant",
|
|
9
|
+
"homeassistant",
|
|
10
|
+
"hass",
|
|
11
|
+
"hacs",
|
|
12
|
+
"lovelace",
|
|
13
|
+
"custom-cards",
|
|
14
|
+
"home",
|
|
15
|
+
"assistant"
|
|
16
|
+
],
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@eslint/js": "9.39.1",
|
|
21
|
+
"@rollup/plugin-json": "^6.0.0",
|
|
22
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
23
|
+
"@rollup/plugin-terser": "^0.4.0",
|
|
24
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
25
|
+
"@typescript-eslint/eslint-plugin": "^8.46.4",
|
|
26
|
+
"@typescript-eslint/parser": "^8.46.4",
|
|
27
|
+
"eslint": "9.21.0",
|
|
28
|
+
"eslint-config-prettier": "10.1.8",
|
|
29
|
+
"eslint-plugin-jest": "29.1.0",
|
|
30
|
+
"eslint-plugin-wc": "^3.0.1",
|
|
31
|
+
"prettier": "^3.6.2",
|
|
32
|
+
"rollup": "^4.53.2",
|
|
33
|
+
"rollup-plugin-commonjs": "^10.1.0",
|
|
34
|
+
"rollup-plugin-serve": "^3.0.0",
|
|
35
|
+
"typescript": "5.8.2",
|
|
36
|
+
"typescript-eslint": "8.26.0"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "yarn rollup",
|
|
40
|
+
"prettier": "prettier ./packages --write",
|
|
41
|
+
"lint": "eslint packages/**/*.ts --max-warnings 0 --no-warn-ignored",
|
|
42
|
+
"full": "echo 'Generating TOC' && yarn docs && echo 'Running Prettier' && yarn prettier && echo 'Linting' && yarn lint",
|
|
43
|
+
"docs": "doctoc ./README.md --maxlevel 2"
|
|
44
|
+
},
|
|
45
|
+
"packageManager": "yarn@4.9.1",
|
|
46
|
+
"prettier": {
|
|
47
|
+
"printWidth": 80,
|
|
48
|
+
"tabWidth": 2,
|
|
49
|
+
"useTabs": false,
|
|
50
|
+
"semi": true,
|
|
51
|
+
"singleQuote": false,
|
|
52
|
+
"trailingComma": "all",
|
|
53
|
+
"bracketSpacing": true,
|
|
54
|
+
"bracketSameLine": false,
|
|
55
|
+
"arrowParens": "always",
|
|
56
|
+
"endOfLine": "lf"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@droans/webawesome": "^3.0.0",
|
|
60
|
+
"@mdi/js": "^7.4.47",
|
|
61
|
+
"lit": "^3.3.2"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type TemplateResult,
|
|
3
|
+
LitElement,
|
|
4
|
+
html,
|
|
5
|
+
css,
|
|
6
|
+
type PropertyValues,
|
|
7
|
+
} from "lit";
|
|
8
|
+
import { property, query } from "lit/decorators.js";
|
|
9
|
+
|
|
10
|
+
export class MarqueeText extends LitElement {
|
|
11
|
+
@property({ type: Number }) speed = 15; // pixels per second
|
|
12
|
+
|
|
13
|
+
@property({ type: Number, attribute: "pause-duration" }) pauseDuration = 1000; // ms delay at ends
|
|
14
|
+
|
|
15
|
+
@property({ type: Boolean, attribute: "pause-on-hover" })
|
|
16
|
+
pauseOnHover = false;
|
|
17
|
+
|
|
18
|
+
private _direction: "left" | "right" = "left";
|
|
19
|
+
|
|
20
|
+
private _animationFrame?: number;
|
|
21
|
+
|
|
22
|
+
@query(".marquee-container")
|
|
23
|
+
private _container?: HTMLDivElement;
|
|
24
|
+
|
|
25
|
+
@query(".marquee-text")
|
|
26
|
+
private _textSpan?: HTMLSpanElement;
|
|
27
|
+
|
|
28
|
+
private _position = 0;
|
|
29
|
+
|
|
30
|
+
private _maxOffset = 0;
|
|
31
|
+
|
|
32
|
+
private _pauseTimeout?: number;
|
|
33
|
+
|
|
34
|
+
protected firstUpdated(changedProps: PropertyValues) {
|
|
35
|
+
super.firstUpdated(changedProps);
|
|
36
|
+
|
|
37
|
+
setTimeout(
|
|
38
|
+
() => {
|
|
39
|
+
this._setupAnimation()
|
|
40
|
+
},
|
|
41
|
+
50
|
|
42
|
+
)
|
|
43
|
+
// this._setupAnimation();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected updated(changedProps: PropertyValues) {
|
|
47
|
+
super.updated(changedProps);
|
|
48
|
+
|
|
49
|
+
if (changedProps.has("text")) {
|
|
50
|
+
this._setupAnimation();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public disconnectedCallback() {
|
|
55
|
+
super.disconnectedCallback();
|
|
56
|
+
|
|
57
|
+
if (this._animationFrame) {
|
|
58
|
+
cancelAnimationFrame(this._animationFrame);
|
|
59
|
+
}
|
|
60
|
+
if (this._pauseTimeout) {
|
|
61
|
+
clearTimeout(this._pauseTimeout);
|
|
62
|
+
this._pauseTimeout = undefined;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
protected render(): TemplateResult {
|
|
67
|
+
return html`
|
|
68
|
+
<div
|
|
69
|
+
class="marquee-container"
|
|
70
|
+
@mouseenter=${this._handleMouseEnter}
|
|
71
|
+
@mouseleave=${this._handleMouseLeave}
|
|
72
|
+
@touchstart=${this._handleMouseEnter}
|
|
73
|
+
@touchend=${this._handleMouseLeave}
|
|
74
|
+
>
|
|
75
|
+
<span class="marquee-text"><slot></slot></span>
|
|
76
|
+
</div>
|
|
77
|
+
`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private _setupAnimation() {
|
|
81
|
+
if (!this._container || !this._textSpan) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
this._position = 0;
|
|
86
|
+
this._direction = "left";
|
|
87
|
+
this._maxOffset = Math.max(
|
|
88
|
+
0,
|
|
89
|
+
this._textSpan.offsetWidth - this._container.offsetWidth
|
|
90
|
+
);
|
|
91
|
+
this._textSpan.style.transform = `translateX(0px)`;
|
|
92
|
+
if (this._animationFrame) {
|
|
93
|
+
cancelAnimationFrame(this._animationFrame);
|
|
94
|
+
}
|
|
95
|
+
if (this._pauseTimeout) {
|
|
96
|
+
clearTimeout(this._pauseTimeout);
|
|
97
|
+
this._pauseTimeout = undefined;
|
|
98
|
+
}
|
|
99
|
+
this._animate();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private _animate = () => {
|
|
103
|
+
if (!this._container || !this._textSpan) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const dt = 1 / 60; // ~16ms per frame
|
|
108
|
+
const pxPerFrame = this.speed * dt;
|
|
109
|
+
let reachedEnd = false;
|
|
110
|
+
if (this._direction === "left") {
|
|
111
|
+
this._position -= pxPerFrame;
|
|
112
|
+
if (this._position <= -this._maxOffset) {
|
|
113
|
+
this._position = -this._maxOffset;
|
|
114
|
+
this._direction = "right";
|
|
115
|
+
reachedEnd = true;
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
this._position += pxPerFrame;
|
|
119
|
+
if (this._position >= 0) {
|
|
120
|
+
this._position = 0;
|
|
121
|
+
this._direction = "left";
|
|
122
|
+
reachedEnd = true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
this._textSpan.style.transform = `translateX(${this._position.toString()}px)`;
|
|
126
|
+
if (reachedEnd) {
|
|
127
|
+
this._pauseTimeout = window.setTimeout(() => {
|
|
128
|
+
this._pauseTimeout = undefined;
|
|
129
|
+
this._animationFrame = requestAnimationFrame(this._animate);
|
|
130
|
+
}, this.pauseDuration);
|
|
131
|
+
} else {
|
|
132
|
+
this._animationFrame = requestAnimationFrame(this._animate);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
private _handleMouseEnter = () => {
|
|
137
|
+
if (this.pauseOnHover && this._animationFrame) {
|
|
138
|
+
cancelAnimationFrame(this._animationFrame);
|
|
139
|
+
this._animationFrame = undefined;
|
|
140
|
+
}
|
|
141
|
+
if (this.pauseOnHover && this._pauseTimeout) {
|
|
142
|
+
clearTimeout(this._pauseTimeout);
|
|
143
|
+
this._pauseTimeout = undefined;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private _handleMouseLeave = () => {
|
|
148
|
+
if (this.pauseOnHover && !this._animationFrame && !this._pauseTimeout) {
|
|
149
|
+
this._animate();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
static styles = css`
|
|
154
|
+
:host {
|
|
155
|
+
display: block;
|
|
156
|
+
overflow: hidden;
|
|
157
|
+
width: 100%;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.marquee-container {
|
|
161
|
+
width: 100%;
|
|
162
|
+
white-space: nowrap;
|
|
163
|
+
overflow: hidden;
|
|
164
|
+
user-select: none;
|
|
165
|
+
cursor: default;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.marquee-text {
|
|
169
|
+
display: inline-block;
|
|
170
|
+
vertical-align: middle;
|
|
171
|
+
will-change: transform;
|
|
172
|
+
font-size: 1em;
|
|
173
|
+
pointer-events: none;
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2021",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"lib": ["es2021", "dom", "dom.iterable"],
|
|
7
|
+
"noEmit": true,
|
|
8
|
+
"noUnusedParameters": true,
|
|
9
|
+
"noImplicitReturns": true,
|
|
10
|
+
"noFallthroughCasesInSwitch": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"noImplicitAny": false,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"experimentalDecorators": true,
|
|
16
|
+
},
|
|
17
|
+
"include": ["packages"]
|
|
18
|
+
}
|