godown 3.0.0-canary.1 → 3.0.0-canary.10

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.
Files changed (301) hide show
  1. package/README.md +37 -8
  2. package/components/alert.d.ts +5 -3
  3. package/components/alert.d.ts.map +1 -1
  4. package/components/alert.js +24 -14
  5. package/components/alert.js.map +1 -1
  6. package/components/avatar.d.ts +5 -1
  7. package/components/avatar.d.ts.map +1 -1
  8. package/components/avatar.js +7 -3
  9. package/components/avatar.js.map +1 -1
  10. package/components/breath.d.ts +2 -1
  11. package/components/breath.d.ts.map +1 -1
  12. package/components/breath.js +5 -4
  13. package/components/breath.js.map +1 -1
  14. package/components/button.d.ts +16 -9
  15. package/components/button.d.ts.map +1 -1
  16. package/components/button.js +22 -20
  17. package/components/button.js.map +1 -1
  18. package/components/card.d.ts +1 -2
  19. package/components/card.d.ts.map +1 -1
  20. package/components/card.js +5 -11
  21. package/components/card.js.map +1 -1
  22. package/components/carousel.d.ts +6 -5
  23. package/components/carousel.d.ts.map +1 -1
  24. package/components/carousel.js +3 -2
  25. package/components/carousel.js.map +1 -1
  26. package/components/details.d.ts +5 -2
  27. package/components/details.d.ts.map +1 -1
  28. package/components/details.js +5 -2
  29. package/components/details.js.map +1 -1
  30. package/components/dialog.d.ts +8 -4
  31. package/components/dialog.d.ts.map +1 -1
  32. package/components/dialog.js +17 -12
  33. package/components/dialog.js.map +1 -1
  34. package/components/divider.d.ts +1 -1
  35. package/components/divider.js +1 -1
  36. package/components/divider.js.map +1 -1
  37. package/components/dragbox.d.ts +7 -7
  38. package/components/dragbox.d.ts.map +1 -1
  39. package/components/dragbox.js +1 -1
  40. package/components/dragbox.js.map +1 -1
  41. package/components/flex.d.ts +2 -1
  42. package/components/flex.d.ts.map +1 -1
  43. package/components/flex.js +8 -0
  44. package/components/flex.js.map +1 -1
  45. package/components/form.d.ts +0 -2
  46. package/components/form.d.ts.map +1 -1
  47. package/components/form.js +0 -2
  48. package/components/form.js.map +1 -1
  49. package/components/grid.d.ts +8 -3
  50. package/components/grid.d.ts.map +1 -1
  51. package/components/grid.js +1 -0
  52. package/components/grid.js.map +1 -1
  53. package/components/input.d.ts +2 -3
  54. package/components/input.d.ts.map +1 -1
  55. package/components/input.js +3 -6
  56. package/components/input.js.map +1 -1
  57. package/components/layout.d.ts +3 -6
  58. package/components/layout.d.ts.map +1 -1
  59. package/components/layout.js +21 -10
  60. package/components/layout.js.map +1 -1
  61. package/components/link.d.ts +3 -1
  62. package/components/link.d.ts.map +1 -1
  63. package/components/link.js +3 -1
  64. package/components/link.js.map +1 -1
  65. package/components/progress.d.ts +2 -11
  66. package/components/progress.d.ts.map +1 -1
  67. package/components/progress.js +6 -15
  68. package/components/progress.js.map +1 -1
  69. package/components/range.d.ts +43 -17
  70. package/components/range.d.ts.map +1 -1
  71. package/components/range.js +132 -58
  72. package/components/range.js.map +1 -1
  73. package/components/rotate.d.ts +1 -1
  74. package/components/rotate.d.ts.map +1 -1
  75. package/components/rotate.js +1 -1
  76. package/components/rotate.js.map +1 -1
  77. package/components/router.d.ts +6 -8
  78. package/components/router.d.ts.map +1 -1
  79. package/components/router.js +10 -10
  80. package/components/router.js.map +1 -1
  81. package/components/select.d.ts +4 -8
  82. package/components/select.d.ts.map +1 -1
  83. package/components/select.js +42 -41
  84. package/components/select.js.map +1 -1
  85. package/components/skeleton.d.ts.map +1 -1
  86. package/components/skeleton.js +3 -4
  87. package/components/skeleton.js.map +1 -1
  88. package/components/split.d.ts +18 -1
  89. package/components/split.d.ts.map +1 -1
  90. package/components/split.js +52 -19
  91. package/components/split.js.map +1 -1
  92. package/components/switch.d.ts +4 -4
  93. package/components/switch.d.ts.map +1 -1
  94. package/components/switch.js +6 -6
  95. package/components/switch.js.map +1 -1
  96. package/components/text.js +3 -3
  97. package/components/text.js.map +1 -1
  98. package/components/time.d.ts +4 -20
  99. package/components/time.d.ts.map +1 -1
  100. package/components/time.js +5 -66
  101. package/components/time.js.map +1 -1
  102. package/components/tooltip.d.ts +11 -1
  103. package/components/tooltip.d.ts.map +1 -1
  104. package/components/tooltip.js +23 -5
  105. package/components/tooltip.js.map +1 -1
  106. package/components/typewriter.d.ts +2 -2
  107. package/components/typewriter.d.ts.map +1 -1
  108. package/components/typewriter.js +2 -2
  109. package/components/typewriter.js.map +1 -1
  110. package/core/global-style.d.ts.map +1 -1
  111. package/core/global-style.js +8 -1
  112. package/core/global-style.js.map +1 -1
  113. package/core/super-anchor.js +1 -1
  114. package/core/super-anchor.js.map +1 -1
  115. package/core/super-input.d.ts +2 -3
  116. package/core/super-input.d.ts.map +1 -1
  117. package/core/super-input.js +3 -6
  118. package/core/super-input.js.map +1 -1
  119. package/core/super-openable.js.map +1 -1
  120. package/custom-elements.json +1 -1
  121. package/dev/components/alert.d.ts +5 -3
  122. package/dev/components/alert.d.ts.map +1 -1
  123. package/dev/components/alert.js +35 -24
  124. package/dev/components/alert.js.map +1 -1
  125. package/dev/components/avatar.d.ts +5 -1
  126. package/dev/components/avatar.d.ts.map +1 -1
  127. package/dev/components/avatar.js +7 -6
  128. package/dev/components/avatar.js.map +1 -1
  129. package/dev/components/breath.d.ts +2 -1
  130. package/dev/components/breath.d.ts.map +1 -1
  131. package/dev/components/breath.js +3 -1
  132. package/dev/components/breath.js.map +1 -1
  133. package/dev/components/button.d.ts +16 -9
  134. package/dev/components/button.d.ts.map +1 -1
  135. package/dev/components/button.js +29 -25
  136. package/dev/components/button.js.map +1 -1
  137. package/dev/components/card.d.ts +1 -2
  138. package/dev/components/card.d.ts.map +1 -1
  139. package/dev/components/card.js +21 -29
  140. package/dev/components/card.js.map +1 -1
  141. package/dev/components/carousel.d.ts +6 -5
  142. package/dev/components/carousel.d.ts.map +1 -1
  143. package/dev/components/carousel.js +9 -7
  144. package/dev/components/carousel.js.map +1 -1
  145. package/dev/components/details.d.ts +5 -2
  146. package/dev/components/details.d.ts.map +1 -1
  147. package/dev/components/details.js +4 -1
  148. package/dev/components/details.js.map +1 -1
  149. package/dev/components/dialog.d.ts +8 -4
  150. package/dev/components/dialog.d.ts.map +1 -1
  151. package/dev/components/dialog.js +23 -18
  152. package/dev/components/dialog.js.map +1 -1
  153. package/dev/components/divider.d.ts +1 -1
  154. package/dev/components/divider.js +1 -1
  155. package/dev/components/dragbox.d.ts +7 -7
  156. package/dev/components/dragbox.d.ts.map +1 -1
  157. package/dev/components/dragbox.js.map +1 -1
  158. package/dev/components/flex.d.ts +2 -1
  159. package/dev/components/flex.d.ts.map +1 -1
  160. package/dev/components/flex.js +8 -0
  161. package/dev/components/flex.js.map +1 -1
  162. package/dev/components/form.d.ts +0 -2
  163. package/dev/components/form.d.ts.map +1 -1
  164. package/dev/components/form.js +0 -2
  165. package/dev/components/form.js.map +1 -1
  166. package/dev/components/grid.d.ts +8 -3
  167. package/dev/components/grid.d.ts.map +1 -1
  168. package/dev/components/grid.js +1 -0
  169. package/dev/components/grid.js.map +1 -1
  170. package/dev/components/input.d.ts +2 -3
  171. package/dev/components/input.d.ts.map +1 -1
  172. package/dev/components/input.js +1 -20
  173. package/dev/components/input.js.map +1 -1
  174. package/dev/components/layout.d.ts +3 -6
  175. package/dev/components/layout.d.ts.map +1 -1
  176. package/dev/components/layout.js +23 -10
  177. package/dev/components/layout.js.map +1 -1
  178. package/dev/components/link.d.ts +3 -1
  179. package/dev/components/link.d.ts.map +1 -1
  180. package/dev/components/link.js +3 -1
  181. package/dev/components/link.js.map +1 -1
  182. package/dev/components/progress.d.ts +2 -11
  183. package/dev/components/progress.d.ts.map +1 -1
  184. package/dev/components/progress.js +7 -16
  185. package/dev/components/progress.js.map +1 -1
  186. package/dev/components/range.d.ts +43 -17
  187. package/dev/components/range.d.ts.map +1 -1
  188. package/dev/components/range.js +157 -99
  189. package/dev/components/range.js.map +1 -1
  190. package/dev/components/rotate.d.ts +1 -1
  191. package/dev/components/rotate.d.ts.map +1 -1
  192. package/dev/components/rotate.js +1 -1
  193. package/dev/components/rotate.js.map +1 -1
  194. package/dev/components/router.d.ts +6 -8
  195. package/dev/components/router.d.ts.map +1 -1
  196. package/dev/components/router.js +10 -10
  197. package/dev/components/router.js.map +1 -1
  198. package/dev/components/select.d.ts +4 -8
  199. package/dev/components/select.d.ts.map +1 -1
  200. package/dev/components/select.js +46 -44
  201. package/dev/components/select.js.map +1 -1
  202. package/dev/components/skeleton.d.ts.map +1 -1
  203. package/dev/components/skeleton.js +2 -3
  204. package/dev/components/skeleton.js.map +1 -1
  205. package/dev/components/split.d.ts +18 -1
  206. package/dev/components/split.d.ts.map +1 -1
  207. package/dev/components/split.js +55 -22
  208. package/dev/components/split.js.map +1 -1
  209. package/dev/components/switch.d.ts +4 -4
  210. package/dev/components/switch.d.ts.map +1 -1
  211. package/dev/components/switch.js +12 -13
  212. package/dev/components/switch.js.map +1 -1
  213. package/dev/components/text.js +3 -3
  214. package/dev/components/time.d.ts +4 -20
  215. package/dev/components/time.d.ts.map +1 -1
  216. package/dev/components/time.js +5 -66
  217. package/dev/components/time.js.map +1 -1
  218. package/dev/components/tooltip.d.ts +11 -1
  219. package/dev/components/tooltip.d.ts.map +1 -1
  220. package/dev/components/tooltip.js +39 -16
  221. package/dev/components/tooltip.js.map +1 -1
  222. package/dev/components/typewriter.d.ts +2 -2
  223. package/dev/components/typewriter.d.ts.map +1 -1
  224. package/dev/components/typewriter.js +0 -1
  225. package/dev/components/typewriter.js.map +1 -1
  226. package/dev/core/global-style.d.ts.map +1 -1
  227. package/dev/core/global-style.js +8 -9
  228. package/dev/core/global-style.js.map +1 -1
  229. package/dev/core/super-input.d.ts +2 -3
  230. package/dev/core/super-input.d.ts.map +1 -1
  231. package/dev/core/super-input.js +21 -20
  232. package/dev/core/super-input.js.map +1 -1
  233. package/dev/range.d.ts +1 -1
  234. package/dev/range.d.ts.map +1 -1
  235. package/index.js +13 -13
  236. package/package.json +9 -7
  237. package/range.d.ts +1 -1
  238. package/range.d.ts.map +1 -1
  239. package/src/alert.ts +11 -0
  240. package/src/avatar.ts +11 -0
  241. package/src/breath.ts +13 -0
  242. package/src/button.ts +11 -0
  243. package/src/card.ts +11 -0
  244. package/src/carousel.ts +11 -0
  245. package/src/components/alert.ts +282 -0
  246. package/src/components/avatar.ts +95 -0
  247. package/src/components/breath.ts +153 -0
  248. package/src/components/button.ts +286 -0
  249. package/src/components/card.ts +80 -0
  250. package/src/components/carousel.ts +169 -0
  251. package/src/components/details.ts +116 -0
  252. package/src/components/dialog.ts +165 -0
  253. package/src/components/divider.ts +44 -0
  254. package/src/components/dragbox.ts +127 -0
  255. package/src/components/flex.ts +70 -0
  256. package/src/components/form.ts +82 -0
  257. package/src/components/grid.ts +75 -0
  258. package/src/components/input.ts +72 -0
  259. package/src/components/layout.ts +82 -0
  260. package/src/components/link.ts +38 -0
  261. package/src/components/progress.ts +95 -0
  262. package/src/components/range.ts +404 -0
  263. package/src/components/rotate.ts +92 -0
  264. package/src/components/router.ts +273 -0
  265. package/src/components/select.ts +268 -0
  266. package/src/components/skeleton.ts +118 -0
  267. package/src/components/split.ts +221 -0
  268. package/src/components/switch.ts +180 -0
  269. package/src/components/text.ts +95 -0
  270. package/src/components/time.ts +81 -0
  271. package/src/components/tooltip.ts +138 -0
  272. package/src/components/typewriter.ts +154 -0
  273. package/src/core/global-style.ts +86 -0
  274. package/src/core/super-anchor.ts +52 -0
  275. package/src/core/super-input.ts +230 -0
  276. package/src/core/super-openable.ts +51 -0
  277. package/src/details.ts +11 -0
  278. package/src/dialog.ts +11 -0
  279. package/src/divider.ts +11 -0
  280. package/src/dragbox.ts +11 -0
  281. package/src/flex.ts +11 -0
  282. package/src/form.ts +11 -0
  283. package/src/grid.ts +11 -0
  284. package/src/index.ts +28 -0
  285. package/src/input.ts +13 -0
  286. package/src/layout.ts +12 -0
  287. package/src/link.ts +13 -0
  288. package/src/progress.ts +12 -0
  289. package/src/range.ts +13 -0
  290. package/src/rotate.ts +13 -0
  291. package/src/router.ts +12 -0
  292. package/src/select.ts +13 -0
  293. package/src/skeleton.ts +13 -0
  294. package/src/split.ts +13 -0
  295. package/src/switch.ts +13 -0
  296. package/src/text.ts +13 -0
  297. package/src/time.ts +13 -0
  298. package/src/tooltip.ts +13 -0
  299. package/src/typewriter.ts +11 -0
  300. package/vscode.html-custom-data.json +1 -1
  301. package/web-types.json +1 -1
@@ -0,0 +1,153 @@
1
+ import { godown } from "@godown/element/decorators/godown.js";
2
+ import { styles } from "@godown/element/decorators/styles.js";
3
+ import { htmlStyle } from "@godown/element/directives/html-style.js";
4
+ import { css, html } from "lit";
5
+ import { property } from "lit/decorators.js";
6
+
7
+ import { cssGlobalVars, GlobalStyle, scopePrefix } from "../core/global-style.js";
8
+
9
+ const defineName = "breath";
10
+ const cssScope = scopePrefix(defineName);
11
+
12
+ /**
13
+ * {@linkcode Breath} render the text with a breathing effect.
14
+ *
15
+ * Dynamically generate a breathing effect based on the length of the split text.
16
+ *
17
+ * If there is not enough CSS variable, overrun elements will use the.
18
+ *
19
+ * godown was a css library in its earliest days,
20
+ * and this is the component version of its first effect.
21
+ *
22
+ * Inspired by Vercel home page (2023).
23
+ *
24
+ * @slot - Breathing parts.
25
+ * @category effect
26
+ */
27
+ @godown(defineName)
28
+ @styles(
29
+ css`
30
+ :host {
31
+ ${cssScope}--deg: 60deg;
32
+ ${cssScope}--1-1: var(${cssGlobalVars._colors.red[5]});
33
+ ${cssScope}--1-2: var(${cssGlobalVars._colors.yellow[5]});
34
+ ${cssScope}--2-1: var(${cssGlobalVars._colors.green[5]});
35
+ ${cssScope}--2-2: var(${cssGlobalVars._colors.purple[5]});
36
+ ${cssScope}--3-1: var(${cssGlobalVars._colors.blue[5]});
37
+ ${cssScope}--3-2: var(${cssGlobalVars._colors.pink[5]});
38
+ ${cssScope}--1: linear-gradient(var(${cssScope}--deg), var(${cssScope}--1-1), var(${cssScope}--1-2));
39
+ ${cssScope}--2: linear-gradient(var(${cssScope}--deg), var(${cssScope}--2-1), var(${cssScope}--2-2));
40
+ ${cssScope}--3: linear-gradient(var(${cssScope}--deg), var(${cssScope}--3-1), var(${cssScope}--3-2));
41
+ }
42
+ `,
43
+ css`
44
+ :host {
45
+ display: flex;
46
+ margin: auto;
47
+ width: -moz-fit-content;
48
+ width: fit-content;
49
+ font-size: 2em;
50
+ align-items: center;
51
+ direction: ltr;
52
+ }
53
+
54
+ ::selection {
55
+ background: none;
56
+ }
57
+
58
+ .rel {
59
+ position: relative;
60
+ font-weight: 800;
61
+ font-size: inherit;
62
+ letter-spacing: -0.05em;
63
+ }
64
+ `,
65
+ css`
66
+ .nocolor,
67
+ .colorful {
68
+ padding: 0 0.05em;
69
+ box-sizing: border-box;
70
+ display: inline-block;
71
+ animation-iteration-count: infinite;
72
+ -webkit-text-fill-color: transparent;
73
+ -webkit-background-clip: text !important;
74
+ background-clip: text !important;
75
+ }
76
+ .colorful {
77
+ opacity: 0;
78
+ animation-name: colorfulN;
79
+ }
80
+ .nocolor {
81
+ position: absolute;
82
+ top: 0;
83
+ background: var(${cssGlobalVars.clipBackground});
84
+ }
85
+ `,
86
+ )
87
+ class Breath extends GlobalStyle {
88
+ /**
89
+ * Strings or array of strings,
90
+ * if array, divided each element into chunks,
91
+ * otherwise split strings by whitespace.
92
+ */
93
+ @property()
94
+ text: string | string[];
95
+
96
+ /**
97
+ * Effect duration, ending in s or ms.
98
+ */
99
+ @property()
100
+ duration: string;
101
+
102
+ protected render() {
103
+ const texts = this.getTexts();
104
+ return [
105
+ texts.map(this.renderText),
106
+ htmlStyle(this.computeStyle(texts.length)),
107
+ ];
108
+ }
109
+
110
+ protected renderText(text: string) {
111
+ return html`<span class="rel">
112
+ <span class="nocolor">${text}</span>
113
+ <span class="colorful">${text}</span>
114
+ </span>`;
115
+ }
116
+
117
+ protected getTexts(): string[] {
118
+ return Array.isArray(this.text) ? this.text : (this.text || this.textContent).split(/\s+/).filter((x) => x);
119
+ }
120
+
121
+ protected computeStyle(len: number) {
122
+ const gap = 100 / 2 / len;
123
+ const duration = this.parseDuration() || len * 2 + 2;
124
+
125
+ return (
126
+ `.colorful{animation-duration:${duration}s;}`
127
+ + `@keyframes colorfulN{0%,${gap * 3}%{opacity:0;}${gap}%,${gap * 2}%{opacity:1;}}`
128
+ + (() => {
129
+ let style1 = "";
130
+ for (let number = 1; number <= len; number++) {
131
+ const delay = -duration / len * (len - number + 1);
132
+ const defaultNumber = ((number - 1) % 3) + 1;
133
+ style1 +=
134
+ `.rel:nth-child(${number}) .colorful{animation-delay:${delay}s;background:var(${cssScope}--${number},var(${cssScope}--${defaultNumber}));}`;
135
+ }
136
+ return style1;
137
+ })()
138
+ );
139
+ }
140
+
141
+ protected parseDuration() {
142
+ const { duration } = this;
143
+ if (duration) {
144
+ if (duration.endsWith("s")) {
145
+ return parseFloat(duration.slice(0, -1));
146
+ } else if (duration.endsWith("ms")) {
147
+ return parseFloat(duration.slice(0, -2)) / 1000;
148
+ }
149
+ }
150
+ }
151
+ }
152
+
153
+ export default Breath;
@@ -0,0 +1,286 @@
1
+ import { godown } from "@godown/element/decorators/godown.js";
2
+ import { part } from "@godown/element/decorators/part.js";
3
+ import { styles } from "@godown/element/decorators/styles.js";
4
+ import { htmlSlot } from "@godown/element/directives/html-slot.js";
5
+ import { htmlStyle } from "@godown/element/directives/html-style.js";
6
+ import { constructCSSObject, toVar } from "@godown/element/tools/css.js";
7
+ import { css, html } from "lit";
8
+ import { property } from "lit/decorators.js";
9
+
10
+ import { cssGlobalVars, GlobalStyle, scopePrefix } from "../core/global-style.js";
11
+
12
+ const protoName = "button";
13
+ const cssScope = scopePrefix(protoName);
14
+
15
+ const whiteFont = cssGlobalVars.white;
16
+ const blackFont = cssGlobalVars.black;
17
+
18
+ const colors = constructCSSObject(
19
+ ["color", "background", "gradients"].map((k) => `${cssScope}--${k}`),
20
+ {
21
+ black: [
22
+ whiteFont, // color
23
+ cssGlobalVars._colors.darkgray[7], // background
24
+ cssGlobalVars._colors.darkgray[5], // gradients
25
+ ],
26
+ gray: [
27
+ whiteFont, // color
28
+ cssGlobalVars._colors.darkgray[1], // background
29
+ cssGlobalVars._colors.lightgray[8], // gradients
30
+ ],
31
+ white: [
32
+ blackFont, // color
33
+ cssGlobalVars._colors.lightgray[3], // background
34
+ cssGlobalVars._colors.lightgray[0], // gradients
35
+ ],
36
+ blue: [
37
+ whiteFont, // color
38
+ cssGlobalVars._colors.blue[6], // background
39
+ cssGlobalVars._colors.blue[4], // gradients
40
+ ],
41
+ green: [
42
+ whiteFont, // color
43
+ cssGlobalVars._colors.green[6], // background
44
+ cssGlobalVars._colors.green[4], // gradients
45
+ ],
46
+ red: [
47
+ whiteFont, // color
48
+ cssGlobalVars._colors.red[6], // background
49
+ cssGlobalVars._colors.red[4], // gradients
50
+ ],
51
+ orange: [
52
+ whiteFont, // color
53
+ cssGlobalVars._colors.orange[6], // background
54
+ cssGlobalVars._colors.orange[4], // gradients
55
+ ],
56
+ pink: [
57
+ whiteFont, // color
58
+ cssGlobalVars._colors.pink[6], // background
59
+ cssGlobalVars._colors.pink[4], // gradients
60
+ ],
61
+ purple: [
62
+ whiteFont, // color
63
+ cssGlobalVars._colors.purple[6], // background
64
+ cssGlobalVars._colors.purple[4], // gradients
65
+ ],
66
+ yellow: [
67
+ blackFont, // color
68
+ cssGlobalVars._colors.yellow[6], // background
69
+ cssGlobalVars._colors.yellow[4], // gradients
70
+ ],
71
+ teal: [
72
+ whiteFont, // color
73
+ cssGlobalVars._colors.teal[6], // background
74
+ cssGlobalVars._colors.teal[4], // gradients
75
+ ],
76
+ },
77
+ () => `:host`,
78
+ (prop) => toVar(prop),
79
+ );
80
+
81
+ /**
82
+ * {@linkcode Button} renders a button.
83
+ *
84
+ * Create modal animation upon clicking.
85
+ *
86
+ * Available colors (background): none, black, gray, white, blue, green, red, orange, pink, purple, yellow, teal.
87
+ *
88
+ * Default color is `black`.
89
+ *
90
+ * Set the color to `none` to prevent applying styles.
91
+ *
92
+ * @category input
93
+ */
94
+ @godown(protoName)
95
+ @styles(
96
+ css`
97
+ :host(:not([disabled]):active) {
98
+ transform: scale(var(${cssScope}--focus-scale));
99
+ }
100
+
101
+ :host([round]) {
102
+ ${cssScope}--padding-x: .75em;
103
+ border-radius: calc(infinity * 1px);
104
+ }
105
+
106
+ :host([disabled]) {
107
+ cursor: not-allowed;
108
+ filter: brightness(0.85);
109
+ }
110
+
111
+ :host([ghost]) {
112
+ ${cssScope}--modal-background: var(${cssScope}--ghost-color);
113
+ box-shadow:inset 0px 0px 0px var(${cssScope}--ghost-width) var(${cssScope}--ghost-color);
114
+ color: var(${cssScope}--ghost-color);
115
+ background: transparent;
116
+ }
117
+ `,
118
+ css`
119
+ :host {
120
+ ${cssScope}--padding-x: .5em;
121
+ ${cssScope}--padding-y: .15em;
122
+ ${cssScope}--padding: var(${cssScope}--padding-y) var(${cssScope}--padding-x);
123
+ ${cssScope}--modal-animation-duration: 1s;
124
+ ${cssScope}--ghost-width: .08em;
125
+ ${cssScope}--focus-scale: .97;
126
+ ${cssScope}--deg: 45deg;
127
+ ${cssScope}--ghost-color:var(${cssScope}--background);
128
+ color: var(${cssScope}--color, inherit);
129
+ background: linear-gradient(
130
+ var(${cssScope}--deg),
131
+ var(${cssScope}--background),
132
+ var(${cssScope}--gradients, var(${cssScope}--background))
133
+ );
134
+ border-radius: 0.3em;
135
+ width: -moz-fit-content;
136
+ width: fit-content;
137
+ transition: 0.1s;
138
+ display: block;
139
+ overflow: hidden;
140
+ text-align: center;
141
+ padding: 0 !important;
142
+ cursor: pointer;
143
+ }
144
+
145
+ [part=root] {
146
+ width: 100%;
147
+ height: 100%;
148
+ overflow: hidden;
149
+ position: relative;
150
+ transition: none;
151
+ user-select: none;
152
+ border-radius: inherit;
153
+ transition-duration: inherit;
154
+ }
155
+
156
+ [part=content] {
157
+ padding: var(${cssScope}--padding);
158
+ }
159
+
160
+ i {
161
+ position: absolute;
162
+ inset: 0;
163
+ opacity: 0;
164
+ width: 100%;
165
+ height: 100%;
166
+ border-radius: 50%;
167
+ visibility: visible;
168
+ pointer-events: none;
169
+ transform-origin: 0 0;
170
+ background: var(${cssScope}--modal-background, currentColor);
171
+ animation-duration: var(${cssScope}--modal-animation-duration);
172
+ }
173
+
174
+ @keyframes kf {
175
+ 0% {
176
+ transform: scale(0) translate(-50%, -50%);
177
+ opacity: var(${cssScope}--modal-opacity, 0.1);
178
+ }
179
+ 80% {
180
+ transform: scale(1) translate(-50%, -50%);
181
+ }
182
+ to {
183
+ opacity: 0;
184
+ }
185
+ }
186
+ `,
187
+ )
188
+ class Button extends GlobalStyle {
189
+ /**
190
+ * Whether to disable this element.
191
+ */
192
+ @property({ type: Boolean, reflect: true })
193
+ disabled: boolean;
194
+
195
+ /**
196
+ * Display ghost.
197
+ */
198
+ @property({ type: Boolean, reflect: true })
199
+ ghost: boolean;
200
+
201
+ /**
202
+ * Whether this element is active or not.
203
+ */
204
+ @property({ type: Boolean, reflect: true })
205
+ active: boolean;
206
+
207
+ /**
208
+ * Display rounded.
209
+ */
210
+ @property({ type: Boolean, reflect: true })
211
+ round: boolean;
212
+
213
+ /**
214
+ * The primary color.
215
+ */
216
+ @property({ reflect: true })
217
+ color: "none" | keyof typeof colors = "black";
218
+
219
+ /**
220
+ * Content text.
221
+ */
222
+ @property()
223
+ content: string;
224
+
225
+ @part("modal-root")
226
+ protected _modalRoot: HTMLElement;
227
+ @part("root")
228
+ protected _root: HTMLElement;
229
+
230
+ protected render() {
231
+ const color = this.nextColor();
232
+ return html`<div part="root">
233
+ <span part="modal-root"></span>
234
+ <div part="content">
235
+ ${[this.content || htmlSlot(), htmlStyle(colors[color])]}
236
+ </div>
237
+ </div>`;
238
+ }
239
+
240
+ focus() {
241
+ if (this.disabled) {
242
+ return;
243
+ }
244
+ this.active = true;
245
+ super.focus();
246
+ }
247
+
248
+ blur() {
249
+ this.active = false;
250
+ super.blur();
251
+ }
252
+
253
+ firstUpdated() {
254
+ this.events.add(this, "click", this._handelClick, true);
255
+ }
256
+
257
+ protected _handelClick(e: MouseEvent) {
258
+ if (this.disabled) {
259
+ e.stopPropagation();
260
+ e.preventDefault();
261
+ return;
262
+ }
263
+ this._handleModal(e);
264
+ }
265
+
266
+ protected _handleModal(e: MouseEvent) {
267
+ const modal = document.createElement("i");
268
+ const rect = this.getBoundingClientRect();
269
+ const h = rect.height;
270
+ const w = rect.width;
271
+ const size = `${Math.sqrt(h * h + w * w) * 2}px`;
272
+ modal.style.height = size;
273
+ modal.style.width = size;
274
+ modal.style.left = `${e.clientX - rect.left}px`;
275
+ modal.style.top = `${e.clientY - rect.y}px`;
276
+ modal.style.animationName = "kf";
277
+ this._modalRoot.appendChild(modal);
278
+ modal.addEventListener("animationend", () => modal.remove(), { once: true });
279
+ }
280
+
281
+ nextColor() {
282
+ return this.color;
283
+ }
284
+ }
285
+
286
+ export default Button;
@@ -0,0 +1,80 @@
1
+ import { godown } from "@godown/element/decorators/godown.js";
2
+ import { styles } from "@godown/element/decorators/styles.js";
3
+ import { htmlSlot } from "@godown/element/directives/html-slot.js";
4
+ import { css } from "lit";
5
+ import { property } from "lit/decorators.js";
6
+
7
+ import { cssGlobalVars, GlobalStyle, scopePrefix } from "../core/global-style.js";
8
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
9
+ import type Layout from "../layout.js";
10
+
11
+ const protoName = "card";
12
+ const cssScope = scopePrefix(protoName);
13
+
14
+ /**
15
+ * {@linkcode Card} renders a card.
16
+ *
17
+ * This may be similar to {@linkcode Layout},
18
+ * but it needs to be specified to enable header and footer.
19
+ *
20
+ * @slot - The main content of the card.
21
+ * @slot header - The header of the card.
22
+ * @slot footer - The footer of the card.
23
+ * @category display
24
+ */
25
+ @godown(protoName)
26
+ @styles(
27
+ css`
28
+ :host {
29
+ ${cssScope}--background: var(${cssGlobalVars.background});
30
+ ${cssScope}--border-width: .0375em;
31
+ ${cssScope}--border-color: transparent;
32
+ ${cssScope}--border-background: var(${cssGlobalVars.passive});
33
+ ${cssScope}--padding: .75em;
34
+ color: var(${cssGlobalVars.foreground});
35
+ background: var(${cssScope}--background);
36
+ border-width: var(${cssScope}--border-width);
37
+ display: block;
38
+ flex-shrink: 0;
39
+ position: relative;
40
+ overflow: hidden;
41
+ box-sizing: border-box;
42
+ }
43
+
44
+ slot {
45
+ display: block;
46
+ padding: var(${cssScope}--padding);
47
+ }
48
+
49
+ :host,
50
+ slot {
51
+ border-color: var(${cssScope}--border-background);
52
+ border-style: solid;
53
+ }
54
+
55
+ [name=footer]{
56
+ border-top-width: var(${cssScope}--border-width);
57
+ }
58
+
59
+ [name=header]{
60
+ border-bottom-width: var(${cssScope}--border-width);
61
+ }
62
+ `,
63
+ )
64
+ class Card extends GlobalStyle {
65
+ @property({ type: Boolean })
66
+ footer = false;
67
+
68
+ @property({ type: Boolean })
69
+ header = false;
70
+
71
+ protected render() {
72
+ return [
73
+ this.header ? htmlSlot("header") : "",
74
+ htmlSlot(),
75
+ this.footer ? htmlSlot("footer") : "",
76
+ ];
77
+ }
78
+ }
79
+
80
+ export default Card;
@@ -0,0 +1,169 @@
1
+ import { godown } from "@godown/element/decorators/godown.js";
2
+ import { part } from "@godown/element/decorators/part.js";
3
+ import { styles } from "@godown/element/decorators/styles.js";
4
+ import { htmlSlot } from "@godown/element/directives/html-slot.js";
5
+ import { htmlStyle } from "@godown/element/directives/html-style.js";
6
+ import iconChevronLeft from "@godown/f7-icon/icons/chevron-left.js";
7
+ import iconChevronRight from "@godown/f7-icon/icons/chevron-right.js";
8
+ import { css, html } from "lit";
9
+ import { property } from "lit/decorators.js";
10
+
11
+ import { GlobalStyle } from "../core/global-style.js";
12
+
13
+ const protoName = "carousel";
14
+
15
+ /**
16
+ * {@linkcode Carousel} make the content display as a carousel.
17
+ *
18
+ * When this component is `firstUpdated`,
19
+ * clone the first and last element and make the matching element visible when switching index.
20
+ *
21
+ * Child elements should maintain the same size.
22
+ *
23
+ * If no width, it will be the width of the first element.
24
+ *
25
+ * @slot - Carousel items, should maintain the same size.
26
+ * @category display
27
+ */
28
+ @godown(protoName)
29
+ @styles(
30
+ css`
31
+ :host {
32
+ display: block;
33
+ transition: .3s;
34
+ }
35
+
36
+ [part=root] {
37
+ overflow: hidden;
38
+ }
39
+
40
+ [part=root],
41
+ [part=move-root] {
42
+ height: 100%;
43
+ width: 100%;
44
+ display: flex;
45
+ position: relative;
46
+ transition: inherit;
47
+ }
48
+
49
+ [part=prev],
50
+ [part=next] {
51
+ height: 100%;
52
+ width: 1.5em;
53
+ z-index: 1;
54
+ position: absolute;
55
+ display: flex;
56
+ align-items: center;
57
+ justify-content: center;
58
+ user-select: none;
59
+ }
60
+
61
+ [part=prev] {
62
+ left: 0;
63
+ }
64
+
65
+ [part=next] {
66
+ right: 0;
67
+ }
68
+
69
+ slot::slotted(*) {
70
+ flex-shrink: 0 !important;
71
+ }
72
+ `,
73
+ )
74
+ class Carousel extends GlobalStyle {
75
+ /**
76
+ * The index of the element is displayed for the first time.
77
+ */
78
+ @property({ type: Number })
79
+ index = 0;
80
+
81
+ /**
82
+ * If autoChange > 0, the rotation will be automated.
83
+ */
84
+ @property({ type: Number })
85
+ autoChange = 0;
86
+
87
+ /**
88
+ * Element width.
89
+ */
90
+ @property()
91
+ width: string;
92
+
93
+ @part("move-root")
94
+ protected _moveRoot: HTMLElement;
95
+
96
+ protected intervalID: number;
97
+
98
+ private _cloneFirst: HTMLElement | undefined;
99
+
100
+ private _cloneLast: HTMLElement | undefined;
101
+
102
+ protected render() {
103
+ return [
104
+ html`<div part="root">
105
+ <i part="prev" @click="${this.prev}">${iconChevronLeft()}</i>
106
+ <div part="move-root" style="transform:${`translateX(-${this.index + 1}00%)`}">${htmlSlot()}</div>
107
+ <i part="next" @click="${this.next}">${iconChevronRight()}</i>
108
+ </div>`,
109
+ htmlStyle(`:host{width:${this.width};}`),
110
+ ];
111
+ }
112
+
113
+ protected async firstUpdated() {
114
+ await this.updateComplete;
115
+
116
+ if (this.children.length) {
117
+ this.width ||= `${(this.firstElementChild as HTMLElement).offsetWidth}px`;
118
+
119
+ this._cloneFirst?.remove();
120
+ this._cloneLast?.remove();
121
+ this._cloneLast = this.firstElementChild.cloneNode(true) as HTMLElement;
122
+ this._cloneFirst = this.lastElementChild.cloneNode(true) as HTMLElement;
123
+ this.appendChild(this._cloneLast);
124
+ this.insertBefore(this._cloneFirst, this.firstElementChild);
125
+ this.show(this.index);
126
+ }
127
+ if (this.autoChange) {
128
+ this.intervalID = window.setInterval(() => {
129
+ this.next();
130
+ }, this.autoChange);
131
+ }
132
+ }
133
+
134
+ disconnectedCallback() {
135
+ clearInterval(this.intervalID);
136
+ }
137
+
138
+ show(i: number) {
139
+ this.index = i;
140
+ }
141
+
142
+ next() {
143
+ if (this.index === this.childElementCount - 3) {
144
+ this._doTranslateX("0", true);
145
+ this.show(0);
146
+ } else {
147
+ this.show(this.index + 1);
148
+ }
149
+ }
150
+
151
+ prev() {
152
+ if (this.index === 0) {
153
+ this._doTranslateX(`-${this.childElementCount - 1}00%`, true);
154
+ this.show(this.children.length - 3);
155
+ } else {
156
+ this.show(this.index - 1);
157
+ }
158
+ }
159
+
160
+ protected _doTranslateX(xValue: string, noTransition?: boolean) {
161
+ this._moveRoot.style.transform = `translateX(${xValue})`;
162
+ if (noTransition) {
163
+ this._moveRoot.style.transition = `none`;
164
+ }
165
+ this._moveRoot.getBoundingClientRect();
166
+ }
167
+ }
168
+
169
+ export default Carousel;