godown 3.0.0-canary.1 → 3.0.0-canary.11
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/README.md +38 -9
- package/components/alert.d.ts +6 -3
- package/components/alert.d.ts.map +1 -1
- package/components/alert.js +22 -14
- package/components/alert.js.map +1 -1
- package/components/avatar.d.ts +7 -2
- package/components/avatar.d.ts.map +1 -1
- package/components/avatar.js +13 -6
- package/components/avatar.js.map +1 -1
- package/components/breath.d.ts +4 -2
- package/components/breath.d.ts.map +1 -1
- package/components/breath.js +8 -6
- package/components/breath.js.map +1 -1
- package/components/button.d.ts +20 -11
- package/components/button.d.ts.map +1 -1
- package/components/button.js +23 -20
- package/components/button.js.map +1 -1
- package/components/card.d.ts +2 -2
- package/components/card.d.ts.map +1 -1
- package/components/card.js +8 -13
- package/components/card.js.map +1 -1
- package/components/carousel.d.ts +8 -5
- package/components/carousel.d.ts.map +1 -1
- package/components/carousel.js +18 -11
- package/components/carousel.js.map +1 -1
- package/components/details.d.ts +7 -3
- package/components/details.d.ts.map +1 -1
- package/components/details.js +7 -3
- package/components/details.js.map +1 -1
- package/components/dialog.d.ts +9 -5
- package/components/dialog.d.ts.map +1 -1
- package/components/dialog.js +20 -14
- package/components/dialog.js.map +1 -1
- package/components/divider.d.ts +3 -4
- package/components/divider.d.ts.map +1 -1
- package/components/divider.js +6 -7
- package/components/divider.js.map +1 -1
- package/components/dragbox.d.ts +9 -8
- package/components/dragbox.d.ts.map +1 -1
- package/components/dragbox.js +3 -2
- package/components/dragbox.js.map +1 -1
- package/components/flex.d.ts +3 -1
- package/components/flex.d.ts.map +1 -1
- package/components/flex.js +13 -4
- package/components/flex.js.map +1 -1
- package/components/form.d.ts +2 -3
- package/components/form.d.ts.map +1 -1
- package/components/form.js +0 -2
- package/components/form.js.map +1 -1
- package/components/grid.d.ts +9 -3
- package/components/grid.d.ts.map +1 -1
- package/components/grid.js +6 -4
- package/components/grid.js.map +1 -1
- package/components/input.d.ts +4 -4
- package/components/input.d.ts.map +1 -1
- package/components/input.js +5 -7
- package/components/input.js.map +1 -1
- package/components/layout.d.ts +4 -6
- package/components/layout.d.ts.map +1 -1
- package/components/layout.js +23 -12
- package/components/layout.js.map +1 -1
- package/components/link.d.ts +3 -1
- package/components/link.d.ts.map +1 -1
- package/components/link.js +3 -1
- package/components/link.js.map +1 -1
- package/components/progress.d.ts +4 -12
- package/components/progress.d.ts.map +1 -1
- package/components/progress.js +9 -17
- package/components/progress.js.map +1 -1
- package/components/range.d.ts +45 -18
- package/components/range.d.ts.map +1 -1
- package/components/range.js +133 -62
- package/components/range.js.map +1 -1
- package/components/rotate.d.ts +3 -2
- package/components/rotate.d.ts.map +1 -1
- package/components/rotate.js +1 -1
- package/components/rotate.js.map +1 -1
- package/components/router.d.ts +15 -17
- package/components/router.d.ts.map +1 -1
- package/components/router.js +10 -10
- package/components/router.js.map +1 -1
- package/components/select.d.ts +6 -9
- package/components/select.d.ts.map +1 -1
- package/components/select.js +48 -43
- package/components/select.js.map +1 -1
- package/components/skeleton.d.ts +2 -1
- package/components/skeleton.d.ts.map +1 -1
- package/components/skeleton.js +5 -5
- package/components/skeleton.js.map +1 -1
- package/components/split.d.ts +20 -2
- package/components/split.d.ts.map +1 -1
- package/components/split.js +54 -20
- package/components/split.js.map +1 -1
- package/components/switch.d.ts +6 -5
- package/components/switch.d.ts.map +1 -1
- package/components/switch.js +7 -6
- package/components/switch.js.map +1 -1
- package/components/text.d.ts +2 -1
- package/components/text.d.ts.map +1 -1
- package/components/text.js +5 -6
- package/components/text.js.map +1 -1
- package/components/time.d.ts +6 -22
- package/components/time.d.ts.map +1 -1
- package/components/time.js +7 -67
- package/components/time.js.map +1 -1
- package/components/tooltip.d.ts +13 -2
- package/components/tooltip.d.ts.map +1 -1
- package/components/tooltip.js +24 -5
- package/components/tooltip.js.map +1 -1
- package/components/typewriter.d.ts +4 -4
- package/components/typewriter.d.ts.map +1 -1
- package/components/typewriter.js +4 -5
- package/components/typewriter.js.map +1 -1
- package/core/global-style.d.ts.map +1 -1
- package/core/global-style.js +9 -2
- package/core/global-style.js.map +1 -1
- package/core/super-anchor.d.ts +2 -1
- package/core/super-anchor.d.ts.map +1 -1
- package/core/super-anchor.js +4 -3
- package/core/super-anchor.js.map +1 -1
- package/core/super-input.d.ts +5 -5
- package/core/super-input.d.ts.map +1 -1
- package/core/super-input.js +3 -6
- package/core/super-input.js.map +1 -1
- package/core/super-openable.d.ts.map +1 -1
- package/core/super-openable.js +1 -1
- package/core/super-openable.js.map +1 -1
- package/custom-elements.json +1 -1
- package/dev/components/alert.d.ts +6 -3
- package/dev/components/alert.d.ts.map +1 -1
- package/dev/components/alert.js +38 -25
- package/dev/components/alert.js.map +1 -1
- package/dev/components/avatar.d.ts +7 -2
- package/dev/components/avatar.d.ts.map +1 -1
- package/dev/components/avatar.js +28 -13
- package/dev/components/avatar.js.map +1 -1
- package/dev/components/breath.d.ts +4 -2
- package/dev/components/breath.d.ts.map +1 -1
- package/dev/components/breath.js +20 -6
- package/dev/components/breath.js.map +1 -1
- package/dev/components/button.d.ts +20 -11
- package/dev/components/button.d.ts.map +1 -1
- package/dev/components/button.js +34 -25
- package/dev/components/button.js.map +1 -1
- package/dev/components/card.d.ts +2 -2
- package/dev/components/card.d.ts.map +1 -1
- package/dev/components/card.js +25 -30
- package/dev/components/card.js.map +1 -1
- package/dev/components/carousel.d.ts +8 -5
- package/dev/components/carousel.d.ts.map +1 -1
- package/dev/components/carousel.js +35 -20
- package/dev/components/carousel.js.map +1 -1
- package/dev/components/details.d.ts +7 -3
- package/dev/components/details.d.ts.map +1 -1
- package/dev/components/details.js +12 -4
- package/dev/components/details.js.map +1 -1
- package/dev/components/dialog.d.ts +9 -5
- package/dev/components/dialog.d.ts.map +1 -1
- package/dev/components/dialog.js +30 -24
- package/dev/components/dialog.js.map +1 -1
- package/dev/components/divider.d.ts +3 -4
- package/dev/components/divider.d.ts.map +1 -1
- package/dev/components/divider.js +20 -8
- package/dev/components/divider.js.map +1 -1
- package/dev/components/dragbox.d.ts +9 -8
- package/dev/components/dragbox.d.ts.map +1 -1
- package/dev/components/dragbox.js +8 -1
- package/dev/components/dragbox.js.map +1 -1
- package/dev/components/flex.d.ts +3 -1
- package/dev/components/flex.d.ts.map +1 -1
- package/dev/components/flex.js +24 -4
- package/dev/components/flex.js.map +1 -1
- package/dev/components/form.d.ts +2 -3
- package/dev/components/form.d.ts.map +1 -1
- package/dev/components/form.js +0 -2
- package/dev/components/form.js.map +1 -1
- package/dev/components/grid.d.ts +9 -3
- package/dev/components/grid.d.ts.map +1 -1
- package/dev/components/grid.js +17 -4
- package/dev/components/grid.js.map +1 -1
- package/dev/components/input.d.ts +4 -4
- package/dev/components/input.d.ts.map +1 -1
- package/dev/components/input.js +3 -21
- package/dev/components/input.js.map +1 -1
- package/dev/components/layout.d.ts +4 -6
- package/dev/components/layout.d.ts.map +1 -1
- package/dev/components/layout.js +33 -13
- package/dev/components/layout.js.map +1 -1
- package/dev/components/link.d.ts +3 -1
- package/dev/components/link.d.ts.map +1 -1
- package/dev/components/link.js +3 -1
- package/dev/components/link.js.map +1 -1
- package/dev/components/progress.d.ts +4 -12
- package/dev/components/progress.d.ts.map +1 -1
- package/dev/components/progress.js +14 -18
- package/dev/components/progress.js.map +1 -1
- package/dev/components/range.d.ts +45 -18
- package/dev/components/range.d.ts.map +1 -1
- package/dev/components/range.js +164 -109
- package/dev/components/range.js.map +1 -1
- package/dev/components/rotate.d.ts +3 -2
- package/dev/components/rotate.d.ts.map +1 -1
- package/dev/components/rotate.js +1 -1
- package/dev/components/rotate.js.map +1 -1
- package/dev/components/router.d.ts +15 -17
- package/dev/components/router.d.ts.map +1 -1
- package/dev/components/router.js +10 -10
- package/dev/components/router.js.map +1 -1
- package/dev/components/select.d.ts +6 -9
- package/dev/components/select.d.ts.map +1 -1
- package/dev/components/select.js +58 -45
- package/dev/components/select.js.map +1 -1
- package/dev/components/skeleton.d.ts +2 -1
- package/dev/components/skeleton.d.ts.map +1 -1
- package/dev/components/skeleton.js +6 -6
- package/dev/components/skeleton.js.map +1 -1
- package/dev/components/split.d.ts +20 -2
- package/dev/components/split.d.ts.map +1 -1
- package/dev/components/split.js +69 -32
- package/dev/components/split.js.map +1 -1
- package/dev/components/switch.d.ts +6 -5
- package/dev/components/switch.d.ts.map +1 -1
- package/dev/components/switch.js +23 -20
- package/dev/components/switch.js.map +1 -1
- package/dev/components/text.d.ts +2 -1
- package/dev/components/text.d.ts.map +1 -1
- package/dev/components/text.js +7 -7
- package/dev/components/text.js.map +1 -1
- package/dev/components/time.d.ts +6 -22
- package/dev/components/time.d.ts.map +1 -1
- package/dev/components/time.js +9 -67
- package/dev/components/time.js.map +1 -1
- package/dev/components/tooltip.d.ts +13 -2
- package/dev/components/tooltip.d.ts.map +1 -1
- package/dev/components/tooltip.js +55 -20
- package/dev/components/tooltip.js.map +1 -1
- package/dev/components/typewriter.d.ts +4 -4
- package/dev/components/typewriter.d.ts.map +1 -1
- package/dev/components/typewriter.js +11 -5
- package/dev/components/typewriter.js.map +1 -1
- package/dev/core/global-style.d.ts.map +1 -1
- package/dev/core/global-style.js +18 -10
- package/dev/core/global-style.js.map +1 -1
- package/dev/core/super-anchor.d.ts +2 -1
- package/dev/core/super-anchor.d.ts.map +1 -1
- package/dev/core/super-anchor.js +8 -5
- package/dev/core/super-anchor.js.map +1 -1
- package/dev/core/super-input.d.ts +5 -5
- package/dev/core/super-input.d.ts.map +1 -1
- package/dev/core/super-input.js +21 -20
- package/dev/core/super-input.js.map +1 -1
- package/dev/core/super-openable.d.ts.map +1 -1
- package/dev/core/super-openable.js +1 -1
- package/dev/core/super-openable.js.map +1 -1
- package/dev/range.d.ts +1 -1
- package/dev/range.d.ts.map +1 -1
- package/index.js +13 -13
- package/package.json +11 -8
- package/range.d.ts +1 -1
- package/range.d.ts.map +1 -1
- package/src/alert.ts +11 -0
- package/src/avatar.ts +11 -0
- package/src/breath.ts +13 -0
- package/src/button.ts +11 -0
- package/src/card.ts +11 -0
- package/src/carousel.ts +11 -0
- package/src/components/alert.ts +284 -0
- package/src/components/avatar.ts +109 -0
- package/src/components/breath.ts +165 -0
- package/src/components/button.ts +292 -0
- package/src/components/card.ts +83 -0
- package/src/components/carousel.ts +183 -0
- package/src/components/details.ts +121 -0
- package/src/components/dialog.ts +166 -0
- package/src/components/divider.ts +56 -0
- package/src/components/dragbox.ts +134 -0
- package/src/components/flex.ts +82 -0
- package/src/components/form.ts +82 -0
- package/src/components/grid.ts +87 -0
- package/src/components/input.ts +73 -0
- package/src/components/layout.ts +89 -0
- package/src/components/link.ts +38 -0
- package/src/components/progress.ts +100 -0
- package/src/components/range.ts +399 -0
- package/src/components/rotate.ts +95 -0
- package/src/components/router.ts +281 -0
- package/src/components/select.ts +281 -0
- package/src/components/skeleton.ts +119 -0
- package/src/components/split.ts +225 -0
- package/src/components/switch.ts +184 -0
- package/src/components/text.ts +93 -0
- package/src/components/time.ts +84 -0
- package/src/components/tooltip.ts +150 -0
- package/src/components/typewriter.ts +159 -0
- package/src/core/global-style.ts +105 -0
- package/src/core/super-anchor.ts +55 -0
- package/src/core/super-input.ts +230 -0
- package/src/core/super-openable.ts +51 -0
- package/src/details.ts +11 -0
- package/src/dialog.ts +11 -0
- package/src/divider.ts +11 -0
- package/src/dragbox.ts +11 -0
- package/src/flex.ts +11 -0
- package/src/form.ts +11 -0
- package/src/grid.ts +11 -0
- package/src/index.ts +28 -0
- package/src/input.ts +13 -0
- package/src/layout.ts +12 -0
- package/src/link.ts +13 -0
- package/src/progress.ts +12 -0
- package/src/range.ts +13 -0
- package/src/rotate.ts +13 -0
- package/src/router.ts +12 -0
- package/src/select.ts +13 -0
- package/src/skeleton.ts +13 -0
- package/src/split.ts +13 -0
- package/src/switch.ts +13 -0
- package/src/text.ts +13 -0
- package/src/time.ts +13 -0
- package/src/tooltip.ts +13 -0
- package/src/typewriter.ts +11 -0
- package/vscode.html-custom-data.json +1 -1
- package/web-types.json +1 -1
@@ -0,0 +1,150 @@
|
|
1
|
+
import { godown } from "@godown/element/decorators/godown.js";
|
2
|
+
import { styles } from "@godown/element/decorators/styles.js";
|
3
|
+
import { attr } from "@godown/element/directives/attr.js";
|
4
|
+
import { htmlSlot } from "@godown/element/directives/html-slot.js";
|
5
|
+
import { css, html, type TemplateResult } from "lit";
|
6
|
+
import { property } from "lit/decorators.js";
|
7
|
+
|
8
|
+
import { scopePrefix } from "../core/global-style.js";
|
9
|
+
import SuperOpenable, { type Direction8 } from "../core/super-openable.js";
|
10
|
+
|
11
|
+
const protoName = "tooltip";
|
12
|
+
const cssScope = scopePrefix(protoName);
|
13
|
+
|
14
|
+
/**
|
15
|
+
* {@linkcode Tooltip} provide tooltip for slot elements.
|
16
|
+
*
|
17
|
+
* If it has the tip property, ignore the slot tip.
|
18
|
+
*
|
19
|
+
* @slot tip - Tip element if no `tip` provided.
|
20
|
+
* @slot - Content.
|
21
|
+
* @category feedback
|
22
|
+
*/
|
23
|
+
@godown(protoName)
|
24
|
+
@styles(
|
25
|
+
css`
|
26
|
+
:host {
|
27
|
+
${cssScope}--tip-background: inherit;
|
28
|
+
width: fit-content;
|
29
|
+
}
|
30
|
+
|
31
|
+
:host,
|
32
|
+
[part=root] {
|
33
|
+
display: inline-flex;
|
34
|
+
}
|
35
|
+
|
36
|
+
[part=root] {
|
37
|
+
position: relative;
|
38
|
+
transition: inherit;
|
39
|
+
border-radius: inherit;
|
40
|
+
}
|
41
|
+
|
42
|
+
[part=tip] {
|
43
|
+
width: fit-content;
|
44
|
+
height: fit-content;
|
45
|
+
position: absolute;
|
46
|
+
visibility: hidden;
|
47
|
+
transition: inherit;
|
48
|
+
user-select: none;
|
49
|
+
}
|
50
|
+
|
51
|
+
:host([open]) [part=tip] {
|
52
|
+
visibility: visible;
|
53
|
+
}
|
54
|
+
|
55
|
+
.passive {
|
56
|
+
background: var(${cssScope}--tip-background);
|
57
|
+
}
|
58
|
+
|
59
|
+
[propagation] [part=tip] {
|
60
|
+
pointer-events: none;
|
61
|
+
}
|
62
|
+
`,
|
63
|
+
css`
|
64
|
+
[direction^=top] [part=tip] {
|
65
|
+
bottom: 100%;
|
66
|
+
}
|
67
|
+
|
68
|
+
[direction^=bottom] [part=tip] {
|
69
|
+
top: 100%;
|
70
|
+
}
|
71
|
+
|
72
|
+
[direction$=right] [part=tip] {
|
73
|
+
left: 100%;
|
74
|
+
}
|
75
|
+
|
76
|
+
[direction$=left] [part=tip] {
|
77
|
+
right: 100%;
|
78
|
+
}
|
79
|
+
`,
|
80
|
+
)
|
81
|
+
class Tooltip extends SuperOpenable {
|
82
|
+
/**
|
83
|
+
* Tip text, if there is a value, the slot will be ignored.
|
84
|
+
*/
|
85
|
+
@property()
|
86
|
+
tip: string;
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Direction of opening the tip.
|
90
|
+
*/
|
91
|
+
@property()
|
92
|
+
direction: Direction8 = "top";
|
93
|
+
|
94
|
+
/**
|
95
|
+
* Content alignment.
|
96
|
+
*/
|
97
|
+
@property()
|
98
|
+
align: "center" | "flex-start" | "flex-end" | "start" | "end" = "center";
|
99
|
+
|
100
|
+
/**
|
101
|
+
* If true, allow penetration of the tip.
|
102
|
+
*/
|
103
|
+
@property({ type: Boolean })
|
104
|
+
propagation = false;
|
105
|
+
|
106
|
+
/**
|
107
|
+
* How can tips be triggered.
|
108
|
+
*
|
109
|
+
* If `focus`, element will be focusable, open tip when focused.
|
110
|
+
*
|
111
|
+
* If `hover`, element will open tip when hovered.
|
112
|
+
*
|
113
|
+
* @default "hover"
|
114
|
+
*/
|
115
|
+
@property()
|
116
|
+
type: "hover" | "focus" = "hover";
|
117
|
+
|
118
|
+
static aligns = {
|
119
|
+
start: "flex-start",
|
120
|
+
end: "flex-end",
|
121
|
+
center: "center",
|
122
|
+
"flex-start": "flex-start",
|
123
|
+
"flex-end": "flex-end",
|
124
|
+
};
|
125
|
+
|
126
|
+
protected render(): TemplateResult<1> {
|
127
|
+
const align = Tooltip.aligns[this.align] || "inherit";
|
128
|
+
const isFocusable = this.type === "focus";
|
129
|
+
return html`<div
|
130
|
+
part="root"
|
131
|
+
${attr(this.observedRecord)}
|
132
|
+
tabindex="${isFocusable ? 0 : -1}"
|
133
|
+
@focus="${isFocusable ? () => this.open = true : null}"
|
134
|
+
@blur="${isFocusable ? () => this.open = false : null}"
|
135
|
+
@mouseenter="${isFocusable ? null : () => this.open = true}"
|
136
|
+
@mouseleave="${isFocusable ? null : () => this.open = false}"
|
137
|
+
style="justify-content:${align};align-items:${align}">
|
138
|
+
${htmlSlot()}
|
139
|
+
<div part="tip">
|
140
|
+
${
|
141
|
+
this.tip
|
142
|
+
? html`<span class="passive">${this.tip}</span>`
|
143
|
+
: htmlSlot("tip")
|
144
|
+
}
|
145
|
+
</div>
|
146
|
+
</div>`;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
export default Tooltip;
|
@@ -0,0 +1,159 @@
|
|
1
|
+
import { godown } from "@godown/element/decorators/godown.js";
|
2
|
+
import { styles } from "@godown/element/decorators/styles.js";
|
3
|
+
import { attr } from "@godown/element/directives/attr.js";
|
4
|
+
import { classList } from "@godown/element/directives/class-list.js";
|
5
|
+
import { htmlSlot } from "@godown/element/directives/html-slot.js";
|
6
|
+
import { random } from "@godown/element/tools/lib.js";
|
7
|
+
import { css, html, type PropertyValueMap, TemplateResult } from "lit";
|
8
|
+
import { property, query, state } from "lit/decorators.js";
|
9
|
+
|
10
|
+
import { GlobalStyle, scopePrefix } from "../core/global-style.js";
|
11
|
+
|
12
|
+
const protoName = "typewriter";
|
13
|
+
const cssScope = scopePrefix(protoName);
|
14
|
+
|
15
|
+
/**
|
16
|
+
* {@linkcode Typewriter} renders a typewriter effect to text.
|
17
|
+
*
|
18
|
+
* @category effect
|
19
|
+
*/
|
20
|
+
@godown(protoName)
|
21
|
+
@styles(css`
|
22
|
+
:host {
|
23
|
+
${cssScope}--cursor-width: .05em;
|
24
|
+
}
|
25
|
+
|
26
|
+
:host,
|
27
|
+
:host([contents]) [part=root] {
|
28
|
+
display: inline-block;
|
29
|
+
}
|
30
|
+
|
31
|
+
i {
|
32
|
+
border-right: var(${cssScope}--cursor-width) solid;
|
33
|
+
margin-left: 0.02em;
|
34
|
+
animation: s 1.5s steps(1) infinite;
|
35
|
+
}
|
36
|
+
|
37
|
+
@keyframes s {
|
38
|
+
0% {
|
39
|
+
border-color: currentColor;
|
40
|
+
}
|
41
|
+
50% {
|
42
|
+
border-color: transparent;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
slot {
|
47
|
+
display: none;
|
48
|
+
}
|
49
|
+
|
50
|
+
.hidden {
|
51
|
+
visibility: hidden;
|
52
|
+
}
|
53
|
+
`)
|
54
|
+
class Typewriter extends GlobalStyle {
|
55
|
+
/**
|
56
|
+
* Raw text.
|
57
|
+
*/
|
58
|
+
@property()
|
59
|
+
text = "";
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Start immediately after {@linkcode Typewriter.firstUpdated}.
|
63
|
+
*/
|
64
|
+
@property({ type: Boolean })
|
65
|
+
stopped = false;
|
66
|
+
|
67
|
+
/**
|
68
|
+
* If true, hide the cursor
|
69
|
+
*/
|
70
|
+
@property({ type: Boolean })
|
71
|
+
ended = false;
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Maximum random time.
|
75
|
+
*/
|
76
|
+
@property({ type: Number })
|
77
|
+
max = 100;
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Minimum random time.
|
81
|
+
*/
|
82
|
+
@property({ type: Number })
|
83
|
+
min = 50;
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Fixed time.
|
87
|
+
*/
|
88
|
+
@property({ type: Number })
|
89
|
+
delay = 0;
|
90
|
+
|
91
|
+
/**
|
92
|
+
* The index at the beginning.
|
93
|
+
*/
|
94
|
+
@property({ type: Number })
|
95
|
+
index = 0;
|
96
|
+
|
97
|
+
/**
|
98
|
+
* Internal text.
|
99
|
+
*/
|
100
|
+
@state()
|
101
|
+
content = "";
|
102
|
+
|
103
|
+
protected timeoutID: number;
|
104
|
+
|
105
|
+
@query("i")
|
106
|
+
protected _i: HTMLElement;
|
107
|
+
|
108
|
+
/**
|
109
|
+
* {@linkcode Typewriter.text} length.
|
110
|
+
*/
|
111
|
+
get len(): number {
|
112
|
+
return this.text.length;
|
113
|
+
}
|
114
|
+
|
115
|
+
protected render(): TemplateResult<1> {
|
116
|
+
return html`<div part="root" ${attr(this.observedRecord)}>
|
117
|
+
${htmlSlot()}
|
118
|
+
${this.content}
|
119
|
+
<i part="cursor" class="${classList({ hidden: this.ended })}"></i>
|
120
|
+
</div>`;
|
121
|
+
}
|
122
|
+
|
123
|
+
protected firstUpdated(): void {
|
124
|
+
if (!this.text) {
|
125
|
+
this.text = this._slot?.assignedNodes()[0]?.textContent.trim() || "";
|
126
|
+
}
|
127
|
+
if (!this.stopped && this.len) {
|
128
|
+
this.write();
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
protected updated(changedProperties: PropertyValueMap<this>): void {
|
133
|
+
if (changedProperties.has("index")) {
|
134
|
+
this.dispatchEvent(new CustomEvent(this.index === this.len ? "done" : "write", { detail: this.content }));
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
write(at: number = this.index): void {
|
139
|
+
this.content = this.text.slice(0, at + 1);
|
140
|
+
const timeout = this.delay || random(this.max, this.min);
|
141
|
+
this.timeoutID = window.setTimeout(() => {
|
142
|
+
const nx = at + 1;
|
143
|
+
if (nx <= this.len) {
|
144
|
+
this.index = nx;
|
145
|
+
this.write();
|
146
|
+
}
|
147
|
+
}, timeout);
|
148
|
+
}
|
149
|
+
|
150
|
+
stop(): void {
|
151
|
+
clearTimeout(this.timeoutID);
|
152
|
+
}
|
153
|
+
|
154
|
+
end(): void {
|
155
|
+
this.ended = true;
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
export default Typewriter;
|
@@ -0,0 +1,105 @@
|
|
1
|
+
import { type Gradients, presetsRGB } from "@godown/colors/presets-rgb.js";
|
2
|
+
import { travel } from "@godown/colors/travel.js";
|
3
|
+
import GodownElement from "@godown/element";
|
4
|
+
import GodownConfig from "@godown/element/config.js";
|
5
|
+
import { joinProperties } from "@godown/element/tools/css.js";
|
6
|
+
import { trim } from "@godown/element/tools/lib.js";
|
7
|
+
import { css, CSSResult, unsafeCSS } from "lit";
|
8
|
+
|
9
|
+
GodownElement.godownConfig ||= new GodownConfig();
|
10
|
+
|
11
|
+
export class GlobalStyle extends GodownElement {
|
12
|
+
}
|
13
|
+
|
14
|
+
const cssvar = trim(GlobalStyle.godownConfig.prefix, "-");
|
15
|
+
|
16
|
+
export function scopePrefix(scope: string, len = 1): CSSResult {
|
17
|
+
return variablePrefix(cssvar + "-".repeat(len) + scope);
|
18
|
+
}
|
19
|
+
|
20
|
+
export function variablePrefix(variable: string): CSSResult {
|
21
|
+
return unsafeCSS("--" + variable);
|
22
|
+
}
|
23
|
+
|
24
|
+
export const cssGlobalVars: {
|
25
|
+
foreground: CSSResult;
|
26
|
+
background: CSSResult;
|
27
|
+
clipBackground: CSSResult;
|
28
|
+
active: CSSResult;
|
29
|
+
passive: CSSResult;
|
30
|
+
_colors: PresetsGradientsCSSResult;
|
31
|
+
input: CSSResult;
|
32
|
+
white: CSSResult;
|
33
|
+
black: CSSResult;
|
34
|
+
} = {
|
35
|
+
foreground: scopePrefix("foreground", 2),
|
36
|
+
background: scopePrefix("background", 2),
|
37
|
+
clipBackground: scopePrefix("clip-background", 2),
|
38
|
+
active: scopePrefix("active", 2),
|
39
|
+
passive: scopePrefix("passive", 2),
|
40
|
+
_colors: {} as PresetsGradientsCSSResult,
|
41
|
+
input: scopePrefix("input", 2),
|
42
|
+
white: scopePrefix("color-white", 2),
|
43
|
+
black: scopePrefix("color-black", 2),
|
44
|
+
};
|
45
|
+
|
46
|
+
type PresetsGradientsCSSResult = Record<keyof typeof presetsRGB, Gradients<CSSResult>>;
|
47
|
+
GlobalStyle.styles = [
|
48
|
+
unsafeCSS(
|
49
|
+
":host{"
|
50
|
+
+ `${cssGlobalVars.black}:rgb(0 0 0);`
|
51
|
+
+ `${cssGlobalVars.white}:rgb(255 255 255);`
|
52
|
+
+ travel((key, gradient, rgb) => {
|
53
|
+
cssGlobalVars._colors[key] ||= [] as any;
|
54
|
+
cssGlobalVars._colors[key].push(unsafeCSS(scopePrefix("color", 2) + "-" + key + "-" + gradient));
|
55
|
+
const endKey = `-${key}-${gradient}`;
|
56
|
+
const colorKey = scopePrefix("color", 2) + endKey;
|
57
|
+
return `${colorKey}:rgb(${rgb});`;
|
58
|
+
}, presetsRGB).join("")
|
59
|
+
+ joinProperties({
|
60
|
+
[cssGlobalVars.background + ""]: `var(${cssGlobalVars._colors.darkgray[9]})`,
|
61
|
+
[cssGlobalVars.foreground + ""]: `var(${cssGlobalVars._colors.lightgray[0]})`,
|
62
|
+
[cssGlobalVars.active + ""]: `var(${cssGlobalVars._colors.blue[6]})`,
|
63
|
+
[cssGlobalVars.passive + ""]: `var(${cssGlobalVars._colors.darkgray[6]})`,
|
64
|
+
[cssGlobalVars.clipBackground + ""]:
|
65
|
+
`linear-gradient(to bottom, var(${cssGlobalVars.foreground}), var(${cssGlobalVars.passive}))`,
|
66
|
+
})
|
67
|
+
+ "}",
|
68
|
+
),
|
69
|
+
css`
|
70
|
+
* {
|
71
|
+
border: 0;
|
72
|
+
outline: 0;
|
73
|
+
margin: 0;
|
74
|
+
padding: 0;
|
75
|
+
font-size: 100%;
|
76
|
+
font-style: normal;
|
77
|
+
box-sizing: border-box;
|
78
|
+
}
|
79
|
+
|
80
|
+
:host {
|
81
|
+
box-sizing: border-box;
|
82
|
+
}
|
83
|
+
|
84
|
+
a {
|
85
|
+
text-decoration: none;
|
86
|
+
}
|
87
|
+
|
88
|
+
span {
|
89
|
+
white-space: nowrap;
|
90
|
+
}
|
91
|
+
|
92
|
+
svg {
|
93
|
+
user-select: none;
|
94
|
+
}
|
95
|
+
|
96
|
+
:host([contents]) {
|
97
|
+
display: contents;
|
98
|
+
}
|
99
|
+
|
100
|
+
:where(:host([contents]) [part=root]) {
|
101
|
+
all: inherit;
|
102
|
+
display: revert;
|
103
|
+
}
|
104
|
+
`,
|
105
|
+
];
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { styles } from "@godown/element/decorators/index.js";
|
2
|
+
import { attr } from "@godown/element/directives/attr.js";
|
3
|
+
import { htmlSlot } from "@godown/element/directives/html-slot.js";
|
4
|
+
import { css, html, type TemplateResult } from "lit";
|
5
|
+
import { property } from "lit/decorators.js";
|
6
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
7
|
+
|
8
|
+
import { GlobalStyle } from "./global-style.js";
|
9
|
+
|
10
|
+
@styles(css`
|
11
|
+
:host {
|
12
|
+
display: inline-block;
|
13
|
+
color: currentColor;
|
14
|
+
text-decoration: none;
|
15
|
+
cursor: default;
|
16
|
+
}
|
17
|
+
|
18
|
+
:host([href]) {
|
19
|
+
cursor: pointer;
|
20
|
+
}
|
21
|
+
|
22
|
+
[part=root] {
|
23
|
+
width: 100%;
|
24
|
+
color: inherit;
|
25
|
+
display: inline-block;
|
26
|
+
text-decoration: inherit;
|
27
|
+
}
|
28
|
+
`)
|
29
|
+
class SuperAnchor extends GlobalStyle {
|
30
|
+
/**
|
31
|
+
* A element href.
|
32
|
+
*/
|
33
|
+
@property()
|
34
|
+
href: string = undefined;
|
35
|
+
/**
|
36
|
+
* A element target.
|
37
|
+
*/
|
38
|
+
@property()
|
39
|
+
target: "_blank" | "_self" | "_parent" | "_top" = "_self";
|
40
|
+
|
41
|
+
protected render(): TemplateResult<1> {
|
42
|
+
return html`<a part="root"
|
43
|
+
${attr(this.observedRecord)}
|
44
|
+
href="${ifDefined(this.href)}"
|
45
|
+
target="${this.target}"
|
46
|
+
@click=${this._handleClick}>
|
47
|
+
${htmlSlot()}
|
48
|
+
</a>`;
|
49
|
+
}
|
50
|
+
|
51
|
+
// eslint-disable-next-line
|
52
|
+
protected _handleClick(_: MouseEvent): void {}
|
53
|
+
}
|
54
|
+
|
55
|
+
export default SuperAnchor;
|
@@ -0,0 +1,230 @@
|
|
1
|
+
import { part } from "@godown/element/decorators/part.js";
|
2
|
+
import { styles } from "@godown/element/decorators/styles.js";
|
3
|
+
import { htmlSlot } from "@godown/element/directives/index.js";
|
4
|
+
import { type HandlerEvent } from "@godown/element/element.js";
|
5
|
+
import iconEyeSlashFill from "@godown/f7-icon/icons/eye-slash-fill.js";
|
6
|
+
import { css, html, type TemplateResult } from "lit";
|
7
|
+
import { property } from "lit/decorators.js";
|
8
|
+
|
9
|
+
import { cssGlobalVars, GlobalStyle } from "./global-style.js";
|
10
|
+
|
11
|
+
const fieldStyle = css`
|
12
|
+
.input-field {
|
13
|
+
display: flex;
|
14
|
+
position: relative;
|
15
|
+
align-items: center;
|
16
|
+
border-radius: inherit;
|
17
|
+
height: inherit;
|
18
|
+
}
|
19
|
+
|
20
|
+
.input-field [part=input] {
|
21
|
+
background: transparent;
|
22
|
+
height: 100%;
|
23
|
+
width: 100%;
|
24
|
+
color: inherit;
|
25
|
+
}
|
26
|
+
|
27
|
+
.input-field:focus-within,
|
28
|
+
.input-field.outline {
|
29
|
+
box-shadow: var(${cssGlobalVars.input}-box-shadow);
|
30
|
+
}
|
31
|
+
|
32
|
+
.input-field [part=icon] {
|
33
|
+
display: flex;
|
34
|
+
align-items: center;
|
35
|
+
justify-content: center;
|
36
|
+
}
|
37
|
+
|
38
|
+
.input-field [part=prefix],
|
39
|
+
.input-field [part=suffix] {
|
40
|
+
height: 100%;
|
41
|
+
display: flex;
|
42
|
+
}
|
43
|
+
|
44
|
+
.input-field [part=space] {
|
45
|
+
width: var(${cssGlobalVars.input}-space);
|
46
|
+
}
|
47
|
+
`;
|
48
|
+
|
49
|
+
const inputStyle = css`
|
50
|
+
:host {
|
51
|
+
${cssGlobalVars.input}-width: 10em;
|
52
|
+
${cssGlobalVars.input}-height: 1.6em;
|
53
|
+
${cssGlobalVars.input}-space: 0.2em;
|
54
|
+
${cssGlobalVars.input}-background: var(${cssGlobalVars.background});
|
55
|
+
${cssGlobalVars.input}-control: var(${cssGlobalVars.foreground});
|
56
|
+
${cssGlobalVars.input}-control-edge: var(${cssGlobalVars.active});
|
57
|
+
${cssGlobalVars.input}-radius: 0.2em;
|
58
|
+
${cssGlobalVars.input}-box-shadow: 0px 0px 0px .1em var(${cssGlobalVars.active});
|
59
|
+
border-radius: var(${cssGlobalVars.input}-radius);
|
60
|
+
}
|
61
|
+
|
62
|
+
:host([disabled]) {
|
63
|
+
cursor: not-allowed;
|
64
|
+
filter: brightness(0.85);
|
65
|
+
}
|
66
|
+
|
67
|
+
input:disabled {
|
68
|
+
cursor: inherit;
|
69
|
+
}
|
70
|
+
|
71
|
+
input::-ms-reveal,
|
72
|
+
input::-ms-clear {
|
73
|
+
display: none;
|
74
|
+
}
|
75
|
+
`;
|
76
|
+
|
77
|
+
@styles(fieldStyle, inputStyle)
|
78
|
+
class SuperInput extends GlobalStyle {
|
79
|
+
autofocus: boolean;
|
80
|
+
@property()
|
81
|
+
autocomplete: string | boolean;
|
82
|
+
|
83
|
+
@property({ type: Boolean, reflect: true })
|
84
|
+
disabled: boolean;
|
85
|
+
|
86
|
+
@property({ reflect: true })
|
87
|
+
type: InputType;
|
88
|
+
|
89
|
+
@property({ reflect: true })
|
90
|
+
placeholder: string;
|
91
|
+
|
92
|
+
@property({ reflect: true })
|
93
|
+
name: string;
|
94
|
+
|
95
|
+
@property()
|
96
|
+
value: any;
|
97
|
+
|
98
|
+
/**
|
99
|
+
* default property records the default or initial value and is used to reset the input.
|
100
|
+
*/
|
101
|
+
@property()
|
102
|
+
default: any;
|
103
|
+
|
104
|
+
@part("input")
|
105
|
+
protected _input: HTMLInputElement;
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Returns true when the input is compositing.
|
109
|
+
*/
|
110
|
+
compositing: boolean;
|
111
|
+
|
112
|
+
set defaultValue(value: typeof this.default) {
|
113
|
+
this.default = value;
|
114
|
+
}
|
115
|
+
|
116
|
+
get defaultValue() {
|
117
|
+
return this.default;
|
118
|
+
}
|
119
|
+
|
120
|
+
protected makeId: string = Math.random().toString(36).slice(1);
|
121
|
+
|
122
|
+
namevalue(): [string, any] {
|
123
|
+
return [this.name, this.value];
|
124
|
+
}
|
125
|
+
|
126
|
+
nameValue: () => [string, any] = this.namevalue;
|
127
|
+
|
128
|
+
reset(): void {
|
129
|
+
this.value = this.default;
|
130
|
+
this._input.value = this.default;
|
131
|
+
}
|
132
|
+
|
133
|
+
protected _handleInput(e: HandlerEvent<HTMLInputElement>): void {
|
134
|
+
e.stopPropagation();
|
135
|
+
if (this.compositing) {
|
136
|
+
return;
|
137
|
+
}
|
138
|
+
this.value = e.target.value?.trim();
|
139
|
+
this.dispatchEvent(
|
140
|
+
new CustomEvent("input", {
|
141
|
+
detail: this.value,
|
142
|
+
bubbles: true,
|
143
|
+
composed: true,
|
144
|
+
}),
|
145
|
+
);
|
146
|
+
this.dispatchEvent(new CustomEvent("change", { detail: this.value, composed: true }));
|
147
|
+
}
|
148
|
+
|
149
|
+
connectedCallback(): void {
|
150
|
+
super.connectedCallback();
|
151
|
+
this._connectedInit();
|
152
|
+
}
|
153
|
+
|
154
|
+
protected _connectedInit(): void {
|
155
|
+
this.default ??= this.value || "";
|
156
|
+
this.value ??= this.default;
|
157
|
+
}
|
158
|
+
|
159
|
+
protected _compositionInit(): void {
|
160
|
+
if (this._input) {
|
161
|
+
this.events.add(this._input, "compositionstart", () => this.compositing = true);
|
162
|
+
this.events.add(this._input, "compositionend", (e: HandlerEvent<HTMLInputElement>) => {
|
163
|
+
this.compositing = false;
|
164
|
+
this._handleInput(e);
|
165
|
+
});
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
protected _changeInputType(t: typeof this.type): void {
|
170
|
+
if (this._input) {
|
171
|
+
this._input.type = t;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
focus(options?: FocusOptions): void {
|
176
|
+
this._input?.focus(options);
|
177
|
+
}
|
178
|
+
|
179
|
+
protected firstUpdated(): void {
|
180
|
+
this._compositionInit();
|
181
|
+
}
|
182
|
+
|
183
|
+
protected _renderPrefix(): TemplateResult<1> {
|
184
|
+
return html`<label for=${this.makeId} part="prefix">
|
185
|
+
<i part="space"></i>
|
186
|
+
${htmlSlot("prefix")}</label>`;
|
187
|
+
}
|
188
|
+
|
189
|
+
protected _renderSuffix(): TemplateResult<1> {
|
190
|
+
const PASSWORD = "password";
|
191
|
+
return html`<label for=${this.makeId} part="suffix">${
|
192
|
+
this.type === "password"
|
193
|
+
? html`
|
194
|
+
<i part="space"></i>
|
195
|
+
<i
|
196
|
+
part="icon"
|
197
|
+
@mousedown="${() => this._changeInputType("text")}"
|
198
|
+
@mouseup="${() => this._changeInputType(PASSWORD)}"
|
199
|
+
@mouseleave="${() => this._changeInputType(PASSWORD)}"
|
200
|
+
>${iconEyeSlashFill()}</i>`
|
201
|
+
: htmlSlot("suffix")
|
202
|
+
}
|
203
|
+
<i part="space"></i>
|
204
|
+
</label>`;
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
export default SuperInput;
|
209
|
+
|
210
|
+
type InputType =
|
211
|
+
| "hidden"
|
212
|
+
| "text"
|
213
|
+
| "search"
|
214
|
+
| "tel"
|
215
|
+
| "url"
|
216
|
+
| "email"
|
217
|
+
| "password"
|
218
|
+
| "datetime"
|
219
|
+
| "date"
|
220
|
+
| "month"
|
221
|
+
| "week"
|
222
|
+
| "time"
|
223
|
+
| "datetime-local"
|
224
|
+
| "number"
|
225
|
+
| "range"
|
226
|
+
| "color"
|
227
|
+
| "checkbox"
|
228
|
+
| "radio"
|
229
|
+
| "file"
|
230
|
+
| "image";
|