1 |
|
2 | export const WUPcssHidden = `
|
3 | position: absolute;
|
4 | height:1px; width:1px;
|
5 | overflow:hidden;
|
6 | clip:rect(1px,1px,1px,1px);
|
7 | min-width:initial;
|
8 | padding:0;`;
|
9 |
|
10 | export const WUPcssIcon = `
|
11 | display: inline-block;
|
12 | width: var(--ctrl-icon-size);
|
13 | min-height: var(--ctrl-icon-size);
|
14 | box-sizing: content-box;
|
15 | margin: 0;
|
16 | padding: 5px;
|
17 | flex: 0 0 auto;
|
18 | align-self: stretch;
|
19 | border: none;
|
20 | box-shadow: none;
|
21 | background: var(--ctrl-icon);
|
22 | -webkit-mask-size: var(--ctrl-icon-size);
|
23 | mask-size: var(--ctrl-icon-size);
|
24 | -webkit-mask-repeat: no-repeat;
|
25 | mask-repeat: no-repeat;
|
26 | -webkit-mask-position: center;
|
27 | mask-position: center;
|
28 | -webkit-mask-image: var(--ctrl-icon-img);
|
29 | mask-image: var(--ctrl-icon-img);`;
|
30 |
|
31 |
|
32 |
|
33 | export function WUPcssScrollSmall(tag) {
|
34 | return `
|
35 | ${tag}::-webkit-scrollbar {
|
36 | width: 10px; height: 10px;
|
37 | cursor: pointer;
|
38 | }
|
39 | ${tag}::-webkit-scrollbar-corner {
|
40 | background: none;
|
41 | cursor: pointer;
|
42 | }
|
43 | ${tag}::-webkit-scrollbar-thumb {
|
44 | border: 3px solid rgba(0,0,0,0);
|
45 | background-clip: padding-box;
|
46 | background-color: var(--scroll, rgba(0,0,0,0.2));
|
47 | border-radius: 999px;
|
48 | cursor: pointer;
|
49 | }
|
50 | ${tag}::-webkit-scrollbar-track-piece:vertical:start,
|
51 | ${tag}::-webkit-scrollbar-track-piece:vertical:end,
|
52 | ${tag}::-webkit-scrollbar-track-piece:horizontal:start,
|
53 | ${tag}::-webkit-scrollbar-track-piece:horizontal:end {
|
54 | margin: 0;
|
55 | cursor: pointer;
|
56 | }
|
57 | @media (hover) {
|
58 | ${tag}::-webkit-scrollbar-thumb:hover {
|
59 | background-color: var(--scroll-hover, rgba(0,0,0,0.5));
|
60 | cursor: pointer;
|
61 | }
|
62 | }`;
|
63 | }
|
64 |
|
65 | export function WUPcssButton(tag) {
|
66 | return `
|
67 | ${tag} {
|
68 | box-shadow: none;
|
69 | border: 1px solid var(--base-btn-bg);
|
70 | border-radius: var(--border-radius);
|
71 | box-sizing: border-box;
|
72 | padding: 0.5em;
|
73 | margin: 1em 0;
|
74 | min-width: 10em;
|
75 | cursor: pointer;
|
76 | font: inherit;
|
77 | font-weight: bold;
|
78 | background: var(--base-btn-bg);
|
79 | color: var(--base-btn-text);
|
80 | outline: none;
|
81 | }
|
82 | ${tag}:focus {
|
83 | border-color: var(--base-btn-focus);
|
84 | }
|
85 | @media (hover: hover) and (pointer: fine) {
|
86 | ${tag}:hover {
|
87 | box-shadow: inset 0 0 0 99999px rgba(0,0,0,0.2);
|
88 | }
|
89 | }
|
90 | ${tag}[disabled] {
|
91 | opacity: 0.3;
|
92 | cursor: not-allowed;
|
93 | -webkit-user-select: none;
|
94 | user-select: none;
|
95 | }
|
96 | ${tag}[aria-busy] {
|
97 | cursor: wait;
|
98 | }`;
|
99 | }
|
100 |
|
101 | export function WUPcssMenu(tag) {
|
102 | return `
|
103 | ${tag} {
|
104 | padding: 0;
|
105 | overflow: hidden;
|
106 | }
|
107 | ${tag} ul {
|
108 | margin: 0;
|
109 | padding: 0;
|
110 | list-style-type: none;
|
111 | cursor: pointer;
|
112 | overflow: auto;
|
113 | max-height: 300px;
|
114 | }
|
115 | ${WUPcssScrollSmall(`${tag} ul`)}
|
116 | ${tag} li {
|
117 | padding: 1em;
|
118 | border-radius: var(--border-radius);
|
119 | }
|
120 | @media (hover: hover) and (pointer: fine) {
|
121 | ${tag} li:hover {
|
122 | box-shadow: inset 0 0 3px 0 var(--base-focus);
|
123 | }
|
124 | }
|
125 | ${tag} li[aria-selected="true"] {
|
126 | color: var(--ctrl-selected);
|
127 | display: flex;
|
128 | }
|
129 | ${tag} li[aria-selected="true"]:after {
|
130 | content: "";
|
131 | --ctrl-icon-img: var(--wup-icon-check);
|
132 | ${WUPcssIcon}
|
133 | background: var(--ctrl-selected);
|
134 | margin-left: auto;
|
135 | padding: 0;
|
136 | }
|
137 | ${tag} li[focused] {
|
138 | box-shadow: inset 0 0 4px 0 var(--base-focus);
|
139 | }`;
|
140 | }
|
141 | let refStyle;
|
142 |
|
143 | export function useBuiltinStyle(cssString) {
|
144 | if (!refStyle) {
|
145 | refStyle = document.createElement("style");
|
146 | document.head.prepend(refStyle);
|
147 | }
|
148 | refStyle.append(cssString);
|
149 | return refStyle;
|
150 | }
|