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